Thread View: linux.kernel.netdev
2 messages
2 total messages
Started by Stephen Hemminger
Fri, 20 Nov 2026 20:01
[RFC net-next 0/3] net: fix route flush for routes using nexthop objects
Author: Stephen Hemminger
Date: Fri, 20 Nov 2026 20:01
Date: Fri, 20 Nov 2026 20:01
56 lines
13016 bytes
13016 bytes
"ip route flush" fails on any route that uses a nexthop object:
# ip nexthop add id 101 via 192.0.2.1 dev dummy0
# ip route add 203.0.113.0/24 nhid 101
# ip route flush to 203.0.113.0/24
Failed to send flush request: Invalid argument
The first attempt at fixing that was to modify iproute but
that is just working around a kernel bug. Flush should be
able to be done as dump-and-echo by flipping to set
RTM_DELROUTE. This always worked until nexthop compat mode
was introduced.
This series fixes thes by changing where fib handling
is done on delete. I don't use next hop id anywhere
so this is just a proposal.
Patch 1 ignores the legacy nexthop attributes on RTM_DELROUTE when
RTA_NH_ID is present, for both families. The id is already
authoritative in the matching code, so nothing downstream looks at the
fields being cleared. RTM_NEWROUTE stays strict.
Patch 2 accepts RTN_BLACKHOLE on delete when the alias uses a blackhole
nexthop object, so a route can be removed using the type the kernel
advertised. Dropping the dump-side rewrite instead would change what
every existing reader sees.
Patch 3 adds the selftest coverage that was missing. fib_nexthops.sh
exercises "ip nexthop flush" thoroughly but never "ip route flush"
against nhid routes, which is how the two paths drifted apart in the
first place.
Testing: the new tests fail 15 assertions against an unpatched kernel
and all 26 pass with the series applied, booted under qemu with
nexthop_compat_mode=1. The existing fib_nexthops cases, including the
legacy delete paths patch 1 must not disturb, still pass: 93
assertions across ipv4_fcnal, ipv6_fcnal, the compat_mode pair and the
fcnal_runtime pair.
Stephen Hemminger (3):
net: accept legacy nexthop attributes when deleting by nexthop id
ipv4: accept the reported route type when deleting a blackhole nexthop
route
selftests: fib_nexthops: test route flush with nexthop objects
net/ipv4/fib_frontend.c | 17 ++-
net/ipv4/fib_lookup.h | 1 +
net/ipv4/fib_semantics.c | 14 +++
net/ipv4/fib_trie.c | 2 +-
net/ipv6/route.c | 14 ++-
tools/testing/selftests/net/fib_nexthops.sh | 126 ++++++++++++++++++++
6 files changed, 169 insertions(+), 5 deletions(-)
--
2.53.0
[RFC next-net 3/3] selftests: fib_nexthops: test route flush with nexthop objects
Author: Stephen Hemminger
Date: Fri, 20 Nov 2026 20:01
Date: Fri, 20 Nov 2026 20:01
172 lines
18074 bytes
18074 bytes
fib_nexthops.sh exercises "ip nexthop flush" but never "ip route flush"
against routes using nexthop objects, which is how the dump and delete
paths drifted apart.
Add ipv4_route_flush and ipv6_route_flush: a single nexthop object, a
group, a blackhole object and, for IPv4, a route via an IPv6 nexthop
object, since each expands differently in the dump. Flush a batch mixing
nexthop object routes with an ordinary one, and check the nexthop objects
outlive the routes.
Also check what must keep failing: a delete naming the wrong id, and an
add combining an id with a nexthop spec.
Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
tools/testing/selftests/net/fib_nexthops.sh | 126 ++++++++++++++++++++
1 file changed, 126 insertions(+)
diff --git a/tools/testing/selftests/net/fib_nexthops.sh b/tools/testing/selftests/net/fib_nexthops.sh
index adbec51917eb..501ed0fc05a8 100755
--- a/tools/testing/selftests/net/fib_nexthops.sh
+++ b/tools/testing/selftests/net/fib_nexthops.sh
@@ -29,6 +29,7 @@ IPV4_TESTS="
ipv4_large_grp
ipv4_large_res_grp
ipv4_compat_mode
+ ipv4_route_flush
ipv4_fdb_grp_fcnal
ipv4_fdb_port_fcnal
ipv4_mpath_select
@@ -44,6 +45,7 @@ IPV6_TESTS="
ipv6_large_grp
ipv6_large_res_grp
ipv6_compat_mode
+ ipv6_route_flush
ipv6_fdb_grp_fcnal
ipv6_fdb_port_fcnal
ipv6_mpath_select
@@ -2148,6 +2150,130 @@ ipv6_compat_mode()
sysctl_nexthop_compat_mode_set 1 "IPv6"
}
+ipv4_route_flush()
+{
+ echo
+ echo "IPv4 route flush with nexthop objects"
+ echo "-------------------------------------"
+
+ # "ip route flush" dumps the routes and sends each dumped message
+ # back as RTM_DELROUTE. With nexthop_compat_mode on, a dump of a
+ # route using a nexthop object carries RTA_NH_ID plus the legacy
+ # expansion of that nexthop, so the delete has to accept both.
+
+ run_cmd "$IP nexthop add id 601 via 172.16.1.2 dev veth1"
+ run_cmd "$IP nexthop add id 602 via 172.16.1.3 dev veth1"
+ run_cmd "$IP nexthop add id 610 group 601/602"
+ run_cmd "$IP nexthop add id 603 blackhole"
+ run_cmd "$IP -6 nexthop add id 604 via 2001:db8:91::2 dev veth1"
+
+ # single nexthop object: dump has RTA_NH_ID, RTA_GATEWAY, RTA_OIF
+ run_cmd "$IP ro add 172.16.101.0/24 nhid 601"
+ run_cmd "$IP ro flush 172.16.101.0/24"
+ log_test $? 0 "Flush route with single nexthop object"
+ check_route "172.16.101.0/24" ""
+ log_test $? 0 "Flushed single nexthop object route is gone"
+
+ # nexthop group: dump has RTA_NH_ID plus RTA_MULTIPATH
+ run_cmd "$IP ro add 172.16.102.0/24 nhid 610"
+ run_cmd "$IP ro flush 172.16.102.0/24"
+ log_test $? 0 "Flush route with nexthop group"
+ check_route "172.16.102.0/24" ""
+ log_test $? 0 "Flushed nexthop group route is gone"
+
+ # blackhole nexthop object: the dump reports the route as
+ # RTN_BLACKHOLE even though the FIB alias is unicast
+ run_cmd "$IP ro add 172.16.103.0/24 nhid 603"
+ run_cmd "$IP ro flush 172.16.103.0/24"
+ log_test $? 0 "Flush route with blackhole nexthop object"
+ check_route "172.16.103.0/24" ""
+ log_test $? 0 "Flushed blackhole nexthop object route is gone"
+
+ # IPv4 route via an IPv6 nexthop object expands to RTA_VIA
+ run_cmd "$IP ro add 172.16.104.0/24 nhid 604"
+ run_cmd "$IP ro flush 172.16.104.0/24"
+ log_test $? 0 "Flush route with cross-family nexthop object"
+ check_route "172.16.104.0/24" ""
+ log_test $? 0 "Flushed cross-family route is gone"
+
+ # flushing a mix in one batch must not disturb ordinary routes
+ run_cmd "$IP ro add 172.16.105.0/24 nhid 601"
+ run_cmd "$IP ro add 172.16.106.0/24 nhid 610"
+ run_cmd "$IP ro add 172.16.107.0/24 via 172.16.1.2 dev veth1"
+ run_cmd "$IP ro flush dev veth1 proto boot"
+ log_test $? 0 "Flush mixed batch of nexthop object and ordinary routes"
+
+ # the nexthop objects themselves must survive a route flush
+ run_cmd "$IP nexthop get id 601"
+ log_test $? 0 "Nexthop object survives route flush"
+ run_cmd "$IP nexthop get id 610"
+ log_test $? 0 "Nexthop group survives route flush"
+
+ # deleting by nexthop id must still ignore a conflicting selector
+ # rather than silently deleting the wrong route
+ run_cmd "$IP ro add 172.16.108.0/24 nhid 601"
+ run_cmd "$IP ro del 172.16.108.0/24 nhid 602"
+ log_test $? 2 "Delete by wrong nexthop id fails"
+ check_route "172.16.108.0/24" "172.16.108.0/24 nhid 601 via 172.16.1.2 dev veth1"
+ log_test $? 0 "Route with other nexthop id is retained"
+ run_cmd "$IP ro del 172.16.108.0/24 nhid 601"
+ log_test $? 0 "Delete by correct nexthop id succeeds"
+
+ # adding a route must still reject nhid together with a nexthop spec
+ run_cmd "$IP ro add 172.16.109.0/24 nhid 601 via 172.16.1.2 dev veth1"
+ log_test $? 2 "Add rejects nexthop id with nexthop specification"
+
+ $IP nexthop flush >/dev/null 2>&1
+ $IP ro flush dev veth1 proto boot >/dev/null 2>&1
+}
+
+ipv6_route_flush()
+{
+ echo
+ echo "IPv6 route flush with nexthop objects"
+ echo "-------------------------------------"
+
+ run_cmd "$IP -6 nexthop add id 611 via 2001:db8:91::2 dev veth1"
+ run_cmd "$IP -6 nexthop add id 612 via 2001:db8:91::3 dev veth1"
+ run_cmd "$IP nexthop add id 620 group 611/612"
+ run_cmd "$IP -6 nexthop add id 613 blackhole"
+
+ run_cmd "$IP -6 ro add 2001:db8:101::/64 nhid 611"
+ run_cmd "$IP -6 ro flush 2001:db8:101::/64"
+ log_test $? 0 "Flush IPv6 route with single nexthop object"
+ check_route6 "2001:db8:101::/64" ""
+ log_test $? 0 "Flushed IPv6 single nexthop object route is gone"
+
+ run_cmd "$IP -6 ro add 2001:db8:102::/64 nhid 620"
+ run_cmd "$IP -6 ro flush 2001:db8:102::/64"
+ log_test $? 0 "Flush IPv6 route with nexthop group"
+ check_route6 "2001:db8:102::/64" ""
+ log_test $? 0 "Flushed IPv6 nexthop group route is gone"
+
+ run_cmd "$IP -6 ro add 2001:db8:103::/64 nhid 613"
+ run_cmd "$IP -6 ro flush 2001:db8:103::/64"
+ log_test $? 0 "Flush IPv6 route with blackhole nexthop object"
+ check_route6 "2001:db8:103::/64" ""
+ log_test $? 0 "Flushed IPv6 blackhole nexthop object route is gone"
+
+ run_cmd "$IP -6 nexthop get id 611"
+ log_test $? 0 "IPv6 nexthop object survives route flush"
+ run_cmd "$IP nexthop get id 620"
+ log_test $? 0 "IPv6 nexthop group survives route flush"
+
+ run_cmd "$IP -6 ro add 2001:db8:104::/64 nhid 611"
+ run_cmd "$IP -6 ro del 2001:db8:104::/64 nhid 612"
+ log_test $? 2 "Delete IPv6 route by wrong nexthop id fails"
+ run_cmd "$IP -6 ro del 2001:db8:104::/64 nhid 611"
+ log_test $? 0 "Delete IPv6 route by correct nexthop id succeeds"
+
+ run_cmd "$IP -6 ro add 2001:db8:105::/64 nhid 611 via 2001:db8:91::2 dev veth1"
+ log_test $? 2 "Add rejects IPv6 nexthop id with nexthop specification"
+
+ $IP nexthop flush >/dev/null 2>&1
+ $IP -6 ro flush dev veth1 proto boot >/dev/null 2>&1
+}
+
ipv4_compat_mode()
{
local rc
--
2.53.0
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