]> git.proxmox.com Git - mirror_frr.git/blob - zebra/zebra_vxlan_private.h
redhat: Add option to build with RPKI
[mirror_frr.git] / zebra / zebra_vxlan_private.h
1 /*
2 * Zebra VxLAN (EVPN) Data structures and definitions
3 * These are "internal" to this function.
4 * Copyright (C) 2016, 2017 Cumulus Networks, Inc.
5 *
6 * This file is part of FRR.
7 *
8 * FRR is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the
10 * Free Software Foundation; either version 2, or (at your option) any
11 * later version.
12 *
13 * FRR is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with FRR; see the file COPYING. If not, write to the Free
20 * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
21 * 02111-1307, USA.
22 */
23
24 #ifndef _ZEBRA_VXLAN_PRIVATE_H
25 #define _ZEBRA_VXLAN_PRIVATE_H
26
27 #include <zebra.h>
28
29 #include <zebra.h>
30
31 #include "if.h"
32 #include "linklist.h"
33 #include "zebra_vxlan.h"
34
35 #define ERR_STR_SZ 256
36
37 /* definitions */
38 typedef struct zebra_vni_t_ zebra_vni_t;
39 typedef struct zebra_vtep_t_ zebra_vtep_t;
40 typedef struct zebra_mac_t_ zebra_mac_t;
41 typedef struct zebra_neigh_t_ zebra_neigh_t;
42 typedef struct zebra_l3vni_t_ zebra_l3vni_t;
43
44 /*
45 * VTEP info
46 *
47 * Right now, this just has each remote VTEP's IP address.
48 */
49 struct zebra_vtep_t_ {
50 /* Remote IP. */
51 /* NOTE: Can only be IPv4 right now. */
52 struct in_addr vtep_ip;
53
54 /* Links. */
55 struct zebra_vtep_t_ *next;
56 struct zebra_vtep_t_ *prev;
57 };
58
59
60 /*
61 * VNI hash table
62 *
63 * Contains information pertaining to a VNI:
64 * - the list of remote VTEPs (with this VNI)
65 */
66 struct zebra_vni_t_ {
67 /* VNI - key */
68 vni_t vni;
69
70 /* Flag for advertising gw macip */
71 u_int8_t advertise_gw_macip;
72
73 /* Corresponding VxLAN interface. */
74 struct interface *vxlan_if;
75
76 /* List of remote VTEPs */
77 zebra_vtep_t *vteps;
78
79 /* Local IP */
80 struct in_addr local_vtep_ip;
81
82 /* tenant VRF, if any */
83 vrf_id_t vrf_id;
84
85 /* List of local or remote MAC */
86 struct hash *mac_table;
87
88 /* List of local or remote neighbors (MAC+IP) */
89 struct hash *neigh_table;
90 };
91
92 /* L3 VNI hash table */
93 struct zebra_l3vni_t_ {
94
95 /* VNI key */
96 vni_t vni;
97
98 /* vrf_id */
99 vrf_id_t vrf_id;
100
101 /* Local IP */
102 struct in_addr local_vtep_ip;
103
104 /* kernel interface for l3vni */
105 struct interface *vxlan_if;
106
107 /* SVI interface corresponding to the l3vni */
108 struct interface *svi_if;
109
110 /* list of L2 VNIs associated with the L3 VNI */
111 struct list *l2vnis;
112
113 /* list of remote router-macs */
114 struct hash *rmac_table;
115
116 /* list of remote vtep-ip neigh */
117 struct hash *nh_table;
118 };
119
120 /* get the vx-intf name for l3vni */
121 static inline const char *zl3vni_vxlan_if_name(zebra_l3vni_t *zl3vni)
122 {
123 return zl3vni->vxlan_if ? zl3vni->vxlan_if->name : "None";
124 }
125
126 /* get the svi intf name for l3vni */
127 static inline const char *zl3vni_svi_if_name(zebra_l3vni_t *zl3vni)
128 {
129 return zl3vni->svi_if ? zl3vni->svi_if->name : "None";
130 }
131
132 /* get the vrf name for l3vni */
133 static inline const char *zl3vni_vrf_name(zebra_l3vni_t *zl3vni)
134 {
135 return vrf_id_to_name(zl3vni->vrf_id);
136 }
137
138 /* get the rmac string */
139 static inline const char *zl3vni_rmac2str(zebra_l3vni_t *zl3vni, char *buf,
140 int size)
141 {
142 char *ptr;
143
144 if (!buf)
145 ptr = (char *)XMALLOC(MTYPE_TMP,
146 ETHER_ADDR_STRLEN * sizeof(char));
147 else {
148 assert(size >= ETHER_ADDR_STRLEN);
149 ptr = buf;
150 }
151
152 if (zl3vni->svi_if)
153 snprintf(ptr, (ETHER_ADDR_STRLEN),
154 "%02x:%02x:%02x:%02x:%02x:%02x",
155 (uint8_t)zl3vni->svi_if->hw_addr[0],
156 (uint8_t)zl3vni->svi_if->hw_addr[1],
157 (uint8_t)zl3vni->svi_if->hw_addr[2],
158 (uint8_t)zl3vni->svi_if->hw_addr[3],
159 (uint8_t)zl3vni->svi_if->hw_addr[4],
160 (uint8_t)zl3vni->svi_if->hw_addr[5]);
161 else
162 snprintf(ptr, ETHER_ADDR_STRLEN, "None");
163
164 return ptr;
165 }
166
167 /*
168 * l3-vni is oper up when:
169 * 0. if EVPN is enabled (advertise-all-vni cfged)
170 * 1. it is associated to a vxlan-intf
171 * 2. Associated vxlan-intf is oper up
172 * 3. it is associated to an SVI
173 * 4. associated SVI is oper up
174 */
175 static inline int is_l3vni_oper_up(zebra_l3vni_t *zl3vni)
176 {
177 return (is_evpn_enabled() && zl3vni &&
178 (zl3vni->vrf_id != VRF_UNKNOWN) &&
179 zl3vni->vxlan_if && if_is_operative(zl3vni->vxlan_if) &&
180 zl3vni->svi_if && if_is_operative(zl3vni->svi_if));
181 }
182
183 static inline const char *zl3vni_state2str(zebra_l3vni_t *zl3vni)
184 {
185 if (!zl3vni)
186 return NULL;
187
188 if (is_l3vni_oper_up(zl3vni))
189 return "Up";
190 else
191 return "Down";
192
193 return NULL;
194 }
195
196 static inline vrf_id_t zl3vni_vrf_id(zebra_l3vni_t *zl3vni)
197 {
198 return zl3vni->vrf_id;
199 }
200
201 static inline void zl3vni_get_rmac(zebra_l3vni_t *zl3vni,
202 struct ethaddr *rmac)
203 {
204 if (!zl3vni)
205 return;
206
207 if (!is_l3vni_oper_up(zl3vni))
208 return;
209
210 if (zl3vni->svi_if && if_is_operative(zl3vni->svi_if))
211 memcpy(rmac->octet, zl3vni->svi_if->hw_addr, ETH_ALEN);
212 }
213
214 /*
215 * MAC hash table.
216 *
217 * This table contains the MAC addresses pertaining to this VNI.
218 * This includes local MACs learnt on an attached VLAN that maps
219 * to this VNI as well as remote MACs learnt and installed by BGP.
220 * Local MACs will be known either on a VLAN sub-interface or
221 * on (port, VLAN); however, it is sufficient for zebra to maintain
222 * against the VNI i.e., it does not need to retain the local "port"
223 * information. The correct VNI will be obtained as zebra maintains
224 * the mapping (of VLAN to VNI).
225 */
226 struct zebra_mac_t_ {
227 /* MAC address. */
228 struct ethaddr macaddr;
229
230 u_int32_t flags;
231 #define ZEBRA_MAC_LOCAL 0x01
232 #define ZEBRA_MAC_REMOTE 0x02
233 #define ZEBRA_MAC_AUTO 0x04 /* Auto created for neighbor. */
234 #define ZEBRA_MAC_STICKY 0x08 /* Static MAC */
235 #define ZEBRA_MAC_REMOTE_RMAC 0x10 /* remote router mac */
236
237 /* Local or remote info. */
238 union {
239 struct {
240 ifindex_t ifindex;
241 vlanid_t vid;
242 } local;
243
244 struct in_addr r_vtep_ip;
245 } fwd_info;
246
247 /* List of neigh associated with this mac */
248 struct list *neigh_list;
249
250 /* list of hosts pointing to this remote RMAC */
251 struct list *host_list;
252 };
253
254 /*
255 * Context for MAC hash walk - used by callbacks.
256 */
257 struct mac_walk_ctx {
258 zebra_vni_t *zvni; /* VNI hash */
259 struct zebra_vrf *zvrf; /* VRF - for client notification. */
260 int uninstall; /* uninstall from kernel? */
261 int upd_client; /* uninstall from client? */
262
263 u_int32_t flags;
264 #define DEL_LOCAL_MAC 0x1
265 #define DEL_REMOTE_MAC 0x2
266 #define DEL_ALL_MAC (DEL_LOCAL_MAC | DEL_REMOTE_MAC)
267 #define DEL_REMOTE_MAC_FROM_VTEP 0x4
268 #define SHOW_REMOTE_MAC_FROM_VTEP 0x8
269
270 struct in_addr r_vtep_ip; /* To walk MACs from specific VTEP */
271
272 struct vty *vty; /* Used by VTY handlers */
273 u_int32_t count; /* Used by VTY handlers */
274 struct json_object *json; /* Used for JSON Output */
275 };
276
277 struct rmac_walk_ctx {
278 struct vty *vty;
279 struct json_object *json;
280 };
281
282 enum zebra_neigh_state { ZEBRA_NEIGH_INACTIVE = 0, ZEBRA_NEIGH_ACTIVE = 1 };
283
284 #define IS_ZEBRA_NEIGH_ACTIVE(n) n->state == ZEBRA_NEIGH_ACTIVE
285
286 #define IS_ZEBRA_NEIGH_INACTIVE(n) n->state == ZEBRA_NEIGH_INACTIVE
287
288 #define ZEBRA_NEIGH_SET_ACTIVE(n) n->state = ZEBRA_NEIGH_ACTIVE
289
290 #define ZEBRA_NEIGH_SET_INACTIVE(n) n->state = ZEBRA_NEIGH_INACTIVE
291
292 /*
293 * Neighbor hash table.
294 *
295 * This table contains the neighbors (IP to MAC bindings) pertaining to
296 * this VNI. This includes local neighbors learnt on the attached VLAN
297 * device that maps to this VNI as well as remote neighbors learnt and
298 * installed by BGP.
299 * Local neighbors will be known against the VLAN device (SVI); however,
300 * it is sufficient for zebra to maintain against the VNI. The correct
301 * VNI will be obtained as zebra maintains the mapping (of VLAN to VNI).
302 */
303 struct zebra_neigh_t_ {
304 /* IP address. */
305 struct ipaddr ip;
306
307 /* MAC address. */
308 struct ethaddr emac;
309
310 /* Underlying interface. */
311 ifindex_t ifindex;
312
313 u_int32_t flags;
314 #define ZEBRA_NEIGH_LOCAL 0x01
315 #define ZEBRA_NEIGH_REMOTE 0x02
316 #define ZEBRA_NEIGH_REMOTE_NH 0x04 /* neigh entry for remote vtep */
317
318 enum zebra_neigh_state state;
319
320 /* Remote VTEP IP - applicable only for remote neighbors. */
321 struct in_addr r_vtep_ip;
322
323 /* list of hosts pointing to this remote NH entry */
324 struct list *host_list;
325 };
326
327 /*
328 * Context for neighbor hash walk - used by callbacks.
329 */
330 struct neigh_walk_ctx {
331 zebra_vni_t *zvni; /* VNI hash */
332 struct zebra_vrf *zvrf; /* VRF - for client notification. */
333 int uninstall; /* uninstall from kernel? */
334 int upd_client; /* uninstall from client? */
335
336 u_int32_t flags;
337 #define DEL_LOCAL_NEIGH 0x1
338 #define DEL_REMOTE_NEIGH 0x2
339 #define DEL_ALL_NEIGH (DEL_LOCAL_NEIGH | DEL_REMOTE_NEIGH)
340 #define DEL_REMOTE_NEIGH_FROM_VTEP 0x4
341 #define SHOW_REMOTE_NEIGH_FROM_VTEP 0x8
342
343 struct in_addr r_vtep_ip; /* To walk neighbors from specific VTEP */
344
345 struct vty *vty; /* Used by VTY handlers */
346 u_int32_t count; /* Used by VTY handlers */
347 u_char addr_width; /* Used by VTY handlers */
348 struct json_object *json; /* Used for JSON Output */
349 };
350
351 /* context for neigh hash walk - update l3vni and rmac */
352 struct neigh_l3info_walk_ctx {
353
354 zebra_vni_t *zvni;
355 zebra_l3vni_t *zl3vni;
356 int add;
357 };
358
359 struct nh_walk_ctx {
360
361 struct vty *vty;
362 struct json_object *json;
363 };
364
365 #endif /* _ZEBRA_VXLAN_PRIVATE_H */