Marco Varlese | b598f1d | 2017-09-19 14:25:28 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2017 SUSE LLC. |
| 3 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | * you may not use this file except in compliance with the License. |
| 5 | * You may obtain a copy of the License at: |
| 6 | * |
| 7 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | * |
| 9 | * Unless required by applicable law or agreed to in writing, software |
| 10 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | * See the License for the specific language governing permissions and |
| 13 | * limitations under the License. |
| 14 | */ |
| 15 | |
| 16 | #ifndef included_vnet_geneve_packet_h |
| 17 | #define included_vnet_geneve_packet_h |
| 18 | |
| 19 | /* |
| 20 | * |
| 21 | * As per draft https://tools.ietf.org/html/draft-ietf-nvo3-geneve-05 |
| 22 | * |
| 23 | * Section 3.5 |
| 24 | * |
| 25 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 26 | * | Option Class | Type |R|R|R| Length | |
| 27 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 28 | * | Variable Option Data | |
| 29 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 30 | */ |
| 31 | #define GENEVE_MAX_OPT_LENGTH 128 |
| 32 | |
| 33 | /* |
| 34 | * |
| 35 | * As per draft https://tools.ietf.org/html/draft-ietf-nvo3-geneve-05 |
| 36 | * |
| 37 | * Section 7 |
| 38 | * |
| 39 | * +----------------+--------------------------------------+ |
| 40 | * | Option Class | Description | |
| 41 | * +----------------+--------------------------------------+ |
| 42 | * | 0x0000..0x00FF | Unassigned - IETF Review | |
| 43 | * | 0x0100 | Linux | |
| 44 | * | 0x0101 | Open vSwitch | |
| 45 | * | 0x0102 | Open Virtual Networking (OVN) | |
| 46 | * | 0x0103 | In-band Network Telemetry (INT) | |
| 47 | * | 0x0104 | VMware | |
| 48 | * | 0x0105..0xFFEF | Unassigned - First Come First Served | |
| 49 | * | 0xFFF0..FFFF | Experimental | |
| 50 | * +----------------+--------------------------------------+ |
| 51 | */ |
| 52 | #define LINUX_OPT_CLASS 0x0100 |
| 53 | #define OVS_OPT_CLASS 0x0101 |
| 54 | #define OVN_OPT_CLASS 0x0102 |
| 55 | #define INT_OPT_CLASS 0x0103 |
| 56 | #define VMWARE_OPT_CLASS 0x0104 |
| 57 | |
Marco Varlese | 60d48bb | 2017-11-20 09:20:38 +0100 | [diff] [blame] | 58 | /* |
| 59 | * 0 1 2 3 |
| 60 | * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 |
| 61 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 62 | * | Option Class | Type |R|R|R| Length | |
| 63 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 64 | * | Variable Option Data | |
| 65 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 66 | */ |
Marco Varlese | b598f1d | 2017-09-19 14:25:28 +0200 | [diff] [blame] | 67 | typedef struct |
| 68 | { |
| 69 | u16 opt_class; |
| 70 | u8 type; |
Marco Varlese | 60d48bb | 2017-11-20 09:20:38 +0100 | [diff] [blame] | 71 | /* The 3 reserved bits are for future use; |
| 72 | * Need to be 0 on sending and ignored on receipt. |
| 73 | */ |
| 74 | u8 res; |
| 75 | /* Length is expressed in 4-bytes multiples excluding the options header. */ |
| 76 | u8 length; |
Marco Varlese | b598f1d | 2017-09-19 14:25:28 +0200 | [diff] [blame] | 77 | u32 opt_data[]; |
| 78 | } geneve_options_t; |
| 79 | |
| 80 | /* |
| 81 | * |
| 82 | * As per draft https://tools.ietf.org/html/draft-ietf-nvo3-geneve-05 |
| 83 | * |
| 84 | * Section 3/3.4 |
| 85 | * |
| 86 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 87 | * |Ver| Opt Len |O|C| Rsvd. | Protocol Type | |
| 88 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 89 | * | Virtual Network Identifier (VNI) | Reserved | |
| 90 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 91 | * | Variable Length Options | |
| 92 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 93 | * |
| 94 | */ |
| 95 | #define GENEVE_BASE_HEADER_LENGTH 8 // GENEVE BASE HEADER in bytes |
| 96 | #define GENEVE_MAX_TOTAL_HDR_LENGTH 260 |
| 97 | |
| 98 | #define GENEVE_VERSION 0 |
| 99 | #define GENEVE_ETH_PROTOCOL 0x6558 |
| 100 | |
| 101 | typedef struct |
| 102 | { |
Marco Varlese | 60d48bb | 2017-11-20 09:20:38 +0100 | [diff] [blame] | 103 | /* |
| 104 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 105 | * |Ver| Opt Len |O|C| Rsvd. | Protocol Type | |
| 106 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 107 | */ |
| 108 | u32 first_word; |
| 109 | |
| 110 | /* |
| 111 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 112 | * | Virtual Network Identifier (VNI) | Reserved | |
| 113 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 114 | */ |
| 115 | u32 vni_rsvd; |
Marco Varlese | b598f1d | 2017-09-19 14:25:28 +0200 | [diff] [blame] | 116 | geneve_options_t opts[]; |
| 117 | } geneve_header_t; |
| 118 | |
Marco Varlese | 60d48bb | 2017-11-20 09:20:38 +0100 | [diff] [blame] | 119 | #define GENEVE_VERSION_SHIFT 30 |
| 120 | #define GENEVE_OPTLEN_SHIFT 24 |
| 121 | #define GENEVE_O_BIT_SHIFT 23 |
| 122 | #define GENEVE_C_BIT_SHIFT 22 |
| 123 | #define GENEVE_6_RESERVED_SHIFT 16 |
| 124 | #define GENEVE_VNI_SHIFT 8 |
| 125 | |
| 126 | #define GENEVE_VERSION_MASK 0xC0000000 |
| 127 | #define GENEVE_OPTLEN_MASK 0x3F000000 |
| 128 | #define GENEVE_O_BIT_MASK 0x00800000 |
| 129 | #define GENEVE_C_BIT_MASK 0x00400000 |
| 130 | #define GENEVE_6_RESERVED_MASK 0x003F0000 |
| 131 | #define GENEVE_PROTOCOL_MASK 0x0000FFFF |
| 132 | #define GENEVE_VNI_MASK 0xFFFFFF00 |
| 133 | |
| 134 | /* |
| 135 | * Return the VNI in host-byte order |
| 136 | */ |
Marco Varlese | b598f1d | 2017-09-19 14:25:28 +0200 | [diff] [blame] | 137 | static inline u32 |
| 138 | vnet_get_geneve_vni (geneve_header_t * h) |
| 139 | { |
Neale Ranns | 91fd910 | 2020-04-03 07:46:28 +0000 | [diff] [blame] | 140 | return ((clib_net_to_host_u32 (h->vni_rsvd) & GENEVE_VNI_MASK) >> |
Marco Varlese | 60d48bb | 2017-11-20 09:20:38 +0100 | [diff] [blame] | 141 | GENEVE_VNI_SHIFT); |
| 142 | } |
| 143 | |
Marco Varlese | 60d48bb | 2017-11-20 09:20:38 +0100 | [diff] [blame] | 144 | static inline u32 |
Neale Ranns | 91fd910 | 2020-04-03 07:46:28 +0000 | [diff] [blame] | 145 | vnet_get_geneve_vni_network_order (geneve_header_t * h) |
Marco Varlese | 60d48bb | 2017-11-20 09:20:38 +0100 | [diff] [blame] | 146 | { |
Neale Ranns | 91fd910 | 2020-04-03 07:46:28 +0000 | [diff] [blame] | 147 | return (h->vni_rsvd & clib_net_to_host_u32 (GENEVE_VNI_MASK)); |
Marco Varlese | b598f1d | 2017-09-19 14:25:28 +0200 | [diff] [blame] | 148 | } |
| 149 | |
| 150 | static inline void |
| 151 | vnet_set_geneve_vni (geneve_header_t * h, u32 vni) |
| 152 | { |
Marco Varlese | 60d48bb | 2017-11-20 09:20:38 +0100 | [diff] [blame] | 153 | h->vni_rsvd &= ~(GENEVE_VNI_MASK); |
| 154 | h->vni_rsvd |= |
| 155 | clib_host_to_net_u32 ((vni << GENEVE_VNI_SHIFT) & GENEVE_VNI_MASK); |
Marco Varlese | b598f1d | 2017-09-19 14:25:28 +0200 | [diff] [blame] | 156 | } |
| 157 | |
| 158 | static inline u8 |
| 159 | vnet_get_geneve_version (geneve_header_t * h) |
| 160 | { |
Marco Varlese | 60d48bb | 2017-11-20 09:20:38 +0100 | [diff] [blame] | 161 | return ((h->first_word & GENEVE_VERSION_MASK) >> GENEVE_VERSION_SHIFT); |
Marco Varlese | b598f1d | 2017-09-19 14:25:28 +0200 | [diff] [blame] | 162 | } |
| 163 | |
| 164 | static inline void |
| 165 | vnet_set_geneve_version (geneve_header_t * h, u8 version) |
| 166 | { |
Marco Varlese | 60d48bb | 2017-11-20 09:20:38 +0100 | [diff] [blame] | 167 | h->first_word &= ~(GENEVE_VERSION_MASK); |
| 168 | h->first_word |= ((version << GENEVE_VERSION_SHIFT) & GENEVE_VERSION_MASK); |
Marco Varlese | b598f1d | 2017-09-19 14:25:28 +0200 | [diff] [blame] | 169 | } |
| 170 | |
| 171 | static inline u8 |
| 172 | vnet_get_geneve_options_len (geneve_header_t * h) |
| 173 | { |
Marco Varlese | 60d48bb | 2017-11-20 09:20:38 +0100 | [diff] [blame] | 174 | return ((h->first_word & GENEVE_OPTLEN_MASK) >> GENEVE_OPTLEN_SHIFT); |
Marco Varlese | b598f1d | 2017-09-19 14:25:28 +0200 | [diff] [blame] | 175 | } |
| 176 | |
| 177 | static inline void |
| 178 | vnet_set_geneve_options_len (geneve_header_t * h, u8 len) |
| 179 | { |
Marco Varlese | 60d48bb | 2017-11-20 09:20:38 +0100 | [diff] [blame] | 180 | h->first_word &= ~(GENEVE_OPTLEN_MASK); |
| 181 | h->first_word |= ((len << GENEVE_OPTLEN_SHIFT) & GENEVE_OPTLEN_MASK); |
Marco Varlese | b598f1d | 2017-09-19 14:25:28 +0200 | [diff] [blame] | 182 | } |
| 183 | |
| 184 | static inline u8 |
| 185 | vnet_get_geneve_oamframe_bit (geneve_header_t * h) |
| 186 | { |
Marco Varlese | 60d48bb | 2017-11-20 09:20:38 +0100 | [diff] [blame] | 187 | return ((h->first_word & GENEVE_O_BIT_MASK) >> GENEVE_O_BIT_SHIFT); |
Marco Varlese | b598f1d | 2017-09-19 14:25:28 +0200 | [diff] [blame] | 188 | } |
| 189 | |
| 190 | static inline void |
| 191 | vnet_set_geneve_oamframe_bit (geneve_header_t * h, u8 oam) |
| 192 | { |
Marco Varlese | 60d48bb | 2017-11-20 09:20:38 +0100 | [diff] [blame] | 193 | h->first_word &= ~(GENEVE_O_BIT_MASK); |
| 194 | h->first_word |= ((oam << GENEVE_O_BIT_SHIFT) & GENEVE_O_BIT_MASK); |
Marco Varlese | b598f1d | 2017-09-19 14:25:28 +0200 | [diff] [blame] | 195 | } |
| 196 | |
| 197 | static inline u8 |
| 198 | vnet_get_geneve_critical_bit (geneve_header_t * h) |
| 199 | { |
Marco Varlese | 60d48bb | 2017-11-20 09:20:38 +0100 | [diff] [blame] | 200 | return ((h->first_word & GENEVE_C_BIT_MASK) >> GENEVE_C_BIT_SHIFT); |
Marco Varlese | b598f1d | 2017-09-19 14:25:28 +0200 | [diff] [blame] | 201 | } |
| 202 | |
| 203 | static inline void |
| 204 | vnet_set_geneve_critical_bit (geneve_header_t * h, u8 critical_opts) |
| 205 | { |
Marco Varlese | 60d48bb | 2017-11-20 09:20:38 +0100 | [diff] [blame] | 206 | h->first_word &= ~(GENEVE_C_BIT_MASK); |
| 207 | h->first_word |= |
| 208 | ((critical_opts << GENEVE_C_BIT_SHIFT) & GENEVE_C_BIT_MASK); |
Marco Varlese | b598f1d | 2017-09-19 14:25:28 +0200 | [diff] [blame] | 209 | } |
| 210 | |
| 211 | static inline u16 |
| 212 | vnet_get_geneve_protocol (geneve_header_t * h) |
| 213 | { |
Marco Varlese | 60d48bb | 2017-11-20 09:20:38 +0100 | [diff] [blame] | 214 | return (h->first_word & GENEVE_PROTOCOL_MASK); |
Marco Varlese | b598f1d | 2017-09-19 14:25:28 +0200 | [diff] [blame] | 215 | } |
| 216 | |
| 217 | static inline void |
| 218 | vnet_set_geneve_protocol (geneve_header_t * h, u16 protocol) |
| 219 | { |
Marco Varlese | 60d48bb | 2017-11-20 09:20:38 +0100 | [diff] [blame] | 220 | h->first_word &= ~(GENEVE_PROTOCOL_MASK); |
| 221 | h->first_word |= (protocol & GENEVE_PROTOCOL_MASK); |
Marco Varlese | b598f1d | 2017-09-19 14:25:28 +0200 | [diff] [blame] | 222 | } |
Marco Varlese | 60d48bb | 2017-11-20 09:20:38 +0100 | [diff] [blame] | 223 | |
| 224 | static inline void |
| 225 | vnet_geneve_hdr_1word_ntoh (geneve_header_t * h) |
| 226 | { |
| 227 | h->first_word = clib_net_to_host_u32 (h->first_word); |
| 228 | } |
| 229 | |
| 230 | static inline void |
| 231 | vnet_geneve_hdr_1word_hton (geneve_header_t * h) |
| 232 | { |
| 233 | h->first_word = clib_host_to_net_u32 (h->first_word); |
| 234 | } |
| 235 | |
Marco Varlese | b598f1d | 2017-09-19 14:25:28 +0200 | [diff] [blame] | 236 | #endif |
| 237 | |
| 238 | /* |
| 239 | * fd.io coding-style-patch-verification: ON |
| 240 | * |
| 241 | * Local Variables: |
| 242 | * eval: (c-set-style "gnu") |
| 243 | * End: |
| 244 | */ |