2 # SPDX-License-Identifier: GPL-2.0
11 timeout_test=$((timeout_poll * 2 + 1))
15 rndh=$(printf %x $sec)-$(mktemp -u XXXXXX)
18 ns_sbox="ns_sbox-$rndh"
26 for t in iptables ip6tables; do
27 # just to debug: check we have multiple subflows connection requests
28 ip netns exec $ns $t -A OUTPUT -p tcp --syn -m mark --mark $m -j ACCEPT
30 # RST packets might be handled by a internal dummy socket
31 ip netns exec $ns $t -A OUTPUT -p tcp --tcp-flags RST RST -m mark --mark 0 -j ACCEPT
33 ip netns exec $ns $t -A OUTPUT -p tcp -m mark --mark $m -j ACCEPT
34 ip netns exec $ns $t -A OUTPUT -p tcp -m mark --mark 0 -j DROP
41 for netns in "$ns1" "$ns2" "$ns_sbox";do
42 ip netns add $netns || exit $ksft_skip
43 ip -net $netns link set lo up
44 ip netns exec $netns sysctl -q net.mptcp.enabled=1
45 ip netns exec $netns sysctl -q net.ipv4.conf.all.rp_filter=0
46 ip netns exec $netns sysctl -q net.ipv4.conf.default.rp_filter=0
50 for i in `seq 1 4`; do
51 ip link add ns1eth$i netns "$ns1" type veth peer name ns2eth$i netns "$ns2"
52 ip -net "$ns1" addr add 10.0.$i.1/24 dev ns1eth$i
53 ip -net "$ns1" addr add dead:beef:$i::1/64 dev ns1eth$i nodad
54 ip -net "$ns1" link set ns1eth$i up
56 ip -net "$ns2" addr add 10.0.$i.2/24 dev ns2eth$i
57 ip -net "$ns2" addr add dead:beef:$i::2/64 dev ns2eth$i nodad
58 ip -net "$ns2" link set ns2eth$i up
60 # let $ns2 reach any $ns1 address from any interface
61 ip -net "$ns2" route add default via 10.0.$i.1 dev ns2eth$i metric 10$i
63 ip netns exec $ns1 ./pm_nl_ctl add 10.0.$i.1 flags signal
64 ip netns exec $ns1 ./pm_nl_ctl add dead:beef:$i::1 flags signal
66 ip netns exec $ns2 ./pm_nl_ctl add 10.0.$i.2 flags signal
67 ip netns exec $ns2 ./pm_nl_ctl add dead:beef:$i::2 flags signal
70 ip netns exec $ns1 ./pm_nl_ctl limits 8 8
71 ip netns exec $ns2 ./pm_nl_ctl limits 8 8
80 for netns in "$ns1" "$ns2" "$ns_sbox"; do
87 ip -Version > /dev/null 2>&1
89 echo "SKIP: Could not run test without ip tool"
93 iptables -V > /dev/null 2>&1
95 echo "SKIP: Could not run all tests without iptables tool"
99 ip6tables -V > /dev/null 2>&1
101 echo "SKIP: Could not run all tests without ip6tables tool"
110 local tables=iptables
112 if [ $af -eq 6 ];then
116 local counters values
117 counters=$(ip netns exec $ns $tables -v -L OUTPUT | grep DROP)
118 values=${counters%DROP*}
122 if [ $v -ne 0 ]; then
123 echo "FAIL: got $tables $values in ns $ns , not 0 - not all expected packets marked" 1>&2
134 echo "Trailing bytes are: "
144 cmp "$in" "$out" > /dev/null 2>&1
145 if [ $? -ne 0 ] ;then
146 echo "[ FAIL ] $what does not match (in, out):"
148 print_file_err "$out"
165 local listener_ns="$1"
166 local connector_ns="$2"
169 local connect_addr="$5"
176 local mptcp_connect="./mptcp_connect -r 20"
179 if is_v6 "${connect_addr}"; then
185 timeout ${timeout_test} \
186 ip netns exec ${listener_ns} \
187 $mptcp_connect -t ${timeout_poll} -l -M 1 -p $port -s ${srv_proto} -c TIMESTAMPNS,TCPINQ \
188 ${local_addr} < "$sin" > "$sout" &
193 timeout ${timeout_test} \
194 ip netns exec ${connector_ns} \
195 $mptcp_connect -t ${timeout_poll} -M 2 -p $port -s ${cl_proto} -c TIMESTAMPNS,TCPINQ \
196 $connect_addr < "$cin" > "$cout" &
205 if [ ${rets} -ne 0 ] || [ ${retc} -ne 0 ]; then
206 echo " client exit code $retc, server $rets" 1>&2
207 echo -e "\nnetns ${listener_ns} socket stat for ${port}:" 1>&2
208 ip netns exec ${listener_ns} ss -Menita 1>&2 -o "sport = :$port"
210 echo -e "\nnetns ${connector_ns} socket stat for ${port}:" 1>&2
211 ip netns exec ${connector_ns} ss -Menita 1>&2 -o "dport = :$port"
217 if [ $local_addr = "::" ];then
218 check_mark $listener_ns 6
219 check_mark $connector_ns 6
221 check_mark $listener_ns 4
222 check_mark $connector_ns 4
225 check_transfer $cin $sout "file received by server"
229 if [ $retc -eq 0 ] && [ $rets -eq 0 ];then
242 dd if=/dev/urandom of="$name" bs=1024 count=$size 2> /dev/null
243 echo -e "\nMPTCP_TEST_FILE_END_MARKER" >> "$name"
245 echo "Created $name (size $size KB) containing data sent by $who"
248 do_mptcp_sockopt_tests()
252 ip netns exec "$ns_sbox" ./mptcp_sockopt
255 if [ $lret -ne 0 ]; then
256 echo "FAIL: SOL_MPTCP getsockopt" 1>&2
261 ip netns exec "$ns_sbox" ./mptcp_sockopt -6
264 if [ $lret -ne 0 ]; then
265 echo "FAIL: SOL_MPTCP getsockopt (ipv6)" 1>&2
273 local listener_ns="$1"
274 local connector_ns="$2"
275 local connect_addr="$3"
278 do_transfer ${listener_ns} ${connector_ns} MPTCP MPTCP ${connect_addr}
282 if [ $lret -ne 0 ]; then
290 ip netns exec "$ns_sbox" ./mptcp_inq "$@"
292 if [ $lret -ne 0 ];then
294 echo "FAIL: mptcp_inq $@" 1>&2
298 echo "PASS: TCP_INQ cmsg/ioctl $@"
307 for args in "-t tcp" "-r tcp"; do
310 if [ $lret -ne 0 ] ; then
313 do_tcpinq_test -6 $args
315 if [ $lret -ne 0 ] ; then
320 do_tcpinq_test -r tcp -t tcp
330 make_file "$cin" "client" 1
331 make_file "$sin" "server" 1
334 run_tests $ns1 $ns2 10.0.1.1
335 run_tests $ns1 $ns2 dead:beef:1::1
337 if [ $ret -eq 0 ];then
338 echo "PASS: all packets had packet mark set"
341 do_mptcp_sockopt_tests
342 if [ $ret -eq 0 ];then
343 echo "PASS: SOL_MPTCP getsockopt has expected information"