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>
30 typedef CLIB_PACKED (struct {
31 ip4_header_t ip4; /* 20 bytes */
32 udp_header_t udp; /* 8 bytes */
33 lisp_gpe_header_t lisp; /* 8 bytes */
34 }) ip4_udp_lisp_gpe_header_t;
36 typedef CLIB_PACKED (struct {
37 ip6_header_t ip6; /* 40 bytes */
38 udp_header_t udp; /* 8 bytes */
39 lisp_gpe_header_t lisp; /* 8 bytes */
40 }) ip6_udp_lisp_gpe_header_t;
48 ip_prefix_t eid; /* within the dp only ip and mac can be eids */
54 } lisp_gpe_tunnel_key_t;
58 /* Rewrite string. $$$$ embed vnet_rewrite header */
61 /* decap next index */
64 /* tunnel src and dst addresses */
69 u32 encap_fib_index; /* tunnel partner lookup here */
70 u32 decap_fib_index; /* inner IP lookup here */
72 /* vnet intfc hw/sw_if_index */
76 /* LISP header fields in HOST byte order */
84 #define foreach_lisp_gpe_ip_input_next \
85 _(DROP, "error-drop") \
86 _(IP4_INPUT, "ip4-input") \
87 _(IP6_INPUT, "ip6-input") \
88 _(ETHERNET_INPUT, "ethernet-input")
91 #define _(s,n) LISP_GPE_INPUT_NEXT_##s,
92 foreach_lisp_gpe_ip_input_next
94 LISP_GPE_INPUT_N_NEXT,
95 } lisp_gpe_input_next_t;
98 #define lisp_gpe_error(n,s) LISP_GPE_ERROR_##n,
99 #include <vnet/lisp-gpe/lisp_gpe_error.def>
100 #undef lisp_gpe_error
104 /* As a first step, reuse v4 fib. The goal of the typedef is to shield
105 * consumers from future updates that may result in the lisp ip4 fib diverging
107 typedef ip4_fib_t ip4_src_fib_t;
109 typedef struct ip6_src_fib
111 BVT(clib_bihash) ip6_lookup_table;
113 /* bitmap/vector of mask widths to search */
114 uword * non_empty_dst_address_length_bitmap;
115 u8 * prefix_lengths_in_search_order;
116 ip6_address_t fib_masks[129];
117 i32 dst_address_length_refcounts[129];
119 /* ip6 lookup table config parameters */
120 u32 lookup_table_nbuckets;
121 uword lookup_table_size;
124 typedef struct lisp_gpe_main
126 /* Pool of src fibs that are paired with dst fibs */
127 ip4_src_fib_t * ip4_src_fibs;
128 ip6_src_fib_t * ip6_src_fibs;
130 /* vector of encap tunnel instances */
131 lisp_gpe_tunnel_t * tunnels;
133 /* lookup tunnel by key */
134 mhash_t lisp_gpe_tunnel_by_key;
136 /* lookup decap tunnel termination sw_if_index by vni and vice versa */
137 uword * tunnel_term_sw_if_index_by_vni;
138 uword * vni_by_tunnel_term_sw_if_index;
140 /* Free vlib hw_if_indices */
141 u32 * free_lisp_gpe_tunnel_hw_if_indices;
143 /* Lookup lisp-gpe interfaces by vrf */
144 uword * lisp_gpe_hw_if_index_by_table_id;
146 /* Lookup lgpe_ipX_lookup_next by vrf */
147 uword * lgpe_ip4_lookup_next_index_by_table_id;
148 uword * lgpe_ip6_lookup_next_index_by_table_id;
150 /* next node indexes that point ip4/6 lookup to lisp gpe ip lookup */
151 u32 ip4_lookup_next_lgpe_ip4_lookup;
152 u32 ip6_lookup_next_lgpe_ip6_lookup;
155 vlib_main_t * vlib_main;
156 vnet_main_t * vnet_main;
159 ip_lookup_main_t * lm4;
160 ip_lookup_main_t * lm6;
164 lisp_gpe_main_t lisp_gpe_main;
166 extern vlib_node_registration_t lgpe_ip4_lookup_node;
167 extern vlib_node_registration_t lgpe_ip6_lookup_node;
168 extern vlib_node_registration_t lisp_gpe_ip4_input_node;
169 extern vlib_node_registration_t lisp_gpe_ip6_input_node;
172 format_lisp_gpe_header_with_length (u8 * s, va_list * args);
177 u32 table_id; /* vrf */
178 u32 vni; /* host byte order */
179 } vnet_lisp_gpe_add_del_iface_args_t;
182 vnet_lisp_gpe_enable_disable_status(void);
184 vnet_lisp_gpe_add_del_iface (vnet_lisp_gpe_add_del_iface_args_t *a,
190 } vnet_lisp_gpe_enable_disable_args_t;
193 vnet_lisp_gpe_enable_disable (vnet_lisp_gpe_enable_disable_args_t *a);
201 } negative_fwd_actions_e;
207 /* type of mapping */
209 negative_fwd_actions_e action;
211 /* local and remote eids */
212 gid_address_t seid; /* TODO convert to ip4, ip6, mac ? */
215 /* local and remote locators (underlay attachment points) */
216 ip_address_t slocator;
217 ip_address_t dlocator;
219 /* FIB indices to lookup remote locator at encap and inner IP at decap */
223 u32 decap_next_index; /* TODO is this really needed? */
225 /* VNI/tenant id in HOST byte order */
228 /* vrf where fwd entry should be inserted */
230 } vnet_lisp_gpe_add_del_fwd_entry_args_t;
233 vnet_lisp_gpe_add_del_fwd_entry (vnet_lisp_gpe_add_del_fwd_entry_args_t *a,
237 ip_sd_fib_add_del_route (lisp_gpe_main_t * lgm, ip_prefix_t * dst_prefix,
238 ip_prefix_t * src_prefix, u32 table_id,
239 ip_adjacency_t * add_adj, u8 is_add);
241 ip_sd_fib_get_route (lisp_gpe_main_t * lgm, ip_prefix_t * dst_prefix,
242 ip_prefix_t * src_prefix, u32 table_id);
244 #define foreach_lgpe_ip4_lookup_next \
245 _(DROP, "error-drop") \
246 _(LISP_CP_LOOKUP, "lisp-cp-lookup")
248 typedef enum lgpe_ip4_lookup_next
250 #define _(sym,str) LGPE_IP4_LOOKUP_NEXT_##sym,
251 foreach_lgpe_ip4_lookup_next
253 LGPE_IP4_LOOKUP_N_NEXT,
254 } lgpe_ip4_lookup_next_t;
256 #define foreach_lgpe_ip6_lookup_next \
257 _(DROP, "error-drop") \
258 _(LISP_CP_LOOKUP, "lisp-cp-lookup")
260 typedef enum lgpe_ip6_lookup_next
262 #define _(sym,str) LGPE_IP6_LOOKUP_NEXT_##sym,
263 foreach_lgpe_ip6_lookup_next
265 LGPE_IP6_LOOKUP_N_NEXT,
266 } lgpe_ip6_lookup_next_t;
268 u8 * format_vnet_lisp_gpe_status (u8 * s, va_list * args);
270 #endif /* included_vnet_lisp_gpe_h */