1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Zebra EVPN for VxLAN code
4 * Copyright (C) 2016, 2017 Cumulus Networks, Inc.
21 #include <linux/neighbour.h>
23 #include "lib/printfrr.h"
25 #include "zebra/zebra_router.h"
26 #include "zebra/debug.h"
27 #include "zebra/interface.h"
28 #include "zebra/rib.h"
30 #include "zebra/rt_netlink.h"
31 #include "zebra/zebra_errors.h"
32 #include "zebra/zebra_l2.h"
33 #include "zebra/zebra_ns.h"
34 #include "zebra/zebra_vrf.h"
35 #include "zebra/zebra_vxlan.h"
36 #include "zebra/zebra_evpn.h"
37 #include "zebra/zebra_evpn_mac.h"
38 #include "zebra/zebra_evpn_neigh.h"
39 #include "zebra/zebra_vxlan_private.h"
40 #include "zebra/zebra_evpn_mh.h"
41 #include "zebra/zebra_evpn_vxlan.h"
42 #include "zebra/zebra_router.h"
44 DEFINE_MTYPE_STATIC(ZEBRA
, HOST_PREFIX
, "host prefix");
45 DEFINE_MTYPE_STATIC(ZEBRA
, ZL3VNI
, "L3 VNI hash");
46 DEFINE_MTYPE_STATIC(ZEBRA
, L3VNI_MAC
, "EVPN L3VNI MAC");
47 DEFINE_MTYPE_STATIC(ZEBRA
, L3NEIGH
, "EVPN Neighbor");
48 DEFINE_MTYPE_STATIC(ZEBRA
, ZVXLAN_SG
, "zebra VxLAN multicast group");
49 DEFINE_MTYPE_STATIC(ZEBRA
, EVPN_VTEP
, "zebra VxLAN VTEP IP");
51 DEFINE_HOOK(zebra_rmac_update
,
52 (struct zebra_mac
* rmac
, struct zebra_l3vni
*zl3vni
, bool delete,
54 (rmac
, zl3vni
, delete, reason
));
57 static bool accept_bgp_seq
= true;
59 /* static function declarations */
60 static void zevpn_print_neigh_hash_all_evpn(struct hash_bucket
*bucket
,
62 static void zl3vni_print_nh(struct zebra_neigh
*n
, struct vty
*vty
,
64 static void zl3vni_print_rmac(struct zebra_mac
*zrmac
, struct vty
*vty
,
66 static void zevpn_print_mac_hash_all_evpn(struct hash_bucket
*bucket
, void *ctxt
);
68 /* l3-vni next-hop neigh related APIs */
69 static struct zebra_neigh
*zl3vni_nh_lookup(struct zebra_l3vni
*zl3vni
,
70 const struct ipaddr
*ip
);
71 static void *zl3vni_nh_alloc(void *p
);
72 static struct zebra_neigh
*zl3vni_nh_add(struct zebra_l3vni
*zl3vni
,
73 const struct ipaddr
*vtep_ip
,
74 const struct ethaddr
*rmac
);
75 static int zl3vni_nh_del(struct zebra_l3vni
*zl3vni
, struct zebra_neigh
*n
);
76 static int zl3vni_nh_install(struct zebra_l3vni
*zl3vni
, struct zebra_neigh
*n
);
77 static int zl3vni_nh_uninstall(struct zebra_l3vni
*zl3vni
,
78 struct zebra_neigh
*n
);
80 /* l3-vni rmac related APIs */
81 static void zl3vni_print_rmac_hash(struct hash_bucket
*, void *);
82 static struct zebra_mac
*zl3vni_rmac_lookup(struct zebra_l3vni
*zl3vni
,
83 const struct ethaddr
*rmac
);
84 static void *zl3vni_rmac_alloc(void *p
);
85 static struct zebra_mac
*zl3vni_rmac_add(struct zebra_l3vni
*zl3vni
,
86 const struct ethaddr
*rmac
);
87 static int zl3vni_rmac_del(struct zebra_l3vni
*zl3vni
, struct zebra_mac
*zrmac
);
88 static int zl3vni_rmac_install(struct zebra_l3vni
*zl3vni
,
89 struct zebra_mac
*zrmac
);
90 static int zl3vni_rmac_uninstall(struct zebra_l3vni
*zl3vni
,
91 struct zebra_mac
*zrmac
);
93 /* l3-vni related APIs*/
94 static void *zl3vni_alloc(void *p
);
95 static struct zebra_l3vni
*zl3vni_add(vni_t vni
, vrf_id_t vrf_id
);
96 static int zl3vni_del(struct zebra_l3vni
*zl3vni
);
97 static void zebra_vxlan_process_l3vni_oper_up(struct zebra_l3vni
*zl3vni
);
98 static void zebra_vxlan_process_l3vni_oper_down(struct zebra_l3vni
*zl3vni
);
100 static void zevpn_build_hash_table(void);
101 static unsigned int zebra_vxlan_sg_hash_key_make(const void *p
);
102 static bool zebra_vxlan_sg_hash_eq(const void *p1
, const void *p2
);
103 static void zebra_vxlan_sg_do_deref(struct zebra_vrf
*zvrf
,
104 struct in_addr sip
, struct in_addr mcast_grp
);
105 static struct zebra_vxlan_sg
*zebra_vxlan_sg_do_ref(struct zebra_vrf
*vrf
,
107 struct in_addr mcast_grp
);
108 static void zebra_vxlan_sg_deref(struct in_addr local_vtep_ip
,
109 struct in_addr mcast_grp
);
110 static void zebra_vxlan_sg_ref(struct in_addr local_vtep_ip
,
111 struct in_addr mcast_grp
);
112 static void zebra_vxlan_cleanup_sg_table(struct zebra_vrf
*zvrf
);
114 bool zebra_evpn_do_dup_addr_detect(struct zebra_vrf
*zvrf
)
116 return zvrf
->dup_addr_detect
&& zebra_evpn_mh_do_dup_addr_detect();
119 /* Private functions */
120 static int host_rb_entry_compare(const struct host_rb_entry
*hle1
,
121 const struct host_rb_entry
*hle2
)
123 if (hle1
->p
.family
< hle2
->p
.family
)
126 if (hle1
->p
.family
> hle2
->p
.family
)
129 if (hle1
->p
.prefixlen
< hle2
->p
.prefixlen
)
132 if (hle1
->p
.prefixlen
> hle2
->p
.prefixlen
)
135 if (hle1
->p
.family
== AF_INET
) {
136 if (hle1
->p
.u
.prefix4
.s_addr
< hle2
->p
.u
.prefix4
.s_addr
)
139 if (hle1
->p
.u
.prefix4
.s_addr
> hle2
->p
.u
.prefix4
.s_addr
)
143 } else if (hle1
->p
.family
== AF_INET6
) {
144 return memcmp(&hle1
->p
.u
.prefix6
, &hle2
->p
.u
.prefix6
,
146 } else if (hle1
->p
.family
== AF_EVPN
) {
150 /* two (v4/v6) dummy prefixes of route_type BGP_EVPN_AD_ROUTE
151 * are used for all nexthops associated with a non-zero ESI
153 family1
= is_evpn_prefix_ipaddr_v4(
154 (const struct prefix_evpn
*)&hle1
->p
)
157 family2
= is_evpn_prefix_ipaddr_v4(
158 (const struct prefix_evpn
*)&hle2
->p
)
163 if (family1
< family2
)
166 if (family1
> family2
)
171 zlog_debug("%s: Unexpected family type: %d", __func__
,
176 RB_GENERATE(host_rb_tree_entry
, host_rb_entry
, hl_entry
, host_rb_entry_compare
);
178 static uint32_t rb_host_count(struct host_rb_tree_entry
*hrbe
)
180 struct host_rb_entry
*hle
;
183 RB_FOREACH (hle
, host_rb_tree_entry
, hrbe
)
189 static int l3vni_rmac_nh_list_cmp(void *p1
, void *p2
)
191 const struct ipaddr
*vtep_ip1
= p1
;
192 const struct ipaddr
*vtep_ip2
= p2
;
194 return !ipaddr_cmp(vtep_ip1
, vtep_ip2
);
197 static void l3vni_rmac_nh_free(struct ipaddr
*vtep_ip
)
199 XFREE(MTYPE_EVPN_VTEP
, vtep_ip
);
202 static void l3vni_rmac_nh_list_nh_delete(struct zebra_l3vni
*zl3vni
,
203 struct zebra_mac
*zrmac
,
204 struct ipaddr
*vtep_ip
)
206 struct listnode
*node
= NULL
, *nnode
= NULL
;
207 struct ipaddr
*vtep
= NULL
;
209 for (ALL_LIST_ELEMENTS(zrmac
->nh_list
, node
, nnode
, vtep
)) {
210 if (ipaddr_cmp(vtep
, vtep_ip
) == 0)
215 l3vni_rmac_nh_free(vtep
);
216 list_delete_node(zrmac
->nh_list
, node
);
221 * Print neighbors for all EVPN.
223 static void zevpn_print_neigh_hash_all_evpn(struct hash_bucket
*bucket
,
227 json_object
*json
= NULL
, *json_evpn
= NULL
;
228 struct zebra_evpn
*zevpn
;
230 struct neigh_walk_ctx wctx
;
231 char vni_str
[VNI_STR_LEN
];
234 vty
= (struct vty
*)args
[0];
235 json
= (json_object
*)args
[1];
236 print_dup
= (uint32_t)(uintptr_t)args
[2];
238 zevpn
= (struct zebra_evpn
*)bucket
->data
;
240 num_neigh
= hashcount(zevpn
->neigh_table
);
243 num_neigh
= num_dup_detected_neighs(zevpn
);
247 "\nVNI %u #ARP (IPv4 and IPv6, local and remote) %u\n\n",
248 zevpn
->vni
, num_neigh
);
250 json_evpn
= json_object_new_object();
251 json_object_int_add(json_evpn
, "numArpNd", num_neigh
);
252 snprintf(vni_str
, VNI_STR_LEN
, "%u", zevpn
->vni
);
257 json_object_object_add(json
, vni_str
, json_evpn
);
261 /* Since we have IPv6 addresses to deal with which can vary widely in
262 * size, we try to be a bit more elegant in display by first computing
265 memset(&wctx
, 0, sizeof(wctx
));
268 wctx
.addr_width
= 15;
269 wctx
.json
= json_evpn
;
270 hash_iterate(zevpn
->neigh_table
, zebra_evpn_find_neigh_addr_width
,
274 zebra_evpn_print_neigh_hdr(vty
, &wctx
);
277 hash_iterate(zevpn
->neigh_table
,
278 zebra_evpn_print_dad_neigh_hash
, &wctx
);
280 hash_iterate(zevpn
->neigh_table
, zebra_evpn_print_neigh_hash
,
284 json_object_object_add(json
, vni_str
, json_evpn
);
288 * Print neighbors for all EVPNs in detail.
290 static void zevpn_print_neigh_hash_all_evpn_detail(struct hash_bucket
*bucket
,
294 json_object
*json
= NULL
, *json_evpn
= NULL
;
295 struct zebra_evpn
*zevpn
;
297 struct neigh_walk_ctx wctx
;
298 char vni_str
[VNI_STR_LEN
];
301 vty
= (struct vty
*)args
[0];
302 json
= (json_object
*)args
[1];
303 print_dup
= (uint32_t)(uintptr_t)args
[2];
305 zevpn
= (struct zebra_evpn
*)bucket
->data
;
308 vty_out(vty
, "{}\n");
311 num_neigh
= hashcount(zevpn
->neigh_table
);
313 if (print_dup
&& num_dup_detected_neighs(zevpn
) == 0)
318 "\nVNI %u #ARP (IPv4 and IPv6, local and remote) %u\n\n",
319 zevpn
->vni
, num_neigh
);
321 json_evpn
= json_object_new_object();
322 json_object_int_add(json_evpn
, "numArpNd", num_neigh
);
323 snprintf(vni_str
, VNI_STR_LEN
, "%u", zevpn
->vni
);
327 json_object_object_add(json
, vni_str
, json_evpn
);
331 memset(&wctx
, 0, sizeof(wctx
));
334 wctx
.addr_width
= 15;
335 wctx
.json
= json_evpn
;
338 hash_iterate(zevpn
->neigh_table
,
339 zebra_evpn_print_dad_neigh_hash_detail
, &wctx
);
341 hash_iterate(zevpn
->neigh_table
,
342 zebra_evpn_print_neigh_hash_detail
, &wctx
);
345 json_object_object_add(json
, vni_str
, json_evpn
);
348 /* print a specific next hop for an l3vni */
349 static void zl3vni_print_nh(struct zebra_neigh
*n
, struct vty
*vty
,
352 char buf1
[ETHER_ADDR_STRLEN
];
353 char buf2
[INET6_ADDRSTRLEN
];
354 json_object
*json_hosts
= NULL
;
355 struct host_rb_entry
*hle
;
358 vty_out(vty
, "Ip: %s\n",
359 ipaddr2str(&n
->ip
, buf2
, sizeof(buf2
)));
360 vty_out(vty
, " RMAC: %s\n",
361 prefix_mac2str(&n
->emac
, buf1
, sizeof(buf1
)));
362 vty_out(vty
, " Refcount: %d\n",
363 rb_host_count(&n
->host_rb
));
364 vty_out(vty
, " Prefixes:\n");
365 RB_FOREACH (hle
, host_rb_tree_entry
, &n
->host_rb
)
366 vty_out(vty
, " %pFX\n", &hle
->p
);
368 json_hosts
= json_object_new_array();
369 json_object_string_add(
370 json
, "ip", ipaddr2str(&(n
->ip
), buf2
, sizeof(buf2
)));
371 json_object_string_add(
373 prefix_mac2str(&n
->emac
, buf2
, sizeof(buf2
)));
374 json_object_int_add(json
, "refCount",
375 rb_host_count(&n
->host_rb
));
376 RB_FOREACH (hle
, host_rb_tree_entry
, &n
->host_rb
)
377 json_object_array_add(json_hosts
,
378 json_object_new_string(prefix2str(
379 &hle
->p
, buf2
, sizeof(buf2
))));
380 json_object_object_add(json
, "prefixList", json_hosts
);
384 /* Print a specific RMAC entry */
385 static void zl3vni_print_rmac(struct zebra_mac
*zrmac
, struct vty
*vty
,
388 struct listnode
*node
= NULL
;
389 struct ipaddr
*vtep
= NULL
;
390 json_object
*json_nhs
= NULL
;
393 vty_out(vty
, "MAC: %pEA\n", &zrmac
->macaddr
);
394 vty_out(vty
, " Remote VTEP: %pI4\n",
395 &zrmac
->fwd_info
.r_vtep_ip
);
397 json_nhs
= json_object_new_array();
398 json_object_string_addf(json
, "routerMac", "%pEA",
400 json_object_string_addf(json
, "vtepIp", "%pI4",
401 &zrmac
->fwd_info
.r_vtep_ip
);
402 for (ALL_LIST_ELEMENTS_RO(zrmac
->nh_list
, node
, vtep
)) {
403 json_object_array_add(json_nhs
, json_object_new_stringf(
406 json_object_object_add(json
, "nexthops", json_nhs
);
411 * Print MACs for all EVPNs.
413 static void zevpn_print_mac_hash_all_evpn(struct hash_bucket
*bucket
, void *ctxt
)
416 json_object
*json
= NULL
, *json_evpn
= NULL
;
417 json_object
*json_mac
= NULL
;
418 struct zebra_evpn
*zevpn
;
420 struct mac_walk_ctx
*wctx
= ctxt
;
421 char vni_str
[VNI_STR_LEN
];
426 zevpn
= (struct zebra_evpn
*)bucket
->data
;
429 /*We are iterating over a new VNI, set the count to 0*/
432 num_macs
= num_valid_macs(zevpn
);
437 num_macs
= num_dup_detected_macs(zevpn
);
440 json_evpn
= json_object_new_object();
441 json_mac
= json_object_new_object();
442 snprintf(vni_str
, VNI_STR_LEN
, "%u", zevpn
->vni
);
445 if (!CHECK_FLAG(wctx
->flags
, SHOW_REMOTE_MAC_FROM_VTEP
)) {
447 vty_out(vty
, "\nVNI %u #MACs (local and remote) %u\n\n",
448 zevpn
->vni
, num_macs
);
450 "Flags: N=sync-neighs, I=local-inactive, P=peer-active, X=peer-proxy\n");
451 vty_out(vty
, "%-17s %-6s %-5s %-30s %-5s %s\n", "MAC",
452 "Type", "Flags", "Intf/Remote ES/VTEP",
455 json_object_int_add(json_evpn
, "numMacs", num_macs
);
460 json_object_int_add(json_evpn
, "numMacs", num_macs
);
461 json_object_object_add(json
, vni_str
, json_evpn
);
466 /* assign per-evpn to wctx->json object to fill macs
467 * under the evpn. Re-assign primary json object to fill
468 * next evpn information.
470 wctx
->json
= json_mac
;
472 hash_iterate(zevpn
->mac_table
, zebra_evpn_print_dad_mac_hash
,
475 hash_iterate(zevpn
->mac_table
, zebra_evpn_print_mac_hash
, wctx
);
479 json_object_object_add(json_evpn
, "macs", json_mac
);
480 json_object_object_add(json
, vni_str
, json_evpn
);
485 * Print MACs in detail for all EVPNs.
487 static void zevpn_print_mac_hash_all_evpn_detail(struct hash_bucket
*bucket
,
491 json_object
*json
= NULL
, *json_evpn
= NULL
;
492 json_object
*json_mac
= NULL
;
493 struct zebra_evpn
*zevpn
;
495 struct mac_walk_ctx
*wctx
= ctxt
;
496 char vni_str
[VNI_STR_LEN
];
501 zevpn
= (struct zebra_evpn
*)bucket
->data
;
504 vty_out(vty
, "{}\n");
509 /*We are iterating over a new EVPN, set the count to 0*/
512 num_macs
= num_valid_macs(zevpn
);
516 if (wctx
->print_dup
&& (num_dup_detected_macs(zevpn
) == 0))
520 json_evpn
= json_object_new_object();
521 json_mac
= json_object_new_object();
522 snprintf(vni_str
, VNI_STR_LEN
, "%u", zevpn
->vni
);
525 if (!CHECK_FLAG(wctx
->flags
, SHOW_REMOTE_MAC_FROM_VTEP
)) {
527 vty_out(vty
, "\nVNI %u #MACs (local and remote) %u\n\n",
528 zevpn
->vni
, num_macs
);
530 json_object_int_add(json_evpn
, "numMacs", num_macs
);
532 /* assign per-evpn to wctx->json object to fill macs
533 * under the evpn. Re-assign primary json object to fill
534 * next evpn information.
536 wctx
->json
= json_mac
;
538 hash_iterate(zevpn
->mac_table
,
539 zebra_evpn_print_dad_mac_hash_detail
, wctx
);
541 hash_iterate(zevpn
->mac_table
, zebra_evpn_print_mac_hash_detail
,
546 json_object_object_add(json_evpn
, "macs", json_mac
);
547 json_object_object_add(json
, vni_str
, json_evpn
);
551 static void zl3vni_print_nh_hash(struct hash_bucket
*bucket
, void *ctx
)
553 struct nh_walk_ctx
*wctx
= NULL
;
554 struct vty
*vty
= NULL
;
555 struct json_object
*json_evpn
= NULL
;
556 struct json_object
*json_nh
= NULL
;
557 struct zebra_neigh
*n
= NULL
;
558 char buf1
[ETHER_ADDR_STRLEN
];
559 char buf2
[INET6_ADDRSTRLEN
];
561 wctx
= (struct nh_walk_ctx
*)ctx
;
563 json_evpn
= wctx
->json
;
565 json_nh
= json_object_new_object();
566 n
= (struct zebra_neigh
*)bucket
->data
;
569 vty_out(vty
, "%-15s %-17s\n",
570 ipaddr2str(&(n
->ip
), buf2
, sizeof(buf2
)),
571 prefix_mac2str(&n
->emac
, buf1
, sizeof(buf1
)));
573 json_object_string_add(json_nh
, "nexthopIp",
574 ipaddr2str(&n
->ip
, buf2
, sizeof(buf2
)));
575 json_object_string_add(
576 json_nh
, "routerMac",
577 prefix_mac2str(&n
->emac
, buf1
, sizeof(buf1
)));
578 json_object_object_add(json_evpn
,
579 ipaddr2str(&(n
->ip
), buf2
, sizeof(buf2
)),
584 static void zl3vni_print_nh_hash_all_vni(struct hash_bucket
*bucket
,
587 struct vty
*vty
= NULL
;
588 json_object
*json
= NULL
;
589 json_object
*json_evpn
= NULL
;
590 struct zebra_l3vni
*zl3vni
= NULL
;
592 struct nh_walk_ctx wctx
;
593 char vni_str
[VNI_STR_LEN
];
595 vty
= (struct vty
*)args
[0];
596 json
= (struct json_object
*)args
[1];
598 zl3vni
= (struct zebra_l3vni
*)bucket
->data
;
600 num_nh
= hashcount(zl3vni
->nh_table
);
605 json_evpn
= json_object_new_object();
606 snprintf(vni_str
, VNI_STR_LEN
, "%u", zl3vni
->vni
);
610 vty_out(vty
, "\nVNI %u #Next-Hops %u\n\n", zl3vni
->vni
, num_nh
);
611 vty_out(vty
, "%-15s %-17s\n", "IP", "RMAC");
613 json_object_int_add(json_evpn
, "numNextHops", num_nh
);
615 memset(&wctx
, 0, sizeof(wctx
));
617 wctx
.json
= json_evpn
;
618 hash_iterate(zl3vni
->nh_table
, zl3vni_print_nh_hash
, &wctx
);
620 json_object_object_add(json
, vni_str
, json_evpn
);
623 static void zl3vni_print_rmac_hash_all_vni(struct hash_bucket
*bucket
,
626 struct vty
*vty
= NULL
;
627 json_object
*json
= NULL
;
628 json_object
*json_evpn
= NULL
;
629 struct zebra_l3vni
*zl3vni
= NULL
;
631 struct rmac_walk_ctx wctx
;
632 char vni_str
[VNI_STR_LEN
];
634 vty
= (struct vty
*)args
[0];
635 json
= (struct json_object
*)args
[1];
637 zl3vni
= (struct zebra_l3vni
*)bucket
->data
;
639 num_rmacs
= hashcount(zl3vni
->rmac_table
);
644 json_evpn
= json_object_new_object();
645 snprintf(vni_str
, VNI_STR_LEN
, "%u", zl3vni
->vni
);
649 vty_out(vty
, "\nVNI %u #RMACs %u\n\n", zl3vni
->vni
, num_rmacs
);
650 vty_out(vty
, "%-17s %-21s\n", "RMAC", "Remote VTEP");
652 json_object_int_add(json_evpn
, "numRmacs", num_rmacs
);
654 /* assign per-vni to wctx->json object to fill macs
655 * under the vni. Re-assign primary json object to fill
656 * next vni information.
658 memset(&wctx
, 0, sizeof(wctx
));
660 wctx
.json
= json_evpn
;
661 hash_iterate(zl3vni
->rmac_table
, zl3vni_print_rmac_hash
, &wctx
);
663 json_object_object_add(json
, vni_str
, json_evpn
);
666 static void zl3vni_print_rmac_hash(struct hash_bucket
*bucket
, void *ctx
)
668 struct zebra_mac
*zrmac
= NULL
;
669 struct rmac_walk_ctx
*wctx
= NULL
;
670 struct vty
*vty
= NULL
;
671 struct json_object
*json
= NULL
;
672 struct json_object
*json_rmac
= NULL
;
673 char buf
[PREFIX_STRLEN
];
675 wctx
= (struct rmac_walk_ctx
*)ctx
;
679 json_rmac
= json_object_new_object();
680 zrmac
= (struct zebra_mac
*)bucket
->data
;
683 vty_out(vty
, "%-17s %-21pI4\n",
684 prefix_mac2str(&zrmac
->macaddr
, buf
, sizeof(buf
)),
685 &zrmac
->fwd_info
.r_vtep_ip
);
687 json_object_string_add(
688 json_rmac
, "routerMac",
689 prefix_mac2str(&zrmac
->macaddr
, buf
, sizeof(buf
)));
690 json_object_string_addf(json_rmac
, "vtepIp", "%pI4",
691 &zrmac
->fwd_info
.r_vtep_ip
);
692 json_object_object_add(
693 json
, prefix_mac2str(&zrmac
->macaddr
, buf
, sizeof(buf
)),
698 /* print a specific L3 VNI entry */
699 static void zl3vni_print(struct zebra_l3vni
*zl3vni
, void **ctx
)
701 char buf
[PREFIX_STRLEN
];
702 struct vty
*vty
= NULL
;
703 json_object
*json
= NULL
;
704 struct zebra_evpn
*zevpn
= NULL
;
705 json_object
*json_evpn_list
= NULL
;
706 struct listnode
*node
= NULL
, *nnode
= NULL
;
712 vty_out(vty
, "VNI: %u\n", zl3vni
->vni
);
713 vty_out(vty
, " Type: %s\n", "L3");
714 vty_out(vty
, " Tenant VRF: %s\n", zl3vni_vrf_name(zl3vni
));
715 vty_out(vty
, " Local Vtep Ip: %pI4\n",
716 &zl3vni
->local_vtep_ip
);
717 vty_out(vty
, " Vxlan-Intf: %s\n",
718 zl3vni_vxlan_if_name(zl3vni
));
719 vty_out(vty
, " SVI-If: %s\n", zl3vni_svi_if_name(zl3vni
));
720 vty_out(vty
, " State: %s\n", zl3vni_state2str(zl3vni
));
721 vty_out(vty
, " VNI Filter: %s\n",
722 CHECK_FLAG(zl3vni
->filter
, PREFIX_ROUTES_ONLY
)
723 ? "prefix-routes-only"
725 vty_out(vty
, " System MAC: %s\n",
726 zl3vni_sysmac2str(zl3vni
, buf
, sizeof(buf
)));
727 vty_out(vty
, " Router MAC: %s\n",
728 zl3vni_rmac2str(zl3vni
, buf
, sizeof(buf
)));
729 vty_out(vty
, " L2 VNIs: ");
730 for (ALL_LIST_ELEMENTS(zl3vni
->l2vnis
, node
, nnode
, zevpn
))
731 vty_out(vty
, "%u ", zevpn
->vni
);
734 json_evpn_list
= json_object_new_array();
735 json_object_int_add(json
, "vni", zl3vni
->vni
);
736 json_object_string_add(json
, "type", "L3");
737 #if CONFDATE > 20240210
738 CPP_NOTICE("Drop `vrf` from JSON outputs")
740 json_object_string_add(json
, "vrf", zl3vni_vrf_name(zl3vni
));
741 json_object_string_add(json
, "tenantVrf",
742 zl3vni_vrf_name(zl3vni
));
743 json_object_string_addf(json
, "localVtepIp", "%pI4",
744 &zl3vni
->local_vtep_ip
);
745 json_object_string_add(json
, "vxlanIntf",
746 zl3vni_vxlan_if_name(zl3vni
));
747 json_object_string_add(json
, "sviIntf",
748 zl3vni_svi_if_name(zl3vni
));
749 json_object_string_add(json
, "state", zl3vni_state2str(zl3vni
));
750 json_object_string_add(
752 zl3vni_sysmac2str(zl3vni
, buf
, sizeof(buf
)));
753 json_object_string_add(
755 zl3vni_rmac2str(zl3vni
, buf
, sizeof(buf
)));
756 json_object_string_add(
758 CHECK_FLAG(zl3vni
->filter
, PREFIX_ROUTES_ONLY
)
759 ? "prefix-routes-only"
761 for (ALL_LIST_ELEMENTS(zl3vni
->l2vnis
, node
, nnode
, zevpn
)) {
762 json_object_array_add(json_evpn_list
,
763 json_object_new_int(zevpn
->vni
));
765 json_object_object_add(json
, "l2Vnis", json_evpn_list
);
769 /* print a L3 VNI hash entry */
770 static void zl3vni_print_hash(struct hash_bucket
*bucket
, void *ctx
[])
772 struct vty
*vty
= NULL
;
773 json_object
*json
= NULL
;
774 json_object
*json_evpn
= NULL
;
775 struct zebra_l3vni
*zl3vni
= NULL
;
777 vty
= (struct vty
*)ctx
[0];
778 json
= (json_object
*)ctx
[1];
780 zl3vni
= (struct zebra_l3vni
*)bucket
->data
;
783 vty_out(vty
, "%-10u %-4s %-21s %-8lu %-8lu %-15s %-37s\n",
784 zl3vni
->vni
, "L3", zl3vni_vxlan_if_name(zl3vni
),
785 hashcount(zl3vni
->rmac_table
),
786 hashcount(zl3vni
->nh_table
), "n/a",
787 zl3vni_vrf_name(zl3vni
));
789 char vni_str
[VNI_STR_LEN
];
791 snprintf(vni_str
, VNI_STR_LEN
, "%u", zl3vni
->vni
);
792 json_evpn
= json_object_new_object();
793 json_object_int_add(json_evpn
, "vni", zl3vni
->vni
);
794 json_object_string_add(json_evpn
, "vxlanIf",
795 zl3vni_vxlan_if_name(zl3vni
));
796 json_object_int_add(json_evpn
, "numMacs",
797 hashcount(zl3vni
->rmac_table
));
798 json_object_int_add(json_evpn
, "numArpNd",
799 hashcount(zl3vni
->nh_table
));
800 json_object_string_add(json_evpn
, "numRemoteVteps", "n/a");
801 json_object_string_add(json_evpn
, "type", "L3");
802 json_object_string_add(json_evpn
, "tenantVrf",
803 zl3vni_vrf_name(zl3vni
));
804 json_object_object_add(json
, vni_str
, json_evpn
);
808 /* print a L3 VNI hash entry in detail*/
809 static void zl3vni_print_hash_detail(struct hash_bucket
*bucket
, void *data
)
811 struct vty
*vty
= NULL
;
812 struct zebra_l3vni
*zl3vni
= NULL
;
813 json_object
*json_array
= NULL
;
814 bool use_json
= false;
815 struct zebra_evpn_show
*zes
= data
;
818 json_array
= zes
->json
;
819 use_json
= zes
->use_json
;
821 zl3vni
= (struct zebra_l3vni
*)bucket
->data
;
823 zebra_vxlan_print_vni(vty
, zes
->zvrf
, zl3vni
->vni
,
824 use_json
, json_array
);
830 static int zvni_map_to_svi_ns(struct ns
*ns
,
834 struct zebra_ns
*zns
= ns
->info
;
835 struct route_node
*rn
;
836 struct zebra_from_svi_param
*in_param
=
837 (struct zebra_from_svi_param
*)_in_param
;
838 struct zebra_l2info_vlan
*vl
;
839 struct interface
*tmp_if
= NULL
;
840 struct interface
**p_ifp
= (struct interface
**)_p_ifp
;
841 struct zebra_if
*zif
;
843 assert(in_param
&& p_ifp
);
845 /* TODO: Optimize with a hash. */
846 for (rn
= route_top(zns
->if_table
); rn
; rn
= route_next(rn
)) {
847 tmp_if
= (struct interface
*)rn
->info
;
848 /* Check oper status of the SVI. */
849 if (!tmp_if
|| !if_is_operative(tmp_if
))
852 if (!zif
|| zif
->zif_type
!= ZEBRA_IF_VLAN
853 || zif
->link
!= in_param
->br_if
)
855 vl
= (struct zebra_l2info_vlan
*)&zif
->l2info
.vl
;
857 if (vl
->vid
== in_param
->vid
) {
862 return NS_WALK_CONTINUE
;
865 /* Map to SVI on bridge corresponding to specified VLAN. This can be one
867 * (a) In the case of a VLAN-aware bridge, the SVI is a L3 VLAN interface
868 * linked to the bridge
869 * (b) In the case of a VLAN-unaware bridge, the SVI is the bridge interface
872 struct interface
*zvni_map_to_svi(vlanid_t vid
, struct interface
*br_if
)
874 struct interface
*tmp_if
= NULL
;
875 struct zebra_if
*zif
;
876 struct zebra_l2info_bridge
*br
;
877 struct zebra_from_svi_param in_param
;
878 struct interface
**p_ifp
;
879 /* Defensive check, caller expected to invoke only with valid bridge. */
883 /* Determine if bridge is VLAN-aware or not */
886 br
= &zif
->l2info
.br
;
887 in_param
.bridge_vlan_aware
= br
->vlan_aware
;
888 /* Check oper status of the SVI. */
889 if (!in_param
.bridge_vlan_aware
)
890 return if_is_operative(br_if
) ? br_if
: NULL
;
893 in_param
.br_if
= br_if
;
896 /* Identify corresponding VLAN interface. */
897 ns_walk_func(zvni_map_to_svi_ns
, (void *)&in_param
,
902 static int zebra_evpn_vxlan_del(struct zebra_evpn
*zevpn
)
904 zevpn_vxlan_if_set(zevpn
, zevpn
->vxlan_if
, false /* set */);
906 /* Remove references to the BUM mcast grp */
907 zebra_vxlan_sg_deref(zevpn
->local_vtep_ip
, zevpn
->mcast_grp
);
909 return zebra_evpn_del(zevpn
);
912 static int zevpn_build_hash_table_zns(struct ns
*ns
,
913 void *param_in
__attribute__((unused
)),
914 void **param_out
__attribute__((unused
)))
916 struct zebra_ns
*zns
= ns
->info
;
917 struct route_node
*rn
;
918 struct interface
*ifp
;
919 struct zebra_vrf
*zvrf
;
921 zvrf
= zebra_vrf_get_evpn();
923 /* Walk VxLAN interfaces and create EVPN hash. */
924 for (rn
= route_top(zns
->if_table
); rn
; rn
= route_next(rn
)) {
926 struct zebra_evpn
*zevpn
= NULL
;
927 struct zebra_l3vni
*zl3vni
= NULL
;
928 struct zebra_if
*zif
;
929 struct zebra_l2info_vxlan
*vxl
;
931 ifp
= (struct interface
*)rn
->info
;
935 if (!zif
|| zif
->zif_type
!= ZEBRA_IF_VXLAN
)
938 vxl
= &zif
->l2info
.vxl
;
940 /* link of VXLAN interface should be in zebra_evpn_vrf */
941 if (zvrf
->zns
->ns_id
!= vxl
->link_nsid
) {
942 if (IS_ZEBRA_DEBUG_VXLAN
)
944 "Intf %s(%u) VNI %u, link not in same "
945 "namespace than BGP EVPN core instance ",
946 ifp
->name
, ifp
->ifindex
, vni
);
949 /* L3-VNI and L2-VNI are handled seperately */
950 zl3vni
= zl3vni_lookup(vni
);
953 if (IS_ZEBRA_DEBUG_VXLAN
)
955 "create L3-VNI hash for Intf %s(%u) L3-VNI %u",
956 ifp
->name
, ifp
->ifindex
, vni
);
958 /* associate with vxlan_if */
959 zl3vni
->local_vtep_ip
= vxl
->vtep_ip
;
960 zl3vni
->vxlan_if
= ifp
;
963 * we need to associate with SVI.
964 * we can associate with svi-if only after association
965 * with vxlan-intf is complete
967 zl3vni
->svi_if
= zl3vni_map_to_svi_if(zl3vni
);
969 /* Associate l3vni to mac-vlan and extract VRR MAC */
970 zl3vni
->mac_vlan_if
= zl3vni_map_to_mac_vlan_if(zl3vni
);
972 if (IS_ZEBRA_DEBUG_VXLAN
)
973 zlog_debug("create l3vni %u svi_if %s mac_vlan_if %s",
974 vni
, zl3vni
->svi_if
? zl3vni
->svi_if
->name
976 zl3vni
->mac_vlan_if
?
977 zl3vni
->mac_vlan_if
->name
: "NIL");
979 if (is_l3vni_oper_up(zl3vni
))
980 zebra_vxlan_process_l3vni_oper_up(zl3vni
);
983 struct interface
*vlan_if
= NULL
;
985 if (IS_ZEBRA_DEBUG_VXLAN
)
987 "Create L2-VNI hash for intf %s(%u) L2-VNI %u local IP %pI4",
988 ifp
->name
, ifp
->ifindex
, vni
,
991 /* EVPN hash entry is expected to exist, if the BGP process is killed */
992 zevpn
= zebra_evpn_lookup(vni
);
995 "EVPN hash already present for IF %s(%u) L2-VNI %u",
996 ifp
->name
, ifp
->ifindex
, vni
);
999 * Inform BGP if intf is up and mapped to
1002 if (if_is_operative(ifp
) &&
1003 zif
->brslave_info
.br_if
)
1004 zebra_evpn_send_add_to_client(zevpn
);
1006 /* Send Local MAC-entries to client */
1007 zebra_evpn_send_mac_list_to_client(zevpn
);
1009 /* Send Loval Neighbor entries to client */
1010 zebra_evpn_send_neigh_to_client(zevpn
);
1012 zevpn
= zebra_evpn_add(vni
);
1015 "Failed to add EVPN hash, IF %s(%u) L2-VNI %u",
1016 ifp
->name
, ifp
->ifindex
, vni
);
1017 return NS_WALK_CONTINUE
;
1020 if (zevpn
->local_vtep_ip
.s_addr
!=
1021 vxl
->vtep_ip
.s_addr
||
1022 zevpn
->mcast_grp
.s_addr
!=
1023 vxl
->mcast_grp
.s_addr
) {
1024 zebra_vxlan_sg_deref(
1025 zevpn
->local_vtep_ip
,
1027 zebra_vxlan_sg_ref(vxl
->vtep_ip
,
1029 zevpn
->local_vtep_ip
= vxl
->vtep_ip
;
1030 zevpn
->mcast_grp
= vxl
->mcast_grp
;
1031 /* on local vtep-ip check if ES
1032 * orig-ip needs to be updated
1034 zebra_evpn_es_set_base_evpn(zevpn
);
1036 zevpn_vxlan_if_set(zevpn
, ifp
, true /* set */);
1037 vlan_if
= zvni_map_to_svi(
1039 zif
->brslave_info
.br_if
);
1041 zevpn
->svi_if
= vlan_if
;
1042 zevpn
->vrf_id
= vlan_if
->vrf
->vrf_id
;
1043 zl3vni
= zl3vni_from_vrf(
1044 vlan_if
->vrf
->vrf_id
);
1047 zl3vni
->l2vnis
, zevpn
);
1051 * Inform BGP if intf is up and mapped to
1054 if (if_is_operative(ifp
) &&
1055 zif
->brslave_info
.br_if
)
1056 zebra_evpn_send_add_to_client(zevpn
);
1060 return NS_WALK_CONTINUE
;
1064 * Build the VNI hash table by going over the VxLAN interfaces. This
1065 * is called when EVPN (advertise-all-vni) is enabled.
1068 static void zevpn_build_hash_table(void)
1070 ns_walk_func(zevpn_build_hash_table_zns
, NULL
, NULL
);
1074 * Cleanup EVPN/VTEP and update kernel
1076 static void zebra_evpn_vxlan_cleanup_all(struct hash_bucket
*bucket
, void *arg
)
1078 struct zebra_evpn
*zevpn
= NULL
;
1079 struct zebra_l3vni
*zl3vni
= NULL
;
1081 zevpn
= (struct zebra_evpn
*)bucket
->data
;
1083 /* remove l2vni from l2vni's tenant-vrf l3-vni list */
1084 zl3vni
= zl3vni_from_vrf(zevpn
->vrf_id
);
1086 listnode_delete(zl3vni
->l2vnis
, zevpn
);
1088 zebra_evpn_cleanup_all(bucket
, arg
);
1092 static void zl3vni_cleanup_all(struct hash_bucket
*bucket
, void *args
)
1094 struct zebra_l3vni
*zl3vni
= NULL
;
1096 zl3vni
= (struct zebra_l3vni
*)bucket
->data
;
1098 zebra_vxlan_process_l3vni_oper_down(zl3vni
);
1101 static void rb_find_or_add_host(struct host_rb_tree_entry
*hrbe
,
1102 const struct prefix
*host
)
1104 struct host_rb_entry lookup
;
1105 struct host_rb_entry
*hle
;
1107 memset(&lookup
, 0, sizeof(lookup
));
1108 memcpy(&lookup
.p
, host
, sizeof(*host
));
1110 hle
= RB_FIND(host_rb_tree_entry
, hrbe
, &lookup
);
1114 hle
= XCALLOC(MTYPE_HOST_PREFIX
, sizeof(struct host_rb_entry
));
1115 memcpy(hle
, &lookup
, sizeof(lookup
));
1117 RB_INSERT(host_rb_tree_entry
, hrbe
, hle
);
1120 static void rb_delete_host(struct host_rb_tree_entry
*hrbe
, struct prefix
*host
)
1122 struct host_rb_entry lookup
;
1123 struct host_rb_entry
*hle
;
1125 memset(&lookup
, 0, sizeof(lookup
));
1126 memcpy(&lookup
.p
, host
, sizeof(*host
));
1128 hle
= RB_FIND(host_rb_tree_entry
, hrbe
, &lookup
);
1130 RB_REMOVE(host_rb_tree_entry
, hrbe
, hle
);
1131 XFREE(MTYPE_HOST_PREFIX
, hle
);
1138 * Look up MAC hash entry.
1140 static struct zebra_mac
*zl3vni_rmac_lookup(struct zebra_l3vni
*zl3vni
,
1141 const struct ethaddr
*rmac
)
1143 struct zebra_mac tmp
;
1144 struct zebra_mac
*pmac
;
1146 memset(&tmp
, 0, sizeof(tmp
));
1147 memcpy(&tmp
.macaddr
, rmac
, ETH_ALEN
);
1148 pmac
= hash_lookup(zl3vni
->rmac_table
, &tmp
);
1154 * Callback to allocate RMAC hash entry.
1156 static void *zl3vni_rmac_alloc(void *p
)
1158 const struct zebra_mac
*tmp_rmac
= p
;
1159 struct zebra_mac
*zrmac
;
1161 zrmac
= XCALLOC(MTYPE_L3VNI_MAC
, sizeof(struct zebra_mac
));
1164 return ((void *)zrmac
);
1168 * Add RMAC entry to l3-vni
1170 static struct zebra_mac
*zl3vni_rmac_add(struct zebra_l3vni
*zl3vni
,
1171 const struct ethaddr
*rmac
)
1173 struct zebra_mac tmp_rmac
;
1174 struct zebra_mac
*zrmac
= NULL
;
1176 memset(&tmp_rmac
, 0, sizeof(tmp_rmac
));
1177 memcpy(&tmp_rmac
.macaddr
, rmac
, ETH_ALEN
);
1178 zrmac
= hash_get(zl3vni
->rmac_table
, &tmp_rmac
, zl3vni_rmac_alloc
);
1179 zrmac
->nh_list
= list_new();
1180 zrmac
->nh_list
->cmp
= (int (*)(void *, void *))l3vni_rmac_nh_list_cmp
;
1181 zrmac
->nh_list
->del
= (void (*)(void *))l3vni_rmac_nh_free
;
1183 SET_FLAG(zrmac
->flags
, ZEBRA_MAC_REMOTE
);
1184 SET_FLAG(zrmac
->flags
, ZEBRA_MAC_REMOTE_RMAC
);
1192 static int zl3vni_rmac_del(struct zebra_l3vni
*zl3vni
, struct zebra_mac
*zrmac
)
1194 struct zebra_mac
*tmp_rmac
;
1196 /* free the list of nh list*/
1197 list_delete(&zrmac
->nh_list
);
1199 tmp_rmac
= hash_release(zl3vni
->rmac_table
, zrmac
);
1200 XFREE(MTYPE_L3VNI_MAC
, tmp_rmac
);
1206 * Install remote RMAC into the forwarding plane.
1208 static int zl3vni_rmac_install(struct zebra_l3vni
*zl3vni
,
1209 struct zebra_mac
*zrmac
)
1211 const struct zebra_if
*zif
= NULL
, *br_zif
= NULL
;
1212 const struct zebra_l2info_vxlan
*vxl
= NULL
;
1213 const struct interface
*br_ifp
;
1214 enum zebra_dplane_result res
;
1217 if (!(CHECK_FLAG(zrmac
->flags
, ZEBRA_MAC_REMOTE
))
1218 || !(CHECK_FLAG(zrmac
->flags
, ZEBRA_MAC_REMOTE_RMAC
)))
1221 zif
= zl3vni
->vxlan_if
->info
;
1225 br_ifp
= zif
->brslave_info
.br_if
;
1229 vxl
= &zif
->l2info
.vxl
;
1231 br_zif
= (const struct zebra_if
*)br_ifp
->info
;
1233 if (IS_ZEBRA_IF_BRIDGE_VLAN_AWARE(br_zif
))
1234 vid
= vxl
->access_vlan
;
1238 res
= dplane_rem_mac_add(zl3vni
->vxlan_if
, br_ifp
, vid
,
1239 &zrmac
->macaddr
, zrmac
->fwd_info
.r_vtep_ip
, 0, 0,
1240 false /*was_static*/);
1241 if (res
!= ZEBRA_DPLANE_REQUEST_FAILURE
)
1248 * Uninstall remote RMAC from the forwarding plane.
1250 static int zl3vni_rmac_uninstall(struct zebra_l3vni
*zl3vni
,
1251 struct zebra_mac
*zrmac
)
1253 const struct zebra_if
*zif
= NULL
, *br_zif
;
1254 const struct zebra_l2info_vxlan
*vxl
= NULL
;
1255 const struct interface
*br_ifp
;
1257 enum zebra_dplane_result res
;
1259 if (!(CHECK_FLAG(zrmac
->flags
, ZEBRA_MAC_REMOTE
))
1260 || !(CHECK_FLAG(zrmac
->flags
, ZEBRA_MAC_REMOTE_RMAC
)))
1263 if (!zl3vni
->vxlan_if
) {
1264 if (IS_ZEBRA_DEBUG_VXLAN
)
1266 "RMAC %pEA on L3-VNI %u hash %p couldn't be uninstalled - no vxlan_if",
1267 &zrmac
->macaddr
, zl3vni
->vni
, zl3vni
);
1271 zif
= zl3vni
->vxlan_if
->info
;
1275 br_ifp
= zif
->brslave_info
.br_if
;
1279 vxl
= &zif
->l2info
.vxl
;
1281 br_zif
= (const struct zebra_if
*)br_ifp
->info
;
1282 if (IS_ZEBRA_IF_BRIDGE_VLAN_AWARE(br_zif
))
1283 vid
= vxl
->access_vlan
;
1287 res
= dplane_rem_mac_del(zl3vni
->vxlan_if
, br_ifp
, vid
,
1288 &zrmac
->macaddr
, zrmac
->fwd_info
.r_vtep_ip
);
1289 if (res
!= ZEBRA_DPLANE_REQUEST_FAILURE
)
1295 /* handle rmac add */
1296 static int zl3vni_remote_rmac_add(struct zebra_l3vni
*zl3vni
,
1297 const struct ethaddr
*rmac
,
1298 const struct ipaddr
*vtep_ip
)
1300 struct zebra_mac
*zrmac
= NULL
;
1301 struct ipaddr
*vtep
= NULL
;
1303 zrmac
= zl3vni_rmac_lookup(zl3vni
, rmac
);
1306 /* Create the RMAC entry, or update its vtep, if necessary. */
1307 zrmac
= zl3vni_rmac_add(zl3vni
, rmac
);
1310 "Failed to add RMAC %pEA L3VNI %u Remote VTEP %pIA",
1311 rmac
, zl3vni
->vni
, vtep_ip
);
1314 memset(&zrmac
->fwd_info
, 0, sizeof(zrmac
->fwd_info
));
1315 zrmac
->fwd_info
.r_vtep_ip
= vtep_ip
->ipaddr_v4
;
1317 vtep
= XCALLOC(MTYPE_EVPN_VTEP
, sizeof(struct ipaddr
));
1318 memcpy(vtep
, vtep_ip
, sizeof(struct ipaddr
));
1319 if (!listnode_add_sort_nodup(zrmac
->nh_list
, (void *)vtep
))
1320 XFREE(MTYPE_EVPN_VTEP
, vtep
);
1322 /* Send RMAC for FPM processing */
1323 hook_call(zebra_rmac_update
, zrmac
, zl3vni
, false,
1326 /* install rmac in kernel */
1327 zl3vni_rmac_install(zl3vni
, zrmac
);
1328 } else if (!IPV4_ADDR_SAME(&zrmac
->fwd_info
.r_vtep_ip
,
1329 &vtep_ip
->ipaddr_v4
)) {
1330 if (IS_ZEBRA_DEBUG_VXLAN
)
1332 "L3VNI %u Remote VTEP change(%pI4 -> %pIA) for RMAC %pEA",
1333 zl3vni
->vni
, &zrmac
->fwd_info
.r_vtep_ip
,
1336 zrmac
->fwd_info
.r_vtep_ip
= vtep_ip
->ipaddr_v4
;
1338 vtep
= XCALLOC(MTYPE_EVPN_VTEP
, sizeof(struct ipaddr
));
1339 memcpy(vtep
, vtep_ip
, sizeof(struct ipaddr
));
1340 if (!listnode_add_sort_nodup(zrmac
->nh_list
, (void *)vtep
))
1341 XFREE(MTYPE_EVPN_VTEP
, vtep
);
1343 /* install rmac in kernel */
1344 zl3vni_rmac_install(zl3vni
, zrmac
);
1351 /* handle rmac delete */
1352 static void zl3vni_remote_rmac_del(struct zebra_l3vni
*zl3vni
,
1353 struct zebra_mac
*zrmac
,
1354 struct ipaddr
*vtep_ip
)
1356 struct ipaddr ipv4_vtep
;
1358 if (!zl3vni_nh_lookup(zl3vni
, vtep_ip
)) {
1359 memset(&ipv4_vtep
, 0, sizeof(ipv4_vtep
));
1360 ipv4_vtep
.ipa_type
= IPADDR_V4
;
1361 if (vtep_ip
->ipa_type
== IPADDR_V6
)
1362 ipv4_mapped_ipv6_to_ipv4(&vtep_ip
->ipaddr_v6
,
1363 &ipv4_vtep
.ipaddr_v4
);
1365 memcpy(&(ipv4_vtep
.ipaddr_v4
), &vtep_ip
->ipaddr_v4
,
1366 sizeof(struct in_addr
));
1368 /* remove nh from rmac's list */
1369 l3vni_rmac_nh_list_nh_delete(zl3vni
, zrmac
, &ipv4_vtep
);
1370 /* delete nh is same as current selected, fall back to
1371 * one present in the list
1373 if (IPV4_ADDR_SAME(&zrmac
->fwd_info
.r_vtep_ip
,
1374 &ipv4_vtep
.ipaddr_v4
) &&
1375 listcount(zrmac
->nh_list
)) {
1376 struct ipaddr
*vtep
;
1378 vtep
= listgetdata(listhead(zrmac
->nh_list
));
1379 zrmac
->fwd_info
.r_vtep_ip
= vtep
->ipaddr_v4
;
1380 if (IS_ZEBRA_DEBUG_VXLAN
)
1382 "L3VNI %u Remote VTEP nh change(%pIA -> %pI4) for RMAC %pEA",
1383 zl3vni
->vni
, &ipv4_vtep
,
1384 &zrmac
->fwd_info
.r_vtep_ip
,
1387 /* install rmac in kernel */
1388 zl3vni_rmac_install(zl3vni
, zrmac
);
1391 if (!listcount(zrmac
->nh_list
)) {
1392 /* uninstall from kernel */
1393 zl3vni_rmac_uninstall(zl3vni
, zrmac
);
1395 /* Send RMAC for FPM processing */
1396 hook_call(zebra_rmac_update
, zrmac
, zl3vni
, true,
1399 if (IS_ZEBRA_DEBUG_VXLAN
)
1401 "L3VNI %u RMAC %pEA vtep_ip %pIA delete",
1402 zl3vni
->vni
, &zrmac
->macaddr
, vtep_ip
);
1404 /* del the rmac entry */
1405 zl3vni_rmac_del(zl3vni
, zrmac
);
1411 * Look up nh hash entry on a l3-vni.
1413 static struct zebra_neigh
*zl3vni_nh_lookup(struct zebra_l3vni
*zl3vni
,
1414 const struct ipaddr
*ip
)
1416 struct zebra_neigh tmp
;
1417 struct zebra_neigh
*n
;
1419 memset(&tmp
, 0, sizeof(tmp
));
1420 memcpy(&tmp
.ip
, ip
, sizeof(struct ipaddr
));
1421 n
= hash_lookup(zl3vni
->nh_table
, &tmp
);
1428 * Callback to allocate NH hash entry on L3-VNI.
1430 static void *zl3vni_nh_alloc(void *p
)
1432 const struct zebra_neigh
*tmp_n
= p
;
1433 struct zebra_neigh
*n
;
1435 n
= XCALLOC(MTYPE_L3NEIGH
, sizeof(struct zebra_neigh
));
1442 * Add neighbor entry.
1444 static struct zebra_neigh
*zl3vni_nh_add(struct zebra_l3vni
*zl3vni
,
1445 const struct ipaddr
*ip
,
1446 const struct ethaddr
*mac
)
1448 struct zebra_neigh tmp_n
;
1449 struct zebra_neigh
*n
= NULL
;
1451 memset(&tmp_n
, 0, sizeof(tmp_n
));
1452 memcpy(&tmp_n
.ip
, ip
, sizeof(struct ipaddr
));
1453 n
= hash_get(zl3vni
->nh_table
, &tmp_n
, zl3vni_nh_alloc
);
1455 RB_INIT(host_rb_tree_entry
, &n
->host_rb
);
1457 memcpy(&n
->emac
, mac
, ETH_ALEN
);
1458 SET_FLAG(n
->flags
, ZEBRA_NEIGH_REMOTE
);
1459 SET_FLAG(n
->flags
, ZEBRA_NEIGH_REMOTE_NH
);
1465 * Delete neighbor entry.
1467 static int zl3vni_nh_del(struct zebra_l3vni
*zl3vni
, struct zebra_neigh
*n
)
1469 struct zebra_neigh
*tmp_n
;
1470 struct host_rb_entry
*hle
;
1472 while (!RB_EMPTY(host_rb_tree_entry
, &n
->host_rb
)) {
1473 hle
= RB_ROOT(host_rb_tree_entry
, &n
->host_rb
);
1475 RB_REMOVE(host_rb_tree_entry
, &n
->host_rb
, hle
);
1476 XFREE(MTYPE_HOST_PREFIX
, hle
);
1479 tmp_n
= hash_release(zl3vni
->nh_table
, n
);
1480 XFREE(MTYPE_L3NEIGH
, tmp_n
);
1486 * Install remote nh as neigh into the kernel.
1488 static int zl3vni_nh_install(struct zebra_l3vni
*zl3vni
, struct zebra_neigh
*n
)
1493 if (!is_l3vni_oper_up(zl3vni
))
1496 if (!(n
->flags
& ZEBRA_NEIGH_REMOTE
)
1497 || !(n
->flags
& ZEBRA_NEIGH_REMOTE_NH
))
1500 flags
= DPLANE_NTF_EXT_LEARNED
;
1501 if (n
->flags
& ZEBRA_NEIGH_ROUTER_FLAG
)
1502 flags
|= DPLANE_NTF_ROUTER
;
1504 dplane_rem_neigh_add(zl3vni
->svi_if
, &n
->ip
, &n
->emac
, flags
,
1505 false /*was_static*/);
1511 * Uninstall remote nh from the kernel.
1513 static int zl3vni_nh_uninstall(struct zebra_l3vni
*zl3vni
,
1514 struct zebra_neigh
*n
)
1516 if (!(n
->flags
& ZEBRA_NEIGH_REMOTE
)
1517 || !(n
->flags
& ZEBRA_NEIGH_REMOTE_NH
))
1520 if (!zl3vni
->svi_if
|| !if_is_operative(zl3vni
->svi_if
))
1523 dplane_rem_neigh_delete(zl3vni
->svi_if
, &n
->ip
);
1528 /* add remote vtep as a neigh entry */
1529 static int zl3vni_remote_nh_add(struct zebra_l3vni
*zl3vni
,
1530 const struct ipaddr
*vtep_ip
,
1531 const struct ethaddr
*rmac
,
1532 const struct prefix
*host_prefix
)
1534 struct zebra_neigh
*nh
= NULL
;
1536 /* Create the next hop entry, or update its mac, if necessary. */
1537 nh
= zl3vni_nh_lookup(zl3vni
, vtep_ip
);
1539 nh
= zl3vni_nh_add(zl3vni
, vtep_ip
, rmac
);
1542 "Failed to add NH %pIA as Neigh (RMAC %pEA L3-VNI %u prefix %pFX)",
1543 vtep_ip
, rmac
, zl3vni
->vni
, host_prefix
);
1547 /* install the nh neigh in kernel */
1548 zl3vni_nh_install(zl3vni
, nh
);
1549 } else if (memcmp(&nh
->emac
, rmac
, ETH_ALEN
) != 0) {
1550 if (IS_ZEBRA_DEBUG_VXLAN
)
1552 "L3VNI %u RMAC change(%pEA --> %pEA) for nexthop %pIA, prefix %pFX",
1553 zl3vni
->vni
, &nh
->emac
, rmac
, vtep_ip
,
1556 memcpy(&nh
->emac
, rmac
, ETH_ALEN
);
1557 /* install (update) the nh neigh in kernel */
1558 zl3vni_nh_install(zl3vni
, nh
);
1561 rb_find_or_add_host(&nh
->host_rb
, host_prefix
);
1566 /* handle nh neigh delete */
1567 static void zl3vni_remote_nh_del(struct zebra_l3vni
*zl3vni
,
1568 struct zebra_neigh
*nh
,
1569 struct prefix
*host_prefix
)
1571 rb_delete_host(&nh
->host_rb
, host_prefix
);
1573 if (RB_EMPTY(host_rb_tree_entry
, &nh
->host_rb
)) {
1574 /* uninstall from kernel */
1575 zl3vni_nh_uninstall(zl3vni
, nh
);
1577 /* delete the nh entry */
1578 zl3vni_nh_del(zl3vni
, nh
);
1582 /* handle neigh update from kernel - the only thing of interest is to
1583 * readd stale entries.
1585 static int zl3vni_local_nh_add_update(struct zebra_l3vni
*zl3vni
,
1586 struct ipaddr
*ip
, uint16_t state
)
1589 struct zebra_neigh
*n
= NULL
;
1591 n
= zl3vni_nh_lookup(zl3vni
, ip
);
1595 /* all next hop neigh are remote and installed by frr.
1596 * If the kernel has aged this entry, re-install.
1598 if (state
& NUD_STALE
)
1599 zl3vni_nh_install(zl3vni
, n
);
1604 /* handle neigh delete from kernel */
1605 static int zl3vni_local_nh_del(struct zebra_l3vni
*zl3vni
, struct ipaddr
*ip
)
1607 struct zebra_neigh
*n
= NULL
;
1609 n
= zl3vni_nh_lookup(zl3vni
, ip
);
1613 /* all next hop neigh are remote and installed by frr.
1614 * If we get an age out notification for these neigh entries, we have to
1617 zl3vni_nh_install(zl3vni
, n
);
1623 * Hash function for L3 VNI.
1625 static unsigned int l3vni_hash_keymake(const void *p
)
1627 const struct zebra_l3vni
*zl3vni
= p
;
1629 return jhash_1word(zl3vni
->vni
, 0);
1633 * Compare 2 L3 VNI hash entries.
1635 static bool l3vni_hash_cmp(const void *p1
, const void *p2
)
1637 const struct zebra_l3vni
*zl3vni1
= p1
;
1638 const struct zebra_l3vni
*zl3vni2
= p2
;
1640 return (zl3vni1
->vni
== zl3vni2
->vni
);
1644 * Callback to allocate L3 VNI hash entry.
1646 static void *zl3vni_alloc(void *p
)
1648 struct zebra_l3vni
*zl3vni
= NULL
;
1649 const struct zebra_l3vni
*tmp_l3vni
= p
;
1651 zl3vni
= XCALLOC(MTYPE_ZL3VNI
, sizeof(struct zebra_l3vni
));
1652 zl3vni
->vni
= tmp_l3vni
->vni
;
1653 return ((void *)zl3vni
);
1657 * Look up L3 VNI hash entry.
1659 struct zebra_l3vni
*zl3vni_lookup(vni_t vni
)
1661 struct zebra_l3vni tmp_l3vni
;
1662 struct zebra_l3vni
*zl3vni
= NULL
;
1664 memset(&tmp_l3vni
, 0, sizeof(tmp_l3vni
));
1665 tmp_l3vni
.vni
= vni
;
1666 zl3vni
= hash_lookup(zrouter
.l3vni_table
, &tmp_l3vni
);
1672 * Add L3 VNI hash entry.
1674 static struct zebra_l3vni
*zl3vni_add(vni_t vni
, vrf_id_t vrf_id
)
1676 struct zebra_l3vni tmp_zl3vni
;
1677 struct zebra_l3vni
*zl3vni
= NULL
;
1679 memset(&tmp_zl3vni
, 0, sizeof(tmp_zl3vni
));
1680 tmp_zl3vni
.vni
= vni
;
1682 zl3vni
= hash_get(zrouter
.l3vni_table
, &tmp_zl3vni
, zl3vni_alloc
);
1684 zl3vni
->vrf_id
= vrf_id
;
1685 zl3vni
->svi_if
= NULL
;
1686 zl3vni
->vxlan_if
= NULL
;
1687 zl3vni
->l2vnis
= list_new();
1688 zl3vni
->l2vnis
->cmp
= zebra_evpn_list_cmp
;
1690 /* Create hash table for remote RMAC */
1691 zl3vni
->rmac_table
= zebra_mac_db_create("Zebra L3-VNI RMAC-Table");
1693 /* Create hash table for neighbors */
1694 zl3vni
->nh_table
= zebra_neigh_db_create("Zebra L3-VNI next-hop table");
1700 * Delete L3 VNI hash entry.
1702 static int zl3vni_del(struct zebra_l3vni
*zl3vni
)
1704 struct zebra_l3vni
*tmp_zl3vni
;
1706 /* free the list of l2vnis */
1707 list_delete(&zl3vni
->l2vnis
);
1708 zl3vni
->l2vnis
= NULL
;
1710 /* Free the rmac table */
1711 hash_free(zl3vni
->rmac_table
);
1712 zl3vni
->rmac_table
= NULL
;
1714 /* Free the nh table */
1715 hash_free(zl3vni
->nh_table
);
1716 zl3vni
->nh_table
= NULL
;
1718 /* Free the VNI hash entry and allocated memory. */
1719 tmp_zl3vni
= hash_release(zrouter
.l3vni_table
, zl3vni
);
1720 XFREE(MTYPE_ZL3VNI
, tmp_zl3vni
);
1725 static int zl3vni_map_to_vxlan_if_ns(struct ns
*ns
,
1729 struct zebra_ns
*zns
= ns
->info
;
1730 struct zebra_l3vni
*zl3vni
= (struct zebra_l3vni
*)_zl3vni
;
1731 struct route_node
*rn
= NULL
;
1732 struct interface
*ifp
= NULL
;
1733 struct zebra_vrf
*zvrf
;
1735 zvrf
= zebra_vrf_get_evpn();
1739 /* loop through all vxlan-interface */
1740 for (rn
= route_top(zns
->if_table
); rn
; rn
= route_next(rn
)) {
1742 struct zebra_if
*zif
= NULL
;
1743 struct zebra_l2info_vxlan
*vxl
= NULL
;
1745 ifp
= (struct interface
*)rn
->info
;
1750 if (!zif
|| zif
->zif_type
!= ZEBRA_IF_VXLAN
)
1753 vxl
= &zif
->l2info
.vxl
;
1754 if (vxl
->vni
!= zl3vni
->vni
)
1757 /* link of VXLAN interface should be in zebra_evpn_vrf */
1758 if (zvrf
->zns
->ns_id
!= vxl
->link_nsid
) {
1759 if (IS_ZEBRA_DEBUG_VXLAN
)
1761 "Intf %s(%u) VNI %u, link not in same "
1762 "namespace than BGP EVPN core instance ",
1763 ifp
->name
, ifp
->ifindex
, vxl
->vni
);
1768 zl3vni
->local_vtep_ip
= vxl
->vtep_ip
;
1769 *_pifp
= (void *)ifp
;
1770 return NS_WALK_STOP
;
1773 return NS_WALK_CONTINUE
;
1776 struct interface
*zl3vni_map_to_vxlan_if(struct zebra_l3vni
*zl3vni
)
1778 struct interface
**p_ifp
;
1779 struct interface
*ifp
= NULL
;
1783 ns_walk_func(zl3vni_map_to_vxlan_if_ns
,
1784 (void *)zl3vni
, (void **)p_ifp
);
1788 struct interface
*zl3vni_map_to_svi_if(struct zebra_l3vni
*zl3vni
)
1790 struct zebra_if
*zif
= NULL
; /* zebra_if for vxlan_if */
1791 struct zebra_l2info_vxlan
*vxl
= NULL
; /* l2 info for vxlan_if */
1796 if (!zl3vni
->vxlan_if
)
1799 zif
= zl3vni
->vxlan_if
->info
;
1803 vxl
= &zif
->l2info
.vxl
;
1805 return zvni_map_to_svi(vxl
->access_vlan
, zif
->brslave_info
.br_if
);
1808 struct interface
*zl3vni_map_to_mac_vlan_if(struct zebra_l3vni
*zl3vni
)
1810 struct zebra_if
*zif
= NULL
; /* zebra_if for vxlan_if */
1815 if (!zl3vni
->vxlan_if
)
1818 zif
= zl3vni
->vxlan_if
->info
;
1822 return zebra_evpn_map_to_macvlan(zif
->brslave_info
.br_if
,
1827 struct zebra_l3vni
*zl3vni_from_vrf(vrf_id_t vrf_id
)
1829 struct zebra_vrf
*zvrf
= NULL
;
1831 zvrf
= zebra_vrf_lookup_by_id(vrf_id
);
1835 return zl3vni_lookup(zvrf
->l3vni
);
1838 static int zl3vni_from_svi_ns(struct ns
*ns
, void *_in_param
, void **_p_zl3vni
)
1840 struct zebra_ns
*zns
= ns
->info
;
1841 struct zebra_l3vni
**p_zl3vni
= (struct zebra_l3vni
**)_p_zl3vni
;
1842 struct zebra_from_svi_param
*in_param
=
1843 (struct zebra_from_svi_param
*)_in_param
;
1844 struct route_node
*rn
= NULL
;
1845 struct interface
*tmp_if
= NULL
;
1846 struct zebra_if
*zif
= NULL
;
1847 struct zebra_l2info_vxlan
*vxl
= NULL
;
1849 assert(in_param
&& p_zl3vni
);
1851 /* loop through all vxlan-interface */
1852 for (rn
= route_top(zns
->if_table
); rn
; rn
= route_next(rn
)) {
1853 tmp_if
= (struct interface
*)rn
->info
;
1857 if (!zif
|| zif
->zif_type
!= ZEBRA_IF_VXLAN
)
1859 if (!if_is_operative(tmp_if
))
1861 vxl
= &zif
->l2info
.vxl
;
1863 if (zif
->brslave_info
.br_if
!= in_param
->br_if
)
1866 if (!in_param
->bridge_vlan_aware
1867 || vxl
->access_vlan
== in_param
->vid
) {
1868 *p_zl3vni
= zl3vni_lookup(vxl
->vni
);
1869 return NS_WALK_STOP
;
1873 return NS_WALK_CONTINUE
;
1877 * Map SVI and associated bridge to a VNI. This is invoked upon getting
1878 * neighbor notifications, to see if they are of interest.
1880 static struct zebra_l3vni
*zl3vni_from_svi(struct interface
*ifp
,
1881 struct interface
*br_if
)
1883 struct zebra_l3vni
*zl3vni
= NULL
;
1884 struct zebra_if
*zif
= NULL
;
1885 struct zebra_l2info_bridge
*br
= NULL
;
1886 struct zebra_from_svi_param in_param
= {};
1887 struct zebra_l3vni
**p_zl3vni
;
1892 /* Make sure the linked interface is a bridge. */
1893 if (!IS_ZEBRA_IF_BRIDGE(br_if
))
1895 in_param
.br_if
= br_if
;
1897 /* Determine if bridge is VLAN-aware or not */
1900 br
= &zif
->l2info
.br
;
1901 in_param
.bridge_vlan_aware
= br
->vlan_aware
;
1902 if (in_param
.bridge_vlan_aware
) {
1903 struct zebra_l2info_vlan
*vl
;
1905 if (!IS_ZEBRA_IF_VLAN(ifp
))
1910 vl
= &zif
->l2info
.vl
;
1911 in_param
.vid
= vl
->vid
;
1914 /* See if this interface (or interface plus VLAN Id) maps to a VxLAN */
1915 /* TODO: Optimize with a hash. */
1919 ns_walk_func(zl3vni_from_svi_ns
, (void *)&in_param
, (void **)p_zl3vni
);
1923 vni_t
vni_id_from_svi(struct interface
*ifp
, struct interface
*br_if
)
1926 struct zebra_evpn
*zevpn
= NULL
;
1927 struct zebra_l3vni
*zl3vni
= NULL
;
1929 /* Check if an L3VNI belongs to this SVI interface.
1930 * If not, check if an L2VNI belongs to this SVI interface.
1932 zl3vni
= zl3vni_from_svi(ifp
, br_if
);
1936 zevpn
= zebra_evpn_from_svi(ifp
, br_if
);
1944 static inline void zl3vni_get_vrr_rmac(struct zebra_l3vni
*zl3vni
,
1945 struct ethaddr
*rmac
)
1950 if (!is_l3vni_oper_up(zl3vni
))
1953 if (zl3vni
->mac_vlan_if
&& if_is_operative(zl3vni
->mac_vlan_if
))
1954 memcpy(rmac
->octet
, zl3vni
->mac_vlan_if
->hw_addr
, ETH_ALEN
);
1958 * Inform BGP about l3-vni.
1960 static int zl3vni_send_add_to_client(struct zebra_l3vni
*zl3vni
)
1962 struct stream
*s
= NULL
;
1963 struct zserv
*client
= NULL
;
1964 struct ethaddr svi_rmac
, vrr_rmac
= {.octet
= {0} };
1965 struct zebra_vrf
*zvrf
;
1966 bool is_anycast_mac
= true;
1968 client
= zserv_find_client(ZEBRA_ROUTE_BGP
, 0);
1969 /* BGP may not be running. */
1973 zvrf
= zebra_vrf_lookup_by_id(zl3vni
->vrf_id
);
1976 /* get the svi and vrr rmac values */
1977 memset(&svi_rmac
, 0, sizeof(svi_rmac
));
1978 zl3vni_get_svi_rmac(zl3vni
, &svi_rmac
);
1979 zl3vni_get_vrr_rmac(zl3vni
, &vrr_rmac
);
1981 /* In absence of vrr mac use svi mac as anycast MAC value */
1982 if (is_zero_mac(&vrr_rmac
)) {
1983 memcpy(&vrr_rmac
, &svi_rmac
, ETH_ALEN
);
1984 is_anycast_mac
= false;
1987 s
= stream_new(ZEBRA_MAX_PACKET_SIZ
);
1989 /* The message is used for both vni add and/or update like
1990 * vrr mac is added for l3vni SVI.
1992 zclient_create_header(s
, ZEBRA_L3VNI_ADD
, zl3vni_vrf_id(zl3vni
));
1993 stream_putl(s
, zl3vni
->vni
);
1994 stream_put(s
, &svi_rmac
, sizeof(struct ethaddr
));
1995 stream_put_in_addr(s
, &zl3vni
->local_vtep_ip
);
1996 stream_put(s
, &zl3vni
->filter
, sizeof(int));
1997 stream_putl(s
, zl3vni
->svi_if
->ifindex
);
1998 stream_put(s
, &vrr_rmac
, sizeof(struct ethaddr
));
1999 stream_putl(s
, is_anycast_mac
);
2001 /* Write packet size. */
2002 stream_putw_at(s
, 0, stream_get_endp(s
));
2004 if (IS_ZEBRA_DEBUG_VXLAN
)
2006 "Send L3_VNI_ADD %u VRF %s RMAC %pEA VRR %pEA local-ip %pI4 filter %s to %s",
2007 zl3vni
->vni
, vrf_id_to_name(zl3vni_vrf_id(zl3vni
)),
2008 &svi_rmac
, &vrr_rmac
, &zl3vni
->local_vtep_ip
,
2009 CHECK_FLAG(zl3vni
->filter
, PREFIX_ROUTES_ONLY
)
2010 ? "prefix-routes-only"
2012 zebra_route_string(client
->proto
));
2014 client
->l3vniadd_cnt
++;
2015 return zserv_send_message(client
, s
);
2019 * Inform BGP about local l3-VNI deletion.
2021 static int zl3vni_send_del_to_client(struct zebra_l3vni
*zl3vni
)
2023 struct stream
*s
= NULL
;
2024 struct zserv
*client
= NULL
;
2026 client
= zserv_find_client(ZEBRA_ROUTE_BGP
, 0);
2027 /* BGP may not be running. */
2031 s
= stream_new(ZEBRA_MAX_PACKET_SIZ
);
2033 zclient_create_header(s
, ZEBRA_L3VNI_DEL
, zl3vni_vrf_id(zl3vni
));
2034 stream_putl(s
, zl3vni
->vni
);
2036 /* Write packet size. */
2037 stream_putw_at(s
, 0, stream_get_endp(s
));
2039 if (IS_ZEBRA_DEBUG_VXLAN
)
2040 zlog_debug("Send L3_VNI_DEL %u VRF %s to %s", zl3vni
->vni
,
2041 vrf_id_to_name(zl3vni_vrf_id(zl3vni
)),
2042 zebra_route_string(client
->proto
));
2044 client
->l3vnidel_cnt
++;
2045 return zserv_send_message(client
, s
);
2048 static void zebra_vxlan_process_l3vni_oper_up(struct zebra_l3vni
*zl3vni
)
2053 /* send l3vni add to BGP */
2054 zl3vni_send_add_to_client(zl3vni
);
2057 static void zebra_vxlan_process_l3vni_oper_down(struct zebra_l3vni
*zl3vni
)
2062 /* send l3-vni del to BGP*/
2063 zl3vni_send_del_to_client(zl3vni
);
2066 static void zevpn_add_to_l3vni_list(struct hash_bucket
*bucket
, void *ctxt
)
2068 struct zebra_evpn
*zevpn
= (struct zebra_evpn
*)bucket
->data
;
2069 struct zebra_l3vni
*zl3vni
= (struct zebra_l3vni
*)ctxt
;
2071 if (zevpn
->vrf_id
== zl3vni_vrf_id(zl3vni
))
2072 listnode_add_sort(zl3vni
->l2vnis
, zevpn
);
2076 * Handle transition of vni from l2 to l3 and vice versa.
2077 * This function handles only the L2VNI add/delete part of
2078 * the above transition.
2079 * L3VNI add/delete is handled by the calling functions.
2081 static int zebra_vxlan_handle_vni_transition(struct zebra_vrf
*zvrf
, vni_t vni
,
2084 struct zebra_evpn
*zevpn
= NULL
;
2085 struct zebra_l3vni
*zl3vni
= NULL
;
2087 /* There is a possibility that VNI notification was already received
2088 * from kernel and we programmed it as L2-VNI
2089 * In such a case we need to delete this L2-VNI first, so
2090 * that it can be reprogrammed as L3-VNI in the system. It is also
2091 * possible that the vrf-vni mapping is removed from FRR while the vxlan
2092 * interface is still present in kernel. In this case to keep it
2093 * symmetric, we will delete the l3-vni and reprogram it as l2-vni
2096 /* Locate hash entry */
2097 zevpn
= zebra_evpn_lookup(vni
);
2101 if (IS_ZEBRA_DEBUG_VXLAN
)
2102 zlog_debug("Del L2-VNI %u - transition to L3-VNI", vni
);
2104 /* Delete EVPN from BGP. */
2105 zebra_evpn_send_del_to_client(zevpn
);
2107 zebra_evpn_neigh_del_all(zevpn
, 0, 0, DEL_ALL_NEIGH
);
2108 zebra_evpn_mac_del_all(zevpn
, 0, 0, DEL_ALL_MAC
);
2110 /* Free up all remote VTEPs, if any. */
2111 zebra_evpn_vtep_del_all(zevpn
, 1);
2113 zl3vni
= zl3vni_from_vrf(zevpn
->vrf_id
);
2115 listnode_delete(zl3vni
->l2vnis
, zevpn
);
2117 /* Delete the hash entry. */
2118 if (zebra_evpn_vxlan_del(zevpn
)) {
2119 flog_err(EC_ZEBRA_VNI_DEL_FAILED
,
2120 "Failed to del EVPN hash %p, VNI %u", zevpn
,
2125 struct zebra_ns
*zns
;
2126 struct route_node
*rn
;
2127 struct interface
*ifp
;
2128 struct zebra_if
*zif
;
2129 struct zebra_l2info_vxlan
*vxl
;
2130 struct interface
*vlan_if
;
2133 if (IS_ZEBRA_DEBUG_VXLAN
)
2134 zlog_debug("Adding L2-VNI %u - transition from L3-VNI",
2137 /* Find VxLAN interface for this VNI. */
2138 zns
= zebra_ns_lookup(NS_DEFAULT
);
2139 for (rn
= route_top(zns
->if_table
); rn
; rn
= route_next(rn
)) {
2140 ifp
= (struct interface
*)rn
->info
;
2144 if (!zif
|| zif
->zif_type
!= ZEBRA_IF_VXLAN
)
2147 vxl
= &zif
->l2info
.vxl
;
2148 if (vxl
->vni
== vni
) {
2155 if (IS_ZEBRA_DEBUG_VXLAN
)
2157 "Adding L2-VNI - Failed to find VxLAN interface for VNI %u",
2162 /* Create VNI hash entry for L2VNI */
2163 zevpn
= zebra_evpn_lookup(vni
);
2167 zevpn
= zebra_evpn_add(vni
);
2169 /* Find bridge interface for the VNI */
2170 vlan_if
= zvni_map_to_svi(vxl
->access_vlan
,
2171 zif
->brslave_info
.br_if
);
2173 zevpn
->vrf_id
= vlan_if
->vrf
->vrf_id
;
2174 zl3vni
= zl3vni_from_vrf(vlan_if
->vrf
->vrf_id
);
2176 listnode_add_sort_nodup(zl3vni
->l2vnis
, zevpn
);
2179 zevpn
->vxlan_if
= ifp
;
2180 zevpn
->local_vtep_ip
= vxl
->vtep_ip
;
2182 /* Inform BGP if the VNI is up and mapped to a bridge. */
2183 if (if_is_operative(ifp
) && zif
->brslave_info
.br_if
) {
2184 zebra_evpn_send_add_to_client(zevpn
);
2185 zebra_evpn_read_mac_neigh(zevpn
, ifp
);
2192 /* delete and uninstall rmac hash entry */
2193 static void zl3vni_del_rmac_hash_entry(struct hash_bucket
*bucket
, void *ctx
)
2195 struct zebra_mac
*zrmac
= NULL
;
2196 struct zebra_l3vni
*zl3vni
= NULL
;
2198 zrmac
= (struct zebra_mac
*)bucket
->data
;
2199 zl3vni
= (struct zebra_l3vni
*)ctx
;
2200 zl3vni_rmac_uninstall(zl3vni
, zrmac
);
2202 /* Send RMAC for FPM processing */
2203 hook_call(zebra_rmac_update
, zrmac
, zl3vni
, true, "RMAC deleted");
2205 zl3vni_rmac_del(zl3vni
, zrmac
);
2208 /* delete and uninstall nh hash entry */
2209 static void zl3vni_del_nh_hash_entry(struct hash_bucket
*bucket
, void *ctx
)
2211 struct zebra_neigh
*n
= NULL
;
2212 struct zebra_l3vni
*zl3vni
= NULL
;
2214 n
= (struct zebra_neigh
*)bucket
->data
;
2215 zl3vni
= (struct zebra_l3vni
*)ctx
;
2216 zl3vni_nh_uninstall(zl3vni
, n
);
2217 zl3vni_nh_del(zl3vni
, n
);
2220 /* re-add remote rmac if needed */
2221 static int zebra_vxlan_readd_remote_rmac(struct zebra_l3vni
*zl3vni
,
2222 struct ethaddr
*rmac
)
2224 struct zebra_mac
*zrmac
= NULL
;
2226 zrmac
= zl3vni_rmac_lookup(zl3vni
, rmac
);
2230 if (IS_ZEBRA_DEBUG_VXLAN
)
2231 zlog_debug("Del remote RMAC %pEA L3VNI %u - readd",
2234 zl3vni_rmac_install(zl3vni
, zrmac
);
2238 /* Public functions */
2240 int is_l3vni_for_prefix_routes_only(vni_t vni
)
2242 struct zebra_l3vni
*zl3vni
= NULL
;
2244 zl3vni
= zl3vni_lookup(vni
);
2248 return CHECK_FLAG(zl3vni
->filter
, PREFIX_ROUTES_ONLY
) ? 1 : 0;
2251 /* handle evpn route in vrf table */
2252 void zebra_vxlan_evpn_vrf_route_add(vrf_id_t vrf_id
, const struct ethaddr
*rmac
,
2253 const struct ipaddr
*vtep_ip
,
2254 const struct prefix
*host_prefix
)
2256 struct zebra_l3vni
*zl3vni
= NULL
;
2257 struct ipaddr ipv4_vtep
;
2259 zl3vni
= zl3vni_from_vrf(vrf_id
);
2260 if (!zl3vni
|| !is_l3vni_oper_up(zl3vni
))
2264 * add the next hop neighbor -
2265 * neigh to be installed is the ipv6 nexthop neigh
2267 zl3vni_remote_nh_add(zl3vni
, vtep_ip
, rmac
, host_prefix
);
2270 * if the remote vtep is a ipv4 mapped ipv6 address convert it to ipv4
2271 * address. Rmac is programmed against the ipv4 vtep because we only
2272 * support ipv4 tunnels in the h/w right now
2274 memset(&ipv4_vtep
, 0, sizeof(ipv4_vtep
));
2275 ipv4_vtep
.ipa_type
= IPADDR_V4
;
2276 if (vtep_ip
->ipa_type
== IPADDR_V6
)
2277 ipv4_mapped_ipv6_to_ipv4(&vtep_ip
->ipaddr_v6
,
2278 &(ipv4_vtep
.ipaddr_v4
));
2280 memcpy(&(ipv4_vtep
.ipaddr_v4
), &vtep_ip
->ipaddr_v4
,
2281 sizeof(struct in_addr
));
2284 * add the rmac - remote rmac to be installed is against the ipv4
2287 zl3vni_remote_rmac_add(zl3vni
, rmac
, &ipv4_vtep
);
2290 /* handle evpn vrf route delete */
2291 void zebra_vxlan_evpn_vrf_route_del(vrf_id_t vrf_id
,
2292 struct ipaddr
*vtep_ip
,
2293 struct prefix
*host_prefix
)
2295 struct zebra_l3vni
*zl3vni
= NULL
;
2296 struct zebra_neigh
*nh
= NULL
;
2297 struct zebra_mac
*zrmac
= NULL
;
2299 zl3vni
= zl3vni_from_vrf(vrf_id
);
2303 /* find the next hop entry and rmac entry */
2304 nh
= zl3vni_nh_lookup(zl3vni
, vtep_ip
);
2307 zrmac
= zl3vni_rmac_lookup(zl3vni
, &nh
->emac
);
2309 /* delete the next hop entry */
2310 zl3vni_remote_nh_del(zl3vni
, nh
, host_prefix
);
2312 /* delete the rmac entry */
2314 zl3vni_remote_rmac_del(zl3vni
, zrmac
, vtep_ip
);
2317 void zebra_vxlan_print_specific_rmac_l3vni(struct vty
*vty
, vni_t l3vni
,
2318 struct ethaddr
*rmac
, bool use_json
)
2320 struct zebra_l3vni
*zl3vni
= NULL
;
2321 struct zebra_mac
*zrmac
= NULL
;
2322 json_object
*json
= NULL
;
2324 if (!is_evpn_enabled()) {
2326 vty_out(vty
, "{}\n");
2331 json
= json_object_new_object();
2333 zl3vni
= zl3vni_lookup(l3vni
);
2336 vty_out(vty
, "{}\n");
2338 vty_out(vty
, "%% L3-VNI %u doesn't exist\n", l3vni
);
2342 zrmac
= zl3vni_rmac_lookup(zl3vni
, rmac
);
2345 vty_out(vty
, "{}\n");
2348 "%% Requested RMAC doesn't exist in L3-VNI %u\n",
2353 zl3vni_print_rmac(zrmac
, vty
, json
);
2356 vty_json(vty
, json
);
2359 void zebra_vxlan_print_rmacs_l3vni(struct vty
*vty
, vni_t l3vni
, bool use_json
)
2361 struct zebra_l3vni
*zl3vni
;
2363 struct rmac_walk_ctx wctx
;
2364 json_object
*json
= NULL
;
2366 if (!is_evpn_enabled())
2369 zl3vni
= zl3vni_lookup(l3vni
);
2372 vty_out(vty
, "{}\n");
2374 vty_out(vty
, "%% L3-VNI %u does not exist\n", l3vni
);
2377 num_rmacs
= hashcount(zl3vni
->rmac_table
);
2382 json
= json_object_new_object();
2384 memset(&wctx
, 0, sizeof(wctx
));
2388 vty_out(vty
, "Number of Remote RMACs known for this VNI: %u\n",
2390 vty_out(vty
, "%-17s %-21s\n", "MAC", "Remote VTEP");
2392 json_object_int_add(json
, "numRmacs", num_rmacs
);
2394 hash_iterate(zl3vni
->rmac_table
, zl3vni_print_rmac_hash
, &wctx
);
2397 vty_json(vty
, json
);
2400 void zebra_vxlan_print_rmacs_all_l3vni(struct vty
*vty
, bool use_json
)
2402 json_object
*json
= NULL
;
2405 if (!is_evpn_enabled()) {
2407 vty_out(vty
, "{}\n");
2412 json
= json_object_new_object();
2416 hash_iterate(zrouter
.l3vni_table
,
2417 (void (*)(struct hash_bucket
*,
2418 void *))zl3vni_print_rmac_hash_all_vni
,
2422 vty_json(vty
, json
);
2425 void zebra_vxlan_print_specific_nh_l3vni(struct vty
*vty
, vni_t l3vni
,
2426 struct ipaddr
*ip
, bool use_json
)
2428 struct zebra_l3vni
*zl3vni
= NULL
;
2429 struct zebra_neigh
*n
= NULL
;
2430 json_object
*json
= NULL
;
2432 if (!is_evpn_enabled()) {
2434 vty_out(vty
, "{}\n");
2439 json
= json_object_new_object();
2441 zl3vni
= zl3vni_lookup(l3vni
);
2444 vty_out(vty
, "{}\n");
2446 vty_out(vty
, "%% L3-VNI %u does not exist\n", l3vni
);
2450 n
= zl3vni_nh_lookup(zl3vni
, ip
);
2453 vty_out(vty
, "{}\n");
2456 "%% Requested next-hop not present for L3-VNI %u",
2461 zl3vni_print_nh(n
, vty
, json
);
2464 vty_json(vty
, json
);
2467 void zebra_vxlan_print_nh_l3vni(struct vty
*vty
, vni_t l3vni
, bool use_json
)
2470 struct nh_walk_ctx wctx
;
2471 json_object
*json
= NULL
;
2472 struct zebra_l3vni
*zl3vni
= NULL
;
2474 if (!is_evpn_enabled())
2477 zl3vni
= zl3vni_lookup(l3vni
);
2480 vty_out(vty
, "{}\n");
2482 vty_out(vty
, "%% L3-VNI %u does not exist\n", l3vni
);
2486 num_nh
= hashcount(zl3vni
->nh_table
);
2491 json
= json_object_new_object();
2496 vty_out(vty
, "Number of NH Neighbors known for this VNI: %u\n",
2498 vty_out(vty
, "%-15s %-17s\n", "IP", "RMAC");
2500 json_object_int_add(json
, "numNextHops", num_nh
);
2502 hash_iterate(zl3vni
->nh_table
, zl3vni_print_nh_hash
, &wctx
);
2505 vty_json(vty
, json
);
2508 void zebra_vxlan_print_nh_all_l3vni(struct vty
*vty
, bool use_json
)
2510 json_object
*json
= NULL
;
2513 if (!is_evpn_enabled()) {
2515 vty_out(vty
, "{}\n");
2520 json
= json_object_new_object();
2524 hash_iterate(zrouter
.l3vni_table
,
2525 (void (*)(struct hash_bucket
*,
2526 void *))zl3vni_print_nh_hash_all_vni
,
2530 vty_json(vty
, json
);
2534 * Display L3 VNI information (VTY command handler).
2536 void zebra_vxlan_print_l3vni(struct vty
*vty
, vni_t vni
, bool use_json
)
2539 json_object
*json
= NULL
;
2540 struct zebra_l3vni
*zl3vni
= NULL
;
2542 if (!is_evpn_enabled()) {
2544 vty_out(vty
, "{}\n");
2548 zl3vni
= zl3vni_lookup(vni
);
2551 vty_out(vty
, "{}\n");
2553 vty_out(vty
, "%% VNI %u does not exist\n", vni
);
2558 json
= json_object_new_object();
2562 zl3vni_print(zl3vni
, (void *)args
);
2565 vty_json(vty
, json
);
2568 void zebra_vxlan_print_vrf_vni(struct vty
*vty
, struct zebra_vrf
*zvrf
,
2569 json_object
*json_vrfs
)
2571 char buf
[ETHER_ADDR_STRLEN
];
2572 struct zebra_l3vni
*zl3vni
= NULL
;
2574 zl3vni
= zl3vni_lookup(zvrf
->l3vni
);
2579 vty_out(vty
, "%-37s %-10u %-20s %-20s %-5s %-18s\n",
2580 zvrf_name(zvrf
), zl3vni
->vni
,
2581 zl3vni_vxlan_if_name(zl3vni
),
2582 zl3vni_svi_if_name(zl3vni
), zl3vni_state2str(zl3vni
),
2583 zl3vni_rmac2str(zl3vni
, buf
, sizeof(buf
)));
2585 json_object
*json_vrf
= NULL
;
2587 json_vrf
= json_object_new_object();
2588 json_object_string_add(json_vrf
, "vrf", zvrf_name(zvrf
));
2589 json_object_int_add(json_vrf
, "vni", zl3vni
->vni
);
2590 json_object_string_add(json_vrf
, "vxlanIntf",
2591 zl3vni_vxlan_if_name(zl3vni
));
2592 json_object_string_add(json_vrf
, "sviIntf",
2593 zl3vni_svi_if_name(zl3vni
));
2594 json_object_string_add(json_vrf
, "state",
2595 zl3vni_state2str(zl3vni
));
2596 json_object_string_add(
2597 json_vrf
, "routerMac",
2598 zl3vni_rmac2str(zl3vni
, buf
, sizeof(buf
)));
2599 json_object_array_add(json_vrfs
, json_vrf
);
2604 * Display Neighbors for a VNI (VTY command handler).
2606 void zebra_vxlan_print_neigh_vni(struct vty
*vty
, struct zebra_vrf
*zvrf
,
2607 vni_t vni
, bool use_json
)
2609 struct zebra_evpn
*zevpn
;
2611 struct neigh_walk_ctx wctx
;
2612 json_object
*json
= NULL
;
2614 if (!is_evpn_enabled())
2616 zevpn
= zebra_evpn_lookup(vni
);
2619 vty_out(vty
, "{}\n");
2621 vty_out(vty
, "%% VNI %u does not exist\n", vni
);
2624 num_neigh
= hashcount(zevpn
->neigh_table
);
2629 json
= json_object_new_object();
2631 /* Since we have IPv6 addresses to deal with which can vary widely in
2632 * size, we try to be a bit more elegant in display by first computing
2633 * the maximum width.
2635 memset(&wctx
, 0, sizeof(wctx
));
2638 wctx
.addr_width
= 15;
2640 hash_iterate(zevpn
->neigh_table
, zebra_evpn_find_neigh_addr_width
,
2645 "Number of ARPs (local and remote) known for this VNI: %u\n",
2647 zebra_evpn_print_neigh_hdr(vty
, &wctx
);
2649 json_object_int_add(json
, "numArpNd", num_neigh
);
2651 hash_iterate(zevpn
->neigh_table
, zebra_evpn_print_neigh_hash
, &wctx
);
2653 vty_json(vty
, json
);
2657 * Display neighbors across all VNIs (VTY command handler).
2659 void zebra_vxlan_print_neigh_all_vni(struct vty
*vty
, struct zebra_vrf
*zvrf
,
2660 bool print_dup
, bool use_json
)
2662 json_object
*json
= NULL
;
2665 if (!is_evpn_enabled())
2669 json
= json_object_new_object();
2673 args
[2] = (void *)(ptrdiff_t)print_dup
;
2675 hash_iterate(zvrf
->evpn_table
,
2676 (void (*)(struct hash_bucket
*,
2677 void *))zevpn_print_neigh_hash_all_evpn
,
2680 vty_json(vty
, json
);
2684 * Display neighbors across all VNIs in detail(VTY command handler).
2686 void zebra_vxlan_print_neigh_all_vni_detail(struct vty
*vty
,
2687 struct zebra_vrf
*zvrf
,
2688 bool print_dup
, bool use_json
)
2690 json_object
*json
= NULL
;
2693 if (!is_evpn_enabled())
2697 json
= json_object_new_object();
2701 args
[2] = (void *)(ptrdiff_t)print_dup
;
2703 hash_iterate(zvrf
->evpn_table
,
2704 (void (*)(struct hash_bucket
*,
2705 void *))zevpn_print_neigh_hash_all_evpn_detail
,
2708 vty_json(vty
, json
);
2712 * Display specific neighbor for a VNI, if present (VTY command handler).
2714 void zebra_vxlan_print_specific_neigh_vni(struct vty
*vty
,
2715 struct zebra_vrf
*zvrf
, vni_t vni
,
2716 struct ipaddr
*ip
, bool use_json
)
2718 struct zebra_evpn
*zevpn
;
2719 struct zebra_neigh
*n
;
2720 json_object
*json
= NULL
;
2722 if (!is_evpn_enabled())
2724 zevpn
= zebra_evpn_lookup(vni
);
2727 vty_out(vty
, "{}\n");
2729 vty_out(vty
, "%% VNI %u does not exist\n", vni
);
2732 n
= zebra_evpn_neigh_lookup(zevpn
, ip
);
2736 "%% Requested neighbor does not exist in VNI %u\n",
2741 json
= json_object_new_object();
2743 zebra_evpn_print_neigh(n
, vty
, json
);
2746 vty_json(vty
, json
);
2750 * Display neighbors for a VNI from specific VTEP (VTY command handler).
2751 * By definition, these are remote neighbors.
2753 void zebra_vxlan_print_neigh_vni_vtep(struct vty
*vty
, struct zebra_vrf
*zvrf
,
2754 vni_t vni
, struct in_addr vtep_ip
,
2757 struct zebra_evpn
*zevpn
;
2759 struct neigh_walk_ctx wctx
;
2760 json_object
*json
= NULL
;
2762 if (!is_evpn_enabled())
2764 zevpn
= zebra_evpn_lookup(vni
);
2767 vty_out(vty
, "{}\n");
2769 vty_out(vty
, "%% VNI %u does not exist\n", vni
);
2772 num_neigh
= hashcount(zevpn
->neigh_table
);
2777 json
= json_object_new_object();
2779 memset(&wctx
, 0, sizeof(wctx
));
2782 wctx
.addr_width
= 15;
2783 wctx
.flags
= SHOW_REMOTE_NEIGH_FROM_VTEP
;
2784 wctx
.r_vtep_ip
= vtep_ip
;
2786 hash_iterate(zevpn
->neigh_table
, zebra_evpn_find_neigh_addr_width
,
2788 hash_iterate(zevpn
->neigh_table
, zebra_evpn_print_neigh_hash
, &wctx
);
2791 vty_json(vty
, json
);
2795 * Display Duplicate detected Neighbors for a VNI
2796 * (VTY command handler).
2798 void zebra_vxlan_print_neigh_vni_dad(struct vty
*vty
,
2799 struct zebra_vrf
*zvrf
,
2803 struct zebra_evpn
*zevpn
;
2805 struct neigh_walk_ctx wctx
;
2806 json_object
*json
= NULL
;
2808 if (!is_evpn_enabled())
2811 zevpn
= zebra_evpn_lookup(vni
);
2813 vty_out(vty
, "%% VNI %u does not exist\n", vni
);
2817 num_neigh
= hashcount(zevpn
->neigh_table
);
2821 num_neigh
= num_dup_detected_neighs(zevpn
);
2826 json
= json_object_new_object();
2828 /* Since we have IPv6 addresses to deal with which can vary widely in
2829 * size, we try to be a bit more elegant in display by first computing
2830 * the maximum width.
2832 memset(&wctx
, 0, sizeof(wctx
));
2835 wctx
.addr_width
= 15;
2837 hash_iterate(zevpn
->neigh_table
, zebra_evpn_find_neigh_addr_width
,
2842 "Number of ARPs (local and remote) known for this VNI: %u\n",
2844 vty_out(vty
, "%*s %-6s %-8s %-17s %-30s\n",
2845 -wctx
.addr_width
, "IP", "Type",
2846 "State", "MAC", "Remote ES/VTEP");
2848 json_object_int_add(json
, "numArpNd", num_neigh
);
2850 hash_iterate(zevpn
->neigh_table
, zebra_evpn_print_dad_neigh_hash
,
2854 vty_json(vty
, json
);
2858 * Display MACs for a VNI (VTY command handler).
2860 void zebra_vxlan_print_macs_vni(struct vty
*vty
, struct zebra_vrf
*zvrf
,
2861 vni_t vni
, bool use_json
, bool detail
)
2863 struct zebra_evpn
*zevpn
;
2865 struct mac_walk_ctx wctx
;
2866 json_object
*json
= NULL
;
2867 json_object
*json_mac
= NULL
;
2869 if (!is_evpn_enabled())
2871 zevpn
= zebra_evpn_lookup(vni
);
2874 vty_out(vty
, "{}\n");
2876 vty_out(vty
, "%% VNI %u does not exist\n", vni
);
2879 num_macs
= num_valid_macs(zevpn
);
2884 json
= json_object_new_object();
2885 json_mac
= json_object_new_object();
2888 memset(&wctx
, 0, sizeof(wctx
));
2891 wctx
.json
= json_mac
;
2895 vty_out(vty
, "\nVNI %u #MACs (local and remote) %u\n\n",
2896 zevpn
->vni
, num_macs
);
2899 "Number of MACs (local and remote) known for this VNI: %u\n",
2902 "Flags: N=sync-neighs, I=local-inactive, P=peer-active, X=peer-proxy\n");
2903 vty_out(vty
, "%-17s %-6s %-5s %-30s %-5s %s\n", "MAC",
2904 "Type", "Flags", "Intf/Remote ES/VTEP", "VLAN",
2908 json_object_int_add(json
, "numMacs", num_macs
);
2911 hash_iterate(zevpn
->mac_table
, zebra_evpn_print_mac_hash_detail
,
2914 hash_iterate(zevpn
->mac_table
, zebra_evpn_print_mac_hash
,
2918 json_object_object_add(json
, "macs", json_mac
);
2919 vty_json(vty
, json
);
2924 * Display MACs for all VNIs (VTY command handler).
2926 void zebra_vxlan_print_macs_all_vni(struct vty
*vty
, struct zebra_vrf
*zvrf
,
2927 bool print_dup
, bool use_json
)
2929 struct mac_walk_ctx wctx
;
2930 json_object
*json
= NULL
;
2932 if (!is_evpn_enabled()) {
2934 vty_out(vty
, "{}\n");
2938 json
= json_object_new_object();
2940 memset(&wctx
, 0, sizeof(wctx
));
2943 wctx
.print_dup
= print_dup
;
2944 hash_iterate(zvrf
->evpn_table
, zevpn_print_mac_hash_all_evpn
, &wctx
);
2947 vty_json(vty
, json
);
2951 * Display MACs in detail for all VNIs (VTY command handler).
2953 void zebra_vxlan_print_macs_all_vni_detail(struct vty
*vty
,
2954 struct zebra_vrf
*zvrf
,
2955 bool print_dup
, bool use_json
)
2957 struct mac_walk_ctx wctx
;
2958 json_object
*json
= NULL
;
2960 if (!is_evpn_enabled()) {
2962 vty_out(vty
, "{}\n");
2966 json
= json_object_new_object();
2968 memset(&wctx
, 0, sizeof(wctx
));
2971 wctx
.print_dup
= print_dup
;
2972 hash_iterate(zvrf
->evpn_table
, zevpn_print_mac_hash_all_evpn_detail
,
2976 vty_json(vty
, json
);
2980 * Display MACs for all VNIs (VTY command handler).
2982 void zebra_vxlan_print_macs_all_vni_vtep(struct vty
*vty
,
2983 struct zebra_vrf
*zvrf
,
2984 struct in_addr vtep_ip
, bool use_json
)
2986 struct mac_walk_ctx wctx
;
2987 json_object
*json
= NULL
;
2989 if (!is_evpn_enabled())
2993 json
= json_object_new_object();
2995 memset(&wctx
, 0, sizeof(wctx
));
2997 wctx
.flags
= SHOW_REMOTE_MAC_FROM_VTEP
;
2998 wctx
.r_vtep_ip
= vtep_ip
;
3000 hash_iterate(zvrf
->evpn_table
, zevpn_print_mac_hash_all_evpn
, &wctx
);
3003 vty_json(vty
, json
);
3007 * Display specific MAC for a VNI, if present (VTY command handler).
3009 void zebra_vxlan_print_specific_mac_vni(struct vty
*vty
, struct zebra_vrf
*zvrf
,
3010 vni_t vni
, struct ethaddr
*macaddr
,
3013 struct zebra_evpn
*zevpn
;
3014 struct zebra_mac
*mac
;
3015 json_object
*json
= NULL
;
3017 if (!is_evpn_enabled())
3020 zevpn
= zebra_evpn_lookup(vni
);
3023 vty_out(vty
, "{}\n");
3025 vty_out(vty
, "%% VNI %u does not exist\n", vni
);
3028 mac
= zebra_evpn_mac_lookup(zevpn
, macaddr
);
3031 vty_out(vty
, "{}\n");
3034 "%% Requested MAC does not exist in VNI %u\n",
3040 json
= json_object_new_object();
3042 zebra_evpn_print_mac(mac
, vty
, json
);
3044 vty_json(vty
, json
);
3047 /* Print Duplicate MACs per VNI */
3048 void zebra_vxlan_print_macs_vni_dad(struct vty
*vty
,
3049 struct zebra_vrf
*zvrf
,
3050 vni_t vni
, bool use_json
)
3052 struct zebra_evpn
*zevpn
;
3053 struct mac_walk_ctx wctx
;
3055 json_object
*json
= NULL
;
3056 json_object
*json_mac
= NULL
;
3058 if (!is_evpn_enabled())
3061 zevpn
= zebra_evpn_lookup(vni
);
3063 vty_out(vty
, "%% VNI %u does not exist\n", vni
);
3067 num_macs
= num_valid_macs(zevpn
);
3071 num_macs
= num_dup_detected_macs(zevpn
);
3076 json
= json_object_new_object();
3077 json_mac
= json_object_new_object();
3080 memset(&wctx
, 0, sizeof(wctx
));
3083 wctx
.json
= json_mac
;
3087 "Number of MACs (local and remote) known for this VNI: %u\n",
3089 vty_out(vty
, "%-17s %-6s %-5s %-30s %-5s\n", "MAC", "Type",
3090 "Flags", "Intf/Remote ES/VTEP", "VLAN");
3092 json_object_int_add(json
, "numMacs", num_macs
);
3094 hash_iterate(zevpn
->mac_table
, zebra_evpn_print_dad_mac_hash
, &wctx
);
3097 json_object_object_add(json
, "macs", json_mac
);
3098 vty_json(vty
, json
);
3103 int zebra_vxlan_clear_dup_detect_vni_mac(struct zebra_vrf
*zvrf
, vni_t vni
,
3104 struct ethaddr
*macaddr
, char *errmsg
,
3107 struct zebra_evpn
*zevpn
;
3108 struct zebra_mac
*mac
;
3109 struct listnode
*node
= NULL
;
3110 struct zebra_neigh
*nbr
= NULL
;
3112 if (!is_evpn_enabled())
3115 zevpn
= zebra_evpn_lookup(vni
);
3117 snprintfrr(errmsg
, errmsg_len
, "VNI %u does not exist", vni
);
3121 mac
= zebra_evpn_mac_lookup(zevpn
, macaddr
);
3123 snprintf(errmsg
, errmsg_len
,
3124 "Requested MAC does not exist in VNI %u\n", vni
);
3128 if (!CHECK_FLAG(mac
->flags
, ZEBRA_MAC_DUPLICATE
)) {
3129 snprintfrr(errmsg
, errmsg_len
,
3130 "Requested MAC is not duplicate detected\n");
3134 /* Remove all IPs as duplicate associcated with this MAC */
3135 for (ALL_LIST_ELEMENTS_RO(mac
->neigh_list
, node
, nbr
)) {
3136 /* For local neigh mark inactive so MACIP update is generated
3137 * to BGP. This is a scenario where MAC update received
3138 * and detected as duplicate which marked neigh as duplicate.
3139 * Later local neigh update did not get a chance to relay
3140 * to BGP. Similarly remote macip update, neigh needs to be
3141 * installed locally.
3143 if (zvrf
->dad_freeze
&&
3144 CHECK_FLAG(nbr
->flags
, ZEBRA_NEIGH_DUPLICATE
)) {
3145 if (CHECK_FLAG(nbr
->flags
, ZEBRA_NEIGH_LOCAL
))
3146 ZEBRA_NEIGH_SET_INACTIVE(nbr
);
3147 else if (CHECK_FLAG(nbr
->flags
, ZEBRA_NEIGH_REMOTE
))
3148 zebra_evpn_rem_neigh_install(
3149 zevpn
, nbr
, false /*was_static*/);
3152 UNSET_FLAG(nbr
->flags
, ZEBRA_NEIGH_DUPLICATE
);
3154 nbr
->detect_start_time
.tv_sec
= 0;
3155 nbr
->dad_dup_detect_time
= 0;
3158 UNSET_FLAG(mac
->flags
, ZEBRA_MAC_DUPLICATE
);
3160 mac
->detect_start_time
.tv_sec
= 0;
3161 mac
->detect_start_time
.tv_usec
= 0;
3162 mac
->dad_dup_detect_time
= 0;
3163 THREAD_OFF(mac
->dad_mac_auto_recovery_timer
);
3165 /* warn-only action return */
3166 if (!zvrf
->dad_freeze
)
3169 /* Local: Notify Peer VTEPs, Remote: Install the entry */
3170 if (CHECK_FLAG(mac
->flags
, ZEBRA_MAC_LOCAL
)) {
3172 if (zebra_evpn_mac_send_add_to_client(zevpn
->vni
, &mac
->macaddr
,
3173 mac
->flags
, mac
->loc_seq
,
3177 /* Process all neighbors associated with this MAC. */
3178 zebra_evpn_process_neigh_on_local_mac_change(zevpn
, mac
, 0,
3181 } else if (CHECK_FLAG(mac
->flags
, ZEBRA_MAC_REMOTE
)) {
3182 zebra_evpn_process_neigh_on_remote_mac_add(zevpn
, mac
);
3184 /* Install the entry. */
3185 zebra_evpn_rem_mac_install(zevpn
, mac
, false /* was_static */);
3191 int zebra_vxlan_clear_dup_detect_vni_ip(struct zebra_vrf
*zvrf
, vni_t vni
,
3192 struct ipaddr
*ip
, char *errmsg
,
3195 struct zebra_evpn
*zevpn
;
3196 struct zebra_neigh
*nbr
;
3197 struct zebra_mac
*mac
;
3198 char buf
[INET6_ADDRSTRLEN
];
3199 char buf2
[ETHER_ADDR_STRLEN
];
3201 if (!is_evpn_enabled())
3204 zevpn
= zebra_evpn_lookup(vni
);
3206 snprintfrr(errmsg
, errmsg_len
, "VNI %u does not exist\n", vni
);
3210 nbr
= zebra_evpn_neigh_lookup(zevpn
, ip
);
3212 snprintfrr(errmsg
, errmsg_len
,
3213 "Requested host IP does not exist in VNI %u\n", vni
);
3217 ipaddr2str(&nbr
->ip
, buf
, sizeof(buf
));
3219 if (!CHECK_FLAG(nbr
->flags
, ZEBRA_NEIGH_DUPLICATE
)) {
3220 snprintfrr(errmsg
, errmsg_len
,
3221 "Requested host IP %s is not duplicate detected\n",
3226 mac
= zebra_evpn_mac_lookup(zevpn
, &nbr
->emac
);
3228 if (CHECK_FLAG(mac
->flags
, ZEBRA_MAC_DUPLICATE
)) {
3231 "Requested IP's associated MAC %s is still in duplicate state\n",
3232 prefix_mac2str(&nbr
->emac
, buf2
, sizeof(buf2
)));
3236 if (IS_ZEBRA_DEBUG_VXLAN
)
3237 zlog_debug("%s: clear neigh %s in dup state, flags 0x%x seq %u",
3238 __func__
, buf
, nbr
->flags
, nbr
->loc_seq
);
3240 UNSET_FLAG(nbr
->flags
, ZEBRA_NEIGH_DUPLICATE
);
3242 nbr
->detect_start_time
.tv_sec
= 0;
3243 nbr
->detect_start_time
.tv_usec
= 0;
3244 nbr
->dad_dup_detect_time
= 0;
3245 THREAD_OFF(nbr
->dad_ip_auto_recovery_timer
);
3247 if (!!CHECK_FLAG(nbr
->flags
, ZEBRA_NEIGH_LOCAL
)) {
3248 zebra_evpn_neigh_send_add_to_client(zevpn
->vni
, ip
, &nbr
->emac
,
3249 nbr
->mac
, nbr
->flags
,
3251 } else if (!!CHECK_FLAG(nbr
->flags
, ZEBRA_NEIGH_REMOTE
)) {
3252 zebra_evpn_rem_neigh_install(zevpn
, nbr
, false /*was_static*/);
3258 static void zevpn_clear_dup_mac_hash(struct hash_bucket
*bucket
, void *ctxt
)
3260 struct mac_walk_ctx
*wctx
= ctxt
;
3261 struct zebra_mac
*mac
;
3262 struct zebra_evpn
*zevpn
;
3263 struct listnode
*node
= NULL
;
3264 struct zebra_neigh
*nbr
= NULL
;
3266 mac
= (struct zebra_mac
*)bucket
->data
;
3270 zevpn
= wctx
->zevpn
;
3272 if (!CHECK_FLAG(mac
->flags
, ZEBRA_MAC_DUPLICATE
))
3275 UNSET_FLAG(mac
->flags
, ZEBRA_MAC_DUPLICATE
);
3277 mac
->detect_start_time
.tv_sec
= 0;
3278 mac
->detect_start_time
.tv_usec
= 0;
3279 mac
->dad_dup_detect_time
= 0;
3280 THREAD_OFF(mac
->dad_mac_auto_recovery_timer
);
3282 /* Remove all IPs as duplicate associcated with this MAC */
3283 for (ALL_LIST_ELEMENTS_RO(mac
->neigh_list
, node
, nbr
)) {
3284 if (CHECK_FLAG(nbr
->flags
, ZEBRA_NEIGH_LOCAL
)
3286 ZEBRA_NEIGH_SET_INACTIVE(nbr
);
3288 UNSET_FLAG(nbr
->flags
, ZEBRA_NEIGH_DUPLICATE
);
3290 nbr
->detect_start_time
.tv_sec
= 0;
3291 nbr
->dad_dup_detect_time
= 0;
3294 /* Local: Notify Peer VTEPs, Remote: Install the entry */
3295 if (CHECK_FLAG(mac
->flags
, ZEBRA_MAC_LOCAL
)) {
3297 if (zebra_evpn_mac_send_add_to_client(zevpn
->vni
, &mac
->macaddr
,
3298 mac
->flags
, mac
->loc_seq
,
3302 /* Process all neighbors associated with this MAC. */
3303 zebra_evpn_process_neigh_on_local_mac_change(zevpn
, mac
, 0,
3306 } else if (CHECK_FLAG(mac
->flags
, ZEBRA_MAC_REMOTE
)) {
3307 zebra_evpn_process_neigh_on_remote_mac_add(zevpn
, mac
);
3309 /* Install the entry. */
3310 zebra_evpn_rem_mac_install(zevpn
, mac
, false /* was_static */);
3314 static void zevpn_clear_dup_detect_hash_vni_all(struct hash_bucket
*bucket
,
3317 struct zebra_evpn
*zevpn
;
3318 struct zebra_vrf
*zvrf
;
3319 struct mac_walk_ctx m_wctx
;
3320 struct neigh_walk_ctx n_wctx
;
3322 zevpn
= (struct zebra_evpn
*)bucket
->data
;
3326 zvrf
= (struct zebra_vrf
*)args
[0];
3328 if (hashcount(zevpn
->neigh_table
)) {
3329 memset(&n_wctx
, 0, sizeof(n_wctx
));
3330 n_wctx
.zevpn
= zevpn
;
3332 hash_iterate(zevpn
->neigh_table
,
3333 zebra_evpn_clear_dup_neigh_hash
, &n_wctx
);
3336 if (num_valid_macs(zevpn
)) {
3337 memset(&m_wctx
, 0, sizeof(m_wctx
));
3338 m_wctx
.zevpn
= zevpn
;
3340 hash_iterate(zevpn
->mac_table
, zevpn_clear_dup_mac_hash
, &m_wctx
);
3345 int zebra_vxlan_clear_dup_detect_vni_all(struct zebra_vrf
*zvrf
)
3349 if (!is_evpn_enabled())
3354 hash_iterate(zvrf
->evpn_table
,
3355 (void (*)(struct hash_bucket
*, void *))
3356 zevpn_clear_dup_detect_hash_vni_all
, args
);
3361 int zebra_vxlan_clear_dup_detect_vni(struct zebra_vrf
*zvrf
, vni_t vni
)
3363 struct zebra_evpn
*zevpn
;
3364 struct mac_walk_ctx m_wctx
;
3365 struct neigh_walk_ctx n_wctx
;
3367 if (!is_evpn_enabled())
3370 zevpn
= zebra_evpn_lookup(vni
);
3372 zlog_warn("VNI %u does not exist", vni
);
3376 if (hashcount(zevpn
->neigh_table
)) {
3377 memset(&n_wctx
, 0, sizeof(n_wctx
));
3378 n_wctx
.zevpn
= zevpn
;
3380 hash_iterate(zevpn
->neigh_table
,
3381 zebra_evpn_clear_dup_neigh_hash
, &n_wctx
);
3384 if (num_valid_macs(zevpn
)) {
3385 memset(&m_wctx
, 0, sizeof(m_wctx
));
3386 m_wctx
.zevpn
= zevpn
;
3388 hash_iterate(zevpn
->mac_table
, zevpn_clear_dup_mac_hash
, &m_wctx
);
3395 * Display MACs for a VNI from specific VTEP (VTY command handler).
3397 void zebra_vxlan_print_macs_vni_vtep(struct vty
*vty
, struct zebra_vrf
*zvrf
,
3398 vni_t vni
, struct in_addr vtep_ip
,
3401 struct zebra_evpn
*zevpn
;
3403 struct mac_walk_ctx wctx
;
3404 json_object
*json
= NULL
;
3405 json_object
*json_mac
= NULL
;
3407 if (!is_evpn_enabled())
3409 zevpn
= zebra_evpn_lookup(vni
);
3412 vty_out(vty
, "{}\n");
3414 vty_out(vty
, "%% VNI %u does not exist\n", vni
);
3417 num_macs
= num_valid_macs(zevpn
);
3422 json
= json_object_new_object();
3423 json_mac
= json_object_new_object();
3426 memset(&wctx
, 0, sizeof(wctx
));
3429 wctx
.flags
= SHOW_REMOTE_MAC_FROM_VTEP
;
3430 wctx
.r_vtep_ip
= vtep_ip
;
3431 wctx
.json
= json_mac
;
3432 hash_iterate(zevpn
->mac_table
, zebra_evpn_print_mac_hash
, &wctx
);
3435 json_object_int_add(json
, "numMacs", wctx
.count
);
3437 json_object_object_add(json
, "macs", json_mac
);
3438 vty_json(vty
, json
);
3444 * Display VNI information (VTY command handler).
3446 * use_json flag indicates that output should be in JSON format.
3447 * json_array is non NULL when JSON output needs to be aggregated (by the
3448 * caller) and then printed, otherwise, JSON evpn vni info is printed
3451 void zebra_vxlan_print_vni(struct vty
*vty
, struct zebra_vrf
*zvrf
, vni_t vni
,
3452 bool use_json
, json_object
*json_array
)
3454 json_object
*json
= NULL
;
3456 struct zebra_l3vni
*zl3vni
= NULL
;
3457 struct zebra_evpn
*zevpn
= NULL
;
3459 if (!is_evpn_enabled())
3463 json
= json_object_new_object();
3468 zl3vni
= zl3vni_lookup(vni
);
3470 zl3vni_print(zl3vni
, (void *)args
);
3472 zevpn
= zebra_evpn_lookup(vni
);
3474 zebra_evpn_print(zevpn
, (void *)args
);
3476 vty_out(vty
, "%% VNI %u does not exist\n", vni
);
3481 * Each "json" object contains info about 1 VNI.
3482 * When "json_array" is non-null, we aggreggate the json output
3483 * into json_array and print it as a JSON array.
3486 json_object_array_add(json_array
, json
);
3488 vty_json(vty
, json
);
3492 /* Display all global details for EVPN */
3493 void zebra_vxlan_print_evpn(struct vty
*vty
, bool uj
)
3498 json_object
*json
= NULL
;
3499 struct zebra_vrf
*zvrf
= NULL
;
3501 if (!is_evpn_enabled())
3504 zvrf
= zebra_vrf_get_evpn();
3506 num_l3vnis
= hashcount(zrouter
.l3vni_table
);
3507 num_l2vnis
= hashcount(zvrf
->evpn_table
);
3508 num_vnis
= num_l2vnis
+ num_l3vnis
;
3511 json
= json_object_new_object();
3512 json_object_string_add(json
, "advertiseGatewayMacip",
3513 zvrf
->advertise_gw_macip
? "Yes" : "No");
3514 json_object_string_add(json
, "advertiseSviMacip",
3515 zvrf
->advertise_svi_macip
? "Yes"
3517 json_object_string_add(json
, "advertiseSviMac",
3518 zebra_evpn_mh_do_adv_svi_mac() ? "Yes"
3520 json_object_int_add(json
, "numVnis", num_vnis
);
3521 json_object_int_add(json
, "numL2Vnis", num_l2vnis
);
3522 json_object_int_add(json
, "numL3Vnis", num_l3vnis
);
3523 if (zebra_evpn_do_dup_addr_detect(zvrf
))
3524 json_object_boolean_true_add(json
,
3525 "isDuplicateAddrDetection");
3527 json_object_boolean_false_add(json
,
3528 "isDuplicateAddrDetection");
3529 json_object_int_add(json
, "maxMoves", zvrf
->dad_max_moves
);
3530 json_object_int_add(json
, "detectionTime", zvrf
->dad_time
);
3531 json_object_int_add(json
, "detectionFreezeTime",
3532 zvrf
->dad_freeze_time
);
3533 zebra_evpn_mh_json(json
);
3535 vty_out(vty
, "L2 VNIs: %u\n", num_l2vnis
);
3536 vty_out(vty
, "L3 VNIs: %u\n", num_l3vnis
);
3537 vty_out(vty
, "Advertise gateway mac-ip: %s\n",
3538 zvrf
->advertise_gw_macip
? "Yes" : "No");
3539 vty_out(vty
, "Advertise svi mac-ip: %s\n",
3540 zvrf
->advertise_svi_macip
? "Yes" : "No");
3541 vty_out(vty
, "Advertise svi mac: %s\n",
3542 zebra_evpn_mh_do_adv_svi_mac() ? "Yes" : "No");
3543 vty_out(vty
, "Duplicate address detection: %s\n",
3544 zebra_evpn_do_dup_addr_detect(zvrf
) ? "Enable"
3546 vty_out(vty
, " Detection max-moves %u, time %d\n",
3547 zvrf
->dad_max_moves
, zvrf
->dad_time
);
3548 if (zvrf
->dad_freeze
) {
3549 if (zvrf
->dad_freeze_time
)
3550 vty_out(vty
, " Detection freeze %u\n",
3551 zvrf
->dad_freeze_time
);
3553 vty_out(vty
, " Detection freeze %s\n",
3556 zebra_evpn_mh_print(vty
);
3560 vty_json(vty
, json
);
3564 * Display VNI hash table (VTY command handler).
3566 void zebra_vxlan_print_vnis(struct vty
*vty
, struct zebra_vrf
*zvrf
,
3569 json_object
*json
= NULL
;
3572 if (!is_evpn_enabled())
3576 json
= json_object_new_object();
3578 vty_out(vty
, "%-10s %-4s %-21s %-8s %-8s %-15s %-37s\n", "VNI",
3579 "Type", "VxLAN IF", "# MACs", "# ARPs",
3580 "# Remote VTEPs", "Tenant VRF");
3585 /* Display all L2-VNIs */
3588 (void (*)(struct hash_bucket
*, void *))zebra_evpn_print_hash
,
3591 /* Display all L3-VNIs */
3592 hash_iterate(zrouter
.l3vni_table
,
3593 (void (*)(struct hash_bucket
*, void *))zl3vni_print_hash
,
3597 vty_json(vty
, json
);
3600 void zebra_vxlan_dup_addr_detection(ZAPI_HANDLER_ARGS
)
3604 uint32_t max_moves
= 0;
3605 uint32_t freeze_time
= 0;
3606 bool dup_addr_detect
= false;
3607 bool freeze
= false;
3608 bool old_addr_detect
;
3611 STREAM_GETL(s
, dup_addr_detect
);
3612 STREAM_GETL(s
, time
);
3613 STREAM_GETL(s
, max_moves
);
3614 STREAM_GETL(s
, freeze
);
3615 STREAM_GETL(s
, freeze_time
);
3617 old_addr_detect
= zebra_evpn_do_dup_addr_detect(zvrf
);
3618 zvrf
->dup_addr_detect
= dup_addr_detect
;
3619 dup_addr_detect
= zebra_evpn_do_dup_addr_detect(zvrf
);
3621 /* DAD previous state was enabled, and new state is disable,
3622 * clear all duplicate detected addresses.
3624 if (old_addr_detect
&& !dup_addr_detect
)
3625 zebra_vxlan_clear_dup_detect_vni_all(zvrf
);
3627 zvrf
->dad_time
= time
;
3628 zvrf
->dad_max_moves
= max_moves
;
3629 zvrf
->dad_freeze
= freeze
;
3630 zvrf
->dad_freeze_time
= freeze_time
;
3632 if (IS_ZEBRA_DEBUG_VXLAN
)
3634 "VRF %s duplicate detect %s max_moves %u timeout %u freeze %s freeze_time %u",
3635 vrf_id_to_name(zvrf
->vrf
->vrf_id
),
3636 dup_addr_detect
? "enable" : "disable",
3637 zvrf
->dad_max_moves
, zvrf
->dad_time
,
3638 zvrf
->dad_freeze
? "enable" : "disable",
3639 zvrf
->dad_freeze_time
);
3646 * Display VNI hash table in detail(VTY command handler).
3648 void zebra_vxlan_print_vnis_detail(struct vty
*vty
, struct zebra_vrf
*zvrf
,
3651 json_object
*json_array
= NULL
;
3652 struct zebra_ns
*zns
= NULL
;
3653 struct zebra_evpn_show zes
;
3655 if (!is_evpn_enabled())
3658 zns
= zebra_ns_lookup(NS_DEFAULT
);
3663 json_array
= json_object_new_array();
3666 zes
.json
= json_array
;
3668 zes
.use_json
= use_json
;
3670 /* Display all L2-VNIs */
3671 hash_iterate(zvrf
->evpn_table
,
3672 (void (*)(struct hash_bucket
*,
3673 void *))zebra_evpn_print_hash_detail
,
3676 /* Display all L3-VNIs */
3677 hash_iterate(zrouter
.l3vni_table
,
3678 (void (*)(struct hash_bucket
*,
3679 void *))zl3vni_print_hash_detail
,
3683 vty_json(vty
, json_array
);
3687 * Handle neighbor delete notification from the kernel (on a VLAN device
3688 * / L3 interface). This may result in either the neighbor getting deleted
3689 * from our database or being re-added to the kernel (if it is a valid
3692 int zebra_vxlan_handle_kernel_neigh_del(struct interface
*ifp
,
3693 struct interface
*link_if
,
3696 struct zebra_evpn
*zevpn
= NULL
;
3697 struct zebra_l3vni
*zl3vni
= NULL
;
3699 /* check if this is a remote neigh entry corresponding to remote
3702 zl3vni
= zl3vni_from_svi(ifp
, link_if
);
3704 return zl3vni_local_nh_del(zl3vni
, ip
);
3706 /* We are only interested in neighbors on an SVI that resides on top
3707 * of a VxLAN bridge.
3709 zevpn
= zebra_evpn_from_svi(ifp
, link_if
);
3711 if (IS_ZEBRA_DEBUG_VXLAN
)
3713 "%s: Del neighbor %pIA EVPN is not present for interface %s",
3714 __func__
, ip
, ifp
->name
);
3718 if (!zevpn
->vxlan_if
) {
3720 "VNI %u hash %p doesn't have intf upon local neighbor DEL",
3725 if (IS_ZEBRA_DEBUG_VXLAN
)
3726 zlog_debug("Del neighbor %pIA intf %s(%u) -> L2-VNI %u",
3727 ip
, ifp
->name
, ifp
->ifindex
, zevpn
->vni
);
3729 return zebra_evpn_neigh_del_ip(zevpn
, ip
);
3733 * Handle neighbor add or update notification from the kernel (on a VLAN
3734 * device / L3 interface). This is typically for a local neighbor but can
3735 * also be for a remote neighbor (e.g., ageout notification). It could
3736 * also be a "move" scenario.
3738 int zebra_vxlan_handle_kernel_neigh_update(struct interface
*ifp
,
3739 struct interface
*link_if
,
3741 struct ethaddr
*macaddr
,
3745 bool local_inactive
, bool dp_static
)
3747 struct zebra_evpn
*zevpn
= NULL
;
3748 struct zebra_l3vni
*zl3vni
= NULL
;
3750 /* check if this is a remote neigh entry corresponding to remote
3753 zl3vni
= zl3vni_from_svi(ifp
, link_if
);
3755 return zl3vni_local_nh_add_update(zl3vni
, ip
, state
);
3757 /* We are only interested in neighbors on an SVI that resides on top
3758 * of a VxLAN bridge.
3760 zevpn
= zebra_evpn_from_svi(ifp
, link_if
);
3764 if (IS_ZEBRA_DEBUG_VXLAN
|| IS_ZEBRA_DEBUG_EVPN_MH_NEIGH
)
3766 "Add/Update neighbor %pIA MAC %pEA intf %s(%u) state 0x%x %s%s%s%s-> L2-VNI %u",
3767 ip
, macaddr
, ifp
->name
,
3768 ifp
->ifindex
, state
, is_ext
? "ext-learned " : "",
3769 is_router
? "router " : "",
3770 local_inactive
? "local_inactive " : "",
3771 dp_static
? "peer_sync " : "", zevpn
->vni
);
3773 /* Is this about a local neighbor or a remote one? */
3775 return zebra_evpn_local_neigh_update(zevpn
, ifp
, ip
, macaddr
,
3776 is_router
, local_inactive
,
3779 return zebra_evpn_remote_neigh_update(zevpn
, ifp
, ip
, macaddr
, state
);
3783 zebra_vxlan_remote_macip_helper(bool add
, struct stream
*s
, vni_t
*vni
,
3784 struct ethaddr
*macaddr
, uint16_t *ipa_len
,
3785 struct ipaddr
*ip
, struct in_addr
*vtep_ip
,
3786 uint8_t *flags
, uint32_t *seq
, esi_t
*esi
)
3791 * Obtain each remote MACIP and process.
3792 * Message contains VNI, followed by MAC followed by IP (if any)
3793 * followed by remote VTEP IP.
3795 memset(ip
, 0, sizeof(*ip
));
3796 STREAM_GETL(s
, *vni
);
3797 STREAM_GET(macaddr
->octet
, s
, ETH_ALEN
);
3798 STREAM_GETW(s
, *ipa_len
);
3801 if (*ipa_len
== IPV4_MAX_BYTELEN
)
3802 ip
->ipa_type
= IPADDR_V4
;
3803 else if (*ipa_len
== IPV6_MAX_BYTELEN
)
3804 ip
->ipa_type
= IPADDR_V6
;
3806 if (IS_ZEBRA_DEBUG_VXLAN
)
3808 "ipa_len *must* be %d or %d bytes in length not %d",
3809 IPV4_MAX_BYTELEN
, IPV6_MAX_BYTELEN
,
3811 goto stream_failure
;
3814 STREAM_GET(&ip
->ip
.addr
, s
, *ipa_len
);
3816 l
+= 4 + ETH_ALEN
+ 4 + *ipa_len
;
3817 STREAM_GET(&vtep_ip
->s_addr
, s
, IPV4_MAX_BYTELEN
);
3818 l
+= IPV4_MAX_BYTELEN
;
3821 STREAM_GETC(s
, *flags
);
3822 STREAM_GETL(s
, *seq
);
3824 STREAM_GET(esi
, s
, sizeof(esi_t
));
3835 * Handle message from client to delete a remote MACIP for a VNI.
3837 void zebra_vxlan_remote_macip_del(ZAPI_HANDLER_ARGS
)
3841 struct ethaddr macaddr
;
3843 struct in_addr vtep_ip
;
3844 uint16_t l
= 0, ipa_len
;
3845 char buf1
[INET6_ADDRSTRLEN
];
3849 while (l
< hdr
->length
) {
3850 int res_length
= zebra_vxlan_remote_macip_helper(
3851 false, s
, &vni
, &macaddr
, &ipa_len
, &ip
, &vtep_ip
, NULL
,
3854 if (res_length
== -1)
3855 goto stream_failure
;
3858 if (IS_ZEBRA_DEBUG_VXLAN
)
3860 "Recv MACIP DEL VNI %u MAC %pEA%s%s Remote VTEP %pI4 from %s",
3862 ipa_len
? " IP " : "",
3864 ipaddr2str(&ip
, buf1
, sizeof(buf1
)) : "",
3865 &vtep_ip
, zebra_route_string(client
->proto
));
3867 /* Enqueue to workqueue for processing */
3868 zebra_rib_queue_evpn_rem_macip_del(vni
, &macaddr
, &ip
, vtep_ip
);
3876 * Handle message from client to add a remote MACIP for a VNI. This
3877 * could be just the add of a MAC address or the add of a neighbor
3880 void zebra_vxlan_remote_macip_add(ZAPI_HANDLER_ARGS
)
3884 struct ethaddr macaddr
;
3886 struct in_addr vtep_ip
;
3887 uint16_t l
= 0, ipa_len
;
3890 char buf1
[INET6_ADDRSTRLEN
];
3892 char esi_buf
[ESI_STR_LEN
];
3894 if (!EVPN_ENABLED(zvrf
)) {
3895 zlog_debug("EVPN not enabled, ignoring remote MACIP ADD");
3901 while (l
< hdr
->length
) {
3903 int res_length
= zebra_vxlan_remote_macip_helper(
3904 true, s
, &vni
, &macaddr
, &ipa_len
, &ip
, &vtep_ip
,
3905 &flags
, &seq
, &esi
);
3907 if (res_length
== -1)
3908 goto stream_failure
;
3911 if (IS_ZEBRA_DEBUG_VXLAN
) {
3912 if (memcmp(&esi
, zero_esi
, sizeof(esi_t
)))
3913 esi_to_str(&esi
, esi_buf
, sizeof(esi_buf
));
3915 strlcpy(esi_buf
, "-", ESI_STR_LEN
);
3917 "Recv %sMACIP ADD VNI %u MAC %pEA%s%s flags 0x%x seq %u VTEP %pI4 ESI %s from %s",
3918 (flags
& ZEBRA_MACIP_TYPE_SYNC_PATH
) ?
3921 ipa_len
? " IP " : "",
3923 ipaddr2str(&ip
, buf1
, sizeof(buf1
)) : "",
3924 flags
, seq
, &vtep_ip
, esi_buf
,
3925 zebra_route_string(client
->proto
));
3928 /* Enqueue to workqueue for processing */
3929 zebra_rib_queue_evpn_rem_macip_add(vni
, &macaddr
, &ip
, flags
,
3930 seq
, vtep_ip
, &esi
);
3938 * Handle remote vtep delete by kernel; re-add the vtep if we have it
3940 int zebra_vxlan_check_readd_vtep(struct interface
*ifp
,
3941 struct in_addr vtep_ip
)
3943 struct zebra_if
*zif
;
3944 struct zebra_vrf
*zvrf
= NULL
;
3945 struct zebra_l2info_vxlan
*vxl
;
3947 struct zebra_evpn
*zevpn
= NULL
;
3948 struct zebra_vtep
*zvtep
= NULL
;
3952 vxl
= &zif
->l2info
.vxl
;
3955 /* If EVPN is not enabled, nothing to do. */
3956 if (!is_evpn_enabled())
3959 /* Locate VRF corresponding to interface. */
3960 zvrf
= ifp
->vrf
->info
;
3964 /* Locate hash entry; it is expected to exist. */
3965 zevpn
= zebra_evpn_lookup(vni
);
3969 /* If the remote vtep entry doesn't exists nothing to do */
3970 zvtep
= zebra_evpn_vtep_find(zevpn
, &vtep_ip
);
3974 if (IS_ZEBRA_DEBUG_VXLAN
)
3976 "Del MAC for remote VTEP %pI4 intf %s(%u) VNI %u - readd",
3977 &vtep_ip
, ifp
->name
, ifp
->ifindex
, vni
);
3979 zebra_evpn_vtep_install(zevpn
, zvtep
);
3984 * Handle notification of MAC add/update over VxLAN. If the kernel is notifying
3985 * us, this must involve a multihoming scenario. Treat this as implicit delete
3986 * of any prior local MAC.
3988 static int zebra_vxlan_check_del_local_mac(struct interface
*ifp
,
3989 struct interface
*br_if
,
3990 struct ethaddr
*macaddr
,
3993 struct zebra_if
*zif
;
3994 struct zebra_l2info_vxlan
*vxl
;
3996 struct zebra_evpn
*zevpn
;
3997 struct zebra_mac
*mac
;
4001 vxl
= &zif
->l2info
.vxl
;
4004 /* Check if EVPN is enabled. */
4005 if (!is_evpn_enabled())
4008 /* Locate hash entry; it is expected to exist. */
4009 zevpn
= zebra_evpn_lookup(vni
);
4013 /* If entry doesn't exist, nothing to do. */
4014 mac
= zebra_evpn_mac_lookup(zevpn
, macaddr
);
4018 /* Is it a local entry? */
4019 if (!CHECK_FLAG(mac
->flags
, ZEBRA_MAC_LOCAL
))
4022 if (IS_ZEBRA_DEBUG_VXLAN
)
4024 "Add/update remote MAC %pEA intf %s(%u) VNI %u flags 0x%x - del local",
4025 macaddr
, ifp
->name
, ifp
->ifindex
, vni
, mac
->flags
);
4027 /* Remove MAC from BGP. */
4028 zebra_evpn_mac_send_del_to_client(zevpn
->vni
, macaddr
, mac
->flags
,
4032 * If there are no neigh associated with the mac delete the mac
4033 * else mark it as AUTO for forward reference
4035 if (!listcount(mac
->neigh_list
)) {
4036 zebra_evpn_mac_del(zevpn
, mac
);
4038 zebra_evpn_mac_clear_fwd_info(mac
);
4039 UNSET_FLAG(mac
->flags
, ZEBRA_MAC_ALL_LOCAL_FLAGS
);
4040 UNSET_FLAG(mac
->flags
, ZEBRA_MAC_STICKY
);
4041 SET_FLAG(mac
->flags
, ZEBRA_MAC_AUTO
);
4047 /* MAC notification from the dataplane with a network dest port -
4048 * 1. This can be a local MAC on a down ES (if fast-failover is not possible
4049 * 2. Or it can be a remote MAC
4051 int zebra_vxlan_dp_network_mac_add(struct interface
*ifp
,
4052 struct interface
*br_if
,
4053 struct ethaddr
*macaddr
, vlanid_t vid
,
4054 uint32_t nhg_id
, bool sticky
, bool dp_static
)
4056 struct zebra_evpn_es
*es
;
4057 struct interface
*acc_ifp
;
4059 /* If netlink message is with vid, it will have no nexthop.
4063 if (IS_ZEBRA_DEBUG_VXLAN
|| IS_ZEBRA_DEBUG_EVPN_MH_MAC
)
4064 zlog_debug("dpAdd MAC %pEA VID %u - ignore as no nhid",
4069 /* Get vxlan's vid for netlink message has no it. */
4070 vid
= ((struct zebra_if
*)ifp
->info
)->l2info
.vxl
.access_vlan
;
4072 /* if remote mac delete the local entry */
4073 if (!nhg_id
|| !zebra_evpn_nhg_is_local_es(nhg_id
, &es
)
4074 || !zebra_evpn_es_local_mac_via_network_port(es
)) {
4075 if (IS_ZEBRA_DEBUG_VXLAN
|| IS_ZEBRA_DEBUG_EVPN_MH_MAC
)
4076 zlog_debug("dpAdd remote MAC %pEA VID %u", macaddr
,
4078 return zebra_vxlan_check_del_local_mac(ifp
, br_if
, macaddr
,
4082 /* If local MAC on a down local ES translate the network-mac-add
4083 * to a local-active-mac-add
4085 if (IS_ZEBRA_DEBUG_VXLAN
|| IS_ZEBRA_DEBUG_EVPN_MH_MAC
)
4086 zlog_debug("dpAdd local-nw-MAC %pEA VID %u", macaddr
, vid
);
4087 acc_ifp
= es
->zif
->ifp
;
4088 return zebra_vxlan_local_mac_add_update(
4089 acc_ifp
, br_if
, macaddr
, vid
, sticky
,
4090 false /* local_inactive */, dp_static
);
4094 * Handle network MAC delete by kernel -
4095 * 1. readd the remote MAC if we have it
4096 * 2. local MAC with does ES may also need to be re-installed
4098 int zebra_vxlan_dp_network_mac_del(struct interface
*ifp
,
4099 struct interface
*br_if
,
4100 struct ethaddr
*macaddr
, vlanid_t vid
)
4102 struct zebra_if
*zif
= NULL
;
4103 struct zebra_l2info_vxlan
*vxl
= NULL
;
4105 struct zebra_evpn
*zevpn
= NULL
;
4106 struct zebra_l3vni
*zl3vni
= NULL
;
4107 struct zebra_mac
*mac
= NULL
;
4111 vxl
= &zif
->l2info
.vxl
;
4114 /* Check if EVPN is enabled. */
4115 if (!is_evpn_enabled())
4118 /* check if this is a remote RMAC and readd simillar to remote macs */
4119 zl3vni
= zl3vni_lookup(vni
);
4121 return zebra_vxlan_readd_remote_rmac(zl3vni
, macaddr
);
4123 /* Locate hash entry; it is expected to exist. */
4124 zevpn
= zebra_evpn_lookup(vni
);
4128 /* If entry doesn't exist, nothing to do. */
4129 mac
= zebra_evpn_mac_lookup(zevpn
, macaddr
);
4133 if (CHECK_FLAG(mac
->flags
, ZEBRA_MAC_REMOTE
)) {
4134 /* If remote entry simply re-install */
4135 if (IS_ZEBRA_DEBUG_VXLAN
|| IS_ZEBRA_DEBUG_EVPN_MH_MAC
)
4137 "dpDel remote MAC %pEA intf %s(%u) VNI %u - readd",
4138 macaddr
, ifp
->name
, ifp
->ifindex
, vni
);
4139 zebra_evpn_rem_mac_install(zevpn
, mac
, false /* was_static */);
4140 } else if (CHECK_FLAG(mac
->flags
, ZEBRA_MAC_LOCAL
) && mac
->es
4141 && zebra_evpn_es_local_mac_via_network_port(mac
->es
)) {
4142 /* If local entry via nw-port call local-del which will
4143 * re-install entry in the dataplane is needed
4145 if (IS_ZEBRA_DEBUG_VXLAN
|| IS_ZEBRA_DEBUG_EVPN_MH_MAC
)
4146 zlog_debug("dpDel local-nw-MAC %pEA VNI %u", macaddr
,
4149 zebra_evpn_del_local_mac(zevpn
, mac
, false);
4156 * Handle local MAC delete (on a port or VLAN corresponding to this VNI).
4158 int zebra_vxlan_local_mac_del(struct interface
*ifp
, struct interface
*br_if
,
4159 struct ethaddr
*macaddr
, vlanid_t vid
)
4161 struct zebra_evpn
*zevpn
;
4162 struct zebra_mac
*mac
;
4164 /* We are interested in MACs only on ports or (port, VLAN) that
4167 zevpn
= zebra_evpn_map_vlan(ifp
, br_if
, vid
);
4170 if (!zevpn
->vxlan_if
) {
4172 "VNI %u hash %p doesn't have intf upon local MAC DEL",
4177 /* If entry doesn't exist, nothing to do. */
4178 mac
= zebra_evpn_mac_lookup(zevpn
, macaddr
);
4182 /* Is it a local entry? */
4183 if (!CHECK_FLAG(mac
->flags
, ZEBRA_MAC_LOCAL
))
4186 return zebra_evpn_del_local_mac(zevpn
, mac
, false);
4190 * Handle local MAC add (on a port or VLAN corresponding to this VNI).
4192 int zebra_vxlan_local_mac_add_update(struct interface
*ifp
,
4193 struct interface
*br_if
,
4194 struct ethaddr
*macaddr
, vlanid_t vid
,
4195 bool sticky
, bool local_inactive
,
4198 struct zebra_evpn
*zevpn
;
4199 struct zebra_vrf
*zvrf
;
4203 /* We are interested in MACs only on ports or (port, VLAN) that
4206 zevpn
= zebra_evpn_map_vlan(ifp
, br_if
, vid
);
4208 if (IS_ZEBRA_DEBUG_VXLAN
)
4210 " Add/Update %sMAC %pEA intf %s(%u) VID %u, could not find EVPN",
4211 sticky
? "sticky " : "", macaddr
,
4212 ifp
->name
, ifp
->ifindex
, vid
);
4216 if (!zevpn
->vxlan_if
) {
4217 if (IS_ZEBRA_DEBUG_VXLAN
)
4219 " VNI %u hash %p doesn't have intf upon local MAC ADD",
4224 zvrf
= zebra_vrf_get_evpn();
4225 return zebra_evpn_add_update_local_mac(zvrf
, zevpn
, ifp
, macaddr
, vid
,
4226 sticky
, local_inactive
,
4231 * Handle message from client to delete a remote VTEP for an EVPN.
4233 void zebra_vxlan_remote_vtep_del_zapi(ZAPI_HANDLER_ARGS
)
4236 unsigned short l
= 0;
4238 struct in_addr vtep_ip
;
4240 if (!is_evpn_enabled()) {
4242 "%s: EVPN is not enabled yet we have received a VTEP DEL msg",
4247 if (!EVPN_ENABLED(zvrf
)) {
4248 zlog_debug("Recv VTEP DEL zapi for non-EVPN VRF %u",
4255 while (l
< hdr
->length
) {
4256 int flood_control
__attribute__((unused
));
4258 /* Obtain each remote VTEP and process. */
4259 STREAM_GETL(s
, vni
);
4261 STREAM_GET(&vtep_ip
.s_addr
, s
, IPV4_MAX_BYTELEN
);
4262 l
+= IPV4_MAX_BYTELEN
;
4264 /* Flood control is intentionally ignored right now */
4265 STREAM_GETL(s
, flood_control
);
4268 if (IS_ZEBRA_DEBUG_VXLAN
)
4269 zlog_debug("Recv VTEP DEL %pI4 VNI %u from %s",
4271 zebra_route_string(client
->proto
));
4273 /* Enqueue for processing */
4274 zebra_rib_queue_evpn_rem_vtep_del(zvrf_id(zvrf
), vni
, vtep_ip
);
4282 * Handle message from client to delete a remote VTEP for an EVPN.
4284 void zebra_vxlan_remote_vtep_del(vrf_id_t vrf_id
, vni_t vni
,
4285 struct in_addr vtep_ip
)
4287 struct zebra_evpn
*zevpn
;
4288 struct zebra_vtep
*zvtep
;
4289 struct interface
*ifp
;
4290 struct zebra_if
*zif
;
4291 struct zebra_vrf
*zvrf
;
4293 if (!is_evpn_enabled()) {
4294 zlog_debug("%s: Can't process vtep del: EVPN is not enabled",
4299 zvrf
= zebra_vrf_lookup_by_id(vrf_id
);
4303 if (!EVPN_ENABLED(zvrf
)) {
4304 zlog_debug("Can't process VTEP DEL for non-EVPN VRF %u",
4309 /* Locate VNI hash entry - expected to exist. */
4310 zevpn
= zebra_evpn_lookup(vni
);
4312 if (IS_ZEBRA_DEBUG_VXLAN
)
4314 "Failed to locate VNI hash for remote VTEP DEL, VNI %u",
4319 ifp
= zevpn
->vxlan_if
;
4322 "VNI %u hash %p doesn't have intf upon remote VTEP DEL",
4328 /* If down or not mapped to a bridge, we're done. */
4329 if (!if_is_operative(ifp
) || !zif
->brslave_info
.br_if
)
4332 /* If the remote VTEP does not exist, there's nothing more to
4334 * Otherwise, uninstall any remote MACs pointing to this VTEP
4335 * and then, the VTEP entry itself and remove it.
4337 zvtep
= zebra_evpn_vtep_find(zevpn
, &vtep_ip
);
4341 zebra_evpn_vtep_uninstall(zevpn
, &vtep_ip
);
4342 zebra_evpn_vtep_del(zevpn
, zvtep
);
4346 * Handle message from client to add a remote VTEP for an EVPN.
4348 void zebra_vxlan_remote_vtep_add(vrf_id_t vrf_id
, vni_t vni
,
4349 struct in_addr vtep_ip
, int flood_control
)
4351 struct zebra_evpn
*zevpn
;
4352 struct interface
*ifp
;
4353 struct zebra_if
*zif
;
4354 struct zebra_vtep
*zvtep
;
4355 struct zebra_vrf
*zvrf
;
4357 if (!is_evpn_enabled()) {
4358 zlog_debug("%s: EVPN not enabled: can't process a VTEP ADD",
4363 zvrf
= zebra_vrf_lookup_by_id(vrf_id
);
4367 if (!EVPN_ENABLED(zvrf
)) {
4368 zlog_debug("Can't process VTEP ADD for non-EVPN VRF %u",
4373 /* Locate VNI hash entry - expected to exist. */
4374 zevpn
= zebra_evpn_lookup(vni
);
4377 EC_ZEBRA_VTEP_ADD_FAILED
,
4378 "Failed to locate EVPN hash upon remote VTEP ADD, VNI %u",
4383 ifp
= zevpn
->vxlan_if
;
4386 EC_ZEBRA_VTEP_ADD_FAILED
,
4387 "VNI %u hash %p doesn't have intf upon remote VTEP ADD",
4394 /* If down or not mapped to a bridge, we're done. */
4395 if (!if_is_operative(ifp
) || !zif
->brslave_info
.br_if
)
4398 zvtep
= zebra_evpn_vtep_find(zevpn
, &vtep_ip
);
4400 /* If the remote VTEP already exists check if
4401 * the flood mode has changed
4403 if (zvtep
->flood_control
!= flood_control
) {
4404 if (zvtep
->flood_control
== VXLAN_FLOOD_DISABLED
)
4405 /* old mode was head-end-replication but
4406 * is no longer; get rid of the HER fdb
4407 * entry installed before
4409 zebra_evpn_vtep_uninstall(zevpn
, &vtep_ip
);
4410 zvtep
->flood_control
= flood_control
;
4411 zebra_evpn_vtep_install(zevpn
, zvtep
);
4414 zvtep
= zebra_evpn_vtep_add(zevpn
, &vtep_ip
, flood_control
);
4416 zebra_evpn_vtep_install(zevpn
, zvtep
);
4418 flog_err(EC_ZEBRA_VTEP_ADD_FAILED
,
4419 "Failed to add remote VTEP, VNI %u zevpn %p",
4425 * Handle message from client to add a remote VTEP for an EVPN.
4427 void zebra_vxlan_remote_vtep_add_zapi(ZAPI_HANDLER_ARGS
)
4430 unsigned short l
= 0;
4432 struct in_addr vtep_ip
;
4435 if (!is_evpn_enabled()) {
4437 "%s: EVPN not enabled yet we received a VTEP ADD zapi msg",
4442 if (!EVPN_ENABLED(zvrf
)) {
4443 zlog_debug("Recv VTEP ADD zapi for non-EVPN VRF %u",
4450 while (l
< hdr
->length
) {
4451 /* Obtain each remote VTEP and process. */
4452 STREAM_GETL(s
, vni
);
4454 STREAM_GET(&vtep_ip
.s_addr
, s
, IPV4_MAX_BYTELEN
);
4455 STREAM_GETL(s
, flood_control
);
4456 l
+= IPV4_MAX_BYTELEN
+ 4;
4458 if (IS_ZEBRA_DEBUG_VXLAN
)
4459 zlog_debug("Recv VTEP ADD %pI4 VNI %u flood %d from %s",
4460 &vtep_ip
, vni
, flood_control
,
4461 zebra_route_string(client
->proto
));
4463 /* Enqueue for processing */
4464 zebra_rib_queue_evpn_rem_vtep_add(zvrf_id(zvrf
), vni
, vtep_ip
,
4473 * Add/Del gateway macip to evpn
4475 * 1. SVI interface on a vlan aware bridge
4476 * 2. SVI interface on a vlan unaware bridge
4477 * 3. vrr interface (MACVLAN) associated to a SVI
4478 * We advertise macip routes for an interface if it is associated to VxLan vlan
4480 int zebra_vxlan_add_del_gw_macip(struct interface
*ifp
, const struct prefix
*p
,
4484 struct ethaddr macaddr
;
4485 struct zebra_evpn
*zevpn
= NULL
;
4487 memset(&ip
, 0, sizeof(ip
));
4488 memset(&macaddr
, 0, sizeof(macaddr
));
4490 /* Check if EVPN is enabled. */
4491 if (!is_evpn_enabled())
4494 if (IS_ZEBRA_IF_MACVLAN(ifp
)) {
4495 struct interface
*svi_if
=
4496 NULL
; /* SVI corresponding to the MACVLAN */
4497 struct zebra_if
*ifp_zif
=
4498 NULL
; /* Zebra daemon specific info for MACVLAN */
4499 struct zebra_if
*svi_if_zif
=
4500 NULL
; /* Zebra daemon specific info for SVI*/
4502 ifp_zif
= ifp
->info
;
4507 * for a MACVLAN interface the link represents the svi_if
4509 svi_if
= if_lookup_by_index_per_ns(zebra_ns_lookup(NS_DEFAULT
),
4510 ifp_zif
->link_ifindex
);
4512 zlog_debug("MACVLAN %s(%u) without link information",
4513 ifp
->name
, ifp
->ifindex
);
4517 if (IS_ZEBRA_IF_VLAN(svi_if
)) {
4519 * If it is a vlan aware bridge then the link gives the
4520 * bridge information
4522 struct interface
*svi_if_link
= NULL
;
4524 svi_if_zif
= svi_if
->info
;
4526 svi_if_link
= if_lookup_by_index_per_ns(
4527 zebra_ns_lookup(NS_DEFAULT
),
4528 svi_if_zif
->link_ifindex
);
4529 zevpn
= zebra_evpn_from_svi(svi_if
,
4532 } else if (IS_ZEBRA_IF_BRIDGE(svi_if
)) {
4534 * If it is a vlan unaware bridge then svi is the bridge
4537 zevpn
= zebra_evpn_from_svi(svi_if
, svi_if
);
4539 } else if (IS_ZEBRA_IF_VLAN(ifp
)) {
4540 struct zebra_if
*svi_if_zif
=
4541 NULL
; /* Zebra daemon specific info for SVI */
4542 struct interface
*svi_if_link
=
4543 NULL
; /* link info for the SVI = bridge info */
4545 svi_if_zif
= ifp
->info
;
4547 svi_if_link
= if_lookup_by_index_per_ns(
4548 zebra_ns_lookup(NS_DEFAULT
),
4549 svi_if_zif
->link_ifindex
);
4551 zevpn
= zebra_evpn_from_svi(ifp
, svi_if_link
);
4553 } else if (IS_ZEBRA_IF_BRIDGE(ifp
)) {
4554 zevpn
= zebra_evpn_from_svi(ifp
, ifp
);
4560 if (!zevpn
->vxlan_if
) {
4561 zlog_debug("VNI %u hash %p doesn't have intf upon MACVLAN up",
4566 /* VRR IP is advertised only if gw-macip-adv-enabled */
4567 if (IS_ZEBRA_IF_MACVLAN(ifp
)) {
4568 if (!advertise_gw_macip_enabled(zevpn
))
4571 /* SVI IP is advertised if gw or svi macip-adv-enabled */
4572 if (!advertise_svi_macip_enabled(zevpn
)
4573 && !advertise_gw_macip_enabled(zevpn
))
4577 memcpy(&macaddr
.octet
, ifp
->hw_addr
, ETH_ALEN
);
4579 if (p
->family
== AF_INET
) {
4580 ip
.ipa_type
= IPADDR_V4
;
4581 memcpy(&(ip
.ipaddr_v4
), &(p
->u
.prefix4
),
4582 sizeof(struct in_addr
));
4583 } else if (p
->family
== AF_INET6
) {
4584 ip
.ipa_type
= IPADDR_V6
;
4585 memcpy(&(ip
.ipaddr_v6
), &(p
->u
.prefix6
),
4586 sizeof(struct in6_addr
));
4591 zebra_evpn_gw_macip_add(ifp
, zevpn
, &macaddr
, &ip
);
4593 zebra_evpn_gw_macip_del(ifp
, zevpn
, &ip
);
4599 * Handle SVI interface going down.
4600 * SVI can be associated to either L3-VNI or L2-VNI.
4601 * For L2-VNI: At this point, this is a NOP since
4602 * the kernel deletes the neighbor entries on this SVI (if any).
4603 * We only need to update the vrf corresponding to zevpn.
4604 * For L3-VNI: L3-VNI is operationally down, update mac-ip routes and delete
4607 int zebra_vxlan_svi_down(struct interface
*ifp
, struct interface
*link_if
)
4609 struct zebra_l3vni
*zl3vni
= NULL
;
4611 zl3vni
= zl3vni_from_svi(ifp
, link_if
);
4614 /* process l3-vni down */
4615 zebra_vxlan_process_l3vni_oper_down(zl3vni
);
4617 /* remove association with svi-if */
4618 zl3vni
->svi_if
= NULL
;
4620 struct zebra_evpn
*zevpn
= NULL
;
4622 /* Unlink the SVI from the access VLAN */
4623 zebra_evpn_acc_bd_svi_set(ifp
->info
, link_if
->info
, false);
4625 /* since we dont have svi corresponding to zevpn, we associate it
4626 * to default vrf. Note: the corresponding neigh entries on the
4627 * SVI would have already been deleted */
4628 zevpn
= zebra_evpn_from_svi(ifp
, link_if
);
4631 /* remove from l3-vni list */
4632 zl3vni
= zl3vni_from_vrf(zevpn
->vrf_id
);
4634 listnode_delete(zl3vni
->l2vnis
, zevpn
);
4636 zevpn
->svi_if
= NULL
;
4637 zevpn
->vrf_id
= VRF_DEFAULT
;
4639 /* update the tenant vrf in BGP */
4640 if (if_is_operative(zevpn
->vxlan_if
))
4641 zebra_evpn_send_add_to_client(zevpn
);
4648 * Handle SVI interface coming up.
4649 * SVI can be associated to L3-VNI (l3vni vxlan interface) or L2-VNI (l2-vni
4651 * For L2-VNI: we need to install any remote neighbors entried (used for
4653 * For L3-VNI: SVI will be used to get the rmac to be used with L3-VNI
4655 int zebra_vxlan_svi_up(struct interface
*ifp
, struct interface
*link_if
)
4657 struct zebra_evpn
*zevpn
= NULL
;
4658 struct zebra_l3vni
*zl3vni
= NULL
;
4660 zl3vni
= zl3vni_from_svi(ifp
, link_if
);
4663 /* associate with svi */
4664 zl3vni
->svi_if
= ifp
;
4666 /* process oper-up */
4667 if (is_l3vni_oper_up(zl3vni
))
4668 zebra_vxlan_process_l3vni_oper_up(zl3vni
);
4671 /* process SVI up for l2-vni */
4672 struct neigh_walk_ctx n_wctx
;
4674 zevpn
= zebra_evpn_from_svi(ifp
, link_if
);
4678 if (!zevpn
->vxlan_if
) {
4680 "VNI %u hash %p doesn't have intf upon SVI up",
4685 if (IS_ZEBRA_DEBUG_VXLAN
)
4687 "SVI %s(%u) VNI %u VRF %s is UP, installing neighbors",
4688 ifp
->name
, ifp
->ifindex
, zevpn
->vni
,
4691 /* update the vrf information for l2-vni and inform bgp */
4692 zevpn
->svi_if
= ifp
;
4693 zevpn
->vrf_id
= ifp
->vrf
->vrf_id
;
4695 zl3vni
= zl3vni_from_vrf(zevpn
->vrf_id
);
4697 listnode_add_sort_nodup(zl3vni
->l2vnis
, zevpn
);
4699 if (if_is_operative(zevpn
->vxlan_if
))
4700 zebra_evpn_send_add_to_client(zevpn
);
4702 /* Install any remote neighbors for this VNI. */
4703 memset(&n_wctx
, 0, sizeof(n_wctx
));
4704 n_wctx
.zevpn
= zevpn
;
4705 hash_iterate(zevpn
->neigh_table
, zebra_evpn_install_neigh_hash
,
4708 /* Link the SVI from the access VLAN */
4709 zebra_evpn_acc_bd_svi_set(ifp
->info
, link_if
->info
, true);
4711 /* Update MACIP routes created by advertise-svi-ip */
4712 if (advertise_svi_macip_enabled(zevpn
)) {
4713 zebra_evpn_del_macip_for_intf(ifp
, zevpn
);
4714 zebra_evpn_add_macip_for_intf(ifp
, zevpn
);
4722 * Handle MAC-VLAN interface going down.
4723 * L3VNI: When MAC-VLAN interface goes down,
4724 * find its associated SVI and update type2/type-5 routes
4727 void zebra_vxlan_macvlan_down(struct interface
*ifp
)
4729 struct zebra_l3vni
*zl3vni
= NULL
;
4730 struct zebra_if
*zif
, *link_zif
;
4731 struct interface
*link_ifp
, *link_if
;
4735 link_ifp
= zif
->link
;
4737 if (IS_ZEBRA_DEBUG_VXLAN
)
4739 "macvlan parent link is not found. Parent index %d ifp %s",
4741 ifindex2ifname(zif
->link_ifindex
,
4745 link_zif
= link_ifp
->info
;
4748 link_if
= if_lookup_by_index_per_ns(zebra_ns_lookup(NS_DEFAULT
),
4749 link_zif
->link_ifindex
);
4751 zl3vni
= zl3vni_from_svi(link_ifp
, link_if
);
4753 zl3vni
->mac_vlan_if
= NULL
;
4754 if (is_l3vni_oper_up(zl3vni
))
4755 zebra_vxlan_process_l3vni_oper_up(zl3vni
);
4760 * Handle MAC-VLAN interface going up.
4761 * L3VNI: When MAC-VLAN interface comes up,
4762 * find its associated SVI and update type-2 routes
4763 * with MAC-VLAN's MAC as RMAC and for type-5 routes
4764 * use SVI's MAC as RMAC.
4766 void zebra_vxlan_macvlan_up(struct interface
*ifp
)
4768 struct zebra_l3vni
*zl3vni
= NULL
;
4769 struct zebra_if
*zif
, *link_zif
;
4770 struct interface
*link_ifp
, *link_if
;
4774 link_ifp
= zif
->link
;
4775 link_zif
= link_ifp
->info
;
4778 link_if
= if_lookup_by_index_per_ns(zebra_ns_lookup(NS_DEFAULT
),
4779 link_zif
->link_ifindex
);
4780 zl3vni
= zl3vni_from_svi(link_ifp
, link_if
);
4782 /* associate with macvlan (VRR) interface */
4783 zl3vni
->mac_vlan_if
= ifp
;
4785 /* process oper-up */
4786 if (is_l3vni_oper_up(zl3vni
))
4787 zebra_vxlan_process_l3vni_oper_up(zl3vni
);
4792 * Handle VxLAN interface down
4794 int zebra_vxlan_if_down(struct interface
*ifp
)
4797 struct zebra_if
*zif
= NULL
;
4798 struct zebra_l2info_vxlan
*vxl
= NULL
;
4799 struct zebra_l3vni
*zl3vni
= NULL
;
4800 struct zebra_evpn
*zevpn
;
4802 /* Check if EVPN is enabled. */
4803 if (!is_evpn_enabled())
4808 vxl
= &zif
->l2info
.vxl
;
4811 zl3vni
= zl3vni_lookup(vni
);
4813 /* process-if-down for l3-vni */
4814 if (IS_ZEBRA_DEBUG_VXLAN
)
4815 zlog_debug("Intf %s(%u) L3-VNI %u is DOWN", ifp
->name
,
4818 zebra_vxlan_process_l3vni_oper_down(zl3vni
);
4820 /* process if-down for l2-vni */
4821 if (IS_ZEBRA_DEBUG_VXLAN
)
4822 zlog_debug("Intf %s(%u) L2-VNI %u is DOWN", ifp
->name
,
4825 /* Locate hash entry; it is expected to exist. */
4826 zevpn
= zebra_evpn_lookup(vni
);
4829 "Failed to locate VNI hash at DOWN, IF %s(%u) VNI %u",
4830 ifp
->name
, ifp
->ifindex
, vni
);
4834 assert(zevpn
->vxlan_if
== ifp
);
4836 /* remove from l3-vni list */
4837 zl3vni
= zl3vni_from_vrf(zevpn
->vrf_id
);
4839 listnode_delete(zl3vni
->l2vnis
, zevpn
);
4841 /* Delete this VNI from BGP. */
4842 zebra_evpn_send_del_to_client(zevpn
);
4844 /* Free up all neighbors and MACs, if any. */
4845 zebra_evpn_neigh_del_all(zevpn
, 1, 0, DEL_ALL_NEIGH
);
4846 zebra_evpn_mac_del_all(zevpn
, 1, 0, DEL_ALL_MAC
);
4848 /* Free up all remote VTEPs, if any. */
4849 zebra_evpn_vtep_del_all(zevpn
, 1);
4855 * Handle VxLAN interface up - update BGP if required.
4857 int zebra_vxlan_if_up(struct interface
*ifp
)
4860 struct zebra_if
*zif
= NULL
;
4861 struct zebra_l2info_vxlan
*vxl
= NULL
;
4862 struct zebra_evpn
*zevpn
= NULL
;
4863 struct zebra_l3vni
*zl3vni
= NULL
;
4865 /* Check if EVPN is enabled. */
4866 if (!is_evpn_enabled())
4871 vxl
= &zif
->l2info
.vxl
;
4874 zl3vni
= zl3vni_lookup(vni
);
4876 /* we need to associate with SVI, if any, we can associate with
4877 * svi-if only after association with vxlan-intf is complete
4879 zl3vni
->svi_if
= zl3vni_map_to_svi_if(zl3vni
);
4880 zl3vni
->mac_vlan_if
= zl3vni_map_to_mac_vlan_if(zl3vni
);
4882 if (IS_ZEBRA_DEBUG_VXLAN
)
4883 zlog_debug("Intf %s(%u) L3-VNI %u is UP svi_if %s mac_vlan_if %s"
4884 , ifp
->name
, ifp
->ifindex
, vni
,
4885 zl3vni
->svi_if
? zl3vni
->svi_if
->name
: "NIL",
4886 zl3vni
->mac_vlan_if
?
4887 zl3vni
->mac_vlan_if
->name
: "NIL");
4889 if (is_l3vni_oper_up(zl3vni
))
4890 zebra_vxlan_process_l3vni_oper_up(zl3vni
);
4892 /* Handle L2-VNI add */
4893 struct interface
*vlan_if
= NULL
;
4895 if (IS_ZEBRA_DEBUG_VXLAN
)
4896 zlog_debug("Intf %s(%u) L2-VNI %u is UP", ifp
->name
,
4899 /* Locate hash entry; it is expected to exist. */
4900 zevpn
= zebra_evpn_lookup(vni
);
4903 "Failed to locate EVPN hash at UP, IF %s(%u) VNI %u",
4904 ifp
->name
, ifp
->ifindex
, vni
);
4908 assert(zevpn
->vxlan_if
== ifp
);
4909 vlan_if
= zvni_map_to_svi(vxl
->access_vlan
,
4910 zif
->brslave_info
.br_if
);
4912 zevpn
->svi_if
= vlan_if
;
4913 zevpn
->vrf_id
= vlan_if
->vrf
->vrf_id
;
4914 zl3vni
= zl3vni_from_vrf(vlan_if
->vrf
->vrf_id
);
4916 listnode_add_sort_nodup(zl3vni
->l2vnis
, zevpn
);
4919 /* If part of a bridge, inform BGP about this VNI. */
4920 /* Also, read and populate local MACs and neighbors. */
4921 if (zif
->brslave_info
.br_if
) {
4922 zebra_evpn_send_add_to_client(zevpn
);
4923 zebra_evpn_read_mac_neigh(zevpn
, ifp
);
4931 * Handle VxLAN interface delete. Locate and remove entry in hash table
4932 * and update BGP, if required.
4934 int zebra_vxlan_if_del(struct interface
*ifp
)
4937 struct zebra_if
*zif
= NULL
;
4938 struct zebra_l2info_vxlan
*vxl
= NULL
;
4939 struct zebra_evpn
*zevpn
= NULL
;
4940 struct zebra_l3vni
*zl3vni
= NULL
;
4942 /* Check if EVPN is enabled. */
4943 if (!is_evpn_enabled())
4948 vxl
= &zif
->l2info
.vxl
;
4951 zl3vni
= zl3vni_lookup(vni
);
4954 if (IS_ZEBRA_DEBUG_VXLAN
)
4955 zlog_debug("Del L3-VNI %u intf %s(%u)", vni
, ifp
->name
,
4958 /* process oper-down for l3-vni */
4959 zebra_vxlan_process_l3vni_oper_down(zl3vni
);
4961 /* remove the association with vxlan_if */
4962 memset(&zl3vni
->local_vtep_ip
, 0, sizeof(struct in_addr
));
4963 zl3vni
->vxlan_if
= NULL
;
4966 /* process if-del for l2-vni*/
4967 if (IS_ZEBRA_DEBUG_VXLAN
)
4968 zlog_debug("Del L2-VNI %u intf %s(%u)", vni
, ifp
->name
,
4971 /* Locate hash entry; it is expected to exist. */
4972 zevpn
= zebra_evpn_lookup(vni
);
4975 "Failed to locate VNI hash at del, IF %s(%u) VNI %u",
4976 ifp
->name
, ifp
->ifindex
, vni
);
4980 /* remove from l3-vni list */
4981 zl3vni
= zl3vni_from_vrf(zevpn
->vrf_id
);
4983 listnode_delete(zl3vni
->l2vnis
, zevpn
);
4984 /* Delete VNI from BGP. */
4985 zebra_evpn_send_del_to_client(zevpn
);
4987 /* Free up all neighbors and MAC, if any. */
4988 zebra_evpn_neigh_del_all(zevpn
, 0, 0, DEL_ALL_NEIGH
);
4989 zebra_evpn_mac_del_all(zevpn
, 0, 0, DEL_ALL_MAC
);
4991 /* Free up all remote VTEPs, if any. */
4992 zebra_evpn_vtep_del_all(zevpn
, 0);
4994 /* Delete the hash entry. */
4995 if (zebra_evpn_vxlan_del(zevpn
)) {
4996 flog_err(EC_ZEBRA_VNI_DEL_FAILED
,
4997 "Failed to del EVPN hash %p, IF %s(%u) VNI %u",
4998 zevpn
, ifp
->name
, ifp
->ifindex
, zevpn
->vni
);
5006 * Handle VxLAN interface update - change to tunnel IP, master or VLAN.
5008 int zebra_vxlan_if_update(struct interface
*ifp
, uint16_t chgflags
)
5011 struct zebra_if
*zif
= NULL
;
5012 struct zebra_l2info_vxlan
*vxl
= NULL
;
5013 struct zebra_evpn
*zevpn
= NULL
;
5014 struct zebra_l3vni
*zl3vni
= NULL
;
5015 struct interface
*vlan_if
= NULL
;
5017 /* Check if EVPN is enabled. */
5018 if (!is_evpn_enabled())
5023 vxl
= &zif
->l2info
.vxl
;
5026 zl3vni
= zl3vni_lookup(vni
);
5029 if (IS_ZEBRA_DEBUG_VXLAN
)
5031 "Update L3-VNI %u intf %s(%u) VLAN %u local IP %pI4 master %u chg 0x%x",
5032 vni
, ifp
->name
, ifp
->ifindex
, vxl
->access_vlan
,
5034 zif
->brslave_info
.bridge_ifindex
, chgflags
);
5036 /* Removed from bridge? Cleanup and return */
5037 if ((chgflags
& ZEBRA_VXLIF_MASTER_CHANGE
)
5038 && (zif
->brslave_info
.bridge_ifindex
== IFINDEX_INTERNAL
)) {
5039 zebra_vxlan_process_l3vni_oper_down(zl3vni
);
5043 if ((chgflags
& ZEBRA_VXLIF_MASTER_MAC_CHANGE
)
5044 && if_is_operative(ifp
) && is_l3vni_oper_up(zl3vni
)) {
5045 zebra_vxlan_process_l3vni_oper_down(zl3vni
);
5046 zebra_vxlan_process_l3vni_oper_up(zl3vni
);
5050 /* access-vlan change - process oper down, associate with new
5051 * svi_if and then process oper up again
5053 if (chgflags
& ZEBRA_VXLIF_VLAN_CHANGE
) {
5054 if (if_is_operative(ifp
)) {
5055 zebra_vxlan_process_l3vni_oper_down(zl3vni
);
5056 zl3vni
->svi_if
= NULL
;
5057 zl3vni
->svi_if
= zl3vni_map_to_svi_if(zl3vni
);
5058 zl3vni
->mac_vlan_if
=
5059 zl3vni_map_to_mac_vlan_if(zl3vni
);
5060 zl3vni
->local_vtep_ip
= vxl
->vtep_ip
;
5061 if (is_l3vni_oper_up(zl3vni
))
5062 zebra_vxlan_process_l3vni_oper_up(
5068 * local-ip change - process oper down, associate with new
5069 * local-ip and then process oper up again
5071 if (chgflags
& ZEBRA_VXLIF_LOCAL_IP_CHANGE
) {
5072 if (if_is_operative(ifp
)) {
5073 zebra_vxlan_process_l3vni_oper_down(zl3vni
);
5074 zl3vni
->local_vtep_ip
= vxl
->vtep_ip
;
5075 if (is_l3vni_oper_up(zl3vni
))
5076 zebra_vxlan_process_l3vni_oper_up(
5081 /* Update local tunnel IP. */
5082 zl3vni
->local_vtep_ip
= vxl
->vtep_ip
;
5084 /* if we have a valid new master, process l3-vni oper up */
5085 if (chgflags
& ZEBRA_VXLIF_MASTER_CHANGE
) {
5086 if (if_is_operative(ifp
) && is_l3vni_oper_up(zl3vni
))
5087 zebra_vxlan_process_l3vni_oper_up(zl3vni
);
5091 /* Update VNI hash. */
5092 zevpn
= zebra_evpn_lookup(vni
);
5095 "Failed to find EVPN hash on update, IF %s(%u) VNI %u",
5096 ifp
->name
, ifp
->ifindex
, vni
);
5100 if (IS_ZEBRA_DEBUG_VXLAN
)
5102 "Update L2-VNI %u intf %s(%u) VLAN %u local IP %pI4 master %u chg 0x%x",
5103 vni
, ifp
->name
, ifp
->ifindex
, vxl
->access_vlan
,
5105 zif
->brslave_info
.bridge_ifindex
, chgflags
);
5107 /* Removed from bridge? Cleanup and return */
5108 if ((chgflags
& ZEBRA_VXLIF_MASTER_CHANGE
)
5109 && (zif
->brslave_info
.bridge_ifindex
== IFINDEX_INTERNAL
)) {
5110 /* Delete from client, remove all remote VTEPs */
5111 /* Also, free up all MACs and neighbors. */
5112 zevpn
->svi_if
= NULL
;
5113 zebra_evpn_send_del_to_client(zevpn
);
5114 zebra_evpn_neigh_del_all(zevpn
, 1, 0, DEL_ALL_NEIGH
);
5115 zebra_evpn_mac_del_all(zevpn
, 1, 0, DEL_ALL_MAC
);
5116 zebra_evpn_vtep_del_all(zevpn
, 1);
5120 /* Handle other changes. */
5121 if (chgflags
& ZEBRA_VXLIF_VLAN_CHANGE
) {
5122 /* Remove all existing local neigh and MACs for this VNI
5123 * (including from BGP)
5125 zebra_evpn_neigh_del_all(zevpn
, 0, 1, DEL_LOCAL_MAC
);
5126 zebra_evpn_mac_del_all(zevpn
, 0, 1, DEL_LOCAL_MAC
);
5129 if (zevpn
->local_vtep_ip
.s_addr
!= vxl
->vtep_ip
.s_addr
||
5130 zevpn
->mcast_grp
.s_addr
!= vxl
->mcast_grp
.s_addr
) {
5131 zebra_vxlan_sg_deref(zevpn
->local_vtep_ip
,
5133 zebra_vxlan_sg_ref(vxl
->vtep_ip
, vxl
->mcast_grp
);
5134 zevpn
->local_vtep_ip
= vxl
->vtep_ip
;
5135 zevpn
->mcast_grp
= vxl
->mcast_grp
;
5136 /* on local vtep-ip check if ES orig-ip
5137 * needs to be updated
5139 zebra_evpn_es_set_base_evpn(zevpn
);
5141 zevpn_vxlan_if_set(zevpn
, ifp
, true /* set */);
5142 vlan_if
= zvni_map_to_svi(vxl
->access_vlan
,
5143 zif
->brslave_info
.br_if
);
5145 zevpn
->svi_if
= vlan_if
;
5146 zevpn
->vrf_id
= vlan_if
->vrf
->vrf_id
;
5147 zl3vni
= zl3vni_from_vrf(vlan_if
->vrf
->vrf_id
);
5149 listnode_add_sort_nodup(zl3vni
->l2vnis
, zevpn
);
5152 /* Take further actions needed.
5153 * Note that if we are here, there is a change of interest.
5155 /* If down or not mapped to a bridge, we're done. */
5156 if (!if_is_operative(ifp
) || !zif
->brslave_info
.br_if
)
5159 /* Inform BGP, if there is a change of interest. */
5161 (ZEBRA_VXLIF_MASTER_CHANGE
| ZEBRA_VXLIF_LOCAL_IP_CHANGE
|
5162 ZEBRA_VXLIF_MCAST_GRP_CHANGE
| ZEBRA_VXLIF_VLAN_CHANGE
))
5163 zebra_evpn_send_add_to_client(zevpn
);
5165 /* If there is a valid new master or a VLAN mapping change,
5166 * read and populate local MACs and neighbors.
5167 * Also, reinstall any remote MACs and neighbors
5168 * for this VNI (based on new VLAN).
5170 if (chgflags
& ZEBRA_VXLIF_MASTER_CHANGE
)
5171 zebra_evpn_read_mac_neigh(zevpn
, ifp
);
5172 else if (chgflags
& ZEBRA_VXLIF_VLAN_CHANGE
) {
5173 struct mac_walk_ctx m_wctx
;
5174 struct neigh_walk_ctx n_wctx
;
5176 zebra_evpn_read_mac_neigh(zevpn
, ifp
);
5178 memset(&m_wctx
, 0, sizeof(m_wctx
));
5179 m_wctx
.zevpn
= zevpn
;
5180 hash_iterate(zevpn
->mac_table
,
5181 zebra_evpn_install_mac_hash
, &m_wctx
);
5183 memset(&n_wctx
, 0, sizeof(n_wctx
));
5184 n_wctx
.zevpn
= zevpn
;
5185 hash_iterate(zevpn
->neigh_table
,
5186 zebra_evpn_install_neigh_hash
, &n_wctx
);
5194 * Handle VxLAN interface add.
5196 int zebra_vxlan_if_add(struct interface
*ifp
)
5199 struct zebra_if
*zif
= NULL
;
5200 struct zebra_l2info_vxlan
*vxl
= NULL
;
5201 struct zebra_evpn
*zevpn
= NULL
;
5202 struct zebra_l3vni
*zl3vni
= NULL
;
5204 /* Check if EVPN is enabled. */
5205 if (!is_evpn_enabled())
5210 vxl
= &zif
->l2info
.vxl
;
5213 zl3vni
= zl3vni_lookup(vni
);
5216 /* process if-add for l3-vni*/
5217 if (IS_ZEBRA_DEBUG_VXLAN
)
5219 "Add L3-VNI %u intf %s(%u) VLAN %u local IP %pI4 master %u",
5220 vni
, ifp
->name
, ifp
->ifindex
, vxl
->access_vlan
,
5222 zif
->brslave_info
.bridge_ifindex
);
5224 /* associate with vxlan_if */
5225 zl3vni
->local_vtep_ip
= vxl
->vtep_ip
;
5226 zl3vni
->vxlan_if
= ifp
;
5228 /* Associate with SVI, if any. We can associate with svi-if only
5229 * after association with vxlan_if is complete */
5230 zl3vni
->svi_if
= zl3vni_map_to_svi_if(zl3vni
);
5232 zl3vni
->mac_vlan_if
= zl3vni_map_to_mac_vlan_if(zl3vni
);
5234 if (is_l3vni_oper_up(zl3vni
))
5235 zebra_vxlan_process_l3vni_oper_up(zl3vni
);
5238 /* process if-add for l2-vni */
5239 struct interface
*vlan_if
= NULL
;
5241 /* Create or update EVPN hash. */
5242 zevpn
= zebra_evpn_lookup(vni
);
5244 zevpn
= zebra_evpn_add(vni
);
5246 if (zevpn
->local_vtep_ip
.s_addr
!= vxl
->vtep_ip
.s_addr
||
5247 zevpn
->mcast_grp
.s_addr
!= vxl
->mcast_grp
.s_addr
) {
5248 zebra_vxlan_sg_deref(zevpn
->local_vtep_ip
,
5250 zebra_vxlan_sg_ref(vxl
->vtep_ip
, vxl
->mcast_grp
);
5251 zevpn
->local_vtep_ip
= vxl
->vtep_ip
;
5252 zevpn
->mcast_grp
= vxl
->mcast_grp
;
5253 /* on local vtep-ip check if ES orig-ip
5254 * needs to be updated
5256 zebra_evpn_es_set_base_evpn(zevpn
);
5258 zevpn_vxlan_if_set(zevpn
, ifp
, true /* set */);
5259 vlan_if
= zvni_map_to_svi(vxl
->access_vlan
,
5260 zif
->brslave_info
.br_if
);
5262 zevpn
->svi_if
= vlan_if
;
5263 zevpn
->vrf_id
= vlan_if
->vrf
->vrf_id
;
5264 zl3vni
= zl3vni_from_vrf(vlan_if
->vrf
->vrf_id
);
5266 listnode_add_sort_nodup(zl3vni
->l2vnis
, zevpn
);
5269 if (IS_ZEBRA_DEBUG_VXLAN
)
5271 "Add L2-VNI %u VRF %s intf %s(%u) VLAN %u local IP %pI4 mcast_grp %pI4 master %u",
5273 vlan_if
? vlan_if
->vrf
->name
: VRF_DEFAULT_NAME
,
5274 ifp
->name
, ifp
->ifindex
, vxl
->access_vlan
,
5275 &vxl
->vtep_ip
, &vxl
->mcast_grp
,
5276 zif
->brslave_info
.bridge_ifindex
);
5278 /* If down or not mapped to a bridge, we're done. */
5279 if (!if_is_operative(ifp
) || !zif
->brslave_info
.br_if
)
5283 zebra_evpn_send_add_to_client(zevpn
);
5285 /* Read and populate local MACs and neighbors */
5286 zebra_evpn_read_mac_neigh(zevpn
, ifp
);
5292 int zebra_vxlan_process_vrf_vni_cmd(struct zebra_vrf
*zvrf
, vni_t vni
,
5293 char *err
, int err_str_sz
, int filter
,
5296 struct zebra_l3vni
*zl3vni
= NULL
;
5297 struct zebra_vrf
*zvrf_evpn
= NULL
;
5299 zvrf_evpn
= zebra_vrf_get_evpn();
5301 if (IS_ZEBRA_DEBUG_VXLAN
)
5302 zlog_debug("vrf %s vni %u %s", zvrf_name(zvrf
), vni
,
5303 add
? "ADD" : "DEL");
5306 /* check if the vni is already present under zvrf */
5308 snprintf(err
, err_str_sz
,
5309 "VNI is already configured under the vrf");
5313 /* check if this VNI is already present in the system */
5314 zl3vni
= zl3vni_lookup(vni
);
5316 snprintf(err
, err_str_sz
,
5317 "VNI is already configured as L3-VNI");
5321 /* Remove L2VNI if present */
5322 zebra_vxlan_handle_vni_transition(zvrf
, vni
, add
);
5324 /* add the L3-VNI to the global table */
5325 zl3vni
= zl3vni_add(vni
, zvrf_id(zvrf
));
5327 /* associate the vrf with vni */
5330 /* set the filter in l3vni to denote if we are using l3vni only
5334 SET_FLAG(zl3vni
->filter
, PREFIX_ROUTES_ONLY
);
5336 /* associate with vxlan-intf;
5337 * we need to associate with the vxlan-intf first
5339 zl3vni
->vxlan_if
= zl3vni_map_to_vxlan_if(zl3vni
);
5341 /* associate with corresponding SVI interface, we can associate
5342 * with svi-if only after vxlan interface association is
5345 zl3vni
->svi_if
= zl3vni_map_to_svi_if(zl3vni
);
5347 zl3vni
->mac_vlan_if
= zl3vni_map_to_mac_vlan_if(zl3vni
);
5349 if (IS_ZEBRA_DEBUG_VXLAN
)
5351 "%s: l3vni %u svi_if %s mac_vlan_if %s",
5353 zl3vni
->svi_if
? zl3vni
->svi_if
->name
: "NIL",
5354 zl3vni
->mac_vlan_if
? zl3vni
->mac_vlan_if
->name
5357 /* formulate l2vni list */
5358 hash_iterate(zvrf_evpn
->evpn_table
, zevpn_add_to_l3vni_list
,
5361 if (is_l3vni_oper_up(zl3vni
))
5362 zebra_vxlan_process_l3vni_oper_up(zl3vni
);
5365 zl3vni
= zl3vni_lookup(vni
);
5367 snprintf(err
, err_str_sz
, "VNI doesn't exist");
5371 if (zvrf
->l3vni
!= vni
) {
5372 snprintf(err
, err_str_sz
,
5373 "VNI %d doesn't exist in VRF: %s",
5374 vni
, zvrf
->vrf
->name
);
5378 if (filter
&& !CHECK_FLAG(zl3vni
->filter
, PREFIX_ROUTES_ONLY
)) {
5379 snprintf(err
, ERR_STR_SZ
,
5380 "prefix-routes-only is not set for the vni");
5384 zebra_vxlan_process_l3vni_oper_down(zl3vni
);
5386 /* delete and uninstall all rmacs */
5387 hash_iterate(zl3vni
->rmac_table
, zl3vni_del_rmac_hash_entry
,
5390 /* delete and uninstall all next-hops */
5391 hash_iterate(zl3vni
->nh_table
, zl3vni_del_nh_hash_entry
,
5397 /* Add L2VNI for this VNI */
5398 zebra_vxlan_handle_vni_transition(zvrf
, vni
, add
);
5403 int zebra_vxlan_vrf_enable(struct zebra_vrf
*zvrf
)
5405 struct zebra_l3vni
*zl3vni
= NULL
;
5408 zl3vni
= zl3vni_lookup(zvrf
->l3vni
);
5412 zl3vni
->vrf_id
= zvrf_id(zvrf
);
5413 if (is_l3vni_oper_up(zl3vni
))
5414 zebra_vxlan_process_l3vni_oper_up(zl3vni
);
5418 int zebra_vxlan_vrf_disable(struct zebra_vrf
*zvrf
)
5420 struct zebra_l3vni
*zl3vni
= NULL
;
5423 zl3vni
= zl3vni_lookup(zvrf
->l3vni
);
5427 zebra_vxlan_process_l3vni_oper_down(zl3vni
);
5429 /* delete and uninstall all rmacs */
5430 hash_iterate(zl3vni
->rmac_table
, zl3vni_del_rmac_hash_entry
, zl3vni
);
5431 /* delete and uninstall all next-hops */
5432 hash_iterate(zl3vni
->nh_table
, zl3vni_del_nh_hash_entry
, zl3vni
);
5434 zl3vni
->vrf_id
= VRF_UNKNOWN
;
5439 int zebra_vxlan_vrf_delete(struct zebra_vrf
*zvrf
)
5441 struct zebra_l3vni
*zl3vni
= NULL
;
5445 zl3vni
= zl3vni_lookup(zvrf
->l3vni
);
5451 zebra_vxlan_handle_vni_transition(zvrf
, vni
, 0);
5457 * Handle message from client to specify the flooding mechanism for
5458 * BUM packets. The default is to do head-end (ingress) replication
5459 * and the other supported option is to disable it. This applies to
5460 * all BUM traffic and disabling it applies to both the transmit and
5461 * receive direction.
5463 void zebra_vxlan_flood_control(ZAPI_HANDLER_ARGS
)
5466 enum vxlan_flood_control flood_ctrl
;
5468 if (!EVPN_ENABLED(zvrf
)) {
5469 zlog_err("EVPN flood control for non-EVPN VRF %u",
5475 STREAM_GETC(s
, flood_ctrl
);
5477 if (IS_ZEBRA_DEBUG_VXLAN
)
5478 zlog_debug("EVPN flood control %u, currently %u",
5479 flood_ctrl
, zvrf
->vxlan_flood_ctrl
);
5481 if (zvrf
->vxlan_flood_ctrl
== flood_ctrl
)
5484 zvrf
->vxlan_flood_ctrl
= flood_ctrl
;
5486 /* Install or uninstall flood entries corresponding to
5489 hash_iterate(zvrf
->evpn_table
, zebra_evpn_handle_flooding_remote_vteps
,
5497 * Handle message from client to enable/disable advertisement of svi macip
5500 void zebra_vxlan_advertise_svi_macip(ZAPI_HANDLER_ARGS
)
5505 struct zebra_evpn
*zevpn
= NULL
;
5506 struct interface
*ifp
= NULL
;
5508 if (!EVPN_ENABLED(zvrf
)) {
5509 zlog_debug("EVPN SVI-MACIP Adv for non-EVPN VRF %u",
5515 STREAM_GETC(s
, advertise
);
5516 STREAM_GETL(s
, vni
);
5519 if (IS_ZEBRA_DEBUG_VXLAN
)
5520 zlog_debug("EVPN SVI-MACIP Adv %s, currently %s",
5521 advertise
? "enabled" : "disabled",
5522 advertise_svi_macip_enabled(NULL
)
5526 if (zvrf
->advertise_svi_macip
== advertise
)
5531 zvrf
->advertise_svi_macip
= advertise
;
5532 hash_iterate(zvrf
->evpn_table
,
5533 zebra_evpn_gw_macip_add_for_evpn_hash
,
5536 hash_iterate(zvrf
->evpn_table
,
5537 zebra_evpn_svi_macip_del_for_evpn_hash
,
5539 zvrf
->advertise_svi_macip
= advertise
;
5543 struct zebra_if
*zif
= NULL
;
5544 struct zebra_l2info_vxlan zl2_info
;
5545 struct interface
*vlan_if
= NULL
;
5548 zevpn
= zebra_evpn_lookup(vni
);
5552 if (IS_ZEBRA_DEBUG_VXLAN
)
5554 "EVPN SVI macip Adv %s on VNI %d, currently %s",
5555 advertise
? "enabled" : "disabled", vni
,
5556 advertise_svi_macip_enabled(zevpn
)
5560 old_advertise
= advertise_svi_macip_enabled(zevpn
);
5562 /* Store flag even though SVI is not present.
5563 * Once SVI comes up triggers self MAC-IP route add.
5565 zevpn
->advertise_svi_macip
= advertise
;
5566 if (advertise_svi_macip_enabled(zevpn
) == old_advertise
)
5569 ifp
= zevpn
->vxlan_if
;
5575 /* If down or not mapped to a bridge, we're done. */
5576 if (!if_is_operative(ifp
) || !zif
->brslave_info
.br_if
)
5579 zl2_info
= zif
->l2info
.vxl
;
5580 vlan_if
= zvni_map_to_svi(zl2_info
.access_vlan
,
5581 zif
->brslave_info
.br_if
);
5586 /* Add primary SVI MAC-IP */
5587 zebra_evpn_add_macip_for_intf(vlan_if
, zevpn
);
5589 /* Del primary SVI MAC-IP */
5590 zebra_evpn_del_macip_for_intf(vlan_if
, zevpn
);
5599 * Handle message from client to enable/disable advertisement of g/w macip
5602 void zebra_vxlan_advertise_subnet(ZAPI_HANDLER_ARGS
)
5607 struct zebra_evpn
*zevpn
= NULL
;
5608 struct interface
*ifp
= NULL
;
5609 struct zebra_if
*zif
= NULL
;
5610 struct zebra_l2info_vxlan zl2_info
;
5611 struct interface
*vlan_if
= NULL
;
5613 if (!EVPN_ENABLED(zvrf
)) {
5614 zlog_debug("EVPN GW-MACIP Adv for non-EVPN VRF %u",
5620 STREAM_GETC(s
, advertise
);
5621 STREAM_GET(&vni
, s
, 3);
5623 zevpn
= zebra_evpn_lookup(vni
);
5627 if (zevpn
->advertise_subnet
== advertise
)
5630 if (IS_ZEBRA_DEBUG_VXLAN
)
5631 zlog_debug("EVPN subnet Adv %s on VNI %d, currently %s",
5632 advertise
? "enabled" : "disabled", vni
,
5633 zevpn
->advertise_subnet
? "enabled" : "disabled");
5636 zevpn
->advertise_subnet
= advertise
;
5638 ifp
= zevpn
->vxlan_if
;
5644 /* If down or not mapped to a bridge, we're done. */
5645 if (!if_is_operative(ifp
) || !zif
->brslave_info
.br_if
)
5648 zl2_info
= zif
->l2info
.vxl
;
5651 zvni_map_to_svi(zl2_info
.access_vlan
, zif
->brslave_info
.br_if
);
5655 if (zevpn
->advertise_subnet
)
5656 zebra_evpn_advertise_subnet(zevpn
, vlan_if
, 1);
5658 zebra_evpn_advertise_subnet(zevpn
, vlan_if
, 0);
5665 * Handle message from client to enable/disable advertisement of g/w macip
5668 void zebra_vxlan_advertise_gw_macip(ZAPI_HANDLER_ARGS
)
5673 struct zebra_evpn
*zevpn
= NULL
;
5674 struct interface
*ifp
= NULL
;
5676 if (!EVPN_ENABLED(zvrf
)) {
5677 zlog_debug("EVPN GW-MACIP Adv for non-EVPN VRF %u",
5683 STREAM_GETC(s
, advertise
);
5684 STREAM_GETL(s
, vni
);
5687 if (IS_ZEBRA_DEBUG_VXLAN
)
5688 zlog_debug("EVPN gateway macip Adv %s, currently %s",
5689 advertise
? "enabled" : "disabled",
5690 advertise_gw_macip_enabled(NULL
)
5694 if (zvrf
->advertise_gw_macip
== advertise
)
5697 zvrf
->advertise_gw_macip
= advertise
;
5699 if (advertise_gw_macip_enabled(zevpn
))
5700 hash_iterate(zvrf
->evpn_table
,
5701 zebra_evpn_gw_macip_add_for_evpn_hash
,
5704 hash_iterate(zvrf
->evpn_table
,
5705 zebra_evpn_gw_macip_del_for_evpn_hash
,
5709 struct zebra_if
*zif
= NULL
;
5710 struct zebra_l2info_vxlan zl2_info
;
5711 struct interface
*vlan_if
= NULL
;
5712 struct interface
*vrr_if
= NULL
;
5715 zevpn
= zebra_evpn_lookup(vni
);
5719 if (IS_ZEBRA_DEBUG_VXLAN
)
5721 "EVPN gateway macip Adv %s on VNI %d, currently %s",
5722 advertise
? "enabled" : "disabled", vni
,
5723 advertise_gw_macip_enabled(zevpn
) ? "enabled"
5726 old_advertise
= advertise_gw_macip_enabled(zevpn
);
5728 zevpn
->advertise_gw_macip
= advertise
;
5729 if (advertise_gw_macip_enabled(zevpn
) == old_advertise
)
5732 ifp
= zevpn
->vxlan_if
;
5738 /* If down or not mapped to a bridge, we're done. */
5739 if (!if_is_operative(ifp
) || !zif
->brslave_info
.br_if
)
5742 zl2_info
= zif
->l2info
.vxl
;
5744 vlan_if
= zvni_map_to_svi(zl2_info
.access_vlan
,
5745 zif
->brslave_info
.br_if
);
5749 if (advertise_gw_macip_enabled(zevpn
)) {
5750 /* Add primary SVI MAC-IP */
5751 zebra_evpn_add_macip_for_intf(vlan_if
, zevpn
);
5753 /* Add VRR MAC-IP - if any*/
5754 vrr_if
= zebra_get_vrr_intf_for_svi(vlan_if
);
5756 zebra_evpn_add_macip_for_intf(vrr_if
, zevpn
);
5758 /* Del primary MAC-IP */
5759 zebra_evpn_del_macip_for_intf(vlan_if
, zevpn
);
5761 /* Del VRR MAC-IP - if any*/
5762 vrr_if
= zebra_get_vrr_intf_for_svi(vlan_if
);
5764 zebra_evpn_del_macip_for_intf(vrr_if
, zevpn
);
5772 static int macfdb_read_ns(struct ns
*ns
,
5773 void *_in_param
__attribute__((unused
)),
5774 void **out_param
__attribute__((unused
)))
5776 struct zebra_ns
*zns
= ns
->info
;
5779 return NS_WALK_CONTINUE
;
5782 static int neigh_read_ns(struct ns
*ns
,
5783 void *_in_param
__attribute__((unused
)),
5784 void **out_param
__attribute__((unused
)))
5786 struct zebra_ns
*zns
= ns
->info
;
5789 return NS_WALK_CONTINUE
;
5793 * Handle message from client to learn (or stop learning) about VNIs and MACs.
5794 * When enabled, the VNI hash table will be built and MAC FDB table read;
5795 * when disabled, the entries should be deleted and remote VTEPs and MACs
5796 * uninstalled from the kernel.
5797 * This also informs the setting for BUM handling at the time this change
5798 * occurs; it is relevant only when specifying "learn".
5800 void zebra_vxlan_advertise_all_vni(ZAPI_HANDLER_ARGS
)
5802 struct stream
*s
= NULL
;
5804 enum vxlan_flood_control flood_ctrl
;
5806 /* Mismatch between EVPN VRF and current VRF (should be prevented by
5808 if (is_evpn_enabled() && !EVPN_ENABLED(zvrf
))
5812 STREAM_GETC(s
, advertise
);
5813 STREAM_GETC(s
, flood_ctrl
);
5815 if (IS_ZEBRA_DEBUG_VXLAN
)
5816 zlog_debug("EVPN VRF %s(%u) VNI Adv %s, currently %s, flood control %u",
5817 zvrf_name(zvrf
), zvrf_id(zvrf
),
5818 advertise
? "enabled" : "disabled",
5819 is_evpn_enabled() ? "enabled" : "disabled",
5822 if (zvrf
->advertise_all_vni
== advertise
)
5825 zvrf
->advertise_all_vni
= advertise
;
5826 if (EVPN_ENABLED(zvrf
)) {
5827 zrouter
.evpn_vrf
= zvrf
;
5829 /* Note BUM handling */
5830 zvrf
->vxlan_flood_ctrl
= flood_ctrl
;
5832 /* Replay all ESs */
5833 zebra_evpn_es_send_all_to_client(true /* add */);
5835 /* Build EVPN hash table and inform BGP. */
5836 zevpn_build_hash_table();
5838 /* Add all SVI (L3 GW) MACs to BGP*/
5839 hash_iterate(zvrf
->evpn_table
,
5840 zebra_evpn_gw_macip_add_for_evpn_hash
, NULL
);
5842 /* Read the MAC FDB */
5843 ns_walk_func(macfdb_read_ns
, NULL
, NULL
);
5845 /* Read neighbors */
5846 ns_walk_func(neigh_read_ns
, NULL
, NULL
);
5848 /* Cleanup VTEPs for all EVPNs - uninstall from
5849 * kernel and free entries.
5851 hash_iterate(zvrf
->evpn_table
, zebra_evpn_vxlan_cleanup_all
,
5854 /* Delete all ESs in BGP */
5855 zebra_evpn_es_send_all_to_client(false /* add */);
5857 /* cleanup all l3vnis */
5858 hash_iterate(zrouter
.l3vni_table
, zl3vni_cleanup_all
, NULL
);
5860 /* Mark as "no EVPN VRF" */
5861 zrouter
.evpn_vrf
= NULL
;
5869 * Allocate EVPN hash table for this VRF and do other initialization.
5870 * NOTE: Currently supported only for default VRF.
5872 void zebra_vxlan_init_tables(struct zebra_vrf
*zvrf
)
5879 snprintf(buffer
, sizeof(buffer
), "Zebra VRF EVPN Table: %s",
5881 zvrf
->evpn_table
= hash_create_size(8, zebra_evpn_hash_keymake
,
5882 zebra_evpn_hash_cmp
, buffer
);
5884 snprintf(buffer
, sizeof(buffer
), "Zebra VxLAN SG Table: %s",
5886 zvrf
->vxlan_sg_table
= hash_create_size(8, zebra_vxlan_sg_hash_key_make
,
5887 zebra_vxlan_sg_hash_eq
, buffer
);
5890 /* Cleanup EVPN info, but don't free the table. */
5891 void zebra_vxlan_cleanup_tables(struct zebra_vrf
*zvrf
)
5893 struct zebra_vrf
*evpn_zvrf
= zebra_vrf_get_evpn();
5895 hash_iterate(zvrf
->evpn_table
, zebra_evpn_vxlan_cleanup_all
, zvrf
);
5896 zebra_vxlan_cleanup_sg_table(zvrf
);
5898 if (zvrf
== evpn_zvrf
)
5899 zebra_evpn_es_cleanup();
5902 /* Close all EVPN handling */
5903 void zebra_vxlan_close_tables(struct zebra_vrf
*zvrf
)
5907 hash_iterate(zvrf
->evpn_table
, zebra_evpn_vxlan_cleanup_all
, zvrf
);
5908 hash_free(zvrf
->evpn_table
);
5909 if (zvrf
->vxlan_sg_table
) {
5910 zebra_vxlan_cleanup_sg_table(zvrf
);
5911 hash_free(zvrf
->vxlan_sg_table
);
5912 zvrf
->vxlan_sg_table
= NULL
;
5916 /* init the l3vni table */
5917 void zebra_vxlan_init(void)
5919 zrouter
.l3vni_table
= hash_create(l3vni_hash_keymake
, l3vni_hash_cmp
,
5920 "Zebra VRF L3 VNI table");
5921 zrouter
.evpn_vrf
= NULL
;
5922 zebra_evpn_mh_init();
5925 /* free l3vni table */
5926 void zebra_vxlan_disable(void)
5928 hash_free(zrouter
.l3vni_table
);
5929 zebra_evpn_mh_terminate();
5932 /* get the l3vni svi ifindex */
5933 ifindex_t
get_l3vni_svi_ifindex(vrf_id_t vrf_id
)
5935 struct zebra_l3vni
*zl3vni
= NULL
;
5937 zl3vni
= zl3vni_from_vrf(vrf_id
);
5938 if (!zl3vni
|| !is_l3vni_oper_up(zl3vni
))
5941 return zl3vni
->svi_if
->ifindex
;
5944 /************************** vxlan SG cache management ************************/
5945 /* Inform PIM about the mcast group */
5946 static int zebra_vxlan_sg_send(struct zebra_vrf
*zvrf
,
5947 struct prefix_sg
*sg
,
5948 char *sg_str
, uint16_t cmd
)
5950 struct zserv
*client
= NULL
;
5951 struct stream
*s
= NULL
;
5953 client
= zserv_find_client(ZEBRA_ROUTE_PIM
, 0);
5957 if (!CHECK_FLAG(zvrf
->flags
, ZEBRA_PIM_SEND_VXLAN_SG
))
5960 s
= stream_new(ZEBRA_MAX_PACKET_SIZ
);
5962 zclient_create_header(s
, cmd
, VRF_DEFAULT
);
5963 stream_putl(s
, IPV4_MAX_BYTELEN
);
5964 stream_put(s
, &sg
->src
.s_addr
, IPV4_MAX_BYTELEN
);
5965 stream_put(s
, &sg
->grp
.s_addr
, IPV4_MAX_BYTELEN
);
5967 /* Write packet size. */
5968 stream_putw_at(s
, 0, stream_get_endp(s
));
5970 if (IS_ZEBRA_DEBUG_VXLAN
)
5973 (cmd
== ZEBRA_VXLAN_SG_ADD
) ? "add" : "del", sg_str
,
5974 zebra_route_string(client
->proto
));
5976 if (cmd
== ZEBRA_VXLAN_SG_ADD
)
5977 client
->vxlan_sg_add_cnt
++;
5979 client
->vxlan_sg_del_cnt
++;
5981 return zserv_send_message(client
, s
);
5984 static unsigned int zebra_vxlan_sg_hash_key_make(const void *p
)
5986 const struct zebra_vxlan_sg
*vxlan_sg
= p
;
5988 return (jhash_2words(vxlan_sg
->sg
.src
.s_addr
,
5989 vxlan_sg
->sg
.grp
.s_addr
, 0));
5992 static bool zebra_vxlan_sg_hash_eq(const void *p1
, const void *p2
)
5994 const struct zebra_vxlan_sg
*sg1
= p1
;
5995 const struct zebra_vxlan_sg
*sg2
= p2
;
5997 return ((sg1
->sg
.src
.s_addr
== sg2
->sg
.src
.s_addr
)
5998 && (sg1
->sg
.grp
.s_addr
== sg2
->sg
.grp
.s_addr
));
6001 static struct zebra_vxlan_sg
*zebra_vxlan_sg_new(struct zebra_vrf
*zvrf
,
6002 struct prefix_sg
*sg
)
6004 struct zebra_vxlan_sg
*vxlan_sg
;
6006 vxlan_sg
= XCALLOC(MTYPE_ZVXLAN_SG
, sizeof(*vxlan_sg
));
6008 vxlan_sg
->zvrf
= zvrf
;
6010 prefix_sg2str(sg
, vxlan_sg
->sg_str
);
6012 vxlan_sg
= hash_get(zvrf
->vxlan_sg_table
, vxlan_sg
, hash_alloc_intern
);
6014 if (IS_ZEBRA_DEBUG_VXLAN
)
6015 zlog_debug("vxlan SG %s created", vxlan_sg
->sg_str
);
6020 static struct zebra_vxlan_sg
*zebra_vxlan_sg_find(struct zebra_vrf
*zvrf
,
6021 struct prefix_sg
*sg
)
6023 struct zebra_vxlan_sg lookup
;
6026 return hash_lookup(zvrf
->vxlan_sg_table
, &lookup
);
6029 static struct zebra_vxlan_sg
*zebra_vxlan_sg_add(struct zebra_vrf
*zvrf
,
6030 struct prefix_sg
*sg
)
6032 struct zebra_vxlan_sg
*vxlan_sg
;
6033 struct zebra_vxlan_sg
*parent
= NULL
;
6036 vxlan_sg
= zebra_vxlan_sg_find(zvrf
, sg
);
6040 /* create a *G entry for every BUM group implicitly -
6041 * 1. The SG entry is used by pimd to setup the vxlan-origination-mroute
6042 * 2. the XG entry is used by pimd to setup the
6043 * vxlan-termination-mroute
6045 if (sg
->src
.s_addr
!= INADDR_ANY
) {
6046 memset(&sip
, 0, sizeof(sip
));
6047 parent
= zebra_vxlan_sg_do_ref(zvrf
, sip
, sg
->grp
);
6052 vxlan_sg
= zebra_vxlan_sg_new(zvrf
, sg
);
6054 zebra_vxlan_sg_send(zvrf
, sg
, vxlan_sg
->sg_str
,
6055 ZEBRA_VXLAN_SG_ADD
);
6060 static void zebra_vxlan_sg_del(struct zebra_vxlan_sg
*vxlan_sg
)
6063 struct zebra_vrf
*zvrf
;
6065 zvrf
= vrf_info_lookup(VRF_DEFAULT
);
6069 /* On SG entry deletion remove the reference to its parent XG
6072 if (vxlan_sg
->sg
.src
.s_addr
!= INADDR_ANY
) {
6073 memset(&sip
, 0, sizeof(sip
));
6074 zebra_vxlan_sg_do_deref(zvrf
, sip
, vxlan_sg
->sg
.grp
);
6077 zebra_vxlan_sg_send(zvrf
, &vxlan_sg
->sg
,
6078 vxlan_sg
->sg_str
, ZEBRA_VXLAN_SG_DEL
);
6080 hash_release(vxlan_sg
->zvrf
->vxlan_sg_table
, vxlan_sg
);
6082 if (IS_ZEBRA_DEBUG_VXLAN
)
6083 zlog_debug("VXLAN SG %s deleted", vxlan_sg
->sg_str
);
6085 XFREE(MTYPE_ZVXLAN_SG
, vxlan_sg
);
6088 static void zebra_vxlan_sg_do_deref(struct zebra_vrf
*zvrf
,
6089 struct in_addr sip
, struct in_addr mcast_grp
)
6091 struct zebra_vxlan_sg
*vxlan_sg
;
6092 struct prefix_sg sg
;
6094 sg
.family
= AF_INET
;
6095 sg
.prefixlen
= IPV4_MAX_BYTELEN
;
6098 vxlan_sg
= zebra_vxlan_sg_find(zvrf
, &sg
);
6102 if (vxlan_sg
->ref_cnt
)
6103 --vxlan_sg
->ref_cnt
;
6105 if (!vxlan_sg
->ref_cnt
)
6106 zebra_vxlan_sg_del(vxlan_sg
);
6109 static struct zebra_vxlan_sg
*zebra_vxlan_sg_do_ref(struct zebra_vrf
*zvrf
,
6111 struct in_addr mcast_grp
)
6113 struct zebra_vxlan_sg
*vxlan_sg
;
6114 struct prefix_sg sg
;
6116 sg
.family
= AF_INET
;
6117 sg
.prefixlen
= IPV4_MAX_BYTELEN
;
6120 vxlan_sg
= zebra_vxlan_sg_add(zvrf
, &sg
);
6122 ++vxlan_sg
->ref_cnt
;
6127 static void zebra_vxlan_sg_deref(struct in_addr local_vtep_ip
,
6128 struct in_addr mcast_grp
)
6130 struct zebra_vrf
*zvrf
;
6132 if (local_vtep_ip
.s_addr
== INADDR_ANY
6133 || mcast_grp
.s_addr
== INADDR_ANY
)
6136 zvrf
= vrf_info_lookup(VRF_DEFAULT
);
6140 zebra_vxlan_sg_do_deref(zvrf
, local_vtep_ip
, mcast_grp
);
6143 static void zebra_vxlan_sg_ref(struct in_addr local_vtep_ip
,
6144 struct in_addr mcast_grp
)
6146 struct zebra_vrf
*zvrf
;
6148 if (local_vtep_ip
.s_addr
== INADDR_ANY
6149 || mcast_grp
.s_addr
== INADDR_ANY
)
6152 zvrf
= vrf_info_lookup(VRF_DEFAULT
);
6155 zebra_vxlan_sg_do_ref(zvrf
, local_vtep_ip
, mcast_grp
);
6158 static void zebra_vxlan_xg_pre_cleanup(struct hash_bucket
*bucket
, void *arg
)
6160 struct zebra_vxlan_sg
*vxlan_sg
= (struct zebra_vxlan_sg
*)bucket
->data
;
6162 /* increment the ref count against (*,G) to prevent them from being
6165 if (vxlan_sg
->sg
.src
.s_addr
== INADDR_ANY
)
6166 ++vxlan_sg
->ref_cnt
;
6169 static void zebra_vxlan_xg_post_cleanup(struct hash_bucket
*bucket
, void *arg
)
6171 struct zebra_vxlan_sg
*vxlan_sg
= (struct zebra_vxlan_sg
*)bucket
->data
;
6173 /* decrement the dummy ref count against (*,G) to delete them */
6174 if (vxlan_sg
->sg
.src
.s_addr
== INADDR_ANY
) {
6175 if (vxlan_sg
->ref_cnt
)
6176 --vxlan_sg
->ref_cnt
;
6177 if (!vxlan_sg
->ref_cnt
)
6178 zebra_vxlan_sg_del(vxlan_sg
);
6182 static void zebra_vxlan_sg_cleanup(struct hash_bucket
*bucket
, void *arg
)
6184 struct zebra_vxlan_sg
*vxlan_sg
= (struct zebra_vxlan_sg
*)bucket
->data
;
6186 zebra_vxlan_sg_del(vxlan_sg
);
6189 static void zebra_vxlan_cleanup_sg_table(struct zebra_vrf
*zvrf
)
6191 /* increment the ref count against (*,G) to prevent them from being
6194 hash_iterate(zvrf
->vxlan_sg_table
, zebra_vxlan_xg_pre_cleanup
, NULL
);
6196 hash_iterate(zvrf
->vxlan_sg_table
, zebra_vxlan_sg_cleanup
, NULL
);
6198 /* decrement the dummy ref count against the XG entries */
6199 hash_iterate(zvrf
->vxlan_sg_table
, zebra_vxlan_xg_post_cleanup
, NULL
);
6202 static void zebra_vxlan_sg_replay_send(struct hash_bucket
*bucket
, void *arg
)
6204 struct zebra_vxlan_sg
*vxlan_sg
= (struct zebra_vxlan_sg
*)bucket
->data
;
6206 zebra_vxlan_sg_send(vxlan_sg
->zvrf
, &vxlan_sg
->sg
,
6207 vxlan_sg
->sg_str
, ZEBRA_VXLAN_SG_ADD
);
6210 /* Handle message from client to replay vxlan SG entries */
6211 void zebra_vxlan_sg_replay(ZAPI_HANDLER_ARGS
)
6213 if (IS_ZEBRA_DEBUG_VXLAN
)
6214 zlog_debug("VxLAN SG updates to PIM, start");
6216 SET_FLAG(zvrf
->flags
, ZEBRA_PIM_SEND_VXLAN_SG
);
6218 if (!EVPN_ENABLED(zvrf
)) {
6219 if (IS_ZEBRA_DEBUG_VXLAN
)
6220 zlog_debug("VxLAN SG replay request on unexpected vrf %d",
6225 hash_iterate(zvrf
->vxlan_sg_table
, zebra_vxlan_sg_replay_send
, NULL
);
6229 /* Cleanup EVPN configuration of a specific VRF */
6230 static void zebra_evpn_vrf_cfg_cleanup(struct zebra_vrf
*zvrf
)
6232 struct zebra_l3vni
*zl3vni
= NULL
;
6234 zvrf
->advertise_all_vni
= 0;
6235 zvrf
->advertise_gw_macip
= 0;
6236 zvrf
->advertise_svi_macip
= 0;
6237 zvrf
->vxlan_flood_ctrl
= VXLAN_FLOOD_HEAD_END_REPL
;
6239 hash_iterate(zvrf
->evpn_table
, zebra_evpn_cfg_cleanup
, NULL
);
6242 zl3vni
= zl3vni_lookup(zvrf
->l3vni
);
6244 /* delete and uninstall all rmacs */
6245 hash_iterate(zl3vni
->rmac_table
, zl3vni_del_rmac_hash_entry
,
6247 /* delete and uninstall all next-hops */
6248 hash_iterate(zl3vni
->nh_table
, zl3vni_del_nh_hash_entry
,
6253 /* Cleanup BGP EVPN configuration upon client disconnect */
6254 static int zebra_evpn_bgp_cfg_clean_up(struct zserv
*client
)
6257 struct zebra_vrf
*zvrf
;
6259 RB_FOREACH (vrf
, vrf_id_head
, &vrfs_by_id
) {
6262 zebra_evpn_vrf_cfg_cleanup(zvrf
);
6268 static int zebra_evpn_pim_cfg_clean_up(struct zserv
*client
)
6270 struct zebra_vrf
*zvrf
= zebra_vrf_get_evpn();
6272 if (CHECK_FLAG(zvrf
->flags
, ZEBRA_PIM_SEND_VXLAN_SG
)) {
6273 if (IS_ZEBRA_DEBUG_VXLAN
)
6274 zlog_debug("VxLAN SG updates to PIM, stop");
6275 UNSET_FLAG(zvrf
->flags
, ZEBRA_PIM_SEND_VXLAN_SG
);
6281 static int zebra_evpn_cfg_clean_up(struct zserv
*client
)
6283 if (client
->proto
== ZEBRA_ROUTE_BGP
)
6284 return zebra_evpn_bgp_cfg_clean_up(client
);
6286 if (client
->proto
== ZEBRA_ROUTE_PIM
)
6287 return zebra_evpn_pim_cfg_clean_up(client
);
6293 * Handle results for vxlan dataplane operations.
6295 extern void zebra_vxlan_handle_result(struct zebra_dplane_ctx
*ctx
)
6300 /* Config knob for accepting lower sequence numbers */
6301 void zebra_vxlan_set_accept_bgp_seq(bool set
)
6303 accept_bgp_seq
= set
;
6306 bool zebra_vxlan_get_accept_bgp_seq(void)
6308 return accept_bgp_seq
;
6311 /* Cleanup BGP EVPN configuration upon client disconnect */
6312 extern void zebra_evpn_init(void)
6314 hook_register(zserv_client_close
, zebra_evpn_cfg_clean_up
);