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

selftests: net: use setup_ns for SRv6 tests and remove rp_filter configuration

Some SRv6 tests manually set up network namespaces and disable rp_filter.
Since the setup_ns library function already handles rp_filter configuration,
convert these SRv6 tests to use setup_ns and remove the redundant rp_filter
settings.

Signed-off-by: Hangbin Liu <liuhangbin@gmail.com>
Acked-by: Andrea Mayer <andrea.mayer@uniroma2.it>
Link: https://patch.msgid.link/20250508081910.84216-5-liuhangbin@gmail.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

authored by

Hangbin Liu and committed by
Jakub Kicinski
3f68f59e 69ea46e7

+76 -251
-5
tools/testing/selftests/net/srv6_end_dt46_l3vpn_test.sh
··· 285 285 ip netns exec ${hsname} sysctl -wq net.ipv6.conf.all.accept_dad=0 286 286 ip netns exec ${hsname} sysctl -wq net.ipv6.conf.default.accept_dad=0 287 287 288 - # disable the rp_filter otherwise the kernel gets confused about how 289 - # to route decap ipv4 packets. 290 - ip netns exec ${rtname} sysctl -wq net.ipv4.conf.all.rp_filter=0 291 - ip netns exec ${rtname} sysctl -wq net.ipv4.conf.default.rp_filter=0 292 - 293 288 ip -netns ${hsname} link add veth0 type veth peer name ${rtveth} 294 289 ip -netns ${hsname} link set ${rtveth} netns ${rtname} 295 290 ip -netns ${hsname} addr add ${IPv6_HS_NETWORK}::${hid}/64 dev veth0 nodad
-5
tools/testing/selftests/net/srv6_end_dt4_l3vpn_test.sh
··· 250 250 eval local rtname=\${rt_${rid}} 251 251 local rtveth=veth-t${tid} 252 252 253 - # disable the rp_filter otherwise the kernel gets confused about how 254 - # to route decap ipv4 packets. 255 - ip netns exec ${rtname} sysctl -wq net.ipv4.conf.all.rp_filter=0 256 - ip netns exec ${rtname} sysctl -wq net.ipv4.conf.default.rp_filter=0 257 - 258 253 ip -netns ${hsname} link add veth0 type veth peer name ${rtveth} 259 254 ip -netns ${hsname} link set ${rtveth} netns ${rtname} 260 255 ip -netns ${hsname} addr add ${IPv4_HS_NETWORK}.${hid}/24 dev veth0
+18 -59
tools/testing/selftests/net/srv6_end_next_csid_l3vpn_test.sh
··· 245 245 # that adopted in the use cases already examined (of course, it is necessary to 246 246 # consider the different SIDs/C-SIDs). 247 247 248 - # Kselftest framework requirement - SKIP code is 4. 249 - readonly ksft_skip=4 248 + source lib.sh 250 249 251 - readonly RDMSUFF="$(mktemp -u XXXXXXXX)" 252 250 readonly DUMMY_DEVNAME="dum0" 253 251 readonly VRF_TID=100 254 252 readonly VRF_DEVNAME="vrf-${VRF_TID}" ··· 374 376 fi 375 377 } 376 378 377 - get_nodename() 378 - { 379 - local name="$1" 380 - 381 - echo "${name}-${RDMSUFF}" 382 - } 383 - 384 379 get_rtname() 385 380 { 386 381 local rtid="$1" 387 382 388 - get_nodename "rt-${rtid}" 383 + echo "rt_${rtid}" 389 384 } 390 385 391 386 get_hsname() 392 387 { 393 388 local hsid="$1" 394 389 395 - get_nodename "hs-${hsid}" 396 - } 397 - 398 - __create_namespace() 399 - { 400 - local name="$1" 401 - 402 - ip netns add "${name}" 390 + echo "hs_${hsid}" 403 391 } 404 392 405 393 create_router() ··· 394 410 local nsname 395 411 396 412 nsname="$(get_rtname "${rtid}")" 397 - 398 - __create_namespace "${nsname}" 413 + setup_ns "${nsname}" 399 414 } 400 415 401 416 create_host() ··· 403 420 local nsname 404 421 405 422 nsname="$(get_hsname "${hsid}")" 406 - 407 - __create_namespace "${nsname}" 423 + setup_ns "${nsname}" 408 424 } 409 425 410 426 cleanup() 411 427 { 412 - local nsname 413 - local i 414 - 415 - # destroy routers 416 - for i in ${ROUTERS}; do 417 - nsname="$(get_rtname "${i}")" 418 - 419 - ip netns del "${nsname}" &>/dev/null || true 420 - done 421 - 422 - # destroy hosts 423 - for i in ${HOSTS}; do 424 - nsname="$(get_hsname "${i}")" 425 - 426 - ip netns del "${nsname}" &>/dev/null || true 427 - done 428 + cleanup_all_ns 428 429 429 430 # check whether the setup phase was completed successfully or not. In 430 431 # case of an error during the setup phase of the testing environment, ··· 429 462 local nsname 430 463 local neigh_nsname 431 464 432 - nsname="$(get_rtname "${rt}")" 465 + eval nsname=\${$(get_rtname "${rt}")} 433 466 434 467 for neigh in ${rt_neighs}; do 435 - neigh_nsname="$(get_rtname "${neigh}")" 468 + eval neigh_nsname=\${$(get_rtname "${neigh}")} 436 469 437 470 ip link add "veth-rt-${rt}-${neigh}" netns "${nsname}" \ 438 471 type veth peer name "veth-rt-${neigh}-${rt}" \ ··· 464 497 local devname 465 498 local neigh 466 499 467 - nsname="$(get_rtname "${rt}")" 500 + eval nsname=\${$(get_rtname "${rt}")} 468 501 469 502 for neigh in ${rt_neighs}; do 470 503 devname="veth-rt-${rt}-${neigh}" ··· 485 518 ip netns exec "${nsname}" sysctl -wq net.ipv6.conf.all.accept_dad=0 486 519 ip netns exec "${nsname}" sysctl -wq net.ipv6.conf.default.accept_dad=0 487 520 ip netns exec "${nsname}" sysctl -wq net.ipv6.conf.all.forwarding=1 488 - 489 - ip netns exec "${nsname}" sysctl -wq net.ipv4.conf.all.rp_filter=0 490 - ip netns exec "${nsname}" sysctl -wq net.ipv4.conf.default.rp_filter=0 491 521 ip netns exec "${nsname}" sysctl -wq net.ipv4.ip_forward=1 492 522 } 493 523 ··· 560 596 local lcnode_func_prefix 561 597 local lcblock_prefix 562 598 563 - nsname="$(get_rtname "${rt}")" 599 + eval nsname=\${$(get_rtname "${rt}")} 564 600 565 601 for neigh in ${rt_neighs}; do 566 602 devname="veth-rt-${rt}-${neigh}" ··· 632 668 local rtsrc_nsname 633 669 local rtdst_nsname 634 670 635 - rtsrc_nsname="$(get_rtname "${src}")" 636 - rtdst_nsname="$(get_rtname "${dst}")" 671 + eval rtsrc_nsname=\${$(get_rtname "${src}")} 672 + eval rtdst_nsname=\${$(get_rtname "${dst}")} 637 673 638 674 container="${LCBLOCK_ADDR}" 639 675 ··· 708 744 local hsname 709 745 local rtname 710 746 711 - hsname="$(get_hsname "${hs}")" 712 - rtname="$(get_rtname "${rt}")" 747 + eval hsname=\${$(get_hsname "${hs}")} 748 + eval rtname=\${$(get_rtname "${rt}")} 713 749 714 750 ip netns exec "${hsname}" sysctl -wq net.ipv6.conf.all.accept_dad=0 715 751 ip netns exec "${hsname}" sysctl -wq net.ipv6.conf.default.accept_dad=0 ··· 754 790 sysctl -wq net.ipv6.conf."${RT2HS_DEVNAME}".proxy_ndp=1 755 791 ip netns exec "${rtname}" \ 756 792 sysctl -wq net.ipv4.conf."${RT2HS_DEVNAME}".proxy_arp=1 757 - 758 - # disable the rp_filter otherwise the kernel gets confused about how 759 - # to route decap ipv4 packets. 760 - ip netns exec "${rtname}" \ 761 - sysctl -wq net.ipv4.conf."${RT2HS_DEVNAME}".rp_filter=0 762 793 763 794 ip netns exec "${rtname}" sh -c "echo 1 > /proc/sys/net/vrf/strict_mode" 764 795 } ··· 839 880 local prefix 840 881 local rtsrc_nsname 841 882 842 - rtsrc_nsname="$(get_rtname "${rtsrc}")" 883 + eval rtsrc_nsname=\${$(get_rtname "${rtsrc}")} 843 884 844 885 prefix="$(get_network_prefix "${rtsrc}" "${rtdst}")" 845 886 ··· 862 903 local hsdst="$2" 863 904 local hssrc_nsname 864 905 865 - hssrc_nsname="$(get_hsname "${hssrc}")" 906 + eval hssrc_nsname=\${$(get_hsname "${hssrc}")} 866 907 867 908 ip netns exec "${hssrc_nsname}" ping -c 1 -W "${PING_TIMEOUT_SEC}" \ 868 909 "${IPv6_HS_NETWORK}::${hsdst}" >/dev/null 2>&1 ··· 874 915 local hsdst="$2" 875 916 local hssrc_nsname 876 917 877 - hssrc_nsname="$(get_hsname "${hssrc}")" 918 + eval hssrc_nsname=\${$(get_hsname "${hssrc}")} 878 919 879 920 ip netns exec "${hssrc_nsname}" ping -c 1 -W "${PING_TIMEOUT_SEC}" \ 880 921 "${IPv4_HS_NETWORK}.${hsdst}" >/dev/null 2>&1 ··· 984 1025 local nsname 985 1026 local ret 986 1027 987 - nsname="$(get_rtname "${rt}")" 1028 + eval nsname=\${$(get_rtname "${rt}")} 988 1029 989 1030 __nextcsid_end_behavior_test "${nsname}" "add" "${blen}" "${flen}" 990 1031 ret="$?"
+21 -62
tools/testing/selftests/net/srv6_end_x_next_csid_l3vpn_test.sh
··· 287 287 # packet using the SRv6 End.DT46 behavior (associated with the SID fcff:1::d46) 288 288 # and sends it to the host hs-1. 289 289 290 - # Kselftest framework requirement - SKIP code is 4. 291 - readonly ksft_skip=4 290 + source lib.sh 292 291 293 - readonly RDMSUFF="$(mktemp -u XXXXXXXX)" 294 292 readonly DUMMY_DEVNAME="dum0" 295 293 readonly VRF_TID=100 296 294 readonly VRF_DEVNAME="vrf-${VRF_TID}" ··· 416 418 fi 417 419 } 418 420 419 - get_nodename() 420 - { 421 - local name="$1" 422 - 423 - echo "${name}-${RDMSUFF}" 424 - } 425 - 426 421 get_rtname() 427 422 { 428 423 local rtid="$1" 429 424 430 - get_nodename "rt-${rtid}" 425 + echo "rt_${rtid}" 431 426 } 432 427 433 428 get_hsname() 434 429 { 435 430 local hsid="$1" 436 431 437 - get_nodename "hs-${hsid}" 438 - } 439 - 440 - __create_namespace() 441 - { 442 - local name="$1" 443 - 444 - ip netns add "${name}" 432 + echo "hs_${hsid}" 445 433 } 446 434 447 435 create_router() ··· 436 452 local nsname 437 453 438 454 nsname="$(get_rtname "${rtid}")" 455 + setup_ns "${nsname}" 439 456 440 - __create_namespace "${nsname}" 441 - 457 + eval nsname=\${$(get_rtname "${rtid}")} 442 458 ip netns exec "${nsname}" sysctl -wq net.ipv6.conf.all.accept_dad=0 443 459 ip netns exec "${nsname}" sysctl -wq net.ipv6.conf.default.accept_dad=0 444 460 ip netns exec "${nsname}" sysctl -wq net.ipv6.conf.all.forwarding=1 445 - 446 - ip netns exec "${nsname}" sysctl -wq net.ipv4.conf.all.rp_filter=0 447 - ip netns exec "${nsname}" sysctl -wq net.ipv4.conf.default.rp_filter=0 448 461 ip netns exec "${nsname}" sysctl -wq net.ipv4.ip_forward=1 449 462 } 450 463 ··· 451 470 local nsname 452 471 453 472 nsname="$(get_hsname "${hsid}")" 454 - 455 - __create_namespace "${nsname}" 473 + setup_ns "${nsname}" 456 474 } 457 475 458 476 cleanup() 459 477 { 460 - local nsname 461 - local i 462 - 463 - # destroy routers 464 - for i in ${ROUTERS}; do 465 - nsname="$(get_rtname "${i}")" 466 - 467 - ip netns del "${nsname}" &>/dev/null || true 468 - done 469 - 470 - # destroy hosts 471 - for i in ${HOSTS}; do 472 - nsname="$(get_hsname "${i}")" 473 - 474 - ip netns del "${nsname}" &>/dev/null || true 475 - done 476 - 478 + cleanup_all_ns 477 479 # check whether the setup phase was completed successfully or not. In 478 480 # case of an error during the setup phase of the testing environment, 479 481 # the selftest is considered as "skipped". ··· 476 512 local nsname 477 513 local neigh_nsname 478 514 479 - nsname="$(get_rtname "${rt}")" 515 + eval nsname=\${$(get_rtname "${rt}")} 480 516 481 517 for neigh in ${rt_neighs}; do 482 - neigh_nsname="$(get_rtname "${neigh}")" 518 + eval neigh_nsname=\${$(get_rtname "${neigh}")} 483 519 484 520 ip link add "veth-rt-${rt}-${neigh}" netns "${nsname}" \ 485 521 type veth peer name "veth-rt-${neigh}-${rt}" \ ··· 511 547 local devname 512 548 local neigh 513 549 514 - nsname="$(get_rtname "${rt}")" 550 + eval nsname=\${$(get_rtname "${rt}")} 515 551 516 552 for neigh in ${rt_neighs}; do 517 553 devname="veth-rt-${rt}-${neigh}" ··· 595 631 local rt="$1" 596 632 local adj="$2" 597 633 598 - nsname="$(get_rtname "${rt}")" 634 + eval nsname=\${$(get_rtname "${rt}")} 599 635 net_prefix="$(get_network_prefix "${rt}" "${adj}")" 600 636 lcnode_func_prefix="$(build_lcnode_func_prefix "${rt}")" 601 637 ··· 614 650 local rt="$1" 615 651 local rt_neighs="$2" 616 652 617 - nsname="$(get_rtname "${rt}")" 653 + eval nsname=\${$(get_rtname "${rt}")} 618 654 619 655 for neigh in ${rt_neighs}; do 620 656 devname="veth-rt-${rt}-${neigh}" ··· 649 685 local lcnode_func_prefix 650 686 local lcblock_prefix 651 687 652 - nsname="$(get_rtname "${rt}")" 688 + eval nsname=\${$(get_rtname "${rt}")} 653 689 654 690 set_underlay_sids_reachability "${rt}" "${rt_neighs}" 655 691 ··· 692 728 local rtsrc_nsname 693 729 local rtdst_nsname 694 730 695 - rtsrc_nsname="$(get_rtname "${src}")" 696 - rtdst_nsname="$(get_rtname "${dst}")" 731 + eval rtsrc_nsname=\${$(get_rtname "${src}")} 732 + eval rtdst_nsname=\${$(get_rtname "${dst}")} 697 733 698 734 container="${LCBLOCK_ADDR}" 699 735 ··· 768 804 local hsname 769 805 local rtname 770 806 771 - hsname="$(get_hsname "${hs}")" 772 - rtname="$(get_rtname "${rt}")" 807 + eval hsname=\${$(get_hsname "${hs}")} 808 + eval rtname=\${$(get_rtname "${rt}")} 773 809 774 810 ip netns exec "${hsname}" sysctl -wq net.ipv6.conf.all.accept_dad=0 775 811 ip netns exec "${hsname}" sysctl -wq net.ipv6.conf.default.accept_dad=0 ··· 814 850 sysctl -wq net.ipv6.conf."${RT2HS_DEVNAME}".proxy_ndp=1 815 851 ip netns exec "${rtname}" \ 816 852 sysctl -wq net.ipv4.conf."${RT2HS_DEVNAME}".proxy_arp=1 817 - 818 - # disable the rp_filter otherwise the kernel gets confused about how 819 - # to route decap ipv4 packets. 820 - ip netns exec "${rtname}" \ 821 - sysctl -wq net.ipv4.conf."${RT2HS_DEVNAME}".rp_filter=0 822 853 823 854 ip netns exec "${rtname}" sh -c "echo 1 > /proc/sys/net/vrf/strict_mode" 824 855 } ··· 906 947 local prefix 907 948 local rtsrc_nsname 908 949 909 - rtsrc_nsname="$(get_rtname "${rtsrc}")" 950 + eval rtsrc_nsname=\${$(get_rtname "${rtsrc}")} 910 951 911 952 prefix="$(get_network_prefix "${rtsrc}" "${rtdst}")" 912 953 ··· 929 970 local hsdst="$2" 930 971 local hssrc_nsname 931 972 932 - hssrc_nsname="$(get_hsname "${hssrc}")" 973 + eval hssrc_nsname=\${$(get_hsname "${hssrc}")} 933 974 934 975 ip netns exec "${hssrc_nsname}" ping -c 1 -W "${PING_TIMEOUT_SEC}" \ 935 976 "${IPv6_HS_NETWORK}::${hsdst}" >/dev/null 2>&1 ··· 941 982 local hsdst="$2" 942 983 local hssrc_nsname 943 984 944 - hssrc_nsname="$(get_hsname "${hssrc}")" 985 + eval hssrc_nsname=\${$(get_hsname "${hssrc}")} 945 986 946 987 ip netns exec "${hssrc_nsname}" ping -c 1 -W "${PING_TIMEOUT_SEC}" \ 947 988 "${IPv4_HS_NETWORK}.${hsdst}" >/dev/null 2>&1 ··· 1052 1093 local nsname 1053 1094 local ret 1054 1095 1055 - nsname="$(get_rtname "${rt}")" 1096 + eval nsname=\${$(get_rtname "${rt}")} 1056 1097 1057 1098 __nextcsid_end_x_behavior_test "${nsname}" "add" "${blen}" "${flen}" 1058 1099 ret="$?"
+16 -58
tools/testing/selftests/net/srv6_hencap_red_l3vpn_test.sh
··· 166 166 # hs-4->hs-3 |IPv6 DA=fcff:1::e|SRH SIDs=fcff:3::d46|IPv6|...| (i.d) 167 167 # 168 168 169 - # Kselftest framework requirement - SKIP code is 4. 170 - readonly ksft_skip=4 169 + source lib.sh 171 170 172 - readonly RDMSUFF="$(mktemp -u XXXXXXXX)" 173 171 readonly VRF_TID=100 174 172 readonly VRF_DEVNAME="vrf-${VRF_TID}" 175 173 readonly RT2HS_DEVNAME="veth-t${VRF_TID}" ··· 246 248 fi 247 249 } 248 250 249 - get_nodename() 250 - { 251 - local name="$1" 252 - 253 - echo "${name}-${RDMSUFF}" 254 - } 255 - 256 251 get_rtname() 257 252 { 258 253 local rtid="$1" 259 254 260 - get_nodename "rt-${rtid}" 255 + echo "rt_${rtid}" 261 256 } 262 257 263 258 get_hsname() 264 259 { 265 260 local hsid="$1" 266 261 267 - get_nodename "hs-${hsid}" 268 - } 269 - 270 - __create_namespace() 271 - { 272 - local name="$1" 273 - 274 - ip netns add "${name}" 262 + echo "hs_${hsid}" 275 263 } 276 264 277 265 create_router() ··· 266 282 local nsname 267 283 268 284 nsname="$(get_rtname "${rtid}")" 269 - 270 - __create_namespace "${nsname}" 285 + setup_ns "${nsname}" 271 286 } 272 287 273 288 create_host() ··· 275 292 local nsname 276 293 277 294 nsname="$(get_hsname "${hsid}")" 278 - 279 - __create_namespace "${nsname}" 295 + setup_ns "${nsname}" 280 296 } 281 297 282 298 cleanup() 283 299 { 284 - local nsname 285 - local i 286 - 287 - # destroy routers 288 - for i in ${ROUTERS}; do 289 - nsname="$(get_rtname "${i}")" 290 - 291 - ip netns del "${nsname}" &>/dev/null || true 292 - done 293 - 294 - # destroy hosts 295 - for i in ${HOSTS}; do 296 - nsname="$(get_hsname "${i}")" 297 - 298 - ip netns del "${nsname}" &>/dev/null || true 299 - done 300 - 300 + cleanup_all_ns 301 301 # check whether the setup phase was completed successfully or not. In 302 302 # case of an error during the setup phase of the testing environment, 303 303 # the selftest is considered as "skipped". ··· 300 334 local nsname 301 335 local neigh_nsname 302 336 303 - nsname="$(get_rtname "${rt}")" 337 + eval nsname=\${$(get_rtname "${rt}")} 304 338 305 339 for neigh in ${rt_neighs}; do 306 - neigh_nsname="$(get_rtname "${neigh}")" 340 + eval neigh_nsname=\${$(get_rtname "${neigh}")} 307 341 308 342 ip link add "veth-rt-${rt}-${neigh}" netns "${nsname}" \ 309 343 type veth peer name "veth-rt-${neigh}-${rt}" \ ··· 335 369 local devname 336 370 local neigh 337 371 338 - nsname="$(get_rtname "${rt}")" 372 + eval nsname=\${$(get_rtname "${rt}")} 339 373 340 374 for neigh in ${rt_neighs}; do 341 375 devname="veth-rt-${rt}-${neigh}" ··· 353 387 ip netns exec "${nsname}" sysctl -wq net.ipv6.conf.all.accept_dad=0 354 388 ip netns exec "${nsname}" sysctl -wq net.ipv6.conf.default.accept_dad=0 355 389 ip netns exec "${nsname}" sysctl -wq net.ipv6.conf.all.forwarding=1 356 - 357 - ip netns exec "${nsname}" sysctl -wq net.ipv4.conf.all.rp_filter=0 358 - ip netns exec "${nsname}" sysctl -wq net.ipv4.conf.default.rp_filter=0 359 390 ip netns exec "${nsname}" sysctl -wq net.ipv4.ip_forward=1 360 391 } 361 392 ··· 366 403 local nsname 367 404 local neigh 368 405 369 - nsname="$(get_rtname "${rt}")" 406 + eval nsname=\${$(get_rtname "${rt}")} 370 407 371 408 for neigh in ${rt_neighs}; do 372 409 devname="veth-rt-${rt}-${neigh}" ··· 432 469 local policy='' 433 470 local n 434 471 435 - nsname="$(get_rtname "${encap_rt}")" 472 + eval nsname=\${$(get_rtname "${encap_rt}")} 436 473 437 474 for n in ${end_rts}; do 438 475 policy="${policy}${VPN_LOCATOR_SERVICE}:${n}::${END_FUNC}," ··· 479 516 local hsname 480 517 local rtname 481 518 482 - hsname="$(get_hsname "${hs}")" 483 - rtname="$(get_rtname "${rt}")" 519 + eval hsname=\${$(get_hsname "${hs}")} 520 + eval rtname=\${$(get_rtname "${rt}")} 484 521 485 522 ip netns exec "${hsname}" sysctl -wq net.ipv6.conf.all.accept_dad=0 486 523 ip netns exec "${hsname}" sysctl -wq net.ipv6.conf.default.accept_dad=0 ··· 517 554 sysctl -wq net.ipv6.conf."${RT2HS_DEVNAME}".proxy_ndp=1 518 555 ip netns exec "${rtname}" \ 519 556 sysctl -wq net.ipv4.conf."${RT2HS_DEVNAME}".proxy_arp=1 520 - 521 - # disable the rp_filter otherwise the kernel gets confused about how 522 - # to route decap ipv4 packets. 523 - ip netns exec "${rtname}" \ 524 - sysctl -wq net.ipv4.conf."${RT2HS_DEVNAME}".rp_filter=0 525 557 526 558 ip netns exec "${rtname}" sh -c "echo 1 > /proc/sys/net/vrf/strict_mode" 527 559 } ··· 614 656 local prefix 615 657 local rtsrc_nsname 616 658 617 - rtsrc_nsname="$(get_rtname "${rtsrc}")" 659 + eval rtsrc_nsname=\${$(get_rtname "${rtsrc}")} 618 660 619 661 prefix="$(get_network_prefix "${rtsrc}" "${rtdst}")" 620 662 ··· 637 679 local hsdst="$2" 638 680 local hssrc_nsname 639 681 640 - hssrc_nsname="$(get_hsname "${hssrc}")" 682 + eval hssrc_nsname=\${$(get_hsname "${hssrc}")} 641 683 642 684 ip netns exec "${hssrc_nsname}" ping -c 1 -W "${PING_TIMEOUT_SEC}" \ 643 685 "${IPv6_HS_NETWORK}::${hsdst}" >/dev/null 2>&1 ··· 649 691 local hsdst="$2" 650 692 local hssrc_nsname 651 693 652 - hssrc_nsname="$(get_hsname "${hssrc}")" 694 + eval hssrc_nsname=\${$(get_hsname "${hssrc}")} 653 695 654 696 ip netns exec "${hssrc_nsname}" ping -c 1 -W "${PING_TIMEOUT_SEC}" \ 655 697 "${IPv4_HS_NETWORK}.${hsdst}" >/dev/null 2>&1
+21 -62
tools/testing/selftests/net/srv6_hl2encap_red_l2vpn_test.sh
··· 116 116 # hs-2->hs-1 |IPv6 DA=fcff:4::e|SRH SIDs=fcff:3::e,fcff:1::d2|eth|...| (i.b) 117 117 # 118 118 119 - # Kselftest framework requirement - SKIP code is 4. 120 - readonly ksft_skip=4 119 + source lib.sh 121 120 122 - readonly RDMSUFF="$(mktemp -u XXXXXXXX)" 123 121 readonly DUMMY_DEVNAME="dum0" 124 122 readonly RT2HS_DEVNAME="veth-hs" 125 123 readonly HS_VETH_NAME="veth0" ··· 197 199 fi 198 200 } 199 201 200 - get_nodename() 201 - { 202 - local name="$1" 203 - 204 - echo "${name}-${RDMSUFF}" 205 - } 206 - 207 202 get_rtname() 208 203 { 209 204 local rtid="$1" 210 205 211 - get_nodename "rt-${rtid}" 206 + echo "rt_${rtid}" 212 207 } 213 208 214 209 get_hsname() 215 210 { 216 211 local hsid="$1" 217 212 218 - get_nodename "hs-${hsid}" 219 - } 220 - 221 - __create_namespace() 222 - { 223 - local name="$1" 224 - 225 - ip netns add "${name}" 213 + echo "hs_${hsid}" 226 214 } 227 215 228 216 create_router() ··· 217 233 local nsname 218 234 219 235 nsname="$(get_rtname "${rtid}")" 220 - 221 - __create_namespace "${nsname}" 236 + setup_ns "${nsname}" 222 237 } 223 238 224 239 create_host() ··· 226 243 local nsname 227 244 228 245 nsname="$(get_hsname "${hsid}")" 229 - 230 - __create_namespace "${nsname}" 246 + setup_ns "${nsname}" 231 247 } 232 248 233 249 cleanup() 234 250 { 235 - local nsname 236 - local i 237 - 238 - # destroy routers 239 - for i in ${ROUTERS}; do 240 - nsname="$(get_rtname "${i}")" 241 - 242 - ip netns del "${nsname}" &>/dev/null || true 243 - done 244 - 245 - # destroy hosts 246 - for i in ${HOSTS}; do 247 - nsname="$(get_hsname "${i}")" 248 - 249 - ip netns del "${nsname}" &>/dev/null || true 250 - done 251 + cleanup_all_ns 251 252 252 253 # check whether the setup phase was completed successfully or not. In 253 254 # case of an error during the setup phase of the testing environment, ··· 252 285 local nsname 253 286 local neigh_nsname 254 287 255 - nsname="$(get_rtname "${rt}")" 288 + eval nsname=\${$(get_rtname "${rt}")} 256 289 257 290 for neigh in ${rt_neighs}; do 258 - neigh_nsname="$(get_rtname "${neigh}")" 291 + eval neigh_nsname=\${$(get_rtname "${neigh}")} 259 292 260 293 ip link add "veth-rt-${rt}-${neigh}" netns "${nsname}" \ 261 294 type veth peer name "veth-rt-${neigh}-${rt}" \ ··· 287 320 local devname 288 321 local neigh 289 322 290 - nsname="$(get_rtname "${rt}")" 323 + eval nsname=\${$(get_rtname "${rt}")} 291 324 292 325 for neigh in ${rt_neighs}; do 293 326 devname="veth-rt-${rt}-${neigh}" ··· 308 341 ip netns exec "${nsname}" sysctl -wq net.ipv6.conf.all.accept_dad=0 309 342 ip netns exec "${nsname}" sysctl -wq net.ipv6.conf.default.accept_dad=0 310 343 ip netns exec "${nsname}" sysctl -wq net.ipv6.conf.all.forwarding=1 311 - 312 - ip netns exec "${nsname}" sysctl -wq net.ipv4.conf.all.rp_filter=0 313 - ip netns exec "${nsname}" sysctl -wq net.ipv4.conf.default.rp_filter=0 314 344 ip netns exec "${nsname}" sysctl -wq net.ipv4.ip_forward=1 315 345 } 316 346 ··· 321 357 local nsname 322 358 local neigh 323 359 324 - nsname="$(get_rtname "${rt}")" 360 + eval nsname=\${$(get_rtname "${rt}")} 325 361 326 362 for neigh in ${rt_neighs}; do 327 363 devname="veth-rt-${rt}-${neigh}" ··· 371 407 local policy='' 372 408 local n 373 409 374 - nsname="$(get_rtname "${encap_rt}")" 410 + eval nsname=\${$(get_rtname "${encap_rt}")} 375 411 376 412 for n in ${end_rts}; do 377 413 policy="${policy}${VPN_LOCATOR_SERVICE}:${n}::${END_FUNC}," ··· 410 446 local rt="$1" 411 447 local nsname 412 448 413 - nsname="$(get_rtname "${rt}")" 449 + eval nsname=\${$(get_rtname "${rt}")} 414 450 415 451 # Local End.DX2 behavior 416 452 ip -netns "${nsname}" -6 route \ ··· 427 463 local hsname 428 464 local rtname 429 465 430 - hsname="$(get_hsname "${hs}")" 431 - rtname="$(get_rtname "${rt}")" 466 + eval hsname=\${$(get_hsname "${hs}")} 467 + eval rtname=\${$(get_rtname "${rt}")} 432 468 433 469 ip netns exec "${hsname}" sysctl -wq net.ipv6.conf.all.accept_dad=0 434 470 ip netns exec "${hsname}" sysctl -wq net.ipv6.conf.default.accept_dad=0 ··· 450 486 add "${IPv4_HS_NETWORK}.254/24" dev "${RT2HS_DEVNAME}" 451 487 452 488 ip -netns "${rtname}" link set "${RT2HS_DEVNAME}" up 453 - 454 - # disable the rp_filter otherwise the kernel gets confused about how 455 - # to route decap ipv4 packets. 456 - ip netns exec "${rtname}" \ 457 - sysctl -wq net.ipv4.conf."${RT2HS_DEVNAME}".rp_filter=0 458 489 } 459 490 460 491 # set an auto-generated mac address ··· 467 508 local ifname="$4" 468 509 local nsname 469 510 470 - nsname=$(get_nodename "${nodename}") 511 + eval nsname=\${${nodename}} 471 512 472 513 ip -netns "${nsname}" link set dev "${ifname}" down 473 514 ··· 491 532 local hssrc_name 492 533 local ipaddr 493 534 494 - hssrc_name="$(get_hsname "${hssrc}")" 535 + eval hssrc_name=\${$(get_hsname "${hssrc}")} 495 536 496 537 if [ "${proto}" -eq 6 ]; then 497 538 ipaddr="${ipprefix}::${hsdst}" ··· 521 562 local rtdst="${hsdst}" 522 563 523 564 # set fixed mac for source node and the neigh MAC address 524 - set_mac_address "hs-${hssrc}" "${hssrc}" "${hssrc}" "${HS_VETH_NAME}" 565 + set_mac_address "hs_${hssrc}" "${hssrc}" "${hssrc}" "${HS_VETH_NAME}" 525 566 set_host_l2peer "${hssrc}" "${hsdst}" "${IPv6_HS_NETWORK}" 6 526 567 set_host_l2peer "${hssrc}" "${hsdst}" "${IPv4_HS_NETWORK}" 4 527 568 ··· 529 570 # to the mac address of the remote peer (L2 VPN destination host). 530 571 # Otherwise, traffic coming from the source host is dropped at the 531 572 # ingress router. 532 - set_mac_address "rt-${rtsrc}" "${hsdst}" 254 "${RT2HS_DEVNAME}" 573 + set_mac_address "rt_${rtsrc}" "${hsdst}" 254 "${RT2HS_DEVNAME}" 533 574 534 575 # set the SRv6 Policies at the ingress router 535 576 setup_rt_policy_ipv6 "${hsdst}" "${rtsrc}" "${end_rts}" "${rtdst}" \ ··· 606 647 local prefix 607 648 local rtsrc_nsname 608 649 609 - rtsrc_nsname="$(get_rtname "${rtsrc}")" 650 + eval rtsrc_nsname=\${$(get_rtname "${rtsrc}")} 610 651 611 652 prefix="$(get_network_prefix "${rtsrc}" "${rtdst}")" 612 653 ··· 629 670 local hsdst="$2" 630 671 local hssrc_nsname 631 672 632 - hssrc_nsname="$(get_hsname "${hssrc}")" 673 + eval hssrc_nsname=\${$(get_hsname "${hssrc}")} 633 674 634 675 ip netns exec "${hssrc_nsname}" ping -c 1 -W "${PING_TIMEOUT_SEC}" \ 635 676 "${IPv6_HS_NETWORK}::${hsdst}" >/dev/null 2>&1 ··· 641 682 local hsdst="$2" 642 683 local hssrc_nsname 643 684 644 - hssrc_nsname="$(get_hsname "${hssrc}")" 685 + eval hssrc_nsname=\${$(get_hsname "${hssrc}")} 645 686 646 687 ip netns exec "${hssrc_nsname}" ping -c 1 -W "${PING_TIMEOUT_SEC}" \ 647 688 "${IPv4_HS_NETWORK}.${hsdst}" >/dev/null 2>&1