Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

selftests/bpf: Cover skb metadata access after bpf_skb_change_proto

Add a test to verify that skb metadata remains accessible after calling
bpf_skb_change_proto(), which modifies packet headroom to accommodate
different IP header sizes.

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-16-5ceb08a9b37b@cloudflare.com

authored by

Jakub Sitnicki and committed by
Martin KaFai Lau
d2c5cca3 85d454af

+30
+5
tools/testing/selftests/bpf/prog_tests/xdp_context_test_run.c
··· 502 502 skel->progs.helper_skb_change_head_tail, 503 503 NULL, /* tc prio 2 */ 504 504 &skel->bss->test_pass); 505 + if (test__start_subtest("helper_skb_change_proto")) 506 + test_tuntap(skel->progs.ing_xdp, 507 + skel->progs.helper_skb_change_proto, 508 + NULL, /* tc prio 2 */ 509 + &skel->bss->test_pass); 505 510 506 511 test_xdp_meta__destroy(skel); 507 512 }
+25
tools/testing/selftests/bpf/progs/test_xdp_meta.c
··· 4 4 #include <linux/if_ether.h> 5 5 #include <linux/pkt_cls.h> 6 6 7 + #include <bpf/bpf_endian.h> 7 8 #include <bpf/bpf_helpers.h> 8 9 #include "bpf_kfuncs.h" 9 10 ··· 635 634 636 635 /* Reserve 4k extra bytes in the back to trigger head reallocation */ 637 636 err = bpf_skb_change_tail(ctx, ctx->len + 4096, 0); 637 + if (err) 638 + goto out; 639 + 640 + if (!check_skb_metadata(ctx)) 641 + goto out; 642 + 643 + test_pass = true; 644 + out: 645 + return TC_ACT_SHOT; 646 + } 647 + 648 + SEC("tc") 649 + int helper_skb_change_proto(struct __sk_buff *ctx) 650 + { 651 + int err; 652 + 653 + err = bpf_skb_change_proto(ctx, bpf_htons(ETH_P_IPV6), 0); 654 + if (err) 655 + goto out; 656 + 657 + if (!check_skb_metadata(ctx)) 658 + goto out; 659 + 660 + err = bpf_skb_change_proto(ctx, bpf_htons(ETH_P_IP), 0); 638 661 if (err) 639 662 goto out; 640 663