selftests/bpf: Cover skb metadata access after change_head/tail helper
Add a test to verify that skb metadata remains accessible after calling bpf_skb_change_head() and bpf_skb_change_tail(), which modify packet headroom/tailroom and can trigger head reallocation. Signed-off-by: Jakub Sitnicki <jakub@cloudflare.com> Signed-off-by: Martin KaFai Lau <martin.lau@kernel.org> Link: https://patch.msgid.link/20251105-skb-meta-rx-path-v4-15-5ceb08a9b37b@cloudflare.com
This commit is contained in:
committed by
Martin KaFai Lau
parent
29960e635b
commit
85d454afef
@@ -497,6 +497,11 @@ void test_xdp_context_tuntap(void)
|
||||
skel->progs.helper_skb_adjust_room,
|
||||
NULL, /* tc prio 2 */
|
||||
&skel->bss->test_pass);
|
||||
if (test__start_subtest("helper_skb_change_head_tail"))
|
||||
test_tuntap(skel->progs.ing_xdp,
|
||||
skel->progs.helper_skb_change_head_tail,
|
||||
NULL, /* tc prio 2 */
|
||||
&skel->bss->test_pass);
|
||||
|
||||
test_xdp_meta__destroy(skel);
|
||||
}
|
||||
|
||||
@@ -611,4 +611,38 @@ out:
|
||||
return TC_ACT_SHOT;
|
||||
}
|
||||
|
||||
SEC("tc")
|
||||
int helper_skb_change_head_tail(struct __sk_buff *ctx)
|
||||
{
|
||||
int err;
|
||||
|
||||
/* Reserve 1 extra in the front for packet data */
|
||||
err = bpf_skb_change_head(ctx, 1, 0);
|
||||
if (err)
|
||||
goto out;
|
||||
|
||||
if (!check_skb_metadata(ctx))
|
||||
goto out;
|
||||
|
||||
/* Reserve 256 extra bytes in the front to trigger head reallocation */
|
||||
err = bpf_skb_change_head(ctx, 256, 0);
|
||||
if (err)
|
||||
goto out;
|
||||
|
||||
if (!check_skb_metadata(ctx))
|
||||
goto out;
|
||||
|
||||
/* Reserve 4k extra bytes in the back to trigger head reallocation */
|
||||
err = bpf_skb_change_tail(ctx, ctx->len + 4096, 0);
|
||||
if (err)
|
||||
goto out;
|
||||
|
||||
if (!check_skb_metadata(ctx))
|
||||
goto out;
|
||||
|
||||
test_pass = true;
|
||||
out:
|
||||
return TC_ACT_SHOT;
|
||||
}
|
||||
|
||||
char _license[] SEC("license") = "GPL";
|
||||
|
||||
Reference in New Issue
Block a user