Commit dd9f6cfb authored by Jakub Sitnicki's avatar Jakub Sitnicki Committed by Martin KaFai Lau
Browse files

selftests/bpf: Parametrize test_xdp_context_tuntap



We want to add more test cases to cover different ways to access the
metadata area. Prepare for it. Pull up the skeleton management.

Signed-off-by: default avatarJakub Sitnicki <jakub@cloudflare.com>
Signed-off-by: default avatarMartin KaFai Lau <martin.lau@kernel.org>
Reviewed-by: default avatarJesse Brandeburg <jbrandeburg@cloudflare.com>
Acked-by: default avatarEduard Zingerman <eddyz87@gmail.com>
Link: https://patch.msgid.link/20250814-skb-metadata-thru-dynptr-v7-5-8a39e636e0fb@cloudflare.com
parent 6dfd5e01
Loading
Loading
Loading
Loading
+21 −10
Original line number Diff line number Diff line
@@ -256,12 +256,13 @@ void test_xdp_context_veth(void)
	netns_free(tx_ns);
}

void test_xdp_context_tuntap(void)
static void test_tuntap(struct bpf_program *xdp_prog,
			struct bpf_program *tc_prog,
			struct bpf_map *result_map)
{
	LIBBPF_OPTS(bpf_tc_hook, tc_hook, .attach_point = BPF_TC_INGRESS);
	LIBBPF_OPTS(bpf_tc_opts, tc_opts, .handle = 1, .priority = 1);
	struct netns_obj *ns = NULL;
	struct test_xdp_meta *skel = NULL;
	__u8 packet[sizeof(struct ethhdr) + TEST_PAYLOAD_LEN];
	int tap_fd = -1;
	int tap_ifindex;
@@ -277,10 +278,6 @@ void test_xdp_context_tuntap(void)

	SYS(close, "ip link set dev " TAP_NAME " up");

	skel = test_xdp_meta__open_and_load();
	if (!ASSERT_OK_PTR(skel, "open and load skeleton"))
		goto close;

	tap_ifindex = if_nametoindex(TAP_NAME);
	if (!ASSERT_GE(tap_ifindex, 0, "if_nametoindex"))
		goto close;
@@ -290,12 +287,12 @@ void test_xdp_context_tuntap(void)
	if (!ASSERT_OK(ret, "bpf_tc_hook_create"))
		goto close;

	tc_opts.prog_fd = bpf_program__fd(skel->progs.ing_cls);
	tc_opts.prog_fd = bpf_program__fd(tc_prog);
	ret = bpf_tc_attach(&tc_hook, &tc_opts);
	if (!ASSERT_OK(ret, "bpf_tc_attach"))
		goto close;

	ret = bpf_xdp_attach(tap_ifindex, bpf_program__fd(skel->progs.ing_xdp),
	ret = bpf_xdp_attach(tap_ifindex, bpf_program__fd(xdp_prog),
			     0, NULL);
	if (!ASSERT_GE(ret, 0, "bpf_xdp_attach"))
		goto close;
@@ -312,11 +309,25 @@ void test_xdp_context_tuntap(void)
	if (!ASSERT_EQ(ret, sizeof(packet), "write packet"))
		goto close;

	assert_test_result(skel->maps.test_result);
	assert_test_result(result_map);

close:
	if (tap_fd >= 0)
		close(tap_fd);
	test_xdp_meta__destroy(skel);
	netns_free(ns);
}

void test_xdp_context_tuntap(void)
{
	struct test_xdp_meta *skel = NULL;

	skel = test_xdp_meta__open_and_load();
	if (!ASSERT_OK_PTR(skel, "open and load skeleton"))
		return;

	if (test__start_subtest("data_meta"))
		test_tuntap(skel->progs.ing_xdp, skel->progs.ing_cls,
			    skel->maps.test_result);

	test_xdp_meta__destroy(skel);
}