blob: 73052278a48ed0a06cf5d30cd47f64f7aad0df64 [file] [log] [blame]
Ed Warnickecb9cada2015-12-08 15:45:58 -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 */
15#ifndef included_vnet_vxlan_h
16#define included_vnet_vxlan_h
17
18#include <vppinfra/error.h>
19#include <vppinfra/hash.h>
Eyal Baridd47eca2018-07-08 08:15:56 +030020#include <vppinfra/bihash_16_8.h>
Eyal Bari0fa56782018-06-04 12:25:05 +030021#include <vppinfra/bihash_24_8.h>
Ed Warnickecb9cada2015-12-08 15:45:58 -070022#include <vnet/vnet.h>
23#include <vnet/ip/ip.h>
24#include <vnet/l2/l2_input.h>
John Lo3ef822e2016-06-07 09:14:07 -040025#include <vnet/l2/l2_output.h>
Ed Warnickecb9cada2015-12-08 15:45:58 -070026#include <vnet/l2/l2_bd.h>
27#include <vnet/ethernet/ethernet.h>
28#include <vnet/vxlan/vxlan_packet.h>
29#include <vnet/ip/ip4_packet.h>
Chris Luke99cb3352016-04-26 10:49:53 -040030#include <vnet/ip/ip6_packet.h>
Dave Barach68b0fb02017-02-28 15:15:56 -050031#include <vnet/udp/udp.h>
John Loc42912d2016-11-07 18:30:47 -050032#include <vnet/dpo/dpo.h>
Eyal Baric5b13602016-11-24 19:42:43 +020033#include <vnet/adj/adj_types.h>
Ed Warnickecb9cada2015-12-08 15:45:58 -070034
Eyal Bari0fa56782018-06-04 12:25:05 +030035/* *INDENT-OFF* */
Ed Warnickecb9cada2015-12-08 15:45:58 -070036typedef CLIB_PACKED (struct {
Eyal Bari0fa56782018-06-04 12:25:05 +030037 ip4_header_t ip4; /* 20 bytes */
38 udp_header_t udp; /* 8 bytes */
39 vxlan_header_t vxlan; /* 8 bytes */
Ed Warnickecb9cada2015-12-08 15:45:58 -070040}) ip4_vxlan_header_t;
41
Chris Luke99cb3352016-04-26 10:49:53 -040042typedef CLIB_PACKED (struct {
Eyal Bari0fa56782018-06-04 12:25:05 +030043 ip6_header_t ip6; /* 40 bytes */
44 udp_header_t udp; /* 8 bytes */
45 vxlan_header_t vxlan; /* 8 bytes */
Chris Luke99cb3352016-04-26 10:49:53 -040046}) ip6_vxlan_header_t;
Eyal Baridd47eca2018-07-08 08:15:56 +030047/* *INDENT-ON* */
Chris Luke99cb3352016-04-26 10:49:53 -040048
Eyal Baridd47eca2018-07-08 08:15:56 +030049/*
50* Key fields: remote ip, vni on incoming VXLAN packet
51* all fields in NET byte order
52*/
53typedef clib_bihash_kv_16_8_t vxlan4_tunnel_key_t;
Chris Luke99cb3352016-04-26 10:49:53 -040054
Eyal Bari0fa56782018-06-04 12:25:05 +030055/*
56* Key fields: remote ip, vni and fib index on incoming VXLAN packet
57* ip, vni fields in NET byte order
58* fib index field in host byte order
59*/
Eyal Baridd47eca2018-07-08 08:15:56 +030060typedef clib_bihash_kv_24_8_t vxlan6_tunnel_key_t;
Ed Warnickecb9cada2015-12-08 15:45:58 -070061
Eyal Bariefd9cf32018-10-02 12:23:06 +030062typedef union
63{
64 struct
65 {
66 u32 sw_if_index; /* unicast - input interface / mcast - stats interface */
67 union
68 {
69 struct /* unicast action */
70 {
71 u16 next_index;
72 u8 error;
73 };
74 ip4_address_t local_ip; /* used as dst ip for mcast pkts to assign them to unicast tunnel */
75 };
76 };
77 u64 as_u64;
78} vxlan_decap_info_t;
79
Eyal Bari0fa56782018-06-04 12:25:05 +030080typedef struct
81{
Dave Baracheb987d32018-05-03 08:26:39 -040082 /* Required for pool_get_aligned */
Eyal Bari0fa56782018-06-04 12:25:05 +030083 CLIB_CACHE_LINE_ALIGN_MARK (cacheline0);
Dave Baracheb987d32018-05-03 08:26:39 -040084
John Loc42912d2016-11-07 18:30:47 -050085 /* FIB DPO for IP forwarding of VXLAN encap packet */
Eyal Bari0fa56782018-06-04 12:25:05 +030086 dpo_id_t next_dpo;
John Loc42912d2016-11-07 18:30:47 -050087
Ed Warnickecb9cada2015-12-08 15:45:58 -070088 /* vxlan VNI in HOST byte order */
89 u32 vni;
90
John Loc42912d2016-11-07 18:30:47 -050091 /* tunnel src and dst addresses */
92 ip46_address_t src;
93 ip46_address_t dst;
Chris Luke99cb3352016-04-26 10:49:53 -040094
John Lo56912c82016-12-08 16:10:02 -050095 /* mcast packet output intfc index (used only if dst is mcast) */
Eyal Baric5b13602016-11-24 19:42:43 +020096 u32 mcast_sw_if_index;
John Lo56912c82016-12-08 16:10:02 -050097
Hongjun Nibeb4bf72016-11-25 00:03:46 +080098 /* decap next index */
Eyal Baria5679e82018-08-26 15:20:07 +030099 u16 decap_next_index;
Eyal Baric5b13602016-11-24 19:42:43 +0200100
John Loc42912d2016-11-07 18:30:47 -0500101 /* The FIB index for src/dst addresses */
102 u32 encap_fib_index;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700103
John Loc42912d2016-11-07 18:30:47 -0500104 /* vnet intfc index */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700105 u32 sw_if_index;
John Loc42912d2016-11-07 18:30:47 -0500106 u32 hw_if_index;
Chris Luke99cb3352016-04-26 10:49:53 -0400107
John Loc42912d2016-11-07 18:30:47 -0500108 /**
109 * Linkage into the FIB object graph
110 */
111 fib_node_t node;
Chris Luke99cb3352016-04-26 10:49:53 -0400112
Eyal Baric5b13602016-11-24 19:42:43 +0200113 /*
114 * The FIB entry for (depending on VXLAN tunnel is unicast or mcast)
115 * sending unicast VXLAN encap packets or receiving mcast VXLAN packets
116 */
John Loc42912d2016-11-07 18:30:47 -0500117 fib_node_index_t fib_entry_index;
Eyal Baric5b13602016-11-24 19:42:43 +0200118 adj_index_t mcast_adj_index;
John Loc42912d2016-11-07 18:30:47 -0500119
120 /**
Paul Vinciguerrabdc0e6b2018-09-22 05:32:50 -0700121 * The tunnel is a child of the FIB entry for its destination. This is
John Loc42912d2016-11-07 18:30:47 -0500122 * so it receives updates when the forwarding information for that entry
123 * changes.
124 * The tunnels sibling index on the FIB entry's dependency list.
125 */
126 u32 sibling_index;
Jon Loeliger3d460bd2018-02-01 16:36:12 -0600127
Eyal Bari0fa56782018-06-04 12:25:05 +0300128 u32 flow_index; /* infra flow index */
129 u32 dev_instance; /* Real device instance in tunnel vector */
130 u32 user_instance; /* Instance name being shown to user */
eyal bari82e21d72018-04-26 13:14:55 +0300131
Eyal Bari0fa56782018-06-04 12:25:05 +0300132 vnet_declare_rewrite (VLIB_BUFFER_PRE_DATA_SIZE);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700133} vxlan_tunnel_t;
134
135#define foreach_vxlan_input_next \
136_(DROP, "error-drop") \
John Loc42912d2016-11-07 18:30:47 -0500137_(L2_INPUT, "l2-input")
Ed Warnickecb9cada2015-12-08 15:45:58 -0700138
Eyal Bari0fa56782018-06-04 12:25:05 +0300139typedef enum
140{
Ed Warnickecb9cada2015-12-08 15:45:58 -0700141#define _(s,n) VXLAN_INPUT_NEXT_##s,
142 foreach_vxlan_input_next
143#undef _
Eyal Bari0fa56782018-06-04 12:25:05 +0300144 VXLAN_INPUT_N_NEXT,
Ed Warnickecb9cada2015-12-08 15:45:58 -0700145} vxlan_input_next_t;
146
Eyal Bari0fa56782018-06-04 12:25:05 +0300147typedef enum
148{
Ed Warnickecb9cada2015-12-08 15:45:58 -0700149#define vxlan_error(n,s) VXLAN_ERROR_##n,
150#include <vnet/vxlan/vxlan_error.def>
151#undef vxlan_error
152 VXLAN_N_ERROR,
153} vxlan_input_error_t;
154
Eyal Bari0fa56782018-06-04 12:25:05 +0300155typedef struct
156{
Ed Warnickecb9cada2015-12-08 15:45:58 -0700157 /* vector of encap tunnel instances */
Eyal Bari0fa56782018-06-04 12:25:05 +0300158 vxlan_tunnel_t *tunnels;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700159
160 /* lookup tunnel by key */
Eyal Baridd47eca2018-07-08 08:15:56 +0300161 clib_bihash_16_8_t vxlan4_tunnel_by_key; /* keyed on ipv4.dst + fib + vni */
162 clib_bihash_24_8_t vxlan6_tunnel_by_key; /* keyed on ipv6.dst + fib + vni */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700163
Eyal Barifff67c82016-12-21 12:45:47 +0200164 /* local VTEP IPs ref count used by vxlan-bypass node to check if
165 received VXLAN packet DIP matches any local VTEP address */
Eyal Bari0fa56782018-06-04 12:25:05 +0300166 uword *vtep4; /* local ip4 VTEPs keyed on their ip4 addr */
167 uword *vtep6; /* local ip6 VTEPs keyed on their ip6 addr */
John Lo37682e12016-11-30 12:51:39 -0500168
Eyal Bari0ded8512017-01-19 17:01:09 +0200169 /* mcast shared info */
Eyal Bari0fa56782018-06-04 12:25:05 +0300170 uword *mcast_shared; /* keyed on mcast ip46 addr */
Eyal Barifff67c82016-12-21 12:45:47 +0200171
Dave Wallace60231f32015-12-17 21:04:30 -0500172 /* Mapping from sw_if_index to tunnel index */
Eyal Bari0fa56782018-06-04 12:25:05 +0300173 u32 *tunnel_index_by_sw_if_index;
Dave Wallace60231f32015-12-17 21:04:30 -0500174
Ed Warnickecb9cada2015-12-08 15:45:58 -0700175 /* convenience */
Eyal Bari0fa56782018-06-04 12:25:05 +0300176 vlib_main_t *vlib_main;
177 vnet_main_t *vnet_main;
Jon Loeliger3d460bd2018-02-01 16:36:12 -0600178
179 /* Record used instances */
180 uword *instance_used;
eyal bariaf86a482018-04-17 11:20:27 +0300181 u32 flow_id_start;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700182} vxlan_main_t;
183
Dave Wallace71612d62017-10-24 01:32:41 -0400184extern vxlan_main_t vxlan_main;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700185
Chris Luke99cb3352016-04-26 10:49:53 -0400186extern vlib_node_registration_t vxlan4_input_node;
187extern vlib_node_registration_t vxlan6_input_node;
John Loc42912d2016-11-07 18:30:47 -0500188extern vlib_node_registration_t vxlan4_encap_node;
189extern vlib_node_registration_t vxlan6_encap_node;
eyal bariaf86a482018-04-17 11:20:27 +0300190extern vlib_node_registration_t vxlan4_flow_input_node;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700191
Eyal Bari0fa56782018-06-04 12:25:05 +0300192u8 *format_vxlan_encap_trace (u8 * s, va_list * args);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700193
Eyal Bari0fa56782018-06-04 12:25:05 +0300194typedef struct
195{
Ed Warnickecb9cada2015-12-08 15:45:58 -0700196 u8 is_add;
Chris Luke99cb3352016-04-26 10:49:53 -0400197
198 /* we normally use is_ip4, but since this adds to the
Paul Vinciguerrabdc0e6b2018-09-22 05:32:50 -0700199 * structure, this seems less of a breaking change */
Chris Luke99cb3352016-04-26 10:49:53 -0400200 u8 is_ip6;
Jon Loeliger3d460bd2018-02-01 16:36:12 -0600201 u32 instance;
Chris Luke99cb3352016-04-26 10:49:53 -0400202 ip46_address_t src, dst;
Eyal Baric5b13602016-11-24 19:42:43 +0200203 u32 mcast_sw_if_index;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700204 u32 encap_fib_index;
205 u32 decap_next_index;
206 u32 vni;
207} vnet_vxlan_add_del_tunnel_args_t;
208
Eyal Bari0fa56782018-06-04 12:25:05 +0300209int vnet_vxlan_add_del_tunnel
210 (vnet_vxlan_add_del_tunnel_args_t * a, u32 * sw_if_indexp);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700211
Eyal Bari0fa56782018-06-04 12:25:05 +0300212void vnet_int_vxlan_bypass_mode (u32 sw_if_index, u8 is_ip6, u8 is_enable);
eyal bariaf86a482018-04-17 11:20:27 +0300213
Eyal Bari0fa56782018-06-04 12:25:05 +0300214int vnet_vxlan_add_del_rx_flow (u32 hw_if_index, u32 t_imdex, int is_add);
eyal bariaf86a482018-04-17 11:20:27 +0300215
216u32 vnet_vxlan_get_tunnel_index (u32 sw_if_index);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700217#endif /* included_vnet_vxlan_h */
Jon Loeliger3d460bd2018-02-01 16:36:12 -0600218
219/*
Eyal Bari0fa56782018-06-04 12:25:05 +0300220 * fd.io coding-style-patch-verification: ON
221 *
Jon Loeliger3d460bd2018-02-01 16:36:12 -0600222 * Local Variables:
223 * eval: (c-set-style "gnu")
224 * End:
225 */