Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) #!/bin/bash
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) # SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3) #
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4) # Run traceroute/traceroute6 tests
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5) #
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7) VERBOSE=0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) PAUSE_ON_FAIL=no
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) ################################################################################
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) log_test()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) 	local rc=$1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) 	local expected=$2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) 	local msg="$3"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) 	if [ ${rc} -eq ${expected} ]; then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) 		printf "TEST: %-60s  [ OK ]\n" "${msg}"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) 		nsuccess=$((nsuccess+1))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) 		ret=1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) 		nfail=$((nfail+1))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) 		printf "TEST: %-60s  [FAIL]\n" "${msg}"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 		if [ "${PAUSE_ON_FAIL}" = "yes" ]; then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) 			echo
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 			echo "hit enter to continue, 'q' to quit"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 			read a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 			[ "$a" = "q" ] && exit 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 		fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 	fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) run_cmd()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 	local ns
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 	local cmd
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 	local out
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 	local rc
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 	ns="$1"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 	shift
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 	cmd="$*"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 	if [ "$VERBOSE" = "1" ]; then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 		printf "    COMMAND: $cmd\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 	fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 	out=$(eval ip netns exec ${ns} ${cmd} 2>&1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 	rc=$?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 	if [ "$VERBOSE" = "1" -a -n "$out" ]; then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 		echo "    $out"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 	fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 	[ "$VERBOSE" = "1" ] && echo
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 	return $rc
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) ################################################################################
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) # create namespaces and interconnects
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) create_ns()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 	local ns=$1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 	local addr=$2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 	local addr6=$3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 	[ -z "${addr}" ] && addr="-"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 	[ -z "${addr6}" ] && addr6="-"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 	ip netns add ${ns}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 	ip netns exec ${ns} ip link set lo up
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	if [ "${addr}" != "-" ]; then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 		ip netns exec ${ns} ip addr add dev lo ${addr}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 	fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 	if [ "${addr6}" != "-" ]; then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 		ip netns exec ${ns} ip -6 addr add dev lo ${addr6}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 	fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 	ip netns exec ${ns} ip ro add unreachable default metric 8192
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 	ip netns exec ${ns} ip -6 ro add unreachable default metric 8192
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 	ip netns exec ${ns} sysctl -qw net.ipv4.ip_forward=1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 	ip netns exec ${ns} sysctl -qw net.ipv6.conf.all.keep_addr_on_down=1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 	ip netns exec ${ns} sysctl -qw net.ipv6.conf.all.forwarding=1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	ip netns exec ${ns} sysctl -qw net.ipv6.conf.default.forwarding=1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 	ip netns exec ${ns} sysctl -qw net.ipv6.conf.default.accept_dad=0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) # create veth pair to connect namespaces and apply addresses.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) connect_ns()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 	local ns1=$1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 	local ns1_dev=$2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	local ns1_addr=$3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 	local ns1_addr6=$4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 	local ns2=$5
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 	local ns2_dev=$6
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 	local ns2_addr=$7
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 	local ns2_addr6=$8
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 	ip netns exec ${ns1} ip li add ${ns1_dev} type veth peer name tmp
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 	ip netns exec ${ns1} ip li set ${ns1_dev} up
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 	ip netns exec ${ns1} ip li set tmp netns ${ns2} name ${ns2_dev}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 	ip netns exec ${ns2} ip li set ${ns2_dev} up
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 	if [ "${ns1_addr}" != "-" ]; then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 		ip netns exec ${ns1} ip addr add dev ${ns1_dev} ${ns1_addr}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 	fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 	if [ "${ns2_addr}" != "-" ]; then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 		ip netns exec ${ns2} ip addr add dev ${ns2_dev} ${ns2_addr}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 	fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 	if [ "${ns1_addr6}" != "-" ]; then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 		ip netns exec ${ns1} ip addr add dev ${ns1_dev} ${ns1_addr6}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 	fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 	if [ "${ns2_addr6}" != "-" ]; then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 		ip netns exec ${ns2} ip addr add dev ${ns2_dev} ${ns2_addr6}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 	fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) ################################################################################
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) # traceroute6 test
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) #
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) # Verify that in this scenario
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) #
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) #        ------------------------ N2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) #         |                    |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) #       ------              ------  N3  ----
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) #       | R1 |              | R2 |------|H2|
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) #       ------              ------      ----
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) #         |                    |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) #        ------------------------ N1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) #                  |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) #                 ----
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) #                 |H1|
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) #                 ----
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) #
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) # where H1's default route goes through R1 and R1's default route goes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) # through R2 over N2, traceroute6 from H1 to H2 reports R2's address
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) # on N2 and not N1.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) #
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) # Addresses are assigned as follows:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) #
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) # N1: 2000:101::/64
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) # N2: 2000:102::/64
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) # N3: 2000:103::/64
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) #
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) # R1's host part of address: 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) # R2's host part of address: 2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) # H1's host part of address: 3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) # H2's host part of address: 4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) #
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) # For example:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) # the IPv6 address of R1's interface on N2 is 2000:102::1/64
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) cleanup_traceroute6()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 	local ns
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 	for ns in host-1 host-2 router-1 router-2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 	do
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 		ip netns del ${ns} 2>/dev/null
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 	done
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) setup_traceroute6()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 	brdev=br0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 	# start clean
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 	cleanup_traceroute6
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 	set -e
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 	create_ns host-1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 	create_ns host-2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 	create_ns router-1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 	create_ns router-2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 	# Setup N3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 	connect_ns router-2 eth3 - 2000:103::2/64 host-2 eth3 - 2000:103::4/64
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 	ip netns exec host-2 ip route add default via 2000:103::2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 	# Setup N2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 	connect_ns router-1 eth2 - 2000:102::1/64 router-2 eth2 - 2000:102::2/64
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 	ip netns exec router-1 ip route add default via 2000:102::2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 	# Setup N1. host-1 and router-2 connect to a bridge in router-1.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 	ip netns exec router-1 ip link add name ${brdev} type bridge
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 	ip netns exec router-1 ip link set ${brdev} up
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 	ip netns exec router-1 ip addr add 2000:101::1/64 dev ${brdev}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 	connect_ns host-1 eth0 - 2000:101::3/64 router-1 eth0 - -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 	ip netns exec router-1 ip link set dev eth0 master ${brdev}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 	ip netns exec host-1 ip route add default via 2000:101::1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 	connect_ns router-2 eth1 - 2000:101::2/64 router-1 eth1 - -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 	ip netns exec router-1 ip link set dev eth1 master ${brdev}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 	# Prime the network
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 	ip netns exec host-1 ping6 -c5 2000:103::4 >/dev/null 2>&1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 	set +e
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) run_traceroute6()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 	if [ ! -x "$(command -v traceroute6)" ]; then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 		echo "SKIP: Could not run IPV6 test without traceroute6"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 		return
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 	fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 	setup_traceroute6
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 	# traceroute6 host-2 from host-1 (expects 2000:102::2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 	run_cmd host-1 "traceroute6 2000:103::4 | grep -q 2000:102::2"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 	log_test $? 0 "IPV6 traceroute"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 	cleanup_traceroute6
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) ################################################################################
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) # traceroute test
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) #
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) # Verify that traceroute from H1 to H2 shows 1.0.1.1 in this scenario
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) #
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) #                    1.0.3.1/24
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) # ---- 1.0.1.3/24    1.0.1.1/24 ---- 1.0.2.1/24    1.0.2.4/24 ----
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) # |H1|--------------------------|R1|--------------------------|H2|
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) # ----            N1            ----            N2            ----
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) #
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) # where net.ipv4.icmp_errors_use_inbound_ifaddr is set on R1 and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) # 1.0.3.1/24 and 1.0.1.1/24 are respectively R1's primary and secondary
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) # address on N1.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) #
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) cleanup_traceroute()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 	local ns
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 	for ns in host-1 host-2 router
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 	do
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 		ip netns del ${ns} 2>/dev/null
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 	done
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) setup_traceroute()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 	# start clean
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 	cleanup_traceroute
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 	set -e
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 	create_ns host-1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 	create_ns host-2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 	create_ns router
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 	connect_ns host-1 eth0 1.0.1.3/24 - \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 	           router eth1 1.0.3.1/24 -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 	ip netns exec host-1 ip route add default via 1.0.1.1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 	ip netns exec router ip addr add 1.0.1.1/24 dev eth1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 	ip netns exec router sysctl -qw \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 				net.ipv4.icmp_errors_use_inbound_ifaddr=1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 	connect_ns host-2 eth0 1.0.2.4/24 - \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 	           router eth2 1.0.2.1/24 -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 	ip netns exec host-2 ip route add default via 1.0.2.1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 	# Prime the network
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 	ip netns exec host-1 ping -c5 1.0.2.4 >/dev/null 2>&1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 	set +e
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) run_traceroute()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 	if [ ! -x "$(command -v traceroute)" ]; then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 		echo "SKIP: Could not run IPV4 test without traceroute"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 		return
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 	fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 	setup_traceroute
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 	# traceroute host-2 from host-1 (expects 1.0.1.1). Takes a while.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 	run_cmd host-1 "traceroute 1.0.2.4 | grep -q 1.0.1.1"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 	log_test $? 0 "IPV4 traceroute"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 	cleanup_traceroute
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) ################################################################################
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) # Run tests
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) run_tests()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 	run_traceroute6
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 	run_traceroute
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) ################################################################################
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) # main
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) declare -i nfail=0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) declare -i nsuccess=0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) while getopts :pv o
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) do
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 	case $o in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 		p) PAUSE_ON_FAIL=yes;;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 		v) VERBOSE=$(($VERBOSE + 1));;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 		*) exit 1;;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 	esac
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) done
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) run_tests
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) printf "\nTests passed: %3d\n" ${nsuccess}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) printf "Tests failed: %3d\n"   ${nfail}