Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

selftests/net: convert fib_nexthop_multiprefix to run it in unique namespace

Here is the test result after conversion.

]# ./fib_nexthop_multiprefix.sh
TEST: IPv4: host 0 to host 1, mtu 1300 [ OK ]
TEST: IPv6: host 0 to host 1, mtu 1300 [ OK ]

TEST: IPv4: host 0 to host 2, mtu 1350 [ OK ]
TEST: IPv6: host 0 to host 2, mtu 1350 [ OK ]

TEST: IPv4: host 0 to host 3, mtu 1400 [ OK ]
TEST: IPv6: host 0 to host 3, mtu 1400 [ OK ]

TEST: IPv4: host 0 to host 1, mtu 1300 [ OK ]
TEST: IPv6: host 0 to host 1, mtu 1300 [ OK ]

TEST: IPv4: host 0 to host 2, mtu 1350 [ OK ]
TEST: IPv6: host 0 to host 2, mtu 1350 [ OK ]

TEST: IPv4: host 0 to host 3, mtu 1400 [ OK ]
TEST: IPv6: host 0 to host 3, mtu 1400 [ OK ]

Acked-by: David Ahern <dsahern@kernel.org>
Signed-off-by: Hangbin Liu <liuhangbin@gmail.com>
Link: https://lore.kernel.org/r/20231213060856.4030084-8-liuhangbin@gmail.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

authored by

Hangbin Liu and committed by
Jakub Kicinski
5ae89fe4 a33e9da3

+47 -49
+47 -49
tools/testing/selftests/net/fib_nexthop_multiprefix.sh
··· 12 12 # 13 13 # routing in h0 to hN is done with nexthop objects. 14 14 15 + source lib.sh 15 16 PAUSE_ON_FAIL=no 16 17 VERBOSE=0 17 18 ··· 73 72 { 74 73 local ns=${1} 75 74 76 - ip netns del ${ns} 2>/dev/null 77 - 78 - ip netns add ${ns} 79 - ip -netns ${ns} addr add 127.0.0.1/8 dev lo 80 - ip -netns ${ns} link set lo up 81 - 82 75 ip netns exec ${ns} sysctl -q -w net.ipv6.conf.all.keep_addr_on_down=1 83 76 case ${ns} in 84 77 h*) ··· 92 97 93 98 #set -e 94 99 95 - for ns in h0 r1 h1 h2 h3 100 + setup_ns h0 r1 h1 h2 h3 101 + h[0]=$h0 102 + h[1]=$h1 103 + h[2]=$h2 104 + h[3]=$h3 105 + r[1]=$r1 106 + for ns in ${h[0]} ${r[1]} ${h[1]} ${h[2]} ${h[3]} 96 107 do 97 108 create_ns ${ns} 98 109 done ··· 109 108 110 109 for i in 0 1 2 3 111 110 do 112 - ip -netns h${i} li add eth0 type veth peer name r1h${i} 113 - ip -netns h${i} li set eth0 up 114 - ip -netns h${i} li set r1h${i} netns r1 name eth${i} up 111 + ip -netns ${h[$i]} li add eth0 type veth peer name r1h${i} 112 + ip -netns ${h[$i]} li set eth0 up 113 + ip -netns ${h[$i]} li set r1h${i} netns ${r[1]} name eth${i} up 115 114 116 - ip -netns h${i} addr add dev eth0 172.16.10${i}.1/24 117 - ip -netns h${i} -6 addr add dev eth0 2001:db8:10${i}::1/64 118 - ip -netns r1 addr add dev eth${i} 172.16.10${i}.254/24 119 - ip -netns r1 -6 addr add dev eth${i} 2001:db8:10${i}::64/64 115 + ip -netns ${h[$i]} addr add dev eth0 172.16.10${i}.1/24 116 + ip -netns ${h[$i]} -6 addr add dev eth0 2001:db8:10${i}::1/64 117 + ip -netns ${r[1]} addr add dev eth${i} 172.16.10${i}.254/24 118 + ip -netns ${r[1]} -6 addr add dev eth${i} 2001:db8:10${i}::64/64 120 119 done 121 120 122 - ip -netns h0 nexthop add id 4 via 172.16.100.254 dev eth0 123 - ip -netns h0 nexthop add id 6 via 2001:db8:100::64 dev eth0 121 + ip -netns ${h[0]} nexthop add id 4 via 172.16.100.254 dev eth0 122 + ip -netns ${h[0]} nexthop add id 6 via 2001:db8:100::64 dev eth0 124 123 125 - # routing from h0 to h1-h3 and back 124 + # routing from ${h[0]} to h1-h3 and back 126 125 for i in 1 2 3 127 126 do 128 - ip -netns h0 ro add 172.16.10${i}.0/24 nhid 4 129 - ip -netns h${i} ro add 172.16.100.0/24 via 172.16.10${i}.254 127 + ip -netns ${h[0]} ro add 172.16.10${i}.0/24 nhid 4 128 + ip -netns ${h[$i]} ro add 172.16.100.0/24 via 172.16.10${i}.254 130 129 131 - ip -netns h0 -6 ro add 2001:db8:10${i}::/64 nhid 6 132 - ip -netns h${i} -6 ro add 2001:db8:100::/64 via 2001:db8:10${i}::64 130 + ip -netns ${h[0]} -6 ro add 2001:db8:10${i}::/64 nhid 6 131 + ip -netns ${h[$i]} -6 ro add 2001:db8:100::/64 via 2001:db8:10${i}::64 133 132 done 134 133 135 134 if [ "$VERBOSE" = "1" ]; then 136 135 echo 137 136 echo "host 1 config" 138 - ip -netns h0 li sh 139 - ip -netns h0 ro sh 140 - ip -netns h0 -6 ro sh 137 + ip -netns ${h[0]} li sh 138 + ip -netns ${h[0]} ro sh 139 + ip -netns ${h[0]} -6 ro sh 141 140 fi 142 141 143 142 #set +e ··· 145 144 146 145 cleanup() 147 146 { 148 - for n in h0 r1 h1 h2 h3 149 - do 150 - ip netns del ${n} 2>/dev/null 151 - done 147 + cleanup_all_ns 152 148 } 153 149 154 150 change_mtu() ··· 154 156 local mtu=$2 155 157 156 158 run_cmd ip -netns h${hostid} li set eth0 mtu ${mtu} 157 - run_cmd ip -netns r1 li set eth${hostid} mtu ${mtu} 159 + run_cmd ip -netns ${r1} li set eth${hostid} mtu ${mtu} 158 160 } 159 161 160 162 ################################################################################ ··· 166 168 local mtu=$2 167 169 local ping_sz=$3 168 170 local dst="172.16.10${i}.1" 169 - local h0=172.16.100.1 170 - local r1=172.16.100.254 171 + local h0_ip=172.16.100.1 172 + local r1_ip=172.16.100.254 171 173 local rc 172 174 173 175 if [ ${ping_sz} != "0" ]; then 174 - run_cmd ip netns exec h0 ping -s ${ping_sz} -c5 -w5 ${dst} 176 + run_cmd ip netns exec ${h0} ping -s ${ping_sz} -c5 -w5 ${dst} 175 177 fi 176 178 177 179 if [ "$VERBOSE" = "1" ]; then 178 180 echo "Route get" 179 - ip -netns h0 ro get ${dst} 181 + ip -netns ${h0} ro get ${dst} 180 182 echo "Searching for:" 181 183 echo " cache .* mtu ${mtu}" 182 184 echo 183 185 fi 184 186 185 - ip -netns h0 ro get ${dst} | \ 187 + ip -netns ${h0} ro get ${dst} | \ 186 188 grep -q "cache .* mtu ${mtu}" 187 189 rc=$? 188 190 ··· 195 197 local mtu=$2 196 198 local ping_sz=$3 197 199 local dst="2001:db8:10${i}::1" 198 - local h0=2001:db8:100::1 199 - local r1=2001:db8:100::64 200 + local h0_ip=2001:db8:100::1 201 + local r1_ip=2001:db8:100::64 200 202 local rc 201 203 202 204 if [ ${ping_sz} != "0" ]; then 203 - run_cmd ip netns exec h0 ${ping6} -s ${ping_sz} -c5 -w5 ${dst} 205 + run_cmd ip netns exec ${h0} ${ping6} -s ${ping_sz} -c5 -w5 ${dst} 204 206 fi 205 207 206 208 if [ "$VERBOSE" = "1" ]; then 207 209 echo "Route get" 208 - ip -netns h0 -6 ro get ${dst} 210 + ip -netns ${h0} -6 ro get ${dst} 209 211 echo "Searching for:" 210 - echo " ${dst}.* via ${r1} dev eth0 src ${h0} .* mtu ${mtu}" 212 + echo " ${dst}.* via ${r1_ip} dev eth0 src ${h0_ip} .* mtu ${mtu}" 211 213 echo 212 214 fi 213 215 214 - ip -netns h0 -6 ro get ${dst} | \ 215 - grep -q "${dst}.* via ${r1} dev eth0 src ${h0} .* mtu ${mtu}" 216 + ip -netns ${h0} -6 ro get ${dst} | \ 217 + grep -q "${dst}.* via ${r1_ip} dev eth0 src ${h0_ip} .* mtu ${mtu}" 216 218 rc=$? 217 219 218 220 log_test $rc 0 "IPv6: host 0 to host ${i}, mtu ${mtu}" ··· 240 242 do 241 243 # generate a cached route per-cpu 242 244 for c in ${cpus}; do 243 - run_cmd taskset -c ${c} ip netns exec h0 ping -c1 -w1 172.16.10${i}.1 244 - [ $? -ne 0 ] && printf "\nERROR: ping to h${i} failed\n" && ret=1 245 + run_cmd taskset -c ${c} ip netns exec ${h0} ping -c1 -w1 172.16.10${i}.1 246 + [ $? -ne 0 ] && printf "\nERROR: ping to ${h[$i]} failed\n" && ret=1 245 247 246 - run_cmd taskset -c ${c} ip netns exec h0 ${ping6} -c1 -w1 2001:db8:10${i}::1 247 - [ $? -ne 0 ] && printf "\nERROR: ping6 to h${i} failed\n" && ret=1 248 + run_cmd taskset -c ${c} ip netns exec ${h0} ${ping6} -c1 -w1 2001:db8:10${i}::1 249 + [ $? -ne 0 ] && printf "\nERROR: ping6 to ${h[$i]} failed\n" && ret=1 248 250 249 251 [ $ret -ne 0 ] && break 250 252 done ··· 280 282 validate_v6_exception 3 1400 0 281 283 282 284 # targeted deletes to trigger cleanup paths in kernel 283 - ip -netns h0 ro del 172.16.102.0/24 nhid 4 284 - ip -netns h0 -6 ro del 2001:db8:102::/64 nhid 6 285 + ip -netns ${h0} ro del 172.16.102.0/24 nhid 4 286 + ip -netns ${h0} -6 ro del 2001:db8:102::/64 nhid 6 285 287 286 - ip -netns h0 nexthop del id 4 287 - ip -netns h0 nexthop del id 6 288 + ip -netns ${h0} nexthop del id 4 289 + ip -netns ${h0} nexthop del id 6 288 290 fi 289 291 290 292 cleanup