session: memory leaks on various transports when session disable and enable
[vpp.git] / src / plugins / lisp / lisp-gpe / lisp_gpe.h
1 /*
2  * Copyright (c) 2016 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 /**
16  * @file
17  * @brief LISP-GPE definitions.
18  */
19
20 #ifndef included_vnet_lisp_gpe_h
21 #define included_vnet_lisp_gpe_h
22
23 #include <vppinfra/error.h>
24 #include <vppinfra/mhash.h>
25 #include <vnet/vnet.h>
26 #include <vnet/ip/ip.h>
27 #include <vnet/l2/l2_input.h>
28 #include <vnet/ethernet/ethernet.h>
29 #include <vnet/ip/ip4_packet.h>
30 #include <vnet/udp/udp_packet.h>
31 #include <vnet/udp/udp_local.h>
32 #include <lisp/lisp-cp/lisp_types.h>
33 #include <lisp/lisp-gpe/lisp_gpe_packet.h>
34 #include <vnet/adj/adj_types.h>
35 #include <vppinfra/bihash_24_8.h>
36 #include <vppinfra/bihash_template.h>
37
38 /** IP4-UDP-LISP encap header */
39 typedef 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;
44
45 /** IP6-UDP-LISP encap header */
46 typedef CLIB_PACKED (struct {
47   ip6_header_t ip6;             /* 40 bytes */
48   udp_header_t udp;             /* 8 bytes */
49   lisp_gpe_header_t lisp;       /* 8 bytes */
50 }) ip6_udp_lisp_gpe_header_t;
51
52 #define foreach_lisp_gpe_ip_input_next          \
53 _(DROP, "error-drop")                           \
54 _(IP4_INPUT, "ip4-input")                       \
55 _(IP6_INPUT, "ip6-input")                       \
56 _(L2_INPUT, "l2-input")
57
58 /** Enum of possible next nodes post LISP-GPE decap */
59 typedef enum
60 {
61 #define _(s,n) LISP_GPE_INPUT_NEXT_##s,
62   foreach_lisp_gpe_ip_input_next
63 #undef _
64     LISP_GPE_INPUT_N_NEXT,
65 } lisp_gpe_input_next_t;
66
67 /* Arc to nsh-input added only if nsh-input exists */
68 #define LISP_GPE_INPUT_NEXT_NSH_INPUT 4
69
70 typedef enum
71 {
72 #define lisp_gpe_error(n,s) LISP_GPE_ERROR_##n,
73 #include <lisp/lisp-gpe/lisp_gpe_error.def>
74 #undef lisp_gpe_error
75   LISP_GPE_N_ERROR,
76 } lisp_gpe_error_t;
77
78 typedef struct tunnel_lookup
79 {
80   /** Lookup lisp-gpe interfaces by dp table (eg. vrf/bridge index) */
81   uword *hw_if_index_by_dp_table;
82
83   /** lookup decap tunnel termination sw_if_index by vni and vice versa */
84   uword *sw_if_index_by_vni;
85
86   // FIXME - Need this?
87   uword *vni_by_sw_if_index;
88 } tunnel_lookup_t;
89
90 typedef struct
91 {
92   u32 fwd_entry_index;
93   u32 tunnel_index;
94 } lisp_stats_key_t;
95
96 typedef struct
97 {
98   u32 vni;
99   dp_address_t deid;
100   dp_address_t seid;
101   ip_address_t loc_rloc;
102   ip_address_t rmt_rloc;
103
104   vlib_counter_t counters;
105 } lisp_api_stats_t;
106
107 typedef enum gpe_encap_mode_e
108 {
109   GPE_ENCAP_LISP,
110   GPE_ENCAP_VXLAN,
111   GPE_ENCAP_COUNT
112 } gpe_encap_mode_t;
113
114 /** LISP-GPE global state*/
115 typedef struct lisp_gpe_main
116 {
117   /**
118    * @brief DB of all forwarding entries. The Key is:{l-EID,r-EID,vni}
119    * where the EID encodes L2 or L3
120    */
121   uword *lisp_gpe_fwd_entries;
122
123   /**
124    * @brief A Pool of all LISP forwarding entries
125    */
126   struct lisp_gpe_fwd_entry_t_ *lisp_fwd_entry_pool;
127
128   /** Free vlib hw_if_indices */
129   u32 *free_tunnel_hw_if_indices;
130
131   u8 is_en;
132
133   /* L3 data structures
134    * ================== */
135   tunnel_lookup_t l3_ifaces;
136
137   /* L2 data structures
138    * ================== */
139
140   /** L2 LISP FIB */
141     BVT (clib_bihash) l2_fib;
142
143   tunnel_lookup_t l2_ifaces;
144
145   /** Load-balance for a miss in the table */
146   dpo_id_t l2_lb_cp_lkup;
147
148   /* NSH data structures
149    * ================== */
150
151     BVT (clib_bihash) nsh_fib;
152
153   tunnel_lookup_t nsh_ifaces;
154
155   const dpo_id_t *nsh_cp_lkup;
156
157   gpe_encap_mode_t encap_mode;
158
159   u8 *placeholder_stats_pool;
160   uword *lisp_stats_index_by_key;
161   vlib_combined_counter_main_t counters;
162
163   /** Native fwd data structures */
164   fib_route_path_t *native_fwd_rpath[2];
165   u32 *native_fwd_lfes[2];
166
167   /** convenience */
168   vlib_main_t *vlib_main;
169   vnet_main_t *vnet_main;
170   ip4_main_t *im4;
171   ip6_main_t *im6;
172   ip_lookup_main_t *lm4;
173   ip_lookup_main_t *lm6;
174 } lisp_gpe_main_t;
175
176 /** LISP-GPE global state*/
177 extern lisp_gpe_main_t lisp_gpe_main;
178
179 always_inline lisp_gpe_main_t *
180 vnet_lisp_gpe_get_main ()
181 {
182   return &lisp_gpe_main;
183 }
184
185
186 extern vlib_node_registration_t lisp_gpe_ip4_input_node;
187 extern vlib_node_registration_t lisp_gpe_ip6_input_node;
188 extern vnet_hw_interface_class_t lisp_gpe_hw_class;
189
190 u8 *format_lisp_gpe_header_with_length (u8 * s, va_list * args);
191
192 /** Read LISP-GPE status */
193 u8 vnet_lisp_gpe_enable_disable_status (void);
194
195 u32
196 lisp_gpe_l3_iface_find_or_create (lisp_gpe_main_t * lgm,
197                                   u32 overlay_table_id, u32 vni);
198
199 /** Add/del LISP-GPE interface. */
200 extern void lisp_gpe_del_l2_iface (lisp_gpe_main_t * lgm, u32 vni, u32 bd_id);
201 extern u32 lisp_gpe_add_l2_iface (lisp_gpe_main_t * lgm, u32 vni, u32 bd_id);
202 extern void lisp_gpe_del_l3_iface (lisp_gpe_main_t * lgm, u32 vni, u32 bd_id);
203 extern u32 lisp_gpe_add_l3_iface (lisp_gpe_main_t * lgm, u32 vni, u32 bd_id,
204                                   u8 with_default_route);
205
206
207 typedef struct
208 {
209   u8 is_en;
210 } vnet_lisp_gpe_enable_disable_args_t;
211
212 clib_error_t
213   * vnet_lisp_gpe_enable_disable (vnet_lisp_gpe_enable_disable_args_t * a);
214
215 typedef enum
216 {
217   NO_ACTION,
218   FORWARD_NATIVE,
219   SEND_MAP_REQUEST,
220   DROP
221 } negative_fwd_actions_e;
222
223 /** */
224 typedef struct
225 {
226   /** forwarding entry index of */
227   u32 fwd_entry_index;
228
229   u8 is_src_dst;
230
231   u8 is_add;
232
233   /** type of mapping */
234   u8 is_negative;
235
236   /** action for negative mappings */
237   negative_fwd_actions_e action;
238
239   /** local eid */
240   gid_address_t lcl_eid;
241
242   /** remote eid */
243   gid_address_t rmt_eid;
244
245   /** vector of locator pairs */
246   locator_pair_t *locator_pairs;
247
248   /** FIB index to lookup remote locator at encap */
249   u32 encap_fib_index;
250
251   /** FIB index to lookup inner IP at decap */
252   u32 decap_fib_index;
253
254   /* TODO remove */
255   u32 decap_next_index;
256
257   /** VNI/tenant id in HOST byte order */
258   u32 vni;
259
260   /** vrf or bd where fwd entry should be inserted */
261   union
262   {
263     /** table (vrf) id */
264     u32 table_id;
265
266     /** bridge domain id */
267     u32 bd_id;
268
269     /** generic access */
270     u32 dp_table;
271   };
272 } vnet_lisp_gpe_add_del_fwd_entry_args_t;
273
274 typedef struct
275 {
276   fib_route_path_t rpath;
277   u8 is_add;
278 } vnet_gpe_native_fwd_rpath_args_t;
279
280 typedef struct
281 {
282   u32 fwd_entry_index;
283   u32 dp_table;
284   u32 vni;
285   u8 action;
286   dp_address_t leid;
287   dp_address_t reid;
288 } lisp_api_gpe_fwd_entry_t;
289
290 #define foreach_lgpe_ip4_lookup_next    \
291   _(DROP, "error-drop")                 \
292   _(LISP_CP_LOOKUP, "lisp-cp-lookup")
293
294 typedef enum lgpe_ip4_lookup_next
295 {
296 #define _(sym,str) LGPE_IP4_LOOKUP_NEXT_##sym,
297   foreach_lgpe_ip4_lookup_next
298 #undef _
299     LGPE_IP4_LOOKUP_N_NEXT,
300 } lgpe_ip4_lookup_next_t;
301
302 #define foreach_lgpe_ip6_lookup_next    \
303   _(DROP, "error-drop")                 \
304   _(LISP_CP_LOOKUP, "lisp-cp-lookup")
305
306 typedef enum lgpe_ip6_lookup_next
307 {
308 #define _(sym,str) LGPE_IP6_LOOKUP_NEXT_##sym,
309   foreach_lgpe_ip6_lookup_next
310 #undef _
311     LGPE_IP6_LOOKUP_N_NEXT,
312 } lgpe_ip6_lookup_next_t;
313
314 u8 *format_vnet_lisp_gpe_status (u8 * s, va_list * args);
315
316 lisp_api_gpe_fwd_entry_t *vnet_lisp_gpe_fwd_entries_get_by_vni (u32 vni);
317 gpe_encap_mode_t vnet_gpe_get_encap_mode (void);
318 int vnet_gpe_set_encap_mode (gpe_encap_mode_t mode);
319
320 u8 vnet_lisp_stats_enable_disable_state (void);
321 vnet_api_error_t vnet_lisp_stats_enable_disable (u8 enable);
322 lisp_api_stats_t *vnet_lisp_get_stats (void);
323 int vnet_lisp_flush_stats (void);
324 int vnet_gpe_add_del_native_fwd_rpath (vnet_gpe_native_fwd_rpath_args_t * a);
325 u32 vnet_lisp_gpe_add_nsh_iface (lisp_gpe_main_t * lgm);
326 void vnet_lisp_gpe_del_nsh_iface (lisp_gpe_main_t * lgm);
327
328 #endif /* included_vnet_lisp_gpe_h */
329
330 /*
331  * fd.io coding-style-patch-verification: ON
332  *
333  * Local Variables:
334  * eval: (c-set-style "gnu")
335  * End:
336  */