]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
selftests/bpf: Parametrize test_xdp_context_tuntap
authorJakub Sitnicki <jakub@cloudflare.com>
Thu, 14 Aug 2025 09:59:31 +0000 (11:59 +0200)
committerMartin KaFai Lau <martin.lau@kernel.org>
Mon, 18 Aug 2025 17:29:42 +0000 (10:29 -0700)
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: Jakub Sitnicki <jakub@cloudflare.com>
Signed-off-by: Martin KaFai Lau <martin.lau@kernel.org>
Reviewed-by: Jesse Brandeburg <jbrandeburg@cloudflare.com>
Acked-by: Eduard Zingerman <eddyz87@gmail.com>
Link: https://patch.msgid.link/20250814-skb-metadata-thru-dynptr-v7-5-8a39e636e0fb@cloudflare.com
tools/testing/selftests/bpf/prog_tests/xdp_context_test_run.c

index 0134651d94ab08f7ba779f55d5ae87d6c4589768..6c66e27e5bc74af6950cd1226c8be9901939898d 100644 (file)
@@ -256,12 +256,13 @@ close:
        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);
+}