LISP API/VAT cleanup
[vpp.git] / vnet / vnet / 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 #ifndef included_vnet_lisp_gpe_h
17 #define included_vnet_lisp_gpe_h
18
19 #include <vppinfra/error.h>
20 #include <vppinfra/mhash.h>
21 #include <vnet/vnet.h>
22 #include <vnet/ip/ip.h>
23 #include <vnet/l2/l2_input.h>
24 #include <vnet/ethernet/ethernet.h>
25 #include <vnet/ip/ip4_packet.h>
26 #include <vnet/ip/udp.h>
27 #include <vnet/lisp-cp/lisp_types.h>
28 #include <vnet/lisp-gpe/lisp_gpe_packet.h>
29
30 /* encap headers */
31 typedef CLIB_PACKED (struct {
32   ip4_header_t ip4;             /* 20 bytes */
33   udp_header_t udp;             /* 8 bytes */
34   lisp_gpe_header_t lisp;       /* 8 bytes */
35 }) ip4_udp_lisp_gpe_header_t;
36
37 typedef CLIB_PACKED (struct {
38   ip6_header_t ip6;             /* 40 bytes */
39   udp_header_t udp;             /* 8 bytes */
40   lisp_gpe_header_t lisp;       /* 8 bytes */
41 }) ip6_udp_lisp_gpe_header_t;
42
43 typedef struct
44 {
45   union
46   {
47     struct
48     {
49       /* within the dp only ip and mac can be eids */
50       union
51       {
52         ip_prefix_t rmt_ippref;
53         u8 rmt_mac[6];
54       };
55       ip_address_t rmt_loc;
56       u32 vni;
57     };
58     u8 as_u8[40];
59   };
60 } lisp_gpe_tunnel_key_t;
61
62 typedef struct
63 {
64   /* Rewrite string. $$$$ embed vnet_rewrite header */
65   u8 * rewrite;
66
67   /* decap next index */
68   u32 decap_next_index;
69
70   /* tunnel src and dst addresses */
71   ip_address_t src;
72   ip_address_t dst;
73
74   /* FIB indices */
75   u32 encap_fib_index;          /* tunnel partner lookup here */
76   u32 decap_fib_index;          /* inner IP lookup here */
77
78   /* vnet intfc hw/sw_if_index */
79   u32 hw_if_index;
80   u32 sw_if_index;
81
82   /* action for 'negative' tunnels */
83   u8 action;
84
85   /* LISP header fields in HOST byte order */
86   u8 flags;
87   u8 ver_res;
88   u8 res;
89   u8 next_protocol;
90   u32 vni;
91 } lisp_gpe_tunnel_t;
92
93 #define foreach_lisp_gpe_ip_input_next          \
94 _(DROP, "error-drop")                           \
95 _(IP4_INPUT, "ip4-input")                       \
96 _(IP6_INPUT, "ip6-input")                       \
97 _(L2_INPUT, "l2-input")
98
99 typedef enum {
100 #define _(s,n) LISP_GPE_INPUT_NEXT_##s,
101   foreach_lisp_gpe_ip_input_next
102 #undef _
103   LISP_GPE_INPUT_N_NEXT,
104 } lisp_gpe_input_next_t;
105
106 typedef enum {
107 #define lisp_gpe_error(n,s) LISP_GPE_ERROR_##n,
108 #include <vnet/lisp-gpe/lisp_gpe_error.def>
109 #undef lisp_gpe_error
110   LISP_GPE_N_ERROR,
111 } lisp_gpe_error_t;
112
113 /* As a first step, reuse v4 fib. The goal of the typedef is to shield
114  * consumers from future updates that may result in the lisp ip4 fib diverging
115  * from ip4 fib */
116 typedef ip4_fib_t ip4_src_fib_t;
117
118 typedef struct ip6_src_fib
119 {
120   BVT(clib_bihash) ip6_lookup_table;
121
122   /* bitmap/vector of mask widths to search */
123   uword * non_empty_dst_address_length_bitmap;
124   u8 * prefix_lengths_in_search_order;
125   ip6_address_t fib_masks[129];
126   i32 dst_address_length_refcounts[129];
127
128   /* ip6 lookup table config parameters */
129   u32 lookup_table_nbuckets;
130   uword lookup_table_size;
131 } ip6_src_fib_t;
132
133 typedef struct tunnel_lookup
134 {
135   /* Lookup lisp-gpe interfaces by dp table (eg. vrf/bridge index) */
136   uword * hw_if_index_by_dp_table;
137
138   /* lookup decap tunnel termination sw_if_index by vni and vice versa */
139   uword * sw_if_index_by_vni;
140   uword * vni_by_sw_if_index;
141 } tunnel_lookup_t;
142
143 typedef struct lisp_gpe_main
144 {
145   /* pool of encap tunnel instances */
146   lisp_gpe_tunnel_t * tunnels;
147
148   /* lookup tunnel by key */
149   mhash_t lisp_gpe_tunnel_by_key;
150
151   /* Free vlib hw_if_indices */
152   u32 * free_tunnel_hw_if_indices;
153
154   u8 is_en;
155
156   /* L3 data structures
157    * ================== */
158
159   /* Pool of src fibs that are paired with dst fibs */
160   ip4_src_fib_t * ip4_src_fibs;
161   ip6_src_fib_t * ip6_src_fibs;
162
163   tunnel_lookup_t l3_ifaces;
164
165   /* Lookup lgpe_ipX_lookup_next by vrf */
166   uword * lgpe_ip4_lookup_next_index_by_table_id;
167   uword * lgpe_ip6_lookup_next_index_by_table_id;
168
169   /* next node indexes that point ip4/6 lookup to lisp gpe ip lookup */
170   u32 ip4_lookup_next_lgpe_ip4_lookup;
171   u32 ip6_lookup_next_lgpe_ip6_lookup;
172
173   /* L2 data structures
174    * ================== */
175
176   /* l2 lisp fib */
177   BVT(clib_bihash) l2_fib;
178
179   tunnel_lookup_t l2_ifaces;
180
181   /* convenience */
182   vlib_main_t * vlib_main;
183   vnet_main_t * vnet_main;
184   ip4_main_t * im4;
185   ip6_main_t * im6;
186   ip_lookup_main_t * lm4;
187   ip_lookup_main_t * lm6;
188 } lisp_gpe_main_t;
189
190 lisp_gpe_main_t lisp_gpe_main;
191
192 always_inline lisp_gpe_main_t *
193 vnet_lisp_gpe_get_main() {
194   return &lisp_gpe_main;
195 }
196
197 extern vlib_node_registration_t lgpe_ip4_lookup_node;
198 extern vlib_node_registration_t lgpe_ip6_lookup_node;
199 extern vlib_node_registration_t lisp_gpe_ip4_input_node;
200 extern vlib_node_registration_t lisp_gpe_ip6_input_node;
201
202 u8 *
203 format_lisp_gpe_header_with_length (u8 * s, va_list * args);
204
205 typedef struct
206 {
207   u8 is_add;
208   union
209   {
210     /* vrf */
211     u32 table_id;
212
213     /* bridge domain */
214     u16 bd_id;
215
216     /* generic access */
217     u32 dp_table;
218   };
219   u8 is_l2;
220   u32 vni; /* host byte order */
221 } vnet_lisp_gpe_add_del_iface_args_t;
222
223 u8
224 vnet_lisp_gpe_enable_disable_status(void);
225 int
226 vnet_lisp_gpe_add_del_iface (vnet_lisp_gpe_add_del_iface_args_t *a,
227                              u32 * hw_if_indexp);
228
229 typedef struct
230 {
231   u8 is_en;
232 } vnet_lisp_gpe_enable_disable_args_t;
233
234 clib_error_t *
235 vnet_lisp_gpe_enable_disable (vnet_lisp_gpe_enable_disable_args_t *a);
236
237 typedef struct
238 {
239   u8 is_add;
240
241   /* type of mapping */
242   u8 is_negative;
243   u8 action;
244
245   /* local and remote eids */
246   gid_address_t lcl_eid;
247   gid_address_t rmt_eid;
248
249   /* local and remote locators (underlay attachment points) */
250   ip_address_t lcl_loc;
251   ip_address_t rmt_loc;
252
253   /* FIB indices to lookup remote locator at encap and inner IP at decap */
254   u32 encap_fib_index;
255   u32 decap_fib_index;
256
257   u32 decap_next_index; /* TODO is this really needed? */
258
259   /* VNI/tenant id in HOST byte order */
260   u32 vni;
261
262   /* vrf or bd where fwd entry should be inserted */
263   union
264   {
265     u32 table_id;
266     u16 bd_id;
267
268     /* generic access */
269     u32 dp_table;
270   };
271 } vnet_lisp_gpe_add_del_fwd_entry_args_t;
272
273 int
274 vnet_lisp_gpe_add_del_fwd_entry (vnet_lisp_gpe_add_del_fwd_entry_args_t *a,
275                                  u32 * hw_if_indexp);
276
277 int
278 ip_sd_fib_add_del_route (lisp_gpe_main_t * lgm, ip_prefix_t * dst_prefix,
279                          ip_prefix_t * src_prefix, u32 table_id,
280                          ip_adjacency_t * add_adj, u8 is_add);
281 u32
282 ip_sd_fib_get_route (lisp_gpe_main_t * lgm, ip_prefix_t * dst_prefix,
283                      ip_prefix_t * src_prefix, u32 table_id);
284
285 #define foreach_lgpe_ip4_lookup_next    \
286   _(DROP, "error-drop")                 \
287   _(LISP_CP_LOOKUP, "lisp-cp-lookup")
288
289 typedef enum lgpe_ip4_lookup_next
290 {
291 #define _(sym,str) LGPE_IP4_LOOKUP_NEXT_##sym,
292   foreach_lgpe_ip4_lookup_next
293 #undef _
294   LGPE_IP4_LOOKUP_N_NEXT,
295 } lgpe_ip4_lookup_next_t;
296
297 #define foreach_lgpe_ip6_lookup_next     \
298   _(DROP, "error-drop")                 \
299   _(LISP_CP_LOOKUP, "lisp-cp-lookup")
300
301 typedef enum lgpe_ip6_lookup_next
302 {
303 #define _(sym,str) LGPE_IP6_LOOKUP_NEXT_##sym,
304   foreach_lgpe_ip6_lookup_next
305 #undef _
306   LGPE_IP6_LOOKUP_N_NEXT,
307 } lgpe_ip6_lookup_next_t;
308
309 u8 * format_vnet_lisp_gpe_status (u8 * s, va_list * args);
310
311 #define L2_FIB_DEFAULT_HASH_NUM_BUCKETS (64 * 1024)
312 #define L2_FIB_DEFAULT_HASH_MEMORY_SIZE (32<<20)
313
314 u32
315 lisp_l2_fib_lookup (lisp_gpe_main_t * lgm, u16 bd_index, u8 src_mac[8],
316                     u8 dst_mac[8]);
317
318 #endif /* included_vnet_lisp_gpe_h */