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

Merge branch 'selftests-mptcp-share-code-and-fix-shellcheck-warnings'

Matthieu Baerts says:

====================
selftests: mptcp: share code and fix shellcheck warnings

This series cleans MPTCP selftests code.

Patch 1 stops using 'iptables-legacy' if available, but uses 'iptables',
which is likely 'iptables-nft' behind.

Patches 2, 4 and 6 move duplicated code to mptcp_lib.sh. Patch 3 is a
preparation for patch 4, and patch 5 adds generic actions at the
creation and deletion of netns.

Patches 7 to 11 disable a few shellcheck warnings, and fix the rest, so
it is easy to spot real issues later. MPTCP CI is checking that now.

Patch 12 avoids redoing some actions at init time twice, e.g. restarting
the pm events tool.

v1: https://lore.kernel.org/r/20240305-upstream-net-next-20240304-selftests-mptcp-shared-code-shellcheck-v1-0-66618ea5504e@kernel.org
====================

Link: https://lore.kernel.org/r/20240306-upstream-net-next-20240304-selftests-mptcp-shared-code-shellcheck-v2-0-bc79e6e5e6a0@kernel.org
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

+210 -244
+14 -21
tools/testing/selftests/net/mptcp/diag.sh
··· 1 1 #!/bin/bash 2 2 # SPDX-License-Identifier: GPL-2.0 3 3 4 + # Double quotes to prevent globbing and word splitting is recommended in new 5 + # code but we accept it, especially because there were too many before having 6 + # address all other issues detected by shellcheck. 7 + #shellcheck disable=SC2086 8 + 4 9 . "$(dirname "${0}")/mptcp_lib.sh" 5 10 6 - sec=$(date +%s) 7 - rndh=$(printf %x $sec)-$(mktemp -u XXXXXX) 8 - ns="ns1-$rndh" 9 - ksft_skip=4 11 + ns="" 10 12 test_cnt=1 11 13 timeout_poll=30 12 14 timeout_test=$((timeout_poll * 2 + 1)) ··· 28 26 done 29 27 } 30 28 29 + # This function is used in the cleanup trap 30 + #shellcheck disable=SC2317 31 31 cleanup() 32 32 { 33 33 ip netns pids "${ns}" | xargs --no-run-if-empty kill -SIGKILL &>/dev/null 34 34 35 - ip netns del $ns 35 + mptcp_lib_ns_exit "${ns}" 36 36 } 37 37 38 38 mptcp_lib_check_mptcp 39 - 40 - ip -Version > /dev/null 2>&1 41 - if [ $? -ne 0 ];then 42 - echo "SKIP: Could not run test without ip tool" 43 - exit $ksft_skip 44 - fi 45 - ss -h | grep -q MPTCP 46 - if [ $? -ne 0 ];then 47 - echo "SKIP: ss tool does not support MPTCP" 48 - exit $ksft_skip 49 - fi 39 + mptcp_lib_check_tools ip ss 50 40 51 41 get_msk_inuse() 52 42 { ··· 180 186 expected=$((expected + listen_nr)) 181 187 182 188 for _ in $(seq 10); do 183 - if [ $(get_msk_inuse) -eq $expected ];then 189 + if [ "$(get_msk_inuse)" -eq $expected ]; then 184 190 break 185 191 fi 186 192 sleep 0.1 ··· 218 224 } 219 225 220 226 trap cleanup EXIT 221 - ip netns add $ns 222 - ip -n $ns link set dev lo up 227 + mptcp_lib_ns_init ns 223 228 224 229 echo "a" | \ 225 230 timeout ${timeout_test} \ ··· 266 273 chk_msk_cestab 0 "1->0" 267 274 268 275 NR_CLIENTS=100 269 - for I in `seq 1 $NR_CLIENTS`; do 276 + for I in $(seq 1 $NR_CLIENTS); do 270 277 echo "a" | \ 271 278 timeout ${timeout_test} \ 272 279 ip netns exec $ns \ ··· 275 282 done 276 283 mptcp_lib_wait_local_port_listen $ns $((NR_CLIENTS + 10001)) 277 284 278 - for I in `seq 1 $NR_CLIENTS`; do 285 + for I in $(seq 1 $NR_CLIENTS); do 279 286 echo "b" | \ 280 287 timeout ${timeout_test} \ 281 288 ip netns exec $ns \
+58 -53
tools/testing/selftests/net/mptcp/mptcp_connect.sh
··· 1 1 #!/bin/bash 2 2 # SPDX-License-Identifier: GPL-2.0 3 3 4 + # Double quotes to prevent globbing and word splitting is recommended in new 5 + # code but we accept it, especially because there were too many before having 6 + # address all other issues detected by shellcheck. 7 + #shellcheck disable=SC2086 8 + 4 9 . "$(dirname "${0}")/mptcp_lib.sh" 5 10 6 11 time_start=$(date +%s) ··· 18 13 cin_disconnect="" 19 14 cin="" 20 15 cout="" 21 - ksft_skip=4 22 16 capture=false 23 17 timeout_poll=30 24 18 timeout_test=$((timeout_poll * 2 + 1)) ··· 125 121 esac 126 122 done 127 123 128 - sec=$(date +%s) 129 - rndh=$(printf %x $sec)-$(mktemp -u XXXXXX) 130 - ns1="ns1-$rndh" 131 - ns2="ns2-$rndh" 132 - ns3="ns3-$rndh" 133 - ns4="ns4-$rndh" 124 + ns1="" 125 + ns2="" 126 + ns3="" 127 + ns4="" 134 128 135 129 TEST_COUNT=0 136 130 TEST_GROUP="" 137 131 132 + # This function is used in the cleanup trap 133 + #shellcheck disable=SC2317 138 134 cleanup() 139 135 { 140 136 rm -f "$cin_disconnect" "$cout_disconnect" ··· 142 138 rm -f "$sin" "$sout" 143 139 rm -f "$capout" 144 140 145 - local netns 146 - for netns in "$ns1" "$ns2" "$ns3" "$ns4";do 147 - ip netns del $netns 148 - rm -f /tmp/$netns.{nstat,out} 149 - done 141 + mptcp_lib_ns_exit "${ns1}" "${ns2}" "${ns3}" "${ns4}" 150 142 } 151 143 152 144 mptcp_lib_check_mptcp 153 145 mptcp_lib_check_kallsyms 154 - 155 - ip -Version > /dev/null 2>&1 156 - if [ $? -ne 0 ];then 157 - echo "SKIP: Could not run test without ip tool" 158 - exit $ksft_skip 159 - fi 146 + mptcp_lib_check_tools ip 160 147 161 148 sin=$(mktemp) 162 149 sout=$(mktemp) ··· 158 163 cout_disconnect="$cout".disconnect 159 164 trap cleanup EXIT 160 165 161 - for i in "$ns1" "$ns2" "$ns3" "$ns4";do 162 - ip netns add $i || exit $ksft_skip 163 - ip -net $i link set lo up 164 - done 166 + mptcp_lib_ns_init ns1 ns2 ns3 ns4 165 167 166 168 # "$ns1" ns2 ns3 ns4 167 169 # ns1eth2 ns2eth1 ns2eth3 ns3eth2 ns3eth4 ns4eth3 ··· 217 225 local dev="$2" 218 226 local flags="$3" 219 227 220 - ip netns exec $ns ethtool -K $dev $flags 2>/dev/null 221 - [ $? -eq 0 ] && echo "INFO: set $ns dev $dev: ethtool -K $flags" 228 + if ip netns exec $ns ethtool -K $dev $flags 2>/dev/null; then 229 + echo "INFO: set $ns dev $dev: ethtool -K $flags" 230 + fi 222 231 } 223 232 224 233 set_random_ethtool_flags() { ··· 249 256 250 257 check_mptcp_disabled() 251 258 { 252 - local disabled_ns="ns_disabled-$rndh" 253 - ip netns add ${disabled_ns} || exit $ksft_skip 259 + local disabled_ns 260 + mptcp_lib_ns_init disabled_ns 254 261 255 262 # net.mptcp.enabled should be enabled by default 256 263 if [ "$(ip netns exec ${disabled_ns} sysctl net.mptcp.enabled | awk '{ print $3 }')" -ne 1 ]; then ··· 264 271 local err=0 265 272 LC_ALL=C ip netns exec ${disabled_ns} ./mptcp_connect -p 10000 -s MPTCP 127.0.0.1 < "$cin" 2>&1 | \ 266 273 grep -q "^socket: Protocol not available$" && err=1 267 - ip netns delete ${disabled_ns} 274 + mptcp_lib_ns_exit "${disabled_ns}" 268 275 269 276 if [ ${err} -eq 0 ]; then 270 277 echo -e "New MPTCP socket cannot be blocked via sysctl\t\t[ FAIL ]" ··· 314 321 local extra_args="$7" 315 322 316 323 local port 317 - port=$((10000+$TEST_COUNT)) 324 + port=$((10000+TEST_COUNT)) 318 325 TEST_COUNT=$((TEST_COUNT+1)) 319 326 320 327 if [ "$rcvbuf" -gt 0 ]; then ··· 346 353 347 354 if $capture; then 348 355 local capuser 356 + local rndh="${connector_ns:4}" 349 357 if [ -z $SUDO_USER ] ; then 350 358 capuser="" 351 359 else ··· 372 378 nstat -n 373 379 fi 374 380 375 - local stat_synrx_last_l=$(mptcp_lib_get_counter "${listener_ns}" "MPTcpExtMPCapableSYNRX") 376 - local stat_ackrx_last_l=$(mptcp_lib_get_counter "${listener_ns}" "MPTcpExtMPCapableACKRX") 377 - local stat_cookietx_last=$(mptcp_lib_get_counter "${listener_ns}" "TcpExtSyncookiesSent") 378 - local stat_cookierx_last=$(mptcp_lib_get_counter "${listener_ns}" "TcpExtSyncookiesRecv") 379 - local stat_csum_err_s=$(mptcp_lib_get_counter "${listener_ns}" "MPTcpExtDataCsumErr") 380 - local stat_csum_err_c=$(mptcp_lib_get_counter "${connector_ns}" "MPTcpExtDataCsumErr") 381 + local stat_synrx_last_l 382 + local stat_ackrx_last_l 383 + local stat_cookietx_last 384 + local stat_cookierx_last 385 + local stat_csum_err_s 386 + local stat_csum_err_c 387 + stat_synrx_last_l=$(mptcp_lib_get_counter "${listener_ns}" "MPTcpExtMPCapableSYNRX") 388 + stat_ackrx_last_l=$(mptcp_lib_get_counter "${listener_ns}" "MPTcpExtMPCapableACKRX") 389 + stat_cookietx_last=$(mptcp_lib_get_counter "${listener_ns}" "TcpExtSyncookiesSent") 390 + stat_cookierx_last=$(mptcp_lib_get_counter "${listener_ns}" "TcpExtSyncookiesRecv") 391 + stat_csum_err_s=$(mptcp_lib_get_counter "${listener_ns}" "MPTcpExtDataCsumErr") 392 + stat_csum_err_c=$(mptcp_lib_get_counter "${connector_ns}" "MPTcpExtDataCsumErr") 381 393 382 394 timeout ${timeout_test} \ 383 395 ip netns exec ${listener_ns} \ ··· 446 446 mptcp_lib_check_transfer $cin $sout "file received by server" 447 447 rets=$? 448 448 449 - local stat_synrx_now_l=$(mptcp_lib_get_counter "${listener_ns}" "MPTcpExtMPCapableSYNRX") 450 - local stat_ackrx_now_l=$(mptcp_lib_get_counter "${listener_ns}" "MPTcpExtMPCapableACKRX") 451 - local stat_cookietx_now=$(mptcp_lib_get_counter "${listener_ns}" "TcpExtSyncookiesSent") 452 - local stat_cookierx_now=$(mptcp_lib_get_counter "${listener_ns}" "TcpExtSyncookiesRecv") 453 - local stat_ooo_now=$(mptcp_lib_get_counter "${listener_ns}" "TcpExtTCPOFOQueue") 449 + local stat_synrx_now_l 450 + local stat_ackrx_now_l 451 + local stat_cookietx_now 452 + local stat_cookierx_now 453 + local stat_ooo_now 454 + stat_synrx_now_l=$(mptcp_lib_get_counter "${listener_ns}" "MPTcpExtMPCapableSYNRX") 455 + stat_ackrx_now_l=$(mptcp_lib_get_counter "${listener_ns}" "MPTcpExtMPCapableACKRX") 456 + stat_cookietx_now=$(mptcp_lib_get_counter "${listener_ns}" "TcpExtSyncookiesSent") 457 + stat_cookierx_now=$(mptcp_lib_get_counter "${listener_ns}" "TcpExtSyncookiesRecv") 458 + stat_ooo_now=$(mptcp_lib_get_counter "${listener_ns}" "TcpExtTCPOFOQueue") 454 459 455 460 expect_synrx=$((stat_synrx_last_l)) 456 461 expect_ackrx=$((stat_ackrx_last_l)) ··· 464 459 cookies=${cookies##*=} 465 460 466 461 if [ ${cl_proto} = "MPTCP" ] && [ ${srv_proto} = "MPTCP" ]; then 467 - expect_synrx=$((stat_synrx_last_l+$connect_per_transfer)) 468 - expect_ackrx=$((stat_ackrx_last_l+$connect_per_transfer)) 462 + expect_synrx=$((stat_synrx_last_l+connect_per_transfer)) 463 + expect_ackrx=$((stat_ackrx_last_l+connect_per_transfer)) 469 464 fi 470 465 471 466 if [ ${stat_synrx_now_l} -lt ${expect_synrx} ]; then ··· 473 468 "${stat_synrx_now_l}" "${expect_synrx}" 1>&2 474 469 retc=1 475 470 fi 476 - if [ ${stat_ackrx_now_l} -lt ${expect_ackrx} -a ${stat_ooo_now} -eq 0 ]; then 471 + if [ ${stat_ackrx_now_l} -lt ${expect_ackrx} ] && [ ${stat_ooo_now} -eq 0 ]; then 477 472 if [ ${stat_ooo_now} -eq 0 ]; then 478 473 printf "[ FAIL ] lower MPC ACK rx (%d) than expected (%d)\n" \ 479 474 "${stat_ackrx_now_l}" "${expect_ackrx}" 1>&2 ··· 484 479 fi 485 480 486 481 if $checksum; then 487 - local csum_err_s=$(mptcp_lib_get_counter "${listener_ns}" "MPTcpExtDataCsumErr") 488 - local csum_err_c=$(mptcp_lib_get_counter "${connector_ns}" "MPTcpExtDataCsumErr") 482 + local csum_err_s 483 + local csum_err_c 484 + csum_err_s=$(mptcp_lib_get_counter "${listener_ns}" "MPTcpExtDataCsumErr") 485 + csum_err_c=$(mptcp_lib_get_counter "${connector_ns}" "MPTcpExtDataCsumErr") 489 486 490 487 local csum_err_s_nr=$((csum_err_s - stat_csum_err_s)) 491 488 if [ $csum_err_s_nr -gt 0 ]; then 492 - printf "[ FAIL ]\nserver got $csum_err_s_nr data checksum error[s]" 489 + printf "[ FAIL ]\nserver got %d data checksum error[s]" ${csum_err_s_nr} 493 490 rets=1 494 491 fi 495 492 496 493 local csum_err_c_nr=$((csum_err_c - stat_csum_err_c)) 497 494 if [ $csum_err_c_nr -gt 0 ]; then 498 - printf "[ FAIL ]\nclient got $csum_err_c_nr data checksum error[s]" 495 + printf "[ FAIL ]\nclient got %d data checksum error[s]" ${csum_err_c_nr} 499 496 retc=1 500 497 fi 501 498 fi ··· 665 658 return 666 659 fi 667 660 668 - ip netns exec "$listener_ns" nft -f /dev/stdin <<"EOF" 661 + if ! ip netns exec "$listener_ns" nft -f /dev/stdin <<"EOF" 669 662 flush ruleset 670 663 table inet mangle { 671 664 chain divert { ··· 676 669 } 677 670 } 678 671 EOF 679 - if [ $? -ne 0 ]; then 672 + then 680 673 echo "SKIP: $msg, could not load nft ruleset" 681 674 mptcp_lib_fail_if_expected_feature "nft rules" 682 675 mptcp_lib_result_skip "${TEST_GROUP}" ··· 691 684 local_addr="0.0.0.0" 692 685 fi 693 686 694 - ip -net "$listener_ns" $r6flag rule add fwmark 1 lookup 100 695 - if [ $? -ne 0 ]; then 687 + if ! ip -net "$listener_ns" $r6flag rule add fwmark 1 lookup 100; then 696 688 ip netns exec "$listener_ns" nft flush ruleset 697 689 echo "SKIP: $msg, ip $r6flag rule failed" 698 690 mptcp_lib_fail_if_expected_feature "ip rule" ··· 699 693 return 700 694 fi 701 695 702 - ip -net "$listener_ns" route add local $local_addr/0 dev lo table 100 703 - if [ $? -ne 0 ]; then 696 + if ! ip -net "$listener_ns" route add local $local_addr/0 dev lo table 100; then 704 697 ip netns exec "$listener_ns" nft flush ruleset 705 698 ip -net "$listener_ns" $r6flag rule del fwmark 1 lookup 100 706 699 echo "SKIP: $msg, ip route add local $local_addr failed" ··· 862 857 echo -n "INFO: Using loss of $tc_loss " 863 858 test "$tc_delay" -gt 0 && echo -n "delay $tc_delay ms " 864 859 865 - reorder_delay=$(($tc_delay / 4)) 860 + reorder_delay=$((tc_delay / 4)) 866 861 867 862 if [ -z "${tc_reorder}" ]; then 868 863 reorder1=$((RANDOM%10))
+9 -51
tools/testing/selftests/net/mptcp/mptcp_join.sh
··· 86 86 { 87 87 capout=$(mktemp) 88 88 89 - local sec rndh 90 - sec=$(date +%s) 91 - rndh=$(printf %x $sec)-$(mktemp -u XXXXXX) 92 - 93 - ns1="ns1-$rndh" 94 - ns2="ns2-$rndh" 89 + mptcp_lib_ns_init ns1 ns2 95 90 96 91 local netns 97 92 for netns in "$ns1" "$ns2"; do 98 - ip netns add $netns || exit $ksft_skip 99 - ip -net $netns link set lo up 100 - ip netns exec $netns sysctl -q net.mptcp.enabled=1 101 93 ip netns exec $netns sysctl -q net.mptcp.pm_type=0 2>/dev/null || true 102 - ip netns exec $netns sysctl -q net.ipv4.conf.all.rp_filter=0 103 - ip netns exec $netns sysctl -q net.ipv4.conf.default.rp_filter=0 104 94 if $checksum; then 105 95 ip netns exec $netns sysctl -q net.mptcp.checksum_enabled=1 106 96 fi ··· 135 145 { 136 146 rm -f "$capout" 137 147 138 - local netns 139 - for netns in "$ns1" "$ns2"; do 140 - ip netns del $netns 141 - rm -f /tmp/$netns.{nstat,out} 142 - done 143 - } 144 - 145 - check_tools() 146 - { 147 - mptcp_lib_check_mptcp 148 - mptcp_lib_check_kallsyms 149 - 150 - if ! ip -Version &> /dev/null; then 151 - echo "SKIP: Could not run test without ip tool" 152 - exit $ksft_skip 153 - fi 154 - 155 - if ! ss -h | grep -q MPTCP; then 156 - echo "SKIP: ss tool does not support MPTCP" 157 - exit $ksft_skip 158 - fi 159 - 160 - # Use the legacy version if available to support old kernel versions 161 - if iptables-legacy -V &> /dev/null; then 162 - iptables="iptables-legacy" 163 - ip6tables="ip6tables-legacy" 164 - elif ! iptables -V &> /dev/null; then 165 - echo "SKIP: Could not run all tests without iptables tool" 166 - exit $ksft_skip 167 - elif ! ip6tables -V &> /dev/null; then 168 - echo "SKIP: Could not run all tests without ip6tables tool" 169 - exit $ksft_skip 170 - fi 148 + mptcp_lib_ns_exit "${ns1}" "${ns2}" 171 149 } 172 150 173 151 init() { 174 152 init=1 175 153 176 - check_tools 154 + mptcp_lib_check_mptcp 155 + mptcp_lib_check_kallsyms 156 + mptcp_lib_check_tools ip ss "${iptables}" "${ip6tables}" 177 157 178 158 sin=$(mktemp) 179 159 sout=$(mktemp) ··· 430 470 { 431 471 reset "${1}" || return 1 432 472 433 - :> "$evts_ns1" 434 - :> "$evts_ns2" 435 - ip netns exec $ns1 ./pm_nl_ctl events >> "$evts_ns1" 2>&1 & 436 - evts_ns1_pid=$! 437 - ip netns exec $ns2 ./pm_nl_ctl events >> "$evts_ns2" 2>&1 & 438 - evts_ns2_pid=$! 473 + mptcp_lib_events "${ns1}" "${evts_ns1}" evts_ns1_pid 474 + mptcp_lib_events "${ns2}" "${evts_ns2}" evts_ns2_pid 439 475 } 440 476 441 477 reset_with_tcp_filter() ··· 604 648 kill_events_pids() 605 649 { 606 650 mptcp_lib_kill_wait $evts_ns1_pid 651 + evts_ns1_pid=0 607 652 mptcp_lib_kill_wait $evts_ns2_pid 653 + evts_ns2_pid=0 608 654 } 609 655 610 656 pm_nl_set_limits()
+68
tools/testing/selftests/net/mptcp/mptcp_lib.sh
··· 342 342 return 1 343 343 fi 344 344 } 345 + 346 + mptcp_lib_check_tools() { 347 + local tool 348 + 349 + for tool in "${@}"; do 350 + case "${tool}" in 351 + "ip") 352 + if ! ip -Version &> /dev/null; then 353 + mptcp_lib_print_warn "SKIP: Could not run test without ip tool" 354 + exit ${KSFT_SKIP} 355 + fi 356 + ;; 357 + "ss") 358 + if ! ss -h | grep -q MPTCP; then 359 + mptcp_lib_print_warn "SKIP: ss tool does not support MPTCP" 360 + exit ${KSFT_SKIP} 361 + fi 362 + ;; 363 + "iptables"* | "ip6tables"*) 364 + if ! "${tool}" -V &> /dev/null; then 365 + mptcp_lib_print_warn "SKIP: Could not run all tests without ${tool}" 366 + exit ${KSFT_SKIP} 367 + fi 368 + ;; 369 + *) 370 + mptcp_lib_print_err "Internal error: unsupported tool: ${tool}" 371 + exit ${KSFT_FAIL} 372 + ;; 373 + esac 374 + done 375 + } 376 + mptcp_lib_ns_init() { 377 + local sec rndh 378 + 379 + sec=$(date +%s) 380 + rndh=$(printf %x "${sec}")-$(mktemp -u XXXXXX) 381 + 382 + local netns 383 + for netns in "${@}"; do 384 + eval "${netns}=${netns}-${rndh}" 385 + 386 + ip netns add "${!netns}" || exit ${KSFT_SKIP} 387 + ip -net "${!netns}" link set lo up 388 + ip netns exec "${!netns}" sysctl -q net.mptcp.enabled=1 389 + ip netns exec "${!netns}" sysctl -q net.ipv4.conf.all.rp_filter=0 390 + ip netns exec "${!netns}" sysctl -q net.ipv4.conf.default.rp_filter=0 391 + done 392 + } 393 + 394 + mptcp_lib_ns_exit() { 395 + local netns 396 + for netns in "${@}"; do 397 + ip netns del "${netns}" 398 + rm -f /tmp/"${netns}".{nstat,out} 399 + done 400 + } 401 + 402 + mptcp_lib_events() { 403 + local ns="${1}" 404 + local evts="${2}" 405 + declare -n pid="${3}" 406 + 407 + :>"${evts}" 408 + 409 + mptcp_lib_kill_wait "${pid:-0}" 410 + ip netns exec "${ns}" ./pm_nl_ctl events >> "${evts}" 2>&1 & 411 + pid=$! 412 + }
+16 -39
tools/testing/selftests/net/mptcp/mptcp_sockopt.sh
··· 1 1 #!/bin/bash 2 2 # SPDX-License-Identifier: GPL-2.0 3 3 4 + # Double quotes to prevent globbing and word splitting is recommended in new 5 + # code but we accept it, especially because there were too many before having 6 + # address all other issues detected by shellcheck. 7 + #shellcheck disable=SC2086 8 + 4 9 . "$(dirname "${0}")/mptcp_lib.sh" 5 10 6 11 ret=0 ··· 13 8 sout="" 14 9 cin="" 15 10 cout="" 16 - ksft_skip=4 17 11 timeout_poll=30 18 12 timeout_test=$((timeout_poll * 2 + 1)) 19 13 iptables="iptables" 20 14 ip6tables="ip6tables" 21 15 22 - sec=$(date +%s) 23 - rndh=$(printf %x $sec)-$(mktemp -u XXXXXX) 24 - ns1="ns1-$rndh" 25 - ns2="ns2-$rndh" 26 - ns_sbox="ns_sbox-$rndh" 16 + ns1="" 17 + ns2="" 18 + ns_sbox="" 27 19 28 20 add_mark_rules() 29 21 { ··· 42 40 43 41 init() 44 42 { 45 - local netns 46 - for netns in "$ns1" "$ns2" "$ns_sbox";do 47 - ip netns add $netns || exit $ksft_skip 48 - ip -net $netns link set lo up 49 - ip netns exec $netns sysctl -q net.mptcp.enabled=1 50 - ip netns exec $netns sysctl -q net.ipv4.conf.all.rp_filter=0 51 - ip netns exec $netns sysctl -q net.ipv4.conf.default.rp_filter=0 52 - done 43 + mptcp_lib_ns_init ns1 ns2 ns_sbox 53 44 54 45 local i 55 - for i in `seq 1 4`; do 46 + for i in $(seq 1 4); do 56 47 ip link add ns1eth$i netns "$ns1" type veth peer name ns2eth$i netns "$ns2" 57 48 ip -net "$ns1" addr add 10.0.$i.1/24 dev ns1eth$i 58 49 ip -net "$ns1" addr add dead:beef:$i::1/64 dev ns1eth$i nodad ··· 72 77 add_mark_rules $ns2 2 73 78 } 74 79 80 + # This function is used in the cleanup trap 81 + #shellcheck disable=SC2317 75 82 cleanup() 76 83 { 77 - local netns 78 - for netns in "$ns1" "$ns2" "$ns_sbox"; do 79 - ip netns del $netns 80 - done 84 + mptcp_lib_ns_exit "${ns1}" "${ns2}" "${ns_sbox}" 81 85 rm -f "$cin" "$cout" 82 86 rm -f "$sin" "$sout" 83 87 } 84 88 85 89 mptcp_lib_check_mptcp 86 90 mptcp_lib_check_kallsyms 87 - 88 - ip -Version > /dev/null 2>&1 89 - if [ $? -ne 0 ];then 90 - echo "SKIP: Could not run test without ip tool" 91 - exit $ksft_skip 92 - fi 93 - 94 - # Use the legacy version if available to support old kernel versions 95 - if iptables-legacy -V &> /dev/null; then 96 - iptables="iptables-legacy" 97 - ip6tables="ip6tables-legacy" 98 - elif ! iptables -V &> /dev/null; then 99 - echo "SKIP: Could not run all tests without iptables tool" 100 - exit $ksft_skip 101 - elif ! ip6tables -V &> /dev/null; then 102 - echo "SKIP: Could not run all tests without ip6tables tool" 103 - exit $ksft_skip 104 - fi 91 + mptcp_lib_check_tools ip "${iptables}" "${ip6tables}" 105 92 106 93 check_mark() 107 94 { ··· 263 286 local lret=$? 264 287 if [ $lret -ne 0 ];then 265 288 ret=$lret 266 - echo "FAIL: mptcp_inq $@" 1>&2 289 + echo "FAIL: mptcp_inq $*" 1>&2 267 290 mptcp_lib_result_fail "TCP_INQ: $*" 268 291 return $lret 269 292 fi 270 293 271 - echo "PASS: TCP_INQ cmsg/ioctl $@" 294 + echo "PASS: TCP_INQ cmsg/ioctl $*" 272 295 mptcp_lib_result_pass "TCP_INQ: $*" 273 296 return $lret 274 297 }
+14 -17
tools/testing/selftests/net/mptcp/pm_netlink.sh
··· 1 1 #!/bin/bash 2 2 # SPDX-License-Identifier: GPL-2.0 3 3 4 + # Double quotes to prevent globbing and word splitting is recommended in new 5 + # code but we accept it, especially because there were too many before having 6 + # address all other issues detected by shellcheck. 7 + #shellcheck disable=SC2086 8 + 4 9 . "$(dirname "${0}")/mptcp_lib.sh" 5 10 6 - ksft_skip=4 7 11 ret=0 8 12 9 13 usage() { 10 14 echo "Usage: $0 [ -h ]" 11 15 } 12 16 13 - 17 + optstring=h 14 18 while getopts "$optstring" option;do 15 19 case "$option" in 16 20 "h") ··· 28 24 esac 29 25 done 30 26 31 - sec=$(date +%s) 32 - rndh=$(printf %x $sec)-$(mktemp -u XXXXXX) 33 - ns1="ns1-$rndh" 27 + ns1="" 34 28 err=$(mktemp) 35 29 30 + # This function is used in the cleanup trap 31 + #shellcheck disable=SC2317 36 32 cleanup() 37 33 { 38 34 rm -f $err 39 - ip netns del $ns1 35 + mptcp_lib_ns_exit "${ns1}" 40 36 } 41 37 42 38 mptcp_lib_check_mptcp 43 - 44 - ip -Version > /dev/null 2>&1 45 - if [ $? -ne 0 ];then 46 - echo "SKIP: Could not run test without ip tool" 47 - exit $ksft_skip 48 - fi 39 + mptcp_lib_check_tools ip 49 40 50 41 trap cleanup EXIT 51 42 52 - ip netns add $ns1 || exit $ksft_skip 53 - ip -net $ns1 link set lo up 54 - ip netns exec $ns1 sysctl -q net.mptcp.enabled=1 43 + mptcp_lib_ns_init ns1 55 44 56 45 check() 57 46 { ··· 97 100 ip netns exec $ns1 ./pm_nl_ctl add 10.0.1.4 flags signal 98 101 check "ip netns exec $ns1 ./pm_nl_ctl get 4" "id 4 flags signal 10.0.1.4" "id addr increment" 99 102 100 - for i in `seq 5 9`; do 103 + for i in $(seq 5 9); do 101 104 ip netns exec $ns1 ./pm_nl_ctl add 10.0.1.$i flags signal >/dev/null 2>&1 102 105 done 103 106 check "ip netns exec $ns1 ./pm_nl_ctl get 9" "id 9 flags signal 10.0.1.9" "hard addr limit" 104 107 check "ip netns exec $ns1 ./pm_nl_ctl get 10" "" "above hard addr limit" 105 108 106 109 ip netns exec $ns1 ./pm_nl_ctl del 9 107 - for i in `seq 10 255`; do 110 + for i in $(seq 10 255); do 108 111 ip netns exec $ns1 ./pm_nl_ctl add 10.0.0.9 id $i 109 112 ip netns exec $ns1 ./pm_nl_ctl del $i 110 113 done
+15 -23
tools/testing/selftests/net/mptcp/simult_flows.sh
··· 1 1 #!/bin/bash 2 2 # SPDX-License-Identifier: GPL-2.0 3 3 4 + # Double quotes to prevent globbing and word splitting is recommended in new 5 + # code but we accept it, especially because there were too many before having 6 + # address all other issues detected by shellcheck. 7 + #shellcheck disable=SC2086 8 + 4 9 . "$(dirname "${0}")/mptcp_lib.sh" 5 10 6 - sec=$(date +%s) 7 - rndh=$(printf %x $sec)-$(mktemp -u XXXXXX) 8 - ns1="ns1-$rndh" 9 - ns2="ns2-$rndh" 10 - ns3="ns3-$rndh" 11 + ns1="" 12 + ns2="" 13 + ns3="" 11 14 capture=false 12 - ksft_skip=4 13 15 timeout_poll=30 14 16 timeout_test=$((timeout_poll * 2 + 1)) 15 17 test_cnt=1 ··· 32 30 echo -e "\t-d: debug this script" 33 31 } 34 32 33 + # This function is used in the cleanup trap 34 + #shellcheck disable=SC2317 35 35 cleanup() 36 36 { 37 37 rm -f "$cout" "$sout" 38 38 rm -f "$large" "$small" 39 39 rm -f "$capout" 40 40 41 - local netns 42 - for netns in "$ns1" "$ns2" "$ns3";do 43 - ip netns del $netns 44 - done 41 + mptcp_lib_ns_exit "${ns1}" "${ns2}" "${ns3}" 45 42 } 46 43 47 44 mptcp_lib_check_mptcp 48 - 49 - ip -Version > /dev/null 2>&1 50 - if [ $? -ne 0 ];then 51 - echo "SKIP: Could not run test without ip tool" 52 - exit $ksft_skip 53 - fi 45 + mptcp_lib_check_tools ip 54 46 55 47 # "$ns1" ns2 ns3 56 48 # ns1eth1 ns2eth1 ns2eth3 ns3eth1 ··· 66 70 67 71 trap cleanup EXIT 68 72 69 - for i in "$ns1" "$ns2" "$ns3";do 70 - ip netns add $i || exit $ksft_skip 71 - ip -net $i link set lo up 72 - ip netns exec $i sysctl -q net.ipv4.conf.all.rp_filter=0 73 - ip netns exec $i sysctl -q net.ipv4.conf.default.rp_filter=0 74 - done 73 + mptcp_lib_ns_init ns1 ns2 ns3 75 74 76 75 ip link add ns1eth1 netns "$ns1" type veth peer name ns2eth1 netns "$ns2" 77 76 ip link add ns1eth2 netns "$ns1" type veth peer name ns2eth2 netns "$ns2" ··· 126 135 local sin=$2 127 136 local max_time=$3 128 137 local port 129 - port=$((10000+$test_cnt)) 138 + port=$((10000+test_cnt)) 130 139 test_cnt=$((test_cnt+1)) 131 140 132 141 :> "$cout" ··· 135 144 136 145 if $capture; then 137 146 local capuser 147 + local rndh="${ns1:4}" 138 148 if [ -z $SUDO_USER ] ; then 139 149 capuser="" 140 150 else
+16 -40
tools/testing/selftests/net/mptcp/userspace_pm.sh
··· 17 17 echo "userspace pm tests are not supported by the kernel: SKIP" 18 18 exit ${KSFT_SKIP} 19 19 fi 20 - 21 - if ! ip -Version &> /dev/null; then 22 - echo "SKIP: Cannot not run test without ip tool" 23 - exit ${KSFT_SKIP} 24 - fi 20 + mptcp_lib_check_tools ip 25 21 26 22 ANNOUNCED=6 # MPTCP_EVENT_ANNOUNCED 27 23 REMOVED=7 # MPTCP_EVENT_REMOVED ··· 50 54 client_addr_id=${RANDOM:0:2} 51 55 server_addr_id=${RANDOM:0:2} 52 56 53 - sec=$(date +%s) 54 - rndh=$(printf %x "$sec")-$(mktemp -u XXXXXX) 55 - ns1="ns1-$rndh" 56 - ns2="ns2-$rndh" 57 + ns1="" 58 + ns2="" 57 59 ret=0 58 60 test_name="" 59 61 ··· 116 122 mptcp_lib_kill_wait $pid 117 123 done 118 124 119 - local netns 120 - for netns in "$ns1" "$ns2" ;do 121 - ip netns del "$netns" 122 - done 125 + mptcp_lib_ns_exit "${ns1}" "${ns2}" 123 126 124 127 rm -rf $file $client_evts $server_evts 125 128 ··· 126 135 trap cleanup EXIT 127 136 128 137 # Create and configure network namespaces for testing 138 + mptcp_lib_ns_init ns1 ns2 129 139 for i in "$ns1" "$ns2" ;do 130 - ip netns add "$i" || exit 1 131 - ip -net "$i" link set lo up 132 - ip netns exec "$i" sysctl -q net.mptcp.enabled=1 133 140 ip netns exec "$i" sysctl -q net.mptcp.pm_type=1 134 141 done 135 142 ··· 149 160 ip -net "$ns2" addr add dead:beef:2::2/64 dev ns2eth1 nodad 150 161 ip -net "$ns2" link set ns2eth1 up 151 162 163 + file=$(mktemp) 164 + mptcp_lib_make_file "$file" 2 1 165 + 166 + # Capture netlink events over the two network namespaces running 167 + # the MPTCP client and server 168 + client_evts=$(mktemp) 169 + mptcp_lib_events "${ns2}" "${client_evts}" client_evts_pid 170 + server_evts=$(mktemp) 171 + mptcp_lib_events "${ns1}" "${server_evts}" server_evts_pid 172 + sleep 0.5 173 + 152 174 print_title "Init" 153 175 print_test "Created network namespaces ns1, ns2" 154 176 test_pass 155 177 156 178 make_connection() 157 179 { 158 - if [ -z "$file" ]; then 159 - file=$(mktemp) 160 - fi 161 - mptcp_lib_make_file "$file" 2 1 162 - 163 180 local is_v6=$1 164 181 local app_port=$app4_port 165 182 local connect_addr="10.0.1.1" ··· 179 184 is_v6="v4" 180 185 fi 181 186 182 - # Capture netlink events over the two network namespaces running 183 - # the MPTCP client and server 184 - if [ -z "$client_evts" ]; then 185 - client_evts=$(mktemp) 186 - fi 187 187 :>"$client_evts" 188 - if [ $client_evts_pid -ne 0 ]; then 189 - mptcp_lib_kill_wait $client_evts_pid 190 - fi 191 - ip netns exec "$ns2" ./pm_nl_ctl events >> "$client_evts" 2>&1 & 192 - client_evts_pid=$! 193 - if [ -z "$server_evts" ]; then 194 - server_evts=$(mktemp) 195 - fi 196 188 :>"$server_evts" 197 - if [ $server_evts_pid -ne 0 ]; then 198 - mptcp_lib_kill_wait $server_evts_pid 199 - fi 200 - ip netns exec "$ns1" ./pm_nl_ctl events >> "$server_evts" 2>&1 & 201 - server_evts_pid=$! 202 - sleep 0.5 203 189 204 190 # Run the server 205 191 ip netns exec "$ns1" \