From 57ce645f05d18d8ad10711c347a5989076f1f788 Mon Sep 17 00:00:00 2001 From: willcl-ark Date: Wed, 2 Apr 2025 09:46:56 +0100 Subject: [PATCH] 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. --- src/common/netif.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/common/netif.cpp b/src/common/netif.cpp index 7424f977c7..dbdd3ddde9 100644 --- a/src/common/netif.cpp +++ b/src/common/netif.cpp @@ -97,6 +97,11 @@ std::optional QueryDefaultGatewayImpl(sa_family_t family) rtmsg* r = (rtmsg*)NLMSG_DATA(hdr); int remaining_len = RTM_PAYLOAD(hdr); + // Only consider default routes (destination prefix length of 0). + if (r->rtm_dst_len != 0) { + continue; + } + // Iterate over the attributes. rtattr *rta_gateway = nullptr; int scope_id = 0;