1 // SPDX-License-Identifier: GPL-2.0-only
2 /* Copyright (c) 2017 Facebook
7 #include <linux/pkt_cls.h>
8 #include <bpf/bpf_helpers.h>
10 int _version
SEC("version") = 1;
12 #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
13 #define TEST_FIELD(TYPE, FIELD, MASK) \
15 TYPE tmp = *(volatile TYPE *)&skb->FIELD; \
16 if (tmp != ((*(volatile __u32 *)&skb->FIELD) & MASK)) \
20 #define TEST_FIELD_OFFSET(a, b) ((sizeof(a) - sizeof(b)) / sizeof(b))
21 #define TEST_FIELD(TYPE, FIELD, MASK) \
23 TYPE tmp = *((volatile TYPE *)&skb->FIELD + \
24 TEST_FIELD_OFFSET(skb->FIELD, TYPE)); \
25 if (tmp != ((*(volatile __u32 *)&skb->FIELD) & MASK)) \
30 SEC("classifier/test_pkt_md_access")
31 int test_pkt_md_access(struct __sk_buff
*skb
)
33 TEST_FIELD(__u8
, len
, 0xFF);
34 TEST_FIELD(__u16
, len
, 0xFFFF);
35 TEST_FIELD(__u32
, len
, 0xFFFFFFFF);
36 TEST_FIELD(__u16
, protocol
, 0xFFFF);
37 TEST_FIELD(__u32
, protocol
, 0xFFFFFFFF);
38 TEST_FIELD(__u8
, hash
, 0xFF);
39 TEST_FIELD(__u16
, hash
, 0xFFFF);
40 TEST_FIELD(__u32
, hash
, 0xFFFFFFFF);