Skip to content

Commit

Permalink
Merge pull request #489 from flu0r1ne/set-mark-during-address-selection
Browse files Browse the repository at this point in the history
Set mark during address selection
  • Loading branch information
rewolff authored Oct 4, 2023
2 parents 62bd718 + 7d8b704 commit 6e659b8
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
2 changes: 1 addition & 1 deletion packet/probe.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ struct probe_param_t {
int type_of_service;

/* The packet "mark" used for mark-based routing on Linux */
int routing_mark;
uint32_t routing_mark;

/* Time to live for the transmitted probe */
int ttl;
Expand Down
15 changes: 12 additions & 3 deletions ui/net.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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.
Expand Down Expand Up @@ -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);
}

}
Expand Down
2 changes: 1 addition & 1 deletion ui/utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ int strtonum_or_err(

if (str != NULL && *str != '\0') {
errno = 0;
num = strtoul(str, &end, 10);
num = strtoul(str, &end, 0);
if (errno == 0 && str != end && end != NULL && *end == '\0') {
switch (type) {
case STRTO_INT:
Expand Down

0 comments on commit 6e659b8

Please sign in to comment.