blob: aabaafeee6f99f5676628561e4e818423983a117 [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 */
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;
51
Hongjun Nidf921cc2016-05-25 01:16:19 +080052typedef CLIB_PACKED (struct {
Keith Burns (alagalah)d46cca12016-08-25 11:21:39 -070053 /** 40 bytes */
54 ip6_header_t ip6;
55 /** 8 bytes */
56 udp_header_t udp;
57 /** 8 bytes */
58 vxlan_gpe_header_t vxlan;
Hongjun Nidf921cc2016-05-25 01:16:19 +080059}) ip6_vxlan_gpe_header_t;
60
Keith Burns (alagalah)d46cca12016-08-25 11:21:39 -070061/**
62 * @brief Key struct for IPv4 VXLAN GPE tunnel.
Artem Glazychevea962922021-05-28 19:09:14 +070063 * Key fields: local remote, vni, udp-port
Keith Burns (alagalah)d46cca12016-08-25 11:21:39 -070064 * all fields in NET byte order
65 * VNI shifted 8 bits
66 */
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -070067typedef CLIB_PACKED(struct {
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -070068 union {
69 struct {
70 u32 local;
71 u32 remote;
Keith Burns (alagalah)d46cca12016-08-25 11:21:39 -070072
73 u32 vni;
Artem Glazychevea962922021-05-28 19:09:14 +070074 u32 port;
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -070075 };
76 u64 as_u64[2];
77 };
Hongjun Nidf921cc2016-05-25 01:16:19 +080078}) vxlan4_gpe_tunnel_key_t;
79
Keith Burns (alagalah)d46cca12016-08-25 11:21:39 -070080/**
81 * @brief Key struct for IPv6 VXLAN GPE tunnel.
Artem Glazychevea962922021-05-28 19:09:14 +070082 * Key fields: local remote, vni, udp-port
Keith Burns (alagalah)d46cca12016-08-25 11:21:39 -070083 * all fields in NET byte order
84 * VNI shifted 8 bits
85 */
Hongjun Nidf921cc2016-05-25 01:16:19 +080086typedef CLIB_PACKED(struct {
Hongjun Nidf921cc2016-05-25 01:16:19 +080087 ip6_address_t local;
88 ip6_address_t remote;
Keith Burns (alagalah)d46cca12016-08-25 11:21:39 -070089 u32 vni;
Artem Glazychevea962922021-05-28 19:09:14 +070090 u32 port;
Hongjun Nidf921cc2016-05-25 01:16:19 +080091}) vxlan6_gpe_tunnel_key_t;
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -070092
Artem Glazychevea962922021-05-28 19:09:14 +070093typedef union
94{
95 struct
96 {
97 u32 tunnel_index;
98 u16 next_index;
99 u8 error;
100 };
101 u64 as_u64;
102} vxlan_gpe_decap_info_t;
103
Keith Burns (alagalah)d46cca12016-08-25 11:21:39 -0700104/**
105 * @brief Struct for VXLAN GPE tunnel
106 */
sharath reddy6f8273a2017-12-11 11:31:31 +0530107typedef struct
108{
Dave Baracheb987d32018-05-03 08:26:39 -0400109 /* Required for pool_get_aligned */
110 CLIB_CACHE_LINE_ALIGN_MARK (cacheline0);
111
Keith Burns (alagalah)d46cca12016-08-25 11:21:39 -0700112 /** Rewrite string. $$$$ embed vnet_rewrite header */
sharath reddy6f8273a2017-12-11 11:31:31 +0530113 u8 *rewrite;
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700114
Keith Burns (alagalah)d46cca12016-08-25 11:21:39 -0700115 /** encapsulated protocol */
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700116 u8 protocol;
117
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800118 /* FIB DPO for IP forwarding of VXLAN-GPE encap packet */
sharath reddy6f8273a2017-12-11 11:31:31 +0530119 dpo_id_t next_dpo;
Keith Burns (alagalah)d46cca12016-08-25 11:21:39 -0700120 /** tunnel local address */
Hongjun Nidf921cc2016-05-25 01:16:19 +0800121 ip46_address_t local;
Keith Burns (alagalah)d46cca12016-08-25 11:21:39 -0700122 /** tunnel remote address */
Hongjun Nidf921cc2016-05-25 01:16:19 +0800123 ip46_address_t remote;
Artem Glazychevea962922021-05-28 19:09:14 +0700124 /** local udp-port **/
125 u16 local_port;
126 /** remote udp-port **/
127 u16 remote_port;
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700128
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800129 /* mcast packet output intfc index (used only if dst is mcast) */
130 u32 mcast_sw_if_index;
sharath reddy6f8273a2017-12-11 11:31:31 +0530131
Keith Burns (alagalah)d46cca12016-08-25 11:21:39 -0700132 /** FIB indices - tunnel partner lookup here */
133 u32 encap_fib_index;
134 /** FIB indices - inner IP packet lookup here */
135 u32 decap_fib_index;
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700136
Keith Burns (alagalah)d46cca12016-08-25 11:21:39 -0700137 /** VXLAN GPE VNI in HOST byte order, shifted left 8 bits */
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700138 u32 vni;
139
Keith Burns (alagalah)d46cca12016-08-25 11:21:39 -0700140 /** vnet intfc hw_if_index */
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700141 u32 hw_if_index;
Keith Burns (alagalah)d46cca12016-08-25 11:21:39 -0700142 /** vnet intfc sw_if_index */
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700143 u32 sw_if_index;
144
Keith Burns (alagalah)d46cca12016-08-25 11:21:39 -0700145 /** flags */
Hongjun Nidf921cc2016-05-25 01:16:19 +0800146 u32 flags;
Vengada Govindan6d403a02016-10-12 05:54:09 -0700147
148 /** rewrite size for dynamic plugins like iOAM */
sharath reddy6f8273a2017-12-11 11:31:31 +0530149 u8 rewrite_size;
Vengada Govindan6d403a02016-10-12 05:54:09 -0700150
151 /** Next node after VxLAN-GPE encap */
152 uword encap_next_node;
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800153
154 /**
155 * Linkage into the FIB object graph
156 */
157 fib_node_t node;
158
159 /*
160 * The FIB entry for (depending on VXLAN-GPE tunnel is unicast or mcast)
161 * sending unicast VXLAN-GPE encap packets or receiving mcast VXLAN-GPE packets
162 */
163 fib_node_index_t fib_entry_index;
164 adj_index_t mcast_adj_index;
165
166 /**
Paul Vinciguerrabdc0e6b2018-09-22 05:32:50 -0700167 * The tunnel is a child of the FIB entry for its destination. This is
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800168 * so it receives updates when the forwarding information for that entry
169 * changes.
170 * The tunnels sibling index on the FIB entry's dependency list.
171 */
172 u32 sibling_index;
173
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700174} vxlan_gpe_tunnel_t;
175
Keith Burns (alagalah)d46cca12016-08-25 11:21:39 -0700176/** Flags for vxlan_gpe_tunnel_t */
Hongjun Nidf921cc2016-05-25 01:16:19 +0800177#define VXLAN_GPE_TUNNEL_IS_IPV4 1
178
Keith Burns (alagalah)d46cca12016-08-25 11:21:39 -0700179/** next nodes for VXLAN GPE input */
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700180#define foreach_vxlan_gpe_input_next \
181_(DROP, "error-drop") \
182_(IP4_INPUT, "ip4-input") \
183_(IP6_INPUT, "ip6-input") \
Gabriel Ganne7e665d62017-11-17 09:18:53 +0100184_(L2_INPUT, "l2-input")
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700185
Keith Burns (alagalah)d46cca12016-08-25 11:21:39 -0700186/** struct for next nodes for VXLAN GPE input */
sharath reddy6f8273a2017-12-11 11:31:31 +0530187typedef enum
188{
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700189#define _(s,n) VXLAN_GPE_INPUT_NEXT_##s,
190 foreach_vxlan_gpe_input_next
191#undef _
sharath reddy6f8273a2017-12-11 11:31:31 +0530192 VXLAN_GPE_INPUT_N_NEXT,
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700193} vxlan_gpe_input_next_t;
194
Keith Burns (alagalah)d46cca12016-08-25 11:21:39 -0700195/** struct for VXLAN GPE errors */
sharath reddy6f8273a2017-12-11 11:31:31 +0530196typedef enum
197{
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700198#define vxlan_gpe_error(n,s) VXLAN_GPE_ERROR_##n,
199#include <vnet/vxlan-gpe/vxlan_gpe_error.def>
200#undef vxlan_gpe_error
201 VXLAN_GPE_N_ERROR,
202} vxlan_gpe_input_error_t;
203
Keith Burns (alagalah)d46cca12016-08-25 11:21:39 -0700204/** Struct for VXLAN GPE node state */
sharath reddy6f8273a2017-12-11 11:31:31 +0530205typedef struct
206{
Keith Burns (alagalah)d46cca12016-08-25 11:21:39 -0700207 /** vector of encap tunnel instances */
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700208 vxlan_gpe_tunnel_t *tunnels;
209
Keith Burns (alagalah)d46cca12016-08-25 11:21:39 -0700210 /** lookup IPv4 VXLAN GPE tunnel by key */
sharath reddy6f8273a2017-12-11 11:31:31 +0530211 uword *vxlan4_gpe_tunnel_by_key;
Keith Burns (alagalah)d46cca12016-08-25 11:21:39 -0700212 /** lookup IPv6 VXLAN GPE tunnel by key */
sharath reddy6f8273a2017-12-11 11:31:31 +0530213 uword *vxlan6_gpe_tunnel_by_key;
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700214
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800215 /* local VTEP IPs ref count used by vxlan-bypass node to check if
216 received VXLAN packet DIP matches any local VTEP address */
Nick Zavaritsky27518c22020-02-27 15:54:58 +0000217 vtep_table_t vtep_table;
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800218 /* mcast shared info */
sharath reddy6f8273a2017-12-11 11:31:31 +0530219 uword *mcast_shared; /* keyed on mcast ip46 addr */
Keith Burns (alagalah)d46cca12016-08-25 11:21:39 -0700220 /** Free vlib hw_if_indices */
sharath reddy6f8273a2017-12-11 11:31:31 +0530221 u32 *free_vxlan_gpe_tunnel_hw_if_indices;
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700222
Keith Burns (alagalah)d46cca12016-08-25 11:21:39 -0700223 /** Mapping from sw_if_index to tunnel index */
sharath reddy6f8273a2017-12-11 11:31:31 +0530224 u32 *tunnel_index_by_sw_if_index;
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700225
Keith Burns (alagalah)d46cca12016-08-25 11:21:39 -0700226 /** State convenience vlib_main_t */
sharath reddy6f8273a2017-12-11 11:31:31 +0530227 vlib_main_t *vlib_main;
Keith Burns (alagalah)d46cca12016-08-25 11:21:39 -0700228 /** State convenience vnet_main_t */
sharath reddy6f8273a2017-12-11 11:31:31 +0530229 vnet_main_t *vnet_main;
Vengada Govindan6d403a02016-10-12 05:54:09 -0700230
Junfeng Wang290526e2021-03-09 16:44:57 +0800231 /* cache for last 8 vxlan_gpe tunnel */
Junfeng Wang290526e2021-03-09 16:44:57 +0800232 vtep4_cache_t vtep4_u512;
Junfeng Wang290526e2021-03-09 16:44:57 +0800233
Vengada Govindan6d403a02016-10-12 05:54:09 -0700234 /** List of next nodes for the decap indexed on protocol */
235 uword decap_next_node_list[VXLAN_GPE_PROTOCOL_MAX];
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700236} vxlan_gpe_main_t;
237
Dave Wallace71612d62017-10-24 01:32:41 -0400238extern vxlan_gpe_main_t vxlan_gpe_main;
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700239
240extern vlib_node_registration_t vxlan_gpe_encap_node;
Hongjun Nidf921cc2016-05-25 01:16:19 +0800241extern vlib_node_registration_t vxlan4_gpe_input_node;
242extern vlib_node_registration_t vxlan6_gpe_input_node;
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700243
sharath reddy6f8273a2017-12-11 11:31:31 +0530244u8 *format_vxlan_gpe_encap_trace (u8 * s, va_list * args);
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700245
Keith Burns (alagalah)d46cca12016-08-25 11:21:39 -0700246/** Struct for VXLAN GPE add/del args */
sharath reddy6f8273a2017-12-11 11:31:31 +0530247typedef struct
248{
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700249 u8 is_add;
Hongjun Nidf921cc2016-05-25 01:16:19 +0800250 u8 is_ip6;
251 ip46_address_t local, remote;
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700252 u8 protocol;
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800253 u32 mcast_sw_if_index;
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700254 u32 encap_fib_index;
255 u32 decap_fib_index;
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700256 u32 vni;
Artem Glazychevea962922021-05-28 19:09:14 +0700257 u16 local_port;
258 u16 remote_port;
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700259} vnet_vxlan_gpe_add_del_tunnel_args_t;
260
261
Hongjun Ni7deb1392016-06-15 22:49:23 +0800262int vnet_vxlan_gpe_add_del_tunnel
sharath reddy6f8273a2017-12-11 11:31:31 +0530263 (vnet_vxlan_gpe_add_del_tunnel_args_t * a, u32 * sw_if_indexp);
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700264
265
Vengada Govindan6d403a02016-10-12 05:54:09 -0700266int vxlan4_gpe_rewrite (vxlan_gpe_tunnel_t * t, u32 extension_size,
sharath reddy6f8273a2017-12-11 11:31:31 +0530267 u8 protocol_override, uword encap_next_node);
Vengada Govindan6d403a02016-10-12 05:54:09 -0700268int vxlan6_gpe_rewrite (vxlan_gpe_tunnel_t * t, u32 extension_size,
sharath reddy6f8273a2017-12-11 11:31:31 +0530269 u8 protocol_override, uword encap_next_node);
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700270
Vengada Govindan6d403a02016-10-12 05:54:09 -0700271/**
272 * @brief Struct for defining VXLAN GPE next nodes
273 */
sharath reddy6f8273a2017-12-11 11:31:31 +0530274typedef enum
275{
Vengada Govindan6d403a02016-10-12 05:54:09 -0700276 VXLAN_GPE_ENCAP_NEXT_IP4_LOOKUP,
277 VXLAN_GPE_ENCAP_NEXT_IP6_LOOKUP,
278 VXLAN_GPE_ENCAP_NEXT_DROP,
279 VXLAN_GPE_ENCAP_N_NEXT
280} vxlan_gpe_encap_next_t;
281
282
sharath reddy6f8273a2017-12-11 11:31:31 +0530283void vxlan_gpe_unregister_decap_protocol (u8 protocol_id,
284 uword next_node_index);
Vengada Govindan6d403a02016-10-12 05:54:09 -0700285
sharath reddy6f8273a2017-12-11 11:31:31 +0530286void vxlan_gpe_register_decap_protocol (u8 protocol_id,
287 uword next_node_index);
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700288
sharath reddy6f8273a2017-12-11 11:31:31 +0530289void vnet_int_vxlan_gpe_bypass_mode (u32 sw_if_index, u8 is_ip6,
290 u8 is_enable);
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700291
292#endif /* included_vnet_vxlan_gpe_h */
sharath reddy6f8273a2017-12-11 11:31:31 +0530293
294/*
295 * fd.io coding-style-patch-verification: ON
296 *
297 * Local Variables:
298 * eval: (c-set-style "gnu")
299 * End:
300 */