Skip to content

Commit cd72e61

Browse files
NicolasDichtelPaolo Abeni
authored andcommitted
selftests/net: test nexthop without gw
This test implement the scenario described in the commit "ip: fix dflt addr selection for connected nexthop". The test configures a nexthop object with an output device only (no gateway address) and a route that uses this nexthop. The goal is to check if the kernel selects a valid source address. Link: https://lore.kernel.org/netdev/[email protected]/ Signed-off-by: Nicolas Dichtel <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Paolo Abeni <[email protected]>
1 parent 747c143 commit cd72e61

File tree

2 files changed

+120
-1
lines changed

2 files changed

+120
-1
lines changed

tools/testing/selftests/net/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ TEST_PROGS += udpgso_bench.sh fib_rule_tests.sh msg_zerocopy.sh psock_snd.sh
1111
TEST_PROGS += udpgro_bench.sh udpgro.sh test_vxlan_under_vrf.sh reuseport_addr_any.sh
1212
TEST_PROGS += test_vxlan_fdb_changelink.sh so_txtime.sh ipv6_flowlabel.sh
1313
TEST_PROGS += tcp_fastopen_backup_key.sh fcnal-test.sh l2tp.sh traceroute.sh
14-
TEST_PROGS += fin_ack_lat.sh fib_nexthop_multiprefix.sh fib_nexthops.sh
14+
TEST_PROGS += fin_ack_lat.sh fib_nexthop_multiprefix.sh fib_nexthops.sh fib_nexthop_nongw.sh
1515
TEST_PROGS += altnames.sh icmp.sh icmp_redirect.sh ip6_gre_headroom.sh
1616
TEST_PROGS += route_localnet.sh
1717
TEST_PROGS += reuseaddr_ports_exhausted.sh
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
#!/bin/bash
2+
# SPDX-License-Identifier: GPL-2.0
3+
#
4+
# ns: h1 | ns: h2
5+
# 192.168.0.1/24 |
6+
# eth0 |
7+
# | 192.168.1.1/32
8+
# veth0 <---|---> veth1
9+
# Validate source address selection for route without gateway
10+
11+
PAUSE_ON_FAIL=no
12+
VERBOSE=0
13+
ret=0
14+
15+
################################################################################
16+
# helpers
17+
18+
log_test()
19+
{
20+
local rc=$1
21+
local expected=$2
22+
local msg="$3"
23+
24+
if [ ${rc} -eq ${expected} ]; then
25+
printf "TEST: %-60s [ OK ]\n" "${msg}"
26+
nsuccess=$((nsuccess+1))
27+
else
28+
ret=1
29+
nfail=$((nfail+1))
30+
printf "TEST: %-60s [FAIL]\n" "${msg}"
31+
if [ "${PAUSE_ON_FAIL}" = "yes" ]; then
32+
echo
33+
echo "hit enter to continue, 'q' to quit"
34+
read a
35+
[ "$a" = "q" ] && exit 1
36+
fi
37+
fi
38+
39+
[ "$VERBOSE" = "1" ] && echo
40+
}
41+
42+
run_cmd()
43+
{
44+
local cmd="$*"
45+
local out
46+
local rc
47+
48+
if [ "$VERBOSE" = "1" ]; then
49+
echo "COMMAND: $cmd"
50+
fi
51+
52+
out=$(eval $cmd 2>&1)
53+
rc=$?
54+
if [ "$VERBOSE" = "1" -a -n "$out" ]; then
55+
echo "$out"
56+
fi
57+
58+
[ "$VERBOSE" = "1" ] && echo
59+
60+
return $rc
61+
}
62+
63+
################################################################################
64+
# config
65+
setup()
66+
{
67+
ip netns add h1
68+
ip -n h1 link set lo up
69+
ip netns add h2
70+
ip -n h2 link set lo up
71+
72+
# Add a fake eth0 to support an ip address
73+
ip -n h1 link add name eth0 type dummy
74+
ip -n h1 link set eth0 up
75+
ip -n h1 address add 192.168.0.1/24 dev eth0
76+
77+
# Configure veths (same @mac, arp off)
78+
ip -n h1 link add name veth0 type veth peer name veth1 netns h2
79+
ip -n h1 link set veth0 up
80+
81+
ip -n h2 link set veth1 up
82+
83+
# Configure @IP in the peer netns
84+
ip -n h2 address add 192.168.1.1/32 dev veth1
85+
ip -n h2 route add default dev veth1
86+
87+
# Add a nexthop without @gw and use it in a route
88+
ip -n h1 nexthop add id 1 dev veth0
89+
ip -n h1 route add 192.168.1.1 nhid 1
90+
}
91+
92+
cleanup()
93+
{
94+
ip netns del h1 2>/dev/null
95+
ip netns del h2 2>/dev/null
96+
}
97+
98+
trap cleanup EXIT
99+
100+
################################################################################
101+
# main
102+
103+
while getopts :pv o
104+
do
105+
case $o in
106+
p) PAUSE_ON_FAIL=yes;;
107+
v) VERBOSE=1;;
108+
esac
109+
done
110+
111+
cleanup
112+
setup
113+
114+
run_cmd ip -netns h1 route get 192.168.1.1
115+
log_test $? 0 "nexthop: get route with nexthop without gw"
116+
run_cmd ip netns exec h1 ping -c1 192.168.1.1
117+
log_test $? 0 "nexthop: ping through nexthop without gw"
118+
119+
exit $ret

0 commit comments

Comments
 (0)