Thread View: linux.kernel.netdev
2 messages
2 total messages
Started by Vladimir Vdovin
Tue, 17 Nov 2026 19:31
[PATCH net-next v4 2/3] ipv6: Cache pmtu for all paths of a multipath route
Author: Vladimir Vdovin
Date: Tue, 17 Nov 2026 19:31
Date: Tue, 17 Nov 2026 19:31
228 lines
17818 bytes
17818 bytes
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
Re: [PATCH net-next v4 2/3] ipv6: Cache pmtu for all paths of a multipath route
Author: netdev-bot+sashiko
Date: Fri, 20 Nov 2026 10:32
Date: Fri, 20 Nov 2026 10:32
146 lines
12770 bytes
12770 bytes
Thank you for your contribution! Sashiko AI review found 1 potential
issue(s) to consider.
Critical: 0 ยท High: 0 ยท Medium: 1 ยท Low: 0
If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).
- [Medium] In __ip6_rt_update_pmtu() (net/ipv6/route.c), the from_lookup
branch is meant to skip a blackhole nexthop.
--
ipv6: Cache pmtu for all paths of a multipath route
This commit makes ip6_update_pmtu() cache a Packet Too Big pmtu on every
path of a multipath route, the same way commit 7d3f3b4367f3 does for IPv4.
It walks the fib6_nh entries of a nexthop object or the siblings of the
fib6_info, and it skips siblings that are not in the tree and nexthops
replaced by a blackhole.
Link: https://lore.kernel.org/netdev/ad29493c-9e48-4a94-b327-e47af3a9d137@kernel.org/
> diff --git a/net/ipv6/route.c b/net/ipv6/route.c
> index 04098cf32eabe..a835abc698d25 100644
> --- a/net/ipv6/route.c
> +++ b/net/ipv6/route.c
[ ... ]
> @@ -2939,55 +2982,80 @@ static void __ip6_rt_update_pmtu(struct dst_entry *dst, const struct sock *sk,
[ ... ]
> - 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) {
[ ... ]
> + 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);
[Severity: Medium]
Can a concurrent nexthop replace put a usable exception on a blackhole
fib6_nh here?
nexthop_is_blackhole() and nexthop_for_each_fib6_nh() each read
f6i->nh->nh_info (or nh_grp) separately, using rcu_dereference_rtnl().
replace_nexthop_single() in net/ipv4/nexthop.c holds only RTNL when it
swaps the pointers:
rcu_assign_pointer(old->nh_info, newi);
rcu_assign_pointer(new->nh_info, oldi);
Say "ip nexthop replace id N blackhole" runs between the two reads. The
check then sees the old non-reject nh_info. The walk then passes the
blackhole nh_info's fib6_nh to rt6_nh_update_pmtu().
That fib6_nh has fib_nh_dev set to loopback_dev, so fib6_mtu() returns the
mtu6 of lo. Any Packet Too Big mtu from IPV6_MIN_MTU up to that value gets
through.
ip6_rt_cache_alloc() builds the dst from arg.res.fib6_flags and
arg.res.fib6_type. Those were copied from f6i (RTN_UNICAST), not
RTF_REJECT/RTN_BLACKHOLE. rt6_insert_exception() has no reject_nh check,
so a usable dst on lo goes into the exception bucket of the blackhole
fib6_nh.
For a single nexthop replace, nh_rt_cache_flush() returns early:
net/ipv4/nexthop.c:nh_rt_cache_flush() {
...
if (!replaced_nh->is_group)
return;
...
}
So the exception is not flushed.
Later lookups take the blackhole branch of __find_rr_leaf():
if (nexthop_is_blackhole(f6i->nh)) {
res->fib6_flags = RTF_REJECT;
res->fib6_type = RTN_BLACKHOLE;
res->f6i = f6i;
res->nh = nexthop_fib6_nh(f6i->nh);
return;
}
res->nh is the same fib6_nh. ip6_pol_route() then finds the exception
through rt6_find_cached_rt() and returns it instead of the discard dst.
Would this override the configured blackhole for that daddr until the
exception expires (ip6_rt_mtu_expires)?
Locally sent packets would go out lo instead of failing with -EINVAL.
With forwarding enabled, forwarded packets would loop through
ip6_forward() on lo until the hop limit runs out.
Before this patch, the nexthop path only used fib6_nh_find_match() with
the dev and gateway of the looked-up dst. That could never match the
loopback fib6_nh of a blackhole, which has no gateway.
The commit message says:
- siblings not in the tree and a nexthop replaced by a blackhole are
skipped.
That only holds when the replace does not happen between the two reads.
The later selftest patch in the series does not touch net/, so this race
is still there at the end of the series.
Could reject_nh be checked for each fib6_nh during the nexthop walk? One
way is a small wrapper callback that tests
container_of(nh, struct nh_info, fib6_nh)->reject_nh before calling
rt6_nh_update_pmtu(). Another is to dereference nh_info once and use that
snapshot for both the check and the walk.
> }
> + goto out;
> + }
[ ... ]
--
Sashiko AI review ยท https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261117193141.27004-1-deliran%40verdict.gg
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads