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

selftests/net: convert vrf_route_leaking.sh to run it in unique namespace

Here is the test result after conversion.

]# ./vrf_route_leaking.sh

###########################################################################
IPv4 (sym route): VRF ICMP ttl error route lookup ping
###########################################################################

TEST: Basic IPv4 connectivity [ OK ]
TEST: Ping received ICMP ttl exceeded [ OK ]

...

TEST: Basic IPv6 connectivity [ OK ]
TEST: Traceroute6 reports a hop on r1 [ OK ]

Tests passed: 18
Tests failed: 0

Acked-by: David Ahern <dsahern@kernel.org>
Signed-off-by: Hangbin Liu <liuhangbin@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Hangbin Liu and committed by
David S. Miller
bedc99ab 5ece8371

+96 -105
+96 -105
tools/testing/selftests/net/vrf_route_leaking.sh
··· 58 58 # to send an ICMP error back to the source when the ttl of a packet reaches 1 59 59 # while it is forwarded between different vrfs. 60 60 61 + source lib.sh 61 62 VERBOSE=0 62 63 PAUSE_ON_FAIL=no 63 64 DEFAULT_TTYPE=sym ··· 172 171 173 172 cleanup() 174 173 { 175 - local ns 176 - 177 - for ns in h1 h2 r1 r2; do 178 - ip netns del $ns 2>/dev/null 179 - done 174 + cleanup_ns $h1 $h2 $r1 $r2 180 175 } 181 176 182 177 setup_vrf() ··· 209 212 210 213 # 211 214 # create nodes as namespaces 212 - # 213 - for ns in h1 h2 r1; do 214 - ip netns add $ns 215 - ip -netns $ns link set lo up 216 - 217 - case "${ns}" in 218 - h[12]) ip netns exec $ns sysctl -q -w net.ipv6.conf.all.forwarding=0 219 - ip netns exec $ns sysctl -q -w net.ipv6.conf.all.keep_addr_on_down=1 220 - ;; 221 - r1) ip netns exec $ns sysctl -q -w net.ipv4.ip_forward=1 222 - ip netns exec $ns sysctl -q -w net.ipv6.conf.all.forwarding=1 223 - esac 215 + setup_ns h1 h2 r1 216 + for ns in $h1 $h2 $r1; do 217 + if echo $ns | grep -q h[12]-; then 218 + ip netns exec $ns sysctl -q -w net.ipv6.conf.all.forwarding=0 219 + ip netns exec $ns sysctl -q -w net.ipv6.conf.all.keep_addr_on_down=1 220 + else 221 + ip netns exec $ns sysctl -q -w net.ipv4.ip_forward=1 222 + ip netns exec $ns sysctl -q -w net.ipv6.conf.all.forwarding=1 223 + fi 224 224 done 225 225 226 226 # 227 227 # create interconnects 228 228 # 229 - ip -netns h1 link add eth0 type veth peer name r1h1 230 - ip -netns h1 link set r1h1 netns r1 name eth0 up 229 + ip -netns $h1 link add eth0 type veth peer name r1h1 230 + ip -netns $h1 link set r1h1 netns $r1 name eth0 up 231 231 232 - ip -netns h2 link add eth0 type veth peer name r1h2 233 - ip -netns h2 link set r1h2 netns r1 name eth1 up 232 + ip -netns $h2 link add eth0 type veth peer name r1h2 233 + ip -netns $h2 link set r1h2 netns $r1 name eth1 up 234 234 235 235 # 236 236 # h1 237 237 # 238 - ip -netns h1 addr add dev eth0 ${H1_N1_IP}/24 239 - ip -netns h1 -6 addr add dev eth0 ${H1_N1_IP6}/64 nodad 240 - ip -netns h1 link set eth0 up 238 + ip -netns $h1 addr add dev eth0 ${H1_N1_IP}/24 239 + ip -netns $h1 -6 addr add dev eth0 ${H1_N1_IP6}/64 nodad 240 + ip -netns $h1 link set eth0 up 241 241 242 242 # h1 to h2 via r1 243 - ip -netns h1 route add ${H2_N2} via ${R1_N1_IP} dev eth0 244 - ip -netns h1 -6 route add ${H2_N2_6} via "${R1_N1_IP6}" dev eth0 243 + ip -netns $h1 route add ${H2_N2} via ${R1_N1_IP} dev eth0 244 + ip -netns $h1 -6 route add ${H2_N2_6} via "${R1_N1_IP6}" dev eth0 245 245 246 246 # 247 247 # h2 248 248 # 249 - ip -netns h2 addr add dev eth0 ${H2_N2_IP}/24 250 - ip -netns h2 -6 addr add dev eth0 ${H2_N2_IP6}/64 nodad 251 - ip -netns h2 link set eth0 up 249 + ip -netns $h2 addr add dev eth0 ${H2_N2_IP}/24 250 + ip -netns $h2 -6 addr add dev eth0 ${H2_N2_IP6}/64 nodad 251 + ip -netns $h2 link set eth0 up 252 252 253 253 # h2 to h1 via r1 254 - ip -netns h2 route add default via ${R1_N2_IP} dev eth0 255 - ip -netns h2 -6 route add default via ${R1_N2_IP6} dev eth0 254 + ip -netns $h2 route add default via ${R1_N2_IP} dev eth0 255 + ip -netns $h2 -6 route add default via ${R1_N2_IP6} dev eth0 256 256 257 257 # 258 258 # r1 259 259 # 260 - setup_vrf r1 261 - create_vrf r1 blue 1101 262 - create_vrf r1 red 1102 263 - ip -netns r1 link set mtu 1400 dev eth1 264 - ip -netns r1 link set eth0 vrf blue up 265 - ip -netns r1 link set eth1 vrf red up 266 - ip -netns r1 addr add dev eth0 ${R1_N1_IP}/24 267 - ip -netns r1 -6 addr add dev eth0 ${R1_N1_IP6}/64 nodad 268 - ip -netns r1 addr add dev eth1 ${R1_N2_IP}/24 269 - ip -netns r1 -6 addr add dev eth1 ${R1_N2_IP6}/64 nodad 260 + setup_vrf $r1 261 + create_vrf $r1 blue 1101 262 + create_vrf $r1 red 1102 263 + ip -netns $r1 link set mtu 1400 dev eth1 264 + ip -netns $r1 link set eth0 vrf blue up 265 + ip -netns $r1 link set eth1 vrf red up 266 + ip -netns $r1 addr add dev eth0 ${R1_N1_IP}/24 267 + ip -netns $r1 -6 addr add dev eth0 ${R1_N1_IP6}/64 nodad 268 + ip -netns $r1 addr add dev eth1 ${R1_N2_IP}/24 269 + ip -netns $r1 -6 addr add dev eth1 ${R1_N2_IP6}/64 nodad 270 270 271 271 # Route leak from blue to red 272 - ip -netns r1 route add vrf blue ${H2_N2} dev red 273 - ip -netns r1 -6 route add vrf blue ${H2_N2_6} dev red 272 + ip -netns $r1 route add vrf blue ${H2_N2} dev red 273 + ip -netns $r1 -6 route add vrf blue ${H2_N2_6} dev red 274 274 275 275 # Route leak from red to blue 276 - ip -netns r1 route add vrf red ${H1_N1} dev blue 277 - ip -netns r1 -6 route add vrf red ${H1_N1_6} dev blue 276 + ip -netns $r1 route add vrf red ${H1_N1} dev blue 277 + ip -netns $r1 -6 route add vrf red ${H1_N1_6} dev blue 278 278 279 279 280 280 # Wait for ip config to settle ··· 287 293 288 294 # 289 295 # create nodes as namespaces 290 - # 291 - for ns in h1 h2 r1 r2; do 292 - ip netns add $ns 293 - ip -netns $ns link set lo up 294 - 295 - case "${ns}" in 296 - h[12]) ip netns exec $ns sysctl -q -w net.ipv6.conf.all.forwarding=0 297 - ip netns exec $ns sysctl -q -w net.ipv6.conf.all.keep_addr_on_down=1 298 - ;; 299 - r[12]) ip netns exec $ns sysctl -q -w net.ipv4.ip_forward=1 300 - ip netns exec $ns sysctl -q -w net.ipv6.conf.all.forwarding=1 301 - esac 296 + setup_ns h1 h2 r1 r2 297 + for ns in $h1 $h2 $r1 $r2; do 298 + if echo $ns | grep -q h[12]-; then 299 + ip netns exec $ns sysctl -q -w net.ipv6.conf.all.forwarding=0 300 + ip netns exec $ns sysctl -q -w net.ipv6.conf.all.keep_addr_on_down=1 301 + else 302 + ip netns exec $ns sysctl -q -w net.ipv4.ip_forward=1 303 + ip netns exec $ns sysctl -q -w net.ipv6.conf.all.forwarding=1 304 + fi 302 305 done 303 306 304 307 # 305 308 # create interconnects 306 309 # 307 - ip -netns h1 link add eth0 type veth peer name r1h1 308 - ip -netns h1 link set r1h1 netns r1 name eth0 up 310 + ip -netns $h1 link add eth0 type veth peer name r1h1 311 + ip -netns $h1 link set r1h1 netns $r1 name eth0 up 309 312 310 - ip -netns h1 link add eth1 type veth peer name r2h1 311 - ip -netns h1 link set r2h1 netns r2 name eth0 up 313 + ip -netns $h1 link add eth1 type veth peer name r2h1 314 + ip -netns $h1 link set r2h1 netns $r2 name eth0 up 312 315 313 - ip -netns h2 link add eth0 type veth peer name r1h2 314 - ip -netns h2 link set r1h2 netns r1 name eth1 up 316 + ip -netns $h2 link add eth0 type veth peer name r1h2 317 + ip -netns $h2 link set r1h2 netns $r1 name eth1 up 315 318 316 - ip -netns h2 link add eth1 type veth peer name r2h2 317 - ip -netns h2 link set r2h2 netns r2 name eth1 up 319 + ip -netns $h2 link add eth1 type veth peer name r2h2 320 + ip -netns $h2 link set r2h2 netns $r2 name eth1 up 318 321 319 322 # 320 323 # h1 321 324 # 322 - ip -netns h1 link add br0 type bridge 323 - ip -netns h1 link set br0 up 324 - ip -netns h1 addr add dev br0 ${H1_N1_IP}/24 325 - ip -netns h1 -6 addr add dev br0 ${H1_N1_IP6}/64 nodad 326 - ip -netns h1 link set eth0 master br0 up 327 - ip -netns h1 link set eth1 master br0 up 325 + ip -netns $h1 link add br0 type bridge 326 + ip -netns $h1 link set br0 up 327 + ip -netns $h1 addr add dev br0 ${H1_N1_IP}/24 328 + ip -netns $h1 -6 addr add dev br0 ${H1_N1_IP6}/64 nodad 329 + ip -netns $h1 link set eth0 master br0 up 330 + ip -netns $h1 link set eth1 master br0 up 328 331 329 332 # h1 to h2 via r1 330 - ip -netns h1 route add ${H2_N2} via ${R1_N1_IP} dev br0 331 - ip -netns h1 -6 route add ${H2_N2_6} via "${R1_N1_IP6}" dev br0 333 + ip -netns $h1 route add ${H2_N2} via ${R1_N1_IP} dev br0 334 + ip -netns $h1 -6 route add ${H2_N2_6} via "${R1_N1_IP6}" dev br0 332 335 333 336 # 334 337 # h2 335 338 # 336 - ip -netns h2 link add br0 type bridge 337 - ip -netns h2 link set br0 up 338 - ip -netns h2 addr add dev br0 ${H2_N2_IP}/24 339 - ip -netns h2 -6 addr add dev br0 ${H2_N2_IP6}/64 nodad 340 - ip -netns h2 link set eth0 master br0 up 341 - ip -netns h2 link set eth1 master br0 up 339 + ip -netns $h2 link add br0 type bridge 340 + ip -netns $h2 link set br0 up 341 + ip -netns $h2 addr add dev br0 ${H2_N2_IP}/24 342 + ip -netns $h2 -6 addr add dev br0 ${H2_N2_IP6}/64 nodad 343 + ip -netns $h2 link set eth0 master br0 up 344 + ip -netns $h2 link set eth1 master br0 up 342 345 343 346 # h2 to h1 via r2 344 - ip -netns h2 route add default via ${R2_N2_IP} dev br0 345 - ip -netns h2 -6 route add default via ${R2_N2_IP6} dev br0 347 + ip -netns $h2 route add default via ${R2_N2_IP} dev br0 348 + ip -netns $h2 -6 route add default via ${R2_N2_IP6} dev br0 346 349 347 350 # 348 351 # r1 349 352 # 350 - setup_vrf r1 351 - create_vrf r1 blue 1101 352 - create_vrf r1 red 1102 353 - ip -netns r1 link set mtu 1400 dev eth1 354 - ip -netns r1 link set eth0 vrf blue up 355 - ip -netns r1 link set eth1 vrf red up 356 - ip -netns r1 addr add dev eth0 ${R1_N1_IP}/24 357 - ip -netns r1 -6 addr add dev eth0 ${R1_N1_IP6}/64 nodad 358 - ip -netns r1 addr add dev eth1 ${R1_N2_IP}/24 359 - ip -netns r1 -6 addr add dev eth1 ${R1_N2_IP6}/64 nodad 353 + setup_vrf $r1 354 + create_vrf $r1 blue 1101 355 + create_vrf $r1 red 1102 356 + ip -netns $r1 link set mtu 1400 dev eth1 357 + ip -netns $r1 link set eth0 vrf blue up 358 + ip -netns $r1 link set eth1 vrf red up 359 + ip -netns $r1 addr add dev eth0 ${R1_N1_IP}/24 360 + ip -netns $r1 -6 addr add dev eth0 ${R1_N1_IP6}/64 nodad 361 + ip -netns $r1 addr add dev eth1 ${R1_N2_IP}/24 362 + ip -netns $r1 -6 addr add dev eth1 ${R1_N2_IP6}/64 nodad 360 363 361 364 # Route leak from blue to red 362 - ip -netns r1 route add vrf blue ${H2_N2} dev red 363 - ip -netns r1 -6 route add vrf blue ${H2_N2_6} dev red 365 + ip -netns $r1 route add vrf blue ${H2_N2} dev red 366 + ip -netns $r1 -6 route add vrf blue ${H2_N2_6} dev red 364 367 365 368 # No route leak from red to blue 366 369 367 370 # 368 371 # r2 369 372 # 370 - ip -netns r2 addr add dev eth0 ${R2_N1_IP}/24 371 - ip -netns r2 -6 addr add dev eth0 ${R2_N1_IP6}/64 nodad 372 - ip -netns r2 addr add dev eth1 ${R2_N2_IP}/24 373 - ip -netns r2 -6 addr add dev eth1 ${R2_N2_IP6}/64 nodad 373 + ip -netns $r2 addr add dev eth0 ${R2_N1_IP}/24 374 + ip -netns $r2 -6 addr add dev eth0 ${R2_N1_IP6}/64 nodad 375 + ip -netns $r2 addr add dev eth1 ${R2_N2_IP}/24 376 + ip -netns $r2 -6 addr add dev eth1 ${R2_N2_IP6}/64 nodad 374 377 375 378 # Wait for ip config to settle 376 379 sleep 2 ··· 375 384 376 385 check_connectivity() 377 386 { 378 - ip netns exec h1 ping -c1 -w1 ${H2_N2_IP} >/dev/null 2>&1 387 + ip netns exec $h1 ping -c1 -w1 ${H2_N2_IP} >/dev/null 2>&1 379 388 log_test $? 0 "Basic IPv4 connectivity" 380 389 return $? 381 390 } 382 391 383 392 check_connectivity6() 384 393 { 385 - ip netns exec h1 "${ping6}" -c1 -w1 ${H2_N2_IP6} >/dev/null 2>&1 394 + ip netns exec $h1 "${ping6}" -c1 -w1 ${H2_N2_IP6} >/dev/null 2>&1 386 395 log_test $? 0 "Basic IPv6 connectivity" 387 396 return $? 388 397 } ··· 417 426 418 427 check_connectivity || return 419 428 420 - run_cmd_grep "${R1_N1_IP}" ip netns exec h1 traceroute ${H2_N2_IP} 429 + run_cmd_grep "${R1_N1_IP}" ip netns exec $h1 traceroute ${H2_N2_IP} 421 430 log_test $? 0 "Traceroute reports a hop on r1" 422 431 } 423 432 ··· 440 449 441 450 check_connectivity6 || return 442 451 443 - run_cmd_grep "${R1_N1_IP6}" ip netns exec h1 traceroute6 ${H2_N2_IP6} 452 + run_cmd_grep "${R1_N1_IP6}" ip netns exec $h1 traceroute6 ${H2_N2_IP6} 444 453 log_test $? 0 "Traceroute6 reports a hop on r1" 445 454 } 446 455 ··· 461 470 462 471 check_connectivity || return 463 472 464 - run_cmd_grep "Time to live exceeded" ip netns exec h1 ping -t1 -c1 -W2 ${H2_N2_IP} 473 + run_cmd_grep "Time to live exceeded" ip netns exec $h1 ping -t1 -c1 -W2 ${H2_N2_IP} 465 474 log_test $? 0 "Ping received ICMP ttl exceeded" 466 475 } 467 476 ··· 482 491 483 492 check_connectivity || return 484 493 485 - run_cmd_grep "Frag needed" ip netns exec h1 ping -s 1450 -Mdo -c1 -W2 ${H2_N2_IP} 494 + run_cmd_grep "Frag needed" ip netns exec $h1 ping -s 1450 -Mdo -c1 -W2 ${H2_N2_IP} 486 495 log_test $? 0 "Ping received ICMP Frag needed" 487 496 } 488 497 ··· 503 512 504 513 check_connectivity6 || return 505 514 506 - run_cmd_grep "Time exceeded: Hop limit" ip netns exec h1 "${ping6}" -t1 -c1 -W2 ${H2_N2_IP6} 515 + run_cmd_grep "Time exceeded: Hop limit" ip netns exec $h1 "${ping6}" -t1 -c1 -W2 ${H2_N2_IP6} 507 516 log_test $? 0 "Ping received ICMP Hop limit" 508 517 } 509 518 ··· 524 533 525 534 check_connectivity6 || return 526 535 527 - run_cmd_grep "Packet too big" ip netns exec h1 "${ping6}" -s 1450 -Mdo -c1 -W2 ${H2_N2_IP6} 536 + run_cmd_grep "Packet too big" ip netns exec $h1 "${ping6}" -s 1450 -Mdo -c1 -W2 ${H2_N2_IP6} 528 537 log_test $? 0 "Ping received ICMP Packet too big" 529 538 } 530 539