Skip to contentSkip to conversation

selftests/bpf: run mptcp in a dedicated netns

PATCH Superseded Hangbin Liu 3 participants 3 messages Feb 17, 2023

Subsystems (6)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 selftests/bpf: run mptcp in a dedicated netns

The current mptcp test is run in init netns. If the user or default system config disabled mptcp, the test will fail. Let's run the mptcp test in a dedicated netns to avoid none kernel default mptcp setting.

---
 .../testing/selftests/bpf/prog_tests/mptcp.c  | 24 +++++++++++++++++++
 1 file changed, 24 insertions(+)
tools/testing/selftests/bpf/prog_tests/mptcp.c +24 -0
index 59f08d6d1d53..8a4ed9510ec7 100644
@@ -7,6 +7,16 @@
 #include "network_helpers.h"
 #include "mptcp_sock.skel.h"
 
+#define SYS(fmt, ...)						\
+	({							\
+		char cmd[1024];					\
+		snprintf(cmd, sizeof(cmd), fmt, ##__VA_ARGS__);	\
+		if (!ASSERT_OK(system(cmd), cmd))		\
+			goto cmd_fail;				\
+	})
+
+#define NS_TEST "mptcp_ns"
+
 #ifndef TCP_CA_NAME_MAX
 #define TCP_CA_NAME_MAX	16
 #endif
@@ -138,12 +148,20 @@ static int run_test(int cgroup_fd, int server_fd, bool is_mptcp)
 
 static void test_base(void)
 {
+	struct nstoken *nstoken = NULL;
 	int server_fd, cgroup_fd;
 
 	cgroup_fd = test__join_cgroup("/mptcp");
 	if (!ASSERT_GE(cgroup_fd, 0, "test__join_cgroup"))
 		return;
 
+	SYS("ip netns add %s", NS_TEST);
+	SYS("ip -net %s link set dev lo up", NS_TEST);
+
+	nstoken = open_netns(NS_TEST);
+	if (!ASSERT_OK_PTR(nstoken, "open_netns"))
+		goto cmd_fail;
+
 	/* without MPTCP */
 	server_fd = start_server(AF_INET, SOCK_STREAM, NULL, 0, 0);
 	if (!ASSERT_GE(server_fd, 0, "start_server"))
@@ -163,6 +181,12 @@ static void test_base(void)
 
 	close(server_fd);
 
+cmd_fail:
+	if (nstoken)
+		close_netns(nstoken);
+
+	system("ip netns del " NS_TEST " >& /dev/null");
+
 close_cgroup_fd:
 	close(cgroup_fd);
 }
Signature · 1 line
2.38.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 5 lines · Hangbin Liu

The current mptcp test is run in init netns. If the user or default system config disabled mptcp, the test will fail. Let's run the mptcp test in a dedicated netns to avoid none kernel default mptcp setting.

Quoted 63 lines
---
 .../testing/selftests/bpf/prog_tests/mptcp.c  | 24 +++++++++++++++++++
 1 file changed, 24 insertions(+)
tools/testing/selftests/bpf/prog_tests/mptcp.c +24 -0
index 59f08d6d1d53..8a4ed9510ec7 100644
@@ -7,6 +7,16 @@
 #include "network_helpers.h"
 #include "mptcp_sock.skel.h"
 
+#define SYS(fmt, ...)						\
+	({							\
+		char cmd[1024];					\
+		snprintf(cmd, sizeof(cmd), fmt, ##__VA_ARGS__);	\
+		if (!ASSERT_OK(system(cmd), cmd))		\
+			goto cmd_fail;				\
+	})
+
+#define NS_TEST "mptcp_ns"
+
 #ifndef TCP_CA_NAME_MAX
 #define TCP_CA_NAME_MAX	16
 #endif
@@ -138,12 +148,20 @@ static int run_test(int cgroup_fd, int server_fd, bool is_mptcp)
 
 static void test_base(void)
 {
+	struct nstoken *nstoken = NULL;
 	int server_fd, cgroup_fd;
 
 	cgroup_fd = test__join_cgroup("/mptcp");
 	if (!ASSERT_GE(cgroup_fd, 0, "test__join_cgroup"))
 		return;
 
+	SYS("ip netns add %s", NS_TEST);
+	SYS("ip -net %s link set dev lo up", NS_TEST);
+
+	nstoken = open_netns(NS_TEST);
+	if (!ASSERT_OK_PTR(nstoken, "open_netns"))
+		goto cmd_fail;
+
 	/* without MPTCP */
 	server_fd = start_server(AF_INET, SOCK_STREAM, NULL, 0, 0);
 	if (!ASSERT_GE(server_fd, 0, "start_server"))
@@ -163,6 +181,12 @@ static void test_base(void)
 
 	close(server_fd);
 
+cmd_fail:
+	if (nstoken)
+		close_netns(nstoken);
+
+	system("ip netns del " NS_TEST " >& /dev/null");
+
 close_cgroup_fd:
 	close(cgroup_fd);
 }
Signature · 1 line
2.38.1
#2 lore raw
In reply to Hangbin Liu

Hi Hangbin,

(+cc MPTCP ML)

Quoted 3 lines · Hangbin Liu

The current mptcp test is run in init netns. If the user or default system config disabled mptcp, the test will fail. Let's run the mptcp test in a dedicated netns to avoid none kernel default mptcp setting.

Thank you for the patch!

I just have one request below if you don't mind:

(...)

Quoted 4 lines
tools/testing/selftests/bpf/prog_tests/mptcp.c +0 -0
index 59f08d6d1d53..8a4ed9510ec7 100644

(...)

Quoted 22 lines
tools/testing/selftests/bpf/prog_tests/mptcp.c +8 -0
@@ -138,12 +148,20 @@ static int run_test(int cgroup_fd, int server_fd, bool is_mptcp)
 
 static void test_base(void)
 {
+	struct nstoken *nstoken = NULL;
 	int server_fd, cgroup_fd;
 
 	cgroup_fd = test__join_cgroup("/mptcp");
 	if (!ASSERT_GE(cgroup_fd, 0, "test__join_cgroup"))
 		return;
 
+	SYS("ip netns add %s", NS_TEST);
+	SYS("ip -net %s link set dev lo up", NS_TEST);
+
+	nstoken = open_netns(NS_TEST);
+	if (!ASSERT_OK_PTR(nstoken, "open_netns"))
+		goto cmd_fail;
+
 	/* without MPTCP */
 	server_fd = start_server(AF_INET, SOCK_STREAM, NULL, 0, 0);
 	if (!ASSERT_GE(server_fd, 0, "start_server"))

tools/testing/selftests/bpf/prog_tests/mptcp.c static void test_base(void) · line 190

Quoted 10 lines
tools/testing/selftests/bpf/prog_tests/mptcp.c +6 -0
@@ -163,6 +181,12 @@ static void test_base(void)
 
 	close(server_fd);
 
+cmd_fail:
+	if (nstoken)
+		close_netns(nstoken);
+
+	system("ip netns del " NS_TEST " >& /dev/null");
+
 close_cgroup_fd:

If I'm not mistaken, this label should no longer be needed: after the modification you did, the only 'goto close_cgroup_fd' used above should be replaced by 'goto cmd_fail', no?

Apart from that, the rest looks good to me.

Cheers,
Matt

Quoted 2 lines
tools/testing/selftests/bpf/prog_tests/mptcp.c +0 -0
 	close(cgroup_fd);
 }
Signature · 2 lines
Tessares | Belgium | Hybrid Access Solutions
www.tessares.net