blob: 8f028df517f7f07e4c551a858d29475e7aaf3798 [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#ifndef included_vnet_geneve_h
16#define included_vnet_geneve_h
17
18#include <vppinfra/error.h>
19#include <vppinfra/hash.h>
20#include <vnet/vnet.h>
21#include <vnet/ip/ip.h>
22#include <vnet/l2/l2_input.h>
23#include <vnet/l2/l2_output.h>
24#include <vnet/l2/l2_bd.h>
25#include <vnet/ethernet/ethernet.h>
26#include <vnet/geneve/geneve_packet.h>
27#include <vnet/ip/ip4_packet.h>
28#include <vnet/ip/ip6_packet.h>
29#include <vnet/udp/udp.h>
30#include <vnet/dpo/dpo.h>
31#include <vnet/adj/adj_types.h>
32
33#define SUPPORT_OPTIONS_HEADER 0
34
35typedef CLIB_PACKED (struct
36 {
37 ip4_header_t ip4; /* 20 bytes */
38 udp_header_t udp; /* 8 bytes */
39 geneve_header_t geneve; /* Min 8 bytes, Max 260 bytes */
40 }) ip4_geneve_header_t;
41
42typedef CLIB_PACKED (struct
43 {
44 ip6_header_t ip6; /* 40 bytes */
45 udp_header_t udp; /* 8 bytes */
46 geneve_header_t geneve; /* Min 8 bytes, Max 260 bytes */
47 }) ip6_geneve_header_t;
48
49typedef CLIB_PACKED (struct
50 {
51 /*
52 * Key fields: ip source and geneve vni on incoming GENEVE packet
53 * all fields in NET byte order
54 */
55 union
56 {
57 struct
58 {
59 u32 remote;
60 u32 vni; /* shifted left 8 bits */
61 };
62 u64 as_u64;
63 };
64 }) geneve4_tunnel_key_t;
65
66typedef CLIB_PACKED (struct
67 {
68 /*
69 * Key fields: ip source and geneve vni on incoming GENEVE packet
70 * all fields in NET byte order
71 */
72 ip6_address_t remote;
73 u32 vni; /* shifted left 8 bits */
74 }) geneve6_tunnel_key_t;
75
76typedef struct
77{
Dave Baracheb987d32018-05-03 08:26:39 -040078 /* Required for pool_get_aligned */
79 CLIB_CACHE_LINE_ALIGN_MARK (cacheline0);
80
Marco Varleseb598f1d2017-09-19 14:25:28 +020081 /* Rewrite string. $$$$ embed vnet_rewrite header */
82 u8 *rewrite;
83
84 /* FIB DPO for IP forwarding of GENEVE encap packet */
85 dpo_id_t next_dpo;
86
87 /* geneve VNI in HOST byte order */
88 u32 vni;
89
90 /* geneve OPTIONS LEN in HOST byte order */
91#if SUPPORT_OPTIONS_HEADER==1
92 u8 options_len;
93#endif
94
95 /* tunnel local and remote addresses */
96 ip46_address_t local;
97 ip46_address_t remote;
98
99 /* mcast packet output intfc index (used only if remote is mcast) */
100 u32 mcast_sw_if_index;
101
102 /* decap next index */
103 u32 decap_next_index;
104
105 /* The FIB index for local/remote addresses */
106 u32 encap_fib_index;
107
108 /* vnet intfc index */
109 u32 sw_if_index;
110 u32 hw_if_index;
111
112 /**
113 * Linkage into the FIB object graph
114 */
115 fib_node_t node;
116
117 /*
118 * The FIB entry for (depending on GENEVE tunnel is unicast or mcast)
119 * sending unicast GENEVE encap packets or receiving mcast GENEVE packets
120 */
121 fib_node_index_t fib_entry_index;
122 adj_index_t mcast_adj_index;
123
124 /**
125 * The tunnel is a child of the FIB entry for its desintion. This is
126 * so it receives updates when the forwarding information for that entry
127 * changes.
128 * The tunnels sibling index on the FIB entry's dependency list.
129 */
130 u32 sibling_index;
131} geneve_tunnel_t;
132
133#define foreach_geneve_input_next \
134_(DROP, "error-drop") \
135_(L2_INPUT, "l2-input")
136
137typedef enum
138{
139#define _(s,n) GENEVE_INPUT_NEXT_##s,
140 foreach_geneve_input_next
141#undef _
142 GENEVE_INPUT_N_NEXT,
143} geneve_input_next_t;
144
145typedef enum
146{
147#define geneve_error(n,s) GENEVE_ERROR_##n,
148#include <vnet/geneve/geneve_error.def>
149#undef geneve_error
150 GENEVE_N_ERROR,
151} geneve_input_error_t;
152
153typedef struct
154{
155 /* vector of encap tunnel instances */
156 geneve_tunnel_t *tunnels;
157
158 /* lookup tunnel by key */
159 uword *geneve4_tunnel_by_key; /* keyed on ipv4.remote + vni */
160 uword *geneve6_tunnel_by_key; /* keyed on ipv6.remote + vni */
161
162 /* local VTEP IPs ref count used by geneve-bypass node to check if
163 received GENEVE packet DIP matches any local VTEP address */
164 uword *vtep4; /* local ip4 VTEPs keyed on their ip4 addr */
165 uword *vtep6; /* local ip6 VTEPs keyed on their ip6 addr */
166
167 /* mcast shared info */
168 uword *mcast_shared; /* keyed on mcast ip46 addr */
169
170 /* Free vlib hw_if_indices */
171 u32 *free_geneve_tunnel_hw_if_indices;
172
173 /* Mapping from sw_if_index to tunnel index */
174 u32 *tunnel_index_by_sw_if_index;
175
176 /* convenience */
177 vlib_main_t *vlib_main;
178 vnet_main_t *vnet_main;
179} geneve_main_t;
180
Dave Wallace71612d62017-10-24 01:32:41 -0400181extern geneve_main_t geneve_main;
Marco Varleseb598f1d2017-09-19 14:25:28 +0200182
183extern vlib_node_registration_t geneve4_input_node;
184extern vlib_node_registration_t geneve6_input_node;
185extern vlib_node_registration_t geneve4_encap_node;
186extern vlib_node_registration_t geneve6_encap_node;
187
188u8 *format_geneve_encap_trace (u8 * s, va_list * args);
189
190typedef struct
191{
192 u8 is_add;
193
194 /* we normally use is_ip4, but since this adds to the
195 * structure, this seems less of abreaking change */
196 u8 is_ip6;
197 ip46_address_t local, remote;
198 u32 mcast_sw_if_index;
199 u32 encap_fib_index;
200 u32 decap_next_index;
201 u32 vni;
202} vnet_geneve_add_del_tunnel_args_t;
203
204int vnet_geneve_add_del_tunnel
205 (vnet_geneve_add_del_tunnel_args_t * a, u32 * sw_if_indexp);
206
207void vnet_int_geneve_bypass_mode (u32 sw_if_index, u8 is_ip6, u8 is_enable);
208#endif /* included_vnet_geneve_h */
209
210/*
211 * fd.io coding-style-patch-verification: ON
212 *
213 * Local Variables:
214 * eval: (c-set-style "gnu")
215 * End:
216 */