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. 6 #shellcheck disable=SC2086 7 8 # Some variables are used below but indirectly, see verify_*_event() 9 #shellcheck disable=SC2034 10 11 . "$(dirname "${0}")/mptcp_lib.sh" 12 13 mptcp_lib_check_mptcp 14 mptcp_lib_check_kallsyms 15 16 if ! mptcp_lib_has_file '/proc/sys/net/mptcp/pm_type'; then 17 echo "userspace pm tests are not supported by the kernel: SKIP" 18 exit ${KSFT_SKIP} 19 fi 20 mptcp_lib_check_tools ip 21 22 ANNOUNCED=${MPTCP_LIB_EVENT_ANNOUNCED} 23 REMOVED=${MPTCP_LIB_EVENT_REMOVED} 24 SUB_ESTABLISHED=${MPTCP_LIB_EVENT_SUB_ESTABLISHED} 25 SUB_CLOSED=${MPTCP_LIB_EVENT_SUB_CLOSED} 26 LISTENER_CREATED=${MPTCP_LIB_EVENT_LISTENER_CREATED} 27 LISTENER_CLOSED=${MPTCP_LIB_EVENT_LISTENER_CLOSED} 28 29 AF_INET=${MPTCP_LIB_AF_INET} 30 AF_INET6=${MPTCP_LIB_AF_INET6} 31 32 file="" 33 server_evts="" 34 client_evts="" 35 server_evts_pid=0 36 client_evts_pid=0 37 client4_pid=0 38 server4_pid=0 39 client6_pid=0 40 server6_pid=0 41 client4_token="" 42 server4_token="" 43 client6_token="" 44 server6_token="" 45 client4_port=0; 46 client6_port=0; 47 app4_port=50002 48 new4_port=50003 49 app6_port=50004 50 client_addr_id=${RANDOM:0:2} 51 server_addr_id=${RANDOM:0:2} 52 53 ns1="" 54 ns2="" 55 ret=0 56 test_name="" 57 # a bit more space: because we have more to display 58 MPTCP_LIB_TEST_FORMAT="%02u %-68s" 59 60 print_title() 61 { 62 mptcp_lib_pr_info "${1}" 63 } 64 65 # $1: test name 66 print_test() 67 { 68 test_name="${1}" 69 70 mptcp_lib_print_title "${test_name}" 71 } 72 73 test_pass() 74 { 75 mptcp_lib_pr_ok 76 mptcp_lib_result_pass "${test_name}" 77 } 78 79 test_skip() 80 { 81 mptcp_lib_pr_skip 82 mptcp_lib_result_skip "${test_name}" 83 } 84 85 # $1: msg 86 test_fail() 87 { 88 if [ ${#} -gt 0 ] 89 then 90 mptcp_lib_pr_fail "${@}" 91 fi 92 ret=${KSFT_FAIL} 93 mptcp_lib_result_fail "${test_name}" 94 } 95 96 # This function is used in the cleanup trap 97 #shellcheck disable=SC2317 98 cleanup() 99 { 100 print_title "Cleanup" 101 102 # Terminate the MPTCP connection and related processes 103 local pid 104 for pid in $client4_pid $server4_pid $client6_pid $server6_pid\ 105 $server_evts_pid $client_evts_pid 106 do 107 mptcp_lib_kill_wait $pid 108 done 109 110 mptcp_lib_ns_exit "${ns1}" "${ns2}" 111 112 rm -rf $file $client_evts $server_evts 113 114 mptcp_lib_pr_info "Done" 115 } 116 117 trap cleanup EXIT 118 119 # Create and configure network namespaces for testing 120 mptcp_lib_ns_init ns1 ns2 121 for i in "$ns1" "$ns2" ;do 122 ip netns exec "$i" sysctl -q net.mptcp.pm_type=1 123 done 124 125 # "$ns1" ns2 126 # ns1eth2 ns2eth1 127 128 ip link add ns1eth2 netns "$ns1" type veth peer name ns2eth1 netns "$ns2" 129 130 # Add IPv4/v6 addresses to the namespaces 131 ip -net "$ns1" addr add 10.0.1.1/24 dev ns1eth2 132 ip -net "$ns1" addr add 10.0.2.1/24 dev ns1eth2 133 ip -net "$ns1" addr add dead:beef:1::1/64 dev ns1eth2 nodad 134 ip -net "$ns1" addr add dead:beef:2::1/64 dev ns1eth2 nodad 135 ip -net "$ns1" link set ns1eth2 up 136 137 ip -net "$ns2" addr add 10.0.1.2/24 dev ns2eth1 138 ip -net "$ns2" addr add 10.0.2.2/24 dev ns2eth1 139 ip -net "$ns2" addr add dead:beef:1::2/64 dev ns2eth1 nodad 140 ip -net "$ns2" addr add dead:beef:2::2/64 dev ns2eth1 nodad 141 ip -net "$ns2" link set ns2eth1 up 142 143 file=$(mktemp) 144 mptcp_lib_make_file "$file" 2 1 145 146 # Capture netlink events over the two network namespaces running 147 # the MPTCP client and server 148 client_evts=$(mktemp) 149 mptcp_lib_events "${ns2}" "${client_evts}" client_evts_pid 150 server_evts=$(mktemp) 151 mptcp_lib_events "${ns1}" "${server_evts}" server_evts_pid 152 sleep 0.5 153 mptcp_lib_subtests_last_ts_reset 154 155 print_title "Init" 156 print_test "Created network namespaces ns1, ns2" 157 test_pass 158 159 make_connection() 160 { 161 local is_v6=$1 162 local app_port=$app4_port 163 local connect_addr="10.0.1.1" 164 local client_addr="10.0.1.2" 165 local listen_addr="0.0.0.0" 166 if [ "$is_v6" = "v6" ] 167 then 168 connect_addr="dead:beef:1::1" 169 client_addr="dead:beef:1::2" 170 listen_addr="::" 171 app_port=$app6_port 172 else 173 is_v6="v4" 174 fi 175 176 :>"$client_evts" 177 :>"$server_evts" 178 179 # Run the server 180 ip netns exec "$ns1" \ 181 ./mptcp_connect -s MPTCP -w 300 -p $app_port -l $listen_addr > /dev/null 2>&1 & 182 local server_pid=$! 183 sleep 0.5 184 185 # Run the client, transfer $file and stay connected to the server 186 # to conduct tests 187 ip netns exec "$ns2" \ 188 ./mptcp_connect -s MPTCP -w 300 -m sendfile -p $app_port $connect_addr\ 189 2>&1 > /dev/null < "$file" & 190 local client_pid=$! 191 sleep 1 192 193 # Capture client/server attributes from MPTCP connection netlink events 194 195 local client_token 196 local client_port 197 local client_serverside 198 local server_token 199 local server_serverside 200 201 client_token=$(mptcp_lib_evts_get_info token "$client_evts") 202 client_port=$(mptcp_lib_evts_get_info sport "$client_evts") 203 client_serverside=$(mptcp_lib_evts_get_info server_side "$client_evts") 204 server_token=$(mptcp_lib_evts_get_info token "$server_evts") 205 server_serverside=$(mptcp_lib_evts_get_info server_side "$server_evts") 206 207 print_test "Established IP${is_v6} MPTCP Connection ns2 => ns1" 208 if [ "$client_token" != "" ] && [ "$server_token" != "" ] && [ "$client_serverside" = 0 ] && 209 [ "$server_serverside" = 1 ] 210 then 211 test_pass 212 print_title "Connection info: ${client_addr}:${client_port} -> ${connect_addr}:${app_port}" 213 else 214 test_fail "Expected tokens (c:${client_token} - s:${server_token}) and server (c:${client_serverside} - s:${server_serverside})" 215 mptcp_lib_result_print_all_tap 216 exit ${KSFT_FAIL} 217 fi 218 219 if [ "$is_v6" = "v6" ] 220 then 221 client6_token=$client_token 222 server6_token=$server_token 223 client6_port=$client_port 224 client6_pid=$client_pid 225 server6_pid=$server_pid 226 else 227 client4_token=$client_token 228 server4_token=$server_token 229 client4_port=$client_port 230 client4_pid=$client_pid 231 server4_pid=$server_pid 232 fi 233 } 234 235 # $@: all var names to check 236 check_expected() 237 { 238 if mptcp_lib_check_expected "${@}" 239 then 240 test_pass 241 return 0 242 fi 243 244 test_fail 245 return 1 246 } 247 248 verify_announce_event() 249 { 250 local evt=$1 251 local e_type=$2 252 local e_token=$3 253 local e_addr=$4 254 local e_id=$5 255 local e_dport=$6 256 local e_af=$7 257 local type 258 local token 259 local addr 260 local dport 261 local id 262 263 type=$(mptcp_lib_evts_get_info type "$evt" $e_type) 264 token=$(mptcp_lib_evts_get_info token "$evt" $e_type) 265 if [ "$e_af" = "v6" ] 266 then 267 addr=$(mptcp_lib_evts_get_info daddr6 "$evt" $e_type) 268 else 269 addr=$(mptcp_lib_evts_get_info daddr4 "$evt" $e_type) 270 fi 271 dport=$(mptcp_lib_evts_get_info dport "$evt" $e_type) 272 id=$(mptcp_lib_evts_get_info rem_id "$evt" $e_type) 273 274 check_expected "type" "token" "addr" "dport" "id" 275 } 276 277 test_announce() 278 { 279 print_title "Announce tests" 280 281 # Capture events on the network namespace running the server 282 :>"$server_evts" 283 284 # ADD_ADDR using an invalid token should result in no action 285 local invalid_token=$(( client4_token - 1)) 286 ip netns exec "$ns2" ./pm_nl_ctl ann 10.0.2.2 token $invalid_token id\ 287 $client_addr_id dev ns2eth1 > /dev/null 2>&1 288 289 local type 290 type=$(mptcp_lib_evts_get_info type "$server_evts") 291 print_test "ADD_ADDR 10.0.2.2 (ns2) => ns1, invalid token" 292 if [ "$type" = "" ] 293 then 294 test_pass 295 else 296 test_fail "type defined: ${type}" 297 fi 298 299 # ADD_ADDR from the client to server machine reusing the subflow port 300 :>"$server_evts" 301 ip netns exec "$ns2"\ 302 ./pm_nl_ctl ann 10.0.2.2 token "$client4_token" id $client_addr_id dev\ 303 ns2eth1 304 print_test "ADD_ADDR id:client 10.0.2.2 (ns2) => ns1, reuse port" 305 sleep 0.5 306 verify_announce_event $server_evts $ANNOUNCED $server4_token "10.0.2.2" $client_addr_id \ 307 "$client4_port" 308 309 # ADD_ADDR6 from the client to server machine reusing the subflow port 310 :>"$server_evts" 311 ip netns exec "$ns2" ./pm_nl_ctl ann\ 312 dead:beef:2::2 token "$client6_token" id $client_addr_id dev ns2eth1 313 print_test "ADD_ADDR6 id:client dead:beef:2::2 (ns2) => ns1, reuse port" 314 sleep 0.5 315 verify_announce_event "$server_evts" "$ANNOUNCED" "$server6_token" "dead:beef:2::2"\ 316 "$client_addr_id" "$client6_port" "v6" 317 318 # ADD_ADDR from the client to server machine using a new port 319 :>"$server_evts" 320 client_addr_id=$((client_addr_id+1)) 321 ip netns exec "$ns2" ./pm_nl_ctl ann 10.0.2.2 token "$client4_token" id\ 322 $client_addr_id dev ns2eth1 port $new4_port 323 print_test "ADD_ADDR id:client+1 10.0.2.2 (ns2) => ns1, new port" 324 sleep 0.5 325 verify_announce_event "$server_evts" "$ANNOUNCED" "$server4_token" "10.0.2.2"\ 326 "$client_addr_id" "$new4_port" 327 328 # Capture events on the network namespace running the client 329 :>"$client_evts" 330 331 # ADD_ADDR from the server to client machine reusing the subflow port 332 ip netns exec "$ns1" ./pm_nl_ctl ann 10.0.2.1 token "$server4_token" id\ 333 $server_addr_id dev ns1eth2 334 print_test "ADD_ADDR id:server 10.0.2.1 (ns1) => ns2, reuse port" 335 sleep 0.5 336 verify_announce_event "$client_evts" "$ANNOUNCED" "$client4_token" "10.0.2.1"\ 337 "$server_addr_id" "$app4_port" 338 339 # ADD_ADDR6 from the server to client machine reusing the subflow port 340 :>"$client_evts" 341 ip netns exec "$ns1" ./pm_nl_ctl ann dead:beef:2::1 token "$server6_token" id\ 342 $server_addr_id dev ns1eth2 343 print_test "ADD_ADDR6 id:server dead:beef:2::1 (ns1) => ns2, reuse port" 344 sleep 0.5 345 verify_announce_event "$client_evts" "$ANNOUNCED" "$client6_token" "dead:beef:2::1"\ 346 "$server_addr_id" "$app6_port" "v6" 347 348 # ADD_ADDR from the server to client machine using a new port 349 :>"$client_evts" 350 server_addr_id=$((server_addr_id+1)) 351 ip netns exec "$ns1" ./pm_nl_ctl ann 10.0.2.1 token "$server4_token" id\ 352 $server_addr_id dev ns1eth2 port $new4_port 353 print_test "ADD_ADDR id:server+1 10.0.2.1 (ns1) => ns2, new port" 354 sleep 0.5 355 verify_announce_event "$client_evts" "$ANNOUNCED" "$client4_token" "10.0.2.1"\ 356 "$server_addr_id" "$new4_port" 357 } 358 359 verify_remove_event() 360 { 361 local evt=$1 362 local e_type=$2 363 local e_token=$3 364 local e_id=$4 365 local type 366 local token 367 local id 368 369 type=$(mptcp_lib_evts_get_info type "$evt" $e_type) 370 token=$(mptcp_lib_evts_get_info token "$evt" $e_type) 371 id=$(mptcp_lib_evts_get_info rem_id "$evt" $e_type) 372 373 check_expected "type" "token" "id" 374 } 375 376 test_remove() 377 { 378 print_title "Remove tests" 379 380 # Capture events on the network namespace running the server 381 :>"$server_evts" 382 383 # RM_ADDR using an invalid token should result in no action 384 local invalid_token=$(( client4_token - 1 )) 385 ip netns exec "$ns2" ./pm_nl_ctl rem token $invalid_token id\ 386 $client_addr_id > /dev/null 2>&1 387 print_test "RM_ADDR id:client ns2 => ns1, invalid token" 388 local type 389 type=$(mptcp_lib_evts_get_info type "$server_evts") 390 if [ "$type" = "" ] 391 then 392 test_pass 393 else 394 test_fail "unexpected type: ${type}" 395 fi 396 397 # RM_ADDR using an invalid addr id should result in no action 398 local invalid_id=$(( client_addr_id + 1 )) 399 ip netns exec "$ns2" ./pm_nl_ctl rem token "$client4_token" id\ 400 $invalid_id > /dev/null 2>&1 401 print_test "RM_ADDR id:client+1 ns2 => ns1, invalid id" 402 type=$(mptcp_lib_evts_get_info type "$server_evts") 403 if [ "$type" = "" ] 404 then 405 test_pass 406 else 407 test_fail "unexpected type: ${type}" 408 fi 409 410 # RM_ADDR from the client to server machine 411 :>"$server_evts" 412 ip netns exec "$ns2" ./pm_nl_ctl rem token "$client4_token" id\ 413 $client_addr_id 414 print_test "RM_ADDR id:client ns2 => ns1" 415 sleep 0.5 416 verify_remove_event "$server_evts" "$REMOVED" "$server4_token" "$client_addr_id" 417 418 # RM_ADDR from the client to server machine 419 :>"$server_evts" 420 client_addr_id=$(( client_addr_id - 1 )) 421 ip netns exec "$ns2" ./pm_nl_ctl rem token "$client4_token" id\ 422 $client_addr_id 423 print_test "RM_ADDR id:client-1 ns2 => ns1" 424 sleep 0.5 425 verify_remove_event "$server_evts" "$REMOVED" "$server4_token" "$client_addr_id" 426 427 # RM_ADDR6 from the client to server machine 428 :>"$server_evts" 429 ip netns exec "$ns2" ./pm_nl_ctl rem token "$client6_token" id\ 430 $client_addr_id 431 print_test "RM_ADDR6 id:client-1 ns2 => ns1" 432 sleep 0.5 433 verify_remove_event "$server_evts" "$REMOVED" "$server6_token" "$client_addr_id" 434 435 # Capture events on the network namespace running the client 436 :>"$client_evts" 437 438 # RM_ADDR from the server to client machine 439 ip netns exec "$ns1" ./pm_nl_ctl rem token "$server4_token" id\ 440 $server_addr_id 441 print_test "RM_ADDR id:server ns1 => ns2" 442 sleep 0.5 443 verify_remove_event "$client_evts" "$REMOVED" "$client4_token" "$server_addr_id" 444 445 # RM_ADDR from the server to client machine 446 :>"$client_evts" 447 server_addr_id=$(( server_addr_id - 1 )) 448 ip netns exec "$ns1" ./pm_nl_ctl rem token "$server4_token" id\ 449 $server_addr_id 450 print_test "RM_ADDR id:server-1 ns1 => ns2" 451 sleep 0.5 452 verify_remove_event "$client_evts" "$REMOVED" "$client4_token" "$server_addr_id" 453 454 # RM_ADDR6 from the server to client machine 455 :>"$client_evts" 456 ip netns exec "$ns1" ./pm_nl_ctl rem token "$server6_token" id\ 457 $server_addr_id 458 print_test "RM_ADDR6 id:server-1 ns1 => ns2" 459 sleep 0.5 460 verify_remove_event "$client_evts" "$REMOVED" "$client6_token" "$server_addr_id" 461 } 462 463 verify_subflow_events() 464 { 465 local evt=$1 466 local e_type=$2 467 local e_token=$3 468 local e_family=$4 469 local e_saddr=$5 470 local e_daddr=$6 471 local e_dport=$7 472 local e_locid=$8 473 local e_remid=$9 474 shift 2 475 local e_from=$8 476 local e_to=$9 477 local type 478 local token 479 local family 480 local saddr 481 local daddr 482 local dport 483 local locid 484 local remid 485 local info 486 local e_dport_txt 487 488 # only display the fixed ports 489 if [ "${e_dport}" -ge "${app4_port}" ] && [ "${e_dport}" -le "${app6_port}" ]; then 490 e_dport_txt=":${e_dport}" 491 fi 492 493 info="${e_saddr} (${e_from}) => ${e_daddr}${e_dport_txt} (${e_to})" 494 495 if [ "$e_type" = "$SUB_ESTABLISHED" ] 496 then 497 if [ "$e_family" = "$AF_INET6" ] 498 then 499 print_test "CREATE_SUBFLOW6 ${info}" 500 else 501 print_test "CREATE_SUBFLOW ${info}" 502 fi 503 else 504 if [ "$e_family" = "$AF_INET6" ] 505 then 506 print_test "DESTROY_SUBFLOW6 ${info}" 507 else 508 print_test "DESTROY_SUBFLOW ${info}" 509 fi 510 fi 511 512 type=$(mptcp_lib_evts_get_info type "$evt" $e_type) 513 token=$(mptcp_lib_evts_get_info token "$evt" $e_type) 514 family=$(mptcp_lib_evts_get_info family "$evt" $e_type) 515 dport=$(mptcp_lib_evts_get_info dport "$evt" $e_type) 516 locid=$(mptcp_lib_evts_get_info loc_id "$evt" $e_type) 517 remid=$(mptcp_lib_evts_get_info rem_id "$evt" $e_type) 518 if [ "$family" = "$AF_INET6" ] 519 then 520 saddr=$(mptcp_lib_evts_get_info saddr6 "$evt" $e_type) 521 daddr=$(mptcp_lib_evts_get_info daddr6 "$evt" $e_type) 522 else 523 saddr=$(mptcp_lib_evts_get_info saddr4 "$evt" $e_type) 524 daddr=$(mptcp_lib_evts_get_info daddr4 "$evt" $e_type) 525 fi 526 527 check_expected "type" "token" "daddr" "dport" "family" "saddr" "locid" "remid" 528 } 529 530 test_subflows() 531 { 532 print_title "Subflows v4 or v6 only tests" 533 534 # Capture events on the network namespace running the server 535 :>"$server_evts" 536 537 # Attempt to add a listener at 10.0.2.2:<subflow-port> 538 ip netns exec "$ns2" ./pm_nl_ctl listen 10.0.2.2\ 539 "$client4_port" & 540 local listener_pid=$! 541 542 # ADD_ADDR from client to server machine reusing the subflow port 543 ip netns exec "$ns2" ./pm_nl_ctl ann 10.0.2.2 token "$client4_token" id\ 544 $client_addr_id 545 sleep 0.5 546 547 # CREATE_SUBFLOW from server to client machine 548 :>"$server_evts" 549 ip netns exec "$ns1" ./pm_nl_ctl csf lip 10.0.2.1 lid 23 rip 10.0.2.2\ 550 rport "$client4_port" token "$server4_token" 551 sleep 0.5 552 verify_subflow_events $server_evts $SUB_ESTABLISHED $server4_token $AF_INET "10.0.2.1" \ 553 "10.0.2.2" "$client4_port" "23" "$client_addr_id" "ns1" "ns2" 554 555 # Delete the listener from the client ns, if one was created 556 mptcp_lib_kill_wait $listener_pid 557 558 local sport 559 sport=$(mptcp_lib_evts_get_info sport "$server_evts" $SUB_ESTABLISHED) 560 561 # DESTROY_SUBFLOW from server to client machine 562 :>"$server_evts" 563 ip netns exec "$ns1" ./pm_nl_ctl dsf lip 10.0.2.1 lport "$sport" rip 10.0.2.2 rport\ 564 "$client4_port" token "$server4_token" 565 sleep 0.5 566 verify_subflow_events "$server_evts" "$SUB_CLOSED" "$server4_token" "$AF_INET" "10.0.2.1"\ 567 "10.0.2.2" "$client4_port" "23" "$client_addr_id" "ns1" "ns2" 568 569 # RM_ADDR from client to server machine 570 ip netns exec "$ns2" ./pm_nl_ctl rem id $client_addr_id token\ 571 "$client4_token" 572 sleep 0.5 573 574 # Attempt to add a listener at dead:beef:2::2:<subflow-port> 575 ip netns exec "$ns2" ./pm_nl_ctl listen dead:beef:2::2\ 576 "$client6_port" & 577 listener_pid=$! 578 579 # ADD_ADDR6 from client to server machine reusing the subflow port 580 :>"$server_evts" 581 ip netns exec "$ns2" ./pm_nl_ctl ann dead:beef:2::2 token "$client6_token" id\ 582 $client_addr_id 583 sleep 0.5 584 585 # CREATE_SUBFLOW6 from server to client machine 586 :>"$server_evts" 587 ip netns exec "$ns1" ./pm_nl_ctl csf lip dead:beef:2::1 lid 23 rip\ 588 dead:beef:2::2 rport "$client6_port" token "$server6_token" 589 sleep 0.5 590 verify_subflow_events "$server_evts" "$SUB_ESTABLISHED" "$server6_token" "$AF_INET6"\ 591 "dead:beef:2::1" "dead:beef:2::2" "$client6_port" "23"\ 592 "$client_addr_id" "ns1" "ns2" 593 594 # Delete the listener from the client ns, if one was created 595 mptcp_lib_kill_wait $listener_pid 596 597 sport=$(mptcp_lib_evts_get_info sport "$server_evts" $SUB_ESTABLISHED) 598 599 # DESTROY_SUBFLOW6 from server to client machine 600 :>"$server_evts" 601 ip netns exec "$ns1" ./pm_nl_ctl dsf lip dead:beef:2::1 lport "$sport" rip\ 602 dead:beef:2::2 rport "$client6_port" token "$server6_token" 603 sleep 0.5 604 verify_subflow_events "$server_evts" "$SUB_CLOSED" "$server6_token" "$AF_INET6"\ 605 "dead:beef:2::1" "dead:beef:2::2" "$client6_port" "23"\ 606 "$client_addr_id" "ns1" "ns2" 607 608 # RM_ADDR from client to server machine 609 ip netns exec "$ns2" ./pm_nl_ctl rem id $client_addr_id token\ 610 "$client6_token" 611 sleep 0.5 612 613 # Attempt to add a listener at 10.0.2.2:<new-port> 614 ip netns exec "$ns2" ./pm_nl_ctl listen 10.0.2.2\ 615 $new4_port & 616 listener_pid=$! 617 618 # ADD_ADDR from client to server machine using a new port 619 :>"$server_evts" 620 ip netns exec "$ns2" ./pm_nl_ctl ann 10.0.2.2 token "$client4_token" id\ 621 $client_addr_id port $new4_port 622 sleep 0.5 623 624 # CREATE_SUBFLOW from server to client machine 625 :>"$server_evts" 626 ip netns exec "$ns1" ./pm_nl_ctl csf lip 10.0.2.1 lid 23 rip 10.0.2.2 rport\ 627 $new4_port token "$server4_token" 628 sleep 0.5 629 verify_subflow_events "$server_evts" "$SUB_ESTABLISHED" "$server4_token" "$AF_INET"\ 630 "10.0.2.1" "10.0.2.2" "$new4_port" "23"\ 631 "$client_addr_id" "ns1" "ns2" 632 633 # Delete the listener from the client ns, if one was created 634 mptcp_lib_kill_wait $listener_pid 635 636 sport=$(mptcp_lib_evts_get_info sport "$server_evts" $SUB_ESTABLISHED) 637 638 # DESTROY_SUBFLOW from server to client machine 639 :>"$server_evts" 640 ip netns exec "$ns1" ./pm_nl_ctl dsf lip 10.0.2.1 lport "$sport" rip 10.0.2.2 rport\ 641 $new4_port token "$server4_token" 642 sleep 0.5 643 verify_subflow_events "$server_evts" "$SUB_CLOSED" "$server4_token" "$AF_INET" "10.0.2.1"\ 644 "10.0.2.2" "$new4_port" "23" "$client_addr_id" "ns1" "ns2" 645 646 # RM_ADDR from client to server machine 647 ip netns exec "$ns2" ./pm_nl_ctl rem id $client_addr_id token\ 648 "$client4_token" 649 650 # Capture events on the network namespace running the client 651 :>"$client_evts" 652 653 # Attempt to add a listener at 10.0.2.1:<subflow-port> 654 ip netns exec "$ns1" ./pm_nl_ctl listen 10.0.2.1\ 655 $app4_port & 656 listener_pid=$! 657 658 # ADD_ADDR from server to client machine reusing the subflow port 659 ip netns exec "$ns1" ./pm_nl_ctl ann 10.0.2.1 token "$server4_token" id\ 660 $server_addr_id 661 sleep 0.5 662 663 # CREATE_SUBFLOW from client to server machine 664 :>"$client_evts" 665 ip netns exec "$ns2" ./pm_nl_ctl csf lip 10.0.2.2 lid 23 rip 10.0.2.1 rport\ 666 $app4_port token "$client4_token" 667 sleep 0.5 668 verify_subflow_events $client_evts $SUB_ESTABLISHED $client4_token $AF_INET "10.0.2.2"\ 669 "10.0.2.1" "$app4_port" "23" "$server_addr_id" "ns2" "ns1" 670 671 # Delete the listener from the server ns, if one was created 672 mptcp_lib_kill_wait $listener_pid 673 674 sport=$(mptcp_lib_evts_get_info sport "$client_evts" $SUB_ESTABLISHED) 675 676 # DESTROY_SUBFLOW from client to server machine 677 :>"$client_evts" 678 ip netns exec "$ns2" ./pm_nl_ctl dsf lip 10.0.2.2 lport "$sport" rip 10.0.2.1 rport\ 679 $app4_port token "$client4_token" 680 sleep 0.5 681 verify_subflow_events "$client_evts" "$SUB_CLOSED" "$client4_token" "$AF_INET" "10.0.2.2"\ 682 "10.0.2.1" "$app4_port" "23" "$server_addr_id" "ns2" "ns1" 683 684 # RM_ADDR from server to client machine 685 ip netns exec "$ns1" ./pm_nl_ctl rem id $server_addr_id token\ 686 "$server4_token" 687 sleep 0.5 688 689 # Attempt to add a listener at dead:beef:2::1:<subflow-port> 690 ip netns exec "$ns1" ./pm_nl_ctl listen dead:beef:2::1\ 691 $app6_port & 692 listener_pid=$! 693 694 # ADD_ADDR6 from server to client machine reusing the subflow port 695 :>"$client_evts" 696 ip netns exec "$ns1" ./pm_nl_ctl ann dead:beef:2::1 token "$server6_token" id\ 697 $server_addr_id 698 sleep 0.5 699 700 # CREATE_SUBFLOW6 from client to server machine 701 :>"$client_evts" 702 ip netns exec "$ns2" ./pm_nl_ctl csf lip dead:beef:2::2 lid 23 rip\ 703 dead:beef:2::1 rport $app6_port token "$client6_token" 704 sleep 0.5 705 verify_subflow_events "$client_evts" "$SUB_ESTABLISHED" "$client6_token"\ 706 "$AF_INET6" "dead:beef:2::2"\ 707 "dead:beef:2::1" "$app6_port" "23"\ 708 "$server_addr_id" "ns2" "ns1" 709 710 # Delete the listener from the server ns, if one was created 711 mptcp_lib_kill_wait $listener_pid 712 713 sport=$(mptcp_lib_evts_get_info sport "$client_evts" $SUB_ESTABLISHED) 714 715 # DESTROY_SUBFLOW6 from client to server machine 716 :>"$client_evts" 717 ip netns exec "$ns2" ./pm_nl_ctl dsf lip dead:beef:2::2 lport "$sport" rip\ 718 dead:beef:2::1 rport $app6_port token "$client6_token" 719 sleep 0.5 720 verify_subflow_events $client_evts $SUB_CLOSED $client6_token $AF_INET6 "dead:beef:2::2"\ 721 "dead:beef:2::1" "$app6_port" "23" "$server_addr_id" "ns2" "ns1" 722 723 # RM_ADDR6 from server to client machine 724 ip netns exec "$ns1" ./pm_nl_ctl rem id $server_addr_id token\ 725 "$server6_token" 726 sleep 0.5 727 728 # Attempt to add a listener at 10.0.2.1:<new-port> 729 ip netns exec "$ns1" ./pm_nl_ctl listen 10.0.2.1\ 730 $new4_port & 731 listener_pid=$! 732 733 # ADD_ADDR from server to client machine using a new port 734 :>"$client_evts" 735 ip netns exec "$ns1" ./pm_nl_ctl ann 10.0.2.1 token "$server4_token" id\ 736 $server_addr_id port $new4_port 737 sleep 0.5 738 739 # CREATE_SUBFLOW from client to server machine 740 :>"$client_evts" 741 ip netns exec "$ns2" ./pm_nl_ctl csf lip 10.0.2.2 lid 23 rip 10.0.2.1 rport\ 742 $new4_port token "$client4_token" 743 sleep 0.5 744 verify_subflow_events "$client_evts" "$SUB_ESTABLISHED" "$client4_token" "$AF_INET"\ 745 "10.0.2.2" "10.0.2.1" "$new4_port" "23" "$server_addr_id" "ns2" "ns1" 746 747 # Delete the listener from the server ns, if one was created 748 mptcp_lib_kill_wait $listener_pid 749 750 sport=$(mptcp_lib_evts_get_info sport "$client_evts" $SUB_ESTABLISHED) 751 752 # DESTROY_SUBFLOW from client to server machine 753 :>"$client_evts" 754 ip netns exec "$ns2" ./pm_nl_ctl dsf lip 10.0.2.2 lport "$sport" rip 10.0.2.1 rport\ 755 $new4_port token "$client4_token" 756 sleep 0.5 757 verify_subflow_events "$client_evts" "$SUB_CLOSED" "$client4_token" "$AF_INET" "10.0.2.2"\ 758 "10.0.2.1" "$new4_port" "23" "$server_addr_id" "ns2" "ns1" 759 760 # RM_ADDR from server to client machine 761 ip netns exec "$ns1" ./pm_nl_ctl rem id $server_addr_id token\ 762 "$server4_token" 763 } 764 765 test_subflows_v4_v6_mix() 766 { 767 print_title "Subflows v4 and v6 mix tests" 768 769 # Attempt to add a listener at 10.0.2.1:<subflow-port> 770 ip netns exec "$ns1" ./pm_nl_ctl listen 10.0.2.1\ 771 $app6_port & 772 local listener_pid=$! 773 774 # ADD_ADDR4 from server to client machine reusing the subflow port on 775 # the established v6 connection 776 :>"$client_evts" 777 ip netns exec "$ns1" ./pm_nl_ctl ann 10.0.2.1 token "$server6_token" id\ 778 $server_addr_id dev ns1eth2 779 print_test "ADD_ADDR4 id:server 10.0.2.1 (ns1) => ns2, reuse port" 780 sleep 0.5 781 verify_announce_event "$client_evts" "$ANNOUNCED" "$client6_token" "10.0.2.1"\ 782 "$server_addr_id" "$app6_port" 783 784 # CREATE_SUBFLOW from client to server machine 785 :>"$client_evts" 786 ip netns exec "$ns2" ./pm_nl_ctl csf lip 10.0.2.2 lid 23 rip 10.0.2.1 rport\ 787 $app6_port token "$client6_token" 788 sleep 0.5 789 verify_subflow_events "$client_evts" "$SUB_ESTABLISHED" "$client6_token"\ 790 "$AF_INET" "10.0.2.2" "10.0.2.1" "$app6_port" "23"\ 791 "$server_addr_id" "ns2" "ns1" 792 793 # Delete the listener from the server ns, if one was created 794 mptcp_lib_kill_wait $listener_pid 795 796 sport=$(mptcp_lib_evts_get_info sport "$client_evts" $SUB_ESTABLISHED) 797 798 # DESTROY_SUBFLOW from client to server machine 799 :>"$client_evts" 800 ip netns exec "$ns2" ./pm_nl_ctl dsf lip 10.0.2.2 lport "$sport" rip 10.0.2.1 rport\ 801 $app6_port token "$client6_token" 802 sleep 0.5 803 verify_subflow_events "$client_evts" "$SUB_CLOSED" "$client6_token" \ 804 "$AF_INET" "10.0.2.2" "10.0.2.1" "$app6_port" "23"\ 805 "$server_addr_id" "ns2" "ns1" 806 807 # RM_ADDR from server to client machine 808 ip netns exec "$ns1" ./pm_nl_ctl rem id $server_addr_id token\ 809 "$server6_token" 810 sleep 0.5 811 } 812 813 test_prio() 814 { 815 print_title "Prio tests" 816 817 local count 818 819 # Send MP_PRIO signal from client to server machine 820 ip netns exec "$ns2" ./pm_nl_ctl set 10.0.1.2 port "$client4_port" flags backup token "$client4_token" rip 10.0.1.1 rport "$app4_port" 821 sleep 0.5 822 823 # Check TX 824 print_test "MP_PRIO TX" 825 count=$(mptcp_lib_get_counter "$ns2" "MPTcpExtMPPrioTx") 826 if [ -z "$count" ]; then 827 test_skip 828 elif [ $count != 1 ]; then 829 test_fail "Count != 1: ${count}" 830 else 831 test_pass 832 fi 833 834 # Check RX 835 print_test "MP_PRIO RX" 836 count=$(mptcp_lib_get_counter "$ns1" "MPTcpExtMPPrioRx") 837 if [ -z "$count" ]; then 838 test_skip 839 elif [ $count != 1 ]; then 840 test_fail "Count != 1: ${count}" 841 else 842 test_pass 843 fi 844 } 845 846 verify_listener_events() 847 { 848 if mptcp_lib_verify_listener_events "${@}"; then 849 test_pass 850 else 851 test_fail 852 fi 853 } 854 855 test_listener() 856 { 857 print_title "Listener tests" 858 859 if ! mptcp_lib_kallsyms_has "mptcp_event_pm_listener$"; then 860 print_test "LISTENER events" 861 test_skip 862 return 863 fi 864 865 # Capture events on the network namespace running the client 866 :>$client_evts 867 868 # Attempt to add a listener at 10.0.2.2:<subflow-port> 869 ip netns exec $ns2 ./pm_nl_ctl listen 10.0.2.2\ 870 $client4_port & 871 local listener_pid=$! 872 873 sleep 0.5 874 print_test "CREATE_LISTENER 10.0.2.2 (client port)" 875 verify_listener_events $client_evts $LISTENER_CREATED $AF_INET 10.0.2.2 $client4_port 876 877 # ADD_ADDR from client to server machine reusing the subflow port 878 ip netns exec $ns2 ./pm_nl_ctl ann 10.0.2.2 token $client4_token id\ 879 $client_addr_id 880 sleep 0.5 881 882 # CREATE_SUBFLOW from server to client machine 883 ip netns exec $ns1 ./pm_nl_ctl csf lip 10.0.2.1 lid 23 rip 10.0.2.2\ 884 rport $client4_port token $server4_token 885 sleep 0.5 886 887 # Delete the listener from the client ns, if one was created 888 mptcp_lib_kill_wait $listener_pid 889 890 sleep 0.5 891 print_test "CLOSE_LISTENER 10.0.2.2 (client port)" 892 verify_listener_events $client_evts $LISTENER_CLOSED $AF_INET 10.0.2.2 $client4_port 893 } 894 895 print_title "Make connections" 896 make_connection 897 make_connection "v6" 898 print_title "Will be using address IDs ${client_addr_id} (client) and ${server_addr_id} (server)" 899 900 test_announce 901 test_remove 902 test_subflows 903 test_subflows_v4_v6_mix 904 test_prio 905 test_listener 906 907 mptcp_lib_result_print_all_tap 908 exit ${ret}
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.