blob: 2cbbb6c5f365ee91b3b2f5ffba5b85dfd4d0b15a [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>
Nick Zavaritsky27518c22020-02-27 15:54:58 +000027#include <vnet/ip/vtep.h>
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -070028#include <vnet/l2/l2_input.h>
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +080029#include <vnet/l2/l2_output.h>
30#include <vnet/l2/l2_bd.h>
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -070031#include <vnet/ethernet/ethernet.h>
32#include <vnet/vxlan-gpe/vxlan_gpe_packet.h>
33#include <vnet/ip/ip4_packet.h>
Hongjun Nidf921cc2016-05-25 01:16:19 +080034#include <vnet/ip/ip6_packet.h>
Florin Corasb040f982020-10-20 14:59:43 -070035#include <vnet/udp/udp_packet.h>
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +080036#include <vnet/dpo/dpo.h>
37#include <vnet/adj/adj_types.h>
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -070038
Keith Burns (alagalah)d46cca12016-08-25 11:21:39 -070039/**
40 * @brief VXLAN GPE header struct
41 *
42 */
sharath reddy6f8273a2017-12-11 11:31:31 +053043/* *INDENT-OFF* */
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -070044typedef CLIB_PACKED (struct {
Keith Burns (alagalah)d46cca12016-08-25 11:21:39 -070045 /** 20 bytes */
46 ip4_header_t ip4;
47 /** 8 bytes */
48 udp_header_t udp;
49 /** 8 bytes */
50 vxlan_gpe_header_t vxlan;
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -070051}) ip4_vxlan_gpe_header_t;
sharath reddy6f8273a2017-12-11 11:31:31 +053052/* *INDENT-ON* */
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -070053
sharath reddy6f8273a2017-12-11 11:31:31 +053054/* *INDENT-OFF* */
Hongjun Nidf921cc2016-05-25 01:16:19 +080055typedef CLIB_PACKED (struct {
Keith Burns (alagalah)d46cca12016-08-25 11:21:39 -070056 /** 40 bytes */
57 ip6_header_t ip6;
58 /** 8 bytes */
59 udp_header_t udp;
60 /** 8 bytes */
61 vxlan_gpe_header_t vxlan;
Hongjun Nidf921cc2016-05-25 01:16:19 +080062}) ip6_vxlan_gpe_header_t;
sharath reddy6f8273a2017-12-11 11:31:31 +053063/* *INDENT-ON* */
Hongjun Nidf921cc2016-05-25 01:16:19 +080064
Keith Burns (alagalah)d46cca12016-08-25 11:21:39 -070065/**
66 * @brief Key struct for IPv4 VXLAN GPE tunnel.
Artem Glazychevea962922021-05-28 19:09:14 +070067 * Key fields: local remote, vni, udp-port
Keith Burns (alagalah)d46cca12016-08-25 11:21:39 -070068 * all fields in NET byte order
69 * VNI shifted 8 bits
70 */
sharath reddy6f8273a2017-12-11 11:31:31 +053071/* *INDENT-OFF* */
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -070072typedef CLIB_PACKED(struct {
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -070073 union {
74 struct {
75 u32 local;
76 u32 remote;
Keith Burns (alagalah)d46cca12016-08-25 11:21:39 -070077
78 u32 vni;
Artem Glazychevea962922021-05-28 19:09:14 +070079 u32 port;
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -070080 };
81 u64 as_u64[2];
82 };
Hongjun Nidf921cc2016-05-25 01:16:19 +080083}) vxlan4_gpe_tunnel_key_t;
sharath reddy6f8273a2017-12-11 11:31:31 +053084/* *INDENT-ON* */
Hongjun Nidf921cc2016-05-25 01:16:19 +080085
Keith Burns (alagalah)d46cca12016-08-25 11:21:39 -070086/**
87 * @brief Key struct for IPv6 VXLAN GPE tunnel.
Artem Glazychevea962922021-05-28 19:09:14 +070088 * Key fields: local remote, vni, udp-port
Keith Burns (alagalah)d46cca12016-08-25 11:21:39 -070089 * all fields in NET byte order
90 * VNI shifted 8 bits
91 */
sharath reddy6f8273a2017-12-11 11:31:31 +053092/* *INDENT-OFF* */
Hongjun Nidf921cc2016-05-25 01:16:19 +080093typedef CLIB_PACKED(struct {
Hongjun Nidf921cc2016-05-25 01:16:19 +080094 ip6_address_t local;
95 ip6_address_t remote;
Keith Burns (alagalah)d46cca12016-08-25 11:21:39 -070096 u32 vni;
Artem Glazychevea962922021-05-28 19:09:14 +070097 u32 port;
Hongjun Nidf921cc2016-05-25 01:16:19 +080098}) vxlan6_gpe_tunnel_key_t;
sharath reddy6f8273a2017-12-11 11:31:31 +053099/* *INDENT-ON* */
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700100
Artem Glazychevea962922021-05-28 19:09:14 +0700101typedef union
102{
103 struct
104 {
105 u32 tunnel_index;
106 u16 next_index;
107 u8 error;
108 };
109 u64 as_u64;
110} vxlan_gpe_decap_info_t;
111
Keith Burns (alagalah)d46cca12016-08-25 11:21:39 -0700112/**
113 * @brief Struct for VXLAN GPE tunnel
114 */
sharath reddy6f8273a2017-12-11 11:31:31 +0530115typedef struct
116{
Dave Baracheb987d32018-05-03 08:26:39 -0400117 /* Required for pool_get_aligned */
118 CLIB_CACHE_LINE_ALIGN_MARK (cacheline0);
119
Keith Burns (alagalah)d46cca12016-08-25 11:21:39 -0700120 /** Rewrite string. $$$$ embed vnet_rewrite header */
sharath reddy6f8273a2017-12-11 11:31:31 +0530121 u8 *rewrite;
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700122
Keith Burns (alagalah)d46cca12016-08-25 11:21:39 -0700123 /** encapsulated protocol */
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700124 u8 protocol;
125
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800126 /* FIB DPO for IP forwarding of VXLAN-GPE encap packet */
sharath reddy6f8273a2017-12-11 11:31:31 +0530127 dpo_id_t next_dpo;
Keith Burns (alagalah)d46cca12016-08-25 11:21:39 -0700128 /** tunnel local address */
Hongjun Nidf921cc2016-05-25 01:16:19 +0800129 ip46_address_t local;
Keith Burns (alagalah)d46cca12016-08-25 11:21:39 -0700130 /** tunnel remote address */
Hongjun Nidf921cc2016-05-25 01:16:19 +0800131 ip46_address_t remote;
Artem Glazychevea962922021-05-28 19:09:14 +0700132 /** local udp-port **/
133 u16 local_port;
134 /** remote udp-port **/
135 u16 remote_port;
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700136
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800137 /* mcast packet output intfc index (used only if dst is mcast) */
138 u32 mcast_sw_if_index;
sharath reddy6f8273a2017-12-11 11:31:31 +0530139
Keith Burns (alagalah)d46cca12016-08-25 11:21:39 -0700140 /** FIB indices - tunnel partner lookup here */
141 u32 encap_fib_index;
142 /** FIB indices - inner IP packet lookup here */
143 u32 decap_fib_index;
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700144
Keith Burns (alagalah)d46cca12016-08-25 11:21:39 -0700145 /** VXLAN GPE VNI in HOST byte order, shifted left 8 bits */
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700146 u32 vni;
147
Keith Burns (alagalah)d46cca12016-08-25 11:21:39 -0700148 /** vnet intfc hw_if_index */
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700149 u32 hw_if_index;
Keith Burns (alagalah)d46cca12016-08-25 11:21:39 -0700150 /** vnet intfc sw_if_index */
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700151 u32 sw_if_index;
152
Keith Burns (alagalah)d46cca12016-08-25 11:21:39 -0700153 /** flags */
Hongjun Nidf921cc2016-05-25 01:16:19 +0800154 u32 flags;
Vengada Govindan6d403a02016-10-12 05:54:09 -0700155
156 /** rewrite size for dynamic plugins like iOAM */
sharath reddy6f8273a2017-12-11 11:31:31 +0530157 u8 rewrite_size;
Vengada Govindan6d403a02016-10-12 05:54:09 -0700158
159 /** Next node after VxLAN-GPE encap */
160 uword encap_next_node;
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800161
162 /**
163 * Linkage into the FIB object graph
164 */
165 fib_node_t node;
166
167 /*
168 * The FIB entry for (depending on VXLAN-GPE tunnel is unicast or mcast)
169 * sending unicast VXLAN-GPE encap packets or receiving mcast VXLAN-GPE packets
170 */
171 fib_node_index_t fib_entry_index;
172 adj_index_t mcast_adj_index;
173
174 /**
Paul Vinciguerrabdc0e6b2018-09-22 05:32:50 -0700175 * The tunnel is a child of the FIB entry for its destination. This is
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800176 * so it receives updates when the forwarding information for that entry
177 * changes.
178 * The tunnels sibling index on the FIB entry's dependency list.
179 */
180 u32 sibling_index;
181
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700182} vxlan_gpe_tunnel_t;
183
Keith Burns (alagalah)d46cca12016-08-25 11:21:39 -0700184/** Flags for vxlan_gpe_tunnel_t */
Hongjun Nidf921cc2016-05-25 01:16:19 +0800185#define VXLAN_GPE_TUNNEL_IS_IPV4 1
186
Keith Burns (alagalah)d46cca12016-08-25 11:21:39 -0700187/** next nodes for VXLAN GPE input */
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700188#define foreach_vxlan_gpe_input_next \
189_(DROP, "error-drop") \
190_(IP4_INPUT, "ip4-input") \
191_(IP6_INPUT, "ip6-input") \
Gabriel Ganne7e665d62017-11-17 09:18:53 +0100192_(L2_INPUT, "l2-input")
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700193
Keith Burns (alagalah)d46cca12016-08-25 11:21:39 -0700194/** struct for next nodes for VXLAN GPE input */
sharath reddy6f8273a2017-12-11 11:31:31 +0530195typedef enum
196{
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700197#define _(s,n) VXLAN_GPE_INPUT_NEXT_##s,
198 foreach_vxlan_gpe_input_next
199#undef _
sharath reddy6f8273a2017-12-11 11:31:31 +0530200 VXLAN_GPE_INPUT_N_NEXT,
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700201} vxlan_gpe_input_next_t;
202
Keith Burns (alagalah)d46cca12016-08-25 11:21:39 -0700203/** struct for VXLAN GPE errors */
sharath reddy6f8273a2017-12-11 11:31:31 +0530204typedef enum
205{
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700206#define vxlan_gpe_error(n,s) VXLAN_GPE_ERROR_##n,
207#include <vnet/vxlan-gpe/vxlan_gpe_error.def>
208#undef vxlan_gpe_error
209 VXLAN_GPE_N_ERROR,
210} vxlan_gpe_input_error_t;
211
Keith Burns (alagalah)d46cca12016-08-25 11:21:39 -0700212/** Struct for VXLAN GPE node state */
sharath reddy6f8273a2017-12-11 11:31:31 +0530213typedef struct
214{
Keith Burns (alagalah)d46cca12016-08-25 11:21:39 -0700215 /** vector of encap tunnel instances */
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700216 vxlan_gpe_tunnel_t *tunnels;
217
Keith Burns (alagalah)d46cca12016-08-25 11:21:39 -0700218 /** lookup IPv4 VXLAN GPE tunnel by key */
sharath reddy6f8273a2017-12-11 11:31:31 +0530219 uword *vxlan4_gpe_tunnel_by_key;
Keith Burns (alagalah)d46cca12016-08-25 11:21:39 -0700220 /** lookup IPv6 VXLAN GPE tunnel by key */
sharath reddy6f8273a2017-12-11 11:31:31 +0530221 uword *vxlan6_gpe_tunnel_by_key;
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700222
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800223 /* local VTEP IPs ref count used by vxlan-bypass node to check if
224 received VXLAN packet DIP matches any local VTEP address */
Nick Zavaritsky27518c22020-02-27 15:54:58 +0000225 vtep_table_t vtep_table;
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800226 /* mcast shared info */
sharath reddy6f8273a2017-12-11 11:31:31 +0530227 uword *mcast_shared; /* keyed on mcast ip46 addr */
Keith Burns (alagalah)d46cca12016-08-25 11:21:39 -0700228 /** Free vlib hw_if_indices */
sharath reddy6f8273a2017-12-11 11:31:31 +0530229 u32 *free_vxlan_gpe_tunnel_hw_if_indices;
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700230
Keith Burns (alagalah)d46cca12016-08-25 11:21:39 -0700231 /** Mapping from sw_if_index to tunnel index */
sharath reddy6f8273a2017-12-11 11:31:31 +0530232 u32 *tunnel_index_by_sw_if_index;
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700233
Keith Burns (alagalah)d46cca12016-08-25 11:21:39 -0700234 /** State convenience vlib_main_t */
sharath reddy6f8273a2017-12-11 11:31:31 +0530235 vlib_main_t *vlib_main;
Keith Burns (alagalah)d46cca12016-08-25 11:21:39 -0700236 /** State convenience vnet_main_t */
sharath reddy6f8273a2017-12-11 11:31:31 +0530237 vnet_main_t *vnet_main;
Vengada Govindan6d403a02016-10-12 05:54:09 -0700238
Junfeng Wang290526e2021-03-09 16:44:57 +0800239 /* cache for last 8 vxlan_gpe tunnel */
Junfeng Wang290526e2021-03-09 16:44:57 +0800240 vtep4_cache_t vtep4_u512;
Junfeng Wang290526e2021-03-09 16:44:57 +0800241
Vengada Govindan6d403a02016-10-12 05:54:09 -0700242 /** List of next nodes for the decap indexed on protocol */
243 uword decap_next_node_list[VXLAN_GPE_PROTOCOL_MAX];
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700244} vxlan_gpe_main_t;
245
Dave Wallace71612d62017-10-24 01:32:41 -0400246extern vxlan_gpe_main_t vxlan_gpe_main;
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700247
248extern vlib_node_registration_t vxlan_gpe_encap_node;
Hongjun Nidf921cc2016-05-25 01:16:19 +0800249extern vlib_node_registration_t vxlan4_gpe_input_node;
250extern vlib_node_registration_t vxlan6_gpe_input_node;
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700251
sharath reddy6f8273a2017-12-11 11:31:31 +0530252u8 *format_vxlan_gpe_encap_trace (u8 * s, va_list * args);
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700253
Keith Burns (alagalah)d46cca12016-08-25 11:21:39 -0700254/** Struct for VXLAN GPE add/del args */
sharath reddy6f8273a2017-12-11 11:31:31 +0530255typedef struct
256{
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700257 u8 is_add;
Hongjun Nidf921cc2016-05-25 01:16:19 +0800258 u8 is_ip6;
259 ip46_address_t local, remote;
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700260 u8 protocol;
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800261 u32 mcast_sw_if_index;
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700262 u32 encap_fib_index;
263 u32 decap_fib_index;
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700264 u32 vni;
Artem Glazychevea962922021-05-28 19:09:14 +0700265 u16 local_port;
266 u16 remote_port;
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700267} vnet_vxlan_gpe_add_del_tunnel_args_t;
268
269
Hongjun Ni7deb1392016-06-15 22:49:23 +0800270int vnet_vxlan_gpe_add_del_tunnel
sharath reddy6f8273a2017-12-11 11:31:31 +0530271 (vnet_vxlan_gpe_add_del_tunnel_args_t * a, u32 * sw_if_indexp);
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700272
273
Vengada Govindan6d403a02016-10-12 05:54:09 -0700274int vxlan4_gpe_rewrite (vxlan_gpe_tunnel_t * t, u32 extension_size,
sharath reddy6f8273a2017-12-11 11:31:31 +0530275 u8 protocol_override, uword encap_next_node);
Vengada Govindan6d403a02016-10-12 05:54:09 -0700276int vxlan6_gpe_rewrite (vxlan_gpe_tunnel_t * t, u32 extension_size,
sharath reddy6f8273a2017-12-11 11:31:31 +0530277 u8 protocol_override, uword encap_next_node);
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700278
Vengada Govindan6d403a02016-10-12 05:54:09 -0700279/**
280 * @brief Struct for defining VXLAN GPE next nodes
281 */
sharath reddy6f8273a2017-12-11 11:31:31 +0530282typedef enum
283{
Vengada Govindan6d403a02016-10-12 05:54:09 -0700284 VXLAN_GPE_ENCAP_NEXT_IP4_LOOKUP,
285 VXLAN_GPE_ENCAP_NEXT_IP6_LOOKUP,
286 VXLAN_GPE_ENCAP_NEXT_DROP,
287 VXLAN_GPE_ENCAP_N_NEXT
288} vxlan_gpe_encap_next_t;
289
290
sharath reddy6f8273a2017-12-11 11:31:31 +0530291void vxlan_gpe_unregister_decap_protocol (u8 protocol_id,
292 uword next_node_index);
Vengada Govindan6d403a02016-10-12 05:54:09 -0700293
sharath reddy6f8273a2017-12-11 11:31:31 +0530294void vxlan_gpe_register_decap_protocol (u8 protocol_id,
295 uword next_node_index);
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700296
sharath reddy6f8273a2017-12-11 11:31:31 +0530297void vnet_int_vxlan_gpe_bypass_mode (u32 sw_if_index, u8 is_ip6,
298 u8 is_enable);
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700299
300#endif /* included_vnet_vxlan_gpe_h */
sharath reddy6f8273a2017-12-11 11:31:31 +0530301
302/*
303 * fd.io coding-style-patch-verification: ON
304 *
305 * Local Variables:
306 * eval: (c-set-style "gnu")
307 * End:
308 */