FD.io VPP  v16.09
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 typedef enum
23 {
24  IP4,
27 
28 /* *INDENT-OFF* */
29 typedef CLIB_PACKED(struct ip_address
30 {
31  union
32  {
33  ip4_address_t v4;
34  ip6_address_t v6;
35  } ip;
36  u8 version;
37 }) ip_address_t;
38 /* *INDENT-ON* */
39 
40 #define ip_addr_addr(_a) (_a)->ip
41 #define ip_addr_v4(_a) (_a)->ip.v4
42 #define ip_addr_v6(_a) (_a)->ip.v6
43 #define ip_addr_version(_a) (_a)->version
44 
45 int ip_address_cmp (ip_address_t * ip1, ip_address_t * ip2);
46 void ip_address_copy (ip_address_t * dst, ip_address_t * src);
47 void ip_address_copy_addr (void *dst, ip_address_t * src);
48 void ip_address_set (ip_address_t * dst, void *src, u8 version);
49 
50 /* *INDENT-OFF* */
51 typedef CLIB_PACKED(struct ip_prefix
52 {
53  ip_address_t addr;
54  u8 len;
55 }) ip_prefix_t;
56 /* *INDENT-ON* */
57 
58 #define ip_prefix_addr(_a) (_a)->addr
59 #define ip_prefix_version(_a) ip_addr_version(&ip_prefix_addr(_a))
60 #define ip_prefix_len(_a) (_a)->len
61 #define ip_prefix_v4(_a) ip_addr_v4(&ip_prefix_addr(_a))
62 #define ip_prefix_v6(_a) ip_addr_v6(&ip_prefix_addr(_a))
63 
64 void ip_prefix_normalize (ip_prefix_t * a);
65 
66 typedef enum
67 {
68  /* NOTE: ip addresses are left out on purpose. Use max masked ip-prefixes
69  * instead */
77 
78 typedef enum
79 {
80  /* make sure that values corresponds with RFC */
86 } lcaf_type_t;
87 
88 typedef enum
89 {
93 
94 /* flat address type */
95 typedef struct
96 {
97  union
98  {
99  ip_prefix_t ippref;
100  u8 mac[6];
101  };
102  u8 type; /* fid_addr_type_t */
103 } fid_address_t;
104 
106 
107 #define fid_addr_ippref(_a) (_a)->ippref
108 #define fid_addr_mac(_a) (_a)->mac
109 #define fid_addr_type(_a) (_a)->type
110 
111 typedef struct
112 {
115 } source_dest_t;
116 
117 #define sd_dst(_a) (_a)->dst
118 #define sd_src(_a) (_a)->src
119 #define sd_src_ippref(_a) fid_addr_ippref(&sd_src(_a))
120 #define sd_dst_ippref(_a) fid_addr_ippref(&sd_dst(_a))
121 #define sd_src_mac(_a) fid_addr_mac(&sd_src(_a))
122 #define sd_dst_mac(_a) fid_addr_mac(&sd_dst(_a))
123 
124 typedef struct
125 {
128  struct _gid_address_t *gid_addr;
129 } vni_t;
130 
131 #define vni_vni(_a) (_a)->vni
132 #define vni_mask_len(_a) (_a)->vni_mask_len
133 #define vni_gid(_a) (_a)->gid_addr
134 
135 typedef struct
136 {
137  /* the union needs to be at the beginning! */
138  union
139  {
142  };
144 } lcaf_t;
145 
146 #define lcaf_type(_a) (_a)->type
147 #define lcaf_vni(_a) vni_vni(& (_a)->uni)
148 #define lcaf_vni_len(_a) vni_mask_len(& (_a)->uni)
149 
150 /* might want to expand this in the future :) */
151 typedef struct _gid_address_t
152 {
153  union
154  {
155  ip_prefix_t ippref;
156  lcaf_t lcaf;
157  u8 mac[6];
158  source_dest_t sd;
159  };
160  u8 type;
161  u32 vni;
162  u8 vni_mask;
163 } gid_address_t;
164 
165 u8 *format_ip_address (u8 * s, va_list * args);
166 uword unformat_ip_address (unformat_input_t * input, va_list * args);
167 u8 *format_ip_prefix (u8 * s, va_list * args);
168 uword unformat_ip_prefix (unformat_input_t * input, va_list * args);
169 u8 *format_mac_address (u8 * s, va_list * args);
170 uword unformat_mac_address (unformat_input_t * input, va_list * args);
171 
176 
177 u16 ip_address_size_to_write (ip_address_t * a);
178 u16 ip_address_iana_afi (ip_address_t * a);
179 u8 ip_address_max_len (u8 ver);
180 u32 ip_address_put (u8 * b, ip_address_t * a);
181 
182 /* LISP AFI codes */
183 typedef enum
184 {
188  LISP_AFI_LCAF = 16387,
189  LISP_AFI_MAC = 16389
190 } lisp_afi_e;
191 
192 u8 *format_gid_address (u8 * s, va_list * args);
193 uword unformat_gid_address (unformat_input_t * input, va_list * args);
196 
198 u16 gid_address_put (u8 * b, gid_address_t * gid);
200 void *gid_address_cast (gid_address_t * gid, gid_address_type_t type);
201 void gid_address_copy (gid_address_t * dst, gid_address_t * src);
203 void gid_address_ip_set (gid_address_t * dst, void *src, u8 version);
204 
205 #define gid_address_type(_a) (_a)->type
206 #define gid_address_ippref(_a) (_a)->ippref
207 #define gid_address_ippref_len(_a) (_a)->ippref.len
208 #define gid_address_ip(_a) ip_prefix_addr(&gid_address_ippref(_a))
209 #define gid_address_ip_version(_a) ip_addr_version(&gid_address_ip(_a))
210 #define gid_address_lcaf(_a) (_a)->lcaf
211 #define gid_address_mac(_a) (_a)->mac
212 #define gid_address_vni(_a) (_a)->vni
213 #define gid_address_vni_mask(_a) (_a)->vni_mask
214 #define gid_address_sd_dst_ippref(_a) sd_dst_ippref(&(_a)->sd)
215 #define gid_address_sd_src_ippref(_a) sd_src_ippref(&(_a)->sd)
216 #define gid_address_sd_dst_mac(_a) sd_dst_mac(&(_a)->sd)
217 #define gid_address_sd_src_mac(_a) sd_src_mac(&(_a)->sd)
218 #define gid_address_sd(_a) (_a)->sd
219 #define gid_address_sd_src(_a) sd_src(&gid_address_sd(_a))
220 #define gid_address_sd_dst(_a) sd_dst(&gid_address_sd(_a))
221 
222 /* 'sub'address functions */
223 #define foreach_gid_address_type_fcns \
224  _(ip_prefix) \
225  _(lcaf) \
226  _(mac) \
227  _(sd)
228 
229 /* *INDENT-OFF* */
230 #define _(_n) \
231 u16 _n ## _size_to_write (void * pref); \
232 u16 _n ## _write (u8 * p, void * pref); \
233 u8 _n ## _length (void *a); \
234 void * _n ## _cast (gid_address_t * a); \
235 void _n ## _copy (void * dst , void * src);
236 
238 #undef _
239 /* *INDENT-ON* */
240 
243 {
244  return (*((u64 *) m) & 0xffffffffffff);
245 }
246 
247 typedef struct
248 {
249  /* mark locator as local as opposed to remote */
252  union
253  {
256  };
261 } locator_t;
262 
263 u32 locator_parse (void *ptr, locator_t * loc);
264 void locator_copy (locator_t * dst, locator_t * src);
265 u32 locator_cmp (locator_t * l1, locator_t * l2);
266 void locator_free (locator_t * l);
267 
268 typedef struct
269 {
270  /* locator-set name */
272 
273  /* vector of locator indices */
276 } locator_set_t;
277 
278 typedef struct
279 {
281 
282  /* index of local locator set */
284 
288 
290  /* valid only for remote mappings */
292 } mapping_t;
293 
294 uword
295 unformat_negative_mapping_action (unformat_input_t * input, va_list * args);
296 
297 typedef struct locator_pair
298 {
299  /* local and remote locators (underlay attachment points) */
300  ip_address_t lcl_loc;
301  ip_address_t rmt_loc;
302 
303  u8 priority; /* TODO remove */
306 
307 #endif /* VNET_LISP_GPE_LISP_TYPES_H_ */
308 
309 /*
310  * fd.io coding-style-patch-verification: ON
311  *
312  * Local Variables:
313  * eval: (c-set-style "gnu")
314  * End:
315  */
u8 vni_mask_len
Definition: lisp_types.h:126
u16 ip_address_iana_afi(ip_address_t *a)
Definition: lisp_types.c:416
void locator_free(locator_t *l)
Definition: lisp_types.c:1418
fid_address_t dst
Definition: lisp_types.h:114
void gid_address_copy(gid_address_t *dst, gid_address_t *src)
Definition: lisp_types.c:1188
typedef CLIB_PACKED(struct ip_address{union{ip4_address_t v4;ip6_address_t v6;}ip;u8 version;}) ip_address_t
uword unformat_mac_address(unformat_input_t *input, va_list *args)
Definition: lisp_types.c:188
gid_address_type_t
Definition: lisp_types.h:66
bad routing header type(not 4)") sr_error (NO_MORE_SEGMENTS
lcaf_type_t
Definition: lisp_types.h:78
vni_t uni
Definition: lisp_types.h:141
u16 gid_address_put(u8 *b, gid_address_t *gid)
Definition: lisp_types.c:1157
struct locator_pair locator_pair_t
u8 mpriority
Definition: lisp_types.h:259
void ip_address_set(ip_address_t *dst, void *src, u8 version)
Definition: lisp_types.c:685
u32 vni
Definition: lisp_types.h:127
u16 ip6_address_size_to_put()
Definition: lisp_types.c:435
uword unformat_ip_address(unformat_input_t *input, va_list *args)
Definition: lisp_types.c:147
u16 ip_address_size_to_write(ip_address_t *a)
Definition: lisp_types.c:410
int ip_address_cmp(ip_address_t *ip1, ip_address_t *ip2)
Definition: lisp_types.c:656
ip_prefix_t ippref
Definition: lisp_types.h:99
u32 locator_parse(void *ptr, locator_t *loc)
Definition: lisp_types.c:1366
#define always_inline
Definition: clib.h:84
u32 gid_address_parse(u8 *offset, gid_address_t *a)
Definition: lisp_types.c:1208
uword unformat_negative_mapping_action(unformat_input_t *input, va_list *args)
Definition: lisp_types.c:306
static foreach_gid_address_type_fcns u64 mac_to_u64(u8 *m)
Definition: lisp_types.h:242
unsigned long u64
Definition: types.h:89
u8 type
Definition: lisp_types.h:143
void ip_address_copy(ip_address_t *dst, ip_address_t *src)
Definition: lisp_types.c:673
struct _gid_address_t * gid_addr
Definition: lisp_types.h:128
u8 gid_address_len(gid_address_t *a)
Definition: lisp_types.c:1143
u8 authoritative
Definition: lisp_types.h:287
void ip_address_copy_addr(void *dst, ip_address_t *src)
Definition: lisp_types.c:679
ip_address_t lcl_loc
Definition: lisp_types.h:300
lisp_afi_e
Definition: lisp_types.h:183
uword unformat_gid_address(unformat_input_t *input, va_list *args)
Definition: lisp_types.c:271
u32 ip4_address_put(u8 *b, ip4_address_t *a)
Definition: lisp_types.c:442
u8 * format_ip_prefix(u8 *s, va_list *args)
Definition: lisp_types.c:160
u32 sw_if_index
Definition: lisp_types.h:254
u32 ip_address_put(u8 *b, ip_address_t *a)
Definition: lisp_types.c:460
fid_addr_type_t
Definition: lisp_types.h:88
u32 locator_set_index
Definition: lisp_types.h:283
void gid_address_free(gid_address_t *a)
Definition: lisp_types.c:645
u16 gid_address_size_to_put(gid_address_t *a)
Definition: lisp_types.c:1173
u8 * format_gid_address(u8 *s, va_list *args)
Definition: lisp_types.c:224
int gid_address_cmp(gid_address_t *a1, gid_address_t *a2)
Definition: lisp_types.c:1319
void gid_address_ip_set(gid_address_t *dst, void *src, u8 version)
Definition: lisp_types.c:1254
void ip_prefix_normalize(ip_prefix_t *a)
Definition: lisp_types.c:745
struct _gid_address_t gid_address_t
void * gid_address_cast(gid_address_t *gid, gid_address_type_t type)
Definition: lisp_types.c:1182
unsigned int u32
Definition: types.h:88
u8 * format_mac_address(u8 *s, va_list *args)
Definition: lisp_types.c:196
u8 is_static
Definition: lisp_types.h:291
fid_address_t dp_address_t
Definition: lisp_types.h:105
u8 ip_address_max_len(u8 ver)
Definition: lisp_types.c:422
u16 ip4_address_size_to_put()
Definition: lisp_types.c:428
u64 uword
Definition: types.h:112
template key/value backing page structure
Definition: bihash_doc.h:44
unsigned short u16
Definition: types.h:57
fid_address_t src
Definition: lisp_types.h:113
unsigned char u8
Definition: types.h:56
u8 * format_ip_address(u8 *s, va_list *args)
Definition: lisp_types.c:127
u32 locator_cmp(locator_t *l1, locator_t *l2)
Definition: lisp_types.c:1400
Definition: lisp_types.h:24
gid_address_t eid
Definition: lisp_types.h:280
gid_address_t address
Definition: lisp_types.h:255
#define foreach_gid_address_type_fcns
Definition: lisp_types.h:223
ip_address_t rmt_loc
Definition: lisp_types.h:301
u32 ip6_address_put(u8 *b, ip6_address_t *a)
Definition: lisp_types.c:451
void locator_copy(locator_t *dst, locator_t *src)
Definition: lisp_types.c:1391
vhost_vring_addr_t addr
Definition: vhost-user.h:82
struct _unformat_input_t unformat_input_t
Definition: lisp_types.h:25
ip_address_type_t
Definition: lisp_types.h:22
source_dest_t sd
Definition: lisp_types.h:140
u32 * locator_indices
Definition: lisp_types.h:274
uword unformat_ip_prefix(unformat_input_t *input, va_list *args)
Definition: lisp_types.c:168