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. Suggested-by: Martin KaFai Lau <martin.lau@linux.dev> Signed-off-by: Hangbin Liu <liuhangbin@gmail.com> Acked-by: Matthieu Baerts <matthieu.baerts@tessares.net> Link: https://lore.kernel.org/r/20230224061343.506571-3-liuhangbin@gmail.com Signed-off-by: Martin KaFai Lau <martin.lau@kernel.org>
This commit is contained in:
parent
b61987d37c
commit
02d6a057c7
@ -7,6 +7,8 @@
|
||||
#include "network_helpers.h"
|
||||
#include "mptcp_sock.skel.h"
|
||||
|
||||
#define NS_TEST "mptcp_ns"
|
||||
|
||||
#ifndef TCP_CA_NAME_MAX
|
||||
#define TCP_CA_NAME_MAX 16
|
||||
#endif
|
||||
@ -138,12 +140,20 @@ out:
|
||||
|
||||
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(fail, "ip netns add %s", NS_TEST);
|
||||
SYS(fail, "ip -net %s link set dev lo up", NS_TEST);
|
||||
|
||||
nstoken = open_netns(NS_TEST);
|
||||
if (!ASSERT_OK_PTR(nstoken, "open_netns"))
|
||||
goto fail;
|
||||
|
||||
/* without MPTCP */
|
||||
server_fd = start_server(AF_INET, SOCK_STREAM, NULL, 0, 0);
|
||||
if (!ASSERT_GE(server_fd, 0, "start_server"))
|
||||
@ -157,13 +167,18 @@ with_mptcp:
|
||||
/* with MPTCP */
|
||||
server_fd = start_mptcp_server(AF_INET, NULL, 0, 0);
|
||||
if (!ASSERT_GE(server_fd, 0, "start_mptcp_server"))
|
||||
goto close_cgroup_fd;
|
||||
goto fail;
|
||||
|
||||
ASSERT_OK(run_test(cgroup_fd, server_fd, true), "run_test mptcp");
|
||||
|
||||
close(server_fd);
|
||||
|
||||
close_cgroup_fd:
|
||||
fail:
|
||||
if (nstoken)
|
||||
close_netns(nstoken);
|
||||
|
||||
SYS_NOFAIL("ip netns del " NS_TEST " &> /dev/null");
|
||||
|
||||
close(cgroup_fd);
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user