mirror of
https://github.com/torvalds/linux.git
synced 2025-12-07 20:06:24 +00:00
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:
committed by
Martin KaFai Lau
parent
85d454afef
commit
d2c5cca3fb
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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";
|
||||
|
||||
Reference in New Issue
Block a user