FD.io VPP  v17.07.01-10-g3be13f0
Vector Packet Processing
lisp_types.h
Go to the documentation of this file.
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>
21 
22 #define SHA1_AUTH_DATA_LEN 20
23 #define SHA256_AUTH_DATA_LEN 32
24 
25 typedef enum
26 {
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,
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 */
97 
98 typedef enum
99 {
100  /* make sure that values corresponds with RFC */
105  LCAF_NSH = 17,
107 } lcaf_type_t;
108 
109 typedef enum fid_addr_type_t_
110 {
114 } __attribute__ ((packed)) fid_addr_type_t;
115 
116 /* flat address type */
117 typedef struct
118 {
119  union
120  {
121  ip_prefix_t ippref;
122  u8 mac[6];
124  };
125  fid_addr_type_t type;
126 } fid_address_t;
127 
129 
130 #define fid_addr_ippref(_a) (_a)->ippref
131 #define fid_addr_prefix_length(_a) ip_prefix_len(&fid_addr_ippref(_a))
132 #define fid_addr_ip_version(_a) ip_prefix_version(&fid_addr_ippref(_a))
133 #define fid_addr_mac(_a) (_a)->mac
134 #define fid_addr_nsh(_a) (_a)->nsh
135 #define fid_addr_type(_a) (_a)->type
136 u8 *format_fid_address (u8 * s, va_list * args);
137 
138 typedef struct
139 {
142 } source_dest_t;
143 
144 #define sd_dst(_a) (_a)->dst
145 #define sd_src(_a) (_a)->src
146 #define sd_src_ippref(_a) fid_addr_ippref(&sd_src(_a))
147 #define sd_dst_ippref(_a) fid_addr_ippref(&sd_dst(_a))
148 #define sd_src_mac(_a) fid_addr_mac(&sd_src(_a))
149 #define sd_dst_mac(_a) fid_addr_mac(&sd_dst(_a))
150 #define sd_src_type(_a) fid_addr_type(&sd_src(_a))
151 #define sd_dst_type(_a) fid_addr_type(&sd_dst(_a))
152 
153 typedef struct
154 {
157  struct _gid_address_t *gid_addr;
158 } vni_t;
159 
160 #define vni_vni(_a) (_a)->vni
161 #define vni_mask_len(_a) (_a)->vni_mask_len
162 #define vni_gid(_a) (_a)->gid_addr
163 
164 typedef struct
165 {
168 } nsh_t;
169 
170 #define nsh_spi(_a) (_a)->spi
171 #define nsh_si(_a) (_a)->si
172 
173 typedef struct
174 {
177 } lcaf_arp_t;
178 
179 #define lcaf_arp_ip4(_a) (_a)->addr
180 #define lcaf_arp_bd(_a) (_a)->bd
181 
182 typedef struct
183 {
184  /* the union needs to be at the beginning! */
185  union
186  {
190  };
192 } lcaf_t;
193 
194 #define lcaf_type(_a) (_a)->type
195 #define lcaf_vni(_a) vni_vni(& (_a)->uni)
196 #define lcaf_vni_len(_a) vni_mask_len(& (_a)->uni)
197 
198 /* might want to expand this in the future :) */
199 typedef struct _gid_address_t
200 {
201  union
202  {
203  ip_prefix_t ippref;
204  lcaf_t lcaf;
205  u8 mac[6];
206  source_dest_t sd;
207  lcaf_arp_t arp;
208  nsh_t nsh;
209  };
210  u8 type;
211  u32 vni;
212  u8 vni_mask;
213 } gid_address_t;
214 
215 u8 *format_ip_address (u8 * s, va_list * args);
216 uword unformat_ip_address (unformat_input_t * input, va_list * args);
217 u8 *format_ip_prefix (u8 * s, va_list * args);
218 uword unformat_ip_prefix (unformat_input_t * input, va_list * args);
219 u8 *format_mac_address (u8 * s, va_list * args);
220 uword unformat_mac_address (unformat_input_t * input, va_list * args);
221 
226 
227 u16 ip_address_size_to_write (ip_address_t * a);
228 u16 ip_address_iana_afi (ip_address_t * a);
229 u8 ip_address_max_len (u8 ver);
230 u32 ip_address_put (u8 * b, ip_address_t * a);
231 void ip_address_to_46 (const ip_address_t * addr,
232  ip46_address_t * a, fib_protocol_t * proto);
233 
234 /* LISP AFI codes */
235 typedef enum
236 {
240  LISP_AFI_LCAF = 16387,
241  LISP_AFI_MAC = 16389
242 } lisp_afi_e;
243 
244 u8 *format_gid_address (u8 * s, va_list * args);
245 uword unformat_gid_address (unformat_input_t * input, va_list * args);
248 
250 u16 gid_address_put (u8 * b, gid_address_t * gid);
252 void *gid_address_cast (gid_address_t * gid, gid_address_type_t type);
253 void gid_address_copy (gid_address_t * dst, gid_address_t * src);
255 void gid_address_ip_set (gid_address_t * dst, void *src, u8 version);
256 
257 #define gid_address_type(_a) (_a)->type
258 #define gid_address_ippref(_a) (_a)->ippref
259 #define gid_address_ippref_len(_a) (_a)->ippref.len
260 #define gid_address_ip(_a) ip_prefix_addr(&gid_address_ippref(_a))
261 #define gid_address_ip_version(_a) ip_addr_version(&gid_address_ip(_a))
262 #define gid_address_lcaf(_a) (_a)->lcaf
263 #define gid_address_mac(_a) (_a)->mac
264 #define gid_address_nsh(_a) (_a)->nsh
265 #define gid_address_nsh_spi(_a) nsh_spi(&gid_address_nsh(_a))
266 #define gid_address_nsh_si(_a) nsh_si(&gid_address_nsh(_a))
267 #define gid_address_vni(_a) (_a)->vni
268 #define gid_address_vni_mask(_a) (_a)->vni_mask
269 #define gid_address_sd_dst_ippref(_a) sd_dst_ippref(&(_a)->sd)
270 #define gid_address_sd_src_ippref(_a) sd_src_ippref(&(_a)->sd)
271 #define gid_address_sd_dst_mac(_a) sd_dst_mac(&(_a)->sd)
272 #define gid_address_sd_src_mac(_a) sd_src_mac(&(_a)->sd)
273 #define gid_address_sd(_a) (_a)->sd
274 #define gid_address_sd_src(_a) sd_src(&gid_address_sd(_a))
275 #define gid_address_sd_dst(_a) sd_dst(&gid_address_sd(_a))
276 #define gid_address_sd_src_type(_a) sd_src_type(&gid_address_sd(_a))
277 #define gid_address_sd_dst_type(_a) sd_dst_type(&gid_address_sd(_a))
278 #define gid_address_arp(_a) (_a)->arp
279 #define gid_address_arp_ip4(_a) lcaf_arp_ip4(&gid_address_arp (_a))
280 #define gid_address_arp_bd(_a) lcaf_arp_bd(&gid_address_arp (_a))
281 
282 /* 'sub'address functions */
283 #define foreach_gid_address_type_fcns \
284  _(no_addr) \
285  _(ip_prefix) \
286  _(lcaf) \
287  _(mac) \
288  _(nsh) \
289  _(sd)
290 
291 /* *INDENT-OFF* */
292 #define _(_n) \
293 u16 _n ## _size_to_write (void * pref); \
294 u16 _n ## _write (u8 * p, void * pref); \
295 u8 _n ## _length (void *a); \
296 void * _n ## _cast (gid_address_t * a); \
297 void _n ## _copy (void * dst , void * src);
298 
300 #undef _
301 /* *INDENT-ON* */
302 
305 {
306  return (*((u64 *) m) & 0xffffffffffff);
307 }
308 
309 typedef struct
310 {
311  /* mark locator as local as opposed to remote */
314  union
315  {
318  };
324 } locator_t;
325 
326 u32 locator_parse (void *ptr, locator_t * loc);
327 void locator_copy (locator_t * dst, locator_t * src);
328 u32 locator_cmp (locator_t * l1, locator_t * l2);
329 void locator_free (locator_t * l);
330 
331 typedef struct
332 {
333  /* locator-set name */
335 
336  /* vector of locator indices */
339 } locator_set_t;
340 
341 typedef struct
342 {
344 
345  /* index of local locator set */
346  union
347  {
349  locator_t *locators; /* used for map register message */
350  };
351 
354 
355  u8 authoritative:1;
356  u8 local:1;
357  /* valid only for remote mappings */
358  u8 is_static:1;
359  u8 pitr_set:1;
360  u8 nsh_set:1;
361  u8 rsvd:3;
362 
363 
364  u8 *key;
365  lisp_key_type_t key_id;
367 } mapping_t;
368 
369 uword
370 unformat_negative_mapping_action (unformat_input_t * input, va_list * args);
371 u8 *format_negative_mapping_action (u8 *, va_list * args);
372 
373 typedef struct locator_pair
374 {
375  /* local and remote locators (underlay attachment points) */
376  ip_address_t lcl_loc;
377  ip_address_t rmt_loc;
378 
382 
383 void
385 
386 void gid_address_from_ip (gid_address_t * g, ip_address_t * ip);
387 void gid_to_dp_address (gid_address_t * g, dp_address_t * d);
388 
389 #endif /* VNET_LISP_GPE_LISP_TYPES_H_ */
390 
391 /*
392  * fd.io coding-style-patch-verification: ON
393  *
394  * Local Variables:
395  * eval: (c-set-style "gnu")
396  * End:
397  */
u8 vni_mask_len
Definition: lisp_types.h:155
u16 ip_address_iana_afi(ip_address_t *a)
Definition: lisp_types.c:535
void locator_free(locator_t *l)
Definition: lisp_types.c:1728
u8 timer_set
Definition: lisp_types.h:366
fid_address_t dst
Definition: lisp_types.h:141
void gid_address_copy(gid_address_t *dst, gid_address_t *src)
Definition: lisp_types.c:1487
typedef CLIB_PACKED(struct ip_address{union{ip4_address_t v4;ip6_address_t v6;}ip;u8 version;}) ip_address_t
void ip_address_copy(ip_address_t *dst, const ip_address_t *src)
Definition: lisp_types.c:878
void build_src_dst(gid_address_t *sd, gid_address_t *src, gid_address_t *dst)
Definition: lisp_types.c:1735
uword unformat_mac_address(unformat_input_t *input, va_list *args)
Definition: lisp_types.c:207
gid_address_type_t
Definition: lisp_types.h:84
lcaf_type_t
Definition: lisp_types.h:98
uword unformat_hmac_key_id(unformat_input_t *input, va_list *args)
Definition: lisp_types.c:317
vni_t uni
Definition: lisp_types.h:189
u16 gid_address_put(u8 *b, gid_address_t *gid)
Definition: lisp_types.c:1456
struct locator_pair locator_pair_t
void gid_to_dp_address(gid_address_t *g, dp_address_t *d)
Definition: lisp_types.c:598
u8 mpriority
Definition: lisp_types.h:321
u32 vni
Definition: lisp_types.h:156
u16 ip6_address_size_to_put()
Definition: lisp_types.c:554
uword unformat_ip_address(unformat_input_t *input, va_list *args)
Definition: lisp_types.c:164
enum fid_addr_type_t_ fid_addr_type_t
u16 ip_address_size_to_write(ip_address_t *a)
Definition: lisp_types.c:529
u8 * format_negative_mapping_action(u8 *, va_list *args)
Definition: lisp_types.c:430
enum fib_protocol_t_ fib_protocol_t
Protocol Type.
ip_prefix_t ippref
Definition: lisp_types.h:121
u32 locator_parse(void *ptr, locator_t *loc)
Definition: lisp_types.c:1676
u32 spi
Definition: lisp_types.h:166
#define always_inline
Definition: clib.h:84
u32 gid_address_parse(u8 *offset, gid_address_t *a)
Definition: lisp_types.c:1507
uword unformat_negative_mapping_action(unformat_input_t *input, va_list *args)
Definition: lisp_types.c:383
u8 * key
Definition: lisp_types.h:364
Aggregrate type for a prefix.
Definition: fib_types.h:160
static foreach_gid_address_type_fcns u64 mac_to_u64(u8 *m)
Definition: lisp_types.h:304
unsigned long u64
Definition: types.h:89
u8 type
Definition: lisp_types.h:191
struct _gid_address_t * gid_addr
Definition: lisp_types.h:157
u8 gid_address_len(gid_address_t *a)
Definition: lisp_types.c:1442
struct _unformat_input_t unformat_input_t
ip_address_t lcl_loc
Definition: lisp_types.h:376
lisp_afi_e
Definition: lisp_types.h:235
void ip_address_to_fib_prefix(const ip_address_t *addr, fib_prefix_t *prefix)
convert from a LISP address to a FIB prefix
Definition: control.c:141
uword unformat_gid_address(unformat_input_t *input, va_list *args)
Definition: lisp_types.c:342
u32 ip4_address_put(u8 *b, ip4_address_t *a)
Definition: lisp_types.c:561
u8 * format_ip_prefix(u8 *s, va_list *args)
Definition: lisp_types.c:179
void ip_address_copy_addr(void *dst, const ip_address_t *src)
Definition: lisp_types.c:894
u32 sw_if_index
Definition: lisp_types.h:316
u32 ip_address_put(u8 *b, ip_address_t *a)
Definition: lisp_types.c:579
int ip_address_cmp(const ip_address_t *ip1, const ip_address_t *ip2)
Definition: lisp_types.c:861
fid_addr_type_t_
Definition: lisp_types.h:109
u32 locator_set_index
Definition: lisp_types.h:348
void gid_address_free(gid_address_t *a)
Definition: lisp_types.c:842
u16 gid_address_size_to_put(gid_address_t *a)
Definition: lisp_types.c:1472
u8 * format_gid_address(u8 *s, va_list *args)
Definition: lisp_types.c:258
int gid_address_cmp(gid_address_t *a1, gid_address_t *a2)
Definition: lisp_types.c:1624
void ip_address_set(ip_address_t *dst, const void *src, u8 version)
Definition: lisp_types.c:900
void gid_address_ip_set(gid_address_t *dst, void *src, u8 version)
Definition: lisp_types.c:1552
lisp_key_type_t key_id
Definition: lisp_types.h:365
fid_addr_type_t type
Definition: lisp_types.h:125
u8 si
Definition: lisp_types.h:167
void ip_prefix_normalize(ip_prefix_t *a)
Definition: lisp_types.c:980
struct _gid_address_t gid_address_t
void * gid_address_cast(gid_address_t *gid, gid_address_type_t type)
Definition: lisp_types.c:1481
unsigned int u32
Definition: types.h:88
lcaf_arp_t arp
Definition: lisp_types.h:188
u8 * format_mac_address(u8 *s, va_list *args)
Definition: lisp_types.c:215
fid_address_t dp_address_t
Definition: lisp_types.h:128
void ip_prefix_to_fib_prefix(const ip_prefix_t *ipp, fib_prefix_t *fibp)
convert from a LISP to a FIB prefix
Definition: control.c:162
u8 ip_address_max_len(u8 ver)
Definition: lisp_types.c:541
u16 ip4_address_size_to_put()
Definition: lisp_types.c:547
u64 uword
Definition: types.h:112
template key/value backing page structure
Definition: bihash_doc.h:44
unsigned short u16
Definition: types.h:57
lisp_key_type_t
Definition: lisp_types.h:25
fid_address_t src
Definition: lisp_types.h:140
u8 * format_fid_address(u8 *s, va_list *args)
Definition: lisp_types.c:237
unsigned char u8
Definition: types.h:56
u8 * format_ip_address(u8 *s, va_list *args)
Definition: lisp_types.c:144
void gid_address_from_ip(gid_address_t *g, ip_address_t *ip)
Definition: lisp_types.c:853
u32 locator_cmp(locator_t *l1, locator_t *l2)
Definition: lisp_types.c:1710
Definition: lisp_types.h:37
gid_address_t eid
Definition: lisp_types.h:343
gid_address_t address
Definition: lisp_types.h:317
#define foreach_gid_address_type_fcns
Definition: lisp_types.h:283
ip_address_t rmt_loc
Definition: lisp_types.h:377
u32 ip6_address_put(u8 *b, ip6_address_t *a)
Definition: lisp_types.c:570
void locator_copy(locator_t *dst, locator_t *src)
Definition: lisp_types.c:1701
vhost_vring_addr_t addr
Definition: vhost-user.h:82
Definition: lisp_types.h:38
ip_address_type_t
Definition: lisp_types.h:35
void ip_address_to_46(const ip_address_t *addr, ip46_address_t *a, fib_protocol_t *proto)
Definition: lisp_types.c:907
source_dest_t sd
Definition: lisp_types.h:187
ip4_address_t addr
Definition: lisp_types.h:175
u32 * locator_indices
Definition: lisp_types.h:337
uword unformat_ip_prefix(unformat_input_t *input, va_list *args)
Definition: lisp_types.c:187
locator_t * locators
Definition: lisp_types.h:349
u8 * format_hmac_key_id(u8 *s, va_list *args)
Definition: lisp_types.c:412