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" $*
108 wait_local_port_listen()
110 local listener_ns="${1}"
115 port_hex="$(printf "%04X" "${port}")"
116 for i in $(seq 10); do
117 ip netns exec "${listener_ns}" cat /proc/net/tcp | \
118 awk "BEGIN {rc=1} {if (\$2 ~ /:${port_hex}\$/ && \$4 ~ /0A/) {rc=0; exit}} END {exit rc}" &&
126 local listener_ns="${1}"
131 port_hex="$(printf "%04X" "${port}")"
132 for i in $(seq 10); do
133 ip netns exec ${listener_ns} grep -q " 0100007F:${port_hex} " /proc/net/tcp && break
140 ip -n $ns link set dev lo up
143 timeout ${timeout_test} \
145 ./mptcp_connect -p 10000 -l -t ${timeout_poll} -w 20 \
147 wait_local_port_listen $ns 10000
148 chk_msk_nr 0 "no msk on netns creation"
151 timeout ${timeout_test} \
153 ./mptcp_connect -p 10000 -r 0 -t ${timeout_poll} -w 20 \
154 127.0.0.1 >/dev/null &
155 wait_connected $ns 10000
156 chk_msk_nr 2 "after MPC handshake "
157 chk_msk_remote_key_nr 2 "....chk remote_key"
158 chk_msk_fallback_nr 0 "....chk no fallback"
163 timeout ${timeout_test} \
165 ./mptcp_connect -p 10001 -l -s TCP -t ${timeout_poll} -w 20 \
167 wait_local_port_listen $ns 10001
169 timeout ${timeout_test} \
171 ./mptcp_connect -p 10001 -r 0 -t ${timeout_poll} -w 20 \
172 127.0.0.1 >/dev/null &
173 wait_connected $ns 10001
174 chk_msk_fallback_nr 1 "check fallback"
178 for I in `seq 1 $NR_CLIENTS`; do
180 timeout ${timeout_test} \
182 ./mptcp_connect -p $((I+10001)) -l -w 20 \
183 -t ${timeout_poll} 0.0.0.0 >/dev/null &
185 wait_local_port_listen $ns $((NR_CLIENTS + 10001))
187 for I in `seq 1 $NR_CLIENTS`; do
189 timeout ${timeout_test} \
191 ./mptcp_connect -p $((I+10001)) -w 20 \
192 -t ${timeout_poll} 127.0.0.1 >/dev/null &
195 wait_msk_nr $((NR_CLIENTS*2)) "many msk socket present"