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
......
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