Skip to content

Commit c8bbf87

Browse files
jsitnickiKernel Patches Daemon
authored andcommitted
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 8d01859 commit c8bbf87

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
@@ -502,6 +502,11 @@ void test_xdp_context_tuntap(void)
502502
skel->progs.helper_skb_change_head_tail,
503503
NULL, /* tc prio 2 */
504504
&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);
505510

506511
test_xdp_meta__destroy(skel);
507512
}

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)