Thread View: linux.kernel.netdev
2 messages
2 total messages
Started by Ralf Lici
Fri, 20 Nov 2026 09:36
[PATCH net-next v4 1/5] ipv6: stamp the default route node with a fresh serial on link failure
Author: Ralf Lici
Date: Fri, 20 Nov 2026 09:36
Date: Fri, 20 Nov 2026 09:36
81 lines
12808 bytes
12808 bytes
ip6_link_failure invalidates the cached dsts of an RTF_DEFAULT route by
writing -1 into the node's fn_sernum. Once the node already holds -1,
another link failure leaves the serial unchanged, so dsts cached with
that cookie can survive subsequent failures.
The assignment also leaves net->ipv6.fib6_sernum unchanged, making the
invalidation invisible to lookups watching the namespace generation.
Use fib6_update_sernum under tb6_lock to allocate and stamp a fresh
serial. This makes repeated invalidations distinguishable and allows the
lookup-cookie generation checks introduced later in this series to
detect them.
Advancing the namespace generation also invalidates unrelated dsts using
nexthop objects, which are validated against that generation. This
happens once per ip6_link_failure call, so once per queued skb when the
neighbour of the default router fails. These are error paths and add no
cost to the fast path.
Found while reviewing the IPv6 routing code to address the dst-cache
race.
Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
Signed-off-by: Ralf Lici <ralf@mandelbit.com>
---
Changes since v3 https://lore.kernel.org/netdev/5b59512a6c51c7a5d7c7b4e16728de3c522d9a1e.1794906743.git.ralf@mandelbit.com/
- Note that the generation advances once per ip6_link_failure call.
(Sashiko)
- Widen the rt6_exception_net comment. (Sashiko)
Changes since v2 https://lore.kernel.org/all/143461e2c94a20060ff4c7d6e5eb46c47ac46aa0.1794384146.git.ralf@mandelbit.com/
- Add a Fixes tag referencing the initial git import. (Sashiko)
- Clarify that the nexthop-object invalidation is a harmless side
effect, rather than a deficiency being fixed. (Sashiko)
No changes since v1 https://lore.kernel.org/netdev/5b039a5a24808f2678eedd283c29f8dae514ef5e.1793806941.git.ralf@mandelbit.com/
net/ipv6/route.c | 18 ++++++++++--------
1 file changed, 10 insertions(+), 8 deletions(-)
diff --git a/net/ipv6/route.c b/net/ipv6/route.c
index 4a4c5ace63c5..bbe6d67bb696 100644
--- a/net/ipv6/route.c
+++ b/net/ipv6/route.c
@@ -1531,9 +1531,11 @@ static struct rt6_info *rt6_make_pcpu_route(struct net *net,
*/
static DEFINE_SPINLOCK(rt6_exception_lock);
-/* Exceptions are accounted to the netns their dst was allocated in.
- * Unlike dev_net(dst->dev), it does not change when the device moves to
- * another netns or when dst_dev_put() points the dst to blackhole_netdev.
+/* Return the netns the dst was allocated in, which owns the fib6 table of
+ * its route. Exceptions are accounted to it, and ip6_link_failure advances
+ * its generation. Unlike dev_net(dst->dev), it does not change when the
+ * device moves to another netns or when dst_dev_put() points the dst to
+ * blackhole_netdev.
*/
static struct net *rt6_exception_net(const struct rt6_info *rt)
{
@@ -2873,13 +2875,13 @@ static void ip6_link_failure(struct sk_buff *skb)
rt6_remove_exception_rt(rt);
} else {
struct fib6_info *from;
- struct fib6_node *fn;
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 && from->fib6_table &&
+ (rt->rt6i_flags & RTF_DEFAULT)) {
+ spin_lock_bh(&from->fib6_table->tb6_lock);
+ fib6_update_sernum(rt6_exception_net(rt), from);
+ spin_unlock_bh(&from->fib6_table->tb6_lock);
}
}
rcu_read_unlock();
--
2.56.0
Re: [PATCH net-next v4 1/5] ipv6: stamp the default route node with a fresh serial on link failure
Author: netdev-bot+sashiko
Date: Tue, 24 Nov 2026 10:26
Date: Tue, 24 Nov 2026 10:26
112 lines
12343 bytes
12343 bytes
Thank you for your contribution! Sashiko AI review found more severe
issue(s) in other patches of this series. This mail is only an FYI, in case
you want to address the nit picks below when you respin.
Low priority / nit picks for your consideration:
- [Low] The patch makes ip6_link_failure() (net/ipv6/route.c) do much
more work for an RTF_DEFAULT, non-RTF_CACHE dst.
--
ipv6: stamp the default route node with a fresh serial on link failure
This commit changes ip6_link_failure() so that it no longer writes -1 into
fn_sernum of an RTF_DEFAULT route's node. It now calls fib6_update_sernum()
under tb6_lock, which allocates a fresh serial and advances the netns-wide
fib6_sernum generation. The changelog says the extra cost happens once per
queued skb when the neighbour of the default router fails.
> diff --git a/net/ipv6/route.c b/net/ipv6/route.c
> index 4a4c5ace63c54..bbe6d67bb6964 100644
> --- a/net/ipv6/route.c
> +++ b/net/ipv6/route.c
[ ... ]
> @@ -2873,13 +2875,13 @@ static void ip6_link_failure(struct sk_buff *skb)
> rt6_remove_exception_rt(rt);
> } else {
> struct fib6_info *from;
> - struct fib6_node *fn;
>
> 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 && from->fib6_table &&
> + (rt->rt6i_flags & RTF_DEFAULT)) {
> + spin_lock_bh(&from->fib6_table->tb6_lock);
> + fib6_update_sernum(rt6_exception_net(rt), from);
> + spin_unlock_bh(&from->fib6_table->tb6_lock);
[Severity: Low]
Is the cost of this path limited to neighbour failure, as the commit
message says?
This happens once per ip6_link_failure call, so once per queued skb
when the neighbour of the default router fails.
Several tunnel transmit error paths call dst_link_failure(skb) once per
packet. For an IPv6 inner packet the inner route's dst is still attached,
so they reach ip6_link_failure():
ipip6_tunnel_xmit() in net/ipv6/sit.c:
tx_error_icmp:
dst_link_failure(skb);
This one is taken when ip_route_output_flow() fails or when the underlay
route is not unicast or local.
ip6_tnl_xmit() in net/ipv6/ip6_tunnel.c:
tx_err_link_failure:
DEV_STATS_INC(dev, tx_carrier_errors);
dst_link_failure(skb);
This one is taken when ip6_route_output() returns dst->error, when
xfrm_lookup() fails, or when ip6_tnl_xmit_ctl() fails. skb_dst_set() runs
later than this, so skb_dst is still the inner IPv6 route here.
ip_tunnel_xmit() in net/ipv4/ip_tunnel.c also reaches tx_error_icmp in the
NBMA case when the IPv6 next hop is not v4-compatible.
There are also the err_count paths in ip_tunnel_xmit(),
ipip6_tunnel_xmit() and ip6_tnl_xmit():
WRITE_ONCE(tunnel->err_count, err_count - 1);
dst_link_failure(skb);
These run once per ICMP error received for the tunnel, so a remote host
can drive them.
RA-learned default routes carry RTF_DEFAULT, for example a default router
learned over ISATAP/sit, gretap or ip6gretap. pcpu copies keep the flag
through ip6_rt_copy_init().
While the underlay is broken, wouldn't every IPv6 packet sent through
such a route take tb6_lock with BH disabled? Each one would also run
fib6_new_sernum()'s atomic_try_cmpxchg on net->ipv6.fib6_sernum.
tb6_lock is the same lock that route insert/delete, GC and PMTU exception
insertion use. Each generation bump also invalidates every nexthop-object
dst in the netns, because rt6_is_valid() checks those against the netns
generation. Later in the series, ip6_dst_lookup_flow_cookie() returns
cookie 0 to socket lookups that race with a bump.
These are error paths where the traffic is already being dropped. Also,
rt6_insert_exception() already takes tb6_lock and bumps the generation on
remotely triggered PMTU exceptions. Still, the cost here seems to scale
with packets on these tunnel paths, not with neighbour queue length.
Could the changelog mention these callers? Would it be worth
rate-limiting the bump, or skipping it when the node's serial has already
moved past the one the dst cached?
> }
> }
> rcu_read_unlock();
--
Sashiko AI review ยท https://netdev-ai.bots.linux.dev/sashiko/#/patchset/cover.1795166508.git.ralf%40mandelbit.com
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