blob: 87e5225f7559bd292454fd526345bc0f3a469744 [file] [log] [blame]
Marco Varleseb598f1d2017-09-19 14:25:28 +02001/*
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
58typedef struct
59{
60 u16 opt_class;
61 u8 type;
62 u8 res:3;
63 u8 length:5;
64 u32 opt_data[];
65} geneve_options_t;
66
67/*
68 *
69 * As per draft https://tools.ietf.org/html/draft-ietf-nvo3-geneve-05
70 *
71 * Section 3/3.4
72 *
73 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
74 * |Ver| Opt Len |O|C| Rsvd. | Protocol Type |
75 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
76 * | Virtual Network Identifier (VNI) | Reserved |
77 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
78 * | Variable Length Options |
79 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
80 *
81 */
82#define GENEVE_BASE_HEADER_LENGTH 8 // GENEVE BASE HEADER in bytes
83#define GENEVE_MAX_TOTAL_HDR_LENGTH 260
84
85#define GENEVE_VERSION 0
86#define GENEVE_ETH_PROTOCOL 0x6558
87
88typedef struct
89{
90 u8 ver:2;
91 u8 opt_len:6;
92 u8 oam_frame:1;
93 u8 critical_options:1;
94 u8 res1:6;
95 u16 protocol;
96 u32 vni:24;
97 u8 res2;
98 geneve_options_t opts[];
99} geneve_header_t;
100
101static inline u32
102vnet_get_geneve_vni (geneve_header_t * h)
103{
104 return (clib_net_to_host_u32 (h->vni) >> 8);
105}
106
107static inline void
108vnet_set_geneve_vni (geneve_header_t * h, u32 vni)
109{
110 h->vni = clib_host_to_net_u32 (vni << 8);
111}
112
113static inline u8
114vnet_get_geneve_version (geneve_header_t * h)
115{
116 return (clib_net_to_host_u32 (h->ver) >> 30);
117}
118
119static inline void
120vnet_set_geneve_version (geneve_header_t * h, u8 version)
121{
122 h->ver = clib_host_to_net_u32 (version << 30);
123}
124
125static inline u8
126vnet_get_geneve_options_len (geneve_header_t * h)
127{
128 return (clib_net_to_host_u32 (h->opt_len) >> 24);
129}
130
131static inline void
132vnet_set_geneve_options_len (geneve_header_t * h, u8 len)
133{
134 h->opt_len = clib_host_to_net_u32 (len << 24);
135}
136
137static inline u8
138vnet_get_geneve_oamframe_bit (geneve_header_t * h)
139{
140 return (clib_net_to_host_u32 (h->oam_frame) >> 23);
141}
142
143static inline void
144vnet_set_geneve_oamframe_bit (geneve_header_t * h, u8 oam)
145{
146 h->oam_frame = clib_host_to_net_u32 (oam << 23);
147}
148
149static inline u8
150vnet_get_geneve_critical_bit (geneve_header_t * h)
151{
152 return (clib_net_to_host_u32 (h->critical_options) >> 22);
153}
154
155static inline void
156vnet_set_geneve_critical_bit (geneve_header_t * h, u8 critical_opts)
157{
158 h->critical_options = clib_host_to_net_u32 (critical_opts << 22);
159}
160
161static inline u16
162vnet_get_geneve_protocol (geneve_header_t * h)
163{
164 return clib_net_to_host_u32 (h->protocol);
165}
166
167static inline void
168vnet_set_geneve_protocol (geneve_header_t * h, u16 protocol)
169{
170 h->protocol = clib_host_to_net_u32 (protocol);
171}
172#endif
173
174/*
175 * fd.io coding-style-patch-verification: ON
176 *
177 * Local Variables:
178 * eval: (c-set-style "gnu")
179 * End:
180 */