From: Geliang Tang tanggeliang@kylinos.cn
New netns selftest helpers make_netns() and remove_netns() has been added in network_helpers.c, let's use them in mptcp selftests too.
Signed-off-by: Geliang Tang tanggeliang@kylinos.cn Reviewed-by: Matthieu Baerts (NGI0) matttbe@kernel.org --- tools/testing/selftests/bpf/prog_tests/mptcp.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-)
diff --git a/tools/testing/selftests/bpf/prog_tests/mptcp.c b/tools/testing/selftests/bpf/prog_tests/mptcp.c index d2ca32fa3b21..8276398f7d6a 100644 --- a/tools/testing/selftests/bpf/prog_tests/mptcp.c +++ b/tools/testing/selftests/bpf/prog_tests/mptcp.c @@ -66,12 +66,18 @@ struct mptcp_storage {
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); + struct nstoken *nstoken;
- return open_netns(NS_TEST); -fail: - return NULL; + if (make_netns(NS_TEST) < 0) + return NULL; + + nstoken = open_netns(NS_TEST); + if (!nstoken) { + log_err("open netns %s failed", NS_TEST); + remove_netns(NS_TEST); + } + + return nstoken; }
static void cleanup_netns(struct nstoken *nstoken) @@ -79,7 +85,7 @@ static void cleanup_netns(struct nstoken *nstoken) if (nstoken) close_netns(nstoken);
- SYS_NOFAIL("ip netns del %s", NS_TEST); + remove_netns(NS_TEST); }
static int start_mptcp_server(int family, const char *addr_str, __u16 port,
On 10/24/24 1:11 AM, Geliang Tang wrote:
From: Geliang Tang tanggeliang@kylinos.cn
New netns selftest helpers make_netns() and remove_netns() has been added in network_helpers.c, let's use them in mptcp selftests too.
Signed-off-by: Geliang Tang tanggeliang@kylinos.cn Reviewed-by: Matthieu Baerts (NGI0) matttbe@kernel.org
tools/testing/selftests/bpf/prog_tests/mptcp.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-)
diff --git a/tools/testing/selftests/bpf/prog_tests/mptcp.c b/tools/testing/selftests/bpf/prog_tests/mptcp.c index d2ca32fa3b21..8276398f7d6a 100644 --- a/tools/testing/selftests/bpf/prog_tests/mptcp.c +++ b/tools/testing/selftests/bpf/prog_tests/mptcp.c @@ -66,12 +66,18 @@ struct mptcp_storage { 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);
- struct nstoken *nstoken;
- return open_netns(NS_TEST);
-fail:
- return NULL;
- if (make_netns(NS_TEST) < 0)
return NULL;
- nstoken = open_netns(NS_TEST);
- if (!nstoken) {
log_err("open netns %s failed", NS_TEST);
remove_netns(NS_TEST);
- }
- return nstoken; }
This can be further simplified by using the netns_new() and netns_free(). Then create_netns() and remove_netns() can be removed from mptcp.c. Take a look at a recent usage in prog_tests/btf_skc_cls_ingress.c.
pw-bot: cr
static void cleanup_netns(struct nstoken *nstoken) @@ -79,7 +85,7 @@ static void cleanup_netns(struct nstoken *nstoken) if (nstoken) close_netns(nstoken);
- SYS_NOFAIL("ip netns del %s", NS_TEST);
- remove_netns(NS_TEST); }
static int start_mptcp_server(int family, const char *addr_str, __u16 port,
linux-kselftest-mirror@lists.linaro.org