Commit e6a34faf authored by Jakub Kicinski's avatar Jakub Kicinski

Merge branch 'mptcp-pm-listener-events-selftests-cleanup'

Matthieu Baerts says:

====================
mptcp: PM listener events + selftests cleanup

Thanks to the patch 6/11, the MPTCP path manager now sends Netlink events
when MPTCP listening sockets are created and closed. The reason why it is
needed is explained in the linked ticket [1]:

  MPTCP for Linux, when not using the in-kernel PM, depends on the
  userspace PM to create extra listening sockets before announcing
  addresses and ports. Let's call these "PM listeners".

  With the existing MPTCP netlink events, a userspace PM can create
  PM listeners at startup time, or in response to an incoming connection.
  Creating sockets in response to connections is not optimal: ADD_ADDRs
  can't be sent until the sockets are created and listen()ed, and if all
  connections are closed then it may not be clear to the userspace
  PM daemon that PM listener sockets should be cleaned up.

  Hence this feature request: to add MPTCP netlink events for listening
  socket close & create, so PM listening sockets can be managed based
  on application activity.

  [1] https://github.com/multipath-tcp/mptcp_net-next/issues/313

Selftests for these new Netlink events have been added in patches 9,11/11.

The remaining patches introduce different cleanups and small improvements
in MPTCP selftests to ease the maintenance and the addition of new tests.
====================

Link: https://lore.kernel.org/r/20221130140637.409926-1-matthieu.baerts@tessares.netSigned-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parents a802073d 178d0232
...@@ -160,6 +160,12 @@ struct mptcp_info { ...@@ -160,6 +160,12 @@ struct mptcp_info {
* daddr4 | daddr6, sport, dport, backup, if_idx * daddr4 | daddr6, sport, dport, backup, if_idx
* [, error] * [, error]
* The priority of a subflow has changed. 'error' should not be set. * The priority of a subflow has changed. 'error' should not be set.
*
* MPTCP_EVENT_LISTENER_CREATED: family, sport, saddr4 | saddr6
* A new PM listener is created.
*
* MPTCP_EVENT_LISTENER_CLOSED: family, sport, saddr4 | saddr6
* A PM listener is closed.
*/ */
enum mptcp_event_type { enum mptcp_event_type {
MPTCP_EVENT_UNSPEC = 0, MPTCP_EVENT_UNSPEC = 0,
...@@ -174,6 +180,9 @@ enum mptcp_event_type { ...@@ -174,6 +180,9 @@ enum mptcp_event_type {
MPTCP_EVENT_SUB_CLOSED = 11, MPTCP_EVENT_SUB_CLOSED = 11,
MPTCP_EVENT_SUB_PRIORITY = 13, MPTCP_EVENT_SUB_PRIORITY = 13,
MPTCP_EVENT_LISTENER_CREATED = 15,
MPTCP_EVENT_LISTENER_CLOSED = 16,
}; };
enum mptcp_event_attr { enum mptcp_event_attr {
......
...@@ -1029,6 +1029,8 @@ static int mptcp_pm_nl_create_listen_socket(struct sock *sk, ...@@ -1029,6 +1029,8 @@ static int mptcp_pm_nl_create_listen_socket(struct sock *sk,
if (err) if (err)
return err; return err;
mptcp_event_pm_listener(ssock->sk, MPTCP_EVENT_LISTENER_CREATED);
return 0; return 0;
} }
...@@ -2152,6 +2154,58 @@ void mptcp_event_addr_announced(const struct sock *ssk, ...@@ -2152,6 +2154,58 @@ void mptcp_event_addr_announced(const struct sock *ssk,
kfree_skb(skb); kfree_skb(skb);
} }
void mptcp_event_pm_listener(const struct sock *ssk,
enum mptcp_event_type event)
{
const struct inet_sock *issk = inet_sk(ssk);
struct net *net = sock_net(ssk);
struct nlmsghdr *nlh;
struct sk_buff *skb;
if (!genl_has_listeners(&mptcp_genl_family, net, MPTCP_PM_EV_GRP_OFFSET))
return;
skb = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
if (!skb)
return;
nlh = genlmsg_put(skb, 0, 0, &mptcp_genl_family, 0, event);
if (!nlh)
goto nla_put_failure;
if (nla_put_u16(skb, MPTCP_ATTR_FAMILY, ssk->sk_family))
goto nla_put_failure;
if (nla_put_be16(skb, MPTCP_ATTR_SPORT, issk->inet_sport))
goto nla_put_failure;
switch (ssk->sk_family) {
case AF_INET:
if (nla_put_in_addr(skb, MPTCP_ATTR_SADDR4, issk->inet_saddr))
goto nla_put_failure;
break;
#if IS_ENABLED(CONFIG_MPTCP_IPV6)
case AF_INET6: {
const struct ipv6_pinfo *np = inet6_sk(ssk);
if (nla_put_in6_addr(skb, MPTCP_ATTR_SADDR6, &np->saddr))
goto nla_put_failure;
break;
}
#endif
default:
WARN_ON_ONCE(1);
goto nla_put_failure;
}
genlmsg_end(skb, nlh);
mptcp_nl_mcast_send(net, skb, GFP_KERNEL);
return;
nla_put_failure:
kfree_skb(skb);
}
void mptcp_event(enum mptcp_event_type type, const struct mptcp_sock *msk, void mptcp_event(enum mptcp_event_type type, const struct mptcp_sock *msk,
const struct sock *ssk, gfp_t gfp) const struct sock *ssk, gfp_t gfp)
{ {
...@@ -2197,6 +2251,9 @@ void mptcp_event(enum mptcp_event_type type, const struct mptcp_sock *msk, ...@@ -2197,6 +2251,9 @@ void mptcp_event(enum mptcp_event_type type, const struct mptcp_sock *msk,
if (mptcp_event_sub_closed(skb, msk, ssk) < 0) if (mptcp_event_sub_closed(skb, msk, ssk) < 0)
goto nla_put_failure; goto nla_put_failure;
break; break;
case MPTCP_EVENT_LISTENER_CREATED:
case MPTCP_EVENT_LISTENER_CLOSED:
break;
} }
genlmsg_end(skb, nlh); genlmsg_end(skb, nlh);
......
...@@ -2355,6 +2355,7 @@ static void __mptcp_close_ssk(struct sock *sk, struct sock *ssk, ...@@ -2355,6 +2355,7 @@ static void __mptcp_close_ssk(struct sock *sk, struct sock *ssk,
tcp_set_state(ssk, TCP_CLOSE); tcp_set_state(ssk, TCP_CLOSE);
mptcp_subflow_queue_clean(ssk); mptcp_subflow_queue_clean(ssk);
inet_csk_listen_stop(ssk); inet_csk_listen_stop(ssk);
mptcp_event_pm_listener(ssk, MPTCP_EVENT_LISTENER_CLOSED);
} }
__tcp_close(ssk, 0); __tcp_close(ssk, 0);
...@@ -3647,6 +3648,8 @@ static int mptcp_listen(struct socket *sock, int backlog) ...@@ -3647,6 +3648,8 @@ static int mptcp_listen(struct socket *sock, int backlog)
if (!err) if (!err)
mptcp_copy_inaddrs(sock->sk, ssock->sk); mptcp_copy_inaddrs(sock->sk, ssock->sk);
mptcp_event_pm_listener(ssock->sk, MPTCP_EVENT_LISTENER_CREATED);
unlock: unlock:
release_sock(sock->sk); release_sock(sock->sk);
return err; return err;
......
...@@ -839,6 +839,8 @@ void mptcp_event(enum mptcp_event_type type, const struct mptcp_sock *msk, ...@@ -839,6 +839,8 @@ void mptcp_event(enum mptcp_event_type type, const struct mptcp_sock *msk,
const struct sock *ssk, gfp_t gfp); const struct sock *ssk, gfp_t gfp);
void mptcp_event_addr_announced(const struct sock *ssk, const struct mptcp_addr_info *info); void mptcp_event_addr_announced(const struct sock *ssk, const struct mptcp_addr_info *info);
void mptcp_event_addr_removed(const struct mptcp_sock *msk, u8 id); void mptcp_event_addr_removed(const struct mptcp_sock *msk, u8 id);
void mptcp_event_pm_listener(const struct sock *ssk,
enum mptcp_event_type event);
bool mptcp_userspace_pm_active(const struct mptcp_sock *msk); bool mptcp_userspace_pm_active(const struct mptcp_sock *msk);
void mptcp_fastopen_gen_msk_ackseq(struct mptcp_sock *msk, struct mptcp_subflow_context *subflow, void mptcp_fastopen_gen_msk_ackseq(struct mptcp_sock *msk, struct mptcp_subflow_context *subflow,
......
#!/bin/bash #!/bin/bash
# SPDX-License-Identifier: GPL-2.0 # SPDX-License-Identifier: GPL-2.0
sec=$(date +%s)
rndh=$(printf %x $sec)-$(mktemp -u XXXXXX) rndh=$(printf %x $sec)-$(mktemp -u XXXXXX)
ns="ns1-$rndh" ns="ns1-$rndh"
ksft_skip=4 ksft_skip=4
......
...@@ -274,8 +274,7 @@ check_transfer() ...@@ -274,8 +274,7 @@ check_transfer()
check_mptcp_disabled() check_mptcp_disabled()
{ {
local disabled_ns local disabled_ns="ns_disabled-$rndh"
disabled_ns="ns_disabled-$sech-$(mktemp -u XXXXXX)"
ip netns add ${disabled_ns} || exit $ksft_skip ip netns add ${disabled_ns} || exit $ksft_skip
# net.mptcp.enabled should be enabled by default # net.mptcp.enabled should be enabled by default
...@@ -781,7 +780,6 @@ run_tests_mptfo() ...@@ -781,7 +780,6 @@ run_tests_mptfo()
run_tests_disconnect() run_tests_disconnect()
{ {
local peekmode="$1"
local old_cin=$cin local old_cin=$cin
local old_sin=$sin local old_sin=$sin
...@@ -789,7 +787,6 @@ run_tests_disconnect() ...@@ -789,7 +787,6 @@ run_tests_disconnect()
# force do_transfer to cope with the multiple tranmissions # force do_transfer to cope with the multiple tranmissions
sin="$cin.disconnect" sin="$cin.disconnect"
sin_disconnect=$old_sin
cin="$cin.disconnect" cin="$cin.disconnect"
cin_disconnect="$old_cin" cin_disconnect="$old_cin"
connect_per_transfer=3 connect_per_transfer=3
...@@ -800,7 +797,6 @@ run_tests_disconnect() ...@@ -800,7 +797,6 @@ run_tests_disconnect()
# restore previous status # restore previous status
sin=$old_sin sin=$old_sin
sin_disconnect="$cout".disconnect
cin=$old_cin cin=$old_cin
cin_disconnect="$cin".disconnect cin_disconnect="$cin".disconnect
connect_per_transfer=1 connect_per_transfer=1
......
...@@ -26,6 +26,10 @@ ip_mptcp=0 ...@@ -26,6 +26,10 @@ ip_mptcp=0
check_invert=0 check_invert=0
validate_checksum=0 validate_checksum=0
init=0 init=0
evts_ns1=""
evts_ns2=""
evts_ns1_pid=0
evts_ns2_pid=0
declare -A all_tests declare -A all_tests
declare -a only_tests_ids declare -a only_tests_ids
...@@ -59,8 +63,9 @@ init_partial() ...@@ -59,8 +63,9 @@ init_partial()
{ {
capout=$(mktemp) capout=$(mktemp)
local rndh local sec rndh
rndh=$(mktemp -u XXXXXX) sec=$(date +%s)
rndh=$(printf %x $sec)-$(mktemp -u XXXXXX)
ns1="ns1-$rndh" ns1="ns1-$rndh"
ns2="ns2-$rndh" ns2="ns2-$rndh"
...@@ -153,6 +158,8 @@ init() { ...@@ -153,6 +158,8 @@ init() {
cin=$(mktemp) cin=$(mktemp)
cinsent=$(mktemp) cinsent=$(mktemp)
cout=$(mktemp) cout=$(mktemp)
evts_ns1=$(mktemp)
evts_ns2=$(mktemp)
trap cleanup EXIT trap cleanup EXIT
...@@ -164,6 +171,7 @@ cleanup() ...@@ -164,6 +171,7 @@ cleanup()
{ {
rm -f "$cin" "$cout" "$sinfail" rm -f "$cin" "$cout" "$sinfail"
rm -f "$sin" "$sout" "$cinsent" "$cinfail" rm -f "$sin" "$sout" "$cinsent" "$cinfail"
rm -rf $evts_ns1 $evts_ns2
cleanup_partial cleanup_partial
} }
...@@ -319,6 +327,18 @@ reset_with_fail() ...@@ -319,6 +327,18 @@ reset_with_fail()
index 100 || exit 1 index 100 || exit 1
} }
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=$!
}
fail_test() fail_test()
{ {
ret=1 ret=1
...@@ -472,6 +492,12 @@ kill_wait() ...@@ -472,6 +492,12 @@ kill_wait()
wait $1 2>/dev/null wait $1 2>/dev/null
} }
kill_events_pids()
{
kill_wait $evts_ns1_pid
kill_wait $evts_ns2_pid
}
pm_nl_set_limits() pm_nl_set_limits()
{ {
local ns=$1 local ns=$1
...@@ -672,10 +698,6 @@ do_transfer() ...@@ -672,10 +698,6 @@ do_transfer()
local port=$((10000 + TEST_COUNT - 1)) local port=$((10000 + TEST_COUNT - 1))
local cappid local cappid
local userspace_pm=0 local userspace_pm=0
local evts_ns1
local evts_ns1_pid
local evts_ns2
local evts_ns2_pid
:> "$cout" :> "$cout"
:> "$sout" :> "$sout"
...@@ -752,17 +774,6 @@ do_transfer() ...@@ -752,17 +774,6 @@ do_transfer()
addr_nr_ns2=${addr_nr_ns2:9} addr_nr_ns2=${addr_nr_ns2:9}
fi fi
if [ $userspace_pm -eq 1 ]; then
evts_ns1=$(mktemp)
evts_ns2=$(mktemp)
:> "$evts_ns1"
:> "$evts_ns2"
ip netns exec ${listener_ns} ./pm_nl_ctl events >> "$evts_ns1" 2>&1 &
evts_ns1_pid=$!
ip netns exec ${connector_ns} ./pm_nl_ctl events >> "$evts_ns2" 2>&1 &
evts_ns2_pid=$!
fi
local local_addr local local_addr
if is_v6 "${connect_addr}"; then if is_v6 "${connect_addr}"; then
local_addr="::" local_addr="::"
...@@ -829,7 +840,8 @@ do_transfer() ...@@ -829,7 +840,8 @@ do_transfer()
if [ $userspace_pm -eq 0 ]; then if [ $userspace_pm -eq 0 ]; then
pm_nl_add_endpoint $ns1 $addr flags signal pm_nl_add_endpoint $ns1 $addr flags signal
else else
tk=$(sed -n 's/.*\(token:\)\([[:digit:]]*\).*$/\2/p;q' "$evts_ns1") tk=$(grep "type:1," "$evts_ns1" |
sed -n 's/.*\(token:\)\([[:digit:]]*\).*$/\2/p;q')
ip netns exec ${listener_ns} ./pm_nl_ctl ann $addr token $tk id $id ip netns exec ${listener_ns} ./pm_nl_ctl ann $addr token $tk id $id
sleep 1 sleep 1
ip netns exec ${listener_ns} ./pm_nl_ctl rem token $tk id $id ip netns exec ${listener_ns} ./pm_nl_ctl rem token $tk id $id
...@@ -980,12 +992,6 @@ do_transfer() ...@@ -980,12 +992,6 @@ do_transfer()
kill $cappid kill $cappid
fi fi
if [ $userspace_pm -eq 1 ]; then
kill_wait $evts_ns1_pid
kill_wait $evts_ns2_pid
rm -rf $evts_ns1 $evts_ns2
fi
NSTAT_HISTORY=/tmp/${listener_ns}.nstat ip netns exec ${listener_ns} \ NSTAT_HISTORY=/tmp/${listener_ns}.nstat ip netns exec ${listener_ns} \
nstat | grep Tcp > /tmp/${listener_ns}.out nstat | grep Tcp > /tmp/${listener_ns}.out
NSTAT_HISTORY=/tmp/${connector_ns}.nstat ip netns exec ${connector_ns} \ NSTAT_HISTORY=/tmp/${connector_ns}.nstat ip netns exec ${connector_ns} \
...@@ -2507,6 +2513,57 @@ backup_tests() ...@@ -2507,6 +2513,57 @@ backup_tests()
fi fi
} }
LISTENER_CREATED=15 #MPTCP_EVENT_LISTENER_CREATED
LISTENER_CLOSED=16 #MPTCP_EVENT_LISTENER_CLOSED
AF_INET=2
AF_INET6=10
verify_listener_events()
{
local evt=$1
local e_type=$2
local e_family=$3
local e_saddr=$4
local e_sport=$5
local type
local family
local saddr
local sport
if [ $e_type = $LISTENER_CREATED ]; then
stdbuf -o0 -e0 printf "\t\t\t\t\t CREATE_LISTENER %s:%s"\
$e_saddr $e_sport
elif [ $e_type = $LISTENER_CLOSED ]; then
stdbuf -o0 -e0 printf "\t\t\t\t\t CLOSE_LISTENER %s:%s "\
$e_saddr $e_sport
fi
type=$(grep "type:$e_type," $evt |
sed --unbuffered -n 's/.*\(type:\)\([[:digit:]]*\).*$/\2/p;q')
family=$(grep "type:$e_type," $evt |
sed --unbuffered -n 's/.*\(family:\)\([[:digit:]]*\).*$/\2/p;q')
sport=$(grep "type:$e_type," $evt |
sed --unbuffered -n 's/.*\(sport:\)\([[:digit:]]*\).*$/\2/p;q')
if [ $family ] && [ $family = $AF_INET6 ]; then
saddr=$(grep "type:$e_type," $evt |
sed --unbuffered -n 's/.*\(saddr6:\)\([0-9a-f:.]*\).*$/\2/p;q')
else
saddr=$(grep "type:$e_type," $evt |
sed --unbuffered -n 's/.*\(saddr4:\)\([0-9.]*\).*$/\2/p;q')
fi
if [ $type ] && [ $type = $e_type ] &&
[ $family ] && [ $family = $e_family ] &&
[ $saddr ] && [ $saddr = $e_saddr ] &&
[ $sport ] && [ $sport = $e_sport ]; then
stdbuf -o0 -e0 printf "[ ok ]\n"
return 0
fi
fail_test
stdbuf -o0 -e0 printf "[fail]\n"
}
add_addr_ports_tests() add_addr_ports_tests()
{ {
# signal address with port # signal address with port
...@@ -2531,7 +2588,8 @@ add_addr_ports_tests() ...@@ -2531,7 +2588,8 @@ add_addr_ports_tests()
fi fi
# single address with port, remove # single address with port, remove
if reset "remove single address with port"; then # pm listener events
if reset_with_events "remove single address with port"; then
pm_nl_set_limits $ns1 0 1 pm_nl_set_limits $ns1 0 1
pm_nl_add_endpoint $ns1 10.0.2.1 flags signal port 10100 pm_nl_add_endpoint $ns1 10.0.2.1 flags signal port 10100
pm_nl_set_limits $ns2 1 1 pm_nl_set_limits $ns2 1 1
...@@ -2539,6 +2597,10 @@ add_addr_ports_tests() ...@@ -2539,6 +2597,10 @@ add_addr_ports_tests()
chk_join_nr 1 1 1 chk_join_nr 1 1 1
chk_add_nr 1 1 1 chk_add_nr 1 1 1
chk_rm_nr 1 1 invert 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
fi fi
# subflow and signal with port, remove # subflow and signal with port, remove
...@@ -2959,22 +3021,24 @@ userspace_tests() ...@@ -2959,22 +3021,24 @@ userspace_tests()
fi fi
# userspace pm add & remove address # userspace pm add & remove address
if reset "userspace pm add & remove address"; then if reset_with_events "userspace pm add & remove address"; then
set_userspace_pm $ns1 set_userspace_pm $ns1
pm_nl_set_limits $ns2 1 1 pm_nl_set_limits $ns2 1 1
run_tests $ns1 $ns2 10.0.1.1 0 userspace_1 0 slow run_tests $ns1 $ns2 10.0.1.1 0 userspace_1 0 slow
chk_join_nr 1 1 1 chk_join_nr 1 1 1
chk_add_nr 1 1 chk_add_nr 1 1
chk_rm_nr 1 1 invert chk_rm_nr 1 1 invert
kill_events_pids
fi fi
# userspace pm create destroy subflow # userspace pm create destroy subflow
if reset "userspace pm create destroy subflow"; then if reset_with_events "userspace pm create destroy subflow"; then
set_userspace_pm $ns2 set_userspace_pm $ns2
pm_nl_set_limits $ns1 0 1 pm_nl_set_limits $ns1 0 1
run_tests $ns1 $ns2 10.0.1.1 0 0 userspace_1 slow run_tests $ns1 $ns2 10.0.1.1 0 0 userspace_1 slow
chk_join_nr 1 1 1 chk_join_nr 1 1 1
chk_rm_nr 0 1 chk_rm_nr 0 1
kill_events_pids
fi fi
} }
......
...@@ -10,13 +10,19 @@ ksft_skip=4 ...@@ -10,13 +10,19 @@ ksft_skip=4
timeout_poll=30 timeout_poll=30
timeout_test=$((timeout_poll * 2 + 1)) timeout_test=$((timeout_poll * 2 + 1))
mptcp_connect="" mptcp_connect=""
do_all_tests=1
sec=$(date +%s)
rndh=$(printf %x $sec)-$(mktemp -u XXXXXX)
ns1="ns1-$rndh"
ns2="ns2-$rndh"
ns_sbox="ns_sbox-$rndh"
add_mark_rules() add_mark_rules()
{ {
local ns=$1 local ns=$1
local m=$2 local m=$2
local t
for t in iptables ip6tables; do for t in iptables ip6tables; do
# just to debug: check we have multiple subflows connection requests # just to debug: check we have multiple subflows connection requests
ip netns exec $ns $t -A OUTPUT -p tcp --syn -m mark --mark $m -j ACCEPT ip netns exec $ns $t -A OUTPUT -p tcp --syn -m mark --mark $m -j ACCEPT
...@@ -31,12 +37,7 @@ add_mark_rules() ...@@ -31,12 +37,7 @@ add_mark_rules()
init() init()
{ {
rndh=$(printf %x $sec)-$(mktemp -u XXXXXX) local netns
ns1="ns1-$rndh"
ns2="ns2-$rndh"
ns_sbox="ns_sbox-$rndh"
for netns in "$ns1" "$ns2" "$ns_sbox";do for netns in "$ns1" "$ns2" "$ns_sbox";do
ip netns add $netns || exit $ksft_skip ip netns add $netns || exit $ksft_skip
ip -net $netns link set lo up ip -net $netns link set lo up
...@@ -45,6 +46,7 @@ init() ...@@ -45,6 +46,7 @@ init()
ip netns exec $netns sysctl -q net.ipv4.conf.default.rp_filter=0 ip netns exec $netns sysctl -q net.ipv4.conf.default.rp_filter=0
done done
local i
for i in `seq 1 4`; do for i in `seq 1 4`; do
ip link add ns1eth$i netns "$ns1" type veth peer name ns2eth$i netns "$ns2" ip link add ns1eth$i netns "$ns1" type veth peer name ns2eth$i netns "$ns2"
ip -net "$ns1" addr add 10.0.$i.1/24 dev ns1eth$i ip -net "$ns1" addr add 10.0.$i.1/24 dev ns1eth$i
...@@ -74,6 +76,7 @@ init() ...@@ -74,6 +76,7 @@ init()
cleanup() cleanup()
{ {
local netns
for netns in "$ns1" "$ns2" "$ns_sbox"; do for netns in "$ns1" "$ns2" "$ns_sbox"; do
ip netns del $netns ip netns del $netns
done done
...@@ -104,15 +107,17 @@ check_mark() ...@@ -104,15 +107,17 @@ check_mark()
local ns=$1 local ns=$1
local af=$2 local af=$2
tables=iptables local tables=iptables
if [ $af -eq 6 ];then if [ $af -eq 6 ];then
tables=ip6tables tables=ip6tables
fi fi
local counters values
counters=$(ip netns exec $ns $tables -v -L OUTPUT | grep DROP) counters=$(ip netns exec $ns $tables -v -L OUTPUT | grep DROP)
values=${counters%DROP*} values=${counters%DROP*}
local v
for v in $values; do for v in $values; do
if [ $v -ne 0 ]; then if [ $v -ne 0 ]; then
echo "FAIL: got $tables $values in ns $ns , not 0 - not all expected packets marked" 1>&2 echo "FAIL: got $tables $values in ns $ns , not 0 - not all expected packets marked" 1>&2
...@@ -132,9 +137,9 @@ print_file_err() ...@@ -132,9 +137,9 @@ print_file_err()
check_transfer() check_transfer()
{ {
in=$1 local in=$1
out=$2 local out=$2
what=$3 local what=$3
cmp "$in" "$out" > /dev/null 2>&1 cmp "$in" "$out" > /dev/null 2>&1
if [ $? -ne 0 ] ;then if [ $? -ne 0 ] ;then
...@@ -157,18 +162,18 @@ is_v6() ...@@ -157,18 +162,18 @@ is_v6()
do_transfer() do_transfer()
{ {
listener_ns="$1" local listener_ns="$1"
connector_ns="$2" local connector_ns="$2"
cl_proto="$3" local cl_proto="$3"
srv_proto="$4" local srv_proto="$4"
connect_addr="$5" local connect_addr="$5"
port=12001 local port=12001
:> "$cout" :> "$cout"
:> "$sout" :> "$sout"
mptcp_connect="./mptcp_connect -r 20" local mptcp_connect="./mptcp_connect -r 20"
local local_addr local local_addr
if is_v6 "${connect_addr}"; then if is_v6 "${connect_addr}"; then
...@@ -181,7 +186,7 @@ do_transfer() ...@@ -181,7 +186,7 @@ do_transfer()
ip netns exec ${listener_ns} \ ip netns exec ${listener_ns} \
$mptcp_connect -t ${timeout_poll} -l -M 1 -p $port -s ${srv_proto} -c TIMESTAMPNS,TCPINQ \ $mptcp_connect -t ${timeout_poll} -l -M 1 -p $port -s ${srv_proto} -c TIMESTAMPNS,TCPINQ \
${local_addr} < "$sin" > "$sout" & ${local_addr} < "$sin" > "$sout" &
spid=$! local spid=$!
sleep 1 sleep 1
...@@ -190,12 +195,12 @@ do_transfer() ...@@ -190,12 +195,12 @@ do_transfer()
$mptcp_connect -t ${timeout_poll} -M 2 -p $port -s ${cl_proto} -c TIMESTAMPNS,TCPINQ \ $mptcp_connect -t ${timeout_poll} -M 2 -p $port -s ${cl_proto} -c TIMESTAMPNS,TCPINQ \
$connect_addr < "$cin" > "$cout" & $connect_addr < "$cin" > "$cout" &
cpid=$! local cpid=$!
wait $cpid wait $cpid
retc=$? local retc=$?
wait $spid wait $spid
rets=$? local rets=$?
if [ ${rets} -ne 0 ] || [ ${retc} -ne 0 ]; then if [ ${rets} -ne 0 ] || [ ${retc} -ne 0 ]; then
echo " client exit code $retc, server $rets" 1>&2 echo " client exit code $retc, server $rets" 1>&2
...@@ -230,9 +235,9 @@ do_transfer() ...@@ -230,9 +235,9 @@ do_transfer()
make_file() make_file()
{ {
name=$1 local name=$1
who=$2 local who=$2
size=$3 local size=$3
dd if=/dev/urandom of="$name" bs=1024 count=$size 2> /dev/null dd if=/dev/urandom of="$name" bs=1024 count=$size 2> /dev/null
echo -e "\nMPTCP_TEST_FILE_END_MARKER" >> "$name" echo -e "\nMPTCP_TEST_FILE_END_MARKER" >> "$name"
...@@ -265,9 +270,9 @@ do_mptcp_sockopt_tests() ...@@ -265,9 +270,9 @@ do_mptcp_sockopt_tests()
run_tests() run_tests()
{ {
listener_ns="$1" local listener_ns="$1"
connector_ns="$2" local connector_ns="$2"
connect_addr="$3" local connect_addr="$3"
local lret=0 local lret=0
do_transfer ${listener_ns} ${connector_ns} MPTCP MPTCP ${connect_addr} do_transfer ${listener_ns} ${connector_ns} MPTCP MPTCP ${connect_addr}
...@@ -282,8 +287,8 @@ run_tests() ...@@ -282,8 +287,8 @@ run_tests()
do_tcpinq_test() do_tcpinq_test()
{ {
ip netns exec "$ns1" ./mptcp_inq "$@" ip netns exec "$ns_sbox" ./mptcp_inq "$@"
lret=$? local lret=$?
if [ $lret -ne 0 ];then if [ $lret -ne 0 ];then
ret=$lret ret=$lret
echo "FAIL: mptcp_inq $@" 1>&2 echo "FAIL: mptcp_inq $@" 1>&2
...@@ -298,9 +303,7 @@ do_tcpinq_tests() ...@@ -298,9 +303,7 @@ do_tcpinq_tests()
{ {
local lret=0 local lret=0
ip netns exec "$ns1" iptables -F local args
ip netns exec "$ns1" ip6tables -F
for args in "-t tcp" "-r tcp"; do for args in "-t tcp" "-r tcp"; do
do_tcpinq_test $args do_tcpinq_test $args
lret=$? lret=$?
......
#!/bin/bash #!/bin/bash
# SPDX-License-Identifier: GPL-2.0 # SPDX-License-Identifier: GPL-2.0
sec=$(date +%s)
rndh=$(printf %x $sec)-$(mktemp -u XXXXXX) rndh=$(printf %x $sec)-$(mktemp -u XXXXXX)
ns1="ns1-$rndh" ns1="ns1-$rndh"
ns2="ns2-$rndh" ns2="ns2-$rndh"
...@@ -148,9 +149,6 @@ do_transfer() ...@@ -148,9 +149,6 @@ do_transfer()
:> "$sout" :> "$sout"
:> "$capout" :> "$capout"
local addr_port
addr_port=$(printf "%s:%d" ${connect_addr} ${port})
if $capture; then if $capture; then
local capuser local capuser
if [ -z $SUDO_USER ] ; then if [ -z $SUDO_USER ] ; then
......
...@@ -11,11 +11,17 @@ ANNOUNCED=6 # MPTCP_EVENT_ANNOUNCED ...@@ -11,11 +11,17 @@ ANNOUNCED=6 # MPTCP_EVENT_ANNOUNCED
REMOVED=7 # MPTCP_EVENT_REMOVED REMOVED=7 # MPTCP_EVENT_REMOVED
SUB_ESTABLISHED=10 # MPTCP_EVENT_SUB_ESTABLISHED SUB_ESTABLISHED=10 # MPTCP_EVENT_SUB_ESTABLISHED
SUB_CLOSED=11 # MPTCP_EVENT_SUB_CLOSED SUB_CLOSED=11 # MPTCP_EVENT_SUB_CLOSED
LISTENER_CREATED=15 #MPTCP_EVENT_LISTENER_CREATED
LISTENER_CLOSED=16 #MPTCP_EVENT_LISTENER_CLOSED
AF_INET=2 AF_INET=2
AF_INET6=10 AF_INET6=10
evts_pid=0 file=""
server_evts=""
client_evts=""
server_evts_pid=0
client_evts_pid=0
client4_pid=0 client4_pid=0
server4_pid=0 server4_pid=0
client6_pid=0 client6_pid=0
...@@ -33,7 +39,7 @@ client_addr_id=${RANDOM:0:2} ...@@ -33,7 +39,7 @@ client_addr_id=${RANDOM:0:2}
server_addr_id=${RANDOM:0:2} server_addr_id=${RANDOM:0:2}
sec=$(date +%s) sec=$(date +%s)
rndh=$(stdbuf -o0 -e0 printf %x "$sec")-$(mktemp -u XXXXXX) rndh=$(printf %x "$sec")-$(mktemp -u XXXXXX)
ns1="ns1-$rndh" ns1="ns1-$rndh"
ns2="ns2-$rndh" ns2="ns2-$rndh"
...@@ -47,7 +53,7 @@ cleanup() ...@@ -47,7 +53,7 @@ cleanup()
{ {
echo "cleanup" echo "cleanup"
rm -rf $file rm -rf $file $client_evts $server_evts
# Terminate the MPTCP connection and related processes # Terminate the MPTCP connection and related processes
if [ $client4_pid -ne 0 ]; then if [ $client4_pid -ne 0 ]; then
...@@ -62,8 +68,11 @@ cleanup() ...@@ -62,8 +68,11 @@ cleanup()
if [ $server6_pid -ne 0 ]; then if [ $server6_pid -ne 0 ]; then
kill_wait $server6_pid kill_wait $server6_pid
fi fi
if [ $evts_pid -ne 0 ]; then if [ $server_evts_pid -ne 0 ]; then
kill_wait $evts_pid kill_wait $server_evts_pid
fi
if [ $client_evts_pid -ne 0 ]; then
kill_wait $client_evts_pid
fi fi
local netns local netns
for netns in "$ns1" "$ns2" ;do for netns in "$ns1" "$ns2" ;do
...@@ -113,8 +122,9 @@ make_file() ...@@ -113,8 +122,9 @@ make_file()
make_connection() make_connection()
{ {
local file if [ -z "$file" ]; then
file=$(mktemp) file=$(mktemp)
fi
make_file "$file" "client" make_file "$file" "client"
local is_v6=$1 local is_v6=$1
...@@ -132,16 +142,24 @@ make_connection() ...@@ -132,16 +142,24 @@ make_connection()
# Capture netlink events over the two network namespaces running # Capture netlink events over the two network namespaces running
# the MPTCP client and server # the MPTCP client and server
local client_evts if [ -z "$client_evts" ]; then
client_evts=$(mktemp) client_evts=$(mktemp)
fi
:>"$client_evts" :>"$client_evts"
if [ $client_evts_pid -ne 0 ]; then
kill_wait $client_evts_pid
fi
ip netns exec "$ns2" ./pm_nl_ctl events >> "$client_evts" 2>&1 & ip netns exec "$ns2" ./pm_nl_ctl events >> "$client_evts" 2>&1 &
local client_evts_pid=$! client_evts_pid=$!
local server_evts if [ -z "$server_evts" ]; then
server_evts=$(mktemp) server_evts=$(mktemp)
fi
:>"$server_evts" :>"$server_evts"
if [ $server_evts_pid -ne 0 ]; then
kill_wait $server_evts_pid
fi
ip netns exec "$ns1" ./pm_nl_ctl events >> "$server_evts" 2>&1 & ip netns exec "$ns1" ./pm_nl_ctl events >> "$server_evts" 2>&1 &
local server_evts_pid=$! server_evts_pid=$!
sleep 0.5 sleep 0.5
# Run the server # Run the server
...@@ -159,7 +177,6 @@ make_connection() ...@@ -159,7 +177,6 @@ make_connection()
sleep 1 sleep 1
# Capture client/server attributes from MPTCP connection netlink events # Capture client/server attributes from MPTCP connection netlink events
kill_wait $client_evts_pid
local client_token local client_token
local client_port local client_port
...@@ -171,11 +188,10 @@ make_connection() ...@@ -171,11 +188,10 @@ make_connection()
client_port=$(sed --unbuffered -n 's/.*\(sport:\)\([[:digit:]]*\).*$/\2/p;q' "$client_evts") client_port=$(sed --unbuffered -n 's/.*\(sport:\)\([[:digit:]]*\).*$/\2/p;q' "$client_evts")
client_serverside=$(sed --unbuffered -n 's/.*\(server_side:\)\([[:digit:]]*\).*$/\2/p;q'\ client_serverside=$(sed --unbuffered -n 's/.*\(server_side:\)\([[:digit:]]*\).*$/\2/p;q'\
"$client_evts") "$client_evts")
kill_wait $server_evts_pid server_token=$(grep "type:1," "$server_evts" |
server_token=$(sed --unbuffered -n 's/.*\(token:\)\([[:digit:]]*\).*$/\2/p;q' "$server_evts") sed --unbuffered -n 's/.*\(token:\)\([[:digit:]]*\).*$/\2/p;q')
server_serverside=$(sed --unbuffered -n 's/.*\(server_side:\)\([[:digit:]]*\).*$/\2/p;q'\ server_serverside=$(grep "type:1," "$server_evts" |
"$server_evts") sed --unbuffered -n 's/.*\(server_side:\)\([[:digit:]]*\).*$/\2/p;q')
rm -f "$client_evts" "$server_evts" "$file"
if [ "$client_token" != "" ] && [ "$server_token" != "" ] && [ "$client_serverside" = 0 ] && if [ "$client_token" != "" ] && [ "$server_token" != "" ] && [ "$client_serverside" = 0 ] &&
[ "$server_serverside" = 1 ] [ "$server_serverside" = 1 ]
...@@ -239,13 +255,8 @@ verify_announce_event() ...@@ -239,13 +255,8 @@ verify_announce_event()
test_announce() test_announce()
{ {
local evts
evts=$(mktemp)
# Capture events on the network namespace running the server # Capture events on the network namespace running the server
:>"$evts" :>"$server_evts"
ip netns exec "$ns1" ./pm_nl_ctl events >> "$evts" 2>&1 &
evts_pid=$!
sleep 0.5
# ADD_ADDR using an invalid token should result in no action # ADD_ADDR using an invalid token should result in no action
local invalid_token=$(( client4_token - 1)) local invalid_token=$(( client4_token - 1))
...@@ -253,7 +264,7 @@ test_announce() ...@@ -253,7 +264,7 @@ test_announce()
$client_addr_id dev ns2eth1 > /dev/null 2>&1 $client_addr_id dev ns2eth1 > /dev/null 2>&1
local type local type
type=$(sed --unbuffered -n 's/.*\(type:\)\([[:digit:]]*\).*$/\2/p;q' "$evts") type=$(sed --unbuffered -n 's/.*\(type:\)\([[:digit:]]*\).*$/\2/p;q' "$server_evts")
stdbuf -o0 -e0 printf "ADD_ADDR 10.0.2.2 (ns2) => ns1, invalid token \t\t" stdbuf -o0 -e0 printf "ADD_ADDR 10.0.2.2 (ns2) => ns1, invalid token \t\t"
if [ "$type" = "" ] if [ "$type" = "" ]
then then
...@@ -264,71 +275,63 @@ test_announce() ...@@ -264,71 +275,63 @@ test_announce()
fi fi
# ADD_ADDR from the client to server machine reusing the subflow port # ADD_ADDR from the client to server machine reusing the subflow port
:>"$evts" :>"$server_evts"
ip netns exec "$ns2"\ ip netns exec "$ns2"\
./pm_nl_ctl ann 10.0.2.2 token "$client4_token" id $client_addr_id dev\ ./pm_nl_ctl ann 10.0.2.2 token "$client4_token" id $client_addr_id dev\
ns2eth1 > /dev/null 2>&1 ns2eth1 > /dev/null 2>&1
stdbuf -o0 -e0 printf "ADD_ADDR id:%d 10.0.2.2 (ns2) => ns1, reuse port \t\t" $client_addr_id stdbuf -o0 -e0 printf "ADD_ADDR id:%d 10.0.2.2 (ns2) => ns1, reuse port \t\t" $client_addr_id
sleep 0.5 sleep 0.5
verify_announce_event "$evts" "$ANNOUNCED" "$server4_token" "10.0.2.2" "$client_addr_id"\ verify_announce_event $server_evts $ANNOUNCED $server4_token "10.0.2.2" $client_addr_id \
"$client4_port" "$client4_port"
# ADD_ADDR6 from the client to server machine reusing the subflow port # ADD_ADDR6 from the client to server machine reusing the subflow port
:>"$evts" :>"$server_evts"
ip netns exec "$ns2" ./pm_nl_ctl ann\ ip netns exec "$ns2" ./pm_nl_ctl ann\
dead:beef:2::2 token "$client6_token" id $client_addr_id dev ns2eth1 > /dev/null 2>&1 dead:beef:2::2 token "$client6_token" id $client_addr_id dev ns2eth1 > /dev/null 2>&1
stdbuf -o0 -e0 printf "ADD_ADDR6 id:%d dead:beef:2::2 (ns2) => ns1, reuse port\t\t" $client_addr_id stdbuf -o0 -e0 printf "ADD_ADDR6 id:%d dead:beef:2::2 (ns2) => ns1, reuse port\t\t" $client_addr_id
sleep 0.5 sleep 0.5
verify_announce_event "$evts" "$ANNOUNCED" "$server6_token" "dead:beef:2::2"\ verify_announce_event "$server_evts" "$ANNOUNCED" "$server6_token" "dead:beef:2::2"\
"$client_addr_id" "$client6_port" "v6" "$client_addr_id" "$client6_port" "v6"
# ADD_ADDR from the client to server machine using a new port # ADD_ADDR from the client to server machine using a new port
:>"$evts" :>"$server_evts"
client_addr_id=$((client_addr_id+1)) client_addr_id=$((client_addr_id+1))
ip netns exec "$ns2" ./pm_nl_ctl ann 10.0.2.2 token "$client4_token" id\ ip netns exec "$ns2" ./pm_nl_ctl ann 10.0.2.2 token "$client4_token" id\
$client_addr_id dev ns2eth1 port $new4_port > /dev/null 2>&1 $client_addr_id dev ns2eth1 port $new4_port > /dev/null 2>&1
stdbuf -o0 -e0 printf "ADD_ADDR id:%d 10.0.2.2 (ns2) => ns1, new port \t\t\t" $client_addr_id stdbuf -o0 -e0 printf "ADD_ADDR id:%d 10.0.2.2 (ns2) => ns1, new port \t\t\t" $client_addr_id
sleep 0.5 sleep 0.5
verify_announce_event "$evts" "$ANNOUNCED" "$server4_token" "10.0.2.2"\ verify_announce_event "$server_evts" "$ANNOUNCED" "$server4_token" "10.0.2.2"\
"$client_addr_id" "$new4_port" "$client_addr_id" "$new4_port"
kill_wait $evts_pid
# Capture events on the network namespace running the client # Capture events on the network namespace running the client
:>"$evts" :>"$client_evts"
ip netns exec "$ns2" ./pm_nl_ctl events >> "$evts" 2>&1 &
evts_pid=$!
sleep 0.5
# ADD_ADDR from the server to client machine reusing the subflow port # ADD_ADDR from the server to client machine reusing the subflow port
ip netns exec "$ns1" ./pm_nl_ctl ann 10.0.2.1 token "$server4_token" id\ ip netns exec "$ns1" ./pm_nl_ctl ann 10.0.2.1 token "$server4_token" id\
$server_addr_id dev ns1eth2 > /dev/null 2>&1 $server_addr_id dev ns1eth2 > /dev/null 2>&1
stdbuf -o0 -e0 printf "ADD_ADDR id:%d 10.0.2.1 (ns1) => ns2, reuse port \t\t" $server_addr_id stdbuf -o0 -e0 printf "ADD_ADDR id:%d 10.0.2.1 (ns1) => ns2, reuse port \t\t" $server_addr_id
sleep 0.5 sleep 0.5
verify_announce_event "$evts" "$ANNOUNCED" "$client4_token" "10.0.2.1"\ verify_announce_event "$client_evts" "$ANNOUNCED" "$client4_token" "10.0.2.1"\
"$server_addr_id" "$app4_port" "$server_addr_id" "$app4_port"
# ADD_ADDR6 from the server to client machine reusing the subflow port # ADD_ADDR6 from the server to client machine reusing the subflow port
:>"$evts" :>"$client_evts"
ip netns exec "$ns1" ./pm_nl_ctl ann dead:beef:2::1 token "$server6_token" id\ ip netns exec "$ns1" ./pm_nl_ctl ann dead:beef:2::1 token "$server6_token" id\
$server_addr_id dev ns1eth2 > /dev/null 2>&1 $server_addr_id dev ns1eth2 > /dev/null 2>&1
stdbuf -o0 -e0 printf "ADD_ADDR6 id:%d dead:beef:2::1 (ns1) => ns2, reuse port\t\t" $server_addr_id stdbuf -o0 -e0 printf "ADD_ADDR6 id:%d dead:beef:2::1 (ns1) => ns2, reuse port\t\t" $server_addr_id
sleep 0.5 sleep 0.5
verify_announce_event "$evts" "$ANNOUNCED" "$client6_token" "dead:beef:2::1"\ verify_announce_event "$client_evts" "$ANNOUNCED" "$client6_token" "dead:beef:2::1"\
"$server_addr_id" "$app6_port" "v6" "$server_addr_id" "$app6_port" "v6"
# ADD_ADDR from the server to client machine using a new port # ADD_ADDR from the server to client machine using a new port
:>"$evts" :>"$client_evts"
server_addr_id=$((server_addr_id+1)) server_addr_id=$((server_addr_id+1))
ip netns exec "$ns1" ./pm_nl_ctl ann 10.0.2.1 token "$server4_token" id\ ip netns exec "$ns1" ./pm_nl_ctl ann 10.0.2.1 token "$server4_token" id\
$server_addr_id dev ns1eth2 port $new4_port > /dev/null 2>&1 $server_addr_id dev ns1eth2 port $new4_port > /dev/null 2>&1
stdbuf -o0 -e0 printf "ADD_ADDR id:%d 10.0.2.1 (ns1) => ns2, new port \t\t\t" $server_addr_id stdbuf -o0 -e0 printf "ADD_ADDR id:%d 10.0.2.1 (ns1) => ns2, new port \t\t\t" $server_addr_id
sleep 0.5 sleep 0.5
verify_announce_event "$evts" "$ANNOUNCED" "$client4_token" "10.0.2.1"\ verify_announce_event "$client_evts" "$ANNOUNCED" "$client4_token" "10.0.2.1"\
"$server_addr_id" "$new4_port" "$server_addr_id" "$new4_port"
kill_wait $evts_pid
rm -f "$evts"
} }
verify_remove_event() verify_remove_event()
...@@ -356,14 +359,8 @@ verify_remove_event() ...@@ -356,14 +359,8 @@ verify_remove_event()
test_remove() test_remove()
{ {
local evts
evts=$(mktemp)
# Capture events on the network namespace running the server # Capture events on the network namespace running the server
:>"$evts" :>"$server_evts"
ip netns exec "$ns1" ./pm_nl_ctl events >> "$evts" 2>&1 &
evts_pid=$!
sleep 0.5
# RM_ADDR using an invalid token should result in no action # RM_ADDR using an invalid token should result in no action
local invalid_token=$(( client4_token - 1 )) local invalid_token=$(( client4_token - 1 ))
...@@ -372,7 +369,7 @@ test_remove() ...@@ -372,7 +369,7 @@ test_remove()
stdbuf -o0 -e0 printf "RM_ADDR id:%d ns2 => ns1, invalid token \t"\ stdbuf -o0 -e0 printf "RM_ADDR id:%d ns2 => ns1, invalid token \t"\
$client_addr_id $client_addr_id
local type local type
type=$(sed --unbuffered -n 's/.*\(type:\)\([[:digit:]]*\).*$/\2/p;q' "$evts") type=$(sed --unbuffered -n 's/.*\(type:\)\([[:digit:]]*\).*$/\2/p;q' "$server_evts")
if [ "$type" = "" ] if [ "$type" = "" ]
then then
stdbuf -o0 -e0 printf "[OK]\n" stdbuf -o0 -e0 printf "[OK]\n"
...@@ -386,7 +383,7 @@ test_remove() ...@@ -386,7 +383,7 @@ test_remove()
$invalid_id > /dev/null 2>&1 $invalid_id > /dev/null 2>&1
stdbuf -o0 -e0 printf "RM_ADDR id:%d ns2 => ns1, invalid id \t"\ stdbuf -o0 -e0 printf "RM_ADDR id:%d ns2 => ns1, invalid id \t"\
$invalid_id $invalid_id
type=$(sed --unbuffered -n 's/.*\(type:\)\([[:digit:]]*\).*$/\2/p;q' "$evts") type=$(sed --unbuffered -n 's/.*\(type:\)\([[:digit:]]*\).*$/\2/p;q' "$server_evts")
if [ "$type" = "" ] if [ "$type" = "" ]
then then
stdbuf -o0 -e0 printf "[OK]\n" stdbuf -o0 -e0 printf "[OK]\n"
...@@ -395,40 +392,35 @@ test_remove() ...@@ -395,40 +392,35 @@ test_remove()
fi fi
# RM_ADDR from the client to server machine # RM_ADDR from the client to server machine
:>"$evts" :>"$server_evts"
ip netns exec "$ns2" ./pm_nl_ctl rem token "$client4_token" id\ ip netns exec "$ns2" ./pm_nl_ctl rem token "$client4_token" id\
$client_addr_id > /dev/null 2>&1 $client_addr_id > /dev/null 2>&1
stdbuf -o0 -e0 printf "RM_ADDR id:%d ns2 => ns1 \t"\ stdbuf -o0 -e0 printf "RM_ADDR id:%d ns2 => ns1 \t"\
$client_addr_id $client_addr_id
sleep 0.5 sleep 0.5
verify_remove_event "$evts" "$REMOVED" "$server4_token" "$client_addr_id" verify_remove_event "$server_evts" "$REMOVED" "$server4_token" "$client_addr_id"
# RM_ADDR from the client to server machine # RM_ADDR from the client to server machine
:>"$evts" :>"$server_evts"
client_addr_id=$(( client_addr_id - 1 )) client_addr_id=$(( client_addr_id - 1 ))
ip netns exec "$ns2" ./pm_nl_ctl rem token "$client4_token" id\ ip netns exec "$ns2" ./pm_nl_ctl rem token "$client4_token" id\
$client_addr_id > /dev/null 2>&1 $client_addr_id > /dev/null 2>&1
stdbuf -o0 -e0 printf "RM_ADDR id:%d ns2 => ns1 \t"\ stdbuf -o0 -e0 printf "RM_ADDR id:%d ns2 => ns1 \t"\
$client_addr_id $client_addr_id
sleep 0.5 sleep 0.5
verify_remove_event "$evts" "$REMOVED" "$server4_token" "$client_addr_id" verify_remove_event "$server_evts" "$REMOVED" "$server4_token" "$client_addr_id"
# RM_ADDR6 from the client to server machine # RM_ADDR6 from the client to server machine
:>"$evts" :>"$server_evts"
ip netns exec "$ns2" ./pm_nl_ctl rem token "$client6_token" id\ ip netns exec "$ns2" ./pm_nl_ctl rem token "$client6_token" id\
$client_addr_id > /dev/null 2>&1 $client_addr_id > /dev/null 2>&1
stdbuf -o0 -e0 printf "RM_ADDR6 id:%d ns2 => ns1 \t"\ stdbuf -o0 -e0 printf "RM_ADDR6 id:%d ns2 => ns1 \t"\
$client_addr_id $client_addr_id
sleep 0.5 sleep 0.5
verify_remove_event "$evts" "$REMOVED" "$server6_token" "$client_addr_id" verify_remove_event "$server_evts" "$REMOVED" "$server6_token" "$client_addr_id"
kill_wait $evts_pid
# Capture events on the network namespace running the client # Capture events on the network namespace running the client
:>"$evts" :>"$client_evts"
ip netns exec "$ns2" ./pm_nl_ctl events >> "$evts" 2>&1 &
evts_pid=$!
sleep 0.5
# RM_ADDR from the server to client machine # RM_ADDR from the server to client machine
ip netns exec "$ns1" ./pm_nl_ctl rem token "$server4_token" id\ ip netns exec "$ns1" ./pm_nl_ctl rem token "$server4_token" id\
...@@ -436,27 +428,24 @@ test_remove() ...@@ -436,27 +428,24 @@ test_remove()
stdbuf -o0 -e0 printf "RM_ADDR id:%d ns1 => ns2 \t"\ stdbuf -o0 -e0 printf "RM_ADDR id:%d ns1 => ns2 \t"\
$server_addr_id $server_addr_id
sleep 0.5 sleep 0.5
verify_remove_event "$evts" "$REMOVED" "$client4_token" "$server_addr_id" verify_remove_event "$client_evts" "$REMOVED" "$client4_token" "$server_addr_id"
# RM_ADDR from the server to client machine # RM_ADDR from the server to client machine
:>"$evts" :>"$client_evts"
server_addr_id=$(( server_addr_id - 1 )) server_addr_id=$(( server_addr_id - 1 ))
ip netns exec "$ns1" ./pm_nl_ctl rem token "$server4_token" id\ ip netns exec "$ns1" ./pm_nl_ctl rem token "$server4_token" id\
$server_addr_id > /dev/null 2>&1 $server_addr_id > /dev/null 2>&1
stdbuf -o0 -e0 printf "RM_ADDR id:%d ns1 => ns2 \t" $server_addr_id stdbuf -o0 -e0 printf "RM_ADDR id:%d ns1 => ns2 \t" $server_addr_id
sleep 0.5 sleep 0.5
verify_remove_event "$evts" "$REMOVED" "$client4_token" "$server_addr_id" verify_remove_event "$client_evts" "$REMOVED" "$client4_token" "$server_addr_id"
# RM_ADDR6 from the server to client machine # RM_ADDR6 from the server to client machine
:>"$evts" :>"$client_evts"
ip netns exec "$ns1" ./pm_nl_ctl rem token "$server6_token" id\ ip netns exec "$ns1" ./pm_nl_ctl rem token "$server6_token" id\
$server_addr_id > /dev/null 2>&1 $server_addr_id > /dev/null 2>&1
stdbuf -o0 -e0 printf "RM_ADDR6 id:%d ns1 => ns2 \t" $server_addr_id stdbuf -o0 -e0 printf "RM_ADDR6 id:%d ns1 => ns2 \t" $server_addr_id
sleep 0.5 sleep 0.5
verify_remove_event "$evts" "$REMOVED" "$client6_token" "$server_addr_id" verify_remove_event "$client_evts" "$REMOVED" "$client6_token" "$server_addr_id"
kill_wait $evts_pid
rm -f "$evts"
} }
verify_subflow_events() verify_subflow_events()
...@@ -532,13 +521,8 @@ verify_subflow_events() ...@@ -532,13 +521,8 @@ verify_subflow_events()
test_subflows() test_subflows()
{ {
local evts
evts=$(mktemp)
# Capture events on the network namespace running the server # Capture events on the network namespace running the server
:>"$evts" :>"$server_evts"
ip netns exec "$ns1" ./pm_nl_ctl events >> "$evts" 2>&1 &
evts_pid=$!
sleep 0.5
# Attempt to add a listener at 10.0.2.2:<subflow-port> # Attempt to add a listener at 10.0.2.2:<subflow-port>
ip netns exec "$ns2" ./pm_nl_ctl listen 10.0.2.2\ ip netns exec "$ns2" ./pm_nl_ctl listen 10.0.2.2\
...@@ -551,25 +535,25 @@ test_subflows() ...@@ -551,25 +535,25 @@ test_subflows()
sleep 0.5 sleep 0.5
# CREATE_SUBFLOW from server to client machine # CREATE_SUBFLOW from server to client machine
:>"$evts" :>"$server_evts"
ip netns exec "$ns1" ./pm_nl_ctl csf lip 10.0.2.1 lid 23 rip 10.0.2.2\ ip netns exec "$ns1" ./pm_nl_ctl csf lip 10.0.2.1 lid 23 rip 10.0.2.2\
rport "$client4_port" token "$server4_token" > /dev/null 2>&1 rport "$client4_port" token "$server4_token" > /dev/null 2>&1
sleep 0.5 sleep 0.5
verify_subflow_events "$evts" "$SUB_ESTABLISHED" "$server4_token" "$AF_INET" "10.0.2.1"\ verify_subflow_events $server_evts $SUB_ESTABLISHED $server4_token $AF_INET "10.0.2.1" \
"10.0.2.2" "$client4_port" "23" "$client_addr_id" "ns1" "ns2" "10.0.2.2" "$client4_port" "23" "$client_addr_id" "ns1" "ns2"
# Delete the listener from the client ns, if one was created # Delete the listener from the client ns, if one was created
kill_wait $listener_pid kill_wait $listener_pid
local sport local sport
sport=$(sed --unbuffered -n 's/.*\(sport:\)\([[:digit:]]*\).*$/\2/p;q' "$evts") sport=$(sed --unbuffered -n 's/.*\(sport:\)\([[:digit:]]*\).*$/\2/p;q' "$server_evts")
# DESTROY_SUBFLOW from server to client machine # DESTROY_SUBFLOW from server to client machine
:>"$evts" :>"$server_evts"
ip netns exec "$ns1" ./pm_nl_ctl dsf lip 10.0.2.1 lport "$sport" rip 10.0.2.2 rport\ ip netns exec "$ns1" ./pm_nl_ctl dsf lip 10.0.2.1 lport "$sport" rip 10.0.2.2 rport\
"$client4_port" token "$server4_token" > /dev/null 2>&1 "$client4_port" token "$server4_token" > /dev/null 2>&1
sleep 0.5 sleep 0.5
verify_subflow_events "$evts" "$SUB_CLOSED" "$server4_token" "$AF_INET" "10.0.2.1"\ verify_subflow_events "$server_evts" "$SUB_CLOSED" "$server4_token" "$AF_INET" "10.0.2.1"\
"10.0.2.2" "$client4_port" "23" "$client_addr_id" "ns1" "ns2" "10.0.2.2" "$client4_port" "23" "$client_addr_id" "ns1" "ns2"
# RM_ADDR from client to server machine # RM_ADDR from client to server machine
...@@ -583,31 +567,31 @@ test_subflows() ...@@ -583,31 +567,31 @@ test_subflows()
listener_pid=$! listener_pid=$!
# ADD_ADDR6 from client to server machine reusing the subflow port # ADD_ADDR6 from client to server machine reusing the subflow port
:>"$evts" :>"$server_evts"
ip netns exec "$ns2" ./pm_nl_ctl ann dead:beef:2::2 token "$client6_token" id\ ip netns exec "$ns2" ./pm_nl_ctl ann dead:beef:2::2 token "$client6_token" id\
$client_addr_id > /dev/null 2>&1 $client_addr_id > /dev/null 2>&1
sleep 0.5 sleep 0.5
# CREATE_SUBFLOW6 from server to client machine # CREATE_SUBFLOW6 from server to client machine
:>"$evts" :>"$server_evts"
ip netns exec "$ns1" ./pm_nl_ctl csf lip dead:beef:2::1 lid 23 rip\ ip netns exec "$ns1" ./pm_nl_ctl csf lip dead:beef:2::1 lid 23 rip\
dead:beef:2::2 rport "$client6_port" token "$server6_token" > /dev/null 2>&1 dead:beef:2::2 rport "$client6_port" token "$server6_token" > /dev/null 2>&1
sleep 0.5 sleep 0.5
verify_subflow_events "$evts" "$SUB_ESTABLISHED" "$server6_token" "$AF_INET6"\ verify_subflow_events "$server_evts" "$SUB_ESTABLISHED" "$server6_token" "$AF_INET6"\
"dead:beef:2::1" "dead:beef:2::2" "$client6_port" "23"\ "dead:beef:2::1" "dead:beef:2::2" "$client6_port" "23"\
"$client_addr_id" "ns1" "ns2" "$client_addr_id" "ns1" "ns2"
# Delete the listener from the client ns, if one was created # Delete the listener from the client ns, if one was created
kill_wait $listener_pid kill_wait $listener_pid
sport=$(sed --unbuffered -n 's/.*\(sport:\)\([[:digit:]]*\).*$/\2/p;q' "$evts") sport=$(sed --unbuffered -n 's/.*\(sport:\)\([[:digit:]]*\).*$/\2/p;q' "$server_evts")
# DESTROY_SUBFLOW6 from server to client machine # DESTROY_SUBFLOW6 from server to client machine
:>"$evts" :>"$server_evts"
ip netns exec "$ns1" ./pm_nl_ctl dsf lip dead:beef:2::1 lport "$sport" rip\ ip netns exec "$ns1" ./pm_nl_ctl dsf lip dead:beef:2::1 lport "$sport" rip\
dead:beef:2::2 rport "$client6_port" token "$server6_token" > /dev/null 2>&1 dead:beef:2::2 rport "$client6_port" token "$server6_token" > /dev/null 2>&1
sleep 0.5 sleep 0.5
verify_subflow_events "$evts" "$SUB_CLOSED" "$server6_token" "$AF_INET6"\ verify_subflow_events "$server_evts" "$SUB_CLOSED" "$server6_token" "$AF_INET6"\
"dead:beef:2::1" "dead:beef:2::2" "$client6_port" "23"\ "dead:beef:2::1" "dead:beef:2::2" "$client6_port" "23"\
"$client_addr_id" "ns1" "ns2" "$client_addr_id" "ns1" "ns2"
...@@ -622,44 +606,39 @@ test_subflows() ...@@ -622,44 +606,39 @@ test_subflows()
listener_pid=$! listener_pid=$!
# ADD_ADDR from client to server machine using a new port # ADD_ADDR from client to server machine using a new port
:>"$evts" :>"$server_evts"
ip netns exec "$ns2" ./pm_nl_ctl ann 10.0.2.2 token "$client4_token" id\ ip netns exec "$ns2" ./pm_nl_ctl ann 10.0.2.2 token "$client4_token" id\
$client_addr_id port $new4_port > /dev/null 2>&1 $client_addr_id port $new4_port > /dev/null 2>&1
sleep 0.5 sleep 0.5
# CREATE_SUBFLOW from server to client machine # CREATE_SUBFLOW from server to client machine
:>"$evts" :>"$server_evts"
ip netns exec "$ns1" ./pm_nl_ctl csf lip 10.0.2.1 lid 23 rip 10.0.2.2 rport\ ip netns exec "$ns1" ./pm_nl_ctl csf lip 10.0.2.1 lid 23 rip 10.0.2.2 rport\
$new4_port token "$server4_token" > /dev/null 2>&1 $new4_port token "$server4_token" > /dev/null 2>&1
sleep 0.5 sleep 0.5
verify_subflow_events "$evts" "$SUB_ESTABLISHED" "$server4_token" "$AF_INET"\ verify_subflow_events "$server_evts" "$SUB_ESTABLISHED" "$server4_token" "$AF_INET"\
"10.0.2.1" "10.0.2.2" "$new4_port" "23"\ "10.0.2.1" "10.0.2.2" "$new4_port" "23"\
"$client_addr_id" "ns1" "ns2" "$client_addr_id" "ns1" "ns2"
# Delete the listener from the client ns, if one was created # Delete the listener from the client ns, if one was created
kill_wait $listener_pid kill_wait $listener_pid
sport=$(sed --unbuffered -n 's/.*\(sport:\)\([[:digit:]]*\).*$/\2/p;q' "$evts") sport=$(sed --unbuffered -n 's/.*\(sport:\)\([[:digit:]]*\).*$/\2/p;q' "$server_evts")
# DESTROY_SUBFLOW from server to client machine # DESTROY_SUBFLOW from server to client machine
:>"$evts" :>"$server_evts"
ip netns exec "$ns1" ./pm_nl_ctl dsf lip 10.0.2.1 lport "$sport" rip 10.0.2.2 rport\ ip netns exec "$ns1" ./pm_nl_ctl dsf lip 10.0.2.1 lport "$sport" rip 10.0.2.2 rport\
$new4_port token "$server4_token" > /dev/null 2>&1 $new4_port token "$server4_token" > /dev/null 2>&1
sleep 0.5 sleep 0.5
verify_subflow_events "$evts" "$SUB_CLOSED" "$server4_token" "$AF_INET" "10.0.2.1"\ verify_subflow_events "$server_evts" "$SUB_CLOSED" "$server4_token" "$AF_INET" "10.0.2.1"\
"10.0.2.2" "$new4_port" "23" "$client_addr_id" "ns1" "ns2" "10.0.2.2" "$new4_port" "23" "$client_addr_id" "ns1" "ns2"
# RM_ADDR from client to server machine # RM_ADDR from client to server machine
ip netns exec "$ns2" ./pm_nl_ctl rem id $client_addr_id token\ ip netns exec "$ns2" ./pm_nl_ctl rem id $client_addr_id token\
"$client4_token" > /dev/null 2>&1 "$client4_token" > /dev/null 2>&1
kill_wait $evts_pid
# Capture events on the network namespace running the client # Capture events on the network namespace running the client
:>"$evts" :>"$client_evts"
ip netns exec "$ns2" ./pm_nl_ctl events >> "$evts" 2>&1 &
evts_pid=$!
sleep 0.5
# Attempt to add a listener at 10.0.2.1:<subflow-port> # Attempt to add a listener at 10.0.2.1:<subflow-port>
ip netns exec "$ns1" ./pm_nl_ctl listen 10.0.2.1\ ip netns exec "$ns1" ./pm_nl_ctl listen 10.0.2.1\
...@@ -672,24 +651,24 @@ test_subflows() ...@@ -672,24 +651,24 @@ test_subflows()
sleep 0.5 sleep 0.5
# CREATE_SUBFLOW from client to server machine # CREATE_SUBFLOW from client to server machine
:>"$evts" :>"$client_evts"
ip netns exec "$ns2" ./pm_nl_ctl csf lip 10.0.2.2 lid 23 rip 10.0.2.1 rport\ ip netns exec "$ns2" ./pm_nl_ctl csf lip 10.0.2.2 lid 23 rip 10.0.2.1 rport\
$app4_port token "$client4_token" > /dev/null 2>&1 $app4_port token "$client4_token" > /dev/null 2>&1
sleep 0.5 sleep 0.5
verify_subflow_events "$evts" "$SUB_ESTABLISHED" "$client4_token" "$AF_INET" "10.0.2.2"\ verify_subflow_events $client_evts $SUB_ESTABLISHED $client4_token $AF_INET "10.0.2.2"\
"10.0.2.1" "$app4_port" "23" "$server_addr_id" "ns2" "ns1" "10.0.2.1" "$app4_port" "23" "$server_addr_id" "ns2" "ns1"
# Delete the listener from the server ns, if one was created # Delete the listener from the server ns, if one was created
kill_wait $listener_pid kill_wait $listener_pid
sport=$(sed --unbuffered -n 's/.*\(sport:\)\([[:digit:]]*\).*$/\2/p;q' "$evts") sport=$(sed --unbuffered -n 's/.*\(sport:\)\([[:digit:]]*\).*$/\2/p;q' "$client_evts")
# DESTROY_SUBFLOW from client to server machine # DESTROY_SUBFLOW from client to server machine
:>"$evts" :>"$client_evts"
ip netns exec "$ns2" ./pm_nl_ctl dsf lip 10.0.2.2 lport "$sport" rip 10.0.2.1 rport\ ip netns exec "$ns2" ./pm_nl_ctl dsf lip 10.0.2.2 lport "$sport" rip 10.0.2.1 rport\
$app4_port token "$client4_token" > /dev/null 2>&1 $app4_port token "$client4_token" > /dev/null 2>&1
sleep 0.5 sleep 0.5
verify_subflow_events "$evts" "$SUB_CLOSED" "$client4_token" "$AF_INET" "10.0.2.2"\ verify_subflow_events "$client_evts" "$SUB_CLOSED" "$client4_token" "$AF_INET" "10.0.2.2"\
"10.0.2.1" "$app4_port" "23" "$server_addr_id" "ns2" "ns1" "10.0.2.1" "$app4_port" "23" "$server_addr_id" "ns2" "ns1"
# RM_ADDR from server to client machine # RM_ADDR from server to client machine
...@@ -703,17 +682,17 @@ test_subflows() ...@@ -703,17 +682,17 @@ test_subflows()
listener_pid=$! listener_pid=$!
# ADD_ADDR6 from server to client machine reusing the subflow port # ADD_ADDR6 from server to client machine reusing the subflow port
:>"$evts" :>"$client_evts"
ip netns exec "$ns1" ./pm_nl_ctl ann dead:beef:2::1 token "$server6_token" id\ ip netns exec "$ns1" ./pm_nl_ctl ann dead:beef:2::1 token "$server6_token" id\
$server_addr_id > /dev/null 2>&1 $server_addr_id > /dev/null 2>&1
sleep 0.5 sleep 0.5
# CREATE_SUBFLOW6 from client to server machine # CREATE_SUBFLOW6 from client to server machine
:>"$evts" :>"$client_evts"
ip netns exec "$ns2" ./pm_nl_ctl csf lip dead:beef:2::2 lid 23 rip\ ip netns exec "$ns2" ./pm_nl_ctl csf lip dead:beef:2::2 lid 23 rip\
dead:beef:2::1 rport $app6_port token "$client6_token" > /dev/null 2>&1 dead:beef:2::1 rport $app6_port token "$client6_token" > /dev/null 2>&1
sleep 0.5 sleep 0.5
verify_subflow_events "$evts" "$SUB_ESTABLISHED" "$client6_token"\ verify_subflow_events "$client_evts" "$SUB_ESTABLISHED" "$client6_token"\
"$AF_INET6" "dead:beef:2::2"\ "$AF_INET6" "dead:beef:2::2"\
"dead:beef:2::1" "$app6_port" "23"\ "dead:beef:2::1" "$app6_port" "23"\
"$server_addr_id" "ns2" "ns1" "$server_addr_id" "ns2" "ns1"
...@@ -721,14 +700,14 @@ test_subflows() ...@@ -721,14 +700,14 @@ test_subflows()
# Delete the listener from the server ns, if one was created # Delete the listener from the server ns, if one was created
kill_wait $listener_pid kill_wait $listener_pid
sport=$(sed --unbuffered -n 's/.*\(sport:\)\([[:digit:]]*\).*$/\2/p;q' "$evts") sport=$(sed --unbuffered -n 's/.*\(sport:\)\([[:digit:]]*\).*$/\2/p;q' "$client_evts")
# DESTROY_SUBFLOW6 from client to server machine # DESTROY_SUBFLOW6 from client to server machine
:>"$evts" :>"$client_evts"
ip netns exec "$ns2" ./pm_nl_ctl dsf lip dead:beef:2::2 lport "$sport" rip\ ip netns exec "$ns2" ./pm_nl_ctl dsf lip dead:beef:2::2 lport "$sport" rip\
dead:beef:2::1 rport $app6_port token "$client6_token" > /dev/null 2>&1 dead:beef:2::1 rport $app6_port token "$client6_token" > /dev/null 2>&1
sleep 0.5 sleep 0.5
verify_subflow_events "$evts" "$SUB_CLOSED" "$client6_token" "$AF_INET6" "dead:beef:2::2"\ verify_subflow_events $client_evts $SUB_CLOSED $client6_token $AF_INET6 "dead:beef:2::2"\
"dead:beef:2::1" "$app6_port" "23" "$server_addr_id" "ns2" "ns1" "dead:beef:2::1" "$app6_port" "23" "$server_addr_id" "ns2" "ns1"
# RM_ADDR6 from server to client machine # RM_ADDR6 from server to client machine
...@@ -742,38 +721,35 @@ test_subflows() ...@@ -742,38 +721,35 @@ test_subflows()
listener_pid=$! listener_pid=$!
# ADD_ADDR from server to client machine using a new port # ADD_ADDR from server to client machine using a new port
:>"$evts" :>"$client_evts"
ip netns exec "$ns1" ./pm_nl_ctl ann 10.0.2.1 token "$server4_token" id\ ip netns exec "$ns1" ./pm_nl_ctl ann 10.0.2.1 token "$server4_token" id\
$server_addr_id port $new4_port > /dev/null 2>&1 $server_addr_id port $new4_port > /dev/null 2>&1
sleep 0.5 sleep 0.5
# CREATE_SUBFLOW from client to server machine # CREATE_SUBFLOW from client to server machine
:>"$evts" :>"$client_evts"
ip netns exec "$ns2" ./pm_nl_ctl csf lip 10.0.2.2 lid 23 rip 10.0.2.1 rport\ ip netns exec "$ns2" ./pm_nl_ctl csf lip 10.0.2.2 lid 23 rip 10.0.2.1 rport\
$new4_port token "$client4_token" > /dev/null 2>&1 $new4_port token "$client4_token" > /dev/null 2>&1
sleep 0.5 sleep 0.5
verify_subflow_events "$evts" "$SUB_ESTABLISHED" "$client4_token" "$AF_INET"\ verify_subflow_events "$client_evts" "$SUB_ESTABLISHED" "$client4_token" "$AF_INET"\
"10.0.2.2" "10.0.2.1" "$new4_port" "23" "$server_addr_id" "ns2" "ns1" "10.0.2.2" "10.0.2.1" "$new4_port" "23" "$server_addr_id" "ns2" "ns1"
# Delete the listener from the server ns, if one was created # Delete the listener from the server ns, if one was created
kill_wait $listener_pid kill_wait $listener_pid
sport=$(sed --unbuffered -n 's/.*\(sport:\)\([[:digit:]]*\).*$/\2/p;q' "$evts") sport=$(sed --unbuffered -n 's/.*\(sport:\)\([[:digit:]]*\).*$/\2/p;q' "$client_evts")
# DESTROY_SUBFLOW from client to server machine # DESTROY_SUBFLOW from client to server machine
:>"$evts" :>"$client_evts"
ip netns exec "$ns2" ./pm_nl_ctl dsf lip 10.0.2.2 lport "$sport" rip 10.0.2.1 rport\ ip netns exec "$ns2" ./pm_nl_ctl dsf lip 10.0.2.2 lport "$sport" rip 10.0.2.1 rport\
$new4_port token "$client4_token" > /dev/null 2>&1 $new4_port token "$client4_token" > /dev/null 2>&1
sleep 0.5 sleep 0.5
verify_subflow_events "$evts" "$SUB_CLOSED" "$client4_token" "$AF_INET" "10.0.2.2"\ verify_subflow_events "$client_evts" "$SUB_CLOSED" "$client4_token" "$AF_INET" "10.0.2.2"\
"10.0.2.1" "$new4_port" "23" "$server_addr_id" "ns2" "ns1" "10.0.2.1" "$new4_port" "23" "$server_addr_id" "ns2" "ns1"
# RM_ADDR from server to client machine # RM_ADDR from server to client machine
ip netns exec "$ns1" ./pm_nl_ctl rem id $server_addr_id token\ ip netns exec "$ns1" ./pm_nl_ctl rem id $server_addr_id token\
"$server4_token" > /dev/null 2>&1 "$server4_token" > /dev/null 2>&1
kill_wait $evts_pid
rm -f "$evts"
} }
test_prio() test_prio()
...@@ -807,11 +783,85 @@ test_prio() ...@@ -807,11 +783,85 @@ test_prio()
fi fi
} }
verify_listener_events()
{
local evt=$1
local e_type=$2
local e_family=$3
local e_saddr=$4
local e_sport=$5
local type
local family
local saddr
local sport
if [ $e_type = $LISTENER_CREATED ]; then
stdbuf -o0 -e0 printf "CREATE_LISTENER %s:%s\t\t\t\t\t"\
$e_saddr $e_sport
elif [ $e_type = $LISTENER_CLOSED ]; then
stdbuf -o0 -e0 printf "CLOSE_LISTENER %s:%s\t\t\t\t\t"\
$e_saddr $e_sport
fi
type=$(grep "type:$e_type," $evt |
sed --unbuffered -n 's/.*\(type:\)\([[:digit:]]*\).*$/\2/p;q')
family=$(grep "type:$e_type," $evt |
sed --unbuffered -n 's/.*\(family:\)\([[:digit:]]*\).*$/\2/p;q')
sport=$(grep "type:$e_type," $evt |
sed --unbuffered -n 's/.*\(sport:\)\([[:digit:]]*\).*$/\2/p;q')
if [ $family ] && [ $family = $AF_INET6 ]; then
saddr=$(grep "type:$e_type," $evt |
sed --unbuffered -n 's/.*\(saddr6:\)\([0-9a-f:.]*\).*$/\2/p;q')
else
saddr=$(grep "type:$e_type," $evt |
sed --unbuffered -n 's/.*\(saddr4:\)\([0-9.]*\).*$/\2/p;q')
fi
if [ $type ] && [ $type = $e_type ] &&
[ $family ] && [ $family = $e_family ] &&
[ $saddr ] && [ $saddr = $e_saddr ] &&
[ $sport ] && [ $sport = $e_sport ]; then
stdbuf -o0 -e0 printf "[OK]\n"
return 0
fi
stdbuf -o0 -e0 printf "[FAIL]\n"
exit 1
}
test_listener()
{
# Capture events on the network namespace running the client
:>$client_evts
# Attempt to add a listener at 10.0.2.2:<subflow-port>
ip netns exec $ns2 ./pm_nl_ctl listen 10.0.2.2\
$client4_port > /dev/null 2>&1 &
local listener_pid=$!
verify_listener_events $client_evts $LISTENER_CREATED $AF_INET 10.0.2.2 $client4_port
# ADD_ADDR from client to server machine reusing the subflow port
ip netns exec $ns2 ./pm_nl_ctl ann 10.0.2.2 token $client4_token id\
$client_addr_id > /dev/null 2>&1
sleep 0.5
# CREATE_SUBFLOW from server to client machine
ip netns exec $ns1 ./pm_nl_ctl csf lip 10.0.2.1 lid 23 rip 10.0.2.2\
rport $client4_port token $server4_token > /dev/null 2>&1
sleep 0.5
# Delete the listener from the client ns, if one was created
kill_wait $listener_pid
verify_listener_events $client_evts $LISTENER_CLOSED $AF_INET 10.0.2.2 $client4_port
}
make_connection make_connection
make_connection "v6" make_connection "v6"
test_announce test_announce
test_remove test_remove
test_subflows test_subflows
test_prio test_prio
test_listener
exit 0 exit 0
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment