2 # SPDX-License-Identifier: GPL-2.0
4 . "$(dirname "${0}")/mptcp_lib.sh"
7 rndh=$(printf %x $sec)-$(mktemp -u XXXXXX)
12 timeout_test=$((timeout_poll * 2 + 1))
17 # mptcp_connect in join mode will sleep a bit before completing,
21 ip netns pids "${ns}" | xargs --no-run-if-empty kill -SIGUSR1 &>/dev/null
23 for _ in $(seq 10); do
24 [ -z "$(ip netns pids "${ns}")" ] && break
31 ip netns pids "${ns}" | xargs --no-run-if-empty kill -SIGKILL &>/dev/null
38 ip -Version > /dev/null 2>&1
40 echo "SKIP: Could not run test without ip tool"
45 echo "SKIP: ss tool does not support MPTCP"
51 ip netns exec $ns cat /proc/net/protocols | awk '$1~/^MPTCP$/{print $3}'
59 local skip="${4:-SKIP}"
65 if [ $nr != $expected ]; then
66 if [ $nr = "$skip" ] && ! mptcp_lib_expect_all_features; then
67 echo "[ skip ] Feature probably not supported"
68 mptcp_lib_result_skip "${msg}"
70 echo "[ fail ] expected $expected found $nr"
71 mptcp_lib_result_fail "${msg}"
76 mptcp_lib_result_pass "${msg}"
78 test_cnt=$((test_cnt+1))
86 __chk_nr "ss -inmHMN $ns | $condition" "$@"
91 __chk_msk_nr "grep -c token:" "$@"
96 local condition="grep -c token:"
106 while [ $i -lt $timeout ]; do
107 nr=$(ss -inmHMN $ns | $condition)
108 [ $nr == $expected ] && break;
109 [ $nr -gt $max ] && max=$nr
114 printf "%-50s" "$msg"
115 if [ $i -ge $timeout ]; then
116 echo "[ fail ] timeout while expecting $expected max $max last $nr"
117 mptcp_lib_result_fail "${msg} # timeout"
119 elif [ $nr != $expected ]; then
120 echo "[ fail ] expected $expected found $nr"
121 mptcp_lib_result_fail "${msg} # unexpected result"
125 mptcp_lib_result_pass "${msg}"
127 test_cnt=$((test_cnt+1))
130 chk_msk_fallback_nr()
132 __chk_msk_nr "grep -c fallback" "$@"
135 chk_msk_remote_key_nr()
137 __chk_msk_nr "grep -c remote_key" "$@"
146 __chk_nr "ss -N $ns -Ml '$filter' | grep -c LISTEN" "$expected" "$msg" 0
153 # destination port search should always return empty list
154 __chk_listen "dport $lport" 0 "listen match for dport $lport"
156 # should return 'our' mptcp listen socket
157 __chk_listen "sport $lport" 1 "listen match for sport $lport"
159 __chk_listen "src inet:0.0.0.0:$lport" 1 "listen match for saddr and sport"
161 __chk_listen "" 1 "all listen sockets"
163 nr=$(ss -Ml $filter | wc -l)
172 listen_nr=$(ss -N "${ns}" -Ml | grep -c LISTEN)
173 expected=$((expected + listen_nr))
175 for _ in $(seq 10); do
176 if [ $(get_msk_inuse) -eq $expected ];then
182 __chk_nr get_msk_inuse $expected "$msg" 0
186 wait_local_port_listen()
188 local listener_ns="${1}"
193 port_hex="$(printf "%04X" "${port}")"
194 for i in $(seq 10); do
195 ip netns exec "${listener_ns}" cat /proc/net/tcp | \
196 awk "BEGIN {rc=1} {if (\$2 ~ /:${port_hex}\$/ && \$4 ~ /0A/) {rc=0; exit}} END {exit rc}" &&
204 local listener_ns="${1}"
209 port_hex="$(printf "%04X" "${port}")"
210 for i in $(seq 10); do
211 ip netns exec ${listener_ns} grep -q " 0100007F:${port_hex} " /proc/net/tcp && break
218 ip -n $ns link set dev lo up
221 timeout ${timeout_test} \
223 ./mptcp_connect -p 10000 -l -t ${timeout_poll} -w 20 \
225 wait_local_port_listen $ns 10000
226 chk_msk_nr 0 "no msk on netns creation"
230 timeout ${timeout_test} \
232 ./mptcp_connect -p 10000 -r 0 -t ${timeout_poll} -w 20 \
233 127.0.0.1 >/dev/null &
234 wait_connected $ns 10000
235 chk_msk_nr 2 "after MPC handshake "
236 chk_msk_remote_key_nr 2 "....chk remote_key"
237 chk_msk_fallback_nr 0 "....chk no fallback"
238 chk_msk_inuse 2 "....chk 2 msk in use"
241 chk_msk_inuse 0 "....chk 0 msk in use after flush"
244 timeout ${timeout_test} \
246 ./mptcp_connect -p 10001 -l -s TCP -t ${timeout_poll} -w 20 \
248 wait_local_port_listen $ns 10001
250 timeout ${timeout_test} \
252 ./mptcp_connect -p 10001 -r 0 -t ${timeout_poll} -w 20 \
253 127.0.0.1 >/dev/null &
254 wait_connected $ns 10001
255 chk_msk_fallback_nr 1 "check fallback"
256 chk_msk_inuse 1 "....chk 1 msk in use"
259 chk_msk_inuse 0 "....chk 0 msk in use after flush"
262 for I in `seq 1 $NR_CLIENTS`; do
264 timeout ${timeout_test} \
266 ./mptcp_connect -p $((I+10001)) -l -w 20 \
267 -t ${timeout_poll} 0.0.0.0 >/dev/null &
269 wait_local_port_listen $ns $((NR_CLIENTS + 10001))
271 for I in `seq 1 $NR_CLIENTS`; do
273 timeout ${timeout_test} \
275 ./mptcp_connect -p $((I+10001)) -w 20 \
276 -t ${timeout_poll} 127.0.0.1 >/dev/null &
279 wait_msk_nr $((NR_CLIENTS*2)) "many msk socket present"
280 chk_msk_inuse $((NR_CLIENTS*2)) "....chk many msk in use"
283 chk_msk_inuse 0 "....chk 0 msk in use after flush"
285 mptcp_lib_result_print_all_tap