FD.io VPP  v21.06-3-gbb25fbf28
Vector Packet Processing
geneve_packet.h
Go to the documentation of this file.
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 
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  */
67 typedef struct
68 {
71  /* The 3 reserved bits are for future use;
72  * Need to be 0 on sending and ignored on receipt.
73  */
75  /* Length is expressed in 4-bytes multiples excluding the options header. */
77  u32 opt_data[];
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 {
103  /*
104  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
105  * |Ver| Opt Len |O|C| Rsvd. | Protocol Type |
106  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
107  */
109 
110  /*
111  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
112  * | Virtual Network Identifier (VNI) | Reserved |
113  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
114  */
118 
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  */
137 static inline u32
139 {
140  return ((clib_net_to_host_u32 (h->vni_rsvd) & GENEVE_VNI_MASK) >>
142 }
143 
144 static inline u32
146 {
147  return (h->vni_rsvd & clib_net_to_host_u32 (GENEVE_VNI_MASK));
148 }
149 
150 static inline void
152 {
153  h->vni_rsvd &= ~(GENEVE_VNI_MASK);
154  h->vni_rsvd |=
155  clib_host_to_net_u32 ((vni << GENEVE_VNI_SHIFT) & GENEVE_VNI_MASK);
156 }
157 
158 static inline u8
160 {
161  return ((h->first_word & GENEVE_VERSION_MASK) >> GENEVE_VERSION_SHIFT);
162 }
163 
164 static inline void
166 {
167  h->first_word &= ~(GENEVE_VERSION_MASK);
168  h->first_word |= ((version << GENEVE_VERSION_SHIFT) & GENEVE_VERSION_MASK);
169 }
170 
171 static inline u8
173 {
174  return ((h->first_word & GENEVE_OPTLEN_MASK) >> GENEVE_OPTLEN_SHIFT) << 2;
175 }
176 
177 static inline void
179 {
180  ASSERT ((len & 0x3) == 0);
181  h->first_word &= ~(GENEVE_OPTLEN_MASK);
182  h->first_word |= ((len << (GENEVE_OPTLEN_SHIFT - 2)) & GENEVE_OPTLEN_MASK);
183 }
184 
185 static inline u8
187 {
188  return ((h->first_word & GENEVE_O_BIT_MASK) >> GENEVE_O_BIT_SHIFT);
189 }
190 
191 static inline void
193 {
194  h->first_word &= ~(GENEVE_O_BIT_MASK);
195  h->first_word |= ((oam << GENEVE_O_BIT_SHIFT) & GENEVE_O_BIT_MASK);
196 }
197 
198 static inline u8
200 {
201  return ((h->first_word & GENEVE_C_BIT_MASK) >> GENEVE_C_BIT_SHIFT);
202 }
203 
204 static inline void
206 {
207  h->first_word &= ~(GENEVE_C_BIT_MASK);
208  h->first_word |=
209  ((critical_opts << GENEVE_C_BIT_SHIFT) & GENEVE_C_BIT_MASK);
210 }
211 
212 static inline u16
214 {
215  return (h->first_word & GENEVE_PROTOCOL_MASK);
216 }
217 
218 static inline void
220 {
221  h->first_word &= ~(GENEVE_PROTOCOL_MASK);
222  h->first_word |= (protocol & GENEVE_PROTOCOL_MASK);
223 }
224 
225 static inline void
227 {
228  h->first_word = clib_net_to_host_u32 (h->first_word);
229 }
230 
231 static inline void
233 {
234  h->first_word = clib_host_to_net_u32 (h->first_word);
235 }
236 
237 #endif
238 
239 /*
240  * fd.io coding-style-patch-verification: ON
241  *
242  * Local Variables:
243  * eval: (c-set-style "gnu")
244  * End:
245  */
geneve_options_t::type
u8 type
Definition: geneve_packet.h:70
vnet_set_geneve_protocol
static void vnet_set_geneve_protocol(geneve_header_t *h, u16 protocol)
Definition: geneve_packet.h:219
GENEVE_PROTOCOL_MASK
#define GENEVE_PROTOCOL_MASK
Definition: geneve_packet.h:131
geneve_options_t::opt_class
u16 opt_class
Definition: geneve_packet.h:69
GENEVE_C_BIT_MASK
#define GENEVE_C_BIT_MASK
Definition: geneve_packet.h:129
vni
u32 vni
Definition: flow_types.api:160
u16
unsigned short u16
Definition: types.h:57
vnet_get_geneve_version
static u8 vnet_get_geneve_version(geneve_header_t *h)
Definition: geneve_packet.h:159
vnet_get_geneve_vni_network_order
static u32 vnet_get_geneve_vni_network_order(geneve_header_t *h)
Definition: geneve_packet.h:145
geneve_header_t::vni_rsvd
u32 vni_rsvd
Definition: geneve_packet.h:115
vnet_set_geneve_critical_bit
static void vnet_set_geneve_critical_bit(geneve_header_t *h, u8 critical_opts)
Definition: geneve_packet.h:205
vnet_set_geneve_vni
static void vnet_set_geneve_vni(geneve_header_t *h, u32 vni)
Definition: geneve_packet.h:151
GENEVE_C_BIT_SHIFT
#define GENEVE_C_BIT_SHIFT
Definition: geneve_packet.h:122
h
h
Definition: flowhash_template.h:372
GENEVE_VNI_SHIFT
#define GENEVE_VNI_SHIFT
Definition: geneve_packet.h:124
len
u8 len
Definition: ip_types.api:103
vnet_geneve_hdr_1word_hton
static void vnet_geneve_hdr_1word_hton(geneve_header_t *h)
Definition: geneve_packet.h:232
geneve_options_t::length
u8 length
Definition: geneve_packet.h:76
vnet_get_geneve_protocol
static u16 vnet_get_geneve_protocol(geneve_header_t *h)
Definition: geneve_packet.h:213
GENEVE_O_BIT_SHIFT
#define GENEVE_O_BIT_SHIFT
Definition: geneve_packet.h:121
vnet_get_geneve_critical_bit
static u8 vnet_get_geneve_critical_bit(geneve_header_t *h)
Definition: geneve_packet.h:199
geneve_header_t::first_word
u32 first_word
Definition: geneve_packet.h:108
ASSERT
#define ASSERT(truth)
Definition: error_bootstrap.h:69
version
option version
Definition: sample.api:19
vnet_set_geneve_oamframe_bit
static void vnet_set_geneve_oamframe_bit(geneve_header_t *h, u8 oam)
Definition: geneve_packet.h:192
u32
unsigned int u32
Definition: types.h:88
protocol
vl_api_ip_proto_t protocol
Definition: lb_types.api:72
geneve_options_t
Definition: geneve_packet.h:67
geneve_options_t::res
u8 res
Definition: geneve_packet.h:74
GENEVE_VERSION_MASK
#define GENEVE_VERSION_MASK
Definition: geneve_packet.h:126
vnet_get_geneve_oamframe_bit
static u8 vnet_get_geneve_oamframe_bit(geneve_header_t *h)
Definition: geneve_packet.h:186
geneve_header_t
Definition: geneve_packet.h:101
u8
unsigned char u8
Definition: types.h:56
vnet_set_geneve_options_len
static void vnet_set_geneve_options_len(geneve_header_t *h, u8 len)
Definition: geneve_packet.h:178
GENEVE_OPTLEN_MASK
#define GENEVE_OPTLEN_MASK
Definition: geneve_packet.h:127
vnet_get_geneve_vni
static u32 vnet_get_geneve_vni(geneve_header_t *h)
Definition: geneve_packet.h:138
GENEVE_VNI_MASK
#define GENEVE_VNI_MASK
Definition: geneve_packet.h:132
GENEVE_O_BIT_MASK
#define GENEVE_O_BIT_MASK
Definition: geneve_packet.h:128
vnet_geneve_hdr_1word_ntoh
static void vnet_geneve_hdr_1word_ntoh(geneve_header_t *h)
Definition: geneve_packet.h:226
vnet_get_geneve_options_len
static u8 vnet_get_geneve_options_len(geneve_header_t *h)
Definition: geneve_packet.h:172
vnet_set_geneve_version
static void vnet_set_geneve_version(geneve_header_t *h, u8 version)
Definition: geneve_packet.h:165
GENEVE_OPTLEN_SHIFT
#define GENEVE_OPTLEN_SHIFT
Definition: geneve_packet.h:120
GENEVE_VERSION_SHIFT
#define GENEVE_VERSION_SHIFT
Definition: geneve_packet.h:119