🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: linux.kernel.netdev
2 messages
2 total messages Started by Yifei Sun Thu, 26 Nov 2026 16:25
[PATCH net v2 1/2] ipv4: keep scanning the leaf when a nexthop object is unusable
#23166
Author: Yifei Sun
Date: Thu, 26 Nov 2026 16:25
55 lines
10084 bytes
With veth1 on 172.16.1.0/24 and veth3 on 172.16.2.0/24:

  # ip nexthop add id 12 via 172.16.1.2 dev veth1
  # ip route add 10.0.0.0/24 nhid 12
  # ip route add 10.0.0.0/16 via 172.16.2.2 dev veth3
  # ip route get fibmatch 10.0.0.1 oif veth3
  RTNETLINK answers: No route to host

When the /24's nexthop object has no path on veth3, fib_table_lookup()
backtracks past the /16 in the same leaf. A socket bound to veth3 then
ARPs for the destination instead of the gateway. Fix this by trying the
next alias in the same leaf. The lookup already does this when no
inline nexthop is usable.

Fixes: af7888ad9edb ("ipv4: Refactor nhc evaluation in fib_table_lookup")
Signed-off-by: Yifei Sun <yifei.sun@inria.fr>
---
Encountered this while work on a unrelated IPv4 SADR patch (not sure if
this is even needed...)

In QEMU with lockdep on 5e2976e52671, the selftest and device-bound
ping and UDP failed before the fix and passed after it.

v2: Reworded.
v1: https://lore.kernel.org/netdev/20261121182031.36626-1-yifei.sun@inria.fr/

 net/ipv4/fib_trie.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/net/ipv4/fib_trie.c b/net/ipv4/fib_trie.c
index 394df1de1281..2a670e9b0417 100644
--- a/net/ipv4/fib_trie.c
+++ b/net/ipv4/fib_trie.c
@@ -1591,7 +1591,7 @@ int fib_table_lookup(struct fib_table *tb, const struct flowi4 *flp,
 						     &nhsel);
 			if (nhc)
 				goto set_result;
-			goto miss;
+			continue;
 		}
 
 		for (nhsel = 0; nhsel < fib_info_num_path(fi); nhsel++) {
@@ -1622,7 +1622,6 @@ int fib_table_lookup(struct fib_table *tb, const struct flowi4 *flp,
 			return err;
 		}
 	}
-miss:
 #ifdef CONFIG_IP_FIB_TRIE_STATS
 	this_cpu_inc(stats->semantic_match_miss);
 #endif

base-commit: ae8e5ef9fa9eeaf4ee0a9a9bde0fc63023d9b154
-- 
2.56.1
[PATCH net v2 2/2] selftests: net: test IPv4 nexthop fallback in the same trie leaf
#23167
Author: Yifei Sun
Date: Thu, 26 Nov 2026 16:25
133 lines
12320 bytes
Check that a lookup bound to dummy0 selects the preferred route, while
one bound to dummy1 falls back to another route in the same trie leaf.
Cover both a shorter prefix and a higher metric for the same prefix.
Run the same checks with legacy nexthops and for IPv6.

Signed-off-by: Yifei Sun <yifei.sun@inria.fr>
---
v2: Moved to fib_tests.sh. Added legacy and IPv6 cases.
v1: https://lore.kernel.org/netdev/20261121182031.36626-2-yifei.sun@inria.fr/

 tools/testing/selftests/net/fib_tests.sh | 92 ++++++++++++++++++++++++
 1 file changed, 92 insertions(+)

diff --git a/tools/testing/selftests/net/fib_tests.sh b/tools/testing/selftests/net/fib_tests.sh
index d7ac3c727f70..c06eacc8108f 100755
--- a/tools/testing/selftests/net/fib_tests.sh
+++ b/tools/testing/selftests/net/fib_tests.sh
@@ -14,6 +14,8 @@ TESTS="unregister down carrier nexthop suppress ipv6_notify ipv4_notify \
        ipv4_mpath_list ipv6_mpath_list ipv4_mpath_balance ipv6_mpath_balance \
        ipv4_mpath_balance_preferred ipv4_mpath_oif ipv4_mpath_oif_nh \
        ipv4_mpath_oif_vrf ipv6_mpath_oif ipv6_mpath_oif_nh ipv6_mpath_oif_vrf \
+       ipv4_oif_fallback ipv4_oif_fallback_nh ipv6_oif_fallback \
+       ipv6_oif_fallback_nh \
        fib6_ra_to_static fib6_temp_addr_renewal"
 
 VERBOSE=0
@@ -3228,6 +3230,92 @@ ipv6_mpath_oif_vrf_test()
 	cleanup
 }
 
+check_oif_fallback()
+{
+	local dst=$1 dev=$2 prefix=$3 metric=$4
+	local out
+
+	out=$($IP -o route get fibmatch "$dst" oif "$dev") || return 1
+	[[ $out == "$prefix "* && " $out " == *" metric $metric "* ]]
+}
+
+oif_fallback_test_common()
+{
+	local family=$1 mode=$2
+	local addr gw1 gw2 dst longer shorter
+	local -a nh1 nh2
+
+	echo
+	echo "IPv$family output interface fallback ($mode nexthops)"
+
+	if [ "$family" = 4 ]; then
+		addr=192.0.2.1/24
+		gw1=198.51.100.2
+		gw2=192.0.2.2
+		dst=203.0.113.1
+		longer=203.0.113.0/25
+		shorter=203.0.113.0/24
+	else
+		addr=2001:db8:2::1/64
+		gw1=2001:db8:1::2
+		gw2=2001:db8:2::2
+		dst=2001:db8:10::1
+		longer=2001:db8:10::/64
+		shorter=2001:db8:10::/48
+	fi
+
+	setup
+	set -e
+	$IP link add dummy1 up type dummy
+	$IP address add "$addr" dev dummy1
+
+	nh1=(via "$gw1" dev dummy0)
+	nh2=(via "$gw2" dev dummy1)
+	if [ "$mode" = object ]; then
+		$IP nexthop add id 1 "${nh1[@]}"
+		$IP nexthop add id 2 "${nh2[@]}"
+		nh1=(nhid 1)
+		nh2=(nhid 2)
+	fi
+
+	$IP route add "$longer" "${nh1[@]}" metric 100
+	$IP route add "$shorter" "${nh2[@]}" metric 100
+	set +e
+
+	check_oif_fallback "$dst" dummy0 "$longer" 100
+	log_test $? 0 "Lookup on the preferred route's device"
+	check_oif_fallback "$dst" dummy1 "$shorter" 100
+	log_test $? 0 "Fallback to the shorter prefix"
+
+	set -e
+	$IP route add "$longer" "${nh2[@]}" metric 200
+	set +e
+	check_oif_fallback "$dst" dummy1 "$longer" 200
+	log_test $? 0 "Fallback to the higher metric for the same prefix"
+
+	cleanup
+}
+
+ipv4_oif_fallback_test()
+{
+	oif_fallback_test_common 4 legacy
+}
+
+ipv4_oif_fallback_nh_test()
+{
+	oif_fallback_test_common 4 object
+}
+
+ipv6_oif_fallback_test()
+{
+	oif_fallback_test_common 6 legacy
+}
+
+ipv6_oif_fallback_nh_test()
+{
+	oif_fallback_test_common 6 object
+}
+
 ################################################################################
 # usage
 
@@ -3320,6 +3408,10 @@ do
 	ipv6_mpath_oif)			ipv6_mpath_oif_test;;
 	ipv6_mpath_oif_nh)		ipv6_mpath_oif_nh_test;;
 	ipv6_mpath_oif_vrf)		ipv6_mpath_oif_vrf_test;;
+	ipv4_oif_fallback)		ipv4_oif_fallback_test;;
+	ipv4_oif_fallback_nh)		ipv4_oif_fallback_nh_test;;
+	ipv6_oif_fallback)		ipv6_oif_fallback_test;;
+	ipv6_oif_fallback_nh)		ipv6_oif_fallback_nh_test;;
 	fib6_ra_to_static)		fib6_ra_to_static;;
 	fib6_temp_addr_renewal)		fib6_temp_addr_renewal;;
 
-- 
2.56.1
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