-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
selftests/bpf: Xdp_adjust_tail add grow tail tests
Extend BPF selftest xdp_adjust_tail with grow tail tests, which is added as subtest's. The first grow test stays in same form as original shrink test. The second grow test use the newer bpf_prog_test_run_xattr() calls, and does extra checking of data contents. Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com> Signed-off-by: Alexei Starovoitov <ast@kernel.org> Link: https://lore.kernel.org/bpf/158945350567.97035.9632611946765811876.stgit@firesoul
- Loading branch information
Jesper Dangaard Brouer
authored and
Alexei Starovoitov
committed
May 15, 2020
1 parent
68545fb
commit 7ae2e00
Showing
2 changed files
with
144 additions
and
5 deletions.
There are no files selected for viewing
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
33 changes: 33 additions & 0 deletions
33
tools/testing/selftests/bpf/progs/test_xdp_adjust_tail_grow.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,33 @@ | ||
// SPDX-License-Identifier: GPL-2.0 | ||
#include <linux/bpf.h> | ||
#include <bpf/bpf_helpers.h> | ||
|
||
SEC("xdp_adjust_tail_grow") | ||
int _xdp_adjust_tail_grow(struct xdp_md *xdp) | ||
{ | ||
void *data_end = (void *)(long)xdp->data_end; | ||
void *data = (void *)(long)xdp->data; | ||
unsigned int data_len; | ||
int offset = 0; | ||
|
||
/* Data length determine test case */ | ||
data_len = data_end - data; | ||
|
||
if (data_len == 54) { /* sizeof(pkt_v4) */ | ||
offset = 4096; /* test too large offset */ | ||
} else if (data_len == 74) { /* sizeof(pkt_v6) */ | ||
offset = 40; | ||
} else if (data_len == 64) { | ||
offset = 128; | ||
} else if (data_len == 128) { | ||
offset = 4096 - 256 - 320 - data_len; /* Max tail grow 3520 */ | ||
} else { | ||
return XDP_ABORTED; /* No matching test */ | ||
} | ||
|
||
if (bpf_xdp_adjust_tail(xdp, offset)) | ||
return XDP_DROP; | ||
return XDP_TX; | ||
} | ||
|
||
char _license[] SEC("license") = "GPL"; |