Skip to contentSkip to conversation

add netns helpers

PATCH In review Geliang Tang 3 participants 9 messages Oct 30, 2024 – Nov 6, 2024

Subsystems (4)
lore
Share & tools
lore

Geliang Tang

author reviewer
#0 lore raw

v4 cover add netns helpers

From: Geliang Tang <[email protected]>

v4:
- Use netns_new/netns_free instead of create_netns/cleanup_netns as
Martin suggested.

The commit 1e115a58be0ff ("selftests/bpf: netns_new() and netns_free() helpers.") now in bpf-next makes v2 of this set useless. v3 only uses these new helpers in mptcp selftests and drops other patches.

v3:
https://patchwork.kernel.org/project/mptcp/cover/[email protected]/

v2:
https://patchwork.kernel.org/project/mptcp/cover/[email protected]/

Geliang Tang (4):
selftests/bpf: Drop netns helpers in mptcp
Squash to "selftests/bpf: Add mptcp_subflow bpf_iter subtest" Squash to "selftests/bpf: Add bpf scheduler test" Squash to "selftests/bpf: Add bpf_first scheduler & test"

 .../testing/selftests/bpf/prog_tests/mptcp.c  | 78 +++++++------------
 1 file changed, 30 insertions(+), 48 deletions(-)
Signature · 1 line
2.45.2
author reviewer
#1 lore raw

PATCH v4 1/4 selftests/bpf: Drop netns helpers in mptcp

From: Geliang Tang <[email protected]>

New netns selftest helpers netns_new() and netns_free() has been added in network_helpers.c, let's use them in mptcp selftests too instead of using MPTCP's own helpers create_netns() and cleanup_netns().

---
 .../testing/selftests/bpf/prog_tests/mptcp.c  | 42 ++++++-------------
 1 file changed, 12 insertions(+), 30 deletions(-)
tools/testing/selftests/bpf/prog_tests/mptcp.c +12 -30
index be746e0fc393..e32eceabfc40 100644
@@ -90,24 +90,6 @@ struct mptcp_storage {
 	char ca_name[TCP_CA_NAME_MAX];
 };
 
-static struct nstoken *create_netns(void)
-{
-	SYS(fail, "ip netns add %s", NS_TEST);
-	SYS(fail, "ip -net %s link set dev lo up", NS_TEST);
-
-	return open_netns(NS_TEST);
-fail:
-	return NULL;
-}
-
-static void cleanup_netns(struct nstoken *nstoken)
-{
-	if (nstoken)
-		close_netns(nstoken);
-
-	SYS_NOFAIL("ip netns del %s", NS_TEST);
-}
-
 static int start_mptcp_server(int family, const char *addr_str, __u16 port,
 			      int timeout_ms)
 {
@@ -227,15 +209,15 @@ static int run_test(int cgroup_fd, int server_fd, bool is_mptcp)
 
 static void test_base(void)
 {
-	struct nstoken *nstoken = NULL;
+	struct netns_obj *netns = NULL;
 	int server_fd, cgroup_fd;
 
 	cgroup_fd = test__join_cgroup("/mptcp");
 	if (!ASSERT_GE(cgroup_fd, 0, "test__join_cgroup"))
 		return;
 
-	nstoken = create_netns();
-	if (!ASSERT_OK_PTR(nstoken, "create_netns"))
+	netns = netns_new(NS_TEST, true);
+	if (!ASSERT_OK_PTR(netns, "netns_new"))
 		goto fail;
 
 	/* without MPTCP */
@@ -258,7 +240,7 @@ static void test_base(void)
 	close(server_fd);
 
 fail:
-	cleanup_netns(nstoken);
+	netns_free(netns);
 	close(cgroup_fd);
 }
 
@@ -343,21 +325,21 @@ static int run_mptcpify(int cgroup_fd)
 
 static void test_mptcpify(void)
 {
-	struct nstoken *nstoken = NULL;
+	struct netns_obj *netns = NULL;
 	int cgroup_fd;
 
 	cgroup_fd = test__join_cgroup("/mptcpify");
 	if (!ASSERT_GE(cgroup_fd, 0, "test__join_cgroup"))
 		return;
 
-	nstoken = create_netns();
-	if (!ASSERT_OK_PTR(nstoken, "create_netns"))
+	netns = netns_new(NS_TEST, true);
+	if (!ASSERT_OK_PTR(netns, "netns_new"))
 		goto fail;
 
 	ASSERT_OK(run_mptcpify(cgroup_fd), "run_mptcpify");
 
 fail:
-	cleanup_netns(nstoken);
+	netns_free(netns);
 	close(cgroup_fd);
 }
 
@@ -473,7 +455,7 @@ static void run_subflow(void)
 static void test_subflow(void)
 {
 	struct mptcp_subflow *skel;
-	struct nstoken *nstoken;
+	struct netns_obj *netns;
 	int cgroup_fd;
 
 	cgroup_fd = test__join_cgroup("/mptcp_subflow");
@@ -496,8 +478,8 @@ static void test_subflow(void)
 	if (!ASSERT_OK_PTR(skel->links._getsockopt_subflow, "attach _getsockopt_subflow"))
 		goto skel_destroy;
 
-	nstoken = create_netns();
-	if (!ASSERT_OK_PTR(nstoken, "create_netns: mptcp_subflow"))
+	netns = netns_new(NS_TEST, true);
+	if (!ASSERT_OK_PTR(netns, "netns_new: mptcp_subflow"))
 		goto skel_destroy;
 
 	if (endpoint_init("subflow", 2) < 0)
@@ -506,7 +488,7 @@ static void test_subflow(void)
 	run_subflow();
 
 close_netns:
-	cleanup_netns(nstoken);
+	netns_free(netns);
 skel_destroy:
 	mptcp_subflow__destroy(skel);
 close_cgroup:
Signature · 1 line
2.45.2
author reviewer
#2 lore raw

PATCH v4 2/4 Squash to "selftests/bpf: Add mptcp_subflow bpf_iter subtest"

In reply to Geliang Tang

From: Geliang Tang <[email protected]>

Use new netns helpers.

---
 tools/testing/selftests/bpf/prog_tests/mptcp.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
tools/testing/selftests/bpf/prog_tests/mptcp.c +4 -4
index e32eceabfc40..238d2f1cd96e 100644
@@ -526,7 +526,7 @@ static void run_iters_subflow(void)
 static void test_iters_subflow(void)
 {
 	struct mptcp_bpf_iters *skel;
-	struct nstoken *nstoken;
+	struct netns_obj *netns;
 	int cgroup_fd;
 
 	cgroup_fd = test__join_cgroup("/iters_subflow");
@@ -542,8 +542,8 @@ static void test_iters_subflow(void)
 	if (!ASSERT_OK_PTR(skel->links.iters_subflow, "attach getsockopt"))
 		goto skel_destroy;
 
-	nstoken = create_netns();
-	if (!ASSERT_OK_PTR(nstoken, "create_netns: iters_subflow"))
+	netns = netns_new(NS_TEST, true);
+	if (!ASSERT_OK_PTR(netns, "netns_new: iters_subflow"))
 		goto skel_destroy;
 
 	if (endpoint_init("subflow", 4) < 0)
@@ -555,7 +555,7 @@ static void test_iters_subflow(void)
 	ASSERT_EQ(skel->bss->ids, 10, "subflow ids");
 
 close_netns:
-	cleanup_netns(nstoken);
+	netns_free(netns);
 skel_destroy:
 	mptcp_bpf_iters__destroy(skel);
 close_cgroup:
Signature · 1 line
2.45.2
author reviewer
#3 lore raw

PATCH v4 3/4 Squash to "selftests/bpf: Add bpf scheduler test"

In reply to Geliang Tang

From: Geliang Tang <[email protected]>

Use new netns helpers.

---
 .../testing/selftests/bpf/prog_tests/mptcp.c  | 20 +++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)
tools/testing/selftests/bpf/prog_tests/mptcp.c +10 -10
index 238d2f1cd96e..8db1def2e219 100644
@@ -562,12 +562,12 @@ static void test_iters_subflow(void)
 	close(cgroup_fd);
 }
 
-static struct nstoken *sched_init(char *flags, char *sched)
+static struct netns_obj *sched_init(char *flags, char *sched)
 {
-	struct nstoken *nstoken;
+	struct netns_obj *netns;
 
-	nstoken = create_netns();
-	if (!ASSERT_OK_PTR(nstoken, "create_netns"))
+	netns = netns_new(NS_TEST, true);
+	if (!ASSERT_OK_PTR(netns, "netns_new"))
 		return NULL;
 
 	if (endpoint_init("subflow", 2) < 0)
@@ -575,9 +575,9 @@ static struct nstoken *sched_init(char *flags, char *sched)
 
 	SYS(fail, "ip netns exec %s sysctl -qw net.mptcp.scheduler=%s", NS_TEST, sched);
 
-	return nstoken;
+	return netns;
 fail:
-	cleanup_netns(nstoken);
+	netns_free(netns);
 	return NULL;
 }
 
@@ -635,16 +635,16 @@ static void send_data_and_verify(char *sched, bool addr1, bool addr2)
 
 static void test_default(void)
 {
-	struct nstoken *nstoken;
+	struct netns_obj *netns;
 
-	nstoken = sched_init("subflow", "default");
-	if (!nstoken)
+	netns = sched_init("subflow", "default");
+	if (!netns)
 		goto fail;
 
 	send_data_and_verify("default", WITH_DATA, WITH_DATA);
 
 fail:
-	cleanup_netns(nstoken);
+	netns_free(netns);
 }
 
 static void test_bpf_sched(struct bpf_object *obj, char *sched,
Signature · 1 line
2.45.2
author reviewer
#4 lore raw

PATCH v4 4/4 Squash to "selftests/bpf: Add bpf_first scheduler & test"

In reply to Geliang Tang

From: Geliang Tang <[email protected]>

Use new netns helpers.

---
 tools/testing/selftests/bpf/prog_tests/mptcp.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
tools/testing/selftests/bpf/prog_tests/mptcp.c +4 -4
index 8db1def2e219..1d68bbda3370 100644
@@ -651,7 +651,7 @@ static void test_bpf_sched(struct bpf_object *obj, char *sched,
 			   bool addr1, bool addr2)
 {
 	char bpf_sched[MPTCP_SCHED_NAME_MAX] = "bpf_";
-	struct nstoken *nstoken;
+	struct netns_obj *netns;
 	struct bpf_link *link;
 	struct bpf_map *map;
 
@@ -664,14 +664,14 @@ static void test_bpf_sched(struct bpf_object *obj, char *sched,
 	if (CHECK(!link, sched, "attach_struct_ops: %d\n", errno))
 		return;
 
-	nstoken = sched_init("subflow", strcat(bpf_sched, sched));
-	if (!nstoken)
+	netns = sched_init("subflow", strcat(bpf_sched, sched));
+	if (!netns)
 		goto fail;
 
 	send_data_and_verify(sched, addr1, addr2);
 
 fail:
-	cleanup_netns(nstoken);
+	netns_free(netns);
 	bpf_link__destroy(link);
 }
 
Signature · 1 line
2.45.2
#5 lore raw
In reply to Geliang Tang

Hi Geliang,

Thank you for your modifications, that's great!

Our CI did some validations and here is its report:

- KVM Validation: normal: Success! ✅
- KVM Validation: debug: Success! ✅
- KVM Validation: btf-normal (only bpftest_all): Success! ✅
- KVM Validation: btf-debug (only bpftest_all): Success! ✅
- Task: https://github.com/multipath-tcp/mptcp_net-next/actions/runs/11586931001

Initiator: Patchew Applier
Commits: https://github.com/multipath-tcp/mptcp_net-next/commits/639f675bca10
Patchwork: https://patchwork.kernel.org/project/mptcp/list/?series=904491

If there are some issues, you can reproduce them using the same environment as the one used by the CI thanks to a docker image, e.g.:

    $ cd [kernel source code]
    $ docker run -v "${PWD}:${PWD}:rw" -w "${PWD}" --privileged --rm -it \
        --pull always mptcp/mptcp-upstream-virtme-docker:latest \
        auto-normal

For more details:

https://github.com/multipath-tcp/mptcp-upstream-virtme-docker

Please note that despite all the efforts that have been already done to have a stable tests suite when executed on a public CI like here, it is possible some reported issues are not due to your modifications. Still, do not hesitate to help us improve that ;-)

Cheers,
MPTCP GH Action bot
Bot operated by Matthieu Baerts (NGI0 Core)

maintainer Reviewed-by on the v4 series
#6 lore raw
In reply to Geliang Tang

Hi Geliang,

Quoted 9 lines · Geliang Tang

From: Geliang Tang <[email protected]>

v4:
- Use netns_new/netns_free instead of create_netns/cleanup_netns as
Martin suggested.

The commit 1e115a58be0ff ("selftests/bpf: netns_new() and netns_free() helpers.") now in bpf-next makes v2 of this set useless. v3 only uses these new helpers in mptcp selftests and drops other patches.

Thank you for the modifications! The new version looks good to me:

If that's OK, I will wait for a review from the BPF maintainers before applying these patches in our repo, not to do too many manipulations just in case an (unexpected) new version is required.

Cheers,
Matt

Signature · 1 line
Sponsored by the NGI0 Core fund.
author reviewer
#7 lore raw

Hi Matt,

Quoted 16 lines · Matthieu Baerts

Hi Geliang,

Quoted 7 lines · Geliang Tang

From: Geliang Tang <[email protected]>

v4:
 - Use netns_new/netns_free instead of create_netns/cleanup_netns as
Martin suggested.

Quoted 5 lines

The commit 1e115a58be0ff ("selftests/bpf: netns_new() and netns_free()
helpers.") now in bpf-next makes v2 of this set useless. v3 only uses
these new helpers in mptcp selftests and drops other patches.

Quoted 8 lines

Thank you for the modifications! The new version looks good to me:

If that's OK, I will wait for a review from the BPF maintainers before
applying these patches in our repo, not to do too many manipulations just in case an (unexpected) new version is required.

Patch 1 has been merged into bpf-next/net by Martin today. Please apply this set in our repo too. After this, the "add mptcp_subflow bpf_iter" series in our repo is ready to be sent to upstream.

Thanks,
-Geliang

Quoted 3 lines

Cheers,
Matt

maintainer
#8 lore raw

Hi Geliang,

Quoted 23 lines · Geliang Tang

Hi Matt,

Quoted 20 lines · Matthieu Baerts

Hi Geliang,

Quoted 7 lines · Geliang Tang

From: Geliang Tang <[email protected]>

v4:
 - Use netns_new/netns_free instead of create_netns/cleanup_netns as
Martin suggested.

Quoted 5 lines

The commit 1e115a58be0ff ("selftests/bpf: netns_new() and netns_free()
helpers.") now in bpf-next makes v2 of this set useless. v3 only uses
these new helpers in mptcp selftests and drops other patches.

Thank you for the modifications! The new version looks good to me:

Quoted 8 lines
Quoted 4 lines

If that's OK, I will wait for a review from the BPF maintainers before
applying these patches in our repo, not to do too many manipulations just in case an (unexpected) new version is required.

Patch 1 has been merged into bpf-next/net by Martin today. Please apply this set in our repo too. After this, the "add mptcp_subflow bpf_iter" series in our repo is ready to be sent to upstream.

Thanks!

New patches for t/upstream:
- c786bfbfa13f: selftests/bpf: Drop netns helpers in mptcp
- Results: b4f136198f02..ac39b3f1d92b (export)

- de2a335efeba: "squashed" patch 2/4 in "selftests/bpf: Add mptcp_subflow bpf_iter subtest"
- ea4672e6e042: "squashed" (with conflicts) patch 3/4 in "selftests/bpf:
Add bpf scheduler test"
- 8c6acd6502af: "squashed" patch 4/4 in "selftests/bpf: Add bpf_first scheduler & test"
- Results: ac39b3f1d92b..370ec37a4049 (export)

Tests are now in progress:

- export:
https://github.com/multipath-tcp/mptcp_net-next/commit/3fd30039804ef2d1b62fd95d7cadd5a61dd7f542/checks

Cheers,
Matt

Signature · 1 line
Sponsored by the NGI0 Core fund.