2 # SPDX-License-Identifier: GPL-2.0
4 # Run traceroute/traceroute6 tests
11 ################################################################################
19 if [ ${rc} -eq ${expected} ]; then
20 printf "TEST: %-60s [ OK ]\n" "${msg}"
21 nsuccess
=$
((nsuccess
+1))
25 printf "TEST: %-60s [FAIL]\n" "${msg}"
26 if [ "${PAUSE_ON_FAIL}" = "yes" ]; then
28 echo "hit enter to continue, 'q' to quit"
30 [ "$a" = "q" ] && exit 1
46 if [ "$VERBOSE" = "1" ]; then
47 printf " COMMAND: $cmd\n"
50 out
=$
(eval ip netns
exec ${ns} ${cmd} 2>&1)
52 if [ "$VERBOSE" = "1" -a -n "$out" ]; then
56 [ "$VERBOSE" = "1" ] && echo
61 ################################################################################
62 # create namespaces and interconnects
70 [ -z "${addr}" ] && addr
="-"
71 [ -z "${addr6}" ] && addr6
="-"
73 if [ "${addr}" != "-" ]; then
74 ip netns
exec ${ns} ip addr add dev lo
${addr}
76 if [ "${addr6}" != "-" ]; then
77 ip netns
exec ${ns} ip
-6 addr add dev lo
${addr6}
80 ip netns
exec ${ns} ip ro add unreachable default metric
8192
81 ip netns
exec ${ns} ip
-6 ro add unreachable default metric
8192
83 ip netns
exec ${ns} sysctl
-qw net.ipv4.ip_forward
=1
84 ip netns
exec ${ns} sysctl
-qw net.ipv6.conf.all.keep_addr_on_down
=1
85 ip netns
exec ${ns} sysctl
-qw net.ipv6.conf.all.forwarding
=1
86 ip netns
exec ${ns} sysctl
-qw net.ipv6.conf.default.forwarding
=1
87 ip netns
exec ${ns} sysctl
-qw net.ipv6.conf.default.accept_dad
=0
90 # create veth pair to connect namespaces and apply addresses.
102 ip netns
exec ${ns1} ip li add
${ns1_dev} type veth peer name tmp
103 ip netns
exec ${ns1} ip li
set ${ns1_dev} up
104 ip netns
exec ${ns1} ip li set tmp netns ${ns2} name ${ns2_dev}
105 ip netns
exec ${ns2} ip li
set ${ns2_dev} up
107 if [ "${ns1_addr}" != "-" ]; then
108 ip netns
exec ${ns1} ip addr add dev ${ns1_dev} ${ns1_addr}
111 if [ "${ns2_addr}" != "-" ]; then
112 ip netns
exec ${ns2} ip addr add dev ${ns2_dev} ${ns2_addr}
115 if [ "${ns1_addr6}" != "-" ]; then
116 ip netns
exec ${ns1} ip addr add dev ${ns1_dev} ${ns1_addr6}
119 if [ "${ns2_addr6}" != "-" ]; then
120 ip netns
exec ${ns2} ip addr add dev ${ns2_dev} ${ns2_addr6}
124 ################################################################################
127 # Verify that in this scenario
129 # ------------------------ N2
131 # ------ ------ N3 ----
132 # | R1 | | R2 |------|H2|
135 # ------------------------ N1
141 # where H1's default route goes through R1 and R1's default route goes
142 # through R2 over N2, traceroute6 from H1 to H2 reports R2's address
145 # Addresses are assigned as follows:
151 # R1's host part of address: 1
152 # R2's host part of address: 2
153 # H1's host part of address: 3
154 # H2's host part of address: 4
157 # the IPv6 address of R1's interface on N2 is 2000:102::1/64
159 cleanup_traceroute6
()
161 cleanup_ns
$h1 $h2 $r1 $r2
179 connect_ns
$r2 eth3
- 2000:103::2/64 $h2 eth3
- 2000:103::4/64
180 ip netns
exec $h2 ip route add default via
2000:103::2
183 connect_ns
$r1 eth2
- 2000:102::1/64 $r2 eth2
- 2000:102::2/64
184 ip netns
exec $r1 ip route add default via
2000:102::2
186 # Setup N1. host-1 and router-2 connect to a bridge in router-1.
187 ip netns
exec $r1 ip link add name
${brdev} type bridge
188 ip netns
exec $r1 ip link
set ${brdev} up
189 ip netns
exec $r1 ip addr add
2000:101::1/64 dev
${brdev}
191 connect_ns
$h1 eth0
- 2000:101::3/64 $r1 eth0
- -
192 ip netns
exec $r1 ip link
set dev eth0 master
${brdev}
193 ip netns
exec $h1 ip route add default via
2000:101::1
195 connect_ns
$r2 eth1
- 2000:101::2/64 $r1 eth1
- -
196 ip netns
exec $r1 ip link
set dev eth1 master
${brdev}
199 ip netns
exec $h1 ping6
-c5 2000:103::4 >/dev
/null
2>&1
206 if [ ! -x "$(command -v traceroute6)" ]; then
207 echo "SKIP: Could not run IPV6 test without traceroute6"
213 # traceroute6 host-2 from host-1 (expects 2000:102::2)
214 run_cmd
$h1 "traceroute6 2000:103::4 | grep -q 2000:102::2"
215 log_test $?
0 "IPV6 traceroute"
220 ################################################################################
223 # Verify that traceroute from H1 to H2 shows 1.0.1.1 in this scenario
226 # ---- 1.0.1.3/24 1.0.1.1/24 ---- 1.0.2.1/24 1.0.2.4/24 ----
227 # |H1|--------------------------|R1|--------------------------|H2|
228 # ---- N1 ---- N2 ----
230 # where net.ipv4.icmp_errors_use_inbound_ifaddr is set on R1 and
231 # 1.0.3.1/24 and 1.0.1.1/24 are respectively R1's primary and secondary
237 cleanup_ns
$h1 $h2 $router
246 setup_ns h1 h2 router
251 connect_ns
$h1 eth0
1.0.1.3/24 - \
252 $router eth1
1.0.3.1/24 -
253 ip netns
exec $h1 ip route add default via
1.0.1.1
255 ip netns
exec $router ip addr add
1.0.1.1/24 dev eth1
256 ip netns
exec $router sysctl
-qw \
257 net.ipv4.icmp_errors_use_inbound_ifaddr
=1
259 connect_ns
$h2 eth0
1.0.2.4/24 - \
260 $router eth2
1.0.2.1/24 -
261 ip netns
exec $h2 ip route add default via
1.0.2.1
264 ip netns
exec $h1 ping -c5 1.0.2.4 >/dev
/null
2>&1
271 if [ ! -x "$(command -v traceroute)" ]; then
272 echo "SKIP: Could not run IPV4 test without traceroute"
278 # traceroute host-2 from host-1 (expects 1.0.1.1). Takes a while.
279 run_cmd
$h1 "traceroute 1.0.2.4 | grep -q 1.0.1.1"
280 log_test $?
0 "IPV4 traceroute"
285 ################################################################################
294 ################################################################################
298 declare -i nsuccess
=0
303 p
) PAUSE_ON_FAIL
=yes;;
304 v
) VERBOSE
=$
(($VERBOSE + 1));;
311 printf "\nTests passed: %3d\n" ${nsuccess}
312 printf "Tests failed: %3d\n" ${nfail}