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:
7 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 #ifndef included_vnet_lisp_gpe_h
17 #define included_vnet_lisp_gpe_h
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>
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;
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;
49 /* within the dp only ip and mac can be eids */
52 ip_prefix_t rmt_ippref;
60 } lisp_gpe_tunnel_key_t;
64 /* Rewrite string. $$$$ embed vnet_rewrite header */
67 /* decap next index */
70 /* tunnel src and dst addresses */
75 u32 encap_fib_index; /* tunnel partner lookup here */
76 u32 decap_fib_index; /* inner IP lookup here */
78 /* vnet intfc hw/sw_if_index */
82 /* action for 'negative' tunnels */
85 /* LISP header fields in HOST byte order */
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")
100 #define _(s,n) LISP_GPE_INPUT_NEXT_##s,
101 foreach_lisp_gpe_ip_input_next
103 LISP_GPE_INPUT_N_NEXT,
104 } lisp_gpe_input_next_t;
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
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
116 typedef ip4_fib_t ip4_src_fib_t;
118 typedef struct ip6_src_fib
120 BVT(clib_bihash) ip6_lookup_table;
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];
128 /* ip6 lookup table config parameters */
129 u32 lookup_table_nbuckets;
130 uword lookup_table_size;
133 typedef struct tunnel_lookup
135 /* Lookup lisp-gpe interfaces by dp table (eg. vrf/bridge index) */
136 uword * hw_if_index_by_dp_table;
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;
143 typedef struct lisp_gpe_main
145 /* pool of encap tunnel instances */
146 lisp_gpe_tunnel_t * tunnels;
148 /* lookup tunnel by key */
149 mhash_t lisp_gpe_tunnel_by_key;
151 /* Free vlib hw_if_indices */
152 u32 * free_tunnel_hw_if_indices;
156 /* L3 data structures
157 * ================== */
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;
163 tunnel_lookup_t l3_ifaces;
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;
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;
173 /* L2 data structures
174 * ================== */
177 BVT(clib_bihash) l2_fib;
179 tunnel_lookup_t l2_ifaces;
182 vlib_main_t * vlib_main;
183 vnet_main_t * vnet_main;
186 ip_lookup_main_t * lm4;
187 ip_lookup_main_t * lm6;
190 lisp_gpe_main_t lisp_gpe_main;
192 always_inline lisp_gpe_main_t *
193 vnet_lisp_gpe_get_main() {
194 return &lisp_gpe_main;
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;
203 format_lisp_gpe_header_with_length (u8 * s, va_list * args);
220 u32 vni; /* host byte order */
221 } vnet_lisp_gpe_add_del_iface_args_t;
224 vnet_lisp_gpe_enable_disable_status(void);
226 vnet_lisp_gpe_add_del_iface (vnet_lisp_gpe_add_del_iface_args_t *a,
232 } vnet_lisp_gpe_enable_disable_args_t;
235 vnet_lisp_gpe_enable_disable (vnet_lisp_gpe_enable_disable_args_t *a);
241 /* type of mapping */
245 /* local and remote eids */
246 gid_address_t lcl_eid;
247 gid_address_t rmt_eid;
249 /* local and remote locators (underlay attachment points) */
250 ip_address_t lcl_loc;
251 ip_address_t rmt_loc;
253 /* FIB indices to lookup remote locator at encap and inner IP at decap */
257 u32 decap_next_index; /* TODO is this really needed? */
259 /* VNI/tenant id in HOST byte order */
262 /* vrf or bd where fwd entry should be inserted */
268 } vnet_lisp_gpe_add_del_fwd_entry_args_t;
271 vnet_lisp_gpe_add_del_fwd_entry (vnet_lisp_gpe_add_del_fwd_entry_args_t *a,
275 ip_sd_fib_add_del_route (lisp_gpe_main_t * lgm, ip_prefix_t * dst_prefix,
276 ip_prefix_t * src_prefix, u32 table_id,
277 ip_adjacency_t * add_adj, u8 is_add);
279 ip_sd_fib_get_route (lisp_gpe_main_t * lgm, ip_prefix_t * dst_prefix,
280 ip_prefix_t * src_prefix, u32 table_id);
282 #define foreach_lgpe_ip4_lookup_next \
283 _(DROP, "error-drop") \
284 _(LISP_CP_LOOKUP, "lisp-cp-lookup")
286 typedef enum lgpe_ip4_lookup_next
288 #define _(sym,str) LGPE_IP4_LOOKUP_NEXT_##sym,
289 foreach_lgpe_ip4_lookup_next
291 LGPE_IP4_LOOKUP_N_NEXT,
292 } lgpe_ip4_lookup_next_t;
294 #define foreach_lgpe_ip6_lookup_next \
295 _(DROP, "error-drop") \
296 _(LISP_CP_LOOKUP, "lisp-cp-lookup")
298 typedef enum lgpe_ip6_lookup_next
300 #define _(sym,str) LGPE_IP6_LOOKUP_NEXT_##sym,
301 foreach_lgpe_ip6_lookup_next
303 LGPE_IP6_LOOKUP_N_NEXT,
304 } lgpe_ip6_lookup_next_t;
306 u8 * format_vnet_lisp_gpe_status (u8 * s, va_list * args);
308 #define L2_FIB_DEFAULT_HASH_NUM_BUCKETS (64 * 1024)
309 #define L2_FIB_DEFAULT_HASH_MEMORY_SIZE (32<<20)
312 lisp_l2_fib_lookup (lisp_gpe_main_t * lgm, u16 bd_index, u8 src_mac[8],
315 #endif /* included_vnet_lisp_gpe_h */