1 | /* SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause */ |
2 | /* Copyright 2019, 2020 Cloudflare */ |
3 | |
4 | #include <stdbool.h> |
5 | #include <stddef.h> |
6 | #include <stdint.h> |
7 | #include <string.h> |
8 | |
9 | #include <linux/if_ether.h> |
10 | #include <linux/in.h> |
11 | #include <linux/ip.h> |
12 | #include <linux/ipv6.h> |
13 | #include <linux/udp.h> |
14 | |
15 | /* offsetof() is used in static asserts, and the libbpf-redefined CO-RE |
16 | * friendly version breaks compilation for older clang versions <= 15 |
17 | * when invoked in a static assert. Restore original here. |
18 | */ |
19 | #ifdef offsetof |
20 | #undef offsetof |
21 | #define offsetof(type, member) __builtin_offsetof(type, member) |
22 | #endif |
23 | |
24 | struct gre_base_hdr { |
25 | uint16_t flags; |
26 | uint16_t protocol; |
27 | } __attribute__((packed)); |
28 | |
29 | struct guehdr { |
30 | #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ |
31 | uint8_t hlen : 5, control : 1, variant : 2; |
32 | #else |
33 | uint8_t variant : 2, control : 1, hlen : 5; |
34 | #endif |
35 | uint8_t proto_ctype; |
36 | uint16_t flags; |
37 | }; |
38 | |
39 | struct unigue { |
40 | #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ |
41 | uint8_t _r : 2, last_hop_gre : 1, forward_syn : 1, version : 4; |
42 | #else |
43 | uint8_t version : 4, forward_syn : 1, last_hop_gre : 1, _r : 2; |
44 | #endif |
45 | uint8_t reserved; |
46 | uint8_t next_hop; |
47 | uint8_t hop_count; |
48 | // Next hops go here |
49 | } __attribute__((packed)); |
50 | |
51 | typedef struct { |
52 | struct ethhdr eth; |
53 | struct iphdr ip; |
54 | struct gre_base_hdr gre; |
55 | } __attribute__((packed)) encap_gre_t; |
56 | |
57 | typedef struct { |
58 | struct ethhdr ; |
59 | struct iphdr ; |
60 | struct udphdr ; |
61 | struct guehdr ; |
62 | struct unigue ; |
63 | } __attribute__((packed)) ; |
64 | |