-
Notifications
You must be signed in to change notification settings - Fork 123
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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 <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Alexei Starovoitov <[email protected]>
- Loading branch information
Showing
2 changed files
with
43 additions
and
0 deletions.
There are no files selected for viewing
28 changes: 28 additions & 0 deletions
28
tools/testing/selftests/bpf/prog_tests/cgroup_skb_direct_packet_access.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// SPDX-License-Identifier: GPL-2.0 | ||
|
||
#include <test_progs.h> | ||
#include "cgroup_skb_direct_packet_access.skel.h" | ||
|
||
void test_cgroup_skb_prog_run_direct_packet_access(void) | ||
{ | ||
int err; | ||
struct cgroup_skb_direct_packet_access *skel; | ||
char test_skb[64] = {}; | ||
|
||
LIBBPF_OPTS(bpf_test_run_opts, topts, | ||
.data_in = test_skb, | ||
.data_size_in = sizeof(test_skb), | ||
); | ||
|
||
skel = cgroup_skb_direct_packet_access__open_and_load(); | ||
if (!ASSERT_OK_PTR(skel, "cgroup_skb_direct_packet_access__open_and_load")) | ||
return; | ||
|
||
err = bpf_prog_test_run_opts(bpf_program__fd(skel->progs.direct_packet_access), &topts); | ||
ASSERT_OK(err, "bpf_prog_test_run_opts err"); | ||
ASSERT_EQ(topts.retval, 1, "retval"); | ||
|
||
ASSERT_NEQ(skel->bss->data_end, 0, "data_end"); | ||
|
||
cgroup_skb_direct_packet_access__destroy(skel); | ||
} |
15 changes: 15 additions & 0 deletions
15
tools/testing/selftests/bpf/progs/cgroup_skb_direct_packet_access.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// SPDX-License-Identifier: GPL-2.0 | ||
|
||
#include "vmlinux.h" | ||
#include <bpf/bpf_helpers.h> | ||
|
||
__u32 data_end; | ||
|
||
SEC("cgroup_skb/ingress") | ||
int direct_packet_access(struct __sk_buff *skb) | ||
{ | ||
data_end = skb->data_end; | ||
return 1; | ||
} | ||
|
||
char _license[] SEC("license") = "GPL"; |