1#!/bin/bash 2# SPDX-License-Identifier: GPL-2.0 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 9# ShellCheck incorrectly believes that most of the code here is unreachable 10# because it's invoked by variable name, see how the "tests" array is used 11#shellcheck disable=SC2317 12 13. "$(dirname "${0}")/mptcp_lib.sh" 14 15ret=0 16sin="" 17sinfail="" 18sout="" 19cin="" 20cinfail="" 21cinsent="" 22tmpfile="" 23cout="" 24err="" 25capout="" 26ns1="" 27ns2="" 28iptables="iptables" 29ip6tables="ip6tables" 30timeout_poll=30 31timeout_test=$((timeout_poll * 2 + 1)) 32capture=false 33checksum=false 34check_invert=0 35validate_checksum=false 36init=0 37evts_ns1="" 38evts_ns2="" 39evts_ns1_pid=0 40evts_ns2_pid=0 41last_test_failed=0 42last_test_skipped=0 43last_test_ignored=1 44 45declare -A all_tests 46declare -a only_tests_ids 47declare -a only_tests_names 48declare -A failed_tests 49MPTCP_LIB_TEST_FORMAT="%03u %s\n" 50TEST_NAME="" 51nr_blank=6 52 53# These var are used only in some tests, make sure they are not already set 54unset FAILING_LINKS 55unset test_linkfail 56unset addr_nr_ns1 57unset addr_nr_ns2 58unset cestab_ns1 59unset cestab_ns2 60unset sflags 61unset fastclose 62unset fullmesh 63unset speed 64 65# generated using "nfbpf_compile '(ip && (ip[54] & 0xf0) == 0x30) || 66# (ip6 && (ip6[74] & 0xf0) == 0x30)'" 67CBPF_MPTCP_SUBOPTION_ADD_ADDR="14, 68 48 0 0 0, 69 84 0 0 240, 70 21 0 3 64, 71 48 0 0 54, 72 84 0 0 240, 73 21 6 7 48, 74 48 0 0 0, 75 84 0 0 240, 76 21 0 4 96, 77 48 0 0 74, 78 84 0 0 240, 79 21 0 1 48, 80 6 0 0 65535, 81 6 0 0 0" 82 83init_partial() 84{ 85 capout=$(mktemp) 86 87 mptcp_lib_ns_init ns1 ns2 88 89 local netns 90 for netns in "$ns1" "$ns2"; do 91 ip netns exec $netns sysctl -q net.mptcp.pm_type=0 2>/dev/null || true 92 if $checksum; then 93 ip netns exec $netns sysctl -q net.mptcp.checksum_enabled=1 94 fi 95 done 96 97 check_invert=0 98 validate_checksum=$checksum 99 100 # ns1 ns2 101 # ns1eth1 ns2eth1 102 # ns1eth2 ns2eth2 103 # ns1eth3 ns2eth3 104 # ns1eth4 ns2eth4 105 106 local i 107 for i in $(seq 1 4); do 108 ip link add ns1eth$i netns "$ns1" type veth peer name ns2eth$i netns "$ns2" 109 ip -net "$ns1" addr add 10.0.$i.1/24 dev ns1eth$i 110 ip -net "$ns1" addr add dead:beef:$i::1/64 dev ns1eth$i nodad 111 ip -net "$ns1" link set ns1eth$i up 112 113 ip -net "$ns2" addr add 10.0.$i.2/24 dev ns2eth$i 114 ip -net "$ns2" addr add dead:beef:$i::2/64 dev ns2eth$i nodad 115 ip -net "$ns2" link set ns2eth$i up 116 117 # let $ns2 reach any $ns1 address from any interface 118 ip -net "$ns2" route add default via 10.0.$i.1 dev ns2eth$i metric 10$i 119 ip -net "$ns2" route add default via dead:beef:$i::1 dev ns2eth$i metric 10$i 120 done 121} 122 123init_shapers() 124{ 125 local i 126 for i in $(seq 1 4); do 127 tc -n $ns1 qdisc add dev ns1eth$i root netem rate 20mbit delay 1ms 128 tc -n $ns2 qdisc add dev ns2eth$i root netem rate 20mbit delay 1ms 129 done 130} 131 132cleanup_partial() 133{ 134 rm -f "$capout" 135 136 mptcp_lib_ns_exit "${ns1}" "${ns2}" 137} 138 139init() { 140 init=1 141 142 mptcp_lib_check_mptcp 143 mptcp_lib_check_kallsyms 144 mptcp_lib_check_tools ip tc ss "${iptables}" "${ip6tables}" 145 146 sin=$(mktemp) 147 sout=$(mktemp) 148 cin=$(mktemp) 149 cinsent=$(mktemp) 150 cout=$(mktemp) 151 err=$(mktemp) 152 evts_ns1=$(mktemp) 153 evts_ns2=$(mktemp) 154 155 trap cleanup EXIT 156 157 make_file "$cin" "client" 1 >/dev/null 158 make_file "$sin" "server" 1 >/dev/null 159} 160 161cleanup() 162{ 163 rm -f "$cin" "$cout" "$sinfail" 164 rm -f "$sin" "$sout" "$cinsent" "$cinfail" 165 rm -f "$tmpfile" 166 rm -rf $evts_ns1 $evts_ns2 167 rm -f "$err" 168 cleanup_partial 169} 170 171print_check() 172{ 173 printf "%-${nr_blank}s%-36s" " " "${*}" 174} 175 176print_info() 177{ 178 # It can be empty, no need to print anything then 179 [ -z "${1}" ] && return 180 181 mptcp_lib_print_info " Info: ${*}" 182} 183 184print_ok() 185{ 186 mptcp_lib_pr_ok "${@}" 187} 188 189print_fail() 190{ 191 mptcp_lib_pr_fail "${@}" 192} 193 194print_skip() 195{ 196 mptcp_lib_pr_skip "${@}" 197} 198 199# [ $1: fail msg ] 200mark_as_skipped() 201{ 202 local msg="${1:-"Feature not supported"}" 203 204 mptcp_lib_fail_if_expected_feature "${msg}" 205 206 print_check "${msg}" 207 print_skip 208 209 last_test_skipped=1 210} 211 212# $@: condition 213continue_if() 214{ 215 if ! "${@}"; then 216 mark_as_skipped 217 return 1 218 fi 219} 220 221skip_test() 222{ 223 if [ "${#only_tests_ids[@]}" -eq 0 ] && [ "${#only_tests_names[@]}" -eq 0 ]; then 224 return 1 225 fi 226 227 local i 228 for i in "${only_tests_ids[@]}"; do 229 if [ "$((MPTCP_LIB_TEST_COUNTER+1))" -eq "${i}" ]; then 230 return 1 231 fi 232 done 233 for i in "${only_tests_names[@]}"; do 234 if [ "${TEST_NAME}" = "${i}" ]; then 235 return 1 236 fi 237 done 238 239 return 0 240} 241 242append_prev_results() 243{ 244 if [ ${last_test_failed} -eq 1 ]; then 245 mptcp_lib_result_fail "${TEST_NAME}" 246 elif [ ${last_test_skipped} -eq 1 ]; then 247 mptcp_lib_result_skip "${TEST_NAME}" 248 elif [ ${last_test_ignored} -ne 1 ]; then 249 mptcp_lib_result_pass "${TEST_NAME}" 250 fi 251 252 last_test_failed=0 253 last_test_skipped=0 254 last_test_ignored=0 255} 256 257# $1: test name 258reset() 259{ 260 append_prev_results 261 262 TEST_NAME="${1}" 263 264 MPTCP_LIB_SUBTEST_FLAKY=0 # reset if modified 265 266 if skip_test; then 267 MPTCP_LIB_TEST_COUNTER=$((MPTCP_LIB_TEST_COUNTER+1)) 268 last_test_ignored=1 269 return 1 270 fi 271 272 mptcp_lib_print_title "${TEST_NAME}" 273 274 if [ "${init}" != "1" ]; then 275 init 276 else 277 cleanup_partial 278 fi 279 280 init_partial 281 282 return 0 283} 284 285# $1: test name ; $2: counter to check 286reset_check_counter() 287{ 288 reset "${1}" || return 1 289 290 local counter="${2}" 291 292 if ! nstat -asz "${counter}" | grep -wq "${counter}"; then 293 mark_as_skipped "counter '${counter}' is not available" 294 return 1 295 fi 296} 297 298# $1: test name 299reset_with_cookies() 300{ 301 reset "${1}" || return 1 302 303 local netns 304 for netns in "$ns1" "$ns2"; do 305 ip netns exec $netns sysctl -q net.ipv4.tcp_syncookies=2 306 done 307} 308 309# $1: test name 310reset_with_add_addr_timeout() 311{ 312 local ip="${2:-4}" 313 local tables 314 315 reset "${1}" || return 1 316 317 tables="${iptables}" 318 if [ $ip -eq 6 ]; then 319 tables="${ip6tables}" 320 fi 321 322 ip netns exec $ns1 sysctl -q net.mptcp.add_addr_timeout=1 323 324 if ! ip netns exec $ns2 $tables -A OUTPUT -p tcp \ 325 -m tcp --tcp-option 30 \ 326 -m bpf --bytecode \ 327 "$CBPF_MPTCP_SUBOPTION_ADD_ADDR" \ 328 -j DROP; then 329 mark_as_skipped "unable to set the 'add addr' rule" 330 return 1 331 fi 332} 333 334# $1: test name 335reset_with_checksum() 336{ 337 local ns1_enable=$1 338 local ns2_enable=$2 339 340 reset "checksum test ${1} ${2}" || return 1 341 342 ip netns exec $ns1 sysctl -q net.mptcp.checksum_enabled=$ns1_enable 343 ip netns exec $ns2 sysctl -q net.mptcp.checksum_enabled=$ns2_enable 344 345 validate_checksum=true 346} 347 348reset_with_allow_join_id0() 349{ 350 local ns1_enable=$2 351 local ns2_enable=$3 352 353 reset "${1}" || return 1 354 355 ip netns exec $ns1 sysctl -q net.mptcp.allow_join_initial_addr_port=$ns1_enable 356 ip netns exec $ns2 sysctl -q net.mptcp.allow_join_initial_addr_port=$ns2_enable 357} 358 359# Modify TCP payload without corrupting the TCP packet 360# 361# This rule inverts a 8-bit word at byte offset 148 for the 2nd TCP ACK packets 362# carrying enough data. 363# Once it is done, the TCP Checksum field is updated so the packet is still 364# considered as valid at the TCP level. 365# Because the MPTCP checksum, covering the TCP options and data, has not been 366# updated, the modification will be detected and an MP_FAIL will be emitted: 367# what we want to validate here without corrupting "random" MPTCP options. 368# 369# To avoid having tc producing this pr_info() message for each TCP ACK packets 370# not carrying enough data: 371# 372# tc action pedit offset 162 out of bounds 373# 374# Netfilter is used to mark packets with enough data. 375setup_fail_rules() 376{ 377 check_invert=1 378 validate_checksum=true 379 local i="$1" 380 local ip="${2:-4}" 381 local tables 382 383 tables="${iptables}" 384 if [ $ip -eq 6 ]; then 385 tables="${ip6tables}" 386 fi 387 388 ip netns exec $ns2 $tables \ 389 -t mangle \ 390 -A OUTPUT \ 391 -o ns2eth$i \ 392 -p tcp \ 393 -m length --length 150:9999 \ 394 -m statistic --mode nth --packet 1 --every 99999 \ 395 -j MARK --set-mark 42 || return ${KSFT_SKIP} 396 397 tc -n $ns2 qdisc add dev ns2eth$i clsact || return ${KSFT_SKIP} 398 tc -n $ns2 filter add dev ns2eth$i egress \ 399 protocol ip prio 1000 \ 400 handle 42 fw \ 401 action pedit munge offset 148 u8 invert \ 402 pipe csum tcp \ 403 index 100 || return ${KSFT_SKIP} 404} 405 406reset_with_fail() 407{ 408 reset_check_counter "${1}" "MPTcpExtInfiniteMapTx" || return 1 409 shift 410 411 ip netns exec $ns1 sysctl -q net.mptcp.checksum_enabled=1 412 ip netns exec $ns2 sysctl -q net.mptcp.checksum_enabled=1 413 414 local rc=0 415 setup_fail_rules "${@}" || rc=$? 416 417 if [ ${rc} -eq ${KSFT_SKIP} ]; then 418 mark_as_skipped "unable to set the 'fail' rules" 419 return 1 420 fi 421} 422 423reset_with_events() 424{ 425 reset "${1}" || return 1 426 427 mptcp_lib_events "${ns1}" "${evts_ns1}" evts_ns1_pid 428 mptcp_lib_events "${ns2}" "${evts_ns2}" evts_ns2_pid 429} 430 431reset_with_tcp_filter() 432{ 433 reset "${1}" || return 1 434 shift 435 436 local ns="${!1}" 437 local src="${2}" 438 local target="${3}" 439 440 if ! ip netns exec "${ns}" ${iptables} \ 441 -A INPUT \ 442 -s "${src}" \ 443 -p tcp \ 444 -j "${target}"; then 445 mark_as_skipped "unable to set the filter rules" 446 return 1 447 fi 448} 449 450# $1: err msg 451fail_test() 452{ 453 if ! mptcp_lib_subtest_is_flaky; then 454 ret=${KSFT_FAIL} 455 fi 456 457 if [ ${#} -gt 0 ]; then 458 print_fail "${@}" 459 fi 460 461 # just in case a test is marked twice as failed 462 if [ ${last_test_failed} -eq 0 ]; then 463 failed_tests[${MPTCP_LIB_TEST_COUNTER}]="${TEST_NAME}" 464 dump_stats 465 last_test_failed=1 466 fi 467} 468 469get_failed_tests_ids() 470{ 471 # sorted 472 local i 473 for i in "${!failed_tests[@]}"; do 474 echo "${i}" 475 done | sort -n 476} 477 478check_transfer() 479{ 480 local in=$1 481 local out=$2 482 local what=$3 483 local bytes=$4 484 local i a b 485 486 local line 487 if [ -n "$bytes" ]; then 488 local out_size 489 # when truncating we must check the size explicitly 490 out_size=$(wc -c $out | awk '{print $1}') 491 if [ $out_size -ne $bytes ]; then 492 fail_test "$what output file has wrong size ($out_size, $bytes)" 493 return 1 494 fi 495 496 # note: BusyBox's "cmp" command doesn't support --bytes 497 tmpfile=$(mktemp) 498 head --bytes="$bytes" "$in" > "$tmpfile" 499 mv "$tmpfile" "$in" 500 head --bytes="$bytes" "$out" > "$tmpfile" 501 mv "$tmpfile" "$out" 502 tmpfile="" 503 fi 504 cmp -l "$in" "$out" | while read -r i a b; do 505 local sum=$((0${a} + 0${b})) 506 if [ $check_invert -eq 0 ] || [ $sum -ne $((0xff)) ]; then 507 fail_test "$what does not match (in, out):" 508 mptcp_lib_print_file_err "$in" 509 mptcp_lib_print_file_err "$out" 510 511 return 1 512 else 513 print_info "$what has inverted byte at ${i}" 514 fi 515 done 516 517 return 0 518} 519 520do_ping() 521{ 522 local listener_ns="$1" 523 local connector_ns="$2" 524 local connect_addr="$3" 525 526 if ! ip netns exec ${connector_ns} ping -q -c 1 $connect_addr >/dev/null; then 527 fail_test "$listener_ns -> $connect_addr connectivity" 528 fi 529} 530 531link_failure() 532{ 533 local ns="$1" 534 535 if [ -z "$FAILING_LINKS" ]; then 536 l=$((RANDOM%4)) 537 FAILING_LINKS=$((l+1)) 538 fi 539 540 local l 541 for l in $FAILING_LINKS; do 542 local veth="ns1eth$l" 543 ip -net "$ns" link set "$veth" down 544 done 545} 546 547rm_addr_count() 548{ 549 mptcp_lib_get_counter "${1}" "MPTcpExtRmAddr" 550} 551 552# $1: ns, $2: old rm_addr counter in $ns 553wait_rm_addr() 554{ 555 local ns="${1}" 556 local old_cnt="${2}" 557 local cnt 558 559 local i 560 for i in $(seq 10); do 561 cnt=$(rm_addr_count ${ns}) 562 [ "$cnt" = "${old_cnt}" ] || break 563 sleep 0.1 564 done 565} 566 567rm_sf_count() 568{ 569 mptcp_lib_get_counter "${1}" "MPTcpExtRmSubflow" 570} 571 572# $1: ns, $2: old rm_sf counter in $ns 573wait_rm_sf() 574{ 575 local ns="${1}" 576 local old_cnt="${2}" 577 local cnt 578 579 local i 580 for i in $(seq 10); do 581 cnt=$(rm_sf_count ${ns}) 582 [ "$cnt" = "${old_cnt}" ] || break 583 sleep 0.1 584 done 585} 586 587wait_mpj() 588{ 589 local ns="${1}" 590 local cnt old_cnt 591 592 old_cnt=$(mptcp_lib_get_counter ${ns} "MPTcpExtMPJoinAckRx") 593 594 local i 595 for i in $(seq 10); do 596 cnt=$(mptcp_lib_get_counter ${ns} "MPTcpExtMPJoinAckRx") 597 [ "$cnt" = "${old_cnt}" ] || break 598 sleep 0.1 599 done 600} 601 602kill_events_pids() 603{ 604 mptcp_lib_kill_wait $evts_ns1_pid 605 evts_ns1_pid=0 606 mptcp_lib_kill_wait $evts_ns2_pid 607 evts_ns2_pid=0 608} 609 610pm_nl_set_limits() 611{ 612 mptcp_lib_pm_nl_set_limits "${@}" 613} 614 615pm_nl_add_endpoint() 616{ 617 mptcp_lib_pm_nl_add_endpoint "${@}" 618} 619 620pm_nl_del_endpoint() 621{ 622 mptcp_lib_pm_nl_del_endpoint "${@}" 623} 624 625pm_nl_flush_endpoint() 626{ 627 mptcp_lib_pm_nl_flush_endpoint "${@}" 628} 629 630pm_nl_show_endpoints() 631{ 632 mptcp_lib_pm_nl_show_endpoints "${@}" 633} 634 635pm_nl_change_endpoint() 636{ 637 mptcp_lib_pm_nl_change_endpoint "${@}" 638} 639 640pm_nl_check_endpoint() 641{ 642 local msg="$1" 643 local ns=$2 644 local addr=$3 645 local flags dev id port 646 647 print_check "${msg}" 648 649 shift 3 650 while [ -n "$1" ]; do 651 case "${1}" in 652 "flags" | "dev" | "id" | "port") 653 eval "${1}"="${2}" 654 shift 655 ;; 656 *) 657 ;; 658 esac 659 660 shift 661 done 662 663 if [ -z "${id}" ]; then 664 test_fail "bad test - missing endpoint id" 665 return 666 fi 667 668 check_output "mptcp_lib_pm_nl_get_endpoint ${ns} ${id}" \ 669 "$(mptcp_lib_pm_nl_format_endpoints \ 670 "${id},${addr},${flags//","/" "},${dev},${port}")" 671} 672 673pm_nl_set_endpoint() 674{ 675 local listener_ns="$1" 676 local connector_ns="$2" 677 local connect_addr="$3" 678 679 local addr_nr_ns1=${addr_nr_ns1:-0} 680 local addr_nr_ns2=${addr_nr_ns2:-0} 681 local sflags=${sflags:-""} 682 local fullmesh=${fullmesh:-""} 683 684 local flags="subflow" 685 if [ -n "${fullmesh}" ]; then 686 flags="${flags},fullmesh" 687 addr_nr_ns2=${fullmesh} 688 fi 689 690 # let the mptcp subflow be established in background before 691 # do endpoint manipulation 692 if [ $addr_nr_ns1 != "0" ] || [ $addr_nr_ns2 != "0" ]; then 693 sleep 1 694 fi 695 696 if [ $addr_nr_ns1 -gt 0 ]; then 697 local counter=2 698 local add_nr_ns1=${addr_nr_ns1} 699 local id=10 700 while [ $add_nr_ns1 -gt 0 ]; do 701 local addr 702 if mptcp_lib_is_v6 "${connect_addr}"; then 703 addr="dead:beef:$counter::1" 704 else 705 addr="10.0.$counter.1" 706 fi 707 pm_nl_add_endpoint $ns1 $addr flags signal 708 counter=$((counter + 1)) 709 add_nr_ns1=$((add_nr_ns1 - 1)) 710 id=$((id + 1)) 711 done 712 elif [ $addr_nr_ns1 -lt 0 ]; then 713 local rm_nr_ns1=$((-addr_nr_ns1)) 714 if [ $rm_nr_ns1 -lt 8 ]; then 715 local counter=0 716 local line 717 pm_nl_show_endpoints ${listener_ns} | while read -r line; do 718 # shellcheck disable=SC2206 # we do want to split per word 719 local arr=($line) 720 local nr=0 721 722 local i 723 for i in "${arr[@]}"; do 724 if [ $i = "id" ]; then 725 if [ $counter -eq $rm_nr_ns1 ]; then 726 break 727 fi 728 id=${arr[$nr+1]} 729 rm_addr=$(rm_addr_count ${connector_ns}) 730 pm_nl_del_endpoint ${listener_ns} $id 731 wait_rm_addr ${connector_ns} ${rm_addr} 732 counter=$((counter + 1)) 733 fi 734 nr=$((nr + 1)) 735 done 736 done 737 elif [ $rm_nr_ns1 -eq 8 ]; then 738 pm_nl_flush_endpoint ${listener_ns} 739 elif [ $rm_nr_ns1 -eq 9 ]; then 740 pm_nl_del_endpoint ${listener_ns} 0 ${connect_addr} 741 fi 742 fi 743 744 # if newly added endpoints must be deleted, give the background msk 745 # some time to created them 746 [ $addr_nr_ns1 -gt 0 ] && [ $addr_nr_ns2 -lt 0 ] && sleep 1 747 748 if [ $addr_nr_ns2 -gt 0 ]; then 749 local add_nr_ns2=${addr_nr_ns2} 750 local counter=3 751 local id=20 752 while [ $add_nr_ns2 -gt 0 ]; do 753 local addr 754 if mptcp_lib_is_v6 "${connect_addr}"; then 755 addr="dead:beef:$counter::2" 756 else 757 addr="10.0.$counter.2" 758 fi 759 pm_nl_add_endpoint $ns2 $addr flags $flags 760 counter=$((counter + 1)) 761 add_nr_ns2=$((add_nr_ns2 - 1)) 762 id=$((id + 1)) 763 done 764 elif [ $addr_nr_ns2 -lt 0 ]; then 765 local rm_nr_ns2=$((-addr_nr_ns2)) 766 if [ $rm_nr_ns2 -lt 8 ]; then 767 local counter=0 768 local line 769 pm_nl_show_endpoints ${connector_ns} | while read -r line; do 770 # shellcheck disable=SC2206 # we do want to split per word 771 local arr=($line) 772 local nr=0 773 774 local i 775 for i in "${arr[@]}"; do 776 if [ $i = "id" ]; then 777 if [ $counter -eq $rm_nr_ns2 ]; then 778 break 779 fi 780 local id rm_addr 781 # rm_addr are serialized, allow the previous one to 782 # complete 783 id=${arr[$nr+1]} 784 rm_addr=$(rm_addr_count ${listener_ns}) 785 pm_nl_del_endpoint ${connector_ns} $id 786 wait_rm_addr ${listener_ns} ${rm_addr} 787 counter=$((counter + 1)) 788 fi 789 nr=$((nr + 1)) 790 done 791 done 792 elif [ $rm_nr_ns2 -eq 8 ]; then 793 pm_nl_flush_endpoint ${connector_ns} 794 elif [ $rm_nr_ns2 -eq 9 ]; then 795 local addr 796 if mptcp_lib_is_v6 "${connect_addr}"; then 797 addr="dead:beef:1::2" 798 else 799 addr="10.0.1.2" 800 fi 801 pm_nl_del_endpoint ${connector_ns} 0 $addr 802 fi 803 fi 804 805 if [ -n "${sflags}" ]; then 806 sleep 1 807 808 local netns 809 for netns in "$ns1" "$ns2"; do 810 local line 811 pm_nl_show_endpoints $netns | while read -r line; do 812 # shellcheck disable=SC2206 # we do want to split per word 813 local arr=($line) 814 local nr=0 815 local id 816 817 local i 818 for i in "${arr[@]}"; do 819 if [ $i = "id" ]; then 820 id=${arr[$nr+1]} 821 fi 822 nr=$((nr + 1)) 823 done 824 pm_nl_change_endpoint $netns $id $sflags 825 done 826 done 827 fi 828} 829 830chk_cestab_nr() 831{ 832 local ns=$1 833 local cestab=$2 834 local count 835 836 print_check "cestab $cestab" 837 count=$(mptcp_lib_get_counter ${ns} "MPTcpExtMPCurrEstab") 838 if [ -z "$count" ]; then 839 print_skip 840 elif [ "$count" != "$cestab" ]; then 841 fail_test "got $count current establish[s] expected $cestab" 842 else 843 print_ok 844 fi 845} 846 847# $1 namespace 1, $2 namespace 2 848check_cestab() 849{ 850 if [ -n "${cestab_ns1}" ]; then 851 chk_cestab_nr ${1} ${cestab_ns1} 852 fi 853 if [ -n "${cestab_ns2}" ]; then 854 chk_cestab_nr ${2} ${cestab_ns2} 855 fi 856} 857 858do_transfer() 859{ 860 local listener_ns="$1" 861 local connector_ns="$2" 862 local cl_proto="$3" 863 local srv_proto="$4" 864 local connect_addr="$5" 865 866 local port=$((10000 + MPTCP_LIB_TEST_COUNTER - 1)) 867 local cappid 868 local FAILING_LINKS=${FAILING_LINKS:-""} 869 local fastclose=${fastclose:-""} 870 local speed=${speed:-"fast"} 871 872 :> "$cout" 873 :> "$sout" 874 :> "$capout" 875 876 if $capture; then 877 local capuser 878 if [ -z $SUDO_USER ] ; then 879 capuser="" 880 else 881 capuser="-Z $SUDO_USER" 882 fi 883 884 capfile=$(printf "mp_join-%02u-%s.pcap" "$MPTCP_LIB_TEST_COUNTER" "${listener_ns}") 885 886 echo "Capturing traffic for test $MPTCP_LIB_TEST_COUNTER into $capfile" 887 ip netns exec ${listener_ns} tcpdump -i any -s 65535 -B 32768 $capuser -w $capfile > "$capout" 2>&1 & 888 cappid=$! 889 890 sleep 1 891 fi 892 893 NSTAT_HISTORY=/tmp/${listener_ns}.nstat ip netns exec ${listener_ns} \ 894 nstat -n 895 NSTAT_HISTORY=/tmp/${connector_ns}.nstat ip netns exec ${connector_ns} \ 896 nstat -n 897 898 local extra_args 899 if [ $speed = "fast" ]; then 900 extra_args="-j" 901 elif [ $speed = "slow" ]; then 902 extra_args="-r 50" 903 elif [ $speed -gt 0 ]; then 904 extra_args="-r ${speed}" 905 fi 906 907 local extra_cl_args="" 908 local extra_srv_args="" 909 local trunc_size="" 910 if [ -n "${fastclose}" ]; then 911 if [ ${test_linkfail} -le 1 ]; then 912 fail_test "fastclose tests need test_linkfail argument" 913 return 1 914 fi 915 916 # disconnect 917 trunc_size=${test_linkfail} 918 local side=${fastclose} 919 920 if [ ${side} = "client" ]; then 921 extra_cl_args="-f ${test_linkfail}" 922 extra_srv_args="-f -1" 923 elif [ ${side} = "server" ]; then 924 extra_srv_args="-f ${test_linkfail}" 925 extra_cl_args="-f -1" 926 else 927 fail_test "wrong/unknown fastclose spec ${side}" 928 return 1 929 fi 930 fi 931 932 extra_srv_args="$extra_args $extra_srv_args" 933 if [ "$test_linkfail" -gt 1 ];then 934 timeout ${timeout_test} \ 935 ip netns exec ${listener_ns} \ 936 ./mptcp_connect -t ${timeout_poll} -l -p $port -s ${srv_proto} \ 937 $extra_srv_args "::" < "$sinfail" > "$sout" & 938 else 939 timeout ${timeout_test} \ 940 ip netns exec ${listener_ns} \ 941 ./mptcp_connect -t ${timeout_poll} -l -p $port -s ${srv_proto} \ 942 $extra_srv_args "::" < "$sin" > "$sout" & 943 fi 944 local spid=$! 945 946 mptcp_lib_wait_local_port_listen "${listener_ns}" "${port}" 947 948 extra_cl_args="$extra_args $extra_cl_args" 949 if [ "$test_linkfail" -eq 0 ];then 950 timeout ${timeout_test} \ 951 ip netns exec ${connector_ns} \ 952 ./mptcp_connect -t ${timeout_poll} -p $port -s ${cl_proto} \ 953 $extra_cl_args $connect_addr < "$cin" > "$cout" & 954 elif [ "$test_linkfail" -eq 1 ] || [ "$test_linkfail" -eq 2 ];then 955 ( cat "$cinfail" ; sleep 2; link_failure $listener_ns ; cat "$cinfail" ) | \ 956 tee "$cinsent" | \ 957 timeout ${timeout_test} \ 958 ip netns exec ${connector_ns} \ 959 ./mptcp_connect -t ${timeout_poll} -p $port -s ${cl_proto} \ 960 $extra_cl_args $connect_addr > "$cout" & 961 else 962 tee "$cinsent" < "$cinfail" | \ 963 timeout ${timeout_test} \ 964 ip netns exec ${connector_ns} \ 965 ./mptcp_connect -t ${timeout_poll} -p $port -s ${cl_proto} \ 966 $extra_cl_args $connect_addr > "$cout" & 967 fi 968 local cpid=$! 969 970 pm_nl_set_endpoint $listener_ns $connector_ns $connect_addr 971 check_cestab $listener_ns $connector_ns 972 973 wait $cpid 974 local retc=$? 975 wait $spid 976 local rets=$? 977 978 if $capture; then 979 sleep 1 980 kill $cappid 981 fi 982 983 NSTAT_HISTORY=/tmp/${listener_ns}.nstat ip netns exec ${listener_ns} \ 984 nstat | grep Tcp > /tmp/${listener_ns}.out 985 NSTAT_HISTORY=/tmp/${connector_ns}.nstat ip netns exec ${connector_ns} \ 986 nstat | grep Tcp > /tmp/${connector_ns}.out 987 988 if [ ${rets} -ne 0 ] || [ ${retc} -ne 0 ]; then 989 fail_test "client exit code $retc, server $rets" 990 echo -e "\nnetns ${listener_ns} socket stat for ${port}:" 1>&2 991 ip netns exec ${listener_ns} ss -Menita 1>&2 -o "sport = :$port" 992 cat /tmp/${listener_ns}.out 993 echo -e "\nnetns ${connector_ns} socket stat for ${port}:" 1>&2 994 ip netns exec ${connector_ns} ss -Menita 1>&2 -o "dport = :$port" 995 cat /tmp/${connector_ns}.out 996 997 cat "$capout" 998 return 1 999 fi 1000 1001 if [ "$test_linkfail" -gt 1 ];then 1002 check_transfer $sinfail $cout "file received by client" $trunc_size 1003 else 1004 check_transfer $sin $cout "file received by client" $trunc_size 1005 fi 1006 retc=$? 1007 if [ "$test_linkfail" -eq 0 ];then 1008 check_transfer $cin $sout "file received by server" $trunc_size 1009 else 1010 check_transfer $cinsent $sout "file received by server" $trunc_size 1011 fi 1012 rets=$? 1013 1014 if [ $retc -eq 0 ] && [ $rets -eq 0 ];then 1015 cat "$capout" 1016 return 0 1017 fi 1018 1019 cat "$capout" 1020 return 1 1021} 1022 1023make_file() 1024{ 1025 local name=$1 1026 local who=$2 1027 local size=$3 1028 1029 mptcp_lib_make_file $name 1024 $size 1030 1031 print_info "Test file (size $size KB) for $who" 1032} 1033 1034run_tests() 1035{ 1036 local listener_ns="$1" 1037 local connector_ns="$2" 1038 local connect_addr="$3" 1039 1040 local size 1041 local test_linkfail=${test_linkfail:-0} 1042 1043 # The values above 2 are reused to make test files 1044 # with the given sizes (KB) 1045 if [ "$test_linkfail" -gt 2 ]; then 1046 size=$test_linkfail 1047 1048 if [ -z "$cinfail" ]; then 1049 cinfail=$(mktemp) 1050 fi 1051 make_file "$cinfail" "client" $size 1052 # create the input file for the failure test when 1053 # the first failure test run 1054 elif [ "$test_linkfail" -ne 0 ] && [ -z "$cinfail" ]; then 1055 # the client file must be considerably larger 1056 # of the maximum expected cwin value, or the 1057 # link utilization will be not predicable 1058 size=$((RANDOM%2)) 1059 size=$((size+1)) 1060 size=$((size*8192)) 1061 size=$((size + ( RANDOM % 8192) )) 1062 1063 cinfail=$(mktemp) 1064 make_file "$cinfail" "client" $size 1065 fi 1066 1067 if [ "$test_linkfail" -gt 2 ]; then 1068 size=$test_linkfail 1069 1070 if [ -z "$sinfail" ]; then 1071 sinfail=$(mktemp) 1072 fi 1073 make_file "$sinfail" "server" $size 1074 elif [ "$test_linkfail" -eq 2 ] && [ -z "$sinfail" ]; then 1075 size=$((RANDOM%16)) 1076 size=$((size+1)) 1077 size=$((size*2048)) 1078 1079 sinfail=$(mktemp) 1080 make_file "$sinfail" "server" $size 1081 fi 1082 1083 do_transfer ${listener_ns} ${connector_ns} MPTCP MPTCP ${connect_addr} 1084} 1085 1086dump_stats() 1087{ 1088 echo Server ns stats 1089 ip netns exec $ns1 nstat -as | grep Tcp 1090 echo Client ns stats 1091 ip netns exec $ns2 nstat -as | grep Tcp 1092} 1093 1094chk_csum_nr() 1095{ 1096 local csum_ns1=${1:-0} 1097 local csum_ns2=${2:-0} 1098 local count 1099 local extra_msg="" 1100 local allow_multi_errors_ns1=0 1101 local allow_multi_errors_ns2=0 1102 1103 if [[ "${csum_ns1}" = "+"* ]]; then 1104 allow_multi_errors_ns1=1 1105 csum_ns1=${csum_ns1:1} 1106 fi 1107 if [[ "${csum_ns2}" = "+"* ]]; then 1108 allow_multi_errors_ns2=1 1109 csum_ns2=${csum_ns2:1} 1110 fi 1111 1112 print_check "sum" 1113 count=$(mptcp_lib_get_counter ${ns1} "MPTcpExtDataCsumErr") 1114 if [ "$count" != "$csum_ns1" ]; then 1115 extra_msg+=" ns1=$count" 1116 fi 1117 if [ -z "$count" ]; then 1118 print_skip 1119 elif { [ "$count" != $csum_ns1 ] && [ $allow_multi_errors_ns1 -eq 0 ]; } || 1120 { [ "$count" -lt $csum_ns1 ] && [ $allow_multi_errors_ns1 -eq 1 ]; }; then 1121 fail_test "got $count data checksum error[s] expected $csum_ns1" 1122 else 1123 print_ok 1124 fi 1125 print_check "csum" 1126 count=$(mptcp_lib_get_counter ${ns2} "MPTcpExtDataCsumErr") 1127 if [ "$count" != "$csum_ns2" ]; then 1128 extra_msg+=" ns2=$count" 1129 fi 1130 if [ -z "$count" ]; then 1131 print_skip 1132 elif { [ "$count" != $csum_ns2 ] && [ $allow_multi_errors_ns2 -eq 0 ]; } || 1133 { [ "$count" -lt $csum_ns2 ] && [ $allow_multi_errors_ns2 -eq 1 ]; }; then 1134 fail_test "got $count data checksum error[s] expected $csum_ns2" 1135 else 1136 print_ok 1137 fi 1138 1139 print_info "$extra_msg" 1140} 1141 1142chk_fail_nr() 1143{ 1144 local fail_tx=$1 1145 local fail_rx=$2 1146 local ns_invert=${3:-""} 1147 local count 1148 local ns_tx=$ns1 1149 local ns_rx=$ns2 1150 local extra_msg="" 1151 local allow_tx_lost=0 1152 local allow_rx_lost=0 1153 1154 if [[ $ns_invert = "invert" ]]; then 1155 ns_tx=$ns2 1156 ns_rx=$ns1 1157 extra_msg="invert" 1158 fi 1159 1160 if [[ "${fail_tx}" = "-"* ]]; then 1161 allow_tx_lost=1 1162 fail_tx=${fail_tx:1} 1163 fi 1164 if [[ "${fail_rx}" = "-"* ]]; then 1165 allow_rx_lost=1 1166 fail_rx=${fail_rx:1} 1167 fi 1168 1169 print_check "ftx" 1170 count=$(mptcp_lib_get_counter ${ns_tx} "MPTcpExtMPFailTx") 1171 if [ "$count" != "$fail_tx" ]; then 1172 extra_msg+=",tx=$count" 1173 fi 1174 if [ -z "$count" ]; then 1175 print_skip 1176 elif { [ "$count" != "$fail_tx" ] && [ $allow_tx_lost -eq 0 ]; } || 1177 { [ "$count" -gt "$fail_tx" ] && [ $allow_tx_lost -eq 1 ]; }; then 1178 fail_test "got $count MP_FAIL[s] TX expected $fail_tx" 1179 else 1180 print_ok 1181 fi 1182 1183 print_check "failrx" 1184 count=$(mptcp_lib_get_counter ${ns_rx} "MPTcpExtMPFailRx") 1185 if [ "$count" != "$fail_rx" ]; then 1186 extra_msg+=",rx=$count" 1187 fi 1188 if [ -z "$count" ]; then 1189 print_skip 1190 elif { [ "$count" != "$fail_rx" ] && [ $allow_rx_lost -eq 0 ]; } || 1191 { [ "$count" -gt "$fail_rx" ] && [ $allow_rx_lost -eq 1 ]; }; then 1192 fail_test "got $count MP_FAIL[s] RX expected $fail_rx" 1193 else 1194 print_ok 1195 fi 1196 1197 print_info "$extra_msg" 1198} 1199 1200chk_fclose_nr() 1201{ 1202 local fclose_tx=$1 1203 local fclose_rx=$2 1204 local ns_invert=$3 1205 local count 1206 local ns_tx=$ns2 1207 local ns_rx=$ns1 1208 local extra_msg="" 1209 1210 if [[ $ns_invert = "invert" ]]; then 1211 ns_tx=$ns1 1212 ns_rx=$ns2 1213 extra_msg="invert" 1214 fi 1215 1216 print_check "ctx" 1217 count=$(mptcp_lib_get_counter ${ns_tx} "MPTcpExtMPFastcloseTx") 1218 if [ -z "$count" ]; then 1219 print_skip 1220 elif [ "$count" != "$fclose_tx" ]; then 1221 extra_msg+=",tx=$count" 1222 fail_test "got $count MP_FASTCLOSE[s] TX expected $fclose_tx" 1223 else 1224 print_ok 1225 fi 1226 1227 print_check "fclzrx" 1228 count=$(mptcp_lib_get_counter ${ns_rx} "MPTcpExtMPFastcloseRx") 1229 if [ -z "$count" ]; then 1230 print_skip 1231 elif [ "$count" != "$fclose_rx" ]; then 1232 extra_msg+=",rx=$count" 1233 fail_test "got $count MP_FASTCLOSE[s] RX expected $fclose_rx" 1234 else 1235 print_ok 1236 fi 1237 1238 print_info "$extra_msg" 1239} 1240 1241chk_rst_nr() 1242{ 1243 local rst_tx=$1 1244 local rst_rx=$2 1245 local ns_invert=${3:-""} 1246 local count 1247 local ns_tx=$ns1 1248 local ns_rx=$ns2 1249 local extra_msg="" 1250 1251 if [[ $ns_invert = "invert" ]]; then 1252 ns_tx=$ns2 1253 ns_rx=$ns1 1254 extra_msg="invert" 1255 fi 1256 1257 print_check "rtx" 1258 count=$(mptcp_lib_get_counter ${ns_tx} "MPTcpExtMPRstTx") 1259 if [ -z "$count" ]; then 1260 print_skip 1261 # accept more rst than expected except if we don't expect any 1262 elif { [ $rst_tx -ne 0 ] && [ $count -lt $rst_tx ]; } || 1263 { [ $rst_tx -eq 0 ] && [ $count -ne 0 ]; }; then 1264 fail_test "got $count MP_RST[s] TX expected $rst_tx" 1265 else 1266 print_ok 1267 fi 1268 1269 print_check "rstrx" 1270 count=$(mptcp_lib_get_counter ${ns_rx} "MPTcpExtMPRstRx") 1271 if [ -z "$count" ]; then 1272 print_skip 1273 # accept more rst than expected except if we don't expect any 1274 elif { [ $rst_rx -ne 0 ] && [ $count -lt $rst_rx ]; } || 1275 { [ $rst_rx -eq 0 ] && [ $count -ne 0 ]; }; then 1276 fail_test "got $count MP_RST[s] RX expected $rst_rx" 1277 else 1278 print_ok 1279 fi 1280 1281 print_info "$extra_msg" 1282} 1283 1284chk_infi_nr() 1285{ 1286 local infi_tx=$1 1287 local infi_rx=$2 1288 local count 1289 1290 print_check "itx" 1291 count=$(mptcp_lib_get_counter ${ns2} "MPTcpExtInfiniteMapTx") 1292 if [ -z "$count" ]; then 1293 print_skip 1294 elif [ "$count" != "$infi_tx" ]; then 1295 fail_test "got $count infinite map[s] TX expected $infi_tx" 1296 else 1297 print_ok 1298 fi 1299 1300 print_check "infirx" 1301 count=$(mptcp_lib_get_counter ${ns1} "MPTcpExtInfiniteMapRx") 1302 if [ -z "$count" ]; then 1303 print_skip 1304 elif [ "$count" != "$infi_rx" ]; then 1305 fail_test "got $count infinite map[s] RX expected $infi_rx" 1306 else 1307 print_ok 1308 fi 1309} 1310 1311chk_join_nr() 1312{ 1313 local syn_nr=$1 1314 local syn_ack_nr=$2 1315 local ack_nr=$3 1316 local csum_ns1=${4:-0} 1317 local csum_ns2=${5:-0} 1318 local fail_nr=${6:-0} 1319 local rst_nr=${7:-0} 1320 local infi_nr=${8:-0} 1321 local corrupted_pkts=${9:-0} 1322 local count 1323 local with_cookie 1324 1325 if [ "${corrupted_pkts}" -gt 0 ]; then 1326 print_info "${corrupted_pkts} corrupted pkts" 1327 fi 1328 1329 print_check "syn" 1330 count=$(mptcp_lib_get_counter ${ns1} "MPTcpExtMPJoinSynRx") 1331 if [ -z "$count" ]; then 1332 print_skip 1333 elif [ "$count" != "$syn_nr" ]; then 1334 fail_test "got $count JOIN[s] syn expected $syn_nr" 1335 else 1336 print_ok 1337 fi 1338 1339 print_check "synack" 1340 with_cookie=$(ip netns exec $ns2 sysctl -n net.ipv4.tcp_syncookies) 1341 count=$(mptcp_lib_get_counter ${ns2} "MPTcpExtMPJoinSynAckRx") 1342 if [ -z "$count" ]; then 1343 print_skip 1344 elif [ "$count" != "$syn_ack_nr" ]; then 1345 # simult connections exceeding the limit with cookie enabled could go up to 1346 # synack validation as the conn limit can be enforced reliably only after 1347 # the subflow creation 1348 if [ "$with_cookie" = 2 ] && [ "$count" -gt "$syn_ack_nr" ] && [ "$count" -le "$syn_nr" ]; then 1349 print_ok 1350 else 1351 fail_test "got $count JOIN[s] synack expected $syn_ack_nr" 1352 fi 1353 else 1354 print_ok 1355 fi 1356 1357 print_check "ack" 1358 count=$(mptcp_lib_get_counter ${ns1} "MPTcpExtMPJoinAckRx") 1359 if [ -z "$count" ]; then 1360 print_skip 1361 elif [ "$count" != "$ack_nr" ]; then 1362 fail_test "got $count JOIN[s] ack expected $ack_nr" 1363 else 1364 print_ok 1365 fi 1366 if $validate_checksum; then 1367 chk_csum_nr $csum_ns1 $csum_ns2 1368 chk_fail_nr $fail_nr $fail_nr 1369 chk_rst_nr $rst_nr $rst_nr 1370 chk_infi_nr $infi_nr $infi_nr 1371 fi 1372} 1373 1374# a negative value for 'stale_max' means no upper bound: 1375# for bidirectional transfer, if one peer sleep for a while 1376# - as these tests do - we can have a quite high number of 1377# stale/recover conversions, proportional to 1378# sleep duration/ MPTCP-level RTX interval. 1379chk_stale_nr() 1380{ 1381 local ns=$1 1382 local stale_min=$2 1383 local stale_max=$3 1384 local stale_delta=$4 1385 local dump_stats 1386 local stale_nr 1387 local recover_nr 1388 1389 print_check "stale" 1390 1391 stale_nr=$(mptcp_lib_get_counter ${ns} "MPTcpExtSubflowStale") 1392 recover_nr=$(mptcp_lib_get_counter ${ns} "MPTcpExtSubflowRecover") 1393 if [ -z "$stale_nr" ] || [ -z "$recover_nr" ]; then 1394 print_skip 1395 elif [ $stale_nr -lt $stale_min ] || 1396 { [ $stale_max -gt 0 ] && [ $stale_nr -gt $stale_max ]; } || 1397 [ $((stale_nr - recover_nr)) -ne $stale_delta ]; then 1398 fail_test "got $stale_nr stale[s] $recover_nr recover[s], " \ 1399 " expected stale in range [$stale_min..$stale_max]," \ 1400 " stale-recover delta $stale_delta" 1401 dump_stats=1 1402 else 1403 print_ok 1404 fi 1405 1406 if [ "${dump_stats}" = 1 ]; then 1407 echo $ns stats 1408 ip netns exec $ns ip -s link show 1409 ip netns exec $ns nstat -as | grep MPTcp 1410 fi 1411} 1412 1413chk_add_nr() 1414{ 1415 local add_nr=$1 1416 local echo_nr=$2 1417 local port_nr=${3:-0} 1418 local syn_nr=${4:-$port_nr} 1419 local syn_ack_nr=${5:-$port_nr} 1420 local ack_nr=${6:-$port_nr} 1421 local mis_syn_nr=${7:-0} 1422 local mis_ack_nr=${8:-0} 1423 local count 1424 local timeout 1425 1426 timeout=$(ip netns exec $ns1 sysctl -n net.mptcp.add_addr_timeout) 1427 1428 print_check "add" 1429 count=$(mptcp_lib_get_counter ${ns2} "MPTcpExtAddAddr") 1430 if [ -z "$count" ]; then 1431 print_skip 1432 # if the test configured a short timeout tolerate greater then expected 1433 # add addrs options, due to retransmissions 1434 elif [ "$count" != "$add_nr" ] && { [ "$timeout" -gt 1 ] || [ "$count" -lt "$add_nr" ]; }; then 1435 fail_test "got $count ADD_ADDR[s] expected $add_nr" 1436 else 1437 print_ok 1438 fi 1439 1440 print_check "echo" 1441 count=$(mptcp_lib_get_counter ${ns1} "MPTcpExtEchoAdd") 1442 if [ -z "$count" ]; then 1443 print_skip 1444 elif [ "$count" != "$echo_nr" ]; then 1445 fail_test "got $count ADD_ADDR echo[s] expected $echo_nr" 1446 else 1447 print_ok 1448 fi 1449 1450 if [ $port_nr -gt 0 ]; then 1451 print_check "pt" 1452 count=$(mptcp_lib_get_counter ${ns2} "MPTcpExtPortAdd") 1453 if [ -z "$count" ]; then 1454 print_skip 1455 elif [ "$count" != "$port_nr" ]; then 1456 fail_test "got $count ADD_ADDR[s] with a port-number expected $port_nr" 1457 else 1458 print_ok 1459 fi 1460 1461 print_check "syn" 1462 count=$(mptcp_lib_get_counter ${ns1} "MPTcpExtMPJoinPortSynRx") 1463 if [ -z "$count" ]; then 1464 print_skip 1465 elif [ "$count" != "$syn_nr" ]; then 1466 fail_test "got $count JOIN[s] syn with a different \ 1467 port-number expected $syn_nr" 1468 else 1469 print_ok 1470 fi 1471 1472 print_check "synack" 1473 count=$(mptcp_lib_get_counter ${ns2} "MPTcpExtMPJoinPortSynAckRx") 1474 if [ -z "$count" ]; then 1475 print_skip 1476 elif [ "$count" != "$syn_ack_nr" ]; then 1477 fail_test "got $count JOIN[s] synack with a different \ 1478 port-number expected $syn_ack_nr" 1479 else 1480 print_ok 1481 fi 1482 1483 print_check "ack" 1484 count=$(mptcp_lib_get_counter ${ns1} "MPTcpExtMPJoinPortAckRx") 1485 if [ -z "$count" ]; then 1486 print_skip 1487 elif [ "$count" != "$ack_nr" ]; then 1488 fail_test "got $count JOIN[s] ack with a different \ 1489 port-number expected $ack_nr" 1490 else 1491 print_ok 1492 fi 1493 1494 print_check "syn" 1495 count=$(mptcp_lib_get_counter ${ns1} "MPTcpExtMismatchPortSynRx") 1496 if [ -z "$count" ]; then 1497 print_skip 1498 elif [ "$count" != "$mis_syn_nr" ]; then 1499 fail_test "got $count JOIN[s] syn with a mismatched \ 1500 port-number expected $mis_syn_nr" 1501 else 1502 print_ok 1503 fi 1504 1505 print_check "ack" 1506 count=$(mptcp_lib_get_counter ${ns1} "MPTcpExtMismatchPortAckRx") 1507 if [ -z "$count" ]; then 1508 print_skip 1509 elif [ "$count" != "$mis_ack_nr" ]; then 1510 fail_test "got $count JOIN[s] ack with a mismatched \ 1511 port-number expected $mis_ack_nr" 1512 else 1513 print_ok 1514 fi 1515 fi 1516} 1517 1518chk_add_tx_nr() 1519{ 1520 local add_tx_nr=$1 1521 local echo_tx_nr=$2 1522 local timeout 1523 local count 1524 1525 timeout=$(ip netns exec $ns1 sysctl -n net.mptcp.add_addr_timeout) 1526 1527 print_check "add TX" 1528 count=$(mptcp_lib_get_counter ${ns1} "MPTcpExtAddAddrTx") 1529 if [ -z "$count" ]; then 1530 print_skip 1531 # if the test configured a short timeout tolerate greater then expected 1532 # add addrs options, due to retransmissions 1533 elif [ "$count" != "$add_tx_nr" ] && { [ "$timeout" -gt 1 ] || [ "$count" -lt "$add_tx_nr" ]; }; then 1534 fail_test "got $count ADD_ADDR[s] TX, expected $add_tx_nr" 1535 else 1536 print_ok 1537 fi 1538 1539 print_check "echo TX" 1540 count=$(mptcp_lib_get_counter ${ns2} "MPTcpExtEchoAddTx") 1541 if [ -z "$count" ]; then 1542 print_skip 1543 elif [ "$count" != "$echo_tx_nr" ]; then 1544 fail_test "got $count ADD_ADDR echo[s] TX, expected $echo_tx_nr" 1545 else 1546 print_ok 1547 fi 1548} 1549 1550chk_rm_nr() 1551{ 1552 local rm_addr_nr=$1 1553 local rm_subflow_nr=$2 1554 local invert 1555 local simult 1556 local count 1557 local addr_ns=$ns1 1558 local subflow_ns=$ns2 1559 local extra_msg="" 1560 1561 shift 2 1562 while [ -n "$1" ]; do 1563 [ "$1" = "invert" ] && invert=true 1564 [ "$1" = "simult" ] && simult=true 1565 shift 1566 done 1567 1568 if [ -z $invert ]; then 1569 addr_ns=$ns1 1570 subflow_ns=$ns2 1571 elif [ $invert = "true" ]; then 1572 addr_ns=$ns2 1573 subflow_ns=$ns1 1574 extra_msg="invert" 1575 fi 1576 1577 print_check "rm" 1578 count=$(mptcp_lib_get_counter ${addr_ns} "MPTcpExtRmAddr") 1579 if [ -z "$count" ]; then 1580 print_skip 1581 elif [ "$count" != "$rm_addr_nr" ]; then 1582 fail_test "got $count RM_ADDR[s] expected $rm_addr_nr" 1583 else 1584 print_ok 1585 fi 1586 1587 print_check "rmsf" 1588 count=$(mptcp_lib_get_counter ${subflow_ns} "MPTcpExtRmSubflow") 1589 if [ -z "$count" ]; then 1590 print_skip 1591 elif [ -n "$simult" ]; then 1592 local cnt suffix 1593 1594 cnt=$(mptcp_lib_get_counter ${addr_ns} "MPTcpExtRmSubflow") 1595 1596 # in case of simult flush, the subflow removal count on each side is 1597 # unreliable 1598 count=$((count + cnt)) 1599 if [ "$count" != "$rm_subflow_nr" ]; then 1600 suffix="$count in [$rm_subflow_nr:$((rm_subflow_nr*2))]" 1601 extra_msg+=" simult" 1602 fi 1603 if [ $count -ge "$rm_subflow_nr" ] && \ 1604 [ "$count" -le "$((rm_subflow_nr *2 ))" ]; then 1605 print_ok "$suffix" 1606 else 1607 fail_test "got $count RM_SUBFLOW[s] expected in range [$rm_subflow_nr:$((rm_subflow_nr*2))]" 1608 fi 1609 elif [ "$count" != "$rm_subflow_nr" ]; then 1610 fail_test "got $count RM_SUBFLOW[s] expected $rm_subflow_nr" 1611 else 1612 print_ok 1613 fi 1614 1615 print_info "$extra_msg" 1616} 1617 1618chk_rm_tx_nr() 1619{ 1620 local rm_addr_tx_nr=$1 1621 1622 print_check "rm TX" 1623 count=$(mptcp_lib_get_counter ${ns2} "MPTcpExtRmAddrTx") 1624 if [ -z "$count" ]; then 1625 print_skip 1626 elif [ "$count" != "$rm_addr_tx_nr" ]; then 1627 fail_test "got $count RM_ADDR[s] expected $rm_addr_tx_nr" 1628 else 1629 print_ok 1630 fi 1631} 1632 1633chk_prio_nr() 1634{ 1635 local mp_prio_nr_tx=$1 1636 local mp_prio_nr_rx=$2 1637 local count 1638 1639 print_check "ptx" 1640 count=$(mptcp_lib_get_counter ${ns1} "MPTcpExtMPPrioTx") 1641 if [ -z "$count" ]; then 1642 print_skip 1643 elif [ "$count" != "$mp_prio_nr_tx" ]; then 1644 fail_test "got $count MP_PRIO[s] TX expected $mp_prio_nr_tx" 1645 else 1646 print_ok 1647 fi 1648 1649 print_check "prx" 1650 count=$(mptcp_lib_get_counter ${ns1} "MPTcpExtMPPrioRx") 1651 if [ -z "$count" ]; then 1652 print_skip 1653 elif [ "$count" != "$mp_prio_nr_rx" ]; then 1654 fail_test "got $count MP_PRIO[s] RX expected $mp_prio_nr_rx" 1655 else 1656 print_ok 1657 fi 1658} 1659 1660chk_subflow_nr() 1661{ 1662 local msg="$1" 1663 local subflow_nr=$2 1664 local cnt1 1665 local cnt2 1666 local dump_stats 1667 1668 print_check "${msg}" 1669 1670 cnt1=$(ss -N $ns1 -tOni | grep -c token) 1671 cnt2=$(ss -N $ns2 -tOni | grep -c token) 1672 if [ "$cnt1" != "$subflow_nr" ] || [ "$cnt2" != "$subflow_nr" ]; then 1673 fail_test "got $cnt1:$cnt2 subflows expected $subflow_nr" 1674 dump_stats=1 1675 else 1676 print_ok 1677 fi 1678 1679 if [ "${dump_stats}" = 1 ]; then 1680 ss -N $ns1 -tOni 1681 ss -N $ns1 -tOni | grep token 1682 ip -n $ns1 mptcp endpoint 1683 fi 1684} 1685 1686chk_mptcp_info() 1687{ 1688 local info1=$1 1689 local exp1=$2 1690 local info2=$3 1691 local exp2=$4 1692 local cnt1 1693 local cnt2 1694 local dump_stats 1695 1696 print_check "mptcp_info ${info1:0:15}=$exp1:$exp2" 1697 1698 cnt1=$(ss -N $ns1 -inmHM | mptcp_lib_get_info_value "$info1" "$info1") 1699 cnt2=$(ss -N $ns2 -inmHM | mptcp_lib_get_info_value "$info2" "$info2") 1700 # 'ss' only display active connections and counters that are not 0. 1701 [ -z "$cnt1" ] && cnt1=0 1702 [ -z "$cnt2" ] && cnt2=0 1703 1704 if [ "$cnt1" != "$exp1" ] || [ "$cnt2" != "$exp2" ]; then 1705 fail_test "got $cnt1:$cnt2 $info1:$info2 expected $exp1:$exp2" 1706 dump_stats=1 1707 else 1708 print_ok 1709 fi 1710 1711 if [ "$dump_stats" = 1 ]; then 1712 ss -N $ns1 -inmHM 1713 ss -N $ns2 -inmHM 1714 fi 1715} 1716 1717# $1: subflows in ns1 ; $2: subflows in ns2 1718# number of all subflows, including the initial subflow. 1719chk_subflows_total() 1720{ 1721 local cnt1 1722 local cnt2 1723 local info="subflows_total" 1724 local dump_stats 1725 1726 # if subflows_total counter is supported, use it: 1727 if [ -n "$(ss -N $ns1 -inmHM | mptcp_lib_get_info_value $info $info)" ]; then 1728 chk_mptcp_info $info $1 $info $2 1729 return 1730 fi 1731 1732 print_check "$info $1:$2" 1733 1734 # if not, count the TCP connections that are in fact MPTCP subflows 1735 cnt1=$(ss -N $ns1 -ti state established state syn-sent state syn-recv | 1736 grep -c tcp-ulp-mptcp) 1737 cnt2=$(ss -N $ns2 -ti state established state syn-sent state syn-recv | 1738 grep -c tcp-ulp-mptcp) 1739 1740 if [ "$1" != "$cnt1" ] || [ "$2" != "$cnt2" ]; then 1741 fail_test "got subflows $cnt1:$cnt2 expected $1:$2" 1742 dump_stats=1 1743 else 1744 print_ok 1745 fi 1746 1747 if [ "$dump_stats" = 1 ]; then 1748 ss -N $ns1 -ti 1749 ss -N $ns2 -ti 1750 fi 1751} 1752 1753chk_link_usage() 1754{ 1755 local ns=$1 1756 local link=$2 1757 local out=$3 1758 local expected_rate=$4 1759 1760 local tx_link tx_total 1761 tx_link=$(ip netns exec $ns cat /sys/class/net/$link/statistics/tx_bytes) 1762 tx_total=$(stat --format=%s $out) 1763 local tx_rate=$((tx_link * 100 / tx_total)) 1764 local tolerance=5 1765 1766 print_check "link usage" 1767 if [ $tx_rate -lt $((expected_rate - tolerance)) ] || \ 1768 [ $tx_rate -gt $((expected_rate + tolerance)) ]; then 1769 fail_test "got $tx_rate% usage, expected $expected_rate%" 1770 else 1771 print_ok 1772 fi 1773} 1774 1775wait_attempt_fail() 1776{ 1777 local timeout_ms=$((timeout_poll * 1000)) 1778 local time=0 1779 local ns=$1 1780 1781 while [ $time -lt $timeout_ms ]; do 1782 local cnt 1783 1784 cnt=$(mptcp_lib_get_counter ${ns} "TcpAttemptFails") 1785 1786 [ "$cnt" = 1 ] && return 1 1787 time=$((time + 100)) 1788 sleep 0.1 1789 done 1790 return 1 1791} 1792 1793set_userspace_pm() 1794{ 1795 local ns=$1 1796 1797 ip netns exec $ns sysctl -q net.mptcp.pm_type=1 1798} 1799 1800subflows_tests() 1801{ 1802 if reset "no JOIN"; then 1803 run_tests $ns1 $ns2 10.0.1.1 1804 chk_join_nr 0 0 0 1805 fi 1806 1807 # subflow limited by client 1808 if reset "single subflow, limited by client"; then 1809 pm_nl_set_limits $ns1 0 0 1810 pm_nl_set_limits $ns2 0 0 1811 pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 1812 run_tests $ns1 $ns2 10.0.1.1 1813 chk_join_nr 0 0 0 1814 fi 1815 1816 # subflow limited by server 1817 if reset "single subflow, limited by server"; then 1818 pm_nl_set_limits $ns1 0 0 1819 pm_nl_set_limits $ns2 0 1 1820 pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 1821 run_tests $ns1 $ns2 10.0.1.1 1822 chk_join_nr 1 1 0 1823 fi 1824 1825 # subflow 1826 if reset "single subflow"; then 1827 pm_nl_set_limits $ns1 0 1 1828 pm_nl_set_limits $ns2 0 1 1829 pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 1830 run_tests $ns1 $ns2 10.0.1.1 1831 chk_join_nr 1 1 1 1832 fi 1833 1834 # multiple subflows 1835 if reset "multiple subflows"; then 1836 pm_nl_set_limits $ns1 0 2 1837 pm_nl_set_limits $ns2 0 2 1838 pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 1839 pm_nl_add_endpoint $ns2 10.0.2.2 flags subflow 1840 run_tests $ns1 $ns2 10.0.1.1 1841 chk_join_nr 2 2 2 1842 fi 1843 1844 # multiple subflows limited by server 1845 if reset "multiple subflows, limited by server"; then 1846 pm_nl_set_limits $ns1 0 1 1847 pm_nl_set_limits $ns2 0 2 1848 pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 1849 pm_nl_add_endpoint $ns2 10.0.2.2 flags subflow 1850 run_tests $ns1 $ns2 10.0.1.1 1851 chk_join_nr 2 2 1 1852 fi 1853 1854 # single subflow, dev 1855 if reset "single subflow, dev"; then 1856 pm_nl_set_limits $ns1 0 1 1857 pm_nl_set_limits $ns2 0 1 1858 pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow dev ns2eth3 1859 run_tests $ns1 $ns2 10.0.1.1 1860 chk_join_nr 1 1 1 1861 fi 1862} 1863 1864subflows_error_tests() 1865{ 1866 # If a single subflow is configured, and matches the MPC src 1867 # address, no additional subflow should be created 1868 if reset "no MPC reuse with single endpoint"; then 1869 pm_nl_set_limits $ns1 0 1 1870 pm_nl_set_limits $ns2 0 1 1871 pm_nl_add_endpoint $ns2 10.0.1.2 flags subflow 1872 speed=slow \ 1873 run_tests $ns1 $ns2 10.0.1.1 1874 chk_join_nr 0 0 0 1875 fi 1876 1877 # multiple subflows, with subflow creation error 1878 if reset_with_tcp_filter "multi subflows, with failing subflow" ns1 10.0.3.2 REJECT && 1879 continue_if mptcp_lib_kallsyms_has "mptcp_pm_subflow_check_next$"; then 1880 pm_nl_set_limits $ns1 0 2 1881 pm_nl_set_limits $ns2 0 2 1882 pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 1883 pm_nl_add_endpoint $ns2 10.0.2.2 flags subflow 1884 speed=slow \ 1885 run_tests $ns1 $ns2 10.0.1.1 1886 chk_join_nr 1 1 1 1887 fi 1888 1889 # multiple subflows, with subflow timeout on MPJ 1890 if reset_with_tcp_filter "multi subflows, with subflow timeout" ns1 10.0.3.2 DROP && 1891 continue_if mptcp_lib_kallsyms_has "mptcp_pm_subflow_check_next$"; then 1892 pm_nl_set_limits $ns1 0 2 1893 pm_nl_set_limits $ns2 0 2 1894 pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 1895 pm_nl_add_endpoint $ns2 10.0.2.2 flags subflow 1896 speed=slow \ 1897 run_tests $ns1 $ns2 10.0.1.1 1898 chk_join_nr 1 1 1 1899 fi 1900 1901 # multiple subflows, check that the endpoint corresponding to 1902 # closed subflow (due to reset) is not reused if additional 1903 # subflows are added later 1904 if reset_with_tcp_filter "multi subflows, fair usage on close" ns1 10.0.3.2 REJECT && 1905 continue_if mptcp_lib_kallsyms_has "mptcp_pm_subflow_check_next$"; then 1906 pm_nl_set_limits $ns1 0 1 1907 pm_nl_set_limits $ns2 0 1 1908 pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 1909 speed=slow \ 1910 run_tests $ns1 $ns2 10.0.1.1 & 1911 1912 # mpj subflow will be in TW after the reset 1913 wait_attempt_fail $ns2 1914 pm_nl_add_endpoint $ns2 10.0.2.2 flags subflow 1915 wait 1916 1917 # additional subflow could be created only if the PM select 1918 # the later endpoint, skipping the already used one 1919 chk_join_nr 1 1 1 1920 fi 1921} 1922 1923signal_address_tests() 1924{ 1925 # add_address, unused 1926 if reset "unused signal address"; then 1927 pm_nl_add_endpoint $ns1 10.0.2.1 flags signal 1928 run_tests $ns1 $ns2 10.0.1.1 1929 chk_join_nr 0 0 0 1930 chk_add_tx_nr 1 1 1931 chk_add_nr 1 1 1932 fi 1933 1934 # accept and use add_addr 1935 if reset "signal address"; then 1936 pm_nl_set_limits $ns1 0 1 1937 pm_nl_set_limits $ns2 1 1 1938 pm_nl_add_endpoint $ns1 10.0.2.1 flags signal 1939 run_tests $ns1 $ns2 10.0.1.1 1940 chk_join_nr 1 1 1 1941 chk_add_nr 1 1 1942 fi 1943 1944 # accept and use add_addr with an additional subflow 1945 # note: signal address in server ns and local addresses in client ns must 1946 # belong to different subnets or one of the listed local address could be 1947 # used for 'add_addr' subflow 1948 if reset "subflow and signal"; then 1949 pm_nl_add_endpoint $ns1 10.0.2.1 flags signal 1950 pm_nl_set_limits $ns1 0 2 1951 pm_nl_set_limits $ns2 1 2 1952 pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 1953 run_tests $ns1 $ns2 10.0.1.1 1954 chk_join_nr 2 2 2 1955 chk_add_nr 1 1 1956 fi 1957 1958 # accept and use add_addr with additional subflows 1959 if reset "multiple subflows and signal"; then 1960 pm_nl_set_limits $ns1 0 3 1961 pm_nl_add_endpoint $ns1 10.0.2.1 flags signal 1962 pm_nl_set_limits $ns2 1 3 1963 pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 1964 pm_nl_add_endpoint $ns2 10.0.4.2 flags subflow 1965 run_tests $ns1 $ns2 10.0.1.1 1966 chk_join_nr 3 3 3 1967 chk_add_nr 1 1 1968 fi 1969 1970 # signal addresses 1971 if reset "signal addresses"; then 1972 pm_nl_set_limits $ns1 3 3 1973 pm_nl_add_endpoint $ns1 10.0.2.1 flags signal 1974 pm_nl_add_endpoint $ns1 10.0.3.1 flags signal 1975 pm_nl_add_endpoint $ns1 10.0.4.1 flags signal 1976 pm_nl_set_limits $ns2 3 3 1977 run_tests $ns1 $ns2 10.0.1.1 1978 chk_join_nr 3 3 3 1979 chk_add_nr 3 3 1980 fi 1981 1982 # signal invalid addresses 1983 if reset "signal invalid addresses"; then 1984 pm_nl_set_limits $ns1 3 3 1985 pm_nl_add_endpoint $ns1 10.0.12.1 flags signal 1986 pm_nl_add_endpoint $ns1 10.0.3.1 flags signal 1987 pm_nl_add_endpoint $ns1 10.0.14.1 flags signal 1988 pm_nl_set_limits $ns2 3 3 1989 run_tests $ns1 $ns2 10.0.1.1 1990 chk_join_nr 1 1 1 1991 chk_add_nr 3 3 1992 fi 1993 1994 # signal addresses race test 1995 if reset "signal addresses race test"; then 1996 pm_nl_set_limits $ns1 4 4 1997 pm_nl_set_limits $ns2 4 4 1998 pm_nl_add_endpoint $ns1 10.0.1.1 flags signal 1999 pm_nl_add_endpoint $ns1 10.0.2.1 flags signal 2000 pm_nl_add_endpoint $ns1 10.0.3.1 flags signal 2001 pm_nl_add_endpoint $ns1 10.0.4.1 flags signal 2002 pm_nl_add_endpoint $ns2 10.0.1.2 flags signal 2003 pm_nl_add_endpoint $ns2 10.0.2.2 flags signal 2004 pm_nl_add_endpoint $ns2 10.0.3.2 flags signal 2005 pm_nl_add_endpoint $ns2 10.0.4.2 flags signal 2006 2007 # the peer could possibly miss some addr notification, allow retransmission 2008 ip netns exec $ns1 sysctl -q net.mptcp.add_addr_timeout=1 2009 speed=slow \ 2010 run_tests $ns1 $ns2 10.0.1.1 2011 2012 # It is not directly linked to the commit introducing this 2013 # symbol but for the parent one which is linked anyway. 2014 if ! mptcp_lib_kallsyms_has "mptcp_pm_subflow_check_next$"; then 2015 chk_join_nr 3 3 2 2016 chk_add_nr 4 4 2017 else 2018 chk_join_nr 3 3 3 2019 # the server will not signal the address terminating 2020 # the MPC subflow 2021 chk_add_nr 3 3 2022 fi 2023 fi 2024} 2025 2026link_failure_tests() 2027{ 2028 # accept and use add_addr with additional subflows and link loss 2029 if reset "multiple flows, signal, link failure"; then 2030 # without any b/w limit each veth could spool the packets and get 2031 # them acked at xmit time, so that the corresponding subflow will 2032 # have almost always no outstanding pkts, the scheduler will pick 2033 # always the first subflow and we will have hard time testing 2034 # active backup and link switch-over. 2035 # Let's set some arbitrary (low) virtual link limits. 2036 init_shapers 2037 pm_nl_set_limits $ns1 0 3 2038 pm_nl_add_endpoint $ns1 10.0.2.1 dev ns1eth2 flags signal 2039 pm_nl_set_limits $ns2 1 3 2040 pm_nl_add_endpoint $ns2 10.0.3.2 dev ns2eth3 flags subflow 2041 pm_nl_add_endpoint $ns2 10.0.4.2 dev ns2eth4 flags subflow 2042 test_linkfail=1 \ 2043 run_tests $ns1 $ns2 10.0.1.1 2044 chk_join_nr 3 3 3 2045 chk_add_nr 1 1 2046 chk_stale_nr $ns2 1 5 1 2047 fi 2048 2049 # accept and use add_addr with additional subflows and link loss 2050 # for bidirectional transfer 2051 if reset "multi flows, signal, bidi, link fail"; then 2052 init_shapers 2053 pm_nl_set_limits $ns1 0 3 2054 pm_nl_add_endpoint $ns1 10.0.2.1 dev ns1eth2 flags signal 2055 pm_nl_set_limits $ns2 1 3 2056 pm_nl_add_endpoint $ns2 10.0.3.2 dev ns2eth3 flags subflow 2057 pm_nl_add_endpoint $ns2 10.0.4.2 dev ns2eth4 flags subflow 2058 test_linkfail=2 \ 2059 run_tests $ns1 $ns2 10.0.1.1 2060 chk_join_nr 3 3 3 2061 chk_add_nr 1 1 2062 chk_stale_nr $ns2 1 -1 1 2063 fi 2064 2065 # 2 subflows plus 1 backup subflow with a lossy link, backup 2066 # will never be used 2067 if reset "backup subflow unused, link failure"; then 2068 init_shapers 2069 pm_nl_set_limits $ns1 0 2 2070 pm_nl_add_endpoint $ns1 10.0.2.1 dev ns1eth2 flags signal 2071 pm_nl_set_limits $ns2 1 2 2072 pm_nl_add_endpoint $ns2 10.0.3.2 dev ns2eth3 flags subflow,backup 2073 FAILING_LINKS="1" test_linkfail=1 \ 2074 run_tests $ns1 $ns2 10.0.1.1 2075 chk_join_nr 2 2 2 2076 chk_add_nr 1 1 2077 chk_link_usage $ns2 ns2eth3 $cinsent 0 2078 fi 2079 2080 # 2 lossy links after half transfer, backup will get half of 2081 # the traffic 2082 if reset "backup flow used, multi links fail"; then 2083 init_shapers 2084 pm_nl_set_limits $ns1 0 2 2085 pm_nl_add_endpoint $ns1 10.0.2.1 dev ns1eth2 flags signal 2086 pm_nl_set_limits $ns2 1 2 2087 pm_nl_add_endpoint $ns2 10.0.3.2 dev ns2eth3 flags subflow,backup 2088 FAILING_LINKS="1 2" test_linkfail=1 \ 2089 run_tests $ns1 $ns2 10.0.1.1 2090 chk_join_nr 2 2 2 2091 chk_add_nr 1 1 2092 chk_stale_nr $ns2 2 4 2 2093 chk_link_usage $ns2 ns2eth3 $cinsent 50 2094 fi 2095 2096 # use a backup subflow with the first subflow on a lossy link 2097 # for bidirectional transfer 2098 if reset "backup flow used, bidi, link failure"; then 2099 init_shapers 2100 pm_nl_set_limits $ns1 0 2 2101 pm_nl_add_endpoint $ns1 10.0.2.1 dev ns1eth2 flags signal 2102 pm_nl_set_limits $ns2 1 3 2103 pm_nl_add_endpoint $ns2 10.0.3.2 dev ns2eth3 flags subflow,backup 2104 FAILING_LINKS="1 2" test_linkfail=2 \ 2105 run_tests $ns1 $ns2 10.0.1.1 2106 chk_join_nr 2 2 2 2107 chk_add_nr 1 1 2108 chk_stale_nr $ns2 1 -1 2 2109 chk_link_usage $ns2 ns2eth3 $cinsent 50 2110 fi 2111} 2112 2113add_addr_timeout_tests() 2114{ 2115 # add_addr timeout 2116 if reset_with_add_addr_timeout "signal address, ADD_ADDR timeout"; then 2117 pm_nl_set_limits $ns1 0 1 2118 pm_nl_set_limits $ns2 1 1 2119 pm_nl_add_endpoint $ns1 10.0.2.1 flags signal 2120 speed=slow \ 2121 run_tests $ns1 $ns2 10.0.1.1 2122 chk_join_nr 1 1 1 2123 chk_add_tx_nr 4 4 2124 chk_add_nr 4 0 2125 fi 2126 2127 # add_addr timeout IPv6 2128 if reset_with_add_addr_timeout "signal address, ADD_ADDR6 timeout" 6; then 2129 pm_nl_set_limits $ns1 0 1 2130 pm_nl_set_limits $ns2 1 1 2131 pm_nl_add_endpoint $ns1 dead:beef:2::1 flags signal 2132 speed=slow \ 2133 run_tests $ns1 $ns2 dead:beef:1::1 2134 chk_join_nr 1 1 1 2135 chk_add_nr 4 0 2136 fi 2137 2138 # signal addresses timeout 2139 if reset_with_add_addr_timeout "signal addresses, ADD_ADDR timeout"; then 2140 pm_nl_set_limits $ns1 2 2 2141 pm_nl_add_endpoint $ns1 10.0.2.1 flags signal 2142 pm_nl_add_endpoint $ns1 10.0.3.1 flags signal 2143 pm_nl_set_limits $ns2 2 2 2144 speed=10 \ 2145 run_tests $ns1 $ns2 10.0.1.1 2146 chk_join_nr 2 2 2 2147 chk_add_nr 8 0 2148 fi 2149 2150 # signal invalid addresses timeout 2151 if reset_with_add_addr_timeout "invalid address, ADD_ADDR timeout"; then 2152 pm_nl_set_limits $ns1 2 2 2153 pm_nl_add_endpoint $ns1 10.0.12.1 flags signal 2154 pm_nl_add_endpoint $ns1 10.0.3.1 flags signal 2155 pm_nl_set_limits $ns2 2 2 2156 speed=10 \ 2157 run_tests $ns1 $ns2 10.0.1.1 2158 chk_join_nr 1 1 1 2159 chk_add_nr 8 0 2160 fi 2161} 2162 2163remove_tests() 2164{ 2165 # single subflow, remove 2166 if reset "remove single subflow"; then 2167 pm_nl_set_limits $ns1 0 1 2168 pm_nl_set_limits $ns2 0 1 2169 pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 2170 addr_nr_ns2=-1 speed=slow \ 2171 run_tests $ns1 $ns2 10.0.1.1 2172 chk_join_nr 1 1 1 2173 chk_rm_tx_nr 1 2174 chk_rm_nr 1 1 2175 chk_rst_nr 0 0 2176 fi 2177 2178 # multiple subflows, remove 2179 if reset "remove multiple subflows"; then 2180 pm_nl_set_limits $ns1 0 2 2181 pm_nl_set_limits $ns2 0 2 2182 pm_nl_add_endpoint $ns2 10.0.2.2 flags subflow 2183 pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 2184 addr_nr_ns2=-2 speed=slow \ 2185 run_tests $ns1 $ns2 10.0.1.1 2186 chk_join_nr 2 2 2 2187 chk_rm_nr 2 2 2188 chk_rst_nr 0 0 2189 fi 2190 2191 # single address, remove 2192 if reset "remove single address"; then 2193 pm_nl_set_limits $ns1 0 1 2194 pm_nl_add_endpoint $ns1 10.0.2.1 flags signal 2195 pm_nl_set_limits $ns2 1 1 2196 addr_nr_ns1=-1 speed=slow \ 2197 run_tests $ns1 $ns2 10.0.1.1 2198 chk_join_nr 1 1 1 2199 chk_add_nr 1 1 2200 chk_rm_nr 1 1 invert 2201 chk_rst_nr 0 0 2202 fi 2203 2204 # subflow and signal, remove 2205 if reset "remove subflow and signal"; then 2206 pm_nl_set_limits $ns1 0 2 2207 pm_nl_add_endpoint $ns1 10.0.2.1 flags signal 2208 pm_nl_set_limits $ns2 1 2 2209 pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 2210 addr_nr_ns1=-1 addr_nr_ns2=-1 speed=slow \ 2211 run_tests $ns1 $ns2 10.0.1.1 2212 chk_join_nr 2 2 2 2213 chk_add_nr 1 1 2214 chk_rm_nr 1 1 2215 chk_rst_nr 0 0 2216 fi 2217 2218 # subflows and signal, remove 2219 if reset "remove subflows and signal"; then 2220 pm_nl_set_limits $ns1 0 3 2221 pm_nl_add_endpoint $ns1 10.0.2.1 flags signal 2222 pm_nl_set_limits $ns2 1 3 2223 pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 2224 pm_nl_add_endpoint $ns2 10.0.4.2 flags subflow 2225 addr_nr_ns1=-1 addr_nr_ns2=-2 speed=10 \ 2226 run_tests $ns1 $ns2 10.0.1.1 2227 chk_join_nr 3 3 3 2228 chk_add_nr 1 1 2229 chk_rm_nr 2 2 2230 chk_rst_nr 0 0 2231 fi 2232 2233 # addresses remove 2234 if reset "remove addresses"; then 2235 pm_nl_set_limits $ns1 3 3 2236 pm_nl_add_endpoint $ns1 10.0.2.1 flags signal id 250 2237 pm_nl_add_endpoint $ns1 10.0.3.1 flags signal 2238 pm_nl_add_endpoint $ns1 10.0.4.1 flags signal 2239 pm_nl_set_limits $ns2 3 3 2240 addr_nr_ns1=-3 speed=10 \ 2241 run_tests $ns1 $ns2 10.0.1.1 2242 chk_join_nr 3 3 3 2243 chk_add_nr 3 3 2244 chk_rm_nr 3 3 invert 2245 chk_rst_nr 0 0 2246 fi 2247 2248 # invalid addresses remove 2249 if reset "remove invalid addresses"; then 2250 pm_nl_set_limits $ns1 3 3 2251 pm_nl_add_endpoint $ns1 10.0.12.1 flags signal 2252 # broadcast IP: no packet for this address will be received on ns1 2253 pm_nl_add_endpoint $ns1 224.0.0.1 flags signal 2254 pm_nl_add_endpoint $ns1 10.0.3.1 flags signal 2255 pm_nl_set_limits $ns2 2 2 2256 addr_nr_ns1=-3 speed=10 \ 2257 run_tests $ns1 $ns2 10.0.1.1 2258 chk_join_nr 1 1 1 2259 chk_add_nr 3 3 2260 chk_rm_nr 3 1 invert 2261 chk_rst_nr 0 0 2262 fi 2263 2264 # subflows and signal, flush 2265 if reset "flush subflows and signal"; then 2266 pm_nl_set_limits $ns1 0 3 2267 pm_nl_add_endpoint $ns1 10.0.2.1 flags signal 2268 pm_nl_set_limits $ns2 1 3 2269 pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 2270 pm_nl_add_endpoint $ns2 10.0.4.2 flags subflow 2271 addr_nr_ns1=-8 addr_nr_ns2=-8 speed=slow \ 2272 run_tests $ns1 $ns2 10.0.1.1 2273 chk_join_nr 3 3 3 2274 chk_add_nr 1 1 2275 chk_rm_nr 1 3 invert simult 2276 chk_rst_nr 0 0 2277 fi 2278 2279 # subflows flush 2280 if reset "flush subflows"; then 2281 pm_nl_set_limits $ns1 3 3 2282 pm_nl_set_limits $ns2 3 3 2283 pm_nl_add_endpoint $ns2 10.0.2.2 flags subflow id 150 2284 pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 2285 pm_nl_add_endpoint $ns2 10.0.4.2 flags subflow 2286 addr_nr_ns1=-8 addr_nr_ns2=-8 speed=slow \ 2287 run_tests $ns1 $ns2 10.0.1.1 2288 chk_join_nr 3 3 3 2289 2290 if mptcp_lib_kversion_ge 5.18; then 2291 chk_rm_tx_nr 0 2292 chk_rm_nr 0 3 simult 2293 else 2294 chk_rm_nr 3 3 2295 fi 2296 chk_rst_nr 0 0 2297 fi 2298 2299 # addresses flush 2300 if reset "flush addresses"; then 2301 pm_nl_set_limits $ns1 3 3 2302 pm_nl_add_endpoint $ns1 10.0.2.1 flags signal id 250 2303 pm_nl_add_endpoint $ns1 10.0.3.1 flags signal 2304 pm_nl_add_endpoint $ns1 10.0.4.1 flags signal 2305 pm_nl_set_limits $ns2 3 3 2306 addr_nr_ns1=-8 addr_nr_ns2=-8 speed=slow \ 2307 run_tests $ns1 $ns2 10.0.1.1 2308 chk_join_nr 3 3 3 2309 chk_add_nr 3 3 2310 chk_rm_nr 3 3 invert simult 2311 chk_rst_nr 0 0 2312 fi 2313 2314 # invalid addresses flush 2315 if reset "flush invalid addresses"; then 2316 pm_nl_set_limits $ns1 3 3 2317 pm_nl_add_endpoint $ns1 10.0.12.1 flags signal 2318 pm_nl_add_endpoint $ns1 10.0.3.1 flags signal 2319 pm_nl_add_endpoint $ns1 10.0.14.1 flags signal 2320 pm_nl_set_limits $ns2 3 3 2321 addr_nr_ns1=-8 speed=slow \ 2322 run_tests $ns1 $ns2 10.0.1.1 2323 chk_join_nr 1 1 1 2324 chk_add_nr 3 3 2325 chk_rm_nr 3 1 invert 2326 chk_rst_nr 0 0 2327 fi 2328 2329 # remove id 0 subflow 2330 if reset "remove id 0 subflow"; then 2331 pm_nl_set_limits $ns1 0 1 2332 pm_nl_set_limits $ns2 0 1 2333 pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 2334 addr_nr_ns2=-9 speed=slow \ 2335 run_tests $ns1 $ns2 10.0.1.1 2336 chk_join_nr 1 1 1 2337 chk_rm_nr 1 1 2338 chk_rst_nr 0 0 2339 fi 2340 2341 # remove id 0 address 2342 if reset "remove id 0 address"; then 2343 pm_nl_set_limits $ns1 0 1 2344 pm_nl_add_endpoint $ns1 10.0.2.1 flags signal 2345 pm_nl_set_limits $ns2 1 1 2346 addr_nr_ns1=-9 speed=slow \ 2347 run_tests $ns1 $ns2 10.0.1.1 2348 chk_join_nr 1 1 1 2349 chk_add_nr 1 1 2350 chk_rm_nr 1 1 invert 2351 chk_rst_nr 0 0 invert 2352 fi 2353} 2354 2355add_tests() 2356{ 2357 # add single subflow 2358 if reset "add single subflow"; then 2359 pm_nl_set_limits $ns1 0 1 2360 pm_nl_set_limits $ns2 0 1 2361 addr_nr_ns2=1 speed=slow cestab_ns2=1 \ 2362 run_tests $ns1 $ns2 10.0.1.1 2363 chk_join_nr 1 1 1 2364 chk_cestab_nr $ns2 0 2365 fi 2366 2367 # add signal address 2368 if reset "add signal address"; then 2369 pm_nl_set_limits $ns1 0 1 2370 pm_nl_set_limits $ns2 1 1 2371 addr_nr_ns1=1 speed=slow cestab_ns1=1 \ 2372 run_tests $ns1 $ns2 10.0.1.1 2373 chk_join_nr 1 1 1 2374 chk_add_nr 1 1 2375 chk_cestab_nr $ns1 0 2376 fi 2377 2378 # add multiple subflows 2379 if reset "add multiple subflows"; then 2380 pm_nl_set_limits $ns1 0 2 2381 pm_nl_set_limits $ns2 0 2 2382 addr_nr_ns2=2 speed=slow cestab_ns2=1 \ 2383 run_tests $ns1 $ns2 10.0.1.1 2384 chk_join_nr 2 2 2 2385 chk_cestab_nr $ns2 0 2386 fi 2387 2388 # add multiple subflows IPv6 2389 if reset "add multiple subflows IPv6"; then 2390 pm_nl_set_limits $ns1 0 2 2391 pm_nl_set_limits $ns2 0 2 2392 addr_nr_ns2=2 speed=slow cestab_ns2=1 \ 2393 run_tests $ns1 $ns2 dead:beef:1::1 2394 chk_join_nr 2 2 2 2395 chk_cestab_nr $ns2 0 2396 fi 2397 2398 # add multiple addresses IPv6 2399 if reset "add multiple addresses IPv6"; then 2400 pm_nl_set_limits $ns1 0 2 2401 pm_nl_set_limits $ns2 2 2 2402 addr_nr_ns1=2 speed=slow cestab_ns1=1 \ 2403 run_tests $ns1 $ns2 dead:beef:1::1 2404 chk_join_nr 2 2 2 2405 chk_add_nr 2 2 2406 chk_cestab_nr $ns1 0 2407 fi 2408} 2409 2410ipv6_tests() 2411{ 2412 # subflow IPv6 2413 if reset "single subflow IPv6"; then 2414 pm_nl_set_limits $ns1 0 1 2415 pm_nl_set_limits $ns2 0 1 2416 pm_nl_add_endpoint $ns2 dead:beef:3::2 dev ns2eth3 flags subflow 2417 speed=slow \ 2418 run_tests $ns1 $ns2 dead:beef:1::1 2419 chk_join_nr 1 1 1 2420 fi 2421 2422 # add_address, unused IPv6 2423 if reset "unused signal address IPv6"; then 2424 pm_nl_add_endpoint $ns1 dead:beef:2::1 flags signal 2425 speed=slow \ 2426 run_tests $ns1 $ns2 dead:beef:1::1 2427 chk_join_nr 0 0 0 2428 chk_add_nr 1 1 2429 fi 2430 2431 # signal address IPv6 2432 if reset "single address IPv6"; then 2433 pm_nl_set_limits $ns1 0 1 2434 pm_nl_add_endpoint $ns1 dead:beef:2::1 flags signal 2435 pm_nl_set_limits $ns2 1 1 2436 speed=slow \ 2437 run_tests $ns1 $ns2 dead:beef:1::1 2438 chk_join_nr 1 1 1 2439 chk_add_nr 1 1 2440 fi 2441 2442 # single address IPv6, remove 2443 if reset "remove single address IPv6"; then 2444 pm_nl_set_limits $ns1 0 1 2445 pm_nl_add_endpoint $ns1 dead:beef:2::1 flags signal 2446 pm_nl_set_limits $ns2 1 1 2447 addr_nr_ns1=-1 speed=slow \ 2448 run_tests $ns1 $ns2 dead:beef:1::1 2449 chk_join_nr 1 1 1 2450 chk_add_nr 1 1 2451 chk_rm_nr 1 1 invert 2452 fi 2453 2454 # subflow and signal IPv6, remove 2455 if reset "remove subflow and signal IPv6"; then 2456 pm_nl_set_limits $ns1 0 2 2457 pm_nl_add_endpoint $ns1 dead:beef:2::1 flags signal 2458 pm_nl_set_limits $ns2 1 2 2459 pm_nl_add_endpoint $ns2 dead:beef:3::2 dev ns2eth3 flags subflow 2460 addr_nr_ns1=-1 addr_nr_ns2=-1 speed=slow \ 2461 run_tests $ns1 $ns2 dead:beef:1::1 2462 chk_join_nr 2 2 2 2463 chk_add_nr 1 1 2464 chk_rm_nr 1 1 2465 fi 2466} 2467 2468v4mapped_tests() 2469{ 2470 # subflow IPv4-mapped to IPv4-mapped 2471 if reset "single subflow IPv4-mapped"; then 2472 pm_nl_set_limits $ns1 0 1 2473 pm_nl_set_limits $ns2 0 1 2474 pm_nl_add_endpoint $ns2 "::ffff:10.0.3.2" flags subflow 2475 run_tests $ns1 $ns2 "::ffff:10.0.1.1" 2476 chk_join_nr 1 1 1 2477 fi 2478 2479 # signal address IPv4-mapped with IPv4-mapped sk 2480 if reset "signal address IPv4-mapped"; then 2481 pm_nl_set_limits $ns1 0 1 2482 pm_nl_set_limits $ns2 1 1 2483 pm_nl_add_endpoint $ns1 "::ffff:10.0.2.1" flags signal 2484 run_tests $ns1 $ns2 "::ffff:10.0.1.1" 2485 chk_join_nr 1 1 1 2486 chk_add_nr 1 1 2487 fi 2488 2489 # subflow v4-map-v6 2490 if reset "single subflow v4-map-v6"; then 2491 pm_nl_set_limits $ns1 0 1 2492 pm_nl_set_limits $ns2 0 1 2493 pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 2494 run_tests $ns1 $ns2 "::ffff:10.0.1.1" 2495 chk_join_nr 1 1 1 2496 fi 2497 2498 # signal address v4-map-v6 2499 if reset "signal address v4-map-v6"; then 2500 pm_nl_set_limits $ns1 0 1 2501 pm_nl_set_limits $ns2 1 1 2502 pm_nl_add_endpoint $ns1 10.0.2.1 flags signal 2503 run_tests $ns1 $ns2 "::ffff:10.0.1.1" 2504 chk_join_nr 1 1 1 2505 chk_add_nr 1 1 2506 fi 2507 2508 # subflow v6-map-v4 2509 if reset "single subflow v6-map-v4"; then 2510 pm_nl_set_limits $ns1 0 1 2511 pm_nl_set_limits $ns2 0 1 2512 pm_nl_add_endpoint $ns2 "::ffff:10.0.3.2" flags subflow 2513 run_tests $ns1 $ns2 10.0.1.1 2514 chk_join_nr 1 1 1 2515 fi 2516 2517 # signal address v6-map-v4 2518 if reset "signal address v6-map-v4"; then 2519 pm_nl_set_limits $ns1 0 1 2520 pm_nl_set_limits $ns2 1 1 2521 pm_nl_add_endpoint $ns1 "::ffff:10.0.2.1" flags signal 2522 run_tests $ns1 $ns2 10.0.1.1 2523 chk_join_nr 1 1 1 2524 chk_add_nr 1 1 2525 fi 2526 2527 # no subflow IPv6 to v4 address 2528 if reset "no JOIN with diff families v4-v6"; then 2529 pm_nl_set_limits $ns1 0 1 2530 pm_nl_set_limits $ns2 0 1 2531 pm_nl_add_endpoint $ns2 dead:beef:2::2 flags subflow 2532 run_tests $ns1 $ns2 10.0.1.1 2533 chk_join_nr 0 0 0 2534 fi 2535 2536 # no subflow IPv6 to v4 address even if v6 has a valid v4 at the end 2537 if reset "no JOIN with diff families v4-v6-2"; then 2538 pm_nl_set_limits $ns1 0 1 2539 pm_nl_set_limits $ns2 0 1 2540 pm_nl_add_endpoint $ns2 dead:beef:2::10.0.3.2 flags subflow 2541 run_tests $ns1 $ns2 10.0.1.1 2542 chk_join_nr 0 0 0 2543 fi 2544 2545 # no subflow IPv4 to v6 address, no need to slow down too then 2546 if reset "no JOIN with diff families v6-v4"; then 2547 pm_nl_set_limits $ns1 0 1 2548 pm_nl_set_limits $ns2 0 1 2549 pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 2550 run_tests $ns1 $ns2 dead:beef:1::1 2551 chk_join_nr 0 0 0 2552 fi 2553} 2554 2555mixed_tests() 2556{ 2557 if reset "IPv4 sockets do not use IPv6 addresses" && 2558 continue_if mptcp_lib_kversion_ge 6.3; then 2559 pm_nl_set_limits $ns1 0 1 2560 pm_nl_set_limits $ns2 1 1 2561 pm_nl_add_endpoint $ns1 dead:beef:2::1 flags signal 2562 speed=slow \ 2563 run_tests $ns1 $ns2 10.0.1.1 2564 chk_join_nr 0 0 0 2565 fi 2566 2567 # Need an IPv6 mptcp socket to allow subflows of both families 2568 if reset "simult IPv4 and IPv6 subflows" && 2569 continue_if mptcp_lib_kversion_ge 6.3; then 2570 pm_nl_set_limits $ns1 0 1 2571 pm_nl_set_limits $ns2 1 1 2572 pm_nl_add_endpoint $ns1 10.0.1.1 flags signal 2573 speed=slow \ 2574 run_tests $ns1 $ns2 dead:beef:2::1 2575 chk_join_nr 1 1 1 2576 fi 2577 2578 # cross families subflows will not be created even in fullmesh mode 2579 if reset "simult IPv4 and IPv6 subflows, fullmesh 1x1" && 2580 continue_if mptcp_lib_kversion_ge 6.3; then 2581 pm_nl_set_limits $ns1 0 4 2582 pm_nl_set_limits $ns2 1 4 2583 pm_nl_add_endpoint $ns2 dead:beef:2::2 flags subflow,fullmesh 2584 pm_nl_add_endpoint $ns1 10.0.1.1 flags signal 2585 speed=slow \ 2586 run_tests $ns1 $ns2 dead:beef:2::1 2587 chk_join_nr 1 1 1 2588 fi 2589 2590 # fullmesh still tries to create all the possibly subflows with 2591 # matching family 2592 if reset "simult IPv4 and IPv6 subflows, fullmesh 2x2" && 2593 continue_if mptcp_lib_kversion_ge 6.3; then 2594 pm_nl_set_limits $ns1 0 4 2595 pm_nl_set_limits $ns2 2 4 2596 pm_nl_add_endpoint $ns1 10.0.2.1 flags signal 2597 pm_nl_add_endpoint $ns1 dead:beef:2::1 flags signal 2598 fullmesh=1 speed=slow \ 2599 run_tests $ns1 $ns2 dead:beef:1::1 2600 chk_join_nr 4 4 4 2601 fi 2602} 2603 2604backup_tests() 2605{ 2606 # single subflow, backup 2607 if reset "single subflow, backup" && 2608 continue_if mptcp_lib_kallsyms_has "subflow_rebuild_header$"; then 2609 pm_nl_set_limits $ns1 0 1 2610 pm_nl_set_limits $ns2 0 1 2611 pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow,backup 2612 sflags=nobackup speed=slow \ 2613 run_tests $ns1 $ns2 10.0.1.1 2614 chk_join_nr 1 1 1 2615 chk_prio_nr 0 1 2616 fi 2617 2618 # single address, backup 2619 if reset "single address, backup" && 2620 continue_if mptcp_lib_kallsyms_has "subflow_rebuild_header$"; then 2621 pm_nl_set_limits $ns1 0 1 2622 pm_nl_add_endpoint $ns1 10.0.2.1 flags signal 2623 pm_nl_set_limits $ns2 1 1 2624 sflags=backup speed=slow \ 2625 run_tests $ns1 $ns2 10.0.1.1 2626 chk_join_nr 1 1 1 2627 chk_add_nr 1 1 2628 chk_prio_nr 1 1 2629 fi 2630 2631 # single address with port, backup 2632 if reset "single address with port, backup" && 2633 continue_if mptcp_lib_kallsyms_has "subflow_rebuild_header$"; then 2634 pm_nl_set_limits $ns1 0 1 2635 pm_nl_add_endpoint $ns1 10.0.2.1 flags signal port 10100 2636 pm_nl_set_limits $ns2 1 1 2637 sflags=backup speed=slow \ 2638 run_tests $ns1 $ns2 10.0.1.1 2639 chk_join_nr 1 1 1 2640 chk_add_nr 1 1 2641 chk_prio_nr 1 1 2642 fi 2643 2644 if reset "mpc backup" && 2645 continue_if mptcp_lib_kallsyms_doesnt_have "T mptcp_subflow_send_ack$"; then 2646 pm_nl_add_endpoint $ns2 10.0.1.2 flags subflow,backup 2647 speed=slow \ 2648 run_tests $ns1 $ns2 10.0.1.1 2649 chk_join_nr 0 0 0 2650 chk_prio_nr 0 1 2651 fi 2652 2653 if reset "mpc backup both sides" && 2654 continue_if mptcp_lib_kallsyms_doesnt_have "T mptcp_subflow_send_ack$"; then 2655 pm_nl_add_endpoint $ns1 10.0.1.1 flags subflow,backup 2656 pm_nl_add_endpoint $ns2 10.0.1.2 flags subflow,backup 2657 speed=slow \ 2658 run_tests $ns1 $ns2 10.0.1.1 2659 chk_join_nr 0 0 0 2660 chk_prio_nr 1 1 2661 fi 2662 2663 if reset "mpc switch to backup" && 2664 continue_if mptcp_lib_kallsyms_doesnt_have "T mptcp_subflow_send_ack$"; then 2665 pm_nl_add_endpoint $ns2 10.0.1.2 flags subflow 2666 sflags=backup speed=slow \ 2667 run_tests $ns1 $ns2 10.0.1.1 2668 chk_join_nr 0 0 0 2669 chk_prio_nr 0 1 2670 fi 2671 2672 if reset "mpc switch to backup both sides" && 2673 continue_if mptcp_lib_kallsyms_doesnt_have "T mptcp_subflow_send_ack$"; then 2674 pm_nl_add_endpoint $ns1 10.0.1.1 flags subflow 2675 pm_nl_add_endpoint $ns2 10.0.1.2 flags subflow 2676 sflags=backup speed=slow \ 2677 run_tests $ns1 $ns2 10.0.1.1 2678 chk_join_nr 0 0 0 2679 chk_prio_nr 1 1 2680 fi 2681} 2682 2683verify_listener_events() 2684{ 2685 local e_type=$2 2686 local e_saddr=$4 2687 local e_sport=$5 2688 local name 2689 2690 if [ $e_type = $MPTCP_LIB_EVENT_LISTENER_CREATED ]; then 2691 name="LISTENER_CREATED" 2692 elif [ $e_type = $MPTCP_LIB_EVENT_LISTENER_CLOSED ]; then 2693 name="LISTENER_CLOSED " 2694 else 2695 name="$e_type" 2696 fi 2697 2698 print_check "$name $e_saddr:$e_sport" 2699 2700 if ! mptcp_lib_kallsyms_has "mptcp_event_pm_listener$"; then 2701 print_skip "event not supported" 2702 return 2703 fi 2704 2705 if mptcp_lib_verify_listener_events "${@}"; then 2706 print_ok 2707 return 0 2708 fi 2709 fail_test 2710} 2711 2712add_addr_ports_tests() 2713{ 2714 # signal address with port 2715 if reset "signal address with port"; then 2716 pm_nl_set_limits $ns1 0 1 2717 pm_nl_set_limits $ns2 1 1 2718 pm_nl_add_endpoint $ns1 10.0.2.1 flags signal port 10100 2719 run_tests $ns1 $ns2 10.0.1.1 2720 chk_join_nr 1 1 1 2721 chk_add_nr 1 1 1 2722 fi 2723 2724 # subflow and signal with port 2725 if reset "subflow and signal with port"; then 2726 pm_nl_add_endpoint $ns1 10.0.2.1 flags signal port 10100 2727 pm_nl_set_limits $ns1 0 2 2728 pm_nl_set_limits $ns2 1 2 2729 pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 2730 run_tests $ns1 $ns2 10.0.1.1 2731 chk_join_nr 2 2 2 2732 chk_add_nr 1 1 1 2733 fi 2734 2735 # single address with port, remove 2736 # pm listener events 2737 if reset_with_events "remove single address with port"; then 2738 pm_nl_set_limits $ns1 0 1 2739 pm_nl_add_endpoint $ns1 10.0.2.1 flags signal port 10100 2740 pm_nl_set_limits $ns2 1 1 2741 addr_nr_ns1=-1 speed=slow \ 2742 run_tests $ns1 $ns2 10.0.1.1 2743 chk_join_nr 1 1 1 2744 chk_add_nr 1 1 1 2745 chk_rm_nr 1 1 invert 2746 2747 verify_listener_events $evts_ns1 $MPTCP_LIB_EVENT_LISTENER_CREATED \ 2748 $MPTCP_LIB_AF_INET 10.0.2.1 10100 2749 verify_listener_events $evts_ns1 $MPTCP_LIB_EVENT_LISTENER_CLOSED \ 2750 $MPTCP_LIB_AF_INET 10.0.2.1 10100 2751 kill_events_pids 2752 fi 2753 2754 # subflow and signal with port, remove 2755 if reset "remove subflow and signal with port"; then 2756 pm_nl_set_limits $ns1 0 2 2757 pm_nl_add_endpoint $ns1 10.0.2.1 flags signal port 10100 2758 pm_nl_set_limits $ns2 1 2 2759 pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 2760 addr_nr_ns1=-1 addr_nr_ns2=-1 speed=slow \ 2761 run_tests $ns1 $ns2 10.0.1.1 2762 chk_join_nr 2 2 2 2763 chk_add_nr 1 1 1 2764 chk_rm_nr 1 1 2765 fi 2766 2767 # subflows and signal with port, flush 2768 if reset "flush subflows and signal with port"; then 2769 pm_nl_set_limits $ns1 0 3 2770 pm_nl_add_endpoint $ns1 10.0.2.1 flags signal port 10100 2771 pm_nl_set_limits $ns2 1 3 2772 pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 2773 pm_nl_add_endpoint $ns2 10.0.4.2 flags subflow 2774 addr_nr_ns1=-8 addr_nr_ns2=-2 speed=slow \ 2775 run_tests $ns1 $ns2 10.0.1.1 2776 chk_join_nr 3 3 3 2777 chk_add_nr 1 1 2778 chk_rm_nr 1 3 invert simult 2779 fi 2780 2781 # multiple addresses with port 2782 if reset "multiple addresses with port"; then 2783 pm_nl_set_limits $ns1 2 2 2784 pm_nl_add_endpoint $ns1 10.0.2.1 flags signal port 10100 2785 pm_nl_add_endpoint $ns1 10.0.3.1 flags signal port 10100 2786 pm_nl_set_limits $ns2 2 2 2787 run_tests $ns1 $ns2 10.0.1.1 2788 chk_join_nr 2 2 2 2789 chk_add_nr 2 2 2 2790 fi 2791 2792 # multiple addresses with ports 2793 if reset "multiple addresses with ports"; then 2794 pm_nl_set_limits $ns1 2 2 2795 pm_nl_add_endpoint $ns1 10.0.2.1 flags signal port 10100 2796 pm_nl_add_endpoint $ns1 10.0.3.1 flags signal port 10101 2797 pm_nl_set_limits $ns2 2 2 2798 run_tests $ns1 $ns2 10.0.1.1 2799 chk_join_nr 2 2 2 2800 chk_add_nr 2 2 2 2801 fi 2802} 2803 2804syncookies_tests() 2805{ 2806 # single subflow, syncookies 2807 if reset_with_cookies "single subflow with syn cookies"; then 2808 pm_nl_set_limits $ns1 0 1 2809 pm_nl_set_limits $ns2 0 1 2810 pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 2811 run_tests $ns1 $ns2 10.0.1.1 2812 chk_join_nr 1 1 1 2813 fi 2814 2815 # multiple subflows with syn cookies 2816 if reset_with_cookies "multiple subflows with syn cookies"; then 2817 pm_nl_set_limits $ns1 0 2 2818 pm_nl_set_limits $ns2 0 2 2819 pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 2820 pm_nl_add_endpoint $ns2 10.0.2.2 flags subflow 2821 run_tests $ns1 $ns2 10.0.1.1 2822 chk_join_nr 2 2 2 2823 fi 2824 2825 # multiple subflows limited by server 2826 if reset_with_cookies "subflows limited by server w cookies"; then 2827 pm_nl_set_limits $ns1 0 1 2828 pm_nl_set_limits $ns2 0 2 2829 pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 2830 pm_nl_add_endpoint $ns2 10.0.2.2 flags subflow 2831 run_tests $ns1 $ns2 10.0.1.1 2832 chk_join_nr 2 1 1 2833 fi 2834 2835 # test signal address with cookies 2836 if reset_with_cookies "signal address with syn cookies"; then 2837 pm_nl_set_limits $ns1 0 1 2838 pm_nl_set_limits $ns2 1 1 2839 pm_nl_add_endpoint $ns1 10.0.2.1 flags signal 2840 run_tests $ns1 $ns2 10.0.1.1 2841 chk_join_nr 1 1 1 2842 chk_add_nr 1 1 2843 fi 2844 2845 # test cookie with subflow and signal 2846 if reset_with_cookies "subflow and signal w cookies"; then 2847 pm_nl_add_endpoint $ns1 10.0.2.1 flags signal 2848 pm_nl_set_limits $ns1 0 2 2849 pm_nl_set_limits $ns2 1 2 2850 pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 2851 run_tests $ns1 $ns2 10.0.1.1 2852 chk_join_nr 2 2 2 2853 chk_add_nr 1 1 2854 fi 2855 2856 # accept and use add_addr with additional subflows 2857 if reset_with_cookies "subflows and signal w. cookies"; then 2858 pm_nl_set_limits $ns1 0 3 2859 pm_nl_add_endpoint $ns1 10.0.2.1 flags signal 2860 pm_nl_set_limits $ns2 1 3 2861 pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 2862 pm_nl_add_endpoint $ns2 10.0.4.2 flags subflow 2863 run_tests $ns1 $ns2 10.0.1.1 2864 chk_join_nr 3 3 3 2865 chk_add_nr 1 1 2866 fi 2867} 2868 2869checksum_tests() 2870{ 2871 # checksum test 0 0 2872 if reset_with_checksum 0 0; then 2873 pm_nl_set_limits $ns1 0 1 2874 pm_nl_set_limits $ns2 0 1 2875 run_tests $ns1 $ns2 10.0.1.1 2876 chk_join_nr 0 0 0 2877 fi 2878 2879 # checksum test 1 1 2880 if reset_with_checksum 1 1; then 2881 pm_nl_set_limits $ns1 0 1 2882 pm_nl_set_limits $ns2 0 1 2883 run_tests $ns1 $ns2 10.0.1.1 2884 chk_join_nr 0 0 0 2885 fi 2886 2887 # checksum test 0 1 2888 if reset_with_checksum 0 1; then 2889 pm_nl_set_limits $ns1 0 1 2890 pm_nl_set_limits $ns2 0 1 2891 run_tests $ns1 $ns2 10.0.1.1 2892 chk_join_nr 0 0 0 2893 fi 2894 2895 # checksum test 1 0 2896 if reset_with_checksum 1 0; then 2897 pm_nl_set_limits $ns1 0 1 2898 pm_nl_set_limits $ns2 0 1 2899 run_tests $ns1 $ns2 10.0.1.1 2900 chk_join_nr 0 0 0 2901 fi 2902} 2903 2904deny_join_id0_tests() 2905{ 2906 # subflow allow join id0 ns1 2907 if reset_with_allow_join_id0 "single subflow allow join id0 ns1" 1 0; then 2908 pm_nl_set_limits $ns1 1 1 2909 pm_nl_set_limits $ns2 1 1 2910 pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 2911 run_tests $ns1 $ns2 10.0.1.1 2912 chk_join_nr 1 1 1 2913 fi 2914 2915 # subflow allow join id0 ns2 2916 if reset_with_allow_join_id0 "single subflow allow join id0 ns2" 0 1; then 2917 pm_nl_set_limits $ns1 1 1 2918 pm_nl_set_limits $ns2 1 1 2919 pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 2920 run_tests $ns1 $ns2 10.0.1.1 2921 chk_join_nr 0 0 0 2922 fi 2923 2924 # signal address allow join id0 ns1 2925 # ADD_ADDRs are not affected by allow_join_id0 value. 2926 if reset_with_allow_join_id0 "signal address allow join id0 ns1" 1 0; then 2927 pm_nl_set_limits $ns1 1 1 2928 pm_nl_set_limits $ns2 1 1 2929 pm_nl_add_endpoint $ns1 10.0.2.1 flags signal 2930 run_tests $ns1 $ns2 10.0.1.1 2931 chk_join_nr 1 1 1 2932 chk_add_nr 1 1 2933 fi 2934 2935 # signal address allow join id0 ns2 2936 # ADD_ADDRs are not affected by allow_join_id0 value. 2937 if reset_with_allow_join_id0 "signal address allow join id0 ns2" 0 1; then 2938 pm_nl_set_limits $ns1 1 1 2939 pm_nl_set_limits $ns2 1 1 2940 pm_nl_add_endpoint $ns1 10.0.2.1 flags signal 2941 run_tests $ns1 $ns2 10.0.1.1 2942 chk_join_nr 1 1 1 2943 chk_add_nr 1 1 2944 fi 2945 2946 # subflow and address allow join id0 ns1 2947 if reset_with_allow_join_id0 "subflow and address allow join id0 1" 1 0; then 2948 pm_nl_set_limits $ns1 2 2 2949 pm_nl_set_limits $ns2 2 2 2950 pm_nl_add_endpoint $ns1 10.0.2.1 flags signal 2951 pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 2952 run_tests $ns1 $ns2 10.0.1.1 2953 chk_join_nr 2 2 2 2954 fi 2955 2956 # subflow and address allow join id0 ns2 2957 if reset_with_allow_join_id0 "subflow and address allow join id0 2" 0 1; then 2958 pm_nl_set_limits $ns1 2 2 2959 pm_nl_set_limits $ns2 2 2 2960 pm_nl_add_endpoint $ns1 10.0.2.1 flags signal 2961 pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 2962 run_tests $ns1 $ns2 10.0.1.1 2963 chk_join_nr 1 1 1 2964 fi 2965} 2966 2967fullmesh_tests() 2968{ 2969 # fullmesh 1 2970 # 2 fullmesh addrs in ns2, added before the connection, 2971 # 1 non-fullmesh addr in ns1, added during the connection. 2972 if reset "fullmesh test 2x1"; then 2973 pm_nl_set_limits $ns1 0 4 2974 pm_nl_set_limits $ns2 1 4 2975 pm_nl_add_endpoint $ns2 10.0.2.2 flags subflow,fullmesh 2976 pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow,fullmesh 2977 addr_nr_ns1=1 speed=slow \ 2978 run_tests $ns1 $ns2 10.0.1.1 2979 chk_join_nr 4 4 4 2980 chk_add_nr 1 1 2981 fi 2982 2983 # fullmesh 2 2984 # 1 non-fullmesh addr in ns1, added before the connection, 2985 # 1 fullmesh addr in ns2, added during the connection. 2986 if reset "fullmesh test 1x1"; then 2987 pm_nl_set_limits $ns1 1 3 2988 pm_nl_set_limits $ns2 1 3 2989 pm_nl_add_endpoint $ns1 10.0.2.1 flags signal 2990 fullmesh=1 speed=slow \ 2991 run_tests $ns1 $ns2 10.0.1.1 2992 chk_join_nr 3 3 3 2993 chk_add_nr 1 1 2994 fi 2995 2996 # fullmesh 3 2997 # 1 non-fullmesh addr in ns1, added before the connection, 2998 # 2 fullmesh addrs in ns2, added during the connection. 2999 if reset "fullmesh test 1x2"; then 3000 pm_nl_set_limits $ns1 2 5 3001 pm_nl_set_limits $ns2 1 5 3002 pm_nl_add_endpoint $ns1 10.0.2.1 flags signal 3003 fullmesh=2 speed=slow \ 3004 run_tests $ns1 $ns2 10.0.1.1 3005 chk_join_nr 5 5 5 3006 chk_add_nr 1 1 3007 fi 3008 3009 # fullmesh 4 3010 # 1 non-fullmesh addr in ns1, added before the connection, 3011 # 2 fullmesh addrs in ns2, added during the connection, 3012 # limit max_subflows to 4. 3013 if reset "fullmesh test 1x2, limited"; then 3014 pm_nl_set_limits $ns1 2 4 3015 pm_nl_set_limits $ns2 1 4 3016 pm_nl_add_endpoint $ns1 10.0.2.1 flags signal 3017 fullmesh=2 speed=slow \ 3018 run_tests $ns1 $ns2 10.0.1.1 3019 chk_join_nr 4 4 4 3020 chk_add_nr 1 1 3021 fi 3022 3023 # set fullmesh flag 3024 if reset "set fullmesh flag test" && 3025 continue_if mptcp_lib_kversion_ge 5.18; then 3026 pm_nl_set_limits $ns1 4 4 3027 pm_nl_add_endpoint $ns1 10.0.2.1 flags subflow 3028 pm_nl_set_limits $ns2 4 4 3029 addr_nr_ns2=1 sflags=fullmesh speed=slow \ 3030 run_tests $ns1 $ns2 10.0.1.1 3031 chk_join_nr 2 2 2 3032 chk_rm_nr 0 1 3033 fi 3034 3035 # set nofullmesh flag 3036 if reset "set nofullmesh flag test" && 3037 continue_if mptcp_lib_kversion_ge 5.18; then 3038 pm_nl_set_limits $ns1 4 4 3039 pm_nl_add_endpoint $ns1 10.0.2.1 flags subflow,fullmesh 3040 pm_nl_set_limits $ns2 4 4 3041 fullmesh=1 sflags=nofullmesh speed=slow \ 3042 run_tests $ns1 $ns2 10.0.1.1 3043 chk_join_nr 2 2 2 3044 chk_rm_nr 0 1 3045 fi 3046 3047 # set backup,fullmesh flags 3048 if reset "set backup,fullmesh flags test" && 3049 continue_if mptcp_lib_kversion_ge 5.18; then 3050 pm_nl_set_limits $ns1 4 4 3051 pm_nl_add_endpoint $ns1 10.0.2.1 flags subflow 3052 pm_nl_set_limits $ns2 4 4 3053 addr_nr_ns2=1 sflags=backup,fullmesh speed=slow \ 3054 run_tests $ns1 $ns2 10.0.1.1 3055 chk_join_nr 2 2 2 3056 chk_prio_nr 0 1 3057 chk_rm_nr 0 1 3058 fi 3059 3060 # set nobackup,nofullmesh flags 3061 if reset "set nobackup,nofullmesh flags test" && 3062 continue_if mptcp_lib_kversion_ge 5.18; then 3063 pm_nl_set_limits $ns1 4 4 3064 pm_nl_set_limits $ns2 4 4 3065 pm_nl_add_endpoint $ns2 10.0.2.2 flags subflow,backup,fullmesh 3066 sflags=nobackup,nofullmesh speed=slow \ 3067 run_tests $ns1 $ns2 10.0.1.1 3068 chk_join_nr 2 2 2 3069 chk_prio_nr 0 1 3070 chk_rm_nr 0 1 3071 fi 3072} 3073 3074fastclose_tests() 3075{ 3076 if reset_check_counter "fastclose test" "MPTcpExtMPFastcloseTx"; then 3077 MPTCP_LIB_SUBTEST_FLAKY=1 3078 test_linkfail=1024 fastclose=client \ 3079 run_tests $ns1 $ns2 10.0.1.1 3080 chk_join_nr 0 0 0 3081 chk_fclose_nr 1 1 3082 chk_rst_nr 1 1 invert 3083 fi 3084 3085 if reset_check_counter "fastclose server test" "MPTcpExtMPFastcloseRx"; then 3086 MPTCP_LIB_SUBTEST_FLAKY=1 3087 test_linkfail=1024 fastclose=server \ 3088 run_tests $ns1 $ns2 10.0.1.1 3089 chk_join_nr 0 0 0 0 0 0 1 3090 chk_fclose_nr 1 1 invert 3091 chk_rst_nr 1 1 3092 fi 3093} 3094 3095pedit_action_pkts() 3096{ 3097 tc -n $ns2 -j -s action show action pedit index 100 | \ 3098 mptcp_lib_get_info_value \"packets\" packets 3099} 3100 3101fail_tests() 3102{ 3103 # single subflow 3104 if reset_with_fail "Infinite map" 1; then 3105 MPTCP_LIB_SUBTEST_FLAKY=1 3106 test_linkfail=128 \ 3107 run_tests $ns1 $ns2 10.0.1.1 3108 chk_join_nr 0 0 0 +1 +0 1 0 1 "$(pedit_action_pkts)" 3109 chk_fail_nr 1 -1 invert 3110 fi 3111 3112 # multiple subflows 3113 if reset_with_fail "MP_FAIL MP_RST" 2; then 3114 MPTCP_LIB_SUBTEST_FLAKY=1 3115 tc -n $ns2 qdisc add dev ns2eth1 root netem rate 1mbit delay 5ms 3116 pm_nl_set_limits $ns1 0 1 3117 pm_nl_set_limits $ns2 0 1 3118 pm_nl_add_endpoint $ns2 10.0.2.2 dev ns2eth2 flags subflow 3119 test_linkfail=1024 \ 3120 run_tests $ns1 $ns2 10.0.1.1 3121 chk_join_nr 1 1 1 1 0 1 1 0 "$(pedit_action_pkts)" 3122 fi 3123} 3124 3125# $1: ns ; $2: addr ; $3: id 3126userspace_pm_add_addr() 3127{ 3128 local evts=$evts_ns1 3129 local tk 3130 3131 [ "$1" == "$ns2" ] && evts=$evts_ns2 3132 tk=$(mptcp_lib_evts_get_info token "$evts") 3133 3134 ip netns exec $1 ./pm_nl_ctl ann $2 token $tk id $3 3135 sleep 1 3136} 3137 3138# $1: ns ; $2: id 3139userspace_pm_rm_addr() 3140{ 3141 local evts=$evts_ns1 3142 local tk 3143 local cnt 3144 3145 [ "$1" == "$ns2" ] && evts=$evts_ns2 3146 tk=$(mptcp_lib_evts_get_info token "$evts") 3147 3148 cnt=$(rm_addr_count ${1}) 3149 ip netns exec $1 ./pm_nl_ctl rem token $tk id $2 3150 wait_rm_addr $1 "${cnt}" 3151} 3152 3153# $1: ns ; $2: addr ; $3: id 3154userspace_pm_add_sf() 3155{ 3156 local evts=$evts_ns1 3157 local tk da dp 3158 3159 [ "$1" == "$ns2" ] && evts=$evts_ns2 3160 tk=$(mptcp_lib_evts_get_info token "$evts") 3161 da=$(mptcp_lib_evts_get_info daddr4 "$evts") 3162 dp=$(mptcp_lib_evts_get_info dport "$evts") 3163 3164 ip netns exec $1 ./pm_nl_ctl csf lip $2 lid $3 \ 3165 rip $da rport $dp token $tk 3166 sleep 1 3167} 3168 3169# $1: ns ; $2: addr $3: event type 3170userspace_pm_rm_sf() 3171{ 3172 local evts=$evts_ns1 3173 local t=${3:-1} 3174 local ip 3175 local tk da dp sp 3176 local cnt 3177 3178 [ "$1" == "$ns2" ] && evts=$evts_ns2 3179 [ -n "$(mptcp_lib_evts_get_info "saddr4" "$evts" $t)" ] && ip=4 3180 [ -n "$(mptcp_lib_evts_get_info "saddr6" "$evts" $t)" ] && ip=6 3181 tk=$(mptcp_lib_evts_get_info token "$evts") 3182 da=$(mptcp_lib_evts_get_info "daddr$ip" "$evts" $t $2) 3183 dp=$(mptcp_lib_evts_get_info dport "$evts" $t $2) 3184 sp=$(mptcp_lib_evts_get_info sport "$evts" $t $2) 3185 3186 cnt=$(rm_sf_count ${1}) 3187 ip netns exec $1 ./pm_nl_ctl dsf lip $2 lport $sp \ 3188 rip $da rport $dp token $tk 3189 wait_rm_sf $1 "${cnt}" 3190} 3191 3192check_output() 3193{ 3194 local cmd="$1" 3195 local expected="$2" 3196 local msg="$3" 3197 local rc=0 3198 3199 mptcp_lib_check_output "${err}" "${cmd}" "${expected}" || rc=${?} 3200 if [ ${rc} -eq 2 ]; then 3201 fail_test "fail to check output # error ${rc}" 3202 elif [ ${rc} -eq 0 ]; then 3203 print_ok 3204 elif [ ${rc} -eq 1 ]; then 3205 fail_test "fail to check output # different output" 3206 fi 3207} 3208 3209# $1: ns 3210userspace_pm_dump() 3211{ 3212 local evts=$evts_ns1 3213 local tk 3214 3215 [ "$1" == "$ns2" ] && evts=$evts_ns2 3216 tk=$(mptcp_lib_evts_get_info token "$evts") 3217 3218 ip netns exec $1 ./pm_nl_ctl dump token $tk 3219} 3220 3221# $1: ns ; $2: id 3222userspace_pm_get_addr() 3223{ 3224 local evts=$evts_ns1 3225 local tk 3226 3227 [ "$1" == "$ns2" ] && evts=$evts_ns2 3228 tk=$(mptcp_lib_evts_get_info token "$evts") 3229 3230 ip netns exec $1 ./pm_nl_ctl get $2 token $tk 3231} 3232 3233userspace_pm_chk_dump_addr() 3234{ 3235 local ns="${1}" 3236 local exp="${2}" 3237 local check="${3}" 3238 3239 print_check "dump addrs ${check}" 3240 3241 if mptcp_lib_kallsyms_has "mptcp_userspace_pm_dump_addr$"; then 3242 check_output "userspace_pm_dump ${ns}" "${exp}" 3243 else 3244 print_skip 3245 fi 3246} 3247 3248userspace_pm_chk_get_addr() 3249{ 3250 local ns="${1}" 3251 local id="${2}" 3252 local exp="${3}" 3253 3254 print_check "get id ${id} addr" 3255 3256 if mptcp_lib_kallsyms_has "mptcp_userspace_pm_get_addr$"; then 3257 check_output "userspace_pm_get_addr ${ns} ${id}" "${exp}" 3258 else 3259 print_skip 3260 fi 3261} 3262 3263userspace_tests() 3264{ 3265 # userspace pm type prevents add_addr 3266 if reset "userspace pm type prevents add_addr" && 3267 continue_if mptcp_lib_has_file '/proc/sys/net/mptcp/pm_type'; then 3268 set_userspace_pm $ns1 3269 pm_nl_set_limits $ns1 0 2 3270 pm_nl_set_limits $ns2 0 2 3271 pm_nl_add_endpoint $ns1 10.0.2.1 flags signal 3272 run_tests $ns1 $ns2 10.0.1.1 3273 chk_join_nr 0 0 0 3274 chk_add_nr 0 0 3275 fi 3276 3277 # userspace pm type does not echo add_addr without daemon 3278 if reset "userspace pm no echo w/o daemon" && 3279 continue_if mptcp_lib_has_file '/proc/sys/net/mptcp/pm_type'; then 3280 set_userspace_pm $ns2 3281 pm_nl_set_limits $ns1 0 2 3282 pm_nl_set_limits $ns2 0 2 3283 pm_nl_add_endpoint $ns1 10.0.2.1 flags signal 3284 run_tests $ns1 $ns2 10.0.1.1 3285 chk_join_nr 0 0 0 3286 chk_add_nr 1 0 3287 fi 3288 3289 # userspace pm type rejects join 3290 if reset "userspace pm type rejects join" && 3291 continue_if mptcp_lib_has_file '/proc/sys/net/mptcp/pm_type'; then 3292 set_userspace_pm $ns1 3293 pm_nl_set_limits $ns1 1 1 3294 pm_nl_set_limits $ns2 1 1 3295 pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 3296 run_tests $ns1 $ns2 10.0.1.1 3297 chk_join_nr 1 1 0 3298 fi 3299 3300 # userspace pm type does not send join 3301 if reset "userspace pm type does not send join" && 3302 continue_if mptcp_lib_has_file '/proc/sys/net/mptcp/pm_type'; then 3303 set_userspace_pm $ns2 3304 pm_nl_set_limits $ns1 1 1 3305 pm_nl_set_limits $ns2 1 1 3306 pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 3307 run_tests $ns1 $ns2 10.0.1.1 3308 chk_join_nr 0 0 0 3309 fi 3310 3311 # userspace pm type prevents mp_prio 3312 if reset "userspace pm type prevents mp_prio" && 3313 continue_if mptcp_lib_has_file '/proc/sys/net/mptcp/pm_type'; then 3314 set_userspace_pm $ns1 3315 pm_nl_set_limits $ns1 1 1 3316 pm_nl_set_limits $ns2 1 1 3317 pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 3318 sflags=backup speed=slow \ 3319 run_tests $ns1 $ns2 10.0.1.1 3320 chk_join_nr 1 1 0 3321 chk_prio_nr 0 0 3322 fi 3323 3324 # userspace pm type prevents rm_addr 3325 if reset "userspace pm type prevents rm_addr" && 3326 continue_if mptcp_lib_has_file '/proc/sys/net/mptcp/pm_type'; then 3327 set_userspace_pm $ns1 3328 set_userspace_pm $ns2 3329 pm_nl_set_limits $ns1 0 1 3330 pm_nl_set_limits $ns2 0 1 3331 pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 3332 addr_nr_ns2=-1 speed=slow \ 3333 run_tests $ns1 $ns2 10.0.1.1 3334 chk_join_nr 0 0 0 3335 chk_rm_nr 0 0 3336 fi 3337 3338 # userspace pm add & remove address 3339 if reset_with_events "userspace pm add & remove address" && 3340 continue_if mptcp_lib_has_file '/proc/sys/net/mptcp/pm_type'; then 3341 set_userspace_pm $ns1 3342 pm_nl_set_limits $ns2 2 2 3343 speed=5 \ 3344 run_tests $ns1 $ns2 10.0.1.1 & 3345 local tests_pid=$! 3346 wait_mpj $ns1 3347 userspace_pm_add_addr $ns1 10.0.2.1 10 3348 userspace_pm_add_addr $ns1 10.0.3.1 20 3349 chk_join_nr 2 2 2 3350 chk_add_nr 2 2 3351 chk_mptcp_info subflows 2 subflows 2 3352 chk_subflows_total 3 3 3353 chk_mptcp_info add_addr_signal 2 add_addr_accepted 2 3354 userspace_pm_chk_dump_addr "${ns1}" \ 3355 $'id 10 flags signal 10.0.2.1\nid 20 flags signal 10.0.3.1' \ 3356 "signal" 3357 userspace_pm_chk_get_addr "${ns1}" "10" "id 10 flags signal 10.0.2.1" 3358 userspace_pm_chk_get_addr "${ns1}" "20" "id 20 flags signal 10.0.3.1" 3359 userspace_pm_rm_addr $ns1 10 3360 userspace_pm_rm_sf $ns1 "::ffff:10.0.2.1" $MPTCP_LIB_EVENT_SUB_ESTABLISHED 3361 userspace_pm_chk_dump_addr "${ns1}" \ 3362 "id 20 flags signal 10.0.3.1" "after rm_addr 10" 3363 userspace_pm_rm_addr $ns1 20 3364 userspace_pm_rm_sf $ns1 10.0.3.1 $MPTCP_LIB_EVENT_SUB_ESTABLISHED 3365 userspace_pm_chk_dump_addr "${ns1}" "" "after rm_addr 20" 3366 chk_rm_nr 2 2 invert 3367 chk_mptcp_info subflows 0 subflows 0 3368 chk_subflows_total 1 1 3369 kill_events_pids 3370 mptcp_lib_kill_wait $tests_pid 3371 fi 3372 3373 # userspace pm create destroy subflow 3374 if reset_with_events "userspace pm create destroy subflow" && 3375 continue_if mptcp_lib_has_file '/proc/sys/net/mptcp/pm_type'; then 3376 set_userspace_pm $ns2 3377 pm_nl_set_limits $ns1 0 1 3378 speed=5 \ 3379 run_tests $ns1 $ns2 10.0.1.1 & 3380 local tests_pid=$! 3381 wait_mpj $ns2 3382 userspace_pm_add_sf $ns2 10.0.3.2 20 3383 chk_join_nr 1 1 1 3384 chk_mptcp_info subflows 1 subflows 1 3385 chk_subflows_total 2 2 3386 userspace_pm_chk_dump_addr "${ns2}" \ 3387 "id 20 flags subflow 10.0.3.2" \ 3388 "subflow" 3389 userspace_pm_chk_get_addr "${ns2}" "20" "id 20 flags subflow 10.0.3.2" 3390 userspace_pm_rm_addr $ns2 20 3391 userspace_pm_rm_sf $ns2 10.0.3.2 $MPTCP_LIB_EVENT_SUB_ESTABLISHED 3392 userspace_pm_chk_dump_addr "${ns2}" \ 3393 "" \ 3394 "after rm_addr 20" 3395 chk_rm_nr 1 1 3396 chk_mptcp_info subflows 0 subflows 0 3397 chk_subflows_total 1 1 3398 kill_events_pids 3399 mptcp_lib_kill_wait $tests_pid 3400 fi 3401 3402 # userspace pm create id 0 subflow 3403 if reset_with_events "userspace pm create id 0 subflow" && 3404 continue_if mptcp_lib_has_file '/proc/sys/net/mptcp/pm_type'; then 3405 set_userspace_pm $ns2 3406 pm_nl_set_limits $ns1 0 1 3407 speed=5 \ 3408 run_tests $ns1 $ns2 10.0.1.1 & 3409 local tests_pid=$! 3410 wait_mpj $ns2 3411 chk_mptcp_info subflows 0 subflows 0 3412 chk_subflows_total 1 1 3413 userspace_pm_add_sf $ns2 10.0.3.2 0 3414 userspace_pm_chk_dump_addr "${ns2}" \ 3415 "id 0 flags subflow 10.0.3.2" "id 0 subflow" 3416 chk_join_nr 1 1 1 3417 chk_mptcp_info subflows 1 subflows 1 3418 chk_subflows_total 2 2 3419 kill_events_pids 3420 mptcp_lib_kill_wait $tests_pid 3421 fi 3422 3423 # userspace pm remove initial subflow 3424 if reset_with_events "userspace pm remove initial subflow" && 3425 continue_if mptcp_lib_has_file '/proc/sys/net/mptcp/pm_type'; then 3426 set_userspace_pm $ns2 3427 pm_nl_set_limits $ns1 0 1 3428 speed=5 \ 3429 run_tests $ns1 $ns2 10.0.1.1 & 3430 local tests_pid=$! 3431 wait_mpj $ns2 3432 userspace_pm_add_sf $ns2 10.0.3.2 20 3433 chk_join_nr 1 1 1 3434 chk_mptcp_info subflows 1 subflows 1 3435 chk_subflows_total 2 2 3436 userspace_pm_rm_sf $ns2 10.0.1.2 3437 # we don't look at the counter linked to the RM_ADDR but 3438 # to the one linked to the subflows that have been removed 3439 chk_rm_nr 0 1 3440 chk_rst_nr 0 0 invert 3441 chk_mptcp_info subflows 1 subflows 1 3442 chk_subflows_total 1 1 3443 kill_events_pids 3444 mptcp_lib_kill_wait $tests_pid 3445 fi 3446 3447 # userspace pm send RM_ADDR for ID 0 3448 if reset_with_events "userspace pm send RM_ADDR for ID 0" && 3449 continue_if mptcp_lib_has_file '/proc/sys/net/mptcp/pm_type'; then 3450 set_userspace_pm $ns1 3451 pm_nl_set_limits $ns2 1 1 3452 speed=5 \ 3453 run_tests $ns1 $ns2 10.0.1.1 & 3454 local tests_pid=$! 3455 wait_mpj $ns1 3456 userspace_pm_add_addr $ns1 10.0.2.1 10 3457 chk_join_nr 1 1 1 3458 chk_add_nr 1 1 3459 chk_mptcp_info subflows 1 subflows 1 3460 chk_subflows_total 2 2 3461 chk_mptcp_info add_addr_signal 1 add_addr_accepted 1 3462 userspace_pm_rm_addr $ns1 0 3463 # we don't look at the counter linked to the subflows that 3464 # have been removed but to the one linked to the RM_ADDR 3465 chk_rm_nr 1 0 invert 3466 chk_rst_nr 0 0 invert 3467 chk_mptcp_info subflows 1 subflows 1 3468 chk_subflows_total 1 1 3469 kill_events_pids 3470 mptcp_lib_kill_wait $tests_pid 3471 fi 3472} 3473 3474endpoint_tests() 3475{ 3476 # subflow_rebuild_header is needed to support the implicit flag 3477 # userspace pm type prevents add_addr 3478 if reset "implicit EP" && 3479 mptcp_lib_kallsyms_has "subflow_rebuild_header$"; then 3480 pm_nl_set_limits $ns1 2 2 3481 pm_nl_set_limits $ns2 2 2 3482 pm_nl_add_endpoint $ns1 10.0.2.1 flags signal 3483 speed=slow \ 3484 run_tests $ns1 $ns2 10.0.1.1 & 3485 local tests_pid=$! 3486 3487 wait_mpj $ns1 3488 pm_nl_check_endpoint "creation" \ 3489 $ns2 10.0.2.2 id 1 flags implicit 3490 chk_mptcp_info subflows 1 subflows 1 3491 chk_mptcp_info add_addr_signal 1 add_addr_accepted 1 3492 3493 pm_nl_add_endpoint $ns2 10.0.2.2 id 33 2>/dev/null 3494 pm_nl_check_endpoint "ID change is prevented" \ 3495 $ns2 10.0.2.2 id 1 flags implicit 3496 3497 pm_nl_add_endpoint $ns2 10.0.2.2 flags signal 3498 pm_nl_check_endpoint "modif is allowed" \ 3499 $ns2 10.0.2.2 id 1 flags signal 3500 mptcp_lib_kill_wait $tests_pid 3501 fi 3502 3503 if reset "delete and re-add" && 3504 mptcp_lib_kallsyms_has "subflow_rebuild_header$"; then 3505 pm_nl_set_limits $ns1 1 1 3506 pm_nl_set_limits $ns2 1 1 3507 pm_nl_add_endpoint $ns2 10.0.2.2 id 2 dev ns2eth2 flags subflow 3508 test_linkfail=4 speed=20 \ 3509 run_tests $ns1 $ns2 10.0.1.1 & 3510 local tests_pid=$! 3511 3512 wait_mpj $ns2 3513 pm_nl_check_endpoint "creation" \ 3514 $ns2 10.0.2.2 id 2 flags subflow dev ns2eth2 3515 chk_subflow_nr "before delete" 2 3516 chk_mptcp_info subflows 1 subflows 1 3517 3518 pm_nl_del_endpoint $ns2 2 10.0.2.2 3519 sleep 0.5 3520 chk_subflow_nr "after delete" 1 3521 chk_mptcp_info subflows 0 subflows 0 3522 3523 pm_nl_add_endpoint $ns2 10.0.2.2 dev ns2eth2 flags subflow 3524 wait_mpj $ns2 3525 chk_subflow_nr "after re-add" 2 3526 chk_mptcp_info subflows 1 subflows 1 3527 mptcp_lib_kill_wait $tests_pid 3528 fi 3529} 3530 3531# [$1: error message] 3532usage() 3533{ 3534 if [ -n "${1}" ]; then 3535 echo "${1}" 3536 ret=${KSFT_FAIL} 3537 fi 3538 3539 echo "mptcp_join usage:" 3540 3541 local key 3542 for key in "${!all_tests[@]}"; do 3543 echo " -${key} ${all_tests[${key}]}" 3544 done 3545 3546 echo " -c capture pcap files" 3547 echo " -C enable data checksum" 3548 echo " -i use ip mptcp" 3549 echo " -h help" 3550 3551 echo "[test ids|names]" 3552 3553 exit ${ret} 3554} 3555 3556 3557# Use a "simple" array to force an specific order we cannot have with an associative one 3558all_tests_sorted=( 3559 f@subflows_tests 3560 e@subflows_error_tests 3561 s@signal_address_tests 3562 l@link_failure_tests 3563 t@add_addr_timeout_tests 3564 r@remove_tests 3565 a@add_tests 3566 6@ipv6_tests 3567 4@v4mapped_tests 3568 M@mixed_tests 3569 b@backup_tests 3570 p@add_addr_ports_tests 3571 k@syncookies_tests 3572 S@checksum_tests 3573 d@deny_join_id0_tests 3574 m@fullmesh_tests 3575 z@fastclose_tests 3576 F@fail_tests 3577 u@userspace_tests 3578 I@endpoint_tests 3579) 3580 3581all_tests_args="" 3582all_tests_names=() 3583for subtests in "${all_tests_sorted[@]}"; do 3584 key="${subtests%@*}" 3585 value="${subtests#*@}" 3586 3587 all_tests_args+="${key}" 3588 all_tests_names+=("${value}") 3589 all_tests[${key}]="${value}" 3590done 3591 3592tests=() 3593while getopts "${all_tests_args}cCih" opt; do 3594 case $opt in 3595 ["${all_tests_args}"]) 3596 tests+=("${all_tests[${opt}]}") 3597 ;; 3598 c) 3599 capture=true 3600 ;; 3601 C) 3602 checksum=true 3603 ;; 3604 i) 3605 mptcp_lib_set_ip_mptcp 3606 ;; 3607 h) 3608 usage 3609 ;; 3610 *) 3611 usage "Unknown option: -${opt}" 3612 ;; 3613 esac 3614done 3615 3616shift $((OPTIND - 1)) 3617 3618for arg in "${@}"; do 3619 if [[ "${arg}" =~ ^[0-9]+$ ]]; then 3620 only_tests_ids+=("${arg}") 3621 else 3622 only_tests_names+=("${arg}") 3623 fi 3624done 3625 3626if [ ${#tests[@]} -eq 0 ]; then 3627 tests=("${all_tests_names[@]}") 3628fi 3629 3630for subtests in "${tests[@]}"; do 3631 "${subtests}" 3632done 3633 3634if [ ${ret} -ne 0 ]; then 3635 echo 3636 echo "${#failed_tests[@]} failure(s) has(ve) been detected:" 3637 for i in $(get_failed_tests_ids); do 3638 echo -e "\t- ${i}: ${failed_tests[${i}]}" 3639 done 3640 echo 3641fi 3642 3643append_prev_results 3644mptcp_lib_result_print_all_tap 3645 3646exit $ret 3647