1b08fbf24SPaolo Abeni#!/bin/bash
2b08fbf24SPaolo Abeni# SPDX-License-Identifier: GPL-2.0
3b08fbf24SPaolo Abeni
4b08fbf24SPaolo Abeniret=0
5b08fbf24SPaolo Abenisin=""
6b08fbf24SPaolo Abenisout=""
7b08fbf24SPaolo Abenicin=""
88b819a84SFlorian Westphalcinsent=""
9b08fbf24SPaolo Abenicout=""
10b08fbf24SPaolo Abeniksft_skip=4
11b08fbf24SPaolo Abenitimeout=30
12dd72b0feSGeliang Tangmptcp_connect=""
13b08fbf24SPaolo Abenicapture=0
14b08fbf24SPaolo Abeni
15b08fbf24SPaolo AbeniTEST_COUNT=0
16b08fbf24SPaolo Abeni
178d014eaaSGeliang Tang# generated using "nfbpf_compile '(ip && (ip[54] & 0xf0) == 0x30) ||
188d014eaaSGeliang Tang#				  (ip6 && (ip6[74] & 0xf0) == 0x30)'"
198d014eaaSGeliang TangCBPF_MPTCP_SUBOPTION_ADD_ADDR="14,
208d014eaaSGeliang Tang			       48 0 0 0,
218d014eaaSGeliang Tang			       84 0 0 240,
228d014eaaSGeliang Tang			       21 0 3 64,
238d014eaaSGeliang Tang			       48 0 0 54,
248d014eaaSGeliang Tang			       84 0 0 240,
258d014eaaSGeliang Tang			       21 6 7 48,
268d014eaaSGeliang Tang			       48 0 0 0,
278d014eaaSGeliang Tang			       84 0 0 240,
288d014eaaSGeliang Tang			       21 0 4 96,
298d014eaaSGeliang Tang			       48 0 0 74,
308d014eaaSGeliang Tang			       84 0 0 240,
318d014eaaSGeliang Tang			       21 0 1 48,
328d014eaaSGeliang Tang			       6 0 0 65535,
338d014eaaSGeliang Tang			       6 0 0 0"
348d014eaaSGeliang Tang
35b08fbf24SPaolo Abeniinit()
36b08fbf24SPaolo Abeni{
37b08fbf24SPaolo Abeni	capout=$(mktemp)
38b08fbf24SPaolo Abeni
39b08fbf24SPaolo Abeni	rndh=$(printf %x $sec)-$(mktemp -u XXXXXX)
40b08fbf24SPaolo Abeni
41b08fbf24SPaolo Abeni	ns1="ns1-$rndh"
42b08fbf24SPaolo Abeni	ns2="ns2-$rndh"
43b08fbf24SPaolo Abeni
44b08fbf24SPaolo Abeni	for netns in "$ns1" "$ns2";do
45b08fbf24SPaolo Abeni		ip netns add $netns || exit $ksft_skip
46b08fbf24SPaolo Abeni		ip -net $netns link set lo up
47b08fbf24SPaolo Abeni		ip netns exec $netns sysctl -q net.mptcp.enabled=1
48b08fbf24SPaolo Abeni		ip netns exec $netns sysctl -q net.ipv4.conf.all.rp_filter=0
49b08fbf24SPaolo Abeni		ip netns exec $netns sysctl -q net.ipv4.conf.default.rp_filter=0
50b08fbf24SPaolo Abeni	done
51b08fbf24SPaolo Abeni
52b08fbf24SPaolo Abeni	#  ns1              ns2
53b08fbf24SPaolo Abeni	# ns1eth1    ns2eth1
54b08fbf24SPaolo Abeni	# ns1eth2    ns2eth2
55b08fbf24SPaolo Abeni	# ns1eth3    ns2eth3
56b08fbf24SPaolo Abeni	# ns1eth4    ns2eth4
57b08fbf24SPaolo Abeni
58b08fbf24SPaolo Abeni	for i in `seq 1 4`; do
59b08fbf24SPaolo Abeni		ip link add ns1eth$i netns "$ns1" type veth peer name ns2eth$i netns "$ns2"
60b08fbf24SPaolo Abeni		ip -net "$ns1" addr add 10.0.$i.1/24 dev ns1eth$i
61b08fbf24SPaolo Abeni		ip -net "$ns1" addr add dead:beef:$i::1/64 dev ns1eth$i nodad
62b08fbf24SPaolo Abeni		ip -net "$ns1" link set ns1eth$i up
63b08fbf24SPaolo Abeni
64b08fbf24SPaolo Abeni		ip -net "$ns2" addr add 10.0.$i.2/24 dev ns2eth$i
65b08fbf24SPaolo Abeni		ip -net "$ns2" addr add dead:beef:$i::2/64 dev ns2eth$i nodad
66b08fbf24SPaolo Abeni		ip -net "$ns2" link set ns2eth$i up
67b08fbf24SPaolo Abeni
68b08fbf24SPaolo Abeni		# let $ns2 reach any $ns1 address from any interface
69b08fbf24SPaolo Abeni		ip -net "$ns2" route add default via 10.0.$i.1 dev ns2eth$i metric 10$i
70b08fbf24SPaolo Abeni	done
71b08fbf24SPaolo Abeni}
72b08fbf24SPaolo Abeni
73b08fbf24SPaolo Abenicleanup_partial()
74b08fbf24SPaolo Abeni{
75b08fbf24SPaolo Abeni	rm -f "$capout"
76b08fbf24SPaolo Abeni
77b08fbf24SPaolo Abeni	for netns in "$ns1" "$ns2"; do
78b08fbf24SPaolo Abeni		ip netns del $netns
79b08fbf24SPaolo Abeni	done
80b08fbf24SPaolo Abeni}
81b08fbf24SPaolo Abeni
82b08fbf24SPaolo Abenicleanup()
83b08fbf24SPaolo Abeni{
84b08fbf24SPaolo Abeni	rm -f "$cin" "$cout"
858b819a84SFlorian Westphal	rm -f "$sin" "$sout" "$cinsent"
86b08fbf24SPaolo Abeni	cleanup_partial
87b08fbf24SPaolo Abeni}
88b08fbf24SPaolo Abeni
89b08fbf24SPaolo Abenireset()
90b08fbf24SPaolo Abeni{
91b08fbf24SPaolo Abeni	cleanup_partial
92b08fbf24SPaolo Abeni	init
93b08fbf24SPaolo Abeni}
94b08fbf24SPaolo Abeni
9500587187SFlorian Westphalreset_with_cookies()
9600587187SFlorian Westphal{
9700587187SFlorian Westphal	reset
9800587187SFlorian Westphal
9900587187SFlorian Westphal	for netns in "$ns1" "$ns2";do
10000587187SFlorian Westphal		ip netns exec $netns sysctl -q net.ipv4.tcp_syncookies=2
10100587187SFlorian Westphal	done
10200587187SFlorian Westphal}
10300587187SFlorian Westphal
1048d014eaaSGeliang Tangreset_with_add_addr_timeout()
1058d014eaaSGeliang Tang{
1068d014eaaSGeliang Tang	local ip="${1:-4}"
1078d014eaaSGeliang Tang	local tables
1088d014eaaSGeliang Tang
1098d014eaaSGeliang Tang	tables="iptables"
1108d014eaaSGeliang Tang	if [ $ip -eq 6 ]; then
1118d014eaaSGeliang Tang		tables="ip6tables"
1128d014eaaSGeliang Tang	fi
1138d014eaaSGeliang Tang
1148d014eaaSGeliang Tang	reset
1158d014eaaSGeliang Tang
1168d014eaaSGeliang Tang	ip netns exec $ns1 sysctl -q net.mptcp.add_addr_timeout=1
1178d014eaaSGeliang Tang	ip netns exec $ns2 $tables -A OUTPUT -p tcp \
1188d014eaaSGeliang Tang		-m tcp --tcp-option 30 \
1198d014eaaSGeliang Tang		-m bpf --bytecode \
1208d014eaaSGeliang Tang		"$CBPF_MPTCP_SUBOPTION_ADD_ADDR" \
1218d014eaaSGeliang Tang		-j DROP
1228d014eaaSGeliang Tang}
1238d014eaaSGeliang Tang
124b08fbf24SPaolo Abenifor arg in "$@"; do
125b08fbf24SPaolo Abeni	if [ "$arg" = "-c" ]; then
126b08fbf24SPaolo Abeni		capture=1
127b08fbf24SPaolo Abeni	fi
128b08fbf24SPaolo Abenidone
129b08fbf24SPaolo Abeni
130b08fbf24SPaolo Abeniip -Version > /dev/null 2>&1
131b08fbf24SPaolo Abeniif [ $? -ne 0 ];then
132b08fbf24SPaolo Abeni	echo "SKIP: Could not run test without ip tool"
133b08fbf24SPaolo Abeni	exit $ksft_skip
134b08fbf24SPaolo Abenifi
135b08fbf24SPaolo Abeni
1368d014eaaSGeliang Tangiptables -V > /dev/null 2>&1
1378d014eaaSGeliang Tangif [ $? -ne 0 ];then
1388d014eaaSGeliang Tang	echo "SKIP: Could not run all tests without iptables tool"
1398d014eaaSGeliang Tang	exit $ksft_skip
1408d014eaaSGeliang Tangfi
1418d014eaaSGeliang Tang
1428d014eaaSGeliang Tangip6tables -V > /dev/null 2>&1
1438d014eaaSGeliang Tangif [ $? -ne 0 ];then
1448d014eaaSGeliang Tang	echo "SKIP: Could not run all tests without ip6tables tool"
1458d014eaaSGeliang Tang	exit $ksft_skip
1468d014eaaSGeliang Tangfi
147b08fbf24SPaolo Abeni
1488b819a84SFlorian Westphalprint_file_err()
1498b819a84SFlorian Westphal{
1508b819a84SFlorian Westphal	ls -l "$1" 1>&2
1518b819a84SFlorian Westphal	echo "Trailing bytes are: "
1528b819a84SFlorian Westphal	tail -c 27 "$1"
1538b819a84SFlorian Westphal}
1548b819a84SFlorian Westphal
155b08fbf24SPaolo Abenicheck_transfer()
156b08fbf24SPaolo Abeni{
157b08fbf24SPaolo Abeni	in=$1
158b08fbf24SPaolo Abeni	out=$2
159b08fbf24SPaolo Abeni	what=$3
160b08fbf24SPaolo Abeni
161b08fbf24SPaolo Abeni	cmp "$in" "$out" > /dev/null 2>&1
162b08fbf24SPaolo Abeni	if [ $? -ne 0 ] ;then
163b08fbf24SPaolo Abeni		echo "[ FAIL ] $what does not match (in, out):"
164b08fbf24SPaolo Abeni		print_file_err "$in"
165b08fbf24SPaolo Abeni		print_file_err "$out"
1668b819a84SFlorian Westphal		ret=1
167b08fbf24SPaolo Abeni
168b08fbf24SPaolo Abeni		return 1
169b08fbf24SPaolo Abeni	fi
170b08fbf24SPaolo Abeni
171b08fbf24SPaolo Abeni	return 0
172b08fbf24SPaolo Abeni}
173b08fbf24SPaolo Abeni
174b08fbf24SPaolo Abenido_ping()
175b08fbf24SPaolo Abeni{
176b08fbf24SPaolo Abeni	listener_ns="$1"
177b08fbf24SPaolo Abeni	connector_ns="$2"
178b08fbf24SPaolo Abeni	connect_addr="$3"
179b08fbf24SPaolo Abeni
180b08fbf24SPaolo Abeni	ip netns exec ${connector_ns} ping -q -c 1 $connect_addr >/dev/null
181b08fbf24SPaolo Abeni	if [ $? -ne 0 ] ; then
182b08fbf24SPaolo Abeni		echo "$listener_ns -> $connect_addr connectivity [ FAIL ]" 1>&2
183b08fbf24SPaolo Abeni		ret=1
184b08fbf24SPaolo Abeni	fi
185b08fbf24SPaolo Abeni}
186b08fbf24SPaolo Abeni
1878b819a84SFlorian Westphallink_failure()
1888b819a84SFlorian Westphal{
1898b819a84SFlorian Westphal	ns="$1"
1908b819a84SFlorian Westphal
1918b819a84SFlorian Westphal	l=$((RANDOM%4))
1928b819a84SFlorian Westphal	l=$((l+1))
1938b819a84SFlorian Westphal
1948b819a84SFlorian Westphal	veth="ns1eth$l"
1958b819a84SFlorian Westphal	ip -net "$ns" link set "$veth" down
1968b819a84SFlorian Westphal}
1978b819a84SFlorian Westphal
198523514edSGeliang Tang# $1: IP address
199523514edSGeliang Tangis_v6()
200523514edSGeliang Tang{
201523514edSGeliang Tang	[ -z "${1##*:*}" ]
202523514edSGeliang Tang}
203523514edSGeliang Tang
204b08fbf24SPaolo Abenido_transfer()
205b08fbf24SPaolo Abeni{
206b08fbf24SPaolo Abeni	listener_ns="$1"
207b08fbf24SPaolo Abeni	connector_ns="$2"
208b08fbf24SPaolo Abeni	cl_proto="$3"
209b08fbf24SPaolo Abeni	srv_proto="$4"
210b08fbf24SPaolo Abeni	connect_addr="$5"
2118b819a84SFlorian Westphal	test_link_fail="$6"
2128b819a84SFlorian Westphal	rm_nr_ns1="$7"
2138b819a84SFlorian Westphal	rm_nr_ns2="$8"
2148b819a84SFlorian Westphal	speed="$9"
215b08fbf24SPaolo Abeni
216b08fbf24SPaolo Abeni	port=$((10000+$TEST_COUNT))
217b08fbf24SPaolo Abeni	TEST_COUNT=$((TEST_COUNT+1))
218b08fbf24SPaolo Abeni
219b08fbf24SPaolo Abeni	:> "$cout"
220b08fbf24SPaolo Abeni	:> "$sout"
221b08fbf24SPaolo Abeni	:> "$capout"
222b08fbf24SPaolo Abeni
223b08fbf24SPaolo Abeni	if [ $capture -eq 1 ]; then
224b08fbf24SPaolo Abeni		if [ -z $SUDO_USER ] ; then
225b08fbf24SPaolo Abeni			capuser=""
226b08fbf24SPaolo Abeni		else
227b08fbf24SPaolo Abeni			capuser="-Z $SUDO_USER"
228b08fbf24SPaolo Abeni		fi
229b08fbf24SPaolo Abeni
23000587187SFlorian Westphal		capfile=$(printf "mp_join-%02u-%s.pcap" "$TEST_COUNT" "${listener_ns}")
231b08fbf24SPaolo Abeni
232b08fbf24SPaolo Abeni		echo "Capturing traffic for test $TEST_COUNT into $capfile"
233b08fbf24SPaolo Abeni		ip netns exec ${listener_ns} tcpdump -i any -s 65535 -B 32768 $capuser -w $capfile > "$capout" 2>&1 &
234b08fbf24SPaolo Abeni		cappid=$!
235b08fbf24SPaolo Abeni
236b08fbf24SPaolo Abeni		sleep 1
237b08fbf24SPaolo Abeni	fi
238b08fbf24SPaolo Abeni
2398d014eaaSGeliang Tang	if [ $speed = "fast" ]; then
240dd72b0feSGeliang Tang		mptcp_connect="./mptcp_connect -j"
241dd72b0feSGeliang Tang	else
242dd72b0feSGeliang Tang		mptcp_connect="./mptcp_connect -r"
243dd72b0feSGeliang Tang	fi
244dd72b0feSGeliang Tang
245523514edSGeliang Tang	local local_addr
246523514edSGeliang Tang	if is_v6 "${connect_addr}"; then
247523514edSGeliang Tang		local_addr="::"
248523514edSGeliang Tang	else
249523514edSGeliang Tang		local_addr="0.0.0.0"
250523514edSGeliang Tang	fi
251523514edSGeliang Tang
252523514edSGeliang Tang	ip netns exec ${listener_ns} $mptcp_connect -t $timeout -l -p $port \
253523514edSGeliang Tang		-s ${srv_proto} ${local_addr} < "$sin" > "$sout" &
254b08fbf24SPaolo Abeni	spid=$!
255b08fbf24SPaolo Abeni
256b08fbf24SPaolo Abeni	sleep 1
257b08fbf24SPaolo Abeni
2588b819a84SFlorian Westphal	if [ "$test_link_fail" -eq 0 ];then
259dd72b0feSGeliang Tang		ip netns exec ${connector_ns} $mptcp_connect -t $timeout -p $port -s ${cl_proto} $connect_addr < "$cin" > "$cout" &
2608b819a84SFlorian Westphal	else
2618b819a84SFlorian Westphal		( cat "$cin" ; sleep 2; link_failure $listener_ns ; cat "$cin" ) | tee "$cinsent" | \
2628b819a84SFlorian Westphal		ip netns exec ${connector_ns} $mptcp_connect -t $timeout -p $port -s ${cl_proto} $connect_addr > "$cout" &
2638b819a84SFlorian Westphal	fi
264b08fbf24SPaolo Abeni	cpid=$!
265b08fbf24SPaolo Abeni
266dd72b0feSGeliang Tang	if [ $rm_nr_ns1 -gt 0 ]; then
267*6fe4ccdcSGeliang Tang		if [ $rm_nr_ns1 -lt 8 ]; then
268dd72b0feSGeliang Tang			counter=1
269dd72b0feSGeliang Tang			sleep 1
270dd72b0feSGeliang Tang
271dd72b0feSGeliang Tang			while [ $counter -le $rm_nr_ns1 ]
272dd72b0feSGeliang Tang			do
273dd72b0feSGeliang Tang				ip netns exec ${listener_ns} ./pm_nl_ctl del $counter
274dd72b0feSGeliang Tang				sleep 1
275dd72b0feSGeliang Tang				let counter+=1
276dd72b0feSGeliang Tang			done
277*6fe4ccdcSGeliang Tang		else
278*6fe4ccdcSGeliang Tang			sleep 1
279*6fe4ccdcSGeliang Tang			ip netns exec ${listener_ns} ./pm_nl_ctl flush
280*6fe4ccdcSGeliang Tang		fi
281dd72b0feSGeliang Tang	fi
282dd72b0feSGeliang Tang
283dd72b0feSGeliang Tang	if [ $rm_nr_ns2 -gt 0 ]; then
284*6fe4ccdcSGeliang Tang		if [ $rm_nr_ns2 -lt 8 ]; then
285dd72b0feSGeliang Tang			counter=1
286dd72b0feSGeliang Tang			sleep 1
287dd72b0feSGeliang Tang
288dd72b0feSGeliang Tang			while [ $counter -le $rm_nr_ns2 ]
289dd72b0feSGeliang Tang			do
290dd72b0feSGeliang Tang				ip netns exec ${connector_ns} ./pm_nl_ctl del $counter
291dd72b0feSGeliang Tang				sleep 1
292dd72b0feSGeliang Tang				let counter+=1
293dd72b0feSGeliang Tang			done
294*6fe4ccdcSGeliang Tang		else
295*6fe4ccdcSGeliang Tang			sleep 1
296*6fe4ccdcSGeliang Tang			ip netns exec ${connector_ns} ./pm_nl_ctl flush
297*6fe4ccdcSGeliang Tang		fi
298dd72b0feSGeliang Tang	fi
299dd72b0feSGeliang Tang
300b08fbf24SPaolo Abeni	wait $cpid
301b08fbf24SPaolo Abeni	retc=$?
302b08fbf24SPaolo Abeni	wait $spid
303b08fbf24SPaolo Abeni	rets=$?
304b08fbf24SPaolo Abeni
305b08fbf24SPaolo Abeni	if [ $capture -eq 1 ]; then
306b08fbf24SPaolo Abeni	    sleep 1
307b08fbf24SPaolo Abeni	    kill $cappid
308b08fbf24SPaolo Abeni	fi
309b08fbf24SPaolo Abeni
310b08fbf24SPaolo Abeni	if [ ${rets} -ne 0 ] || [ ${retc} -ne 0 ]; then
311b08fbf24SPaolo Abeni		echo " client exit code $retc, server $rets" 1>&2
3128b974778SMatthieu Baerts		echo -e "\nnetns ${listener_ns} socket stat for ${port}:" 1>&2
313b08fbf24SPaolo Abeni		ip netns exec ${listener_ns} ss -nita 1>&2 -o "sport = :$port"
3148b974778SMatthieu Baerts		echo -e "\nnetns ${connector_ns} socket stat for ${port}:" 1>&2
315b08fbf24SPaolo Abeni		ip netns exec ${connector_ns} ss -nita 1>&2 -o "dport = :$port"
316b08fbf24SPaolo Abeni
317b08fbf24SPaolo Abeni		cat "$capout"
3188b819a84SFlorian Westphal		ret=1
319b08fbf24SPaolo Abeni		return 1
320b08fbf24SPaolo Abeni	fi
321b08fbf24SPaolo Abeni
322b08fbf24SPaolo Abeni	check_transfer $sin $cout "file received by client"
323b08fbf24SPaolo Abeni	retc=$?
3248b819a84SFlorian Westphal	if [ "$test_link_fail" -eq 0 ];then
325b08fbf24SPaolo Abeni		check_transfer $cin $sout "file received by server"
3268b819a84SFlorian Westphal	else
3278b819a84SFlorian Westphal		check_transfer $cinsent $sout "file received by server"
3288b819a84SFlorian Westphal	fi
329b08fbf24SPaolo Abeni	rets=$?
330b08fbf24SPaolo Abeni
331b08fbf24SPaolo Abeni	if [ $retc -eq 0 ] && [ $rets -eq 0 ];then
332b08fbf24SPaolo Abeni		cat "$capout"
333b08fbf24SPaolo Abeni		return 0
334b08fbf24SPaolo Abeni	fi
335b08fbf24SPaolo Abeni
336b08fbf24SPaolo Abeni	cat "$capout"
337b08fbf24SPaolo Abeni	return 1
338b08fbf24SPaolo Abeni}
339b08fbf24SPaolo Abeni
340b08fbf24SPaolo Abenimake_file()
341b08fbf24SPaolo Abeni{
342b08fbf24SPaolo Abeni	name=$1
343b08fbf24SPaolo Abeni	who=$2
3448b819a84SFlorian Westphal	size=$3
345b08fbf24SPaolo Abeni
3468b819a84SFlorian Westphal	dd if=/dev/urandom of="$name" bs=1024 count=$size 2> /dev/null
347b08fbf24SPaolo Abeni	echo -e "\nMPTCP_TEST_FILE_END_MARKER" >> "$name"
348b08fbf24SPaolo Abeni
3498b819a84SFlorian Westphal	echo "Created $name (size $size KB) containing data sent by $who"
350b08fbf24SPaolo Abeni}
351b08fbf24SPaolo Abeni
352b08fbf24SPaolo Abenirun_tests()
353b08fbf24SPaolo Abeni{
354b08fbf24SPaolo Abeni	listener_ns="$1"
355b08fbf24SPaolo Abeni	connector_ns="$2"
356b08fbf24SPaolo Abeni	connect_addr="$3"
3578b819a84SFlorian Westphal	test_linkfail="${4:-0}"
3588b819a84SFlorian Westphal	rm_nr_ns1="${5:-0}"
3598b819a84SFlorian Westphal	rm_nr_ns2="${6:-0}"
3608b819a84SFlorian Westphal	speed="${7:-fast}"
361b08fbf24SPaolo Abeni	lret=0
3628b819a84SFlorian Westphal	oldin=""
3638b819a84SFlorian Westphal
3648b819a84SFlorian Westphal	if [ "$test_linkfail" -eq 1 ];then
3658b819a84SFlorian Westphal		size=$((RANDOM%1024))
3668b819a84SFlorian Westphal		size=$((size+1))
3678b819a84SFlorian Westphal		size=$((size*128))
3688b819a84SFlorian Westphal
3698b819a84SFlorian Westphal		oldin=$(mktemp)
3708b819a84SFlorian Westphal		cp "$cin" "$oldin"
3718b819a84SFlorian Westphal		make_file "$cin" "client" $size
3728b819a84SFlorian Westphal	fi
373b08fbf24SPaolo Abeni
3748d014eaaSGeliang Tang	do_transfer ${listener_ns} ${connector_ns} MPTCP MPTCP ${connect_addr} \
3758b819a84SFlorian Westphal		${test_linkfail} ${rm_nr_ns1} ${rm_nr_ns2} ${speed}
376b08fbf24SPaolo Abeni	lret=$?
3778b819a84SFlorian Westphal
3788b819a84SFlorian Westphal	if [ "$test_linkfail" -eq 1 ];then
3798b819a84SFlorian Westphal		cp "$oldin" "$cin"
3808b819a84SFlorian Westphal		rm -f "$oldin"
3818b819a84SFlorian Westphal	fi
3828b819a84SFlorian Westphal
383b08fbf24SPaolo Abeni	if [ $lret -ne 0 ]; then
384b08fbf24SPaolo Abeni		ret=$lret
385b08fbf24SPaolo Abeni		return
386b08fbf24SPaolo Abeni	fi
387b08fbf24SPaolo Abeni}
388b08fbf24SPaolo Abeni
389b08fbf24SPaolo Abenichk_join_nr()
390b08fbf24SPaolo Abeni{
391b08fbf24SPaolo Abeni	local msg="$1"
392b08fbf24SPaolo Abeni	local syn_nr=$2
393b08fbf24SPaolo Abeni	local syn_ack_nr=$3
394b08fbf24SPaolo Abeni	local ack_nr=$4
395b08fbf24SPaolo Abeni	local count
396b08fbf24SPaolo Abeni	local dump_stats
397b08fbf24SPaolo Abeni
39800587187SFlorian Westphal	printf "%02u %-36s %s" "$TEST_COUNT" "$msg" "syn"
399b08fbf24SPaolo Abeni	count=`ip netns exec $ns1 nstat -as | grep MPTcpExtMPJoinSynRx | awk '{print $2}'`
400b08fbf24SPaolo Abeni	[ -z "$count" ] && count=0
401b08fbf24SPaolo Abeni	if [ "$count" != "$syn_nr" ]; then
402b08fbf24SPaolo Abeni		echo "[fail] got $count JOIN[s] syn expected $syn_nr"
403b08fbf24SPaolo Abeni		ret=1
404b08fbf24SPaolo Abeni		dump_stats=1
405b08fbf24SPaolo Abeni	else
406b08fbf24SPaolo Abeni		echo -n "[ ok ]"
407b08fbf24SPaolo Abeni	fi
408b08fbf24SPaolo Abeni
409b08fbf24SPaolo Abeni	echo -n " - synack"
410b08fbf24SPaolo Abeni	count=`ip netns exec $ns2 nstat -as | grep MPTcpExtMPJoinSynAckRx | awk '{print $2}'`
411b08fbf24SPaolo Abeni	[ -z "$count" ] && count=0
412b08fbf24SPaolo Abeni	if [ "$count" != "$syn_ack_nr" ]; then
413b08fbf24SPaolo Abeni		echo "[fail] got $count JOIN[s] synack expected $syn_ack_nr"
414b08fbf24SPaolo Abeni		ret=1
415b08fbf24SPaolo Abeni		dump_stats=1
416b08fbf24SPaolo Abeni	else
417b08fbf24SPaolo Abeni		echo -n "[ ok ]"
418b08fbf24SPaolo Abeni	fi
419b08fbf24SPaolo Abeni
420b08fbf24SPaolo Abeni	echo -n " - ack"
421b08fbf24SPaolo Abeni	count=`ip netns exec $ns1 nstat -as | grep MPTcpExtMPJoinAckRx | awk '{print $2}'`
422b08fbf24SPaolo Abeni	[ -z "$count" ] && count=0
423b08fbf24SPaolo Abeni	if [ "$count" != "$ack_nr" ]; then
424b08fbf24SPaolo Abeni		echo "[fail] got $count JOIN[s] ack expected $ack_nr"
425b08fbf24SPaolo Abeni		ret=1
426b08fbf24SPaolo Abeni		dump_stats=1
427b08fbf24SPaolo Abeni	else
428b08fbf24SPaolo Abeni		echo "[ ok ]"
429b08fbf24SPaolo Abeni	fi
430b08fbf24SPaolo Abeni	if [ "${dump_stats}" = 1 ]; then
431b08fbf24SPaolo Abeni		echo Server ns stats
432b08fbf24SPaolo Abeni		ip netns exec $ns1 nstat -as | grep MPTcp
433b08fbf24SPaolo Abeni		echo Client ns stats
434b08fbf24SPaolo Abeni		ip netns exec $ns2 nstat -as | grep MPTcp
435b08fbf24SPaolo Abeni	fi
436b08fbf24SPaolo Abeni}
437b08fbf24SPaolo Abeni
438be613160SGeliang Tangchk_add_nr()
439be613160SGeliang Tang{
440be613160SGeliang Tang	local add_nr=$1
441be613160SGeliang Tang	local echo_nr=$2
442be613160SGeliang Tang	local count
443be613160SGeliang Tang	local dump_stats
444be613160SGeliang Tang
445be613160SGeliang Tang	printf "%-39s %s" " " "add"
446be613160SGeliang Tang	count=`ip netns exec $ns2 nstat -as | grep MPTcpExtAddAddr | awk '{print $2}'`
447be613160SGeliang Tang	[ -z "$count" ] && count=0
448be613160SGeliang Tang	if [ "$count" != "$add_nr" ]; then
449be613160SGeliang Tang		echo "[fail] got $count ADD_ADDR[s] expected $add_nr"
450be613160SGeliang Tang		ret=1
451be613160SGeliang Tang		dump_stats=1
452be613160SGeliang Tang	else
453be613160SGeliang Tang		echo -n "[ ok ]"
454be613160SGeliang Tang	fi
455be613160SGeliang Tang
456be613160SGeliang Tang	echo -n " - echo  "
457be613160SGeliang Tang	count=`ip netns exec $ns1 nstat -as | grep MPTcpExtEchoAdd | awk '{print $2}'`
458be613160SGeliang Tang	[ -z "$count" ] && count=0
459be613160SGeliang Tang	if [ "$count" != "$echo_nr" ]; then
460be613160SGeliang Tang		echo "[fail] got $count ADD_ADDR echo[s] expected $echo_nr"
461be613160SGeliang Tang		ret=1
462be613160SGeliang Tang		dump_stats=1
463be613160SGeliang Tang	else
464be613160SGeliang Tang		echo "[ ok ]"
465be613160SGeliang Tang	fi
466be613160SGeliang Tang
467be613160SGeliang Tang	if [ "${dump_stats}" = 1 ]; then
468be613160SGeliang Tang		echo Server ns stats
469be613160SGeliang Tang		ip netns exec $ns1 nstat -as | grep MPTcp
470be613160SGeliang Tang		echo Client ns stats
471be613160SGeliang Tang		ip netns exec $ns2 nstat -as | grep MPTcp
472be613160SGeliang Tang	fi
473be613160SGeliang Tang}
474be613160SGeliang Tang
475dd72b0feSGeliang Tangchk_rm_nr()
476dd72b0feSGeliang Tang{
477dd72b0feSGeliang Tang	local rm_addr_nr=$1
478dd72b0feSGeliang Tang	local rm_subflow_nr=$2
479dd72b0feSGeliang Tang	local count
480dd72b0feSGeliang Tang	local dump_stats
481dd72b0feSGeliang Tang
482dd72b0feSGeliang Tang	printf "%-39s %s" " " "rm "
483dd72b0feSGeliang Tang	count=`ip netns exec $ns1 nstat -as | grep MPTcpExtRmAddr | awk '{print $2}'`
484dd72b0feSGeliang Tang	[ -z "$count" ] && count=0
485dd72b0feSGeliang Tang	if [ "$count" != "$rm_addr_nr" ]; then
486dd72b0feSGeliang Tang		echo "[fail] got $count RM_ADDR[s] expected $rm_addr_nr"
487dd72b0feSGeliang Tang		ret=1
488dd72b0feSGeliang Tang		dump_stats=1
489dd72b0feSGeliang Tang	else
490dd72b0feSGeliang Tang		echo -n "[ ok ]"
491dd72b0feSGeliang Tang	fi
492dd72b0feSGeliang Tang
493dd72b0feSGeliang Tang	echo -n " - sf    "
494dd72b0feSGeliang Tang	count=`ip netns exec $ns2 nstat -as | grep MPTcpExtRmSubflow | awk '{print $2}'`
495dd72b0feSGeliang Tang	[ -z "$count" ] && count=0
496dd72b0feSGeliang Tang	if [ "$count" != "$rm_subflow_nr" ]; then
497dd72b0feSGeliang Tang		echo "[fail] got $count RM_SUBFLOW[s] expected $rm_subflow_nr"
498dd72b0feSGeliang Tang		ret=1
499dd72b0feSGeliang Tang		dump_stats=1
500dd72b0feSGeliang Tang	else
501dd72b0feSGeliang Tang		echo "[ ok ]"
502dd72b0feSGeliang Tang	fi
503dd72b0feSGeliang Tang
504dd72b0feSGeliang Tang	if [ "${dump_stats}" = 1 ]; then
505dd72b0feSGeliang Tang		echo Server ns stats
506dd72b0feSGeliang Tang		ip netns exec $ns1 nstat -as | grep MPTcp
507dd72b0feSGeliang Tang		echo Client ns stats
508dd72b0feSGeliang Tang		ip netns exec $ns2 nstat -as | grep MPTcp
509dd72b0feSGeliang Tang	fi
510dd72b0feSGeliang Tang}
511dd72b0feSGeliang Tang
512b08fbf24SPaolo Abenisin=$(mktemp)
513b08fbf24SPaolo Abenisout=$(mktemp)
514b08fbf24SPaolo Abenicin=$(mktemp)
5158b819a84SFlorian Westphalcinsent=$(mktemp)
516b08fbf24SPaolo Abenicout=$(mktemp)
517b08fbf24SPaolo Abeniinit
5188b819a84SFlorian Westphalmake_file "$cin" "client" 1
5198b819a84SFlorian Westphalmake_file "$sin" "server" 1
520b08fbf24SPaolo Abenitrap cleanup EXIT
521b08fbf24SPaolo Abeni
522b08fbf24SPaolo Abenirun_tests $ns1 $ns2 10.0.1.1
523b08fbf24SPaolo Abenichk_join_nr "no JOIN" "0" "0" "0"
524b08fbf24SPaolo Abeni
525b08fbf24SPaolo Abeni# subflow limted by client
526b08fbf24SPaolo Abenireset
527b08fbf24SPaolo Abeniip netns exec $ns2 ./pm_nl_ctl add 10.0.3.2 flags subflow
528b08fbf24SPaolo Abenirun_tests $ns1 $ns2 10.0.1.1
529b08fbf24SPaolo Abenichk_join_nr "single subflow, limited by client" 0 0 0
530b08fbf24SPaolo Abeni
531b08fbf24SPaolo Abeni# subflow limted by server
532b08fbf24SPaolo Abenireset
533b08fbf24SPaolo Abeniip netns exec $ns2 ./pm_nl_ctl limits 0 1
534b08fbf24SPaolo Abeniip netns exec $ns2 ./pm_nl_ctl add 10.0.3.2 flags subflow
535b08fbf24SPaolo Abenirun_tests $ns1 $ns2 10.0.1.1
536b08fbf24SPaolo Abenichk_join_nr "single subflow, limited by server" 1 1 0
537b08fbf24SPaolo Abeni
538b08fbf24SPaolo Abeni# subflow
539b08fbf24SPaolo Abenireset
540b08fbf24SPaolo Abeniip netns exec $ns1 ./pm_nl_ctl limits 0 1
541b08fbf24SPaolo Abeniip netns exec $ns2 ./pm_nl_ctl limits 0 1
542b08fbf24SPaolo Abeniip netns exec $ns2 ./pm_nl_ctl add 10.0.3.2 flags subflow
543b08fbf24SPaolo Abenirun_tests $ns1 $ns2 10.0.1.1
544b08fbf24SPaolo Abenichk_join_nr "single subflow" 1 1 1
545b08fbf24SPaolo Abeni
546b08fbf24SPaolo Abeni# multiple subflows
547b08fbf24SPaolo Abenireset
548b08fbf24SPaolo Abeniip netns exec $ns1 ./pm_nl_ctl limits 0 2
549b08fbf24SPaolo Abeniip netns exec $ns2 ./pm_nl_ctl limits 0 2
550b08fbf24SPaolo Abeniip netns exec $ns2 ./pm_nl_ctl add 10.0.3.2 flags subflow
551b08fbf24SPaolo Abeniip netns exec $ns2 ./pm_nl_ctl add 10.0.2.2 flags subflow
552b08fbf24SPaolo Abenirun_tests $ns1 $ns2 10.0.1.1
553b08fbf24SPaolo Abenichk_join_nr "multiple subflows" 2 2 2
554b08fbf24SPaolo Abeni
555b08fbf24SPaolo Abeni# multiple subflows limited by serverf
556b08fbf24SPaolo Abenireset
557b08fbf24SPaolo Abeniip netns exec $ns1 ./pm_nl_ctl limits 0 1
558b08fbf24SPaolo Abeniip netns exec $ns2 ./pm_nl_ctl limits 0 2
559b08fbf24SPaolo Abeniip netns exec $ns2 ./pm_nl_ctl add 10.0.3.2 flags subflow
560b08fbf24SPaolo Abeniip netns exec $ns2 ./pm_nl_ctl add 10.0.2.2 flags subflow
561b08fbf24SPaolo Abenirun_tests $ns1 $ns2 10.0.1.1
562b08fbf24SPaolo Abenichk_join_nr "multiple subflows, limited by server" 2 2 1
563b08fbf24SPaolo Abeni
564b08fbf24SPaolo Abeni# add_address, unused
565b08fbf24SPaolo Abenireset
566b08fbf24SPaolo Abeniip netns exec $ns1 ./pm_nl_ctl add 10.0.2.1 flags signal
567b08fbf24SPaolo Abenirun_tests $ns1 $ns2 10.0.1.1
568b08fbf24SPaolo Abenichk_join_nr "unused signal address" 0 0 0
569be613160SGeliang Tangchk_add_nr 1 1
570b08fbf24SPaolo Abeni
571b08fbf24SPaolo Abeni# accept and use add_addr
572b08fbf24SPaolo Abenireset
573b08fbf24SPaolo Abeniip netns exec $ns1 ./pm_nl_ctl limits 0 1
574b08fbf24SPaolo Abeniip netns exec $ns2 ./pm_nl_ctl limits 1 1
575b08fbf24SPaolo Abeniip netns exec $ns1 ./pm_nl_ctl add 10.0.2.1 flags signal
576b08fbf24SPaolo Abenirun_tests $ns1 $ns2 10.0.1.1
577b08fbf24SPaolo Abenichk_join_nr "signal address" 1 1 1
578be613160SGeliang Tangchk_add_nr 1 1
579b08fbf24SPaolo Abeni
580b08fbf24SPaolo Abeni# accept and use add_addr with an additional subflow
581b08fbf24SPaolo Abeni# note: signal address in server ns and local addresses in client ns must
582b08fbf24SPaolo Abeni# belong to different subnets or one of the listed local address could be
583b08fbf24SPaolo Abeni# used for 'add_addr' subflow
584b08fbf24SPaolo Abenireset
585b08fbf24SPaolo Abeniip netns exec $ns1 ./pm_nl_ctl add 10.0.2.1 flags signal
586b08fbf24SPaolo Abeniip netns exec $ns1 ./pm_nl_ctl limits 0 2
587b08fbf24SPaolo Abeniip netns exec $ns2 ./pm_nl_ctl limits 1 2
588b08fbf24SPaolo Abeniip netns exec $ns2 ./pm_nl_ctl add 10.0.3.2 flags subflow
589b08fbf24SPaolo Abenirun_tests $ns1 $ns2 10.0.1.1
590b08fbf24SPaolo Abenichk_join_nr "subflow and signal" 2 2 2
591be613160SGeliang Tangchk_add_nr 1 1
592b08fbf24SPaolo Abeni
593b08fbf24SPaolo Abeni# accept and use add_addr with additional subflows
594b08fbf24SPaolo Abenireset
595b08fbf24SPaolo Abeniip netns exec $ns1 ./pm_nl_ctl limits 0 3
596b08fbf24SPaolo Abeniip netns exec $ns1 ./pm_nl_ctl add 10.0.2.1 flags signal
597b08fbf24SPaolo Abeniip netns exec $ns2 ./pm_nl_ctl limits 1 3
598b08fbf24SPaolo Abeniip netns exec $ns2 ./pm_nl_ctl add 10.0.3.2 flags subflow
599b08fbf24SPaolo Abeniip netns exec $ns2 ./pm_nl_ctl add 10.0.4.2 flags subflow
600b08fbf24SPaolo Abenirun_tests $ns1 $ns2 10.0.1.1
601b08fbf24SPaolo Abenichk_join_nr "multiple subflows and signal" 3 3 3
602be613160SGeliang Tangchk_add_nr 1 1
603b08fbf24SPaolo Abeni
6048b819a84SFlorian Westphal# accept and use add_addr with additional subflows and link loss
6058b819a84SFlorian Westphalreset
6068b819a84SFlorian Westphalip netns exec $ns1 ./pm_nl_ctl limits 0 3
6078b819a84SFlorian Westphalip netns exec $ns1 ./pm_nl_ctl add 10.0.2.1 flags signal
6088b819a84SFlorian Westphalip netns exec $ns2 ./pm_nl_ctl limits 1 3
6098b819a84SFlorian Westphalip netns exec $ns2 ./pm_nl_ctl add 10.0.3.2 flags subflow
6108b819a84SFlorian Westphalip netns exec $ns2 ./pm_nl_ctl add 10.0.4.2 flags subflow
6118b819a84SFlorian Westphalrun_tests $ns1 $ns2 10.0.1.1 1
6128b819a84SFlorian Westphalchk_join_nr "multiple flows, signal, link failure" 3 3 3
6138b819a84SFlorian Westphalchk_add_nr 1 1
6148b819a84SFlorian Westphal
6158d014eaaSGeliang Tang# add_addr timeout
6168d014eaaSGeliang Tangreset_with_add_addr_timeout
6178d014eaaSGeliang Tangip netns exec $ns1 ./pm_nl_ctl limits 0 1
6188d014eaaSGeliang Tangip netns exec $ns2 ./pm_nl_ctl limits 1 1
6198d014eaaSGeliang Tangip netns exec $ns1 ./pm_nl_ctl add 10.0.2.1 flags signal
6208b819a84SFlorian Westphalrun_tests $ns1 $ns2 10.0.1.1 0 0 0 slow
6218d014eaaSGeliang Tangchk_join_nr "signal address, ADD_ADDR timeout" 1 1 1
6228d014eaaSGeliang Tangchk_add_nr 4 0
6238d014eaaSGeliang Tang
624dd72b0feSGeliang Tang# single subflow, remove
625dd72b0feSGeliang Tangreset
626dd72b0feSGeliang Tangip netns exec $ns1 ./pm_nl_ctl limits 0 1
627dd72b0feSGeliang Tangip netns exec $ns2 ./pm_nl_ctl limits 0 1
628dd72b0feSGeliang Tangip netns exec $ns2 ./pm_nl_ctl add 10.0.3.2 flags subflow
6298b819a84SFlorian Westphalrun_tests $ns1 $ns2 10.0.1.1 0 0 1 slow
630dd72b0feSGeliang Tangchk_join_nr "remove single subflow" 1 1 1
631dd72b0feSGeliang Tangchk_rm_nr 1 1
632dd72b0feSGeliang Tang
633dd72b0feSGeliang Tang# multiple subflows, remove
634dd72b0feSGeliang Tangreset
635dd72b0feSGeliang Tangip netns exec $ns1 ./pm_nl_ctl limits 0 2
636dd72b0feSGeliang Tangip netns exec $ns2 ./pm_nl_ctl limits 0 2
637dd72b0feSGeliang Tangip netns exec $ns2 ./pm_nl_ctl add 10.0.2.2 flags subflow
638dd72b0feSGeliang Tangip netns exec $ns2 ./pm_nl_ctl add 10.0.3.2 flags subflow
6398b819a84SFlorian Westphalrun_tests $ns1 $ns2 10.0.1.1 0 0 2 slow
640dd72b0feSGeliang Tangchk_join_nr "remove multiple subflows" 2 2 2
641dd72b0feSGeliang Tangchk_rm_nr 2 2
642dd72b0feSGeliang Tang
643dd72b0feSGeliang Tang# single address, remove
644dd72b0feSGeliang Tangreset
645dd72b0feSGeliang Tangip netns exec $ns1 ./pm_nl_ctl limits 0 1
646dd72b0feSGeliang Tangip netns exec $ns1 ./pm_nl_ctl add 10.0.2.1 flags signal
647dd72b0feSGeliang Tangip netns exec $ns2 ./pm_nl_ctl limits 1 1
6488b819a84SFlorian Westphalrun_tests $ns1 $ns2 10.0.1.1 0 1 0 slow
649dd72b0feSGeliang Tangchk_join_nr "remove single address" 1 1 1
650dd72b0feSGeliang Tangchk_add_nr 1 1
651dd72b0feSGeliang Tangchk_rm_nr 0 0
652dd72b0feSGeliang Tang
653dd72b0feSGeliang Tang# subflow and signal, remove
654dd72b0feSGeliang Tangreset
655dd72b0feSGeliang Tangip netns exec $ns1 ./pm_nl_ctl limits 0 2
656dd72b0feSGeliang Tangip netns exec $ns1 ./pm_nl_ctl add 10.0.2.1 flags signal
657dd72b0feSGeliang Tangip netns exec $ns2 ./pm_nl_ctl limits 1 2
658dd72b0feSGeliang Tangip netns exec $ns2 ./pm_nl_ctl add 10.0.3.2 flags subflow
6598b819a84SFlorian Westphalrun_tests $ns1 $ns2 10.0.1.1 0 1 1 slow
660dd72b0feSGeliang Tangchk_join_nr "remove subflow and signal" 2 2 2
661dd72b0feSGeliang Tangchk_add_nr 1 1
662dd72b0feSGeliang Tangchk_rm_nr 1 1
663dd72b0feSGeliang Tang
664dd72b0feSGeliang Tang# subflows and signal, remove
665dd72b0feSGeliang Tangreset
666dd72b0feSGeliang Tangip netns exec $ns1 ./pm_nl_ctl limits 0 3
667dd72b0feSGeliang Tangip netns exec $ns1 ./pm_nl_ctl add 10.0.2.1 flags signal
668dd72b0feSGeliang Tangip netns exec $ns2 ./pm_nl_ctl limits 1 3
669dd72b0feSGeliang Tangip netns exec $ns2 ./pm_nl_ctl add 10.0.3.2 flags subflow
670dd72b0feSGeliang Tangip netns exec $ns2 ./pm_nl_ctl add 10.0.4.2 flags subflow
6718b819a84SFlorian Westphalrun_tests $ns1 $ns2 10.0.1.1 0 1 2 slow
672dd72b0feSGeliang Tangchk_join_nr "remove subflows and signal" 3 3 3
673dd72b0feSGeliang Tangchk_add_nr 1 1
674dd72b0feSGeliang Tangchk_rm_nr 2 2
675dd72b0feSGeliang Tang
676*6fe4ccdcSGeliang Tang# subflows and signal, flush
677*6fe4ccdcSGeliang Tangreset
678*6fe4ccdcSGeliang Tangip netns exec $ns1 ./pm_nl_ctl limits 0 3
679*6fe4ccdcSGeliang Tangip netns exec $ns1 ./pm_nl_ctl add 10.0.2.1 flags signal
680*6fe4ccdcSGeliang Tangip netns exec $ns2 ./pm_nl_ctl limits 1 3
681*6fe4ccdcSGeliang Tangip netns exec $ns2 ./pm_nl_ctl add 10.0.3.2 flags subflow
682*6fe4ccdcSGeliang Tangip netns exec $ns2 ./pm_nl_ctl add 10.0.4.2 flags subflow
683*6fe4ccdcSGeliang Tangrun_tests $ns1 $ns2 10.0.1.1 0 8 8 slow
684*6fe4ccdcSGeliang Tangchk_join_nr "flush subflows and signal" 3 3 3
685*6fe4ccdcSGeliang Tangchk_add_nr 1 1
686*6fe4ccdcSGeliang Tangchk_rm_nr 2 2
687*6fe4ccdcSGeliang Tang
688523514edSGeliang Tang# subflow IPv6
689523514edSGeliang Tangreset
690523514edSGeliang Tangip netns exec $ns1 ./pm_nl_ctl limits 0 1
691523514edSGeliang Tangip netns exec $ns2 ./pm_nl_ctl limits 0 1
692523514edSGeliang Tangip netns exec $ns2 ./pm_nl_ctl add dead:beef:3::2 flags subflow
693523514edSGeliang Tangrun_tests $ns1 $ns2 dead:beef:1::1 0 0 0 slow
694523514edSGeliang Tangchk_join_nr "single subflow IPv6" 1 1 1
695523514edSGeliang Tang
696523514edSGeliang Tang# add_address, unused IPv6
697523514edSGeliang Tangreset
698523514edSGeliang Tangip netns exec $ns1 ./pm_nl_ctl add dead:beef:2::1 flags signal
699523514edSGeliang Tangrun_tests $ns1 $ns2 dead:beef:1::1 0 0 0 slow
700523514edSGeliang Tangchk_join_nr "unused signal address IPv6" 0 0 0
701523514edSGeliang Tangchk_add_nr 1 1
702523514edSGeliang Tang
703523514edSGeliang Tang# signal address IPv6
704523514edSGeliang Tangreset
705523514edSGeliang Tangip netns exec $ns1 ./pm_nl_ctl limits 0 1
706523514edSGeliang Tangip netns exec $ns1 ./pm_nl_ctl add dead:beef:2::1 flags signal
707523514edSGeliang Tangip netns exec $ns2 ./pm_nl_ctl limits 1 1
708523514edSGeliang Tangrun_tests $ns1 $ns2 dead:beef:1::1 0 0 0 slow
709523514edSGeliang Tangchk_join_nr "single address IPv6" 1 1 1
710523514edSGeliang Tangchk_add_nr 1 1
711523514edSGeliang Tang
712523514edSGeliang Tang# add_addr timeout IPv6
713523514edSGeliang Tangreset_with_add_addr_timeout 6
714523514edSGeliang Tangip netns exec $ns1 ./pm_nl_ctl limits 0 1
715523514edSGeliang Tangip netns exec $ns2 ./pm_nl_ctl limits 1 1
716523514edSGeliang Tangip netns exec $ns1 ./pm_nl_ctl add dead:beef:2::1 flags signal
717523514edSGeliang Tangrun_tests $ns1 $ns2 dead:beef:1::1 0 0 0 slow
718523514edSGeliang Tangchk_join_nr "signal address, ADD_ADDR6 timeout" 1 1 1
719523514edSGeliang Tangchk_add_nr 4 0
720523514edSGeliang Tang
721523514edSGeliang Tang# single address IPv6, remove
722523514edSGeliang Tangreset
723523514edSGeliang Tangip netns exec $ns1 ./pm_nl_ctl limits 0 1
724523514edSGeliang Tangip netns exec $ns1 ./pm_nl_ctl add dead:beef:2::1 flags signal
725523514edSGeliang Tangip netns exec $ns2 ./pm_nl_ctl limits 1 1
726523514edSGeliang Tangrun_tests $ns1 $ns2 dead:beef:1::1 0 1 0 slow
727523514edSGeliang Tangchk_join_nr "remove single address IPv6" 1 1 1
728523514edSGeliang Tangchk_add_nr 1 1
729523514edSGeliang Tangchk_rm_nr 0 0
730523514edSGeliang Tang
731523514edSGeliang Tang# subflow and signal IPv6, remove
732523514edSGeliang Tangreset
733523514edSGeliang Tangip netns exec $ns1 ./pm_nl_ctl limits 0 2
734523514edSGeliang Tangip netns exec $ns1 ./pm_nl_ctl add dead:beef:2::1 flags signal
735523514edSGeliang Tangip netns exec $ns2 ./pm_nl_ctl limits 1 2
736523514edSGeliang Tangip netns exec $ns2 ./pm_nl_ctl add dead:beef:3::2 flags subflow
737523514edSGeliang Tangrun_tests $ns1 $ns2 dead:beef:1::1 0 1 1 slow
738523514edSGeliang Tangchk_join_nr "remove subflow and signal IPv6" 2 2 2
739523514edSGeliang Tangchk_add_nr 1 1
740523514edSGeliang Tangchk_rm_nr 1 1
741523514edSGeliang Tang
74200587187SFlorian Westphal# single subflow, syncookies
74300587187SFlorian Westphalreset_with_cookies
74400587187SFlorian Westphalip netns exec $ns1 ./pm_nl_ctl limits 0 1
74500587187SFlorian Westphalip netns exec $ns2 ./pm_nl_ctl limits 0 1
74600587187SFlorian Westphalip netns exec $ns2 ./pm_nl_ctl add 10.0.3.2 flags subflow
74700587187SFlorian Westphalrun_tests $ns1 $ns2 10.0.1.1
74800587187SFlorian Westphalchk_join_nr "single subflow with syn cookies" 1 1 1
74900587187SFlorian Westphal
75000587187SFlorian Westphal# multiple subflows with syn cookies
75100587187SFlorian Westphalreset_with_cookies
75200587187SFlorian Westphalip netns exec $ns1 ./pm_nl_ctl limits 0 2
75300587187SFlorian Westphalip netns exec $ns2 ./pm_nl_ctl limits 0 2
75400587187SFlorian Westphalip netns exec $ns2 ./pm_nl_ctl add 10.0.3.2 flags subflow
75500587187SFlorian Westphalip netns exec $ns2 ./pm_nl_ctl add 10.0.2.2 flags subflow
75600587187SFlorian Westphalrun_tests $ns1 $ns2 10.0.1.1
75700587187SFlorian Westphalchk_join_nr "multiple subflows with syn cookies" 2 2 2
75800587187SFlorian Westphal
75900587187SFlorian Westphal# multiple subflows limited by server
76000587187SFlorian Westphalreset_with_cookies
76100587187SFlorian Westphalip netns exec $ns1 ./pm_nl_ctl limits 0 1
76200587187SFlorian Westphalip netns exec $ns2 ./pm_nl_ctl limits 0 2
76300587187SFlorian Westphalip netns exec $ns2 ./pm_nl_ctl add 10.0.3.2 flags subflow
76400587187SFlorian Westphalip netns exec $ns2 ./pm_nl_ctl add 10.0.2.2 flags subflow
76500587187SFlorian Westphalrun_tests $ns1 $ns2 10.0.1.1
76600587187SFlorian Westphalchk_join_nr "subflows limited by server w cookies" 2 2 1
76700587187SFlorian Westphal
76800587187SFlorian Westphal# test signal address with cookies
76900587187SFlorian Westphalreset_with_cookies
77000587187SFlorian Westphalip netns exec $ns1 ./pm_nl_ctl limits 0 1
77100587187SFlorian Westphalip netns exec $ns2 ./pm_nl_ctl limits 1 1
77200587187SFlorian Westphalip netns exec $ns1 ./pm_nl_ctl add 10.0.2.1 flags signal
77300587187SFlorian Westphalrun_tests $ns1 $ns2 10.0.1.1
77400587187SFlorian Westphalchk_join_nr "signal address with syn cookies" 1 1 1
775be613160SGeliang Tangchk_add_nr 1 1
77600587187SFlorian Westphal
77700587187SFlorian Westphal# test cookie with subflow and signal
77800587187SFlorian Westphalreset_with_cookies
77900587187SFlorian Westphalip netns exec $ns1 ./pm_nl_ctl add 10.0.2.1 flags signal
78000587187SFlorian Westphalip netns exec $ns1 ./pm_nl_ctl limits 0 2
78100587187SFlorian Westphalip netns exec $ns2 ./pm_nl_ctl limits 1 2
78200587187SFlorian Westphalip netns exec $ns2 ./pm_nl_ctl add 10.0.3.2 flags subflow
78300587187SFlorian Westphalrun_tests $ns1 $ns2 10.0.1.1
78400587187SFlorian Westphalchk_join_nr "subflow and signal w cookies" 2 2 2
785be613160SGeliang Tangchk_add_nr 1 1
78600587187SFlorian Westphal
78700587187SFlorian Westphal# accept and use add_addr with additional subflows
78800587187SFlorian Westphalreset_with_cookies
78900587187SFlorian Westphalip netns exec $ns1 ./pm_nl_ctl limits 0 3
79000587187SFlorian Westphalip netns exec $ns1 ./pm_nl_ctl add 10.0.2.1 flags signal
79100587187SFlorian Westphalip netns exec $ns2 ./pm_nl_ctl limits 1 3
79200587187SFlorian Westphalip netns exec $ns2 ./pm_nl_ctl add 10.0.3.2 flags subflow
79300587187SFlorian Westphalip netns exec $ns2 ./pm_nl_ctl add 10.0.4.2 flags subflow
79400587187SFlorian Westphalrun_tests $ns1 $ns2 10.0.1.1
79500587187SFlorian Westphalchk_join_nr "subflows and signal w. cookies" 3 3 3
796be613160SGeliang Tangchk_add_nr 1 1
79700587187SFlorian Westphal
798b08fbf24SPaolo Abeniexit $ret
799