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 struct gre_base_hdr { 16 uint16_t flags; 17 uint16_t protocol; 18 } __attribute__((packed)); 19 20 struct guehdr { 21 #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ 22 uint8_t hlen : 5, control : 1, variant : 2; 23 #else 24 uint8_t variant : 2, control : 1, hlen : 5; 25 #endif 26 uint8_t proto_ctype; 27 uint16_t flags; 28 }; 29 30 struct unigue { 31 #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ 32 uint8_t _r : 2, last_hop_gre : 1, forward_syn : 1, version : 4; 33 #else 34 uint8_t version : 4, forward_syn : 1, last_hop_gre : 1, _r : 2; 35 #endif 36 uint8_t reserved; 37 uint8_t next_hop; 38 uint8_t hop_count; 39 // Next hops go here 40 } __attribute__((packed)); 41 42 typedef struct { 43 struct ethhdr eth; 44 struct iphdr ip; 45 struct gre_base_hdr gre; 46 } __attribute__((packed)) encap_gre_t; 47 48 typedef struct { 49 struct ethhdr eth; 50 struct iphdr ip; 51 struct udphdr udp; 52 struct guehdr gue; 53 struct unigue unigue; 54 } __attribute__((packed)) encap_headers_t; 55