selftests/bpf: Monitor traffic for tc_redirect.
Enable traffic monitoring for the test case tc_redirect. Acked-by: Stanislav Fomichev <sdf@fomichev.me> Signed-off-by: Kui-Feng Lee <thinker.li@gmail.com> Link: https://lore.kernel.org/r/20240815053254.470944-5-thinker.li@gmail.com Signed-off-by: Martin KaFai Lau <martin.lau@kernel.org>
This commit is contained in:
committed by
Martin KaFai Lau
parent
1e115a58be
commit
52a5b8a30f
@@ -68,6 +68,7 @@
|
||||
__FILE__, __LINE__, strerror(errno), ##__VA_ARGS__)
|
||||
|
||||
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)
|
||||
{
|
||||
@@ -87,27 +88,41 @@ static int write_file(const char *path, const char *newval)
|
||||
|
||||
static int netns_setup_namespaces(const char *verb)
|
||||
{
|
||||
struct netns_obj **ns_obj = netns_objs;
|
||||
const char * const *ns = namespaces;
|
||||
char cmd[128];
|
||||
|
||||
while (*ns) {
|
||||
snprintf(cmd, sizeof(cmd), "ip netns %s %s", verb, *ns);
|
||||
if (!ASSERT_OK(system(cmd), cmd))
|
||||
return -1;
|
||||
if (strcmp(verb, "add") == 0) {
|
||||
*ns_obj = netns_new(*ns, false);
|
||||
if (!ASSERT_OK_PTR(*ns_obj, "netns_new"))
|
||||
return -1;
|
||||
} else {
|
||||
if (!ASSERT_OK_PTR(*ns_obj, "netns_obj is NULL"))
|
||||
return -1;
|
||||
netns_free(*ns_obj);
|
||||
*ns_obj = NULL;
|
||||
}
|
||||
ns++;
|
||||
ns_obj++;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void netns_setup_namespaces_nofail(const char *verb)
|
||||
{
|
||||
struct netns_obj **ns_obj = netns_objs;
|
||||
const char * const *ns = namespaces;
|
||||
char cmd[128];
|
||||
|
||||
while (*ns) {
|
||||
snprintf(cmd, sizeof(cmd), "ip netns %s %s > /dev/null 2>&1", verb, *ns);
|
||||
system(cmd);
|
||||
if (strcmp(verb, "add") == 0) {
|
||||
*ns_obj = netns_new(*ns, false);
|
||||
} else {
|
||||
if (*ns_obj)
|
||||
netns_free(*ns_obj);
|
||||
*ns_obj = NULL;
|
||||
}
|
||||
ns++;
|
||||
ns_obj++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user