1 /* Copyright (c) 2017 Facebook
3 * This program is free software; you can redistribute it and/or
4 * modify it under the terms of version 2 of the GNU General Public
5 * License as published by the Free Software Foundation.
10 #include <linux/pkt_cls.h>
11 #include "bpf_helpers.h"
13 int _version
SEC("version") = 1;
15 #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
16 #define TEST_FIELD(TYPE, FIELD, MASK) \
18 TYPE tmp = *(volatile TYPE *)&skb->FIELD; \
19 if (tmp != ((*(volatile __u32 *)&skb->FIELD) & MASK)) \
23 #define TEST_FIELD_OFFSET(a, b) ((sizeof(a) - sizeof(b)) / sizeof(b))
24 #define TEST_FIELD(TYPE, FIELD, MASK) \
26 TYPE tmp = *((volatile TYPE *)&skb->FIELD + \
27 TEST_FIELD_OFFSET(skb->FIELD, TYPE)); \
28 if (tmp != ((*(volatile __u32 *)&skb->FIELD) & MASK)) \
34 int process(struct __sk_buff
*skb
)
36 TEST_FIELD(__u8
, len
, 0xFF);
37 TEST_FIELD(__u16
, len
, 0xFFFF);
38 TEST_FIELD(__u32
, len
, 0xFFFFFFFF);
39 TEST_FIELD(__u16
, protocol
, 0xFFFF);
40 TEST_FIELD(__u32
, protocol
, 0xFFFFFFFF);
41 TEST_FIELD(__u8
, hash
, 0xFF);
42 TEST_FIELD(__u16
, hash
, 0xFFFF);
43 TEST_FIELD(__u32
, hash
, 0xFFFFFFFF);