Skip to content

Commit df62f2e

Browse files
Paolo Abenidavem330
authored andcommitted
selftests/mptcp: add diag interface tests
basic functional test, triggering the msk diag interface code. Require appropriate iproute2 support, skip elsewhere. Reviewed-by: Mat Martineau <mathew.j.martineau@linux.intel.com> Signed-off-by: Paolo Abeni <pabeni@redhat.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent ac3b45f commit df62f2e

3 files changed

Lines changed: 140 additions & 5 deletions

File tree

‎tools/testing/selftests/net/mptcp/Makefile‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ KSFT_KHDR_INSTALL := 1
55

66
CFLAGS = -Wall -Wl,--no-as-needed -O2 -g -I$(top_srcdir)/usr/include
77

8-
TEST_PROGS := mptcp_connect.sh pm_netlink.sh mptcp_join.sh
8+
TEST_PROGS := mptcp_connect.sh pm_netlink.sh mptcp_join.sh diag.sh
99

1010
TEST_GEN_FILES = mptcp_connect pm_nl_ctl
1111

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
#!/bin/bash
2+
# SPDX-License-Identifier: GPL-2.0
3+
4+
rndh=$(printf %x $sec)-$(mktemp -u XXXXXX)
5+
ns="ns1-$rndh"
6+
ksft_skip=4
7+
test_cnt=1
8+
ret=0
9+
pids=()
10+
11+
flush_pids()
12+
{
13+
# mptcp_connect in join mode will sleep a bit before completing,
14+
# give it some time
15+
sleep 1.1
16+
17+
for pid in ${pids[@]}; do
18+
[ -d /proc/$pid ] && kill -SIGUSR1 $pid >/dev/null 2>&1
19+
done
20+
pids=()
21+
}
22+
23+
cleanup()
24+
{
25+
ip netns del $ns
26+
for pid in ${pids[@]}; do
27+
[ -d /proc/$pid ] && kill -9 $pid >/dev/null 2>&1
28+
done
29+
}
30+
31+
ip -Version > /dev/null 2>&1
32+
if [ $? -ne 0 ];then
33+
echo "SKIP: Could not run test without ip tool"
34+
exit $ksft_skip
35+
fi
36+
ss -h | grep -q MPTCP
37+
if [ $? -ne 0 ];then
38+
echo "SKIP: ss tool does not support MPTCP"
39+
exit $ksft_skip
40+
fi
41+
42+
__chk_nr()
43+
{
44+
local condition="$1"
45+
local expected=$2
46+
local msg nr
47+
48+
shift 2
49+
msg=$*
50+
nr=$(ss -inmHMN $ns | $condition)
51+
52+
printf "%-50s" "$msg"
53+
if [ $nr != $expected ]; then
54+
echo "[ fail ] expected $expected found $nr"
55+
ret=$test_cnt
56+
else
57+
echo "[ ok ]"
58+
fi
59+
test_cnt=$((test_cnt+1))
60+
}
61+
62+
chk_msk_nr()
63+
{
64+
__chk_nr "grep -c token:" $*
65+
}
66+
67+
chk_msk_fallback_nr()
68+
{
69+
__chk_nr "grep -c fallback" $*
70+
}
71+
72+
chk_msk_remote_key_nr()
73+
{
74+
__chk_nr "grep -c remote_key" $*
75+
}
76+
77+
78+
trap cleanup EXIT
79+
ip netns add $ns
80+
ip -n $ns link set dev lo up
81+
82+
echo "a" | ip netns exec $ns ./mptcp_connect -p 10000 -l 0.0.0.0 -t 100 >/dev/null &
83+
sleep 0.1
84+
pids[0]=$!
85+
chk_msk_nr 0 "no msk on netns creation"
86+
87+
echo "b" | ip netns exec $ns ./mptcp_connect -p 10000 127.0.0.1 -j -t 100 >/dev/null &
88+
sleep 0.1
89+
pids[1]=$!
90+
chk_msk_nr 2 "after MPC handshake "
91+
chk_msk_remote_key_nr 2 "....chk remote_key"
92+
chk_msk_fallback_nr 0 "....chk no fallback"
93+
flush_pids
94+
95+
96+
echo "a" | ip netns exec $ns ./mptcp_connect -p 10001 -s TCP -l 0.0.0.0 -t 100 >/dev/null &
97+
pids[0]=$!
98+
sleep 0.1
99+
echo "b" | ip netns exec $ns ./mptcp_connect -p 10001 127.0.0.1 -j -t 100 >/dev/null &
100+
pids[1]=$!
101+
sleep 0.1
102+
chk_msk_fallback_nr 1 "check fallback"
103+
flush_pids
104+
105+
NR_CLIENTS=100
106+
for I in `seq 1 $NR_CLIENTS`; do
107+
echo "a" | ip netns exec $ns ./mptcp_connect -p $((I+10001)) -l 0.0.0.0 -t 100 -w 10 >/dev/null &
108+
pids[$((I*2))]=$!
109+
done
110+
sleep 0.1
111+
112+
for I in `seq 1 $NR_CLIENTS`; do
113+
echo "b" | ip netns exec $ns ./mptcp_connect -p $((I+10001)) 127.0.0.1 -t 100 -w 10 >/dev/null &
114+
pids[$((I*2 + 1))]=$!
115+
done
116+
sleep 1.5
117+
118+
chk_msk_nr $((NR_CLIENTS*2)) "many msk socket present"
119+
flush_pids
120+
121+
exit $ret

‎tools/testing/selftests/net/mptcp/mptcp_connect.c‎

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include <stdio.h>
1212
#include <stdlib.h>
1313
#include <strings.h>
14+
#include <signal.h>
1415
#include <unistd.h>
1516

1617
#include <sys/poll.h>
@@ -36,6 +37,7 @@ extern int optind;
3637

3738
static int poll_timeout = 10 * 1000;
3839
static bool listen_mode;
40+
static bool quit;
3941

4042
enum cfg_mode {
4143
CFG_MODE_POLL,
@@ -52,11 +54,12 @@ static int pf = AF_INET;
5254
static int cfg_sndbuf;
5355
static int cfg_rcvbuf;
5456
static bool cfg_join;
57+
static int cfg_wait;
5558

5659
static void die_usage(void)
5760
{
5861
fprintf(stderr, "Usage: mptcp_connect [-6] [-u] [-s MPTCP|TCP] [-p port] [-m mode]"
59-
"[-l] connect_address\n");
62+
"[-l] [-w sec] connect_address\n");
6063
fprintf(stderr, "\t-6 use ipv6\n");
6164
fprintf(stderr, "\t-t num -- set poll timeout to num\n");
6265
fprintf(stderr, "\t-S num -- set SO_SNDBUF to num\n");
@@ -65,9 +68,15 @@ static void die_usage(void)
6568
fprintf(stderr, "\t-m [MPTCP|TCP] -- use tcp or mptcp sockets\n");
6669
fprintf(stderr, "\t-s [mmap|poll] -- use poll (default) or mmap\n");
6770
fprintf(stderr, "\t-u -- check mptcp ulp\n");
71+
fprintf(stderr, "\t-w num -- wait num sec before closing the socket\n");
6872
exit(1);
6973
}
7074

75+
static void handle_signal(int nr)
76+
{
77+
quit = true;
78+
}
79+
7180
static const char *getxinfo_strerr(int err)
7281
{
7382
if (err == EAI_SYSTEM)
@@ -418,8 +427,8 @@ static int copyfd_io_poll(int infd, int peerfd, int outfd)
418427
}
419428

420429
/* leave some time for late join/announce */
421-
if (cfg_join)
422-
usleep(400000);
430+
if (cfg_wait)
431+
usleep(cfg_wait);
423432

424433
close(peerfd);
425434
return 0;
@@ -812,11 +821,12 @@ static void parse_opts(int argc, char **argv)
812821
{
813822
int c;
814823

815-
while ((c = getopt(argc, argv, "6jlp:s:hut:m:S:R:")) != -1) {
824+
while ((c = getopt(argc, argv, "6jlp:s:hut:m:S:R:w:")) != -1) {
816825
switch (c) {
817826
case 'j':
818827
cfg_join = true;
819828
cfg_mode = CFG_MODE_POLL;
829+
cfg_wait = 400000;
820830
break;
821831
case 'l':
822832
listen_mode = true;
@@ -850,6 +860,9 @@ static void parse_opts(int argc, char **argv)
850860
case 'R':
851861
cfg_rcvbuf = parse_int(optarg);
852862
break;
863+
case 'w':
864+
cfg_wait = atoi(optarg)*1000000;
865+
break;
853866
}
854867
}
855868

@@ -865,6 +878,7 @@ int main(int argc, char *argv[])
865878
{
866879
init_rng();
867880

881+
signal(SIGUSR1, handle_signal);
868882
parse_opts(argc, argv);
869883

870884
if (tcpulp_audit)

0 commit comments

Comments
 (0)