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
90 mptcp_lib_check_kallsyms
92 ip -Version > /dev/null 2>&1
94 echo "SKIP: Could not run test without ip tool"
98 iptables -V > /dev/null 2>&1
100 echo "SKIP: Could not run all tests without iptables tool"
104 ip6tables -V > /dev/null 2>&1
106 echo "SKIP: Could not run all tests without ip6tables tool"
115 local tables=iptables
117 if [ $af -eq 6 ];then
121 local counters values
122 counters=$(ip netns exec $ns $tables -v -L OUTPUT | grep DROP)
123 values=${counters%DROP*}
127 if [ $v -ne 0 ]; then
128 echo "FAIL: got $tables $values in ns $ns , not 0 - not all expected packets marked" 1>&2
139 echo "Trailing bytes are: "
149 cmp "$in" "$out" > /dev/null 2>&1
150 if [ $? -ne 0 ] ;then
151 echo "[ FAIL ] $what does not match (in, out):"
153 print_file_err "$out"
170 local listener_ns="$1"
171 local connector_ns="$2"
174 local connect_addr="$5"
181 local mptcp_connect="./mptcp_connect -r 20"
184 if is_v6 "${connect_addr}"; then
191 if mptcp_lib_kallsyms_has "mptcp_ioctl$"; then
195 timeout ${timeout_test} \
196 ip netns exec ${listener_ns} \
197 $mptcp_connect -t ${timeout_poll} -l -M 1 -p $port -s ${srv_proto} -c "${cmsg}" \
198 ${local_addr} < "$sin" > "$sout" &
203 timeout ${timeout_test} \
204 ip netns exec ${connector_ns} \
205 $mptcp_connect -t ${timeout_poll} -M 2 -p $port -s ${cl_proto} -c "${cmsg}" \
206 $connect_addr < "$cin" > "$cout" &
215 if [ ${rets} -ne 0 ] || [ ${retc} -ne 0 ]; then
216 echo " client exit code $retc, server $rets" 1>&2
217 echo -e "\nnetns ${listener_ns} socket stat for ${port}:" 1>&2
218 ip netns exec ${listener_ns} ss -Menita 1>&2 -o "sport = :$port"
220 echo -e "\nnetns ${connector_ns} socket stat for ${port}:" 1>&2
221 ip netns exec ${connector_ns} ss -Menita 1>&2 -o "dport = :$port"
227 if [ $local_addr = "::" ];then
228 check_mark $listener_ns 6
229 check_mark $connector_ns 6
231 check_mark $listener_ns 4
232 check_mark $connector_ns 4
235 check_transfer $cin $sout "file received by server"
239 if [ $retc -eq 0 ] && [ $rets -eq 0 ];then
252 dd if=/dev/urandom of="$name" bs=1024 count=$size 2> /dev/null
253 echo -e "\nMPTCP_TEST_FILE_END_MARKER" >> "$name"
255 echo "Created $name (size $size KB) containing data sent by $who"
258 do_mptcp_sockopt_tests()
262 if ! mptcp_lib_kallsyms_has "mptcp_diag_fill_info$"; then
263 echo "INFO: MPTCP sockopt not supported: SKIP"
267 ip netns exec "$ns_sbox" ./mptcp_sockopt
270 if [ $lret -ne 0 ]; then
271 echo "FAIL: SOL_MPTCP getsockopt" 1>&2
276 ip netns exec "$ns_sbox" ./mptcp_sockopt -6
279 if [ $lret -ne 0 ]; then
280 echo "FAIL: SOL_MPTCP getsockopt (ipv6)" 1>&2
288 local listener_ns="$1"
289 local connector_ns="$2"
290 local connect_addr="$3"
293 do_transfer ${listener_ns} ${connector_ns} MPTCP MPTCP ${connect_addr}
297 if [ $lret -ne 0 ]; then
305 ip netns exec "$ns_sbox" ./mptcp_inq "$@"
307 if [ $lret -ne 0 ];then
309 echo "FAIL: mptcp_inq $@" 1>&2
313 echo "PASS: TCP_INQ cmsg/ioctl $@"
321 if ! mptcp_lib_kallsyms_has "mptcp_ioctl$"; then
322 echo "INFO: TCP_INQ not supported: SKIP"
327 for args in "-t tcp" "-r tcp"; do
330 if [ $lret -ne 0 ] ; then
333 do_tcpinq_test -6 $args
335 if [ $lret -ne 0 ] ; then
340 do_tcpinq_test -r tcp -t tcp
350 make_file "$cin" "client" 1
351 make_file "$sin" "server" 1
354 run_tests $ns1 $ns2 10.0.1.1
355 run_tests $ns1 $ns2 dead:beef:1::1
357 if [ $ret -eq 0 ];then
358 echo "PASS: all packets had packet mark set"
361 do_mptcp_sockopt_tests
362 if [ $ret -eq 0 ];then
363 echo "PASS: SOL_MPTCP getsockopt has expected information"