[PATCH net-next 2/2] ipv6: allocate the flush serial under each table's lock

From: Ralf Lici

Date: Fri Dec 04 2026 - 06:28:53 EST


fib6_flush_trees allocates one serial and then walks the tables with
__fib6_clean_all, which takes each table's tb6_lock in turn. A route
change in a table the walk has not reached yet stamps its nodes with a
newer serial, which the walk then overwrites with the older one, so the
node's serial goes backwards.

Allocate a fresh serial for each table once its tb6_lock is held, so
that no writer can stamp a newer serial in that table before the walk
does.

This is a preparation for validating dsts by comparing serials by age,
which needs node serials never to go backwards.

Signed-off-by: Ralf Lici <ralf@xxxxxxxxxxxxx>
---
net/ipv6/ip6_fib.c | 13 ++++++++-----
1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/net/ipv6/ip6_fib.c b/net/ipv6/ip6_fib.c
index c2ed54d39f9d..7a31490890d3 100644
--- a/net/ipv6/ip6_fib.c
+++ b/net/ipv6/ip6_fib.c
@@ -139,6 +139,8 @@ static int fib6_new_sernum(struct net *net)

enum {
FIB6_NO_SERNUM_CHANGE = 0,
+ /* A fresh serial for each table, allocated under its tb6_lock */
+ FIB6_NEW_SERNUM = -1,
};

void fib6_update_sernum(struct net *net, struct fib6_info *f6i)
@@ -2337,6 +2339,7 @@ static void __fib6_clean_all(struct net *net,
{
struct fib6_table *table;
struct hlist_head *head;
+ int table_sn = sernum;
unsigned int h;

rcu_read_lock();
@@ -2344,8 +2347,10 @@ static void __fib6_clean_all(struct net *net,
head = &net->ipv6.fib_table_hash[h];
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);
+ if (sernum == FIB6_NEW_SERNUM)
+ table_sn = fib6_new_sernum(net);
+ fib6_clean_tree(net, &table->tb6_root, func,
+ table_sn, arg, skip_notify);
spin_unlock_bh(&table->tb6_lock);
}
}
@@ -2367,9 +2372,7 @@ void fib6_clean_all_skip_notify(struct net *net,

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, NULL, FIB6_NEW_SERNUM, NULL, false);
}

/*
--
2.56.1