Re: [PATCH net-next v5 2/4] ipv6: take fib6_sernum from a sequence shared by all netns
From: Ralf Lici
Date: Sun Nov 22 2026 - 04:04:05 EST
On Sat, 21 Nov 2026 18:21:20 -0500, Qiliang Yuan <qiliang.yuan@xxxxxxxxx> wrote:
> A per-cpu IPv6 route of a nexthop object records fib6_sernum of the
> netns it was created in, and rt6_is_valid() compares it with fib6_sernum
> of the netns its device belongs to when the route is checked. Every netns
> starts its fib6_sernum at 1 and increments it on each tree change, so
> different netns often hold the same value.
>
> When a device moves to another netns, such a route remains usable until
> nexthop_free_rcu() releases it, and fib6_info_destroy_rcu() queues that
> callback from inside an RCU callback, after the device has moved. If the
> fib6_sernum of the new netns matches the cached one in that window,
> ip6_dst_check() accepts the route and a socket in the old netns keeps
> sending through a device that now belongs to another netns.
>
> Take every fib6_sernum bump from one sequence shared by all netns, which
> only hands out values from 2 up, and have rt6_is_valid() reject 1, the
> value every netns starts with: fib6_add() publishes a route before it
> bumps fib6_sernum, so a route looked up in between can record 1. 0 still
> means there is no sernum to check. Any other value a route records was
> drawn from the sequence, which no other netns holds until it wraps after
> 2^31 bumps. fib6_new_sernum() callers only hold their own table's
> tb6_lock, so bumps of one netns can race. Publish each value with a
> cmpxchg on the fib6_sernum of the netns, drawing again if another bump
> changed it first. As before, this orders the routing change before the
> new value and the value before the nodes stamped with it, and keeps
> fib6_sernum monotonic per netns.
>
> A connected UDP socket in netns A caches a route through an IPv6 nexthop
> object on a veth. The veth is moved to netns B and brought up with one
> RTM_NEWLINK, then the socket sends 200000 datagrams. A route is added to
> and removed from B 0 to 20 times before the move, 63 trials:
>
> before after change
> trials sending after move (count) 3 0 -100%
> datagrams sent after move (count) 6634 0 -100%
>
> Signed-off-by: Qiliang Yuan <qiliang.yuan@xxxxxxxxx>
Reviewed-by: Ralf Lici <ralf@xxxxxxxxxxxxx>
Thanks for picking this up.
--
Ralf Lici
Mandelbit Srl