Message ID | 20220310225621.53374-2-toke@redhat.com (mailing list archive) |
---|---|
State | Accepted |
Commit | c09df4bd3a915079eec5e77160366225a28699a2 |
Delegated to: | BPF |
Headers | show |
Series | [bpf-next,1/2] bpf, test_run: Fix packet size check for live packet mode | expand |
Context | Check | Description |
---|---|---|
netdev/tree_selection | success | Clearly marked for bpf-next |
netdev/fixes_present | success | Fixes tag not required for -next series |
netdev/subject_prefix | success | Link |
netdev/cover_letter | success | Single patches do not need cover letters |
netdev/patch_count | success | Link |
netdev/header_inline | success | No static functions without inline keyword in header files |
netdev/build_32bit | success | Errors and warnings before: 0 this patch: 0 |
netdev/cc_maintainers | warning | 1 maintainers not CCed: linux-kselftest@vger.kernel.org |
netdev/build_clang | success | Errors and warnings before: 0 this patch: 0 |
netdev/module_param | success | Was 0 now: 0 |
netdev/verify_signedoff | success | Signed-off-by tag matches author and committer |
netdev/verify_fixes | success | No Fixes tag |
netdev/build_allmodconfig_warn | success | Errors and warnings before: 0 this patch: 0 |
netdev/checkpatch | success | total: 0 errors, 0 warnings, 0 checks, 36 lines checked |
netdev/kdoc | success | Errors and warnings before: 0 this patch: 0 |
netdev/source_inline | success | Was 0 now: 0 |
bpf/vmtest-bpf-next-PR | success | PR summary |
bpf/vmtest-bpf-next | success | VM_Test |
On Thu, Mar 10, 2022 at 11:56:21PM +0100, Toke Høiland-Jørgensen wrote: > This adds an extra test to the xdp_do_redirect selftest for XDP live packet > mode, which verifies that the maximum permissible packet size is accepted > without any errors, and that a too big packet is correctly rejected. Acked-by: Martin KaFai Lau <kafai@fb.com>
diff --git a/tools/testing/selftests/bpf/prog_tests/xdp_do_redirect.c b/tools/testing/selftests/bpf/prog_tests/xdp_do_redirect.c index 9926b07e38c8..a50971c6cf4a 100644 --- a/tools/testing/selftests/bpf/prog_tests/xdp_do_redirect.c +++ b/tools/testing/selftests/bpf/prog_tests/xdp_do_redirect.c @@ -62,6 +62,28 @@ static int attach_tc_prog(struct bpf_tc_hook *hook, int fd) return 0; } +/* The maximum permissible size is: PAGE_SIZE - sizeof(struct xdp_page_head) - + * sizeof(struct skb_shared_info) - XDP_PACKET_HEADROOM = 3368 bytes + */ +#define MAX_PKT_SIZE 3368 +static void test_max_pkt_size(int fd) +{ + char data[MAX_PKT_SIZE + 1] = {}; + int err; + DECLARE_LIBBPF_OPTS(bpf_test_run_opts, opts, + .data_in = &data, + .data_size_in = MAX_PKT_SIZE, + .flags = BPF_F_TEST_XDP_LIVE_FRAMES, + .repeat = 1, + ); + err = bpf_prog_test_run_opts(fd, &opts); + ASSERT_OK(err, "prog_run_max_size"); + + opts.data_size_in += 1; + err = bpf_prog_test_run_opts(fd, &opts); + ASSERT_EQ(err, -EINVAL, "prog_run_too_big"); +} + #define NUM_PKTS 10000 void test_xdp_do_redirect(void) { @@ -167,6 +189,8 @@ void test_xdp_do_redirect(void) ASSERT_EQ(skel->bss->pkts_seen_zero, 2, "pkt_count_zero"); ASSERT_EQ(skel->bss->pkts_seen_tc, NUM_PKTS - 2, "pkt_count_tc"); + test_max_pkt_size(bpf_program__fd(skel->progs.xdp_count_pkts)); + out_tc: bpf_tc_hook_destroy(&tc_hook); out:
This adds an extra test to the xdp_do_redirect selftest for XDP live packet mode, which verifies that the maximum permissible packet size is accepted without any errors, and that a too big packet is correctly rejected. Signed-off-by: Toke Høiland-Jørgensen <toke@redhat.com> --- .../bpf/prog_tests/xdp_do_redirect.c | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+)