Commit d2c5cca3 authored by Jakub Sitnicki's avatar Jakub Sitnicki Committed by Martin KaFai Lau
Browse files

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: default avatarJakub Sitnicki <jakub@cloudflare.com>
Signed-off-by: default avatarMartin KaFai Lau <martin.lau@kernel.org>
Link: https://patch.msgid.link/20251105-skb-meta-rx-path-v4-16-5ceb08a9b37b@cloudflare.com
parent 85d454af
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -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);
}
+25 −0
Original line number Diff line number Diff line
@@ -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 @@ int helper_skb_change_head_tail(struct __sk_buff *ctx)
	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";