]> git.proxmox.com Git - mirror_frr.git/blob - zebra/zebra_vxlan_private.h
zebra: print unknown rule family as number
[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 "if.h"
30 #include "linklist.h"
31 #include "zebra_vxlan.h"
32
33 #ifdef __cplusplus
34 extern "C" {
35 #endif
36
37 #define ERR_STR_SZ 256
38
39 /* definitions */
40 typedef struct zebra_vni_t_ zebra_vni_t;
41 typedef struct zebra_vtep_t_ zebra_vtep_t;
42 typedef struct zebra_mac_t_ zebra_mac_t;
43 typedef struct zebra_neigh_t_ zebra_neigh_t;
44 typedef struct zebra_l3vni_t_ zebra_l3vni_t;
45
46 /*
47 * VTEP info
48 *
49 * Right now, this just has each remote VTEP's IP address.
50 */
51 struct zebra_vtep_t_ {
52 /* Remote IP. */
53 /* NOTE: Can only be IPv4 right now. */
54 struct in_addr vtep_ip;
55 /* Flood mode (one of enum vxlan_flood_control) based on the PMSI
56 * tunnel type advertised by the remote VTEP
57 */
58 int flood_control;
59
60 /* Links. */
61 struct zebra_vtep_t_ *next;
62 struct zebra_vtep_t_ *prev;
63 };
64
65
66 /*
67 * VNI hash table
68 *
69 * Contains information pertaining to a VNI:
70 * - the list of remote VTEPs (with this VNI)
71 */
72 struct zebra_vni_t_ {
73 /* VNI - key */
74 vni_t vni;
75
76 /* Flag for advertising gw macip */
77 uint8_t advertise_gw_macip;
78
79 /* Flag for advertising svi macip */
80 uint8_t advertise_svi_macip;
81
82 /* Flag for advertising gw macip */
83 uint8_t advertise_subnet;
84
85 /* Corresponding VxLAN interface. */
86 struct interface *vxlan_if;
87
88 /* List of remote VTEPs */
89 zebra_vtep_t *vteps;
90
91 /* Local IP */
92 struct in_addr local_vtep_ip;
93
94 /* PIM-SM MDT group for BUM flooding */
95 struct in_addr mcast_grp;
96
97 /* tenant VRF, if any */
98 vrf_id_t vrf_id;
99
100 /* List of local or remote MAC */
101 struct hash *mac_table;
102
103 /* List of local or remote neighbors (MAC+IP) */
104 struct hash *neigh_table;
105 };
106
107 /* L3 VNI hash table */
108 struct zebra_l3vni_t_ {
109
110 /* VNI key */
111 vni_t vni;
112
113 /* vrf_id */
114 vrf_id_t vrf_id;
115
116 uint32_t filter;
117 #define PREFIX_ROUTES_ONLY (1 << 0) /* l3-vni used for prefix routes only */
118
119 /* Local IP */
120 struct in_addr local_vtep_ip;
121
122 /* kernel interface for l3vni */
123 struct interface *vxlan_if;
124
125 /* SVI interface corresponding to the l3vni */
126 struct interface *svi_if;
127
128 struct interface *mac_vlan_if;
129
130 /* list of L2 VNIs associated with the L3 VNI */
131 struct list *l2vnis;
132
133 /* list of remote router-macs */
134 struct hash *rmac_table;
135
136 /* list of remote vtep-ip neigh */
137 struct hash *nh_table;
138 };
139
140 /* get the vx-intf name for l3vni */
141 static inline const char *zl3vni_vxlan_if_name(zebra_l3vni_t *zl3vni)
142 {
143 return zl3vni->vxlan_if ? zl3vni->vxlan_if->name : "None";
144 }
145
146 /* get the svi intf name for l3vni */
147 static inline const char *zl3vni_svi_if_name(zebra_l3vni_t *zl3vni)
148 {
149 return zl3vni->svi_if ? zl3vni->svi_if->name : "None";
150 }
151
152 /* get the vrf name for l3vni */
153 static inline const char *zl3vni_vrf_name(zebra_l3vni_t *zl3vni)
154 {
155 return vrf_id_to_name(zl3vni->vrf_id);
156 }
157
158 /* get the rmac string */
159 static inline const char *zl3vni_rmac2str(zebra_l3vni_t *zl3vni, char *buf,
160 int size)
161 {
162 char *ptr;
163
164 if (!buf)
165 ptr = XMALLOC(MTYPE_TMP, ETHER_ADDR_STRLEN * sizeof(char));
166 else {
167 assert(size >= ETHER_ADDR_STRLEN);
168 ptr = buf;
169 }
170
171 if (zl3vni->mac_vlan_if)
172 snprintf(ptr, (ETHER_ADDR_STRLEN),
173 "%02x:%02x:%02x:%02x:%02x:%02x",
174 (uint8_t)zl3vni->mac_vlan_if->hw_addr[0],
175 (uint8_t)zl3vni->mac_vlan_if->hw_addr[1],
176 (uint8_t)zl3vni->mac_vlan_if->hw_addr[2],
177 (uint8_t)zl3vni->mac_vlan_if->hw_addr[3],
178 (uint8_t)zl3vni->mac_vlan_if->hw_addr[4],
179 (uint8_t)zl3vni->mac_vlan_if->hw_addr[5]);
180 else if (zl3vni->svi_if)
181 snprintf(ptr, (ETHER_ADDR_STRLEN),
182 "%02x:%02x:%02x:%02x:%02x:%02x",
183 (uint8_t)zl3vni->svi_if->hw_addr[0],
184 (uint8_t)zl3vni->svi_if->hw_addr[1],
185 (uint8_t)zl3vni->svi_if->hw_addr[2],
186 (uint8_t)zl3vni->svi_if->hw_addr[3],
187 (uint8_t)zl3vni->svi_if->hw_addr[4],
188 (uint8_t)zl3vni->svi_if->hw_addr[5]);
189 else
190 snprintf(ptr, ETHER_ADDR_STRLEN, "None");
191
192 return ptr;
193 }
194
195 /* get the sys mac string */
196 static inline const char *zl3vni_sysmac2str(zebra_l3vni_t *zl3vni, char *buf,
197 int size)
198 {
199 char *ptr;
200
201 if (!buf)
202 ptr = XMALLOC(MTYPE_TMP, ETHER_ADDR_STRLEN * sizeof(char));
203 else {
204 assert(size >= ETHER_ADDR_STRLEN);
205 ptr = buf;
206 }
207
208 if (zl3vni->svi_if)
209 snprintf(ptr, (ETHER_ADDR_STRLEN),
210 "%02x:%02x:%02x:%02x:%02x:%02x",
211 (uint8_t)zl3vni->svi_if->hw_addr[0],
212 (uint8_t)zl3vni->svi_if->hw_addr[1],
213 (uint8_t)zl3vni->svi_if->hw_addr[2],
214 (uint8_t)zl3vni->svi_if->hw_addr[3],
215 (uint8_t)zl3vni->svi_if->hw_addr[4],
216 (uint8_t)zl3vni->svi_if->hw_addr[5]);
217 else
218 snprintf(ptr, ETHER_ADDR_STRLEN, "None");
219
220 return ptr;
221 }
222
223 /*
224 * l3-vni is oper up when:
225 * 0. if EVPN is enabled (advertise-all-vni cfged)
226 * 1. it is associated to a vxlan-intf
227 * 2. Associated vxlan-intf is oper up
228 * 3. it is associated to an SVI
229 * 4. associated SVI is oper up
230 */
231 static inline int is_l3vni_oper_up(zebra_l3vni_t *zl3vni)
232 {
233 return (is_evpn_enabled() && zl3vni && (zl3vni->vrf_id != VRF_UNKNOWN)
234 && zl3vni->vxlan_if && if_is_operative(zl3vni->vxlan_if)
235 && zl3vni->svi_if && if_is_operative(zl3vni->svi_if));
236 }
237
238 static inline const char *zl3vni_state2str(zebra_l3vni_t *zl3vni)
239 {
240 if (!zl3vni)
241 return NULL;
242
243 if (is_l3vni_oper_up(zl3vni))
244 return "Up";
245 else
246 return "Down";
247
248 return NULL;
249 }
250
251 static inline vrf_id_t zl3vni_vrf_id(zebra_l3vni_t *zl3vni)
252 {
253 return zl3vni->vrf_id;
254 }
255
256 static inline void zl3vni_get_svi_rmac(zebra_l3vni_t *zl3vni,
257 struct ethaddr *rmac)
258 {
259 if (!zl3vni)
260 return;
261
262 if (!is_l3vni_oper_up(zl3vni))
263 return;
264
265 if (zl3vni->svi_if && if_is_operative(zl3vni->svi_if))
266 memcpy(rmac->octet, zl3vni->svi_if->hw_addr, ETH_ALEN);
267 }
268
269 struct host_rb_entry {
270 RB_ENTRY(host_rb_entry) hl_entry;
271
272 struct prefix p;
273 };
274
275 RB_HEAD(host_rb_tree_entry, host_rb_entry);
276 RB_PROTOTYPE(host_rb_tree_entry, host_rb_entry, hl_entry,
277 host_rb_entry_compare);
278 /*
279 * MAC hash table.
280 *
281 * This table contains the MAC addresses pertaining to this VNI.
282 * This includes local MACs learnt on an attached VLAN that maps
283 * to this VNI as well as remote MACs learnt and installed by BGP.
284 * Local MACs will be known either on a VLAN sub-interface or
285 * on (port, VLAN); however, it is sufficient for zebra to maintain
286 * against the VNI i.e., it does not need to retain the local "port"
287 * information. The correct VNI will be obtained as zebra maintains
288 * the mapping (of VLAN to VNI).
289 */
290 struct zebra_mac_t_ {
291 /* MAC address. */
292 struct ethaddr macaddr;
293
294 uint32_t flags;
295 #define ZEBRA_MAC_LOCAL 0x01
296 #define ZEBRA_MAC_REMOTE 0x02
297 #define ZEBRA_MAC_AUTO 0x04 /* Auto created for neighbor. */
298 #define ZEBRA_MAC_STICKY 0x08 /* Static MAC */
299 #define ZEBRA_MAC_REMOTE_RMAC 0x10 /* remote router mac */
300 #define ZEBRA_MAC_DEF_GW 0x20
301 /* remote VTEP advertised MAC as default GW */
302 #define ZEBRA_MAC_REMOTE_DEF_GW 0x40
303 #define ZEBRA_MAC_DUPLICATE 0x80
304
305 /* back pointer to zvni */
306 zebra_vni_t *zvni;
307
308 /* Local or remote info. */
309 union {
310 struct {
311 ifindex_t ifindex;
312 vlanid_t vid;
313 } local;
314
315 struct in_addr r_vtep_ip;
316 } fwd_info;
317
318 /* Mobility sequence numbers associated with this entry. */
319 uint32_t rem_seq;
320 uint32_t loc_seq;
321
322 /* List of neigh associated with this mac */
323 struct list *neigh_list;
324
325 /* list of hosts pointing to this remote RMAC */
326 struct host_rb_tree_entry host_rb;
327
328 /* Duplicate mac detection */
329 uint32_t dad_count;
330
331 struct thread *dad_mac_auto_recovery_timer;
332
333 struct timeval detect_start_time;
334
335 time_t dad_dup_detect_time;
336 };
337
338 /*
339 * Context for MAC hash walk - used by callbacks.
340 */
341 struct mac_walk_ctx {
342 zebra_vni_t *zvni; /* VNI hash */
343 struct zebra_vrf *zvrf; /* VRF - for client notification. */
344 int uninstall; /* uninstall from kernel? */
345 int upd_client; /* uninstall from client? */
346
347 uint32_t flags;
348 #define DEL_LOCAL_MAC 0x1
349 #define DEL_REMOTE_MAC 0x2
350 #define DEL_ALL_MAC (DEL_LOCAL_MAC | DEL_REMOTE_MAC)
351 #define DEL_REMOTE_MAC_FROM_VTEP 0x4
352 #define SHOW_REMOTE_MAC_FROM_VTEP 0x8
353
354 struct in_addr r_vtep_ip; /* To walk MACs from specific VTEP */
355
356 struct vty *vty; /* Used by VTY handlers */
357 uint32_t count; /* Used by VTY handlers */
358 struct json_object *json; /* Used for JSON Output */
359 bool print_dup; /* Used to print dup addr list */
360 };
361
362 struct rmac_walk_ctx {
363 struct vty *vty;
364 struct json_object *json;
365 };
366
367 #define IS_ZEBRA_NEIGH_ACTIVE(n) (n->state == ZEBRA_NEIGH_ACTIVE)
368
369 #define IS_ZEBRA_NEIGH_INACTIVE(n) (n->state == ZEBRA_NEIGH_INACTIVE)
370
371 #define ZEBRA_NEIGH_SET_ACTIVE(n) n->state = ZEBRA_NEIGH_ACTIVE
372
373 #define ZEBRA_NEIGH_SET_INACTIVE(n) n->state = ZEBRA_NEIGH_INACTIVE
374
375 /*
376 * Neighbor hash table.
377 *
378 * This table contains the neighbors (IP to MAC bindings) pertaining to
379 * this VNI. This includes local neighbors learnt on the attached VLAN
380 * device that maps to this VNI as well as remote neighbors learnt and
381 * installed by BGP.
382 * Local neighbors will be known against the VLAN device (SVI); however,
383 * it is sufficient for zebra to maintain against the VNI. The correct
384 * VNI will be obtained as zebra maintains the mapping (of VLAN to VNI).
385 */
386 struct zebra_neigh_t_ {
387 /* IP address. */
388 struct ipaddr ip;
389
390 /* MAC address. */
391 struct ethaddr emac;
392
393 /* Underlying interface. */
394 ifindex_t ifindex;
395
396 zebra_vni_t *zvni;
397
398 uint32_t flags;
399 #define ZEBRA_NEIGH_LOCAL 0x01
400 #define ZEBRA_NEIGH_REMOTE 0x02
401 #define ZEBRA_NEIGH_REMOTE_NH 0x04 /* neigh entry for remote vtep */
402 #define ZEBRA_NEIGH_DEF_GW 0x08
403 #define ZEBRA_NEIGH_ROUTER_FLAG 0x10
404 #define ZEBRA_NEIGH_DUPLICATE 0x20
405 #define ZEBRA_NEIGH_SVI_IP 0x40
406
407 enum zebra_neigh_state state;
408
409 /* Remote VTEP IP - applicable only for remote neighbors. */
410 struct in_addr r_vtep_ip;
411
412 /*
413 * Mobility sequence numbers associated with this entry. The rem_seq
414 * represents the sequence number from the client (BGP) for the most
415 * recent add or update of this entry while the loc_seq represents
416 * the sequence number informed (or to be informed) by zebra to BGP
417 * for this entry.
418 */
419 uint32_t rem_seq;
420 uint32_t loc_seq;
421
422 /* list of hosts pointing to this remote NH entry */
423 struct host_rb_tree_entry host_rb;
424
425 /* Duplicate ip detection */
426 uint32_t dad_count;
427
428 struct thread *dad_ip_auto_recovery_timer;
429
430 struct timeval detect_start_time;
431
432 time_t dad_dup_detect_time;
433 };
434
435 /*
436 * Context for neighbor hash walk - used by callbacks.
437 */
438 struct neigh_walk_ctx {
439 zebra_vni_t *zvni; /* VNI hash */
440 struct zebra_vrf *zvrf; /* VRF - for client notification. */
441 int uninstall; /* uninstall from kernel? */
442 int upd_client; /* uninstall from client? */
443
444 uint32_t flags;
445 #define DEL_LOCAL_NEIGH 0x1
446 #define DEL_REMOTE_NEIGH 0x2
447 #define DEL_ALL_NEIGH (DEL_LOCAL_NEIGH | DEL_REMOTE_NEIGH)
448 #define DEL_REMOTE_NEIGH_FROM_VTEP 0x4
449 #define SHOW_REMOTE_NEIGH_FROM_VTEP 0x8
450
451 struct in_addr r_vtep_ip; /* To walk neighbors from specific VTEP */
452
453 struct vty *vty; /* Used by VTY handlers */
454 uint32_t count; /* Used by VTY handlers */
455 uint8_t addr_width; /* Used by VTY handlers */
456 struct json_object *json; /* Used for JSON Output */
457 };
458
459 /* context for neigh hash walk - update l3vni and rmac */
460 struct neigh_l3info_walk_ctx {
461
462 zebra_vni_t *zvni;
463 zebra_l3vni_t *zl3vni;
464 int add;
465 };
466
467 struct nh_walk_ctx {
468
469 struct vty *vty;
470 struct json_object *json;
471 };
472
473 extern zebra_l3vni_t *zl3vni_from_vrf(vrf_id_t vrf_id);
474 extern struct interface *zl3vni_map_to_vxlan_if(zebra_l3vni_t *zl3vni);
475 extern struct interface *zl3vni_map_to_svi_if(zebra_l3vni_t *zl3vni);
476 extern struct interface *zl3vni_map_to_mac_vlan_if(zebra_l3vni_t *zl3vni);
477
478 DECLARE_HOOK(zebra_rmac_update, (zebra_mac_t *rmac, zebra_l3vni_t *zl3vni,
479 bool delete, const char *reason), (rmac, zl3vni, delete, reason))
480
481
482 #ifdef __cplusplus
483 }
484 #endif
485
486 /*
487 * Multicast hash table.
488 *
489 * This table contains -
490 * 1. The (S, G) entries used for encapsulating and forwarding BUM traffic.
491 * S is the local VTEP-IP and G is a BUM mcast group address.
492 * 2. The (X, G) entries used for terminating a BUM flow.
493 * Multiple L2-VNIs can share the same MDT hence the need to maintain
494 * an aggregated table that pimd can consume without much
495 * re-interpretation.
496 */
497 typedef struct zebra_vxlan_sg_ {
498 struct zebra_vrf *zvrf;
499
500 struct prefix_sg sg;
501 char sg_str[PREFIX_SG_STR_LEN];
502
503 /* For SG - num of L2 VNIs using this entry for sending BUM traffic */
504 /* For XG - num of SG using this as parent */
505 uint32_t ref_cnt;
506 } zebra_vxlan_sg_t;
507
508 #endif /* _ZEBRA_VXLAN_PRIVATE_H */