[PATCH net] ipv6: advance the serial after rebalancing in fib6_ifup and fib6_ifdown
From: Ralf Lici
Date: Thu Nov 26 2026 - 03:14:26 EST
fib6_ifup and fib6_ifdown update the node serial before calling
rt6_multipath_rebalance. A lookup that runs between the two can select a
nexthop using the old ECMP upper bounds and read the new serial as its
cookie. The cached dst then passes dst_check although it was selected
from the old state, until the next relevant change.
Update the serial after rt6_multipath_rebalance, so that it is published
only after the routing state it describes. fib6_new_sernum allocates the
serial with a fully ordered atomic_try_cmpxchg, which orders the
rebalance before the serial update. The invalidation scope is unchanged:
fib6_ifup still updates the node and its ancestors, fib6_ifdown only the
node.
Validating dsts against the generation sampled before the lookup, as
proposed in "ipv6: validate cached dsts against the netns route
generation", relies on this order as well: a lookup that reads the new
generation must also observe the routing change it describes.
Reported by Sashiko while reviewing an earlier version of this change.
Fixes: d7dedee184e7 ("ipv6: Calculate hash thresholds for IPv6 nexthops")
Fixes: 4bc852006b62 ("ipv6: update route serial number on NETDEV_CHANGE")
Link: https://lore.kernel.org/netdev/cover.1795642432.git.dahern@xxxxxxxxxx/
Signed-off-by: Ralf Lici <ralf@xxxxxxxxxxxxx>
Reviewed-by: Xia Yan <yanxia@xxxxxxxxxxxxxxxxxxxx>
---
Split out of v5 of "ipv6: tie dst validation to the lookup that
returned the dst", which is withdrawn in favour of the series in the
Link above:
https://lore.kernel.org/netdev/cover.1795537128.git.ralf@xxxxxxxxxxxxx/
net/ipv6/route.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/net/ipv6/route.c b/net/ipv6/route.c
index 1b2dcc066e19..194432f1fd66 100644
--- a/net/ipv6/route.c
+++ b/net/ipv6/route.c
@@ -4911,8 +4911,8 @@ static int fib6_ifup(struct fib6_info *rt, void *p_arg)
if (rt != net->ipv6.fib6_null_entry && !rt->nh &&
rt->fib6_nh->fib_nh_dev == arg->dev) {
rt->fib6_nh->fib_nh_flags &= ~arg->nh_flags;
- fib6_update_sernum_upto_root(net, rt);
rt6_multipath_rebalance(rt);
+ fib6_update_sernum_upto_root(net, rt);
}
return 0;
@@ -5015,8 +5015,8 @@ static int fib6_ifdown(struct fib6_info *rt, void *p_arg)
}
rt6_multipath_nh_flags_set(rt, dev, RTNH_F_DEAD |
RTNH_F_LINKDOWN);
- fib6_update_sernum(net, rt);
rt6_multipath_rebalance(rt);
+ fib6_update_sernum(net, rt);
}
return -2;
case NETDEV_CHANGE:
@@ -5024,8 +5024,8 @@ static int fib6_ifdown(struct fib6_info *rt, void *p_arg)
rt->fib6_flags & (RTF_LOCAL | RTF_ANYCAST))
break;
rt->fib6_nh->fib_nh_flags |= RTNH_F_LINKDOWN;
- fib6_update_sernum(net, rt);
rt6_multipath_rebalance(rt);
+ fib6_update_sernum(net, rt);
break;
}
base-commit: ef3e21c61baa74e39a49b75318bd4541562ec43f
--
2.56.0