@@ -285,36 +285,33 @@ static void send_data(int lfd, int fd)
#define ADDR_1 "10.0.1.1"
#define ADDR_2 "10.0.1.2"
-static void sched_init(char *flags, char *sched)
+static struct nstoken *sched_init(char *flags, char *sched)
{
- char cmd[64];
-
- system("ip link add veth1 type veth peer name veth2");
- snprintf(cmd, sizeof(cmd), "ip addr add %s/24 dev veth1", ADDR_1);
- system(cmd);
- system("ip link set veth1 up");
- snprintf(cmd, sizeof(cmd), "ip addr add %s/24 dev veth2", ADDR_2);
- system(cmd);
- system("ip link set veth2 up");
-
- snprintf(cmd, sizeof(cmd), "ip mptcp endpoint add %s %s", ADDR_2, flags);
- system(cmd);
- snprintf(cmd, sizeof(cmd), "sysctl -qw net.mptcp.scheduler=%s", sched);
- system(cmd);
-}
+ struct nstoken *nstoken;
-static void sched_cleanup(void)
-{
- system("sysctl -qw net.mptcp.scheduler=default");
- system("ip mptcp endpoint flush");
- system("ip link del veth1");
+ nstoken = create_netns();
+ if (!ASSERT_OK_PTR(nstoken, "create_netns"))
+ goto fail;
+
+ SYS(fail, "ip -net %s link add veth1 type veth peer name veth2", NS_TEST);
+ SYS(fail, "ip -net %s addr add %s/24 dev veth1", NS_TEST, ADDR_1);
+ SYS(fail, "ip -net %s link set dev veth1 up", NS_TEST);
+ SYS(fail, "ip -net %s addr add %s/24 dev veth2", NS_TEST, ADDR_2);
+ SYS(fail, "ip -net %s link set dev veth2 up", NS_TEST);
+ SYS(fail, "ip -net %s mptcp endpoint add %s %s", NS_TEST, ADDR_2, flags);
+ SYS(fail, "ip netns exec %s sysctl -qw net.mptcp.scheduler=%s", NS_TEST, sched);
+
+ return nstoken;
+fail:
+ return NULL;
}
static int has_bytes_sent(char *addr)
{
- char cmd[64];
+ char cmd[128];
- snprintf(cmd, sizeof(cmd), "ss -it dst %s | grep -q 'bytes_sent:'", addr);
+ snprintf(cmd, sizeof(cmd), "ip netns exec %s ss -it dst %s | grep -q bytes_sent:",
+ NS_TEST, addr);
return system(cmd);
}
@@ -322,6 +319,7 @@ static void test_first(void)
{
struct mptcp_bpf_first *first_skel;
int server_fd, client_fd;
+ struct nstoken *nstoken;
struct bpf_link *link;
first_skel = mptcp_bpf_first__open_and_load();
@@ -334,7 +332,9 @@ static void test_first(void)
return;
}
- sched_init("subflow", "bpf_first");
+ nstoken = sched_init("subflow", "bpf_first");
+ if (!ASSERT_OK_PTR(nstoken, "sched_init:bpf_first"))
+ goto fail;
server_fd = start_mptcp_server(AF_INET, ADDR_1, 0, 0);
client_fd = connect_to_fd(server_fd, 0);
@@ -344,7 +344,8 @@ static void test_first(void)
close(client_fd);
close(server_fd);
- sched_cleanup();
+fail:
+ cleanup_netns(nstoken);
bpf_link__destroy(link);
mptcp_bpf_first__destroy(first_skel);
}
Run mptcp sched test in a dedicated netns. Signed-off-by: Geliang Tang <geliang.tang@suse.com> --- .../testing/selftests/bpf/prog_tests/mptcp.c | 51 ++++++++++--------- 1 file changed, 26 insertions(+), 25 deletions(-)