From: Stephen Hemminger <stephen@networkplumber.org>
To: netdev@vger.kernel.org
Cc: dsahern@kernel.org,
Stephen Hemminger <stephen@networkplumber.org>,
Ido Schimmel <idosch@nvidia.com>,
"David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@kernel.org>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
Simon Horman <horms@kernel.org>, Shuah Khan <shuah@kernel.org>,
linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [RFC next-net 3/3] selftests: fib_nexthops: test route flush with nexthop objects
Date: Fri, 20 Nov 2026 12:01:30 -0800 [thread overview]
Message-ID: <20261120200635.95798-4-stephen@networkplumber.org> (raw)
In-Reply-To: <20261120200635.95798-1-stephen@networkplumber.org>
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
prev parent reply other threads:[~2026-11-20 20:06 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20261120200635.95798-1-stephen@networkplumber.org>
2026-11-20 20:01 ` [RFC next-net 1/3] net: accept legacy nexthop attributes when deleting by nexthop id Stephen Hemminger
2026-11-20 20:01 ` [RFC next-net 2/3] ipv4: accept the reported route type when deleting a blackhole nexthop route Stephen Hemminger
2026-11-20 20:01 ` Stephen Hemminger [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261120200635.95798-4-stephen@networkplumber.org \
--to=stephen@networkplumber.org \
--cc=davem@davemloft.net \
--cc=dsahern@kernel.org \
--cc=edumazet@kernel.org \
--cc=horms@kernel.org \
--cc=idosch@nvidia.com \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=shuah@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®