Add lisp-gpe ip6 data-plane support
[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 int ip_address_cmp (ip_address_t * ip1, ip_address_t * ip2);
39 void ip_address_copy (ip_address_t * dst , ip_address_t * src);
40 void ip_address_copy_addr (void * dst , ip_address_t * src);
41
42 typedef CLIB_PACKED(struct ip_prefix
43 {
44   ip_address_t addr;
45   u8 len;
46 }) ip_prefix_t;
47
48 #define ip_addr_addr(_a) (_a)->ip
49 #define ip_addr_v4(_a) (_a)->ip.v4
50 #define ip_addr_v6(_a) (_a)->ip.v6
51 #define ip_addr_version(_a) (_a)->version
52
53 #define ip_prefix_addr(_a) (_a)->addr
54 #define ip_prefix_version(_a) ip_addr_version(&ip_prefix_addr(_a))
55 #define ip_prefix_len(_a) (_a)->len
56 #define ip_prefix_v4(_a) ip_addr_v4(&ip_prefix_addr(_a))
57 #define ip_prefix_v6(_a) ip_addr_v6(&ip_prefix_addr(_a))
58
59 typedef enum
60 {
61   /* NOTE: ip addresses are left out on purpose. Use max masked ip-prefixes
62    * instead */
63   IP_PREFIX,
64   NO_ADDRESS,
65   GID_ADDR_TYPES
66 } gid_address_type_t;
67
68 /* might want to expand this in the future :) */
69 typedef struct
70 {
71   union
72   {
73     ip_prefix_t ippref;
74   };
75   u8 type;
76 } gid_address_t;
77
78 u8 * format_ip_address (u8 * s, va_list * args);
79 uword unformat_ip_address (unformat_input_t * input, va_list * args);
80 u8 * format_ip_prefix (u8 * s, va_list * args);
81 uword unformat_ip_prefix (unformat_input_t * input, va_list * args);
82
83 u16 ip4_address_size_to_put ();
84 u16 ip6_address_size_to_put ();
85 u32 ip4_address_put (u8 * b, ip4_address_t * a);
86 u32 ip6_address_put (u8 * b, ip6_address_t * a);
87
88 u16 ip_address_size_to_write (ip_address_t * a);
89 u16 ip_address_iana_afi(ip_address_t *a);
90 u8 ip_address_max_len (u8 ver);
91 u32 ip_address_put (u8 * b, ip_address_t * a);
92
93 /* LISP AFI codes  */
94 typedef enum {
95     LISP_AFI_NO_ADDR,
96     LISP_AFI_IP,
97     LISP_AFI_IP6,
98     LISP_AFI_LCAF = 16387
99 } lisp_afi_e;
100
101 u8 *format_gid_address (u8 * s, va_list * args);
102 uword unformat_gid_address (unformat_input_t * input, va_list * args);
103 int gid_address_cmp (gid_address_t * a1, gid_address_t * a2);
104
105 u16 gid_address_size_to_put (gid_address_t * a);
106 u16 gid_address_put (u8 * b, gid_address_t * gid);
107 u8 gid_address_len (gid_address_t *a);
108 void * gid_address_cast (gid_address_t * gid, gid_address_type_t type);
109 void gid_address_copy(gid_address_t * dst, gid_address_t * src);
110 u32 gid_address_parse (u8 * offset, gid_address_t *a);
111
112 #define gid_address_type(_a) (_a)->type
113 #define gid_address_ippref(_a) (_a)->ippref
114 #define gid_address_ippref_len(_a) (_a)->ippref.len
115 #define gid_address_ip(_a) ip_prefix_addr(&gid_address_ippref(_a))
116
117 /* 'sub'address functions */
118 u16 ip_prefix_size_to_write (void * pref);
119 u16 ip_prefix_write (u8 * p, void * pref);
120 u8 ip_prefix_length (void *a);
121 void *ip_prefix_cast (gid_address_t * a);
122 void ip_prefix_copy (void * dst , void * src);
123
124 typedef struct
125 {
126   /* mark locator as local as opposed to remote */
127   u8 local;
128   u8 state;
129   union {
130     u32 sw_if_index;
131     gid_address_t address;
132   };
133   u8 priority;
134   u8 weight;
135   u8 mpriority;
136   u8 mweight;
137 } locator_t;
138
139 u32 locator_parse (void * ptr, locator_t * loc);
140 void locator_copy (locator_t * dst, locator_t * src);
141 u32 locator_cmp (locator_t * l1, locator_t * l2);
142
143 typedef struct
144 {
145   /* locator-set name */
146   u8 * name;
147
148   /* vector of locator indices */
149   u32 * locator_indices;
150   u8 local;
151 } locator_set_t;
152
153 typedef struct
154 {
155   gid_address_t eid;
156
157   /* index of local locator set */
158   u32 locator_set_index;
159
160   u32 ttl;
161   u8 action;
162   u8 authoritative;
163
164   u8 local;
165 } mapping_t;
166
167 #endif /* VNET_LISP_GPE_LISP_TYPES_H_ */