Netdev List
 help / color / mirror / Atom feed
* [PATCH net-next v4 0/3] ipv4/ipv6: Cache pmtu on all paths of a multipath route
@ 2026-11-17 19:31 Vladimir Vdovin
  2026-11-17 19:31 ` [PATCH net-next v4 1/3] ipv4: Check a Fragmentation Needed against each path " Vladimir Vdovin
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Vladimir Vdovin @ 2026-11-17 19:31 UTC (permalink / raw)
  To: David Ahern, Ido Schimmel, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, Simon Horman, Shuah Khan
  Cc: netdev, linux-kernel, linux-kselftest, Vladimir Vdovin

IPv6 counterpart of commit 7d3f3b4367f3 ("net: ipv4: Cache pmtu for
all packet paths if multipath enabled"), deferred back then [1].

Patch 1 checks the mtu of a Fragmentation Needed against each path of
the IPv4 fan-out, not against the looked-up one, patch 2 does the IPv6
side, patch 3 adds the tests:
the IPv6 variant of the pmtu.sh multipath test and, for both families,
a multipath test with paths of different MTU. The IPv4 asymmetric
test fails without patch 1, the IPv6 tests without patch 2.

v4, after the Sashiko review of v3:
- ipv4: each path checks the mtu for itself, the early returns on the
  dst are skipped when it was looked up for the Fragmentation Needed;
  a locked mtu goes no higher than what a path uses, a path with a
  locked pmtu is left alone
- ipv6: walk the paths only from ip6_update_pmtu(), where dst comes
  from a lookup; sockets and tunnels update their own dst as before,
  a tunnel mtu no longer lands on the other paths of the inner route
- ipv6: skip a blackhole nexthop and siblings not in the tree
- tests: ping with ICMP sockets, a raw socket handles a Packet Too Big
  a second time and could pass the IPv6 tests without the fix
- tests: the IPv6 addresses on lo are added with nodad, the pings
  through R2 are 1280 bytes to stay below the 1350 link
v3: https://lore.kernel.org/netdev/20261113122237.88990-1-deliran@verdict.gg/

v3, after the Sashiko review of v2:
- compare the mtu with what each path uses now, not once with the
  looked-up dst, so no path gets a pmtu above what it can carry
- ipv6: keep updating a cached dst itself, the walk may not find it
- ipv4: Fixes: tag, Fragmentation Needed wording
- tests: MTU 1350 on the link to R2, so a Packet Too Big from R1 must
  not be cached on the path via R2
- tests: return routes on R1 and R2, hex flow labels, skip when
  "ip route get" has no flowlabel
v2: https://lore.kernel.org/netdev/20261110095903.84813-1-deliran@verdict.gg/

v2, after the Sashiko review of v1:
- update an existing exception in place, on every Packet Too Big
- don't walk the siblings of a fib6_info no longer in the tree
- commit message: the lookup in ip6_update_pmtu() hashes without
  protocol and ports
- new ipv4 patch, tests with paths of different MTU
v1: https://lore.kernel.org/netdev/20261017210508.71849-1-deliran@verdict.gg/

[1] https://lore.kernel.org/netdev/ad29493c-9e48-4a94-b327-e47af3a9d137@kernel.org/

Vladimir Vdovin (3):
  ipv4: Check a Fragmentation Needed against each path of a multipath
    route
  ipv6: Cache pmtu for all paths of a multipath route
  selftests: net: pmtu: Add IPv6 and asymmetric multipath tests

 net/ipv4/route.c                    |  90 ++++++---
 net/ipv6/route.c                    | 138 +++++++++----
 tools/testing/selftests/net/pmtu.sh | 290 ++++++++++++++++++++++++----
 3 files changed, 418 insertions(+), 100 deletions(-)


base-commit: d26955e57475434b59d43ba372b2a50d33d5e0ed
-- 
2.56.0


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH net-next v4 1/3] ipv4: Check a Fragmentation Needed against each path of a multipath route
  2026-11-17 19:31 [PATCH net-next v4 0/3] ipv4/ipv6: Cache pmtu on all paths of a multipath route Vladimir Vdovin
@ 2026-11-17 19:31 ` Vladimir Vdovin
  2026-11-17 19:31 ` [PATCH net-next v4 2/3] ipv6: Cache pmtu for all paths " Vladimir Vdovin
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Vladimir Vdovin @ 2026-11-17 19:31 UTC (permalink / raw)
  To: David Ahern, Ido Schimmel, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, Simon Horman, Shuah Khan
  Cc: netdev, linux-kernel, linux-kselftest, Vladimir Vdovin

Since commit 7d3f3b4367f3 ("net: ipv4: Cache pmtu for all packet paths
if multipath enabled") the mtu of a Fragmentation Needed is cached on
every path of a multipath route, as the lookup for it may land on
another path than the one the flow is on. But the mtu is still checked
against that one path only, by the early returns on the looked-up dst:

- a path whose mtu or pmtu is lower gets a pmtu above what it can
  carry, its flows blackhole until the exception expires
- a mtu locked for being below ip_rt_min_pmtu is written as is, over a
  lower device mtu or locked pmtu
- a looked-up path narrower than the mtu, or already at it, ends the
  update before the path of the flow has learned anything

Check the mtu against each path instead, what it uses now as ipv4_mtu()
reports it: cache the mtu only where it is lower, cap a locked mtu to
it, leave a locked pmtu alone. The checks on the dst stay for the other
callers, sockets and tunnels, whose dst is the path of their flow. A
Fragmentation Needed that changes nothing costs the ICMP callers a fib
lookup and a look at the exception of each path.

Fixes: 7d3f3b4367f3 ("net: ipv4: Cache pmtu for all packet paths if multipath enabled")
Signed-off-by: Vladimir Vdovin <deliran@verdict.gg>
---
 net/ipv4/route.c | 90 +++++++++++++++++++++++++++++++++---------------
 1 file changed, 63 insertions(+), 27 deletions(-)

diff --git a/net/ipv4/route.c b/net/ipv4/route.c
index d0a5f6d77094..b90eed715fb5 100644
--- a/net/ipv4/route.c
+++ b/net/ipv4/route.c
@@ -150,6 +150,8 @@ static struct neighbour *ipv4_dst_neigh_lookup(const struct dst_entry *dst,
 					       struct sk_buff *skb,
 					       const void *daddr);
 static void ipv4_confirm_neigh(const struct dst_entry *dst, const void *daddr);
+static struct fib_nh_exception *find_exception(struct fib_nh_common *nhc,
+					       __be32 daddr);
 
 static struct dst_ops ipv4_dst_ops = {
 	.family =		AF_INET,
@@ -1046,54 +1048,87 @@ out:	kfree_skb_reason(skb, reason);
 	return 0;
 }
 
-static void __ip_rt_update_pmtu(struct rtable *rt, struct flowi4 *fl4, u32 mtu)
+/* The pmtu to cache on a path for the mtu of a Fragmentation Needed, 0 to
+ * leave the path alone: what it uses now, as ipv4_mtu() reports it, is not
+ * above the mtu, or its pmtu is locked. An exception about to expire is
+ * refreshed, a locked mtu is capped at what the path uses.
+ */
+static u32 fib_nhc_pmtu(struct fib_nh_common *nhc, const struct fib_info *fi,
+			__be32 daddr, u32 mtu, bool lock)
+{
+	struct fib_nh_exception *fnhe = find_exception(nhc, daddr);
+	struct net *net = dev_net(nhc->nhc_dev);
+	u32 path_mtu = 0;
+
+	if (fnhe && fnhe->fnhe_genid == fnhe_genid(net) &&
+	    time_before(jiffies, fnhe->fnhe_expires)) {
+		if (fnhe->fnhe_mtu_locked)
+			return 0;
+		if (!lock && fnhe->fnhe_pmtu == mtu &&
+		    time_before(jiffies, fnhe->fnhe_expires -
+					 net->ipv4.ip_rt_mtu_expires / 2))
+			return 0;
+		path_mtu = fnhe->fnhe_pmtu;
+	}
+	if (!path_mtu)
+		path_mtu = fi->fib_mtu;
+	if (!path_mtu)
+		path_mtu = READ_ONCE(nhc->nhc_dev->mtu);
+	path_mtu = min(path_mtu, IP_MAX_MTU);
+
+	if (lock)
+		return min(mtu, path_mtu);
+	return mtu > path_mtu ? 0 : mtu;
+}
+
+static void __ip_rt_update_pmtu(struct rtable *rt, struct flowi4 *fl4, u32 mtu,
+				bool from_lookup)
 {
 	struct dst_entry *dst = &rt->dst;
 	struct fib_result res;
 	bool lock = false;
 	struct net *net;
-	u32 old_mtu;
 
-	if (ip_mtu_locked(dst))
+	if (dst_metric_locked(dst, RTAX_MTU))
 		return;
 
-	old_mtu = ipv4_mtu(dst);
-	if (old_mtu < mtu)
+	/* A dst looked up for the Fragmentation Needed, without the ports
+	 * the packet was hashed on, may be another path of a multipath
+	 * route than the flow is on: don't judge the mtu by it, each path
+	 * does that below.
+	 */
+	if (!from_lookup && (rt->rt_mtu_locked || ipv4_mtu(dst) < mtu))
 		return;
 
 	rcu_read_lock();
 	net = dst_dev_net_rcu(dst);
 	if (mtu < net->ipv4.ip_rt_min_pmtu) {
 		lock = true;
-		mtu = min(old_mtu, net->ipv4.ip_rt_min_pmtu);
+		mtu = net->ipv4.ip_rt_min_pmtu;
 	}
 
-	if (rt->rt_pmtu == mtu && !lock &&
+	if (!from_lookup && rt->rt_pmtu == mtu && !lock &&
 	    time_before(jiffies, READ_ONCE(dst->expires) -
 				 net->ipv4.ip_rt_mtu_expires / 2))
 		goto out;
 
 	if (fib_lookup(net, fl4, &res, 0) == 0) {
 		struct fib_nh_common *nhc;
+		unsigned long expires;
+		u32 pmtu;
+		int nhsel;
 
 		fib_select_path(net, &res, fl4, NULL);
-#ifdef CONFIG_IP_ROUTE_MULTIPATH
-		if (fib_info_num_path(res.fi) > 1) {
-			int nhsel;
-
-			for (nhsel = 0; nhsel < fib_info_num_path(res.fi); nhsel++) {
-				nhc = fib_info_nhc(res.fi, nhsel);
-				if (!nhc)
-					break;
-				update_or_create_fnhe(nhc, fl4->daddr, 0, mtu, lock,
-						      jiffies + net->ipv4.ip_rt_mtu_expires);
-			}
-			goto out;
+		expires = jiffies + net->ipv4.ip_rt_mtu_expires;
+		for (nhsel = 0; nhsel < fib_info_num_path(res.fi); nhsel++) {
+			nhc = fib_info_nhc(res.fi, nhsel);
+			if (!nhc)
+				break;
+			pmtu = fib_nhc_pmtu(nhc, res.fi, fl4->daddr, mtu, lock);
+			if (pmtu)
+				update_or_create_fnhe(nhc, fl4->daddr, 0, pmtu,
+						      lock, expires);
 		}
-#endif /* CONFIG_IP_ROUTE_MULTIPATH */
-		nhc = FIB_RES_NHC(res);
-		update_or_create_fnhe(nhc, fl4->daddr, 0, mtu, lock,
-				      jiffies + net->ipv4.ip_rt_mtu_expires);
 	}
 out:
 	rcu_read_unlock();
@@ -1112,7 +1147,7 @@ static void ip_rt_update_pmtu(struct dst_entry *dst, struct sock *sk,
 	if (skb && netif_is_any_bridge_port(skb->dev))
 		fl4.flowi4_oif = 0;
 
-	__ip_rt_update_pmtu(rt, &fl4, mtu);
+	__ip_rt_update_pmtu(rt, &fl4, mtu, false);
 }
 
 void ipv4_update_pmtu(struct sk_buff *skb, struct net *net, u32 mtu,
@@ -1127,7 +1162,7 @@ void ipv4_update_pmtu(struct sk_buff *skb, struct net *net, u32 mtu,
 			 0);
 	rt = __ip_route_output_key(net, &fl4);
 	if (!IS_ERR(rt)) {
-		__ip_rt_update_pmtu(rt, &fl4, mtu);
+		__ip_rt_update_pmtu(rt, &fl4, mtu, true);
 		ip_rt_put(rt);
 	}
 }
@@ -1146,7 +1181,7 @@ static void __ipv4_sk_update_pmtu(struct sk_buff *skb, struct sock *sk, u32 mtu)
 
 	rt = __ip_route_output_key(sock_net(sk), &fl4);
 	if (!IS_ERR(rt)) {
-		__ip_rt_update_pmtu(rt, &fl4, mtu);
+		__ip_rt_update_pmtu(rt, &fl4, mtu, true);
 		ip_rt_put(rt);
 	}
 }
@@ -1183,7 +1218,8 @@ void ipv4_sk_update_pmtu(struct sk_buff *skb, struct sock *sk, u32 mtu)
 		new = true;
 	}
 
-	__ip_rt_update_pmtu(dst_rtable(xfrm_dst_path(&rt->dst)), &fl4, mtu);
+	__ip_rt_update_pmtu(dst_rtable(xfrm_dst_path(&rt->dst)), &fl4, mtu,
+			    new);
 
 	if (!dst_check(&rt->dst, 0)) {
 		if (new)
-- 
2.56.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH net-next v4 2/3] ipv6: Cache pmtu for all paths of a multipath route
  2026-11-17 19:31 [PATCH net-next v4 0/3] ipv4/ipv6: Cache pmtu on all paths of a multipath route Vladimir Vdovin
  2026-11-17 19:31 ` [PATCH net-next v4 1/3] ipv4: Check a Fragmentation Needed against each path " Vladimir Vdovin
@ 2026-11-17 19:31 ` Vladimir Vdovin
  2026-11-17 19:31 ` [PATCH net-next v4 3/3] selftests: net: pmtu: Add IPv6 and asymmetric multipath tests Vladimir Vdovin
  2026-11-17 19:37 ` [PATCH net-next v4 0/3] ipv4/ipv6: Cache pmtu on all paths of a multipath route netdev-bot+sinfo
  3 siblings, 0 replies; 5+ messages in thread
From: Vladimir Vdovin @ 2026-11-17 19:31 UTC (permalink / raw)
  To: David Ahern, Ido Schimmel, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, Simon Horman, Shuah Khan
  Cc: netdev, linux-kernel, linux-kselftest, Vladimir Vdovin

Same problem and same fix as for IPv4 in commit 7d3f3b4367f3 ("net:
ipv4: Cache pmtu for all packet paths if multipath enabled"): the
exception for a Packet Too Big may land on another path of a multipath
route than the one the flow is on, and the flow keeps blackholing. Cache
the pmtu on every path of the route instead.

For IPv6 that means:

- ip6_update_pmtu() looks the destination up by the interface the
  Packet Too Big came in on, or by a hash without the protocol and
  ports for an unbound socket, neither has to be the path of the flow.

- the paths are the fib6_nh of a nexthop object, or the siblings of the
  fib6_info the dst came from. Only ip6_update_pmtu() walks them, the
  dst of sockets and tunnels is the path of their flow.

- a path only lowers what it uses, the pmtu of its exception, updated
  in place to keep a gateway from a redirect, else the mtu of the route
  and the device. The looked-up dst isn't checked anymore, it may be
  narrower than the Packet Too Big while the path of the flow isn't.

- siblings not in the tree and a nexthop replaced by a blackhole are
  skipped.

A Packet Too Big now costs up to one exception per path, as a
Fragmentation Needed does for IPv4 since the commit above.

Link: https://lore.kernel.org/netdev/ad29493c-9e48-4a94-b327-e47af3a9d137@kernel.org/
Signed-off-by: Vladimir Vdovin <deliran@verdict.gg>
---
 net/ipv6/route.c | 138 +++++++++++++++++++++++++++++++++++------------
 1 file changed, 103 insertions(+), 35 deletions(-)

diff --git a/net/ipv6/route.c b/net/ipv6/route.c
index 04098cf32eab..a835abc698d2 100644
--- a/net/ipv6/route.c
+++ b/net/ipv6/route.c
@@ -2911,12 +2911,55 @@ static bool rt6_cache_allowed_for_pmtu(const struct rt6_info *rt)
 		(rt->rt6i_flags & RTF_PCPU || rcu_access_pointer(rt->from));
 }
 
+struct rt6_pmtu_arg {
+	struct fib6_result	res;
+	const struct in6_addr	*daddr;
+	const struct in6_addr	*saddr;
+	u32			mtu;
+};
+
+/* Cache a pmtu on one path of a route, never raising what the path
+ * uses for daddr. An existing exception is updated in place, a new
+ * one would lose a gateway learned from a redirect.
+ */
+static int rt6_nh_update_pmtu(struct fib6_nh *nh, void *_arg)
+{
+	struct rt6_pmtu_arg *arg = _arg;
+	struct fib6_result *res = &arg->res;
+	struct rt6_info *rt;
+
+	res->nh = nh;
+	rt = rt6_find_cached_rt(res, arg->daddr, arg->saddr);
+	if (rt) {
+		if (arg->mtu < dst6_mtu(&rt->dst)) {
+			rt6_do_update_pmtu(rt, arg->mtu);
+			fib6_nh_update_exception(nh, res->f6i->fib6_src.plen,
+						 rt);
+		}
+		return 0;
+	}
+
+	if (arg->mtu >= fib6_mtu(res))
+		return 0;
+
+	rt = ip6_rt_cache_alloc(res, arg->daddr, arg->saddr);
+	if (rt) {
+		rt6_do_update_pmtu(rt, arg->mtu);
+		if (rt6_insert_exception(rt, res))
+			dst_release_immediate(&rt->dst);
+	}
+
+	return 0;
+}
+
 static void __ip6_rt_update_pmtu(struct dst_entry *dst, const struct sock *sk,
 				 const struct ipv6hdr *iph, u32 mtu,
-				 bool confirm_neigh)
+				 bool confirm_neigh, bool from_lookup)
 {
-	const struct in6_addr *daddr, *saddr;
+	struct rt6_pmtu_arg arg = { .mtu = mtu };
 	struct rt6_info *rt6 = dst_rt6_info(dst);
+	const struct in6_addr *daddr, *saddr;
+	struct fib6_info *f6i, *sibling;
 
 	/* Note: do *NOT* check dst_metric_locked(dst, RTAX_MTU)
 	 * IPv6 pmtu discovery isn't optional, so 'mtu lock' cannot disable it.
@@ -2939,55 +2982,80 @@ static void __ip6_rt_update_pmtu(struct dst_entry *dst, const struct sock *sk,
 
 	if (mtu < IPV6_MIN_MTU)
 		return;
-	if (mtu >= dst6_mtu(dst))
-		return;
 
-	if (!rt6_cache_allowed_for_pmtu(rt6)) {
+	if (mtu >= dst6_mtu(dst)) {
+		/* A dst ip6_update_pmtu() looked up for the Packet Too Big
+		 * may be another path of a multipath route than the flow is
+		 * on: don't judge the mtu by it, each path does that below.
+		 */
+		if (!from_lookup)
+			return;
+	} else if (!rt6_cache_allowed_for_pmtu(rt6)) {
 		rt6_do_update_pmtu(rt6, mtu);
 		/* update rt6_ex->stamp for cache */
 		if (rt6->rt6i_flags & RTF_CACHE)
 			rt6_update_exception_stamp_rt(rt6);
-	} else if (daddr) {
-		struct fib6_result res = {};
-		struct rt6_info *nrt6;
+		if (!from_lookup)
+			return;
+	}
+	if (!daddr)
+		return;
 
-		rcu_read_lock();
-		res.f6i = rcu_dereference(rt6->from);
-		if (!res.f6i)
-			goto out_unlock;
+	rcu_read_lock();
+	f6i = rcu_dereference(rt6->from);
+	/* A route on its way out of the tree takes no exceptions */
+	if (!f6i || !rcu_access_pointer(f6i->fib6_node))
+		goto out;
 
-		res.fib6_flags = res.f6i->fib6_flags;
-		res.fib6_type = res.f6i->fib6_type;
+	arg.daddr = daddr;
+	arg.saddr = saddr;
+	arg.res.f6i = f6i;
+	arg.res.fib6_flags = f6i->fib6_flags;
+	arg.res.fib6_type = f6i->fib6_type;
 
-		if (res.f6i->nh) {
-			struct fib6_nh_match_arg arg = {
+	if (f6i->nh) {
+		if (!from_lookup) {
+			struct fib6_nh_match_arg match = {
 				.dev = dst_dev_rcu(dst),
 				.gw = &rt6->rt6i_gateway,
 			};
 
-			nexthop_for_each_fib6_nh(res.f6i->nh,
-						 fib6_nh_find_match, &arg);
-
+			nexthop_for_each_fib6_nh(f6i->nh, fib6_nh_find_match,
+						 &match);
 			/* fib6_info uses a nexthop that does not have fib6_nh
 			 * using the dst->dev + gw. Should be impossible.
 			 */
-			if (!arg.match)
-				goto out_unlock;
-
-			res.nh = arg.match;
-		} else {
-			res.nh = res.f6i->fib6_nh;
+			if (match.match)
+				rt6_nh_update_pmtu(match.match, &arg);
+		} else if (!nexthop_is_blackhole(f6i->nh)) {
+			/* A blackhole nexthop, swapped in by a replace since
+			 * the lookup, must not get a usable exception.
+			 */
+			nexthop_for_each_fib6_nh(f6i->nh, rt6_nh_update_pmtu,
+						 &arg);
 		}
+		goto out;
+	}
 
-		nrt6 = ip6_rt_cache_alloc(&res, daddr, saddr);
-		if (nrt6) {
-			rt6_do_update_pmtu(nrt6, mtu);
-			if (rt6_insert_exception(nrt6, &res))
-				dst_release_immediate(&nrt6->dst);
-		}
-out_unlock:
-		rcu_read_unlock();
+	rt6_nh_update_pmtu(f6i->fib6_nh, &arg);
+	if (!from_lookup)
+		goto out;
+
+	/* Stop when f6i leaves the sibling list, the walk would never end.
+	 * Skip a sibling not in the tree, being added or removed.
+	 */
+	list_for_each_entry_rcu(sibling, &f6i->fib6_siblings, fib6_siblings) {
+		if (!READ_ONCE(f6i->fib6_nsiblings))
+			break;
+		if (!rcu_access_pointer(sibling->fib6_node))
+			continue;
+		arg.res.f6i = sibling;
+		arg.res.fib6_flags = sibling->fib6_flags;
+		arg.res.fib6_type = sibling->fib6_type;
+		rt6_nh_update_pmtu(sibling->fib6_nh, &arg);
 	}
+out:
+	rcu_read_unlock();
 }
 
 static void ip6_rt_update_pmtu(struct dst_entry *dst, struct sock *sk,
@@ -2995,7 +3063,7 @@ static void ip6_rt_update_pmtu(struct dst_entry *dst, struct sock *sk,
 			       bool confirm_neigh)
 {
 	__ip6_rt_update_pmtu(dst, sk, skb ? ipv6_hdr(skb) : NULL, mtu,
-			     confirm_neigh);
+			     confirm_neigh, false);
 }
 
 void ip6_update_pmtu(struct sk_buff *skb, struct net *net, __be32 mtu,
@@ -3014,7 +3082,7 @@ void ip6_update_pmtu(struct sk_buff *skb, struct net *net, __be32 mtu,
 
 	dst = ip6_route_output(net, NULL, &fl6);
 	if (!dst->error)
-		__ip6_rt_update_pmtu(dst, NULL, iph, ntohl(mtu), true);
+		__ip6_rt_update_pmtu(dst, NULL, iph, ntohl(mtu), true, true);
 	dst_release(dst);
 }
 EXPORT_SYMBOL_GPL(ip6_update_pmtu);
-- 
2.56.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH net-next v4 3/3] selftests: net: pmtu: Add IPv6 and asymmetric multipath tests
  2026-11-17 19:31 [PATCH net-next v4 0/3] ipv4/ipv6: Cache pmtu on all paths of a multipath route Vladimir Vdovin
  2026-11-17 19:31 ` [PATCH net-next v4 1/3] ipv4: Check a Fragmentation Needed against each path " Vladimir Vdovin
  2026-11-17 19:31 ` [PATCH net-next v4 2/3] ipv6: Cache pmtu for all paths " Vladimir Vdovin
@ 2026-11-17 19:31 ` Vladimir Vdovin
  2026-11-17 19:37 ` [PATCH net-next v4 0/3] ipv4/ipv6: Cache pmtu on all paths of a multipath route netdev-bot+sinfo
  3 siblings, 0 replies; 5+ messages in thread
From: Vladimir Vdovin @ 2026-11-17 19:31 UTC (permalink / raw)
  To: David Ahern, Ido Schimmel, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, Simon Horman, Shuah Khan
  Cc: netdev, linux-kernel, linux-kselftest, Vladimir Vdovin

Make pmtu_ipv4_mp_exceptions family agnostic and add
pmtu_ipv6_mp_exceptions: one oversized ping over a multipath route must
leave PMTU exceptions on both paths.

Add pmtu_ipv4_mp_asym_exceptions and pmtu_ipv6_mp_asym_exceptions with
an MTU of 1400 behind one router, and 1350 on the link to the other
router with 1300 behind it. They pick a flow through each router (a
source address for IPv4, whose multipath hash covers addresses only, a
flow label for IPv6) and check that a Packet Too Big from the first
router is cached on its path only, as the second one can't carry 1400,
then that a flow through the second router lowers the PMTU of both
paths.

Host A pings with ICMP sockets. With a raw socket a Packet Too Big is
handled a second time, by rawv6_err(), looked up without the interface
it came in on, and could land the exception on the other path and pass
the IPv6 tests without the fix.

Without the preceding fixes the asymmetric tests fail for both families
and the IPv6 multipath test as well, with both legacy nexthops and
nexthop objects.

Signed-off-by: Vladimir Vdovin <deliran@verdict.gg>
---
 tools/testing/selftests/net/pmtu.sh | 290 ++++++++++++++++++++++++----
 1 file changed, 252 insertions(+), 38 deletions(-)

diff --git a/tools/testing/selftests/net/pmtu.sh b/tools/testing/selftests/net/pmtu.sh
index c7cd271714ef..df0d8f75be20 100755
--- a/tools/testing/selftests/net/pmtu.sh
+++ b/tools/testing/selftests/net/pmtu.sh
@@ -203,6 +203,19 @@
 #	on host A and B on lo reachable via both routers. Host A and B
 #	addresses have multipath routes to each other, b_r1 mtu = 1500.
 #	Check that PMTU exceptions are created for both paths.
+#
+# - pmtu_ipv6_mp_exceptions
+#	Same as above but with IPv6
+#
+# - pmtu_ipv4_mp_asym_exceptions
+#	Same topology as pmtu_ipv4_mp_exceptions, with b_r1 mtu = 1400,
+#	a_r2 mtu = 1350 and b_r2 mtu = 1300. Pick a flow through each router
+#	and check that a Packet Too Big from R1 creates a PMTU exception on
+#	the path via R1 only, as the path via R2 can't carry 1400, then that
+#	a flow through R2 lowers the PMTU of both paths
+#
+# - pmtu_ipv6_mp_asym_exceptions
+#	Same as above but with IPv6
 
 source lib.sh
 
@@ -272,7 +285,10 @@ tests="
 	list_flush_ipv6_exception	ipv6: list and flush cached exceptions	1
 	pmtu_ipv4_route_change		ipv4: PMTU exception w/route replace	1
 	pmtu_ipv6_route_change		ipv6: PMTU exception w/route replace	1
-	pmtu_ipv4_mp_exceptions		ipv4: PMTU multipath nh exceptions	1"
+	pmtu_ipv4_mp_exceptions		ipv4: PMTU multipath nh exceptions	1
+	pmtu_ipv6_mp_exceptions		ipv6: PMTU multipath nh exceptions	1
+	pmtu_ipv4_mp_asym_exceptions	ipv4: PMTU multipath nh exceptions, asymmetric MTUs	1
+	pmtu_ipv6_mp_asym_exceptions	ipv6: PMTU multipath nh exceptions, asymmetric MTUs	1"
 
 # Addressing and routing for tests with routers: four network segments, with
 # index SEGMENT between 1 and 4, a common prefix (PREFIX4 or PREFIX6) and an
@@ -350,8 +366,12 @@ tunnel6_b_addr="fd00:2::b"
 tunnel6_mask="64"
 
 host4_a_addr="192.168.99.99"
+host4_a_net="192.168.97"
 host4_b_addr="192.168.88.88"
 
+host6_a_addr="fc00:1000::a"
+host6_b_addr="fc00:1001::b"
+
 dummy6_0_prefix="fc00:1000::"
 dummy6_1_prefix="fc00:1001::"
 dummy6_mask="64"
@@ -994,49 +1014,121 @@ setup_ovs_bridge() {
 }
 
 setup_multipath_new() {
-	# Set up host A with multipath routes to host B host4_b_addr
-	run_cmd ${ns_a} ip addr add ${host4_a_addr} dev lo
-	run_cmd ${ns_a} ip nexthop add id 401 via ${prefix4}.${a_r1}.2 dev veth_A-R1
-	run_cmd ${ns_a} ip nexthop add id 402 via ${prefix4}.${a_r2}.2 dev veth_A-R2
-	run_cmd ${ns_a} ip nexthop add id 403 group 401/402
-	run_cmd ${ns_a} ip route add ${host4_b_addr} src ${host4_a_addr} nhid 403
+	family=${1}
+
+	if [ ${family} -eq 4 ]; then
+		host_a_addr=${host4_a_addr}
+		host_b_addr=${host4_b_addr}
+		nodad=""
+		nh_a_r1=${prefix4}.${a_r1}.2
+		nh_a_r2=${prefix4}.${a_r2}.2
+		nh_b_r1=${prefix4}.${b_r1}.2
+		nh_b_r2=${prefix4}.${b_r2}.2
+	else
+		host_a_addr=${host6_a_addr}
+		host_b_addr=${host6_b_addr}
+		nodad="nodad"
+		nh_a_r1=${prefix6}:${a_r1}::2
+		nh_a_r2=${prefix6}:${a_r2}::2
+		nh_b_r1=${prefix6}:${b_r1}::2
+		nh_b_r2=${prefix6}:${b_r2}::2
+	fi
+
+	# Set up host A with multipath routes to host B host_b_addr
+	run_cmd ${ns_a} ip addr add ${host_a_addr} dev lo ${nodad}
+	run_cmd ${ns_a} ip nexthop add id ${family}01 via ${nh_a_r1} dev veth_A-R1
+	run_cmd ${ns_a} ip nexthop add id ${family}02 via ${nh_a_r2} dev veth_A-R2
+	run_cmd ${ns_a} ip nexthop add id ${family}03 group ${family}01/${family}02
+	run_cmd ${ns_a} ip route add ${host_b_addr} src ${host_a_addr} nhid ${family}03
 
-	# Set up host B with multipath routes to host A host4_a_addr
-	run_cmd ${ns_b} ip addr add ${host4_b_addr} dev lo
-	run_cmd ${ns_b} ip nexthop add id 401 via ${prefix4}.${b_r1}.2 dev veth_B-R1
-	run_cmd ${ns_b} ip nexthop add id 402 via ${prefix4}.${b_r2}.2 dev veth_B-R2
-	run_cmd ${ns_b} ip nexthop add id 403 group 401/402
-	run_cmd ${ns_b} ip route add ${host4_a_addr} src ${host4_b_addr} nhid 403
+	# Set up host B with multipath routes to host A host_a_addr
+	run_cmd ${ns_b} ip addr add ${host_b_addr} dev lo ${nodad}
+	run_cmd ${ns_b} ip nexthop add id ${family}01 via ${nh_b_r1} dev veth_B-R1
+	run_cmd ${ns_b} ip nexthop add id ${family}02 via ${nh_b_r2} dev veth_B-R2
+	run_cmd ${ns_b} ip nexthop add id ${family}03 group ${family}01/${family}02
+	run_cmd ${ns_b} ip route add ${host_a_addr} src ${host_b_addr} nhid ${family}03
 }
 
 setup_multipath_old() {
-	# Set up host A with multipath routes to host B host4_b_addr
-	run_cmd ${ns_a} ip addr add ${host4_a_addr} dev lo
-	run_cmd ${ns_a} ip route add ${host4_b_addr} \
-			src ${host4_a_addr} \
-			nexthop via ${prefix4}.${a_r1}.2 weight 1 \
-			nexthop via ${prefix4}.${a_r2}.2 weight 1
+	family=${1}
+
+	if [ ${family} -eq 4 ]; then
+		host_a_addr=${host4_a_addr}
+		host_b_addr=${host4_b_addr}
+		nodad=""
+		nh_a_r1=${prefix4}.${a_r1}.2
+		nh_a_r2=${prefix4}.${a_r2}.2
+		nh_b_r1=${prefix4}.${b_r1}.2
+		nh_b_r2=${prefix4}.${b_r2}.2
+	else
+		host_a_addr=${host6_a_addr}
+		host_b_addr=${host6_b_addr}
+		nodad="nodad"
+		nh_a_r1=${prefix6}:${a_r1}::2
+		nh_a_r2=${prefix6}:${a_r2}::2
+		nh_b_r1=${prefix6}:${b_r1}::2
+		nh_b_r2=${prefix6}:${b_r2}::2
+	fi
+
+	# Set up host A with multipath routes to host B host_b_addr
+	run_cmd ${ns_a} ip addr add ${host_a_addr} dev lo ${nodad}
+	run_cmd ${ns_a} ip route add ${host_b_addr} \
+			src ${host_a_addr} \
+			nexthop via ${nh_a_r1} weight 1 \
+			nexthop via ${nh_a_r2} weight 1
 
-	# Set up host B with multipath routes to host A host4_a_addr
-	run_cmd ${ns_b} ip addr add ${host4_b_addr} dev lo
-	run_cmd ${ns_b} ip route add ${host4_a_addr} \
-			src ${host4_b_addr} \
-			nexthop via ${prefix4}.${b_r1}.2 weight 1 \
-			nexthop via ${prefix4}.${b_r2}.2 weight 1
+	# Set up host B with multipath routes to host A host_a_addr
+	run_cmd ${ns_b} ip addr add ${host_b_addr} dev lo ${nodad}
+	run_cmd ${ns_b} ip route add ${host_a_addr} \
+			src ${host_b_addr} \
+			nexthop via ${nh_b_r1} weight 1 \
+			nexthop via ${nh_b_r2} weight 1
 }
 
+
 setup_multipath() {
+	family="$1"
+
+	if [ ${family} -eq 4 ]; then
+		host_a_addr=${host4_a_addr}
+		host_b_addr=${host4_b_addr}
+		nh_r1_a=${prefix4}.${a_r1}.1
+		nh_r1_b=${prefix4}.${b_r1}.1
+		nh_r2_a=${prefix4}.${a_r2}.1
+		nh_r2_b=${prefix4}.${b_r2}.1
+	else
+		host_a_addr=${host6_a_addr}
+		host_b_addr=${host6_b_addr}
+		nh_r1_a=${prefix6}:${a_r1}::1
+		nh_r1_b=${prefix6}:${b_r1}::1
+		nh_r2_a=${prefix6}:${a_r2}::1
+		nh_r2_b=${prefix6}:${b_r2}::1
+	fi
+
 	if [ "$USE_NH" = "yes" ]; then
-		setup_multipath_new
+		setup_multipath_new ${family}
 	else
-		setup_multipath_old
+		setup_multipath_old ${family}
 	fi
 
 	# Set up routers with routes to dummies
-	run_cmd ${ns_r1} ip route add ${host4_a_addr} via ${prefix4}.${a_r1}.1
-	run_cmd ${ns_r2} ip route add ${host4_a_addr} via ${prefix4}.${a_r2}.1
-	run_cmd ${ns_r1} ip route add ${host4_b_addr} via ${prefix4}.${b_r1}.1
-	run_cmd ${ns_r2} ip route add ${host4_b_addr} via ${prefix4}.${b_r2}.1
+	run_cmd ${ns_r1} ip route add ${host_a_addr} via ${nh_r1_a}
+	run_cmd ${ns_r2} ip route add ${host_a_addr} via ${nh_r2_a}
+	run_cmd ${ns_r1} ip route add ${host_b_addr} via ${nh_r1_b}
+	run_cmd ${ns_r2} ip route add ${host_b_addr} via ${nh_r2_b}
+
+	# Ping with ICMP sockets, the sysctl covers IPv6 too: a raw socket gets
+	# a Packet Too Big a second time, through rawv6_err(), looked up without
+	# the interface it came in on, and may cache it on the other path
+	${ns_a} sysctl -q -w net.ipv4.ping_group_range="0 2147483647"
+}
+
+setup_multipath4() {
+	setup_multipath 4
+}
+
+setup_multipath6() {
+	setup_multipath 6
 }
 
 setup() {
@@ -2377,8 +2469,18 @@ test_pmtu_ipv6_route_change() {
 	test_pmtu_ipvX_route_change 6
 }
 
-test_pmtu_ipv4_mp_exceptions() {
-	setup namespaces routing multipath || return $ksft_skip
+test_pmtu_ipvX_mp_exceptions() {
+	family=${1}
+
+	if [ ${family} -eq 4 ]; then
+		ping=ping
+		dst="${host4_b_addr}"
+	else
+		ping=${ping6}
+		dst="${host6_b_addr}"
+	fi
+
+	setup namespaces routing multipath${family} || return $ksft_skip
 
 	trace "${ns_a}"  veth_A-R1    "${ns_r1}" veth_R1-A \
 	      "${ns_r1}" veth_R1-B    "${ns_b}"  veth_B-R1 \
@@ -2395,18 +2497,130 @@ test_pmtu_ipv4_mp_exceptions() {
 	mtu "${ns_r2}" veth_R2-A 2000
 	mtu "${ns_r2}" veth_R2-B 1500
 	mtu "${ns_b}"  veth_B-R2 1500
-
 	# Ping and expect two nexthop exceptions for two routes
-	run_cmd ${ns_a} ping -q -M want -i 0.1 -c 1 -s 1800 "${host4_b_addr}"
+	run_cmd ${ns_a} ${ping} -q -M want -i 0.1 -c 1 -s 1800 "${dst}"
 
 	# Check that exceptions have been created with the correct PMTU
-	pmtu_a_R1="$(route_get_dst_pmtu_from_exception "${ns_a}" "${host4_b_addr}" oif veth_A-R1)"
-	pmtu_a_R2="$(route_get_dst_pmtu_from_exception "${ns_a}" "${host4_b_addr}" oif veth_A-R2)"
-
+	pmtu_a_R1="$(route_get_dst_pmtu_from_exception "${ns_a}" "${dst}" oif veth_A-R1)"
+	pmtu_a_R2="$(route_get_dst_pmtu_from_exception "${ns_a}" "${dst}" oif veth_A-R2)"
 	check_pmtu_value "1500" "${pmtu_a_R1}" "exceeding MTU (veth_A-R1)" || return 1
 	check_pmtu_value "1500" "${pmtu_a_R2}" "exceeding MTU (veth_A-R2)" || return 1
 }
 
+test_pmtu_ipv4_mp_exceptions() {
+	test_pmtu_ipvX_mp_exceptions 4
+}
+
+# Find a flow from host A to ${2} that goes out through ${3}: a source
+# address out of ${host4_a_net}, added to lo as needed, since the IPv4
+# multipath hash covers addresses only, or an IPv6 flow label, in hex as
+# both ip and ping take it, for a packet sent from ${host6_a_addr}
+mp_flow_via() {
+	family="${1}"
+	dst="${2}"
+	oif="${3}"
+
+	for i in $(seq 1 32); do
+		if [ ${family} -eq 4 ]; then
+			flow="${host4_a_net}.${i}"
+			${ns_a} ip addr add ${flow}/32 dev lo 2>/dev/null
+			out="$(${ns_a} ip route get ${dst} from ${flow} 2>/dev/null)"
+		else
+			flow="$(printf "0x%x" ${i})"
+			out="$(${ns_a} ip route get ${dst} from ${host6_a_addr} \
+				ipproto 58 flowlabel ${flow} 2>/dev/null)"
+		fi
+		case "${out}" in
+		*" dev ${oif} "*)
+			echo "${flow}"
+			return 0
+			;;
+		esac
+	done
+
+	return 1
+}
+
+test_pmtu_ipvX_mp_asym_exceptions() {
+	family=${1}
+
+	if [ ${family} -eq 4 ]; then
+		ping=ping
+		dst="${host4_b_addr}"
+	else
+		ping=${ping6}
+		dst="${host6_b_addr}"
+	fi
+
+	setup namespaces routing multipath${family} || return $ksft_skip
+
+	trace "${ns_a}"  veth_A-R1    "${ns_r1}" veth_R1-A \
+	      "${ns_r1}" veth_R1-B    "${ns_b}"  veth_B-R1 \
+	      "${ns_a}"  veth_A-R2    "${ns_r2}" veth_R2-A \
+	      "${ns_r2}" veth_R2-B    "${ns_b}"  veth_B-R2
+
+	if [ ${family} -eq 4 ]; then
+		# Routes back to the source addresses mp_flow_via() picks
+		run_cmd ${ns_r1} ip route add ${host4_a_net}.0/24 via ${prefix4}.${a_r1}.1
+		run_cmd ${ns_r2} ip route add ${host4_a_net}.0/24 via ${prefix4}.${a_r2}.1
+	else
+		${ns_a} ip route get ${dst} ipproto 58 flowlabel 0x1 >/dev/null 2>&1 || {
+			err "  ip route get flowlabel not supported"; return $ksft_skip; }
+	fi
+
+	# Set up initial MTU values: 1400 behind R1, 1350 to R2, 1300 behind R2
+	mtu "${ns_a}"  veth_A-R1 2000
+	mtu "${ns_r1}" veth_R1-A 2000
+	mtu "${ns_r1}" veth_R1-B 1400
+	mtu "${ns_b}"  veth_B-R1 1400
+
+	mtu "${ns_a}"  veth_A-R2 1350
+	mtu "${ns_r2}" veth_R2-A 1350
+	mtu "${ns_r2}" veth_R2-B 1300
+	mtu "${ns_b}"  veth_B-R2 1300
+
+	flow_r1="$(mp_flow_via ${family} ${dst} veth_A-R1)" || {
+		err "  no flow through veth_A-R1 found"; return 1; }
+	flow_r2="$(mp_flow_via ${family} ${dst} veth_A-R2)" || {
+		err "  no flow through veth_A-R2 found"; return 1; }
+	if [ ${family} -eq 4 ]; then
+		ping_r1="${ping} -I ${flow_r1}"
+		ping_r2="${ping} -I ${flow_r2}"
+	else
+		ping_r1="${ping} -I ${host6_a_addr} -F ${flow_r1}"
+		ping_r2="${ping} -I ${host6_a_addr} -F ${flow_r2}"
+	fi
+
+	# A Packet Too Big from R1 is cached on the path via R1, not on the
+	# path via R2, whose link can't carry 1400
+	run_cmd ${ns_a} ${ping_r1} -q -M want -i 0.1 -c 1 -s 1800 "${dst}"
+
+	pmtu_a_R1="$(route_get_dst_pmtu_from_exception "${ns_a}" "${dst}" oif veth_A-R1)"
+	pmtu_a_R2="$(route_get_dst_pmtu_from_exception "${ns_a}" "${dst}" oif veth_A-R2)"
+	check_pmtu_value "1400" "${pmtu_a_R1}" "exceeding MTU via R1 (veth_A-R1)" || return 1
+	check_pmtu_value "" "${pmtu_a_R2}" "exceeding MTU via R1 (veth_A-R2)" || return 1
+
+	# The lower MTU behind R2 lowers the PMTU of both paths
+	run_cmd ${ns_a} ${ping_r2} -q -M want -i 0.1 -c 1 -s 1280 "${dst}"
+
+	pmtu_a_R1="$(route_get_dst_pmtu_from_exception "${ns_a}" "${dst}" oif veth_A-R1)"
+	pmtu_a_R2="$(route_get_dst_pmtu_from_exception "${ns_a}" "${dst}" oif veth_A-R2)"
+	check_pmtu_value "1300" "${pmtu_a_R1}" "exceeding MTU via R2 (veth_A-R1)" || return 1
+	check_pmtu_value "1300" "${pmtu_a_R2}" "exceeding MTU via R2 (veth_A-R2)" || return 1
+}
+
+test_pmtu_ipv4_mp_asym_exceptions() {
+	test_pmtu_ipvX_mp_asym_exceptions 4
+}
+
+test_pmtu_ipv6_mp_asym_exceptions() {
+	test_pmtu_ipvX_mp_asym_exceptions 6
+}
+
+test_pmtu_ipv6_mp_exceptions() {
+	test_pmtu_ipvX_mp_exceptions 6
+}
+
 usage() {
 	echo
 	echo "$0 [OPTIONS] [TEST]..."
-- 
2.56.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH net-next v4 0/3] ipv4/ipv6: Cache pmtu on all paths of a multipath route
  2026-11-17 19:31 [PATCH net-next v4 0/3] ipv4/ipv6: Cache pmtu on all paths of a multipath route Vladimir Vdovin
                   ` (2 preceding siblings ...)
  2026-11-17 19:31 ` [PATCH net-next v4 3/3] selftests: net: pmtu: Add IPv6 and asymmetric multipath tests Vladimir Vdovin
@ 2026-11-17 19:37 ` netdev-bot+sinfo
  3 siblings, 0 replies; 5+ messages in thread
From: netdev-bot+sinfo @ 2026-11-17 19:37 UTC (permalink / raw)
  To: Vladimir Vdovin
  Cc: David Ahern, Ido Schimmel, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, Simon Horman, Shuah Khan, netdev,
	linux-kernel, linux-kselftest

Hi!

This is an automated message. This series looks like a fix, but its
commit messages seem to be missing some information:

 - How the issue was discovered, e.g. hit in production, hit during
   development, syzbot report, manual code inspection, LLM or static
   analysis tool scan.

Please do not repost the series just to address the above. Instead,
reply to this email with the missing information, so that reviewers
can take it into account.

*IMPORTANT*: If you do repost (for other reasons) - please include
the relevant info in the cover letter or commit messages.
-- 
The evaluation is done by an LLM so it may be wrong, if you think
that is the case please reply and explain.

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2026-11-17 19:37 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-17 19:31 [PATCH net-next v4 0/3] ipv4/ipv6: Cache pmtu on all paths of a multipath route Vladimir Vdovin
2026-11-17 19:31 ` [PATCH net-next v4 1/3] ipv4: Check a Fragmentation Needed against each path " Vladimir Vdovin
2026-11-17 19:31 ` [PATCH net-next v4 2/3] ipv6: Cache pmtu for all paths " Vladimir Vdovin
2026-11-17 19:31 ` [PATCH net-next v4 3/3] selftests: net: pmtu: Add IPv6 and asymmetric multipath tests Vladimir Vdovin
2026-11-17 19:37 ` [PATCH net-next v4 0/3] ipv4/ipv6: Cache pmtu on all paths of a multipath route netdev-bot+sinfo

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox