Skip to content

Commit 275d683

Browse files
committed
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 <[email protected]>
1 parent 458a097 commit 275d683

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

tools/testing/selftests/bpf/prog_tests/xdp_context_test_run.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -505,6 +505,11 @@ void test_xdp_context_tuntap(void)
505505
skel->progs.helper_skb_change_head_tail,
506506
NULL, /* tc prio 2 */
507507
&skel->bss->test_pass);
508+
if (test__start_subtest("helper_skb_change_proto"))
509+
test_tuntap(skel->progs.ing_xdp,
510+
skel->progs.helper_skb_change_proto,
511+
NULL, /* tc prio 2 */
512+
&skel->bss->test_pass);
508513

509514
test_xdp_meta__destroy(skel);
510515
}

tools/testing/selftests/bpf/progs/test_xdp_meta.c

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include <linux/if_ether.h>
55
#include <linux/pkt_cls.h>
66

7+
#include <bpf/bpf_endian.h>
78
#include <bpf/bpf_helpers.h>
89
#include "bpf_kfuncs.h"
910

@@ -645,4 +646,28 @@ int helper_skb_change_head_tail(struct __sk_buff *ctx)
645646
return TC_ACT_SHOT;
646647
}
647648

649+
SEC("tc")
650+
int helper_skb_change_proto(struct __sk_buff *ctx)
651+
{
652+
int err;
653+
654+
err = bpf_skb_change_proto(ctx, bpf_htons(ETH_P_IPV6), 0);
655+
if (err)
656+
goto out;
657+
658+
if (!check_skb_metadata(ctx))
659+
goto out;
660+
661+
err = bpf_skb_change_proto(ctx, bpf_htons(ETH_P_IP), 0);
662+
if (err)
663+
goto out;
664+
665+
if (!check_skb_metadata(ctx))
666+
goto out;
667+
668+
test_pass = true;
669+
out:
670+
return TC_ACT_SHOT;
671+
}
672+
648673
char _license[] SEC("license") = "GPL";

0 commit comments

Comments
 (0)