Skip to content

Commit 7b37947

Browse files
committed
Merge branch 'ipv4-relax-source-validation-check-for-loopback-packets'
Cong Wang says: ==================== ipv4: relax source validation check for loopback packets This patchset fixes a corner case when loopback packets get dropped by rp_filter when we route them from veth to lo. Patch 1 is the fix and patch 2 provides a simplified test case for this scenario. ==================== Signed-off-by: David S. Miller <davem@davemloft.net>
2 parents f1bf3e2 + adb701d commit 7b37947

2 files changed

Lines changed: 39 additions & 1 deletion

File tree

‎net/ipv4/fib_frontend.c‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,11 @@ static int __fib_validate_source(struct sk_buff *skb, __be32 src, __be32 dst,
388388
fib_combine_itag(itag, &res);
389389

390390
dev_match = fib_info_nh_uses_dev(res.fi, dev);
391+
/* This is not common, loopback packets retain skb_dst so normally they
392+
* would not even hit this slow path.
393+
*/
394+
dev_match = dev_match || (res.type == RTN_LOCAL &&
395+
dev == net->loopback_dev);
391396
if (dev_match) {
392397
ret = FIB_RES_NHC(res)->nhc_scope >= RT_SCOPE_HOST;
393398
return ret;

‎tools/testing/selftests/net/fib_tests.sh‎

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,13 @@ ret=0
99
ksft_skip=4
1010

1111
# all tests in this script. Can be overridden with -t option
12-
TESTS="unregister down carrier nexthop ipv6_rt ipv4_rt ipv6_addr_metric ipv4_addr_metric ipv6_route_metrics ipv4_route_metrics ipv4_route_v6_gw"
12+
TESTS="unregister down carrier nexthop ipv6_rt ipv4_rt ipv6_addr_metric ipv4_addr_metric ipv6_route_metrics ipv4_route_metrics ipv4_route_v6_gw rp_filter"
1313

1414
VERBOSE=0
1515
PAUSE_ON_FAIL=no
1616
PAUSE=no
1717
IP="ip -netns ns1"
18+
NS_EXEC="ip netns exec ns1"
1819

1920
log_test()
2021
{
@@ -433,6 +434,37 @@ fib_carrier_test()
433434
fib_carrier_unicast_test
434435
}
435436

437+
fib_rp_filter_test()
438+
{
439+
echo
440+
echo "IPv4 rp_filter tests"
441+
442+
setup
443+
444+
set -e
445+
$IP link set dev lo address 52:54:00:6a:c7:5e
446+
$IP link set dummy0 address 52:54:00:6a:c7:5e
447+
$IP link add dummy1 type dummy
448+
$IP link set dummy1 address 52:54:00:6a:c7:5e
449+
$IP link set dev dummy1 up
450+
$NS_EXEC sysctl -qw net.ipv4.conf.all.rp_filter=1
451+
$NS_EXEC sysctl -qw net.ipv4.conf.all.accept_local=1
452+
$NS_EXEC sysctl -qw net.ipv4.conf.all.route_localnet=1
453+
454+
$NS_EXEC tc qd add dev dummy1 parent root handle 1: fq_codel
455+
$NS_EXEC tc filter add dev dummy1 parent 1: protocol arp basic action mirred egress redirect dev lo
456+
$NS_EXEC tc filter add dev dummy1 parent 1: protocol ip basic action mirred egress redirect dev lo
457+
set +e
458+
459+
run_cmd "ip netns exec ns1 ping -I dummy1 -w1 -c1 198.51.100.1"
460+
log_test $? 0 "rp_filter passes local packets"
461+
462+
run_cmd "ip netns exec ns1 ping -I dummy1 -w1 -c1 127.0.0.1"
463+
log_test $? 0 "rp_filter passes loopback packets"
464+
465+
cleanup
466+
}
467+
436468
################################################################################
437469
# Tests on nexthop spec
438470

@@ -1557,6 +1589,7 @@ do
15571589
fib_unreg_test|unregister) fib_unreg_test;;
15581590
fib_down_test|down) fib_down_test;;
15591591
fib_carrier_test|carrier) fib_carrier_test;;
1592+
fib_rp_filter_test|rp_filter) fib_rp_filter_test;;
15601593
fib_nexthop_test|nexthop) fib_nexthop_test;;
15611594
ipv6_route_test|ipv6_rt) ipv6_route_test;;
15621595
ipv4_route_test|ipv4_rt) ipv4_route_test;;

0 commit comments

Comments
 (0)