Skip to content

Commit c09df4b

Browse files
tohojoborkmann
authored andcommitted
selftests/bpf: Add a test for maximum packet size in xdp_do_redirect
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 <[email protected]> Signed-off-by: Daniel Borkmann <[email protected]> Acked-by: Martin KaFai Lau <[email protected]> Link: https://lore.kernel.org/bpf/[email protected]
1 parent b6f1f78 commit c09df4b

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

tools/testing/selftests/bpf/prog_tests/xdp_do_redirect.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,28 @@ static int attach_tc_prog(struct bpf_tc_hook *hook, int fd)
6262
return 0;
6363
}
6464

65+
/* The maximum permissible size is: PAGE_SIZE - sizeof(struct xdp_page_head) -
66+
* sizeof(struct skb_shared_info) - XDP_PACKET_HEADROOM = 3368 bytes
67+
*/
68+
#define MAX_PKT_SIZE 3368
69+
static void test_max_pkt_size(int fd)
70+
{
71+
char data[MAX_PKT_SIZE + 1] = {};
72+
int err;
73+
DECLARE_LIBBPF_OPTS(bpf_test_run_opts, opts,
74+
.data_in = &data,
75+
.data_size_in = MAX_PKT_SIZE,
76+
.flags = BPF_F_TEST_XDP_LIVE_FRAMES,
77+
.repeat = 1,
78+
);
79+
err = bpf_prog_test_run_opts(fd, &opts);
80+
ASSERT_OK(err, "prog_run_max_size");
81+
82+
opts.data_size_in += 1;
83+
err = bpf_prog_test_run_opts(fd, &opts);
84+
ASSERT_EQ(err, -EINVAL, "prog_run_too_big");
85+
}
86+
6587
#define NUM_PKTS 10000
6688
void test_xdp_do_redirect(void)
6789
{
@@ -167,6 +189,8 @@ void test_xdp_do_redirect(void)
167189
ASSERT_EQ(skel->bss->pkts_seen_zero, 2, "pkt_count_zero");
168190
ASSERT_EQ(skel->bss->pkts_seen_tc, NUM_PKTS - 2, "pkt_count_tc");
169191

192+
test_max_pkt_size(bpf_program__fd(skel->progs.xdp_count_pkts));
193+
170194
out_tc:
171195
bpf_tc_hook_destroy(&tc_hook);
172196
out:

0 commit comments

Comments
 (0)