blob: 8c0d37eb07a74c68187a97af2740818ab4775f21 [file] [log] [blame]
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -07001/*
2 * Copyright (c) 2015 Cisco and/or its affiliates.
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 */
Keith Burns (alagalah)d46cca12016-08-25 11:21:39 -070015/**
16 * @file
17 * @brief VXLAN GPE definitions
18 *
19*/
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -070020#ifndef included_vnet_vxlan_gpe_h
21#define included_vnet_vxlan_gpe_h
22
23#include <vppinfra/error.h>
24#include <vppinfra/hash.h>
25#include <vnet/vnet.h>
26#include <vnet/ip/ip.h>
27#include <vnet/l2/l2_input.h>
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +080028#include <vnet/l2/l2_output.h>
29#include <vnet/l2/l2_bd.h>
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -070030#include <vnet/ethernet/ethernet.h>
31#include <vnet/vxlan-gpe/vxlan_gpe_packet.h>
32#include <vnet/ip/ip4_packet.h>
Hongjun Nidf921cc2016-05-25 01:16:19 +080033#include <vnet/ip/ip6_packet.h>
Dave Barach68b0fb02017-02-28 15:15:56 -050034#include <vnet/udp/udp.h>
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +080035#include <vnet/dpo/dpo.h>
36#include <vnet/adj/adj_types.h>
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -070037
Keith Burns (alagalah)d46cca12016-08-25 11:21:39 -070038/**
39 * @brief VXLAN GPE header struct
40 *
41 */
sharath reddy6f8273a2017-12-11 11:31:31 +053042/* *INDENT-OFF* */
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -070043typedef CLIB_PACKED (struct {
Keith Burns (alagalah)d46cca12016-08-25 11:21:39 -070044 /** 20 bytes */
45 ip4_header_t ip4;
46 /** 8 bytes */
47 udp_header_t udp;
48 /** 8 bytes */
49 vxlan_gpe_header_t vxlan;
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -070050}) ip4_vxlan_gpe_header_t;
sharath reddy6f8273a2017-12-11 11:31:31 +053051/* *INDENT-ON* */
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -070052
sharath reddy6f8273a2017-12-11 11:31:31 +053053/* *INDENT-OFF* */
Hongjun Nidf921cc2016-05-25 01:16:19 +080054typedef CLIB_PACKED (struct {
Keith Burns (alagalah)d46cca12016-08-25 11:21:39 -070055 /** 40 bytes */
56 ip6_header_t ip6;
57 /** 8 bytes */
58 udp_header_t udp;
59 /** 8 bytes */
60 vxlan_gpe_header_t vxlan;
Hongjun Nidf921cc2016-05-25 01:16:19 +080061}) ip6_vxlan_gpe_header_t;
sharath reddy6f8273a2017-12-11 11:31:31 +053062/* *INDENT-ON* */
Hongjun Nidf921cc2016-05-25 01:16:19 +080063
Keith Burns (alagalah)d46cca12016-08-25 11:21:39 -070064/**
65 * @brief Key struct for IPv4 VXLAN GPE tunnel.
66 * Key fields: local remote, vni
67 * all fields in NET byte order
68 * VNI shifted 8 bits
69 */
sharath reddy6f8273a2017-12-11 11:31:31 +053070/* *INDENT-OFF* */
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -070071typedef CLIB_PACKED(struct {
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -070072 union {
73 struct {
74 u32 local;
75 u32 remote;
Keith Burns (alagalah)d46cca12016-08-25 11:21:39 -070076
77 u32 vni;
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -070078 u32 pad;
79 };
80 u64 as_u64[2];
81 };
Hongjun Nidf921cc2016-05-25 01:16:19 +080082}) vxlan4_gpe_tunnel_key_t;
sharath reddy6f8273a2017-12-11 11:31:31 +053083/* *INDENT-ON* */
Hongjun Nidf921cc2016-05-25 01:16:19 +080084
Keith Burns (alagalah)d46cca12016-08-25 11:21:39 -070085/**
86 * @brief Key struct for IPv6 VXLAN GPE tunnel.
87 * Key fields: local remote, vni
88 * all fields in NET byte order
89 * VNI shifted 8 bits
90 */
sharath reddy6f8273a2017-12-11 11:31:31 +053091/* *INDENT-OFF* */
Hongjun Nidf921cc2016-05-25 01:16:19 +080092typedef CLIB_PACKED(struct {
Hongjun Nidf921cc2016-05-25 01:16:19 +080093 ip6_address_t local;
94 ip6_address_t remote;
Keith Burns (alagalah)d46cca12016-08-25 11:21:39 -070095 u32 vni;
Hongjun Nidf921cc2016-05-25 01:16:19 +080096}) vxlan6_gpe_tunnel_key_t;
sharath reddy6f8273a2017-12-11 11:31:31 +053097/* *INDENT-ON* */
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -070098
Keith Burns (alagalah)d46cca12016-08-25 11:21:39 -070099/**
100 * @brief Struct for VXLAN GPE tunnel
101 */
sharath reddy6f8273a2017-12-11 11:31:31 +0530102typedef struct
103{
Keith Burns (alagalah)d46cca12016-08-25 11:21:39 -0700104 /** Rewrite string. $$$$ embed vnet_rewrite header */
sharath reddy6f8273a2017-12-11 11:31:31 +0530105 u8 *rewrite;
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700106
Keith Burns (alagalah)d46cca12016-08-25 11:21:39 -0700107 /** encapsulated protocol */
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700108 u8 protocol;
109
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800110 /* FIB DPO for IP forwarding of VXLAN-GPE encap packet */
sharath reddy6f8273a2017-12-11 11:31:31 +0530111 dpo_id_t next_dpo;
Keith Burns (alagalah)d46cca12016-08-25 11:21:39 -0700112 /** tunnel local address */
Hongjun Nidf921cc2016-05-25 01:16:19 +0800113 ip46_address_t local;
Keith Burns (alagalah)d46cca12016-08-25 11:21:39 -0700114 /** tunnel remote address */
Hongjun Nidf921cc2016-05-25 01:16:19 +0800115 ip46_address_t remote;
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700116
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800117 /* mcast packet output intfc index (used only if dst is mcast) */
118 u32 mcast_sw_if_index;
sharath reddy6f8273a2017-12-11 11:31:31 +0530119
Keith Burns (alagalah)d46cca12016-08-25 11:21:39 -0700120 /** FIB indices - tunnel partner lookup here */
121 u32 encap_fib_index;
122 /** FIB indices - inner IP packet lookup here */
123 u32 decap_fib_index;
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700124
Keith Burns (alagalah)d46cca12016-08-25 11:21:39 -0700125 /** VXLAN GPE VNI in HOST byte order, shifted left 8 bits */
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700126 u32 vni;
127
Keith Burns (alagalah)d46cca12016-08-25 11:21:39 -0700128 /** vnet intfc hw_if_index */
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700129 u32 hw_if_index;
Keith Burns (alagalah)d46cca12016-08-25 11:21:39 -0700130 /** vnet intfc sw_if_index */
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700131 u32 sw_if_index;
132
Keith Burns (alagalah)d46cca12016-08-25 11:21:39 -0700133 /** flags */
Hongjun Nidf921cc2016-05-25 01:16:19 +0800134 u32 flags;
Vengada Govindan6d403a02016-10-12 05:54:09 -0700135
136 /** rewrite size for dynamic plugins like iOAM */
sharath reddy6f8273a2017-12-11 11:31:31 +0530137 u8 rewrite_size;
Vengada Govindan6d403a02016-10-12 05:54:09 -0700138
139 /** Next node after VxLAN-GPE encap */
140 uword encap_next_node;
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800141
142 /**
143 * Linkage into the FIB object graph
144 */
145 fib_node_t node;
146
147 /*
148 * The FIB entry for (depending on VXLAN-GPE tunnel is unicast or mcast)
149 * sending unicast VXLAN-GPE encap packets or receiving mcast VXLAN-GPE packets
150 */
151 fib_node_index_t fib_entry_index;
152 adj_index_t mcast_adj_index;
153
154 /**
155 * The tunnel is a child of the FIB entry for its desintion. This is
156 * so it receives updates when the forwarding information for that entry
157 * changes.
158 * The tunnels sibling index on the FIB entry's dependency list.
159 */
160 u32 sibling_index;
161
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700162} vxlan_gpe_tunnel_t;
163
Keith Burns (alagalah)d46cca12016-08-25 11:21:39 -0700164/** Flags for vxlan_gpe_tunnel_t */
Hongjun Nidf921cc2016-05-25 01:16:19 +0800165#define VXLAN_GPE_TUNNEL_IS_IPV4 1
166
Keith Burns (alagalah)d46cca12016-08-25 11:21:39 -0700167/** next nodes for VXLAN GPE input */
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700168#define foreach_vxlan_gpe_input_next \
169_(DROP, "error-drop") \
170_(IP4_INPUT, "ip4-input") \
171_(IP6_INPUT, "ip6-input") \
Gabriel Ganne7e665d62017-11-17 09:18:53 +0100172_(L2_INPUT, "l2-input")
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700173
Keith Burns (alagalah)d46cca12016-08-25 11:21:39 -0700174/** struct for next nodes for VXLAN GPE input */
sharath reddy6f8273a2017-12-11 11:31:31 +0530175typedef enum
176{
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700177#define _(s,n) VXLAN_GPE_INPUT_NEXT_##s,
178 foreach_vxlan_gpe_input_next
179#undef _
sharath reddy6f8273a2017-12-11 11:31:31 +0530180 VXLAN_GPE_INPUT_N_NEXT,
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700181} vxlan_gpe_input_next_t;
182
Keith Burns (alagalah)d46cca12016-08-25 11:21:39 -0700183/** struct for VXLAN GPE errors */
sharath reddy6f8273a2017-12-11 11:31:31 +0530184typedef enum
185{
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700186#define vxlan_gpe_error(n,s) VXLAN_GPE_ERROR_##n,
187#include <vnet/vxlan-gpe/vxlan_gpe_error.def>
188#undef vxlan_gpe_error
189 VXLAN_GPE_N_ERROR,
190} vxlan_gpe_input_error_t;
191
Keith Burns (alagalah)d46cca12016-08-25 11:21:39 -0700192/** Struct for VXLAN GPE node state */
sharath reddy6f8273a2017-12-11 11:31:31 +0530193typedef struct
194{
Keith Burns (alagalah)d46cca12016-08-25 11:21:39 -0700195 /** vector of encap tunnel instances */
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700196 vxlan_gpe_tunnel_t *tunnels;
197
Keith Burns (alagalah)d46cca12016-08-25 11:21:39 -0700198 /** lookup IPv4 VXLAN GPE tunnel by key */
sharath reddy6f8273a2017-12-11 11:31:31 +0530199 uword *vxlan4_gpe_tunnel_by_key;
Keith Burns (alagalah)d46cca12016-08-25 11:21:39 -0700200 /** lookup IPv6 VXLAN GPE tunnel by key */
sharath reddy6f8273a2017-12-11 11:31:31 +0530201 uword *vxlan6_gpe_tunnel_by_key;
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700202
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800203 /* local VTEP IPs ref count used by vxlan-bypass node to check if
204 received VXLAN packet DIP matches any local VTEP address */
sharath reddy6f8273a2017-12-11 11:31:31 +0530205 uword *vtep4; /* local ip4 VTEPs keyed on their ip4 addr */
206 uword *vtep6; /* local ip6 VTEPs keyed on their ip6 addr */
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800207 /* mcast shared info */
sharath reddy6f8273a2017-12-11 11:31:31 +0530208 uword *mcast_shared; /* keyed on mcast ip46 addr */
Keith Burns (alagalah)d46cca12016-08-25 11:21:39 -0700209 /** Free vlib hw_if_indices */
sharath reddy6f8273a2017-12-11 11:31:31 +0530210 u32 *free_vxlan_gpe_tunnel_hw_if_indices;
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700211
Keith Burns (alagalah)d46cca12016-08-25 11:21:39 -0700212 /** Mapping from sw_if_index to tunnel index */
sharath reddy6f8273a2017-12-11 11:31:31 +0530213 u32 *tunnel_index_by_sw_if_index;
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700214
Keith Burns (alagalah)d46cca12016-08-25 11:21:39 -0700215 /** State convenience vlib_main_t */
sharath reddy6f8273a2017-12-11 11:31:31 +0530216 vlib_main_t *vlib_main;
Keith Burns (alagalah)d46cca12016-08-25 11:21:39 -0700217 /** State convenience vnet_main_t */
sharath reddy6f8273a2017-12-11 11:31:31 +0530218 vnet_main_t *vnet_main;
Vengada Govindan6d403a02016-10-12 05:54:09 -0700219
220 /** List of next nodes for the decap indexed on protocol */
221 uword decap_next_node_list[VXLAN_GPE_PROTOCOL_MAX];
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700222} vxlan_gpe_main_t;
223
Dave Wallace71612d62017-10-24 01:32:41 -0400224extern vxlan_gpe_main_t vxlan_gpe_main;
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700225
226extern vlib_node_registration_t vxlan_gpe_encap_node;
Hongjun Nidf921cc2016-05-25 01:16:19 +0800227extern vlib_node_registration_t vxlan4_gpe_input_node;
228extern vlib_node_registration_t vxlan6_gpe_input_node;
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700229
sharath reddy6f8273a2017-12-11 11:31:31 +0530230u8 *format_vxlan_gpe_encap_trace (u8 * s, va_list * args);
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700231
Keith Burns (alagalah)d46cca12016-08-25 11:21:39 -0700232/** Struct for VXLAN GPE add/del args */
sharath reddy6f8273a2017-12-11 11:31:31 +0530233typedef struct
234{
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700235 u8 is_add;
Hongjun Nidf921cc2016-05-25 01:16:19 +0800236 u8 is_ip6;
237 ip46_address_t local, remote;
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700238 u8 protocol;
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800239 u32 mcast_sw_if_index;
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700240 u32 encap_fib_index;
241 u32 decap_fib_index;
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700242 u32 vni;
243} vnet_vxlan_gpe_add_del_tunnel_args_t;
244
245
Hongjun Ni7deb1392016-06-15 22:49:23 +0800246int vnet_vxlan_gpe_add_del_tunnel
sharath reddy6f8273a2017-12-11 11:31:31 +0530247 (vnet_vxlan_gpe_add_del_tunnel_args_t * a, u32 * sw_if_indexp);
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700248
249
Vengada Govindan6d403a02016-10-12 05:54:09 -0700250int vxlan4_gpe_rewrite (vxlan_gpe_tunnel_t * t, u32 extension_size,
sharath reddy6f8273a2017-12-11 11:31:31 +0530251 u8 protocol_override, uword encap_next_node);
Vengada Govindan6d403a02016-10-12 05:54:09 -0700252int vxlan6_gpe_rewrite (vxlan_gpe_tunnel_t * t, u32 extension_size,
sharath reddy6f8273a2017-12-11 11:31:31 +0530253 u8 protocol_override, uword encap_next_node);
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700254
Vengada Govindan6d403a02016-10-12 05:54:09 -0700255/**
256 * @brief Struct for defining VXLAN GPE next nodes
257 */
sharath reddy6f8273a2017-12-11 11:31:31 +0530258typedef enum
259{
Vengada Govindan6d403a02016-10-12 05:54:09 -0700260 VXLAN_GPE_ENCAP_NEXT_IP4_LOOKUP,
261 VXLAN_GPE_ENCAP_NEXT_IP6_LOOKUP,
262 VXLAN_GPE_ENCAP_NEXT_DROP,
263 VXLAN_GPE_ENCAP_N_NEXT
264} vxlan_gpe_encap_next_t;
265
266
sharath reddy6f8273a2017-12-11 11:31:31 +0530267void vxlan_gpe_unregister_decap_protocol (u8 protocol_id,
268 uword next_node_index);
Vengada Govindan6d403a02016-10-12 05:54:09 -0700269
sharath reddy6f8273a2017-12-11 11:31:31 +0530270void vxlan_gpe_register_decap_protocol (u8 protocol_id,
271 uword next_node_index);
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700272
sharath reddy6f8273a2017-12-11 11:31:31 +0530273void vnet_int_vxlan_gpe_bypass_mode (u32 sw_if_index, u8 is_ip6,
274 u8 is_enable);
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700275
276#endif /* included_vnet_vxlan_gpe_h */
sharath reddy6f8273a2017-12-11 11:31:31 +0530277
278/*
279 * fd.io coding-style-patch-verification: ON
280 *
281 * Local Variables:
282 * eval: (c-set-style "gnu")
283 * End:
284 */