blob: b5a50ec68849256d8aee1b4c65b67a9eba38dc65 [file] [log] [blame]
Ed Warnickecb9cada2015-12-08 15:45:58 -07001/*
Florin Corase127a7e2016-02-18 22:20:01 +01002 * Copyright (c) 2016 Cisco and/or its affiliates.
Ed Warnickecb9cada2015-12-08 15:45:58 -07003 * 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 */
Florin Corasff0bf132016-09-05 19:30:35 +020015/**
16 * @file
17 * @brief LISP-GPE definitions.
18 */
Florin Corase127a7e2016-02-18 22:20:01 +010019
Ed Warnickecb9cada2015-12-08 15:45:58 -070020#ifndef included_vnet_lisp_gpe_h
21#define included_vnet_lisp_gpe_h
22
23#include <vppinfra/error.h>
Florin Corase127a7e2016-02-18 22:20:01 +010024#include <vppinfra/mhash.h>
Ed Warnickecb9cada2015-12-08 15:45:58 -070025#include <vnet/vnet.h>
26#include <vnet/ip/ip.h>
27#include <vnet/l2/l2_input.h>
28#include <vnet/ethernet/ethernet.h>
Ed Warnickecb9cada2015-12-08 15:45:58 -070029#include <vnet/ip/ip4_packet.h>
Dave Barach68b0fb02017-02-28 15:15:56 -050030#include <vnet/udp/udp.h>
Florin Corase127a7e2016-02-18 22:20:01 +010031#include <vnet/lisp-cp/lisp_types.h>
32#include <vnet/lisp-gpe/lisp_gpe_packet.h>
Neale Ranns0bfe5d82016-08-25 15:29:12 +010033#include <vnet/adj/adj_types.h>
Dave Barach68b0fb02017-02-28 15:15:56 -050034#include <vppinfra/bihash_24_8.h>
35#include <vppinfra/bihash_template.h>
Florin Corase127a7e2016-02-18 22:20:01 +010036
Florin Corasff0bf132016-09-05 19:30:35 +020037/** IP4-UDP-LISP encap header */
Florin Coras220beac2016-08-16 23:04:00 +020038/* *INDENT-OFF* */
Ed Warnickecb9cada2015-12-08 15:45:58 -070039typedef CLIB_PACKED (struct {
40 ip4_header_t ip4; /* 20 bytes */
41 udp_header_t udp; /* 8 bytes */
42 lisp_gpe_header_t lisp; /* 8 bytes */
43}) ip4_udp_lisp_gpe_header_t;
Florin Coras220beac2016-08-16 23:04:00 +020044/* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -070045
Florin Corasff0bf132016-09-05 19:30:35 +020046/** IP6-UDP-LISP encap header */
Florin Coras220beac2016-08-16 23:04:00 +020047/* *INDENT-OFF* */
Florin Coras02655bd2016-04-26 00:17:24 +020048typedef CLIB_PACKED (struct {
49 ip6_header_t ip6; /* 40 bytes */
50 udp_header_t udp; /* 8 bytes */
51 lisp_gpe_header_t lisp; /* 8 bytes */
52}) ip6_udp_lisp_gpe_header_t;
Florin Coras220beac2016-08-16 23:04:00 +020053/* *INDENT-ON* */
Florin Coras02655bd2016-04-26 00:17:24 +020054
Florin Coras02655bd2016-04-26 00:17:24 +020055#define foreach_lisp_gpe_ip_input_next \
Ed Warnickecb9cada2015-12-08 15:45:58 -070056_(DROP, "error-drop") \
57_(IP4_INPUT, "ip4-input") \
58_(IP6_INPUT, "ip6-input") \
Florin Coras1a1adc72016-07-22 01:45:30 +020059_(L2_INPUT, "l2-input")
Ed Warnickecb9cada2015-12-08 15:45:58 -070060
Florin Corasff0bf132016-09-05 19:30:35 +020061/** Enum of possible next nodes post LISP-GPE decap */
Florin Coras220beac2016-08-16 23:04:00 +020062typedef enum
63{
Ed Warnickecb9cada2015-12-08 15:45:58 -070064#define _(s,n) LISP_GPE_INPUT_NEXT_##s,
Florin Coras02655bd2016-04-26 00:17:24 +020065 foreach_lisp_gpe_ip_input_next
Ed Warnickecb9cada2015-12-08 15:45:58 -070066#undef _
Florin Coras220beac2016-08-16 23:04:00 +020067 LISP_GPE_INPUT_N_NEXT,
Ed Warnickecb9cada2015-12-08 15:45:58 -070068} lisp_gpe_input_next_t;
69
Florin Coras263440e2017-02-22 23:38:08 -080070/* Arc to nsh-input added only if nsh-input exists */
71#define LISP_GPE_INPUT_NEXT_NSH_INPUT 4
72
Florin Coras220beac2016-08-16 23:04:00 +020073typedef enum
74{
Ed Warnickecb9cada2015-12-08 15:45:58 -070075#define lisp_gpe_error(n,s) LISP_GPE_ERROR_##n,
76#include <vnet/lisp-gpe/lisp_gpe_error.def>
77#undef lisp_gpe_error
78 LISP_GPE_N_ERROR,
Florin Coras577c3552016-04-21 00:45:40 +020079} lisp_gpe_error_t;
Ed Warnickecb9cada2015-12-08 15:45:58 -070080
Florin Coras1a1adc72016-07-22 01:45:30 +020081typedef struct tunnel_lookup
82{
Florin Corasff0bf132016-09-05 19:30:35 +020083 /** Lookup lisp-gpe interfaces by dp table (eg. vrf/bridge index) */
Florin Coras220beac2016-08-16 23:04:00 +020084 uword *hw_if_index_by_dp_table;
Florin Coras1a1adc72016-07-22 01:45:30 +020085
Florin Corasff0bf132016-09-05 19:30:35 +020086 /** lookup decap tunnel termination sw_if_index by vni and vice versa */
Florin Coras220beac2016-08-16 23:04:00 +020087 uword *sw_if_index_by_vni;
Neale Ranns0bfe5d82016-08-25 15:29:12 +010088
89 // FIXME - Need this?
Florin Coras220beac2016-08-16 23:04:00 +020090 uword *vni_by_sw_if_index;
Florin Coras1a1adc72016-07-22 01:45:30 +020091} tunnel_lookup_t;
92
Filip Tehlar3e7b56932017-02-21 18:28:34 +010093
94typedef enum gpe_encap_mode_e
95{
96 GPE_ENCAP_LISP,
97 GPE_ENCAP_VXLAN,
98 GPE_ENCAP_COUNT
99} gpe_encap_mode_t;
100
Florin Corasff0bf132016-09-05 19:30:35 +0200101/** LISP-GPE global state*/
Florin Corase127a7e2016-02-18 22:20:01 +0100102typedef struct lisp_gpe_main
103{
Neale Ranns5e575b12016-10-03 09:40:25 +0100104 /**
105 * @brief DB of all forwarding entries. The Key is:{l-EID,r-EID,vni}
106 * where the EID encodes L2 or L3
107 */
108 uword *lisp_gpe_fwd_entries;
109
110 /**
111 * @brief A Pool of all LISP forwarding entries
112 */
113 struct lisp_gpe_fwd_entry_t_ *lisp_fwd_entry_pool;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700114
Florin Corasff0bf132016-09-05 19:30:35 +0200115 /** Free vlib hw_if_indices */
Florin Coras220beac2016-08-16 23:04:00 +0200116 u32 *free_tunnel_hw_if_indices;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700117
Florin Coras1a1adc72016-07-22 01:45:30 +0200118 u8 is_en;
119
120 /* L3 data structures
121 * ================== */
Florin Coras1a1adc72016-07-22 01:45:30 +0200122 tunnel_lookup_t l3_ifaces;
Florin Coras577c3552016-04-21 00:45:40 +0200123
Florin Coras1a1adc72016-07-22 01:45:30 +0200124 /* L2 data structures
125 * ================== */
126
Florin Corasff0bf132016-09-05 19:30:35 +0200127 /** L2 LISP FIB */
Florin Coras220beac2016-08-16 23:04:00 +0200128 BVT (clib_bihash) l2_fib;
Florin Coras1a1adc72016-07-22 01:45:30 +0200129
130 tunnel_lookup_t l2_ifaces;
131
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100132 /** Load-balance for a miss in the table */
Neale Ranns5e575b12016-10-03 09:40:25 +0100133 dpo_id_t l2_lb_cp_lkup;
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100134
Florin Corasce1b4c72017-01-26 14:25:34 -0800135 /* NSH data structures
136 * ================== */
137
138 BVT (clib_bihash) nsh_fib;
139
140 tunnel_lookup_t nsh_ifaces;
141
142 const dpo_id_t *nsh_cp_lkup;
143
Filip Tehlar3e7b56932017-02-21 18:28:34 +0100144 gpe_encap_mode_t encap_mode;
145
Florin Corasff0bf132016-09-05 19:30:35 +0200146 /** convenience */
Florin Coras220beac2016-08-16 23:04:00 +0200147 vlib_main_t *vlib_main;
148 vnet_main_t *vnet_main;
149 ip4_main_t *im4;
150 ip6_main_t *im6;
151 ip_lookup_main_t *lm4;
152 ip_lookup_main_t *lm6;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700153} lisp_gpe_main_t;
154
Florin Corasff0bf132016-09-05 19:30:35 +0200155/** LISP-GPE global state*/
Ed Warnickecb9cada2015-12-08 15:45:58 -0700156lisp_gpe_main_t lisp_gpe_main;
157
Florin Coras1a1adc72016-07-22 01:45:30 +0200158always_inline lisp_gpe_main_t *
Florin Coras220beac2016-08-16 23:04:00 +0200159vnet_lisp_gpe_get_main ()
160{
Florin Coras1a1adc72016-07-22 01:45:30 +0200161 return &lisp_gpe_main;
162}
163
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100164
Florin Coras02655bd2016-04-26 00:17:24 +0200165extern vlib_node_registration_t lisp_gpe_ip4_input_node;
166extern vlib_node_registration_t lisp_gpe_ip6_input_node;
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100167extern vnet_hw_interface_class_t lisp_gpe_hw_class;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700168
Florin Coras220beac2016-08-16 23:04:00 +0200169u8 *format_lisp_gpe_header_with_length (u8 * s, va_list * args);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700170
Florin Corasff0bf132016-09-05 19:30:35 +0200171/** Read LISP-GPE status */
Florin Coras220beac2016-08-16 23:04:00 +0200172u8 vnet_lisp_gpe_enable_disable_status (void);
Florin Corasff0bf132016-09-05 19:30:35 +0200173
Neale Ranns5e575b12016-10-03 09:40:25 +0100174u32
175lisp_gpe_l3_iface_find_or_create (lisp_gpe_main_t * lgm,
176 u32 overlay_table_id, u32 vni);
177
Florin Corasff0bf132016-09-05 19:30:35 +0200178/** Add/del LISP-GPE interface. */
Neale Ranns5e575b12016-10-03 09:40:25 +0100179extern void lisp_gpe_del_l2_iface (lisp_gpe_main_t * lgm, u32 vni, u32 bd_id);
180extern u32 lisp_gpe_add_l2_iface (lisp_gpe_main_t * lgm, u32 vni, u32 bd_id);
181extern void lisp_gpe_del_l3_iface (lisp_gpe_main_t * lgm, u32 vni, u32 bd_id);
182extern u32 lisp_gpe_add_l3_iface (lisp_gpe_main_t * lgm, u32 vni, u32 bd_id);
183
Florin Corase127a7e2016-02-18 22:20:01 +0100184
Florin Coras577c3552016-04-21 00:45:40 +0200185typedef struct
186{
187 u8 is_en;
188} vnet_lisp_gpe_enable_disable_args_t;
189
Florin Coras220beac2016-08-16 23:04:00 +0200190clib_error_t
191 * vnet_lisp_gpe_enable_disable (vnet_lisp_gpe_enable_disable_args_t * a);
Florin Coras577c3552016-04-21 00:45:40 +0200192
Neale Ranns5e575b12016-10-03 09:40:25 +0100193typedef enum
194{
195 NO_ACTION,
196 FORWARD_NATIVE,
197 SEND_MAP_REQUEST,
198 DROP
199} negative_fwd_actions_e;
200
Florin Corasff0bf132016-09-05 19:30:35 +0200201/** */
Florin Corase127a7e2016-02-18 22:20:01 +0100202typedef struct
203{
204 u8 is_add;
Florin Corased09a052016-05-06 14:22:40 +0200205
Florin Corasff0bf132016-09-05 19:30:35 +0200206 /** type of mapping */
Florin Corase127a7e2016-02-18 22:20:01 +0100207 u8 is_negative;
Florin Corasff0bf132016-09-05 19:30:35 +0200208
209 /** action for negative mappings */
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100210 negative_fwd_actions_e action;
Florin Corased09a052016-05-06 14:22:40 +0200211
Florin Corasff0bf132016-09-05 19:30:35 +0200212 /** local eid */
Florin Coras1a1adc72016-07-22 01:45:30 +0200213 gid_address_t lcl_eid;
Florin Corasff0bf132016-09-05 19:30:35 +0200214
215 /** remote eid */
Florin Coras1a1adc72016-07-22 01:45:30 +0200216 gid_address_t rmt_eid;
Florin Corased09a052016-05-06 14:22:40 +0200217
Florin Corasff0bf132016-09-05 19:30:35 +0200218 /** vector of locator pairs */
Florin Coras220beac2016-08-16 23:04:00 +0200219 locator_pair_t *locator_pairs;
Florin Corased09a052016-05-06 14:22:40 +0200220
Florin Corasff0bf132016-09-05 19:30:35 +0200221 /** FIB index to lookup remote locator at encap */
Florin Corase127a7e2016-02-18 22:20:01 +0100222 u32 encap_fib_index;
Florin Corasff0bf132016-09-05 19:30:35 +0200223
224 /** FIB index to lookup inner IP at decap */
Florin Corase127a7e2016-02-18 22:20:01 +0100225 u32 decap_fib_index;
Florin Corased09a052016-05-06 14:22:40 +0200226
Florin Corasff0bf132016-09-05 19:30:35 +0200227 /* TODO remove */
228 u32 decap_next_index;
Florin Corased09a052016-05-06 14:22:40 +0200229
Florin Corasff0bf132016-09-05 19:30:35 +0200230 /** VNI/tenant id in HOST byte order */
Florin Corased09a052016-05-06 14:22:40 +0200231 u32 vni;
232
Florin Corasff0bf132016-09-05 19:30:35 +0200233 /** vrf or bd where fwd entry should be inserted */
Florin Coras1a1adc72016-07-22 01:45:30 +0200234 union
235 {
Florin Corasff0bf132016-09-05 19:30:35 +0200236 /** table (vrf) id */
Florin Coras1a1adc72016-07-22 01:45:30 +0200237 u32 table_id;
Florin Corasff0bf132016-09-05 19:30:35 +0200238
239 /** bridge domain id */
Florin Coras1a1adc72016-07-22 01:45:30 +0200240 u16 bd_id;
Florin Coras429e7952016-08-02 02:31:03 +0200241
Florin Corasff0bf132016-09-05 19:30:35 +0200242 /** generic access */
Florin Coras429e7952016-08-02 02:31:03 +0200243 u32 dp_table;
Florin Coras1a1adc72016-07-22 01:45:30 +0200244 };
Florin Corase127a7e2016-02-18 22:20:01 +0100245} vnet_lisp_gpe_add_del_fwd_entry_args_t;
246
Filip Tehlar5fae99c2017-01-18 12:57:37 +0100247typedef struct
248{
249 u32 fwd_entry_index;
250 u32 dp_table;
251 u32 vni;
252 dp_address_t leid;
253 dp_address_t reid;
254} lisp_api_gpe_fwd_entry_t;
255
Florin Coras02655bd2016-04-26 00:17:24 +0200256#define foreach_lgpe_ip4_lookup_next \
257 _(DROP, "error-drop") \
258 _(LISP_CP_LOOKUP, "lisp-cp-lookup")
259
260typedef enum lgpe_ip4_lookup_next
261{
262#define _(sym,str) LGPE_IP4_LOOKUP_NEXT_##sym,
263 foreach_lgpe_ip4_lookup_next
264#undef _
Florin Coras220beac2016-08-16 23:04:00 +0200265 LGPE_IP4_LOOKUP_N_NEXT,
Florin Coras02655bd2016-04-26 00:17:24 +0200266} lgpe_ip4_lookup_next_t;
267
Florin Corasff0bf132016-09-05 19:30:35 +0200268#define foreach_lgpe_ip6_lookup_next \
Florin Coras02655bd2016-04-26 00:17:24 +0200269 _(DROP, "error-drop") \
270 _(LISP_CP_LOOKUP, "lisp-cp-lookup")
271
272typedef enum lgpe_ip6_lookup_next
273{
274#define _(sym,str) LGPE_IP6_LOOKUP_NEXT_##sym,
275 foreach_lgpe_ip6_lookup_next
276#undef _
Florin Coras220beac2016-08-16 23:04:00 +0200277 LGPE_IP6_LOOKUP_N_NEXT,
Florin Coras02655bd2016-04-26 00:17:24 +0200278} lgpe_ip6_lookup_next_t;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700279
Florin Coras220beac2016-08-16 23:04:00 +0200280u8 *format_vnet_lisp_gpe_status (u8 * s, va_list * args);
Filip Tehlar46d4e362016-05-09 09:39:26 +0200281
Filip Tehlar5fae99c2017-01-18 12:57:37 +0100282lisp_api_gpe_fwd_entry_t *vnet_lisp_gpe_fwd_entries_get_by_vni (u32 vni);
Filip Tehlar3e7b56932017-02-21 18:28:34 +0100283gpe_encap_mode_t vnet_gpe_get_encap_mode (void);
284int vnet_gpe_set_encap_mode (gpe_encap_mode_t mode);
Filip Tehlar5fae99c2017-01-18 12:57:37 +0100285
Ed Warnickecb9cada2015-12-08 15:45:58 -0700286#endif /* included_vnet_lisp_gpe_h */
Florin Coras220beac2016-08-16 23:04:00 +0200287
288/*
289 * fd.io coding-style-patch-verification: ON
290 *
291 * Local Variables:
292 * eval: (c-set-style "gnu")
293 * End:
294 */