Commit 97c9c652 authored by Geliang Tang's avatar Geliang Tang Committed by Martin KaFai Lau

selftests/bpf: Add two mptcp netns helpers

Add two netns helpers for mptcp tests: create_netns() and
cleanup_netns(). Use them in test_base().

These new helpers will be re-used in the following commits
introducing new tests.
Acked-by: default avatarYonghong Song <yonghong.song@linux.dev>
Reviewed-by: default avatarMatthieu Baerts <matthieu.baerts@tessares.net>
Signed-off-by: default avatarGeliang Tang <geliang.tang@suse.com>
Link: https://lore.kernel.org/r/7506371fb6c417b401cc9d7365fe455754f4ba3f.1692147782.git.geliang.tang@suse.comSigned-off-by: default avatarMartin KaFai Lau <martin.lau@kernel.org>
parent 0dd061a6
...@@ -22,6 +22,24 @@ struct mptcp_storage { ...@@ -22,6 +22,24 @@ struct mptcp_storage {
char ca_name[TCP_CA_NAME_MAX]; 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 &> /dev/null", NS_TEST);
}
static int verify_tsk(int map_fd, int client_fd) static int verify_tsk(int map_fd, int client_fd)
{ {
int err, cfd = client_fd; int err, cfd = client_fd;
...@@ -147,11 +165,8 @@ static void test_base(void) ...@@ -147,11 +165,8 @@ static void test_base(void)
if (!ASSERT_GE(cgroup_fd, 0, "test__join_cgroup")) if (!ASSERT_GE(cgroup_fd, 0, "test__join_cgroup"))
return; return;
SYS(fail, "ip netns add %s", NS_TEST); nstoken = create_netns();
SYS(fail, "ip -net %s link set dev lo up", NS_TEST); if (!ASSERT_OK_PTR(nstoken, "create_netns"))
nstoken = open_netns(NS_TEST);
if (!ASSERT_OK_PTR(nstoken, "open_netns"))
goto fail; goto fail;
/* without MPTCP */ /* without MPTCP */
...@@ -174,11 +189,7 @@ static void test_base(void) ...@@ -174,11 +189,7 @@ static void test_base(void)
close(server_fd); close(server_fd);
fail: fail:
if (nstoken) cleanup_netns(nstoken);
close_netns(nstoken);
SYS_NOFAIL("ip netns del " NS_TEST " &> /dev/null");
close(cgroup_fd); close(cgroup_fd);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment