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