Commit 52a5b8a3 authored by Kui-Feng Lee's avatar Kui-Feng Lee Committed by Martin KaFai Lau

selftests/bpf: Monitor traffic for tc_redirect.

Enable traffic monitoring for the test case tc_redirect.
Acked-by: default avatarStanislav Fomichev <sdf@fomichev.me>
Signed-off-by: default avatarKui-Feng Lee <thinker.li@gmail.com>
Link: https://lore.kernel.org/r/20240815053254.470944-5-thinker.li@gmail.comSigned-off-by: default avatarMartin KaFai Lau <martin.lau@kernel.org>
parent 1e115a58
...@@ -68,6 +68,7 @@ ...@@ -68,6 +68,7 @@
__FILE__, __LINE__, strerror(errno), ##__VA_ARGS__) __FILE__, __LINE__, strerror(errno), ##__VA_ARGS__)
static const char * const namespaces[] = {NS_SRC, NS_FWD, NS_DST, NULL}; static const char * const namespaces[] = {NS_SRC, NS_FWD, NS_DST, NULL};
static struct netns_obj *netns_objs[3];
static int write_file(const char *path, const char *newval) static int write_file(const char *path, const char *newval)
{ {
...@@ -87,27 +88,41 @@ static int write_file(const char *path, const char *newval) ...@@ -87,27 +88,41 @@ static int write_file(const char *path, const char *newval)
static int netns_setup_namespaces(const char *verb) static int netns_setup_namespaces(const char *verb)
{ {
struct netns_obj **ns_obj = netns_objs;
const char * const *ns = namespaces; const char * const *ns = namespaces;
char cmd[128];
while (*ns) { while (*ns) {
snprintf(cmd, sizeof(cmd), "ip netns %s %s", verb, *ns); if (strcmp(verb, "add") == 0) {
if (!ASSERT_OK(system(cmd), cmd)) *ns_obj = netns_new(*ns, false);
if (!ASSERT_OK_PTR(*ns_obj, "netns_new"))
return -1; return -1;
} else {
if (!ASSERT_OK_PTR(*ns_obj, "netns_obj is NULL"))
return -1;
netns_free(*ns_obj);
*ns_obj = NULL;
}
ns++; ns++;
ns_obj++;
} }
return 0; return 0;
} }
static void netns_setup_namespaces_nofail(const char *verb) static void netns_setup_namespaces_nofail(const char *verb)
{ {
struct netns_obj **ns_obj = netns_objs;
const char * const *ns = namespaces; const char * const *ns = namespaces;
char cmd[128];
while (*ns) { while (*ns) {
snprintf(cmd, sizeof(cmd), "ip netns %s %s > /dev/null 2>&1", verb, *ns); if (strcmp(verb, "add") == 0) {
system(cmd); *ns_obj = netns_new(*ns, false);
} else {
if (*ns_obj)
netns_free(*ns_obj);
*ns_obj = NULL;
}
ns++; ns++;
ns_obj++;
} }
} }
......
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