Reformat output of lisp eid-table show command.
[vpp.git] / vnet / 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 typedef enum
23 {
24   IP4,
25   IP6
26 } ip_address_type_t;
27
28 typedef CLIB_PACKED(struct ip_address
29 {
30   union
31   {
32     ip4_address_t v4;
33     ip6_address_t v6;
34   } ip;
35   u8 version;
36 }) ip_address_t;
37
38 #define ip_addr_addr(_a) (_a)->ip
39 #define ip_addr_v4(_a) (_a)->ip.v4
40 #define ip_addr_v6(_a) (_a)->ip.v6
41 #define ip_addr_version(_a) (_a)->version
42
43 int ip_address_cmp (ip_address_t * ip1, ip_address_t * ip2);
44 void ip_address_copy (ip_address_t * dst , ip_address_t * src);
45 void ip_address_copy_addr (void * dst , ip_address_t * src);
46 void ip_address_set(ip_address_t * dst, void * src, u8 version);
47
48 typedef CLIB_PACKED(struct ip_prefix
49 {
50   ip_address_t addr;
51   u8 len;
52 }) ip_prefix_t;
53
54 #define ip_prefix_addr(_a) (_a)->addr
55 #define ip_prefix_version(_a) ip_addr_version(&ip_prefix_addr(_a))
56 #define ip_prefix_len(_a) (_a)->len
57 #define ip_prefix_v4(_a) ip_addr_v4(&ip_prefix_addr(_a))
58 #define ip_prefix_v6(_a) ip_addr_v6(&ip_prefix_addr(_a))
59
60 typedef enum
61 {
62   /* NOTE: ip addresses are left out on purpose. Use max masked ip-prefixes
63    * instead */
64   GID_ADDR_IP_PREFIX,
65   GID_ADDR_LCAF,
66   GID_ADDR_MAC,
67   GID_ADDR_SRC_DST,
68   GID_ADDR_NO_ADDRESS,
69   GID_ADDR_TYPES
70 } gid_address_type_t;
71
72 typedef enum
73 {
74   /* make sure that values corresponds with RFC */
75   LCAF_NULL_BODY = 0,
76   LCAF_AFI_LIST_TYPE,
77   LCAF_INSTANCE_ID,
78   LCAF_TYPES
79 } lcaf_type_t;
80
81 struct _gid_address_t;
82
83 typedef struct
84 {
85   u8 src_len;
86   u8 dst_len;
87   struct _gid_address_t *src;
88   struct _gid_address_t *dst;
89 } source_dest_t;
90
91 #define SD_CAST (source_dest_t *)
92 #define sd_dst_gid(_a) (SD_CAST _a)->dst
93 #define sd_src_gid(_a) (SD_CAST _a)->src
94
95 typedef struct
96 {
97   u8 vni_mask_len;
98   u32 vni;
99   struct _gid_address_t *gid_addr;
100 } vni_t;
101
102 #define vni_vni(_a) (_a)->vni
103 #define vni_mask_len(_a) (_a)->vni_mask_len
104 #define vni_gid(_a) (_a)->gid_addr
105
106 typedef struct
107 {
108   /* the union needs to be at the beginning! */
109   union
110   {
111     source_dest_t sd;
112     vni_t uni;
113   };
114   u8 type;
115 } lcaf_t;
116
117 #define lcaf_type(_a) (_a)->type
118 #define lcaf_vni(_a) vni_vni(& (_a)->uni)
119 #define lcaf_vni_len(_a) vni_mask_len(& (_a)->uni)
120
121 /* might want to expand this in the future :) */
122 typedef struct _gid_address_t
123 {
124   union
125   {
126     ip_prefix_t ippref;
127     lcaf_t lcaf;
128     u8 mac[6];
129   };
130   u8 type;
131   u32 vni;
132   u8 vni_mask;
133 } gid_address_t;
134
135 u8 * format_ip_address (u8 * s, va_list * args);
136 uword unformat_ip_address (unformat_input_t * input, va_list * args);
137 u8 * format_ip_prefix (u8 * s, va_list * args);
138 uword unformat_ip_prefix (unformat_input_t * input, va_list * args);
139
140 u16 ip4_address_size_to_put ();
141 u16 ip6_address_size_to_put ();
142 u32 ip4_address_put (u8 * b, ip4_address_t * a);
143 u32 ip6_address_put (u8 * b, ip6_address_t * a);
144
145 u16 ip_address_size_to_write (ip_address_t * a);
146 u16 ip_address_iana_afi(ip_address_t *a);
147 u8 ip_address_max_len (u8 ver);
148 u32 ip_address_put (u8 * b, ip_address_t * a);
149
150 /* LISP AFI codes  */
151 typedef enum {
152     LISP_AFI_NO_ADDR,
153     LISP_AFI_IP,
154     LISP_AFI_IP6,
155     LISP_AFI_MAC = 6,
156     LISP_AFI_LCAF = 16387
157 } lisp_afi_e;
158
159 u8 *format_gid_address (u8 * s, va_list * args);
160 uword unformat_gid_address (unformat_input_t * input, va_list * args);
161 int gid_address_cmp (gid_address_t * a1, gid_address_t * a2);
162 void gid_address_free (gid_address_t *a);
163
164 u16 gid_address_size_to_put (gid_address_t * a);
165 u16 gid_address_put (u8 * b, gid_address_t * gid);
166 u8 gid_address_len (gid_address_t *a);
167 void * gid_address_cast (gid_address_t * gid, gid_address_type_t type);
168 void gid_address_copy(gid_address_t * dst, gid_address_t * src);
169 u32 gid_address_parse (u8 * offset, gid_address_t *a);
170
171 #define gid_address_type(_a) (_a)->type
172 #define gid_address_ippref(_a) (_a)->ippref
173 #define gid_address_ippref_len(_a) (_a)->ippref.len
174 #define gid_address_ip(_a) ip_prefix_addr(&gid_address_ippref(_a))
175 #define gid_address_ip_version(_a) ip_addr_version(&gid_address_ip(_a))
176 #define gid_address_lcaf(_a) (_a)->lcaf
177 #define gid_address_mac(_a) (_a)->mac
178 #define gid_address_vni(_a) (_a)->vni
179 #define gid_address_vni_mask(_a) (_a)->vni_mask
180 #define gid_address_sd_dest_pref(_a) \
181   gid_address_ippref(sd_dst_gid(_a))
182 #define gid_address_sd_source_pref(_a) \
183   gid_address_ippref(sd_src_gid(_a))
184
185 /* 'sub'address functions */
186 #define foreach_gid_address_type_fcns  \
187   _(ip_prefix)                    \
188   _(lcaf)                         \
189   _(mac)
190
191 #define _(_n)                                 \
192 u16    _n ## _size_to_write (void * pref);    \
193 u16    _n ## _write (u8 * p, void * pref);    \
194 u8     _n ## _length (void *a);               \
195 void * _n ## _cast (gid_address_t * a);       \
196 void   _n ## _copy (void * dst , void * src);
197
198 foreach_gid_address_type_fcns
199 #undef _
200
201 typedef struct
202 {
203   /* mark locator as local as opposed to remote */
204   u8 local;
205   u8 state;
206   union {
207     u32 sw_if_index;
208     gid_address_t address;
209   };
210   u8 priority;
211   u8 weight;
212   u8 mpriority;
213   u8 mweight;
214 } locator_t;
215
216 u32 locator_parse (void * ptr, locator_t * loc);
217 void locator_copy (locator_t * dst, locator_t * src);
218 u32 locator_cmp (locator_t * l1, locator_t * l2);
219 void locator_free (locator_t * l);
220
221 typedef struct
222 {
223   /* locator-set name */
224   u8 * name;
225
226   /* vector of locator indices */
227   u32 * locator_indices;
228   u8 local;
229 } locator_set_t;
230
231 typedef struct
232 {
233   gid_address_t eid;
234
235   /* index of local locator set */
236   u32 locator_set_index;
237
238   u32 ttl;
239   u8 action;
240   u8 authoritative;
241
242   u8 local;
243 } mapping_t;
244
245 lcaf_t lcaf_iid_init (u32 vni);
246
247 #endif /* VNET_LISP_GPE_LISP_TYPES_H_ */