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