@@ -35,10 +35,6 @@ ip_mptcp=0
check_invert=0
validate_checksum=0
init=0
-evts_ns1=""
-evts_ns2=""
-evts_ns1_pid=0
-evts_ns2_pid=0
last_test_failed=0
last_test_skipped=0
last_test_ignored=1
@@ -182,8 +178,7 @@ init() {
cin=$(mktemp)
cinsent=$(mktemp)
cout=$(mktemp)
- evts_ns1=$(mktemp)
- evts_ns2=$(mktemp)
+ mptcp_lib_evts_init
trap cleanup EXIT
@@ -196,7 +191,7 @@ cleanup()
rm -f "$cin" "$cout" "$sinfail"
rm -f "$sin" "$sout" "$cinsent" "$cinfail"
rm -f "$tmpfile"
- rm -rf $evts_ns1 $evts_ns2
+ mptcp_lib_evts_remove
cleanup_partial
mptcp_lib_cleanup
}
@@ -461,12 +456,7 @@ reset_with_events()
{
reset "${1}" || return 1
- :> "$evts_ns1"
- :> "$evts_ns2"
- ip netns exec $ns1 ./pm_nl_ctl events >> "$evts_ns1" 2>&1 &
- evts_ns1_pid=$!
- ip netns exec $ns2 ./pm_nl_ctl events >> "$evts_ns2" 2>&1 &
- evts_ns2_pid=$!
+ mptcp_lib_evts_start "${ns1}" "${ns2}"
}
reset_with_tcp_filter()
@@ -636,12 +626,6 @@ wait_mpj()
done
}
-kill_events_pids()
-{
- mptcp_lib_kill_wait $evts_ns1_pid
- mptcp_lib_kill_wait $evts_ns2_pid
-}
-
kill_tests_wait()
{
#shellcheck disable=SC2046
@@ -2884,9 +2868,9 @@ add_addr_ports_tests()
chk_add_nr 1 1 1
chk_rm_nr 1 1 invert
- verify_listener_events $evts_ns1 $LISTENER_CREATED $AF_INET 10.0.2.1 10100
- verify_listener_events $evts_ns1 $LISTENER_CLOSED $AF_INET 10.0.2.1 10100
- kill_events_pids
+ verify_listener_events $server_evts $LISTENER_CREATED $AF_INET 10.0.2.1 10100
+ verify_listener_events $server_evts $LISTENER_CLOSED $AF_INET 10.0.2.1 10100
+ mptcp_lib_evts_kill
fi
# subflow and signal with port, remove
@@ -3259,10 +3243,10 @@ fail_tests()
# $1: ns ; $2: addr ; $3: id
userspace_pm_add_addr()
{
- local evts=$evts_ns1
+ local evts=$server_evts
local tk
- [ "$1" == "$ns2" ] && evts=$evts_ns2
+ [ "$1" == "$ns2" ] && evts=$client_evts
tk=$(mptcp_lib_evts_get_info token "$evts")
ip netns exec $1 ./pm_nl_ctl ann $2 token $tk id $3
@@ -3272,11 +3256,11 @@ userspace_pm_add_addr()
# $1: ns ; $2: id
userspace_pm_rm_addr()
{
- local evts=$evts_ns1
+ local evts=$server_evts
local tk
local cnt
- [ "$1" == "$ns2" ] && evts=$evts_ns2
+ [ "$1" == "$ns2" ] && evts=$client_evts
tk=$(mptcp_lib_evts_get_info token "$evts")
cnt=$(rm_addr_count ${1})
@@ -3287,10 +3271,10 @@ userspace_pm_rm_addr()
# $1: ns ; $2: addr ; $3: id
userspace_pm_add_sf()
{
- local evts=$evts_ns1
+ local evts=$server_evts
local tk da dp
- [ "$1" == "$ns2" ] && evts=$evts_ns2
+ [ "$1" == "$ns2" ] && evts=$client_evts
tk=$(mptcp_lib_evts_get_info token "$evts")
da=$(mptcp_lib_evts_get_info daddr4 "$evts")
dp=$(mptcp_lib_evts_get_info dport "$evts")
@@ -3303,13 +3287,13 @@ userspace_pm_add_sf()
# $1: ns ; $2: addr $3: event type
userspace_pm_rm_sf()
{
- local evts=$evts_ns1
+ local evts=$server_evts
local t=${3:-1}
local ip=4
local tk da dp sp
local cnt
- [ "$1" == "$ns2" ] && evts=$evts_ns2
+ [ "$1" == "$ns2" ] && evts=$client_evts
if mptcp_lib_is_v6 $2; then ip=6; fi
tk=$(mptcp_lib_evts_get_info token "$evts")
da=$(mptcp_lib_evts_get_info "daddr$ip" "$evts" $t)
@@ -3422,7 +3406,7 @@ userspace_tests()
chk_rm_nr 1 1 invert
chk_mptcp_info subflows 0 subflows 0
chk_subflows_total 1 1
- kill_events_pids
+ mptcp_lib_evts_kill
wait $tests_pid
fi
@@ -3444,7 +3428,7 @@ userspace_tests()
chk_rm_nr 1 1
chk_mptcp_info subflows 0 subflows 0
chk_subflows_total 1 1
- kill_events_pids
+ mptcp_lib_evts_kill
wait $tests_pid
fi
@@ -3465,7 +3449,7 @@ userspace_tests()
chk_join_nr 1 1 1
chk_mptcp_info subflows 1 subflows 1
chk_subflows_total 2 2
- kill_events_pids
+ mptcp_lib_evts_kill
wait $tests_pid
fi
@@ -3489,7 +3473,7 @@ userspace_tests()
chk_rst_nr 0 0 invert
chk_mptcp_info subflows 1 subflows 1
chk_subflows_total 1 1
- kill_events_pids
+ mptcp_lib_evts_kill
wait $tests_pid
fi
@@ -3515,7 +3499,7 @@ userspace_tests()
chk_rst_nr 0 0 invert
chk_mptcp_info subflows 1 subflows 1
chk_subflows_total 1 1
- kill_events_pids
+ mptcp_lib_evts_kill
wait $tests_pid
fi
@@ -3543,7 +3527,7 @@ userspace_tests()
chk_rm_nr 1 1 invert
chk_mptcp_info subflows 0 subflows 0
chk_subflows_total 1 1
- kill_events_pids
+ mptcp_lib_evts_kill
wait $tests_pid
fi
@@ -3571,7 +3555,7 @@ userspace_tests()
chk_rm_nr 1 1
chk_mptcp_info subflows 0 subflows 0
chk_subflows_total 1 1
- kill_events_pids
+ mptcp_lib_evts_kill
wait $tests_pid
fi
}
@@ -326,6 +326,69 @@ mptcp_lib_check()
fi
}
+server_evts=""
+client_evts=""
+server_evts_pid=0
+client_evts_pid=0
+
+# server_evts(_pid) and client_evts(_pid) are needed
+# by mptcp_lib_evts_init, _start, _kill and _remove.
+mptcp_lib_evts_init() {
+ : "${server_evts?}"
+ : "${client_evts?}"
+
+ if [ -z "${server_evts}" ]; then
+ server_evts=$(mktemp)
+ fi
+ if [ -z "${client_evts}" ]; then
+ client_evts=$(mktemp)
+ fi
+}
+
+# $1 ns1, $2 ns2
+mptcp_lib_evts_start() {
+ : "${server_evts:?}"
+ : "${client_evts:?}"
+ : "${server_evts_pid:?}"
+ : "${client_evts_pid:?}"
+
+ local ns_1="${1}"
+ local ns_2="${2}"
+
+ :>"$server_evts"
+ :>"$client_evts"
+
+ if [ "${server_evts_pid}" -ne 0 ]; then
+ mptcp_lib_kill_wait "${server_evts_pid}"
+ fi
+ ip netns exec "${ns_1}" ./pm_nl_ctl events >> "${server_evts}" 2>&1 &
+ server_evts_pid=$!
+
+ if [ "${client_evts_pid}" -ne 0 ]; then
+ mptcp_lib_kill_wait "${client_evts_pid}"
+ fi
+ ip netns exec "${ns_2}" ./pm_nl_ctl events >> "${client_evts}" 2>&1 &
+ client_evts_pid=$!
+}
+
+mptcp_lib_evts_kill() {
+ : "${server_evts_pid:?}"
+ : "${client_evts_pid:?}"
+
+ mptcp_lib_kill_wait "${server_evts_pid}"
+ mptcp_lib_kill_wait "${client_evts_pid}"
+
+ server_evts_pid=0
+ client_evts_pid=0
+}
+
+mptcp_lib_evts_remove() {
+ : "${server_evts:?}"
+ : "${client_evts:?}"
+
+ rm -rf "${server_evts}" "${client_evts}"
+}
+
mptcp_lib_cleanup()
{
echo "cleanup"
@@ -34,10 +34,6 @@ AF_INET=2
AF_INET6=10
file=""
-server_evts=""
-client_evts=""
-server_evts_pid=0
-client_evts_pid=0
client4_pid=0
server4_pid=0
client6_pid=0
@@ -116,18 +112,19 @@ cleanup()
# Terminate the MPTCP connection and related processes
local pid
- for pid in $client4_pid $server4_pid $client6_pid $server6_pid\
- $server_evts_pid $client_evts_pid
+ for pid in $client4_pid $server4_pid $client6_pid $server6_pid
do
mptcp_lib_kill_wait $pid
done
+ mptcp_lib_evts_kill
local netns
for netns in "$ns1" "$ns2" ;do
ip netns del "$netns"
done
- rm -rf $file $client_evts $server_evts
+ rm -rf $file
+ mptcp_lib_evts_remove
mptcp_lib_cleanup
_printf "Done\n"
@@ -187,24 +184,8 @@ make_connection()
# Capture netlink events over the two network namespaces running
# the MPTCP client and server
- if [ -z "$client_evts" ]; then
- client_evts=$(mktemp)
- fi
- :>"$client_evts"
- if [ $client_evts_pid -ne 0 ]; then
- mptcp_lib_kill_wait $client_evts_pid
- fi
- ip netns exec "$ns2" ./pm_nl_ctl events >> "$client_evts" 2>&1 &
- client_evts_pid=$!
- if [ -z "$server_evts" ]; then
- server_evts=$(mktemp)
- fi
- :>"$server_evts"
- if [ $server_evts_pid -ne 0 ]; then
- mptcp_lib_kill_wait $server_evts_pid
- fi
- ip netns exec "$ns1" ./pm_nl_ctl events >> "$server_evts" 2>&1 &
- server_evts_pid=$!
+ mptcp_lib_evts_init
+ mptcp_lib_evts_start "${ns1}" "${ns2}"
sleep 0.5
# Run the server
To avoid duplicated code in different MPTCP selftests, we can add and use helpers defined in mptcp_lib.sh. This patch unifies "pm_nl_ctl events" related code in userspace_pm.sh and mptcp_join.sh into four helpers: mptcp_lib_evts_init(), _start(), _kill() and _remove(). Define them in mptcp_lib.sh and use these new helpers in both scripts. Signed-off-by: Geliang Tang <geliang.tang@suse.com> --- .../testing/selftests/net/mptcp/mptcp_join.sh | 58 +++++++---------- .../testing/selftests/net/mptcp/mptcp_lib.sh | 63 +++++++++++++++++++ .../selftests/net/mptcp/userspace_pm.sh | 31 ++------- 3 files changed, 90 insertions(+), 62 deletions(-)