2 # SPDX-License-Identifier: GPL-2.0
4 rndh=$(printf %x $sec)-$(mktemp -u XXXXXX)
9 timeout_test=$((timeout_poll * 2 + 1))
14 # mptcp_connect in join mode will sleep a bit before completing,
18 ip netns pids "${ns}" | xargs --no-run-if-empty kill -SIGUSR1 &>/dev/null
23 ip netns pids "${ns}" | xargs --no-run-if-empty kill -SIGKILL &>/dev/null
28 ip -Version > /dev/null 2>&1
30 echo "SKIP: Could not run test without ip tool"
35 echo "SKIP: ss tool does not support MPTCP"
47 nr=$(ss -inmHMN $ns | $condition)
50 if [ $nr != $expected ]; then
51 echo "[ fail ] expected $expected found $nr"
56 test_cnt=$((test_cnt+1))
61 __chk_nr "grep -c token:" $*
66 local condition="grep -c token:"
76 while [ $i -lt $timeout ]; do
77 nr=$(ss -inmHMN $ns | $condition)
78 [ $nr == $expected ] && break;
79 [ $nr -gt $max ] && max=$nr
85 if [ $i -ge $timeout ]; then
86 echo "[ fail ] timeout while expecting $expected max $max last $nr"
88 elif [ $nr != $expected ]; then
89 echo "[ fail ] expected $expected found $nr"
94 test_cnt=$((test_cnt+1))
99 __chk_nr "grep -c fallback" $*
102 chk_msk_remote_key_nr()
104 __chk_nr "grep -c remote_key" $*
115 nr=$(ss -N $ns -Ml "$filter" | grep -c LISTEN)
116 printf "%-50s" "$msg"
118 if [ $nr != $expected ]; then
119 echo "[ fail ] expected $expected found $nr"
129 local msg="check for listen socket"
131 # destination port search should always return empty list
132 __chk_listen "dport $lport" 0 "listen match for dport $lport"
134 # should return 'our' mptcp listen socket
135 __chk_listen "sport $lport" 1 "listen match for sport $lport"
137 __chk_listen "src inet:0.0.0.0:$lport" 1 "listen match for saddr and sport"
139 __chk_listen "" 1 "all listen sockets"
141 nr=$(ss -Ml $filter | wc -l)
145 wait_local_port_listen()
147 local listener_ns="${1}"
152 port_hex="$(printf "%04X" "${port}")"
153 for i in $(seq 10); do
154 ip netns exec "${listener_ns}" cat /proc/net/tcp | \
155 awk "BEGIN {rc=1} {if (\$2 ~ /:${port_hex}\$/ && \$4 ~ /0A/) {rc=0; exit}} END {exit rc}" &&
163 local listener_ns="${1}"
168 port_hex="$(printf "%04X" "${port}")"
169 for i in $(seq 10); do
170 ip netns exec ${listener_ns} grep -q " 0100007F:${port_hex} " /proc/net/tcp && break
177 ip -n $ns link set dev lo up
180 timeout ${timeout_test} \
182 ./mptcp_connect -p 10000 -l -t ${timeout_poll} -w 20 \
184 wait_local_port_listen $ns 10000
185 chk_msk_nr 0 "no msk on netns creation"
189 timeout ${timeout_test} \
191 ./mptcp_connect -p 10000 -r 0 -t ${timeout_poll} -w 20 \
192 127.0.0.1 >/dev/null &
193 wait_connected $ns 10000
194 chk_msk_nr 2 "after MPC handshake "
195 chk_msk_remote_key_nr 2 "....chk remote_key"
196 chk_msk_fallback_nr 0 "....chk no fallback"
201 timeout ${timeout_test} \
203 ./mptcp_connect -p 10001 -l -s TCP -t ${timeout_poll} -w 20 \
205 wait_local_port_listen $ns 10001
207 timeout ${timeout_test} \
209 ./mptcp_connect -p 10001 -r 0 -t ${timeout_poll} -w 20 \
210 127.0.0.1 >/dev/null &
211 wait_connected $ns 10001
212 chk_msk_fallback_nr 1 "check fallback"
216 for I in `seq 1 $NR_CLIENTS`; do
218 timeout ${timeout_test} \
220 ./mptcp_connect -p $((I+10001)) -l -w 20 \
221 -t ${timeout_poll} 0.0.0.0 >/dev/null &
223 wait_local_port_listen $ns $((NR_CLIENTS + 10001))
225 for I in `seq 1 $NR_CLIENTS`; do
227 timeout ${timeout_test} \
229 ./mptcp_connect -p $((I+10001)) -w 20 \
230 -t ${timeout_poll} 127.0.0.1 >/dev/null &
233 wait_msk_nr $((NR_CLIENTS*2)) "many msk socket present"