2 # SPDX-License-Identifier: GPL-2.0
4 . "$(dirname "${0}")/mptcp_lib.sh"
13 timeout_test=$((timeout_poll * 2 + 1))
19 rndh=$(printf %x $sec)-$(mktemp -u XXXXXX)
22 ns_sbox="ns_sbox-$rndh"
30 for t in ${iptables} ${ip6tables}; do
31 # just to debug: check we have multiple subflows connection requests
32 ip netns exec $ns $t -A OUTPUT -p tcp --syn -m mark --mark $m -j ACCEPT
34 # RST packets might be handled by a internal dummy socket
35 ip netns exec $ns $t -A OUTPUT -p tcp --tcp-flags RST RST -m mark --mark 0 -j ACCEPT
37 ip netns exec $ns $t -A OUTPUT -p tcp -m mark --mark $m -j ACCEPT
38 ip netns exec $ns $t -A OUTPUT -p tcp -m mark --mark 0 -j DROP
45 for netns in "$ns1" "$ns2" "$ns_sbox";do
46 ip netns add $netns || exit $ksft_skip
47 ip -net $netns link set lo up
48 ip netns exec $netns sysctl -q net.mptcp.enabled=1
49 ip netns exec $netns sysctl -q net.ipv4.conf.all.rp_filter=0
50 ip netns exec $netns sysctl -q net.ipv4.conf.default.rp_filter=0
54 for i in `seq 1 4`; do
55 ip link add ns1eth$i netns "$ns1" type veth peer name ns2eth$i netns "$ns2"
56 ip -net "$ns1" addr add 10.0.$i.1/24 dev ns1eth$i
57 ip -net "$ns1" addr add dead:beef:$i::1/64 dev ns1eth$i nodad
58 ip -net "$ns1" link set ns1eth$i up
60 ip -net "$ns2" addr add 10.0.$i.2/24 dev ns2eth$i
61 ip -net "$ns2" addr add dead:beef:$i::2/64 dev ns2eth$i nodad
62 ip -net "$ns2" link set ns2eth$i up
64 # let $ns2 reach any $ns1 address from any interface
65 ip -net "$ns2" route add default via 10.0.$i.1 dev ns2eth$i metric 10$i
67 ip netns exec $ns1 ./pm_nl_ctl add 10.0.$i.1 flags signal
68 ip netns exec $ns1 ./pm_nl_ctl add dead:beef:$i::1 flags signal
70 ip netns exec $ns2 ./pm_nl_ctl add 10.0.$i.2 flags signal
71 ip netns exec $ns2 ./pm_nl_ctl add dead:beef:$i::2 flags signal
74 ip netns exec $ns1 ./pm_nl_ctl limits 8 8
75 ip netns exec $ns2 ./pm_nl_ctl limits 8 8
84 for netns in "$ns1" "$ns2" "$ns_sbox"; do
92 mptcp_lib_check_kallsyms
94 ip -Version > /dev/null 2>&1
96 echo "SKIP: Could not run test without ip tool"
100 # Use the legacy version if available to support old kernel versions
101 if iptables-legacy -V &> /dev/null; then
102 iptables="iptables-legacy"
103 ip6tables="ip6tables-legacy"
104 elif ! iptables -V &> /dev/null; then
105 echo "SKIP: Could not run all tests without iptables tool"
107 elif ! ip6tables -V &> /dev/null; then
108 echo "SKIP: Could not run all tests without ip6tables tool"
117 local tables=${iptables}
119 if [ $af -eq 6 ];then
123 local counters values
124 counters=$(ip netns exec $ns $tables -v -L OUTPUT | grep DROP)
125 values=${counters%DROP*}
129 if [ $v -ne 0 ]; then
130 echo "FAIL: got $tables $values in ns $ns , not 0 - not all expected packets marked" 1>&2
142 echo "Trailing bytes are: "
152 cmp "$in" "$out" > /dev/null 2>&1
153 if [ $? -ne 0 ] ;then
154 echo "[ FAIL ] $what does not match (in, out):"
156 print_file_err "$out"
173 local listener_ns="$1"
174 local connector_ns="$2"
177 local connect_addr="$5"
184 local mptcp_connect="./mptcp_connect -r 20"
187 if is_v6 "${connect_addr}"; then
194 if mptcp_lib_kallsyms_has "mptcp_ioctl$"; then
198 timeout ${timeout_test} \
199 ip netns exec ${listener_ns} \
200 $mptcp_connect -t ${timeout_poll} -l -M 1 -p $port -s ${srv_proto} -c "${cmsg}" \
201 ${local_addr} < "$sin" > "$sout" &
206 timeout ${timeout_test} \
207 ip netns exec ${connector_ns} \
208 $mptcp_connect -t ${timeout_poll} -M 2 -p $port -s ${cl_proto} -c "${cmsg}" \
209 $connect_addr < "$cin" > "$cout" &
218 if [ ${rets} -ne 0 ] || [ ${retc} -ne 0 ]; then
219 echo " client exit code $retc, server $rets" 1>&2
220 echo -e "\nnetns ${listener_ns} socket stat for ${port}:" 1>&2
221 ip netns exec ${listener_ns} ss -Menita 1>&2 -o "sport = :$port"
223 echo -e "\nnetns ${connector_ns} socket stat for ${port}:" 1>&2
224 ip netns exec ${connector_ns} ss -Menita 1>&2 -o "dport = :$port"
230 if [ $local_addr = "::" ];then
231 check_mark $listener_ns 6 || retc=1
232 check_mark $connector_ns 6 || retc=1
234 check_mark $listener_ns 4 || retc=1
235 check_mark $connector_ns 4 || retc=1
238 check_transfer $cin $sout "file received by server"
242 if [ $retc -eq 0 ] && [ $rets -eq 0 ];then
255 dd if=/dev/urandom of="$name" bs=1024 count=$size 2> /dev/null
256 echo -e "\nMPTCP_TEST_FILE_END_MARKER" >> "$name"
258 echo "Created $name (size $size KB) containing data sent by $who"
261 do_mptcp_sockopt_tests()
265 if ! mptcp_lib_kallsyms_has "mptcp_diag_fill_info$"; then
266 echo "INFO: MPTCP sockopt not supported: SKIP"
270 ip netns exec "$ns_sbox" ./mptcp_sockopt
273 if [ $lret -ne 0 ]; then
274 echo "FAIL: SOL_MPTCP getsockopt" 1>&2
279 ip netns exec "$ns_sbox" ./mptcp_sockopt -6
282 if [ $lret -ne 0 ]; then
283 echo "FAIL: SOL_MPTCP getsockopt (ipv6)" 1>&2
291 local listener_ns="$1"
292 local connector_ns="$2"
293 local connect_addr="$3"
296 do_transfer ${listener_ns} ${connector_ns} MPTCP MPTCP ${connect_addr}
300 if [ $lret -ne 0 ]; then
308 ip netns exec "$ns_sbox" ./mptcp_inq "$@"
310 if [ $lret -ne 0 ];then
312 echo "FAIL: mptcp_inq $@" 1>&2
316 echo "PASS: TCP_INQ cmsg/ioctl $@"
324 if ! mptcp_lib_kallsyms_has "mptcp_ioctl$"; then
325 echo "INFO: TCP_INQ not supported: SKIP"
330 for args in "-t tcp" "-r tcp"; do
333 if [ $lret -ne 0 ] ; then
336 do_tcpinq_test -6 $args
338 if [ $lret -ne 0 ] ; then
343 do_tcpinq_test -r tcp -t tcp
353 make_file "$cin" "client" 1
354 make_file "$sin" "server" 1
357 run_tests $ns1 $ns2 10.0.1.1
358 run_tests $ns1 $ns2 dead:beef:1::1
360 if [ $ret -eq 0 ];then
361 echo "PASS: all packets had packet mark set"
364 do_mptcp_sockopt_tests
365 if [ $ret -eq 0 ];then
366 echo "PASS: SOL_MPTCP getsockopt has expected information"