-
-
Notifications
You must be signed in to change notification settings - Fork 45
/
Copy pathmptcp_join.sh
executable file
·3323 lines (2937 loc) · 81 KB
/
mptcp_join.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/bin/bash
# SPDX-License-Identifier: GPL-2.0
# Double quotes to prevent globbing and word splitting is recommended in new
# code but we accept it, especially because there were too many before having
# address all other issues detected by shellcheck.
#shellcheck disable=SC2086
# ShellCheck incorrectly believes that most of the code here is unreachable
# because it's invoked by variable name, see how the "tests" array is used
#shellcheck disable=SC2317
. "$(dirname "${0}")/mptcp_lib.sh"
ret=0
sin=""
sinfail=""
sout=""
cin=""
cinfail=""
cinsent=""
tmpfile=""
cout=""
capout=""
ns1=""
ns2=""
ksft_skip=4
timeout_poll=30
timeout_test=$((timeout_poll * 2 + 1))
capture=0
checksum=0
ip_mptcp=0
check_invert=0
validate_checksum=0
init=0
evts_ns1=""
evts_ns2=""
evts_ns1_pid=0
evts_ns2_pid=0
stats_dumped=0
declare -A all_tests
declare -a only_tests_ids
declare -a only_tests_names
declare -A failed_tests
TEST_COUNT=0
TEST_NAME=""
nr_blank=40
export FAILING_LINKS=""
# generated using "nfbpf_compile '(ip && (ip[54] & 0xf0) == 0x30) ||
# (ip6 && (ip6[74] & 0xf0) == 0x30)'"
CBPF_MPTCP_SUBOPTION_ADD_ADDR="14,
48 0 0 0,
84 0 0 240,
21 0 3 64,
48 0 0 54,
84 0 0 240,
21 6 7 48,
48 0 0 0,
84 0 0 240,
21 0 4 96,
48 0 0 74,
84 0 0 240,
21 0 1 48,
6 0 0 65535,
6 0 0 0"
init_partial()
{
capout=$(mktemp)
local sec rndh
sec=$(date +%s)
rndh=$(printf %x $sec)-$(mktemp -u XXXXXX)
ns1="ns1-$rndh"
ns2="ns2-$rndh"
local netns
for netns in "$ns1" "$ns2"; do
ip netns add $netns || exit $ksft_skip
ip -net $netns link set lo up
ip netns exec $netns sysctl -q net.mptcp.enabled=1
ip netns exec $netns sysctl -q net.mptcp.pm_type=0
ip netns exec $netns sysctl -q net.ipv4.conf.all.rp_filter=0
ip netns exec $netns sysctl -q net.ipv4.conf.default.rp_filter=0
if [ $checksum -eq 1 ]; then
ip netns exec $netns sysctl -q net.mptcp.checksum_enabled=1
fi
done
stats_dumped=0
check_invert=0
validate_checksum=$checksum
FAILING_LINKS=""
# ns1 ns2
# ns1eth1 ns2eth1
# ns1eth2 ns2eth2
# ns1eth3 ns2eth3
# ns1eth4 ns2eth4
local i
for i in $(seq 1 4); do
ip link add ns1eth$i netns "$ns1" type veth peer name ns2eth$i netns "$ns2"
ip -net "$ns1" addr add 10.0.$i.1/24 dev ns1eth$i
ip -net "$ns1" addr add dead:beef:$i::1/64 dev ns1eth$i nodad
ip -net "$ns1" link set ns1eth$i up
ip -net "$ns2" addr add 10.0.$i.2/24 dev ns2eth$i
ip -net "$ns2" addr add dead:beef:$i::2/64 dev ns2eth$i nodad
ip -net "$ns2" link set ns2eth$i up
# let $ns2 reach any $ns1 address from any interface
ip -net "$ns2" route add default via 10.0.$i.1 dev ns2eth$i metric 10$i
ip -net "$ns2" route add default via dead:beef:$i::1 dev ns2eth$i metric 10$i
done
}
init_shapers()
{
local i
for i in $(seq 1 4); do
tc -n $ns1 qdisc add dev ns1eth$i root netem rate 20mbit delay 1
tc -n $ns2 qdisc add dev ns2eth$i root netem rate 20mbit delay 1
done
}
cleanup_partial()
{
rm -f "$capout"
local netns
for netns in "$ns1" "$ns2"; do
ip netns del $netns
rm -f /tmp/$netns.{nstat,out}
done
}
check_tools()
{
mptcp_lib_check_mptcp
if ! ip -Version &> /dev/null; then
echo "SKIP: Could not run test without ip tool"
exit $ksft_skip
fi
if ! iptables -V &> /dev/null; then
echo "SKIP: Could not run all tests without iptables tool"
exit $ksft_skip
fi
if ! ip6tables -V &> /dev/null; then
echo "SKIP: Could not run all tests without ip6tables tool"
exit $ksft_skip
fi
}
init() {
init=1
check_tools
sin=$(mktemp)
sout=$(mktemp)
cin=$(mktemp)
cinsent=$(mktemp)
cout=$(mktemp)
evts_ns1=$(mktemp)
evts_ns2=$(mktemp)
trap cleanup EXIT
make_file "$cin" "client" 1
make_file "$sin" "server" 1
}
cleanup()
{
rm -f "$cin" "$cout" "$sinfail"
rm -f "$sin" "$sout" "$cinsent" "$cinfail"
rm -f "$tmpfile"
rm -rf $evts_ns1 $evts_ns2
cleanup_partial
}
skip_test()
{
if [ "${#only_tests_ids[@]}" -eq 0 ] && [ "${#only_tests_names[@]}" -eq 0 ]; then
return 1
fi
local i
for i in "${only_tests_ids[@]}"; do
if [ "${TEST_COUNT}" -eq "${i}" ]; then
return 1
fi
done
for i in "${only_tests_names[@]}"; do
if [ "${TEST_NAME}" = "${i}" ]; then
return 1
fi
done
return 0
}
# $1: test name
reset()
{
TEST_NAME="${1}"
TEST_COUNT=$((TEST_COUNT+1))
if skip_test; then
return 1
fi
if [ "${init}" != "1" ]; then
init
else
cleanup_partial
fi
init_partial
return 0
}
# $1: test name
reset_with_cookies()
{
reset "${1}" || return 1
local netns
for netns in "$ns1" "$ns2"; do
ip netns exec $netns sysctl -q net.ipv4.tcp_syncookies=2
done
}
# $1: test name
reset_with_add_addr_timeout()
{
local ip="${2:-4}"
local tables
reset "${1}" || return 1
tables="iptables"
if [ $ip -eq 6 ]; then
tables="ip6tables"
fi
ip netns exec $ns1 sysctl -q net.mptcp.add_addr_timeout=1
ip netns exec $ns2 $tables -A OUTPUT -p tcp \
-m tcp --tcp-option 30 \
-m bpf --bytecode \
"$CBPF_MPTCP_SUBOPTION_ADD_ADDR" \
-j DROP
}
# $1: test name
reset_with_checksum()
{
local ns1_enable=$1
local ns2_enable=$2
reset "checksum test ${1} ${2}" || return 1
ip netns exec $ns1 sysctl -q net.mptcp.checksum_enabled=$ns1_enable
ip netns exec $ns2 sysctl -q net.mptcp.checksum_enabled=$ns2_enable
validate_checksum=1
}
reset_with_allow_join_id0()
{
local ns1_enable=$2
local ns2_enable=$3
reset "${1}" || return 1
ip netns exec $ns1 sysctl -q net.mptcp.allow_join_initial_addr_port=$ns1_enable
ip netns exec $ns2 sysctl -q net.mptcp.allow_join_initial_addr_port=$ns2_enable
}
# Modify TCP payload without corrupting the TCP packet
#
# This rule inverts a 8-bit word at byte offset 148 for the 2nd TCP ACK packets
# carrying enough data.
# Once it is done, the TCP Checksum field is updated so the packet is still
# considered as valid at the TCP level.
# Because the MPTCP checksum, covering the TCP options and data, has not been
# updated, the modification will be detected and an MP_FAIL will be emitted:
# what we want to validate here without corrupting "random" MPTCP options.
#
# To avoid having tc producing this pr_info() message for each TCP ACK packets
# not carrying enough data:
#
# tc action pedit offset 162 out of bounds
#
# Netfilter is used to mark packets with enough data.
reset_with_fail()
{
reset "${1}" || return 1
ip netns exec $ns1 sysctl -q net.mptcp.checksum_enabled=1
ip netns exec $ns2 sysctl -q net.mptcp.checksum_enabled=1
check_invert=1
validate_checksum=1
local i="$2"
local ip="${3:-4}"
local tables
tables="iptables"
if [ $ip -eq 6 ]; then
tables="ip6tables"
fi
ip netns exec $ns2 $tables \
-t mangle \
-A OUTPUT \
-o ns2eth$i \
-p tcp \
-m length --length 150:9999 \
-m statistic --mode nth --packet 1 --every 99999 \
-j MARK --set-mark 42 || exit 1
tc -n $ns2 qdisc add dev ns2eth$i clsact || exit 1
tc -n $ns2 filter add dev ns2eth$i egress \
protocol ip prio 1000 \
handle 42 fw \
action pedit munge offset 148 u8 invert \
pipe csum tcp \
index 100 || exit 1
}
reset_with_events()
{
reset "${1}" || return 1
:> "$evts_ns1"
:> "$evts_ns2"
ip netns exec $ns1 ./pm_nl_ctl events >> "$evts_ns1" 2>&1 &
evts_ns1_pid=$!
ip netns exec $ns2 ./pm_nl_ctl events >> "$evts_ns2" 2>&1 &
evts_ns2_pid=$!
}
fail_test()
{
ret=1
failed_tests[${TEST_COUNT}]="${TEST_NAME}"
[ "${stats_dumped}" = 0 ] && dump_stats
stats_dumped=1
}
get_failed_tests_ids()
{
# sorted
local i
for i in "${!failed_tests[@]}"; do
echo "${i}"
done | sort -n
}
print_file_err()
{
ls -l "$1" 1>&2
echo "Trailing bytes are: "
tail -c 27 "$1"
}
check_transfer()
{
local in=$1
local out=$2
local what=$3
local bytes=$4
local i a b
local line
if [ -n "$bytes" ]; then
local out_size
# when truncating we must check the size explicitly
out_size=$(wc -c $out | awk '{print $1}')
if [ $out_size -ne $bytes ]; then
echo "[ FAIL ] $what output file has wrong size ($out_size, $bytes)"
fail_test
return 1
fi
# note: BusyBox's "cmp" command doesn't support --bytes
tmpfile=$(mktemp)
head --bytes="$bytes" "$in" > "$tmpfile"
mv "$tmpfile" "$in"
head --bytes="$bytes" "$out" > "$tmpfile"
mv "$tmpfile" "$out"
tmpfile=""
fi
cmp -l "$in" "$out" | while read -r i a b; do
local sum=$((0${a} + 0${b}))
if [ $check_invert -eq 0 ] || [ $sum -ne $((0xff)) ]; then
echo "[ FAIL ] $what does not match (in, out):"
print_file_err "$in"
print_file_err "$out"
fail_test
return 1
else
echo "$what has inverted byte at ${i}"
fi
done
return 0
}
do_ping()
{
local listener_ns="$1"
local connector_ns="$2"
local connect_addr="$3"
if ! ip netns exec ${connector_ns} ping -q -c 1 $connect_addr >/dev/null; then
echo "$listener_ns -> $connect_addr connectivity [ FAIL ]" 1>&2
fail_test
fi
}
link_failure()
{
local ns="$1"
if [ -z "$FAILING_LINKS" ]; then
l=$((RANDOM%4))
FAILING_LINKS=$((l+1))
fi
local l
for l in $FAILING_LINKS; do
local veth="ns1eth$l"
ip -net "$ns" link set "$veth" down
done
}
# $1: IP address
is_v6()
{
[ -z "${1##*:*}" ]
}
# $1: ns, $2: port
wait_local_port_listen()
{
local listener_ns="${1}"
local port="${2}"
local port_hex
port_hex="$(printf "%04X" "${port}")"
local i
for i in $(seq 10); do
ip netns exec "${listener_ns}" cat /proc/net/tcp* | \
awk "BEGIN {rc=1} {if (\$2 ~ /:${port_hex}\$/ && \$4 ~ /0A/) {rc=0; exit}} END {exit rc}" &&
break
sleep 0.1
done
}
rm_addr_count()
{
local ns=${1}
ip netns exec ${ns} nstat -as | grep MPTcpExtRmAddr | awk '{print $2}'
}
# $1: ns, $2: old rm_addr counter in $ns
wait_rm_addr()
{
local ns="${1}"
local old_cnt="${2}"
local cnt
local i
for i in $(seq 10); do
cnt=$(rm_addr_count ${ns})
[ "$cnt" = "${old_cnt}" ] || break
sleep 0.1
done
}
wait_mpj()
{
local ns="${1}"
local cnt old_cnt
old_cnt=$(ip netns exec ${ns} nstat -as | grep MPJoinAckRx | awk '{print $2}')
local i
for i in $(seq 10); do
cnt=$(ip netns exec ${ns} nstat -as | grep MPJoinAckRx | awk '{print $2}')
[ "$cnt" = "${old_cnt}" ] || break
sleep 0.1
done
}
kill_wait()
{
kill $1 > /dev/null 2>&1
wait $1 2>/dev/null
}
kill_events_pids()
{
kill_wait $evts_ns1_pid
kill_wait $evts_ns2_pid
}
kill_tests_wait()
{
#shellcheck disable=SC2046
kill -SIGUSR1 $(ip netns pids $ns2) $(ip netns pids $ns1)
wait
}
pm_nl_set_limits()
{
local ns=$1
local addrs=$2
local subflows=$3
if [ $ip_mptcp -eq 1 ]; then
ip -n $ns mptcp limits set add_addr_accepted $addrs subflows $subflows
else
ip netns exec $ns ./pm_nl_ctl limits $addrs $subflows
fi
}
pm_nl_add_endpoint()
{
local ns=$1
local addr=$2
local flags _flags
local port _port
local dev _dev
local id _id
local nr=2
local p
for p in "${@}"
do
if [ $p = "flags" ]; then
eval _flags=\$"$nr"
[ -n "$_flags" ]; flags="flags $_flags"
fi
if [ $p = "dev" ]; then
eval _dev=\$"$nr"
[ -n "$_dev" ]; dev="dev $_dev"
fi
if [ $p = "id" ]; then
eval _id=\$"$nr"
[ -n "$_id" ]; id="id $_id"
fi
if [ $p = "port" ]; then
eval _port=\$"$nr"
[ -n "$_port" ]; port="port $_port"
fi
nr=$((nr + 1))
done
if [ $ip_mptcp -eq 1 ]; then
ip -n $ns mptcp endpoint add $addr ${_flags//","/" "} $dev $id $port
else
ip netns exec $ns ./pm_nl_ctl add $addr $flags $dev $id $port
fi
}
pm_nl_del_endpoint()
{
local ns=$1
local id=$2
local addr=$3
if [ $ip_mptcp -eq 1 ]; then
ip -n $ns mptcp endpoint delete id $id $addr
else
ip netns exec $ns ./pm_nl_ctl del $id $addr
fi
}
pm_nl_flush_endpoint()
{
local ns=$1
if [ $ip_mptcp -eq 1 ]; then
ip -n $ns mptcp endpoint flush
else
ip netns exec $ns ./pm_nl_ctl flush
fi
}
pm_nl_show_endpoints()
{
local ns=$1
if [ $ip_mptcp -eq 1 ]; then
ip -n $ns mptcp endpoint show
else
ip netns exec $ns ./pm_nl_ctl dump
fi
}
pm_nl_change_endpoint()
{
local ns=$1
local id=$2
local flags=$3
if [ $ip_mptcp -eq 1 ]; then
ip -n $ns mptcp endpoint change id $id ${flags//","/" "}
else
ip netns exec $ns ./pm_nl_ctl set id $id flags $flags
fi
}
pm_nl_check_endpoint()
{
local line expected_line
local need_title=$1
local msg="$2"
local ns=$3
local addr=$4
local _flags=""
local flags
local _port
local port
local dev
local _id
local id
if [ "${need_title}" = 1 ]; then
printf "%03u %-36s %s" "${TEST_COUNT}" "${TEST_NAME}" "${msg}"
else
printf "%-${nr_blank}s %s" " " "${msg}"
fi
shift 4
while [ -n "$1" ]; do
if [ $1 = "flags" ]; then
_flags=$2
[ -n "$_flags" ]; flags="flags $_flags"
shift
elif [ $1 = "dev" ]; then
[ -n "$2" ]; dev="dev $1"
shift
elif [ $1 = "id" ]; then
_id=$2
[ -n "$_id" ]; id="id $_id"
shift
elif [ $1 = "port" ]; then
_port=$2
[ -n "$_port" ]; port=" port $_port"
shift
fi
shift
done
if [ -z "$id" ]; then
echo "[skip] bad test - missing endpoint id"
return
fi
if [ $ip_mptcp -eq 1 ]; then
line=$(ip -n $ns mptcp endpoint show $id)
# the dump order is: address id flags port dev
expected_line="$addr"
[ -n "$addr" ] && expected_line="$expected_line $addr"
expected_line="$expected_line $id"
[ -n "$_flags" ] && expected_line="$expected_line ${_flags//","/" "}"
[ -n "$dev" ] && expected_line="$expected_line $dev"
[ -n "$port" ] && expected_line="$expected_line $port"
else
line=$(ip netns exec $ns ./pm_nl_ctl get $_id)
# the dump order is: id flags dev address port
expected_line="$id"
[ -n "$flags" ] && expected_line="$expected_line $flags"
[ -n "$dev" ] && expected_line="$expected_line $dev"
[ -n "$addr" ] && expected_line="$expected_line $addr"
[ -n "$_port" ] && expected_line="$expected_line $_port"
fi
if [ "$line" = "$expected_line" ]; then
echo "[ ok ]"
else
echo "[fail] expected '$expected_line' found '$line'"
fail_test
fi
}
filter_tcp_from()
{
local ns="${1}"
local src="${2}"
local target="${3}"
ip netns exec "${ns}" iptables -A INPUT -s "${src}" -p tcp -j "${target}"
}
do_transfer()
{
local listener_ns="$1"
local connector_ns="$2"
local cl_proto="$3"
local srv_proto="$4"
local connect_addr="$5"
local test_link_fail="$6"
local addr_nr_ns1="$7"
local addr_nr_ns2="$8"
local speed="$9"
local sflags="${10}"
local port=$((10000 + TEST_COUNT - 1))
local cappid
local userspace_pm=0
:> "$cout"
:> "$sout"
:> "$capout"
if [ $capture -eq 1 ]; then
local capuser
if [ -z $SUDO_USER ] ; then
capuser=""
else
capuser="-Z $SUDO_USER"
fi
capfile=$(printf "mp_join-%02u-%s.pcap" "$TEST_COUNT" "${listener_ns}")
echo "Capturing traffic for test $TEST_COUNT into $capfile"
ip netns exec ${listener_ns} tcpdump -i any -s 65535 -B 32768 $capuser -w $capfile > "$capout" 2>&1 &
cappid=$!
sleep 1
fi
NSTAT_HISTORY=/tmp/${listener_ns}.nstat ip netns exec ${listener_ns} \
nstat -n
NSTAT_HISTORY=/tmp/${connector_ns}.nstat ip netns exec ${connector_ns} \
nstat -n
local extra_args
if [ $speed = "fast" ]; then
extra_args="-j"
elif [ $speed = "slow" ]; then
extra_args="-r 50"
elif [[ $speed = "speed_"* ]]; then
extra_args="-r ${speed:6}"
fi
if [[ "${addr_nr_ns1}" = "userspace_"* ]]; then
userspace_pm=1
addr_nr_ns1=${addr_nr_ns1:10}
fi
local flags="subflow"
local extra_cl_args=""
local extra_srv_args=""
local trunc_size=""
if [[ "${addr_nr_ns2}" = "fastclose_"* ]]; then
if [ ${test_link_fail} -le 1 ]; then
echo "fastclose tests need test_link_fail argument"
fail_test
return 1
fi
# disconnect
trunc_size=${test_link_fail}
local side=${addr_nr_ns2:10}
if [ ${side} = "client" ]; then
extra_cl_args="-f ${test_link_fail}"
extra_srv_args="-f -1"
elif [ ${side} = "server" ]; then
extra_srv_args="-f ${test_link_fail}"
extra_cl_args="-f -1"
else
echo "wrong/unknown fastclose spec ${side}"
fail_test
return 1
fi
addr_nr_ns2=0
elif [[ "${addr_nr_ns2}" = "userspace_"* ]]; then
userspace_pm=1
addr_nr_ns2=${addr_nr_ns2:10}
elif [[ "${addr_nr_ns2}" = "fullmesh_"* ]]; then
flags="${flags},fullmesh"
addr_nr_ns2=${addr_nr_ns2:9}
fi
extra_srv_args="$extra_args $extra_srv_args"
if [ "$test_link_fail" -gt 1 ];then
timeout ${timeout_test} \
ip netns exec ${listener_ns} \
./mptcp_connect -t ${timeout_poll} -l -p $port -s ${srv_proto} \
$extra_srv_args "::" < "$sinfail" > "$sout" &
else
timeout ${timeout_test} \
ip netns exec ${listener_ns} \
./mptcp_connect -t ${timeout_poll} -l -p $port -s ${srv_proto} \
$extra_srv_args "::" < "$sin" > "$sout" &
fi
local spid=$!
wait_local_port_listen "${listener_ns}" "${port}"
extra_cl_args="$extra_args $extra_cl_args"
if [ "$test_link_fail" -eq 0 ];then
timeout ${timeout_test} \
ip netns exec ${connector_ns} \
./mptcp_connect -t ${timeout_poll} -p $port -s ${cl_proto} \
$extra_cl_args $connect_addr < "$cin" > "$cout" &
elif [ "$test_link_fail" -eq 1 ] || [ "$test_link_fail" -eq 2 ];then
( cat "$cinfail" ; sleep 2; link_failure $listener_ns ; cat "$cinfail" ) | \
tee "$cinsent" | \
timeout ${timeout_test} \
ip netns exec ${connector_ns} \
./mptcp_connect -t ${timeout_poll} -p $port -s ${cl_proto} \
$extra_cl_args $connect_addr > "$cout" &
else
tee "$cinsent" < "$cinfail" | \
timeout ${timeout_test} \
ip netns exec ${connector_ns} \
./mptcp_connect -t ${timeout_poll} -p $port -s ${cl_proto} \
$extra_cl_args $connect_addr > "$cout" &
fi
local cpid=$!
# let the mptcp subflow be established in background before
# do endpoint manipulation
if [ $addr_nr_ns1 != "0" ] || [ $addr_nr_ns2 != "0" ]; then
sleep 1
fi
if [ $addr_nr_ns1 -gt 0 ]; then
local counter=2
local add_nr_ns1=${addr_nr_ns1}
local id=10
local tk
while [ $add_nr_ns1 -gt 0 ]; do
local addr
if is_v6 "${connect_addr}"; then
addr="dead:beef:$counter::1"
else
addr="10.0.$counter.1"
fi
if [ $userspace_pm -eq 0 ]; then
pm_nl_add_endpoint $ns1 $addr flags signal
else
tk=$(grep "type:1," "$evts_ns1" |
sed -n 's/.*\(token:\)\([[:digit:]]*\).*$/\2/p;q')
ip netns exec ${listener_ns} ./pm_nl_ctl ann $addr token $tk id $id
sleep 1
sp=$(grep "type:10" "$evts_ns1" |
sed -n 's/.*\(sport:\)\([[:digit:]]*\).*$/\2/p;q')
da=$(grep "type:10" "$evts_ns1" |
sed -n 's/.*\(daddr6:\)\([0-9a-f:.]*\).*$/\2/p;q')
dp=$(grep "type:10" "$evts_ns1" |
sed -n 's/.*\(dport:\)\([[:digit:]]*\).*$/\2/p;q')
ip netns exec ${listener_ns} ./pm_nl_ctl rem token $tk id $id
ip netns exec ${listener_ns} ./pm_nl_ctl dsf lip "::ffff:$addr" \
lport $sp rip $da rport $dp token $tk
fi
counter=$((counter + 1))
add_nr_ns1=$((add_nr_ns1 - 1))
id=$((id + 1))
done
elif [ $addr_nr_ns1 -lt 0 ]; then
local rm_nr_ns1=$((-addr_nr_ns1))
if [ $rm_nr_ns1 -lt 8 ]; then
local counter=0
local line
pm_nl_show_endpoints ${listener_ns} | while read -r line; do
# shellcheck disable=SC2206 # we do want to split per word
local arr=($line)
local nr=0
local i
for i in "${arr[@]}"; do
if [ $i = "id" ]; then
if [ $counter -eq $rm_nr_ns1 ]; then
break
fi
id=${arr[$nr+1]}
rm_addr=$(rm_addr_count ${connector_ns})
pm_nl_del_endpoint ${listener_ns} $id
wait_rm_addr ${connector_ns} ${rm_addr}
counter=$((counter + 1))
fi
nr=$((nr + 1))
done
done
elif [ $rm_nr_ns1 -eq 8 ]; then
pm_nl_flush_endpoint ${listener_ns}
elif [ $rm_nr_ns1 -eq 9 ]; then
pm_nl_del_endpoint ${listener_ns} 0 ${connect_addr}
fi
fi
# if newly added endpoints must be deleted, give the background msk
# some time to created them
[ $addr_nr_ns1 -gt 0 ] && [ $addr_nr_ns2 -lt 0 ] && sleep 1
if [ $addr_nr_ns2 -gt 0 ]; then
local add_nr_ns2=${addr_nr_ns2}
local counter=3
local id=20
local tk da dp sp
while [ $add_nr_ns2 -gt 0 ]; do
local addr
if is_v6 "${connect_addr}"; then
addr="dead:beef:$counter::2"
else
addr="10.0.$counter.2"
fi
if [ $userspace_pm -eq 0 ]; then
pm_nl_add_endpoint $ns2 $addr flags $flags
else
tk=$(sed -n 's/.*\(token:\)\([[:digit:]]*\).*$/\2/p;q' "$evts_ns2")
da=$(sed -n 's/.*\(daddr4:\)\([0-9.]*\).*$/\2/p;q' "$evts_ns2")
dp=$(sed -n 's/.*\(dport:\)\([[:digit:]]*\).*$/\2/p;q' "$evts_ns2")
ip netns exec ${connector_ns} ./pm_nl_ctl csf lip $addr lid $id \
rip $da rport $dp token $tk
sleep 1
sp=$(grep "type:10" "$evts_ns2" |
sed -n 's/.*\(sport:\)\([[:digit:]]*\).*$/\2/p;q')
ip netns exec ${connector_ns} ./pm_nl_ctl rem token $tk id $id
ip netns exec ${connector_ns} ./pm_nl_ctl dsf lip $addr lport $sp \
rip $da rport $dp token $tk
fi
counter=$((counter + 1))
add_nr_ns2=$((add_nr_ns2 - 1))
id=$((id + 1))
done
elif [ $addr_nr_ns2 -lt 0 ]; then
local rm_nr_ns2=$((-addr_nr_ns2))
if [ $rm_nr_ns2 -lt 8 ]; then
local counter=0
local line
pm_nl_show_endpoints ${connector_ns} | while read -r line; do
# shellcheck disable=SC2206 # we do want to split per word
local arr=($line)
local nr=0
local i
for i in "${arr[@]}"; do
if [ $i = "id" ]; then
if [ $counter -eq $rm_nr_ns2 ]; then
break
fi
local id rm_addr
# rm_addr are serialized, allow the previous one to
# complete
id=${arr[$nr+1]}
rm_addr=$(rm_addr_count ${listener_ns})
pm_nl_del_endpoint ${connector_ns} $id
wait_rm_addr ${listener_ns} ${rm_addr}
counter=$((counter + 1))
fi
nr=$((nr + 1))
done
done
elif [ $rm_nr_ns2 -eq 8 ]; then
pm_nl_flush_endpoint ${connector_ns}
elif [ $rm_nr_ns2 -eq 9 ]; then
local addr
if is_v6 "${connect_addr}"; then
addr="dead:beef:1::2"
else
addr="10.0.1.2"
fi
pm_nl_del_endpoint ${connector_ns} 0 $addr
fi
fi
if [ -n "${sflags}" ]; then
sleep 1
local netns
for netns in "$ns1" "$ns2"; do
local line
pm_nl_show_endpoints $netns | while read -r line; do
# shellcheck disable=SC2206 # we do want to split per word