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