1#!/bin/bash
2# SPDX-License-Identifier: GPL-2.0
3
4ret=0
5sin=""
6sout=""
7cin=""
8cinsent=""
9cout=""
10ksft_skip=4
11timeout=30
12mptcp_connect=""
13capture=0
14
15TEST_COUNT=0
16
17# generated using "nfbpf_compile '(ip && (ip[54] & 0xf0) == 0x30) ||
18#				  (ip6 && (ip6[74] & 0xf0) == 0x30)'"
19CBPF_MPTCP_SUBOPTION_ADD_ADDR="14,
20			       48 0 0 0,
21			       84 0 0 240,
22			       21 0 3 64,
23			       48 0 0 54,
24			       84 0 0 240,
25			       21 6 7 48,
26			       48 0 0 0,
27			       84 0 0 240,
28			       21 0 4 96,
29			       48 0 0 74,
30			       84 0 0 240,
31			       21 0 1 48,
32			       6 0 0 65535,
33			       6 0 0 0"
34
35init()
36{
37	capout=$(mktemp)
38
39	rndh=$(printf %x $sec)-$(mktemp -u XXXXXX)
40
41	ns1="ns1-$rndh"
42	ns2="ns2-$rndh"
43
44	for netns in "$ns1" "$ns2";do
45		ip netns add $netns || exit $ksft_skip
46		ip -net $netns link set lo up
47		ip netns exec $netns sysctl -q net.mptcp.enabled=1
48		ip netns exec $netns sysctl -q net.ipv4.conf.all.rp_filter=0
49		ip netns exec $netns sysctl -q net.ipv4.conf.default.rp_filter=0
50	done
51
52	#  ns1              ns2
53	# ns1eth1    ns2eth1
54	# ns1eth2    ns2eth2
55	# ns1eth3    ns2eth3
56	# ns1eth4    ns2eth4
57
58	for i in `seq 1 4`; do
59		ip link add ns1eth$i netns "$ns1" type veth peer name ns2eth$i netns "$ns2"
60		ip -net "$ns1" addr add 10.0.$i.1/24 dev ns1eth$i
61		ip -net "$ns1" addr add dead:beef:$i::1/64 dev ns1eth$i nodad
62		ip -net "$ns1" link set ns1eth$i up
63
64		ip -net "$ns2" addr add 10.0.$i.2/24 dev ns2eth$i
65		ip -net "$ns2" addr add dead:beef:$i::2/64 dev ns2eth$i nodad
66		ip -net "$ns2" link set ns2eth$i up
67
68		# let $ns2 reach any $ns1 address from any interface
69		ip -net "$ns2" route add default via 10.0.$i.1 dev ns2eth$i metric 10$i
70	done
71}
72
73cleanup_partial()
74{
75	rm -f "$capout"
76
77	for netns in "$ns1" "$ns2"; do
78		ip netns del $netns
79	done
80}
81
82cleanup()
83{
84	rm -f "$cin" "$cout"
85	rm -f "$sin" "$sout" "$cinsent"
86	cleanup_partial
87}
88
89reset()
90{
91	cleanup_partial
92	init
93}
94
95reset_with_cookies()
96{
97	reset
98
99	for netns in "$ns1" "$ns2";do
100		ip netns exec $netns sysctl -q net.ipv4.tcp_syncookies=2
101	done
102}
103
104reset_with_add_addr_timeout()
105{
106	local ip="${1:-4}"
107	local tables
108
109	tables="iptables"
110	if [ $ip -eq 6 ]; then
111		tables="ip6tables"
112	fi
113
114	reset
115
116	ip netns exec $ns1 sysctl -q net.mptcp.add_addr_timeout=1
117	ip netns exec $ns2 $tables -A OUTPUT -p tcp \
118		-m tcp --tcp-option 30 \
119		-m bpf --bytecode \
120		"$CBPF_MPTCP_SUBOPTION_ADD_ADDR" \
121		-j DROP
122}
123
124for arg in "$@"; do
125	if [ "$arg" = "-c" ]; then
126		capture=1
127	fi
128done
129
130ip -Version > /dev/null 2>&1
131if [ $? -ne 0 ];then
132	echo "SKIP: Could not run test without ip tool"
133	exit $ksft_skip
134fi
135
136iptables -V > /dev/null 2>&1
137if [ $? -ne 0 ];then
138	echo "SKIP: Could not run all tests without iptables tool"
139	exit $ksft_skip
140fi
141
142ip6tables -V > /dev/null 2>&1
143if [ $? -ne 0 ];then
144	echo "SKIP: Could not run all tests without ip6tables tool"
145	exit $ksft_skip
146fi
147
148print_file_err()
149{
150	ls -l "$1" 1>&2
151	echo "Trailing bytes are: "
152	tail -c 27 "$1"
153}
154
155check_transfer()
156{
157	in=$1
158	out=$2
159	what=$3
160
161	cmp "$in" "$out" > /dev/null 2>&1
162	if [ $? -ne 0 ] ;then
163		echo "[ FAIL ] $what does not match (in, out):"
164		print_file_err "$in"
165		print_file_err "$out"
166		ret=1
167
168		return 1
169	fi
170
171	return 0
172}
173
174do_ping()
175{
176	listener_ns="$1"
177	connector_ns="$2"
178	connect_addr="$3"
179
180	ip netns exec ${connector_ns} ping -q -c 1 $connect_addr >/dev/null
181	if [ $? -ne 0 ] ; then
182		echo "$listener_ns -> $connect_addr connectivity [ FAIL ]" 1>&2
183		ret=1
184	fi
185}
186
187link_failure()
188{
189	ns="$1"
190
191	l=$((RANDOM%4))
192	l=$((l+1))
193
194	veth="ns1eth$l"
195	ip -net "$ns" link set "$veth" down
196}
197
198# $1: IP address
199is_v6()
200{
201	[ -z "${1##*:*}" ]
202}
203
204do_transfer()
205{
206	listener_ns="$1"
207	connector_ns="$2"
208	cl_proto="$3"
209	srv_proto="$4"
210	connect_addr="$5"
211	test_link_fail="$6"
212	rm_nr_ns1="$7"
213	rm_nr_ns2="$8"
214	speed="$9"
215
216	port=$((10000+$TEST_COUNT))
217	TEST_COUNT=$((TEST_COUNT+1))
218
219	:> "$cout"
220	:> "$sout"
221	:> "$capout"
222
223	if [ $capture -eq 1 ]; then
224		if [ -z $SUDO_USER ] ; then
225			capuser=""
226		else
227			capuser="-Z $SUDO_USER"
228		fi
229
230		capfile=$(printf "mp_join-%02u-%s.pcap" "$TEST_COUNT" "${listener_ns}")
231
232		echo "Capturing traffic for test $TEST_COUNT into $capfile"
233		ip netns exec ${listener_ns} tcpdump -i any -s 65535 -B 32768 $capuser -w $capfile > "$capout" 2>&1 &
234		cappid=$!
235
236		sleep 1
237	fi
238
239	if [ $speed = "fast" ]; then
240		mptcp_connect="./mptcp_connect -j"
241	else
242		mptcp_connect="./mptcp_connect -r"
243	fi
244
245	local local_addr
246	if is_v6 "${connect_addr}"; then
247		local_addr="::"
248	else
249		local_addr="0.0.0.0"
250	fi
251
252	ip netns exec ${listener_ns} $mptcp_connect -t $timeout -l -p $port \
253		-s ${srv_proto} ${local_addr} < "$sin" > "$sout" &
254	spid=$!
255
256	sleep 1
257
258	if [ "$test_link_fail" -eq 0 ];then
259		ip netns exec ${connector_ns} $mptcp_connect -t $timeout -p $port -s ${cl_proto} $connect_addr < "$cin" > "$cout" &
260	else
261		( cat "$cin" ; sleep 2; link_failure $listener_ns ; cat "$cin" ) | tee "$cinsent" | \
262		ip netns exec ${connector_ns} $mptcp_connect -t $timeout -p $port -s ${cl_proto} $connect_addr > "$cout" &
263	fi
264	cpid=$!
265
266	if [ $rm_nr_ns1 -gt 0 ]; then
267		if [ $rm_nr_ns1 -lt 8 ]; then
268			counter=1
269			sleep 1
270
271			while [ $counter -le $rm_nr_ns1 ]
272			do
273				ip netns exec ${listener_ns} ./pm_nl_ctl del $counter
274				sleep 1
275				let counter+=1
276			done
277		else
278			sleep 1
279			ip netns exec ${listener_ns} ./pm_nl_ctl flush
280		fi
281	fi
282
283	if [ $rm_nr_ns2 -gt 0 ]; then
284		if [ $rm_nr_ns2 -lt 8 ]; then
285			counter=1
286			sleep 1
287
288			while [ $counter -le $rm_nr_ns2 ]
289			do
290				ip netns exec ${connector_ns} ./pm_nl_ctl del $counter
291				sleep 1
292				let counter+=1
293			done
294		else
295			sleep 1
296			ip netns exec ${connector_ns} ./pm_nl_ctl flush
297		fi
298	fi
299
300	wait $cpid
301	retc=$?
302	wait $spid
303	rets=$?
304
305	if [ $capture -eq 1 ]; then
306	    sleep 1
307	    kill $cappid
308	fi
309
310	if [ ${rets} -ne 0 ] || [ ${retc} -ne 0 ]; then
311		echo " client exit code $retc, server $rets" 1>&2
312		echo -e "\nnetns ${listener_ns} socket stat for ${port}:" 1>&2
313		ip netns exec ${listener_ns} ss -nita 1>&2 -o "sport = :$port"
314		echo -e "\nnetns ${connector_ns} socket stat for ${port}:" 1>&2
315		ip netns exec ${connector_ns} ss -nita 1>&2 -o "dport = :$port"
316
317		cat "$capout"
318		ret=1
319		return 1
320	fi
321
322	check_transfer $sin $cout "file received by client"
323	retc=$?
324	if [ "$test_link_fail" -eq 0 ];then
325		check_transfer $cin $sout "file received by server"
326	else
327		check_transfer $cinsent $sout "file received by server"
328	fi
329	rets=$?
330
331	if [ $retc -eq 0 ] && [ $rets -eq 0 ];then
332		cat "$capout"
333		return 0
334	fi
335
336	cat "$capout"
337	return 1
338}
339
340make_file()
341{
342	name=$1
343	who=$2
344	size=$3
345
346	dd if=/dev/urandom of="$name" bs=1024 count=$size 2> /dev/null
347	echo -e "\nMPTCP_TEST_FILE_END_MARKER" >> "$name"
348
349	echo "Created $name (size $size KB) containing data sent by $who"
350}
351
352run_tests()
353{
354	listener_ns="$1"
355	connector_ns="$2"
356	connect_addr="$3"
357	test_linkfail="${4:-0}"
358	rm_nr_ns1="${5:-0}"
359	rm_nr_ns2="${6:-0}"
360	speed="${7:-fast}"
361	lret=0
362	oldin=""
363
364	if [ "$test_linkfail" -eq 1 ];then
365		size=$((RANDOM%1024))
366		size=$((size+1))
367		size=$((size*128))
368
369		oldin=$(mktemp)
370		cp "$cin" "$oldin"
371		make_file "$cin" "client" $size
372	fi
373
374	do_transfer ${listener_ns} ${connector_ns} MPTCP MPTCP ${connect_addr} \
375		${test_linkfail} ${rm_nr_ns1} ${rm_nr_ns2} ${speed}
376	lret=$?
377
378	if [ "$test_linkfail" -eq 1 ];then
379		cp "$oldin" "$cin"
380		rm -f "$oldin"
381	fi
382
383	if [ $lret -ne 0 ]; then
384		ret=$lret
385		return
386	fi
387}
388
389chk_join_nr()
390{
391	local msg="$1"
392	local syn_nr=$2
393	local syn_ack_nr=$3
394	local ack_nr=$4
395	local count
396	local dump_stats
397
398	printf "%02u %-36s %s" "$TEST_COUNT" "$msg" "syn"
399	count=`ip netns exec $ns1 nstat -as | grep MPTcpExtMPJoinSynRx | awk '{print $2}'`
400	[ -z "$count" ] && count=0
401	if [ "$count" != "$syn_nr" ]; then
402		echo "[fail] got $count JOIN[s] syn expected $syn_nr"
403		ret=1
404		dump_stats=1
405	else
406		echo -n "[ ok ]"
407	fi
408
409	echo -n " - synack"
410	count=`ip netns exec $ns2 nstat -as | grep MPTcpExtMPJoinSynAckRx | awk '{print $2}'`
411	[ -z "$count" ] && count=0
412	if [ "$count" != "$syn_ack_nr" ]; then
413		echo "[fail] got $count JOIN[s] synack expected $syn_ack_nr"
414		ret=1
415		dump_stats=1
416	else
417		echo -n "[ ok ]"
418	fi
419
420	echo -n " - ack"
421	count=`ip netns exec $ns1 nstat -as | grep MPTcpExtMPJoinAckRx | awk '{print $2}'`
422	[ -z "$count" ] && count=0
423	if [ "$count" != "$ack_nr" ]; then
424		echo "[fail] got $count JOIN[s] ack expected $ack_nr"
425		ret=1
426		dump_stats=1
427	else
428		echo "[ ok ]"
429	fi
430	if [ "${dump_stats}" = 1 ]; then
431		echo Server ns stats
432		ip netns exec $ns1 nstat -as | grep MPTcp
433		echo Client ns stats
434		ip netns exec $ns2 nstat -as | grep MPTcp
435	fi
436}
437
438chk_add_nr()
439{
440	local add_nr=$1
441	local echo_nr=$2
442	local count
443	local dump_stats
444
445	printf "%-39s %s" " " "add"
446	count=`ip netns exec $ns2 nstat -as | grep MPTcpExtAddAddr | awk '{print $2}'`
447	[ -z "$count" ] && count=0
448	if [ "$count" != "$add_nr" ]; then
449		echo "[fail] got $count ADD_ADDR[s] expected $add_nr"
450		ret=1
451		dump_stats=1
452	else
453		echo -n "[ ok ]"
454	fi
455
456	echo -n " - echo  "
457	count=`ip netns exec $ns1 nstat -as | grep MPTcpExtEchoAdd | awk '{print $2}'`
458	[ -z "$count" ] && count=0
459	if [ "$count" != "$echo_nr" ]; then
460		echo "[fail] got $count ADD_ADDR echo[s] expected $echo_nr"
461		ret=1
462		dump_stats=1
463	else
464		echo "[ ok ]"
465	fi
466
467	if [ "${dump_stats}" = 1 ]; then
468		echo Server ns stats
469		ip netns exec $ns1 nstat -as | grep MPTcp
470		echo Client ns stats
471		ip netns exec $ns2 nstat -as | grep MPTcp
472	fi
473}
474
475chk_rm_nr()
476{
477	local rm_addr_nr=$1
478	local rm_subflow_nr=$2
479	local count
480	local dump_stats
481
482	printf "%-39s %s" " " "rm "
483	count=`ip netns exec $ns1 nstat -as | grep MPTcpExtRmAddr | awk '{print $2}'`
484	[ -z "$count" ] && count=0
485	if [ "$count" != "$rm_addr_nr" ]; then
486		echo "[fail] got $count RM_ADDR[s] expected $rm_addr_nr"
487		ret=1
488		dump_stats=1
489	else
490		echo -n "[ ok ]"
491	fi
492
493	echo -n " - sf    "
494	count=`ip netns exec $ns2 nstat -as | grep MPTcpExtRmSubflow | awk '{print $2}'`
495	[ -z "$count" ] && count=0
496	if [ "$count" != "$rm_subflow_nr" ]; then
497		echo "[fail] got $count RM_SUBFLOW[s] expected $rm_subflow_nr"
498		ret=1
499		dump_stats=1
500	else
501		echo "[ ok ]"
502	fi
503
504	if [ "${dump_stats}" = 1 ]; then
505		echo Server ns stats
506		ip netns exec $ns1 nstat -as | grep MPTcp
507		echo Client ns stats
508		ip netns exec $ns2 nstat -as | grep MPTcp
509	fi
510}
511
512sin=$(mktemp)
513sout=$(mktemp)
514cin=$(mktemp)
515cinsent=$(mktemp)
516cout=$(mktemp)
517init
518make_file "$cin" "client" 1
519make_file "$sin" "server" 1
520trap cleanup EXIT
521
522run_tests $ns1 $ns2 10.0.1.1
523chk_join_nr "no JOIN" "0" "0" "0"
524
525# subflow limted by client
526reset
527ip netns exec $ns2 ./pm_nl_ctl add 10.0.3.2 flags subflow
528run_tests $ns1 $ns2 10.0.1.1
529chk_join_nr "single subflow, limited by client" 0 0 0
530
531# subflow limted by server
532reset
533ip netns exec $ns2 ./pm_nl_ctl limits 0 1
534ip netns exec $ns2 ./pm_nl_ctl add 10.0.3.2 flags subflow
535run_tests $ns1 $ns2 10.0.1.1
536chk_join_nr "single subflow, limited by server" 1 1 0
537
538# subflow
539reset
540ip netns exec $ns1 ./pm_nl_ctl limits 0 1
541ip netns exec $ns2 ./pm_nl_ctl limits 0 1
542ip netns exec $ns2 ./pm_nl_ctl add 10.0.3.2 flags subflow
543run_tests $ns1 $ns2 10.0.1.1
544chk_join_nr "single subflow" 1 1 1
545
546# multiple subflows
547reset
548ip netns exec $ns1 ./pm_nl_ctl limits 0 2
549ip netns exec $ns2 ./pm_nl_ctl limits 0 2
550ip netns exec $ns2 ./pm_nl_ctl add 10.0.3.2 flags subflow
551ip netns exec $ns2 ./pm_nl_ctl add 10.0.2.2 flags subflow
552run_tests $ns1 $ns2 10.0.1.1
553chk_join_nr "multiple subflows" 2 2 2
554
555# multiple subflows limited by serverf
556reset
557ip netns exec $ns1 ./pm_nl_ctl limits 0 1
558ip netns exec $ns2 ./pm_nl_ctl limits 0 2
559ip netns exec $ns2 ./pm_nl_ctl add 10.0.3.2 flags subflow
560ip netns exec $ns2 ./pm_nl_ctl add 10.0.2.2 flags subflow
561run_tests $ns1 $ns2 10.0.1.1
562chk_join_nr "multiple subflows, limited by server" 2 2 1
563
564# add_address, unused
565reset
566ip netns exec $ns1 ./pm_nl_ctl add 10.0.2.1 flags signal
567run_tests $ns1 $ns2 10.0.1.1
568chk_join_nr "unused signal address" 0 0 0
569chk_add_nr 1 1
570
571# accept and use add_addr
572reset
573ip netns exec $ns1 ./pm_nl_ctl limits 0 1
574ip netns exec $ns2 ./pm_nl_ctl limits 1 1
575ip netns exec $ns1 ./pm_nl_ctl add 10.0.2.1 flags signal
576run_tests $ns1 $ns2 10.0.1.1
577chk_join_nr "signal address" 1 1 1
578chk_add_nr 1 1
579
580# accept and use add_addr with an additional subflow
581# note: signal address in server ns and local addresses in client ns must
582# belong to different subnets or one of the listed local address could be
583# used for 'add_addr' subflow
584reset
585ip netns exec $ns1 ./pm_nl_ctl add 10.0.2.1 flags signal
586ip netns exec $ns1 ./pm_nl_ctl limits 0 2
587ip netns exec $ns2 ./pm_nl_ctl limits 1 2
588ip netns exec $ns2 ./pm_nl_ctl add 10.0.3.2 flags subflow
589run_tests $ns1 $ns2 10.0.1.1
590chk_join_nr "subflow and signal" 2 2 2
591chk_add_nr 1 1
592
593# accept and use add_addr with additional subflows
594reset
595ip netns exec $ns1 ./pm_nl_ctl limits 0 3
596ip netns exec $ns1 ./pm_nl_ctl add 10.0.2.1 flags signal
597ip netns exec $ns2 ./pm_nl_ctl limits 1 3
598ip netns exec $ns2 ./pm_nl_ctl add 10.0.3.2 flags subflow
599ip netns exec $ns2 ./pm_nl_ctl add 10.0.4.2 flags subflow
600run_tests $ns1 $ns2 10.0.1.1
601chk_join_nr "multiple subflows and signal" 3 3 3
602chk_add_nr 1 1
603
604# accept and use add_addr with additional subflows and link loss
605reset
606ip netns exec $ns1 ./pm_nl_ctl limits 0 3
607ip netns exec $ns1 ./pm_nl_ctl add 10.0.2.1 flags signal
608ip netns exec $ns2 ./pm_nl_ctl limits 1 3
609ip netns exec $ns2 ./pm_nl_ctl add 10.0.3.2 flags subflow
610ip netns exec $ns2 ./pm_nl_ctl add 10.0.4.2 flags subflow
611run_tests $ns1 $ns2 10.0.1.1 1
612chk_join_nr "multiple flows, signal, link failure" 3 3 3
613chk_add_nr 1 1
614
615# add_addr timeout
616reset_with_add_addr_timeout
617ip netns exec $ns1 ./pm_nl_ctl limits 0 1
618ip netns exec $ns2 ./pm_nl_ctl limits 1 1
619ip netns exec $ns1 ./pm_nl_ctl add 10.0.2.1 flags signal
620run_tests $ns1 $ns2 10.0.1.1 0 0 0 slow
621chk_join_nr "signal address, ADD_ADDR timeout" 1 1 1
622chk_add_nr 4 0
623
624# single subflow, remove
625reset
626ip netns exec $ns1 ./pm_nl_ctl limits 0 1
627ip netns exec $ns2 ./pm_nl_ctl limits 0 1
628ip netns exec $ns2 ./pm_nl_ctl add 10.0.3.2 flags subflow
629run_tests $ns1 $ns2 10.0.1.1 0 0 1 slow
630chk_join_nr "remove single subflow" 1 1 1
631chk_rm_nr 1 1
632
633# multiple subflows, remove
634reset
635ip netns exec $ns1 ./pm_nl_ctl limits 0 2
636ip netns exec $ns2 ./pm_nl_ctl limits 0 2
637ip netns exec $ns2 ./pm_nl_ctl add 10.0.2.2 flags subflow
638ip netns exec $ns2 ./pm_nl_ctl add 10.0.3.2 flags subflow
639run_tests $ns1 $ns2 10.0.1.1 0 0 2 slow
640chk_join_nr "remove multiple subflows" 2 2 2
641chk_rm_nr 2 2
642
643# single address, remove
644reset
645ip netns exec $ns1 ./pm_nl_ctl limits 0 1
646ip netns exec $ns1 ./pm_nl_ctl add 10.0.2.1 flags signal
647ip netns exec $ns2 ./pm_nl_ctl limits 1 1
648run_tests $ns1 $ns2 10.0.1.1 0 1 0 slow
649chk_join_nr "remove single address" 1 1 1
650chk_add_nr 1 1
651chk_rm_nr 0 0
652
653# subflow and signal, remove
654reset
655ip netns exec $ns1 ./pm_nl_ctl limits 0 2
656ip netns exec $ns1 ./pm_nl_ctl add 10.0.2.1 flags signal
657ip netns exec $ns2 ./pm_nl_ctl limits 1 2
658ip netns exec $ns2 ./pm_nl_ctl add 10.0.3.2 flags subflow
659run_tests $ns1 $ns2 10.0.1.1 0 1 1 slow
660chk_join_nr "remove subflow and signal" 2 2 2
661chk_add_nr 1 1
662chk_rm_nr 1 1
663
664# subflows and signal, remove
665reset
666ip netns exec $ns1 ./pm_nl_ctl limits 0 3
667ip netns exec $ns1 ./pm_nl_ctl add 10.0.2.1 flags signal
668ip netns exec $ns2 ./pm_nl_ctl limits 1 3
669ip netns exec $ns2 ./pm_nl_ctl add 10.0.3.2 flags subflow
670ip netns exec $ns2 ./pm_nl_ctl add 10.0.4.2 flags subflow
671run_tests $ns1 $ns2 10.0.1.1 0 1 2 slow
672chk_join_nr "remove subflows and signal" 3 3 3
673chk_add_nr 1 1
674chk_rm_nr 2 2
675
676# subflows and signal, flush
677reset
678ip netns exec $ns1 ./pm_nl_ctl limits 0 3
679ip netns exec $ns1 ./pm_nl_ctl add 10.0.2.1 flags signal
680ip netns exec $ns2 ./pm_nl_ctl limits 1 3
681ip netns exec $ns2 ./pm_nl_ctl add 10.0.3.2 flags subflow
682ip netns exec $ns2 ./pm_nl_ctl add 10.0.4.2 flags subflow
683run_tests $ns1 $ns2 10.0.1.1 0 8 8 slow
684chk_join_nr "flush subflows and signal" 3 3 3
685chk_add_nr 1 1
686chk_rm_nr 2 2
687
688# subflow IPv6
689reset
690ip netns exec $ns1 ./pm_nl_ctl limits 0 1
691ip netns exec $ns2 ./pm_nl_ctl limits 0 1
692ip netns exec $ns2 ./pm_nl_ctl add dead:beef:3::2 flags subflow
693run_tests $ns1 $ns2 dead:beef:1::1 0 0 0 slow
694chk_join_nr "single subflow IPv6" 1 1 1
695
696# add_address, unused IPv6
697reset
698ip netns exec $ns1 ./pm_nl_ctl add dead:beef:2::1 flags signal
699run_tests $ns1 $ns2 dead:beef:1::1 0 0 0 slow
700chk_join_nr "unused signal address IPv6" 0 0 0
701chk_add_nr 1 1
702
703# signal address IPv6
704reset
705ip netns exec $ns1 ./pm_nl_ctl limits 0 1
706ip netns exec $ns1 ./pm_nl_ctl add dead:beef:2::1 flags signal
707ip netns exec $ns2 ./pm_nl_ctl limits 1 1
708run_tests $ns1 $ns2 dead:beef:1::1 0 0 0 slow
709chk_join_nr "single address IPv6" 1 1 1
710chk_add_nr 1 1
711
712# add_addr timeout IPv6
713reset_with_add_addr_timeout 6
714ip netns exec $ns1 ./pm_nl_ctl limits 0 1
715ip netns exec $ns2 ./pm_nl_ctl limits 1 1
716ip netns exec $ns1 ./pm_nl_ctl add dead:beef:2::1 flags signal
717run_tests $ns1 $ns2 dead:beef:1::1 0 0 0 slow
718chk_join_nr "signal address, ADD_ADDR6 timeout" 1 1 1
719chk_add_nr 4 0
720
721# single address IPv6, remove
722reset
723ip netns exec $ns1 ./pm_nl_ctl limits 0 1
724ip netns exec $ns1 ./pm_nl_ctl add dead:beef:2::1 flags signal
725ip netns exec $ns2 ./pm_nl_ctl limits 1 1
726run_tests $ns1 $ns2 dead:beef:1::1 0 1 0 slow
727chk_join_nr "remove single address IPv6" 1 1 1
728chk_add_nr 1 1
729chk_rm_nr 0 0
730
731# subflow and signal IPv6, remove
732reset
733ip netns exec $ns1 ./pm_nl_ctl limits 0 2
734ip netns exec $ns1 ./pm_nl_ctl add dead:beef:2::1 flags signal
735ip netns exec $ns2 ./pm_nl_ctl limits 1 2
736ip netns exec $ns2 ./pm_nl_ctl add dead:beef:3::2 flags subflow
737run_tests $ns1 $ns2 dead:beef:1::1 0 1 1 slow
738chk_join_nr "remove subflow and signal IPv6" 2 2 2
739chk_add_nr 1 1
740chk_rm_nr 1 1
741
742# single subflow, syncookies
743reset_with_cookies
744ip netns exec $ns1 ./pm_nl_ctl limits 0 1
745ip netns exec $ns2 ./pm_nl_ctl limits 0 1
746ip netns exec $ns2 ./pm_nl_ctl add 10.0.3.2 flags subflow
747run_tests $ns1 $ns2 10.0.1.1
748chk_join_nr "single subflow with syn cookies" 1 1 1
749
750# multiple subflows with syn cookies
751reset_with_cookies
752ip netns exec $ns1 ./pm_nl_ctl limits 0 2
753ip netns exec $ns2 ./pm_nl_ctl limits 0 2
754ip netns exec $ns2 ./pm_nl_ctl add 10.0.3.2 flags subflow
755ip netns exec $ns2 ./pm_nl_ctl add 10.0.2.2 flags subflow
756run_tests $ns1 $ns2 10.0.1.1
757chk_join_nr "multiple subflows with syn cookies" 2 2 2
758
759# multiple subflows limited by server
760reset_with_cookies
761ip netns exec $ns1 ./pm_nl_ctl limits 0 1
762ip netns exec $ns2 ./pm_nl_ctl limits 0 2
763ip netns exec $ns2 ./pm_nl_ctl add 10.0.3.2 flags subflow
764ip netns exec $ns2 ./pm_nl_ctl add 10.0.2.2 flags subflow
765run_tests $ns1 $ns2 10.0.1.1
766chk_join_nr "subflows limited by server w cookies" 2 2 1
767
768# test signal address with cookies
769reset_with_cookies
770ip netns exec $ns1 ./pm_nl_ctl limits 0 1
771ip netns exec $ns2 ./pm_nl_ctl limits 1 1
772ip netns exec $ns1 ./pm_nl_ctl add 10.0.2.1 flags signal
773run_tests $ns1 $ns2 10.0.1.1
774chk_join_nr "signal address with syn cookies" 1 1 1
775chk_add_nr 1 1
776
777# test cookie with subflow and signal
778reset_with_cookies
779ip netns exec $ns1 ./pm_nl_ctl add 10.0.2.1 flags signal
780ip netns exec $ns1 ./pm_nl_ctl limits 0 2
781ip netns exec $ns2 ./pm_nl_ctl limits 1 2
782ip netns exec $ns2 ./pm_nl_ctl add 10.0.3.2 flags subflow
783run_tests $ns1 $ns2 10.0.1.1
784chk_join_nr "subflow and signal w cookies" 2 2 2
785chk_add_nr 1 1
786
787# accept and use add_addr with additional subflows
788reset_with_cookies
789ip netns exec $ns1 ./pm_nl_ctl limits 0 3
790ip netns exec $ns1 ./pm_nl_ctl add 10.0.2.1 flags signal
791ip netns exec $ns2 ./pm_nl_ctl limits 1 3
792ip netns exec $ns2 ./pm_nl_ctl add 10.0.3.2 flags subflow
793ip netns exec $ns2 ./pm_nl_ctl add 10.0.4.2 flags subflow
794run_tests $ns1 $ns2 10.0.1.1
795chk_join_nr "subflows and signal w. cookies" 3 3 3
796chk_add_nr 1 1
797
798exit $ret
799