2 # SPDX-License-Identifier: GPL-2.0
4 . "$(dirname "${0}")/mptcp_lib.sh"
13 timeout_test=$((timeout_poll * 2 + 1))
17 rndh=$(printf %x $sec)-$(mktemp -u XXXXXX)
20 ns_sbox="ns_sbox-$rndh"
28 for t in iptables ip6tables; do
29 # just to debug: check we have multiple subflows connection requests
30 ip netns exec $ns $t -A OUTPUT -p tcp --syn -m mark --mark $m -j ACCEPT
32 # RST packets might be handled by a internal dummy socket
33 ip netns exec $ns $t -A OUTPUT -p tcp --tcp-flags RST RST -m mark --mark 0 -j ACCEPT
35 ip netns exec $ns $t -A OUTPUT -p tcp -m mark --mark $m -j ACCEPT
36 ip netns exec $ns $t -A OUTPUT -p tcp -m mark --mark 0 -j DROP
43 for netns in "$ns1" "$ns2" "$ns_sbox";do
44 ip netns add $netns || exit $ksft_skip
45 ip -net $netns link set lo up
46 ip netns exec $netns sysctl -q net.mptcp.enabled=1
47 ip netns exec $netns sysctl -q net.ipv4.conf.all.rp_filter=0
48 ip netns exec $netns sysctl -q net.ipv4.conf.default.rp_filter=0
52 for i in `seq 1 4`; do
53 ip link add ns1eth$i netns "$ns1" type veth peer name ns2eth$i netns "$ns2"
54 ip -net "$ns1" addr add 10.0.$i.1/24 dev ns1eth$i
55 ip -net "$ns1" addr add dead:beef:$i::1/64 dev ns1eth$i nodad
56 ip -net "$ns1" link set ns1eth$i up
58 ip -net "$ns2" addr add 10.0.$i.2/24 dev ns2eth$i
59 ip -net "$ns2" addr add dead:beef:$i::2/64 dev ns2eth$i nodad
60 ip -net "$ns2" link set ns2eth$i up
62 # let $ns2 reach any $ns1 address from any interface
63 ip -net "$ns2" route add default via 10.0.$i.1 dev ns2eth$i metric 10$i
65 ip netns exec $ns1 ./pm_nl_ctl add 10.0.$i.1 flags signal
66 ip netns exec $ns1 ./pm_nl_ctl add dead:beef:$i::1 flags signal
68 ip netns exec $ns2 ./pm_nl_ctl add 10.0.$i.2 flags signal
69 ip netns exec $ns2 ./pm_nl_ctl add dead:beef:$i::2 flags signal
72 ip netns exec $ns1 ./pm_nl_ctl limits 8 8
73 ip netns exec $ns2 ./pm_nl_ctl limits 8 8
82 for netns in "$ns1" "$ns2" "$ns_sbox"; do
91 ip -Version > /dev/null 2>&1
93 echo "SKIP: Could not run test without ip tool"
97 iptables -V > /dev/null 2>&1
99 echo "SKIP: Could not run all tests without iptables tool"
103 ip6tables -V > /dev/null 2>&1
105 echo "SKIP: Could not run all tests without ip6tables tool"
114 local tables=iptables
116 if [ $af -eq 6 ];then
120 local counters values
121 counters=$(ip netns exec $ns $tables -v -L OUTPUT | grep DROP)
122 values=${counters%DROP*}
126 if [ $v -ne 0 ]; then
127 echo "FAIL: got $tables $values in ns $ns , not 0 - not all expected packets marked" 1>&2
138 echo "Trailing bytes are: "
148 cmp "$in" "$out" > /dev/null 2>&1
149 if [ $? -ne 0 ] ;then
150 echo "[ FAIL ] $what does not match (in, out):"
152 print_file_err "$out"
169 local listener_ns="$1"
170 local connector_ns="$2"
173 local connect_addr="$5"
180 local mptcp_connect="./mptcp_connect -r 20"
183 if is_v6 "${connect_addr}"; then
189 timeout ${timeout_test} \
190 ip netns exec ${listener_ns} \
191 $mptcp_connect -t ${timeout_poll} -l -M 1 -p $port -s ${srv_proto} -c TIMESTAMPNS,TCPINQ \
192 ${local_addr} < "$sin" > "$sout" &
197 timeout ${timeout_test} \
198 ip netns exec ${connector_ns} \
199 $mptcp_connect -t ${timeout_poll} -M 2 -p $port -s ${cl_proto} -c TIMESTAMPNS,TCPINQ \
200 $connect_addr < "$cin" > "$cout" &
209 if [ ${rets} -ne 0 ] || [ ${retc} -ne 0 ]; then
210 echo " client exit code $retc, server $rets" 1>&2
211 echo -e "\nnetns ${listener_ns} socket stat for ${port}:" 1>&2
212 ip netns exec ${listener_ns} ss -Menita 1>&2 -o "sport = :$port"
214 echo -e "\nnetns ${connector_ns} socket stat for ${port}:" 1>&2
215 ip netns exec ${connector_ns} ss -Menita 1>&2 -o "dport = :$port"
221 if [ $local_addr = "::" ];then
222 check_mark $listener_ns 6
223 check_mark $connector_ns 6
225 check_mark $listener_ns 4
226 check_mark $connector_ns 4
229 check_transfer $cin $sout "file received by server"
233 if [ $retc -eq 0 ] && [ $rets -eq 0 ];then
246 dd if=/dev/urandom of="$name" bs=1024 count=$size 2> /dev/null
247 echo -e "\nMPTCP_TEST_FILE_END_MARKER" >> "$name"
249 echo "Created $name (size $size KB) containing data sent by $who"
252 do_mptcp_sockopt_tests()
256 ip netns exec "$ns_sbox" ./mptcp_sockopt
259 if [ $lret -ne 0 ]; then
260 echo "FAIL: SOL_MPTCP getsockopt" 1>&2
265 ip netns exec "$ns_sbox" ./mptcp_sockopt -6
268 if [ $lret -ne 0 ]; then
269 echo "FAIL: SOL_MPTCP getsockopt (ipv6)" 1>&2
277 local listener_ns="$1"
278 local connector_ns="$2"
279 local connect_addr="$3"
282 do_transfer ${listener_ns} ${connector_ns} MPTCP MPTCP ${connect_addr}
286 if [ $lret -ne 0 ]; then
294 ip netns exec "$ns_sbox" ./mptcp_inq "$@"
296 if [ $lret -ne 0 ];then
298 echo "FAIL: mptcp_inq $@" 1>&2
302 echo "PASS: TCP_INQ cmsg/ioctl $@"
311 for args in "-t tcp" "-r tcp"; do
314 if [ $lret -ne 0 ] ; then
317 do_tcpinq_test -6 $args
319 if [ $lret -ne 0 ] ; then
324 do_tcpinq_test -r tcp -t tcp
334 make_file "$cin" "client" 1
335 make_file "$sin" "server" 1
338 run_tests $ns1 $ns2 10.0.1.1
339 run_tests $ns1 $ns2 dead:beef:1::1
341 if [ $ret -eq 0 ];then
342 echo "PASS: all packets had packet mark set"
345 do_mptcp_sockopt_tests
346 if [ $ret -eq 0 ];then
347 echo "PASS: SOL_MPTCP getsockopt has expected information"