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
This commit is contained in:
Jakub Sitnicki
2025-11-05 21:19:53 +01:00
committed by Martin KaFai Lau
parent 85d454afef
commit d2c5cca3fb
2 changed files with 30 additions and 0 deletions

View File

@@ -502,6 +502,11 @@ void test_xdp_context_tuntap(void)
skel->progs.helper_skb_change_head_tail,
NULL, /* tc prio 2 */
&skel->bss->test_pass);
if (test__start_subtest("helper_skb_change_proto"))
test_tuntap(skel->progs.ing_xdp,
skel->progs.helper_skb_change_proto,
NULL, /* tc prio 2 */
&skel->bss->test_pass);
test_xdp_meta__destroy(skel);
}

View File

@@ -4,6 +4,7 @@
#include <linux/if_ether.h>
#include <linux/pkt_cls.h>
#include <bpf/bpf_endian.h>
#include <bpf/bpf_helpers.h>
#include "bpf_kfuncs.h"
@@ -645,4 +646,28 @@ out:
return TC_ACT_SHOT;
}
SEC("tc")
int helper_skb_change_proto(struct __sk_buff *ctx)
{
int err;
err = bpf_skb_change_proto(ctx, bpf_htons(ETH_P_IPV6), 0);
if (err)
goto out;
if (!check_skb_metadata(ctx))
goto out;
err = bpf_skb_change_proto(ctx, bpf_htons(ETH_P_IP), 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";