LISP: don't show PITR generated mapping in dump call
[vpp.git] / src / vnet / lisp-cp / lisp_types.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 VNET_LISP_GPE_LISP_TYPES_H_
17 #define VNET_LISP_GPE_LISP_TYPES_H_
18
19 #include <vnet/ip/ip.h>
20 #include <vnet/lisp-cp/lisp_cp_messages.h>
21
22 #define SHA1_AUTH_DATA_LEN                  20
23 #define SHA256_AUTH_DATA_LEN                32
24
25 typedef enum
26 {
27   HMAC_NO_KEY = 0,
28   HMAC_SHA_1_96,
29   HMAC_SHA_256_128
30 } lisp_key_type_t;
31
32 uword unformat_hmac_key_id (unformat_input_t * input, va_list * args);
33 u8 *format_hmac_key_id (u8 * s, va_list * args);
34
35 typedef enum
36 {
37   IP4,
38   IP6
39 } ip_address_type_t;
40
41 /* *INDENT-OFF* */
42 typedef CLIB_PACKED(struct ip_address
43 {
44   union
45   {
46     ip4_address_t v4;
47     ip6_address_t v6;
48   } ip;
49   u8 version;
50 }) ip_address_t;
51 /* *INDENT-ON* */
52
53 #define ip_addr_addr(_a) (_a)->ip
54 #define ip_addr_v4(_a) (_a)->ip.v4
55 #define ip_addr_v6(_a) (_a)->ip.v6
56 #define ip_addr_version(_a) (_a)->version
57
58 int ip_address_cmp (const ip_address_t * ip1, const ip_address_t * ip2);
59 void ip_address_copy (ip_address_t * dst, const ip_address_t * src);
60 void ip_address_copy_addr (void *dst, const ip_address_t * src);
61 void ip_address_set (ip_address_t * dst, const void *src, u8 version);
62
63 /* *INDENT-OFF* */
64 typedef CLIB_PACKED(struct ip_prefix
65 {
66   ip_address_t addr;
67   u8 len;
68 }) ip_prefix_t;
69 /* *INDENT-ON* */
70
71 #define ip_prefix_addr(_a) (_a)->addr
72 #define ip_prefix_version(_a) ip_addr_version(&ip_prefix_addr(_a))
73 #define ip_prefix_len(_a) (_a)->len
74 #define ip_prefix_v4(_a) ip_addr_v4(&ip_prefix_addr(_a))
75 #define ip_prefix_v6(_a) ip_addr_v6(&ip_prefix_addr(_a))
76
77 void ip_prefix_normalize (ip_prefix_t * a);
78
79 extern void ip_address_to_fib_prefix (const ip_address_t * addr,
80                                       fib_prefix_t * prefix);
81 extern void ip_prefix_to_fib_prefix (const ip_prefix_t * ipp,
82                                      fib_prefix_t * fibp);
83
84 typedef enum
85 {
86   /* NOTE: ip addresses are left out on purpose. Use max masked ip-prefixes
87    * instead */
88   GID_ADDR_IP_PREFIX,
89   GID_ADDR_LCAF,
90   GID_ADDR_MAC,
91   GID_ADDR_SRC_DST,
92   GID_ADDR_NSH,
93   GID_ADDR_NO_ADDRESS,
94   GID_ADDR_TYPES
95 } gid_address_type_t;
96
97 typedef enum
98 {
99   /* make sure that values corresponds with RFC */
100   LCAF_NULL_BODY = 0,
101   LCAF_AFI_LIST_TYPE,
102   LCAF_INSTANCE_ID,
103   LCAF_SOURCE_DEST = 12,
104   LCAF_TYPES
105 } lcaf_type_t;
106
107 typedef enum fid_addr_type_t_
108 {
109   FID_ADDR_IP_PREF,
110   FID_ADDR_MAC,
111   FID_ADDR_NSH
112 } __attribute__ ((packed)) fid_addr_type_t;
113
114 /* flat address type */
115 typedef struct
116 {
117   union
118   {
119     ip_prefix_t ippref;
120     u8 mac[6];
121     u32 nsh;
122   };
123   fid_addr_type_t type;
124 } fid_address_t;
125
126 typedef fid_address_t dp_address_t;
127
128 #define fid_addr_ippref(_a) (_a)->ippref
129 #define fid_addr_mac(_a) (_a)->mac
130 #define fid_addr_nsh(_a) (_a)->nsh
131 #define fid_addr_type(_a) (_a)->type
132 u8 *format_fid_address (u8 * s, va_list * args);
133
134 typedef struct
135 {
136   fid_address_t src;
137   fid_address_t dst;
138 } source_dest_t;
139
140 #define sd_dst(_a) (_a)->dst
141 #define sd_src(_a) (_a)->src
142 #define sd_src_ippref(_a) fid_addr_ippref(&sd_src(_a))
143 #define sd_dst_ippref(_a) fid_addr_ippref(&sd_dst(_a))
144 #define sd_src_mac(_a) fid_addr_mac(&sd_src(_a))
145 #define sd_dst_mac(_a) fid_addr_mac(&sd_dst(_a))
146 #define sd_src_type(_a) fid_addr_type(&sd_src(_a))
147 #define sd_dst_type(_a) fid_addr_type(&sd_dst(_a))
148
149 typedef struct
150 {
151   u8 vni_mask_len;
152   u32 vni;
153   struct _gid_address_t *gid_addr;
154 } vni_t;
155
156 #define vni_vni(_a) (_a)->vni
157 #define vni_mask_len(_a) (_a)->vni_mask_len
158 #define vni_gid(_a) (_a)->gid_addr
159
160 typedef struct
161 {
162   u32 spi;
163   u8 si;
164 } nsh_t;
165
166 typedef struct
167 {
168   /* the union needs to be at the beginning! */
169   union
170   {
171     source_dest_t sd;
172     vni_t uni;
173   };
174   u8 type;
175 } lcaf_t;
176
177 #define lcaf_type(_a) (_a)->type
178 #define lcaf_vni(_a) vni_vni(& (_a)->uni)
179 #define lcaf_vni_len(_a) vni_mask_len(& (_a)->uni)
180
181 /* might want to expand this in the future :) */
182 typedef struct _gid_address_t
183 {
184   union
185   {
186     ip_prefix_t ippref;
187     lcaf_t lcaf;
188     u8 mac[6];
189     source_dest_t sd;
190     nsh_t nsh;
191   };
192   u8 type;
193   u32 vni;
194   u8 vni_mask;
195 } gid_address_t;
196
197 u8 *format_ip_address (u8 * s, va_list * args);
198 uword unformat_ip_address (unformat_input_t * input, va_list * args);
199 u8 *format_ip_prefix (u8 * s, va_list * args);
200 uword unformat_ip_prefix (unformat_input_t * input, va_list * args);
201 u8 *format_mac_address (u8 * s, va_list * args);
202 uword unformat_mac_address (unformat_input_t * input, va_list * args);
203
204 u16 ip4_address_size_to_put ();
205 u16 ip6_address_size_to_put ();
206 u32 ip4_address_put (u8 * b, ip4_address_t * a);
207 u32 ip6_address_put (u8 * b, ip6_address_t * a);
208
209 u16 ip_address_size_to_write (ip_address_t * a);
210 u16 ip_address_iana_afi (ip_address_t * a);
211 u8 ip_address_max_len (u8 ver);
212 u32 ip_address_put (u8 * b, ip_address_t * a);
213 void ip_address_to_46 (const ip_address_t * addr,
214                        ip46_address_t * a, fib_protocol_t * proto);
215
216 /* LISP AFI codes  */
217 typedef enum
218 {
219   LISP_AFI_NO_ADDR,
220   LISP_AFI_IP,
221   LISP_AFI_IP6,
222   LISP_AFI_LCAF = 16387,
223   LISP_AFI_MAC = 16389
224 } lisp_afi_e;
225
226 u8 *format_gid_address (u8 * s, va_list * args);
227 uword unformat_gid_address (unformat_input_t * input, va_list * args);
228 int gid_address_cmp (gid_address_t * a1, gid_address_t * a2);
229 void gid_address_free (gid_address_t * a);
230
231 u16 gid_address_size_to_put (gid_address_t * a);
232 u16 gid_address_put (u8 * b, gid_address_t * gid);
233 u8 gid_address_len (gid_address_t * a);
234 void *gid_address_cast (gid_address_t * gid, gid_address_type_t type);
235 void gid_address_copy (gid_address_t * dst, gid_address_t * src);
236 u32 gid_address_parse (u8 * offset, gid_address_t * a);
237 void gid_address_ip_set (gid_address_t * dst, void *src, u8 version);
238
239 #define gid_address_type(_a) (_a)->type
240 #define gid_address_ippref(_a) (_a)->ippref
241 #define gid_address_ippref_len(_a) (_a)->ippref.len
242 #define gid_address_ip(_a) ip_prefix_addr(&gid_address_ippref(_a))
243 #define gid_address_ip_version(_a) ip_addr_version(&gid_address_ip(_a))
244 #define gid_address_lcaf(_a) (_a)->lcaf
245 #define gid_address_mac(_a) (_a)->mac
246 #define gid_address_nsh(_a) (_a)->nsh
247 #define gid_address_vni(_a) (_a)->vni
248 #define gid_address_vni_mask(_a) (_a)->vni_mask
249 #define gid_address_sd_dst_ippref(_a) sd_dst_ippref(&(_a)->sd)
250 #define gid_address_sd_src_ippref(_a) sd_src_ippref(&(_a)->sd)
251 #define gid_address_sd_dst_mac(_a) sd_dst_mac(&(_a)->sd)
252 #define gid_address_sd_src_mac(_a) sd_src_mac(&(_a)->sd)
253 #define gid_address_sd(_a) (_a)->sd
254 #define gid_address_sd_src(_a) sd_src(&gid_address_sd(_a))
255 #define gid_address_sd_dst(_a) sd_dst(&gid_address_sd(_a))
256 #define gid_address_sd_src_type(_a) sd_src_type(&gid_address_sd(_a))
257 #define gid_address_sd_dst_type(_a) sd_dst_type(&gid_address_sd(_a))
258
259 /* 'sub'address functions */
260 #define foreach_gid_address_type_fcns  \
261   _(ip_prefix)                    \
262   _(lcaf)                         \
263   _(mac)                          \
264   _(nsh)                          \
265   _(sd)
266
267 /* *INDENT-OFF* */
268 #define _(_n)                                 \
269 u16    _n ## _size_to_write (void * pref);    \
270 u16    _n ## _write (u8 * p, void * pref);    \
271 u8     _n ## _length (void *a);               \
272 void * _n ## _cast (gid_address_t * a);       \
273 void   _n ## _copy (void * dst , void * src);
274
275 foreach_gid_address_type_fcns
276 #undef _
277 /* *INDENT-ON* */
278
279 always_inline u64
280 mac_to_u64 (u8 * m)
281 {
282   return (*((u64 *) m) & 0xffffffffffff);
283 }
284
285 typedef struct
286 {
287   /* mark locator as local as opposed to remote */
288   u8 local;
289   u8 state;
290   union
291   {
292     u32 sw_if_index;
293     gid_address_t address;
294   };
295   u8 priority;
296   u8 weight;
297   u8 mpriority;
298   u8 mweight;
299   u8 probed;
300 } locator_t;
301
302 u32 locator_parse (void *ptr, locator_t * loc);
303 void locator_copy (locator_t * dst, locator_t * src);
304 u32 locator_cmp (locator_t * l1, locator_t * l2);
305 void locator_free (locator_t * l);
306
307 typedef struct
308 {
309   /* locator-set name */
310   u8 *name;
311
312   /* vector of locator indices */
313   u32 *locator_indices;
314   u8 local;
315 } locator_set_t;
316
317 typedef struct
318 {
319   gid_address_t eid;
320
321   /* index of local locator set */
322   union
323   {
324     u32 locator_set_index;
325     locator_t *locators;        /* used for map register message */
326   };
327
328   u32 ttl;
329   u8 action;
330
331   u8 authoritative:1;
332   u8 local:1;
333   /* valid only for remote mappings */
334   u8 is_static:1;
335   u8 pitr_set:1;
336   u8 rsvd:4;
337
338
339   u8 *key;
340   lisp_key_type_t key_id;
341   u8 timer_set;
342 } mapping_t;
343
344 uword
345 unformat_negative_mapping_action (unformat_input_t * input, va_list * args);
346 u8 *format_negative_mapping_action (u8 *, va_list * args);
347
348 typedef struct locator_pair
349 {
350   /* local and remote locators (underlay attachment points) */
351   ip_address_t lcl_loc;
352   ip_address_t rmt_loc;
353
354   u8 priority;
355   u8 weight;
356 } locator_pair_t;
357
358 void
359 build_src_dst (gid_address_t * sd, gid_address_t * src, gid_address_t * dst);
360
361 void gid_address_from_ip (gid_address_t * g, ip_address_t * ip);
362
363 #endif /* VNET_LISP_GPE_LISP_TYPES_H_ */
364
365 /*
366  * fd.io coding-style-patch-verification: ON
367  *
368  * Local Variables:
369  * eval: (c-set-style "gnu")
370  * End:
371  */