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