Skip to content

Commit 5afca7e

Browse files
Paolo Abenikuba-moo
authored andcommitted
selftests: mptcp: join: test for prohibited MPC to port-based endp
Explicitly verify that MPC connection attempts towards a port-based signal endpoint fail with a reset. Note that this new test is a bit different from the other ones, not using 'run_tests'. It is then needed to add the capture capability, and the picking the right port which have been extracted into three new helpers. The info about the capture can also be printed from a single point, which simplifies the exit paths in do_transfer(). The 'Fixes' tag here below is the same as the one from the previous commit: this patch here is not fixing anything wrong in the selftests, but it validates the previous fix for an issue introduced by this commit ID. Fixes: 1729cf1 ("mptcp: create the listening socket for new port") Cc: [email protected] Co-developed-by: Matthieu Baerts (NGI0) <[email protected]> Signed-off-by: Matthieu Baerts (NGI0) <[email protected]> Signed-off-by: Paolo Abeni <[email protected]> Reviewed-by: Mat Martineau <[email protected]> Signed-off-by: Matthieu Baerts (NGI0) <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 3d04139 commit 5afca7e

File tree

1 file changed

+85
-30
lines changed

1 file changed

+85
-30
lines changed

tools/testing/selftests/net/mptcp/mptcp_join.sh

Lines changed: 85 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ tmpfile=""
2323
cout=""
2424
err=""
2525
capout=""
26+
cappid=""
2627
ns1=""
2728
ns2=""
2829
iptables="iptables"
@@ -887,40 +888,62 @@ check_cestab()
887888
fi
888889
}
889890

890-
do_transfer()
891+
cond_start_capture()
891892
{
892-
local listener_ns="$1"
893-
local connector_ns="$2"
894-
local cl_proto="$3"
895-
local srv_proto="$4"
896-
local connect_addr="$5"
897-
898-
local port=$((10000 + MPTCP_LIB_TEST_COUNTER - 1))
899-
local cappid
900-
local FAILING_LINKS=${FAILING_LINKS:-""}
901-
local fastclose=${fastclose:-""}
902-
local speed=${speed:-"fast"}
893+
local ns="$1"
903894

904-
:> "$cout"
905-
:> "$sout"
906895
:> "$capout"
907896

908897
if $capture; then
909-
local capuser
910-
if [ -z $SUDO_USER ] ; then
898+
local capuser capfile
899+
if [ -z $SUDO_USER ]; then
911900
capuser=""
912901
else
913902
capuser="-Z $SUDO_USER"
914903
fi
915904

916-
capfile=$(printf "mp_join-%02u-%s.pcap" "$MPTCP_LIB_TEST_COUNTER" "${listener_ns}")
905+
capfile=$(printf "mp_join-%02u-%s.pcap" "$MPTCP_LIB_TEST_COUNTER" "$ns")
917906

918907
echo "Capturing traffic for test $MPTCP_LIB_TEST_COUNTER into $capfile"
919-
ip netns exec ${listener_ns} tcpdump -i any -s 65535 -B 32768 $capuser -w $capfile > "$capout" 2>&1 &
908+
ip netns exec "$ns" tcpdump -i any -s 65535 -B 32768 $capuser -w "$capfile" > "$capout" 2>&1 &
920909
cappid=$!
921910

922911
sleep 1
923912
fi
913+
}
914+
915+
cond_stop_capture()
916+
{
917+
if $capture; then
918+
sleep 1
919+
kill $cappid
920+
cat "$capout"
921+
fi
922+
}
923+
924+
get_port()
925+
{
926+
echo "$((10000 + MPTCP_LIB_TEST_COUNTER - 1))"
927+
}
928+
929+
do_transfer()
930+
{
931+
local listener_ns="$1"
932+
local connector_ns="$2"
933+
local cl_proto="$3"
934+
local srv_proto="$4"
935+
local connect_addr="$5"
936+
local port
937+
938+
local FAILING_LINKS=${FAILING_LINKS:-""}
939+
local fastclose=${fastclose:-""}
940+
local speed=${speed:-"fast"}
941+
port=$(get_port)
942+
943+
:> "$cout"
944+
:> "$sout"
945+
946+
cond_start_capture ${listener_ns}
924947

925948
NSTAT_HISTORY=/tmp/${listener_ns}.nstat ip netns exec ${listener_ns} \
926949
nstat -n
@@ -1007,10 +1030,7 @@ do_transfer()
10071030
wait $spid
10081031
local rets=$?
10091032

1010-
if $capture; then
1011-
sleep 1
1012-
kill $cappid
1013-
fi
1033+
cond_stop_capture
10141034

10151035
NSTAT_HISTORY=/tmp/${listener_ns}.nstat ip netns exec ${listener_ns} \
10161036
nstat | grep Tcp > /tmp/${listener_ns}.out
@@ -1026,7 +1046,6 @@ do_transfer()
10261046
ip netns exec ${connector_ns} ss -Menita 1>&2 -o "dport = :$port"
10271047
cat /tmp/${connector_ns}.out
10281048

1029-
cat "$capout"
10301049
return 1
10311050
fi
10321051

@@ -1043,13 +1062,7 @@ do_transfer()
10431062
fi
10441063
rets=$?
10451064

1046-
if [ $retc -eq 0 ] && [ $rets -eq 0 ];then
1047-
cat "$capout"
1048-
return 0
1049-
fi
1050-
1051-
cat "$capout"
1052-
return 1
1065+
[ $retc -eq 0 ] && [ $rets -eq 0 ]
10531066
}
10541067

10551068
make_file()
@@ -2873,6 +2886,32 @@ verify_listener_events()
28732886
fail_test
28742887
}
28752888

2889+
chk_mpc_endp_attempt()
2890+
{
2891+
local retl=$1
2892+
local attempts=$2
2893+
2894+
print_check "Connect"
2895+
2896+
if [ ${retl} = 124 ]; then
2897+
fail_test "timeout on connect"
2898+
elif [ ${retl} = 0 ]; then
2899+
fail_test "unexpected successful connect"
2900+
else
2901+
print_ok
2902+
2903+
print_check "Attempts"
2904+
count=$(mptcp_lib_get_counter ${ns1} "MPTcpExtMPCapableEndpAttempt")
2905+
if [ -z "$count" ]; then
2906+
print_skip
2907+
elif [ "$count" != "$attempts" ]; then
2908+
fail_test "got ${count} MPC attempt[s] on port-based endpoint, expected ${attempts}"
2909+
else
2910+
print_ok
2911+
fi
2912+
fi
2913+
}
2914+
28762915
add_addr_ports_tests()
28772916
{
28782917
# signal address with port
@@ -2963,6 +3002,22 @@ add_addr_ports_tests()
29633002
chk_join_nr 2 2 2
29643003
chk_add_nr 2 2 2
29653004
fi
3005+
3006+
if reset "port-based signal endpoint must not accept mpc"; then
3007+
local port retl count
3008+
port=$(get_port)
3009+
3010+
cond_start_capture ${ns1}
3011+
pm_nl_add_endpoint ${ns1} 10.0.2.1 flags signal port ${port}
3012+
mptcp_lib_wait_local_port_listen ${ns1} ${port}
3013+
3014+
timeout 1 ip netns exec ${ns2} \
3015+
./mptcp_connect -t ${timeout_poll} -p $port -s MPTCP 10.0.2.1 >/dev/null 2>&1
3016+
retl=$?
3017+
cond_stop_capture
3018+
3019+
chk_mpc_endp_attempt ${retl} 1
3020+
fi
29663021
}
29673022

29683023
syncookies_tests()

0 commit comments

Comments
 (0)