~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/tools/testing/selftests/net/mptcp/mptcp_join.sh

Version: ~ [ linux-6.12-rc7 ] ~ [ linux-6.11.7 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.60 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.116 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.171 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.229 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.285 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.323 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.12 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

Diff markup

Differences between /tools/testing/selftests/net/mptcp/mptcp_join.sh (Architecture i386) and /tools/testing/selftests/net/mptcp/mptcp_join.sh (Architecture m68k)


  1 #!/bin/bash                                         1 #!/bin/bash
  2 # SPDX-License-Identifier: GPL-2.0                  2 # SPDX-License-Identifier: GPL-2.0
  3                                                     3 
  4 # Double quotes to prevent globbing and word s      4 # Double quotes to prevent globbing and word splitting is recommended in new
  5 # code but we accept it, especially because th      5 # code but we accept it, especially because there were too many before having
  6 # address all other issues detected by shellch      6 # address all other issues detected by shellcheck.
  7 #shellcheck disable=SC2086                          7 #shellcheck disable=SC2086
  8                                                     8 
  9 # ShellCheck incorrectly believes that most of      9 # ShellCheck incorrectly believes that most of the code here is unreachable
 10 # because it's invoked by variable name, see h     10 # because it's invoked by variable name, see how the "tests" array is used
 11 #shellcheck disable=SC2317                         11 #shellcheck disable=SC2317
 12                                                    12 
 13 . "$(dirname "${0}")/mptcp_lib.sh"                 13 . "$(dirname "${0}")/mptcp_lib.sh"
 14                                                    14 
 15 ret=0                                              15 ret=0
 16 sin=""                                             16 sin=""
 17 sinfail=""                                         17 sinfail=""
 18 sout=""                                            18 sout=""
 19 cin=""                                             19 cin=""
 20 cinfail=""                                         20 cinfail=""
 21 cinsent=""                                         21 cinsent=""
 22 tmpfile=""                                         22 tmpfile=""
 23 cout=""                                            23 cout=""
 24 err=""                                             24 err=""
 25 capout=""                                          25 capout=""
 26 cappid=""                                          26 cappid=""
 27 ns1=""                                             27 ns1=""
 28 ns2=""                                             28 ns2=""
 29 iptables="iptables"                                29 iptables="iptables"
 30 ip6tables="ip6tables"                              30 ip6tables="ip6tables"
 31 timeout_poll=30                                    31 timeout_poll=30
 32 timeout_test=$((timeout_poll * 2 + 1))             32 timeout_test=$((timeout_poll * 2 + 1))
 33 capture=false                                      33 capture=false
 34 checksum=false                                     34 checksum=false
 35 check_invert=0                                     35 check_invert=0
 36 validate_checksum=false                            36 validate_checksum=false
 37 init=0                                             37 init=0
 38 evts_ns1=""                                        38 evts_ns1=""
 39 evts_ns2=""                                        39 evts_ns2=""
 40 evts_ns1_pid=0                                     40 evts_ns1_pid=0
 41 evts_ns2_pid=0                                     41 evts_ns2_pid=0
 42 last_test_failed=0                                 42 last_test_failed=0
 43 last_test_skipped=0                                43 last_test_skipped=0
 44 last_test_ignored=1                                44 last_test_ignored=1
 45                                                    45 
 46 declare -A all_tests                               46 declare -A all_tests
 47 declare -a only_tests_ids                          47 declare -a only_tests_ids
 48 declare -a only_tests_names                        48 declare -a only_tests_names
 49 declare -A failed_tests                            49 declare -A failed_tests
 50 MPTCP_LIB_TEST_FORMAT="%03u %s\n"                  50 MPTCP_LIB_TEST_FORMAT="%03u %s\n"
 51 TEST_NAME=""                                       51 TEST_NAME=""
 52 nr_blank=6                                         52 nr_blank=6
 53                                                    53 
 54 # These var are used only in some tests, make      54 # These var are used only in some tests, make sure they are not already set
 55 unset FAILING_LINKS                                55 unset FAILING_LINKS
 56 unset test_linkfail                                56 unset test_linkfail
 57 unset addr_nr_ns1                                  57 unset addr_nr_ns1
 58 unset addr_nr_ns2                                  58 unset addr_nr_ns2
 59 unset cestab_ns1                                   59 unset cestab_ns1
 60 unset cestab_ns2                                   60 unset cestab_ns2
 61 unset sflags                                       61 unset sflags
 62 unset fastclose                                    62 unset fastclose
 63 unset fullmesh                                     63 unset fullmesh
 64 unset speed                                        64 unset speed
 65 unset join_csum_ns1                                65 unset join_csum_ns1
 66 unset join_csum_ns2                                66 unset join_csum_ns2
 67 unset join_fail_nr                                 67 unset join_fail_nr
 68 unset join_rst_nr                                  68 unset join_rst_nr
 69 unset join_infi_nr                                 69 unset join_infi_nr
 70 unset join_corrupted_pkts                          70 unset join_corrupted_pkts
 71 unset join_syn_tx                                  71 unset join_syn_tx
 72 unset join_create_err                              72 unset join_create_err
 73 unset join_bind_err                                73 unset join_bind_err
 74 unset join_connect_err                             74 unset join_connect_err
 75                                                    75 
 76 # generated using "nfbpf_compile '(ip && (ip[5     76 # generated using "nfbpf_compile '(ip && (ip[54] & 0xf0) == 0x30) ||
 77 #                                 (ip6 && (ip6     77 #                                 (ip6 && (ip6[74] & 0xf0) == 0x30)'"
 78 CBPF_MPTCP_SUBOPTION_ADD_ADDR="14,                 78 CBPF_MPTCP_SUBOPTION_ADD_ADDR="14,
 79                                48 0 0 0,           79                                48 0 0 0,
 80                                84 0 0 240,         80                                84 0 0 240,
 81                                21 0 3 64,          81                                21 0 3 64,
 82                                48 0 0 54,          82                                48 0 0 54,
 83                                84 0 0 240,         83                                84 0 0 240,
 84                                21 6 7 48,          84                                21 6 7 48,
 85                                48 0 0 0,           85                                48 0 0 0,
 86                                84 0 0 240,         86                                84 0 0 240,
 87                                21 0 4 96,          87                                21 0 4 96,
 88                                48 0 0 74,          88                                48 0 0 74,
 89                                84 0 0 240,         89                                84 0 0 240,
 90                                21 0 1 48,          90                                21 0 1 48,
 91                                6 0 0 65535,        91                                6 0 0 65535,
 92                                6 0 0 0"            92                                6 0 0 0"
 93                                                    93 
 94 init_partial()                                     94 init_partial()
 95 {                                                  95 {
 96         capout=$(mktemp)                           96         capout=$(mktemp)
 97                                                    97 
 98         mptcp_lib_ns_init ns1 ns2                  98         mptcp_lib_ns_init ns1 ns2
 99                                                    99 
100         local netns                               100         local netns
101         for netns in "$ns1" "$ns2"; do            101         for netns in "$ns1" "$ns2"; do
102                 ip netns exec $netns sysctl -q    102                 ip netns exec $netns sysctl -q net.mptcp.pm_type=0 2>/dev/null || true
103                 if $checksum; then                103                 if $checksum; then
104                         ip netns exec $netns s    104                         ip netns exec $netns sysctl -q net.mptcp.checksum_enabled=1
105                 fi                                105                 fi
106         done                                      106         done
107                                                   107 
108         check_invert=0                            108         check_invert=0
109         validate_checksum=$checksum               109         validate_checksum=$checksum
110                                                   110 
111         #  ns1         ns2                        111         #  ns1         ns2
112         # ns1eth1    ns2eth1                      112         # ns1eth1    ns2eth1
113         # ns1eth2    ns2eth2                      113         # ns1eth2    ns2eth2
114         # ns1eth3    ns2eth3                      114         # ns1eth3    ns2eth3
115         # ns1eth4    ns2eth4                      115         # ns1eth4    ns2eth4
116                                                   116 
117         local i                                   117         local i
118         for i in $(seq 1 4); do                   118         for i in $(seq 1 4); do
119                 ip link add ns1eth$i netns "$n    119                 ip link add ns1eth$i netns "$ns1" type veth peer name ns2eth$i netns "$ns2"
120                 ip -net "$ns1" addr add 10.0.$    120                 ip -net "$ns1" addr add 10.0.$i.1/24 dev ns1eth$i
121                 ip -net "$ns1" addr add dead:b    121                 ip -net "$ns1" addr add dead:beef:$i::1/64 dev ns1eth$i nodad
122                 ip -net "$ns1" link set ns1eth    122                 ip -net "$ns1" link set ns1eth$i up
123                                                   123 
124                 ip -net "$ns2" addr add 10.0.$    124                 ip -net "$ns2" addr add 10.0.$i.2/24 dev ns2eth$i
125                 ip -net "$ns2" addr add dead:b    125                 ip -net "$ns2" addr add dead:beef:$i::2/64 dev ns2eth$i nodad
126                 ip -net "$ns2" link set ns2eth    126                 ip -net "$ns2" link set ns2eth$i up
127                                                   127 
128                 # let $ns2 reach any $ns1 addr    128                 # let $ns2 reach any $ns1 address from any interface
129                 ip -net "$ns2" route add defau    129                 ip -net "$ns2" route add default via 10.0.$i.1 dev ns2eth$i metric 10$i
130                 ip -net "$ns2" route add defau    130                 ip -net "$ns2" route add default via dead:beef:$i::1 dev ns2eth$i metric 10$i
131         done                                      131         done
132 }                                                 132 }
133                                                   133 
134 init_shapers()                                    134 init_shapers()
135 {                                                 135 {
136         local i                                   136         local i
137         for i in $(seq 1 4); do                   137         for i in $(seq 1 4); do
138                 tc -n $ns1 qdisc add dev ns1et    138                 tc -n $ns1 qdisc add dev ns1eth$i root netem rate 20mbit delay 1ms
139                 tc -n $ns2 qdisc add dev ns2et    139                 tc -n $ns2 qdisc add dev ns2eth$i root netem rate 20mbit delay 1ms
140         done                                      140         done
141 }                                                 141 }
142                                                   142 
143 cleanup_partial()                                 143 cleanup_partial()
144 {                                                 144 {
145         rm -f "$capout"                           145         rm -f "$capout"
146                                                   146 
147         mptcp_lib_ns_exit "${ns1}" "${ns2}"       147         mptcp_lib_ns_exit "${ns1}" "${ns2}"
148 }                                                 148 }
149                                                   149 
150 init() {                                          150 init() {
151         init=1                                    151         init=1
152                                                   152 
153         mptcp_lib_check_mptcp                     153         mptcp_lib_check_mptcp
154         mptcp_lib_check_kallsyms                  154         mptcp_lib_check_kallsyms
155         mptcp_lib_check_tools ip tc ss "${ipta    155         mptcp_lib_check_tools ip tc ss "${iptables}" "${ip6tables}"
156                                                   156 
157         sin=$(mktemp)                             157         sin=$(mktemp)
158         sout=$(mktemp)                            158         sout=$(mktemp)
159         cin=$(mktemp)                             159         cin=$(mktemp)
160         cinsent=$(mktemp)                         160         cinsent=$(mktemp)
161         cout=$(mktemp)                            161         cout=$(mktemp)
162         err=$(mktemp)                             162         err=$(mktemp)
163         evts_ns1=$(mktemp)                        163         evts_ns1=$(mktemp)
164         evts_ns2=$(mktemp)                        164         evts_ns2=$(mktemp)
165                                                   165 
166         trap cleanup EXIT                         166         trap cleanup EXIT
167                                                   167 
168         make_file "$cin" "client" 1 >/dev/null    168         make_file "$cin" "client" 1 >/dev/null
169         make_file "$sin" "server" 1 >/dev/null    169         make_file "$sin" "server" 1 >/dev/null
170 }                                                 170 }
171                                                   171 
172 cleanup()                                         172 cleanup()
173 {                                                 173 {
174         rm -f "$cin" "$cout" "$sinfail"           174         rm -f "$cin" "$cout" "$sinfail"
175         rm -f "$sin" "$sout" "$cinsent" "$cinf    175         rm -f "$sin" "$sout" "$cinsent" "$cinfail"
176         rm -f "$tmpfile"                          176         rm -f "$tmpfile"
177         rm -rf $evts_ns1 $evts_ns2                177         rm -rf $evts_ns1 $evts_ns2
178         rm -f "$err"                              178         rm -f "$err"
179         cleanup_partial                           179         cleanup_partial
180 }                                                 180 }
181                                                   181 
182 print_check()                                     182 print_check()
183 {                                                 183 {
184         printf "%-${nr_blank}s%-36s" " " "${*}    184         printf "%-${nr_blank}s%-36s" " " "${*}"
185 }                                                 185 }
186                                                   186 
187 print_info()                                      187 print_info()
188 {                                                 188 {
189         # It can be empty, no need to print an    189         # It can be empty, no need to print anything then
190         [ -z "${1}" ] && return                   190         [ -z "${1}" ] && return
191                                                   191 
192         mptcp_lib_print_info "      Info: ${*}    192         mptcp_lib_print_info "      Info: ${*}"
193 }                                                 193 }
194                                                   194 
195 print_ok()                                        195 print_ok()
196 {                                                 196 {
197         mptcp_lib_pr_ok "${@}"                    197         mptcp_lib_pr_ok "${@}"
198 }                                                 198 }
199                                                   199 
200 print_fail()                                      200 print_fail()
201 {                                                 201 {
202         mptcp_lib_pr_fail "${@}"                  202         mptcp_lib_pr_fail "${@}"
203 }                                                 203 }
204                                                   204 
205 print_skip()                                      205 print_skip()
206 {                                                 206 {
207         mptcp_lib_pr_skip "${@}"                  207         mptcp_lib_pr_skip "${@}"
208 }                                                 208 }
209                                                   209 
210 # $1: check name; $2: rc                          210 # $1: check name; $2: rc
211 print_results()                                   211 print_results()
212 {                                                 212 {
213         local check="${1}"                        213         local check="${1}"
214         local rc=${2}                             214         local rc=${2}
215                                                   215 
216         print_check "${check}"                    216         print_check "${check}"
217         if [ ${rc} = ${KSFT_PASS} ]; then         217         if [ ${rc} = ${KSFT_PASS} ]; then
218                 print_ok                          218                 print_ok
219         elif [ ${rc} = ${KSFT_SKIP} ]; then       219         elif [ ${rc} = ${KSFT_SKIP} ]; then
220                 print_skip                        220                 print_skip
221         else                                      221         else
222                 fail_test "see above"             222                 fail_test "see above"
223         fi                                        223         fi
224 }                                                 224 }
225                                                   225 
226 # [ $1: fail msg ]                                226 # [ $1: fail msg ]
227 mark_as_skipped()                                 227 mark_as_skipped()
228 {                                                 228 {
229         local msg="${1:-"Feature not supported    229         local msg="${1:-"Feature not supported"}"
230                                                   230 
231         mptcp_lib_fail_if_expected_feature "${    231         mptcp_lib_fail_if_expected_feature "${msg}"
232                                                   232 
233         print_check "${msg}"                      233         print_check "${msg}"
234         print_skip                                234         print_skip
235                                                   235 
236         last_test_skipped=1                       236         last_test_skipped=1
237 }                                                 237 }
238                                                   238 
239 # $@: condition                                   239 # $@: condition
240 continue_if()                                     240 continue_if()
241 {                                                 241 {
242         if ! "${@}"; then                         242         if ! "${@}"; then
243                 mark_as_skipped                   243                 mark_as_skipped
244                 return 1                          244                 return 1
245         fi                                        245         fi
246 }                                                 246 }
247                                                   247 
248 skip_test()                                       248 skip_test()
249 {                                                 249 {
250         if [ "${#only_tests_ids[@]}" -eq 0 ] &    250         if [ "${#only_tests_ids[@]}" -eq 0 ] && [ "${#only_tests_names[@]}" -eq 0 ]; then
251                 return 1                          251                 return 1
252         fi                                        252         fi
253                                                   253 
254         local i                                   254         local i
255         for i in "${only_tests_ids[@]}"; do       255         for i in "${only_tests_ids[@]}"; do
256                 if [ "$((MPTCP_LIB_TEST_COUNTE    256                 if [ "$((MPTCP_LIB_TEST_COUNTER+1))" -eq "${i}" ]; then
257                         return 1                  257                         return 1
258                 fi                                258                 fi
259         done                                      259         done
260         for i in "${only_tests_names[@]}"; do     260         for i in "${only_tests_names[@]}"; do
261                 if [ "${TEST_NAME}" = "${i}" ]    261                 if [ "${TEST_NAME}" = "${i}" ]; then
262                         return 1                  262                         return 1
263                 fi                                263                 fi
264         done                                      264         done
265                                                   265 
266         return 0                                  266         return 0
267 }                                                 267 }
268                                                   268 
269 append_prev_results()                             269 append_prev_results()
270 {                                                 270 {
271         if [ ${last_test_failed} -eq 1 ]; then    271         if [ ${last_test_failed} -eq 1 ]; then
272                 mptcp_lib_result_fail "${TEST_    272                 mptcp_lib_result_fail "${TEST_NAME}"
273         elif [ ${last_test_skipped} -eq 1 ]; t    273         elif [ ${last_test_skipped} -eq 1 ]; then
274                 mptcp_lib_result_skip "${TEST_    274                 mptcp_lib_result_skip "${TEST_NAME}"
275         elif [ ${last_test_ignored} -ne 1 ]; t    275         elif [ ${last_test_ignored} -ne 1 ]; then
276                 mptcp_lib_result_pass "${TEST_    276                 mptcp_lib_result_pass "${TEST_NAME}"
277         fi                                        277         fi
278                                                   278 
279         last_test_failed=0                        279         last_test_failed=0
280         last_test_skipped=0                       280         last_test_skipped=0
281         last_test_ignored=0                       281         last_test_ignored=0
282 }                                                 282 }
283                                                   283 
284 # $1: test name                                   284 # $1: test name
285 reset()                                           285 reset()
286 {                                                 286 {
287         append_prev_results                       287         append_prev_results
288                                                   288 
289         TEST_NAME="${1}"                          289         TEST_NAME="${1}"
290                                                   290 
291         MPTCP_LIB_SUBTEST_FLAKY=0 # reset if m    291         MPTCP_LIB_SUBTEST_FLAKY=0 # reset if modified
292                                                   292 
293         if skip_test; then                        293         if skip_test; then
294                 MPTCP_LIB_TEST_COUNTER=$((MPTC    294                 MPTCP_LIB_TEST_COUNTER=$((MPTCP_LIB_TEST_COUNTER+1))
295                 last_test_ignored=1               295                 last_test_ignored=1
296                 return 1                          296                 return 1
297         fi                                        297         fi
298                                                   298 
299         mptcp_lib_print_title "${TEST_NAME}"      299         mptcp_lib_print_title "${TEST_NAME}"
300                                                   300 
301         if [ "${init}" != "1" ]; then             301         if [ "${init}" != "1" ]; then
302                 init                              302                 init
303         else                                      303         else
304                 cleanup_partial                   304                 cleanup_partial
305         fi                                        305         fi
306                                                   306 
307         init_partial                              307         init_partial
308                                                   308 
309         return 0                                  309         return 0
310 }                                                 310 }
311                                                   311 
312 # $1: test name ; $2: counter to check            312 # $1: test name ; $2: counter to check
313 reset_check_counter()                             313 reset_check_counter()
314 {                                                 314 {
315         reset "${1}" || return 1                  315         reset "${1}" || return 1
316                                                   316 
317         local counter="${2}"                      317         local counter="${2}"
318                                                   318 
319         if ! nstat -asz "${counter}" | grep -w    319         if ! nstat -asz "${counter}" | grep -wq "${counter}"; then
320                 mark_as_skipped "counter '${co    320                 mark_as_skipped "counter '${counter}' is not available"
321                 return 1                          321                 return 1
322         fi                                        322         fi
323 }                                                 323 }
324                                                   324 
325 # $1: test name                                   325 # $1: test name
326 reset_with_cookies()                              326 reset_with_cookies()
327 {                                                 327 {
328         reset "${1}" || return 1                  328         reset "${1}" || return 1
329                                                   329 
330         local netns                               330         local netns
331         for netns in "$ns1" "$ns2"; do            331         for netns in "$ns1" "$ns2"; do
332                 ip netns exec $netns sysctl -q    332                 ip netns exec $netns sysctl -q net.ipv4.tcp_syncookies=2
333         done                                      333         done
334 }                                                 334 }
335                                                   335 
336 # $1: test name                                   336 # $1: test name
337 reset_with_add_addr_timeout()                     337 reset_with_add_addr_timeout()
338 {                                                 338 {
339         local ip="${2:-4}"                        339         local ip="${2:-4}"
340         local tables                              340         local tables
341                                                   341 
342         reset "${1}" || return 1                  342         reset "${1}" || return 1
343                                                   343 
344         tables="${iptables}"                      344         tables="${iptables}"
345         if [ $ip -eq 6 ]; then                    345         if [ $ip -eq 6 ]; then
346                 tables="${ip6tables}"             346                 tables="${ip6tables}"
347         fi                                        347         fi
348                                                   348 
349         ip netns exec $ns1 sysctl -q net.mptcp    349         ip netns exec $ns1 sysctl -q net.mptcp.add_addr_timeout=1
350                                                   350 
351         if ! ip netns exec $ns2 $tables -A OUT    351         if ! ip netns exec $ns2 $tables -A OUTPUT -p tcp \
352                         -m tcp --tcp-option 30    352                         -m tcp --tcp-option 30 \
353                         -m bpf --bytecode \       353                         -m bpf --bytecode \
354                         "$CBPF_MPTCP_SUBOPTION    354                         "$CBPF_MPTCP_SUBOPTION_ADD_ADDR" \
355                         -j DROP; then             355                         -j DROP; then
356                 mark_as_skipped "unable to set    356                 mark_as_skipped "unable to set the 'add addr' rule"
357                 return 1                          357                 return 1
358         fi                                        358         fi
359 }                                                 359 }
360                                                   360 
361 # $1: test name                                   361 # $1: test name
362 reset_with_checksum()                             362 reset_with_checksum()
363 {                                                 363 {
364         local ns1_enable=$1                       364         local ns1_enable=$1
365         local ns2_enable=$2                       365         local ns2_enable=$2
366                                                   366 
367         reset "checksum test ${ns1_enable} ${n    367         reset "checksum test ${ns1_enable} ${ns2_enable}" || return 1
368                                                   368 
369         ip netns exec $ns1 sysctl -q net.mptcp    369         ip netns exec $ns1 sysctl -q net.mptcp.checksum_enabled=$ns1_enable
370         ip netns exec $ns2 sysctl -q net.mptcp    370         ip netns exec $ns2 sysctl -q net.mptcp.checksum_enabled=$ns2_enable
371                                                   371 
372         validate_checksum=true                    372         validate_checksum=true
373 }                                                 373 }
374                                                   374 
375 reset_with_allow_join_id0()                       375 reset_with_allow_join_id0()
376 {                                                 376 {
377         local ns1_enable=$2                       377         local ns1_enable=$2
378         local ns2_enable=$3                       378         local ns2_enable=$3
379                                                   379 
380         reset "${1}" || return 1                  380         reset "${1}" || return 1
381                                                   381 
382         ip netns exec $ns1 sysctl -q net.mptcp    382         ip netns exec $ns1 sysctl -q net.mptcp.allow_join_initial_addr_port=$ns1_enable
383         ip netns exec $ns2 sysctl -q net.mptcp    383         ip netns exec $ns2 sysctl -q net.mptcp.allow_join_initial_addr_port=$ns2_enable
384 }                                                 384 }
385                                                   385 
386 # Modify TCP payload without corrupting the TC    386 # Modify TCP payload without corrupting the TCP packet
387 #                                                 387 #
388 # This rule inverts a 8-bit word at byte offse    388 # This rule inverts a 8-bit word at byte offset 148 for the 2nd TCP ACK packets
389 # carrying enough data.                           389 # carrying enough data.
390 # Once it is done, the TCP Checksum field is u    390 # Once it is done, the TCP Checksum field is updated so the packet is still
391 # considered as valid at the TCP level.           391 # considered as valid at the TCP level.
392 # Because the MPTCP checksum, covering the TCP    392 # Because the MPTCP checksum, covering the TCP options and data, has not been
393 # updated, the modification will be detected a    393 # updated, the modification will be detected and an MP_FAIL will be emitted:
394 # what we want to validate here without corrup    394 # what we want to validate here without corrupting "random" MPTCP options.
395 #                                                 395 #
396 # To avoid having tc producing this pr_info()     396 # To avoid having tc producing this pr_info() message for each TCP ACK packets
397 # not carrying enough data:                       397 # not carrying enough data:
398 #                                                 398 #
399 #     tc action pedit offset 162 out of bounds    399 #     tc action pedit offset 162 out of bounds
400 #                                                 400 #
401 # Netfilter is used to mark packets with enoug    401 # Netfilter is used to mark packets with enough data.
402 setup_fail_rules()                                402 setup_fail_rules()
403 {                                                 403 {
404         check_invert=1                            404         check_invert=1
405         validate_checksum=true                    405         validate_checksum=true
406         local i="$1"                              406         local i="$1"
407         local ip="${2:-4}"                        407         local ip="${2:-4}"
408         local tables                              408         local tables
409                                                   409 
410         tables="${iptables}"                      410         tables="${iptables}"
411         if [ $ip -eq 6 ]; then                    411         if [ $ip -eq 6 ]; then
412                 tables="${ip6tables}"             412                 tables="${ip6tables}"
413         fi                                        413         fi
414                                                   414 
415         ip netns exec $ns2 $tables \              415         ip netns exec $ns2 $tables \
416                 -t mangle \                       416                 -t mangle \
417                 -A OUTPUT \                       417                 -A OUTPUT \
418                 -o ns2eth$i \                     418                 -o ns2eth$i \
419                 -p tcp \                          419                 -p tcp \
420                 -m length --length 150:9999 \     420                 -m length --length 150:9999 \
421                 -m statistic --mode nth --pack    421                 -m statistic --mode nth --packet 1 --every 99999 \
422                 -j MARK --set-mark 42 || retur    422                 -j MARK --set-mark 42 || return ${KSFT_SKIP}
423                                                   423 
424         tc -n $ns2 qdisc add dev ns2eth$i clsa    424         tc -n $ns2 qdisc add dev ns2eth$i clsact || return ${KSFT_SKIP}
425         tc -n $ns2 filter add dev ns2eth$i egr    425         tc -n $ns2 filter add dev ns2eth$i egress \
426                 protocol ip prio 1000 \           426                 protocol ip prio 1000 \
427                 handle 42 fw \                    427                 handle 42 fw \
428                 action pedit munge offset 148     428                 action pedit munge offset 148 u8 invert \
429                 pipe csum tcp \                   429                 pipe csum tcp \
430                 index 100 || return ${KSFT_SKI    430                 index 100 || return ${KSFT_SKIP}
431 }                                                 431 }
432                                                   432 
433 reset_with_fail()                                 433 reset_with_fail()
434 {                                                 434 {
435         reset_check_counter "${1}" "MPTcpExtIn    435         reset_check_counter "${1}" "MPTcpExtInfiniteMapTx" || return 1
436         shift                                     436         shift
437                                                   437 
438         ip netns exec $ns1 sysctl -q net.mptcp    438         ip netns exec $ns1 sysctl -q net.mptcp.checksum_enabled=1
439         ip netns exec $ns2 sysctl -q net.mptcp    439         ip netns exec $ns2 sysctl -q net.mptcp.checksum_enabled=1
440                                                   440 
441         local rc=0                                441         local rc=0
442         setup_fail_rules "${@}" || rc=$?          442         setup_fail_rules "${@}" || rc=$?
443                                                   443 
444         if [ ${rc} -eq ${KSFT_SKIP} ]; then       444         if [ ${rc} -eq ${KSFT_SKIP} ]; then
445                 mark_as_skipped "unable to set    445                 mark_as_skipped "unable to set the 'fail' rules"
446                 return 1                          446                 return 1
447         fi                                        447         fi
448 }                                                 448 }
449                                                   449 
450 start_events()                                    450 start_events()
451 {                                                 451 {
452         mptcp_lib_events "${ns1}" "${evts_ns1}    452         mptcp_lib_events "${ns1}" "${evts_ns1}" evts_ns1_pid
453         mptcp_lib_events "${ns2}" "${evts_ns2}    453         mptcp_lib_events "${ns2}" "${evts_ns2}" evts_ns2_pid
454 }                                                 454 }
455                                                   455 
456 reset_with_events()                               456 reset_with_events()
457 {                                                 457 {
458         reset "${1}" || return 1                  458         reset "${1}" || return 1
459                                                   459 
460         start_events                              460         start_events
461 }                                                 461 }
462                                                   462 
463 reset_with_tcp_filter()                           463 reset_with_tcp_filter()
464 {                                                 464 {
465         reset "${1}" || return 1                  465         reset "${1}" || return 1
466         shift                                     466         shift
467                                                   467 
468         local ns="${!1}"                          468         local ns="${!1}"
469         local src="${2}"                          469         local src="${2}"
470         local target="${3}"                       470         local target="${3}"
471         local chain="${4:-INPUT}"                 471         local chain="${4:-INPUT}"
472                                                   472 
473         if ! ip netns exec "${ns}" ${iptables}    473         if ! ip netns exec "${ns}" ${iptables} \
474                         -A "${chain}" \           474                         -A "${chain}" \
475                         -s "${src}" \             475                         -s "${src}" \
476                         -p tcp \                  476                         -p tcp \
477                         -j "${target}"; then      477                         -j "${target}"; then
478                 mark_as_skipped "unable to set    478                 mark_as_skipped "unable to set the filter rules"
479                 return 1                          479                 return 1
480         fi                                        480         fi
481 }                                                 481 }
482                                                   482 
483 # $1: err msg                                     483 # $1: err msg
484 fail_test()                                       484 fail_test()
485 {                                                 485 {
486         if ! mptcp_lib_subtest_is_flaky; then     486         if ! mptcp_lib_subtest_is_flaky; then
487                 ret=${KSFT_FAIL}                  487                 ret=${KSFT_FAIL}
488         fi                                        488         fi
489                                                   489 
490         if [ ${#} -gt 0 ]; then                   490         if [ ${#} -gt 0 ]; then
491                 print_fail "${@}"                 491                 print_fail "${@}"
492         fi                                        492         fi
493                                                   493 
494         # just in case a test is marked twice     494         # just in case a test is marked twice as failed
495         if [ ${last_test_failed} -eq 0 ]; then    495         if [ ${last_test_failed} -eq 0 ]; then
496                 failed_tests[${MPTCP_LIB_TEST_    496                 failed_tests[${MPTCP_LIB_TEST_COUNTER}]="${TEST_NAME}"
497                 dump_stats                        497                 dump_stats
498                 last_test_failed=1                498                 last_test_failed=1
499         fi                                        499         fi
500 }                                                 500 }
501                                                   501 
502 get_failed_tests_ids()                            502 get_failed_tests_ids()
503 {                                                 503 {
504         # sorted                                  504         # sorted
505         local i                                   505         local i
506         for i in "${!failed_tests[@]}"; do        506         for i in "${!failed_tests[@]}"; do
507                 echo "${i}"                       507                 echo "${i}"
508         done | sort -n                            508         done | sort -n
509 }                                                 509 }
510                                                   510 
511 check_transfer()                                  511 check_transfer()
512 {                                                 512 {
513         local in=$1                               513         local in=$1
514         local out=$2                              514         local out=$2
515         local what=$3                             515         local what=$3
516         local bytes=$4                            516         local bytes=$4
517         local i a b                               517         local i a b
518                                                   518 
519         local line                                519         local line
520         if [ -n "$bytes" ]; then                  520         if [ -n "$bytes" ]; then
521                 local out_size                    521                 local out_size
522                 # when truncating we must chec    522                 # when truncating we must check the size explicitly
523                 out_size=$(wc -c $out | awk '{    523                 out_size=$(wc -c $out | awk '{print $1}')
524                 if [ $out_size -ne $bytes ]; t    524                 if [ $out_size -ne $bytes ]; then
525                         fail_test "$what outpu    525                         fail_test "$what output file has wrong size ($out_size, $bytes)"
526                         return 1                  526                         return 1
527                 fi                                527                 fi
528                                                   528 
529                 # note: BusyBox's "cmp" comman    529                 # note: BusyBox's "cmp" command doesn't support --bytes
530                 tmpfile=$(mktemp)                 530                 tmpfile=$(mktemp)
531                 head --bytes="$bytes" "$in" >     531                 head --bytes="$bytes" "$in" > "$tmpfile"
532                 mv "$tmpfile" "$in"               532                 mv "$tmpfile" "$in"
533                 head --bytes="$bytes" "$out" >    533                 head --bytes="$bytes" "$out" > "$tmpfile"
534                 mv "$tmpfile" "$out"              534                 mv "$tmpfile" "$out"
535                 tmpfile=""                        535                 tmpfile=""
536         fi                                        536         fi
537         cmp -l "$in" "$out" | while read -r i     537         cmp -l "$in" "$out" | while read -r i a b; do
538                 local sum=$((0${a} + 0${b}))      538                 local sum=$((0${a} + 0${b}))
539                 if [ $check_invert -eq 0 ] ||     539                 if [ $check_invert -eq 0 ] || [ $sum -ne $((0xff)) ]; then
540                         fail_test "$what does     540                         fail_test "$what does not match (in, out):"
541                         mptcp_lib_print_file_e    541                         mptcp_lib_print_file_err "$in"
542                         mptcp_lib_print_file_e    542                         mptcp_lib_print_file_err "$out"
543                                                   543 
544                         return 1                  544                         return 1
545                 else                              545                 else
546                         print_info "$what has     546                         print_info "$what has inverted byte at ${i}"
547                 fi                                547                 fi
548         done                                      548         done
549                                                   549 
550         return 0                                  550         return 0
551 }                                                 551 }
552                                                   552 
553 do_ping()                                         553 do_ping()
554 {                                                 554 {
555         local listener_ns="$1"                    555         local listener_ns="$1"
556         local connector_ns="$2"                   556         local connector_ns="$2"
557         local connect_addr="$3"                   557         local connect_addr="$3"
558                                                   558 
559         if ! ip netns exec ${connector_ns} pin    559         if ! ip netns exec ${connector_ns} ping -q -c 1 $connect_addr >/dev/null; then
560                 fail_test "$listener_ns -> $co    560                 fail_test "$listener_ns -> $connect_addr connectivity"
561         fi                                        561         fi
562 }                                                 562 }
563                                                   563 
564 link_failure()                                    564 link_failure()
565 {                                                 565 {
566         local ns="$1"                             566         local ns="$1"
567                                                   567 
568         if [ -z "$FAILING_LINKS" ]; then          568         if [ -z "$FAILING_LINKS" ]; then
569                 l=$((RANDOM%4))                   569                 l=$((RANDOM%4))
570                 FAILING_LINKS=$((l+1))            570                 FAILING_LINKS=$((l+1))
571         fi                                        571         fi
572                                                   572 
573         local l                                   573         local l
574         for l in $FAILING_LINKS; do               574         for l in $FAILING_LINKS; do
575                 local veth="ns1eth$l"             575                 local veth="ns1eth$l"
576                 ip -net "$ns" link set "$veth"    576                 ip -net "$ns" link set "$veth" down
577         done                                      577         done
578 }                                                 578 }
579                                                   579 
580 rm_addr_count()                                   580 rm_addr_count()
581 {                                                 581 {
582         mptcp_lib_get_counter "${1}" "MPTcpExt    582         mptcp_lib_get_counter "${1}" "MPTcpExtRmAddr"
583 }                                                 583 }
584                                                   584 
585 # $1: ns, $2: old rm_addr counter in $ns          585 # $1: ns, $2: old rm_addr counter in $ns
586 wait_rm_addr()                                    586 wait_rm_addr()
587 {                                                 587 {
588         local ns="${1}"                           588         local ns="${1}"
589         local old_cnt="${2}"                      589         local old_cnt="${2}"
590         local cnt                                 590         local cnt
591                                                   591 
592         local i                                   592         local i
593         for i in $(seq 10); do                    593         for i in $(seq 10); do
594                 cnt=$(rm_addr_count ${ns})        594                 cnt=$(rm_addr_count ${ns})
595                 [ "$cnt" = "${old_cnt}" ] || b    595                 [ "$cnt" = "${old_cnt}" ] || break
596                 sleep 0.1                         596                 sleep 0.1
597         done                                      597         done
598 }                                                 598 }
599                                                   599 
600 rm_sf_count()                                     600 rm_sf_count()
601 {                                                 601 {
602         mptcp_lib_get_counter "${1}" "MPTcpExt    602         mptcp_lib_get_counter "${1}" "MPTcpExtRmSubflow"
603 }                                                 603 }
604                                                   604 
605 # $1: ns, $2: old rm_sf counter in $ns            605 # $1: ns, $2: old rm_sf counter in $ns
606 wait_rm_sf()                                      606 wait_rm_sf()
607 {                                                 607 {
608         local ns="${1}"                           608         local ns="${1}"
609         local old_cnt="${2}"                      609         local old_cnt="${2}"
610         local cnt                                 610         local cnt
611                                                   611 
612         local i                                   612         local i
613         for i in $(seq 10); do                    613         for i in $(seq 10); do
614                 cnt=$(rm_sf_count ${ns})          614                 cnt=$(rm_sf_count ${ns})
615                 [ "$cnt" = "${old_cnt}" ] || b    615                 [ "$cnt" = "${old_cnt}" ] || break
616                 sleep 0.1                         616                 sleep 0.1
617         done                                      617         done
618 }                                                 618 }
619                                                   619 
620 wait_mpj()                                        620 wait_mpj()
621 {                                                 621 {
622         local ns="${1}"                           622         local ns="${1}"
623         local cnt old_cnt                         623         local cnt old_cnt
624                                                   624 
625         old_cnt=$(mptcp_lib_get_counter ${ns}     625         old_cnt=$(mptcp_lib_get_counter ${ns} "MPTcpExtMPJoinAckRx")
626                                                   626 
627         local i                                   627         local i
628         for i in $(seq 10); do                    628         for i in $(seq 10); do
629                 cnt=$(mptcp_lib_get_counter ${    629                 cnt=$(mptcp_lib_get_counter ${ns} "MPTcpExtMPJoinAckRx")
630                 [ "$cnt" = "${old_cnt}" ] || b    630                 [ "$cnt" = "${old_cnt}" ] || break
631                 sleep 0.1                         631                 sleep 0.1
632         done                                      632         done
633 }                                                 633 }
634                                                   634 
635 kill_events_pids()                                635 kill_events_pids()
636 {                                                 636 {
637         mptcp_lib_kill_wait $evts_ns1_pid         637         mptcp_lib_kill_wait $evts_ns1_pid
638         evts_ns1_pid=0                            638         evts_ns1_pid=0
639         mptcp_lib_kill_wait $evts_ns2_pid         639         mptcp_lib_kill_wait $evts_ns2_pid
640         evts_ns2_pid=0                            640         evts_ns2_pid=0
641 }                                                 641 }
642                                                   642 
643 pm_nl_set_limits()                                643 pm_nl_set_limits()
644 {                                                 644 {
645         mptcp_lib_pm_nl_set_limits "${@}"         645         mptcp_lib_pm_nl_set_limits "${@}"
646 }                                                 646 }
647                                                   647 
648 pm_nl_add_endpoint()                              648 pm_nl_add_endpoint()
649 {                                                 649 {
650         mptcp_lib_pm_nl_add_endpoint "${@}"       650         mptcp_lib_pm_nl_add_endpoint "${@}"
651 }                                                 651 }
652                                                   652 
653 pm_nl_del_endpoint()                              653 pm_nl_del_endpoint()
654 {                                                 654 {
655         mptcp_lib_pm_nl_del_endpoint "${@}"       655         mptcp_lib_pm_nl_del_endpoint "${@}"
656 }                                                 656 }
657                                                   657 
658 pm_nl_flush_endpoint()                            658 pm_nl_flush_endpoint()
659 {                                                 659 {
660         mptcp_lib_pm_nl_flush_endpoint "${@}"     660         mptcp_lib_pm_nl_flush_endpoint "${@}"
661 }                                                 661 }
662                                                   662 
663 pm_nl_show_endpoints()                            663 pm_nl_show_endpoints()
664 {                                                 664 {
665         mptcp_lib_pm_nl_show_endpoints "${@}"     665         mptcp_lib_pm_nl_show_endpoints "${@}"
666 }                                                 666 }
667                                                   667 
668 pm_nl_change_endpoint()                           668 pm_nl_change_endpoint()
669 {                                                 669 {
670         mptcp_lib_pm_nl_change_endpoint "${@}"    670         mptcp_lib_pm_nl_change_endpoint "${@}"
671 }                                                 671 }
672                                                   672 
673 pm_nl_check_endpoint()                            673 pm_nl_check_endpoint()
674 {                                                 674 {
675         local msg="$1"                            675         local msg="$1"
676         local ns=$2                               676         local ns=$2
677         local addr=$3                             677         local addr=$3
678         local flags dev id port                   678         local flags dev id port
679                                                   679 
680         print_check "${msg}"                      680         print_check "${msg}"
681                                                   681 
682         shift 3                                   682         shift 3
683         while [ -n "$1" ]; do                     683         while [ -n "$1" ]; do
684                 case "${1}" in                    684                 case "${1}" in
685                 "flags" | "dev" | "id" | "port    685                 "flags" | "dev" | "id" | "port")
686                         eval "${1}"="${2}"        686                         eval "${1}"="${2}"
687                         shift                     687                         shift
688                         ;;                        688                         ;;
689                 *)                                689                 *)
690                         ;;                        690                         ;;
691                 esac                              691                 esac
692                                                   692 
693                 shift                             693                 shift
694         done                                      694         done
695                                                   695 
696         if [ -z "${id}" ]; then                   696         if [ -z "${id}" ]; then
697                 fail_test "bad test - missing     697                 fail_test "bad test - missing endpoint id"
698                 return                            698                 return
699         fi                                        699         fi
700                                                   700 
701         check_output "mptcp_lib_pm_nl_get_endp    701         check_output "mptcp_lib_pm_nl_get_endpoint ${ns} ${id}" \
702                 "$(mptcp_lib_pm_nl_format_endp    702                 "$(mptcp_lib_pm_nl_format_endpoints \
703                         "${id},${addr},${flags    703                         "${id},${addr},${flags//","/" "},${dev},${port}")"
704 }                                                 704 }
705                                                   705 
706 pm_nl_set_endpoint()                              706 pm_nl_set_endpoint()
707 {                                                 707 {
708         local listener_ns="$1"                    708         local listener_ns="$1"
709         local connector_ns="$2"                   709         local connector_ns="$2"
710         local connect_addr="$3"                   710         local connect_addr="$3"
711                                                   711 
712         local addr_nr_ns1=${addr_nr_ns1:-0}       712         local addr_nr_ns1=${addr_nr_ns1:-0}
713         local addr_nr_ns2=${addr_nr_ns2:-0}       713         local addr_nr_ns2=${addr_nr_ns2:-0}
714         local sflags=${sflags:-""}                714         local sflags=${sflags:-""}
715         local fullmesh=${fullmesh:-""}            715         local fullmesh=${fullmesh:-""}
716                                                   716 
717         local flags="subflow"                     717         local flags="subflow"
718         if [ -n "${fullmesh}" ]; then             718         if [ -n "${fullmesh}" ]; then
719                 flags="${flags},fullmesh"         719                 flags="${flags},fullmesh"
720                 addr_nr_ns2=${fullmesh}           720                 addr_nr_ns2=${fullmesh}
721         fi                                        721         fi
722                                                   722 
723         # let the mptcp subflow be established    723         # let the mptcp subflow be established in background before
724         # do endpoint manipulation                724         # do endpoint manipulation
725         if [ $addr_nr_ns1 != "0" ] || [ $addr_    725         if [ $addr_nr_ns1 != "0" ] || [ $addr_nr_ns2 != "0" ]; then
726                 sleep 1                           726                 sleep 1
727         fi                                        727         fi
728                                                   728 
729         if [ $addr_nr_ns1 -gt 0 ]; then           729         if [ $addr_nr_ns1 -gt 0 ]; then
730                 local counter=2                   730                 local counter=2
731                 local add_nr_ns1=${addr_nr_ns1    731                 local add_nr_ns1=${addr_nr_ns1}
732                 local id=10                       732                 local id=10
733                 while [ $add_nr_ns1 -gt 0 ]; d    733                 while [ $add_nr_ns1 -gt 0 ]; do
734                         local addr                734                         local addr
735                         if mptcp_lib_is_v6 "${    735                         if mptcp_lib_is_v6 "${connect_addr}"; then
736                                 addr="dead:bee    736                                 addr="dead:beef:$counter::1"
737                         else                      737                         else
738                                 addr="10.0.$co    738                                 addr="10.0.$counter.1"
739                         fi                        739                         fi
740                         pm_nl_add_endpoint $ns    740                         pm_nl_add_endpoint $ns1 $addr flags signal
741                         counter=$((counter + 1    741                         counter=$((counter + 1))
742                         add_nr_ns1=$((add_nr_n    742                         add_nr_ns1=$((add_nr_ns1 - 1))
743                         id=$((id + 1))            743                         id=$((id + 1))
744                 done                              744                 done
745         elif [ $addr_nr_ns1 -lt 0 ]; then         745         elif [ $addr_nr_ns1 -lt 0 ]; then
746                 local rm_nr_ns1=$((-addr_nr_ns    746                 local rm_nr_ns1=$((-addr_nr_ns1))
747                 if [ $rm_nr_ns1 -lt 8 ]; then     747                 if [ $rm_nr_ns1 -lt 8 ]; then
748                         local counter=0           748                         local counter=0
749                         local line                749                         local line
750                         pm_nl_show_endpoints $    750                         pm_nl_show_endpoints ${listener_ns} | while read -r line; do
751                                 # shellcheck d    751                                 # shellcheck disable=SC2206 # we do want to split per word
752                                 local arr=($li    752                                 local arr=($line)
753                                 local nr=0        753                                 local nr=0
754                                                   754 
755                                 local i           755                                 local i
756                                 for i in "${ar    756                                 for i in "${arr[@]}"; do
757                                         if [ $    757                                         if [ $i = "id" ]; then
758                                                   758                                                 if [ $counter -eq $rm_nr_ns1 ]; then
759                                                   759                                                         break
760                                                   760                                                 fi
761                                                   761                                                 id=${arr[$nr+1]}
762                                                   762                                                 rm_addr=$(rm_addr_count ${connector_ns})
763                                                   763                                                 pm_nl_del_endpoint ${listener_ns} $id
764                                                   764                                                 wait_rm_addr ${connector_ns} ${rm_addr}
765                                                   765                                                 counter=$((counter + 1))
766                                         fi        766                                         fi
767                                         nr=$((    767                                         nr=$((nr + 1))
768                                 done              768                                 done
769                         done                      769                         done
770                 elif [ $rm_nr_ns1 -eq 8 ]; the    770                 elif [ $rm_nr_ns1 -eq 8 ]; then
771                         pm_nl_flush_endpoint $    771                         pm_nl_flush_endpoint ${listener_ns}
772                 elif [ $rm_nr_ns1 -eq 9 ]; the    772                 elif [ $rm_nr_ns1 -eq 9 ]; then
773                         pm_nl_del_endpoint ${l    773                         pm_nl_del_endpoint ${listener_ns} 0 ${connect_addr}
774                 fi                                774                 fi
775         fi                                        775         fi
776                                                   776 
777         # if newly added endpoints must be del    777         # if newly added endpoints must be deleted, give the background msk
778         # some time to created them               778         # some time to created them
779         [ $addr_nr_ns1 -gt 0 ] && [ $addr_nr_n    779         [ $addr_nr_ns1 -gt 0 ] && [ $addr_nr_ns2 -lt 0 ] && sleep 1
780                                                   780 
781         if [ $addr_nr_ns2 -gt 0 ]; then           781         if [ $addr_nr_ns2 -gt 0 ]; then
782                 local add_nr_ns2=${addr_nr_ns2    782                 local add_nr_ns2=${addr_nr_ns2}
783                 local counter=3                   783                 local counter=3
784                 local id=20                       784                 local id=20
785                 while [ $add_nr_ns2 -gt 0 ]; d    785                 while [ $add_nr_ns2 -gt 0 ]; do
786                         local addr                786                         local addr
787                         if mptcp_lib_is_v6 "${    787                         if mptcp_lib_is_v6 "${connect_addr}"; then
788                                 addr="dead:bee    788                                 addr="dead:beef:$counter::2"
789                         else                      789                         else
790                                 addr="10.0.$co    790                                 addr="10.0.$counter.2"
791                         fi                        791                         fi
792                         pm_nl_add_endpoint $ns    792                         pm_nl_add_endpoint $ns2 $addr flags $flags
793                         counter=$((counter + 1    793                         counter=$((counter + 1))
794                         add_nr_ns2=$((add_nr_n    794                         add_nr_ns2=$((add_nr_ns2 - 1))
795                         id=$((id + 1))            795                         id=$((id + 1))
796                 done                              796                 done
797         elif [ $addr_nr_ns2 -lt 0 ]; then         797         elif [ $addr_nr_ns2 -lt 0 ]; then
798                 local rm_nr_ns2=$((-addr_nr_ns    798                 local rm_nr_ns2=$((-addr_nr_ns2))
799                 if [ $rm_nr_ns2 -lt 8 ]; then     799                 if [ $rm_nr_ns2 -lt 8 ]; then
800                         local counter=0           800                         local counter=0
801                         local line                801                         local line
802                         pm_nl_show_endpoints $    802                         pm_nl_show_endpoints ${connector_ns} | while read -r line; do
803                                 # shellcheck d    803                                 # shellcheck disable=SC2206 # we do want to split per word
804                                 local arr=($li    804                                 local arr=($line)
805                                 local nr=0        805                                 local nr=0
806                                                   806 
807                                 local i           807                                 local i
808                                 for i in "${ar    808                                 for i in "${arr[@]}"; do
809                                         if [ $    809                                         if [ $i = "id" ]; then
810                                                   810                                                 if [ $counter -eq $rm_nr_ns2 ]; then
811                                                   811                                                         break
812                                                   812                                                 fi
813                                                   813                                                 local id rm_addr
814                                                   814                                                 # rm_addr are serialized, allow the previous one to
815                                                   815                                                 # complete
816                                                   816                                                 id=${arr[$nr+1]}
817                                                   817                                                 rm_addr=$(rm_addr_count ${listener_ns})
818                                                   818                                                 pm_nl_del_endpoint ${connector_ns} $id
819                                                   819                                                 wait_rm_addr ${listener_ns} ${rm_addr}
820                                                   820                                                 counter=$((counter + 1))
821                                         fi        821                                         fi
822                                         nr=$((    822                                         nr=$((nr + 1))
823                                 done              823                                 done
824                         done                      824                         done
825                 elif [ $rm_nr_ns2 -eq 8 ]; the    825                 elif [ $rm_nr_ns2 -eq 8 ]; then
826                         pm_nl_flush_endpoint $    826                         pm_nl_flush_endpoint ${connector_ns}
827                 elif [ $rm_nr_ns2 -eq 9 ]; the    827                 elif [ $rm_nr_ns2 -eq 9 ]; then
828                         local addr                828                         local addr
829                         if mptcp_lib_is_v6 "${    829                         if mptcp_lib_is_v6 "${connect_addr}"; then
830                                 addr="dead:bee    830                                 addr="dead:beef:1::2"
831                         else                      831                         else
832                                 addr="10.0.1.2    832                                 addr="10.0.1.2"
833                         fi                        833                         fi
834                         pm_nl_del_endpoint ${c    834                         pm_nl_del_endpoint ${connector_ns} 0 $addr
835                 fi                                835                 fi
836         fi                                        836         fi
837                                                   837 
838         if [ -n "${sflags}" ]; then               838         if [ -n "${sflags}" ]; then
839                 sleep 1                           839                 sleep 1
840                                                   840 
841                 local netns                       841                 local netns
842                 for netns in "$ns1" "$ns2"; do    842                 for netns in "$ns1" "$ns2"; do
843                         local line                843                         local line
844                         pm_nl_show_endpoints $    844                         pm_nl_show_endpoints $netns | while read -r line; do
845                                 # shellcheck d    845                                 # shellcheck disable=SC2206 # we do want to split per word
846                                 local arr=($li    846                                 local arr=($line)
847                                 local nr=0        847                                 local nr=0
848                                 local id          848                                 local id
849                                                   849 
850                                 local i           850                                 local i
851                                 for i in "${ar    851                                 for i in "${arr[@]}"; do
852                                         if [ $    852                                         if [ $i = "id" ]; then
853                                                   853                                                 id=${arr[$nr+1]}
854                                         fi        854                                         fi
855                                         nr=$((    855                                         nr=$((nr + 1))
856                                 done              856                                 done
857                                 pm_nl_change_e    857                                 pm_nl_change_endpoint $netns $id $sflags
858                         done                      858                         done
859                 done                              859                 done
860         fi                                        860         fi
861 }                                                 861 }
862                                                   862 
863 chk_cestab_nr()                                   863 chk_cestab_nr()
864 {                                                 864 {
865         local ns=$1                               865         local ns=$1
866         local cestab=$2                           866         local cestab=$2
867         local count                               867         local count
868                                                   868 
869         print_check "currently established: $c    869         print_check "currently established: $cestab"
870         count=$(mptcp_lib_get_counter ${ns} "M    870         count=$(mptcp_lib_get_counter ${ns} "MPTcpExtMPCurrEstab")
871         if [ -z "$count" ]; then                  871         if [ -z "$count" ]; then
872                 print_skip                        872                 print_skip
873         elif [ "$count" != "$cestab" ]; then      873         elif [ "$count" != "$cestab" ]; then
874                 fail_test "got $count current     874                 fail_test "got $count current establish[s] expected $cestab"
875         else                                      875         else
876                 print_ok                          876                 print_ok
877         fi                                        877         fi
878 }                                                 878 }
879                                                   879 
880 # $1 namespace 1, $2 namespace 2                  880 # $1 namespace 1, $2 namespace 2
881 check_cestab()                                    881 check_cestab()
882 {                                                 882 {
883         if [ -n "${cestab_ns1}" ]; then           883         if [ -n "${cestab_ns1}" ]; then
884                 chk_cestab_nr ${1} ${cestab_ns    884                 chk_cestab_nr ${1} ${cestab_ns1}
885         fi                                        885         fi
886         if [ -n "${cestab_ns2}" ]; then           886         if [ -n "${cestab_ns2}" ]; then
887                 chk_cestab_nr ${2} ${cestab_ns    887                 chk_cestab_nr ${2} ${cestab_ns2}
888         fi                                        888         fi
889 }                                                 889 }
890                                                   890 
891 cond_start_capture()                              891 cond_start_capture()
892 {                                                 892 {
893         local ns="$1"                             893         local ns="$1"
894                                                   894 
895         :> "$capout"                              895         :> "$capout"
896                                                   896 
897         if $capture; then                         897         if $capture; then
898                 local capuser capfile             898                 local capuser capfile
899                 if [ -z $SUDO_USER ]; then        899                 if [ -z $SUDO_USER ]; then
900                         capuser=""                900                         capuser=""
901                 else                              901                 else
902                         capuser="-Z $SUDO_USER    902                         capuser="-Z $SUDO_USER"
903                 fi                                903                 fi
904                                                   904 
905                 capfile=$(printf "mp_join-%02u    905                 capfile=$(printf "mp_join-%02u-%s.pcap" "$MPTCP_LIB_TEST_COUNTER" "$ns")
906                                                   906 
907                 echo "Capturing traffic for te    907                 echo "Capturing traffic for test $MPTCP_LIB_TEST_COUNTER into $capfile"
908                 ip netns exec "$ns" tcpdump -i    908                 ip netns exec "$ns" tcpdump -i any -s 65535 -B 32768 $capuser -w "$capfile" > "$capout" 2>&1 &
909                 cappid=$!                         909                 cappid=$!
910                                                   910 
911                 sleep 1                           911                 sleep 1
912         fi                                        912         fi
913 }                                                 913 }
914                                                   914 
915 cond_stop_capture()                               915 cond_stop_capture()
916 {                                                 916 {
917         if $capture; then                         917         if $capture; then
918                 sleep 1                           918                 sleep 1
919                 kill $cappid                      919                 kill $cappid
920                 cat "$capout"                     920                 cat "$capout"
921         fi                                        921         fi
922 }                                                 922 }
923                                                   923 
924 get_port()                                        924 get_port()
925 {                                                 925 {
926         echo "$((10000 + MPTCP_LIB_TEST_COUNTE    926         echo "$((10000 + MPTCP_LIB_TEST_COUNTER - 1))"
927 }                                                 927 }
928                                                   928 
929 do_transfer()                                     929 do_transfer()
930 {                                                 930 {
931         local listener_ns="$1"                    931         local listener_ns="$1"
932         local connector_ns="$2"                   932         local connector_ns="$2"
933         local cl_proto="$3"                       933         local cl_proto="$3"
934         local srv_proto="$4"                      934         local srv_proto="$4"
935         local connect_addr="$5"                   935         local connect_addr="$5"
936         local port                                936         local port
937                                                   937 
938         local FAILING_LINKS=${FAILING_LINKS:-"    938         local FAILING_LINKS=${FAILING_LINKS:-""}
939         local fastclose=${fastclose:-""}          939         local fastclose=${fastclose:-""}
940         local speed=${speed:-"fast"}              940         local speed=${speed:-"fast"}
941         port=$(get_port)                          941         port=$(get_port)
942                                                   942 
943         :> "$cout"                                943         :> "$cout"
944         :> "$sout"                                944         :> "$sout"
945                                                   945 
946         cond_start_capture ${listener_ns}         946         cond_start_capture ${listener_ns}
947                                                   947 
948         NSTAT_HISTORY=/tmp/${listener_ns}.nsta    948         NSTAT_HISTORY=/tmp/${listener_ns}.nstat ip netns exec ${listener_ns} \
949                 nstat -n                          949                 nstat -n
950         NSTAT_HISTORY=/tmp/${connector_ns}.nst    950         NSTAT_HISTORY=/tmp/${connector_ns}.nstat ip netns exec ${connector_ns} \
951                 nstat -n                          951                 nstat -n
952                                                   952 
953         local extra_args                          953         local extra_args
954         if [ $speed = "fast" ]; then              954         if [ $speed = "fast" ]; then
955                 extra_args="-j"                   955                 extra_args="-j"
956         elif [ $speed = "slow" ]; then            956         elif [ $speed = "slow" ]; then
957                 extra_args="-r 50"                957                 extra_args="-r 50"
958         elif [ $speed -gt 0 ]; then               958         elif [ $speed -gt 0 ]; then
959                 extra_args="-r ${speed}"          959                 extra_args="-r ${speed}"
960         fi                                        960         fi
961                                                   961 
962         local extra_cl_args=""                    962         local extra_cl_args=""
963         local extra_srv_args=""                   963         local extra_srv_args=""
964         local trunc_size=""                       964         local trunc_size=""
965         if [ -n "${fastclose}" ]; then            965         if [ -n "${fastclose}" ]; then
966                 if [ ${test_linkfail} -le 1 ];    966                 if [ ${test_linkfail} -le 1 ]; then
967                         fail_test "fastclose t    967                         fail_test "fastclose tests need test_linkfail argument"
968                         return 1                  968                         return 1
969                 fi                                969                 fi
970                                                   970 
971                 # disconnect                      971                 # disconnect
972                 trunc_size=${test_linkfail}       972                 trunc_size=${test_linkfail}
973                 local side=${fastclose}           973                 local side=${fastclose}
974                                                   974 
975                 if [ ${side} = "client" ]; the    975                 if [ ${side} = "client" ]; then
976                         extra_cl_args="-f ${te    976                         extra_cl_args="-f ${test_linkfail}"
977                         extra_srv_args="-f -1"    977                         extra_srv_args="-f -1"
978                 elif [ ${side} = "server" ]; t    978                 elif [ ${side} = "server" ]; then
979                         extra_srv_args="-f ${t    979                         extra_srv_args="-f ${test_linkfail}"
980                         extra_cl_args="-f -1"     980                         extra_cl_args="-f -1"
981                 else                              981                 else
982                         fail_test "wrong/unkno    982                         fail_test "wrong/unknown fastclose spec ${side}"
983                         return 1                  983                         return 1
984                 fi                                984                 fi
985         fi                                        985         fi
986                                                   986 
987         extra_srv_args="$extra_args $extra_srv    987         extra_srv_args="$extra_args $extra_srv_args"
988         if [ "$test_linkfail" -gt 1 ];then        988         if [ "$test_linkfail" -gt 1 ];then
989                 timeout ${timeout_test} \         989                 timeout ${timeout_test} \
990                         ip netns exec ${listen    990                         ip netns exec ${listener_ns} \
991                                 ./mptcp_connec    991                                 ./mptcp_connect -t ${timeout_poll} -l -p $port -s ${srv_proto} \
992                                         $extra    992                                         $extra_srv_args "::" < "$sinfail" > "$sout" &
993         else                                      993         else
994                 timeout ${timeout_test} \         994                 timeout ${timeout_test} \
995                         ip netns exec ${listen    995                         ip netns exec ${listener_ns} \
996                                 ./mptcp_connec    996                                 ./mptcp_connect -t ${timeout_poll} -l -p $port -s ${srv_proto} \
997                                         $extra    997                                         $extra_srv_args "::" < "$sin" > "$sout" &
998         fi                                        998         fi
999         local spid=$!                             999         local spid=$!
1000                                                  1000 
1001         mptcp_lib_wait_local_port_listen "${l    1001         mptcp_lib_wait_local_port_listen "${listener_ns}" "${port}"
1002                                                  1002 
1003         extra_cl_args="$extra_args $extra_cl_    1003         extra_cl_args="$extra_args $extra_cl_args"
1004         if [ "$test_linkfail" -eq 0 ];then       1004         if [ "$test_linkfail" -eq 0 ];then
1005                 timeout ${timeout_test} \        1005                 timeout ${timeout_test} \
1006                         ip netns exec ${conne    1006                         ip netns exec ${connector_ns} \
1007                                 ./mptcp_conne    1007                                 ./mptcp_connect -t ${timeout_poll} -p $port -s ${cl_proto} \
1008                                         $extr    1008                                         $extra_cl_args $connect_addr < "$cin" > "$cout" &
1009         elif [ "$test_linkfail" -eq 1 ] || [     1009         elif [ "$test_linkfail" -eq 1 ] || [ "$test_linkfail" -eq 2 ];then
1010                 ( cat "$cinfail" ; sleep 2; l    1010                 ( cat "$cinfail" ; sleep 2; link_failure $listener_ns ; cat "$cinfail" ) | \
1011                         tee "$cinsent" | \       1011                         tee "$cinsent" | \
1012                         timeout ${timeout_tes    1012                         timeout ${timeout_test} \
1013                                 ip netns exec    1013                                 ip netns exec ${connector_ns} \
1014                                         ./mpt    1014                                         ./mptcp_connect -t ${timeout_poll} -p $port -s ${cl_proto} \
1015                                                  1015                                                 $extra_cl_args $connect_addr > "$cout" &
1016         else                                     1016         else
1017                 tee "$cinsent" < "$cinfail" |    1017                 tee "$cinsent" < "$cinfail" | \
1018                         timeout ${timeout_tes    1018                         timeout ${timeout_test} \
1019                                 ip netns exec    1019                                 ip netns exec ${connector_ns} \
1020                                         ./mpt    1020                                         ./mptcp_connect -t ${timeout_poll} -p $port -s ${cl_proto} \
1021                                                  1021                                                 $extra_cl_args $connect_addr > "$cout" &
1022         fi                                       1022         fi
1023         local cpid=$!                            1023         local cpid=$!
1024                                                  1024 
1025         pm_nl_set_endpoint $listener_ns $conn    1025         pm_nl_set_endpoint $listener_ns $connector_ns $connect_addr
1026         check_cestab $listener_ns $connector_    1026         check_cestab $listener_ns $connector_ns
1027                                                  1027 
1028         wait $cpid                               1028         wait $cpid
1029         local retc=$?                            1029         local retc=$?
1030         wait $spid                               1030         wait $spid
1031         local rets=$?                            1031         local rets=$?
1032                                                  1032 
1033         cond_stop_capture                        1033         cond_stop_capture
1034                                                  1034 
1035         NSTAT_HISTORY=/tmp/${listener_ns}.nst    1035         NSTAT_HISTORY=/tmp/${listener_ns}.nstat ip netns exec ${listener_ns} \
1036                 nstat | grep Tcp > /tmp/${lis    1036                 nstat | grep Tcp > /tmp/${listener_ns}.out
1037         NSTAT_HISTORY=/tmp/${connector_ns}.ns    1037         NSTAT_HISTORY=/tmp/${connector_ns}.nstat ip netns exec ${connector_ns} \
1038                 nstat | grep Tcp > /tmp/${con    1038                 nstat | grep Tcp > /tmp/${connector_ns}.out
1039                                                  1039 
1040         if [ ${rets} -ne 0 ] || [ ${retc} -ne    1040         if [ ${rets} -ne 0 ] || [ ${retc} -ne 0 ]; then
1041                 fail_test "client exit code $    1041                 fail_test "client exit code $retc, server $rets"
1042                 echo -e "\nnetns ${listener_n    1042                 echo -e "\nnetns ${listener_ns} socket stat for ${port}:" 1>&2
1043                 ip netns exec ${listener_ns}     1043                 ip netns exec ${listener_ns} ss -Menita 1>&2 -o "sport = :$port"
1044                 cat /tmp/${listener_ns}.out      1044                 cat /tmp/${listener_ns}.out
1045                 echo -e "\nnetns ${connector_    1045                 echo -e "\nnetns ${connector_ns} socket stat for ${port}:" 1>&2
1046                 ip netns exec ${connector_ns}    1046                 ip netns exec ${connector_ns} ss -Menita 1>&2 -o "dport = :$port"
1047                 cat /tmp/${connector_ns}.out     1047                 cat /tmp/${connector_ns}.out
1048                                                  1048 
1049                 return 1                         1049                 return 1
1050         fi                                       1050         fi
1051                                                  1051 
1052         if [ "$test_linkfail" -gt 1 ];then       1052         if [ "$test_linkfail" -gt 1 ];then
1053                 check_transfer $sinfail $cout    1053                 check_transfer $sinfail $cout "file received by client" $trunc_size
1054         else                                     1054         else
1055                 check_transfer $sin $cout "fi    1055                 check_transfer $sin $cout "file received by client" $trunc_size
1056         fi                                       1056         fi
1057         retc=$?                                  1057         retc=$?
1058         if [ "$test_linkfail" -eq 0 ];then       1058         if [ "$test_linkfail" -eq 0 ];then
1059                 check_transfer $cin $sout "fi    1059                 check_transfer $cin $sout "file received by server" $trunc_size
1060         else                                     1060         else
1061                 check_transfer $cinsent $sout    1061                 check_transfer $cinsent $sout "file received by server" $trunc_size
1062         fi                                       1062         fi
1063         rets=$?                                  1063         rets=$?
1064                                                  1064 
1065         [ $retc -eq 0 ] && [ $rets -eq 0 ]       1065         [ $retc -eq 0 ] && [ $rets -eq 0 ]
1066 }                                                1066 }
1067                                                  1067 
1068 make_file()                                      1068 make_file()
1069 {                                                1069 {
1070         local name=$1                            1070         local name=$1
1071         local who=$2                             1071         local who=$2
1072         local size=$3                            1072         local size=$3
1073                                                  1073 
1074         mptcp_lib_make_file $name 1024 $size     1074         mptcp_lib_make_file $name 1024 $size
1075                                                  1075 
1076         print_info "Test file (size $size KB)    1076         print_info "Test file (size $size KB) for $who"
1077 }                                                1077 }
1078                                                  1078 
1079 run_tests()                                      1079 run_tests()
1080 {                                                1080 {
1081         local listener_ns="$1"                   1081         local listener_ns="$1"
1082         local connector_ns="$2"                  1082         local connector_ns="$2"
1083         local connect_addr="$3"                  1083         local connect_addr="$3"
1084                                                  1084 
1085         local size                               1085         local size
1086         local test_linkfail=${test_linkfail:-    1086         local test_linkfail=${test_linkfail:-0}
1087                                                  1087 
1088         # The values above 2 are reused to ma    1088         # The values above 2 are reused to make test files
1089         # with the given sizes (KB)              1089         # with the given sizes (KB)
1090         if [ "$test_linkfail" -gt 2 ]; then      1090         if [ "$test_linkfail" -gt 2 ]; then
1091                 size=$test_linkfail              1091                 size=$test_linkfail
1092                                                  1092 
1093                 if [ -z "$cinfail" ]; then       1093                 if [ -z "$cinfail" ]; then
1094                         cinfail=$(mktemp)        1094                         cinfail=$(mktemp)
1095                 fi                               1095                 fi
1096                 make_file "$cinfail" "client"    1096                 make_file "$cinfail" "client" $size
1097         # create the input file for the failu    1097         # create the input file for the failure test when
1098         # the first failure test run             1098         # the first failure test run
1099         elif [ "$test_linkfail" -ne 0 ] && [     1099         elif [ "$test_linkfail" -ne 0 ] && [ -z "$cinfail" ]; then
1100                 # the client file must be con    1100                 # the client file must be considerably larger
1101                 # of the maximum expected cwi    1101                 # of the maximum expected cwin value, or the
1102                 # link utilization will be no    1102                 # link utilization will be not predicable
1103                 size=$((RANDOM%2))               1103                 size=$((RANDOM%2))
1104                 size=$((size+1))                 1104                 size=$((size+1))
1105                 size=$((size*8192))              1105                 size=$((size*8192))
1106                 size=$((size + ( RANDOM % 819    1106                 size=$((size + ( RANDOM % 8192) ))
1107                                                  1107 
1108                 cinfail=$(mktemp)                1108                 cinfail=$(mktemp)
1109                 make_file "$cinfail" "client"    1109                 make_file "$cinfail" "client" $size
1110         fi                                       1110         fi
1111                                                  1111 
1112         if [ "$test_linkfail" -gt 2 ]; then      1112         if [ "$test_linkfail" -gt 2 ]; then
1113                 size=$test_linkfail              1113                 size=$test_linkfail
1114                                                  1114 
1115                 if [ -z "$sinfail" ]; then       1115                 if [ -z "$sinfail" ]; then
1116                         sinfail=$(mktemp)        1116                         sinfail=$(mktemp)
1117                 fi                               1117                 fi
1118                 make_file "$sinfail" "server"    1118                 make_file "$sinfail" "server" $size
1119         elif [ "$test_linkfail" -eq 2 ] && [     1119         elif [ "$test_linkfail" -eq 2 ] && [ -z "$sinfail" ]; then
1120                 size=$((RANDOM%16))              1120                 size=$((RANDOM%16))
1121                 size=$((size+1))                 1121                 size=$((size+1))
1122                 size=$((size*2048))              1122                 size=$((size*2048))
1123                                                  1123 
1124                 sinfail=$(mktemp)                1124                 sinfail=$(mktemp)
1125                 make_file "$sinfail" "server"    1125                 make_file "$sinfail" "server" $size
1126         fi                                       1126         fi
1127                                                  1127 
1128         do_transfer ${listener_ns} ${connecto    1128         do_transfer ${listener_ns} ${connector_ns} MPTCP MPTCP ${connect_addr}
1129 }                                                1129 }
1130                                                  1130 
1131 dump_stats()                                     1131 dump_stats()
1132 {                                                1132 {
1133         echo Server ns stats                     1133         echo Server ns stats
1134         ip netns exec $ns1 nstat -as | grep T    1134         ip netns exec $ns1 nstat -as | grep Tcp
1135         echo Client ns stats                     1135         echo Client ns stats
1136         ip netns exec $ns2 nstat -as | grep T    1136         ip netns exec $ns2 nstat -as | grep Tcp
1137 }                                                1137 }
1138                                                  1138 
1139 chk_csum_nr()                                    1139 chk_csum_nr()
1140 {                                                1140 {
1141         local csum_ns1=${1:-0}                   1141         local csum_ns1=${1:-0}
1142         local csum_ns2=${2:-0}                   1142         local csum_ns2=${2:-0}
1143         local count                              1143         local count
1144         local extra_msg=""                       1144         local extra_msg=""
1145         local allow_multi_errors_ns1=0           1145         local allow_multi_errors_ns1=0
1146         local allow_multi_errors_ns2=0           1146         local allow_multi_errors_ns2=0
1147                                                  1147 
1148         if [[ "${csum_ns1}" = "+"* ]]; then      1148         if [[ "${csum_ns1}" = "+"* ]]; then
1149                 allow_multi_errors_ns1=1         1149                 allow_multi_errors_ns1=1
1150                 csum_ns1=${csum_ns1:1}           1150                 csum_ns1=${csum_ns1:1}
1151         fi                                       1151         fi
1152         if [[ "${csum_ns2}" = "+"* ]]; then      1152         if [[ "${csum_ns2}" = "+"* ]]; then
1153                 allow_multi_errors_ns2=1         1153                 allow_multi_errors_ns2=1
1154                 csum_ns2=${csum_ns2:1}           1154                 csum_ns2=${csum_ns2:1}
1155         fi                                       1155         fi
1156                                                  1156 
1157         print_check "checksum server"            1157         print_check "checksum server"
1158         count=$(mptcp_lib_get_counter ${ns1}     1158         count=$(mptcp_lib_get_counter ${ns1} "MPTcpExtDataCsumErr")
1159         if [ -n "$count" ] && [ "$count" != "    1159         if [ -n "$count" ] && [ "$count" != "$csum_ns1" ]; then
1160                 extra_msg+=" ns1=$count"         1160                 extra_msg+=" ns1=$count"
1161         fi                                       1161         fi
1162         if [ -z "$count" ]; then                 1162         if [ -z "$count" ]; then
1163                 print_skip                       1163                 print_skip
1164         elif { [ "$count" != $csum_ns1 ] && [    1164         elif { [ "$count" != $csum_ns1 ] && [ $allow_multi_errors_ns1 -eq 0 ]; } ||
1165              { [ "$count" -lt $csum_ns1 ] &&     1165              { [ "$count" -lt $csum_ns1 ] && [ $allow_multi_errors_ns1 -eq 1 ]; }; then
1166                 fail_test "got $count data ch    1166                 fail_test "got $count data checksum error[s] expected $csum_ns1"
1167         else                                     1167         else
1168                 print_ok                         1168                 print_ok
1169         fi                                       1169         fi
1170                                                  1170 
1171         print_check "checksum client"            1171         print_check "checksum client"
1172         count=$(mptcp_lib_get_counter ${ns2}     1172         count=$(mptcp_lib_get_counter ${ns2} "MPTcpExtDataCsumErr")
1173         if [ -n "$count" ] && [ "$count" != "    1173         if [ -n "$count" ] && [ "$count" != "$csum_ns2" ]; then
1174                 extra_msg+=" ns2=$count"         1174                 extra_msg+=" ns2=$count"
1175         fi                                       1175         fi
1176         if [ -z "$count" ]; then                 1176         if [ -z "$count" ]; then
1177                 print_skip                       1177                 print_skip
1178         elif { [ "$count" != $csum_ns2 ] && [    1178         elif { [ "$count" != $csum_ns2 ] && [ $allow_multi_errors_ns2 -eq 0 ]; } ||
1179              { [ "$count" -lt $csum_ns2 ] &&     1179              { [ "$count" -lt $csum_ns2 ] && [ $allow_multi_errors_ns2 -eq 1 ]; }; then
1180                 fail_test "got $count data ch    1180                 fail_test "got $count data checksum error[s] expected $csum_ns2"
1181         else                                     1181         else
1182                 print_ok                         1182                 print_ok
1183         fi                                       1183         fi
1184                                                  1184 
1185         print_info "$extra_msg"                  1185         print_info "$extra_msg"
1186 }                                                1186 }
1187                                                  1187 
1188 chk_fail_nr()                                    1188 chk_fail_nr()
1189 {                                                1189 {
1190         local fail_tx=$1                         1190         local fail_tx=$1
1191         local fail_rx=$2                         1191         local fail_rx=$2
1192         local ns_invert=${3:-""}                 1192         local ns_invert=${3:-""}
1193         local count                              1193         local count
1194         local ns_tx=$ns1                         1194         local ns_tx=$ns1
1195         local ns_rx=$ns2                         1195         local ns_rx=$ns2
1196         local tx="server"                        1196         local tx="server"
1197         local rx="client"                        1197         local rx="client"
1198         local extra_msg=""                       1198         local extra_msg=""
1199         local allow_tx_lost=0                    1199         local allow_tx_lost=0
1200         local allow_rx_lost=0                    1200         local allow_rx_lost=0
1201                                                  1201 
1202         if [[ $ns_invert = "invert" ]]; then     1202         if [[ $ns_invert = "invert" ]]; then
1203                 ns_tx=$ns2                       1203                 ns_tx=$ns2
1204                 ns_rx=$ns1                       1204                 ns_rx=$ns1
1205                 tx="client"                      1205                 tx="client"
1206                 rx="server"                      1206                 rx="server"
1207         fi                                       1207         fi
1208                                                  1208 
1209         if [[ "${fail_tx}" = "-"* ]]; then       1209         if [[ "${fail_tx}" = "-"* ]]; then
1210                 allow_tx_lost=1                  1210                 allow_tx_lost=1
1211                 fail_tx=${fail_tx:1}             1211                 fail_tx=${fail_tx:1}
1212         fi                                       1212         fi
1213         if [[ "${fail_rx}" = "-"* ]]; then       1213         if [[ "${fail_rx}" = "-"* ]]; then
1214                 allow_rx_lost=1                  1214                 allow_rx_lost=1
1215                 fail_rx=${fail_rx:1}             1215                 fail_rx=${fail_rx:1}
1216         fi                                       1216         fi
1217                                                  1217 
1218         print_check "fail tx ${tx}"              1218         print_check "fail tx ${tx}"
1219         count=$(mptcp_lib_get_counter ${ns_tx    1219         count=$(mptcp_lib_get_counter ${ns_tx} "MPTcpExtMPFailTx")
1220         if [ -n "$count" ] && [ "$count" != "    1220         if [ -n "$count" ] && [ "$count" != "$fail_tx" ]; then
1221                 extra_msg+=" tx=$count"          1221                 extra_msg+=" tx=$count"
1222         fi                                       1222         fi
1223         if [ -z "$count" ]; then                 1223         if [ -z "$count" ]; then
1224                 print_skip                       1224                 print_skip
1225         elif { [ "$count" != "$fail_tx" ] &&     1225         elif { [ "$count" != "$fail_tx" ] && [ $allow_tx_lost -eq 0 ]; } ||
1226              { [ "$count" -gt "$fail_tx" ] &&    1226              { [ "$count" -gt "$fail_tx" ] && [ $allow_tx_lost -eq 1 ]; }; then
1227                 fail_test "got $count MP_FAIL    1227                 fail_test "got $count MP_FAIL[s] TX expected $fail_tx"
1228         else                                     1228         else
1229                 print_ok                         1229                 print_ok
1230         fi                                       1230         fi
1231                                                  1231 
1232         print_check "fail rx ${rx}"              1232         print_check "fail rx ${rx}"
1233         count=$(mptcp_lib_get_counter ${ns_rx    1233         count=$(mptcp_lib_get_counter ${ns_rx} "MPTcpExtMPFailRx")
1234         if [ -n "$count" ] && [ "$count" != "    1234         if [ -n "$count" ] && [ "$count" != "$fail_rx" ]; then
1235                 extra_msg+=" rx=$count"          1235                 extra_msg+=" rx=$count"
1236         fi                                       1236         fi
1237         if [ -z "$count" ]; then                 1237         if [ -z "$count" ]; then
1238                 print_skip                       1238                 print_skip
1239         elif { [ "$count" != "$fail_rx" ] &&     1239         elif { [ "$count" != "$fail_rx" ] && [ $allow_rx_lost -eq 0 ]; } ||
1240              { [ "$count" -gt "$fail_rx" ] &&    1240              { [ "$count" -gt "$fail_rx" ] && [ $allow_rx_lost -eq 1 ]; }; then
1241                 fail_test "got $count MP_FAIL    1241                 fail_test "got $count MP_FAIL[s] RX expected $fail_rx"
1242         else                                     1242         else
1243                 print_ok                         1243                 print_ok
1244         fi                                       1244         fi
1245                                                  1245 
1246         print_info "$extra_msg"                  1246         print_info "$extra_msg"
1247 }                                                1247 }
1248                                                  1248 
1249 chk_fclose_nr()                                  1249 chk_fclose_nr()
1250 {                                                1250 {
1251         local fclose_tx=$1                       1251         local fclose_tx=$1
1252         local fclose_rx=$2                       1252         local fclose_rx=$2
1253         local ns_invert=$3                       1253         local ns_invert=$3
1254         local count                              1254         local count
1255         local ns_tx=$ns2                         1255         local ns_tx=$ns2
1256         local ns_rx=$ns1                         1256         local ns_rx=$ns1
1257         local tx="client"                        1257         local tx="client"
1258         local rx="server"                        1258         local rx="server"
1259                                                  1259 
1260         if [[ $ns_invert = "invert" ]]; then     1260         if [[ $ns_invert = "invert" ]]; then
1261                 ns_tx=$ns1                       1261                 ns_tx=$ns1
1262                 ns_rx=$ns2                       1262                 ns_rx=$ns2
1263                 tx="server"                      1263                 tx="server"
1264                 rx="client"                      1264                 rx="client"
1265         fi                                       1265         fi
1266                                                  1266 
1267         print_check "fast close tx ${tx}"        1267         print_check "fast close tx ${tx}"
1268         count=$(mptcp_lib_get_counter ${ns_tx    1268         count=$(mptcp_lib_get_counter ${ns_tx} "MPTcpExtMPFastcloseTx")
1269         if [ -z "$count" ]; then                 1269         if [ -z "$count" ]; then
1270                 print_skip                       1270                 print_skip
1271         elif [ "$count" != "$fclose_tx" ]; th    1271         elif [ "$count" != "$fclose_tx" ]; then
1272                 fail_test "got $count MP_FAST    1272                 fail_test "got $count MP_FASTCLOSE[s] TX expected $fclose_tx"
1273         else                                     1273         else
1274                 print_ok                         1274                 print_ok
1275         fi                                       1275         fi
1276                                                  1276 
1277         print_check "fast close rx ${rx}"        1277         print_check "fast close rx ${rx}"
1278         count=$(mptcp_lib_get_counter ${ns_rx    1278         count=$(mptcp_lib_get_counter ${ns_rx} "MPTcpExtMPFastcloseRx")
1279         if [ -z "$count" ]; then                 1279         if [ -z "$count" ]; then
1280                 print_skip                       1280                 print_skip
1281         elif [ "$count" != "$fclose_rx" ]; th    1281         elif [ "$count" != "$fclose_rx" ]; then
1282                 fail_test "got $count MP_FAST    1282                 fail_test "got $count MP_FASTCLOSE[s] RX expected $fclose_rx"
1283         else                                     1283         else
1284                 print_ok                         1284                 print_ok
1285         fi                                       1285         fi
1286 }                                                1286 }
1287                                                  1287 
1288 chk_rst_nr()                                     1288 chk_rst_nr()
1289 {                                                1289 {
1290         local rst_tx=$1                          1290         local rst_tx=$1
1291         local rst_rx=$2                          1291         local rst_rx=$2
1292         local ns_invert=${3:-""}                 1292         local ns_invert=${3:-""}
1293         local count                              1293         local count
1294         local ns_tx=$ns1                         1294         local ns_tx=$ns1
1295         local ns_rx=$ns2                         1295         local ns_rx=$ns2
1296         local tx="server"                        1296         local tx="server"
1297         local rx="client"                        1297         local rx="client"
1298                                                  1298 
1299         if [[ $ns_invert = "invert" ]]; then     1299         if [[ $ns_invert = "invert" ]]; then
1300                 ns_tx=$ns2                       1300                 ns_tx=$ns2
1301                 ns_rx=$ns1                       1301                 ns_rx=$ns1
1302                 tx="client"                      1302                 tx="client"
1303                 rx="server"                      1303                 rx="server"
1304         fi                                       1304         fi
1305                                                  1305 
1306         print_check "reset tx ${tx}"             1306         print_check "reset tx ${tx}"
1307         count=$(mptcp_lib_get_counter ${ns_tx    1307         count=$(mptcp_lib_get_counter ${ns_tx} "MPTcpExtMPRstTx")
1308         if [ -z "$count" ]; then                 1308         if [ -z "$count" ]; then
1309                 print_skip                       1309                 print_skip
1310         # accept more rst than expected excep    1310         # accept more rst than expected except if we don't expect any
1311         elif { [ $rst_tx -ne 0 ] && [ $count     1311         elif { [ $rst_tx -ne 0 ] && [ $count -lt $rst_tx ]; } ||
1312              { [ $rst_tx -eq 0 ] && [ $count     1312              { [ $rst_tx -eq 0 ] && [ $count -ne 0 ]; }; then
1313                 fail_test "got $count MP_RST[    1313                 fail_test "got $count MP_RST[s] TX expected $rst_tx"
1314         else                                     1314         else
1315                 print_ok                         1315                 print_ok
1316         fi                                       1316         fi
1317                                                  1317 
1318         print_check "reset rx ${rx}"             1318         print_check "reset rx ${rx}"
1319         count=$(mptcp_lib_get_counter ${ns_rx    1319         count=$(mptcp_lib_get_counter ${ns_rx} "MPTcpExtMPRstRx")
1320         if [ -z "$count" ]; then                 1320         if [ -z "$count" ]; then
1321                 print_skip                       1321                 print_skip
1322         # accept more rst than expected excep    1322         # accept more rst than expected except if we don't expect any
1323         elif { [ $rst_rx -ne 0 ] && [ $count     1323         elif { [ $rst_rx -ne 0 ] && [ $count -lt $rst_rx ]; } ||
1324              { [ $rst_rx -eq 0 ] && [ $count     1324              { [ $rst_rx -eq 0 ] && [ $count -ne 0 ]; }; then
1325                 fail_test "got $count MP_RST[    1325                 fail_test "got $count MP_RST[s] RX expected $rst_rx"
1326         else                                     1326         else
1327                 print_ok                         1327                 print_ok
1328         fi                                       1328         fi
1329 }                                                1329 }
1330                                                  1330 
1331 chk_infi_nr()                                    1331 chk_infi_nr()
1332 {                                                1332 {
1333         local infi_tx=$1                         1333         local infi_tx=$1
1334         local infi_rx=$2                         1334         local infi_rx=$2
1335         local count                              1335         local count
1336                                                  1336 
1337         print_check "infi tx client"             1337         print_check "infi tx client"
1338         count=$(mptcp_lib_get_counter ${ns2}     1338         count=$(mptcp_lib_get_counter ${ns2} "MPTcpExtInfiniteMapTx")
1339         if [ -z "$count" ]; then                 1339         if [ -z "$count" ]; then
1340                 print_skip                       1340                 print_skip
1341         elif [ "$count" != "$infi_tx" ]; then    1341         elif [ "$count" != "$infi_tx" ]; then
1342                 fail_test "got $count infinit    1342                 fail_test "got $count infinite map[s] TX expected $infi_tx"
1343         else                                     1343         else
1344                 print_ok                         1344                 print_ok
1345         fi                                       1345         fi
1346                                                  1346 
1347         print_check "infi rx server"             1347         print_check "infi rx server"
1348         count=$(mptcp_lib_get_counter ${ns1}     1348         count=$(mptcp_lib_get_counter ${ns1} "MPTcpExtInfiniteMapRx")
1349         if [ -z "$count" ]; then                 1349         if [ -z "$count" ]; then
1350                 print_skip                       1350                 print_skip
1351         elif [ "$count" != "$infi_rx" ]; then    1351         elif [ "$count" != "$infi_rx" ]; then
1352                 fail_test "got $count infinit    1352                 fail_test "got $count infinite map[s] RX expected $infi_rx"
1353         else                                     1353         else
1354                 print_ok                         1354                 print_ok
1355         fi                                       1355         fi
1356 }                                                1356 }
1357                                                  1357 
1358 chk_join_tx_nr()                                 1358 chk_join_tx_nr()
1359 {                                                1359 {
1360         local syn_tx=${join_syn_tx:-0}           1360         local syn_tx=${join_syn_tx:-0}
1361         local create=${join_create_err:-0}       1361         local create=${join_create_err:-0}
1362         local bind=${join_bind_err:-0}           1362         local bind=${join_bind_err:-0}
1363         local connect=${join_connect_err:-0}     1363         local connect=${join_connect_err:-0}
1364         local rc=${KSFT_PASS}                    1364         local rc=${KSFT_PASS}
1365         local count                              1365         local count
1366                                                  1366 
1367         count=$(mptcp_lib_get_counter ${ns2}     1367         count=$(mptcp_lib_get_counter ${ns2} "MPTcpExtMPJoinSynTx")
1368         if [ -z "$count" ]; then                 1368         if [ -z "$count" ]; then
1369                 rc=${KSFT_SKIP}                  1369                 rc=${KSFT_SKIP}
1370         elif [ "$count" != "$syn_tx" ]; then     1370         elif [ "$count" != "$syn_tx" ]; then
1371                 rc=${KSFT_FAIL}                  1371                 rc=${KSFT_FAIL}
1372                 print_check "syn tx"             1372                 print_check "syn tx"
1373                 fail_test "got $count JOIN[s]    1373                 fail_test "got $count JOIN[s] syn tx expected $syn_tx"
1374         fi                                       1374         fi
1375                                                  1375 
1376         count=$(mptcp_lib_get_counter ${ns2}     1376         count=$(mptcp_lib_get_counter ${ns2} "MPTcpExtMPJoinSynTxCreatSkErr")
1377         if [ -z "$count" ]; then                 1377         if [ -z "$count" ]; then
1378                 rc=${KSFT_SKIP}                  1378                 rc=${KSFT_SKIP}
1379         elif [ "$count" != "$create" ]; then     1379         elif [ "$count" != "$create" ]; then
1380                 rc=${KSFT_FAIL}                  1380                 rc=${KSFT_FAIL}
1381                 print_check "syn tx create so    1381                 print_check "syn tx create socket error"
1382                 fail_test "got $count JOIN[s]    1382                 fail_test "got $count JOIN[s] syn tx create socket error expected $create"
1383         fi                                       1383         fi
1384                                                  1384 
1385         count=$(mptcp_lib_get_counter ${ns2}     1385         count=$(mptcp_lib_get_counter ${ns2} "MPTcpExtMPJoinSynTxBindErr")
1386         if [ -z "$count" ]; then                 1386         if [ -z "$count" ]; then
1387                 rc=${KSFT_SKIP}                  1387                 rc=${KSFT_SKIP}
1388         elif [ "$count" != "$bind" ]; then       1388         elif [ "$count" != "$bind" ]; then
1389                 rc=${KSFT_FAIL}                  1389                 rc=${KSFT_FAIL}
1390                 print_check "syn tx bind erro    1390                 print_check "syn tx bind error"
1391                 fail_test "got $count JOIN[s]    1391                 fail_test "got $count JOIN[s] syn tx bind error expected $bind"
1392         fi                                       1392         fi
1393                                                  1393 
1394         count=$(mptcp_lib_get_counter ${ns2}     1394         count=$(mptcp_lib_get_counter ${ns2} "MPTcpExtMPJoinSynTxConnectErr")
1395         if [ -z "$count" ]; then                 1395         if [ -z "$count" ]; then
1396                 rc=${KSFT_SKIP}                  1396                 rc=${KSFT_SKIP}
1397         elif [ "$count" != "$connect" ]; then    1397         elif [ "$count" != "$connect" ]; then
1398                 rc=${KSFT_FAIL}                  1398                 rc=${KSFT_FAIL}
1399                 print_check "syn tx connect e    1399                 print_check "syn tx connect error"
1400                 fail_test "got $count JOIN[s]    1400                 fail_test "got $count JOIN[s] syn tx connect error expected $connect"
1401         fi                                       1401         fi
1402                                                  1402 
1403         print_results "join Tx" ${rc}            1403         print_results "join Tx" ${rc}
1404 }                                                1404 }
1405                                                  1405 
1406 chk_join_nr()                                    1406 chk_join_nr()
1407 {                                                1407 {
1408         local syn_nr=$1                          1408         local syn_nr=$1
1409         local syn_ack_nr=$2                      1409         local syn_ack_nr=$2
1410         local ack_nr=$3                          1410         local ack_nr=$3
1411         local csum_ns1=${join_csum_ns1:-0}       1411         local csum_ns1=${join_csum_ns1:-0}
1412         local csum_ns2=${join_csum_ns2:-0}       1412         local csum_ns2=${join_csum_ns2:-0}
1413         local fail_nr=${join_fail_nr:-0}         1413         local fail_nr=${join_fail_nr:-0}
1414         local rst_nr=${join_rst_nr:-0}           1414         local rst_nr=${join_rst_nr:-0}
1415         local infi_nr=${join_infi_nr:-0}         1415         local infi_nr=${join_infi_nr:-0}
1416         local corrupted_pkts=${join_corrupted    1416         local corrupted_pkts=${join_corrupted_pkts:-0}
1417         local rc=${KSFT_PASS}                    1417         local rc=${KSFT_PASS}
1418         local count                              1418         local count
1419         local with_cookie                        1419         local with_cookie
1420                                                  1420 
1421         if [ "${corrupted_pkts}" -gt 0 ]; the    1421         if [ "${corrupted_pkts}" -gt 0 ]; then
1422                 print_info "${corrupted_pkts}    1422                 print_info "${corrupted_pkts} corrupted pkts"
1423         fi                                       1423         fi
1424                                                  1424 
1425         count=$(mptcp_lib_get_counter ${ns1}     1425         count=$(mptcp_lib_get_counter ${ns1} "MPTcpExtMPJoinSynRx")
1426         if [ -z "$count" ]; then                 1426         if [ -z "$count" ]; then
1427                 rc=${KSFT_SKIP}                  1427                 rc=${KSFT_SKIP}
1428         elif [ "$count" != "$syn_nr" ]; then     1428         elif [ "$count" != "$syn_nr" ]; then
1429                 rc=${KSFT_FAIL}                  1429                 rc=${KSFT_FAIL}
1430                 print_check "syn rx"             1430                 print_check "syn rx"
1431                 fail_test "got $count JOIN[s]    1431                 fail_test "got $count JOIN[s] syn rx expected $syn_nr"
1432         fi                                       1432         fi
1433                                                  1433 
1434         with_cookie=$(ip netns exec $ns2 sysc    1434         with_cookie=$(ip netns exec $ns2 sysctl -n net.ipv4.tcp_syncookies)
1435         count=$(mptcp_lib_get_counter ${ns2}     1435         count=$(mptcp_lib_get_counter ${ns2} "MPTcpExtMPJoinSynAckRx")
1436         if [ -z "$count" ]; then                 1436         if [ -z "$count" ]; then
1437                 rc=${KSFT_SKIP}                  1437                 rc=${KSFT_SKIP}
1438         elif [ "$count" != "$syn_ack_nr" ]; t    1438         elif [ "$count" != "$syn_ack_nr" ]; then
1439                 # simult connections exceedin    1439                 # simult connections exceeding the limit with cookie enabled could go up to
1440                 # synack validation as the co    1440                 # synack validation as the conn limit can be enforced reliably only after
1441                 # the subflow creation           1441                 # the subflow creation
1442                 if [ "$with_cookie" != 2 ] ||    1442                 if [ "$with_cookie" != 2 ] || [ "$count" -le "$syn_ack_nr" ] || [ "$count" -gt "$syn_nr" ]; then
1443                         rc=${KSFT_FAIL}          1443                         rc=${KSFT_FAIL}
1444                         print_check "synack r    1444                         print_check "synack rx"
1445                         fail_test "got $count    1445                         fail_test "got $count JOIN[s] synack rx expected $syn_ack_nr"
1446                 fi                               1446                 fi
1447         fi                                       1447         fi
1448                                                  1448 
1449         count=$(mptcp_lib_get_counter ${ns1}     1449         count=$(mptcp_lib_get_counter ${ns1} "MPTcpExtMPJoinAckRx")
1450         if [ -z "$count" ]; then                 1450         if [ -z "$count" ]; then
1451                 rc=${KSFT_SKIP}                  1451                 rc=${KSFT_SKIP}
1452         elif [ "$count" != "$ack_nr" ]; then     1452         elif [ "$count" != "$ack_nr" ]; then
1453                 rc=${KSFT_FAIL}                  1453                 rc=${KSFT_FAIL}
1454                 print_check "ack rx"             1454                 print_check "ack rx"
1455                 fail_test "got $count JOIN[s]    1455                 fail_test "got $count JOIN[s] ack rx expected $ack_nr"
1456         fi                                       1456         fi
1457                                                  1457 
1458         print_results "join Rx" ${rc}            1458         print_results "join Rx" ${rc}
1459                                                  1459 
1460         join_syn_tx="${join_syn_tx:-${syn_nr}    1460         join_syn_tx="${join_syn_tx:-${syn_nr}}" \
1461                 chk_join_tx_nr                   1461                 chk_join_tx_nr
1462                                                  1462 
1463         if $validate_checksum; then              1463         if $validate_checksum; then
1464                 chk_csum_nr $csum_ns1 $csum_n    1464                 chk_csum_nr $csum_ns1 $csum_ns2
1465                 chk_fail_nr $fail_nr $fail_nr    1465                 chk_fail_nr $fail_nr $fail_nr
1466                 chk_rst_nr $rst_nr $rst_nr       1466                 chk_rst_nr $rst_nr $rst_nr
1467                 chk_infi_nr $infi_nr $infi_nr    1467                 chk_infi_nr $infi_nr $infi_nr
1468         fi                                       1468         fi
1469 }                                                1469 }
1470                                                  1470 
1471 # a negative value for 'stale_max' means no u    1471 # a negative value for 'stale_max' means no upper bound:
1472 # for bidirectional transfer, if one peer sle    1472 # for bidirectional transfer, if one peer sleep for a while
1473 # - as these tests do - we can have a quite h    1473 # - as these tests do - we can have a quite high number of
1474 # stale/recover conversions, proportional to     1474 # stale/recover conversions, proportional to
1475 # sleep duration/ MPTCP-level RTX interval.      1475 # sleep duration/ MPTCP-level RTX interval.
1476 chk_stale_nr()                                   1476 chk_stale_nr()
1477 {                                                1477 {
1478         local ns=$1                              1478         local ns=$1
1479         local stale_min=$2                       1479         local stale_min=$2
1480         local stale_max=$3                       1480         local stale_max=$3
1481         local stale_delta=$4                     1481         local stale_delta=$4
1482         local dump_stats                         1482         local dump_stats
1483         local stale_nr                           1483         local stale_nr
1484         local recover_nr                         1484         local recover_nr
1485                                                  1485 
1486         print_check "stale"                      1486         print_check "stale"
1487                                                  1487 
1488         stale_nr=$(mptcp_lib_get_counter ${ns    1488         stale_nr=$(mptcp_lib_get_counter ${ns} "MPTcpExtSubflowStale")
1489         recover_nr=$(mptcp_lib_get_counter ${    1489         recover_nr=$(mptcp_lib_get_counter ${ns} "MPTcpExtSubflowRecover")
1490         if [ -z "$stale_nr" ] || [ -z "$recov    1490         if [ -z "$stale_nr" ] || [ -z "$recover_nr" ]; then
1491                 print_skip                       1491                 print_skip
1492         elif [ $stale_nr -lt $stale_min ] ||     1492         elif [ $stale_nr -lt $stale_min ] ||
1493            { [ $stale_max -gt 0 ] && [ $stale    1493            { [ $stale_max -gt 0 ] && [ $stale_nr -gt $stale_max ]; } ||
1494            [ $((stale_nr - recover_nr)) -ne $    1494            [ $((stale_nr - recover_nr)) -ne $stale_delta ]; then
1495                 fail_test "got $stale_nr stal    1495                 fail_test "got $stale_nr stale[s] $recover_nr recover[s], " \
1496                      " expected stale in rang    1496                      " expected stale in range [$stale_min..$stale_max]," \
1497                      " stale-recover delta $s    1497                      " stale-recover delta $stale_delta"
1498                 dump_stats=1                     1498                 dump_stats=1
1499         else                                     1499         else
1500                 print_ok                         1500                 print_ok
1501         fi                                       1501         fi
1502                                                  1502 
1503         if [ "${dump_stats}" = 1 ]; then         1503         if [ "${dump_stats}" = 1 ]; then
1504                 echo $ns stats                   1504                 echo $ns stats
1505                 ip netns exec $ns ip -s link     1505                 ip netns exec $ns ip -s link show
1506                 ip netns exec $ns nstat -as |    1506                 ip netns exec $ns nstat -as | grep MPTcp
1507         fi                                       1507         fi
1508 }                                                1508 }
1509                                                  1509 
1510 chk_add_nr()                                     1510 chk_add_nr()
1511 {                                                1511 {
1512         local add_nr=$1                          1512         local add_nr=$1
1513         local echo_nr=$2                         1513         local echo_nr=$2
1514         local port_nr=${3:-0}                    1514         local port_nr=${3:-0}
1515         local ns_invert=${4:-""}                 1515         local ns_invert=${4:-""}
1516         local syn_nr=$port_nr                    1516         local syn_nr=$port_nr
1517         local syn_ack_nr=$port_nr                1517         local syn_ack_nr=$port_nr
1518         local ack_nr=$port_nr                    1518         local ack_nr=$port_nr
1519         local mis_syn_nr=0                       1519         local mis_syn_nr=0
1520         local mis_ack_nr=0                       1520         local mis_ack_nr=0
1521         local ns_tx=$ns1                         1521         local ns_tx=$ns1
1522         local ns_rx=$ns2                         1522         local ns_rx=$ns2
1523         local tx=""                              1523         local tx=""
1524         local rx=""                              1524         local rx=""
1525         local count                              1525         local count
1526         local timeout                            1526         local timeout
1527                                                  1527 
1528         if [[ $ns_invert = "invert" ]]; then     1528         if [[ $ns_invert = "invert" ]]; then
1529                 ns_tx=$ns2                       1529                 ns_tx=$ns2
1530                 ns_rx=$ns1                       1530                 ns_rx=$ns1
1531                 tx=" client"                     1531                 tx=" client"
1532                 rx=" server"                     1532                 rx=" server"
1533         fi                                       1533         fi
1534                                                  1534 
1535         timeout=$(ip netns exec ${ns_tx} sysc    1535         timeout=$(ip netns exec ${ns_tx} sysctl -n net.mptcp.add_addr_timeout)
1536                                                  1536 
1537         print_check "add addr rx${rx}"           1537         print_check "add addr rx${rx}"
1538         count=$(mptcp_lib_get_counter ${ns_rx    1538         count=$(mptcp_lib_get_counter ${ns_rx} "MPTcpExtAddAddr")
1539         if [ -z "$count" ]; then                 1539         if [ -z "$count" ]; then
1540                 print_skip                       1540                 print_skip
1541         # if the test configured a short time    1541         # if the test configured a short timeout tolerate greater then expected
1542         # add addrs options, due to retransmi    1542         # add addrs options, due to retransmissions
1543         elif [ "$count" != "$add_nr" ] && { [    1543         elif [ "$count" != "$add_nr" ] && { [ "$timeout" -gt 1 ] || [ "$count" -lt "$add_nr" ]; }; then
1544                 fail_test "got $count ADD_ADD    1544                 fail_test "got $count ADD_ADDR[s] expected $add_nr"
1545         else                                     1545         else
1546                 print_ok                         1546                 print_ok
1547         fi                                       1547         fi
1548                                                  1548 
1549         print_check "add addr echo rx${tx}"      1549         print_check "add addr echo rx${tx}"
1550         count=$(mptcp_lib_get_counter ${ns_tx    1550         count=$(mptcp_lib_get_counter ${ns_tx} "MPTcpExtEchoAdd")
1551         if [ -z "$count" ]; then                 1551         if [ -z "$count" ]; then
1552                 print_skip                       1552                 print_skip
1553         elif [ "$count" != "$echo_nr" ]; then    1553         elif [ "$count" != "$echo_nr" ]; then
1554                 fail_test "got $count ADD_ADD    1554                 fail_test "got $count ADD_ADDR echo[s] expected $echo_nr"
1555         else                                     1555         else
1556                 print_ok                         1556                 print_ok
1557         fi                                       1557         fi
1558                                                  1558 
1559         if [ $port_nr -gt 0 ]; then              1559         if [ $port_nr -gt 0 ]; then
1560                 print_check "add addr rx with    1560                 print_check "add addr rx with port${rx}"
1561                 count=$(mptcp_lib_get_counter    1561                 count=$(mptcp_lib_get_counter ${ns_rx} "MPTcpExtPortAdd")
1562                 if [ -z "$count" ]; then         1562                 if [ -z "$count" ]; then
1563                         print_skip               1563                         print_skip
1564                 elif [ "$count" != "$port_nr"    1564                 elif [ "$count" != "$port_nr" ]; then
1565                         fail_test "got $count    1565                         fail_test "got $count ADD_ADDR[s] with a port-number expected $port_nr"
1566                 else                             1566                 else
1567                         print_ok                 1567                         print_ok
1568                 fi                               1568                 fi
1569                                                  1569 
1570                 print_check "syn rx port${tx}    1570                 print_check "syn rx port${tx}"
1571                 count=$(mptcp_lib_get_counter    1571                 count=$(mptcp_lib_get_counter ${ns_tx} "MPTcpExtMPJoinPortSynRx")
1572                 if [ -z "$count" ]; then         1572                 if [ -z "$count" ]; then
1573                         print_skip               1573                         print_skip
1574                 elif [ "$count" != "$syn_nr"     1574                 elif [ "$count" != "$syn_nr" ]; then
1575                         fail_test "got $count    1575                         fail_test "got $count JOIN[s] syn with a different \
1576                                    port-numbe    1576                                    port-number expected $syn_nr"
1577                 else                             1577                 else
1578                         print_ok                 1578                         print_ok
1579                 fi                               1579                 fi
1580                                                  1580 
1581                 print_check "synack rx port${    1581                 print_check "synack rx port${rx}"
1582                 count=$(mptcp_lib_get_counter    1582                 count=$(mptcp_lib_get_counter ${ns_rx} "MPTcpExtMPJoinPortSynAckRx")
1583                 if [ -z "$count" ]; then         1583                 if [ -z "$count" ]; then
1584                         print_skip               1584                         print_skip
1585                 elif [ "$count" != "$syn_ack_    1585                 elif [ "$count" != "$syn_ack_nr" ]; then
1586                         fail_test "got $count    1586                         fail_test "got $count JOIN[s] synack with a different \
1587                                    port-numbe    1587                                    port-number expected $syn_ack_nr"
1588                 else                             1588                 else
1589                         print_ok                 1589                         print_ok
1590                 fi                               1590                 fi
1591                                                  1591 
1592                 print_check "ack rx port${tx}    1592                 print_check "ack rx port${tx}"
1593                 count=$(mptcp_lib_get_counter    1593                 count=$(mptcp_lib_get_counter ${ns_tx} "MPTcpExtMPJoinPortAckRx")
1594                 if [ -z "$count" ]; then         1594                 if [ -z "$count" ]; then
1595                         print_skip               1595                         print_skip
1596                 elif [ "$count" != "$ack_nr"     1596                 elif [ "$count" != "$ack_nr" ]; then
1597                         fail_test "got $count    1597                         fail_test "got $count JOIN[s] ack with a different \
1598                                    port-numbe    1598                                    port-number expected $ack_nr"
1599                 else                             1599                 else
1600                         print_ok                 1600                         print_ok
1601                 fi                               1601                 fi
1602                                                  1602 
1603                 print_check "syn rx port mism    1603                 print_check "syn rx port mismatch${tx}"
1604                 count=$(mptcp_lib_get_counter    1604                 count=$(mptcp_lib_get_counter ${ns_tx} "MPTcpExtMismatchPortSynRx")
1605                 if [ -z "$count" ]; then         1605                 if [ -z "$count" ]; then
1606                         print_skip               1606                         print_skip
1607                 elif [ "$count" != "$mis_syn_    1607                 elif [ "$count" != "$mis_syn_nr" ]; then
1608                         fail_test "got $count    1608                         fail_test "got $count JOIN[s] syn with a mismatched \
1609                                    port-numbe    1609                                    port-number expected $mis_syn_nr"
1610                 else                             1610                 else
1611                         print_ok                 1611                         print_ok
1612                 fi                               1612                 fi
1613                                                  1613 
1614                 print_check "ack rx port mism    1614                 print_check "ack rx port mismatch${tx}"
1615                 count=$(mptcp_lib_get_counter    1615                 count=$(mptcp_lib_get_counter ${ns_tx} "MPTcpExtMismatchPortAckRx")
1616                 if [ -z "$count" ]; then         1616                 if [ -z "$count" ]; then
1617                         print_skip               1617                         print_skip
1618                 elif [ "$count" != "$mis_ack_    1618                 elif [ "$count" != "$mis_ack_nr" ]; then
1619                         fail_test "got $count    1619                         fail_test "got $count JOIN[s] ack with a mismatched \
1620                                    port-numbe    1620                                    port-number expected $mis_ack_nr"
1621                 else                             1621                 else
1622                         print_ok                 1622                         print_ok
1623                 fi                               1623                 fi
1624         fi                                       1624         fi
1625 }                                                1625 }
1626                                                  1626 
1627 chk_add_tx_nr()                                  1627 chk_add_tx_nr()
1628 {                                                1628 {
1629         local add_tx_nr=$1                       1629         local add_tx_nr=$1
1630         local echo_tx_nr=$2                      1630         local echo_tx_nr=$2
1631         local timeout                            1631         local timeout
1632         local count                              1632         local count
1633                                                  1633 
1634         timeout=$(ip netns exec $ns1 sysctl -    1634         timeout=$(ip netns exec $ns1 sysctl -n net.mptcp.add_addr_timeout)
1635                                                  1635 
1636         print_check "add addr tx"                1636         print_check "add addr tx"
1637         count=$(mptcp_lib_get_counter ${ns1}     1637         count=$(mptcp_lib_get_counter ${ns1} "MPTcpExtAddAddrTx")
1638         if [ -z "$count" ]; then                 1638         if [ -z "$count" ]; then
1639                 print_skip                       1639                 print_skip
1640         # if the test configured a short time    1640         # if the test configured a short timeout tolerate greater then expected
1641         # add addrs options, due to retransmi    1641         # add addrs options, due to retransmissions
1642         elif [ "$count" != "$add_tx_nr" ] &&     1642         elif [ "$count" != "$add_tx_nr" ] && { [ "$timeout" -gt 1 ] || [ "$count" -lt "$add_tx_nr" ]; }; then
1643                 fail_test "got $count ADD_ADD    1643                 fail_test "got $count ADD_ADDR[s] TX, expected $add_tx_nr"
1644         else                                     1644         else
1645                 print_ok                         1645                 print_ok
1646         fi                                       1646         fi
1647                                                  1647 
1648         print_check "add addr echo tx"           1648         print_check "add addr echo tx"
1649         count=$(mptcp_lib_get_counter ${ns2}     1649         count=$(mptcp_lib_get_counter ${ns2} "MPTcpExtEchoAddTx")
1650         if [ -z "$count" ]; then                 1650         if [ -z "$count" ]; then
1651                 print_skip                       1651                 print_skip
1652         elif [ "$count" != "$echo_tx_nr" ]; t    1652         elif [ "$count" != "$echo_tx_nr" ]; then
1653                 fail_test "got $count ADD_ADD    1653                 fail_test "got $count ADD_ADDR echo[s] TX, expected $echo_tx_nr"
1654         else                                     1654         else
1655                 print_ok                         1655                 print_ok
1656         fi                                       1656         fi
1657 }                                                1657 }
1658                                                  1658 
1659 chk_rm_nr()                                      1659 chk_rm_nr()
1660 {                                                1660 {
1661         local rm_addr_nr=$1                      1661         local rm_addr_nr=$1
1662         local rm_subflow_nr=$2                   1662         local rm_subflow_nr=$2
1663         local invert                             1663         local invert
1664         local simult                             1664         local simult
1665         local count                              1665         local count
1666         local addr_ns=$ns1                       1666         local addr_ns=$ns1
1667         local subflow_ns=$ns2                    1667         local subflow_ns=$ns2
1668         local addr="server"                      1668         local addr="server"
1669         local subflow="client"                   1669         local subflow="client"
1670         local extra_msg=""                       1670         local extra_msg=""
1671                                                  1671 
1672         shift 2                                  1672         shift 2
1673         while [ -n "$1" ]; do                    1673         while [ -n "$1" ]; do
1674                 [ "$1" = "invert" ] && invert    1674                 [ "$1" = "invert" ] && invert=true
1675                 [ "$1" = "simult" ] && simult    1675                 [ "$1" = "simult" ] && simult=true
1676                 shift                            1676                 shift
1677         done                                     1677         done
1678                                                  1678 
1679         if [ "$invert" = "true" ]; then          1679         if [ "$invert" = "true" ]; then
1680                 addr_ns=$ns2                     1680                 addr_ns=$ns2
1681                 subflow_ns=$ns1                  1681                 subflow_ns=$ns1
1682                 addr="client"                    1682                 addr="client"
1683                 subflow="server"                 1683                 subflow="server"
1684         fi                                       1684         fi
1685                                                  1685 
1686         print_check "rm addr rx ${addr}"         1686         print_check "rm addr rx ${addr}"
1687         count=$(mptcp_lib_get_counter ${addr_    1687         count=$(mptcp_lib_get_counter ${addr_ns} "MPTcpExtRmAddr")
1688         if [ -z "$count" ]; then                 1688         if [ -z "$count" ]; then
1689                 print_skip                       1689                 print_skip
1690         elif [ "$count" != "$rm_addr_nr" ]; t    1690         elif [ "$count" != "$rm_addr_nr" ]; then
1691                 fail_test "got $count RM_ADDR    1691                 fail_test "got $count RM_ADDR[s] expected $rm_addr_nr"
1692         else                                     1692         else
1693                 print_ok                         1693                 print_ok
1694         fi                                       1694         fi
1695                                                  1695 
1696         print_check "rm subflow ${subflow}"      1696         print_check "rm subflow ${subflow}"
1697         count=$(mptcp_lib_get_counter ${subfl    1697         count=$(mptcp_lib_get_counter ${subflow_ns} "MPTcpExtRmSubflow")
1698         if [ -z "$count" ]; then                 1698         if [ -z "$count" ]; then
1699                 print_skip                       1699                 print_skip
1700         elif [ -n "$simult" ]; then              1700         elif [ -n "$simult" ]; then
1701                 local cnt suffix                 1701                 local cnt suffix
1702                                                  1702 
1703                 cnt=$(mptcp_lib_get_counter $    1703                 cnt=$(mptcp_lib_get_counter ${addr_ns} "MPTcpExtRmSubflow")
1704                                                  1704 
1705                 # in case of simult flush, th    1705                 # in case of simult flush, the subflow removal count on each side is
1706                 # unreliable                     1706                 # unreliable
1707                 count=$((count + cnt))           1707                 count=$((count + cnt))
1708                 if [ "$count" != "$rm_subflow    1708                 if [ "$count" != "$rm_subflow_nr" ]; then
1709                         suffix="$count in [$r    1709                         suffix="$count in [$rm_subflow_nr:$((rm_subflow_nr*2))]"
1710                         extra_msg="simult"       1710                         extra_msg="simult"
1711                 fi                               1711                 fi
1712                 if [ $count -ge "$rm_subflow_    1712                 if [ $count -ge "$rm_subflow_nr" ] && \
1713                    [ "$count" -le "$((rm_subf    1713                    [ "$count" -le "$((rm_subflow_nr *2 ))" ]; then
1714                         print_ok "$suffix"       1714                         print_ok "$suffix"
1715                 else                             1715                 else
1716                         fail_test "got $count    1716                         fail_test "got $count RM_SUBFLOW[s] expected in range [$rm_subflow_nr:$((rm_subflow_nr*2))]"
1717                 fi                               1717                 fi
1718         elif [ "$count" != "$rm_subflow_nr" ]    1718         elif [ "$count" != "$rm_subflow_nr" ]; then
1719                 fail_test "got $count RM_SUBF    1719                 fail_test "got $count RM_SUBFLOW[s] expected $rm_subflow_nr"
1720         else                                     1720         else
1721                 print_ok                         1721                 print_ok
1722         fi                                       1722         fi
1723                                                  1723 
1724         print_info "$extra_msg"                  1724         print_info "$extra_msg"
1725 }                                                1725 }
1726                                                  1726 
1727 chk_rm_tx_nr()                                   1727 chk_rm_tx_nr()
1728 {                                                1728 {
1729         local rm_addr_tx_nr=$1                   1729         local rm_addr_tx_nr=$1
1730                                                  1730 
1731         print_check "rm addr tx client"          1731         print_check "rm addr tx client"
1732         count=$(mptcp_lib_get_counter ${ns2}     1732         count=$(mptcp_lib_get_counter ${ns2} "MPTcpExtRmAddrTx")
1733         if [ -z "$count" ]; then                 1733         if [ -z "$count" ]; then
1734                 print_skip                       1734                 print_skip
1735         elif [ "$count" != "$rm_addr_tx_nr" ]    1735         elif [ "$count" != "$rm_addr_tx_nr" ]; then
1736                 fail_test "got $count RM_ADDR    1736                 fail_test "got $count RM_ADDR[s] expected $rm_addr_tx_nr"
1737         else                                     1737         else
1738                 print_ok                         1738                 print_ok
1739         fi                                       1739         fi
1740 }                                                1740 }
1741                                                  1741 
1742 chk_prio_nr()                                    1742 chk_prio_nr()
1743 {                                                1743 {
1744         local mp_prio_nr_tx=$1                   1744         local mp_prio_nr_tx=$1
1745         local mp_prio_nr_rx=$2                   1745         local mp_prio_nr_rx=$2
1746         local mpj_syn=$3                         1746         local mpj_syn=$3
1747         local mpj_syn_ack=$4                     1747         local mpj_syn_ack=$4
1748         local count                              1748         local count
1749                                                  1749 
1750         print_check "mp_prio tx server"          1750         print_check "mp_prio tx server"
1751         count=$(mptcp_lib_get_counter ${ns1}     1751         count=$(mptcp_lib_get_counter ${ns1} "MPTcpExtMPPrioTx")
1752         if [ -z "$count" ]; then                 1752         if [ -z "$count" ]; then
1753                 print_skip                       1753                 print_skip
1754         elif [ "$count" != "$mp_prio_nr_tx" ]    1754         elif [ "$count" != "$mp_prio_nr_tx" ]; then
1755                 fail_test "got $count MP_PRIO    1755                 fail_test "got $count MP_PRIO[s] TX expected $mp_prio_nr_tx"
1756         else                                     1756         else
1757                 print_ok                         1757                 print_ok
1758         fi                                       1758         fi
1759                                                  1759 
1760         print_check "mp_prio rx client"          1760         print_check "mp_prio rx client"
1761         count=$(mptcp_lib_get_counter ${ns1}     1761         count=$(mptcp_lib_get_counter ${ns1} "MPTcpExtMPPrioRx")
1762         if [ -z "$count" ]; then                 1762         if [ -z "$count" ]; then
1763                 print_skip                       1763                 print_skip
1764         elif [ "$count" != "$mp_prio_nr_rx" ]    1764         elif [ "$count" != "$mp_prio_nr_rx" ]; then
1765                 fail_test "got $count MP_PRIO    1765                 fail_test "got $count MP_PRIO[s] RX expected $mp_prio_nr_rx"
1766         else                                     1766         else
1767                 print_ok                         1767                 print_ok
1768         fi                                       1768         fi
1769                                                  1769 
1770         print_check "syn backup"                 1770         print_check "syn backup"
1771         count=$(mptcp_lib_get_counter ${ns1}     1771         count=$(mptcp_lib_get_counter ${ns1} "MPTcpExtMPJoinSynBackupRx")
1772         if [ -z "$count" ]; then                 1772         if [ -z "$count" ]; then
1773                 print_skip                       1773                 print_skip
1774         elif [ "$count" != "$mpj_syn" ]; then    1774         elif [ "$count" != "$mpj_syn" ]; then
1775                 fail_test "got $count JOIN[s]    1775                 fail_test "got $count JOIN[s] syn with Backup expected $mpj_syn"
1776         else                                     1776         else
1777                 print_ok                         1777                 print_ok
1778         fi                                       1778         fi
1779                                                  1779 
1780         print_check "synack backup"              1780         print_check "synack backup"
1781         count=$(mptcp_lib_get_counter ${ns2}     1781         count=$(mptcp_lib_get_counter ${ns2} "MPTcpExtMPJoinSynAckBackupRx")
1782         if [ -z "$count" ]; then                 1782         if [ -z "$count" ]; then
1783                 print_skip                       1783                 print_skip
1784         elif [ "$count" != "$mpj_syn_ack" ];     1784         elif [ "$count" != "$mpj_syn_ack" ]; then
1785                 fail_test "got $count JOIN[s]    1785                 fail_test "got $count JOIN[s] synack with Backup expected $mpj_syn_ack"
1786         else                                     1786         else
1787                 print_ok                         1787                 print_ok
1788         fi                                       1788         fi
1789 }                                                1789 }
1790                                                  1790 
1791 chk_subflow_nr()                                 1791 chk_subflow_nr()
1792 {                                                1792 {
1793         local msg="$1"                           1793         local msg="$1"
1794         local subflow_nr=$2                      1794         local subflow_nr=$2
1795         local cnt1                               1795         local cnt1
1796         local cnt2                               1796         local cnt2
1797         local dump_stats                         1797         local dump_stats
1798                                                  1798 
1799         print_check "${msg}"                     1799         print_check "${msg}"
1800                                                  1800 
1801         cnt1=$(ss -N $ns1 -tOni | grep -c tok    1801         cnt1=$(ss -N $ns1 -tOni | grep -c token)
1802         cnt2=$(ss -N $ns2 -tOni | grep -c tok    1802         cnt2=$(ss -N $ns2 -tOni | grep -c token)
1803         if [ "$cnt1" != "$subflow_nr" ] || [     1803         if [ "$cnt1" != "$subflow_nr" ] || [ "$cnt2" != "$subflow_nr" ]; then
1804                 fail_test "got $cnt1:$cnt2 su    1804                 fail_test "got $cnt1:$cnt2 subflows expected $subflow_nr"
1805                 dump_stats=1                     1805                 dump_stats=1
1806         else                                     1806         else
1807                 print_ok                         1807                 print_ok
1808         fi                                       1808         fi
1809                                                  1809 
1810         if [ "${dump_stats}" = 1 ]; then         1810         if [ "${dump_stats}" = 1 ]; then
1811                 ss -N $ns1 -tOni                 1811                 ss -N $ns1 -tOni
1812                 ss -N $ns1 -tOni | grep token    1812                 ss -N $ns1 -tOni | grep token
1813                 ip -n $ns1 mptcp endpoint        1813                 ip -n $ns1 mptcp endpoint
1814         fi                                       1814         fi
1815 }                                                1815 }
1816                                                  1816 
1817 chk_mptcp_info()                                 1817 chk_mptcp_info()
1818 {                                                1818 {
1819         local info1=$1                           1819         local info1=$1
1820         local exp1=$2                            1820         local exp1=$2
1821         local info2=$3                           1821         local info2=$3
1822         local exp2=$4                            1822         local exp2=$4
1823         local cnt1                               1823         local cnt1
1824         local cnt2                               1824         local cnt2
1825         local dump_stats                         1825         local dump_stats
1826                                                  1826 
1827         print_check "mptcp_info ${info1:0:15}    1827         print_check "mptcp_info ${info1:0:15}=$exp1:$exp2"
1828                                                  1828 
1829         cnt1=$(ss -N $ns1 -inmHM | mptcp_lib_    1829         cnt1=$(ss -N $ns1 -inmHM | mptcp_lib_get_info_value "$info1" "$info1")
1830         cnt2=$(ss -N $ns2 -inmHM | mptcp_lib_    1830         cnt2=$(ss -N $ns2 -inmHM | mptcp_lib_get_info_value "$info2" "$info2")
1831         # 'ss' only display active connection    1831         # 'ss' only display active connections and counters that are not 0.
1832         [ -z "$cnt1" ] && cnt1=0                 1832         [ -z "$cnt1" ] && cnt1=0
1833         [ -z "$cnt2" ] && cnt2=0                 1833         [ -z "$cnt2" ] && cnt2=0
1834                                                  1834 
1835         if [ "$cnt1" != "$exp1" ] || [ "$cnt2    1835         if [ "$cnt1" != "$exp1" ] || [ "$cnt2" != "$exp2" ]; then
1836                 fail_test "got $cnt1:$cnt2 $i    1836                 fail_test "got $cnt1:$cnt2 $info1:$info2 expected $exp1:$exp2"
1837                 dump_stats=1                     1837                 dump_stats=1
1838         else                                     1838         else
1839                 print_ok                         1839                 print_ok
1840         fi                                       1840         fi
1841                                                  1841 
1842         if [ "$dump_stats" = 1 ]; then           1842         if [ "$dump_stats" = 1 ]; then
1843                 ss -N $ns1 -inmHM                1843                 ss -N $ns1 -inmHM
1844                 ss -N $ns2 -inmHM                1844                 ss -N $ns2 -inmHM
1845         fi                                       1845         fi
1846 }                                                1846 }
1847                                                  1847 
1848 # $1: subflows in ns1 ; $2: subflows in ns2      1848 # $1: subflows in ns1 ; $2: subflows in ns2
1849 # number of all subflows, including the initi    1849 # number of all subflows, including the initial subflow.
1850 chk_subflows_total()                             1850 chk_subflows_total()
1851 {                                                1851 {
1852         local cnt1                               1852         local cnt1
1853         local cnt2                               1853         local cnt2
1854         local info="subflows_total"              1854         local info="subflows_total"
1855         local dump_stats                         1855         local dump_stats
1856                                                  1856 
1857         # if subflows_total counter is suppor    1857         # if subflows_total counter is supported, use it:
1858         if [ -n "$(ss -N $ns1 -inmHM | mptcp_    1858         if [ -n "$(ss -N $ns1 -inmHM | mptcp_lib_get_info_value $info $info)" ]; then
1859                 chk_mptcp_info $info $1 $info    1859                 chk_mptcp_info $info $1 $info $2
1860                 return                           1860                 return
1861         fi                                       1861         fi
1862                                                  1862 
1863         print_check "$info $1:$2"                1863         print_check "$info $1:$2"
1864                                                  1864 
1865         # if not, count the TCP connections t    1865         # if not, count the TCP connections that are in fact MPTCP subflows
1866         cnt1=$(ss -N $ns1 -ti state establish    1866         cnt1=$(ss -N $ns1 -ti state established state syn-sent state syn-recv |
1867                grep -c tcp-ulp-mptcp)            1867                grep -c tcp-ulp-mptcp)
1868         cnt2=$(ss -N $ns2 -ti state establish    1868         cnt2=$(ss -N $ns2 -ti state established state syn-sent state syn-recv |
1869                grep -c tcp-ulp-mptcp)            1869                grep -c tcp-ulp-mptcp)
1870                                                  1870 
1871         if [ "$1" != "$cnt1" ] || [ "$2" != "    1871         if [ "$1" != "$cnt1" ] || [ "$2" != "$cnt2" ]; then
1872                 fail_test "got subflows $cnt1    1872                 fail_test "got subflows $cnt1:$cnt2 expected $1:$2"
1873                 dump_stats=1                     1873                 dump_stats=1
1874         else                                     1874         else
1875                 print_ok                         1875                 print_ok
1876         fi                                       1876         fi
1877                                                  1877 
1878         if [ "$dump_stats" = 1 ]; then           1878         if [ "$dump_stats" = 1 ]; then
1879                 ss -N $ns1 -ti                   1879                 ss -N $ns1 -ti
1880                 ss -N $ns2 -ti                   1880                 ss -N $ns2 -ti
1881         fi                                       1881         fi
1882 }                                                1882 }
1883                                                  1883 
1884 chk_link_usage()                                 1884 chk_link_usage()
1885 {                                                1885 {
1886         local ns=$1                              1886         local ns=$1
1887         local link=$2                            1887         local link=$2
1888         local out=$3                             1888         local out=$3
1889         local expected_rate=$4                   1889         local expected_rate=$4
1890                                                  1890 
1891         local tx_link tx_total                   1891         local tx_link tx_total
1892         tx_link=$(ip netns exec $ns cat /sys/    1892         tx_link=$(ip netns exec $ns cat /sys/class/net/$link/statistics/tx_bytes)
1893         tx_total=$(stat --format=%s $out)        1893         tx_total=$(stat --format=%s $out)
1894         local tx_rate=$((tx_link * 100 / tx_t    1894         local tx_rate=$((tx_link * 100 / tx_total))
1895         local tolerance=5                        1895         local tolerance=5
1896                                                  1896 
1897         print_check "link usage"                 1897         print_check "link usage"
1898         if [ $tx_rate -lt $((expected_rate -     1898         if [ $tx_rate -lt $((expected_rate - tolerance)) ] || \
1899            [ $tx_rate -gt $((expected_rate +     1899            [ $tx_rate -gt $((expected_rate + tolerance)) ]; then
1900                 fail_test "got $tx_rate% usag    1900                 fail_test "got $tx_rate% usage, expected $expected_rate%"
1901         else                                     1901         else
1902                 print_ok                         1902                 print_ok
1903         fi                                       1903         fi
1904 }                                                1904 }
1905                                                  1905 
1906 wait_attempt_fail()                              1906 wait_attempt_fail()
1907 {                                                1907 {
1908         local timeout_ms=$((timeout_poll * 10    1908         local timeout_ms=$((timeout_poll * 1000))
1909         local time=0                             1909         local time=0
1910         local ns=$1                              1910         local ns=$1
1911                                                  1911 
1912         while [ $time -lt $timeout_ms ]; do      1912         while [ $time -lt $timeout_ms ]; do
1913                 local cnt                        1913                 local cnt
1914                                                  1914 
1915                 cnt=$(mptcp_lib_get_counter $    1915                 cnt=$(mptcp_lib_get_counter ${ns} "TcpAttemptFails")
1916                                                  1916 
1917                 [ "$cnt" = 1 ] && return 1       1917                 [ "$cnt" = 1 ] && return 1
1918                 time=$((time + 100))             1918                 time=$((time + 100))
1919                 sleep 0.1                        1919                 sleep 0.1
1920         done                                     1920         done
1921         return 1                                 1921         return 1
1922 }                                                1922 }
1923                                                  1923 
1924 set_userspace_pm()                               1924 set_userspace_pm()
1925 {                                                1925 {
1926         local ns=$1                              1926         local ns=$1
1927                                                  1927 
1928         ip netns exec $ns sysctl -q net.mptcp    1928         ip netns exec $ns sysctl -q net.mptcp.pm_type=1
1929 }                                                1929 }
1930                                                  1930 
1931 subflows_tests()                                 1931 subflows_tests()
1932 {                                                1932 {
1933         if reset "no JOIN"; then                 1933         if reset "no JOIN"; then
1934                 run_tests $ns1 $ns2 10.0.1.1     1934                 run_tests $ns1 $ns2 10.0.1.1
1935                 chk_join_nr 0 0 0                1935                 chk_join_nr 0 0 0
1936         fi                                       1936         fi
1937                                                  1937 
1938         # subflow limited by client              1938         # subflow limited by client
1939         if reset "single subflow, limited by     1939         if reset "single subflow, limited by client"; then
1940                 pm_nl_set_limits $ns1 0 0        1940                 pm_nl_set_limits $ns1 0 0
1941                 pm_nl_set_limits $ns2 0 0        1941                 pm_nl_set_limits $ns2 0 0
1942                 pm_nl_add_endpoint $ns2 10.0.    1942                 pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow
1943                 run_tests $ns1 $ns2 10.0.1.1     1943                 run_tests $ns1 $ns2 10.0.1.1
1944                 chk_join_nr 0 0 0                1944                 chk_join_nr 0 0 0
1945         fi                                       1945         fi
1946                                                  1946 
1947         # subflow limited by server              1947         # subflow limited by server
1948         if reset "single subflow, limited by     1948         if reset "single subflow, limited by server"; then
1949                 pm_nl_set_limits $ns1 0 0        1949                 pm_nl_set_limits $ns1 0 0
1950                 pm_nl_set_limits $ns2 0 1        1950                 pm_nl_set_limits $ns2 0 1
1951                 pm_nl_add_endpoint $ns2 10.0.    1951                 pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow
1952                 run_tests $ns1 $ns2 10.0.1.1     1952                 run_tests $ns1 $ns2 10.0.1.1
1953                 chk_join_nr 1 1 0                1953                 chk_join_nr 1 1 0
1954         fi                                       1954         fi
1955                                                  1955 
1956         # subflow                                1956         # subflow
1957         if reset "single subflow"; then          1957         if reset "single subflow"; then
1958                 pm_nl_set_limits $ns1 0 1        1958                 pm_nl_set_limits $ns1 0 1
1959                 pm_nl_set_limits $ns2 0 1        1959                 pm_nl_set_limits $ns2 0 1
1960                 pm_nl_add_endpoint $ns2 10.0.    1960                 pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow
1961                 run_tests $ns1 $ns2 10.0.1.1     1961                 run_tests $ns1 $ns2 10.0.1.1
1962                 chk_join_nr 1 1 1                1962                 chk_join_nr 1 1 1
1963         fi                                       1963         fi
1964                                                  1964 
1965         # multiple subflows                      1965         # multiple subflows
1966         if reset "multiple subflows"; then       1966         if reset "multiple subflows"; then
1967                 pm_nl_set_limits $ns1 0 2        1967                 pm_nl_set_limits $ns1 0 2
1968                 pm_nl_set_limits $ns2 0 2        1968                 pm_nl_set_limits $ns2 0 2
1969                 pm_nl_add_endpoint $ns2 10.0.    1969                 pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow
1970                 pm_nl_add_endpoint $ns2 10.0.    1970                 pm_nl_add_endpoint $ns2 10.0.2.2 flags subflow
1971                 run_tests $ns1 $ns2 10.0.1.1     1971                 run_tests $ns1 $ns2 10.0.1.1
1972                 chk_join_nr 2 2 2                1972                 chk_join_nr 2 2 2
1973         fi                                       1973         fi
1974                                                  1974 
1975         # multiple subflows limited by server    1975         # multiple subflows limited by server
1976         if reset "multiple subflows, limited     1976         if reset "multiple subflows, limited by server"; then
1977                 pm_nl_set_limits $ns1 0 1        1977                 pm_nl_set_limits $ns1 0 1
1978                 pm_nl_set_limits $ns2 0 2        1978                 pm_nl_set_limits $ns2 0 2
1979                 pm_nl_add_endpoint $ns2 10.0.    1979                 pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow
1980                 pm_nl_add_endpoint $ns2 10.0.    1980                 pm_nl_add_endpoint $ns2 10.0.2.2 flags subflow
1981                 run_tests $ns1 $ns2 10.0.1.1     1981                 run_tests $ns1 $ns2 10.0.1.1
1982                 chk_join_nr 2 2 1                1982                 chk_join_nr 2 2 1
1983         fi                                       1983         fi
1984                                                  1984 
1985         # single subflow, dev                    1985         # single subflow, dev
1986         if reset "single subflow, dev"; then     1986         if reset "single subflow, dev"; then
1987                 pm_nl_set_limits $ns1 0 1        1987                 pm_nl_set_limits $ns1 0 1
1988                 pm_nl_set_limits $ns2 0 1        1988                 pm_nl_set_limits $ns2 0 1
1989                 pm_nl_add_endpoint $ns2 10.0.    1989                 pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow dev ns2eth3
1990                 run_tests $ns1 $ns2 10.0.1.1     1990                 run_tests $ns1 $ns2 10.0.1.1
1991                 chk_join_nr 1 1 1                1991                 chk_join_nr 1 1 1
1992         fi                                       1992         fi
1993 }                                                1993 }
1994                                                  1994 
1995 subflows_error_tests()                           1995 subflows_error_tests()
1996 {                                                1996 {
1997         # If a single subflow is configured,     1997         # If a single subflow is configured, and matches the MPC src
1998         # address, no additional subflow shou    1998         # address, no additional subflow should be created
1999         if reset "no MPC reuse with single en    1999         if reset "no MPC reuse with single endpoint"; then
2000                 pm_nl_set_limits $ns1 0 1        2000                 pm_nl_set_limits $ns1 0 1
2001                 pm_nl_set_limits $ns2 0 1        2001                 pm_nl_set_limits $ns2 0 1
2002                 pm_nl_add_endpoint $ns2 10.0.    2002                 pm_nl_add_endpoint $ns2 10.0.1.2 flags subflow
2003                 pm_nl_add_endpoint $ns2 10.0.    2003                 pm_nl_add_endpoint $ns2 10.0.12.2 flags subflow
2004                 speed=slow \                     2004                 speed=slow \
2005                         run_tests $ns1 $ns2 1    2005                         run_tests $ns1 $ns2 10.0.1.1
2006                 join_bind_err=1 \                2006                 join_bind_err=1 \
2007                         chk_join_nr 0 0 0        2007                         chk_join_nr 0 0 0
2008         fi                                       2008         fi
2009                                                  2009 
2010         # multiple subflows, with subflow cre    2010         # multiple subflows, with subflow creation error
2011         if reset_with_tcp_filter "multi subfl    2011         if reset_with_tcp_filter "multi subflows, with failing subflow" ns1 10.0.3.2 REJECT &&
2012            continue_if mptcp_lib_kallsyms_has    2012            continue_if mptcp_lib_kallsyms_has "mptcp_pm_subflow_check_next$"; then
2013                 pm_nl_set_limits $ns1 0 2        2013                 pm_nl_set_limits $ns1 0 2
2014                 pm_nl_set_limits $ns2 0 2        2014                 pm_nl_set_limits $ns2 0 2
2015                 pm_nl_add_endpoint $ns2 10.0.    2015                 pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow
2016                 pm_nl_add_endpoint $ns2 10.0.    2016                 pm_nl_add_endpoint $ns2 10.0.2.2 flags subflow
2017                 speed=slow \                     2017                 speed=slow \
2018                         run_tests $ns1 $ns2 1    2018                         run_tests $ns1 $ns2 10.0.1.1
2019                 join_syn_tx=2 \                  2019                 join_syn_tx=2 \
2020                         chk_join_nr 1 1 1        2020                         chk_join_nr 1 1 1
2021         fi                                       2021         fi
2022                                                  2022 
2023         # multiple subflows, with subflow tim    2023         # multiple subflows, with subflow timeout on MPJ
2024         if reset_with_tcp_filter "multi subfl    2024         if reset_with_tcp_filter "multi subflows, with subflow timeout" ns1 10.0.3.2 DROP &&
2025            continue_if mptcp_lib_kallsyms_has    2025            continue_if mptcp_lib_kallsyms_has "mptcp_pm_subflow_check_next$"; then
2026                 pm_nl_set_limits $ns1 0 2        2026                 pm_nl_set_limits $ns1 0 2
2027                 pm_nl_set_limits $ns2 0 2        2027                 pm_nl_set_limits $ns2 0 2
2028                 pm_nl_add_endpoint $ns2 10.0.    2028                 pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow
2029                 pm_nl_add_endpoint $ns2 10.0.    2029                 pm_nl_add_endpoint $ns2 10.0.2.2 flags subflow
2030                 speed=slow \                     2030                 speed=slow \
2031                         run_tests $ns1 $ns2 1    2031                         run_tests $ns1 $ns2 10.0.1.1
2032                 join_syn_tx=2 \                  2032                 join_syn_tx=2 \
2033                         chk_join_nr 1 1 1        2033                         chk_join_nr 1 1 1
2034         fi                                       2034         fi
2035                                                  2035 
2036         # multiple subflows, check that the e    2036         # multiple subflows, check that the endpoint corresponding to
2037         # closed subflow (due to reset) is no    2037         # closed subflow (due to reset) is not reused if additional
2038         # subflows are added later               2038         # subflows are added later
2039         if reset_with_tcp_filter "multi subfl    2039         if reset_with_tcp_filter "multi subflows, fair usage on close" ns1 10.0.3.2 REJECT &&
2040            continue_if mptcp_lib_kallsyms_has    2040            continue_if mptcp_lib_kallsyms_has "mptcp_pm_subflow_check_next$"; then
2041                 pm_nl_set_limits $ns1 0 1        2041                 pm_nl_set_limits $ns1 0 1
2042                 pm_nl_set_limits $ns2 0 1        2042                 pm_nl_set_limits $ns2 0 1
2043                 pm_nl_add_endpoint $ns2 10.0.    2043                 pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow
2044                 speed=slow \                     2044                 speed=slow \
2045                         run_tests $ns1 $ns2 1    2045                         run_tests $ns1 $ns2 10.0.1.1 &
2046                                                  2046 
2047                 # mpj subflow will be in TW a    2047                 # mpj subflow will be in TW after the reset
2048                 wait_attempt_fail $ns2           2048                 wait_attempt_fail $ns2
2049                 pm_nl_add_endpoint $ns2 10.0.    2049                 pm_nl_add_endpoint $ns2 10.0.2.2 flags subflow
2050                 wait                             2050                 wait
2051                                                  2051 
2052                 # additional subflow could be    2052                 # additional subflow could be created only if the PM select
2053                 # the later endpoint, skippin    2053                 # the later endpoint, skipping the already used one
2054                 join_syn_tx=2 \                  2054                 join_syn_tx=2 \
2055                         chk_join_nr 1 1 1        2055                         chk_join_nr 1 1 1
2056         fi                                       2056         fi
2057 }                                                2057 }
2058                                                  2058 
2059 signal_address_tests()                           2059 signal_address_tests()
2060 {                                                2060 {
2061         # add_address, unused                    2061         # add_address, unused
2062         if reset "unused signal address"; the    2062         if reset "unused signal address"; then
2063                 pm_nl_add_endpoint $ns1 10.0.    2063                 pm_nl_add_endpoint $ns1 10.0.2.1 flags signal
2064                 run_tests $ns1 $ns2 10.0.1.1     2064                 run_tests $ns1 $ns2 10.0.1.1
2065                 chk_join_nr 0 0 0                2065                 chk_join_nr 0 0 0
2066                 chk_add_tx_nr 1 1                2066                 chk_add_tx_nr 1 1
2067                 chk_add_nr 1 1                   2067                 chk_add_nr 1 1
2068         fi                                       2068         fi
2069                                                  2069 
2070         # accept and use add_addr                2070         # accept and use add_addr
2071         if reset "signal address"; then          2071         if reset "signal address"; then
2072                 pm_nl_set_limits $ns1 0 1        2072                 pm_nl_set_limits $ns1 0 1
2073                 pm_nl_set_limits $ns2 1 1        2073                 pm_nl_set_limits $ns2 1 1
2074                 pm_nl_add_endpoint $ns1 10.0.    2074                 pm_nl_add_endpoint $ns1 10.0.2.1 flags signal
2075                 run_tests $ns1 $ns2 10.0.1.1     2075                 run_tests $ns1 $ns2 10.0.1.1
2076                 chk_join_nr 1 1 1                2076                 chk_join_nr 1 1 1
2077                 chk_add_nr 1 1                   2077                 chk_add_nr 1 1
2078         fi                                       2078         fi
2079                                                  2079 
2080         # accept and use add_addr with an add    2080         # accept and use add_addr with an additional subflow
2081         # note: signal address in server ns a    2081         # note: signal address in server ns and local addresses in client ns must
2082         # belong to different subnets or one     2082         # belong to different subnets or one of the listed local address could be
2083         # used for 'add_addr' subflow            2083         # used for 'add_addr' subflow
2084         if reset "subflow and signal"; then      2084         if reset "subflow and signal"; then
2085                 pm_nl_add_endpoint $ns1 10.0.    2085                 pm_nl_add_endpoint $ns1 10.0.2.1 flags signal
2086                 pm_nl_set_limits $ns1 0 2        2086                 pm_nl_set_limits $ns1 0 2
2087                 pm_nl_set_limits $ns2 1 2        2087                 pm_nl_set_limits $ns2 1 2
2088                 pm_nl_add_endpoint $ns2 10.0.    2088                 pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow
2089                 run_tests $ns1 $ns2 10.0.1.1     2089                 run_tests $ns1 $ns2 10.0.1.1
2090                 chk_join_nr 2 2 2                2090                 chk_join_nr 2 2 2
2091                 chk_add_nr 1 1                   2091                 chk_add_nr 1 1
2092         fi                                       2092         fi
2093                                                  2093 
2094         # uncommon: subflow and signal flags     2094         # uncommon: subflow and signal flags on the same endpoint
2095         # or because the user wrongly picked     2095         # or because the user wrongly picked both, but still expects the client
2096         # to create additional subflows          2096         # to create additional subflows
2097         if reset "subflow and signal together    2097         if reset "subflow and signal together"; then
2098                 pm_nl_set_limits $ns1 0 2        2098                 pm_nl_set_limits $ns1 0 2
2099                 pm_nl_set_limits $ns2 0 2        2099                 pm_nl_set_limits $ns2 0 2
2100                 pm_nl_add_endpoint $ns2 10.0.    2100                 pm_nl_add_endpoint $ns2 10.0.3.2 flags signal,subflow
2101                 run_tests $ns1 $ns2 10.0.1.1     2101                 run_tests $ns1 $ns2 10.0.1.1
2102                 chk_join_nr 1 1 1                2102                 chk_join_nr 1 1 1
2103                 chk_add_nr 1 1 0 invert  # on    2103                 chk_add_nr 1 1 0 invert  # only initiated by ns2
2104                 chk_add_nr 0 0 0         # no    2104                 chk_add_nr 0 0 0         # none initiated by ns1
2105                 chk_rst_nr 0 0 invert    # no    2105                 chk_rst_nr 0 0 invert    # no RST sent by the client
2106                 chk_rst_nr 0 0           # no    2106                 chk_rst_nr 0 0           # no RST sent by the server
2107         fi                                       2107         fi
2108                                                  2108 
2109         # accept and use add_addr with additi    2109         # accept and use add_addr with additional subflows
2110         if reset "multiple subflows and signa    2110         if reset "multiple subflows and signal"; then
2111                 pm_nl_set_limits $ns1 0 3        2111                 pm_nl_set_limits $ns1 0 3
2112                 pm_nl_add_endpoint $ns1 10.0.    2112                 pm_nl_add_endpoint $ns1 10.0.2.1 flags signal
2113                 pm_nl_set_limits $ns2 1 3        2113                 pm_nl_set_limits $ns2 1 3
2114                 pm_nl_add_endpoint $ns2 10.0.    2114                 pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow
2115                 pm_nl_add_endpoint $ns2 10.0.    2115                 pm_nl_add_endpoint $ns2 10.0.4.2 flags subflow
2116                 run_tests $ns1 $ns2 10.0.1.1     2116                 run_tests $ns1 $ns2 10.0.1.1
2117                 chk_join_nr 3 3 3                2117                 chk_join_nr 3 3 3
2118                 chk_add_nr 1 1                   2118                 chk_add_nr 1 1
2119         fi                                       2119         fi
2120                                                  2120 
2121         # signal addresses                       2121         # signal addresses
2122         if reset "signal addresses"; then        2122         if reset "signal addresses"; then
2123                 pm_nl_set_limits $ns1 3 3        2123                 pm_nl_set_limits $ns1 3 3
2124                 pm_nl_add_endpoint $ns1 10.0.    2124                 pm_nl_add_endpoint $ns1 10.0.2.1 flags signal
2125                 pm_nl_add_endpoint $ns1 10.0.    2125                 pm_nl_add_endpoint $ns1 10.0.3.1 flags signal
2126                 pm_nl_add_endpoint $ns1 10.0.    2126                 pm_nl_add_endpoint $ns1 10.0.4.1 flags signal
2127                 pm_nl_set_limits $ns2 3 3        2127                 pm_nl_set_limits $ns2 3 3
2128                 run_tests $ns1 $ns2 10.0.1.1     2128                 run_tests $ns1 $ns2 10.0.1.1
2129                 chk_join_nr 3 3 3                2129                 chk_join_nr 3 3 3
2130                 chk_add_nr 3 3                   2130                 chk_add_nr 3 3
2131         fi                                       2131         fi
2132                                                  2132 
2133         # signal invalid addresses               2133         # signal invalid addresses
2134         if reset "signal invalid addresses";     2134         if reset "signal invalid addresses"; then
2135                 pm_nl_set_limits $ns1 3 3        2135                 pm_nl_set_limits $ns1 3 3
2136                 pm_nl_add_endpoint $ns1 10.0.    2136                 pm_nl_add_endpoint $ns1 10.0.12.1 flags signal
2137                 pm_nl_add_endpoint $ns1 10.0.    2137                 pm_nl_add_endpoint $ns1 10.0.3.1 flags signal
2138                 pm_nl_add_endpoint $ns1 10.0.    2138                 pm_nl_add_endpoint $ns1 10.0.14.1 flags signal
2139                 pm_nl_set_limits $ns2 3 3        2139                 pm_nl_set_limits $ns2 3 3
2140                 run_tests $ns1 $ns2 10.0.1.1     2140                 run_tests $ns1 $ns2 10.0.1.1
2141                 join_syn_tx=3 \                  2141                 join_syn_tx=3 \
2142                         chk_join_nr 1 1 1        2142                         chk_join_nr 1 1 1
2143                 chk_add_nr 3 3                   2143                 chk_add_nr 3 3
2144         fi                                       2144         fi
2145                                                  2145 
2146         # signal addresses race test             2146         # signal addresses race test
2147         if reset "signal addresses race test"    2147         if reset "signal addresses race test"; then
2148                 pm_nl_set_limits $ns1 4 4        2148                 pm_nl_set_limits $ns1 4 4
2149                 pm_nl_set_limits $ns2 4 4        2149                 pm_nl_set_limits $ns2 4 4
2150                 pm_nl_add_endpoint $ns1 10.0.    2150                 pm_nl_add_endpoint $ns1 10.0.1.1 flags signal
2151                 pm_nl_add_endpoint $ns1 10.0.    2151                 pm_nl_add_endpoint $ns1 10.0.2.1 flags signal
2152                 pm_nl_add_endpoint $ns1 10.0.    2152                 pm_nl_add_endpoint $ns1 10.0.3.1 flags signal
2153                 pm_nl_add_endpoint $ns1 10.0.    2153                 pm_nl_add_endpoint $ns1 10.0.4.1 flags signal
2154                 pm_nl_add_endpoint $ns2 10.0.    2154                 pm_nl_add_endpoint $ns2 10.0.1.2 flags signal
2155                 pm_nl_add_endpoint $ns2 10.0.    2155                 pm_nl_add_endpoint $ns2 10.0.2.2 flags signal
2156                 pm_nl_add_endpoint $ns2 10.0.    2156                 pm_nl_add_endpoint $ns2 10.0.3.2 flags signal
2157                 pm_nl_add_endpoint $ns2 10.0.    2157                 pm_nl_add_endpoint $ns2 10.0.4.2 flags signal
2158                                                  2158 
2159                 # the peer could possibly mis    2159                 # the peer could possibly miss some addr notification, allow retransmission
2160                 ip netns exec $ns1 sysctl -q     2160                 ip netns exec $ns1 sysctl -q net.mptcp.add_addr_timeout=1
2161                 speed=slow \                     2161                 speed=slow \
2162                         run_tests $ns1 $ns2 1    2162                         run_tests $ns1 $ns2 10.0.1.1
2163                                                  2163 
2164                 # It is not directly linked t    2164                 # It is not directly linked to the commit introducing this
2165                 # symbol but for the parent o    2165                 # symbol but for the parent one which is linked anyway.
2166                 if ! mptcp_lib_kallsyms_has "    2166                 if ! mptcp_lib_kallsyms_has "mptcp_pm_subflow_check_next$"; then
2167                         chk_join_nr 3 3 2        2167                         chk_join_nr 3 3 2
2168                         chk_add_nr 4 4           2168                         chk_add_nr 4 4
2169                 else                             2169                 else
2170                         chk_join_nr 3 3 3        2170                         chk_join_nr 3 3 3
2171                         # the server will not    2171                         # the server will not signal the address terminating
2172                         # the MPC subflow        2172                         # the MPC subflow
2173                         chk_add_nr 3 3           2173                         chk_add_nr 3 3
2174                 fi                               2174                 fi
2175         fi                                       2175         fi
2176 }                                                2176 }
2177                                                  2177 
2178 link_failure_tests()                             2178 link_failure_tests()
2179 {                                                2179 {
2180         # accept and use add_addr with additi    2180         # accept and use add_addr with additional subflows and link loss
2181         if reset "multiple flows, signal, lin    2181         if reset "multiple flows, signal, link failure"; then
2182                 # without any b/w limit each     2182                 # without any b/w limit each veth could spool the packets and get
2183                 # them acked at xmit time, so    2183                 # them acked at xmit time, so that the corresponding subflow will
2184                 # have almost always no outst    2184                 # have almost always no outstanding pkts, the scheduler will pick
2185                 # always the first subflow an    2185                 # always the first subflow and we will have hard time testing
2186                 # active backup and link swit    2186                 # active backup and link switch-over.
2187                 # Let's set some arbitrary (l    2187                 # Let's set some arbitrary (low) virtual link limits.
2188                 init_shapers                     2188                 init_shapers
2189                 pm_nl_set_limits $ns1 0 3        2189                 pm_nl_set_limits $ns1 0 3
2190                 pm_nl_add_endpoint $ns1 10.0.    2190                 pm_nl_add_endpoint $ns1 10.0.2.1 dev ns1eth2 flags signal
2191                 pm_nl_set_limits $ns2 1 3        2191                 pm_nl_set_limits $ns2 1 3
2192                 pm_nl_add_endpoint $ns2 10.0.    2192                 pm_nl_add_endpoint $ns2 10.0.3.2 dev ns2eth3 flags subflow
2193                 pm_nl_add_endpoint $ns2 10.0.    2193                 pm_nl_add_endpoint $ns2 10.0.4.2 dev ns2eth4 flags subflow
2194                 test_linkfail=1 \                2194                 test_linkfail=1 \
2195                         run_tests $ns1 $ns2 1    2195                         run_tests $ns1 $ns2 10.0.1.1
2196                 chk_join_nr 3 3 3                2196                 chk_join_nr 3 3 3
2197                 chk_add_nr 1 1                   2197                 chk_add_nr 1 1
2198                 chk_stale_nr $ns2 1 5 1          2198                 chk_stale_nr $ns2 1 5 1
2199         fi                                       2199         fi
2200                                                  2200 
2201         # accept and use add_addr with additi    2201         # accept and use add_addr with additional subflows and link loss
2202         # for bidirectional transfer             2202         # for bidirectional transfer
2203         if reset "multi flows, signal, bidi,     2203         if reset "multi flows, signal, bidi, link fail"; then
2204                 init_shapers                     2204                 init_shapers
2205                 pm_nl_set_limits $ns1 0 3        2205                 pm_nl_set_limits $ns1 0 3
2206                 pm_nl_add_endpoint $ns1 10.0.    2206                 pm_nl_add_endpoint $ns1 10.0.2.1 dev ns1eth2 flags signal
2207                 pm_nl_set_limits $ns2 1 3        2207                 pm_nl_set_limits $ns2 1 3
2208                 pm_nl_add_endpoint $ns2 10.0.    2208                 pm_nl_add_endpoint $ns2 10.0.3.2 dev ns2eth3 flags subflow
2209                 pm_nl_add_endpoint $ns2 10.0.    2209                 pm_nl_add_endpoint $ns2 10.0.4.2 dev ns2eth4 flags subflow
2210                 test_linkfail=2 \                2210                 test_linkfail=2 \
2211                         run_tests $ns1 $ns2 1    2211                         run_tests $ns1 $ns2 10.0.1.1
2212                 chk_join_nr 3 3 3                2212                 chk_join_nr 3 3 3
2213                 chk_add_nr 1 1                   2213                 chk_add_nr 1 1
2214                 chk_stale_nr $ns2 1 -1 1         2214                 chk_stale_nr $ns2 1 -1 1
2215         fi                                       2215         fi
2216                                                  2216 
2217         # 2 subflows plus 1 backup subflow wi    2217         # 2 subflows plus 1 backup subflow with a lossy link, backup
2218         # will never be used                     2218         # will never be used
2219         if reset "backup subflow unused, link    2219         if reset "backup subflow unused, link failure"; then
2220                 init_shapers                     2220                 init_shapers
2221                 pm_nl_set_limits $ns1 0 2        2221                 pm_nl_set_limits $ns1 0 2
2222                 pm_nl_add_endpoint $ns1 10.0.    2222                 pm_nl_add_endpoint $ns1 10.0.2.1 dev ns1eth2 flags signal
2223                 pm_nl_set_limits $ns2 1 2        2223                 pm_nl_set_limits $ns2 1 2
2224                 pm_nl_add_endpoint $ns2 10.0.    2224                 pm_nl_add_endpoint $ns2 10.0.3.2 dev ns2eth3 flags subflow,backup
2225                 FAILING_LINKS="1" test_linkfa    2225                 FAILING_LINKS="1" test_linkfail=1 \
2226                         run_tests $ns1 $ns2 1    2226                         run_tests $ns1 $ns2 10.0.1.1
2227                 chk_join_nr 2 2 2                2227                 chk_join_nr 2 2 2
2228                 chk_add_nr 1 1                   2228                 chk_add_nr 1 1
2229                 chk_link_usage $ns2 ns2eth3 $    2229                 chk_link_usage $ns2 ns2eth3 $cinsent 0
2230         fi                                       2230         fi
2231                                                  2231 
2232         # 2 lossy links after half transfer,     2232         # 2 lossy links after half transfer, backup will get half of
2233         # the traffic                            2233         # the traffic
2234         if reset "backup flow used, multi lin    2234         if reset "backup flow used, multi links fail"; then
2235                 init_shapers                     2235                 init_shapers
2236                 pm_nl_set_limits $ns1 0 2        2236                 pm_nl_set_limits $ns1 0 2
2237                 pm_nl_add_endpoint $ns1 10.0.    2237                 pm_nl_add_endpoint $ns1 10.0.2.1 dev ns1eth2 flags signal
2238                 pm_nl_set_limits $ns2 1 2        2238                 pm_nl_set_limits $ns2 1 2
2239                 pm_nl_add_endpoint $ns2 10.0.    2239                 pm_nl_add_endpoint $ns2 10.0.3.2 dev ns2eth3 flags subflow,backup
2240                 FAILING_LINKS="1 2" test_link    2240                 FAILING_LINKS="1 2" test_linkfail=1 \
2241                         run_tests $ns1 $ns2 1    2241                         run_tests $ns1 $ns2 10.0.1.1
2242                 chk_join_nr 2 2 2                2242                 chk_join_nr 2 2 2
2243                 chk_add_nr 1 1                   2243                 chk_add_nr 1 1
2244                 chk_stale_nr $ns2 2 4 2          2244                 chk_stale_nr $ns2 2 4 2
2245                 chk_link_usage $ns2 ns2eth3 $    2245                 chk_link_usage $ns2 ns2eth3 $cinsent 50
2246         fi                                       2246         fi
2247                                                  2247 
2248         # use a backup subflow with the first    2248         # use a backup subflow with the first subflow on a lossy link
2249         # for bidirectional transfer             2249         # for bidirectional transfer
2250         if reset "backup flow used, bidi, lin    2250         if reset "backup flow used, bidi, link failure"; then
2251                 init_shapers                     2251                 init_shapers
2252                 pm_nl_set_limits $ns1 0 2        2252                 pm_nl_set_limits $ns1 0 2
2253                 pm_nl_add_endpoint $ns1 10.0.    2253                 pm_nl_add_endpoint $ns1 10.0.2.1 dev ns1eth2 flags signal
2254                 pm_nl_set_limits $ns2 1 3        2254                 pm_nl_set_limits $ns2 1 3
2255                 pm_nl_add_endpoint $ns2 10.0.    2255                 pm_nl_add_endpoint $ns2 10.0.3.2 dev ns2eth3 flags subflow,backup
2256                 FAILING_LINKS="1 2" test_link    2256                 FAILING_LINKS="1 2" test_linkfail=2 \
2257                         run_tests $ns1 $ns2 1    2257                         run_tests $ns1 $ns2 10.0.1.1
2258                 chk_join_nr 2 2 2                2258                 chk_join_nr 2 2 2
2259                 chk_add_nr 1 1                   2259                 chk_add_nr 1 1
2260                 chk_stale_nr $ns2 1 -1 2         2260                 chk_stale_nr $ns2 1 -1 2
2261                 chk_link_usage $ns2 ns2eth3 $    2261                 chk_link_usage $ns2 ns2eth3 $cinsent 50
2262         fi                                       2262         fi
2263 }                                                2263 }
2264                                                  2264 
2265 add_addr_timeout_tests()                         2265 add_addr_timeout_tests()
2266 {                                                2266 {
2267         # add_addr timeout                       2267         # add_addr timeout
2268         if reset_with_add_addr_timeout "signa    2268         if reset_with_add_addr_timeout "signal address, ADD_ADDR timeout"; then
2269                 pm_nl_set_limits $ns1 0 1        2269                 pm_nl_set_limits $ns1 0 1
2270                 pm_nl_set_limits $ns2 1 1        2270                 pm_nl_set_limits $ns2 1 1
2271                 pm_nl_add_endpoint $ns1 10.0.    2271                 pm_nl_add_endpoint $ns1 10.0.2.1 flags signal
2272                 speed=slow \                     2272                 speed=slow \
2273                         run_tests $ns1 $ns2 1    2273                         run_tests $ns1 $ns2 10.0.1.1
2274                 chk_join_nr 1 1 1                2274                 chk_join_nr 1 1 1
2275                 chk_add_tx_nr 4 4                2275                 chk_add_tx_nr 4 4
2276                 chk_add_nr 4 0                   2276                 chk_add_nr 4 0
2277         fi                                       2277         fi
2278                                                  2278 
2279         # add_addr timeout IPv6                  2279         # add_addr timeout IPv6
2280         if reset_with_add_addr_timeout "signa    2280         if reset_with_add_addr_timeout "signal address, ADD_ADDR6 timeout" 6; then
2281                 pm_nl_set_limits $ns1 0 1        2281                 pm_nl_set_limits $ns1 0 1
2282                 pm_nl_set_limits $ns2 1 1        2282                 pm_nl_set_limits $ns2 1 1
2283                 pm_nl_add_endpoint $ns1 dead:    2283                 pm_nl_add_endpoint $ns1 dead:beef:2::1 flags signal
2284                 speed=slow \                     2284                 speed=slow \
2285                         run_tests $ns1 $ns2 d    2285                         run_tests $ns1 $ns2 dead:beef:1::1
2286                 chk_join_nr 1 1 1                2286                 chk_join_nr 1 1 1
2287                 chk_add_nr 4 0                   2287                 chk_add_nr 4 0
2288         fi                                       2288         fi
2289                                                  2289 
2290         # signal addresses timeout               2290         # signal addresses timeout
2291         if reset_with_add_addr_timeout "signa    2291         if reset_with_add_addr_timeout "signal addresses, ADD_ADDR timeout"; then
2292                 pm_nl_set_limits $ns1 2 2        2292                 pm_nl_set_limits $ns1 2 2
2293                 pm_nl_add_endpoint $ns1 10.0.    2293                 pm_nl_add_endpoint $ns1 10.0.2.1 flags signal
2294                 pm_nl_add_endpoint $ns1 10.0.    2294                 pm_nl_add_endpoint $ns1 10.0.3.1 flags signal
2295                 pm_nl_set_limits $ns2 2 2        2295                 pm_nl_set_limits $ns2 2 2
2296                 speed=10 \                       2296                 speed=10 \
2297                         run_tests $ns1 $ns2 1    2297                         run_tests $ns1 $ns2 10.0.1.1
2298                 chk_join_nr 2 2 2                2298                 chk_join_nr 2 2 2
2299                 chk_add_nr 8 0                   2299                 chk_add_nr 8 0
2300         fi                                       2300         fi
2301                                                  2301 
2302         # signal invalid addresses timeout       2302         # signal invalid addresses timeout
2303         if reset_with_add_addr_timeout "inval    2303         if reset_with_add_addr_timeout "invalid address, ADD_ADDR timeout"; then
2304                 pm_nl_set_limits $ns1 2 2        2304                 pm_nl_set_limits $ns1 2 2
2305                 pm_nl_add_endpoint $ns1 10.0.    2305                 pm_nl_add_endpoint $ns1 10.0.12.1 flags signal
2306                 pm_nl_add_endpoint $ns1 10.0.    2306                 pm_nl_add_endpoint $ns1 10.0.3.1 flags signal
2307                 pm_nl_set_limits $ns2 2 2        2307                 pm_nl_set_limits $ns2 2 2
2308                 speed=10 \                       2308                 speed=10 \
2309                         run_tests $ns1 $ns2 1    2309                         run_tests $ns1 $ns2 10.0.1.1
2310                 join_syn_tx=2 \                  2310                 join_syn_tx=2 \
2311                         chk_join_nr 1 1 1        2311                         chk_join_nr 1 1 1
2312                 chk_add_nr 8 0                   2312                 chk_add_nr 8 0
2313         fi                                       2313         fi
2314 }                                                2314 }
2315                                                  2315 
2316 remove_tests()                                   2316 remove_tests()
2317 {                                                2317 {
2318         # single subflow, remove                 2318         # single subflow, remove
2319         if reset "remove single subflow"; the    2319         if reset "remove single subflow"; then
2320                 pm_nl_set_limits $ns1 0 1        2320                 pm_nl_set_limits $ns1 0 1
2321                 pm_nl_set_limits $ns2 0 1        2321                 pm_nl_set_limits $ns2 0 1
2322                 pm_nl_add_endpoint $ns2 10.0.    2322                 pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow
2323                 addr_nr_ns2=-1 speed=slow \      2323                 addr_nr_ns2=-1 speed=slow \
2324                         run_tests $ns1 $ns2 1    2324                         run_tests $ns1 $ns2 10.0.1.1
2325                 chk_join_nr 1 1 1                2325                 chk_join_nr 1 1 1
2326                 chk_rm_tx_nr 1                   2326                 chk_rm_tx_nr 1
2327                 chk_rm_nr 1 1                    2327                 chk_rm_nr 1 1
2328                 chk_rst_nr 0 0                   2328                 chk_rst_nr 0 0
2329         fi                                       2329         fi
2330                                                  2330 
2331         # multiple subflows, remove              2331         # multiple subflows, remove
2332         if reset "remove multiple subflows";     2332         if reset "remove multiple subflows"; then
2333                 pm_nl_set_limits $ns1 0 2        2333                 pm_nl_set_limits $ns1 0 2
2334                 pm_nl_set_limits $ns2 0 2        2334                 pm_nl_set_limits $ns2 0 2
2335                 pm_nl_add_endpoint $ns2 10.0.    2335                 pm_nl_add_endpoint $ns2 10.0.2.2 flags subflow
2336                 pm_nl_add_endpoint $ns2 10.0.    2336                 pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow
2337                 addr_nr_ns2=-2 speed=slow \      2337                 addr_nr_ns2=-2 speed=slow \
2338                         run_tests $ns1 $ns2 1    2338                         run_tests $ns1 $ns2 10.0.1.1
2339                 chk_join_nr 2 2 2                2339                 chk_join_nr 2 2 2
2340                 chk_rm_nr 2 2                    2340                 chk_rm_nr 2 2
2341                 chk_rst_nr 0 0                   2341                 chk_rst_nr 0 0
2342         fi                                       2342         fi
2343                                                  2343 
2344         # single address, remove                 2344         # single address, remove
2345         if reset "remove single address"; the    2345         if reset "remove single address"; then
2346                 pm_nl_set_limits $ns1 0 1        2346                 pm_nl_set_limits $ns1 0 1
2347                 pm_nl_add_endpoint $ns1 10.0.    2347                 pm_nl_add_endpoint $ns1 10.0.2.1 flags signal
2348                 pm_nl_set_limits $ns2 1 1        2348                 pm_nl_set_limits $ns2 1 1
2349                 addr_nr_ns1=-1 speed=slow \      2349                 addr_nr_ns1=-1 speed=slow \
2350                         run_tests $ns1 $ns2 1    2350                         run_tests $ns1 $ns2 10.0.1.1
2351                 chk_join_nr 1 1 1                2351                 chk_join_nr 1 1 1
2352                 chk_add_nr 1 1                   2352                 chk_add_nr 1 1
2353                 chk_rm_nr 1 1 invert             2353                 chk_rm_nr 1 1 invert
2354                 chk_rst_nr 0 0                   2354                 chk_rst_nr 0 0
2355         fi                                       2355         fi
2356                                                  2356 
2357         # subflow and signal, remove             2357         # subflow and signal, remove
2358         if reset "remove subflow and signal";    2358         if reset "remove subflow and signal"; then
2359                 pm_nl_set_limits $ns1 0 2        2359                 pm_nl_set_limits $ns1 0 2
2360                 pm_nl_add_endpoint $ns1 10.0.    2360                 pm_nl_add_endpoint $ns1 10.0.2.1 flags signal
2361                 pm_nl_set_limits $ns2 1 2        2361                 pm_nl_set_limits $ns2 1 2
2362                 pm_nl_add_endpoint $ns2 10.0.    2362                 pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow
2363                 addr_nr_ns1=-1 addr_nr_ns2=-1    2363                 addr_nr_ns1=-1 addr_nr_ns2=-1 speed=slow \
2364                         run_tests $ns1 $ns2 1    2364                         run_tests $ns1 $ns2 10.0.1.1
2365                 chk_join_nr 2 2 2                2365                 chk_join_nr 2 2 2
2366                 chk_add_nr 1 1                   2366                 chk_add_nr 1 1
2367                 chk_rm_nr 1 1                    2367                 chk_rm_nr 1 1
2368                 chk_rst_nr 0 0                   2368                 chk_rst_nr 0 0
2369         fi                                       2369         fi
2370                                                  2370 
2371         # subflows and signal, remove            2371         # subflows and signal, remove
2372         if reset "remove subflows and signal"    2372         if reset "remove subflows and signal"; then
2373                 pm_nl_set_limits $ns1 0 3        2373                 pm_nl_set_limits $ns1 0 3
2374                 pm_nl_add_endpoint $ns1 10.0.    2374                 pm_nl_add_endpoint $ns1 10.0.2.1 flags signal
2375                 pm_nl_set_limits $ns2 1 3        2375                 pm_nl_set_limits $ns2 1 3
2376                 pm_nl_add_endpoint $ns2 10.0.    2376                 pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow
2377                 pm_nl_add_endpoint $ns2 10.0.    2377                 pm_nl_add_endpoint $ns2 10.0.4.2 flags subflow
2378                 addr_nr_ns1=-1 addr_nr_ns2=-2    2378                 addr_nr_ns1=-1 addr_nr_ns2=-2 speed=10 \
2379                         run_tests $ns1 $ns2 1    2379                         run_tests $ns1 $ns2 10.0.1.1
2380                 chk_join_nr 3 3 3                2380                 chk_join_nr 3 3 3
2381                 chk_add_nr 1 1                   2381                 chk_add_nr 1 1
2382                 chk_rm_nr 2 2                    2382                 chk_rm_nr 2 2
2383                 chk_rst_nr 0 0                   2383                 chk_rst_nr 0 0
2384         fi                                       2384         fi
2385                                                  2385 
2386         # addresses remove                       2386         # addresses remove
2387         if reset "remove addresses"; then        2387         if reset "remove addresses"; then
2388                 pm_nl_set_limits $ns1 3 3        2388                 pm_nl_set_limits $ns1 3 3
2389                 pm_nl_add_endpoint $ns1 10.0.    2389                 pm_nl_add_endpoint $ns1 10.0.2.1 flags signal id 250
2390                 pm_nl_add_endpoint $ns1 10.0.    2390                 pm_nl_add_endpoint $ns1 10.0.3.1 flags signal
2391                 pm_nl_add_endpoint $ns1 10.0.    2391                 pm_nl_add_endpoint $ns1 10.0.4.1 flags signal
2392                 pm_nl_set_limits $ns2 3 3        2392                 pm_nl_set_limits $ns2 3 3
2393                 addr_nr_ns1=-3 speed=10 \        2393                 addr_nr_ns1=-3 speed=10 \
2394                         run_tests $ns1 $ns2 1    2394                         run_tests $ns1 $ns2 10.0.1.1
2395                 chk_join_nr 3 3 3                2395                 chk_join_nr 3 3 3
2396                 chk_add_nr 3 3                   2396                 chk_add_nr 3 3
2397                 chk_rm_nr 3 3 invert             2397                 chk_rm_nr 3 3 invert
2398                 chk_rst_nr 0 0                   2398                 chk_rst_nr 0 0
2399         fi                                       2399         fi
2400                                                  2400 
2401         # invalid addresses remove               2401         # invalid addresses remove
2402         if reset "remove invalid addresses";     2402         if reset "remove invalid addresses"; then
2403                 pm_nl_set_limits $ns1 3 3        2403                 pm_nl_set_limits $ns1 3 3
2404                 pm_nl_add_endpoint $ns1 10.0.    2404                 pm_nl_add_endpoint $ns1 10.0.12.1 flags signal
2405                 # broadcast IP: no packet for    2405                 # broadcast IP: no packet for this address will be received on ns1
2406                 pm_nl_add_endpoint $ns1 224.0    2406                 pm_nl_add_endpoint $ns1 224.0.0.1 flags signal
2407                 pm_nl_add_endpoint $ns1 10.0.    2407                 pm_nl_add_endpoint $ns1 10.0.3.1 flags signal
2408                 pm_nl_set_limits $ns2 2 2        2408                 pm_nl_set_limits $ns2 2 2
2409                 addr_nr_ns1=-3 speed=10 \        2409                 addr_nr_ns1=-3 speed=10 \
2410                         run_tests $ns1 $ns2 1    2410                         run_tests $ns1 $ns2 10.0.1.1
2411                 join_syn_tx=2 join_connect_er    2411                 join_syn_tx=2 join_connect_err=1 \
2412                         chk_join_nr 1 1 1        2412                         chk_join_nr 1 1 1
2413                 chk_add_nr 3 3                   2413                 chk_add_nr 3 3
2414                 chk_rm_nr 3 1 invert             2414                 chk_rm_nr 3 1 invert
2415                 chk_rst_nr 0 0                   2415                 chk_rst_nr 0 0
2416         fi                                       2416         fi
2417                                                  2417 
2418         # subflows and signal, flush             2418         # subflows and signal, flush
2419         if reset "flush subflows and signal";    2419         if reset "flush subflows and signal"; then
2420                 pm_nl_set_limits $ns1 0 3        2420                 pm_nl_set_limits $ns1 0 3
2421                 pm_nl_add_endpoint $ns1 10.0.    2421                 pm_nl_add_endpoint $ns1 10.0.2.1 flags signal
2422                 pm_nl_set_limits $ns2 1 3        2422                 pm_nl_set_limits $ns2 1 3
2423                 pm_nl_add_endpoint $ns2 10.0.    2423                 pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow
2424                 pm_nl_add_endpoint $ns2 10.0.    2424                 pm_nl_add_endpoint $ns2 10.0.4.2 flags subflow
2425                 addr_nr_ns1=-8 addr_nr_ns2=-8    2425                 addr_nr_ns1=-8 addr_nr_ns2=-8 speed=slow \
2426                         run_tests $ns1 $ns2 1    2426                         run_tests $ns1 $ns2 10.0.1.1
2427                 chk_join_nr 3 3 3                2427                 chk_join_nr 3 3 3
2428                 chk_add_nr 1 1                   2428                 chk_add_nr 1 1
2429                 chk_rm_nr 1 3 invert simult      2429                 chk_rm_nr 1 3 invert simult
2430                 chk_rst_nr 0 0                   2430                 chk_rst_nr 0 0
2431         fi                                       2431         fi
2432                                                  2432 
2433         # subflows flush                         2433         # subflows flush
2434         if reset "flush subflows"; then          2434         if reset "flush subflows"; then
2435                 pm_nl_set_limits $ns1 3 3        2435                 pm_nl_set_limits $ns1 3 3
2436                 pm_nl_set_limits $ns2 3 3        2436                 pm_nl_set_limits $ns2 3 3
2437                 pm_nl_add_endpoint $ns2 10.0.    2437                 pm_nl_add_endpoint $ns2 10.0.2.2 flags subflow id 150
2438                 pm_nl_add_endpoint $ns2 10.0.    2438                 pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow
2439                 pm_nl_add_endpoint $ns2 10.0.    2439                 pm_nl_add_endpoint $ns2 10.0.4.2 flags subflow
2440                 addr_nr_ns1=-8 addr_nr_ns2=-8    2440                 addr_nr_ns1=-8 addr_nr_ns2=-8 speed=slow \
2441                         run_tests $ns1 $ns2 1    2441                         run_tests $ns1 $ns2 10.0.1.1
2442                 chk_join_nr 3 3 3                2442                 chk_join_nr 3 3 3
2443                                                  2443 
2444                 if mptcp_lib_kversion_ge 5.18    2444                 if mptcp_lib_kversion_ge 5.18; then
2445                         chk_rm_tx_nr 0           2445                         chk_rm_tx_nr 0
2446                         chk_rm_nr 0 3 simult     2446                         chk_rm_nr 0 3 simult
2447                 else                             2447                 else
2448                         chk_rm_nr 3 3            2448                         chk_rm_nr 3 3
2449                 fi                               2449                 fi
2450                 chk_rst_nr 0 0                   2450                 chk_rst_nr 0 0
2451         fi                                       2451         fi
2452                                                  2452 
2453         # addresses flush                        2453         # addresses flush
2454         if reset "flush addresses"; then         2454         if reset "flush addresses"; then
2455                 pm_nl_set_limits $ns1 3 3        2455                 pm_nl_set_limits $ns1 3 3
2456                 pm_nl_add_endpoint $ns1 10.0.    2456                 pm_nl_add_endpoint $ns1 10.0.2.1 flags signal id 250
2457                 pm_nl_add_endpoint $ns1 10.0.    2457                 pm_nl_add_endpoint $ns1 10.0.3.1 flags signal
2458                 pm_nl_add_endpoint $ns1 10.0.    2458                 pm_nl_add_endpoint $ns1 10.0.4.1 flags signal
2459                 pm_nl_set_limits $ns2 3 3        2459                 pm_nl_set_limits $ns2 3 3
2460                 addr_nr_ns1=-8 addr_nr_ns2=-8    2460                 addr_nr_ns1=-8 addr_nr_ns2=-8 speed=slow \
2461                         run_tests $ns1 $ns2 1    2461                         run_tests $ns1 $ns2 10.0.1.1
2462                 chk_join_nr 3 3 3                2462                 chk_join_nr 3 3 3
2463                 chk_add_nr 3 3                   2463                 chk_add_nr 3 3
2464                 chk_rm_nr 3 3 invert simult      2464                 chk_rm_nr 3 3 invert simult
2465                 chk_rst_nr 0 0                   2465                 chk_rst_nr 0 0
2466         fi                                       2466         fi
2467                                                  2467 
2468         # invalid addresses flush                2468         # invalid addresses flush
2469         if reset "flush invalid addresses"; t    2469         if reset "flush invalid addresses"; then
2470                 pm_nl_set_limits $ns1 3 3        2470                 pm_nl_set_limits $ns1 3 3
2471                 pm_nl_add_endpoint $ns1 10.0.    2471                 pm_nl_add_endpoint $ns1 10.0.12.1 flags signal
2472                 pm_nl_add_endpoint $ns1 10.0.    2472                 pm_nl_add_endpoint $ns1 10.0.3.1 flags signal
2473                 pm_nl_add_endpoint $ns1 10.0.    2473                 pm_nl_add_endpoint $ns1 10.0.14.1 flags signal
2474                 pm_nl_set_limits $ns2 3 3        2474                 pm_nl_set_limits $ns2 3 3
2475                 addr_nr_ns1=-8 speed=slow \      2475                 addr_nr_ns1=-8 speed=slow \
2476                         run_tests $ns1 $ns2 1    2476                         run_tests $ns1 $ns2 10.0.1.1
2477                 join_syn_tx=3 \                  2477                 join_syn_tx=3 \
2478                         chk_join_nr 1 1 1        2478                         chk_join_nr 1 1 1
2479                 chk_add_nr 3 3                   2479                 chk_add_nr 3 3
2480                 chk_rm_nr 3 1 invert             2480                 chk_rm_nr 3 1 invert
2481                 chk_rst_nr 0 0                   2481                 chk_rst_nr 0 0
2482         fi                                       2482         fi
2483                                                  2483 
2484         # remove id 0 subflow                    2484         # remove id 0 subflow
2485         if reset "remove id 0 subflow"; then     2485         if reset "remove id 0 subflow"; then
2486                 pm_nl_set_limits $ns1 0 1        2486                 pm_nl_set_limits $ns1 0 1
2487                 pm_nl_set_limits $ns2 0 1        2487                 pm_nl_set_limits $ns2 0 1
2488                 pm_nl_add_endpoint $ns2 10.0.    2488                 pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow
2489                 addr_nr_ns2=-9 speed=slow \      2489                 addr_nr_ns2=-9 speed=slow \
2490                         run_tests $ns1 $ns2 1    2490                         run_tests $ns1 $ns2 10.0.1.1
2491                 chk_join_nr 1 1 1                2491                 chk_join_nr 1 1 1
2492                 chk_rm_nr 1 1                    2492                 chk_rm_nr 1 1
2493                 chk_rst_nr 0 0                   2493                 chk_rst_nr 0 0
2494         fi                                       2494         fi
2495                                                  2495 
2496         # remove id 0 address                    2496         # remove id 0 address
2497         if reset "remove id 0 address"; then     2497         if reset "remove id 0 address"; then
2498                 pm_nl_set_limits $ns1 0 1        2498                 pm_nl_set_limits $ns1 0 1
2499                 pm_nl_add_endpoint $ns1 10.0.    2499                 pm_nl_add_endpoint $ns1 10.0.2.1 flags signal
2500                 pm_nl_set_limits $ns2 1 1        2500                 pm_nl_set_limits $ns2 1 1
2501                 addr_nr_ns1=-9 speed=slow \      2501                 addr_nr_ns1=-9 speed=slow \
2502                         run_tests $ns1 $ns2 1    2502                         run_tests $ns1 $ns2 10.0.1.1
2503                 chk_join_nr 1 1 1                2503                 chk_join_nr 1 1 1
2504                 chk_add_nr 1 1                   2504                 chk_add_nr 1 1
2505                 chk_rm_nr 1 1 invert             2505                 chk_rm_nr 1 1 invert
2506                 chk_rst_nr 0 0 invert            2506                 chk_rst_nr 0 0 invert
2507         fi                                       2507         fi
2508 }                                                2508 }
2509                                                  2509 
2510 add_tests()                                      2510 add_tests()
2511 {                                                2511 {
2512         # add single subflow                     2512         # add single subflow
2513         if reset "add single subflow"; then      2513         if reset "add single subflow"; then
2514                 pm_nl_set_limits $ns1 0 1        2514                 pm_nl_set_limits $ns1 0 1
2515                 pm_nl_set_limits $ns2 0 1        2515                 pm_nl_set_limits $ns2 0 1
2516                 addr_nr_ns2=1 speed=slow cest    2516                 addr_nr_ns2=1 speed=slow cestab_ns2=1 \
2517                         run_tests $ns1 $ns2 1    2517                         run_tests $ns1 $ns2 10.0.1.1
2518                 chk_join_nr 1 1 1                2518                 chk_join_nr 1 1 1
2519                 chk_cestab_nr $ns2 0             2519                 chk_cestab_nr $ns2 0
2520         fi                                       2520         fi
2521                                                  2521 
2522         # add signal address                     2522         # add signal address
2523         if reset "add signal address"; then      2523         if reset "add signal address"; then
2524                 pm_nl_set_limits $ns1 0 1        2524                 pm_nl_set_limits $ns1 0 1
2525                 pm_nl_set_limits $ns2 1 1        2525                 pm_nl_set_limits $ns2 1 1
2526                 addr_nr_ns1=1 speed=slow cest    2526                 addr_nr_ns1=1 speed=slow cestab_ns1=1 \
2527                         run_tests $ns1 $ns2 1    2527                         run_tests $ns1 $ns2 10.0.1.1
2528                 chk_join_nr 1 1 1                2528                 chk_join_nr 1 1 1
2529                 chk_add_nr 1 1                   2529                 chk_add_nr 1 1
2530                 chk_cestab_nr $ns1 0             2530                 chk_cestab_nr $ns1 0
2531         fi                                       2531         fi
2532                                                  2532 
2533         # add multiple subflows                  2533         # add multiple subflows
2534         if reset "add multiple subflows"; the    2534         if reset "add multiple subflows"; then
2535                 pm_nl_set_limits $ns1 0 2        2535                 pm_nl_set_limits $ns1 0 2
2536                 pm_nl_set_limits $ns2 0 2        2536                 pm_nl_set_limits $ns2 0 2
2537                 addr_nr_ns2=2 speed=slow cest    2537                 addr_nr_ns2=2 speed=slow cestab_ns2=1 \
2538                         run_tests $ns1 $ns2 1    2538                         run_tests $ns1 $ns2 10.0.1.1
2539                 chk_join_nr 2 2 2                2539                 chk_join_nr 2 2 2
2540                 chk_cestab_nr $ns2 0             2540                 chk_cestab_nr $ns2 0
2541         fi                                       2541         fi
2542                                                  2542 
2543         # add multiple subflows IPv6             2543         # add multiple subflows IPv6
2544         if reset "add multiple subflows IPv6"    2544         if reset "add multiple subflows IPv6"; then
2545                 pm_nl_set_limits $ns1 0 2        2545                 pm_nl_set_limits $ns1 0 2
2546                 pm_nl_set_limits $ns2 0 2        2546                 pm_nl_set_limits $ns2 0 2
2547                 addr_nr_ns2=2 speed=slow cest    2547                 addr_nr_ns2=2 speed=slow cestab_ns2=1 \
2548                         run_tests $ns1 $ns2 d    2548                         run_tests $ns1 $ns2 dead:beef:1::1
2549                 chk_join_nr 2 2 2                2549                 chk_join_nr 2 2 2
2550                 chk_cestab_nr $ns2 0             2550                 chk_cestab_nr $ns2 0
2551         fi                                       2551         fi
2552                                                  2552 
2553         # add multiple addresses IPv6            2553         # add multiple addresses IPv6
2554         if reset "add multiple addresses IPv6    2554         if reset "add multiple addresses IPv6"; then
2555                 pm_nl_set_limits $ns1 0 2        2555                 pm_nl_set_limits $ns1 0 2
2556                 pm_nl_set_limits $ns2 2 2        2556                 pm_nl_set_limits $ns2 2 2
2557                 addr_nr_ns1=2 speed=slow cest    2557                 addr_nr_ns1=2 speed=slow cestab_ns1=1 \
2558                         run_tests $ns1 $ns2 d    2558                         run_tests $ns1 $ns2 dead:beef:1::1
2559                 chk_join_nr 2 2 2                2559                 chk_join_nr 2 2 2
2560                 chk_add_nr 2 2                   2560                 chk_add_nr 2 2
2561                 chk_cestab_nr $ns1 0             2561                 chk_cestab_nr $ns1 0
2562         fi                                       2562         fi
2563 }                                                2563 }
2564                                                  2564 
2565 ipv6_tests()                                     2565 ipv6_tests()
2566 {                                                2566 {
2567         # subflow IPv6                           2567         # subflow IPv6
2568         if reset "single subflow IPv6"; then     2568         if reset "single subflow IPv6"; then
2569                 pm_nl_set_limits $ns1 0 1        2569                 pm_nl_set_limits $ns1 0 1
2570                 pm_nl_set_limits $ns2 0 1        2570                 pm_nl_set_limits $ns2 0 1
2571                 pm_nl_add_endpoint $ns2 dead:    2571                 pm_nl_add_endpoint $ns2 dead:beef:3::2 dev ns2eth3 flags subflow
2572                 speed=slow \                     2572                 speed=slow \
2573                         run_tests $ns1 $ns2 d    2573                         run_tests $ns1 $ns2 dead:beef:1::1
2574                 chk_join_nr 1 1 1                2574                 chk_join_nr 1 1 1
2575         fi                                       2575         fi
2576                                                  2576 
2577         # add_address, unused IPv6               2577         # add_address, unused IPv6
2578         if reset "unused signal address IPv6"    2578         if reset "unused signal address IPv6"; then
2579                 pm_nl_add_endpoint $ns1 dead:    2579                 pm_nl_add_endpoint $ns1 dead:beef:2::1 flags signal
2580                 speed=slow \                     2580                 speed=slow \
2581                         run_tests $ns1 $ns2 d    2581                         run_tests $ns1 $ns2 dead:beef:1::1
2582                 chk_join_nr 0 0 0                2582                 chk_join_nr 0 0 0
2583                 chk_add_nr 1 1                   2583                 chk_add_nr 1 1
2584         fi                                       2584         fi
2585                                                  2585 
2586         # signal address IPv6                    2586         # signal address IPv6
2587         if reset "single address IPv6"; then     2587         if reset "single address IPv6"; then
2588                 pm_nl_set_limits $ns1 0 1        2588                 pm_nl_set_limits $ns1 0 1
2589                 pm_nl_add_endpoint $ns1 dead:    2589                 pm_nl_add_endpoint $ns1 dead:beef:2::1 flags signal
2590                 pm_nl_set_limits $ns2 1 1        2590                 pm_nl_set_limits $ns2 1 1
2591                 speed=slow \                     2591                 speed=slow \
2592                         run_tests $ns1 $ns2 d    2592                         run_tests $ns1 $ns2 dead:beef:1::1
2593                 chk_join_nr 1 1 1                2593                 chk_join_nr 1 1 1
2594                 chk_add_nr 1 1                   2594                 chk_add_nr 1 1
2595         fi                                       2595         fi
2596                                                  2596 
2597         # single address IPv6, remove            2597         # single address IPv6, remove
2598         if reset "remove single address IPv6"    2598         if reset "remove single address IPv6"; then
2599                 pm_nl_set_limits $ns1 0 1        2599                 pm_nl_set_limits $ns1 0 1
2600                 pm_nl_add_endpoint $ns1 dead:    2600                 pm_nl_add_endpoint $ns1 dead:beef:2::1 flags signal
2601                 pm_nl_set_limits $ns2 1 1        2601                 pm_nl_set_limits $ns2 1 1
2602                 addr_nr_ns1=-1 speed=slow \      2602                 addr_nr_ns1=-1 speed=slow \
2603                         run_tests $ns1 $ns2 d    2603                         run_tests $ns1 $ns2 dead:beef:1::1
2604                 chk_join_nr 1 1 1                2604                 chk_join_nr 1 1 1
2605                 chk_add_nr 1 1                   2605                 chk_add_nr 1 1
2606                 chk_rm_nr 1 1 invert             2606                 chk_rm_nr 1 1 invert
2607         fi                                       2607         fi
2608                                                  2608 
2609         # subflow and signal IPv6, remove        2609         # subflow and signal IPv6, remove
2610         if reset "remove subflow and signal I    2610         if reset "remove subflow and signal IPv6"; then
2611                 pm_nl_set_limits $ns1 0 2        2611                 pm_nl_set_limits $ns1 0 2
2612                 pm_nl_add_endpoint $ns1 dead:    2612                 pm_nl_add_endpoint $ns1 dead:beef:2::1 flags signal
2613                 pm_nl_set_limits $ns2 1 2        2613                 pm_nl_set_limits $ns2 1 2
2614                 pm_nl_add_endpoint $ns2 dead:    2614                 pm_nl_add_endpoint $ns2 dead:beef:3::2 dev ns2eth3 flags subflow
2615                 addr_nr_ns1=-1 addr_nr_ns2=-1    2615                 addr_nr_ns1=-1 addr_nr_ns2=-1 speed=slow \
2616                         run_tests $ns1 $ns2 d    2616                         run_tests $ns1 $ns2 dead:beef:1::1
2617                 chk_join_nr 2 2 2                2617                 chk_join_nr 2 2 2
2618                 chk_add_nr 1 1                   2618                 chk_add_nr 1 1
2619                 chk_rm_nr 1 1                    2619                 chk_rm_nr 1 1
2620         fi                                       2620         fi
2621 }                                                2621 }
2622                                                  2622 
2623 v4mapped_tests()                                 2623 v4mapped_tests()
2624 {                                                2624 {
2625         # subflow IPv4-mapped to IPv4-mapped     2625         # subflow IPv4-mapped to IPv4-mapped
2626         if reset "single subflow IPv4-mapped"    2626         if reset "single subflow IPv4-mapped"; then
2627                 pm_nl_set_limits $ns1 0 1        2627                 pm_nl_set_limits $ns1 0 1
2628                 pm_nl_set_limits $ns2 0 1        2628                 pm_nl_set_limits $ns2 0 1
2629                 pm_nl_add_endpoint $ns2 "::ff    2629                 pm_nl_add_endpoint $ns2 "::ffff:10.0.3.2" flags subflow
2630                 run_tests $ns1 $ns2 "::ffff:1    2630                 run_tests $ns1 $ns2 "::ffff:10.0.1.1"
2631                 chk_join_nr 1 1 1                2631                 chk_join_nr 1 1 1
2632         fi                                       2632         fi
2633                                                  2633 
2634         # signal address IPv4-mapped with IPv    2634         # signal address IPv4-mapped with IPv4-mapped sk
2635         if reset "signal address IPv4-mapped"    2635         if reset "signal address IPv4-mapped"; then
2636                 pm_nl_set_limits $ns1 0 1        2636                 pm_nl_set_limits $ns1 0 1
2637                 pm_nl_set_limits $ns2 1 1        2637                 pm_nl_set_limits $ns2 1 1
2638                 pm_nl_add_endpoint $ns1 "::ff    2638                 pm_nl_add_endpoint $ns1 "::ffff:10.0.2.1" flags signal
2639                 run_tests $ns1 $ns2 "::ffff:1    2639                 run_tests $ns1 $ns2 "::ffff:10.0.1.1"
2640                 chk_join_nr 1 1 1                2640                 chk_join_nr 1 1 1
2641                 chk_add_nr 1 1                   2641                 chk_add_nr 1 1
2642         fi                                       2642         fi
2643                                                  2643 
2644         # subflow v4-map-v6                      2644         # subflow v4-map-v6
2645         if reset "single subflow v4-map-v6";     2645         if reset "single subflow v4-map-v6"; then
2646                 pm_nl_set_limits $ns1 0 1        2646                 pm_nl_set_limits $ns1 0 1
2647                 pm_nl_set_limits $ns2 0 1        2647                 pm_nl_set_limits $ns2 0 1
2648                 pm_nl_add_endpoint $ns2 10.0.    2648                 pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow
2649                 run_tests $ns1 $ns2 "::ffff:1    2649                 run_tests $ns1 $ns2 "::ffff:10.0.1.1"
2650                 chk_join_nr 1 1 1                2650                 chk_join_nr 1 1 1
2651         fi                                       2651         fi
2652                                                  2652 
2653         # signal address v4-map-v6               2653         # signal address v4-map-v6
2654         if reset "signal address v4-map-v6";     2654         if reset "signal address v4-map-v6"; then
2655                 pm_nl_set_limits $ns1 0 1        2655                 pm_nl_set_limits $ns1 0 1
2656                 pm_nl_set_limits $ns2 1 1        2656                 pm_nl_set_limits $ns2 1 1
2657                 pm_nl_add_endpoint $ns1 10.0.    2657                 pm_nl_add_endpoint $ns1 10.0.2.1 flags signal
2658                 run_tests $ns1 $ns2 "::ffff:1    2658                 run_tests $ns1 $ns2 "::ffff:10.0.1.1"
2659                 chk_join_nr 1 1 1                2659                 chk_join_nr 1 1 1
2660                 chk_add_nr 1 1                   2660                 chk_add_nr 1 1
2661         fi                                       2661         fi
2662                                                  2662 
2663         # subflow v6-map-v4                      2663         # subflow v6-map-v4
2664         if reset "single subflow v6-map-v4";     2664         if reset "single subflow v6-map-v4"; then
2665                 pm_nl_set_limits $ns1 0 1        2665                 pm_nl_set_limits $ns1 0 1
2666                 pm_nl_set_limits $ns2 0 1        2666                 pm_nl_set_limits $ns2 0 1
2667                 pm_nl_add_endpoint $ns2 "::ff    2667                 pm_nl_add_endpoint $ns2 "::ffff:10.0.3.2" flags subflow
2668                 run_tests $ns1 $ns2 10.0.1.1     2668                 run_tests $ns1 $ns2 10.0.1.1
2669                 chk_join_nr 1 1 1                2669                 chk_join_nr 1 1 1
2670         fi                                       2670         fi
2671                                                  2671 
2672         # signal address v6-map-v4               2672         # signal address v6-map-v4
2673         if reset "signal address v6-map-v4";     2673         if reset "signal address v6-map-v4"; then
2674                 pm_nl_set_limits $ns1 0 1        2674                 pm_nl_set_limits $ns1 0 1
2675                 pm_nl_set_limits $ns2 1 1        2675                 pm_nl_set_limits $ns2 1 1
2676                 pm_nl_add_endpoint $ns1 "::ff    2676                 pm_nl_add_endpoint $ns1 "::ffff:10.0.2.1" flags signal
2677                 run_tests $ns1 $ns2 10.0.1.1     2677                 run_tests $ns1 $ns2 10.0.1.1
2678                 chk_join_nr 1 1 1                2678                 chk_join_nr 1 1 1
2679                 chk_add_nr 1 1                   2679                 chk_add_nr 1 1
2680         fi                                       2680         fi
2681                                                  2681 
2682         # no subflow IPv6 to v4 address          2682         # no subflow IPv6 to v4 address
2683         if reset "no JOIN with diff families     2683         if reset "no JOIN with diff families v4-v6"; then
2684                 pm_nl_set_limits $ns1 0 1        2684                 pm_nl_set_limits $ns1 0 1
2685                 pm_nl_set_limits $ns2 0 1        2685                 pm_nl_set_limits $ns2 0 1
2686                 pm_nl_add_endpoint $ns2 dead:    2686                 pm_nl_add_endpoint $ns2 dead:beef:2::2 flags subflow
2687                 run_tests $ns1 $ns2 10.0.1.1     2687                 run_tests $ns1 $ns2 10.0.1.1
2688                 chk_join_nr 0 0 0                2688                 chk_join_nr 0 0 0
2689         fi                                       2689         fi
2690                                                  2690 
2691         # no subflow IPv6 to v4 address even     2691         # no subflow IPv6 to v4 address even if v6 has a valid v4 at the end
2692         if reset "no JOIN with diff families     2692         if reset "no JOIN with diff families v4-v6-2"; then
2693                 pm_nl_set_limits $ns1 0 1        2693                 pm_nl_set_limits $ns1 0 1
2694                 pm_nl_set_limits $ns2 0 1        2694                 pm_nl_set_limits $ns2 0 1
2695                 pm_nl_add_endpoint $ns2 dead:    2695                 pm_nl_add_endpoint $ns2 dead:beef:2::10.0.3.2 flags subflow
2696                 run_tests $ns1 $ns2 10.0.1.1     2696                 run_tests $ns1 $ns2 10.0.1.1
2697                 chk_join_nr 0 0 0                2697                 chk_join_nr 0 0 0
2698         fi                                       2698         fi
2699                                                  2699 
2700         # no subflow IPv4 to v6 address, no n    2700         # no subflow IPv4 to v6 address, no need to slow down too then
2701         if reset "no JOIN with diff families     2701         if reset "no JOIN with diff families v6-v4"; then
2702                 pm_nl_set_limits $ns1 0 1        2702                 pm_nl_set_limits $ns1 0 1
2703                 pm_nl_set_limits $ns2 0 1        2703                 pm_nl_set_limits $ns2 0 1
2704                 pm_nl_add_endpoint $ns2 10.0.    2704                 pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow
2705                 run_tests $ns1 $ns2 dead:beef    2705                 run_tests $ns1 $ns2 dead:beef:1::1
2706                 chk_join_nr 0 0 0                2706                 chk_join_nr 0 0 0
2707         fi                                       2707         fi
2708 }                                                2708 }
2709                                                  2709 
2710 mixed_tests()                                    2710 mixed_tests()
2711 {                                                2711 {
2712         if reset "IPv4 sockets do not use IPv    2712         if reset "IPv4 sockets do not use IPv6 addresses" &&
2713            continue_if mptcp_lib_kversion_ge     2713            continue_if mptcp_lib_kversion_ge 6.3; then
2714                 pm_nl_set_limits $ns1 0 1        2714                 pm_nl_set_limits $ns1 0 1
2715                 pm_nl_set_limits $ns2 1 1        2715                 pm_nl_set_limits $ns2 1 1
2716                 pm_nl_add_endpoint $ns1 dead:    2716                 pm_nl_add_endpoint $ns1 dead:beef:2::1 flags signal
2717                 speed=slow \                     2717                 speed=slow \
2718                         run_tests $ns1 $ns2 1    2718                         run_tests $ns1 $ns2 10.0.1.1
2719                 chk_join_nr 0 0 0                2719                 chk_join_nr 0 0 0
2720         fi                                       2720         fi
2721                                                  2721 
2722         # Need an IPv6 mptcp socket to allow     2722         # Need an IPv6 mptcp socket to allow subflows of both families
2723         if reset "simult IPv4 and IPv6 subflo    2723         if reset "simult IPv4 and IPv6 subflows" &&
2724            continue_if mptcp_lib_kversion_ge     2724            continue_if mptcp_lib_kversion_ge 6.3; then
2725                 pm_nl_set_limits $ns1 0 1        2725                 pm_nl_set_limits $ns1 0 1
2726                 pm_nl_set_limits $ns2 1 1        2726                 pm_nl_set_limits $ns2 1 1
2727                 pm_nl_add_endpoint $ns1 10.0.    2727                 pm_nl_add_endpoint $ns1 10.0.1.1 flags signal
2728                 speed=slow \                     2728                 speed=slow \
2729                         run_tests $ns1 $ns2 d    2729                         run_tests $ns1 $ns2 dead:beef:2::1
2730                 chk_join_nr 1 1 1                2730                 chk_join_nr 1 1 1
2731         fi                                       2731         fi
2732                                                  2732 
2733         # cross families subflows will not be    2733         # cross families subflows will not be created even in fullmesh mode
2734         if reset "simult IPv4 and IPv6 subflo    2734         if reset "simult IPv4 and IPv6 subflows, fullmesh 1x1" &&
2735            continue_if mptcp_lib_kversion_ge     2735            continue_if mptcp_lib_kversion_ge 6.3; then
2736                 pm_nl_set_limits $ns1 0 4        2736                 pm_nl_set_limits $ns1 0 4
2737                 pm_nl_set_limits $ns2 1 4        2737                 pm_nl_set_limits $ns2 1 4
2738                 pm_nl_add_endpoint $ns2 dead:    2738                 pm_nl_add_endpoint $ns2 dead:beef:2::2 flags subflow,fullmesh
2739                 pm_nl_add_endpoint $ns1 10.0.    2739                 pm_nl_add_endpoint $ns1 10.0.1.1 flags signal
2740                 speed=slow \                     2740                 speed=slow \
2741                         run_tests $ns1 $ns2 d    2741                         run_tests $ns1 $ns2 dead:beef:2::1
2742                 chk_join_nr 1 1 1                2742                 chk_join_nr 1 1 1
2743         fi                                       2743         fi
2744                                                  2744 
2745         # fullmesh still tries to create all     2745         # fullmesh still tries to create all the possibly subflows with
2746         # matching family                        2746         # matching family
2747         if reset "simult IPv4 and IPv6 subflo    2747         if reset "simult IPv4 and IPv6 subflows, fullmesh 2x2" &&
2748            continue_if mptcp_lib_kversion_ge     2748            continue_if mptcp_lib_kversion_ge 6.3; then
2749                 pm_nl_set_limits $ns1 0 4        2749                 pm_nl_set_limits $ns1 0 4
2750                 pm_nl_set_limits $ns2 2 4        2750                 pm_nl_set_limits $ns2 2 4
2751                 pm_nl_add_endpoint $ns1 10.0.    2751                 pm_nl_add_endpoint $ns1 10.0.2.1 flags signal
2752                 pm_nl_add_endpoint $ns1 dead:    2752                 pm_nl_add_endpoint $ns1 dead:beef:2::1 flags signal
2753                 fullmesh=1 speed=slow \          2753                 fullmesh=1 speed=slow \
2754                         run_tests $ns1 $ns2 d    2754                         run_tests $ns1 $ns2 dead:beef:1::1
2755                 chk_join_nr 4 4 4                2755                 chk_join_nr 4 4 4
2756         fi                                       2756         fi
2757 }                                                2757 }
2758                                                  2758 
2759 backup_tests()                                   2759 backup_tests()
2760 {                                                2760 {
2761         # single subflow, backup                 2761         # single subflow, backup
2762         if reset "single subflow, backup" &&     2762         if reset "single subflow, backup" &&
2763            continue_if mptcp_lib_kallsyms_has    2763            continue_if mptcp_lib_kallsyms_has "subflow_rebuild_header$"; then
2764                 pm_nl_set_limits $ns1 0 1        2764                 pm_nl_set_limits $ns1 0 1
2765                 pm_nl_set_limits $ns2 0 1        2765                 pm_nl_set_limits $ns2 0 1
2766                 pm_nl_add_endpoint $ns2 10.0.    2766                 pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow,backup
2767                 sflags=nobackup speed=slow \     2767                 sflags=nobackup speed=slow \
2768                         run_tests $ns1 $ns2 1    2768                         run_tests $ns1 $ns2 10.0.1.1
2769                 chk_join_nr 1 1 1                2769                 chk_join_nr 1 1 1
2770                 chk_prio_nr 0 1 1 0              2770                 chk_prio_nr 0 1 1 0
2771         fi                                       2771         fi
2772                                                  2772 
2773         # single address, backup                 2773         # single address, backup
2774         if reset "single address, backup" &&     2774         if reset "single address, backup" &&
2775            continue_if mptcp_lib_kallsyms_has    2775            continue_if mptcp_lib_kallsyms_has "subflow_rebuild_header$"; then
2776                 pm_nl_set_limits $ns1 0 1        2776                 pm_nl_set_limits $ns1 0 1
2777                 pm_nl_add_endpoint $ns1 10.0.    2777                 pm_nl_add_endpoint $ns1 10.0.2.1 flags signal,backup
2778                 pm_nl_set_limits $ns2 1 1        2778                 pm_nl_set_limits $ns2 1 1
2779                 sflags=nobackup speed=slow \     2779                 sflags=nobackup speed=slow \
2780                         run_tests $ns1 $ns2 1    2780                         run_tests $ns1 $ns2 10.0.1.1
2781                 chk_join_nr 1 1 1                2781                 chk_join_nr 1 1 1
2782                 chk_add_nr 1 1                   2782                 chk_add_nr 1 1
2783                 chk_prio_nr 1 0 0 1              2783                 chk_prio_nr 1 0 0 1
2784         fi                                       2784         fi
2785                                                  2785 
2786         # single address, switch to backup       2786         # single address, switch to backup
2787         if reset "single address, switch to b    2787         if reset "single address, switch to backup" &&
2788            continue_if mptcp_lib_kallsyms_has    2788            continue_if mptcp_lib_kallsyms_has "subflow_rebuild_header$"; then
2789                 pm_nl_set_limits $ns1 0 1        2789                 pm_nl_set_limits $ns1 0 1
2790                 pm_nl_add_endpoint $ns1 10.0.    2790                 pm_nl_add_endpoint $ns1 10.0.2.1 flags signal
2791                 pm_nl_set_limits $ns2 1 1        2791                 pm_nl_set_limits $ns2 1 1
2792                 sflags=backup speed=slow \       2792                 sflags=backup speed=slow \
2793                         run_tests $ns1 $ns2 1    2793                         run_tests $ns1 $ns2 10.0.1.1
2794                 chk_join_nr 1 1 1                2794                 chk_join_nr 1 1 1
2795                 chk_add_nr 1 1                   2795                 chk_add_nr 1 1
2796                 chk_prio_nr 1 1 0 0              2796                 chk_prio_nr 1 1 0 0
2797         fi                                       2797         fi
2798                                                  2798 
2799         # single address with port, backup       2799         # single address with port, backup
2800         if reset "single address with port, b    2800         if reset "single address with port, backup" &&
2801            continue_if mptcp_lib_kallsyms_has    2801            continue_if mptcp_lib_kallsyms_has "subflow_rebuild_header$"; then
2802                 pm_nl_set_limits $ns1 0 1        2802                 pm_nl_set_limits $ns1 0 1
2803                 pm_nl_add_endpoint $ns1 10.0.    2803                 pm_nl_add_endpoint $ns1 10.0.2.1 flags signal,backup port 10100
2804                 pm_nl_set_limits $ns2 1 1        2804                 pm_nl_set_limits $ns2 1 1
2805                 sflags=nobackup speed=slow \     2805                 sflags=nobackup speed=slow \
2806                         run_tests $ns1 $ns2 1    2806                         run_tests $ns1 $ns2 10.0.1.1
2807                 chk_join_nr 1 1 1                2807                 chk_join_nr 1 1 1
2808                 chk_add_nr 1 1                   2808                 chk_add_nr 1 1
2809                 chk_prio_nr 1 0 0 1              2809                 chk_prio_nr 1 0 0 1
2810         fi                                       2810         fi
2811                                                  2811 
2812         if reset "mpc backup" &&                 2812         if reset "mpc backup" &&
2813            continue_if mptcp_lib_kallsyms_doe    2813            continue_if mptcp_lib_kallsyms_doesnt_have "T mptcp_subflow_send_ack$"; then
2814                 pm_nl_add_endpoint $ns2 10.0.    2814                 pm_nl_add_endpoint $ns2 10.0.1.2 flags subflow,backup
2815                 speed=slow \                     2815                 speed=slow \
2816                         run_tests $ns1 $ns2 1    2816                         run_tests $ns1 $ns2 10.0.1.1
2817                 chk_join_nr 0 0 0                2817                 chk_join_nr 0 0 0
2818                 chk_prio_nr 0 1 0 0              2818                 chk_prio_nr 0 1 0 0
2819         fi                                       2819         fi
2820                                                  2820 
2821         if reset "mpc backup both sides" &&      2821         if reset "mpc backup both sides" &&
2822            continue_if mptcp_lib_kallsyms_doe    2822            continue_if mptcp_lib_kallsyms_doesnt_have "T mptcp_subflow_send_ack$"; then
2823                 pm_nl_set_limits $ns1 0 2        2823                 pm_nl_set_limits $ns1 0 2
2824                 pm_nl_set_limits $ns2 1 2        2824                 pm_nl_set_limits $ns2 1 2
2825                 pm_nl_add_endpoint $ns1 10.0.    2825                 pm_nl_add_endpoint $ns1 10.0.1.1 flags signal,backup
2826                 pm_nl_add_endpoint $ns2 10.0.    2826                 pm_nl_add_endpoint $ns2 10.0.1.2 flags subflow,backup
2827                                                  2827 
2828                 # 10.0.2.2 (non-backup) -> 10    2828                 # 10.0.2.2 (non-backup) -> 10.0.1.1 (backup)
2829                 pm_nl_add_endpoint $ns2 10.0.    2829                 pm_nl_add_endpoint $ns2 10.0.2.2 flags subflow
2830                 # 10.0.1.2 (backup) -> 10.0.2    2830                 # 10.0.1.2 (backup) -> 10.0.2.1 (non-backup)
2831                 pm_nl_add_endpoint $ns1 10.0.    2831                 pm_nl_add_endpoint $ns1 10.0.2.1 flags signal
2832                 ip -net "$ns2" route add 10.0    2832                 ip -net "$ns2" route add 10.0.2.1 via 10.0.1.1 dev ns2eth1 # force this path
2833                                                  2833 
2834                 speed=slow \                     2834                 speed=slow \
2835                         run_tests $ns1 $ns2 1    2835                         run_tests $ns1 $ns2 10.0.1.1
2836                 chk_join_nr 2 2 2                2836                 chk_join_nr 2 2 2
2837                 chk_prio_nr 1 1 1 1              2837                 chk_prio_nr 1 1 1 1
2838         fi                                       2838         fi
2839                                                  2839 
2840         if reset "mpc switch to backup" &&       2840         if reset "mpc switch to backup" &&
2841            continue_if mptcp_lib_kallsyms_doe    2841            continue_if mptcp_lib_kallsyms_doesnt_have "T mptcp_subflow_send_ack$"; then
2842                 pm_nl_add_endpoint $ns2 10.0.    2842                 pm_nl_add_endpoint $ns2 10.0.1.2 flags subflow
2843                 sflags=backup speed=slow \       2843                 sflags=backup speed=slow \
2844                         run_tests $ns1 $ns2 1    2844                         run_tests $ns1 $ns2 10.0.1.1
2845                 chk_join_nr 0 0 0                2845                 chk_join_nr 0 0 0
2846                 chk_prio_nr 0 1 0 0              2846                 chk_prio_nr 0 1 0 0
2847         fi                                       2847         fi
2848                                                  2848 
2849         if reset "mpc switch to backup both s    2849         if reset "mpc switch to backup both sides" &&
2850            continue_if mptcp_lib_kallsyms_doe    2850            continue_if mptcp_lib_kallsyms_doesnt_have "T mptcp_subflow_send_ack$"; then
2851                 pm_nl_add_endpoint $ns1 10.0.    2851                 pm_nl_add_endpoint $ns1 10.0.1.1 flags subflow
2852                 pm_nl_add_endpoint $ns2 10.0.    2852                 pm_nl_add_endpoint $ns2 10.0.1.2 flags subflow
2853                 sflags=backup speed=slow \       2853                 sflags=backup speed=slow \
2854                         run_tests $ns1 $ns2 1    2854                         run_tests $ns1 $ns2 10.0.1.1
2855                 chk_join_nr 0 0 0                2855                 chk_join_nr 0 0 0
2856                 chk_prio_nr 1 1 0 0              2856                 chk_prio_nr 1 1 0 0
2857         fi                                       2857         fi
2858 }                                                2858 }
2859                                                  2859 
2860 verify_listener_events()                         2860 verify_listener_events()
2861 {                                                2861 {
2862         local e_type=$2                          2862         local e_type=$2
2863         local e_saddr=$4                         2863         local e_saddr=$4
2864         local e_sport=$5                         2864         local e_sport=$5
2865         local name                               2865         local name
2866                                                  2866 
2867         if [ $e_type = $MPTCP_LIB_EVENT_LISTE    2867         if [ $e_type = $MPTCP_LIB_EVENT_LISTENER_CREATED ]; then
2868                 name="LISTENER_CREATED"          2868                 name="LISTENER_CREATED"
2869         elif [ $e_type = $MPTCP_LIB_EVENT_LIS    2869         elif [ $e_type = $MPTCP_LIB_EVENT_LISTENER_CLOSED ]; then
2870                 name="LISTENER_CLOSED "          2870                 name="LISTENER_CLOSED "
2871         else                                     2871         else
2872                 name="$e_type"                   2872                 name="$e_type"
2873         fi                                       2873         fi
2874                                                  2874 
2875         print_check "$name $e_saddr:$e_sport"    2875         print_check "$name $e_saddr:$e_sport"
2876                                                  2876 
2877         if ! mptcp_lib_kallsyms_has "mptcp_ev    2877         if ! mptcp_lib_kallsyms_has "mptcp_event_pm_listener$"; then
2878                 print_skip "event not support    2878                 print_skip "event not supported"
2879                 return                           2879                 return
2880         fi                                       2880         fi
2881                                                  2881 
2882         if mptcp_lib_verify_listener_events "    2882         if mptcp_lib_verify_listener_events "${@}"; then
2883                 print_ok                         2883                 print_ok
2884                 return 0                         2884                 return 0
2885         fi                                       2885         fi
2886         fail_test                                2886         fail_test
2887 }                                                2887 }
2888                                                  2888 
2889 chk_mpc_endp_attempt()                           2889 chk_mpc_endp_attempt()
2890 {                                                2890 {
2891         local retl=$1                            2891         local retl=$1
2892         local attempts=$2                        2892         local attempts=$2
2893                                                  2893 
2894         print_check "Connect"                    2894         print_check "Connect"
2895                                                  2895 
2896         if [ ${retl} = 124 ]; then               2896         if [ ${retl} = 124 ]; then
2897                 fail_test "timeout on connect    2897                 fail_test "timeout on connect"
2898         elif [ ${retl} = 0 ]; then               2898         elif [ ${retl} = 0 ]; then
2899                 fail_test "unexpected success    2899                 fail_test "unexpected successful connect"
2900         else                                     2900         else
2901                 print_ok                         2901                 print_ok
2902                                                  2902 
2903                 print_check "Attempts"           2903                 print_check "Attempts"
2904                 count=$(mptcp_lib_get_counter    2904                 count=$(mptcp_lib_get_counter ${ns1} "MPTcpExtMPCapableEndpAttempt")
2905                 if [ -z "$count" ]; then         2905                 if [ -z "$count" ]; then
2906                         print_skip               2906                         print_skip
2907                 elif [ "$count" != "$attempts    2907                 elif [ "$count" != "$attempts" ]; then
2908                         fail_test "got ${coun    2908                         fail_test "got ${count} MPC attempt[s] on port-based endpoint, expected ${attempts}"
2909                 else                             2909                 else
2910                         print_ok                 2910                         print_ok
2911                 fi                               2911                 fi
2912         fi                                       2912         fi
2913 }                                                2913 }
2914                                                  2914 
2915 add_addr_ports_tests()                           2915 add_addr_ports_tests()
2916 {                                                2916 {
2917         # signal address with port               2917         # signal address with port
2918         if reset "signal address with port";     2918         if reset "signal address with port"; then
2919                 pm_nl_set_limits $ns1 0 1        2919                 pm_nl_set_limits $ns1 0 1
2920                 pm_nl_set_limits $ns2 1 1        2920                 pm_nl_set_limits $ns2 1 1
2921                 pm_nl_add_endpoint $ns1 10.0.    2921                 pm_nl_add_endpoint $ns1 10.0.2.1 flags signal port 10100
2922                 run_tests $ns1 $ns2 10.0.1.1     2922                 run_tests $ns1 $ns2 10.0.1.1
2923                 chk_join_nr 1 1 1                2923                 chk_join_nr 1 1 1
2924                 chk_add_nr 1 1 1                 2924                 chk_add_nr 1 1 1
2925         fi                                       2925         fi
2926                                                  2926 
2927         # subflow and signal with port           2927         # subflow and signal with port
2928         if reset "subflow and signal with por    2928         if reset "subflow and signal with port"; then
2929                 pm_nl_add_endpoint $ns1 10.0.    2929                 pm_nl_add_endpoint $ns1 10.0.2.1 flags signal port 10100
2930                 pm_nl_set_limits $ns1 0 2        2930                 pm_nl_set_limits $ns1 0 2
2931                 pm_nl_set_limits $ns2 1 2        2931                 pm_nl_set_limits $ns2 1 2
2932                 pm_nl_add_endpoint $ns2 10.0.    2932                 pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow
2933                 run_tests $ns1 $ns2 10.0.1.1     2933                 run_tests $ns1 $ns2 10.0.1.1
2934                 chk_join_nr 2 2 2                2934                 chk_join_nr 2 2 2
2935                 chk_add_nr 1 1 1                 2935                 chk_add_nr 1 1 1
2936         fi                                       2936         fi
2937                                                  2937 
2938         # single address with port, remove       2938         # single address with port, remove
2939         # pm listener events                     2939         # pm listener events
2940         if reset_with_events "remove single a    2940         if reset_with_events "remove single address with port"; then
2941                 pm_nl_set_limits $ns1 0 1        2941                 pm_nl_set_limits $ns1 0 1
2942                 pm_nl_add_endpoint $ns1 10.0.    2942                 pm_nl_add_endpoint $ns1 10.0.2.1 flags signal port 10100
2943                 pm_nl_set_limits $ns2 1 1        2943                 pm_nl_set_limits $ns2 1 1
2944                 addr_nr_ns1=-1 speed=slow \      2944                 addr_nr_ns1=-1 speed=slow \
2945                         run_tests $ns1 $ns2 1    2945                         run_tests $ns1 $ns2 10.0.1.1
2946                 chk_join_nr 1 1 1                2946                 chk_join_nr 1 1 1
2947                 chk_add_nr 1 1 1                 2947                 chk_add_nr 1 1 1
2948                 chk_rm_nr 1 1 invert             2948                 chk_rm_nr 1 1 invert
2949                                                  2949 
2950                 verify_listener_events $evts_    2950                 verify_listener_events $evts_ns1 $MPTCP_LIB_EVENT_LISTENER_CREATED \
2951                                        $MPTCP    2951                                        $MPTCP_LIB_AF_INET 10.0.2.1 10100
2952                 verify_listener_events $evts_    2952                 verify_listener_events $evts_ns1 $MPTCP_LIB_EVENT_LISTENER_CLOSED \
2953                                        $MPTCP    2953                                        $MPTCP_LIB_AF_INET 10.0.2.1 10100
2954                 kill_events_pids                 2954                 kill_events_pids
2955         fi                                       2955         fi
2956                                                  2956 
2957         # subflow and signal with port, remov    2957         # subflow and signal with port, remove
2958         if reset "remove subflow and signal w    2958         if reset "remove subflow and signal with port"; then
2959                 pm_nl_set_limits $ns1 0 2        2959                 pm_nl_set_limits $ns1 0 2
2960                 pm_nl_add_endpoint $ns1 10.0.    2960                 pm_nl_add_endpoint $ns1 10.0.2.1 flags signal port 10100
2961                 pm_nl_set_limits $ns2 1 2        2961                 pm_nl_set_limits $ns2 1 2
2962                 pm_nl_add_endpoint $ns2 10.0.    2962                 pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow
2963                 addr_nr_ns1=-1 addr_nr_ns2=-1    2963                 addr_nr_ns1=-1 addr_nr_ns2=-1 speed=slow \
2964                         run_tests $ns1 $ns2 1    2964                         run_tests $ns1 $ns2 10.0.1.1
2965                 chk_join_nr 2 2 2                2965                 chk_join_nr 2 2 2
2966                 chk_add_nr 1 1 1                 2966                 chk_add_nr 1 1 1
2967                 chk_rm_nr 1 1                    2967                 chk_rm_nr 1 1
2968         fi                                       2968         fi
2969                                                  2969 
2970         # subflows and signal with port, flus    2970         # subflows and signal with port, flush
2971         if reset "flush subflows and signal w    2971         if reset "flush subflows and signal with port"; then
2972                 pm_nl_set_limits $ns1 0 3        2972                 pm_nl_set_limits $ns1 0 3
2973                 pm_nl_add_endpoint $ns1 10.0.    2973                 pm_nl_add_endpoint $ns1 10.0.2.1 flags signal port 10100
2974                 pm_nl_set_limits $ns2 1 3        2974                 pm_nl_set_limits $ns2 1 3
2975                 pm_nl_add_endpoint $ns2 10.0.    2975                 pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow
2976                 pm_nl_add_endpoint $ns2 10.0.    2976                 pm_nl_add_endpoint $ns2 10.0.4.2 flags subflow
2977                 addr_nr_ns1=-8 addr_nr_ns2=-2    2977                 addr_nr_ns1=-8 addr_nr_ns2=-2 speed=slow \
2978                         run_tests $ns1 $ns2 1    2978                         run_tests $ns1 $ns2 10.0.1.1
2979                 chk_join_nr 3 3 3                2979                 chk_join_nr 3 3 3
2980                 chk_add_nr 1 1                   2980                 chk_add_nr 1 1
2981                 chk_rm_nr 1 3 invert simult      2981                 chk_rm_nr 1 3 invert simult
2982         fi                                       2982         fi
2983                                                  2983 
2984         # multiple addresses with port           2984         # multiple addresses with port
2985         if reset "multiple addresses with por    2985         if reset "multiple addresses with port"; then
2986                 pm_nl_set_limits $ns1 2 2        2986                 pm_nl_set_limits $ns1 2 2
2987                 pm_nl_add_endpoint $ns1 10.0.    2987                 pm_nl_add_endpoint $ns1 10.0.2.1 flags signal port 10100
2988                 pm_nl_add_endpoint $ns1 10.0.    2988                 pm_nl_add_endpoint $ns1 10.0.3.1 flags signal port 10100
2989                 pm_nl_set_limits $ns2 2 2        2989                 pm_nl_set_limits $ns2 2 2
2990                 run_tests $ns1 $ns2 10.0.1.1     2990                 run_tests $ns1 $ns2 10.0.1.1
2991                 chk_join_nr 2 2 2                2991                 chk_join_nr 2 2 2
2992                 chk_add_nr 2 2 2                 2992                 chk_add_nr 2 2 2
2993         fi                                       2993         fi
2994                                                  2994 
2995         # multiple addresses with ports          2995         # multiple addresses with ports
2996         if reset "multiple addresses with por    2996         if reset "multiple addresses with ports"; then
2997                 pm_nl_set_limits $ns1 2 2        2997                 pm_nl_set_limits $ns1 2 2
2998                 pm_nl_add_endpoint $ns1 10.0.    2998                 pm_nl_add_endpoint $ns1 10.0.2.1 flags signal port 10100
2999                 pm_nl_add_endpoint $ns1 10.0.    2999                 pm_nl_add_endpoint $ns1 10.0.3.1 flags signal port 10101
3000                 pm_nl_set_limits $ns2 2 2        3000                 pm_nl_set_limits $ns2 2 2
3001                 run_tests $ns1 $ns2 10.0.1.1     3001                 run_tests $ns1 $ns2 10.0.1.1
3002                 chk_join_nr 2 2 2                3002                 chk_join_nr 2 2 2
3003                 chk_add_nr 2 2 2                 3003                 chk_add_nr 2 2 2
3004         fi                                       3004         fi
3005                                                  3005 
3006         if reset "port-based signal endpoint     3006         if reset "port-based signal endpoint must not accept mpc"; then
3007                 local port retl count            3007                 local port retl count
3008                 port=$(get_port)                 3008                 port=$(get_port)
3009                                                  3009 
3010                 cond_start_capture ${ns1}        3010                 cond_start_capture ${ns1}
3011                 pm_nl_add_endpoint ${ns1} 10.    3011                 pm_nl_add_endpoint ${ns1} 10.0.2.1 flags signal port ${port}
3012                 mptcp_lib_wait_local_port_lis    3012                 mptcp_lib_wait_local_port_listen ${ns1} ${port}
3013                                                  3013 
3014                 timeout 1 ip netns exec ${ns2    3014                 timeout 1 ip netns exec ${ns2} \
3015                         ./mptcp_connect -t ${    3015                         ./mptcp_connect -t ${timeout_poll} -p $port -s MPTCP 10.0.2.1 >/dev/null 2>&1
3016                 retl=$?                          3016                 retl=$?
3017                 cond_stop_capture                3017                 cond_stop_capture
3018                                                  3018 
3019                 chk_mpc_endp_attempt ${retl}     3019                 chk_mpc_endp_attempt ${retl} 1
3020         fi                                       3020         fi
3021 }                                                3021 }
3022                                                  3022 
3023 syncookies_tests()                               3023 syncookies_tests()
3024 {                                                3024 {
3025         # single subflow, syncookies             3025         # single subflow, syncookies
3026         if reset_with_cookies "single subflow    3026         if reset_with_cookies "single subflow with syn cookies"; then
3027                 pm_nl_set_limits $ns1 0 1        3027                 pm_nl_set_limits $ns1 0 1
3028                 pm_nl_set_limits $ns2 0 1        3028                 pm_nl_set_limits $ns2 0 1
3029                 pm_nl_add_endpoint $ns2 10.0.    3029                 pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow
3030                 run_tests $ns1 $ns2 10.0.1.1     3030                 run_tests $ns1 $ns2 10.0.1.1
3031                 chk_join_nr 1 1 1                3031                 chk_join_nr 1 1 1
3032         fi                                       3032         fi
3033                                                  3033 
3034         # multiple subflows with syn cookies     3034         # multiple subflows with syn cookies
3035         if reset_with_cookies "multiple subfl    3035         if reset_with_cookies "multiple subflows with syn cookies"; then
3036                 pm_nl_set_limits $ns1 0 2        3036                 pm_nl_set_limits $ns1 0 2
3037                 pm_nl_set_limits $ns2 0 2        3037                 pm_nl_set_limits $ns2 0 2
3038                 pm_nl_add_endpoint $ns2 10.0.    3038                 pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow
3039                 pm_nl_add_endpoint $ns2 10.0.    3039                 pm_nl_add_endpoint $ns2 10.0.2.2 flags subflow
3040                 run_tests $ns1 $ns2 10.0.1.1     3040                 run_tests $ns1 $ns2 10.0.1.1
3041                 chk_join_nr 2 2 2                3041                 chk_join_nr 2 2 2
3042         fi                                       3042         fi
3043                                                  3043 
3044         # multiple subflows limited by server    3044         # multiple subflows limited by server
3045         if reset_with_cookies "subflows limit    3045         if reset_with_cookies "subflows limited by server w cookies"; then
3046                 pm_nl_set_limits $ns1 0 1        3046                 pm_nl_set_limits $ns1 0 1
3047                 pm_nl_set_limits $ns2 0 2        3047                 pm_nl_set_limits $ns2 0 2
3048                 pm_nl_add_endpoint $ns2 10.0.    3048                 pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow
3049                 pm_nl_add_endpoint $ns2 10.0.    3049                 pm_nl_add_endpoint $ns2 10.0.2.2 flags subflow
3050                 run_tests $ns1 $ns2 10.0.1.1     3050                 run_tests $ns1 $ns2 10.0.1.1
3051                 chk_join_nr 2 1 1                3051                 chk_join_nr 2 1 1
3052         fi                                       3052         fi
3053                                                  3053 
3054         # test signal address with cookies       3054         # test signal address with cookies
3055         if reset_with_cookies "signal address    3055         if reset_with_cookies "signal address with syn cookies"; then
3056                 pm_nl_set_limits $ns1 0 1        3056                 pm_nl_set_limits $ns1 0 1
3057                 pm_nl_set_limits $ns2 1 1        3057                 pm_nl_set_limits $ns2 1 1
3058                 pm_nl_add_endpoint $ns1 10.0.    3058                 pm_nl_add_endpoint $ns1 10.0.2.1 flags signal
3059                 run_tests $ns1 $ns2 10.0.1.1     3059                 run_tests $ns1 $ns2 10.0.1.1
3060                 chk_join_nr 1 1 1                3060                 chk_join_nr 1 1 1
3061                 chk_add_nr 1 1                   3061                 chk_add_nr 1 1
3062         fi                                       3062         fi
3063                                                  3063 
3064         # test cookie with subflow and signal    3064         # test cookie with subflow and signal
3065         if reset_with_cookies "subflow and si    3065         if reset_with_cookies "subflow and signal w cookies"; then
3066                 pm_nl_add_endpoint $ns1 10.0.    3066                 pm_nl_add_endpoint $ns1 10.0.2.1 flags signal
3067                 pm_nl_set_limits $ns1 0 2        3067                 pm_nl_set_limits $ns1 0 2
3068                 pm_nl_set_limits $ns2 1 2        3068                 pm_nl_set_limits $ns2 1 2
3069                 pm_nl_add_endpoint $ns2 10.0.    3069                 pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow
3070                 run_tests $ns1 $ns2 10.0.1.1     3070                 run_tests $ns1 $ns2 10.0.1.1
3071                 chk_join_nr 2 2 2                3071                 chk_join_nr 2 2 2
3072                 chk_add_nr 1 1                   3072                 chk_add_nr 1 1
3073         fi                                       3073         fi
3074                                                  3074 
3075         # accept and use add_addr with additi    3075         # accept and use add_addr with additional subflows
3076         if reset_with_cookies "subflows and s    3076         if reset_with_cookies "subflows and signal w. cookies"; then
3077                 pm_nl_set_limits $ns1 0 3        3077                 pm_nl_set_limits $ns1 0 3
3078                 pm_nl_add_endpoint $ns1 10.0.    3078                 pm_nl_add_endpoint $ns1 10.0.2.1 flags signal
3079                 pm_nl_set_limits $ns2 1 3        3079                 pm_nl_set_limits $ns2 1 3
3080                 pm_nl_add_endpoint $ns2 10.0.    3080                 pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow
3081                 pm_nl_add_endpoint $ns2 10.0.    3081                 pm_nl_add_endpoint $ns2 10.0.4.2 flags subflow
3082                 run_tests $ns1 $ns2 10.0.1.1     3082                 run_tests $ns1 $ns2 10.0.1.1
3083                 chk_join_nr 3 3 3                3083                 chk_join_nr 3 3 3
3084                 chk_add_nr 1 1                   3084                 chk_add_nr 1 1
3085         fi                                       3085         fi
3086 }                                                3086 }
3087                                                  3087 
3088 checksum_tests()                                 3088 checksum_tests()
3089 {                                                3089 {
3090         local checksum_enable                    3090         local checksum_enable
3091         for checksum_enable in "0 0" "1 1" "0    3091         for checksum_enable in "0 0" "1 1" "0 1" "1 0"; do
3092                 # checksum test 0 0, 1 1, 0 1    3092                 # checksum test 0 0, 1 1, 0 1, 1 0
3093                 if reset_with_checksum ${chec    3093                 if reset_with_checksum ${checksum_enable}; then
3094                         pm_nl_set_limits $ns1    3094                         pm_nl_set_limits $ns1 0 1
3095                         pm_nl_set_limits $ns2    3095                         pm_nl_set_limits $ns2 0 1
3096                         run_tests $ns1 $ns2 1    3096                         run_tests $ns1 $ns2 10.0.1.1
3097                         chk_join_nr 0 0 0        3097                         chk_join_nr 0 0 0
3098                 fi                               3098                 fi
3099         done                                     3099         done
3100 }                                                3100 }
3101                                                  3101 
3102 deny_join_id0_tests()                            3102 deny_join_id0_tests()
3103 {                                                3103 {
3104         # subflow allow join id0 ns1             3104         # subflow allow join id0 ns1
3105         if reset_with_allow_join_id0 "single     3105         if reset_with_allow_join_id0 "single subflow allow join id0 ns1" 1 0; then
3106                 pm_nl_set_limits $ns1 1 1        3106                 pm_nl_set_limits $ns1 1 1
3107                 pm_nl_set_limits $ns2 1 1        3107                 pm_nl_set_limits $ns2 1 1
3108                 pm_nl_add_endpoint $ns2 10.0.    3108                 pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow
3109                 run_tests $ns1 $ns2 10.0.1.1     3109                 run_tests $ns1 $ns2 10.0.1.1
3110                 chk_join_nr 1 1 1                3110                 chk_join_nr 1 1 1
3111         fi                                       3111         fi
3112                                                  3112 
3113         # subflow allow join id0 ns2             3113         # subflow allow join id0 ns2
3114         if reset_with_allow_join_id0 "single     3114         if reset_with_allow_join_id0 "single subflow allow join id0 ns2" 0 1; then
3115                 pm_nl_set_limits $ns1 1 1        3115                 pm_nl_set_limits $ns1 1 1
3116                 pm_nl_set_limits $ns2 1 1        3116                 pm_nl_set_limits $ns2 1 1
3117                 pm_nl_add_endpoint $ns2 10.0.    3117                 pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow
3118                 run_tests $ns1 $ns2 10.0.1.1     3118                 run_tests $ns1 $ns2 10.0.1.1
3119                 chk_join_nr 0 0 0                3119                 chk_join_nr 0 0 0
3120         fi                                       3120         fi
3121                                                  3121 
3122         # signal address allow join id0 ns1      3122         # signal address allow join id0 ns1
3123         # ADD_ADDRs are not affected by allow    3123         # ADD_ADDRs are not affected by allow_join_id0 value.
3124         if reset_with_allow_join_id0 "signal     3124         if reset_with_allow_join_id0 "signal address allow join id0 ns1" 1 0; then
3125                 pm_nl_set_limits $ns1 1 1        3125                 pm_nl_set_limits $ns1 1 1
3126                 pm_nl_set_limits $ns2 1 1        3126                 pm_nl_set_limits $ns2 1 1
3127                 pm_nl_add_endpoint $ns1 10.0.    3127                 pm_nl_add_endpoint $ns1 10.0.2.1 flags signal
3128                 run_tests $ns1 $ns2 10.0.1.1     3128                 run_tests $ns1 $ns2 10.0.1.1
3129                 chk_join_nr 1 1 1                3129                 chk_join_nr 1 1 1
3130                 chk_add_nr 1 1                   3130                 chk_add_nr 1 1
3131         fi                                       3131         fi
3132                                                  3132 
3133         # signal address allow join id0 ns2      3133         # signal address allow join id0 ns2
3134         # ADD_ADDRs are not affected by allow    3134         # ADD_ADDRs are not affected by allow_join_id0 value.
3135         if reset_with_allow_join_id0 "signal     3135         if reset_with_allow_join_id0 "signal address allow join id0 ns2" 0 1; then
3136                 pm_nl_set_limits $ns1 1 1        3136                 pm_nl_set_limits $ns1 1 1
3137                 pm_nl_set_limits $ns2 1 1        3137                 pm_nl_set_limits $ns2 1 1
3138                 pm_nl_add_endpoint $ns1 10.0.    3138                 pm_nl_add_endpoint $ns1 10.0.2.1 flags signal
3139                 run_tests $ns1 $ns2 10.0.1.1     3139                 run_tests $ns1 $ns2 10.0.1.1
3140                 chk_join_nr 1 1 1                3140                 chk_join_nr 1 1 1
3141                 chk_add_nr 1 1                   3141                 chk_add_nr 1 1
3142         fi                                       3142         fi
3143                                                  3143 
3144         # subflow and address allow join id0     3144         # subflow and address allow join id0 ns1
3145         if reset_with_allow_join_id0 "subflow    3145         if reset_with_allow_join_id0 "subflow and address allow join id0 1" 1 0; then
3146                 pm_nl_set_limits $ns1 2 2        3146                 pm_nl_set_limits $ns1 2 2
3147                 pm_nl_set_limits $ns2 2 2        3147                 pm_nl_set_limits $ns2 2 2
3148                 pm_nl_add_endpoint $ns1 10.0.    3148                 pm_nl_add_endpoint $ns1 10.0.2.1 flags signal
3149                 pm_nl_add_endpoint $ns2 10.0.    3149                 pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow
3150                 run_tests $ns1 $ns2 10.0.1.1     3150                 run_tests $ns1 $ns2 10.0.1.1
3151                 chk_join_nr 2 2 2                3151                 chk_join_nr 2 2 2
3152         fi                                       3152         fi
3153                                                  3153 
3154         # subflow and address allow join id0     3154         # subflow and address allow join id0 ns2
3155         if reset_with_allow_join_id0 "subflow    3155         if reset_with_allow_join_id0 "subflow and address allow join id0 2" 0 1; then
3156                 pm_nl_set_limits $ns1 2 2        3156                 pm_nl_set_limits $ns1 2 2
3157                 pm_nl_set_limits $ns2 2 2        3157                 pm_nl_set_limits $ns2 2 2
3158                 pm_nl_add_endpoint $ns1 10.0.    3158                 pm_nl_add_endpoint $ns1 10.0.2.1 flags signal
3159                 pm_nl_add_endpoint $ns2 10.0.    3159                 pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow
3160                 run_tests $ns1 $ns2 10.0.1.1     3160                 run_tests $ns1 $ns2 10.0.1.1
3161                 chk_join_nr 1 1 1                3161                 chk_join_nr 1 1 1
3162         fi                                       3162         fi
3163 }                                                3163 }
3164                                                  3164 
3165 fullmesh_tests()                                 3165 fullmesh_tests()
3166 {                                                3166 {
3167         # fullmesh 1                             3167         # fullmesh 1
3168         # 2 fullmesh addrs in ns2, added befo    3168         # 2 fullmesh addrs in ns2, added before the connection,
3169         # 1 non-fullmesh addr in ns1, added d    3169         # 1 non-fullmesh addr in ns1, added during the connection.
3170         if reset "fullmesh test 2x1"; then       3170         if reset "fullmesh test 2x1"; then
3171                 pm_nl_set_limits $ns1 0 4        3171                 pm_nl_set_limits $ns1 0 4
3172                 pm_nl_set_limits $ns2 1 4        3172                 pm_nl_set_limits $ns2 1 4
3173                 pm_nl_add_endpoint $ns2 10.0.    3173                 pm_nl_add_endpoint $ns2 10.0.2.2 flags subflow,fullmesh
3174                 pm_nl_add_endpoint $ns2 10.0.    3174                 pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow,fullmesh
3175                 addr_nr_ns1=1 speed=slow \       3175                 addr_nr_ns1=1 speed=slow \
3176                         run_tests $ns1 $ns2 1    3176                         run_tests $ns1 $ns2 10.0.1.1
3177                 chk_join_nr 4 4 4                3177                 chk_join_nr 4 4 4
3178                 chk_add_nr 1 1                   3178                 chk_add_nr 1 1
3179         fi                                       3179         fi
3180                                                  3180 
3181         # fullmesh 2                             3181         # fullmesh 2
3182         # 1 non-fullmesh addr in ns1, added b    3182         # 1 non-fullmesh addr in ns1, added before the connection,
3183         # 1 fullmesh addr in ns2, added durin    3183         # 1 fullmesh addr in ns2, added during the connection.
3184         if reset "fullmesh test 1x1"; then       3184         if reset "fullmesh test 1x1"; then
3185                 pm_nl_set_limits $ns1 1 3        3185                 pm_nl_set_limits $ns1 1 3
3186                 pm_nl_set_limits $ns2 1 3        3186                 pm_nl_set_limits $ns2 1 3
3187                 pm_nl_add_endpoint $ns1 10.0.    3187                 pm_nl_add_endpoint $ns1 10.0.2.1 flags signal
3188                 if mptcp_lib_kallsyms_has "mp    3188                 if mptcp_lib_kallsyms_has "mptcp_pm_subflow_check_next$"; then
3189                         pm_nl_add_endpoint $n    3189                         pm_nl_add_endpoint $ns2 10.0.1.2 flags subflow,fullmesh
3190                 fi                               3190                 fi
3191                 fullmesh=1 speed=slow \          3191                 fullmesh=1 speed=slow \
3192                         run_tests $ns1 $ns2 1    3192                         run_tests $ns1 $ns2 10.0.1.1
3193                 chk_join_nr 3 3 3                3193                 chk_join_nr 3 3 3
3194                 chk_add_nr 1 1                   3194                 chk_add_nr 1 1
3195         fi                                       3195         fi
3196                                                  3196 
3197         # fullmesh 3                             3197         # fullmesh 3
3198         # 1 non-fullmesh addr in ns1, added b    3198         # 1 non-fullmesh addr in ns1, added before the connection,
3199         # 2 fullmesh addrs in ns2, added duri    3199         # 2 fullmesh addrs in ns2, added during the connection.
3200         if reset "fullmesh test 1x2"; then       3200         if reset "fullmesh test 1x2"; then
3201                 pm_nl_set_limits $ns1 2 5        3201                 pm_nl_set_limits $ns1 2 5
3202                 pm_nl_set_limits $ns2 1 5        3202                 pm_nl_set_limits $ns2 1 5
3203                 pm_nl_add_endpoint $ns1 10.0.    3203                 pm_nl_add_endpoint $ns1 10.0.2.1 flags signal
3204                 fullmesh=2 speed=slow \          3204                 fullmesh=2 speed=slow \
3205                         run_tests $ns1 $ns2 1    3205                         run_tests $ns1 $ns2 10.0.1.1
3206                 chk_join_nr 5 5 5                3206                 chk_join_nr 5 5 5
3207                 chk_add_nr 1 1                   3207                 chk_add_nr 1 1
3208         fi                                       3208         fi
3209                                                  3209 
3210         # fullmesh 4                             3210         # fullmesh 4
3211         # 1 non-fullmesh addr in ns1, added b    3211         # 1 non-fullmesh addr in ns1, added before the connection,
3212         # 2 fullmesh addrs in ns2, added duri    3212         # 2 fullmesh addrs in ns2, added during the connection,
3213         # limit max_subflows to 4.               3213         # limit max_subflows to 4.
3214         if reset "fullmesh test 1x2, limited"    3214         if reset "fullmesh test 1x2, limited"; then
3215                 pm_nl_set_limits $ns1 2 4        3215                 pm_nl_set_limits $ns1 2 4
3216                 pm_nl_set_limits $ns2 1 4        3216                 pm_nl_set_limits $ns2 1 4
3217                 pm_nl_add_endpoint $ns1 10.0.    3217                 pm_nl_add_endpoint $ns1 10.0.2.1 flags signal
3218                 fullmesh=2 speed=slow \          3218                 fullmesh=2 speed=slow \
3219                         run_tests $ns1 $ns2 1    3219                         run_tests $ns1 $ns2 10.0.1.1
3220                 chk_join_nr 4 4 4                3220                 chk_join_nr 4 4 4
3221                 chk_add_nr 1 1                   3221                 chk_add_nr 1 1
3222         fi                                       3222         fi
3223                                                  3223 
3224         # set fullmesh flag                      3224         # set fullmesh flag
3225         if reset "set fullmesh flag test" &&     3225         if reset "set fullmesh flag test" &&
3226            continue_if mptcp_lib_kversion_ge     3226            continue_if mptcp_lib_kversion_ge 5.18; then
3227                 pm_nl_set_limits $ns1 4 4        3227                 pm_nl_set_limits $ns1 4 4
3228                 pm_nl_add_endpoint $ns1 10.0.    3228                 pm_nl_add_endpoint $ns1 10.0.2.1 flags subflow
3229                 pm_nl_set_limits $ns2 4 4        3229                 pm_nl_set_limits $ns2 4 4
3230                 addr_nr_ns2=1 sflags=fullmesh    3230                 addr_nr_ns2=1 sflags=fullmesh speed=slow \
3231                         run_tests $ns1 $ns2 1    3231                         run_tests $ns1 $ns2 10.0.1.1
3232                 chk_join_nr 2 2 2                3232                 chk_join_nr 2 2 2
3233                 chk_rm_nr 0 1                    3233                 chk_rm_nr 0 1
3234         fi                                       3234         fi
3235                                                  3235 
3236         # set nofullmesh flag                    3236         # set nofullmesh flag
3237         if reset "set nofullmesh flag test" &    3237         if reset "set nofullmesh flag test" &&
3238            continue_if mptcp_lib_kversion_ge     3238            continue_if mptcp_lib_kversion_ge 5.18; then
3239                 pm_nl_set_limits $ns1 4 4        3239                 pm_nl_set_limits $ns1 4 4
3240                 pm_nl_add_endpoint $ns1 10.0.    3240                 pm_nl_add_endpoint $ns1 10.0.2.1 flags subflow,fullmesh
3241                 pm_nl_set_limits $ns2 4 4        3241                 pm_nl_set_limits $ns2 4 4
3242                 fullmesh=1 sflags=nofullmesh     3242                 fullmesh=1 sflags=nofullmesh speed=slow \
3243                         run_tests $ns1 $ns2 1    3243                         run_tests $ns1 $ns2 10.0.1.1
3244                 chk_join_nr 2 2 2                3244                 chk_join_nr 2 2 2
3245                 chk_rm_nr 0 1                    3245                 chk_rm_nr 0 1
3246         fi                                       3246         fi
3247                                                  3247 
3248         # set backup,fullmesh flags              3248         # set backup,fullmesh flags
3249         if reset "set backup,fullmesh flags t    3249         if reset "set backup,fullmesh flags test" &&
3250            continue_if mptcp_lib_kversion_ge     3250            continue_if mptcp_lib_kversion_ge 5.18; then
3251                 pm_nl_set_limits $ns1 4 4        3251                 pm_nl_set_limits $ns1 4 4
3252                 pm_nl_add_endpoint $ns1 10.0.    3252                 pm_nl_add_endpoint $ns1 10.0.2.1 flags subflow
3253                 pm_nl_set_limits $ns2 4 4        3253                 pm_nl_set_limits $ns2 4 4
3254                 addr_nr_ns2=1 sflags=backup,f    3254                 addr_nr_ns2=1 sflags=backup,fullmesh speed=slow \
3255                         run_tests $ns1 $ns2 1    3255                         run_tests $ns1 $ns2 10.0.1.1
3256                 chk_join_nr 2 2 2                3256                 chk_join_nr 2 2 2
3257                 chk_prio_nr 0 1 1 0              3257                 chk_prio_nr 0 1 1 0
3258                 chk_rm_nr 0 1                    3258                 chk_rm_nr 0 1
3259         fi                                       3259         fi
3260                                                  3260 
3261         # set nobackup,nofullmesh flags          3261         # set nobackup,nofullmesh flags
3262         if reset "set nobackup,nofullmesh fla    3262         if reset "set nobackup,nofullmesh flags test" &&
3263            continue_if mptcp_lib_kversion_ge     3263            continue_if mptcp_lib_kversion_ge 5.18; then
3264                 pm_nl_set_limits $ns1 4 4        3264                 pm_nl_set_limits $ns1 4 4
3265                 pm_nl_set_limits $ns2 4 4        3265                 pm_nl_set_limits $ns2 4 4
3266                 pm_nl_add_endpoint $ns2 10.0.    3266                 pm_nl_add_endpoint $ns2 10.0.2.2 flags subflow,backup,fullmesh
3267                 sflags=nobackup,nofullmesh sp    3267                 sflags=nobackup,nofullmesh speed=slow \
3268                         run_tests $ns1 $ns2 1    3268                         run_tests $ns1 $ns2 10.0.1.1
3269                 chk_join_nr 2 2 2                3269                 chk_join_nr 2 2 2
3270                 chk_prio_nr 0 1 1 0              3270                 chk_prio_nr 0 1 1 0
3271                 chk_rm_nr 0 1                    3271                 chk_rm_nr 0 1
3272         fi                                       3272         fi
3273 }                                                3273 }
3274                                                  3274 
3275 fastclose_tests()                                3275 fastclose_tests()
3276 {                                                3276 {
3277         if reset_check_counter "fastclose tes    3277         if reset_check_counter "fastclose test" "MPTcpExtMPFastcloseTx"; then
3278                 MPTCP_LIB_SUBTEST_FLAKY=1        3278                 MPTCP_LIB_SUBTEST_FLAKY=1
3279                 test_linkfail=1024 fastclose=    3279                 test_linkfail=1024 fastclose=client \
3280                         run_tests $ns1 $ns2 1    3280                         run_tests $ns1 $ns2 10.0.1.1
3281                 chk_join_nr 0 0 0                3281                 chk_join_nr 0 0 0
3282                 chk_fclose_nr 1 1                3282                 chk_fclose_nr 1 1
3283                 chk_rst_nr 1 1 invert            3283                 chk_rst_nr 1 1 invert
3284         fi                                       3284         fi
3285                                                  3285 
3286         if reset_check_counter "fastclose ser    3286         if reset_check_counter "fastclose server test" "MPTcpExtMPFastcloseRx"; then
3287                 MPTCP_LIB_SUBTEST_FLAKY=1        3287                 MPTCP_LIB_SUBTEST_FLAKY=1
3288                 test_linkfail=1024 fastclose=    3288                 test_linkfail=1024 fastclose=server \
3289                         run_tests $ns1 $ns2 1    3289                         run_tests $ns1 $ns2 10.0.1.1
3290                 join_rst_nr=1 \                  3290                 join_rst_nr=1 \
3291                         chk_join_nr 0 0 0        3291                         chk_join_nr 0 0 0
3292                 chk_fclose_nr 1 1 invert         3292                 chk_fclose_nr 1 1 invert
3293                 chk_rst_nr 1 1                   3293                 chk_rst_nr 1 1
3294         fi                                       3294         fi
3295 }                                                3295 }
3296                                                  3296 
3297 pedit_action_pkts()                              3297 pedit_action_pkts()
3298 {                                                3298 {
3299         tc -n $ns2 -j -s action show action p    3299         tc -n $ns2 -j -s action show action pedit index 100 | \
3300                 mptcp_lib_get_info_value \"pa    3300                 mptcp_lib_get_info_value \"packets\" packets
3301 }                                                3301 }
3302                                                  3302 
3303 fail_tests()                                     3303 fail_tests()
3304 {                                                3304 {
3305         # single subflow                         3305         # single subflow
3306         if reset_with_fail "Infinite map" 1;     3306         if reset_with_fail "Infinite map" 1; then
3307                 MPTCP_LIB_SUBTEST_FLAKY=1        3307                 MPTCP_LIB_SUBTEST_FLAKY=1
3308                 test_linkfail=128 \              3308                 test_linkfail=128 \
3309                         run_tests $ns1 $ns2 1    3309                         run_tests $ns1 $ns2 10.0.1.1
3310                 join_csum_ns1=+1 join_csum_ns    3310                 join_csum_ns1=+1 join_csum_ns2=+0 \
3311                         join_fail_nr=1 join_r    3311                         join_fail_nr=1 join_rst_nr=0 join_infi_nr=1 \
3312                         join_corrupted_pkts="    3312                         join_corrupted_pkts="$(pedit_action_pkts)" \
3313                         chk_join_nr 0 0 0        3313                         chk_join_nr 0 0 0
3314                 chk_fail_nr 1 -1 invert          3314                 chk_fail_nr 1 -1 invert
3315         fi                                       3315         fi
3316                                                  3316 
3317         # multiple subflows                      3317         # multiple subflows
3318         if reset_with_fail "MP_FAIL MP_RST" 2    3318         if reset_with_fail "MP_FAIL MP_RST" 2; then
3319                 MPTCP_LIB_SUBTEST_FLAKY=1        3319                 MPTCP_LIB_SUBTEST_FLAKY=1
3320                 tc -n $ns2 qdisc add dev ns2e    3320                 tc -n $ns2 qdisc add dev ns2eth1 root netem rate 1mbit delay 5ms
3321                 pm_nl_set_limits $ns1 0 1        3321                 pm_nl_set_limits $ns1 0 1
3322                 pm_nl_set_limits $ns2 0 1        3322                 pm_nl_set_limits $ns2 0 1
3323                 pm_nl_add_endpoint $ns2 10.0.    3323                 pm_nl_add_endpoint $ns2 10.0.2.2 dev ns2eth2 flags subflow
3324                 test_linkfail=1024 \             3324                 test_linkfail=1024 \
3325                         run_tests $ns1 $ns2 1    3325                         run_tests $ns1 $ns2 10.0.1.1
3326                 join_csum_ns1=1 join_csum_ns2    3326                 join_csum_ns1=1 join_csum_ns2=0 \
3327                         join_fail_nr=1 join_r    3327                         join_fail_nr=1 join_rst_nr=1 join_infi_nr=0 \
3328                         join_corrupted_pkts="    3328                         join_corrupted_pkts="$(pedit_action_pkts)" \
3329                         chk_join_nr 1 1 1        3329                         chk_join_nr 1 1 1
3330         fi                                       3330         fi
3331 }                                                3331 }
3332                                                  3332 
3333 # $1: ns ; $2: addr ; $3: id                     3333 # $1: ns ; $2: addr ; $3: id
3334 userspace_pm_add_addr()                          3334 userspace_pm_add_addr()
3335 {                                                3335 {
3336         local evts=$evts_ns1                     3336         local evts=$evts_ns1
3337         local tk                                 3337         local tk
3338                                                  3338 
3339         [ "$1" == "$ns2" ] && evts=$evts_ns2     3339         [ "$1" == "$ns2" ] && evts=$evts_ns2
3340         tk=$(mptcp_lib_evts_get_info token "$    3340         tk=$(mptcp_lib_evts_get_info token "$evts")
3341                                                  3341 
3342         ip netns exec $1 ./pm_nl_ctl ann $2 t    3342         ip netns exec $1 ./pm_nl_ctl ann $2 token $tk id $3
3343         sleep 1                                  3343         sleep 1
3344 }                                                3344 }
3345                                                  3345 
3346 # $1: ns ; $2: id                                3346 # $1: ns ; $2: id
3347 userspace_pm_rm_addr()                           3347 userspace_pm_rm_addr()
3348 {                                                3348 {
3349         local evts=$evts_ns1                     3349         local evts=$evts_ns1
3350         local tk                                 3350         local tk
3351         local cnt                                3351         local cnt
3352                                                  3352 
3353         [ "$1" == "$ns2" ] && evts=$evts_ns2     3353         [ "$1" == "$ns2" ] && evts=$evts_ns2
3354         tk=$(mptcp_lib_evts_get_info token "$    3354         tk=$(mptcp_lib_evts_get_info token "$evts")
3355                                                  3355 
3356         cnt=$(rm_addr_count ${1})                3356         cnt=$(rm_addr_count ${1})
3357         ip netns exec $1 ./pm_nl_ctl rem toke    3357         ip netns exec $1 ./pm_nl_ctl rem token $tk id $2
3358         wait_rm_addr $1 "${cnt}"                 3358         wait_rm_addr $1 "${cnt}"
3359 }                                                3359 }
3360                                                  3360 
3361 # $1: ns ; $2: addr ; $3: id                     3361 # $1: ns ; $2: addr ; $3: id
3362 userspace_pm_add_sf()                            3362 userspace_pm_add_sf()
3363 {                                                3363 {
3364         local evts=$evts_ns1                     3364         local evts=$evts_ns1
3365         local tk da dp                           3365         local tk da dp
3366                                                  3366 
3367         [ "$1" == "$ns2" ] && evts=$evts_ns2     3367         [ "$1" == "$ns2" ] && evts=$evts_ns2
3368         tk=$(mptcp_lib_evts_get_info token "$    3368         tk=$(mptcp_lib_evts_get_info token "$evts")
3369         da=$(mptcp_lib_evts_get_info daddr4 "    3369         da=$(mptcp_lib_evts_get_info daddr4 "$evts")
3370         dp=$(mptcp_lib_evts_get_info dport "$    3370         dp=$(mptcp_lib_evts_get_info dport "$evts")
3371                                                  3371 
3372         ip netns exec $1 ./pm_nl_ctl csf lip     3372         ip netns exec $1 ./pm_nl_ctl csf lip $2 lid $3 \
3373                                 rip $da rport    3373                                 rip $da rport $dp token $tk
3374         sleep 1                                  3374         sleep 1
3375 }                                                3375 }
3376                                                  3376 
3377 # $1: ns ; $2: addr $3: event type               3377 # $1: ns ; $2: addr $3: event type
3378 userspace_pm_rm_sf()                             3378 userspace_pm_rm_sf()
3379 {                                                3379 {
3380         local evts=$evts_ns1                     3380         local evts=$evts_ns1
3381         local t=${3:-1}                          3381         local t=${3:-1}
3382         local ip                                 3382         local ip
3383         local tk da dp sp                        3383         local tk da dp sp
3384         local cnt                                3384         local cnt
3385                                                  3385 
3386         [ "$1" == "$ns2" ] && evts=$evts_ns2     3386         [ "$1" == "$ns2" ] && evts=$evts_ns2
3387         [ -n "$(mptcp_lib_evts_get_info "sadd    3387         [ -n "$(mptcp_lib_evts_get_info "saddr4" "$evts" $t)" ] && ip=4
3388         [ -n "$(mptcp_lib_evts_get_info "sadd    3388         [ -n "$(mptcp_lib_evts_get_info "saddr6" "$evts" $t)" ] && ip=6
3389         tk=$(mptcp_lib_evts_get_info token "$    3389         tk=$(mptcp_lib_evts_get_info token "$evts")
3390         da=$(mptcp_lib_evts_get_info "daddr$i    3390         da=$(mptcp_lib_evts_get_info "daddr$ip" "$evts" $t $2)
3391         dp=$(mptcp_lib_evts_get_info dport "$    3391         dp=$(mptcp_lib_evts_get_info dport "$evts" $t $2)
3392         sp=$(mptcp_lib_evts_get_info sport "$    3392         sp=$(mptcp_lib_evts_get_info sport "$evts" $t $2)
3393                                                  3393 
3394         cnt=$(rm_sf_count ${1})                  3394         cnt=$(rm_sf_count ${1})
3395         ip netns exec $1 ./pm_nl_ctl dsf lip     3395         ip netns exec $1 ./pm_nl_ctl dsf lip $2 lport $sp \
3396                                 rip $da rport    3396                                 rip $da rport $dp token $tk
3397         wait_rm_sf $1 "${cnt}"                   3397         wait_rm_sf $1 "${cnt}"
3398 }                                                3398 }
3399                                                  3399 
3400 check_output()                                   3400 check_output()
3401 {                                                3401 {
3402         local cmd="$1"                           3402         local cmd="$1"
3403         local expected="$2"                      3403         local expected="$2"
3404         local msg="$3"                           3404         local msg="$3"
3405         local rc=0                               3405         local rc=0
3406                                                  3406 
3407         mptcp_lib_check_output "${err}" "${cm    3407         mptcp_lib_check_output "${err}" "${cmd}" "${expected}" || rc=${?}
3408         if [ ${rc} -eq 2 ]; then                 3408         if [ ${rc} -eq 2 ]; then
3409                 fail_test "fail to check outp    3409                 fail_test "fail to check output # error ${rc}"
3410         elif [ ${rc} -eq 0 ]; then               3410         elif [ ${rc} -eq 0 ]; then
3411                 print_ok                         3411                 print_ok
3412         elif [ ${rc} -eq 1 ]; then               3412         elif [ ${rc} -eq 1 ]; then
3413                 fail_test "fail to check outp    3413                 fail_test "fail to check output # different output"
3414         fi                                       3414         fi
3415 }                                                3415 }
3416                                                  3416 
3417 # $1: ns                                         3417 # $1: ns
3418 userspace_pm_dump()                              3418 userspace_pm_dump()
3419 {                                                3419 {
3420         local evts=$evts_ns1                     3420         local evts=$evts_ns1
3421         local tk                                 3421         local tk
3422                                                  3422 
3423         [ "$1" == "$ns2" ] && evts=$evts_ns2     3423         [ "$1" == "$ns2" ] && evts=$evts_ns2
3424         tk=$(mptcp_lib_evts_get_info token "$    3424         tk=$(mptcp_lib_evts_get_info token "$evts")
3425                                                  3425 
3426         ip netns exec $1 ./pm_nl_ctl dump tok    3426         ip netns exec $1 ./pm_nl_ctl dump token $tk
3427 }                                                3427 }
3428                                                  3428 
3429 # $1: ns ; $2: id                                3429 # $1: ns ; $2: id
3430 userspace_pm_get_addr()                          3430 userspace_pm_get_addr()
3431 {                                                3431 {
3432         local evts=$evts_ns1                     3432         local evts=$evts_ns1
3433         local tk                                 3433         local tk
3434                                                  3434 
3435         [ "$1" == "$ns2" ] && evts=$evts_ns2     3435         [ "$1" == "$ns2" ] && evts=$evts_ns2
3436         tk=$(mptcp_lib_evts_get_info token "$    3436         tk=$(mptcp_lib_evts_get_info token "$evts")
3437                                                  3437 
3438         ip netns exec $1 ./pm_nl_ctl get $2 t    3438         ip netns exec $1 ./pm_nl_ctl get $2 token $tk
3439 }                                                3439 }
3440                                                  3440 
3441 userspace_pm_chk_dump_addr()                     3441 userspace_pm_chk_dump_addr()
3442 {                                                3442 {
3443         local ns="${1}"                          3443         local ns="${1}"
3444         local exp="${2}"                         3444         local exp="${2}"
3445         local check="${3}"                       3445         local check="${3}"
3446                                                  3446 
3447         print_check "dump addrs ${check}"        3447         print_check "dump addrs ${check}"
3448                                                  3448 
3449         if mptcp_lib_kallsyms_has "mptcp_user    3449         if mptcp_lib_kallsyms_has "mptcp_userspace_pm_dump_addr$"; then
3450                 check_output "userspace_pm_du    3450                 check_output "userspace_pm_dump ${ns}" "${exp}"
3451         else                                     3451         else
3452                 print_skip                       3452                 print_skip
3453         fi                                       3453         fi
3454 }                                                3454 }
3455                                                  3455 
3456 userspace_pm_chk_get_addr()                      3456 userspace_pm_chk_get_addr()
3457 {                                                3457 {
3458         local ns="${1}"                          3458         local ns="${1}"
3459         local id="${2}"                          3459         local id="${2}"
3460         local exp="${3}"                         3460         local exp="${3}"
3461                                                  3461 
3462         print_check "get id ${id} addr"          3462         print_check "get id ${id} addr"
3463                                                  3463 
3464         if mptcp_lib_kallsyms_has "mptcp_user    3464         if mptcp_lib_kallsyms_has "mptcp_userspace_pm_get_addr$"; then
3465                 check_output "userspace_pm_ge    3465                 check_output "userspace_pm_get_addr ${ns} ${id}" "${exp}"
3466         else                                     3466         else
3467                 print_skip                       3467                 print_skip
3468         fi                                       3468         fi
3469 }                                                3469 }
3470                                                  3470 
3471 # $1: ns ; $2: event type ; $3: count            3471 # $1: ns ; $2: event type ; $3: count
3472 chk_evt_nr()                                     3472 chk_evt_nr()
3473 {                                                3473 {
3474         local ns=${1}                            3474         local ns=${1}
3475         local evt_name="${2}"                    3475         local evt_name="${2}"
3476         local exp="${3}"                         3476         local exp="${3}"
3477                                                  3477 
3478         local evts="${evts_ns1}"                 3478         local evts="${evts_ns1}"
3479         local evt="${!evt_name}"                 3479         local evt="${!evt_name}"
3480         local count                              3480         local count
3481                                                  3481 
3482         evt_name="${evt_name:16}" # without M    3482         evt_name="${evt_name:16}" # without MPTCP_LIB_EVENT_
3483         [ "${ns}" == "ns2" ] && evts="${evts_    3483         [ "${ns}" == "ns2" ] && evts="${evts_ns2}"
3484                                                  3484 
3485         print_check "event ${ns} ${evt_name}     3485         print_check "event ${ns} ${evt_name} (${exp})"
3486                                                  3486 
3487         if [[ "${evt_name}" = "LISTENER_"* ]]    3487         if [[ "${evt_name}" = "LISTENER_"* ]] &&
3488            ! mptcp_lib_kallsyms_has "mptcp_ev    3488            ! mptcp_lib_kallsyms_has "mptcp_event_pm_listener$"; then
3489                 print_skip "event not support    3489                 print_skip "event not supported"
3490                 return                           3490                 return
3491         fi                                       3491         fi
3492                                                  3492 
3493         count=$(grep -cw "type:${evt}" "${evt    3493         count=$(grep -cw "type:${evt}" "${evts}")
3494         if [ "${count}" != "${exp}" ]; then      3494         if [ "${count}" != "${exp}" ]; then
3495                 fail_test "got ${count} event    3495                 fail_test "got ${count} events, expected ${exp}"
3496         else                                     3496         else
3497                 print_ok                         3497                 print_ok
3498         fi                                       3498         fi
3499 }                                                3499 }
3500                                                  3500 
3501 userspace_tests()                                3501 userspace_tests()
3502 {                                                3502 {
3503         # userspace pm type prevents add_addr    3503         # userspace pm type prevents add_addr
3504         if reset "userspace pm type prevents     3504         if reset "userspace pm type prevents add_addr" &&
3505            continue_if mptcp_lib_has_file '/p    3505            continue_if mptcp_lib_has_file '/proc/sys/net/mptcp/pm_type'; then
3506                 set_userspace_pm $ns1            3506                 set_userspace_pm $ns1
3507                 pm_nl_set_limits $ns1 0 2        3507                 pm_nl_set_limits $ns1 0 2
3508                 pm_nl_set_limits $ns2 0 2        3508                 pm_nl_set_limits $ns2 0 2
3509                 pm_nl_add_endpoint $ns1 10.0.    3509                 pm_nl_add_endpoint $ns1 10.0.2.1 flags signal
3510                 run_tests $ns1 $ns2 10.0.1.1     3510                 run_tests $ns1 $ns2 10.0.1.1
3511                 chk_join_nr 0 0 0                3511                 chk_join_nr 0 0 0
3512                 chk_add_nr 0 0                   3512                 chk_add_nr 0 0
3513         fi                                       3513         fi
3514                                                  3514 
3515         # userspace pm type does not echo add    3515         # userspace pm type does not echo add_addr without daemon
3516         if reset "userspace pm no echo w/o da    3516         if reset "userspace pm no echo w/o daemon" &&
3517            continue_if mptcp_lib_has_file '/p    3517            continue_if mptcp_lib_has_file '/proc/sys/net/mptcp/pm_type'; then
3518                 set_userspace_pm $ns2            3518                 set_userspace_pm $ns2
3519                 pm_nl_set_limits $ns1 0 2        3519                 pm_nl_set_limits $ns1 0 2
3520                 pm_nl_set_limits $ns2 0 2        3520                 pm_nl_set_limits $ns2 0 2
3521                 pm_nl_add_endpoint $ns1 10.0.    3521                 pm_nl_add_endpoint $ns1 10.0.2.1 flags signal
3522                 run_tests $ns1 $ns2 10.0.1.1     3522                 run_tests $ns1 $ns2 10.0.1.1
3523                 chk_join_nr 0 0 0                3523                 chk_join_nr 0 0 0
3524                 chk_add_nr 1 0                   3524                 chk_add_nr 1 0
3525         fi                                       3525         fi
3526                                                  3526 
3527         # userspace pm type rejects join         3527         # userspace pm type rejects join
3528         if reset "userspace pm type rejects j    3528         if reset "userspace pm type rejects join" &&
3529            continue_if mptcp_lib_has_file '/p    3529            continue_if mptcp_lib_has_file '/proc/sys/net/mptcp/pm_type'; then
3530                 set_userspace_pm $ns1            3530                 set_userspace_pm $ns1
3531                 pm_nl_set_limits $ns1 1 1        3531                 pm_nl_set_limits $ns1 1 1
3532                 pm_nl_set_limits $ns2 1 1        3532                 pm_nl_set_limits $ns2 1 1
3533                 pm_nl_add_endpoint $ns2 10.0.    3533                 pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow
3534                 run_tests $ns1 $ns2 10.0.1.1     3534                 run_tests $ns1 $ns2 10.0.1.1
3535                 chk_join_nr 1 1 0                3535                 chk_join_nr 1 1 0
3536         fi                                       3536         fi
3537                                                  3537 
3538         # userspace pm type does not send joi    3538         # userspace pm type does not send join
3539         if reset "userspace pm type does not     3539         if reset "userspace pm type does not send join" &&
3540            continue_if mptcp_lib_has_file '/p    3540            continue_if mptcp_lib_has_file '/proc/sys/net/mptcp/pm_type'; then
3541                 set_userspace_pm $ns2            3541                 set_userspace_pm $ns2
3542                 pm_nl_set_limits $ns1 1 1        3542                 pm_nl_set_limits $ns1 1 1
3543                 pm_nl_set_limits $ns2 1 1        3543                 pm_nl_set_limits $ns2 1 1
3544                 pm_nl_add_endpoint $ns2 10.0.    3544                 pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow
3545                 run_tests $ns1 $ns2 10.0.1.1     3545                 run_tests $ns1 $ns2 10.0.1.1
3546                 chk_join_nr 0 0 0                3546                 chk_join_nr 0 0 0
3547         fi                                       3547         fi
3548                                                  3548 
3549         # userspace pm type prevents mp_prio     3549         # userspace pm type prevents mp_prio
3550         if reset "userspace pm type prevents     3550         if reset "userspace pm type prevents mp_prio" &&
3551            continue_if mptcp_lib_has_file '/p    3551            continue_if mptcp_lib_has_file '/proc/sys/net/mptcp/pm_type'; then
3552                 set_userspace_pm $ns1            3552                 set_userspace_pm $ns1
3553                 pm_nl_set_limits $ns1 1 1        3553                 pm_nl_set_limits $ns1 1 1
3554                 pm_nl_set_limits $ns2 1 1        3554                 pm_nl_set_limits $ns2 1 1
3555                 pm_nl_add_endpoint $ns2 10.0.    3555                 pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow
3556                 sflags=backup speed=slow \       3556                 sflags=backup speed=slow \
3557                         run_tests $ns1 $ns2 1    3557                         run_tests $ns1 $ns2 10.0.1.1
3558                 chk_join_nr 1 1 0                3558                 chk_join_nr 1 1 0
3559                 chk_prio_nr 0 0 0 0              3559                 chk_prio_nr 0 0 0 0
3560         fi                                       3560         fi
3561                                                  3561 
3562         # userspace pm type prevents rm_addr     3562         # userspace pm type prevents rm_addr
3563         if reset "userspace pm type prevents     3563         if reset "userspace pm type prevents rm_addr" &&
3564            continue_if mptcp_lib_has_file '/p    3564            continue_if mptcp_lib_has_file '/proc/sys/net/mptcp/pm_type'; then
3565                 set_userspace_pm $ns1            3565                 set_userspace_pm $ns1
3566                 set_userspace_pm $ns2            3566                 set_userspace_pm $ns2
3567                 pm_nl_set_limits $ns1 0 1        3567                 pm_nl_set_limits $ns1 0 1
3568                 pm_nl_set_limits $ns2 0 1        3568                 pm_nl_set_limits $ns2 0 1
3569                 pm_nl_add_endpoint $ns2 10.0.    3569                 pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow
3570                 addr_nr_ns2=-1 speed=slow \      3570                 addr_nr_ns2=-1 speed=slow \
3571                         run_tests $ns1 $ns2 1    3571                         run_tests $ns1 $ns2 10.0.1.1
3572                 chk_join_nr 0 0 0                3572                 chk_join_nr 0 0 0
3573                 chk_rm_nr 0 0                    3573                 chk_rm_nr 0 0
3574         fi                                       3574         fi
3575                                                  3575 
3576         # userspace pm add & remove address      3576         # userspace pm add & remove address
3577         if reset_with_events "userspace pm ad    3577         if reset_with_events "userspace pm add & remove address" &&
3578            continue_if mptcp_lib_has_file '/p    3578            continue_if mptcp_lib_has_file '/proc/sys/net/mptcp/pm_type'; then
3579                 set_userspace_pm $ns1            3579                 set_userspace_pm $ns1
3580                 pm_nl_set_limits $ns2 2 2        3580                 pm_nl_set_limits $ns2 2 2
3581                 { speed=5 \                      3581                 { speed=5 \
3582                         run_tests $ns1 $ns2 1    3582                         run_tests $ns1 $ns2 10.0.1.1 & } 2>/dev/null
3583                 local tests_pid=$!               3583                 local tests_pid=$!
3584                 wait_mpj $ns1                    3584                 wait_mpj $ns1
3585                 userspace_pm_add_addr $ns1 10    3585                 userspace_pm_add_addr $ns1 10.0.2.1 10
3586                 userspace_pm_add_addr $ns1 10    3586                 userspace_pm_add_addr $ns1 10.0.3.1 20
3587                 chk_join_nr 2 2 2                3587                 chk_join_nr 2 2 2
3588                 chk_add_nr 2 2                   3588                 chk_add_nr 2 2
3589                 chk_mptcp_info subflows 2 sub    3589                 chk_mptcp_info subflows 2 subflows 2
3590                 chk_subflows_total 3 3           3590                 chk_subflows_total 3 3
3591                 chk_mptcp_info add_addr_signa    3591                 chk_mptcp_info add_addr_signal 2 add_addr_accepted 2
3592                 userspace_pm_chk_dump_addr "$    3592                 userspace_pm_chk_dump_addr "${ns1}" \
3593                         $'id 10 flags signal     3593                         $'id 10 flags signal 10.0.2.1\nid 20 flags signal 10.0.3.1' \
3594                         "signal"                 3594                         "signal"
3595                 userspace_pm_chk_get_addr "${    3595                 userspace_pm_chk_get_addr "${ns1}" "10" "id 10 flags signal 10.0.2.1"
3596                 userspace_pm_chk_get_addr "${    3596                 userspace_pm_chk_get_addr "${ns1}" "20" "id 20 flags signal 10.0.3.1"
3597                 userspace_pm_rm_sf $ns1 "::ff    3597                 userspace_pm_rm_sf $ns1 "::ffff:10.0.2.1" $MPTCP_LIB_EVENT_SUB_ESTABLISHED
3598                 userspace_pm_chk_dump_addr "$    3598                 userspace_pm_chk_dump_addr "${ns1}" \
3599                         "id 20 flags signal 1    3599                         "id 20 flags signal 10.0.3.1" "after rm_sf 10"
3600                 userspace_pm_rm_addr $ns1 20     3600                 userspace_pm_rm_addr $ns1 20
3601                 userspace_pm_chk_dump_addr "$    3601                 userspace_pm_chk_dump_addr "${ns1}" "" "after rm_addr 20"
3602                 chk_rm_nr 1 1 invert             3602                 chk_rm_nr 1 1 invert
3603                 chk_mptcp_info subflows 0 sub    3603                 chk_mptcp_info subflows 0 subflows 0
3604                 chk_subflows_total 1 1           3604                 chk_subflows_total 1 1
3605                 kill_events_pids                 3605                 kill_events_pids
3606                 mptcp_lib_kill_wait $tests_pi    3606                 mptcp_lib_kill_wait $tests_pid
3607         fi                                       3607         fi
3608                                                  3608 
3609         # userspace pm create destroy subflow    3609         # userspace pm create destroy subflow
3610         if reset_with_events "userspace pm cr    3610         if reset_with_events "userspace pm create destroy subflow" &&
3611            continue_if mptcp_lib_has_file '/p    3611            continue_if mptcp_lib_has_file '/proc/sys/net/mptcp/pm_type'; then
3612                 set_userspace_pm $ns2            3612                 set_userspace_pm $ns2
3613                 pm_nl_set_limits $ns1 0 1        3613                 pm_nl_set_limits $ns1 0 1
3614                 { speed=5 \                      3614                 { speed=5 \
3615                         run_tests $ns1 $ns2 1    3615                         run_tests $ns1 $ns2 10.0.1.1 & } 2>/dev/null
3616                 local tests_pid=$!               3616                 local tests_pid=$!
3617                 wait_mpj $ns2                    3617                 wait_mpj $ns2
3618                 userspace_pm_add_sf $ns2 10.0    3618                 userspace_pm_add_sf $ns2 10.0.3.2 20
3619                 chk_join_nr 1 1 1                3619                 chk_join_nr 1 1 1
3620                 chk_mptcp_info subflows 1 sub    3620                 chk_mptcp_info subflows 1 subflows 1
3621                 chk_subflows_total 2 2           3621                 chk_subflows_total 2 2
3622                 userspace_pm_chk_dump_addr "$    3622                 userspace_pm_chk_dump_addr "${ns2}" \
3623                         "id 20 flags subflow     3623                         "id 20 flags subflow 10.0.3.2" \
3624                         "subflow"                3624                         "subflow"
3625                 userspace_pm_chk_get_addr "${    3625                 userspace_pm_chk_get_addr "${ns2}" "20" "id 20 flags subflow 10.0.3.2"
3626                 userspace_pm_rm_sf $ns2 10.0.    3626                 userspace_pm_rm_sf $ns2 10.0.3.2 $MPTCP_LIB_EVENT_SUB_ESTABLISHED
3627                 userspace_pm_chk_dump_addr "$    3627                 userspace_pm_chk_dump_addr "${ns2}" \
3628                         "" \                     3628                         "" \
3629                         "after rm_sf 20"         3629                         "after rm_sf 20"
3630                 chk_rm_nr 0 1                    3630                 chk_rm_nr 0 1
3631                 chk_mptcp_info subflows 0 sub    3631                 chk_mptcp_info subflows 0 subflows 0
3632                 chk_subflows_total 1 1           3632                 chk_subflows_total 1 1
3633                 kill_events_pids                 3633                 kill_events_pids
3634                 mptcp_lib_kill_wait $tests_pi    3634                 mptcp_lib_kill_wait $tests_pid
3635         fi                                       3635         fi
3636                                                  3636 
3637         # userspace pm create id 0 subflow       3637         # userspace pm create id 0 subflow
3638         if reset_with_events "userspace pm cr    3638         if reset_with_events "userspace pm create id 0 subflow" &&
3639            continue_if mptcp_lib_has_file '/p    3639            continue_if mptcp_lib_has_file '/proc/sys/net/mptcp/pm_type'; then
3640                 set_userspace_pm $ns2            3640                 set_userspace_pm $ns2
3641                 pm_nl_set_limits $ns1 0 1        3641                 pm_nl_set_limits $ns1 0 1
3642                 { speed=5 \                      3642                 { speed=5 \
3643                         run_tests $ns1 $ns2 1    3643                         run_tests $ns1 $ns2 10.0.1.1 & } 2>/dev/null
3644                 local tests_pid=$!               3644                 local tests_pid=$!
3645                 wait_mpj $ns2                    3645                 wait_mpj $ns2
3646                 chk_mptcp_info subflows 0 sub    3646                 chk_mptcp_info subflows 0 subflows 0
3647                 chk_subflows_total 1 1           3647                 chk_subflows_total 1 1
3648                 userspace_pm_add_sf $ns2 10.0    3648                 userspace_pm_add_sf $ns2 10.0.3.2 0
3649                 userspace_pm_chk_dump_addr "$    3649                 userspace_pm_chk_dump_addr "${ns2}" \
3650                         "id 0 flags subflow 1    3650                         "id 0 flags subflow 10.0.3.2" "id 0 subflow"
3651                 chk_join_nr 1 1 1                3651                 chk_join_nr 1 1 1
3652                 chk_mptcp_info subflows 1 sub    3652                 chk_mptcp_info subflows 1 subflows 1
3653                 chk_subflows_total 2 2           3653                 chk_subflows_total 2 2
3654                 kill_events_pids                 3654                 kill_events_pids
3655                 mptcp_lib_kill_wait $tests_pi    3655                 mptcp_lib_kill_wait $tests_pid
3656         fi                                       3656         fi
3657                                                  3657 
3658         # userspace pm remove initial subflow    3658         # userspace pm remove initial subflow
3659         if reset_with_events "userspace pm re    3659         if reset_with_events "userspace pm remove initial subflow" &&
3660            continue_if mptcp_lib_has_file '/p    3660            continue_if mptcp_lib_has_file '/proc/sys/net/mptcp/pm_type'; then
3661                 set_userspace_pm $ns2            3661                 set_userspace_pm $ns2
3662                 pm_nl_set_limits $ns1 0 1        3662                 pm_nl_set_limits $ns1 0 1
3663                 { speed=5 \                      3663                 { speed=5 \
3664                         run_tests $ns1 $ns2 1    3664                         run_tests $ns1 $ns2 10.0.1.1 & } 2>/dev/null
3665                 local tests_pid=$!               3665                 local tests_pid=$!
3666                 wait_mpj $ns2                    3666                 wait_mpj $ns2
3667                 userspace_pm_add_sf $ns2 10.0    3667                 userspace_pm_add_sf $ns2 10.0.3.2 20
3668                 chk_join_nr 1 1 1                3668                 chk_join_nr 1 1 1
3669                 chk_mptcp_info subflows 1 sub    3669                 chk_mptcp_info subflows 1 subflows 1
3670                 chk_subflows_total 2 2           3670                 chk_subflows_total 2 2
3671                 userspace_pm_rm_sf $ns2 10.0.    3671                 userspace_pm_rm_sf $ns2 10.0.1.2
3672                 # we don't look at the counte    3672                 # we don't look at the counter linked to the RM_ADDR but
3673                 # to the one linked to the su    3673                 # to the one linked to the subflows that have been removed
3674                 chk_rm_nr 0 1                    3674                 chk_rm_nr 0 1
3675                 chk_rst_nr 0 0 invert            3675                 chk_rst_nr 0 0 invert
3676                 chk_mptcp_info subflows 1 sub    3676                 chk_mptcp_info subflows 1 subflows 1
3677                 chk_subflows_total 1 1           3677                 chk_subflows_total 1 1
3678                 kill_events_pids                 3678                 kill_events_pids
3679                 mptcp_lib_kill_wait $tests_pi    3679                 mptcp_lib_kill_wait $tests_pid
3680         fi                                       3680         fi
3681                                                  3681 
3682         # userspace pm send RM_ADDR for ID 0     3682         # userspace pm send RM_ADDR for ID 0
3683         if reset_with_events "userspace pm se    3683         if reset_with_events "userspace pm send RM_ADDR for ID 0" &&
3684            continue_if mptcp_lib_has_file '/p    3684            continue_if mptcp_lib_has_file '/proc/sys/net/mptcp/pm_type'; then
3685                 set_userspace_pm $ns1            3685                 set_userspace_pm $ns1
3686                 pm_nl_set_limits $ns2 1 1        3686                 pm_nl_set_limits $ns2 1 1
3687                 { speed=5 \                      3687                 { speed=5 \
3688                         run_tests $ns1 $ns2 1    3688                         run_tests $ns1 $ns2 10.0.1.1 & } 2>/dev/null
3689                 local tests_pid=$!               3689                 local tests_pid=$!
3690                 wait_mpj $ns1                    3690                 wait_mpj $ns1
3691                 userspace_pm_add_addr $ns1 10    3691                 userspace_pm_add_addr $ns1 10.0.2.1 10
3692                 chk_join_nr 1 1 1                3692                 chk_join_nr 1 1 1
3693                 chk_add_nr 1 1                   3693                 chk_add_nr 1 1
3694                 chk_mptcp_info subflows 1 sub    3694                 chk_mptcp_info subflows 1 subflows 1
3695                 chk_subflows_total 2 2           3695                 chk_subflows_total 2 2
3696                 chk_mptcp_info add_addr_signa    3696                 chk_mptcp_info add_addr_signal 1 add_addr_accepted 1
3697                 userspace_pm_rm_addr $ns1 0      3697                 userspace_pm_rm_addr $ns1 0
3698                 # we don't look at the counte    3698                 # we don't look at the counter linked to the subflows that
3699                 # have been removed but to th    3699                 # have been removed but to the one linked to the RM_ADDR
3700                 chk_rm_nr 1 0 invert             3700                 chk_rm_nr 1 0 invert
3701                 chk_rst_nr 0 0 invert            3701                 chk_rst_nr 0 0 invert
3702                 chk_mptcp_info subflows 1 sub    3702                 chk_mptcp_info subflows 1 subflows 1
3703                 chk_subflows_total 1 1           3703                 chk_subflows_total 1 1
3704                 kill_events_pids                 3704                 kill_events_pids
3705                 mptcp_lib_kill_wait $tests_pi    3705                 mptcp_lib_kill_wait $tests_pid
3706         fi                                       3706         fi
3707 }                                                3707 }
3708                                                  3708 
3709 endpoint_tests()                                 3709 endpoint_tests()
3710 {                                                3710 {
3711         # subflow_rebuild_header is needed to    3711         # subflow_rebuild_header is needed to support the implicit flag
3712         # userspace pm type prevents add_addr    3712         # userspace pm type prevents add_addr
3713         if reset "implicit EP" &&                3713         if reset "implicit EP" &&
3714            mptcp_lib_kallsyms_has "subflow_re    3714            mptcp_lib_kallsyms_has "subflow_rebuild_header$"; then
3715                 pm_nl_set_limits $ns1 2 2        3715                 pm_nl_set_limits $ns1 2 2
3716                 pm_nl_set_limits $ns2 2 2        3716                 pm_nl_set_limits $ns2 2 2
3717                 pm_nl_add_endpoint $ns1 10.0.    3717                 pm_nl_add_endpoint $ns1 10.0.2.1 flags signal
3718                 { speed=slow \                   3718                 { speed=slow \
3719                         run_tests $ns1 $ns2 1    3719                         run_tests $ns1 $ns2 10.0.1.1 & } 2>/dev/null
3720                 local tests_pid=$!               3720                 local tests_pid=$!
3721                                                  3721 
3722                 wait_mpj $ns1                    3722                 wait_mpj $ns1
3723                 pm_nl_check_endpoint "creatio    3723                 pm_nl_check_endpoint "creation" \
3724                         $ns2 10.0.2.2 id 1 fl    3724                         $ns2 10.0.2.2 id 1 flags implicit
3725                 chk_mptcp_info subflows 1 sub    3725                 chk_mptcp_info subflows 1 subflows 1
3726                 chk_mptcp_info add_addr_signa    3726                 chk_mptcp_info add_addr_signal 1 add_addr_accepted 1
3727                                                  3727 
3728                 pm_nl_add_endpoint $ns2 10.0.    3728                 pm_nl_add_endpoint $ns2 10.0.2.2 id 33 2>/dev/null
3729                 pm_nl_check_endpoint "ID chan    3729                 pm_nl_check_endpoint "ID change is prevented" \
3730                         $ns2 10.0.2.2 id 1 fl    3730                         $ns2 10.0.2.2 id 1 flags implicit
3731                                                  3731 
3732                 pm_nl_add_endpoint $ns2 10.0.    3732                 pm_nl_add_endpoint $ns2 10.0.2.2 flags signal
3733                 pm_nl_check_endpoint "modif i    3733                 pm_nl_check_endpoint "modif is allowed" \
3734                         $ns2 10.0.2.2 id 1 fl    3734                         $ns2 10.0.2.2 id 1 flags signal
3735                 mptcp_lib_kill_wait $tests_pi    3735                 mptcp_lib_kill_wait $tests_pid
3736         fi                                       3736         fi
3737                                                  3737 
3738         if reset_with_tcp_filter "delete and     3738         if reset_with_tcp_filter "delete and re-add" ns2 10.0.3.2 REJECT OUTPUT &&
3739            mptcp_lib_kallsyms_has "subflow_re    3739            mptcp_lib_kallsyms_has "subflow_rebuild_header$"; then
3740                 start_events                     3740                 start_events
3741                 pm_nl_set_limits $ns1 0 3        3741                 pm_nl_set_limits $ns1 0 3
3742                 pm_nl_set_limits $ns2 0 3        3742                 pm_nl_set_limits $ns2 0 3
3743                 pm_nl_add_endpoint $ns2 10.0.    3743                 pm_nl_add_endpoint $ns2 10.0.1.2 id 1 dev ns2eth1 flags subflow
3744                 pm_nl_add_endpoint $ns2 10.0.    3744                 pm_nl_add_endpoint $ns2 10.0.2.2 id 2 dev ns2eth2 flags subflow
3745                 { test_linkfail=4 speed=5 \      3745                 { test_linkfail=4 speed=5 \
3746                         run_tests $ns1 $ns2 1    3746                         run_tests $ns1 $ns2 10.0.1.1 & } 2>/dev/null
3747                 local tests_pid=$!               3747                 local tests_pid=$!
3748                                                  3748 
3749                 wait_mpj $ns2                    3749                 wait_mpj $ns2
3750                 pm_nl_check_endpoint "creatio    3750                 pm_nl_check_endpoint "creation" \
3751                         $ns2 10.0.2.2 id 2 fl    3751                         $ns2 10.0.2.2 id 2 flags subflow dev ns2eth2
3752                 chk_subflow_nr "before delete    3752                 chk_subflow_nr "before delete id 2" 2
3753                 chk_mptcp_info subflows 1 sub    3753                 chk_mptcp_info subflows 1 subflows 1
3754                                                  3754 
3755                 pm_nl_del_endpoint $ns2 2 10.    3755                 pm_nl_del_endpoint $ns2 2 10.0.2.2
3756                 sleep 0.5                        3756                 sleep 0.5
3757                 chk_subflow_nr "after delete     3757                 chk_subflow_nr "after delete id 2" 1
3758                 chk_mptcp_info subflows 0 sub    3758                 chk_mptcp_info subflows 0 subflows 0
3759                                                  3759 
3760                 pm_nl_add_endpoint $ns2 10.0.    3760                 pm_nl_add_endpoint $ns2 10.0.2.2 id 2 dev ns2eth2 flags subflow
3761                 wait_mpj $ns2                    3761                 wait_mpj $ns2
3762                 chk_subflow_nr "after re-add     3762                 chk_subflow_nr "after re-add id 2" 2
3763                 chk_mptcp_info subflows 1 sub    3763                 chk_mptcp_info subflows 1 subflows 1
3764                                                  3764 
3765                 pm_nl_add_endpoint $ns2 10.0.    3765                 pm_nl_add_endpoint $ns2 10.0.3.2 id 3 flags subflow
3766                 wait_attempt_fail $ns2           3766                 wait_attempt_fail $ns2
3767                 chk_subflow_nr "after new rej    3767                 chk_subflow_nr "after new reject" 2
3768                 chk_mptcp_info subflows 1 sub    3768                 chk_mptcp_info subflows 1 subflows 1
3769                                                  3769 
3770                 ip netns exec "${ns2}" ${ipta    3770                 ip netns exec "${ns2}" ${iptables} -D OUTPUT -s "10.0.3.2" -p tcp -j REJECT
3771                 pm_nl_del_endpoint $ns2 3 10.    3771                 pm_nl_del_endpoint $ns2 3 10.0.3.2
3772                 pm_nl_add_endpoint $ns2 10.0.    3772                 pm_nl_add_endpoint $ns2 10.0.3.2 id 3 flags subflow
3773                 wait_mpj $ns2                    3773                 wait_mpj $ns2
3774                 chk_subflow_nr "after no reje    3774                 chk_subflow_nr "after no reject" 3
3775                 chk_mptcp_info subflows 2 sub    3775                 chk_mptcp_info subflows 2 subflows 2
3776                                                  3776 
3777                 local i                          3777                 local i
3778                 for i in $(seq 3); do            3778                 for i in $(seq 3); do
3779                         pm_nl_del_endpoint $n    3779                         pm_nl_del_endpoint $ns2 1 10.0.1.2
3780                         sleep 0.5                3780                         sleep 0.5
3781                         chk_subflow_nr "after    3781                         chk_subflow_nr "after delete id 0 ($i)" 2
3782                         chk_mptcp_info subflo    3782                         chk_mptcp_info subflows 2 subflows 2 # only decr for additional sf
3783                                                  3783 
3784                         pm_nl_add_endpoint $n    3784                         pm_nl_add_endpoint $ns2 10.0.1.2 id 1 dev ns2eth1 flags subflow
3785                         wait_mpj $ns2            3785                         wait_mpj $ns2
3786                         chk_subflow_nr "after    3786                         chk_subflow_nr "after re-add id 0 ($i)" 3
3787                         chk_mptcp_info subflo    3787                         chk_mptcp_info subflows 3 subflows 3
3788                 done                             3788                 done
3789                                                  3789 
3790                 mptcp_lib_kill_wait $tests_pi    3790                 mptcp_lib_kill_wait $tests_pid
3791                                                  3791 
3792                 kill_events_pids                 3792                 kill_events_pids
3793                 chk_evt_nr ns1 MPTCP_LIB_EVEN    3793                 chk_evt_nr ns1 MPTCP_LIB_EVENT_LISTENER_CREATED 1
3794                 chk_evt_nr ns1 MPTCP_LIB_EVEN    3794                 chk_evt_nr ns1 MPTCP_LIB_EVENT_CREATED 1
3795                 chk_evt_nr ns1 MPTCP_LIB_EVEN    3795                 chk_evt_nr ns1 MPTCP_LIB_EVENT_ESTABLISHED 1
3796                 chk_evt_nr ns1 MPTCP_LIB_EVEN    3796                 chk_evt_nr ns1 MPTCP_LIB_EVENT_ANNOUNCED 0
3797                 chk_evt_nr ns1 MPTCP_LIB_EVEN    3797                 chk_evt_nr ns1 MPTCP_LIB_EVENT_REMOVED 4
3798                 chk_evt_nr ns1 MPTCP_LIB_EVEN    3798                 chk_evt_nr ns1 MPTCP_LIB_EVENT_SUB_ESTABLISHED 6
3799                 chk_evt_nr ns1 MPTCP_LIB_EVEN    3799                 chk_evt_nr ns1 MPTCP_LIB_EVENT_SUB_CLOSED 4
3800                                                  3800 
3801                 chk_evt_nr ns2 MPTCP_LIB_EVEN    3801                 chk_evt_nr ns2 MPTCP_LIB_EVENT_CREATED 1
3802                 chk_evt_nr ns2 MPTCP_LIB_EVEN    3802                 chk_evt_nr ns2 MPTCP_LIB_EVENT_ESTABLISHED 1
3803                 chk_evt_nr ns2 MPTCP_LIB_EVEN    3803                 chk_evt_nr ns2 MPTCP_LIB_EVENT_ANNOUNCED 0
3804                 chk_evt_nr ns2 MPTCP_LIB_EVEN    3804                 chk_evt_nr ns2 MPTCP_LIB_EVENT_REMOVED 0
3805                 chk_evt_nr ns2 MPTCP_LIB_EVEN    3805                 chk_evt_nr ns2 MPTCP_LIB_EVENT_SUB_ESTABLISHED 6
3806                 chk_evt_nr ns2 MPTCP_LIB_EVEN    3806                 chk_evt_nr ns2 MPTCP_LIB_EVENT_SUB_CLOSED 5 # one has been closed before estab
3807                                                  3807 
3808                 join_syn_tx=7 \                  3808                 join_syn_tx=7 \
3809                         chk_join_nr 6 6 6        3809                         chk_join_nr 6 6 6
3810                 chk_rm_nr 4 4                    3810                 chk_rm_nr 4 4
3811         fi                                       3811         fi
3812                                                  3812 
3813         # remove and re-add                      3813         # remove and re-add
3814         if reset_with_events "delete re-add s    3814         if reset_with_events "delete re-add signal" &&
3815            mptcp_lib_kallsyms_has "subflow_re    3815            mptcp_lib_kallsyms_has "subflow_rebuild_header$"; then
3816                 pm_nl_set_limits $ns1 0 3        3816                 pm_nl_set_limits $ns1 0 3
3817                 pm_nl_set_limits $ns2 3 3        3817                 pm_nl_set_limits $ns2 3 3
3818                 pm_nl_add_endpoint $ns1 10.0.    3818                 pm_nl_add_endpoint $ns1 10.0.2.1 id 1 flags signal
3819                 # broadcast IP: no packet for    3819                 # broadcast IP: no packet for this address will be received on ns1
3820                 pm_nl_add_endpoint $ns1 224.0    3820                 pm_nl_add_endpoint $ns1 224.0.0.1 id 2 flags signal
3821                 pm_nl_add_endpoint $ns1 10.0.    3821                 pm_nl_add_endpoint $ns1 10.0.1.1 id 42 flags signal
3822                 { test_linkfail=4 speed=5 \      3822                 { test_linkfail=4 speed=5 \
3823                         run_tests $ns1 $ns2 1    3823                         run_tests $ns1 $ns2 10.0.1.1 & } 2>/dev/null
3824                 local tests_pid=$!               3824                 local tests_pid=$!
3825                                                  3825 
3826                 wait_mpj $ns2                    3826                 wait_mpj $ns2
3827                 pm_nl_check_endpoint "creatio    3827                 pm_nl_check_endpoint "creation" \
3828                         $ns1 10.0.2.1 id 1 fl    3828                         $ns1 10.0.2.1 id 1 flags signal
3829                 chk_subflow_nr "before delete    3829                 chk_subflow_nr "before delete" 2
3830                 chk_mptcp_info subflows 1 sub    3830                 chk_mptcp_info subflows 1 subflows 1
3831                                                  3831 
3832                 pm_nl_del_endpoint $ns1 1 10.    3832                 pm_nl_del_endpoint $ns1 1 10.0.2.1
3833                 pm_nl_del_endpoint $ns1 2 224    3833                 pm_nl_del_endpoint $ns1 2 224.0.0.1
3834                 sleep 0.5                        3834                 sleep 0.5
3835                 chk_subflow_nr "after delete"    3835                 chk_subflow_nr "after delete" 1
3836                 chk_mptcp_info subflows 0 sub    3836                 chk_mptcp_info subflows 0 subflows 0
3837                                                  3837 
3838                 pm_nl_add_endpoint $ns1 10.0.    3838                 pm_nl_add_endpoint $ns1 10.0.2.1 id 1 flags signal
3839                 pm_nl_add_endpoint $ns1 10.0.    3839                 pm_nl_add_endpoint $ns1 10.0.3.1 id 2 flags signal
3840                 wait_mpj $ns2                    3840                 wait_mpj $ns2
3841                 chk_subflow_nr "after re-add"    3841                 chk_subflow_nr "after re-add" 3
3842                 chk_mptcp_info subflows 2 sub    3842                 chk_mptcp_info subflows 2 subflows 2
3843                                                  3843 
3844                 pm_nl_del_endpoint $ns1 42 10    3844                 pm_nl_del_endpoint $ns1 42 10.0.1.1
3845                 sleep 0.5                        3845                 sleep 0.5
3846                 chk_subflow_nr "after delete     3846                 chk_subflow_nr "after delete ID 0" 2
3847                 chk_mptcp_info subflows 2 sub    3847                 chk_mptcp_info subflows 2 subflows 2
3848                                                  3848 
3849                 pm_nl_add_endpoint $ns1 10.0.    3849                 pm_nl_add_endpoint $ns1 10.0.1.1 id 99 flags signal
3850                 wait_mpj $ns2                    3850                 wait_mpj $ns2
3851                 chk_subflow_nr "after re-add     3851                 chk_subflow_nr "after re-add ID 0" 3
3852                 chk_mptcp_info subflows 3 sub    3852                 chk_mptcp_info subflows 3 subflows 3
3853                                                  3853 
3854                 pm_nl_del_endpoint $ns1 99 10    3854                 pm_nl_del_endpoint $ns1 99 10.0.1.1
3855                 sleep 0.5                        3855                 sleep 0.5
3856                 chk_subflow_nr "after re-dele    3856                 chk_subflow_nr "after re-delete ID 0" 2
3857                 chk_mptcp_info subflows 2 sub    3857                 chk_mptcp_info subflows 2 subflows 2
3858                                                  3858 
3859                 pm_nl_add_endpoint $ns1 10.0.    3859                 pm_nl_add_endpoint $ns1 10.0.1.1 id 88 flags signal
3860                 wait_mpj $ns2                    3860                 wait_mpj $ns2
3861                 chk_subflow_nr "after re-re-a    3861                 chk_subflow_nr "after re-re-add ID 0" 3
3862                 chk_mptcp_info subflows 3 sub    3862                 chk_mptcp_info subflows 3 subflows 3
3863                 mptcp_lib_kill_wait $tests_pi    3863                 mptcp_lib_kill_wait $tests_pid
3864                                                  3864 
3865                 kill_events_pids                 3865                 kill_events_pids
3866                 chk_evt_nr ns1 MPTCP_LIB_EVEN    3866                 chk_evt_nr ns1 MPTCP_LIB_EVENT_LISTENER_CREATED 1
3867                 chk_evt_nr ns1 MPTCP_LIB_EVEN    3867                 chk_evt_nr ns1 MPTCP_LIB_EVENT_CREATED 1
3868                 chk_evt_nr ns1 MPTCP_LIB_EVEN    3868                 chk_evt_nr ns1 MPTCP_LIB_EVENT_ESTABLISHED 1
3869                 chk_evt_nr ns1 MPTCP_LIB_EVEN    3869                 chk_evt_nr ns1 MPTCP_LIB_EVENT_ANNOUNCED 0
3870                 chk_evt_nr ns1 MPTCP_LIB_EVEN    3870                 chk_evt_nr ns1 MPTCP_LIB_EVENT_REMOVED 0
3871                 chk_evt_nr ns1 MPTCP_LIB_EVEN    3871                 chk_evt_nr ns1 MPTCP_LIB_EVENT_SUB_ESTABLISHED 5
3872                 chk_evt_nr ns1 MPTCP_LIB_EVEN    3872                 chk_evt_nr ns1 MPTCP_LIB_EVENT_SUB_CLOSED 3
3873                                                  3873 
3874                 chk_evt_nr ns2 MPTCP_LIB_EVEN    3874                 chk_evt_nr ns2 MPTCP_LIB_EVENT_CREATED 1
3875                 chk_evt_nr ns2 MPTCP_LIB_EVEN    3875                 chk_evt_nr ns2 MPTCP_LIB_EVENT_ESTABLISHED 1
3876                 chk_evt_nr ns2 MPTCP_LIB_EVEN    3876                 chk_evt_nr ns2 MPTCP_LIB_EVENT_ANNOUNCED 6
3877                 chk_evt_nr ns2 MPTCP_LIB_EVEN    3877                 chk_evt_nr ns2 MPTCP_LIB_EVENT_REMOVED 4
3878                 chk_evt_nr ns2 MPTCP_LIB_EVEN    3878                 chk_evt_nr ns2 MPTCP_LIB_EVENT_SUB_ESTABLISHED 5
3879                 chk_evt_nr ns2 MPTCP_LIB_EVEN    3879                 chk_evt_nr ns2 MPTCP_LIB_EVENT_SUB_CLOSED 3
3880                                                  3880 
3881                 join_connect_err=1 \             3881                 join_connect_err=1 \
3882                         chk_join_nr 5 5 5        3882                         chk_join_nr 5 5 5
3883                 chk_add_nr 6 6                   3883                 chk_add_nr 6 6
3884                 chk_rm_nr 4 3 invert             3884                 chk_rm_nr 4 3 invert
3885         fi                                       3885         fi
3886                                                  3886 
3887         # flush and re-add                       3887         # flush and re-add
3888         if reset_with_tcp_filter "flush re-ad    3888         if reset_with_tcp_filter "flush re-add" ns2 10.0.3.2 REJECT OUTPUT &&
3889            mptcp_lib_kallsyms_has "subflow_re    3889            mptcp_lib_kallsyms_has "subflow_rebuild_header$"; then
3890                 pm_nl_set_limits $ns1 0 2        3890                 pm_nl_set_limits $ns1 0 2
3891                 pm_nl_set_limits $ns2 1 2        3891                 pm_nl_set_limits $ns2 1 2
3892                 # broadcast IP: no packet for    3892                 # broadcast IP: no packet for this address will be received on ns1
3893                 pm_nl_add_endpoint $ns1 224.0    3893                 pm_nl_add_endpoint $ns1 224.0.0.1 id 2 flags signal
3894                 pm_nl_add_endpoint $ns2 10.0.    3894                 pm_nl_add_endpoint $ns2 10.0.3.2 id 3 flags subflow
3895                 { test_linkfail=4 speed=20 \     3895                 { test_linkfail=4 speed=20 \
3896                         run_tests $ns1 $ns2 1    3896                         run_tests $ns1 $ns2 10.0.1.1 & } 2>/dev/null
3897                 local tests_pid=$!               3897                 local tests_pid=$!
3898                                                  3898 
3899                 wait_attempt_fail $ns2           3899                 wait_attempt_fail $ns2
3900                 chk_subflow_nr "before flush"    3900                 chk_subflow_nr "before flush" 1
3901                 chk_mptcp_info subflows 0 sub    3901                 chk_mptcp_info subflows 0 subflows 0
3902                                                  3902 
3903                 pm_nl_flush_endpoint $ns2        3903                 pm_nl_flush_endpoint $ns2
3904                 pm_nl_flush_endpoint $ns1        3904                 pm_nl_flush_endpoint $ns1
3905                 wait_rm_addr $ns2 0              3905                 wait_rm_addr $ns2 0
3906                 ip netns exec "${ns2}" ${ipta    3906                 ip netns exec "${ns2}" ${iptables} -D OUTPUT -s "10.0.3.2" -p tcp -j REJECT
3907                 pm_nl_add_endpoint $ns2 10.0.    3907                 pm_nl_add_endpoint $ns2 10.0.3.2 id 3 flags subflow
3908                 wait_mpj $ns2                    3908                 wait_mpj $ns2
3909                 pm_nl_add_endpoint $ns1 10.0.    3909                 pm_nl_add_endpoint $ns1 10.0.3.1 id 2 flags signal
3910                 wait_mpj $ns2                    3910                 wait_mpj $ns2
3911                 mptcp_lib_kill_wait $tests_pi    3911                 mptcp_lib_kill_wait $tests_pid
3912                                                  3912 
3913                 join_syn_tx=3 join_connect_er    3913                 join_syn_tx=3 join_connect_err=1 \
3914                         chk_join_nr 2 2 2        3914                         chk_join_nr 2 2 2
3915                 chk_add_nr 2 2                   3915                 chk_add_nr 2 2
3916                 chk_rm_nr 1 0 invert             3916                 chk_rm_nr 1 0 invert
3917         fi                                       3917         fi
3918 }                                                3918 }
3919                                                  3919 
3920 # [$1: error message]                            3920 # [$1: error message]
3921 usage()                                          3921 usage()
3922 {                                                3922 {
3923         if [ -n "${1}" ]; then                   3923         if [ -n "${1}" ]; then
3924                 echo "${1}"                      3924                 echo "${1}"
3925                 ret=${KSFT_FAIL}                 3925                 ret=${KSFT_FAIL}
3926         fi                                       3926         fi
3927                                                  3927 
3928         echo "mptcp_join usage:"                 3928         echo "mptcp_join usage:"
3929                                                  3929 
3930         local key                                3930         local key
3931         for key in "${!all_tests[@]}"; do        3931         for key in "${!all_tests[@]}"; do
3932                 echo "  -${key} ${all_tests[$    3932                 echo "  -${key} ${all_tests[${key}]}"
3933         done                                     3933         done
3934                                                  3934 
3935         echo "  -c capture pcap files"           3935         echo "  -c capture pcap files"
3936         echo "  -C enable data checksum"         3936         echo "  -C enable data checksum"
3937         echo "  -i use ip mptcp"                 3937         echo "  -i use ip mptcp"
3938         echo "  -h help"                         3938         echo "  -h help"
3939                                                  3939 
3940         echo "[test ids|names]"                  3940         echo "[test ids|names]"
3941                                                  3941 
3942         exit ${ret}                              3942         exit ${ret}
3943 }                                                3943 }
3944                                                  3944 
3945                                                  3945 
3946 # Use a "simple" array to force an specific o    3946 # Use a "simple" array to force an specific order we cannot have with an associative one
3947 all_tests_sorted=(                               3947 all_tests_sorted=(
3948         f@subflows_tests                         3948         f@subflows_tests
3949         e@subflows_error_tests                   3949         e@subflows_error_tests
3950         s@signal_address_tests                   3950         s@signal_address_tests
3951         l@link_failure_tests                     3951         l@link_failure_tests
3952         t@add_addr_timeout_tests                 3952         t@add_addr_timeout_tests
3953         r@remove_tests                           3953         r@remove_tests
3954         a@add_tests                              3954         a@add_tests
3955         6@ipv6_tests                             3955         6@ipv6_tests
3956         4@v4mapped_tests                         3956         4@v4mapped_tests
3957         M@mixed_tests                            3957         M@mixed_tests
3958         b@backup_tests                           3958         b@backup_tests
3959         p@add_addr_ports_tests                   3959         p@add_addr_ports_tests
3960         k@syncookies_tests                       3960         k@syncookies_tests
3961         S@checksum_tests                         3961         S@checksum_tests
3962         d@deny_join_id0_tests                    3962         d@deny_join_id0_tests
3963         m@fullmesh_tests                         3963         m@fullmesh_tests
3964         z@fastclose_tests                        3964         z@fastclose_tests
3965         F@fail_tests                             3965         F@fail_tests
3966         u@userspace_tests                        3966         u@userspace_tests
3967         I@endpoint_tests                         3967         I@endpoint_tests
3968 )                                                3968 )
3969                                                  3969 
3970 all_tests_args=""                                3970 all_tests_args=""
3971 all_tests_names=()                               3971 all_tests_names=()
3972 for subtests in "${all_tests_sorted[@]}"; do     3972 for subtests in "${all_tests_sorted[@]}"; do
3973         key="${subtests%@*}"                     3973         key="${subtests%@*}"
3974         value="${subtests#*@}"                   3974         value="${subtests#*@}"
3975                                                  3975 
3976         all_tests_args+="${key}"                 3976         all_tests_args+="${key}"
3977         all_tests_names+=("${value}")            3977         all_tests_names+=("${value}")
3978         all_tests[${key}]="${value}"             3978         all_tests[${key}]="${value}"
3979 done                                             3979 done
3980                                                  3980 
3981 tests=()                                         3981 tests=()
3982 while getopts "${all_tests_args}cCih" opt; do    3982 while getopts "${all_tests_args}cCih" opt; do
3983         case $opt in                             3983         case $opt in
3984                 ["${all_tests_args}"])           3984                 ["${all_tests_args}"])
3985                         tests+=("${all_tests[    3985                         tests+=("${all_tests[${opt}]}")
3986                         ;;                       3986                         ;;
3987                 c)                               3987                 c)
3988                         capture=true             3988                         capture=true
3989                         ;;                       3989                         ;;
3990                 C)                               3990                 C)
3991                         checksum=true            3991                         checksum=true
3992                         ;;                       3992                         ;;
3993                 i)                               3993                 i)
3994                         mptcp_lib_set_ip_mptc    3994                         mptcp_lib_set_ip_mptcp
3995                         ;;                       3995                         ;;
3996                 h)                               3996                 h)
3997                         usage                    3997                         usage
3998                         ;;                       3998                         ;;
3999                 *)                               3999                 *)
4000                         usage "Unknown option    4000                         usage "Unknown option: -${opt}"
4001                         ;;                       4001                         ;;
4002         esac                                     4002         esac
4003 done                                             4003 done
4004                                                  4004 
4005 shift $((OPTIND - 1))                            4005 shift $((OPTIND - 1))
4006                                                  4006 
4007 for arg in "${@}"; do                            4007 for arg in "${@}"; do
4008         if [[ "${arg}" =~ ^[0-9]+$ ]]; then      4008         if [[ "${arg}" =~ ^[0-9]+$ ]]; then
4009                 only_tests_ids+=("${arg}")       4009                 only_tests_ids+=("${arg}")
4010         else                                     4010         else
4011                 only_tests_names+=("${arg}")     4011                 only_tests_names+=("${arg}")
4012         fi                                       4012         fi
4013 done                                             4013 done
4014                                                  4014 
4015 if [ ${#tests[@]} -eq 0 ]; then                  4015 if [ ${#tests[@]} -eq 0 ]; then
4016         tests=("${all_tests_names[@]}")          4016         tests=("${all_tests_names[@]}")
4017 fi                                               4017 fi
4018                                                  4018 
4019 mptcp_lib_subtests_last_ts_reset                 4019 mptcp_lib_subtests_last_ts_reset
4020 for subtests in "${tests[@]}"; do                4020 for subtests in "${tests[@]}"; do
4021         "${subtests}"                            4021         "${subtests}"
4022 done                                             4022 done
4023 append_prev_results                              4023 append_prev_results
4024                                                  4024 
4025 if [ ${ret} -ne 0 ]; then                        4025 if [ ${ret} -ne 0 ]; then
4026         echo                                     4026         echo
4027         echo "${#failed_tests[@]} failure(s)     4027         echo "${#failed_tests[@]} failure(s) has(ve) been detected:"
4028         for i in $(get_failed_tests_ids); do     4028         for i in $(get_failed_tests_ids); do
4029                 echo -e "\t- ${i}: ${failed_t    4029                 echo -e "\t- ${i}: ${failed_tests[${i}]}"
4030         done                                     4030         done
4031         echo                                     4031         echo
4032 fi                                               4032 fi
4033                                                  4033 
4034 mptcp_lib_result_print_all_tap                   4034 mptcp_lib_result_print_all_tap
4035                                                  4035 
4036 exit $ret                                        4036 exit $ret
                                                      

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php