* [PATCH net 1/2] ipv4: keep scanning the leaf when a nexthop object is unusable
@ 2026-11-21 18:20 Yifei Sun
2026-11-21 18:20 ` [PATCH net 2/2] selftests: net: test IPv4 nexthop fallback in the same trie leaf Yifei Sun
2026-11-24 15:37 ` [PATCH net 1/2] ipv4: keep scanning the leaf when a nexthop object is unusable Ido Schimmel
0 siblings, 2 replies; 4+ messages in thread
From: Yifei Sun @ 2026-11-21 18:20 UTC (permalink / raw)
To: netdev
Cc: Yifei Sun, David Ahern, Ido Schimmel, David S. Miller,
Eric Dumazet, Jakub Kicinski, Paolo Abeni, Willem de Bruijn,
Simon Horman, Nikolay Aleksandrov, Shuah Khan, linux-kselftest
With veth1 on 172.16.1.0/24 and veth3 on 172.16.2.0/24:
```console
$ 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. Try the next alias,
as for inline nexthops.
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.
Fixes: af7888ad9edb ("ipv4: Refactor nhc evaluation in fib_table_lookup")
Signed-off-by: Yifei Sun <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 @@ out_reject:
&nhsel);
if (nhc)
goto set_result;
- goto miss;
+ continue;
}
for (nhsel = 0; nhsel < fib_info_num_path(fi); nhsel++) {
@@ -1622,7 +1622,6 @@ set_result:
return err;
}
}
-miss:
#ifdef CONFIG_IP_FIB_TRIE_STATS
this_cpu_inc(stats->semantic_match_miss);
#endif
base-commit: d5b89d55a322b632e2b465b392a4c1d9d338db9c
^ permalink raw reply related [flat|nested] 4+ messages in thread* [PATCH net 2/2] selftests: net: test IPv4 nexthop fallback in the same trie leaf
2026-11-21 18:20 [PATCH net 1/2] ipv4: keep scanning the leaf when a nexthop object is unusable Yifei Sun
@ 2026-11-21 18:20 ` Yifei Sun
2026-11-24 15:37 ` Ido Schimmel
2026-11-24 15:37 ` [PATCH net 1/2] ipv4: keep scanning the leaf when a nexthop object is unusable Ido Schimmel
1 sibling, 1 reply; 4+ messages in thread
From: Yifei Sun @ 2026-11-21 18:20 UTC (permalink / raw)
To: netdev
Cc: Yifei Sun, David Ahern, Ido Schimmel, David S. Miller,
Eric Dumazet, Jakub Kicinski, Paolo Abeni, Willem de Bruijn,
Simon Horman, Nikolay Aleksandrov, Shuah Khan, linux-kselftest
Check that a lookup bound to veth1 selects the nexthop object, while
one bound to veth3 falls back to another route in the same trie leaf.
Cover both a shorter prefix and a higher metric for the same prefix.
Signed-off-by: Yifei Sun <yifei.sun@inria.fr>
---
tools/testing/selftests/net/fib_nexthops.sh | 23 +++++++++++++++++++++++
1 file changed, 23 insertions(+)
diff --git a/tools/testing/selftests/net/fib_nexthops.sh b/tools/testing/selftests/net/fib_nexthops.sh
index adbec51917eb..38bb56f28187 100755
--- a/tools/testing/selftests/net/fib_nexthops.sh
+++ b/tools/testing/selftests/net/fib_nexthops.sh
@@ -22,6 +22,7 @@ ksft_skip=4
# all tests in this script. Can be overridden with -t option
IPV4_TESTS="
ipv4_fcnal
+ ipv4_oif_fallback
ipv4_grp_fcnal
ipv4_res_grp_fcnal
ipv4_withv6_fcnal
@@ -1535,6 +1536,28 @@ ipv6_res_torture()
log_test 0 0 "IPv6 resilient nexthop group torture test"
}
+ipv4_oif_fallback()
+{
+ local out
+
+ run_cmd "$IP nexthop add id 12 via 172.16.1.2 dev veth1"
+ run_cmd "$IP route add 10.0.0.0/24 nhid 12"
+ run_cmd "$IP route add 10.0.0.0/16 via 172.16.2.2 dev veth3"
+
+ out=$($IP -o route get fibmatch 10.0.0.1 oif veth1)
+ check_output "$out" "10.0.0.0/24 nhid 12 via 172.16.1.2 dev veth1"
+ log_test $? 0 "Lookup bound to nexthop device"
+
+ out=$($IP -o route get fibmatch 10.0.0.1 oif veth3)
+ check_output "$out" "10.0.0.0/16 via 172.16.2.2 dev veth3"
+ log_test $? 0 "Fallback to shorter prefix in the same leaf"
+
+ run_cmd "$IP route add 10.0.0.0/24 via 172.16.2.2 dev veth3 metric 20"
+ out=$($IP -o route get fibmatch 10.0.0.1 oif veth3)
+ check_output "$out" "10.0.0.0/24 via 172.16.2.2 dev veth3 metric 20"
+ log_test $? 0 "Fallback to higher metric for the same prefix"
+}
+
ipv4_fcnal()
{
local rc
^ permalink raw reply related [flat|nested] 4+ messages in thread* Re: [PATCH net 2/2] selftests: net: test IPv4 nexthop fallback in the same trie leaf
2026-11-21 18:20 ` [PATCH net 2/2] selftests: net: test IPv4 nexthop fallback in the same trie leaf Yifei Sun
@ 2026-11-24 15:37 ` Ido Schimmel
0 siblings, 0 replies; 4+ messages in thread
From: Ido Schimmel @ 2026-11-24 15:37 UTC (permalink / raw)
To: Yifei Sun
Cc: netdev, David Ahern, David S. Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, Willem de Bruijn, Simon Horman,
Nikolay Aleksandrov, Shuah Khan, linux-kselftest
On Sat, Nov 21, 2026 at 07:20:17PM +0100, Yifei Sun wrote:
> Check that a lookup bound to veth1 selects the nexthop object, while
> one bound to veth3 falls back to another route in the same trie leaf.
> Cover both a shorter prefix and a higher metric for the same prefix.
>
> Signed-off-by: Yifei Sun <yifei.sun@inria.fr>
> ---
> tools/testing/selftests/net/fib_nexthops.sh | 23 +++++++++++++++++++++++
> 1 file changed, 23 insertions(+)
>
> diff --git a/tools/testing/selftests/net/fib_nexthops.sh b/tools/testing/selftests/net/fib_nexthops.sh
> index adbec51917eb..38bb56f28187 100755
> --- a/tools/testing/selftests/net/fib_nexthops.sh
> +++ b/tools/testing/selftests/net/fib_nexthops.sh
> @@ -22,6 +22,7 @@ ksft_skip=4
> # all tests in this script. Can be overridden with -t option
> IPV4_TESTS="
> ipv4_fcnal
> + ipv4_oif_fallback
> ipv4_grp_fcnal
> ipv4_res_grp_fcnal
> ipv4_withv6_fcnal
Please add a matching test case for IPv6. Ideally both address families
should behave the same.
Also, this test is more about the lookup semantic than nexthop objects,
so I suggest moving it to fib_tests.sh.
I suggest four test cases:
ipv4_oif_fallback - Two routes with legacy nexthops. Should pass even
w/o the fix.
ipv4_oif_fallback_nh - Two routes with nexthop objects. Should fail w/o
the fix and pass with it.
Another two for IPv6 which should pass regardless of the fix.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH net 1/2] ipv4: keep scanning the leaf when a nexthop object is unusable
2026-11-21 18:20 [PATCH net 1/2] ipv4: keep scanning the leaf when a nexthop object is unusable Yifei Sun
2026-11-21 18:20 ` [PATCH net 2/2] selftests: net: test IPv4 nexthop fallback in the same trie leaf Yifei Sun
@ 2026-11-24 15:37 ` Ido Schimmel
1 sibling, 0 replies; 4+ messages in thread
From: Ido Schimmel @ 2026-11-24 15:37 UTC (permalink / raw)
To: Yifei Sun
Cc: netdev, David Ahern, David S. Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, Willem de Bruijn, Simon Horman,
Nikolay Aleksandrov, Shuah Khan, linux-kselftest
Diff itself looks correct. A few comments on the commit message below.
Please wait for the AI review (tomorrow) before posting v2.
On Sat, Nov 21, 2026 at 07:20:16PM +0100, Yifei Sun wrote:
> With veth1 on 172.16.1.0/24 and veth3 on 172.16.2.0/24:
>
> ```console
> $ 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
> ```
Strip the markdown formatting:
# ip nexthop add ..
# ip route add ...
>
> 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. Try the next alias,
> as for inline nexthops.
s/Try the next/Fix by trying the next/
>
> 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.
The last two paragraphs belong under the '---'.
>
> Fixes: af7888ad9edb ("ipv4: Refactor nhc evaluation in fib_table_lookup")
> Signed-off-by: Yifei Sun <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 @@ out_reject:
> &nhsel);
> if (nhc)
> goto set_result;
> - goto miss;
> + continue;
> }
>
> for (nhsel = 0; nhsel < fib_info_num_path(fi); nhsel++) {
> @@ -1622,7 +1622,6 @@ set_result:
> return err;
> }
> }
> -miss:
> #ifdef CONFIG_IP_FIB_TRIE_STATS
> this_cpu_inc(stats->semantic_match_miss);
> #endif
>
> base-commit: d5b89d55a322b632e2b465b392a4c1d9d338db9c
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-11-24 15:37 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-21 18:20 [PATCH net 1/2] ipv4: keep scanning the leaf when a nexthop object is unusable Yifei Sun
2026-11-21 18:20 ` [PATCH net 2/2] selftests: net: test IPv4 nexthop fallback in the same trie leaf Yifei Sun
2026-11-24 15:37 ` Ido Schimmel
2026-11-24 15:37 ` [PATCH net 1/2] ipv4: keep scanning the leaf when a nexthop object is unusable Ido Schimmel
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox