@@ -7,16 +7,9 @@
#include "test_progs.h"
#include "cap_helpers.h"
+#include "network_helpers.h"
#include "bind_perm.skel.h"
-static int create_netns(void)
-{
- if (!ASSERT_OK(unshare(CLONE_NEWNET), "create netns"))
- return -1;
-
- return 0;
-}
-
void try_bind(int family, int port, int expected_errno)
{
struct sockaddr_storage addr = {};
@@ -54,7 +47,7 @@ void test_bind_perm(void)
__u64 old_caps = 0;
int cgroup_fd;
- if (create_netns())
+ if (unshare_netns())
return;
cgroup_fd = test__join_cgroup("/bind_perm");
@@ -8,17 +8,6 @@
#include "bpf_cubic.skel.h"
#include "bpf_iter_setsockopt.skel.h"
-static int create_netns(void)
-{
- if (!ASSERT_OK(unshare(CLONE_NEWNET), "create netns"))
- return -1;
-
- if (!ASSERT_OK(system("ip link set dev lo up"), "bring up lo"))
- return -1;
-
- return 0;
-}
-
static unsigned int set_bpf_cubic(int *fds, unsigned int nr_fds)
{
unsigned int i;
@@ -187,7 +176,7 @@ void serial_test_bpf_iter_setsockopt(void)
struct bpf_link *cubic_link = NULL;
struct bpf_link *dctcp_link = NULL;
- if (create_netns())
+ if (unshare_netns())
return;
/* Load iter_skel */
@@ -20,14 +20,8 @@ static const char addr6_str[] = "::1";
static struct setget_sockopt *skel;
static int cg_fd;
-static int create_netns(void)
+static int create_veth(void)
{
- if (!ASSERT_OK(unshare(CLONE_NEWNET), "create netns"))
- return -1;
-
- if (!ASSERT_OK(system("ip link set dev lo up"), "set lo up"))
- return -1;
-
if (!ASSERT_OK(system("ip link add dev binddevtest1 type veth peer name binddevtest2"),
"add veth"))
return -1;
@@ -160,7 +154,7 @@ void test_setget_sockopt(void)
if (cg_fd < 0)
return;
- if (create_netns())
+ if (unshare_netns() || create_veth())
goto done;
skel = setget_sockopt__open();
@@ -45,17 +45,6 @@ static __u64 child_cg_id;
static int linum_map_fd;
static __u32 duration;
-static bool create_netns(void)
-{
- if (!ASSERT_OK(unshare(CLONE_NEWNET), "create netns"))
- return false;
-
- if (!ASSERT_OK(system("ip link set dev lo up"), "bring up lo"))
- return false;
-
- return true;
-}
-
static void print_sk(const struct bpf_sock *sk, const char *prefix)
{
char src_ip4[24], dst_ip4[24];
@@ -350,7 +339,7 @@ void serial_test_sock_fields(void)
struct bpf_link *link;
/* Use a dedicated netns to have a fixed listen port */
- if (!create_netns())
+ if (unshare_netns())
return;
/* Create a cgroup, get fd, and join it */
@@ -40,17 +40,6 @@ struct sk_fds {
int active_lport;
};
-static int create_netns(void)
-{
- if (!ASSERT_OK(unshare(CLONE_NEWNET), "create netns"))
- return -1;
-
- if (!ASSERT_OK(system("ip link set dev lo up"), "run ip cmd"))
- return -1;
-
- return 0;
-}
-
static void print_hdr_stg(const struct hdr_stg *hdr_stg, const char *prefix)
{
fprintf(stderr, "%s{active:%u, resend_syn:%u, syncookie:%u, fastopen:%u}\n",
@@ -548,7 +537,7 @@ void test_tcp_hdr_options(void)
if (!test__start_subtest(tests[i].desc))
continue;
- if (create_netns())
+ if (unshare_netns())
break;
tests[i].run();