From 2a019d54fc7fd4f54c66d073eb3c22743185ec31 Mon Sep 17 00:00:00 2001 From: Vasily Evseenko Date: Wed, 11 Sep 2024 23:03:10 +0300 Subject: [PATCH] Fix incorrect fd indexing in mirror mode --- src/tx.cpp | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/src/tx.cpp b/src/tx.cpp index 372ea5a1..d6d2b5ce 100644 --- a/src/tx.cpp +++ b/src/tx.cpp @@ -194,16 +194,34 @@ void RawSocketTransmitter::set_mark(uint32_t idx) return; } - int fd = sockfds[current_output]; - uint32_t sockopt = this->fwmark + idx; + if (current_output >= 0) + { + int fd = sockfds[current_output]; + uint32_t sockopt = fwmark + idx; + + if(setsockopt(fd, SOL_SOCKET, SO_MARK, (const void *)&sockopt , sizeof(sockopt)) !=0) + { + throw runtime_error(string_format("Unable to set SO_MARK fd(%d)=%u: %s", fd, sockopt, strerror(errno))); + } + + return; + } - if(setsockopt(fd, SOL_SOCKET, SO_MARK, (const void *)&sockopt , sizeof(sockopt)) !=0) + // Handle mirror mode + for(auto it = sockfds.begin(); it != sockfds.end(); it++) { - throw runtime_error(string_format("Unable to set SO_MARK fd(%d)=%u: %s", fd, sockopt, strerror(errno))); + int fd = *it; + uint32_t sockopt = fwmark + idx; + + if(setsockopt(fd, SOL_SOCKET, SO_MARK, (const void *)&sockopt , sizeof(sockopt)) !=0) + { + throw runtime_error(string_format("Unable to set SO_MARK fd(%d)=%u: %s", fd, sockopt, strerror(errno))); + } } } + RawSocketTransmitter::RawSocketTransmitter(int k, int n, const string &keypair, uint64_t epoch, uint32_t channel_id, uint32_t fec_delay, vector &tags, const vector &wlans, vector &radiotap_header, uint8_t frame_type, bool use_qdisc, uint32_t fwmark) : \