* [PATCH net-next v4 1/4] ipv4: add FIB_LOOKUP_REPORT_MISS
2026-11-15 21:56 [PATCH net-next v4 0/4] ipv4: restrict on-link fallback to lookup misses liamsmith827
@ 2026-11-15 21:56 ` liamsmith827
2026-11-15 21:56 ` [PATCH net-next v4 2/4] ipv4: restrict on-link fallback to lookup misses liamsmith827
` (2 subsequent siblings)
3 siblings, 0 replies; 9+ messages in thread
From: liamsmith827 @ 2026-11-15 21:56 UTC (permalink / raw)
To: netdev
Cc: David Ahern, Ido Schimmel, David S. Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, Simon Horman, Shuah Khan,
linux-kselftest, linux-kernel, Liam Smith
From: Liam Smith <liamsmith827@proton.me>
Currently, fib_lookup() returns -ENETUNREACH for both a routing lookup
miss and an unreachable rule. These two cases must be distinguishable to
facilitate a fallback that only occurs when there's a miss.
Add a new FIB_LOOKUP flag that instructs lookups to return -ESRCH when
there's a miss.
Signed-off-by: Liam Smith <liamsmith827@proton.me>
---
include/net/fib_rules.h | 1 +
include/net/ip_fib.h | 6 +++---
net/ipv4/fib_rules.c | 2 +-
3 files changed, 5 insertions(+), 4 deletions(-)
diff --git a/include/net/fib_rules.h b/include/net/fib_rules.h
index c6b94790fa81..df1cb39ddf92 100644
--- a/include/net/fib_rules.h
+++ b/include/net/fib_rules.h
@@ -59,6 +59,7 @@ struct fib_lookup_arg {
int flags;
#define FIB_LOOKUP_NOREF 1
#define FIB_LOOKUP_IGNORE_LINKSTATE 2
+#define FIB_LOOKUP_REPORT_MISS 4
};
struct fib_rules_ops {
diff --git a/include/net/ip_fib.h b/include/net/ip_fib.h
index 92f4eb8b86d7..d0b4f261585a 100644
--- a/include/net/ip_fib.h
+++ b/include/net/ip_fib.h
@@ -318,7 +318,7 @@ static inline int fib_lookup(struct net *net, const struct flowi4 *flp,
struct fib_result *res, unsigned int flags)
{
struct fib_table *tb;
- int err = -ENETUNREACH;
+ int err = -EAGAIN;
rcu_read_lock();
@@ -327,7 +327,7 @@ static inline int fib_lookup(struct net *net, const struct flowi4 *flp,
err = fib_table_lookup(tb, flp, res, flags | FIB_LOOKUP_NOREF);
if (err == -EAGAIN)
- err = -ENETUNREACH;
+ err = (flags & FIB_LOOKUP_REPORT_MISS) ? -ESRCH : -ENETUNREACH;
rcu_read_unlock();
@@ -398,7 +398,7 @@ static inline int fib_lookup(struct net *net, struct flowi4 *flp,
err = fib_table_lookup(tb, flp, res, flags);
if (err == -EAGAIN)
- err = -ENETUNREACH;
+ err = (flags & FIB_LOOKUP_REPORT_MISS) ? -ESRCH : -ENETUNREACH;
out:
rcu_read_unlock();
diff --git a/net/ipv4/fib_rules.c b/net/ipv4/fib_rules.c
index 060501b376a8..3d7dcb8d0865 100644
--- a/net/ipv4/fib_rules.c
+++ b/net/ipv4/fib_rules.c
@@ -101,7 +101,7 @@ int __fib_lookup(struct net *net, struct flowi4 *flp,
res->tclassid = 0;
#endif
- if (err == -ESRCH)
+ if (err == -ESRCH && !(flags & FIB_LOOKUP_REPORT_MISS))
err = -ENETUNREACH;
return err;
--
2.47.3
^ permalink raw reply related [flat|nested] 9+ messages in thread* [PATCH net-next v4 2/4] ipv4: restrict on-link fallback to lookup misses
2026-11-15 21:56 [PATCH net-next v4 0/4] ipv4: restrict on-link fallback to lookup misses liamsmith827
2026-11-15 21:56 ` [PATCH net-next v4 1/4] ipv4: add FIB_LOOKUP_REPORT_MISS liamsmith827
@ 2026-11-15 21:56 ` liamsmith827
2026-11-16 22:08 ` netdev-bot+sashiko
2026-11-15 21:56 ` [PATCH net-next v4 3/4] selftests: net: test restricted on-link fallback liamsmith827
2026-11-15 21:56 ` [PATCH net-next v4 4/4] ipv4: replace obsolete routing comment liamsmith827
3 siblings, 1 reply; 9+ messages in thread
From: liamsmith827 @ 2026-11-15 21:56 UTC (permalink / raw)
To: netdev
Cc: David Ahern, Ido Schimmel, David S. Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, Simon Horman, Shuah Khan,
linux-kselftest, linux-kernel, Liam Smith
From: Liam Smith <liamsmith827@proton.me>
For non-vrf unicast, the on-link fallback currently occurs regardless of
the particular error returned by fib_lookup(). As a result, routes and
rules that are supposed to restrict traffic (blackhole, prohibit,
unreachable) are unable to do so comprehensively.
A specific example of this being a problem is within Android, where the
VPN "kill switch" is implemented with prohibit rules. Any process that
can set flowi4_oif (SO_BINDTODEVICE, IP_UNICAST_IF, IP_PKTINFO, etc.) is
able to utilize this fallback, meaning unprivileged Android apps can
trivially bypass the VPN. This is particularly bad on cellular networks,
where ARP is often not needed.
Restrict the fallback to routing lookup misses.
This was originally observed on an Android device, by way of packet
capture.
Tested fcnal-test.sh in UML with CONFIG_IP_MULTIPLE_TABLES both enabled
and disabled.
Signed-off-by: Liam Smith <liamsmith827@proton.me>
---
net/ipv4/route.c | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/net/ipv4/route.c b/net/ipv4/route.c
index 595a3b7f1783..03db105303b4 100644
--- a/net/ipv4/route.c
+++ b/net/ipv4/route.c
@@ -2849,12 +2849,13 @@ struct rtable *ip_route_output_key_hash_rcu(struct net *net, struct flowi4 *fl4,
goto make_route;
}
- err = fib_lookup(net, fl4, res, 0);
+ err = fib_lookup(net, fl4, res, FIB_LOOKUP_REPORT_MISS);
if (err) {
res->fi = NULL;
res->table = NULL;
if (fl4->flowi4_oif &&
- (ipv4_is_multicast(fl4->daddr) || !fl4->flowi4_l3mdev)) {
+ (ipv4_is_multicast(fl4->daddr) ||
+ (!fl4->flowi4_l3mdev && err == -ESRCH))) {
/* Apparently, routing tables are wrong. Assume,
* that the destination is on link.
*
@@ -2879,6 +2880,8 @@ struct rtable *ip_route_output_key_hash_rcu(struct net *net, struct flowi4 *fl4,
res->type = RTN_UNICAST;
goto make_route;
}
+ /* Reverse the mapping induced by FIB_LOOKUP_REPORT_MISS. */
+ err = err == -ESRCH ? -ENETUNREACH : err;
rth = ERR_PTR(err);
goto out;
}
--
2.47.3
^ permalink raw reply related [flat|nested] 9+ messages in thread* Re: [PATCH net-next v4 2/4] ipv4: restrict on-link fallback to lookup misses
2026-11-15 21:56 ` [PATCH net-next v4 2/4] ipv4: restrict on-link fallback to lookup misses liamsmith827
@ 2026-11-16 22:08 ` netdev-bot+sashiko
0 siblings, 0 replies; 9+ messages in thread
From: netdev-bot+sashiko @ 2026-11-16 22:08 UTC (permalink / raw)
To: liamsmith827
Cc: netdev, dsahern, idosch, davem, edumazet, kuba, pabeni, horms,
shuah, linux-kselftest, linux-kernel, liamsmith827
Thank you for your contribution! Sashiko AI review found more severe
issue(s) in other patches of this series. This mail is only an FYI, in case
you want to address the nit picks below when you respin.
Low priority / nit picks for your consideration:
- [Low] The commit "ipv4: restrict on-link fallback to lookup misses" is
written up as a bug fix with security impact: "unprivileged Android…
--
ipv4: restrict on-link fallback to lookup misses
This patch changes ip_route_output_key_hash_rcu() so that, for non-vrf
unicast with an oif set, the on-link fallback happens only when
fib_lookup() reports a lookup miss (-ESRCH via FIB_LOOKUP_REPORT_MISS).
Before, it happened for any lookup error. Blackhole, prohibit and
unreachable routes and rules are now honored for oif-bound sends, and
-ESRCH is mapped back to -ENETUNREACH on the error path.
> A specific example of this being a problem is within Android, where the
> VPN "kill switch" is implemented with prohibit rules. Any process that
> can set flowi4_oif (SO_BINDTODEVICE, IP_UNICAST_IF, IP_PKTINFO, etc.) is
> able to utilize this fallback, meaning unprivileged Android apps can
> trivially bypass the VPN. This is particularly bad on cellular networks,
> where ARP is often not needed.
[ ... ]
> Signed-off-by: Liam Smith <liamsmith827@proton.me>
[Severity: Low]
This isn't a code bug, but should the commit carry a Fixes: tag?
The message describes this as a fix for a VPN bypass. The trailer block
only has Signed-off-by. Documentation/process/maintainer-netdev.rst says:
"for fixes the Fixes: tag is required, regardless of the tree"
In ip_route_output_key_hash_rcu(), falling back to on-link for any
fib_lookup() error goes back to:
1da177e4c3f4 ("Linux-2.6.12-rc2")
The baseline form of the condition this patch changes:
(ipv4_is_multicast(fl4->daddr) || !fl4->flowi4_l3mdev)
comes from:
40867d74c374 ("net: Add l3mdev index to flow struct and avoid oif reset for port devices")
Could one of these be named in a Fixes: tag? That would make it clear
whether this change is meant for stable. It also changes what oif-bound
sockets see when they hit reject routes or rules: those sends now return
an error instead of going out on-link.
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261115215640.18728-1-liamsmith827%40grapheneos.org
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH net-next v4 3/4] selftests: net: test restricted on-link fallback
2026-11-15 21:56 [PATCH net-next v4 0/4] ipv4: restrict on-link fallback to lookup misses liamsmith827
2026-11-15 21:56 ` [PATCH net-next v4 1/4] ipv4: add FIB_LOOKUP_REPORT_MISS liamsmith827
2026-11-15 21:56 ` [PATCH net-next v4 2/4] ipv4: restrict on-link fallback to lookup misses liamsmith827
@ 2026-11-15 21:56 ` liamsmith827
2026-11-16 8:59 ` Ido Schimmel
2026-11-16 22:08 ` netdev-bot+sashiko
2026-11-15 21:56 ` [PATCH net-next v4 4/4] ipv4: replace obsolete routing comment liamsmith827
3 siblings, 2 replies; 9+ messages in thread
From: liamsmith827 @ 2026-11-15 21:56 UTC (permalink / raw)
To: netdev
Cc: David Ahern, Ido Schimmel, David S. Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, Simon Horman, Shuah Khan,
linux-kselftest, linux-kernel, Liam Smith
From: Liam Smith <liamsmith827@proton.me>
Following the previous patch, the on-link fallback is no longer taken
when the FIB lookup hits an unreachable, blackhole or prohibit route/
rule. Adjust the IPv4 tests accordingly:
1. ipv4_ping_novrf(): Pinging a loopback address while bound to a
device now fails with an error instead of timing out, since the lookup
hits the unreachable default route. Adjust the expected return code.
2. ipv4_ping_novrf(): Add a variant of the above without the
unreachable default route, to make sure that the fallback is still
taken upon a route miss.
3. ipv4_ping_novrf(): Add a test that demonstrates ping fails as
expected with an unreachable rule. This ensures FIB_LOOKUP_REPORT_MISS
does not break this behavior.
4. ipv4_ping_novrf(): Enable the device bind test cases that were
commented out because of the fallback (prohibit rule, unreachable route
and unreachable default route).
5. ipv4_udp_novrf(): Connecting to a loopback address while bound to a
device now fails with an error instead of timing out. Adjust the
expected return code.
With the exception of the route miss and unreachable ping test cases,
which are specific to IPv4, the IPv4 test cases are now aligned with
their IPv6 counterparts.
Signed-off-by: Liam Smith <liamsmith827@proton.me>
---
tools/testing/selftests/net/fcnal-test.sh | 53 ++++++++++++++---------
1 file changed, 32 insertions(+), 21 deletions(-)
diff --git a/tools/testing/selftests/net/fcnal-test.sh b/tools/testing/selftests/net/fcnal-test.sh
index a50609535fed..9722d7dcad08 100755
--- a/tools/testing/selftests/net/fcnal-test.sh
+++ b/tools/testing/selftests/net/fcnal-test.sh
@@ -619,17 +619,30 @@ ipv4_ping_novrf()
run_cmd ping -c1 -w1 -I ${NSA_DEV} ${a}
log_test_addr ${a} $? 0 "ping local, device bind"
- # loopback addresses not reachable from device bind
- # fails in a really weird way though because ipv4 special cases
- # route lookups with oif set.
+ # loopback addresses not reachable from device bind, unreachable
+ # default route
for a in ${NSA_LO_IP} 127.0.0.1
do
log_start
show_hint "Fails since address on loopback device is out of device scope"
run_cmd ping -c1 -w1 -I ${NSA_DEV} ${a}
- log_test_addr ${a} $? 1 "ping local, device bind"
+ log_test_addr ${a} $? 2 "ping local, device bind, unreachable default route"
done
+ # loopback addresses not reachable from device bind, route miss
+ log_start
+ setup_cmd ip route del unreachable default metric 8192
+
+ for a in ${NSA_LO_IP} 127.0.0.1
+ do
+ log_start
+ show_hint "Fails since address on loopback device is out of device scope"
+ run_cmd ping -c1 -w1 -I ${NSA_DEV} ${a}
+ log_test_addr ${a} $? 1 "ping local, device bind, route miss"
+ done
+
+ setup_cmd ip route add unreachable default metric 8192
+
#
# ip rule blocks reachability to remote address
#
@@ -643,10 +656,14 @@ ipv4_ping_novrf()
run_cmd ping -c1 -w1 ${a}
log_test_addr ${a} $? 2 "ping out, blocked by rule"
- # NOTE: ipv4 actually allows the lookup to fail and yet still create
- # a viable rtable if the oif (e.g., bind to device) is set, so this
- # case succeeds despite the rule
- # run_cmd ping -c1 -w1 -I ${NSA_DEV} ${a}
+ log_start
+ setup_cmd ip rule add pref 49 to ${NSB_LO_IP} unreachable
+ log_test_addr ${a} $? 2 "ping out, blocked by unreachable rule"
+ setup_cmd ip rule del pref 49 to ${NSB_LO_IP} unreachable
+
+ log_start
+ run_cmd ping -c1 -w1 -I ${NSA_DEV} ${a}
+ log_test_addr ${a} $? 2 "ping out, device bind, blocked by rule"
a=${NSA_LO_IP}
log_start
@@ -671,10 +688,9 @@ ipv4_ping_novrf()
run_cmd ping -c1 -w1 ${a}
log_test_addr ${a} $? 2 "ping out, blocked by route"
- # NOTE: ipv4 actually allows the lookup to fail and yet still create
- # a viable rtable if the oif (e.g., bind to device) is set, so this
- # case succeeds despite not having a route for the address
- # run_cmd ping -c1 -w1 -I ${NSA_DEV} ${a}
+ log_start
+ run_cmd ping -c1 -w1 -I ${NSA_DEV} ${a}
+ log_test_addr ${a} $? 2 "ping out, device bind, blocked by route"
a=${NSA_LO_IP}
log_start
@@ -692,10 +708,9 @@ ipv4_ping_novrf()
run_cmd ping -c1 -w1 ${a}
log_test_addr ${a} $? 2 "ping out, unreachable default route"
- # NOTE: ipv4 actually allows the lookup to fail and yet still create
- # a viable rtable if the oif (e.g., bind to device) is set, so this
- # case succeeds despite not having a route for the address
- # run_cmd ping -c1 -w1 -I ${NSA_DEV} ${a}
+ log_start
+ run_cmd ping -c1 -w1 -I ${NSA_DEV} ${a}
+ log_test_addr ${a} $? 2 "ping out, device bind, unreachable default route"
}
ipv4_ping_vrf()
@@ -1602,10 +1617,6 @@ ipv4_udp_novrf()
run_cmd nettest -D -d ${NSA_DEV} -S -r ${a} -U
log_test_addr ${a} $? 0 "Global server, device client via IP_UNICAST_IF, local connection, with connect()"
-
- # IPv4 with device bind has really weird behavior - it overrides the
- # fib lookup, generates an rtable and tries to send the packet. This
- # causes failures for local traffic at different places
for a in ${NSA_LO_IP} 127.0.0.1
do
log_start
@@ -1613,7 +1624,7 @@ ipv4_udp_novrf()
run_cmd nettest -D -s &
wait_local_port_listen ${NSA} 12345 udp
run_cmd nettest -D -r ${a} -d ${NSA_DEV}
- log_test_addr ${a} $? 2 "Global server, device client, local connection"
+ log_test_addr ${a} $? 1 "Global server, device client, local connection"
log_start
show_hint "Should fail since addresses on loopback are out of device scope"
--
2.47.3
^ permalink raw reply related [flat|nested] 9+ messages in thread* Re: [PATCH net-next v4 3/4] selftests: net: test restricted on-link fallback
2026-11-15 21:56 ` [PATCH net-next v4 3/4] selftests: net: test restricted on-link fallback liamsmith827
@ 2026-11-16 8:59 ` Ido Schimmel
2026-11-16 20:27 ` liamsmith827
2026-11-16 22:08 ` netdev-bot+sashiko
1 sibling, 1 reply; 9+ messages in thread
From: Ido Schimmel @ 2026-11-16 8:59 UTC (permalink / raw)
To: liamsmith827
Cc: netdev, David Ahern, David S. Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, Simon Horman, Shuah Khan,
linux-kselftest, linux-kernel, Liam Smith
On Sun, Nov 15, 2026 at 09:56:39PM +0000, liamsmith827 wrote:
> From: Liam Smith <liamsmith827@proton.me>
>
> Following the previous patch, the on-link fallback is no longer taken
> when the FIB lookup hits an unreachable, blackhole or prohibit route/
> rule. Adjust the IPv4 tests accordingly:
>
> 1. ipv4_ping_novrf(): Pinging a loopback address while bound to a
> device now fails with an error instead of timing out, since the lookup
> hits the unreachable default route. Adjust the expected return code.
>
> 2. ipv4_ping_novrf(): Add a variant of the above without the
> unreachable default route, to make sure that the fallback is still
> taken upon a route miss.
>
> 3. ipv4_ping_novrf(): Add a test that demonstrates ping fails as
> expected with an unreachable rule. This ensures FIB_LOOKUP_REPORT_MISS
> does not break this behavior.
>
> 4. ipv4_ping_novrf(): Enable the device bind test cases that were
> commented out because of the fallback (prohibit rule, unreachable route
> and unreachable default route).
>
> 5. ipv4_udp_novrf(): Connecting to a loopback address while bound to a
> device now fails with an error instead of timing out. Adjust the
> expected return code.
>
> With the exception of the route miss and unreachable ping test cases,
> which are specific to IPv4, the IPv4 test cases are now aligned with
> their IPv6 counterparts.
>
> Signed-off-by: Liam Smith <liamsmith827@proton.me>
# ./fcnal-test.sh -t ipv4_ping
[...]
Tests passed: 122
Tests failed: 3
Don't submit tests without running them.
Needs:
diff --git a/tools/testing/selftests/net/fcnal-test.sh b/tools/testing/selftests/net/fcnal-test.sh
index 9722d7dcad08..7d51fdcc8fda 100755
--- a/tools/testing/selftests/net/fcnal-test.sh
+++ b/tools/testing/selftests/net/fcnal-test.sh
@@ -658,7 +658,8 @@ ipv4_ping_novrf()
log_start
setup_cmd ip rule add pref 49 to ${NSB_LO_IP} unreachable
- log_test_addr ${a} $? 2 "ping out, blocked by unreachable rule"
+ run_cmd ping -c1 -w1 -I ${NSA_DEV} ${a}
+ log_test_addr ${a} $? 2 "ping out, device bind, blocked by unreachable rule"
setup_cmd ip rule del pref 49 to ${NSB_LO_IP} unreachable
log_start
^ permalink raw reply related [flat|nested] 9+ messages in thread* Re: [PATCH net-next v4 3/4] selftests: net: test restricted on-link fallback
2026-11-16 8:59 ` Ido Schimmel
@ 2026-11-16 20:27 ` liamsmith827
0 siblings, 0 replies; 9+ messages in thread
From: liamsmith827 @ 2026-11-16 20:27 UTC (permalink / raw)
To: Ido Schimmel
Cc: netdev, David Ahern, David S. Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, Simon Horman, Shuah Khan,
linux-kselftest, linux-kernel, Liam Smith
On 11/16/26 08:59, Ido Schimmel wrote:
> Don't submit tests without running them.
My branch versioning is out of sync with my submission versioning and it
looks like I ran the tests on the wrong branch, sorry about that.
I've made a new submission, v5. This will be my final submission for
this issue unless we encounter any bugs as we begin shipping this
ourselves downstream.
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH net-next v4 3/4] selftests: net: test restricted on-link fallback
2026-11-15 21:56 ` [PATCH net-next v4 3/4] selftests: net: test restricted on-link fallback liamsmith827
2026-11-16 8:59 ` Ido Schimmel
@ 2026-11-16 22:08 ` netdev-bot+sashiko
1 sibling, 0 replies; 9+ messages in thread
From: netdev-bot+sashiko @ 2026-11-16 22:08 UTC (permalink / raw)
To: liamsmith827
Cc: netdev, dsahern, idosch, davem, edumazet, kuba, pabeni, horms,
shuah, linux-kselftest, linux-kernel, liamsmith827
Thank you for your contribution! Sashiko AI review found 2 potential
issue(s) to consider.
Critical: 0 · High: 0 · Medium: 1 · Low: 1
If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).
- [Medium] In ipv4_ping_novrf() (tools/testing/selftests/net/fcnal-
test.sh, lines 659-662), the new case "ping out, blocked by…
- [Low] Even with the missing ping added, the unreachable-rule case in
ipv4_ping_novrf() (fcnal-test.sh lines 659-662) has no device bind…
--
selftests: net: test restricted on-link fallback
This patch updates the IPv4 cases in fcnal-test.sh to match the new
on-link fallback behaviour. The fallback is no longer taken when the FIB
lookup hits an unreachable, blackhole or prohibit route or rule. It
changes the expected return codes, adds a route miss variant and an
unreachable rule case, and enables the device bind cases that were
previously commented out.
> diff --git a/tools/testing/selftests/net/fcnal-test.sh b/tools/testing/selftests/net/fcnal-test.sh
> index a50609535fedc..9722d7dcad085 100755
> --- a/tools/testing/selftests/net/fcnal-test.sh
> +++ b/tools/testing/selftests/net/fcnal-test.sh
[ ... ]
> @@ -643,10 +656,14 @@ ipv4_ping_novrf()
> run_cmd ping -c1 -w1 ${a}
> log_test_addr ${a} $? 2 "ping out, blocked by rule"
>
> - # NOTE: ipv4 actually allows the lookup to fail and yet still create
> - # a viable rtable if the oif (e.g., bind to device) is set, so this
> - # case succeeds despite the rule
> - # run_cmd ping -c1 -w1 -I ${NSA_DEV} ${a}
> + log_start
> + setup_cmd ip rule add pref 49 to ${NSB_LO_IP} unreachable
> + log_test_addr ${a} $? 2 "ping out, blocked by unreachable rule"
[Severity: Medium]
Is a ping missing here? Nothing runs between the rule add and
log_test_addr, so $? is the exit status of setup_cmd.
setup_cmd() exits the whole script if the command fails:
setup_cmd()
{
...
run_cmd ${cmd}
rc=$?
if [ $rc -ne 0 ]; then
...
exit $rc
fi
}
So when it returns here, $? is always 0. log_test_addr() then compares
0 against the expected value of 2. That means this case reports FAIL on
every run, and no packet is ever sent while the pref 49 unreachable rule
is installed.
The commit message says this case will "demonstrate ping fails as
expected with an unreachable rule" and that it "ensures
FIB_LOOKUP_REPORT_MISS does not break this behavior". As written, the
case checks neither.
Would adding run_cmd ping -c1 -w1 ${a} before log_test_addr fix this?
At this point a is still ${NSB_LO_IP}.
> + setup_cmd ip rule del pref 49 to ${NSB_LO_IP} unreachable
> +
> + log_start
> + run_cmd ping -c1 -w1 -I ${NSA_DEV} ${a}
> + log_test_addr ${a} $? 2 "ping out, device bind, blocked by rule"
[Severity: Low]
Even with the ping added, can the unreachable rule case catch a
FIB_LOOKUP_REPORT_MISS regression without a device bind?
In ip_route_output_key_hash_rcu(), the on-link fallback is only taken
when oif is set and err == -ESRCH. In every other case a miss is mapped
back:
err = err == -ESRCH ? -ENETUNREACH : err;
fib4_rule_action() returns -ENETUNREACH for FR_ACT_UNREACHABLE. With oif
unset, two cases give the same ping exit code of 2:
- the unreachable rule is correctly reported as -ENETUNREACH
- the rule is wrongly reported as a miss (-ESRCH), which is then
remapped to -ENETUNREACH
So a non-bound ping cannot tell them apart.
The device bind case that follows runs after the pref 49 rule has been
deleted. It hits the pref 50 prohibit rule (-EACCES), which never goes
through the -ESRCH vs -ENETUNREACH distinction.
Should there also be a run_cmd ping -c1 -w1 -I ${NSA_DEV} ${a} case,
expecting 2, while the pref 49 unreachable rule is still installed?
>
> a=${NSA_LO_IP}
> log_start
[ ... ]
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261115215640.18728-1-liamsmith827%40grapheneos.org
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH net-next v4 4/4] ipv4: replace obsolete routing comment
2026-11-15 21:56 [PATCH net-next v4 0/4] ipv4: restrict on-link fallback to lookup misses liamsmith827
` (2 preceding siblings ...)
2026-11-15 21:56 ` [PATCH net-next v4 3/4] selftests: net: test restricted on-link fallback liamsmith827
@ 2026-11-15 21:56 ` liamsmith827
3 siblings, 0 replies; 9+ messages in thread
From: liamsmith827 @ 2026-11-15 21:56 UTC (permalink / raw)
To: netdev
Cc: David Ahern, Ido Schimmel, David S. Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, Simon Horman, Shuah Khan,
linux-kselftest, linux-kernel, Liam Smith
From: Liam Smith <liamsmith827@proton.me>
Replace an existing comment which describes obsolete fib_lookup(),
MSG_DONTROUTE and IPv6 behavior.
Signed-off-by: Liam Smith <liamsmith827@proton.me>
---
net/ipv4/route.c | 26 ++++++++++----------------
1 file changed, 10 insertions(+), 16 deletions(-)
diff --git a/net/ipv4/route.c b/net/ipv4/route.c
index 03db105303b4..fcdcb63ba09e 100644
--- a/net/ipv4/route.c
+++ b/net/ipv4/route.c
@@ -2856,24 +2856,18 @@ struct rtable *ip_route_output_key_hash_rcu(struct net *net, struct flowi4 *fl4,
if (fl4->flowi4_oif &&
(ipv4_is_multicast(fl4->daddr) ||
(!fl4->flowi4_l3mdev && err == -ESRCH))) {
- /* Apparently, routing tables are wrong. Assume,
- * that the destination is on link.
+ /* When oif is specified, fib_lookup() is called
+ * primarily to determine if the destination is
+ * accessible directly or through a gateway. It also
+ * checks whether there are any traffic restrictions
+ * (blackhole, prohibit, unreachable), or if there's a
+ * routing lookup miss.
*
- * WHY? DW.
- * Because we are allowed to send to iface
- * even if it has NO routes and NO assigned
- * addresses. When oif is specified, routing
- * tables are looked up with only one purpose:
- * to catch if destination is gatewayed, rather than
- * direct. Moreover, if MSG_DONTROUTE is set,
- * we send packet, ignoring both routing tables
- * and ifaddr state. --ANK
- *
- *
- * We could make it even if oif is unknown,
- * likely IPv6, but we do not.
+ * Multicast is sent regardless of restriction or miss.
+ * Non-vrf unicast honors restrictions but allows
+ * oif-bound sends even when oif has no routes. In both
+ * cases the destination is assumed on-link.
*/
-
if (fl4->saddr == 0)
fl4->saddr = inet_select_addr(dev_out, 0,
RT_SCOPE_LINK);
--
2.47.3
^ permalink raw reply related [flat|nested] 9+ messages in thread