Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set mark during address selection #489

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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