Skip to content

Commit 52a5b8a

Browse files
ThinkerYzu1Martin KaFai Lau
authored andcommitted
selftests/bpf: Monitor traffic for tc_redirect.
Enable traffic monitoring for the test case tc_redirect. Acked-by: Stanislav Fomichev <[email protected]> Signed-off-by: Kui-Feng Lee <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Martin KaFai Lau <[email protected]>
1 parent 1e115a5 commit 52a5b8a

File tree

1 file changed

+22
-7
lines changed

1 file changed

+22
-7
lines changed

tools/testing/selftests/bpf/prog_tests/tc_redirect.c

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@
6868
__FILE__, __LINE__, strerror(errno), ##__VA_ARGS__)
6969

7070
static const char * const namespaces[] = {NS_SRC, NS_FWD, NS_DST, NULL};
71+
static struct netns_obj *netns_objs[3];
7172

7273
static int write_file(const char *path, const char *newval)
7374
{
@@ -87,27 +88,41 @@ static int write_file(const char *path, const char *newval)
8788

8889
static int netns_setup_namespaces(const char *verb)
8990
{
91+
struct netns_obj **ns_obj = netns_objs;
9092
const char * const *ns = namespaces;
91-
char cmd[128];
9293

9394
while (*ns) {
94-
snprintf(cmd, sizeof(cmd), "ip netns %s %s", verb, *ns);
95-
if (!ASSERT_OK(system(cmd), cmd))
96-
return -1;
95+
if (strcmp(verb, "add") == 0) {
96+
*ns_obj = netns_new(*ns, false);
97+
if (!ASSERT_OK_PTR(*ns_obj, "netns_new"))
98+
return -1;
99+
} else {
100+
if (!ASSERT_OK_PTR(*ns_obj, "netns_obj is NULL"))
101+
return -1;
102+
netns_free(*ns_obj);
103+
*ns_obj = NULL;
104+
}
97105
ns++;
106+
ns_obj++;
98107
}
99108
return 0;
100109
}
101110

102111
static void netns_setup_namespaces_nofail(const char *verb)
103112
{
113+
struct netns_obj **ns_obj = netns_objs;
104114
const char * const *ns = namespaces;
105-
char cmd[128];
106115

107116
while (*ns) {
108-
snprintf(cmd, sizeof(cmd), "ip netns %s %s > /dev/null 2>&1", verb, *ns);
109-
system(cmd);
117+
if (strcmp(verb, "add") == 0) {
118+
*ns_obj = netns_new(*ns, false);
119+
} else {
120+
if (*ns_obj)
121+
netns_free(*ns_obj);
122+
*ns_obj = NULL;
123+
}
110124
ns++;
125+
ns_obj++;
111126
}
112127
}
113128

0 commit comments

Comments
 (0)