Skip to content

Commit e078e5c

Browse files
jsitnickiKernel Patches Daemon
authored andcommitted
selftests/bpf: Cover skb metadata access after vlan push/pop helper
Add a test to verify that skb metadata remains accessible after calling bpf_skb_vlan_push() and bpf_skb_vlan_pop(), which modify the packet headroom. Signed-off-by: Jakub Sitnicki <[email protected]>
1 parent 6050b9d commit e078e5c

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -478,6 +478,12 @@ void test_xdp_context_tuntap(void)
478478
test_tuntap_mirred(skel->progs.ing_xdp,
479479
skel->progs.clone_meta_dynptr_rw_before_meta_dynptr_write,
480480
&skel->bss->test_pass);
481+
/* Tests for BPF helpers which touch headroom */
482+
if (test__start_subtest("helper_skb_vlan_push_pop"))
483+
test_tuntap(skel->progs.ing_xdp,
484+
skel->progs.helper_skb_vlan_push_pop,
485+
NULL, /* tc prio 2 */
486+
&skel->bss->test_pass);
481487

482488
test_xdp_meta__destroy(skel);
483489
}

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

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,16 @@ static bool check_metadata(const char *file, int line, __u8 *meta_have)
4444

4545
#define check_metadata(meta_have) check_metadata(__FILE__, __LINE__, meta_have)
4646

47+
static bool check_skb_metadata(const char *file, int line, struct __sk_buff *skb)
48+
{
49+
__u8 *data_meta = ctx_ptr(skb, data_meta);
50+
__u8 *data = ctx_ptr(skb, data);
51+
52+
return data_meta + META_SIZE <= data && (check_metadata)(file, line, data_meta);
53+
}
54+
55+
#define check_skb_metadata(skb) check_skb_metadata(__FILE__, __LINE__, skb)
56+
4757
SEC("tc")
4858
int ing_cls(struct __sk_buff *ctx)
4959
{
@@ -525,4 +535,37 @@ int clone_meta_dynptr_rw_before_meta_dynptr_write(struct __sk_buff *ctx)
525535
return TC_ACT_SHOT;
526536
}
527537

538+
SEC("tc")
539+
int helper_skb_vlan_push_pop(struct __sk_buff *ctx)
540+
{
541+
int err;
542+
543+
/* bpf_skb_vlan_push assumes HW offload for primary VLAN tag. Only
544+
* secondary tag push triggers an actual MAC header modification.
545+
*/
546+
err = bpf_skb_vlan_push(ctx, 0, 42);
547+
if (err)
548+
goto out;
549+
err = bpf_skb_vlan_push(ctx, 0, 207);
550+
if (err)
551+
goto out;
552+
553+
if (!check_skb_metadata(ctx))
554+
goto out;
555+
556+
err = bpf_skb_vlan_pop(ctx);
557+
if (err)
558+
goto out;
559+
err = bpf_skb_vlan_pop(ctx);
560+
if (err)
561+
goto out;
562+
563+
if (!check_skb_metadata(ctx))
564+
goto out;
565+
566+
test_pass = true;
567+
out:
568+
return TC_ACT_SHOT;
569+
}
570+
528571
char _license[] SEC("license") = "GPL";

0 commit comments

Comments
 (0)