Skip to content

Commit 2a019d5

Browse files
committed
Fix incorrect fd indexing in mirror mode
1 parent 8c81d23 commit 2a019d5

File tree

1 file changed

+22
-4
lines changed

1 file changed

+22
-4
lines changed

src/tx.cpp

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -194,16 +194,34 @@ void RawSocketTransmitter::set_mark(uint32_t idx)
194194
return;
195195
}
196196

197-
int fd = sockfds[current_output];
198-
uint32_t sockopt = this->fwmark + idx;
197+
if (current_output >= 0)
198+
{
199+
int fd = sockfds[current_output];
200+
uint32_t sockopt = fwmark + idx;
201+
202+
if(setsockopt(fd, SOL_SOCKET, SO_MARK, (const void *)&sockopt , sizeof(sockopt)) !=0)
203+
{
204+
throw runtime_error(string_format("Unable to set SO_MARK fd(%d)=%u: %s", fd, sockopt, strerror(errno)));
205+
}
206+
207+
return;
208+
}
199209

200-
if(setsockopt(fd, SOL_SOCKET, SO_MARK, (const void *)&sockopt , sizeof(sockopt)) !=0)
210+
// Handle mirror mode
211+
for(auto it = sockfds.begin(); it != sockfds.end(); it++)
201212
{
202-
throw runtime_error(string_format("Unable to set SO_MARK fd(%d)=%u: %s", fd, sockopt, strerror(errno)));
213+
int fd = *it;
214+
uint32_t sockopt = fwmark + idx;
215+
216+
if(setsockopt(fd, SOL_SOCKET, SO_MARK, (const void *)&sockopt , sizeof(sockopt)) !=0)
217+
{
218+
throw runtime_error(string_format("Unable to set SO_MARK fd(%d)=%u: %s", fd, sockopt, strerror(errno)));
219+
}
203220
}
204221
}
205222

206223

224+
207225
RawSocketTransmitter::RawSocketTransmitter(int k, int n, const string &keypair, uint64_t epoch, uint32_t channel_id, uint32_t fec_delay,
208226
vector<tags_item_t> &tags, const vector<string> &wlans, vector<uint8_t> &radiotap_header,
209227
uint8_t frame_type, bool use_qdisc, uint32_t fwmark) : \

0 commit comments

Comments
 (0)