Skip to content

Commit 9aef3aa

Browse files
mtardyAlexei Starovoitov
authored andcommitted
selftests/bpf: add cgroup skb direct packet access test
This verifies that programs of BPF_PROG_TYPE_CGROUP_SKB can access skb->data_end with direct packet access when being run with BPF_PROG_TEST_RUN. Signed-off-by: Mahe Tardy <mahe.tardy@gmail.com> Link: https://lore.kernel.org/r/20241125152603.375898-2-mahe.tardy@gmail.com Signed-off-by: Alexei Starovoitov <ast@kernel.org>
1 parent ed3e469 commit 9aef3aa

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// SPDX-License-Identifier: GPL-2.0
2+
3+
#include <test_progs.h>
4+
#include "cgroup_skb_direct_packet_access.skel.h"
5+
6+
void test_cgroup_skb_prog_run_direct_packet_access(void)
7+
{
8+
int err;
9+
struct cgroup_skb_direct_packet_access *skel;
10+
char test_skb[64] = {};
11+
12+
LIBBPF_OPTS(bpf_test_run_opts, topts,
13+
.data_in = test_skb,
14+
.data_size_in = sizeof(test_skb),
15+
);
16+
17+
skel = cgroup_skb_direct_packet_access__open_and_load();
18+
if (!ASSERT_OK_PTR(skel, "cgroup_skb_direct_packet_access__open_and_load"))
19+
return;
20+
21+
err = bpf_prog_test_run_opts(bpf_program__fd(skel->progs.direct_packet_access), &topts);
22+
ASSERT_OK(err, "bpf_prog_test_run_opts err");
23+
ASSERT_EQ(topts.retval, 1, "retval");
24+
25+
ASSERT_NEQ(skel->bss->data_end, 0, "data_end");
26+
27+
cgroup_skb_direct_packet_access__destroy(skel);
28+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// SPDX-License-Identifier: GPL-2.0
2+
3+
#include "vmlinux.h"
4+
#include <bpf/bpf_helpers.h>
5+
6+
__u32 data_end;
7+
8+
SEC("cgroup_skb/ingress")
9+
int direct_packet_access(struct __sk_buff *skb)
10+
{
11+
data_end = skb->data_end;
12+
return 1;
13+
}
14+
15+
char _license[] SEC("license") = "GPL";

0 commit comments

Comments
 (0)