github.com/cilium/cilium@v1.16.2/bpf/lib/tunnel.h (about) 1 /* SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) */ 2 /* Copyright Authors of Cilium */ 3 4 #pragma once 5 6 #include <linux/ipv6.h> 7 8 /* The high-order bit of the Geneve option type indicates that 9 * this is a critical option. 10 * 11 * https://www.rfc-editor.org/rfc/rfc8926.html#name-tunnel-options 12 */ 13 #define GENEVE_OPT_TYPE_CRIT 0x80 14 15 /* Geneve option used to carry service addr and port for DSR. 16 * 17 * Class = 0x014B (Cilium according to [1]) 18 * Type = 0x1 (vendor-specific) 19 * 20 * [1]: https://www.iana.org/assignments/nvo3/nvo3.xhtml#geneve-option-class 21 */ 22 #define DSR_GENEVE_OPT_CLASS 0x014B 23 #define DSR_GENEVE_OPT_TYPE (GENEVE_OPT_TYPE_CRIT | 0x01) 24 #define DSR_IPV4_GENEVE_OPT_LEN \ 25 ((sizeof(struct geneve_dsr_opt4) - sizeof(struct geneve_opt_hdr)) / 4) 26 #define DSR_IPV6_GENEVE_OPT_LEN \ 27 ((sizeof(struct geneve_dsr_opt6) - sizeof(struct geneve_opt_hdr)) / 4) 28 29 struct geneve_opt_hdr { 30 __be16 opt_class; 31 __u8 type; 32 #ifdef __LITTLE_ENDIAN_BITFIELD 33 __u8 length:5, rsvd:3; 34 #else 35 __u8 rsvd:3, length:5; 36 #endif 37 }; 38 39 struct geneve_dsr_opt4 { 40 struct geneve_opt_hdr hdr; 41 __be32 addr; 42 __be16 port; 43 __u16 pad; 44 }; 45 46 struct geneve_dsr_opt6 { 47 struct geneve_opt_hdr hdr; 48 struct in6_addr addr; 49 __be16 port; 50 __u16 pad; 51 }; 52 53 struct genevehdr { 54 #ifdef __LITTLE_ENDIAN_BITFIELD 55 __u8 opt_len:6, ver:2; 56 __u8 rsvd:6, critical:1, control:1; 57 #else 58 __u8 ver:2, opt_len:6; 59 __u8 control:1, critical:1, rsvd:6; 60 #endif 61 __be16 protocol_type; 62 __u8 vni[3]; 63 __u8 reserved; 64 }; 65 66 struct vxlanhdr { 67 __be32 vx_flags; 68 __be32 vx_vni; 69 }; 70 71 static __always_inline __u32 tunnel_vni_to_sec_identity(__be32 vni) 72 { 73 return bpf_ntohl(vni) >> 8; 74 } 75 76 static __always_inline __be32 sec_identity_to_tunnel_vni(__u32 sec_identity) 77 { 78 return bpf_htonl(sec_identity << 8); 79 }