From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: passt.top; dmarc=fail (p=none dis=none) header.from=benschubert.me Received: from mail-4317.protonmail.ch (mail-4317.protonmail.ch [185.70.43.17]) by passt.top (Postfix) with ESMTPS id 2535C5A0269 for ; Thu, 03 Dec 2026 16:12:31 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=benschubert.me; s=protonmail3; t=1796310750; x=1796569950; bh=y6bAiUnCdK9UdUP25D2Q7UsxywPB9sWCcZ2Wt0ZbPkQ=; h=Date:To:From:Subject:Message-ID:Feedback-ID:From:To:Cc:Date: Subject:Reply-To:Feedback-ID:Message-ID:BIMI-Selector; b=GDnXhLMRsF4NlLyphVb4O+U1rh5mLGZ1mGXrOYesWpAXU+5M7qPmrFDmvWgqGx/Gl TqgLcblWlYwpm6bgI3VTMW4zgl3JXbRIeoPdOrDoCSdrWRXHdpHb2FUQjiD959SIls 0xWvduBHa/Qdv2O1xBi2vHPyuLRI2C4oK6QpSD5lBFNS9/OPYyfVtOUbtN1eRN5flX gsIg3JTiQYUVXUX/HyVqgNmvBUK+hRKwIwhLSzmjRACQ5v/CYQksZFlPHRVD15pCS2 SN7LmSxWZCZDBxENzp//R5H8Fa7NC2eTfpIywCUwfSmmjH9iz3NT3TWXUvIr+1ogKB ViV0PNlHuT8Ow== Date: Thu, 03 Dec 2026 15:12:25 +0000 To: "passt-dev@passt.top" From: Benjamin Schubert Subject: [PATCH] netlink: Only consider gateway from the selected template interface Message-ID: <2UuogkMNAhFH_0bGAADpm7VgzMi123uydmdNZpZZ6tWdhkxB8y5S4Z4h4Ela1Vyb0QymFQg2Pe03CsvEWjLtdvbeFhbCuBJthILFuMs-JYo=@benschubert.me> Feedback-ID: 12078535:user:proton X-Pm-Message-ID: fe02033d6c12753053227f7a6039ae1ef481e226 MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-MailFrom: contact@benschubert.me X-Mailman-Rule-Hits: nonmember-moderation X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation Message-ID-Hash: BY7CUV5OG2JE6ZYTQIBVO5ZPENS52Y62 X-Message-ID-Hash: BY7CUV5OG2JE6ZYTQIBVO5ZPENS52Y62 X-Mailman-Approved-At: Thu, 03 Dec 2026 16:25:29 +0100 X-Mailman-Version: 3.3.8 Precedence: list List-Id: Development discussion and patches for passt Archived-At: Archived-At: List-Archive: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: From: Benjamin Schubert Previously, netlink could select a gateway from a different interface if it had higher weights than the one from the selected interface. This can lead to a namespace having an unreachable default gateway. This considers only nexthops from the current interface instead of all interfaces when looking at the template interface, ensuring that the ip and the gateway are always aligned. Link: https://bugs.passt.top/show_bug.cgi?id=3D232 Signed-off-by: Benjamin Schubert --- netlink.c | 8 +++-- test/pasta_options/multipath_gateway | 46 ++++++++++++++++++++++++++-- 2 files changed, 50 insertions(+), 4 deletions(-) diff --git a/netlink.c b/netlink.c index 37c55cc..f7bc7ab 100644 --- a/netlink.c +++ b/netlink.c @@ -362,26 +362,30 @@ unsigned int nl_get_ext_if(int s, sa_family_t af) } =20 /** * nl_route_get_def_multipath() - Get first highest-weight route from next= hop list * @rta:=09Routing netlink attribute with type RTA_MULTIPATH + * @ifi:=09Interface index * @gw:=09=09Default gateway to fill * * Return: true if a gateway was found, false otherwise */ -static bool nl_route_get_def_multipath(struct rtattr *rta, void *gw) +static bool nl_route_get_def_multipath(struct rtattr *rta, unsigned int if= i, void *gw) { =09int nh_len =3D RTA_PAYLOAD(rta); =09struct rtnexthop *rtnh; =09bool found =3D false; =09int hops =3D -1; =20 =09for (rtnh =3D (struct rtnexthop *)RTA_DATA(rta); =09 RTNH_OK(rtnh, nh_len); rtnh =3D RTNH_NEXT_AND_DEC(rtnh, nh_len)) { =09=09size_t len =3D rtnh->rtnh_len - sizeof(*rtnh); =09=09struct rtattr *rta_inner; =20 +=09=09if (rtnh->rtnh_ifindex !=3D (int)ifi) +=09=09=09continue; + =09=09if (rtnh->rtnh_hops <=3D hops) =09=09=09continue; =20 =09=09for (rta_inner =3D RTNH_DATA(rtnh); RTA_OK(rta_inner, len); =09=09 rta_inner =3D RTA_NEXT(rta_inner, len)) { @@ -440,11 +444,11 @@ int nl_route_get_def(int s, unsigned int ifi, sa_fami= ly_t af, void *gw) =09=09=09continue; =20 =09=09for (rta =3D RTM_RTA(rtm), na =3D RTM_PAYLOAD(nh); RTA_OK(rta, na); =09=09 rta =3D RTA_NEXT(rta, na)) { =09=09=09if (rta->rta_type =3D=3D RTA_MULTIPATH) -=09=09=09=09found =3D nl_route_get_def_multipath(rta, gw); +=09=09=09=09found =3D nl_route_get_def_multipath(rta, ifi, gw); =20 =09=09=09if (rta->rta_type !=3D RTA_GATEWAY) =09=09=09=09continue; =20 =09=09=09memcpy(gw, RTA_DATA(rta), RTA_PAYLOAD(rta)); diff --git a/test/pasta_options/multipath_gateway b/test/pasta_options/mult= ipath_gateway index f7bd45d..f954646 100644 --- a/test/pasta_options/multipath_gateway +++ b/test/pasta_options/multipath_gateway @@ -4,42 +4,56 @@ # for qemu/UNIX domain socket mode # # PASTA - Pack A Subtle Tap Abstraction # for network namespace/tap device mode # -# test/pasta_options/multipath_gateway - Check gateway weights and ties +# test/pasta_options/multipath_gateway - Check gateway selection =20 htools=09ip unshare sed grep =20 set=09OUT __STATEDIR__/multipath-gateway.out set=09ERR __STATEDIR__/multipath-gateway.err =20 def=09ipv4 set=09FAMILY 4 set=09PREFIX 192.0.2. set=09ADDRESS 192.0.2.10/24 set=09LINKLOCAL true set=09ADDRESS_SETUP ip -__FAMILY__ address add __ADDRESS__ dev dummy0; __L= INKLOCAL__ +set=09OTHER_INTERFACE_SETUP true endef =20 def=09ipv6 set=09FAMILY 6 set=09PREFIX 2001:db8:1:: set=09ADDRESS 2001:db8:1::10/64 set=09LINKLOCAL ip -6 addr add fe80::10/64 dev dummy0 nodad set=09ADDRESS_SETUP ip -__FAMILY__ address add __ADDRESS__ dev dummy0 noda= d; __LINKLOCAL__ +set=09OTHER_INTERFACE_SETUP true +endef + +def=09ipv4_other_interface +ipv4 +set=09OTHER_PREFIX 192.51.100. +set=09OTHER_INTERFACE_SETUP ip link add dummy1 type dummy; ip link set dum= my1 up; ip -4 address add __OTHER_PREFIX__10/24 dev dummy1 +endef + +def=09ipv6_other_interface +ipv6 +set=09OTHER_PREFIX 2001:db8:2:: +set=09OTHER_INTERFACE_SETUP ip link add dummy1 type dummy; ip link set dum= my1 up; ip -6 address add __OTHER_PREFIX__10/64 dev dummy1 nodad endef =20 # Keep each invocation in its own user/network namespace # Reuse unshare's user namespace instead of creating another with pasta def=09check_gateway set=09LOG __STATEDIR__/ipv__FAMILY__-__CASE__.log set=09LINK_SETUP ip link set lo up; ip link add dummy0 type dummy; ip link= set dummy0 up set=09ROUTE_SETUP ip -__FAMILY__ route add default __NEXTHOPS__ set=09ROUTE_SHOW ip -__FAMILY__ route show default set=09NETWORK_SHOW ip -__FAMILY__ address show dev dummy0; ip -__FAMILY__ = route show table all -set=09SETUP __LINK_SETUP__; __ADDRESS_SETUP__; __NETWORK_SHOW__; __ROUTE_S= ETUP__ +set=09SETUP __LINK_SETUP__; __ADDRESS_SETUP__; __OTHER_INTERFACE_SETUP__; = __NETWORK_SHOW__; __ROUTE_SETUP__ set=09PASTA ./pasta --netns-only --ipv__FAMILY__-only --debug --interface = dummy0 hout=09STATUS unshare --map-root-user --net -- sh -ec '__SETUP__; __ROUTE_= SHOW__; exec __PASTA__ -- true' >'__LOG__' 2>&1; echo \$? host=09cat '__LOG__' check=09[ '__STATUS__' =3D '0' ] hout=09ACTUAL sed --quiet 's/.*router: *//p' '__LOG__' @@ -93,5 +107,33 @@ test=09IPv4: gateway-less nexthop does not mask an equa= l-weight gateway set=09CASE direct ipv4 set=09NEXTHOPS nexthop dev dummy0 weight 1 nexthop via __PREFIX__2 dev dum= my0 weight 1 set=09EXPECTED __PREFIX__2 check_gateway + +test=09IPv4: higher-weight gateway on another interface is ignored +set=09CASE other-after +ipv4_other_interface +set=09NEXTHOPS nexthop via __PREFIX__1 dev dummy0 weight 1 nexthop via __O= THER_PREFIX__1 dev dummy1 weight 3 +set=09EXPECTED __PREFIX__1 +check_gateway + +test=09IPv6: higher-weight gateway on another interface is ignored +set=09CASE other-after +ipv6_other_interface +set=09NEXTHOPS nexthop via __PREFIX__1 dev dummy0 weight 1 nexthop via __O= THER_PREFIX__1 dev dummy1 weight 3 +set=09EXPECTED __PREFIX__1 +check_gateway + +test=09IPv4: selected interface can be the second multipath nexthop +set=09CASE other-before +ipv4_other_interface +set=09NEXTHOPS nexthop via __OTHER_PREFIX__1 dev dummy1 weight 3 nexthop v= ia __PREFIX__1 dev dummy0 weight 1 +set=09EXPECTED __PREFIX__1 +check_gateway + +test=09IPv6: selected interface can be the second multipath nexthop +set=09CASE other-before +ipv6_other_interface +set=09NEXTHOPS nexthop via __OTHER_PREFIX__1 dev dummy1 weight 3 nexthop v= ia __PREFIX__1 dev dummy0 weight 1 +set=09EXPECTED __PREFIX__1 +check_gateway --=20 2.56.1