From: David Ahern <dsahern@kernel.org>
To: netdev@vger.kernel.org
Cc: ralf@mandelbit.com, David Ahern <dahern@nvidia.com>
Subject: [RFC net-next v2 4/7] nexthop: bump the IPv6 route generation on group changes
Date: Mon, 23 Nov 2026 14:26:06 -0700 [thread overview]
Message-ID: <20261123212623.106153-5-dsahern@kernel.org> (raw)
In-Reply-To: <20261123212623.106153-1-dsahern@kernel.org>
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.
Signed-off-by: David Ahern <dahern@nvidia.com>
---
Changes since v1:
- None.
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
next prev parent reply other threads:[~2026-11-23 21:26 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-23 21:26 [RFC net-next v2 0/7] ipv6: validate dsts against the netns route generation at lookup David Ahern
2026-11-23 21:26 ` [RFC net-next v2 1/7] ipv6: validate dsts against the netns route generation David Ahern
2026-11-23 21:26 ` [RFC net-next v2 2/7] ipv6: invalidate the failing dst in ip6_link_failure() David Ahern
2026-11-23 21:26 ` [RFC net-next v2 3/7] nexthop: factor out nh_has_f6i() David Ahern
2026-11-23 21:26 ` David Ahern [this message]
2026-11-23 21:26 ` [RFC net-next v2 5/7] ipv6: scope exception invalidation to the affected nexthop David Ahern
2026-11-23 21:26 ` [RFC net-next v2 6/7] ipv6: make rt_genid_bump_ipv6() a plain counter increment David Ahern
2026-11-23 21:26 ` [RFC net-next v2 7/7] ipv6: stamp dsts with the generation sampled before the FIB lookup David Ahern
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=20261123212623.106153-5-dsahern@kernel.org \
--to=dsahern@kernel.org \
--cc=dahern@nvidia.com \
--cc=netdev@vger.kernel.org \
--cc=ralf@mandelbit.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