Convert lisp-gpe encap to interface tx node
[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 #define IP_UDP_HDR_LEN (word) (sizeof(udp_header_t) + sizeof(ip4_header_t))
31
32 typedef CLIB_PACKED (struct {
33   ip4_header_t ip4;             /* 20 bytes */
34   udp_header_t udp;             /* 8 bytes */
35   lisp_gpe_header_t lisp;       /* 8 bytes */
36 }) ip4_udp_lisp_gpe_header_t;
37
38 typedef struct
39 {
40   union
41   {
42     struct
43       {
44         gid_address_t eid;
45         u32 dst_loc;
46         u32 iid;
47       };
48     u8 as_u8[6];
49   };
50 } lisp_gpe_tunnel_key_t;
51
52 typedef struct
53 {
54   /* Rewrite string. $$$$ embed vnet_rewrite header */
55   u8 * rewrite;
56
57   /* decap next index */
58   u32 decap_next_index;
59
60   /* tunnel src and dst addresses */
61   ip4_address_t src;
62   ip4_address_t dst;
63
64   /* FIB indices */
65   u32 encap_fib_index;          /* tunnel partner lookup here */
66   u32 decap_fib_index;          /* inner IP lookup here */
67
68   /* vnet intfc hw/sw_if_index */
69   u32 hw_if_index;
70   u32 sw_if_index;
71
72   /* LISP header fields in HOST byte order */
73   u8 flags;
74   u8 ver_res;
75   u8 res;
76   u8 next_protocol;
77   u32 vni;
78 } lisp_gpe_tunnel_t;
79
80 #define foreach_lisp_gpe_input_next             \
81 _(DROP, "error-drop")                           \
82 _(IP4_INPUT, "ip4-input")                       \
83 _(IP6_INPUT, "ip6-input")                       \
84 _(ETHERNET_INPUT, "ethernet-input")
85
86 typedef enum {
87 #define _(s,n) LISP_GPE_INPUT_NEXT_##s,
88   foreach_lisp_gpe_input_next
89 #undef _
90   LISP_GPE_INPUT_N_NEXT,
91 } lisp_gpe_input_next_t;
92
93 typedef enum {
94 #define lisp_gpe_error(n,s) LISP_GPE_ERROR_##n,
95 #include <vnet/lisp-gpe/lisp_gpe_error.def>
96 #undef lisp_gpe_error
97   LISP_GPE_N_ERROR,
98 } lisp_gpe_error_t;
99
100 /* As a first step, reuse v4 fib. The goal of the typedef is to shield
101  * consumers from future updates that may result in the lisp ip4 fib diverging
102  * from ip4 fib */
103 typedef ip4_fib_t lisp_ip4_fib_t;
104
105 typedef struct lisp_gpe_main
106 {
107   /* Pool of src fibs that are paired with dst fibs */
108   ip4_fib_t * src_fibs;
109
110   /* vector of encap tunnel instances */
111   lisp_gpe_tunnel_t * tunnels;
112
113   /* lookup tunnel by key */
114   mhash_t lisp_gpe_tunnel_by_key;
115
116   /* lookup decap tunnel termination sw_if_index by vni and vice versa */
117   uword * tunnel_term_sw_if_index_by_vni;
118   uword * vni_by_tunnel_term_sw_if_index;
119
120   /* Free vlib hw_if_indices */
121   u32 * free_lisp_gpe_tunnel_hw_if_indices;
122
123   /* Lookup lisp-gpe interfaces by vrf */
124   uword * lisp_gpe_hw_if_index_by_table_id;
125
126   /* Lookup lgpe_ip4_lookup_next by vrf */
127   uword * lgpe_ip4_lookup_next_index_by_table_id;
128
129   /* next node indexes that points ip4 lookup to lisp gpe lookup and lisp cp */
130   u32 ip4_lookup_next_lgpe_ip4_lookup;
131
132   /* convenience */
133   vlib_main_t * vlib_main;
134   vnet_main_t * vnet_main;
135   ip_lookup_main_t * lookup_main;
136   ip4_main_t * im4;
137 } lisp_gpe_main_t;
138
139 lisp_gpe_main_t lisp_gpe_main;
140
141 extern vlib_node_registration_t lgpe_ip4_lookup_node;
142 extern vlib_node_registration_t lisp_gpe_input_node;
143
144 u8 *
145 format_lisp_gpe_tx_trace (u8 * s, va_list * args);
146 u8 *
147 format_lisp_gpe_header_with_length (u8 * s, va_list * args);
148
149 typedef struct
150 {
151   u8 is_add;
152   ip4_address_t src, dst;
153   u32 encap_fib_index;
154   u32 decap_fib_index;
155   u32 decap_next_index;
156   u8 flags;
157   u8 ver_res;
158   u8 res;
159   u8 next_protocol;
160   u32 vni; /* host byte order */
161 } vnet_lisp_gpe_add_del_tunnel_args_t;
162
163 int
164 vnet_lisp_gpe_add_del_tunnel (vnet_lisp_gpe_add_del_tunnel_args_t *a,
165                               u32 * sw_if_indexp);
166
167 typedef struct
168 {
169   u8 is_add;
170   u32 table_id; /* vrf */
171   u32 vni;      /* host byte order */
172 } vnet_lisp_gpe_add_del_iface_args_t;
173
174 void
175 vnet_lisp_gpe_add_del_iface (vnet_lisp_gpe_add_del_iface_args_t *a,
176                              u32 * hw_if_indexp);
177
178 typedef struct
179 {
180   u8 is_en;
181 } vnet_lisp_gpe_enable_disable_args_t;
182
183 clib_error_t *
184 vnet_lisp_gpe_enable_disable (vnet_lisp_gpe_enable_disable_args_t *a);
185
186 typedef enum
187 {
188   NO_ACTION,
189   FORWARD_NATIVE,
190   SEND_MAP_REQUEST,
191   DROP
192 } negative_fwd_actions_e;
193
194 typedef struct
195 {
196   u8 is_add;
197   u8 is_negative;
198   negative_fwd_actions_e action;
199   gid_address_t seid; /* TODO convert to ip4, ip6, mac ? */
200   gid_address_t deid;
201   ip_address_t slocator;
202   ip_address_t dlocator;
203   u32 encap_fib_index;
204   u32 decap_fib_index;
205   u32 decap_next_index;
206   u8 flags;
207   u8 ver_res;
208   u8 res;
209   u8 next_protocol;
210   u32 vni; /* host byte order */
211   u32 table_id;
212 } vnet_lisp_gpe_add_del_fwd_entry_args_t;
213
214 int
215 vnet_lisp_gpe_add_del_fwd_entry (vnet_lisp_gpe_add_del_fwd_entry_args_t *a,
216                                  u32 * hw_if_indexp);
217
218 u8 *
219 format_lisp_gpe_header_with_length (u8 * s, va_list * args);
220
221 #endif /* included_vnet_lisp_gpe_h */