Netdev List
 help / color / mirror / Atom feed
From: Vladimir Vdovin <deliran@verdict.gg>
To: David Ahern <dsahern@kernel.org>,
	Ido Schimmel <idosch@nvidia.com>,
	"David S. Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@kernel.org>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
	Willem de Bruijn <willemb@google.com>,
	Simon Horman <horms@kernel.org>, Shuah Khan <shuah@kernel.org>
Cc: netdev@vger.kernel.org, linux-kselftest@vger.kernel.org,
	Vladimir Vdovin <deliran@verdict.gg>
Subject: [PATCH net-next v5 1/2] ipv6: Cache pmtu for all paths of a multipath route
Date: Wed,  2 Dec 2026 21:25:44 +0300	[thread overview]
Message-ID: <20261202182545.19656-2-deliran@verdict.gg> (raw)
In-Reply-To: <20261202182545.19656-1-deliran@verdict.gg>

When IPv6 receives a Packet Too Big, the route lookup can select a
different nexthop from the one the original packet used. The lookup can
be constrained by the incoming interface. For an unbound socket, the
lookup can hash the flow without its protocol or ports. If the exception
lands on the wrong path, the sender keeps using the old PMTU and
oversized packets continue to be dropped.

Update the PMTU on each path of the multipath route, as IPv4 does since
commit 7d3f3b4367f3 ("net: ipv4: Cache pmtu for all packet paths if
multipath enabled"). Compare the reported MTU with the MTU in use on
each path. If it is lower, update the existing exception in place to
preserve any gateway learned from a redirect, or create an exception if
none exists. One Packet Too Big can thus create up to one exception per
path.

For legacy multipath routes, skip siblings that are no longer in the
FIB. For routes that use nexthop objects, check for a blackhole as each
nexthop is visited. A concurrent replacement can install a blackhole
after the route lookup.

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 | 122 +++++++++++++++++++++++++++++++++--------------
 1 file changed, 87 insertions(+), 35 deletions(-)

diff --git a/net/ipv6/route.c b/net/ipv6/route.c
index df843178e5ec..cd3672287afe 100644
--- a/net/ipv6/route.c
+++ b/net/ipv6/route.c
@@ -2917,12 +2917,63 @@ 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;
+};
+
+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) {
+		/* Keep any gateway learned from a redirect. */
+		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;
+}
+
+/* A concurrent replace can install a blackhole after the route lookup.
+ * Check the nh_info supplied by the iterator before caching an exception.
+ */
+static int rt6_nexthop_update_pmtu(struct fib6_nh *nh, void *_arg)
+{
+	if (container_of(nh, struct nh_info, fib6_nh)->reject_nh)
+		return 0;
+
+	return rt6_nh_update_pmtu(nh, _arg);
+}
+
 static void __ip6_rt_update_pmtu(struct dst_entry *dst, const struct sock *sk,
 				 const struct ipv6hdr *iph, u32 mtu,
 				 bool confirm_neigh)
 {
-	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.
@@ -2945,6 +2996,7 @@ 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;
 
@@ -2953,47 +3005,47 @@ static void __ip6_rt_update_pmtu(struct dst_entry *dst, const struct sock *sk,
 		/* 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;
-
-		rcu_read_lock();
-		res.f6i = rcu_dereference(rt6->from);
-		if (!res.f6i)
-			goto out_unlock;
+	}
 
-		res.fib6_flags = res.f6i->fib6_flags;
-		res.fib6_type = res.f6i->fib6_type;
+	/* The PTB lookup can select a different path from the original flow. */
+	if (!daddr)
+		return;
 
-		if (res.f6i->nh) {
-			struct fib6_nh_match_arg arg = {
-				.dev = dst_dev_rcu(dst),
-				.gw = &rt6->rt6i_gateway,
-			};
+	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;
 
-			nexthop_for_each_fib6_nh(res.f6i->nh,
-						 fib6_nh_find_match, &arg);
+	arg.daddr = daddr;
+	arg.saddr = saddr;
+	arg.res.f6i = f6i;
+	arg.res.fib6_flags = f6i->fib6_flags;
+	arg.res.fib6_type = f6i->fib6_type;
 
-			/* 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;
+	if (f6i->nh) {
+		nexthop_for_each_fib6_nh(f6i->nh, rt6_nexthop_update_pmtu,
+					 &arg);
+		goto out;
+	}
 
-			res.nh = arg.match;
-		} else {
-			res.nh = res.f6i->fib6_nh;
-		}
+	rt6_nh_update_pmtu(f6i->fib6_nh, &arg);
 
-		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();
+	/* 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,
-- 
2.56.0


  reply	other threads:[~2026-12-02 18:26 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-02 18:25 [PATCH net-next v5 0/2] ipv6: Cache pmtu for all paths of a multipath route Vladimir Vdovin
2026-12-02 18:25 ` Vladimir Vdovin [this message]
2026-12-03 19:01   ` [PATCH net-next v5 1/2] " netdev-bot+sashiko
2026-12-02 18:25 ` [PATCH net-next v5 2/2] selftests: net: pmtu: Add IPv6 multipath tests Vladimir Vdovin
2026-12-03 19:01   ` netdev-bot+sashiko

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261202182545.19656-2-deliran@verdict.gg \
    --to=deliran@verdict.gg \
    --cc=davem@davemloft.net \
    --cc=dsahern@kernel.org \
    --cc=edumazet@kernel.org \
    --cc=horms@kernel.org \
    --cc=idosch@nvidia.com \
    --cc=kuba@kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=shuah@kernel.org \
    --cc=willemb@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox