aboutgitcodebugslistschat
diff options
context:
space:
mode:
-rw-r--r--netlink.c10
-rw-r--r--passt.12
-rw-r--r--test/pasta_options/multipath_gateway46
3 files changed, 53 insertions, 5 deletions
diff --git a/netlink.c b/netlink.c
index e91507d..e1b5f75 100644
--- a/netlink.c
+++ b/netlink.c
@@ -375,11 +375,13 @@ unsigned int nl_get_ext_if(int s, sa_family_t af)
/**
* nl_route_get_def_multipath() - Get first highest-weight route from nexthop list
* @rta: Routing netlink attribute with type RTA_MULTIPATH
+ * @ifi: Interface index
* @gw: Default 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 ifi,
+ void *gw)
{
int nh_len = RTA_PAYLOAD(rta);
struct rtnexthop *rtnh;
@@ -391,6 +393,9 @@ static bool nl_route_get_def_multipath(struct rtattr *rta, void *gw)
size_t len = rtnh->rtnh_len - sizeof(*rtnh);
struct rtattr *rta_inner;
+ if (rtnh->rtnh_ifindex != (int)ifi)
+ continue;
+
if (rtnh->rtnh_hops <= hops)
continue;
@@ -453,7 +458,8 @@ int nl_route_get_def(int s, unsigned int ifi, sa_family_t af, void *gw)
for (rta = RTM_RTA(rtm), na = RTM_PAYLOAD(nh); RTA_OK(rta, na);
rta = RTA_NEXT(rta, na)) {
if (rta->rta_type == RTA_MULTIPATH)
- found = nl_route_get_def_multipath(rta, gw);
+ found = nl_route_get_def_multipath(rta, ifi,
+ gw);
if (rta->rta_type != RTA_GATEWAY)
continue;
diff --git a/passt.1 b/passt.1
index bf7a95b..e64ae94 100644
--- a/passt.1
+++ b/passt.1
@@ -204,7 +204,7 @@ Assign IPv4 \fIaddr\fR as default gateway via DHCP (option 3), or IPv6
This option can be specified zero (for defaults) to two times (once for IPv4,
once for IPv6).
By default, IPv4 and IPv6 gateways are taken from the host interface with the
-first default route, if any, for the corresponding IP version. If the default
+first default route, if any, for the corresponding IP version. If that default
route is a multipath one, the gateway is the first nexthop router returned by
the kernel which has the highest weight in the set of paths. If no default
routes are available and there is just one interface with any route, that
diff --git a/test/pasta_options/multipath_gateway b/test/pasta_options/multipath_gateway
index f7bd45d..b40da30 100644
--- a/test/pasta_options/multipath_gateway
+++ b/test/pasta_options/multipath_gateway
@@ -6,7 +6,7 @@
# 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
htools ip unshare sed grep
@@ -19,6 +19,7 @@ set PREFIX 192.0.2.
set ADDRESS 192.0.2.10/24
set LINKLOCAL true
set ADDRESS_SETUP ip -__FAMILY__ address add __ADDRESS__ dev dummy0; __LINKLOCAL__
+set OTHER_INTERFACE_SETUP true
endef
def ipv6
@@ -27,6 +28,19 @@ set PREFIX 2001:db8:1::
set ADDRESS 2001:db8:1::10/64
set LINKLOCAL ip -6 addr add fe80::10/64 dev dummy0 nodad
set ADDRESS_SETUP ip -__FAMILY__ address add __ADDRESS__ dev dummy0 nodad; __LINKLOCAL__
+set OTHER_INTERFACE_SETUP true
+endef
+
+def ipv4_other_interface
+ipv4
+set OTHER_PREFIX 198.51.100.
+set OTHER_INTERFACE_SETUP ip link add dummy1 type dummy; ip link set dummy1 up; ip -4 address add __OTHER_PREFIX__10/24 dev dummy1
+endef
+
+def ipv6_other_interface
+ipv6
+set OTHER_PREFIX 2001:db8:2::
+set OTHER_INTERFACE_SETUP ip link add dummy1 type dummy; ip link set dummy1 up; ip -6 address add __OTHER_PREFIX__10/64 dev dummy1 nodad
endef
# Keep each invocation in its own user/network namespace
@@ -37,7 +51,7 @@ set LINK_SETUP ip link set lo up; ip link add dummy0 type dummy; ip link set dum
set ROUTE_SETUP ip -__FAMILY__ route add default __NEXTHOPS__
set ROUTE_SHOW ip -__FAMILY__ route show default
set NETWORK_SHOW ip -__FAMILY__ address show dev dummy0; ip -__FAMILY__ route show table all
-set SETUP __LINK_SETUP__; __ADDRESS_SETUP__; __NETWORK_SHOW__; __ROUTE_SETUP__
+set SETUP __LINK_SETUP__; __ADDRESS_SETUP__; __OTHER_INTERFACE_SETUP__; __NETWORK_SHOW__; __ROUTE_SETUP__
set PASTA ./pasta --netns-only --ipv__FAMILY__-only --debug --interface dummy0
hout STATUS unshare --map-root-user --net -- sh -ec '__SETUP__; __ROUTE_SHOW__; exec __PASTA__ -- true' >'__LOG__' 2>&1; echo \$?
host cat '__LOG__'
@@ -95,3 +109,31 @@ ipv4
set NEXTHOPS nexthop dev dummy0 weight 1 nexthop via __PREFIX__2 dev dummy0 weight 1
set EXPECTED __PREFIX__2
check_gateway
+
+test IPv4: higher-weight gateway on another interface is ignored
+set CASE other-after
+ipv4_other_interface
+set NEXTHOPS nexthop via __PREFIX__1 dev dummy0 weight 1 nexthop via __OTHER_PREFIX__1 dev dummy1 weight 3
+set EXPECTED __PREFIX__1
+check_gateway
+
+test IPv6: higher-weight gateway on another interface is ignored
+set CASE other-after
+ipv6_other_interface
+set NEXTHOPS nexthop via __PREFIX__1 dev dummy0 weight 1 nexthop via __OTHER_PREFIX__1 dev dummy1 weight 3
+set EXPECTED __PREFIX__1
+check_gateway
+
+test IPv4: selected interface can be the second multipath nexthop
+set CASE other-before
+ipv4_other_interface
+set NEXTHOPS nexthop via __OTHER_PREFIX__1 dev dummy1 weight 3 nexthop via __PREFIX__1 dev dummy0 weight 1
+set EXPECTED __PREFIX__1
+check_gateway
+
+test IPv6: selected interface can be the second multipath nexthop
+set CASE other-before
+ipv6_other_interface
+set NEXTHOPS nexthop via __OTHER_PREFIX__1 dev dummy1 weight 3 nexthop via __PREFIX__1 dev dummy0 weight 1
+set EXPECTED __PREFIX__1
+check_gateway