* (no subject)
@ 2026-11-22 22:26 David Ahern
2026-11-22 22:26 ` [RFC net-next 0/6] ipv6: validate dsts against the netns route generation David Ahern
` (6 more replies)
0 siblings, 7 replies; 9+ messages in thread
From: David Ahern @ 2026-11-22 22:26 UTC (permalink / raw)
To: netdev; +Cc: ralf, David Ahern
^ permalink raw reply [flat|nested] 9+ messages in thread
* [RFC net-next 0/6] ipv6: validate dsts against the netns route generation
2026-11-22 22:26 David Ahern
@ 2026-11-22 22:26 ` David Ahern
2026-11-22 22:30 ` David Ahern
2026-11-22 22:26 ` [RFC net-next 1/6] " David Ahern
` (5 subsequent siblings)
6 siblings, 1 reply; 9+ messages in thread
From: David Ahern @ 2026-11-22 22:26 UTC (permalink / raw)
To: netdev
Cc: ralf, David Ahern, David Ahern, Ido Schimmel, David S . Miller,
Eric Dumazet, Jakub Kicinski, Paolo Abeni, Simon Horman
From: David Ahern <dahern@nvidia.com>
An IPv6 dst has never carried the fib6 serial number it was created
under. rt6_get_cookie() reads fn->fn_sernum through rt->from when a
socket, dst_cache or xfrm bundle stores its cookie, so a FIB change
that lands between the route lookup and the cookie capture is folded
into the cookie and a stale dst looks valid. The only dsts stamped at
creation are pcpu dsts of nexthop-object routes, which store the netns
genid in rt->sernum.
Looking at this I found that rt_genid_ipv6() and the fib6 serial
number are already the same counter: net->ipv6.fib6_sernum, which
fib6_new_sernum() advances on every FIB change. fn_sernum is a per-node
copy of it. So this series moves dst validation onto that counter, the
way IPv4 uses rt_genid, instead of adding another one:
1. Stamp every dst with the counter in ip6_dst_alloc() and validate by
comparison in ip6_dst_check(). Long-lived dsts (pcpu dsts of routes
with an embedded fib6_nh, and exception dsts) are re-stamped when a
lookup finds them again, otherwise they would stay invalid.
2. ip6_link_failure() forced a new lookup by writing -1 to fn_sernum.
That no longer invalidates anything, so clear the failing dst's
sernum instead.
3-4. Nexthop objects: factor out nh_has_f6i(), then bump the counter
when a nexthop used through a group is replaced, and when a member
is removed from a group.
5. A new PMTU or redirect exception used to bump the counter, which
with (1) would invalidate every dst in the namespace. Do what IPv4
does in update_or_create_fnhe() and invalidate only the pcpu dsts
of the affected fib6_nh. Route dumps still need to see that an
exception was added to the root node, so add a per-table sequence
for that rather than inventing fn_sernum values the counter could
later issue again.
6. Since nothing validates against fn_sernum any more,
rt_genid_bump_ipv6() no longer needs to walk every node of every
table. Make it an atomic increment like rt_genid_bump_ipv4(), and
drop the __fib6_flush_trees pointer. fn_sernum remains only for
route dump consistency, so nexthop, address and rule changes no
longer restart in-progress dumps.
David Ahern (6):
ipv6: validate dsts against the netns route generation
ipv6: invalidate the failing dst in ip6_link_failure()
nexthop: factor out nh_has_f6i()
nexthop: bump the IPv6 route generation on group changes
ipv6: scope exception invalidation to the affected nexthop
ipv6: make rt_genid_bump_ipv6() a plain counter increment
include/net/ip6_fib.h | 45 +++-------------
include/net/net_namespace.h | 26 ++++++---
net/ipv4/nexthop.c | 42 ++++++++++++---
net/ipv6/addrconf_core.c | 7 ---
net/ipv6/ip6_fib.c | 76 +++++++++++---------------
net/ipv6/route.c | 104 ++++++++++++++++++++++++------------
6 files changed, 162 insertions(+), 138 deletions(-)
--
2.43.0
^ permalink raw reply [flat|nested] 9+ messages in thread
* [RFC net-next 1/6] ipv6: validate dsts against the netns route generation
2026-11-22 22:26 David Ahern
2026-11-22 22:26 ` [RFC net-next 0/6] ipv6: validate dsts against the netns route generation David Ahern
@ 2026-11-22 22:26 ` David Ahern
2026-11-22 22:27 ` [RFC net-next 2/6] ipv6: invalidate the failing dst in ip6_link_failure() David Ahern
` (4 subsequent siblings)
6 siblings, 0 replies; 9+ messages in thread
From: David Ahern @ 2026-11-22 22:26 UTC (permalink / raw)
To: netdev
Cc: ralf, David Ahern, David Ahern, Ido Schimmel, David S . Miller,
Eric Dumazet, Jakub Kicinski, Paolo Abeni, Simon Horman,
Claude Sonnet 5 . 5
From: David Ahern <dahern@nvidia.com>
An rt6_info never carried the fib6 serial number it was created
under. rt6_get_cookie() read fn->fn_sernum through rt->from at the time a
socket, dst_cache or xfrm bundle stored its cookie, so a change that
landed between route lookup and cookie capture was folded into the
cookie and a stale dst looked valid. Only nexthop-object pcpu routes
were stamped at creation, with the same counter.
net->ipv6.fib6_sernum is already the counter that rt_genid_ipv6()
reads and that every FIB change bumps. Stamp every dst with it in
ip6_dst_alloc() and validate with a plain comparison in
ip6_dst_check(); the remaining checks are that the fib6_info is still
in the tree and not expired. rt6_get_cookie() now returns rt->sernum
and fib6_get_cookie_safe() goes away. fn_sernum stays for route dump
consistency.
Because validity now lives in the dst, long-lived dsts must be
re-stamped when a lookup finds them again, or they would stay invalid
forever:
- pcpu dsts of routes with an embedded fib6_nh are re-stamped in
rt6_get_pcpu_route(); nexthop-object pcpu dsts are still dropped
and rebuilt.
- exception dsts are re-stamped by rt6_find_cached_rt().
The smp_wmb() in __fib6_update_sernum_upto_root() paired with the
smp_rmb() in fib6_get_cookie_safe(), so that a lockless reader that saw
a new fn_sernum also saw the route inserted before it. That reader is
gone. The remaining fn_sernum readers, the route dumps, take tb6_lock
after reading it and the writers hold it, so drop the barrier.
ip6_link_failure() still writes fn_sernum, which no longer
invalidates anything; that is addressed in the next patch.
Signed-off-by: David Ahern <dahern@nvidia.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
---
include/net/ip6_fib.h | 42 +++------------------------
net/ipv6/ip6_fib.c | 2 --
net/ipv6/route.c | 66 +++++++++++++++++++++++++------------------
3 files changed, 43 insertions(+), 67 deletions(-)
diff --git a/include/net/ip6_fib.h b/include/net/ip6_fib.h
index 232289b439c3..ecce7ab007a5 100644
--- a/include/net/ip6_fib.h
+++ b/include/net/ip6_fib.h
@@ -273,46 +273,12 @@ static inline bool fib6_check_expired(const struct fib6_info *f6i)
return false;
}
-/* Function to safely get fn->fn_sernum for passed in rt
- * and store result in passed in cookie.
- * Return true if we can get cookie safely
- * Return false if not
- */
-static inline bool fib6_get_cookie_safe(const struct fib6_info *f6i,
- u32 *cookie)
-{
- struct fib6_node *fn;
- bool status = false;
-
- fn = rcu_dereference(f6i->fib6_node);
-
- if (fn) {
- *cookie = READ_ONCE(fn->fn_sernum);
- /* pairs with smp_wmb() in __fib6_update_sernum_upto_root() */
- smp_rmb();
- status = true;
- }
-
- return status;
-}
-
static inline u32 rt6_get_cookie(const struct rt6_info *rt)
{
- struct fib6_info *from;
- u32 cookie = 0;
-
- if (rt->sernum)
- return rt->sernum;
-
- rcu_read_lock();
-
- from = rcu_dereference(rt->from);
- if (from)
- fib6_get_cookie_safe(from, &cookie);
-
- rcu_read_unlock();
-
- return cookie;
+ /* sernum is the netns route generation the dst was created or last
+ * revalidated under; ip6_dst_check() compares it to the current one.
+ */
+ return READ_ONCE(rt->sernum);
}
static inline void ip6_rt_put(struct rt6_info *rt)
diff --git a/net/ipv6/ip6_fib.c b/net/ipv6/ip6_fib.c
index e1d49897d6ab..d465ac6ffbc6 100644
--- a/net/ipv6/ip6_fib.c
+++ b/net/ipv6/ip6_fib.c
@@ -1432,8 +1432,6 @@ static void __fib6_update_sernum_upto_root(struct fib6_info *rt,
struct fib6_node *fn = rcu_dereference_protected(rt->fib6_node,
lockdep_is_held(&rt->fib6_table->tb6_lock));
- /* paired with smp_rmb() in fib6_get_cookie_safe() */
- smp_wmb();
while (fn) {
WRITE_ONCE(fn->fn_sernum, sernum);
fn = rcu_dereference_protected(fn->parent,
diff --git a/net/ipv6/route.c b/net/ipv6/route.c
index 4a4c5ace63c5..1f7b2cdc1d9f 100644
--- a/net/ipv6/route.c
+++ b/net/ipv6/route.c
@@ -367,6 +367,7 @@ struct rt6_info *ip6_dst_alloc(struct net *net, struct net_device *dev,
if (rt) {
rt6_info_init(rt);
+ rt->sernum = rt_genid_ipv6(net);
atomic_inc(&net->ipv6.rt6_stats->fib_rt_alloc);
}
@@ -1458,15 +1459,24 @@ static struct rt6_info *ip6_rt_pcpu_alloc(const struct fib6_result *res)
ip6_rt_copy_init(pcpu_rt, res);
pcpu_rt->rt6i_flags |= RTF_PCPU;
- if (f6i->nh)
- pcpu_rt->sernum = rt_genid_ipv6(dev_net(dev));
-
return pcpu_rt;
}
static bool rt6_is_valid(const struct rt6_info *rt6)
{
- return rt6->sernum == rt_genid_ipv6(dev_net(rt6->dst.dev));
+ return READ_ONCE(rt6->sernum) == rt_genid_ipv6(dev_net(rt6->dst.dev));
+}
+
+/* @rt was just found by a lookup against the current FIB, so it is as
+ * valid as a freshly allocated dst. Call with rcu_read_lock() held.
+ */
+static void rt6_refresh_sernum(struct rt6_info *rt,
+ const struct fib6_result *res)
+{
+ int genid = rt_genid_ipv6(dev_net(ip6_rt_get_dev_rcu(res)));
+
+ if (READ_ONCE(rt->sernum) != genid)
+ WRITE_ONCE(rt->sernum, genid);
}
/* It should be called with rcu_read_lock() acquired */
@@ -1476,7 +1486,14 @@ static struct rt6_info *rt6_get_pcpu_route(const struct fib6_result *res)
pcpu_rt = this_cpu_read(*res->nh->rt6i_pcpu);
- if (pcpu_rt && pcpu_rt->sernum && !rt6_is_valid(pcpu_rt)) {
+ /* Routes with an embedded fib6_nh keep their pcpu dsts across FIB
+ * changes; nexthop objects can change under them, so those are
+ * dropped and rebuilt.
+ */
+ if (pcpu_rt && !rt6_is_valid(pcpu_rt) && !res->f6i->nh)
+ rt6_refresh_sernum(pcpu_rt, res);
+
+ if (pcpu_rt && !rt6_is_valid(pcpu_rt)) {
struct rt6_info *prev, **p;
p = this_cpu_ptr(res->nh->rt6i_pcpu);
@@ -1878,8 +1895,10 @@ static struct rt6_info *rt6_find_cached_rt(const struct fib6_result *res,
bucket = fib6_nh_get_excptn_bucket(res->nh, NULL);
rt6_ex = __rt6_find_exception_rcu(&bucket, daddr, src_key);
- if (rt6_ex && !rt6_check_expired(rt6_ex->rt6i))
+ if (rt6_ex && !rt6_check_expired(rt6_ex->rt6i)) {
ret = rt6_ex->rt6i;
+ rt6_refresh_sernum(ret, res);
+ }
#ifdef CONFIG_IPV6_SUBTREES
/* Use fib6_src as src_key and redo lookup */
@@ -2767,27 +2786,18 @@ struct dst_entry *ip6_blackhole_route(struct net *net, struct dst_entry *dst_ori
* Destination cache support functions
*/
-static bool fib6_check(struct fib6_info *f6i, u32 cookie)
+static bool fib6_check(struct fib6_info *f6i)
{
- u32 rt_cookie = 0;
-
- if (!fib6_get_cookie_safe(f6i, &rt_cookie) || rt_cookie != cookie)
- return false;
-
- if (fib6_check_expired(f6i))
+ if (!rcu_access_pointer(f6i->fib6_node))
return false;
- return true;
+ return !fib6_check_expired(f6i);
}
static struct dst_entry *rt6_check(struct rt6_info *rt,
- struct fib6_info *from,
- u32 cookie)
+ struct fib6_info *from)
{
- u32 rt_cookie = 0;
-
- if (!from || !fib6_get_cookie_safe(from, &rt_cookie) ||
- rt_cookie != cookie)
+ if (!from || !rcu_access_pointer(from->fib6_node))
return NULL;
if (rt6_check_expired(rt))
@@ -2797,12 +2807,11 @@ static struct dst_entry *rt6_check(struct rt6_info *rt,
}
static struct dst_entry *rt6_dst_from_check(struct rt6_info *rt,
- struct fib6_info *from,
- u32 cookie)
+ struct fib6_info *from)
{
if (!__rt6_check_expired(rt) &&
READ_ONCE(rt->dst.obsolete) == DST_OBSOLETE_FORCE_CHK &&
- fib6_check(from, cookie))
+ fib6_check(from))
return &rt->dst;
return NULL;
}
@@ -2816,8 +2825,11 @@ INDIRECT_CALLABLE_SCOPE struct dst_entry *ip6_dst_check(struct dst_entry *dst,
rt = dst_rt6_info(dst);
- if (rt->sernum)
- return rt6_is_valid(rt) ? dst : NULL;
+ /* Any FIB change bumps the netns generation, which invalidates
+ * every dst created under an older one.
+ */
+ if (!rt6_is_valid(rt))
+ return NULL;
rcu_read_lock();
@@ -2830,9 +2842,9 @@ INDIRECT_CALLABLE_SCOPE struct dst_entry *ip6_dst_check(struct dst_entry *dst,
if (from && (rt->rt6i_flags & RTF_PCPU ||
unlikely(rt->dst.rt_uncached_list)))
- dst_ret = rt6_dst_from_check(rt, from, cookie);
+ dst_ret = rt6_dst_from_check(rt, from);
else
- dst_ret = rt6_check(rt, from, cookie);
+ dst_ret = rt6_check(rt, from);
rcu_read_unlock();
--
2.43.0
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [RFC net-next 2/6] ipv6: invalidate the failing dst in ip6_link_failure()
2026-11-22 22:26 David Ahern
2026-11-22 22:26 ` [RFC net-next 0/6] ipv6: validate dsts against the netns route generation David Ahern
2026-11-22 22:26 ` [RFC net-next 1/6] " David Ahern
@ 2026-11-22 22:27 ` David Ahern
2026-11-22 22:27 ` [RFC net-next 3/6] nexthop: factor out nh_has_f6i() David Ahern
` (3 subsequent siblings)
6 siblings, 0 replies; 9+ messages in thread
From: David Ahern @ 2026-11-22 22:27 UTC (permalink / raw)
To: netdev
Cc: ralf, David Ahern, David Ahern, Ido Schimmel, David S . Miller,
Eric Dumazet, Jakub Kicinski, Paolo Abeni, Simon Horman,
Claude Sonnet 5 . 5
From: David Ahern <dahern@nvidia.com>
When a default route's neighbour fails, ip6_link_failure() wrote -1
to the fn_sernum of the route's node so that users of dsts under that
node would look the route up again and let router selection pick
another default router.
dsts are now validated against the netns route generation, so that
write no longer invalidates anything. Clear the sernum of the failing
dst instead; 0 never matches the generation, so its users do the
lookup again. Only that dst is invalidated, which for a pcpu dst is
one CPU's copy, rather than every dst under the node. Bumping the
netns generation here would be much costlier, since a failing router
can trigger this for every packet sent through it.
Signed-off-by: David Ahern <dahern@nvidia.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
---
net/ipv6/route.c | 11 +++++------
1 file changed, 5 insertions(+), 6 deletions(-)
diff --git a/net/ipv6/route.c b/net/ipv6/route.c
index 1f7b2cdc1d9f..d355652a0520 100644
--- a/net/ipv6/route.c
+++ b/net/ipv6/route.c
@@ -2885,14 +2885,13 @@ static void ip6_link_failure(struct sk_buff *skb)
rt6_remove_exception_rt(rt);
} else {
struct fib6_info *from;
- struct fib6_node *fn;
+ /* Force sockets using this dst to look the route up
+ * again; 0 never matches the netns generation.
+ */
from = rcu_dereference(rt->from);
- if (from) {
- fn = rcu_dereference(from->fib6_node);
- if (fn && (rt->rt6i_flags & RTF_DEFAULT))
- WRITE_ONCE(fn->fn_sernum, -1);
- }
+ if (from && (rt->rt6i_flags & RTF_DEFAULT))
+ WRITE_ONCE(rt->sernum, 0);
}
rcu_read_unlock();
}
--
2.43.0
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [RFC net-next 3/6] nexthop: factor out nh_has_f6i()
2026-11-22 22:26 David Ahern
` (2 preceding siblings ...)
2026-11-22 22:27 ` [RFC net-next 2/6] ipv6: invalidate the failing dst in ip6_link_failure() David Ahern
@ 2026-11-22 22:27 ` David Ahern
2026-11-22 22:27 ` [RFC net-next 4/6] nexthop: bump the IPv6 route generation on group changes David Ahern
` (2 subsequent siblings)
6 siblings, 0 replies; 9+ messages in thread
From: David Ahern @ 2026-11-22 22:27 UTC (permalink / raw)
To: netdev
Cc: ralf, David Ahern, David Ahern, Ido Schimmel, David S . Miller,
Eric Dumazet, Jakub Kicinski, Paolo Abeni, Simon Horman,
Claude Sonnet 5 . 5
From: David Ahern <dahern@nvidia.com>
nh_rt_cache_flush() open codes a locked check of whether any IPv6
routes use a nexthop. Move it into a helper, placed ahead of
remove_nexthop_from_groups(), so the next patch can use it there as
well.
No functional change.
Signed-off-by: David Ahern <dahern@nvidia.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
---
net/ipv4/nexthop.c | 17 ++++++++++++-----
1 file changed, 12 insertions(+), 5 deletions(-)
diff --git a/net/ipv4/nexthop.c b/net/ipv4/nexthop.c
index 42e55b5a755e..53431fe7d328 100644
--- a/net/ipv4/nexthop.c
+++ b/net/ipv4/nexthop.c
@@ -2109,6 +2109,17 @@ remove_nh_grp_entry(struct net *net, struct nh_grp_entry *nhge,
return false;
}
+static bool nh_has_f6i(struct nexthop *nh)
+{
+ bool have_f6i;
+
+ spin_lock_bh(&nh->lock);
+ have_f6i = !list_empty(&nh->f6i_list);
+ spin_unlock_bh(&nh->lock);
+
+ return have_f6i;
+}
+
static bool __must_check
remove_nexthop_from_groups(struct net *net, struct nexthop *nh,
struct nl_info *nlinfo)
@@ -2248,16 +2259,12 @@ static void nh_rt_cache_flush(struct net *net, struct nexthop *nh,
struct nexthop *replaced_nh)
{
struct nh_group *nhg;
- bool have_f6i;
int i;
if (!list_empty(&nh->fi_list))
rt_cache_flush(net);
- spin_lock_bh(&nh->lock);
- have_f6i = !list_empty(&nh->f6i_list);
- spin_unlock_bh(&nh->lock);
- if (have_f6i)
+ if (nh_has_f6i(nh))
rt_genid_bump_ipv6(net);
/* if an IPv6 group was replaced, we have to release all old
--
2.43.0
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [RFC net-next 4/6] nexthop: bump the IPv6 route generation on group changes
2026-11-22 22:26 David Ahern
` (3 preceding siblings ...)
2026-11-22 22:27 ` [RFC net-next 3/6] nexthop: factor out nh_has_f6i() David Ahern
@ 2026-11-22 22:27 ` David Ahern
2026-11-22 22:27 ` [RFC net-next 5/6] ipv6: scope exception invalidation to the affected nexthop David Ahern
2026-11-22 22:27 ` [RFC net-next 6/6] ipv6: make rt_genid_bump_ipv6() a plain counter increment David Ahern
6 siblings, 0 replies; 9+ messages in thread
From: David Ahern @ 2026-11-22 22:27 UTC (permalink / raw)
To: netdev
Cc: ralf, David Ahern, David Ahern, Ido Schimmel, David S . Miller,
Eric Dumazet, Jakub Kicinski, Paolo Abeni, Simon Horman,
Claude Sonnet 5 . 5
From: David Ahern <dahern@nvidia.com>
IPv6 dsts are invalidated by bumping the netns route generation, but
two nexthop object changes did not do so:
- Replacing a nexthop that is a member of a group only bumped if the
member itself had IPv6 routes, not when routes used a group
containing it.
- Removing a member from a group republishes the group array without
any bump, so dsts built from the old group stayed valid.
Bump in both cases when IPv6 routes use the nexthop, directly or
through a group.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Signed-off-by: David Ahern <dahern@nvidia.com>
---
net/ipv4/nexthop.c | 27 +++++++++++++++++++++++++--
1 file changed, 25 insertions(+), 2 deletions(-)
diff --git a/net/ipv4/nexthop.c b/net/ipv4/nexthop.c
index 53431fe7d328..7cf496589f4f 100644
--- a/net/ipv4/nexthop.c
+++ b/net/ipv4/nexthop.c
@@ -2120,6 +2120,21 @@ static bool nh_has_f6i(struct nexthop *nh)
return have_f6i;
}
+/* true if IPv6 routes use @nh directly or through a group containing it */
+static bool nh_used_by_f6i(struct nexthop *nh)
+{
+ struct nh_grp_entry *nhge;
+
+ if (nh_has_f6i(nh))
+ return true;
+
+ list_for_each_entry(nhge, &nh->grp_list, nh_list)
+ if (nh_has_f6i(nhge->nh_parent))
+ return true;
+
+ return false;
+}
+
static bool __must_check
remove_nexthop_from_groups(struct net *net, struct nexthop *nh,
struct nl_info *nlinfo)
@@ -2127,6 +2142,7 @@ remove_nexthop_from_groups(struct net *net, struct nexthop *nh,
struct nh_grp_entry *nhge, *tmp;
LIST_HEAD(deferred_free);
bool need_flush = false;
+ bool have_f6i = false;
/* If there is nothing to do, let's avoid the costly call to
* synchronize_net()
@@ -2134,13 +2150,19 @@ remove_nexthop_from_groups(struct net *net, struct nexthop *nh,
if (list_empty(&nh->grp_list))
return false;
- list_for_each_entry_safe(nhge, tmp, &nh->grp_list, nh_list)
+ list_for_each_entry_safe(nhge, tmp, &nh->grp_list, nh_list) {
+ have_f6i |= nh_has_f6i(nhge->nh_parent);
need_flush |= remove_nh_grp_entry(net, nhge, nlinfo,
&deferred_free);
+ }
/* make sure all see the newly published array before releasing rtnl */
synchronize_net();
+ /* a group lost a member: dsts built from the old group are stale */
+ if (have_f6i)
+ rt_genid_bump_ipv6(net);
+
/* Now safe to free percpu stats — all RCU readers have finished */
list_for_each_entry_safe(nhge, tmp, &deferred_free, nh_list) {
list_del(&nhge->nh_list);
@@ -2264,7 +2286,8 @@ static void nh_rt_cache_flush(struct net *net, struct nexthop *nh,
if (!list_empty(&nh->fi_list))
rt_cache_flush(net);
- if (nh_has_f6i(nh))
+ /* dsts are validated against the netns route generation */
+ if (nh_used_by_f6i(nh))
rt_genid_bump_ipv6(net);
/* if an IPv6 group was replaced, we have to release all old
--
2.43.0
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [RFC net-next 5/6] ipv6: scope exception invalidation to the affected nexthop
2026-11-22 22:26 David Ahern
` (4 preceding siblings ...)
2026-11-22 22:27 ` [RFC net-next 4/6] nexthop: bump the IPv6 route generation on group changes David Ahern
@ 2026-11-22 22:27 ` David Ahern
2026-11-22 22:27 ` [RFC net-next 6/6] ipv6: make rt_genid_bump_ipv6() a plain counter increment David Ahern
6 siblings, 0 replies; 9+ messages in thread
From: David Ahern @ 2026-11-22 22:27 UTC (permalink / raw)
To: netdev
Cc: ralf, David Ahern, David Ahern, Ido Schimmel, David S . Miller,
Eric Dumazet, Jakub Kicinski, Paolo Abeni, Simon Horman,
Claude Sonnet 5 . 5
From: David Ahern <dahern@nvidia.com>
rt6_insert_exception() bumped the netns route generation, which with
generation-based dst validation invalidates every dst in the
namespace each time a PMTU or redirect exception is created. A burst
of packet-too-big messages would make all sockets and dst_caches look
their routes up again.
IPv4 limits this to the nexthop: update_or_create_fnhe() marks only
that nexthop's cached dsts stale. Do the same here by clearing the
sernum of the fib6_nh's pcpu dsts, so their users look the route up
once and find the exception.
Route dumps notice a changed tree through the root node's fn_sernum,
and the exception dump relies on that changing when an exception is
inserted on the root. A fresh fn_sernum can only come from the netns
counter, which must not be bumped here, and a locally made-up value
could later be issued by the counter to the same node and go
unnoticed. Add a per-table tb6_excp_seq, bumped for exceptions on the
root node, and have fib6_dump_table() restart when either it or the
root's fn_sernum has changed.
Signed-off-by: David Ahern <dahern@nvidia.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
---
include/net/ip6_fib.h | 3 +++
net/ipv6/ip6_fib.c | 25 ++++++++++++++++++++++++-
net/ipv6/route.c | 27 +++++++++++++++++++++++++--
3 files changed, 52 insertions(+), 3 deletions(-)
diff --git a/include/net/ip6_fib.h b/include/net/ip6_fib.h
index ecce7ab007a5..92fed30a7418 100644
--- a/include/net/ip6_fib.h
+++ b/include/net/ip6_fib.h
@@ -329,6 +329,7 @@ struct fib6_walker {
unsigned int skip;
unsigned int count;
unsigned int skip_in_node;
+ unsigned int excp_seq; /* tb6_excp_seq seen by a partial dump */
int (*func)(struct fib6_walker *);
void *args;
};
@@ -362,6 +363,7 @@ struct fib6_table {
struct inet_peer_base tb6_peers;
unsigned int flags;
unsigned int fib_seq; /* writes protected by rtnl_mutex */
+ unsigned int tb6_excp_seq; /* writes under tb6_lock */
struct hlist_head tb6_gc_hlist; /* GC candidates */
#define RT6_TABLE_HAS_DFLT_ROUTER BIT(0)
};
@@ -583,6 +585,7 @@ int fib6_tables_dump(struct net *net, struct notifier_block *nb,
struct netlink_ext_ack *extack);
void fib6_update_sernum(struct net *net, struct fib6_info *rt);
+void fib6_update_excp_seq(struct fib6_info *rt);
#if IS_ENABLED(CONFIG_IPV6)
void fib6_update_sernum_upto_root(struct net *net, struct fib6_info *rt);
#else
diff --git a/net/ipv6/ip6_fib.c b/net/ipv6/ip6_fib.c
index d465ac6ffbc6..266370e15774 100644
--- a/net/ipv6/ip6_fib.c
+++ b/net/ipv6/ip6_fib.c
@@ -148,6 +148,25 @@ void fib6_update_sernum(struct net *net, struct fib6_info *f6i)
WRITE_ONCE(fn->fn_sernum, fib6_new_sernum(net));
}
+/* Tell route dumps that an exception was added under @f6i without
+ * invalidating cached dsts: those follow the netns generation, which this
+ * leaves alone. A dump notices a changed tree through the root node, so
+ * only an exception on the root needs to be visible. Fresh fn_sernum values
+ * can only come from the netns counter, so use a table sequence rather than
+ * a made-up fn_sernum that the counter could later issue again.
+ * Caller holds tb6_lock.
+ */
+void fib6_update_excp_seq(struct fib6_info *f6i)
+{
+ struct fib6_table *table = f6i->fib6_table;
+ struct fib6_node *fn;
+
+ fn = rcu_dereference_protected(f6i->fib6_node,
+ lockdep_is_held(&table->tb6_lock));
+ if (fn == &table->tb6_root)
+ WRITE_ONCE(table->tb6_excp_seq, table->tb6_excp_seq + 1);
+}
+
/*
* Auxiliary address test functions for the radix tree.
*
@@ -637,12 +656,16 @@ static int fib6_dump_table(struct fib6_table *table, struct sk_buff *skb,
if (res > 0) {
cb->args[4] = 1;
cb->args[5] = READ_ONCE(w->root->fn_sernum);
+ w->excp_seq = READ_ONCE(table->tb6_excp_seq);
}
} else {
int sernum = READ_ONCE(w->root->fn_sernum);
- if (cb->args[5] != sernum) {
+ unsigned int excp_seq = READ_ONCE(table->tb6_excp_seq);
+
+ if (cb->args[5] != sernum || w->excp_seq != excp_seq) {
/* Begin at the root if the tree changed */
cb->args[5] = sernum;
+ w->excp_seq = excp_seq;
w->state = FWS_INIT;
w->node = w->root;
w->skip = w->count;
diff --git a/net/ipv6/route.c b/net/ipv6/route.c
index d355652a0520..ee7a62dc16c4 100644
--- a/net/ipv6/route.c
+++ b/net/ipv6/route.c
@@ -1732,6 +1732,28 @@ struct rt6_exception_bucket *fib6_nh_get_excptn_bucket(const struct fib6_nh *nh,
return bucket;
}
+/* A new exception may apply to dsts already cached on @nh. Make them fail
+ * ip6_dst_check() once so their users look the route up again and find it;
+ * dsts of other routes are left alone.
+ */
+static void fib6_nh_invalidate_pcpu(const struct fib6_nh *nh)
+{
+ int cpu;
+
+ if (!nh->rt6i_pcpu)
+ return;
+
+ rcu_read_lock();
+ for_each_possible_cpu(cpu) {
+ struct rt6_info *pcpu_rt;
+
+ pcpu_rt = READ_ONCE(*per_cpu_ptr(nh->rt6i_pcpu, cpu));
+ if (pcpu_rt)
+ WRITE_ONCE(pcpu_rt->sernum, 0);
+ }
+ rcu_read_unlock();
+}
+
static int rt6_insert_exception(struct rt6_info *nrt,
const struct fib6_result *res)
{
@@ -1806,10 +1828,11 @@ static int rt6_insert_exception(struct rt6_info *nrt,
out:
spin_unlock_bh(&rt6_exception_lock);
- /* Update fn->fn_sernum to invalidate all cached dst */
if (!err) {
+ fib6_nh_invalidate_pcpu(nh);
+
spin_lock_bh(&f6i->fib6_table->tb6_lock);
- fib6_update_sernum(net, f6i);
+ fib6_update_excp_seq(f6i);
fib6_add_gc_list(f6i);
spin_unlock_bh(&f6i->fib6_table->tb6_lock);
fib6_force_start_gc(net);
--
2.43.0
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [RFC net-next 6/6] ipv6: make rt_genid_bump_ipv6() a plain counter increment
2026-11-22 22:26 David Ahern
` (5 preceding siblings ...)
2026-11-22 22:27 ` [RFC net-next 5/6] ipv6: scope exception invalidation to the affected nexthop David Ahern
@ 2026-11-22 22:27 ` David Ahern
6 siblings, 0 replies; 9+ messages in thread
From: David Ahern @ 2026-11-22 22:27 UTC (permalink / raw)
To: netdev
Cc: ralf, David Ahern, David Ahern, Ido Schimmel, David S . Miller,
Eric Dumazet, Jakub Kicinski, Paolo Abeni, Simon Horman,
Claude Sonnet 5 . 5
From: David Ahern <dahern@nvidia.com>
rt_genid_bump_ipv6() called fib6_flush_trees() through a function
pointer. That walked every node of every table to write a new
fn_sernum, so that cookies derived from fn_sernum would mismatch.
Cached dsts are now validated against net->ipv6.fib6_sernum itself,
so the walk no longer invalidates anything. Do what
rt_genid_bump_ipv4() does and increment the counter, keeping
fib6_new_sernum()'s wrap to 1 so the value is never 0.
This makes nexthop, address and FIB rule changes cheap, and stops
them from touching fn_sernum, which route dumps use to detect that a
tree changed: a dump is no longer restarted by events that do not
change the tree.
With the walk gone, drop the __fib6_flush_trees pointer and its
export, fib6_new_sernum() in favour of the new helper, and the sernum
handling in fib6_cleaner that only the walk used.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Signed-off-by: David Ahern <dahern@nvidia.com>
---
include/net/net_namespace.h | 26 ++++++++++++++-----
net/ipv6/addrconf_core.c | 7 -----
net/ipv6/ip6_fib.c | 51 ++++++-------------------------------
3 files changed, 27 insertions(+), 57 deletions(-)
diff --git a/include/net/net_namespace.h b/include/net/net_namespace.h
index 4a4d72080acd..f39baf51bcc5 100644
--- a/include/net/net_namespace.h
+++ b/include/net/net_namespace.h
@@ -556,18 +556,30 @@ static inline int rt_genid_ipv6(const struct net *net)
{
return atomic_read(&net->ipv6.fib6_sernum);
}
-#endif
-static inline void rt_genid_bump_ipv4(struct net *net)
+/* Invalidate every cached IPv6 dst in @net. Returns the new generation,
+ * which is never 0.
+ */
+static inline int rt_genid_bump_ipv6(struct net *net)
{
- atomic_inc(&net->ipv4.rt_genid);
+ int new, old = atomic_read(&net->ipv6.fib6_sernum);
+
+ do {
+ new = old < INT_MAX ? old + 1 : 1;
+ } while (!atomic_try_cmpxchg(&net->ipv6.fib6_sernum, &old, new));
+
+ return new;
}
+#else
+static inline int rt_genid_bump_ipv6(struct net *net)
+{
+ return 0;
+}
+#endif
-extern void (*__fib6_flush_trees)(struct net *net);
-static inline void rt_genid_bump_ipv6(struct net *net)
+static inline void rt_genid_bump_ipv4(struct net *net)
{
- if (__fib6_flush_trees)
- __fib6_flush_trees(net);
+ atomic_inc(&net->ipv4.rt_genid);
}
#if IS_ENABLED(CONFIG_IEEE802154_6LOWPAN)
diff --git a/net/ipv6/addrconf_core.c b/net/ipv6/addrconf_core.c
index 29095c90aa16..e7ee5f98327d 100644
--- a/net/ipv6/addrconf_core.c
+++ b/net/ipv6/addrconf_core.c
@@ -9,13 +9,6 @@
#include <net/addrconf.h>
#include <net/ip.h>
-/* if ipv6 module registers this function is used by xfrm to force all
- * sockets to relookup their nodes - this is fairly expensive, be
- * careful
- */
-void (*__fib6_flush_trees)(struct net *);
-EXPORT_SYMBOL(__fib6_flush_trees);
-
#define IPV6_ADDR_SCOPE_TYPE(scope) ((scope) << 16)
static inline unsigned int ipv6_addr_scope2type(unsigned int scope)
diff --git a/net/ipv6/ip6_fib.c b/net/ipv6/ip6_fib.c
index 266370e15774..75512fbcb945 100644
--- a/net/ipv6/ip6_fib.c
+++ b/net/ipv6/ip6_fib.c
@@ -43,7 +43,6 @@ struct fib6_cleaner {
struct fib6_walker w;
struct net *net;
int (*func)(struct fib6_info *, void *arg);
- int sernum;
void *arg;
bool skip_notify;
};
@@ -123,21 +122,6 @@ static void fib6_walkers_skip_rt(struct net *net, struct fib6_info *rt)
fib6_walkers_replace_leaf(net, rt, next);
}
-static int fib6_new_sernum(struct net *net)
-{
- int new, old = atomic_read(&net->ipv6.fib6_sernum);
-
- do {
- new = old < INT_MAX ? old + 1 : 1;
- } while (!atomic_try_cmpxchg(&net->ipv6.fib6_sernum, &old, new));
-
- return new;
-}
-
-enum {
- FIB6_NO_SERNUM_CHANGE = 0,
-};
-
void fib6_update_sernum(struct net *net, struct fib6_info *f6i)
{
struct fib6_node *fn;
@@ -145,7 +129,7 @@ void fib6_update_sernum(struct net *net, struct fib6_info *f6i)
fn = rcu_dereference_protected(f6i->fib6_node,
lockdep_is_held(&f6i->fib6_table->tb6_lock));
if (fn)
- WRITE_ONCE(fn->fn_sernum, fib6_new_sernum(net));
+ WRITE_ONCE(fn->fn_sernum, rt_genid_bump_ipv6(net));
}
/* Tell route dumps that an exception was added under @f6i without
@@ -1464,7 +1448,7 @@ static void __fib6_update_sernum_upto_root(struct fib6_info *rt,
void fib6_update_sernum_upto_root(struct net *net, struct fib6_info *rt)
{
- __fib6_update_sernum_upto_root(rt, fib6_new_sernum(net));
+ __fib6_update_sernum_upto_root(rt, rt_genid_bump_ipv6(net));
}
/*
@@ -1595,7 +1579,7 @@ int fib6_add(struct fib6_node *root, struct fib6_info *rt,
fib6_info_release(iter);
}
- __fib6_update_sernum_upto_root(rt, fib6_new_sernum(info->nl_net));
+ __fib6_update_sernum_upto_root(rt, rt_genid_bump_ipv6(info->nl_net));
if (rt->fib6_flags & RTF_EXPIRES)
fib6_add_gc_list(rt);
@@ -2282,16 +2266,6 @@ static int fib6_clean_node(struct fib6_walker *w)
.skip_notify = c->skip_notify,
};
- if (c->sernum != FIB6_NO_SERNUM_CHANGE &&
- READ_ONCE(w->node->fn_sernum) != c->sernum)
- WRITE_ONCE(w->node->fn_sernum, c->sernum);
-
- if (!c->func) {
- WARN_ON_ONCE(c->sernum == FIB6_NO_SERNUM_CHANGE);
- w->leaf = NULL;
- return 0;
- }
-
for_each_fib6_walker_rt(w) {
res = c->func(rt, c->arg);
if (res == -1) {
@@ -2331,7 +2305,7 @@ static int fib6_clean_node(struct fib6_walker *w)
static void fib6_clean_tree(struct net *net, struct fib6_node *root,
int (*func)(struct fib6_info *, void *arg),
- int sernum, void *arg, bool skip_notify)
+ void *arg, bool skip_notify)
{
struct fib6_cleaner c;
@@ -2341,7 +2315,6 @@ static void fib6_clean_tree(struct net *net, struct fib6_node *root,
c.w.skip = 0;
c.w.skip_in_node = 0;
c.func = func;
- c.sernum = sernum;
c.arg = arg;
c.net = net;
c.skip_notify = skip_notify;
@@ -2351,7 +2324,7 @@ static void fib6_clean_tree(struct net *net, struct fib6_node *root,
static void __fib6_clean_all(struct net *net,
int (*func)(struct fib6_info *, void *),
- int sernum, void *arg, bool skip_notify)
+ void *arg, bool skip_notify)
{
struct fib6_table *table;
struct hlist_head *head;
@@ -2363,7 +2336,7 @@ static void __fib6_clean_all(struct net *net,
hlist_for_each_entry_rcu(table, head, tb6_hlist) {
spin_lock_bh(&table->tb6_lock);
fib6_clean_tree(net, &table->tb6_root,
- func, sernum, arg, skip_notify);
+ func, arg, skip_notify);
spin_unlock_bh(&table->tb6_lock);
}
}
@@ -2373,21 +2346,14 @@ static void __fib6_clean_all(struct net *net,
void fib6_clean_all(struct net *net, int (*func)(struct fib6_info *, void *),
void *arg)
{
- __fib6_clean_all(net, func, FIB6_NO_SERNUM_CHANGE, arg, false);
+ __fib6_clean_all(net, func, arg, false);
}
void fib6_clean_all_skip_notify(struct net *net,
int (*func)(struct fib6_info *, void *),
void *arg)
{
- __fib6_clean_all(net, func, FIB6_NO_SERNUM_CHANGE, arg, true);
-}
-
-static void fib6_flush_trees(struct net *net)
-{
- int new_sernum = fib6_new_sernum(net);
-
- __fib6_clean_all(net, NULL, new_sernum, NULL, false);
+ __fib6_clean_all(net, func, arg, true);
}
/*
@@ -2624,7 +2590,6 @@ int __init fib6_init(void)
if (ret)
goto out_unregister_subsys;
- __fib6_flush_trees = fib6_flush_trees;
out:
return ret;
--
2.43.0
^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [RFC net-next 0/6] ipv6: validate dsts against the netns route generation
2026-11-22 22:26 ` [RFC net-next 0/6] ipv6: validate dsts against the netns route generation David Ahern
@ 2026-11-22 22:30 ` David Ahern
0 siblings, 0 replies; 9+ messages in thread
From: David Ahern @ 2026-11-22 22:30 UTC (permalink / raw)
To: netdev, Ralf Lici
Cc: David Ahern, Ido Schimmel, David S . Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, Simon Horman
On 11/22/26 3:26 PM, David Ahern wrote:
> From: David Ahern <dahern@nvidia.com>
>
> An IPv6 dst has never carried the fib6 serial number it was created
> under. rt6_get_cookie() reads fn->fn_sernum through rt->from when a
> socket, dst_cache or xfrm bundle stores its cookie, so a FIB change
> that lands between the route lookup and the cookie capture is folded
> into the cookie and a stale dst looks valid. The only dsts stamped at
> creation are pcpu dsts of nexthop-object routes, which store the netns
> genid in rt->sernum.
>
> Looking at this I found that rt_genid_ipv6() and the fib6 serial
> number are already the same counter: net->ipv6.fib6_sernum, which
> fib6_new_sernum() advances on every FIB change. fn_sernum is a per-node
> copy of it. So this series moves dst validation onto that counter, the
> way IPv4 uses rt_genid, instead of adding another one:
>
> 1. Stamp every dst with the counter in ip6_dst_alloc() and validate by
> comparison in ip6_dst_check(). Long-lived dsts (pcpu dsts of routes
> with an embedded fib6_nh, and exception dsts) are re-stamped when a
> lookup finds them again, otherwise they would stay invalid.
>
> 2. ip6_link_failure() forced a new lookup by writing -1 to fn_sernum.
> That no longer invalidates anything, so clear the failing dst's
> sernum instead.
>
> 3-4. Nexthop objects: factor out nh_has_f6i(), then bump the counter
> when a nexthop used through a group is replaced, and when a member
> is removed from a group.
>
> 5. A new PMTU or redirect exception used to bump the counter, which
> with (1) would invalidate every dst in the namespace. Do what IPv4
> does in update_or_create_fnhe() and invalidate only the pcpu dsts
> of the affected fib6_nh. Route dumps still need to see that an
> exception was added to the root node, so add a per-table sequence
> for that rather than inventing fn_sernum values the counter could
> later issue again.
>
> 6. Since nothing validates against fn_sernum any more,
> rt_genid_bump_ipv6() no longer needs to walk every node of every
> table. Make it an atomic increment like rt_genid_bump_ipv4(), and
> drop the __fib6_flush_trees pointer. fn_sernum remains only for
> route dump consistency, so nexthop, address and rule changes no
> longer restart in-progress dumps.
>
Ralf: This aligns with the direction I meant in my reply on October 13.
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2026-11-22 22:30 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-22 22:26 David Ahern
2026-11-22 22:26 ` [RFC net-next 0/6] ipv6: validate dsts against the netns route generation David Ahern
2026-11-22 22:30 ` David Ahern
2026-11-22 22:26 ` [RFC net-next 1/6] " David Ahern
2026-11-22 22:27 ` [RFC net-next 2/6] ipv6: invalidate the failing dst in ip6_link_failure() David Ahern
2026-11-22 22:27 ` [RFC net-next 3/6] nexthop: factor out nh_has_f6i() David Ahern
2026-11-22 22:27 ` [RFC net-next 4/6] nexthop: bump the IPv6 route generation on group changes David Ahern
2026-11-22 22:27 ` [RFC net-next 5/6] ipv6: scope exception invalidation to the affected nexthop David Ahern
2026-11-22 22:27 ` [RFC net-next 6/6] ipv6: make rt_genid_bump_ipv6() a plain counter increment David Ahern
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox