mirror of
https://github.com/traviscross/mtr.git
synced 2024-09-21 10:27:10 +00:00
Use Packet Marking for IP Address Selection
In certain scenarios, the routing policy database may affect packet routing. When selecting an address in `mtr`, assign a packet mark if `SO_MARK` is defined and a mark has been supplied.
This commit is contained in:
parent
47dd026ce3
commit
23486b312c
15
ui/net.c
15
ui/net.c
@ -687,8 +687,8 @@ static void net_find_interface_address_from_name(
|
||||
host by connecting a UDP socket and checking the address
|
||||
the socket is bound to.
|
||||
*/
|
||||
static void net_find_local_address(
|
||||
void)
|
||||
static
|
||||
void net_find_local_address(struct mtr_ctl * ctl)
|
||||
{
|
||||
int udp_socket;
|
||||
int addr_length;
|
||||
@ -700,6 +700,15 @@ static void net_find_local_address(
|
||||
error(EXIT_FAILURE, errno, "udp socket creation failed");
|
||||
}
|
||||
|
||||
#ifdef SO_MARK
|
||||
/* On Linux, the packet mark can affect the selection of the source address */
|
||||
if(ctl->mark) {
|
||||
if(setsockopt(udp_socket, SOL_SOCKET, SO_MARK, &ctl->mark, sizeof(ctl->mark))) {
|
||||
error(EXIT_FAILURE, errno, "failed to set the packet mark");
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
We need to set the port to a non-zero value for the connect
|
||||
to succeed.
|
||||
@ -778,7 +787,7 @@ void net_reopen(
|
||||
&sourcesockaddr_struct, ctl->af, ctl->InterfaceName);
|
||||
inet_ntop(sourcesockaddr->sa_family, sourceaddress, localaddr, sizeof(localaddr));
|
||||
} else {
|
||||
net_find_local_address();
|
||||
net_find_local_address(ctl);
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user