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

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.com


Signed-off-by: default avatarMartin KaFai Lau <martin.lau@kernel.org>
parent 1e115a58
Loading
Loading
Loading
Loading
+22 −7
Original line number Diff line number Diff line
@@ -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))
		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++;
	}
}