Skip to content

Commit 57ce645

Browse files
committed
net: filter for default routes in netlink responses
Filter netlink responses to only consider default routes by checking the destination prefix length (rtm_dst_len == 0). Previously, we selected the first route with an RTA_GATEWAY attribute, which for IPv6 often resulted in choosing a non-default route instead of the actual default. This caused occasional PCP port mapping failures because a gateway for a non-default route was selected.
1 parent 74d9598 commit 57ce645

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

src/common/netif.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,11 @@ std::optional<CNetAddr> QueryDefaultGatewayImpl(sa_family_t family)
9797
rtmsg* r = (rtmsg*)NLMSG_DATA(hdr);
9898
int remaining_len = RTM_PAYLOAD(hdr);
9999

100+
// Only consider default routes (destination prefix length of 0).
101+
if (r->rtm_dst_len != 0) {
102+
continue;
103+
}
104+
100105
// Iterate over the attributes.
101106
rtattr *rta_gateway = nullptr;
102107
int scope_id = 0;

0 commit comments

Comments
 (0)