2 * Zebra EVPN for VxLAN code
3 * Copyright (C) 2016, 2017 Cumulus Networks, Inc.
5 * This file is part of FRR.
7 * FRR is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation; either version 2, or (at your option) any
12 * FRR is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with FRR; see the file COPYING. If not, write to the Free
19 * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
37 #include <linux/neighbour.h>
39 #include "lib/printfrr.h"
41 #include "zebra/zebra_router.h"
42 #include "zebra/debug.h"
43 #include "zebra/interface.h"
44 #include "zebra/rib.h"
46 #include "zebra/rt_netlink.h"
47 #include "zebra/zebra_errors.h"
48 #include "zebra/zebra_l2.h"
49 #include "zebra/zebra_l2_bridge_if.h"
50 #include "zebra/zebra_ns.h"
51 #include "zebra/zebra_vrf.h"
52 #include "zebra/zebra_vxlan.h"
53 #include "zebra/zebra_vxlan_private.h"
54 #include "zebra/zebra_evpn.h"
55 #include "zebra/zebra_evpn_mac.h"
56 #include "zebra/zebra_evpn_neigh.h"
57 #include "zebra/zebra_evpn_mh.h"
58 #include "zebra/zebra_evpn_vxlan.h"
59 #include "zebra/zebra_router.h"
61 DEFINE_MTYPE_STATIC(ZEBRA
, HOST_PREFIX
, "host prefix");
62 DEFINE_MTYPE_STATIC(ZEBRA
, ZL3VNI
, "L3 VNI hash");
63 DEFINE_MTYPE_STATIC(ZEBRA
, L3VNI_MAC
, "EVPN L3VNI MAC");
64 DEFINE_MTYPE_STATIC(ZEBRA
, L3NEIGH
, "EVPN Neighbor");
65 DEFINE_MTYPE_STATIC(ZEBRA
, ZVXLAN_SG
, "zebra VxLAN multicast group");
66 DEFINE_MTYPE_STATIC(ZEBRA
, EVPN_VTEP
, "zebra VxLAN VTEP IP");
68 DEFINE_HOOK(zebra_rmac_update
,
69 (struct zebra_mac
* rmac
, struct zebra_l3vni
*zl3vni
, bool delete,
71 (rmac
, zl3vni
, delete, reason
));
74 static bool accept_bgp_seq
= true;
76 /* Single VXlan Device Global Neigh Table */
77 struct hash
*svd_nh_table
;
79 /* static function declarations */
80 static void zevpn_print_neigh_hash_all_evpn(struct hash_bucket
*bucket
,
82 static void zl3vni_print_nh(struct zebra_neigh
*n
, struct vty
*vty
,
84 static void zl3vni_print_rmac(struct zebra_mac
*zrmac
, struct vty
*vty
,
86 static void zevpn_print_mac_hash_all_evpn(struct hash_bucket
*bucket
, void *ctxt
);
88 /* l3-vni next-hop neigh related APIs */
89 static struct zebra_neigh
*zl3vni_nh_lookup(struct zebra_l3vni
*zl3vni
,
90 const struct ipaddr
*ip
);
91 static void *zl3vni_nh_alloc(void *p
);
92 static struct zebra_neigh
*zl3vni_nh_add(struct zebra_l3vni
*zl3vni
,
93 const struct ipaddr
*vtep_ip
,
94 const struct ethaddr
*rmac
);
95 static int zl3vni_nh_del(struct zebra_l3vni
*zl3vni
, struct zebra_neigh
*n
);
96 static int zl3vni_nh_install(struct zebra_l3vni
*zl3vni
, struct zebra_neigh
*n
);
97 static int zl3vni_nh_uninstall(struct zebra_l3vni
*zl3vni
,
98 struct zebra_neigh
*n
);
99 static struct zebra_neigh
*svd_nh_add(const struct ipaddr
*vtep_ip
,
100 const struct ethaddr
*rmac
);
101 static int svd_nh_del(struct zebra_neigh
*n
);
102 static int svd_nh_install(struct zebra_l3vni
*zl3vni
, struct zebra_neigh
*n
);
103 static int svd_nh_uninstall(struct zebra_l3vni
*zl3vni
, struct zebra_neigh
*n
);
105 /* l3-vni rmac related APIs */
106 static void zl3vni_print_rmac_hash(struct hash_bucket
*, void *);
107 static struct zebra_mac
*zl3vni_rmac_lookup(struct zebra_l3vni
*zl3vni
,
108 const struct ethaddr
*rmac
);
109 static void *zl3vni_rmac_alloc(void *p
);
110 static struct zebra_mac
*zl3vni_rmac_add(struct zebra_l3vni
*zl3vni
,
111 const struct ethaddr
*rmac
);
112 static int zl3vni_rmac_del(struct zebra_l3vni
*zl3vni
, struct zebra_mac
*zrmac
);
113 static int zl3vni_rmac_install(struct zebra_l3vni
*zl3vni
,
114 struct zebra_mac
*zrmac
);
115 static int zl3vni_rmac_uninstall(struct zebra_l3vni
*zl3vni
,
116 struct zebra_mac
*zrmac
);
118 /* l3-vni related APIs*/
119 static void *zl3vni_alloc(void *p
);
120 static struct zebra_l3vni
*zl3vni_add(vni_t vni
, vrf_id_t vrf_id
);
121 static int zl3vni_del(struct zebra_l3vni
*zl3vni
);
123 static void zevpn_build_hash_table(void);
124 static unsigned int zebra_vxlan_sg_hash_key_make(const void *p
);
125 static bool zebra_vxlan_sg_hash_eq(const void *p1
, const void *p2
);
126 static void zebra_vxlan_sg_do_deref(struct zebra_vrf
*zvrf
,
127 struct in_addr sip
, struct in_addr mcast_grp
);
128 static struct zebra_vxlan_sg
*zebra_vxlan_sg_do_ref(struct zebra_vrf
*vrf
,
130 struct in_addr mcast_grp
);
131 static void zebra_vxlan_cleanup_sg_table(struct zebra_vrf
*zvrf
);
133 bool zebra_evpn_do_dup_addr_detect(struct zebra_vrf
*zvrf
)
135 return zvrf
->dup_addr_detect
&& zebra_evpn_mh_do_dup_addr_detect();
138 /* Private functions */
139 static int host_rb_entry_compare(const struct host_rb_entry
*hle1
,
140 const struct host_rb_entry
*hle2
)
142 if (hle1
->p
.family
< hle2
->p
.family
)
145 if (hle1
->p
.family
> hle2
->p
.family
)
148 if (hle1
->p
.prefixlen
< hle2
->p
.prefixlen
)
151 if (hle1
->p
.prefixlen
> hle2
->p
.prefixlen
)
154 if (hle1
->p
.family
== AF_INET
) {
155 if (hle1
->p
.u
.prefix4
.s_addr
< hle2
->p
.u
.prefix4
.s_addr
)
158 if (hle1
->p
.u
.prefix4
.s_addr
> hle2
->p
.u
.prefix4
.s_addr
)
162 } else if (hle1
->p
.family
== AF_INET6
) {
163 return memcmp(&hle1
->p
.u
.prefix6
, &hle2
->p
.u
.prefix6
,
165 } else if (hle1
->p
.family
== AF_EVPN
) {
169 /* two (v4/v6) dummy prefixes of route_type BGP_EVPN_AD_ROUTE
170 * are used for all nexthops associated with a non-zero ESI
172 family1
= is_evpn_prefix_ipaddr_v4(
173 (const struct prefix_evpn
*)&hle1
->p
)
176 family2
= is_evpn_prefix_ipaddr_v4(
177 (const struct prefix_evpn
*)&hle2
->p
)
182 if (family1
< family2
)
185 if (family1
> family2
)
190 zlog_debug("%s: Unexpected family type: %d", __func__
,
195 RB_GENERATE(host_rb_tree_entry
, host_rb_entry
, hl_entry
, host_rb_entry_compare
);
197 static uint32_t rb_host_count(struct host_rb_tree_entry
*hrbe
)
199 struct host_rb_entry
*hle
;
202 RB_FOREACH (hle
, host_rb_tree_entry
, hrbe
)
208 static int l3vni_rmac_nh_list_cmp(void *p1
, void *p2
)
210 const struct ipaddr
*vtep_ip1
= p1
;
211 const struct ipaddr
*vtep_ip2
= p2
;
213 return !ipaddr_cmp(vtep_ip1
, vtep_ip2
);
216 static void l3vni_rmac_nh_free(struct ipaddr
*vtep_ip
)
218 XFREE(MTYPE_EVPN_VTEP
, vtep_ip
);
221 static void l3vni_rmac_nh_list_nh_delete(struct zebra_l3vni
*zl3vni
,
222 struct zebra_mac
*zrmac
,
223 struct ipaddr
*vtep_ip
)
225 struct listnode
*node
= NULL
, *nnode
= NULL
;
226 struct ipaddr
*vtep
= NULL
;
228 for (ALL_LIST_ELEMENTS(zrmac
->nh_list
, node
, nnode
, vtep
)) {
229 if (ipaddr_cmp(vtep
, vtep_ip
) == 0)
234 l3vni_rmac_nh_free(vtep
);
235 list_delete_node(zrmac
->nh_list
, node
);
240 * Print neighbors for all EVPN.
242 static void zevpn_print_neigh_hash_all_evpn(struct hash_bucket
*bucket
,
246 json_object
*json
= NULL
, *json_evpn
= NULL
;
247 struct zebra_evpn
*zevpn
;
249 struct neigh_walk_ctx wctx
;
250 char vni_str
[VNI_STR_LEN
];
253 vty
= (struct vty
*)args
[0];
254 json
= (json_object
*)args
[1];
255 print_dup
= (uint32_t)(uintptr_t)args
[2];
257 zevpn
= (struct zebra_evpn
*)bucket
->data
;
259 num_neigh
= hashcount(zevpn
->neigh_table
);
262 num_neigh
= num_dup_detected_neighs(zevpn
);
266 "\nVNI %u #ARP (IPv4 and IPv6, local and remote) %u\n\n",
267 zevpn
->vni
, num_neigh
);
269 json_evpn
= json_object_new_object();
270 json_object_int_add(json_evpn
, "numArpNd", num_neigh
);
271 snprintf(vni_str
, VNI_STR_LEN
, "%u", zevpn
->vni
);
276 json_object_object_add(json
, vni_str
, json_evpn
);
280 /* Since we have IPv6 addresses to deal with which can vary widely in
281 * size, we try to be a bit more elegant in display by first computing
284 memset(&wctx
, 0, sizeof(wctx
));
287 wctx
.addr_width
= 15;
288 wctx
.json
= json_evpn
;
289 hash_iterate(zevpn
->neigh_table
, zebra_evpn_find_neigh_addr_width
,
293 zebra_evpn_print_neigh_hdr(vty
, &wctx
);
296 hash_iterate(zevpn
->neigh_table
,
297 zebra_evpn_print_dad_neigh_hash
, &wctx
);
299 hash_iterate(zevpn
->neigh_table
, zebra_evpn_print_neigh_hash
,
303 json_object_object_add(json
, vni_str
, json_evpn
);
307 * Print neighbors for all EVPNs in detail.
309 static void zevpn_print_neigh_hash_all_evpn_detail(struct hash_bucket
*bucket
,
313 json_object
*json
= NULL
, *json_evpn
= NULL
;
314 struct zebra_evpn
*zevpn
;
316 struct neigh_walk_ctx wctx
;
317 char vni_str
[VNI_STR_LEN
];
320 vty
= (struct vty
*)args
[0];
321 json
= (json_object
*)args
[1];
322 print_dup
= (uint32_t)(uintptr_t)args
[2];
324 zevpn
= (struct zebra_evpn
*)bucket
->data
;
327 vty_out(vty
, "{}\n");
330 num_neigh
= hashcount(zevpn
->neigh_table
);
332 if (print_dup
&& num_dup_detected_neighs(zevpn
) == 0)
337 "\nVNI %u #ARP (IPv4 and IPv6, local and remote) %u\n\n",
338 zevpn
->vni
, num_neigh
);
340 json_evpn
= json_object_new_object();
341 json_object_int_add(json_evpn
, "numArpNd", num_neigh
);
342 snprintf(vni_str
, VNI_STR_LEN
, "%u", zevpn
->vni
);
346 json_object_object_add(json
, vni_str
, json_evpn
);
350 memset(&wctx
, 0, sizeof(wctx
));
353 wctx
.addr_width
= 15;
354 wctx
.json
= json_evpn
;
357 hash_iterate(zevpn
->neigh_table
,
358 zebra_evpn_print_dad_neigh_hash_detail
, &wctx
);
360 hash_iterate(zevpn
->neigh_table
,
361 zebra_evpn_print_neigh_hash_detail
, &wctx
);
364 json_object_object_add(json
, vni_str
, json_evpn
);
367 /* print a specific next hop for an l3vni */
368 static void zl3vni_print_nh(struct zebra_neigh
*n
, struct vty
*vty
,
371 char buf1
[ETHER_ADDR_STRLEN
];
372 char buf2
[INET6_ADDRSTRLEN
];
373 json_object
*json_hosts
= NULL
;
374 struct host_rb_entry
*hle
;
377 vty_out(vty
, "Ip: %s\n",
378 ipaddr2str(&n
->ip
, buf2
, sizeof(buf2
)));
379 vty_out(vty
, " RMAC: %s\n",
380 prefix_mac2str(&n
->emac
, buf1
, sizeof(buf1
)));
383 vty_out(vty
, " Refcount: %u\n", n
->refcnt
);
385 vty_out(vty
, " Refcount: %d\n",
386 rb_host_count(&n
->host_rb
));
387 vty_out(vty
, " Prefixes:\n");
388 RB_FOREACH (hle
, host_rb_tree_entry
, &n
->host_rb
)
389 vty_out(vty
, " %pFX\n", &hle
->p
);
392 json_hosts
= json_object_new_array();
393 json_object_string_add(
394 json
, "ip", ipaddr2str(&(n
->ip
), buf2
, sizeof(buf2
)));
395 json_object_string_add(
397 prefix_mac2str(&n
->emac
, buf2
, sizeof(buf2
)));
400 json_object_int_add(json
, "refCount", n
->refcnt
);
402 json_object_int_add(json
, "refCount",
403 rb_host_count(&n
->host_rb
));
404 RB_FOREACH (hle
, host_rb_tree_entry
, &n
->host_rb
)
405 json_object_array_add(
407 json_object_new_string(prefix2str(
408 &hle
->p
, buf2
, sizeof(buf2
))));
409 json_object_object_add(json
, "prefixList", json_hosts
);
414 /* Print a specific RMAC entry */
415 static void zl3vni_print_rmac(struct zebra_mac
*zrmac
, struct vty
*vty
,
418 struct listnode
*node
= NULL
;
419 struct ipaddr
*vtep
= NULL
;
420 json_object
*json_nhs
= NULL
;
423 vty_out(vty
, "MAC: %pEA\n", &zrmac
->macaddr
);
424 vty_out(vty
, " Remote VTEP: %pI4\n",
425 &zrmac
->fwd_info
.r_vtep_ip
);
427 json_nhs
= json_object_new_array();
428 json_object_string_addf(json
, "routerMac", "%pEA",
430 json_object_string_addf(json
, "vtepIp", "%pI4",
431 &zrmac
->fwd_info
.r_vtep_ip
);
432 for (ALL_LIST_ELEMENTS_RO(zrmac
->nh_list
, node
, vtep
)) {
433 json_object_array_add(json_nhs
, json_object_new_stringf(
436 json_object_object_add(json
, "nexthops", json_nhs
);
441 * Print MACs for all EVPNs.
443 static void zevpn_print_mac_hash_all_evpn(struct hash_bucket
*bucket
, void *ctxt
)
446 json_object
*json
= NULL
, *json_evpn
= NULL
;
447 json_object
*json_mac
= NULL
;
448 struct zebra_evpn
*zevpn
;
450 struct mac_walk_ctx
*wctx
= ctxt
;
451 char vni_str
[VNI_STR_LEN
];
456 zevpn
= (struct zebra_evpn
*)bucket
->data
;
459 /*We are iterating over a new VNI, set the count to 0*/
462 num_macs
= num_valid_macs(zevpn
);
467 num_macs
= num_dup_detected_macs(zevpn
);
470 json_evpn
= json_object_new_object();
471 json_mac
= json_object_new_object();
472 snprintf(vni_str
, VNI_STR_LEN
, "%u", zevpn
->vni
);
475 if (!CHECK_FLAG(wctx
->flags
, SHOW_REMOTE_MAC_FROM_VTEP
)) {
477 vty_out(vty
, "\nVNI %u #MACs (local and remote) %u\n\n",
478 zevpn
->vni
, num_macs
);
480 "Flags: N=sync-neighs, I=local-inactive, P=peer-active, X=peer-proxy\n");
481 vty_out(vty
, "%-17s %-6s %-5s %-30s %-5s %s\n", "MAC",
482 "Type", "Flags", "Intf/Remote ES/VTEP",
485 json_object_int_add(json_evpn
, "numMacs", num_macs
);
490 json_object_int_add(json_evpn
, "numMacs", num_macs
);
491 json_object_object_add(json
, vni_str
, json_evpn
);
496 /* assign per-evpn to wctx->json object to fill macs
497 * under the evpn. Re-assign primary json object to fill
498 * next evpn information.
500 wctx
->json
= json_mac
;
502 hash_iterate(zevpn
->mac_table
, zebra_evpn_print_dad_mac_hash
,
505 hash_iterate(zevpn
->mac_table
, zebra_evpn_print_mac_hash
, wctx
);
509 json_object_object_add(json_evpn
, "macs", json_mac
);
510 json_object_object_add(json
, vni_str
, json_evpn
);
515 * Print MACs in detail for all EVPNs.
517 static void zevpn_print_mac_hash_all_evpn_detail(struct hash_bucket
*bucket
,
521 json_object
*json
= NULL
, *json_evpn
= NULL
;
522 json_object
*json_mac
= NULL
;
523 struct zebra_evpn
*zevpn
;
525 struct mac_walk_ctx
*wctx
= ctxt
;
526 char vni_str
[VNI_STR_LEN
];
531 zevpn
= (struct zebra_evpn
*)bucket
->data
;
534 vty_out(vty
, "{}\n");
539 /*We are iterating over a new EVPN, set the count to 0*/
542 num_macs
= num_valid_macs(zevpn
);
546 if (wctx
->print_dup
&& (num_dup_detected_macs(zevpn
) == 0))
550 json_evpn
= json_object_new_object();
551 json_mac
= json_object_new_object();
552 snprintf(vni_str
, VNI_STR_LEN
, "%u", zevpn
->vni
);
555 if (!CHECK_FLAG(wctx
->flags
, SHOW_REMOTE_MAC_FROM_VTEP
)) {
557 vty_out(vty
, "\nVNI %u #MACs (local and remote) %u\n\n",
558 zevpn
->vni
, num_macs
);
560 json_object_int_add(json_evpn
, "numMacs", num_macs
);
562 /* assign per-evpn to wctx->json object to fill macs
563 * under the evpn. Re-assign primary json object to fill
564 * next evpn information.
566 wctx
->json
= json_mac
;
568 hash_iterate(zevpn
->mac_table
,
569 zebra_evpn_print_dad_mac_hash_detail
, wctx
);
571 hash_iterate(zevpn
->mac_table
, zebra_evpn_print_mac_hash_detail
,
576 json_object_object_add(json_evpn
, "macs", json_mac
);
577 json_object_object_add(json
, vni_str
, json_evpn
);
581 static void zl3vni_print_nh_hash(struct hash_bucket
*bucket
, void *ctx
)
583 struct nh_walk_ctx
*wctx
= NULL
;
584 struct vty
*vty
= NULL
;
585 struct json_object
*json_evpn
= NULL
;
586 struct json_object
*json_nh
= NULL
;
587 struct zebra_neigh
*n
= NULL
;
588 char buf1
[ETHER_ADDR_STRLEN
];
589 char buf2
[INET6_ADDRSTRLEN
];
591 wctx
= (struct nh_walk_ctx
*)ctx
;
593 json_evpn
= wctx
->json
;
595 json_nh
= json_object_new_object();
596 n
= (struct zebra_neigh
*)bucket
->data
;
599 vty_out(vty
, "%-15s %-17s\n",
600 ipaddr2str(&(n
->ip
), buf2
, sizeof(buf2
)),
601 prefix_mac2str(&n
->emac
, buf1
, sizeof(buf1
)));
603 json_object_string_add(json_nh
, "nexthopIp",
604 ipaddr2str(&n
->ip
, buf2
, sizeof(buf2
)));
605 json_object_string_add(
606 json_nh
, "routerMac",
607 prefix_mac2str(&n
->emac
, buf1
, sizeof(buf1
)));
608 json_object_object_add(json_evpn
,
609 ipaddr2str(&(n
->ip
), buf2
, sizeof(buf2
)),
614 static void zl3vni_print_nh_all_table(struct hash
*nh_table
, vni_t vni
,
615 struct vty
*vty
, json_object
*json
)
618 struct nh_walk_ctx wctx
;
619 char vni_str
[VNI_STR_LEN
];
620 json_object
*json_evpn
= NULL
;
622 const char *svd_str
= "Global SVD Table";
627 num_nh
= hashcount(nh_table
);
633 json_evpn
= json_object_new_object();
635 snprintf(vni_str
, VNI_STR_LEN
, "%u", vni
);
640 vty_out(vty
, "\n%s #Next-Hops %u\n\n", svd_str
, num_nh
);
642 vty_out(vty
, "\nVNI %u #Next-Hops %u\n\n", vni
, num_nh
);
644 vty_out(vty
, "%-15s %-17s\n", "IP", "RMAC");
646 json_object_int_add(json_evpn
, "numNextHops", num_nh
);
648 memset(&wctx
, 0, sizeof(wctx
));
650 wctx
.json
= json_evpn
;
651 hash_iterate(nh_table
, zl3vni_print_nh_hash
, &wctx
);
653 json_object_object_add(json
, vni_str
, json_evpn
);
656 static void zl3vni_print_nh_hash_all_vni(struct hash_bucket
*bucket
,
659 struct vty
*vty
= NULL
;
660 json_object
*json
= NULL
;
661 struct zebra_l3vni
*zl3vni
= NULL
;
663 vty
= (struct vty
*)args
[0];
664 json
= (struct json_object
*)args
[1];
666 zl3vni
= (struct zebra_l3vni
*)bucket
->data
;
668 zl3vni_print_nh_all_table(zl3vni
->nh_table
, zl3vni
->vni
, vty
, json
);
671 static void zl3vni_print_rmac_hash_all_vni(struct hash_bucket
*bucket
,
674 struct vty
*vty
= NULL
;
675 json_object
*json
= NULL
;
676 json_object
*json_evpn
= NULL
;
677 struct zebra_l3vni
*zl3vni
= NULL
;
679 struct rmac_walk_ctx wctx
;
680 char vni_str
[VNI_STR_LEN
];
682 vty
= (struct vty
*)args
[0];
683 json
= (struct json_object
*)args
[1];
685 zl3vni
= (struct zebra_l3vni
*)bucket
->data
;
687 num_rmacs
= hashcount(zl3vni
->rmac_table
);
692 json_evpn
= json_object_new_object();
693 snprintf(vni_str
, VNI_STR_LEN
, "%u", zl3vni
->vni
);
697 vty_out(vty
, "\nVNI %u #RMACs %u\n\n", zl3vni
->vni
, num_rmacs
);
698 vty_out(vty
, "%-17s %-21s\n", "RMAC", "Remote VTEP");
700 json_object_int_add(json_evpn
, "numRmacs", num_rmacs
);
702 /* assign per-vni to wctx->json object to fill macs
703 * under the vni. Re-assign primary json object to fill
704 * next vni information.
706 memset(&wctx
, 0, sizeof(wctx
));
708 wctx
.json
= json_evpn
;
709 hash_iterate(zl3vni
->rmac_table
, zl3vni_print_rmac_hash
, &wctx
);
711 json_object_object_add(json
, vni_str
, json_evpn
);
714 static void zl3vni_print_rmac_hash(struct hash_bucket
*bucket
, void *ctx
)
716 struct zebra_mac
*zrmac
= NULL
;
717 struct rmac_walk_ctx
*wctx
= NULL
;
718 struct vty
*vty
= NULL
;
719 struct json_object
*json
= NULL
;
720 struct json_object
*json_rmac
= NULL
;
721 char buf
[PREFIX_STRLEN
];
723 wctx
= (struct rmac_walk_ctx
*)ctx
;
727 json_rmac
= json_object_new_object();
728 zrmac
= (struct zebra_mac
*)bucket
->data
;
731 vty_out(vty
, "%-17s %-21pI4\n",
732 prefix_mac2str(&zrmac
->macaddr
, buf
, sizeof(buf
)),
733 &zrmac
->fwd_info
.r_vtep_ip
);
735 json_object_string_add(
736 json_rmac
, "routerMac",
737 prefix_mac2str(&zrmac
->macaddr
, buf
, sizeof(buf
)));
738 json_object_string_addf(json_rmac
, "vtepIp", "%pI4",
739 &zrmac
->fwd_info
.r_vtep_ip
);
740 json_object_object_add(
741 json
, prefix_mac2str(&zrmac
->macaddr
, buf
, sizeof(buf
)),
746 /* print a specific L3 VNI entry */
747 static void zl3vni_print(struct zebra_l3vni
*zl3vni
, void **ctx
)
749 char buf
[PREFIX_STRLEN
];
750 struct vty
*vty
= NULL
;
751 json_object
*json
= NULL
;
752 struct zebra_evpn
*zevpn
= NULL
;
753 json_object
*json_evpn_list
= NULL
;
754 struct listnode
*node
= NULL
, *nnode
= NULL
;
760 vty_out(vty
, "VNI: %u\n", zl3vni
->vni
);
761 vty_out(vty
, " Type: %s\n", "L3");
762 vty_out(vty
, " Tenant VRF: %s\n", zl3vni_vrf_name(zl3vni
));
763 vty_out(vty
, " Vlan: %u\n", zl3vni
->vid
);
764 vty_out(vty
, " Bridge: %s\n",
765 zl3vni
->bridge_if
? zl3vni
->bridge_if
->name
: "-");
766 vty_out(vty
, " Local Vtep Ip: %pI4\n",
767 &zl3vni
->local_vtep_ip
);
768 vty_out(vty
, " Vxlan-Intf: %s\n",
769 zl3vni_vxlan_if_name(zl3vni
));
770 vty_out(vty
, " SVI-If: %s\n", zl3vni_svi_if_name(zl3vni
));
771 vty_out(vty
, " State: %s\n", zl3vni_state2str(zl3vni
));
772 vty_out(vty
, " VNI Filter: %s\n",
773 CHECK_FLAG(zl3vni
->filter
, PREFIX_ROUTES_ONLY
)
774 ? "prefix-routes-only"
776 vty_out(vty
, " System MAC: %s\n",
777 zl3vni_sysmac2str(zl3vni
, buf
, sizeof(buf
)));
778 vty_out(vty
, " Router MAC: %s\n",
779 zl3vni_rmac2str(zl3vni
, buf
, sizeof(buf
)));
780 vty_out(vty
, " L2 VNIs: ");
781 for (ALL_LIST_ELEMENTS(zl3vni
->l2vnis
, node
, nnode
, zevpn
))
782 vty_out(vty
, "%u ", zevpn
->vni
);
785 json_evpn_list
= json_object_new_array();
786 json_object_int_add(json
, "vni", zl3vni
->vni
);
787 json_object_string_add(json
, "type", "L3");
788 #if CONFDATE > 20240210
789 CPP_NOTICE("Drop `vrf` from JSON outputs")
791 json_object_string_add(json
, "vrf", zl3vni_vrf_name(zl3vni
));
792 json_object_string_add(json
, "tenantVrf",
793 zl3vni_vrf_name(zl3vni
));
794 json_object_string_addf(json
, "localVtepIp", "%pI4",
795 &zl3vni
->local_vtep_ip
);
796 json_object_string_add(json
, "vxlanIntf",
797 zl3vni_vxlan_if_name(zl3vni
));
798 json_object_string_add(json
, "sviIntf",
799 zl3vni_svi_if_name(zl3vni
));
800 json_object_string_add(json
, "state", zl3vni_state2str(zl3vni
));
801 json_object_string_add(
803 zl3vni_sysmac2str(zl3vni
, buf
, sizeof(buf
)));
804 json_object_string_add(
806 zl3vni_rmac2str(zl3vni
, buf
, sizeof(buf
)));
807 json_object_string_add(
809 CHECK_FLAG(zl3vni
->filter
, PREFIX_ROUTES_ONLY
)
810 ? "prefix-routes-only"
812 for (ALL_LIST_ELEMENTS(zl3vni
->l2vnis
, node
, nnode
, zevpn
)) {
813 json_object_array_add(json_evpn_list
,
814 json_object_new_int(zevpn
->vni
));
816 json_object_object_add(json
, "l2Vnis", json_evpn_list
);
820 /* print a L3 VNI hash entry */
821 static void zl3vni_print_hash(struct hash_bucket
*bucket
, void *ctx
[])
823 struct vty
*vty
= NULL
;
824 json_object
*json
= NULL
;
825 json_object
*json_evpn
= NULL
;
826 struct zebra_l3vni
*zl3vni
= NULL
;
828 vty
= (struct vty
*)ctx
[0];
829 json
= (json_object
*)ctx
[1];
831 zl3vni
= (struct zebra_l3vni
*)bucket
->data
;
834 vty_out(vty
, "%-10u %-4s %-21s %-8lu %-8lu %-15s %-37s\n",
835 zl3vni
->vni
, "L3", zl3vni_vxlan_if_name(zl3vni
),
836 hashcount(zl3vni
->rmac_table
),
837 hashcount(zl3vni
->nh_table
), "n/a",
838 zl3vni_vrf_name(zl3vni
));
840 char vni_str
[VNI_STR_LEN
];
842 snprintf(vni_str
, VNI_STR_LEN
, "%u", zl3vni
->vni
);
843 json_evpn
= json_object_new_object();
844 json_object_int_add(json_evpn
, "vni", zl3vni
->vni
);
845 json_object_string_add(json_evpn
, "vxlanIf",
846 zl3vni_vxlan_if_name(zl3vni
));
847 json_object_int_add(json_evpn
, "numMacs",
848 hashcount(zl3vni
->rmac_table
));
849 json_object_int_add(json_evpn
, "numArpNd",
850 hashcount(zl3vni
->nh_table
));
851 json_object_string_add(json_evpn
, "numRemoteVteps", "n/a");
852 json_object_string_add(json_evpn
, "type", "L3");
853 json_object_string_add(json_evpn
, "tenantVrf",
854 zl3vni_vrf_name(zl3vni
));
855 json_object_object_add(json
, vni_str
, json_evpn
);
859 /* print a L3 VNI hash entry in detail*/
860 static void zl3vni_print_hash_detail(struct hash_bucket
*bucket
, void *data
)
862 struct vty
*vty
= NULL
;
863 struct zebra_l3vni
*zl3vni
= NULL
;
864 json_object
*json_array
= NULL
;
865 bool use_json
= false;
866 struct zebra_evpn_show
*zes
= data
;
869 json_array
= zes
->json
;
870 use_json
= zes
->use_json
;
872 zl3vni
= (struct zebra_l3vni
*)bucket
->data
;
874 zebra_vxlan_print_vni(vty
, zes
->zvrf
, zl3vni
->vni
,
875 use_json
, json_array
);
881 static int zvni_map_to_svi_ns(struct ns
*ns
,
885 struct zebra_ns
*zns
= ns
->info
;
886 struct route_node
*rn
;
887 struct zebra_from_svi_param
*in_param
=
888 (struct zebra_from_svi_param
*)_in_param
;
889 struct zebra_l2info_vlan
*vl
;
890 struct interface
*tmp_if
= NULL
;
891 struct interface
**p_ifp
= (struct interface
**)_p_ifp
;
892 struct zebra_if
*zif
;
894 assert(in_param
&& p_ifp
);
896 /* TODO: Optimize with a hash. */
897 for (rn
= route_top(zns
->if_table
); rn
; rn
= route_next(rn
)) {
898 tmp_if
= (struct interface
*)rn
->info
;
899 /* Check oper status of the SVI. */
900 if (!tmp_if
|| !if_is_operative(tmp_if
))
903 if (!zif
|| zif
->zif_type
!= ZEBRA_IF_VLAN
904 || zif
->link
!= in_param
->br_if
)
906 vl
= (struct zebra_l2info_vlan
*)&zif
->l2info
.vl
;
908 if (vl
->vid
== in_param
->vid
) {
913 return NS_WALK_CONTINUE
;
916 /* Map to SVI on bridge corresponding to specified VLAN. This can be one
918 * (a) In the case of a VLAN-aware bridge, the SVI is a L3 VLAN interface
919 * linked to the bridge
920 * (b) In the case of a VLAN-unaware bridge, the SVI is the bridge interface
923 struct interface
*zvni_map_to_svi(vlanid_t vid
, struct interface
*br_if
)
925 struct interface
*tmp_if
= NULL
;
926 struct zebra_if
*zif
;
927 struct zebra_from_svi_param in_param
;
928 struct interface
**p_ifp
;
929 /* Defensive check, caller expected to invoke only with valid bridge. */
933 /* Determine if bridge is VLAN-aware or not */
936 in_param
.bridge_vlan_aware
= IS_ZEBRA_IF_BRIDGE_VLAN_AWARE(zif
);
937 /* Check oper status of the SVI. */
938 if (!in_param
.bridge_vlan_aware
)
939 return if_is_operative(br_if
) ? br_if
: NULL
;
942 in_param
.br_if
= br_if
;
945 /* Identify corresponding VLAN interface. */
946 ns_walk_func(zvni_map_to_svi_ns
, (void *)&in_param
,
951 int zebra_evpn_vxlan_del(struct zebra_evpn
*zevpn
)
954 zevpn_vxlan_if_set(zevpn
, zevpn
->vxlan_if
, false /* set */);
955 zevpn_bridge_if_set(zevpn
, zevpn
->bridge_if
, false /* set */);
957 /* Remove references to the BUM mcast grp */
958 zebra_vxlan_sg_deref(zevpn
->local_vtep_ip
, zevpn
->mcast_grp
);
960 return zebra_evpn_del(zevpn
);
963 static int zevpn_build_vni_hash_table(struct zebra_if
*zif
,
964 struct zebra_vxlan_vni
*vnip
, void *arg
)
967 struct zebra_evpn
*zevpn
;
968 struct zebra_l3vni
*zl3vni
;
969 struct interface
*ifp
;
970 struct zebra_l2info_vxlan
*vxl
;
971 struct interface
*br_if
;
974 vxl
= &zif
->l2info
.vxl
;
977 if (IS_ZEBRA_DEBUG_VXLAN
)
978 zlog_debug("Build vni table for vni %u for Intf %s", vni
,
981 /* L3-VNI and L2-VNI are handled seperately */
982 zl3vni
= zl3vni_lookup(vni
);
985 if (IS_ZEBRA_DEBUG_VXLAN
)
987 "create L3-VNI hash for Intf %s(%u) L3-VNI %u",
988 ifp
->name
, ifp
->ifindex
, vni
);
990 /* associate with vxlan_if */
991 zl3vni
->local_vtep_ip
= vxl
->vtep_ip
;
992 zl3vni
->vxlan_if
= ifp
;
995 * we need to associate with SVI.
996 * we can associate with svi-if only after association
997 * with vxlan-intf is complete
999 zl3vni
->svi_if
= zl3vni_map_to_svi_if(zl3vni
);
1001 /* Associate l3vni to mac-vlan and extract VRR MAC */
1002 zl3vni
->mac_vlan_if
= zl3vni_map_to_mac_vlan_if(zl3vni
);
1004 if (IS_ZEBRA_DEBUG_VXLAN
)
1006 "create l3vni %u svi_if %s mac_vlan_if %s", vni
,
1007 zl3vni
->svi_if
? zl3vni
->svi_if
->name
: "NIL",
1008 zl3vni
->mac_vlan_if
? zl3vni
->mac_vlan_if
->name
1011 if (is_l3vni_oper_up(zl3vni
))
1012 zebra_vxlan_process_l3vni_oper_up(zl3vni
);
1015 struct interface
*vlan_if
= NULL
;
1017 if (IS_ZEBRA_DEBUG_VXLAN
)
1019 "Create L2-VNI hash for intf %s(%u) L2-VNI %u local IP %pI4",
1020 ifp
->name
, ifp
->ifindex
, vni
, &vxl
->vtep_ip
);
1023 * EVPN hash entry is expected to exist, if the BGP process is
1026 zevpn
= zebra_evpn_lookup(vni
);
1029 "EVPN hash already present for IF %s(%u) L2-VNI %u",
1030 ifp
->name
, ifp
->ifindex
, vni
);
1033 * Inform BGP if intf is up and mapped to
1036 if (if_is_operative(ifp
) && zif
->brslave_info
.br_if
)
1037 zebra_evpn_send_add_to_client(zevpn
);
1039 /* Send Local MAC-entries to client */
1040 zebra_evpn_send_mac_list_to_client(zevpn
);
1042 /* Send Loval Neighbor entries to client */
1043 zebra_evpn_send_neigh_to_client(zevpn
);
1045 zevpn
= zebra_evpn_add(vni
);
1048 "Failed to add EVPN hash, IF %s(%u) L2-VNI %u",
1049 ifp
->name
, ifp
->ifindex
, vni
);
1053 if (zevpn
->local_vtep_ip
.s_addr
!=
1054 vxl
->vtep_ip
.s_addr
||
1055 zevpn
->mcast_grp
.s_addr
!= vnip
->mcast_grp
.s_addr
) {
1056 zebra_vxlan_sg_deref(zevpn
->local_vtep_ip
,
1058 zebra_vxlan_sg_ref(vxl
->vtep_ip
,
1060 zevpn
->local_vtep_ip
= vxl
->vtep_ip
;
1061 zevpn
->mcast_grp
= vnip
->mcast_grp
;
1062 /* on local vtep-ip check if ES
1063 * orig-ip needs to be updated
1065 zebra_evpn_es_set_base_evpn(zevpn
);
1067 zevpn_vxlan_if_set(zevpn
, ifp
, true /* set */);
1068 br_if
= zif
->brslave_info
.br_if
;
1069 zevpn_bridge_if_set(zevpn
, br_if
, true /* set */);
1070 vlan_if
= zvni_map_to_svi(vnip
->access_vlan
, br_if
);
1072 zevpn
->vid
= vnip
->access_vlan
;
1073 zevpn
->svi_if
= vlan_if
;
1074 zevpn
->vrf_id
= vlan_if
->vrf
->vrf_id
;
1075 zl3vni
= zl3vni_from_vrf(vlan_if
->vrf
->vrf_id
);
1077 listnode_add_sort(zl3vni
->l2vnis
,
1082 * Inform BGP if intf is up and mapped to
1085 if (if_is_operative(ifp
) && zif
->brslave_info
.br_if
)
1086 zebra_evpn_send_add_to_client(zevpn
);
1093 static int zevpn_build_hash_table_zns(struct ns
*ns
,
1094 void *param_in
__attribute__((unused
)),
1095 void **param_out
__attribute__((unused
)))
1097 struct zebra_ns
*zns
= ns
->info
;
1098 struct route_node
*rn
;
1099 struct interface
*ifp
;
1100 struct zebra_vrf
*zvrf
;
1102 zvrf
= zebra_vrf_get_evpn();
1104 /* Walk VxLAN interfaces and create EVPN hash. */
1105 for (rn
= route_top(zns
->if_table
); rn
; rn
= route_next(rn
)) {
1106 struct zebra_if
*zif
;
1107 struct zebra_l2info_vxlan
*vxl
;
1109 ifp
= (struct interface
*)rn
->info
;
1113 if (!zif
|| zif
->zif_type
!= ZEBRA_IF_VXLAN
)
1116 vxl
= &zif
->l2info
.vxl
;
1117 /* link of VXLAN interface should be in zebra_evpn_vrf */
1118 if (zvrf
->zns
->ns_id
!= vxl
->link_nsid
) {
1119 if (IS_ZEBRA_DEBUG_VXLAN
)
1121 "Intf %s(%u) link not in same "
1122 "namespace than BGP EVPN core instance ",
1123 ifp
->name
, ifp
->ifindex
);
1127 if (IS_ZEBRA_DEBUG_VXLAN
)
1128 zlog_debug("Building vni table for %s-if %s",
1129 IS_ZEBRA_VXLAN_IF_VNI(zif
) ? "vni" : "svd",
1132 zebra_vxlan_if_vni_iterate(zif
, zevpn_build_vni_hash_table
,
1135 return NS_WALK_CONTINUE
;
1139 * Build the VNI hash table by going over the VxLAN interfaces. This
1140 * is called when EVPN (advertise-all-vni) is enabled.
1143 static void zevpn_build_hash_table(void)
1145 ns_walk_func(zevpn_build_hash_table_zns
, NULL
, NULL
);
1149 * Cleanup EVPN/VTEP and update kernel
1151 static void zebra_evpn_vxlan_cleanup_all(struct hash_bucket
*bucket
, void *arg
)
1153 struct zebra_evpn
*zevpn
= NULL
;
1154 struct zebra_l3vni
*zl3vni
= NULL
;
1156 zevpn
= (struct zebra_evpn
*)bucket
->data
;
1158 /* remove l2vni from l2vni's tenant-vrf l3-vni list */
1159 zl3vni
= zl3vni_from_vrf(zevpn
->vrf_id
);
1161 listnode_delete(zl3vni
->l2vnis
, zevpn
);
1163 zebra_evpn_cleanup_all(bucket
, arg
);
1167 static void zl3vni_cleanup_all(struct hash_bucket
*bucket
, void *args
)
1169 struct zebra_l3vni
*zl3vni
= NULL
;
1171 zl3vni
= (struct zebra_l3vni
*)bucket
->data
;
1173 zebra_vxlan_process_l3vni_oper_down(zl3vni
);
1176 static void rb_find_or_add_host(struct host_rb_tree_entry
*hrbe
,
1177 const struct prefix
*host
)
1179 struct host_rb_entry lookup
;
1180 struct host_rb_entry
*hle
;
1182 memset(&lookup
, 0, sizeof(lookup
));
1183 memcpy(&lookup
.p
, host
, sizeof(*host
));
1185 hle
= RB_FIND(host_rb_tree_entry
, hrbe
, &lookup
);
1189 hle
= XCALLOC(MTYPE_HOST_PREFIX
, sizeof(struct host_rb_entry
));
1190 memcpy(hle
, &lookup
, sizeof(lookup
));
1192 RB_INSERT(host_rb_tree_entry
, hrbe
, hle
);
1195 static void rb_delete_host(struct host_rb_tree_entry
*hrbe
, struct prefix
*host
)
1197 struct host_rb_entry lookup
;
1198 struct host_rb_entry
*hle
;
1200 memset(&lookup
, 0, sizeof(lookup
));
1201 memcpy(&lookup
.p
, host
, sizeof(*host
));
1203 hle
= RB_FIND(host_rb_tree_entry
, hrbe
, &lookup
);
1205 RB_REMOVE(host_rb_tree_entry
, hrbe
, hle
);
1206 XFREE(MTYPE_HOST_PREFIX
, hle
);
1213 * Look up MAC hash entry.
1215 static struct zebra_mac
*zl3vni_rmac_lookup(struct zebra_l3vni
*zl3vni
,
1216 const struct ethaddr
*rmac
)
1218 struct zebra_mac tmp
;
1219 struct zebra_mac
*pmac
;
1221 memset(&tmp
, 0, sizeof(tmp
));
1222 memcpy(&tmp
.macaddr
, rmac
, ETH_ALEN
);
1223 pmac
= hash_lookup(zl3vni
->rmac_table
, &tmp
);
1229 * Callback to allocate RMAC hash entry.
1231 static void *zl3vni_rmac_alloc(void *p
)
1233 const struct zebra_mac
*tmp_rmac
= p
;
1234 struct zebra_mac
*zrmac
;
1236 zrmac
= XCALLOC(MTYPE_L3VNI_MAC
, sizeof(struct zebra_mac
));
1239 return ((void *)zrmac
);
1243 * Add RMAC entry to l3-vni
1245 static struct zebra_mac
*zl3vni_rmac_add(struct zebra_l3vni
*zl3vni
,
1246 const struct ethaddr
*rmac
)
1248 struct zebra_mac tmp_rmac
;
1249 struct zebra_mac
*zrmac
= NULL
;
1251 memset(&tmp_rmac
, 0, sizeof(tmp_rmac
));
1252 memcpy(&tmp_rmac
.macaddr
, rmac
, ETH_ALEN
);
1253 zrmac
= hash_get(zl3vni
->rmac_table
, &tmp_rmac
, zl3vni_rmac_alloc
);
1254 zrmac
->nh_list
= list_new();
1255 zrmac
->nh_list
->cmp
= (int (*)(void *, void *))l3vni_rmac_nh_list_cmp
;
1256 zrmac
->nh_list
->del
= (void (*)(void *))l3vni_rmac_nh_free
;
1258 SET_FLAG(zrmac
->flags
, ZEBRA_MAC_REMOTE
);
1259 SET_FLAG(zrmac
->flags
, ZEBRA_MAC_REMOTE_RMAC
);
1267 static int zl3vni_rmac_del(struct zebra_l3vni
*zl3vni
, struct zebra_mac
*zrmac
)
1269 struct zebra_mac
*tmp_rmac
;
1271 /* free the list of nh list*/
1272 list_delete(&zrmac
->nh_list
);
1274 tmp_rmac
= hash_release(zl3vni
->rmac_table
, zrmac
);
1275 XFREE(MTYPE_L3VNI_MAC
, tmp_rmac
);
1281 * Install remote RMAC into the forwarding plane.
1283 static int zl3vni_rmac_install(struct zebra_l3vni
*zl3vni
,
1284 struct zebra_mac
*zrmac
)
1286 const struct zebra_if
*zif
= NULL
, *br_zif
= NULL
;
1287 const struct zebra_vxlan_vni
*vni
;
1288 const struct interface
*br_ifp
;
1289 enum zebra_dplane_result res
;
1292 if (!(CHECK_FLAG(zrmac
->flags
, ZEBRA_MAC_REMOTE
))
1293 || !(CHECK_FLAG(zrmac
->flags
, ZEBRA_MAC_REMOTE_RMAC
)))
1296 zif
= zl3vni
->vxlan_if
->info
;
1300 br_ifp
= zif
->brslave_info
.br_if
;
1304 vni
= zebra_vxlan_if_vni_find(zif
, zl3vni
->vni
);
1306 br_zif
= (const struct zebra_if
*)br_ifp
->info
;
1308 if (IS_ZEBRA_IF_BRIDGE_VLAN_AWARE(br_zif
))
1309 vid
= vni
->access_vlan
;
1313 res
= dplane_rem_mac_add(zl3vni
->vxlan_if
, br_ifp
, vid
, &zrmac
->macaddr
,
1314 vni
->vni
, zrmac
->fwd_info
.r_vtep_ip
, 0, 0,
1315 false /*was_static*/);
1316 if (res
!= ZEBRA_DPLANE_REQUEST_FAILURE
)
1323 * Uninstall remote RMAC from the forwarding plane.
1325 static int zl3vni_rmac_uninstall(struct zebra_l3vni
*zl3vni
,
1326 struct zebra_mac
*zrmac
)
1328 const struct zebra_if
*zif
= NULL
, *br_zif
;
1329 const struct zebra_vxlan_vni
*vni
;
1330 const struct interface
*br_ifp
;
1332 enum zebra_dplane_result res
;
1334 if (!(CHECK_FLAG(zrmac
->flags
, ZEBRA_MAC_REMOTE
))
1335 || !(CHECK_FLAG(zrmac
->flags
, ZEBRA_MAC_REMOTE_RMAC
)))
1338 if (!zl3vni
->vxlan_if
) {
1339 if (IS_ZEBRA_DEBUG_VXLAN
)
1341 "RMAC %pEA on L3-VNI %u hash %p couldn't be uninstalled - no vxlan_if",
1342 &zrmac
->macaddr
, zl3vni
->vni
, zl3vni
);
1346 zif
= zl3vni
->vxlan_if
->info
;
1350 br_ifp
= zif
->brslave_info
.br_if
;
1354 vni
= zebra_vxlan_if_vni_find(zif
, zl3vni
->vni
);
1356 br_zif
= (const struct zebra_if
*)br_ifp
->info
;
1357 if (IS_ZEBRA_IF_BRIDGE_VLAN_AWARE(br_zif
))
1358 vid
= vni
->access_vlan
;
1362 res
= dplane_rem_mac_del(zl3vni
->vxlan_if
, br_ifp
, vid
, &zrmac
->macaddr
,
1363 vni
->vni
, zrmac
->fwd_info
.r_vtep_ip
);
1364 if (res
!= ZEBRA_DPLANE_REQUEST_FAILURE
)
1370 /* handle rmac add */
1371 static int zl3vni_remote_rmac_add(struct zebra_l3vni
*zl3vni
,
1372 const struct ethaddr
*rmac
,
1373 const struct ipaddr
*vtep_ip
)
1375 struct zebra_mac
*zrmac
= NULL
;
1376 struct ipaddr
*vtep
= NULL
;
1378 zrmac
= zl3vni_rmac_lookup(zl3vni
, rmac
);
1381 /* Create the RMAC entry, or update its vtep, if necessary. */
1382 zrmac
= zl3vni_rmac_add(zl3vni
, rmac
);
1385 "Failed to add RMAC %pEA L3VNI %u Remote VTEP %pIA",
1386 rmac
, zl3vni
->vni
, vtep_ip
);
1389 memset(&zrmac
->fwd_info
, 0, sizeof(zrmac
->fwd_info
));
1390 zrmac
->fwd_info
.r_vtep_ip
= vtep_ip
->ipaddr_v4
;
1392 vtep
= XCALLOC(MTYPE_EVPN_VTEP
, sizeof(struct ipaddr
));
1393 memcpy(vtep
, vtep_ip
, sizeof(struct ipaddr
));
1394 if (!listnode_add_sort_nodup(zrmac
->nh_list
, (void *)vtep
))
1395 XFREE(MTYPE_EVPN_VTEP
, vtep
);
1397 /* Send RMAC for FPM processing */
1398 hook_call(zebra_rmac_update
, zrmac
, zl3vni
, false,
1401 /* install rmac in kernel */
1402 zl3vni_rmac_install(zl3vni
, zrmac
);
1403 } else if (!IPV4_ADDR_SAME(&zrmac
->fwd_info
.r_vtep_ip
,
1404 &vtep_ip
->ipaddr_v4
)) {
1405 if (IS_ZEBRA_DEBUG_VXLAN
)
1407 "L3VNI %u Remote VTEP change(%pI4 -> %pIA) for RMAC %pEA",
1408 zl3vni
->vni
, &zrmac
->fwd_info
.r_vtep_ip
,
1411 zrmac
->fwd_info
.r_vtep_ip
= vtep_ip
->ipaddr_v4
;
1413 vtep
= XCALLOC(MTYPE_EVPN_VTEP
, sizeof(struct ipaddr
));
1414 memcpy(vtep
, vtep_ip
, sizeof(struct ipaddr
));
1415 if (!listnode_add_sort_nodup(zrmac
->nh_list
, (void *)vtep
))
1416 XFREE(MTYPE_EVPN_VTEP
, vtep
);
1418 /* install rmac in kernel */
1419 zl3vni_rmac_install(zl3vni
, zrmac
);
1426 /* handle rmac delete */
1427 static void zl3vni_remote_rmac_del(struct zebra_l3vni
*zl3vni
,
1428 struct zebra_mac
*zrmac
,
1429 struct ipaddr
*vtep_ip
)
1431 struct ipaddr ipv4_vtep
;
1433 if (!zl3vni_nh_lookup(zl3vni
, vtep_ip
)) {
1434 memset(&ipv4_vtep
, 0, sizeof(ipv4_vtep
));
1435 ipv4_vtep
.ipa_type
= IPADDR_V4
;
1436 if (vtep_ip
->ipa_type
== IPADDR_V6
)
1437 ipv4_mapped_ipv6_to_ipv4(&vtep_ip
->ipaddr_v6
,
1438 &ipv4_vtep
.ipaddr_v4
);
1440 memcpy(&(ipv4_vtep
.ipaddr_v4
), &vtep_ip
->ipaddr_v4
,
1441 sizeof(struct in_addr
));
1443 /* remove nh from rmac's list */
1444 l3vni_rmac_nh_list_nh_delete(zl3vni
, zrmac
, &ipv4_vtep
);
1445 /* delete nh is same as current selected, fall back to
1446 * one present in the list
1448 if (IPV4_ADDR_SAME(&zrmac
->fwd_info
.r_vtep_ip
,
1449 &ipv4_vtep
.ipaddr_v4
) &&
1450 listcount(zrmac
->nh_list
)) {
1451 struct ipaddr
*vtep
;
1453 vtep
= listgetdata(listhead(zrmac
->nh_list
));
1454 zrmac
->fwd_info
.r_vtep_ip
= vtep
->ipaddr_v4
;
1455 if (IS_ZEBRA_DEBUG_VXLAN
)
1457 "L3VNI %u Remote VTEP nh change(%pIA -> %pI4) for RMAC %pEA",
1458 zl3vni
->vni
, &ipv4_vtep
,
1459 &zrmac
->fwd_info
.r_vtep_ip
,
1462 /* install rmac in kernel */
1463 zl3vni_rmac_install(zl3vni
, zrmac
);
1466 if (!listcount(zrmac
->nh_list
)) {
1467 /* uninstall from kernel */
1468 zl3vni_rmac_uninstall(zl3vni
, zrmac
);
1470 /* Send RMAC for FPM processing */
1471 hook_call(zebra_rmac_update
, zrmac
, zl3vni
, true,
1474 if (IS_ZEBRA_DEBUG_VXLAN
)
1476 "L3VNI %u RMAC %pEA vtep_ip %pIA delete",
1477 zl3vni
->vni
, &zrmac
->macaddr
, vtep_ip
);
1479 /* del the rmac entry */
1480 zl3vni_rmac_del(zl3vni
, zrmac
);
1486 * Common code for look up of nh hash entry.
1488 static struct zebra_neigh
*_nh_lookup(struct zebra_l3vni
*zl3vni
,
1489 const struct ipaddr
*ip
)
1491 struct zebra_neigh tmp
;
1492 struct zebra_neigh
*n
;
1494 memset(&tmp
, 0, sizeof(tmp
));
1495 memcpy(&tmp
.ip
, ip
, sizeof(struct ipaddr
));
1498 n
= hash_lookup(zl3vni
->nh_table
, &tmp
);
1500 n
= hash_lookup(svd_nh_table
, &tmp
);
1506 * Look up nh hash entry on a l3-vni.
1508 static struct zebra_neigh
*zl3vni_nh_lookup(struct zebra_l3vni
*zl3vni
,
1509 const struct ipaddr
*ip
)
1511 return _nh_lookup(zl3vni
, ip
);
1515 * Look up nh hash entry on a SVD.
1517 static struct zebra_neigh
*svd_nh_lookup(const struct ipaddr
*ip
)
1519 return _nh_lookup(NULL
, ip
);
1523 * Callback to allocate NH hash entry on L3-VNI.
1525 static void *zl3vni_nh_alloc(void *p
)
1527 const struct zebra_neigh
*tmp_n
= p
;
1528 struct zebra_neigh
*n
;
1530 n
= XCALLOC(MTYPE_L3NEIGH
, sizeof(struct zebra_neigh
));
1537 * Common code for neigh add.
1539 static struct zebra_neigh
*_nh_add(struct zebra_l3vni
*zl3vni
,
1540 const struct ipaddr
*ip
,
1541 const struct ethaddr
*mac
)
1543 struct zebra_neigh tmp_n
;
1544 struct zebra_neigh
*n
= NULL
;
1546 memset(&tmp_n
, 0, sizeof(tmp_n
));
1547 memcpy(&tmp_n
.ip
, ip
, sizeof(struct ipaddr
));
1550 n
= hash_get(zl3vni
->nh_table
, &tmp_n
, zl3vni_nh_alloc
);
1552 n
= hash_get(svd_nh_table
, &tmp_n
, zl3vni_nh_alloc
);
1556 RB_INIT(host_rb_tree_entry
, &n
->host_rb
);
1558 memcpy(&n
->emac
, mac
, ETH_ALEN
);
1559 SET_FLAG(n
->flags
, ZEBRA_NEIGH_REMOTE
);
1560 SET_FLAG(n
->flags
, ZEBRA_NEIGH_REMOTE_NH
);
1566 * Add neighbor entry.
1568 static struct zebra_neigh
*zl3vni_nh_add(struct zebra_l3vni
*zl3vni
,
1569 const struct ipaddr
*ip
,
1570 const struct ethaddr
*mac
)
1572 return _nh_add(zl3vni
, ip
, mac
);
1576 * Delete neighbor entry.
1578 static int zl3vni_nh_del(struct zebra_l3vni
*zl3vni
, struct zebra_neigh
*n
)
1580 struct zebra_neigh
*tmp_n
;
1581 struct host_rb_entry
*hle
;
1583 while (!RB_EMPTY(host_rb_tree_entry
, &n
->host_rb
)) {
1584 hle
= RB_ROOT(host_rb_tree_entry
, &n
->host_rb
);
1586 RB_REMOVE(host_rb_tree_entry
, &n
->host_rb
, hle
);
1587 XFREE(MTYPE_HOST_PREFIX
, hle
);
1590 tmp_n
= hash_release(zl3vni
->nh_table
, n
);
1591 XFREE(MTYPE_L3NEIGH
, tmp_n
);
1597 * Add Single VXlan Device neighbor entry.
1599 static struct zebra_neigh
*svd_nh_add(const struct ipaddr
*ip
,
1600 const struct ethaddr
*mac
)
1602 return _nh_add(NULL
, ip
, mac
);
1606 * Del Single VXlan Device neighbor entry.
1608 static int svd_nh_del(struct zebra_neigh
*n
)
1613 hash_release(svd_nh_table
, n
);
1614 XFREE(MTYPE_L3NEIGH
, n
);
1620 * Common code to install remote nh as neigh into the kernel.
1622 static int _nh_install(struct zebra_l3vni
*zl3vni
, struct interface
*ifp
,
1623 struct zebra_neigh
*n
)
1628 if (zl3vni
&& !is_l3vni_oper_up(zl3vni
))
1631 if (!(n
->flags
& ZEBRA_NEIGH_REMOTE
)
1632 || !(n
->flags
& ZEBRA_NEIGH_REMOTE_NH
))
1635 flags
= DPLANE_NTF_EXT_LEARNED
;
1636 if (n
->flags
& ZEBRA_NEIGH_ROUTER_FLAG
)
1637 flags
|= DPLANE_NTF_ROUTER
;
1639 dplane_rem_neigh_add(ifp
, &n
->ip
, &n
->emac
, flags
,
1640 false /*was_static*/);
1646 * Common code to uninstall remote nh from the kernel.
1648 static int _nh_uninstall(struct interface
*ifp
, struct zebra_neigh
*n
)
1650 if (!(n
->flags
& ZEBRA_NEIGH_REMOTE
)
1651 || !(n
->flags
& ZEBRA_NEIGH_REMOTE_NH
))
1654 if (!ifp
|| !if_is_operative(ifp
))
1657 dplane_rem_neigh_delete(ifp
, &n
->ip
);
1663 * Install remote nh as neigh into the kernel.
1665 static int zl3vni_nh_install(struct zebra_l3vni
*zl3vni
, struct zebra_neigh
*n
)
1667 return _nh_install(zl3vni
, zl3vni
->svi_if
, n
);
1671 * Uninstall remote nh from the kernel.
1673 static int zl3vni_nh_uninstall(struct zebra_l3vni
*zl3vni
,
1674 struct zebra_neigh
*n
)
1676 return _nh_uninstall(zl3vni
->svi_if
, n
);
1680 * Install SVD remote nh as neigh into the kernel.
1682 static int svd_nh_install(struct zebra_l3vni
*zl3vni
, struct zebra_neigh
*n
)
1684 return _nh_install(zl3vni
, zl3vni
->vxlan_if
, n
);
1688 * Uninstall SVD remote nh from the kernel.
1690 static int svd_nh_uninstall(struct zebra_l3vni
*zl3vni
, struct zebra_neigh
*n
)
1692 return _nh_uninstall(zl3vni
->vxlan_if
, n
);
1695 /* Add remote vtep as a neigh entry */
1696 static int zl3vni_remote_nh_add(struct zebra_l3vni
*zl3vni
,
1697 const struct ipaddr
*vtep_ip
,
1698 const struct ethaddr
*rmac
,
1699 const struct prefix
*host_prefix
)
1701 struct zebra_neigh
*nh
= NULL
;
1703 /* Create the next hop entry, or update its mac, if necessary. */
1704 nh
= zl3vni_nh_lookup(zl3vni
, vtep_ip
);
1706 nh
= zl3vni_nh_add(zl3vni
, vtep_ip
, rmac
);
1709 "Failed to add NH %pIA as Neigh (RMAC %pEA L3-VNI %u prefix %pFX)",
1710 vtep_ip
, rmac
, zl3vni
->vni
, host_prefix
);
1714 /* install the nh neigh in kernel */
1715 zl3vni_nh_install(zl3vni
, nh
);
1716 } else if (memcmp(&nh
->emac
, rmac
, ETH_ALEN
) != 0) {
1717 if (IS_ZEBRA_DEBUG_VXLAN
)
1719 "L3VNI %u RMAC change(%pEA --> %pEA) for nexthop %pIA, prefix %pFX",
1720 zl3vni
->vni
, &nh
->emac
, rmac
, vtep_ip
,
1723 memcpy(&nh
->emac
, rmac
, ETH_ALEN
);
1724 /* install (update) the nh neigh in kernel */
1725 zl3vni_nh_install(zl3vni
, nh
);
1728 rb_find_or_add_host(&nh
->host_rb
, host_prefix
);
1733 /* Del remote vtep as a neigh entry */
1734 static void zl3vni_remote_nh_del(struct zebra_l3vni
*zl3vni
,
1735 struct zebra_neigh
*nh
,
1736 struct prefix
*host_prefix
)
1738 rb_delete_host(&nh
->host_rb
, host_prefix
);
1740 if (RB_EMPTY(host_rb_tree_entry
, &nh
->host_rb
)) {
1741 /* uninstall from kernel */
1742 zl3vni_nh_uninstall(zl3vni
, nh
);
1744 /* delete the nh entry */
1745 zl3vni_nh_del(zl3vni
, nh
);
1749 /* Add remote vtep as a SVD neigh entry */
1750 static int svd_remote_nh_add(struct zebra_l3vni
*zl3vni
,
1751 const struct ipaddr
*vtep_ip
,
1752 const struct ethaddr
*rmac
,
1753 const struct prefix
*host_prefix
)
1755 struct zebra_neigh
*nh
= NULL
;
1757 /* SVD backed VNI check */
1758 if (!IS_ZL3VNI_SVD_BACKED(zl3vni
))
1761 /* Create the SVD next hop entry, or update its mac, if necessary. */
1762 nh
= svd_nh_lookup(vtep_ip
);
1764 nh
= svd_nh_add(vtep_ip
, rmac
);
1767 "Failed to add NH %pIA as SVD Neigh (RMAC %pEA prefix %pFX)",
1768 vtep_ip
, rmac
, host_prefix
);
1772 } else if (memcmp(&nh
->emac
, rmac
, ETH_ALEN
) != 0) {
1773 if (IS_ZEBRA_DEBUG_VXLAN
)
1775 "SVD RMAC change(%pEA --> %pEA) for nexthop %pIA, prefix %pFX",
1776 &nh
->emac
, rmac
, vtep_ip
, host_prefix
);
1778 memcpy(&nh
->emac
, rmac
, ETH_ALEN
);
1779 /* install (update) the nh neigh in kernel */
1780 svd_nh_install(zl3vni
, nh
);
1782 /* Don't increment refcnt change */
1788 if (IS_ZEBRA_DEBUG_VXLAN
)
1789 zlog_debug("SVD NH ADD refcnt (%u) for nexthop %pIA",
1790 nh
->refcnt
, vtep_ip
);
1793 * Install the nh neigh in kernel if this is the first time we
1796 if (nh
->refcnt
== 1)
1797 svd_nh_install(zl3vni
, nh
);
1802 /* Del remote vtep as a SVD neigh entry */
1803 static int svd_remote_nh_del(struct zebra_l3vni
*zl3vni
,
1804 const struct ipaddr
*vtep_ip
)
1806 struct zebra_neigh
*nh
;
1808 /* SVD backed VNI check */
1809 if (!IS_ZL3VNI_SVD_BACKED(zl3vni
))
1812 nh
= svd_nh_lookup(vtep_ip
);
1814 zlog_debug("Failed to del NH %pIA as SVD Neigh", vtep_ip
);
1821 if (IS_ZEBRA_DEBUG_VXLAN
)
1822 zlog_debug("SVD NH Del refcnt (%u) for nexthop %pIA",
1823 nh
->refcnt
, vtep_ip
);
1825 /* Last refcnt on NH, remove it completely. */
1826 if (nh
->refcnt
== 0) {
1827 svd_nh_uninstall(zl3vni
, nh
);
1834 /* handle neigh update from kernel - the only thing of interest is to
1835 * readd stale entries.
1837 static int zl3vni_local_nh_add_update(struct zebra_l3vni
*zl3vni
,
1838 struct ipaddr
*ip
, uint16_t state
)
1841 struct zebra_neigh
*n
= NULL
;
1843 n
= zl3vni_nh_lookup(zl3vni
, ip
);
1847 /* all next hop neigh are remote and installed by frr.
1848 * If the kernel has aged this entry, re-install.
1850 if (state
& NUD_STALE
)
1851 zl3vni_nh_install(zl3vni
, n
);
1856 /* handle neigh delete from kernel */
1857 static int zl3vni_local_nh_del(struct zebra_l3vni
*zl3vni
, struct ipaddr
*ip
)
1859 struct zebra_neigh
*n
= NULL
;
1861 n
= zl3vni_nh_lookup(zl3vni
, ip
);
1865 /* all next hop neigh are remote and installed by frr.
1866 * If we get an age out notification for these neigh entries, we have to
1869 zl3vni_nh_install(zl3vni
, n
);
1875 * Hash function for L3 VNI.
1877 static unsigned int l3vni_hash_keymake(const void *p
)
1879 const struct zebra_l3vni
*zl3vni
= p
;
1881 return jhash_1word(zl3vni
->vni
, 0);
1885 * Compare 2 L3 VNI hash entries.
1887 static bool l3vni_hash_cmp(const void *p1
, const void *p2
)
1889 const struct zebra_l3vni
*zl3vni1
= p1
;
1890 const struct zebra_l3vni
*zl3vni2
= p2
;
1892 return (zl3vni1
->vni
== zl3vni2
->vni
);
1896 * Callback to allocate L3 VNI hash entry.
1898 static void *zl3vni_alloc(void *p
)
1900 struct zebra_l3vni
*zl3vni
= NULL
;
1901 const struct zebra_l3vni
*tmp_l3vni
= p
;
1903 zl3vni
= XCALLOC(MTYPE_ZL3VNI
, sizeof(struct zebra_l3vni
));
1904 zl3vni
->vni
= tmp_l3vni
->vni
;
1905 return ((void *)zl3vni
);
1909 * Look up L3 VNI hash entry.
1911 struct zebra_l3vni
*zl3vni_lookup(vni_t vni
)
1913 struct zebra_l3vni tmp_l3vni
;
1914 struct zebra_l3vni
*zl3vni
= NULL
;
1916 memset(&tmp_l3vni
, 0, sizeof(tmp_l3vni
));
1917 tmp_l3vni
.vni
= vni
;
1918 zl3vni
= hash_lookup(zrouter
.l3vni_table
, &tmp_l3vni
);
1924 * Add L3 VNI hash entry.
1926 static struct zebra_l3vni
*zl3vni_add(vni_t vni
, vrf_id_t vrf_id
)
1928 struct zebra_l3vni tmp_zl3vni
;
1929 struct zebra_l3vni
*zl3vni
= NULL
;
1931 memset(&tmp_zl3vni
, 0, sizeof(tmp_zl3vni
));
1932 tmp_zl3vni
.vni
= vni
;
1934 zl3vni
= hash_get(zrouter
.l3vni_table
, &tmp_zl3vni
, zl3vni_alloc
);
1936 zl3vni
->vrf_id
= vrf_id
;
1937 zl3vni
->svi_if
= NULL
;
1938 zl3vni
->vxlan_if
= NULL
;
1939 zl3vni
->l2vnis
= list_new();
1940 zl3vni
->l2vnis
->cmp
= zebra_evpn_list_cmp
;
1942 /* Create hash table for remote RMAC */
1943 zl3vni
->rmac_table
= zebra_mac_db_create("Zebra L3-VNI RMAC-Table");
1945 /* Create hash table for neighbors */
1946 zl3vni
->nh_table
= zebra_neigh_db_create("Zebra L3-VNI next-hop table");
1952 * Delete L3 VNI hash entry.
1954 static int zl3vni_del(struct zebra_l3vni
*zl3vni
)
1956 struct zebra_l3vni
*tmp_zl3vni
;
1958 /* free the list of l2vnis */
1959 list_delete(&zl3vni
->l2vnis
);
1960 zl3vni
->l2vnis
= NULL
;
1962 /* Free the rmac table */
1963 hash_free(zl3vni
->rmac_table
);
1964 zl3vni
->rmac_table
= NULL
;
1966 /* Free the nh table */
1967 hash_free(zl3vni
->nh_table
);
1968 zl3vni
->nh_table
= NULL
;
1970 /* Free the VNI hash entry and allocated memory. */
1971 tmp_zl3vni
= hash_release(zrouter
.l3vni_table
, zl3vni
);
1972 XFREE(MTYPE_ZL3VNI
, tmp_zl3vni
);
1977 static int zl3vni_map_to_vxlan_if_ns(struct ns
*ns
,
1981 struct zebra_ns
*zns
= ns
->info
;
1982 struct zebra_l3vni
*zl3vni
= (struct zebra_l3vni
*)_zl3vni
;
1983 struct route_node
*rn
= NULL
;
1984 struct interface
*ifp
= NULL
;
1985 struct zebra_vrf
*zvrf
;
1987 zvrf
= zebra_vrf_get_evpn();
1991 /* loop through all vxlan-interface */
1992 for (rn
= route_top(zns
->if_table
); rn
; rn
= route_next(rn
)) {
1994 struct zebra_if
*zif
= NULL
;
1995 struct zebra_l2info_vxlan
*vxl
;
1996 struct zebra_vxlan_vni
*vni
= NULL
;
1998 ifp
= (struct interface
*)rn
->info
;
2003 if (!zif
|| zif
->zif_type
!= ZEBRA_IF_VXLAN
)
2006 vxl
= &zif
->l2info
.vxl
;
2007 vni
= zebra_vxlan_if_vni_find(zif
, zl3vni
->vni
);
2008 if (!vni
|| vni
->vni
!= zl3vni
->vni
)
2011 /* link of VXLAN interface should be in zebra_evpn_vrf */
2012 if (zvrf
->zns
->ns_id
!= vxl
->link_nsid
) {
2013 if (IS_ZEBRA_DEBUG_VXLAN
)
2015 "Intf %s(%u) VNI %u, link not in same "
2016 "namespace than BGP EVPN core instance ",
2017 ifp
->name
, ifp
->ifindex
, vni
->vni
);
2022 zl3vni
->local_vtep_ip
= zif
->l2info
.vxl
.vtep_ip
;
2023 *_pifp
= (void *)ifp
;
2024 return NS_WALK_STOP
;
2027 return NS_WALK_CONTINUE
;
2030 struct interface
*zl3vni_map_to_vxlan_if(struct zebra_l3vni
*zl3vni
)
2032 struct interface
**p_ifp
;
2033 struct interface
*ifp
= NULL
;
2037 ns_walk_func(zl3vni_map_to_vxlan_if_ns
,
2038 (void *)zl3vni
, (void **)p_ifp
);
2042 struct interface
*zl3vni_map_to_svi_if(struct zebra_l3vni
*zl3vni
)
2044 struct zebra_if
*zif
= NULL
; /* zebra_if for vxlan_if */
2045 struct zebra_vxlan_vni
*vni
= NULL
; /* vni info in vxlan_if */
2050 if (!zl3vni
->vxlan_if
)
2053 zif
= zl3vni
->vxlan_if
->info
;
2057 vni
= zebra_vxlan_if_vni_find(zif
, zl3vni
->vni
);
2061 return zvni_map_to_svi(vni
->access_vlan
, zif
->brslave_info
.br_if
);
2064 struct interface
*zl3vni_map_to_mac_vlan_if(struct zebra_l3vni
*zl3vni
)
2066 struct zebra_if
*zif
= NULL
; /* zebra_if for vxlan_if */
2071 if (!zl3vni
->vxlan_if
)
2074 zif
= zl3vni
->vxlan_if
->info
;
2078 return zebra_evpn_map_to_macvlan(zif
->brslave_info
.br_if
,
2083 struct zebra_l3vni
*zl3vni_from_vrf(vrf_id_t vrf_id
)
2085 struct zebra_vrf
*zvrf
= NULL
;
2087 zvrf
= zebra_vrf_lookup_by_id(vrf_id
);
2091 return zl3vni_lookup(zvrf
->l3vni
);
2094 static int zl3vni_from_svi_ns(struct ns
*ns
, void *_in_param
, void **_p_zl3vni
)
2098 struct zebra_ns
*zns
= ns
->info
;
2099 struct zebra_l3vni
**p_zl3vni
= (struct zebra_l3vni
**)_p_zl3vni
;
2100 struct zebra_from_svi_param
*in_param
=
2101 (struct zebra_from_svi_param
*)_in_param
;
2102 struct route_node
*rn
= NULL
;
2103 struct interface
*tmp_if
= NULL
;
2104 struct zebra_if
*zif
= NULL
;
2105 struct zebra_if
*br_zif
= NULL
;
2107 assert(in_param
&& p_zl3vni
);
2109 br_zif
= in_param
->br_if
->info
;
2112 if (in_param
->bridge_vlan_aware
) {
2113 vni_id
= zebra_l2_bridge_if_vni_find(br_zif
, in_param
->vid
);
2117 /* loop through all vxlan-interface */
2118 for (rn
= route_top(zns
->if_table
); rn
; rn
= route_next(rn
)) {
2119 tmp_if
= (struct interface
*)rn
->info
;
2123 if (!zif
|| zif
->zif_type
!= ZEBRA_IF_VXLAN
)
2125 if (!if_is_operative(tmp_if
))
2128 if (zif
->brslave_info
.br_if
!= in_param
->br_if
)
2131 vni_id
= zebra_vxlan_if_access_vlan_vni_find(
2132 zif
, in_param
->br_if
);
2141 return NS_WALK_CONTINUE
;
2143 *p_zl3vni
= zl3vni_lookup(vni_id
);
2144 return NS_WALK_STOP
;
2148 * Map SVI and associated bridge to a VNI. This is invoked upon getting
2149 * neighbor notifications, to see if they are of interest.
2151 static struct zebra_l3vni
*zl3vni_from_svi(struct interface
*ifp
,
2152 struct interface
*br_if
)
2154 struct zebra_l3vni
*zl3vni
= NULL
;
2155 struct zebra_if
*zif
= NULL
;
2156 struct zebra_from_svi_param in_param
= {};
2157 struct zebra_l3vni
**p_zl3vni
;
2162 /* Make sure the linked interface is a bridge. */
2163 if (!IS_ZEBRA_IF_BRIDGE(br_if
))
2165 in_param
.br_if
= br_if
;
2167 /* Determine if bridge is VLAN-aware or not */
2170 in_param
.bridge_vlan_aware
= IS_ZEBRA_IF_BRIDGE_VLAN_AWARE(zif
);
2171 if (in_param
.bridge_vlan_aware
) {
2172 struct zebra_l2info_vlan
*vl
;
2174 if (!IS_ZEBRA_IF_VLAN(ifp
))
2179 vl
= &zif
->l2info
.vl
;
2180 in_param
.vid
= vl
->vid
;
2183 /* See if this interface (or interface plus VLAN Id) maps to a VxLAN */
2184 /* TODO: Optimize with a hash. */
2188 ns_walk_func(zl3vni_from_svi_ns
, (void *)&in_param
, (void **)p_zl3vni
);
2192 vni_t
vni_id_from_svi(struct interface
*ifp
, struct interface
*br_if
)
2195 struct zebra_evpn
*zevpn
= NULL
;
2196 struct zebra_l3vni
*zl3vni
= NULL
;
2198 /* Check if an L3VNI belongs to this SVI interface.
2199 * If not, check if an L2VNI belongs to this SVI interface.
2201 zl3vni
= zl3vni_from_svi(ifp
, br_if
);
2205 zevpn
= zebra_evpn_from_svi(ifp
, br_if
);
2213 static inline void zl3vni_get_vrr_rmac(struct zebra_l3vni
*zl3vni
,
2214 struct ethaddr
*rmac
)
2219 if (!is_l3vni_oper_up(zl3vni
))
2222 if (zl3vni
->mac_vlan_if
&& if_is_operative(zl3vni
->mac_vlan_if
))
2223 memcpy(rmac
->octet
, zl3vni
->mac_vlan_if
->hw_addr
, ETH_ALEN
);
2227 * Inform BGP about l3-vni.
2229 static int zl3vni_send_add_to_client(struct zebra_l3vni
*zl3vni
)
2231 struct stream
*s
= NULL
;
2232 struct zserv
*client
= NULL
;
2233 struct ethaddr svi_rmac
, vrr_rmac
= {.octet
= {0} };
2234 struct zebra_vrf
*zvrf
;
2235 bool is_anycast_mac
= true;
2237 client
= zserv_find_client(ZEBRA_ROUTE_BGP
, 0);
2238 /* BGP may not be running. */
2242 zvrf
= zebra_vrf_lookup_by_id(zl3vni
->vrf_id
);
2245 /* get the svi and vrr rmac values */
2246 memset(&svi_rmac
, 0, sizeof(svi_rmac
));
2247 zl3vni_get_svi_rmac(zl3vni
, &svi_rmac
);
2248 zl3vni_get_vrr_rmac(zl3vni
, &vrr_rmac
);
2250 /* In absence of vrr mac use svi mac as anycast MAC value */
2251 if (is_zero_mac(&vrr_rmac
)) {
2252 memcpy(&vrr_rmac
, &svi_rmac
, ETH_ALEN
);
2253 is_anycast_mac
= false;
2256 s
= stream_new(ZEBRA_MAX_PACKET_SIZ
);
2258 /* The message is used for both vni add and/or update like
2259 * vrr mac is added for l3vni SVI.
2261 zclient_create_header(s
, ZEBRA_L3VNI_ADD
, zl3vni_vrf_id(zl3vni
));
2262 stream_putl(s
, zl3vni
->vni
);
2263 stream_put(s
, &svi_rmac
, sizeof(struct ethaddr
));
2264 stream_put_in_addr(s
, &zl3vni
->local_vtep_ip
);
2265 stream_put(s
, &zl3vni
->filter
, sizeof(int));
2266 stream_putl(s
, zl3vni
->svi_if
->ifindex
);
2267 stream_put(s
, &vrr_rmac
, sizeof(struct ethaddr
));
2268 stream_putl(s
, is_anycast_mac
);
2270 /* Write packet size. */
2271 stream_putw_at(s
, 0, stream_get_endp(s
));
2273 if (IS_ZEBRA_DEBUG_VXLAN
)
2275 "Send L3_VNI_ADD %u VRF %s RMAC %pEA VRR %pEA local-ip %pI4 filter %s to %s",
2276 zl3vni
->vni
, vrf_id_to_name(zl3vni_vrf_id(zl3vni
)),
2277 &svi_rmac
, &vrr_rmac
, &zl3vni
->local_vtep_ip
,
2278 CHECK_FLAG(zl3vni
->filter
, PREFIX_ROUTES_ONLY
)
2279 ? "prefix-routes-only"
2281 zebra_route_string(client
->proto
));
2283 client
->l3vniadd_cnt
++;
2284 return zserv_send_message(client
, s
);
2288 * Inform BGP about local l3-VNI deletion.
2290 static int zl3vni_send_del_to_client(struct zebra_l3vni
*zl3vni
)
2292 struct stream
*s
= NULL
;
2293 struct zserv
*client
= NULL
;
2295 client
= zserv_find_client(ZEBRA_ROUTE_BGP
, 0);
2296 /* BGP may not be running. */
2300 s
= stream_new(ZEBRA_MAX_PACKET_SIZ
);
2302 zclient_create_header(s
, ZEBRA_L3VNI_DEL
, zl3vni_vrf_id(zl3vni
));
2303 stream_putl(s
, zl3vni
->vni
);
2305 /* Write packet size. */
2306 stream_putw_at(s
, 0, stream_get_endp(s
));
2308 if (IS_ZEBRA_DEBUG_VXLAN
)
2309 zlog_debug("Send L3_VNI_DEL %u VRF %s to %s", zl3vni
->vni
,
2310 vrf_id_to_name(zl3vni_vrf_id(zl3vni
)),
2311 zebra_route_string(client
->proto
));
2313 client
->l3vnidel_cnt
++;
2314 return zserv_send_message(client
, s
);
2317 void zebra_vxlan_process_l3vni_oper_up(struct zebra_l3vni
*zl3vni
)
2322 /* send l3vni add to BGP */
2323 zl3vni_send_add_to_client(zl3vni
);
2326 void zebra_vxlan_process_l3vni_oper_down(struct zebra_l3vni
*zl3vni
)
2331 /* send l3-vni del to BGP*/
2332 zl3vni_send_del_to_client(zl3vni
);
2335 static void zevpn_add_to_l3vni_list(struct hash_bucket
*bucket
, void *ctxt
)
2337 struct zebra_evpn
*zevpn
= (struct zebra_evpn
*)bucket
->data
;
2338 struct zebra_l3vni
*zl3vni
= (struct zebra_l3vni
*)ctxt
;
2340 if (zevpn
->vrf_id
== zl3vni_vrf_id(zl3vni
))
2341 listnode_add_sort(zl3vni
->l2vnis
, zevpn
);
2345 * Handle transition of vni from l2 to l3 and vice versa.
2346 * This function handles only the L2VNI add/delete part of
2347 * the above transition.
2348 * L3VNI add/delete is handled by the calling functions.
2350 static int zebra_vxlan_handle_vni_transition(struct zebra_vrf
*zvrf
, vni_t vni
,
2353 struct zebra_evpn
*zevpn
= NULL
;
2354 struct zebra_l3vni
*zl3vni
= NULL
;
2356 /* There is a possibility that VNI notification was already received
2357 * from kernel and we programmed it as L2-VNI
2358 * In such a case we need to delete this L2-VNI first, so
2359 * that it can be reprogrammed as L3-VNI in the system. It is also
2360 * possible that the vrf-vni mapping is removed from FRR while the vxlan
2361 * interface is still present in kernel. In this case to keep it
2362 * symmetric, we will delete the l3-vni and reprogram it as l2-vni
2365 /* Locate hash entry */
2366 zevpn
= zebra_evpn_lookup(vni
);
2370 if (IS_ZEBRA_DEBUG_VXLAN
)
2371 zlog_debug("Del L2-VNI %u - transition to L3-VNI", vni
);
2373 /* Delete EVPN from BGP. */
2374 zebra_evpn_send_del_to_client(zevpn
);
2376 zebra_evpn_neigh_del_all(zevpn
, 0, 0, DEL_ALL_NEIGH
);
2377 zebra_evpn_mac_del_all(zevpn
, 0, 0, DEL_ALL_MAC
);
2379 /* Free up all remote VTEPs, if any. */
2380 zebra_evpn_vtep_del_all(zevpn
, 1);
2382 zl3vni
= zl3vni_from_vrf(zevpn
->vrf_id
);
2384 listnode_delete(zl3vni
->l2vnis
, zevpn
);
2386 /* Delete the hash entry. */
2387 if (zebra_evpn_vxlan_del(zevpn
)) {
2388 flog_err(EC_ZEBRA_VNI_DEL_FAILED
,
2389 "Failed to del EVPN hash %p, VNI %u", zevpn
,
2394 struct zebra_ns
*zns
;
2395 struct route_node
*rn
;
2396 struct interface
*ifp
;
2397 struct zebra_if
*zif
;
2398 struct zebra_vxlan_vni
*vnip
;
2399 struct zebra_l2info_vxlan
*vxl
;
2400 struct interface
*vlan_if
;
2403 if (IS_ZEBRA_DEBUG_VXLAN
)
2404 zlog_debug("Adding L2-VNI %u - transition from L3-VNI",
2407 /* Find VxLAN interface for this VNI. */
2408 zns
= zebra_ns_lookup(NS_DEFAULT
);
2409 for (rn
= route_top(zns
->if_table
); rn
; rn
= route_next(rn
)) {
2410 ifp
= (struct interface
*)rn
->info
;
2414 if (!zif
|| zif
->zif_type
!= ZEBRA_IF_VXLAN
)
2417 vxl
= &zif
->l2info
.vxl
;
2418 vnip
= zebra_vxlan_if_vni_find(zif
, vni
);
2426 if (IS_ZEBRA_DEBUG_VXLAN
)
2428 "Adding L2-VNI - Failed to find VxLAN interface for VNI %u",
2433 /* Create VNI hash entry for L2VNI */
2434 zevpn
= zebra_evpn_lookup(vni
);
2438 zevpn
= zebra_evpn_add(vni
);
2440 /* Find bridge interface for the VNI */
2441 vlan_if
= zvni_map_to_svi(vnip
->access_vlan
,
2442 zif
->brslave_info
.br_if
);
2444 zevpn
->vrf_id
= vlan_if
->vrf
->vrf_id
;
2445 zl3vni
= zl3vni_from_vrf(vlan_if
->vrf
->vrf_id
);
2447 listnode_add_sort_nodup(zl3vni
->l2vnis
, zevpn
);
2450 zevpn
->vxlan_if
= ifp
;
2451 zevpn
->local_vtep_ip
= vxl
->vtep_ip
;
2453 /* Inform BGP if the VNI is up and mapped to a bridge. */
2454 if (if_is_operative(ifp
) && zif
->brslave_info
.br_if
) {
2455 zebra_evpn_send_add_to_client(zevpn
);
2456 zebra_evpn_read_mac_neigh(zevpn
, ifp
);
2463 /* delete and uninstall rmac hash entry */
2464 static void zl3vni_del_rmac_hash_entry(struct hash_bucket
*bucket
, void *ctx
)
2466 struct zebra_mac
*zrmac
= NULL
;
2467 struct zebra_l3vni
*zl3vni
= NULL
;
2469 zrmac
= (struct zebra_mac
*)bucket
->data
;
2470 zl3vni
= (struct zebra_l3vni
*)ctx
;
2471 zl3vni_rmac_uninstall(zl3vni
, zrmac
);
2473 /* Send RMAC for FPM processing */
2474 hook_call(zebra_rmac_update
, zrmac
, zl3vni
, true, "RMAC deleted");
2476 zl3vni_rmac_del(zl3vni
, zrmac
);
2479 /* delete and uninstall nh hash entry */
2480 static void zl3vni_del_nh_hash_entry(struct hash_bucket
*bucket
, void *ctx
)
2482 struct zebra_neigh
*n
= NULL
;
2483 struct zebra_l3vni
*zl3vni
= NULL
;
2485 n
= (struct zebra_neigh
*)bucket
->data
;
2486 zl3vni
= (struct zebra_l3vni
*)ctx
;
2487 zl3vni_nh_uninstall(zl3vni
, n
);
2488 zl3vni_nh_del(zl3vni
, n
);
2491 /* re-add remote rmac if needed */
2492 static int zebra_vxlan_readd_remote_rmac(struct zebra_l3vni
*zl3vni
,
2493 struct ethaddr
*rmac
)
2495 struct zebra_mac
*zrmac
= NULL
;
2497 zrmac
= zl3vni_rmac_lookup(zl3vni
, rmac
);
2501 if (IS_ZEBRA_DEBUG_VXLAN
)
2502 zlog_debug("Del remote RMAC %pEA L3VNI %u - readd",
2505 zl3vni_rmac_install(zl3vni
, zrmac
);
2509 /* Public functions */
2511 int is_l3vni_for_prefix_routes_only(vni_t vni
)
2513 struct zebra_l3vni
*zl3vni
= NULL
;
2515 zl3vni
= zl3vni_lookup(vni
);
2519 return CHECK_FLAG(zl3vni
->filter
, PREFIX_ROUTES_ONLY
) ? 1 : 0;
2522 /* handle evpn route in vrf table */
2523 void zebra_vxlan_evpn_vrf_route_add(vrf_id_t vrf_id
, const struct ethaddr
*rmac
,
2524 const struct ipaddr
*vtep_ip
,
2525 const struct prefix
*host_prefix
)
2527 struct zebra_l3vni
*zl3vni
= NULL
;
2528 struct ipaddr ipv4_vtep
;
2530 zl3vni
= zl3vni_from_vrf(vrf_id
);
2531 if (!zl3vni
|| !is_l3vni_oper_up(zl3vni
))
2535 * add the next hop neighbor -
2536 * neigh to be installed is the ipv6 nexthop neigh
2538 zl3vni_remote_nh_add(zl3vni
, vtep_ip
, rmac
, host_prefix
);
2540 /* Add SVD next hop neighbor */
2541 svd_remote_nh_add(zl3vni
, vtep_ip
, rmac
, host_prefix
);
2544 * if the remote vtep is a ipv4 mapped ipv6 address convert it to ipv4
2545 * address. Rmac is programmed against the ipv4 vtep because we only
2546 * support ipv4 tunnels in the h/w right now
2548 memset(&ipv4_vtep
, 0, sizeof(ipv4_vtep
));
2549 ipv4_vtep
.ipa_type
= IPADDR_V4
;
2550 if (vtep_ip
->ipa_type
== IPADDR_V6
)
2551 ipv4_mapped_ipv6_to_ipv4(&vtep_ip
->ipaddr_v6
,
2552 &(ipv4_vtep
.ipaddr_v4
));
2554 memcpy(&(ipv4_vtep
.ipaddr_v4
), &vtep_ip
->ipaddr_v4
,
2555 sizeof(struct in_addr
));
2558 * add the rmac - remote rmac to be installed is against the ipv4
2561 zl3vni_remote_rmac_add(zl3vni
, rmac
, &ipv4_vtep
);
2564 /* handle evpn vrf route delete */
2565 void zebra_vxlan_evpn_vrf_route_del(vrf_id_t vrf_id
,
2566 struct ipaddr
*vtep_ip
,
2567 struct prefix
*host_prefix
)
2569 struct zebra_l3vni
*zl3vni
= NULL
;
2570 struct zebra_neigh
*nh
= NULL
;
2571 struct zebra_mac
*zrmac
= NULL
;
2573 zl3vni
= zl3vni_from_vrf(vrf_id
);
2577 /* find the next hop entry and rmac entry */
2578 nh
= zl3vni_nh_lookup(zl3vni
, vtep_ip
);
2581 zrmac
= zl3vni_rmac_lookup(zl3vni
, &nh
->emac
);
2583 /* delete the next hop entry */
2584 zl3vni_remote_nh_del(zl3vni
, nh
, host_prefix
);
2586 /* Delete SVD next hop entry */
2587 svd_remote_nh_del(zl3vni
, vtep_ip
);
2589 /* delete the rmac entry */
2591 zl3vni_remote_rmac_del(zl3vni
, zrmac
, vtep_ip
);
2594 void zebra_vxlan_print_specific_rmac_l3vni(struct vty
*vty
, vni_t l3vni
,
2595 struct ethaddr
*rmac
, bool use_json
)
2597 struct zebra_l3vni
*zl3vni
= NULL
;
2598 struct zebra_mac
*zrmac
= NULL
;
2599 json_object
*json
= NULL
;
2601 if (!is_evpn_enabled()) {
2603 vty_out(vty
, "{}\n");
2608 json
= json_object_new_object();
2610 zl3vni
= zl3vni_lookup(l3vni
);
2613 vty_out(vty
, "{}\n");
2615 vty_out(vty
, "%% L3-VNI %u doesn't exist\n", l3vni
);
2619 zrmac
= zl3vni_rmac_lookup(zl3vni
, rmac
);
2622 vty_out(vty
, "{}\n");
2625 "%% Requested RMAC doesn't exist in L3-VNI %u\n",
2630 zl3vni_print_rmac(zrmac
, vty
, json
);
2633 vty_json(vty
, json
);
2636 void zebra_vxlan_print_rmacs_l3vni(struct vty
*vty
, vni_t l3vni
, bool use_json
)
2638 struct zebra_l3vni
*zl3vni
;
2640 struct rmac_walk_ctx wctx
;
2641 json_object
*json
= NULL
;
2643 if (!is_evpn_enabled())
2646 zl3vni
= zl3vni_lookup(l3vni
);
2649 vty_out(vty
, "{}\n");
2651 vty_out(vty
, "%% L3-VNI %u does not exist\n", l3vni
);
2654 num_rmacs
= hashcount(zl3vni
->rmac_table
);
2659 json
= json_object_new_object();
2661 memset(&wctx
, 0, sizeof(wctx
));
2665 vty_out(vty
, "Number of Remote RMACs known for this VNI: %u\n",
2667 vty_out(vty
, "%-17s %-21s\n", "MAC", "Remote VTEP");
2669 json_object_int_add(json
, "numRmacs", num_rmacs
);
2671 hash_iterate(zl3vni
->rmac_table
, zl3vni_print_rmac_hash
, &wctx
);
2674 vty_json(vty
, json
);
2677 void zebra_vxlan_print_rmacs_all_l3vni(struct vty
*vty
, bool use_json
)
2679 json_object
*json
= NULL
;
2682 if (!is_evpn_enabled()) {
2684 vty_out(vty
, "{}\n");
2689 json
= json_object_new_object();
2693 hash_iterate(zrouter
.l3vni_table
,
2694 (void (*)(struct hash_bucket
*,
2695 void *))zl3vni_print_rmac_hash_all_vni
,
2699 vty_json(vty
, json
);
2702 void zebra_vxlan_print_specific_nh_l3vni(struct vty
*vty
, vni_t l3vni
,
2703 struct ipaddr
*ip
, bool use_json
)
2705 struct zebra_l3vni
*zl3vni
= NULL
;
2706 struct zebra_neigh
*n
= NULL
;
2707 json_object
*json
= NULL
;
2709 if (!is_evpn_enabled()) {
2711 vty_out(vty
, "{}\n");
2716 json
= json_object_new_object();
2718 /* If vni=0 passed, assume svd lookup */
2720 n
= svd_nh_lookup(ip
);
2722 zl3vni
= zl3vni_lookup(l3vni
);
2725 vty_out(vty
, "{}\n");
2727 vty_out(vty
, "%% L3-VNI %u does not exist\n",
2732 n
= zl3vni_nh_lookup(zl3vni
, ip
);
2737 vty_out(vty
, "{}\n");
2740 "%% Requested next-hop not present for L3-VNI %u\n",
2745 zl3vni_print_nh(n
, vty
, json
);
2748 vty_json(vty
, json
);
2751 static void l3vni_print_nh_table(struct hash
*nh_table
, struct vty
*vty
,
2755 struct nh_walk_ctx wctx
;
2756 json_object
*json
= NULL
;
2758 num_nh
= hashcount(nh_table
);
2763 json
= json_object_new_object();
2768 vty_out(vty
, "Number of NH Neighbors known for this VNI: %u\n",
2770 vty_out(vty
, "%-15s %-17s\n", "IP", "RMAC");
2772 json_object_int_add(json
, "numNextHops", num_nh
);
2774 hash_iterate(nh_table
, zl3vni_print_nh_hash
, &wctx
);
2777 vty_json(vty
, json
);
2780 void zebra_vxlan_print_nh_l3vni(struct vty
*vty
, vni_t l3vni
, bool use_json
)
2782 struct zebra_l3vni
*zl3vni
= NULL
;
2784 if (!is_evpn_enabled()) {
2786 vty_out(vty
, "{}\n");
2790 zl3vni
= zl3vni_lookup(l3vni
);
2793 vty_out(vty
, "{}\n");
2795 vty_out(vty
, "%% L3-VNI %u does not exist\n", l3vni
);
2799 l3vni_print_nh_table(zl3vni
->nh_table
, vty
, use_json
);
2802 void zebra_vxlan_print_nh_svd(struct vty
*vty
, bool use_json
)
2804 if (!is_evpn_enabled()) {
2806 vty_out(vty
, "{}\n");
2810 l3vni_print_nh_table(svd_nh_table
, vty
, use_json
);
2813 void zebra_vxlan_print_nh_all_l3vni(struct vty
*vty
, bool use_json
)
2815 json_object
*json
= NULL
;
2818 if (!is_evpn_enabled()) {
2820 vty_out(vty
, "{}\n");
2825 json
= json_object_new_object();
2829 hash_iterate(zrouter
.l3vni_table
,
2830 (void (*)(struct hash_bucket
*,
2831 void *))zl3vni_print_nh_hash_all_vni
,
2835 vty_json(vty
, json
);
2839 * Display L3 VNI information (VTY command handler).
2841 void zebra_vxlan_print_l3vni(struct vty
*vty
, vni_t vni
, bool use_json
)
2844 json_object
*json
= NULL
;
2845 struct zebra_l3vni
*zl3vni
= NULL
;
2847 if (!is_evpn_enabled()) {
2849 vty_out(vty
, "{}\n");
2853 zl3vni
= zl3vni_lookup(vni
);
2856 vty_out(vty
, "{}\n");
2858 vty_out(vty
, "%% VNI %u does not exist\n", vni
);
2863 json
= json_object_new_object();
2867 zl3vni_print(zl3vni
, (void *)args
);
2870 vty_json(vty
, json
);
2873 void zebra_vxlan_print_vrf_vni(struct vty
*vty
, struct zebra_vrf
*zvrf
,
2874 json_object
*json_vrfs
)
2876 char buf
[ETHER_ADDR_STRLEN
];
2877 struct zebra_l3vni
*zl3vni
= NULL
;
2879 zl3vni
= zl3vni_lookup(zvrf
->l3vni
);
2884 vty_out(vty
, "%-37s %-10u %-20s %-20s %-5s %-18s\n",
2885 zvrf_name(zvrf
), zl3vni
->vni
,
2886 zl3vni_vxlan_if_name(zl3vni
),
2887 zl3vni_svi_if_name(zl3vni
), zl3vni_state2str(zl3vni
),
2888 zl3vni_rmac2str(zl3vni
, buf
, sizeof(buf
)));
2890 json_object
*json_vrf
= NULL
;
2892 json_vrf
= json_object_new_object();
2893 json_object_string_add(json_vrf
, "vrf", zvrf_name(zvrf
));
2894 json_object_int_add(json_vrf
, "vni", zl3vni
->vni
);
2895 json_object_string_add(json_vrf
, "vxlanIntf",
2896 zl3vni_vxlan_if_name(zl3vni
));
2897 json_object_string_add(json_vrf
, "sviIntf",
2898 zl3vni_svi_if_name(zl3vni
));
2899 json_object_string_add(json_vrf
, "state",
2900 zl3vni_state2str(zl3vni
));
2901 json_object_string_add(
2902 json_vrf
, "routerMac",
2903 zl3vni_rmac2str(zl3vni
, buf
, sizeof(buf
)));
2904 json_object_array_add(json_vrfs
, json_vrf
);
2909 * Display Neighbors for a VNI (VTY command handler).
2911 void zebra_vxlan_print_neigh_vni(struct vty
*vty
, struct zebra_vrf
*zvrf
,
2912 vni_t vni
, bool use_json
)
2914 struct zebra_evpn
*zevpn
;
2916 struct neigh_walk_ctx wctx
;
2917 json_object
*json
= NULL
;
2919 if (!is_evpn_enabled())
2921 zevpn
= zebra_evpn_lookup(vni
);
2924 vty_out(vty
, "{}\n");
2926 vty_out(vty
, "%% VNI %u does not exist\n", vni
);
2929 num_neigh
= hashcount(zevpn
->neigh_table
);
2934 json
= json_object_new_object();
2936 /* Since we have IPv6 addresses to deal with which can vary widely in
2937 * size, we try to be a bit more elegant in display by first computing
2938 * the maximum width.
2940 memset(&wctx
, 0, sizeof(wctx
));
2943 wctx
.addr_width
= 15;
2945 hash_iterate(zevpn
->neigh_table
, zebra_evpn_find_neigh_addr_width
,
2950 "Number of ARPs (local and remote) known for this VNI: %u\n",
2952 zebra_evpn_print_neigh_hdr(vty
, &wctx
);
2954 json_object_int_add(json
, "numArpNd", num_neigh
);
2956 hash_iterate(zevpn
->neigh_table
, zebra_evpn_print_neigh_hash
, &wctx
);
2958 vty_json(vty
, json
);
2962 * Display neighbors across all VNIs (VTY command handler).
2964 void zebra_vxlan_print_neigh_all_vni(struct vty
*vty
, struct zebra_vrf
*zvrf
,
2965 bool print_dup
, bool use_json
)
2967 json_object
*json
= NULL
;
2970 if (!is_evpn_enabled())
2974 json
= json_object_new_object();
2978 args
[2] = (void *)(ptrdiff_t)print_dup
;
2980 hash_iterate(zvrf
->evpn_table
,
2981 (void (*)(struct hash_bucket
*,
2982 void *))zevpn_print_neigh_hash_all_evpn
,
2985 vty_json(vty
, json
);
2989 * Display neighbors across all VNIs in detail(VTY command handler).
2991 void zebra_vxlan_print_neigh_all_vni_detail(struct vty
*vty
,
2992 struct zebra_vrf
*zvrf
,
2993 bool print_dup
, bool use_json
)
2995 json_object
*json
= NULL
;
2998 if (!is_evpn_enabled())
3002 json
= json_object_new_object();
3006 args
[2] = (void *)(ptrdiff_t)print_dup
;
3008 hash_iterate(zvrf
->evpn_table
,
3009 (void (*)(struct hash_bucket
*,
3010 void *))zevpn_print_neigh_hash_all_evpn_detail
,
3013 vty_json(vty
, json
);
3017 * Display specific neighbor for a VNI, if present (VTY command handler).
3019 void zebra_vxlan_print_specific_neigh_vni(struct vty
*vty
,
3020 struct zebra_vrf
*zvrf
, vni_t vni
,
3021 struct ipaddr
*ip
, bool use_json
)
3023 struct zebra_evpn
*zevpn
;
3024 struct zebra_neigh
*n
;
3025 json_object
*json
= NULL
;
3027 if (!is_evpn_enabled())
3029 zevpn
= zebra_evpn_lookup(vni
);
3032 vty_out(vty
, "{}\n");
3034 vty_out(vty
, "%% VNI %u does not exist\n", vni
);
3037 n
= zebra_evpn_neigh_lookup(zevpn
, ip
);
3041 "%% Requested neighbor does not exist in VNI %u\n",
3046 json
= json_object_new_object();
3048 zebra_evpn_print_neigh(n
, vty
, json
);
3051 vty_json(vty
, json
);
3055 * Display neighbors for a VNI from specific VTEP (VTY command handler).
3056 * By definition, these are remote neighbors.
3058 void zebra_vxlan_print_neigh_vni_vtep(struct vty
*vty
, struct zebra_vrf
*zvrf
,
3059 vni_t vni
, struct in_addr vtep_ip
,
3062 struct zebra_evpn
*zevpn
;
3064 struct neigh_walk_ctx wctx
;
3065 json_object
*json
= NULL
;
3067 if (!is_evpn_enabled())
3069 zevpn
= zebra_evpn_lookup(vni
);
3072 vty_out(vty
, "{}\n");
3074 vty_out(vty
, "%% VNI %u does not exist\n", vni
);
3077 num_neigh
= hashcount(zevpn
->neigh_table
);
3082 json
= json_object_new_object();
3084 memset(&wctx
, 0, sizeof(wctx
));
3087 wctx
.addr_width
= 15;
3088 wctx
.flags
= SHOW_REMOTE_NEIGH_FROM_VTEP
;
3089 wctx
.r_vtep_ip
= vtep_ip
;
3091 hash_iterate(zevpn
->neigh_table
, zebra_evpn_find_neigh_addr_width
,
3093 hash_iterate(zevpn
->neigh_table
, zebra_evpn_print_neigh_hash
, &wctx
);
3096 vty_json(vty
, json
);
3100 * Display Duplicate detected Neighbors for a VNI
3101 * (VTY command handler).
3103 void zebra_vxlan_print_neigh_vni_dad(struct vty
*vty
,
3104 struct zebra_vrf
*zvrf
,
3108 struct zebra_evpn
*zevpn
;
3110 struct neigh_walk_ctx wctx
;
3111 json_object
*json
= NULL
;
3113 if (!is_evpn_enabled())
3116 zevpn
= zebra_evpn_lookup(vni
);
3118 vty_out(vty
, "%% VNI %u does not exist\n", vni
);
3122 num_neigh
= hashcount(zevpn
->neigh_table
);
3126 num_neigh
= num_dup_detected_neighs(zevpn
);
3131 json
= json_object_new_object();
3133 /* Since we have IPv6 addresses to deal with which can vary widely in
3134 * size, we try to be a bit more elegant in display by first computing
3135 * the maximum width.
3137 memset(&wctx
, 0, sizeof(wctx
));
3140 wctx
.addr_width
= 15;
3142 hash_iterate(zevpn
->neigh_table
, zebra_evpn_find_neigh_addr_width
,
3147 "Number of ARPs (local and remote) known for this VNI: %u\n",
3149 vty_out(vty
, "%*s %-6s %-8s %-17s %-30s\n",
3150 -wctx
.addr_width
, "IP", "Type",
3151 "State", "MAC", "Remote ES/VTEP");
3153 json_object_int_add(json
, "numArpNd", num_neigh
);
3155 hash_iterate(zevpn
->neigh_table
, zebra_evpn_print_dad_neigh_hash
,
3159 vty_json(vty
, json
);
3163 * Display MACs for a VNI (VTY command handler).
3165 void zebra_vxlan_print_macs_vni(struct vty
*vty
, struct zebra_vrf
*zvrf
,
3166 vni_t vni
, bool use_json
, bool detail
)
3168 struct zebra_evpn
*zevpn
;
3170 struct mac_walk_ctx wctx
;
3171 json_object
*json
= NULL
;
3172 json_object
*json_mac
= NULL
;
3174 if (!is_evpn_enabled())
3176 zevpn
= zebra_evpn_lookup(vni
);
3179 vty_out(vty
, "{}\n");
3181 vty_out(vty
, "%% VNI %u does not exist\n", vni
);
3184 num_macs
= num_valid_macs(zevpn
);
3189 json
= json_object_new_object();
3190 json_mac
= json_object_new_object();
3193 memset(&wctx
, 0, sizeof(wctx
));
3196 wctx
.json
= json_mac
;
3200 vty_out(vty
, "\nVNI %u #MACs (local and remote) %u\n\n",
3201 zevpn
->vni
, num_macs
);
3204 "Number of MACs (local and remote) known for this VNI: %u\n",
3207 "Flags: N=sync-neighs, I=local-inactive, P=peer-active, X=peer-proxy\n");
3208 vty_out(vty
, "%-17s %-6s %-5s %-30s %-5s %s\n", "MAC",
3209 "Type", "Flags", "Intf/Remote ES/VTEP", "VLAN",
3213 json_object_int_add(json
, "numMacs", num_macs
);
3216 hash_iterate(zevpn
->mac_table
, zebra_evpn_print_mac_hash_detail
,
3219 hash_iterate(zevpn
->mac_table
, zebra_evpn_print_mac_hash
,
3223 json_object_object_add(json
, "macs", json_mac
);
3224 vty_json(vty
, json
);
3229 * Display MACs for all VNIs (VTY command handler).
3231 void zebra_vxlan_print_macs_all_vni(struct vty
*vty
, struct zebra_vrf
*zvrf
,
3232 bool print_dup
, bool use_json
)
3234 struct mac_walk_ctx wctx
;
3235 json_object
*json
= NULL
;
3237 if (!is_evpn_enabled()) {
3239 vty_out(vty
, "{}\n");
3243 json
= json_object_new_object();
3245 memset(&wctx
, 0, sizeof(wctx
));
3248 wctx
.print_dup
= print_dup
;
3249 hash_iterate(zvrf
->evpn_table
, zevpn_print_mac_hash_all_evpn
, &wctx
);
3252 vty_json(vty
, json
);
3256 * Display MACs in detail for all VNIs (VTY command handler).
3258 void zebra_vxlan_print_macs_all_vni_detail(struct vty
*vty
,
3259 struct zebra_vrf
*zvrf
,
3260 bool print_dup
, bool use_json
)
3262 struct mac_walk_ctx wctx
;
3263 json_object
*json
= NULL
;
3265 if (!is_evpn_enabled()) {
3267 vty_out(vty
, "{}\n");
3271 json
= json_object_new_object();
3273 memset(&wctx
, 0, sizeof(wctx
));
3276 wctx
.print_dup
= print_dup
;
3277 hash_iterate(zvrf
->evpn_table
, zevpn_print_mac_hash_all_evpn_detail
,
3281 vty_json(vty
, json
);
3285 * Display MACs for all VNIs (VTY command handler).
3287 void zebra_vxlan_print_macs_all_vni_vtep(struct vty
*vty
,
3288 struct zebra_vrf
*zvrf
,
3289 struct in_addr vtep_ip
, bool use_json
)
3291 struct mac_walk_ctx wctx
;
3292 json_object
*json
= NULL
;
3294 if (!is_evpn_enabled())
3298 json
= json_object_new_object();
3300 memset(&wctx
, 0, sizeof(wctx
));
3302 wctx
.flags
= SHOW_REMOTE_MAC_FROM_VTEP
;
3303 wctx
.r_vtep_ip
= vtep_ip
;
3305 hash_iterate(zvrf
->evpn_table
, zevpn_print_mac_hash_all_evpn
, &wctx
);
3308 vty_json(vty
, json
);
3312 * Display specific MAC for a VNI, if present (VTY command handler).
3314 void zebra_vxlan_print_specific_mac_vni(struct vty
*vty
, struct zebra_vrf
*zvrf
,
3315 vni_t vni
, struct ethaddr
*macaddr
,
3318 struct zebra_evpn
*zevpn
;
3319 struct zebra_mac
*mac
;
3320 json_object
*json
= NULL
;
3322 if (!is_evpn_enabled())
3325 zevpn
= zebra_evpn_lookup(vni
);
3328 vty_out(vty
, "{}\n");
3330 vty_out(vty
, "%% VNI %u does not exist\n", vni
);
3333 mac
= zebra_evpn_mac_lookup(zevpn
, macaddr
);
3336 vty_out(vty
, "{}\n");
3339 "%% Requested MAC does not exist in VNI %u\n",
3345 json
= json_object_new_object();
3347 zebra_evpn_print_mac(mac
, vty
, json
);
3349 vty_json(vty
, json
);
3352 /* Print Duplicate MACs per VNI */
3353 void zebra_vxlan_print_macs_vni_dad(struct vty
*vty
,
3354 struct zebra_vrf
*zvrf
,
3355 vni_t vni
, bool use_json
)
3357 struct zebra_evpn
*zevpn
;
3358 struct mac_walk_ctx wctx
;
3360 json_object
*json
= NULL
;
3361 json_object
*json_mac
= NULL
;
3363 if (!is_evpn_enabled())
3366 zevpn
= zebra_evpn_lookup(vni
);
3368 vty_out(vty
, "%% VNI %u does not exist\n", vni
);
3372 num_macs
= num_valid_macs(zevpn
);
3376 num_macs
= num_dup_detected_macs(zevpn
);
3381 json
= json_object_new_object();
3382 json_mac
= json_object_new_object();
3385 memset(&wctx
, 0, sizeof(wctx
));
3388 wctx
.json
= json_mac
;
3392 "Number of MACs (local and remote) known for this VNI: %u\n",
3394 vty_out(vty
, "%-17s %-6s %-5s %-30s %-5s\n", "MAC", "Type",
3395 "Flags", "Intf/Remote ES/VTEP", "VLAN");
3397 json_object_int_add(json
, "numMacs", num_macs
);
3399 hash_iterate(zevpn
->mac_table
, zebra_evpn_print_dad_mac_hash
, &wctx
);
3402 json_object_object_add(json
, "macs", json_mac
);
3403 vty_json(vty
, json
);
3408 int zebra_vxlan_clear_dup_detect_vni_mac(struct zebra_vrf
*zvrf
, vni_t vni
,
3409 struct ethaddr
*macaddr
, char *errmsg
,
3412 struct zebra_evpn
*zevpn
;
3413 struct zebra_mac
*mac
;
3414 struct listnode
*node
= NULL
;
3415 struct zebra_neigh
*nbr
= NULL
;
3417 if (!is_evpn_enabled())
3420 zevpn
= zebra_evpn_lookup(vni
);
3422 snprintfrr(errmsg
, errmsg_len
, "VNI %u does not exist", vni
);
3426 mac
= zebra_evpn_mac_lookup(zevpn
, macaddr
);
3428 snprintf(errmsg
, errmsg_len
,
3429 "Requested MAC does not exist in VNI %u\n", vni
);
3433 if (!CHECK_FLAG(mac
->flags
, ZEBRA_MAC_DUPLICATE
)) {
3434 snprintfrr(errmsg
, errmsg_len
,
3435 "Requested MAC is not duplicate detected\n");
3439 /* Remove all IPs as duplicate associcated with this MAC */
3440 for (ALL_LIST_ELEMENTS_RO(mac
->neigh_list
, node
, nbr
)) {
3441 /* For local neigh mark inactive so MACIP update is generated
3442 * to BGP. This is a scenario where MAC update received
3443 * and detected as duplicate which marked neigh as duplicate.
3444 * Later local neigh update did not get a chance to relay
3445 * to BGP. Similarly remote macip update, neigh needs to be
3446 * installed locally.
3448 if (zvrf
->dad_freeze
&&
3449 CHECK_FLAG(nbr
->flags
, ZEBRA_NEIGH_DUPLICATE
)) {
3450 if (CHECK_FLAG(nbr
->flags
, ZEBRA_NEIGH_LOCAL
))
3451 ZEBRA_NEIGH_SET_INACTIVE(nbr
);
3452 else if (CHECK_FLAG(nbr
->flags
, ZEBRA_NEIGH_REMOTE
))
3453 zebra_evpn_rem_neigh_install(
3454 zevpn
, nbr
, false /*was_static*/);
3457 UNSET_FLAG(nbr
->flags
, ZEBRA_NEIGH_DUPLICATE
);
3459 nbr
->detect_start_time
.tv_sec
= 0;
3460 nbr
->dad_dup_detect_time
= 0;
3463 UNSET_FLAG(mac
->flags
, ZEBRA_MAC_DUPLICATE
);
3465 mac
->detect_start_time
.tv_sec
= 0;
3466 mac
->detect_start_time
.tv_usec
= 0;
3467 mac
->dad_dup_detect_time
= 0;
3468 THREAD_OFF(mac
->dad_mac_auto_recovery_timer
);
3470 /* warn-only action return */
3471 if (!zvrf
->dad_freeze
)
3474 /* Local: Notify Peer VTEPs, Remote: Install the entry */
3475 if (CHECK_FLAG(mac
->flags
, ZEBRA_MAC_LOCAL
)) {
3477 if (zebra_evpn_mac_send_add_to_client(zevpn
->vni
, &mac
->macaddr
,
3478 mac
->flags
, mac
->loc_seq
,
3482 /* Process all neighbors associated with this MAC. */
3483 zebra_evpn_process_neigh_on_local_mac_change(zevpn
, mac
, 0,
3486 } else if (CHECK_FLAG(mac
->flags
, ZEBRA_MAC_REMOTE
)) {
3487 zebra_evpn_process_neigh_on_remote_mac_add(zevpn
, mac
);
3489 /* Install the entry. */
3490 zebra_evpn_rem_mac_install(zevpn
, mac
, false /* was_static */);
3496 int zebra_vxlan_clear_dup_detect_vni_ip(struct zebra_vrf
*zvrf
, vni_t vni
,
3497 struct ipaddr
*ip
, char *errmsg
,
3500 struct zebra_evpn
*zevpn
;
3501 struct zebra_neigh
*nbr
;
3502 struct zebra_mac
*mac
;
3503 char buf
[INET6_ADDRSTRLEN
];
3504 char buf2
[ETHER_ADDR_STRLEN
];
3506 if (!is_evpn_enabled())
3509 zevpn
= zebra_evpn_lookup(vni
);
3511 snprintfrr(errmsg
, errmsg_len
, "VNI %u does not exist\n", vni
);
3515 nbr
= zebra_evpn_neigh_lookup(zevpn
, ip
);
3517 snprintfrr(errmsg
, errmsg_len
,
3518 "Requested host IP does not exist in VNI %u\n", vni
);
3522 ipaddr2str(&nbr
->ip
, buf
, sizeof(buf
));
3524 if (!CHECK_FLAG(nbr
->flags
, ZEBRA_NEIGH_DUPLICATE
)) {
3525 snprintfrr(errmsg
, errmsg_len
,
3526 "Requested host IP %s is not duplicate detected\n",
3531 mac
= zebra_evpn_mac_lookup(zevpn
, &nbr
->emac
);
3533 if (CHECK_FLAG(mac
->flags
, ZEBRA_MAC_DUPLICATE
)) {
3536 "Requested IP's associated MAC %s is still in duplicate state\n",
3537 prefix_mac2str(&nbr
->emac
, buf2
, sizeof(buf2
)));
3541 if (IS_ZEBRA_DEBUG_VXLAN
)
3542 zlog_debug("%s: clear neigh %s in dup state, flags 0x%x seq %u",
3543 __func__
, buf
, nbr
->flags
, nbr
->loc_seq
);
3545 UNSET_FLAG(nbr
->flags
, ZEBRA_NEIGH_DUPLICATE
);
3547 nbr
->detect_start_time
.tv_sec
= 0;
3548 nbr
->detect_start_time
.tv_usec
= 0;
3549 nbr
->dad_dup_detect_time
= 0;
3550 THREAD_OFF(nbr
->dad_ip_auto_recovery_timer
);
3552 if (!!CHECK_FLAG(nbr
->flags
, ZEBRA_NEIGH_LOCAL
)) {
3553 zebra_evpn_neigh_send_add_to_client(zevpn
->vni
, ip
, &nbr
->emac
,
3554 nbr
->mac
, nbr
->flags
,
3556 } else if (!!CHECK_FLAG(nbr
->flags
, ZEBRA_NEIGH_REMOTE
)) {
3557 zebra_evpn_rem_neigh_install(zevpn
, nbr
, false /*was_static*/);
3563 static void zevpn_clear_dup_mac_hash(struct hash_bucket
*bucket
, void *ctxt
)
3565 struct mac_walk_ctx
*wctx
= ctxt
;
3566 struct zebra_mac
*mac
;
3567 struct zebra_evpn
*zevpn
;
3568 struct listnode
*node
= NULL
;
3569 struct zebra_neigh
*nbr
= NULL
;
3571 mac
= (struct zebra_mac
*)bucket
->data
;
3575 zevpn
= wctx
->zevpn
;
3577 if (!CHECK_FLAG(mac
->flags
, ZEBRA_MAC_DUPLICATE
))
3580 UNSET_FLAG(mac
->flags
, ZEBRA_MAC_DUPLICATE
);
3582 mac
->detect_start_time
.tv_sec
= 0;
3583 mac
->detect_start_time
.tv_usec
= 0;
3584 mac
->dad_dup_detect_time
= 0;
3585 THREAD_OFF(mac
->dad_mac_auto_recovery_timer
);
3587 /* Remove all IPs as duplicate associcated with this MAC */
3588 for (ALL_LIST_ELEMENTS_RO(mac
->neigh_list
, node
, nbr
)) {
3589 if (CHECK_FLAG(nbr
->flags
, ZEBRA_NEIGH_LOCAL
)
3591 ZEBRA_NEIGH_SET_INACTIVE(nbr
);
3593 UNSET_FLAG(nbr
->flags
, ZEBRA_NEIGH_DUPLICATE
);
3595 nbr
->detect_start_time
.tv_sec
= 0;
3596 nbr
->dad_dup_detect_time
= 0;
3599 /* Local: Notify Peer VTEPs, Remote: Install the entry */
3600 if (CHECK_FLAG(mac
->flags
, ZEBRA_MAC_LOCAL
)) {
3602 if (zebra_evpn_mac_send_add_to_client(zevpn
->vni
, &mac
->macaddr
,
3603 mac
->flags
, mac
->loc_seq
,
3607 /* Process all neighbors associated with this MAC. */
3608 zebra_evpn_process_neigh_on_local_mac_change(zevpn
, mac
, 0,
3611 } else if (CHECK_FLAG(mac
->flags
, ZEBRA_MAC_REMOTE
)) {
3612 zebra_evpn_process_neigh_on_remote_mac_add(zevpn
, mac
);
3614 /* Install the entry. */
3615 zebra_evpn_rem_mac_install(zevpn
, mac
, false /* was_static */);
3619 static void zevpn_clear_dup_detect_hash_vni_all(struct hash_bucket
*bucket
,
3622 struct zebra_evpn
*zevpn
;
3623 struct zebra_vrf
*zvrf
;
3624 struct mac_walk_ctx m_wctx
;
3625 struct neigh_walk_ctx n_wctx
;
3627 zevpn
= (struct zebra_evpn
*)bucket
->data
;
3631 zvrf
= (struct zebra_vrf
*)args
[0];
3633 if (hashcount(zevpn
->neigh_table
)) {
3634 memset(&n_wctx
, 0, sizeof(n_wctx
));
3635 n_wctx
.zevpn
= zevpn
;
3637 hash_iterate(zevpn
->neigh_table
,
3638 zebra_evpn_clear_dup_neigh_hash
, &n_wctx
);
3641 if (num_valid_macs(zevpn
)) {
3642 memset(&m_wctx
, 0, sizeof(m_wctx
));
3643 m_wctx
.zevpn
= zevpn
;
3645 hash_iterate(zevpn
->mac_table
, zevpn_clear_dup_mac_hash
, &m_wctx
);
3650 int zebra_vxlan_clear_dup_detect_vni_all(struct zebra_vrf
*zvrf
)
3654 if (!is_evpn_enabled())
3659 hash_iterate(zvrf
->evpn_table
,
3660 (void (*)(struct hash_bucket
*, void *))
3661 zevpn_clear_dup_detect_hash_vni_all
, args
);
3666 int zebra_vxlan_clear_dup_detect_vni(struct zebra_vrf
*zvrf
, vni_t vni
)
3668 struct zebra_evpn
*zevpn
;
3669 struct mac_walk_ctx m_wctx
;
3670 struct neigh_walk_ctx n_wctx
;
3672 if (!is_evpn_enabled())
3675 zevpn
= zebra_evpn_lookup(vni
);
3677 zlog_warn("VNI %u does not exist", vni
);
3681 if (hashcount(zevpn
->neigh_table
)) {
3682 memset(&n_wctx
, 0, sizeof(n_wctx
));
3683 n_wctx
.zevpn
= zevpn
;
3685 hash_iterate(zevpn
->neigh_table
,
3686 zebra_evpn_clear_dup_neigh_hash
, &n_wctx
);
3689 if (num_valid_macs(zevpn
)) {
3690 memset(&m_wctx
, 0, sizeof(m_wctx
));
3691 m_wctx
.zevpn
= zevpn
;
3693 hash_iterate(zevpn
->mac_table
, zevpn_clear_dup_mac_hash
, &m_wctx
);
3700 * Display MACs for a VNI from specific VTEP (VTY command handler).
3702 void zebra_vxlan_print_macs_vni_vtep(struct vty
*vty
, struct zebra_vrf
*zvrf
,
3703 vni_t vni
, struct in_addr vtep_ip
,
3706 struct zebra_evpn
*zevpn
;
3708 struct mac_walk_ctx wctx
;
3709 json_object
*json
= NULL
;
3710 json_object
*json_mac
= NULL
;
3712 if (!is_evpn_enabled())
3714 zevpn
= zebra_evpn_lookup(vni
);
3717 vty_out(vty
, "{}\n");
3719 vty_out(vty
, "%% VNI %u does not exist\n", vni
);
3722 num_macs
= num_valid_macs(zevpn
);
3727 json
= json_object_new_object();
3728 json_mac
= json_object_new_object();
3731 memset(&wctx
, 0, sizeof(wctx
));
3734 wctx
.flags
= SHOW_REMOTE_MAC_FROM_VTEP
;
3735 wctx
.r_vtep_ip
= vtep_ip
;
3736 wctx
.json
= json_mac
;
3737 hash_iterate(zevpn
->mac_table
, zebra_evpn_print_mac_hash
, &wctx
);
3740 json_object_int_add(json
, "numMacs", wctx
.count
);
3742 json_object_object_add(json
, "macs", json_mac
);
3743 vty_json(vty
, json
);
3749 * Display VNI information (VTY command handler).
3751 * use_json flag indicates that output should be in JSON format.
3752 * json_array is non NULL when JSON output needs to be aggregated (by the
3753 * caller) and then printed, otherwise, JSON evpn vni info is printed
3756 void zebra_vxlan_print_vni(struct vty
*vty
, struct zebra_vrf
*zvrf
, vni_t vni
,
3757 bool use_json
, json_object
*json_array
)
3759 json_object
*json
= NULL
;
3761 struct zebra_l3vni
*zl3vni
= NULL
;
3762 struct zebra_evpn
*zevpn
= NULL
;
3764 if (!is_evpn_enabled())
3768 json
= json_object_new_object();
3773 zl3vni
= zl3vni_lookup(vni
);
3775 zl3vni_print(zl3vni
, (void *)args
);
3777 zevpn
= zebra_evpn_lookup(vni
);
3779 zebra_evpn_print(zevpn
, (void *)args
);
3781 vty_out(vty
, "%% VNI %u does not exist\n", vni
);
3786 * Each "json" object contains info about 1 VNI.
3787 * When "json_array" is non-null, we aggreggate the json output
3788 * into json_array and print it as a JSON array.
3791 json_object_array_add(json_array
, json
);
3793 vty_json(vty
, json
);
3797 /* Display all global details for EVPN */
3798 void zebra_vxlan_print_evpn(struct vty
*vty
, bool uj
)
3803 json_object
*json
= NULL
;
3804 struct zebra_vrf
*zvrf
= NULL
;
3806 if (!is_evpn_enabled())
3809 zvrf
= zebra_vrf_get_evpn();
3811 num_l3vnis
= hashcount(zrouter
.l3vni_table
);
3812 num_l2vnis
= hashcount(zvrf
->evpn_table
);
3813 num_vnis
= num_l2vnis
+ num_l3vnis
;
3816 json
= json_object_new_object();
3817 json_object_string_add(json
, "advertiseGatewayMacip",
3818 zvrf
->advertise_gw_macip
? "Yes" : "No");
3819 json_object_string_add(json
, "advertiseSviMacip",
3820 zvrf
->advertise_svi_macip
? "Yes"
3822 json_object_string_add(json
, "advertiseSviMac",
3823 zebra_evpn_mh_do_adv_svi_mac() ? "Yes"
3825 json_object_int_add(json
, "numVnis", num_vnis
);
3826 json_object_int_add(json
, "numL2Vnis", num_l2vnis
);
3827 json_object_int_add(json
, "numL3Vnis", num_l3vnis
);
3828 if (zebra_evpn_do_dup_addr_detect(zvrf
))
3829 json_object_boolean_true_add(json
,
3830 "isDuplicateAddrDetection");
3832 json_object_boolean_false_add(json
,
3833 "isDuplicateAddrDetection");
3834 json_object_int_add(json
, "maxMoves", zvrf
->dad_max_moves
);
3835 json_object_int_add(json
, "detectionTime", zvrf
->dad_time
);
3836 json_object_int_add(json
, "detectionFreezeTime",
3837 zvrf
->dad_freeze_time
);
3838 zebra_evpn_mh_json(json
);
3840 vty_out(vty
, "L2 VNIs: %u\n", num_l2vnis
);
3841 vty_out(vty
, "L3 VNIs: %u\n", num_l3vnis
);
3842 vty_out(vty
, "Advertise gateway mac-ip: %s\n",
3843 zvrf
->advertise_gw_macip
? "Yes" : "No");
3844 vty_out(vty
, "Advertise svi mac-ip: %s\n",
3845 zvrf
->advertise_svi_macip
? "Yes" : "No");
3846 vty_out(vty
, "Advertise svi mac: %s\n",
3847 zebra_evpn_mh_do_adv_svi_mac() ? "Yes" : "No");
3848 vty_out(vty
, "Duplicate address detection: %s\n",
3849 zebra_evpn_do_dup_addr_detect(zvrf
) ? "Enable"
3851 vty_out(vty
, " Detection max-moves %u, time %d\n",
3852 zvrf
->dad_max_moves
, zvrf
->dad_time
);
3853 if (zvrf
->dad_freeze
) {
3854 if (zvrf
->dad_freeze_time
)
3855 vty_out(vty
, " Detection freeze %u\n",
3856 zvrf
->dad_freeze_time
);
3858 vty_out(vty
, " Detection freeze %s\n",
3861 zebra_evpn_mh_print(vty
);
3865 vty_json(vty
, json
);
3869 * Display VNI hash table (VTY command handler).
3871 void zebra_vxlan_print_vnis(struct vty
*vty
, struct zebra_vrf
*zvrf
,
3874 json_object
*json
= NULL
;
3877 if (!is_evpn_enabled())
3881 json
= json_object_new_object();
3883 vty_out(vty
, "%-10s %-4s %-21s %-8s %-8s %-15s %-37s\n", "VNI",
3884 "Type", "VxLAN IF", "# MACs", "# ARPs",
3885 "# Remote VTEPs", "Tenant VRF");
3890 /* Display all L2-VNIs */
3893 (void (*)(struct hash_bucket
*, void *))zebra_evpn_print_hash
,
3896 /* Display all L3-VNIs */
3897 hash_iterate(zrouter
.l3vni_table
,
3898 (void (*)(struct hash_bucket
*, void *))zl3vni_print_hash
,
3902 vty_json(vty
, json
);
3905 void zebra_vxlan_dup_addr_detection(ZAPI_HANDLER_ARGS
)
3909 uint32_t max_moves
= 0;
3910 uint32_t freeze_time
= 0;
3911 bool dup_addr_detect
= false;
3912 bool freeze
= false;
3913 bool old_addr_detect
;
3916 STREAM_GETL(s
, dup_addr_detect
);
3917 STREAM_GETL(s
, time
);
3918 STREAM_GETL(s
, max_moves
);
3919 STREAM_GETL(s
, freeze
);
3920 STREAM_GETL(s
, freeze_time
);
3922 old_addr_detect
= zebra_evpn_do_dup_addr_detect(zvrf
);
3923 zvrf
->dup_addr_detect
= dup_addr_detect
;
3924 dup_addr_detect
= zebra_evpn_do_dup_addr_detect(zvrf
);
3926 /* DAD previous state was enabled, and new state is disable,
3927 * clear all duplicate detected addresses.
3929 if (old_addr_detect
&& !dup_addr_detect
)
3930 zebra_vxlan_clear_dup_detect_vni_all(zvrf
);
3932 zvrf
->dad_time
= time
;
3933 zvrf
->dad_max_moves
= max_moves
;
3934 zvrf
->dad_freeze
= freeze
;
3935 zvrf
->dad_freeze_time
= freeze_time
;
3937 if (IS_ZEBRA_DEBUG_VXLAN
)
3939 "VRF %s duplicate detect %s max_moves %u timeout %u freeze %s freeze_time %u",
3940 vrf_id_to_name(zvrf
->vrf
->vrf_id
),
3941 dup_addr_detect
? "enable" : "disable",
3942 zvrf
->dad_max_moves
, zvrf
->dad_time
,
3943 zvrf
->dad_freeze
? "enable" : "disable",
3944 zvrf
->dad_freeze_time
);
3951 * Display VNI hash table in detail(VTY command handler).
3953 void zebra_vxlan_print_vnis_detail(struct vty
*vty
, struct zebra_vrf
*zvrf
,
3956 json_object
*json_array
= NULL
;
3957 struct zebra_ns
*zns
= NULL
;
3958 struct zebra_evpn_show zes
;
3960 if (!is_evpn_enabled())
3963 zns
= zebra_ns_lookup(NS_DEFAULT
);
3968 json_array
= json_object_new_array();
3971 zes
.json
= json_array
;
3973 zes
.use_json
= use_json
;
3975 /* Display all L2-VNIs */
3976 hash_iterate(zvrf
->evpn_table
,
3977 (void (*)(struct hash_bucket
*,
3978 void *))zebra_evpn_print_hash_detail
,
3981 /* Display all L3-VNIs */
3982 hash_iterate(zrouter
.l3vni_table
,
3983 (void (*)(struct hash_bucket
*,
3984 void *))zl3vni_print_hash_detail
,
3988 vty_json(vty
, json_array
);
3992 * Handle neighbor delete notification from the kernel (on a VLAN device
3993 * / L3 interface). This may result in either the neighbor getting deleted
3994 * from our database or being re-added to the kernel (if it is a valid
3997 int zebra_vxlan_handle_kernel_neigh_del(struct interface
*ifp
,
3998 struct interface
*link_if
,
4001 struct zebra_evpn
*zevpn
= NULL
;
4002 struct zebra_l3vni
*zl3vni
= NULL
;
4004 /* check if this is a remote neigh entry corresponding to remote
4007 zl3vni
= zl3vni_from_svi(ifp
, link_if
);
4009 return zl3vni_local_nh_del(zl3vni
, ip
);
4011 /* We are only interested in neighbors on an SVI that resides on top
4012 * of a VxLAN bridge.
4014 zevpn
= zebra_evpn_from_svi(ifp
, link_if
);
4016 if (IS_ZEBRA_DEBUG_VXLAN
)
4018 "%s: Del neighbor %pIA EVPN is not present for interface %s",
4019 __func__
, ip
, ifp
->name
);
4023 if (!zevpn
->vxlan_if
) {
4025 "VNI %u hash %p doesn't have intf upon local neighbor DEL",
4030 if (IS_ZEBRA_DEBUG_VXLAN
)
4031 zlog_debug("Del neighbor %pIA intf %s(%u) -> L2-VNI %u",
4032 ip
, ifp
->name
, ifp
->ifindex
, zevpn
->vni
);
4034 return zebra_evpn_neigh_del_ip(zevpn
, ip
);
4038 * Handle neighbor add or update notification from the kernel (on a VLAN
4039 * device / L3 interface). This is typically for a local neighbor but can
4040 * also be for a remote neighbor (e.g., ageout notification). It could
4041 * also be a "move" scenario.
4043 int zebra_vxlan_handle_kernel_neigh_update(struct interface
*ifp
,
4044 struct interface
*link_if
,
4046 struct ethaddr
*macaddr
,
4050 bool local_inactive
, bool dp_static
)
4052 struct zebra_evpn
*zevpn
= NULL
;
4053 struct zebra_l3vni
*zl3vni
= NULL
;
4055 /* check if this is a remote neigh entry corresponding to remote
4058 zl3vni
= zl3vni_from_svi(ifp
, link_if
);
4060 return zl3vni_local_nh_add_update(zl3vni
, ip
, state
);
4062 /* We are only interested in neighbors on an SVI that resides on top
4063 * of a VxLAN bridge.
4065 zevpn
= zebra_evpn_from_svi(ifp
, link_if
);
4069 if (IS_ZEBRA_DEBUG_VXLAN
|| IS_ZEBRA_DEBUG_EVPN_MH_NEIGH
)
4071 "Add/Update neighbor %pIA MAC %pEA intf %s(%u) state 0x%x %s%s%s%s-> L2-VNI %u",
4072 ip
, macaddr
, ifp
->name
,
4073 ifp
->ifindex
, state
, is_ext
? "ext-learned " : "",
4074 is_router
? "router " : "",
4075 local_inactive
? "local_inactive " : "",
4076 dp_static
? "peer_sync " : "", zevpn
->vni
);
4078 /* Is this about a local neighbor or a remote one? */
4080 return zebra_evpn_local_neigh_update(zevpn
, ifp
, ip
, macaddr
,
4081 is_router
, local_inactive
,
4084 return zebra_evpn_remote_neigh_update(zevpn
, ifp
, ip
, macaddr
, state
);
4088 zebra_vxlan_remote_macip_helper(bool add
, struct stream
*s
, vni_t
*vni
,
4089 struct ethaddr
*macaddr
, uint16_t *ipa_len
,
4090 struct ipaddr
*ip
, struct in_addr
*vtep_ip
,
4091 uint8_t *flags
, uint32_t *seq
, esi_t
*esi
)
4096 * Obtain each remote MACIP and process.
4097 * Message contains VNI, followed by MAC followed by IP (if any)
4098 * followed by remote VTEP IP.
4100 memset(ip
, 0, sizeof(*ip
));
4101 STREAM_GETL(s
, *vni
);
4102 STREAM_GET(macaddr
->octet
, s
, ETH_ALEN
);
4103 STREAM_GETW(s
, *ipa_len
);
4106 if (*ipa_len
== IPV4_MAX_BYTELEN
)
4107 ip
->ipa_type
= IPADDR_V4
;
4108 else if (*ipa_len
== IPV6_MAX_BYTELEN
)
4109 ip
->ipa_type
= IPADDR_V6
;
4111 if (IS_ZEBRA_DEBUG_VXLAN
)
4113 "ipa_len *must* be %d or %d bytes in length not %d",
4114 IPV4_MAX_BYTELEN
, IPV6_MAX_BYTELEN
,
4116 goto stream_failure
;
4119 STREAM_GET(&ip
->ip
.addr
, s
, *ipa_len
);
4121 l
+= 4 + ETH_ALEN
+ 4 + *ipa_len
;
4122 STREAM_GET(&vtep_ip
->s_addr
, s
, IPV4_MAX_BYTELEN
);
4123 l
+= IPV4_MAX_BYTELEN
;
4126 STREAM_GETC(s
, *flags
);
4127 STREAM_GETL(s
, *seq
);
4129 STREAM_GET(esi
, s
, sizeof(esi_t
));
4140 * Handle message from client to delete a remote MACIP for a VNI.
4142 void zebra_vxlan_remote_macip_del(ZAPI_HANDLER_ARGS
)
4146 struct ethaddr macaddr
;
4148 struct in_addr vtep_ip
;
4149 uint16_t l
= 0, ipa_len
;
4150 char buf1
[INET6_ADDRSTRLEN
];
4154 while (l
< hdr
->length
) {
4155 int res_length
= zebra_vxlan_remote_macip_helper(
4156 false, s
, &vni
, &macaddr
, &ipa_len
, &ip
, &vtep_ip
, NULL
,
4159 if (res_length
== -1)
4160 goto stream_failure
;
4163 if (IS_ZEBRA_DEBUG_VXLAN
)
4165 "Recv MACIP DEL VNI %u MAC %pEA%s%s Remote VTEP %pI4 from %s",
4167 ipa_len
? " IP " : "",
4169 ipaddr2str(&ip
, buf1
, sizeof(buf1
)) : "",
4170 &vtep_ip
, zebra_route_string(client
->proto
));
4172 /* Enqueue to workqueue for processing */
4173 zebra_rib_queue_evpn_rem_macip_del(vni
, &macaddr
, &ip
, vtep_ip
);
4181 * Handle message from client to add a remote MACIP for a VNI. This
4182 * could be just the add of a MAC address or the add of a neighbor
4185 void zebra_vxlan_remote_macip_add(ZAPI_HANDLER_ARGS
)
4189 struct ethaddr macaddr
;
4191 struct in_addr vtep_ip
;
4192 uint16_t l
= 0, ipa_len
;
4195 char buf1
[INET6_ADDRSTRLEN
];
4197 char esi_buf
[ESI_STR_LEN
];
4199 if (!EVPN_ENABLED(zvrf
)) {
4200 zlog_debug("EVPN not enabled, ignoring remote MACIP ADD");
4206 while (l
< hdr
->length
) {
4208 int res_length
= zebra_vxlan_remote_macip_helper(
4209 true, s
, &vni
, &macaddr
, &ipa_len
, &ip
, &vtep_ip
,
4210 &flags
, &seq
, &esi
);
4212 if (res_length
== -1)
4213 goto stream_failure
;
4216 if (IS_ZEBRA_DEBUG_VXLAN
) {
4217 if (memcmp(&esi
, zero_esi
, sizeof(esi_t
)))
4218 esi_to_str(&esi
, esi_buf
, sizeof(esi_buf
));
4220 strlcpy(esi_buf
, "-", ESI_STR_LEN
);
4222 "Recv %sMACIP ADD VNI %u MAC %pEA%s%s flags 0x%x seq %u VTEP %pI4 ESI %s from %s",
4223 (flags
& ZEBRA_MACIP_TYPE_SYNC_PATH
) ?
4226 ipa_len
? " IP " : "",
4228 ipaddr2str(&ip
, buf1
, sizeof(buf1
)) : "",
4229 flags
, seq
, &vtep_ip
, esi_buf
,
4230 zebra_route_string(client
->proto
));
4233 /* Enqueue to workqueue for processing */
4234 zebra_rib_queue_evpn_rem_macip_add(vni
, &macaddr
, &ip
, flags
,
4235 seq
, vtep_ip
, &esi
);
4243 * Handle remote vtep delete by kernel; re-add the vtep if we have it
4245 int zebra_vxlan_check_readd_vtep(struct interface
*ifp
, vni_t vni
,
4246 struct in_addr vtep_ip
)
4248 struct zebra_if
*zif
;
4249 struct zebra_vrf
*zvrf
= NULL
;
4250 struct zebra_evpn
*zevpn
= NULL
;
4251 struct zebra_vtep
*zvtep
= NULL
;
4252 struct zebra_vxlan_vni
*vnip
;
4257 /* If EVPN is not enabled, nothing to do. */
4258 if (!is_evpn_enabled())
4261 /* Locate VRF corresponding to interface. */
4262 zvrf
= ifp
->vrf
->info
;
4266 vnip
= zebra_vxlan_if_vni_find(zif
, vni
);
4270 /* Locate hash entry; it is expected to exist. */
4271 zevpn
= zebra_evpn_lookup(vni
);
4275 /* If the remote vtep entry doesn't exists nothing to do */
4276 zvtep
= zebra_evpn_vtep_find(zevpn
, &vtep_ip
);
4280 if (IS_ZEBRA_DEBUG_VXLAN
)
4282 "Del MAC for remote VTEP %pI4 intf %s(%u) VNI %u - readd",
4283 &vtep_ip
, ifp
->name
, ifp
->ifindex
, vni
);
4285 zebra_evpn_vtep_install(zevpn
, zvtep
);
4290 * Handle notification of MAC add/update over VxLAN. If the kernel is notifying
4291 * us, this must involve a multihoming scenario. Treat this as implicit delete
4292 * of any prior local MAC.
4294 static int zebra_vxlan_check_del_local_mac(struct interface
*ifp
,
4295 struct interface
*br_if
,
4296 struct ethaddr
*macaddr
,
4297 vlanid_t vid
, vni_t vni
)
4299 struct zebra_if
*zif
;
4300 struct zebra_evpn
*zevpn
;
4301 struct zebra_mac
*mac
;
4306 /* Check if EVPN is enabled. */
4307 if (!is_evpn_enabled())
4310 /* Locate hash entry; it is expected to exist. */
4311 zevpn
= zebra_evpn_lookup(vni
);
4315 /* If entry doesn't exist, nothing to do. */
4316 mac
= zebra_evpn_mac_lookup(zevpn
, macaddr
);
4320 /* Is it a local entry? */
4321 if (!CHECK_FLAG(mac
->flags
, ZEBRA_MAC_LOCAL
))
4324 if (IS_ZEBRA_DEBUG_VXLAN
)
4326 "Add/update remote MAC %pEA intf %s(%u) VNI %u flags 0x%x - del local",
4327 macaddr
, ifp
->name
, ifp
->ifindex
, vni
, mac
->flags
);
4329 /* Remove MAC from BGP. */
4330 zebra_evpn_mac_send_del_to_client(zevpn
->vni
, macaddr
, mac
->flags
,
4334 * If there are no neigh associated with the mac delete the mac
4335 * else mark it as AUTO for forward reference
4337 if (!listcount(mac
->neigh_list
)) {
4338 zebra_evpn_mac_del(zevpn
, mac
);
4340 zebra_evpn_mac_clear_fwd_info(mac
);
4341 UNSET_FLAG(mac
->flags
, ZEBRA_MAC_ALL_LOCAL_FLAGS
);
4342 UNSET_FLAG(mac
->flags
, ZEBRA_MAC_STICKY
);
4343 SET_FLAG(mac
->flags
, ZEBRA_MAC_AUTO
);
4349 /* MAC notification from the dataplane with a network dest port -
4350 * 1. This can be a local MAC on a down ES (if fast-failover is not possible
4351 * 2. Or it can be a remote MAC
4353 int zebra_vxlan_dp_network_mac_add(struct interface
*ifp
,
4354 struct interface
*br_if
,
4355 struct ethaddr
*macaddr
, vlanid_t vid
,
4356 vni_t vni
, uint32_t nhg_id
, bool sticky
,
4359 struct zebra_evpn_es
*es
;
4360 struct interface
*acc_ifp
;
4362 /* If netlink message is with vid, it will have no nexthop.
4366 if (IS_ZEBRA_DEBUG_VXLAN
|| IS_ZEBRA_DEBUG_EVPN_MH_MAC
)
4367 zlog_debug("dpAdd MAC %pEA VID %u - ignore as no nhid",
4372 /* Get vxlan's vid for netlink message has no it. */
4373 vid
= ((struct zebra_if
*)ifp
->info
)
4374 ->l2info
.vxl
.vni_info
.vni
.access_vlan
;
4376 /* if remote mac delete the local entry */
4377 if (!nhg_id
|| !zebra_evpn_nhg_is_local_es(nhg_id
, &es
)
4378 || !zebra_evpn_es_local_mac_via_network_port(es
)) {
4379 if (IS_ZEBRA_DEBUG_VXLAN
|| IS_ZEBRA_DEBUG_EVPN_MH_MAC
)
4380 zlog_debug("dpAdd remote MAC %pEA VID %u", macaddr
,
4382 return zebra_vxlan_check_del_local_mac(ifp
, br_if
, macaddr
, vid
,
4386 /* If local MAC on a down local ES translate the network-mac-add
4387 * to a local-active-mac-add
4389 if (IS_ZEBRA_DEBUG_VXLAN
|| IS_ZEBRA_DEBUG_EVPN_MH_MAC
)
4390 zlog_debug("dpAdd local-nw-MAC %pEA VID %u", macaddr
, vid
);
4391 acc_ifp
= es
->zif
->ifp
;
4392 return zebra_vxlan_local_mac_add_update(
4393 acc_ifp
, br_if
, macaddr
, vid
, sticky
,
4394 false /* local_inactive */, dp_static
);
4398 * Handle network MAC delete by kernel -
4399 * 1. readd the remote MAC if we have it
4400 * 2. local MAC with does ES may also need to be re-installed
4402 int zebra_vxlan_dp_network_mac_del(struct interface
*ifp
,
4403 struct interface
*br_if
,
4404 struct ethaddr
*macaddr
, vlanid_t vid
,
4407 struct zebra_if
*zif
= NULL
;
4408 struct zebra_evpn
*zevpn
= NULL
;
4409 struct zebra_l3vni
*zl3vni
= NULL
;
4410 struct zebra_mac
*mac
= NULL
;
4415 /* Check if EVPN is enabled. */
4416 if (!is_evpn_enabled())
4419 /* check if this is a remote RMAC and readd simillar to remote macs */
4420 zl3vni
= zl3vni_lookup(vni
);
4422 return zebra_vxlan_readd_remote_rmac(zl3vni
, macaddr
);
4424 /* Locate hash entry; it is expected to exist. */
4425 zevpn
= zebra_evpn_lookup(vni
);
4429 /* If entry doesn't exist, nothing to do. */
4430 mac
= zebra_evpn_mac_lookup(zevpn
, macaddr
);
4434 if (CHECK_FLAG(mac
->flags
, ZEBRA_MAC_REMOTE
)) {
4435 /* If remote entry simply re-install */
4436 if (IS_ZEBRA_DEBUG_VXLAN
|| IS_ZEBRA_DEBUG_EVPN_MH_MAC
)
4438 "dpDel remote MAC %pEA intf %s(%u) VNI %u - readd",
4439 macaddr
, ifp
->name
, ifp
->ifindex
, vni
);
4440 zebra_evpn_rem_mac_install(zevpn
, mac
, false /* was_static */);
4441 } else if (CHECK_FLAG(mac
->flags
, ZEBRA_MAC_LOCAL
) && mac
->es
4442 && zebra_evpn_es_local_mac_via_network_port(mac
->es
)) {
4443 /* If local entry via nw-port call local-del which will
4444 * re-install entry in the dataplane is needed
4446 if (IS_ZEBRA_DEBUG_VXLAN
|| IS_ZEBRA_DEBUG_EVPN_MH_MAC
)
4447 zlog_debug("dpDel local-nw-MAC %pEA VNI %u", macaddr
,
4450 zebra_evpn_del_local_mac(zevpn
, mac
, false);
4457 * Handle local MAC delete (on a port or VLAN corresponding to this VNI).
4459 int zebra_vxlan_local_mac_del(struct interface
*ifp
, struct interface
*br_if
,
4460 struct ethaddr
*macaddr
, vlanid_t vid
)
4462 struct zebra_evpn
*zevpn
;
4463 struct zebra_mac
*mac
;
4465 /* We are interested in MACs only on ports or (port, VLAN) that
4468 zevpn
= zebra_evpn_map_vlan(ifp
, br_if
, vid
);
4471 if (!zevpn
->vxlan_if
) {
4473 "VNI %u hash %p doesn't have intf upon local MAC DEL",
4478 /* If entry doesn't exist, nothing to do. */
4479 mac
= zebra_evpn_mac_lookup(zevpn
, macaddr
);
4483 /* Is it a local entry? */
4484 if (!CHECK_FLAG(mac
->flags
, ZEBRA_MAC_LOCAL
))
4487 return zebra_evpn_del_local_mac(zevpn
, mac
, false);
4491 * Handle local MAC add (on a port or VLAN corresponding to this VNI).
4493 int zebra_vxlan_local_mac_add_update(struct interface
*ifp
,
4494 struct interface
*br_if
,
4495 struct ethaddr
*macaddr
, vlanid_t vid
,
4496 bool sticky
, bool local_inactive
,
4499 struct zebra_evpn
*zevpn
;
4500 struct zebra_vrf
*zvrf
;
4504 /* We are interested in MACs only on ports or (port, VLAN) that
4507 zevpn
= zebra_evpn_map_vlan(ifp
, br_if
, vid
);
4509 if (IS_ZEBRA_DEBUG_VXLAN
)
4511 " Add/Update %sMAC %pEA intf %s(%u) VID %u, could not find EVPN",
4512 sticky
? "sticky " : "", macaddr
,
4513 ifp
->name
, ifp
->ifindex
, vid
);
4517 if (!zevpn
->vxlan_if
) {
4518 if (IS_ZEBRA_DEBUG_VXLAN
)
4520 " VNI %u hash %p doesn't have intf upon local MAC ADD",
4525 zvrf
= zebra_vrf_get_evpn();
4526 return zebra_evpn_add_update_local_mac(zvrf
, zevpn
, ifp
, macaddr
, vid
,
4527 sticky
, local_inactive
,
4532 * Handle message from client to delete a remote VTEP for an EVPN.
4534 void zebra_vxlan_remote_vtep_del_zapi(ZAPI_HANDLER_ARGS
)
4537 unsigned short l
= 0;
4539 struct in_addr vtep_ip
;
4541 if (!is_evpn_enabled()) {
4543 "%s: EVPN is not enabled yet we have received a VTEP DEL msg",
4548 if (!EVPN_ENABLED(zvrf
)) {
4549 zlog_debug("Recv VTEP DEL zapi for non-EVPN VRF %u",
4556 while (l
< hdr
->length
) {
4557 int flood_control
__attribute__((unused
));
4559 /* Obtain each remote VTEP and process. */
4560 STREAM_GETL(s
, vni
);
4562 STREAM_GET(&vtep_ip
.s_addr
, s
, IPV4_MAX_BYTELEN
);
4563 l
+= IPV4_MAX_BYTELEN
;
4565 /* Flood control is intentionally ignored right now */
4566 STREAM_GETL(s
, flood_control
);
4569 if (IS_ZEBRA_DEBUG_VXLAN
)
4570 zlog_debug("Recv VTEP DEL %pI4 VNI %u from %s",
4572 zebra_route_string(client
->proto
));
4574 /* Enqueue for processing */
4575 zebra_rib_queue_evpn_rem_vtep_del(zvrf_id(zvrf
), vni
, vtep_ip
);
4583 * Handle message from client to delete a remote VTEP for an EVPN.
4585 void zebra_vxlan_remote_vtep_del(vrf_id_t vrf_id
, vni_t vni
,
4586 struct in_addr vtep_ip
)
4588 struct zebra_evpn
*zevpn
;
4589 struct zebra_vtep
*zvtep
;
4590 struct interface
*ifp
;
4591 struct zebra_if
*zif
;
4592 struct zebra_vrf
*zvrf
;
4594 if (!is_evpn_enabled()) {
4595 zlog_debug("%s: Can't process vtep del: EVPN is not enabled",
4600 zvrf
= zebra_vrf_lookup_by_id(vrf_id
);
4604 if (!EVPN_ENABLED(zvrf
)) {
4605 zlog_debug("Can't process VTEP DEL for non-EVPN VRF %u",
4610 /* Locate VNI hash entry - expected to exist. */
4611 zevpn
= zebra_evpn_lookup(vni
);
4613 if (IS_ZEBRA_DEBUG_VXLAN
)
4615 "Failed to locate VNI hash for remote VTEP DEL, VNI %u",
4620 ifp
= zevpn
->vxlan_if
;
4623 "VNI %u hash %p doesn't have intf upon remote VTEP DEL",
4629 /* If down or not mapped to a bridge, we're done. */
4630 if (!if_is_operative(ifp
) || !zif
->brslave_info
.br_if
)
4633 /* If the remote VTEP does not exist, there's nothing more to
4635 * Otherwise, uninstall any remote MACs pointing to this VTEP
4636 * and then, the VTEP entry itself and remove it.
4638 zvtep
= zebra_evpn_vtep_find(zevpn
, &vtep_ip
);
4642 zebra_evpn_vtep_uninstall(zevpn
, &vtep_ip
);
4643 zebra_evpn_vtep_del(zevpn
, zvtep
);
4647 * Handle message from client to add a remote VTEP for an EVPN.
4649 void zebra_vxlan_remote_vtep_add(vrf_id_t vrf_id
, vni_t vni
,
4650 struct in_addr vtep_ip
, int flood_control
)
4652 struct zebra_evpn
*zevpn
;
4653 struct interface
*ifp
;
4654 struct zebra_if
*zif
;
4655 struct zebra_vtep
*zvtep
;
4656 struct zebra_vrf
*zvrf
;
4658 if (!is_evpn_enabled()) {
4659 zlog_debug("%s: EVPN not enabled: can't process a VTEP ADD",
4664 zvrf
= zebra_vrf_lookup_by_id(vrf_id
);
4668 if (!EVPN_ENABLED(zvrf
)) {
4669 zlog_debug("Can't process VTEP ADD for non-EVPN VRF %u",
4674 /* Locate VNI hash entry - expected to exist. */
4675 zevpn
= zebra_evpn_lookup(vni
);
4678 EC_ZEBRA_VTEP_ADD_FAILED
,
4679 "Failed to locate EVPN hash upon remote VTEP ADD, VNI %u",
4684 ifp
= zevpn
->vxlan_if
;
4687 EC_ZEBRA_VTEP_ADD_FAILED
,
4688 "VNI %u hash %p doesn't have intf upon remote VTEP ADD",
4695 /* If down or not mapped to a bridge, we're done. */
4696 if (!if_is_operative(ifp
) || !zif
->brslave_info
.br_if
)
4699 zvtep
= zebra_evpn_vtep_find(zevpn
, &vtep_ip
);
4701 /* If the remote VTEP already exists check if
4702 * the flood mode has changed
4704 if (zvtep
->flood_control
!= flood_control
) {
4705 if (zvtep
->flood_control
== VXLAN_FLOOD_DISABLED
)
4706 /* old mode was head-end-replication but
4707 * is no longer; get rid of the HER fdb
4708 * entry installed before
4710 zebra_evpn_vtep_uninstall(zevpn
, &vtep_ip
);
4711 zvtep
->flood_control
= flood_control
;
4712 zebra_evpn_vtep_install(zevpn
, zvtep
);
4715 zvtep
= zebra_evpn_vtep_add(zevpn
, &vtep_ip
, flood_control
);
4717 zebra_evpn_vtep_install(zevpn
, zvtep
);
4719 flog_err(EC_ZEBRA_VTEP_ADD_FAILED
,
4720 "Failed to add remote VTEP, VNI %u zevpn %p",
4726 * Handle message from client to add a remote VTEP for an EVPN.
4728 void zebra_vxlan_remote_vtep_add_zapi(ZAPI_HANDLER_ARGS
)
4731 unsigned short l
= 0;
4733 struct in_addr vtep_ip
;
4736 if (!is_evpn_enabled()) {
4738 "%s: EVPN not enabled yet we received a VTEP ADD zapi msg",
4743 if (!EVPN_ENABLED(zvrf
)) {
4744 zlog_debug("Recv VTEP ADD zapi for non-EVPN VRF %u",
4751 while (l
< hdr
->length
) {
4752 /* Obtain each remote VTEP and process. */
4753 STREAM_GETL(s
, vni
);
4755 STREAM_GET(&vtep_ip
.s_addr
, s
, IPV4_MAX_BYTELEN
);
4756 STREAM_GETL(s
, flood_control
);
4757 l
+= IPV4_MAX_BYTELEN
+ 4;
4759 if (IS_ZEBRA_DEBUG_VXLAN
)
4760 zlog_debug("Recv VTEP ADD %pI4 VNI %u flood %d from %s",
4761 &vtep_ip
, vni
, flood_control
,
4762 zebra_route_string(client
->proto
));
4764 /* Enqueue for processing */
4765 zebra_rib_queue_evpn_rem_vtep_add(zvrf_id(zvrf
), vni
, vtep_ip
,
4774 * Add/Del gateway macip to evpn
4776 * 1. SVI interface on a vlan aware bridge
4777 * 2. SVI interface on a vlan unaware bridge
4778 * 3. vrr interface (MACVLAN) associated to a SVI
4779 * We advertise macip routes for an interface if it is associated to VxLan vlan
4781 int zebra_vxlan_add_del_gw_macip(struct interface
*ifp
, const struct prefix
*p
,
4785 struct ethaddr macaddr
;
4786 struct zebra_evpn
*zevpn
= NULL
;
4788 memset(&ip
, 0, sizeof(ip
));
4789 memset(&macaddr
, 0, sizeof(macaddr
));
4791 /* Check if EVPN is enabled. */
4792 if (!is_evpn_enabled())
4795 if (IS_ZEBRA_IF_MACVLAN(ifp
)) {
4796 struct interface
*svi_if
=
4797 NULL
; /* SVI corresponding to the MACVLAN */
4798 struct zebra_if
*ifp_zif
=
4799 NULL
; /* Zebra daemon specific info for MACVLAN */
4800 struct zebra_if
*svi_if_zif
=
4801 NULL
; /* Zebra daemon specific info for SVI*/
4803 ifp_zif
= ifp
->info
;
4808 * for a MACVLAN interface the link represents the svi_if
4810 svi_if
= if_lookup_by_index_per_ns(zebra_ns_lookup(NS_DEFAULT
),
4811 ifp_zif
->link_ifindex
);
4813 zlog_debug("MACVLAN %s(%u) without link information",
4814 ifp
->name
, ifp
->ifindex
);
4818 if (IS_ZEBRA_IF_VLAN(svi_if
)) {
4820 * If it is a vlan aware bridge then the link gives the
4821 * bridge information
4823 struct interface
*svi_if_link
= NULL
;
4825 svi_if_zif
= svi_if
->info
;
4827 svi_if_link
= if_lookup_by_index_per_ns(
4828 zebra_ns_lookup(NS_DEFAULT
),
4829 svi_if_zif
->link_ifindex
);
4830 zevpn
= zebra_evpn_from_svi(svi_if
,
4833 } else if (IS_ZEBRA_IF_BRIDGE(svi_if
)) {
4835 * If it is a vlan unaware bridge then svi is the bridge
4838 zevpn
= zebra_evpn_from_svi(svi_if
, svi_if
);
4840 } else if (IS_ZEBRA_IF_VLAN(ifp
)) {
4841 struct zebra_if
*svi_if_zif
=
4842 NULL
; /* Zebra daemon specific info for SVI */
4843 struct interface
*svi_if_link
=
4844 NULL
; /* link info for the SVI = bridge info */
4846 svi_if_zif
= ifp
->info
;
4848 svi_if_link
= if_lookup_by_index_per_ns(
4849 zebra_ns_lookup(NS_DEFAULT
),
4850 svi_if_zif
->link_ifindex
);
4852 zevpn
= zebra_evpn_from_svi(ifp
, svi_if_link
);
4854 } else if (IS_ZEBRA_IF_BRIDGE(ifp
)) {
4855 zevpn
= zebra_evpn_from_svi(ifp
, ifp
);
4861 if (!zevpn
->vxlan_if
) {
4862 zlog_debug("VNI %u hash %p doesn't have intf upon MACVLAN up",
4867 /* VRR IP is advertised only if gw-macip-adv-enabled */
4868 if (IS_ZEBRA_IF_MACVLAN(ifp
)) {
4869 if (!advertise_gw_macip_enabled(zevpn
))
4872 /* SVI IP is advertised if gw or svi macip-adv-enabled */
4873 if (!advertise_svi_macip_enabled(zevpn
)
4874 && !advertise_gw_macip_enabled(zevpn
))
4878 memcpy(&macaddr
.octet
, ifp
->hw_addr
, ETH_ALEN
);
4880 if (p
->family
== AF_INET
) {
4881 ip
.ipa_type
= IPADDR_V4
;
4882 memcpy(&(ip
.ipaddr_v4
), &(p
->u
.prefix4
),
4883 sizeof(struct in_addr
));
4884 } else if (p
->family
== AF_INET6
) {
4885 ip
.ipa_type
= IPADDR_V6
;
4886 memcpy(&(ip
.ipaddr_v6
), &(p
->u
.prefix6
),
4887 sizeof(struct in6_addr
));
4892 zebra_evpn_gw_macip_add(ifp
, zevpn
, &macaddr
, &ip
);
4894 zebra_evpn_gw_macip_del(ifp
, zevpn
, &ip
);
4900 * Handle SVI interface going down.
4901 * SVI can be associated to either L3-VNI or L2-VNI.
4902 * For L2-VNI: At this point, this is a NOP since
4903 * the kernel deletes the neighbor entries on this SVI (if any).
4904 * We only need to update the vrf corresponding to zevpn.
4905 * For L3-VNI: L3-VNI is operationally down, update mac-ip routes and delete
4908 int zebra_vxlan_svi_down(struct interface
*ifp
, struct interface
*link_if
)
4910 struct zebra_l3vni
*zl3vni
= NULL
;
4912 zl3vni
= zl3vni_from_svi(ifp
, link_if
);
4915 /* process l3-vni down */
4916 zebra_vxlan_process_l3vni_oper_down(zl3vni
);
4918 /* remove association with svi-if */
4919 zl3vni
->svi_if
= NULL
;
4921 struct zebra_evpn
*zevpn
= NULL
;
4923 /* Unlink the SVI from the access VLAN */
4924 zebra_evpn_acc_bd_svi_set(ifp
->info
, link_if
->info
, false);
4926 /* since we dont have svi corresponding to zevpn, we associate it
4927 * to default vrf. Note: the corresponding neigh entries on the
4928 * SVI would have already been deleted */
4929 zevpn
= zebra_evpn_from_svi(ifp
, link_if
);
4932 /* remove from l3-vni list */
4933 zl3vni
= zl3vni_from_vrf(zevpn
->vrf_id
);
4935 listnode_delete(zl3vni
->l2vnis
, zevpn
);
4937 zevpn
->svi_if
= NULL
;
4938 zevpn
->vrf_id
= VRF_DEFAULT
;
4940 /* update the tenant vrf in BGP */
4941 if (if_is_operative(zevpn
->vxlan_if
))
4942 zebra_evpn_send_add_to_client(zevpn
);
4949 * Handle SVI interface coming up.
4950 * SVI can be associated to L3-VNI (l3vni vxlan interface) or L2-VNI (l2-vni
4952 * For L2-VNI: we need to install any remote neighbors entried (used for
4954 * For L3-VNI: SVI will be used to get the rmac to be used with L3-VNI
4956 int zebra_vxlan_svi_up(struct interface
*ifp
, struct interface
*link_if
)
4958 struct zebra_evpn
*zevpn
= NULL
;
4959 struct zebra_l3vni
*zl3vni
= NULL
;
4961 zl3vni
= zl3vni_from_svi(ifp
, link_if
);
4964 /* associate with svi */
4965 zl3vni
->svi_if
= ifp
;
4967 /* process oper-up */
4968 if (is_l3vni_oper_up(zl3vni
))
4969 zebra_vxlan_process_l3vni_oper_up(zl3vni
);
4972 /* process SVI up for l2-vni */
4973 struct neigh_walk_ctx n_wctx
;
4975 zevpn
= zebra_evpn_from_svi(ifp
, link_if
);
4979 if (!zevpn
->vxlan_if
) {
4981 "VNI %u hash %p doesn't have intf upon SVI up",
4986 if (IS_ZEBRA_DEBUG_VXLAN
)
4988 "SVI %s(%u) VNI %u VRF %s is UP, installing neighbors",
4989 ifp
->name
, ifp
->ifindex
, zevpn
->vni
,
4992 /* update the vrf information for l2-vni and inform bgp */
4993 zevpn
->svi_if
= ifp
;
4994 zevpn
->vrf_id
= ifp
->vrf
->vrf_id
;
4996 zl3vni
= zl3vni_from_vrf(zevpn
->vrf_id
);
4998 listnode_add_sort_nodup(zl3vni
->l2vnis
, zevpn
);
5000 if (if_is_operative(zevpn
->vxlan_if
))
5001 zebra_evpn_send_add_to_client(zevpn
);
5003 /* Install any remote neighbors for this VNI. */
5004 memset(&n_wctx
, 0, sizeof(n_wctx
));
5005 n_wctx
.zevpn
= zevpn
;
5006 hash_iterate(zevpn
->neigh_table
, zebra_evpn_install_neigh_hash
,
5009 /* Link the SVI from the access VLAN */
5010 zebra_evpn_acc_bd_svi_set(ifp
->info
, link_if
->info
, true);
5012 /* Update MACIP routes created by advertise-svi-ip */
5013 if (advertise_svi_macip_enabled(zevpn
)) {
5014 zebra_evpn_del_macip_for_intf(ifp
, zevpn
);
5015 zebra_evpn_add_macip_for_intf(ifp
, zevpn
);
5023 * Handle MAC-VLAN interface going down.
5024 * L3VNI: When MAC-VLAN interface goes down,
5025 * find its associated SVI and update type2/type-5 routes
5028 void zebra_vxlan_macvlan_down(struct interface
*ifp
)
5030 struct zebra_l3vni
*zl3vni
= NULL
;
5031 struct zebra_if
*zif
, *link_zif
;
5032 struct interface
*link_ifp
, *link_if
;
5036 link_ifp
= zif
->link
;
5038 if (IS_ZEBRA_DEBUG_VXLAN
)
5040 "macvlan parent link is not found. Parent index %d ifp %s",
5042 ifindex2ifname(zif
->link_ifindex
,
5046 link_zif
= link_ifp
->info
;
5049 link_if
= if_lookup_by_index_per_ns(zebra_ns_lookup(NS_DEFAULT
),
5050 link_zif
->link_ifindex
);
5052 zl3vni
= zl3vni_from_svi(link_ifp
, link_if
);
5054 zl3vni
->mac_vlan_if
= NULL
;
5055 if (is_l3vni_oper_up(zl3vni
))
5056 zebra_vxlan_process_l3vni_oper_up(zl3vni
);
5061 * Handle MAC-VLAN interface going up.
5062 * L3VNI: When MAC-VLAN interface comes up,
5063 * find its associated SVI and update type-2 routes
5064 * with MAC-VLAN's MAC as RMAC and for type-5 routes
5065 * use SVI's MAC as RMAC.
5067 void zebra_vxlan_macvlan_up(struct interface
*ifp
)
5069 struct zebra_l3vni
*zl3vni
= NULL
;
5070 struct zebra_if
*zif
, *link_zif
;
5071 struct interface
*link_ifp
, *link_if
;
5075 link_ifp
= zif
->link
;
5076 link_zif
= link_ifp
->info
;
5079 link_if
= if_lookup_by_index_per_ns(zebra_ns_lookup(NS_DEFAULT
),
5080 link_zif
->link_ifindex
);
5081 zl3vni
= zl3vni_from_svi(link_ifp
, link_if
);
5083 /* associate with macvlan (VRR) interface */
5084 zl3vni
->mac_vlan_if
= ifp
;
5086 /* process oper-up */
5087 if (is_l3vni_oper_up(zl3vni
))
5088 zebra_vxlan_process_l3vni_oper_up(zl3vni
);
5092 int zebra_vxlan_process_vrf_vni_cmd(struct zebra_vrf
*zvrf
, vni_t vni
,
5093 char *err
, int err_str_sz
, int filter
,
5096 struct zebra_l3vni
*zl3vni
= NULL
;
5097 struct zebra_vrf
*zvrf_evpn
= NULL
;
5099 zvrf_evpn
= zebra_vrf_get_evpn();
5101 if (IS_ZEBRA_DEBUG_VXLAN
)
5102 zlog_debug("vrf %s vni %u %s", zvrf_name(zvrf
), vni
,
5103 add
? "ADD" : "DEL");
5106 /* check if the vni is already present under zvrf */
5108 snprintf(err
, err_str_sz
,
5109 "VNI is already configured under the vrf");
5113 /* check if this VNI is already present in the system */
5114 zl3vni
= zl3vni_lookup(vni
);
5116 snprintf(err
, err_str_sz
,
5117 "VNI is already configured as L3-VNI");
5121 /* Remove L2VNI if present */
5122 zebra_vxlan_handle_vni_transition(zvrf
, vni
, add
);
5124 /* add the L3-VNI to the global table */
5125 zl3vni
= zl3vni_add(vni
, zvrf_id(zvrf
));
5127 /* associate the vrf with vni */
5130 /* set the filter in l3vni to denote if we are using l3vni only
5134 SET_FLAG(zl3vni
->filter
, PREFIX_ROUTES_ONLY
);
5136 /* associate with vxlan-intf;
5137 * we need to associate with the vxlan-intf first
5139 zl3vni
->vxlan_if
= zl3vni_map_to_vxlan_if(zl3vni
);
5141 /* associate with corresponding SVI interface, we can associate
5142 * with svi-if only after vxlan interface association is
5145 zl3vni
->svi_if
= zl3vni_map_to_svi_if(zl3vni
);
5147 zl3vni
->mac_vlan_if
= zl3vni_map_to_mac_vlan_if(zl3vni
);
5149 if (IS_ZEBRA_DEBUG_VXLAN
)
5151 "%s: l3vni %u svi_if %s mac_vlan_if %s",
5153 zl3vni
->svi_if
? zl3vni
->svi_if
->name
: "NIL",
5154 zl3vni
->mac_vlan_if
? zl3vni
->mac_vlan_if
->name
5157 /* formulate l2vni list */
5158 hash_iterate(zvrf_evpn
->evpn_table
, zevpn_add_to_l3vni_list
,
5161 if (is_l3vni_oper_up(zl3vni
))
5162 zebra_vxlan_process_l3vni_oper_up(zl3vni
);
5165 zl3vni
= zl3vni_lookup(vni
);
5167 snprintf(err
, err_str_sz
, "VNI doesn't exist");
5171 if (zvrf
->l3vni
!= vni
) {
5172 snprintf(err
, err_str_sz
,
5173 "VNI %d doesn't exist in VRF: %s",
5174 vni
, zvrf
->vrf
->name
);
5178 if (filter
&& !CHECK_FLAG(zl3vni
->filter
, PREFIX_ROUTES_ONLY
)) {
5179 snprintf(err
, ERR_STR_SZ
,
5180 "prefix-routes-only is not set for the vni");
5184 zebra_vxlan_process_l3vni_oper_down(zl3vni
);
5186 /* delete and uninstall all rmacs */
5187 hash_iterate(zl3vni
->rmac_table
, zl3vni_del_rmac_hash_entry
,
5190 /* delete and uninstall all next-hops */
5191 hash_iterate(zl3vni
->nh_table
, zl3vni_del_nh_hash_entry
,
5197 /* Add L2VNI for this VNI */
5198 zebra_vxlan_handle_vni_transition(zvrf
, vni
, add
);
5203 int zebra_vxlan_vrf_enable(struct zebra_vrf
*zvrf
)
5205 struct zebra_l3vni
*zl3vni
= NULL
;
5208 zl3vni
= zl3vni_lookup(zvrf
->l3vni
);
5212 zl3vni
->vrf_id
= zvrf_id(zvrf
);
5213 if (is_l3vni_oper_up(zl3vni
))
5214 zebra_vxlan_process_l3vni_oper_up(zl3vni
);
5218 int zebra_vxlan_vrf_disable(struct zebra_vrf
*zvrf
)
5220 struct zebra_l3vni
*zl3vni
= NULL
;
5223 zl3vni
= zl3vni_lookup(zvrf
->l3vni
);
5227 zebra_vxlan_process_l3vni_oper_down(zl3vni
);
5229 /* delete and uninstall all rmacs */
5230 hash_iterate(zl3vni
->rmac_table
, zl3vni_del_rmac_hash_entry
, zl3vni
);
5231 /* delete and uninstall all next-hops */
5232 hash_iterate(zl3vni
->nh_table
, zl3vni_del_nh_hash_entry
, zl3vni
);
5234 zl3vni
->vrf_id
= VRF_UNKNOWN
;
5239 int zebra_vxlan_vrf_delete(struct zebra_vrf
*zvrf
)
5241 struct zebra_l3vni
*zl3vni
= NULL
;
5245 zl3vni
= zl3vni_lookup(zvrf
->l3vni
);
5251 zebra_vxlan_handle_vni_transition(zvrf
, vni
, 0);
5257 * Handle message from client to specify the flooding mechanism for
5258 * BUM packets. The default is to do head-end (ingress) replication
5259 * and the other supported option is to disable it. This applies to
5260 * all BUM traffic and disabling it applies to both the transmit and
5261 * receive direction.
5263 void zebra_vxlan_flood_control(ZAPI_HANDLER_ARGS
)
5266 enum vxlan_flood_control flood_ctrl
;
5268 if (!EVPN_ENABLED(zvrf
)) {
5269 zlog_err("EVPN flood control for non-EVPN VRF %u",
5275 STREAM_GETC(s
, flood_ctrl
);
5277 if (IS_ZEBRA_DEBUG_VXLAN
)
5278 zlog_debug("EVPN flood control %u, currently %u",
5279 flood_ctrl
, zvrf
->vxlan_flood_ctrl
);
5281 if (zvrf
->vxlan_flood_ctrl
== flood_ctrl
)
5284 zvrf
->vxlan_flood_ctrl
= flood_ctrl
;
5286 /* Install or uninstall flood entries corresponding to
5289 hash_iterate(zvrf
->evpn_table
, zebra_evpn_handle_flooding_remote_vteps
,
5297 * Handle message from client to enable/disable advertisement of svi macip
5300 void zebra_vxlan_advertise_svi_macip(ZAPI_HANDLER_ARGS
)
5305 struct zebra_evpn
*zevpn
= NULL
;
5306 struct interface
*ifp
= NULL
;
5308 if (!EVPN_ENABLED(zvrf
)) {
5309 zlog_debug("EVPN SVI-MACIP Adv for non-EVPN VRF %u",
5315 STREAM_GETC(s
, advertise
);
5316 STREAM_GETL(s
, vni
);
5319 if (IS_ZEBRA_DEBUG_VXLAN
)
5320 zlog_debug("EVPN SVI-MACIP Adv %s, currently %s",
5321 advertise
? "enabled" : "disabled",
5322 advertise_svi_macip_enabled(NULL
)
5326 if (zvrf
->advertise_svi_macip
== advertise
)
5331 zvrf
->advertise_svi_macip
= advertise
;
5332 hash_iterate(zvrf
->evpn_table
,
5333 zebra_evpn_gw_macip_add_for_evpn_hash
,
5336 hash_iterate(zvrf
->evpn_table
,
5337 zebra_evpn_svi_macip_del_for_evpn_hash
,
5339 zvrf
->advertise_svi_macip
= advertise
;
5343 struct zebra_if
*zif
= NULL
;
5344 struct interface
*vlan_if
= NULL
;
5345 struct zebra_vxlan_vni
*zl2_info_vni
;
5348 zevpn
= zebra_evpn_lookup(vni
);
5352 if (IS_ZEBRA_DEBUG_VXLAN
)
5354 "EVPN SVI macip Adv %s on VNI %d, currently %s",
5355 advertise
? "enabled" : "disabled", vni
,
5356 advertise_svi_macip_enabled(zevpn
)
5360 old_advertise
= advertise_svi_macip_enabled(zevpn
);
5362 /* Store flag even though SVI is not present.
5363 * Once SVI comes up triggers self MAC-IP route add.
5365 zevpn
->advertise_svi_macip
= advertise
;
5366 if (advertise_svi_macip_enabled(zevpn
) == old_advertise
)
5369 ifp
= zevpn
->vxlan_if
;
5375 /* If down or not mapped to a bridge, we're done. */
5376 if (!if_is_operative(ifp
) || !zif
->brslave_info
.br_if
)
5379 zl2_info_vni
= zebra_vxlan_if_vni_find(zif
, vni
);
5383 vlan_if
= zvni_map_to_svi(zl2_info_vni
->access_vlan
,
5384 zif
->brslave_info
.br_if
);
5389 /* Add primary SVI MAC-IP */
5390 zebra_evpn_add_macip_for_intf(vlan_if
, zevpn
);
5392 /* Del primary SVI MAC-IP */
5393 zebra_evpn_del_macip_for_intf(vlan_if
, zevpn
);
5402 * Handle message from client to enable/disable advertisement of g/w macip
5405 void zebra_vxlan_advertise_subnet(ZAPI_HANDLER_ARGS
)
5410 struct zebra_evpn
*zevpn
= NULL
;
5411 struct interface
*ifp
= NULL
;
5412 struct zebra_if
*zif
= NULL
;
5413 struct interface
*vlan_if
= NULL
;
5414 struct zebra_vxlan_vni
*zl2_info_vni
= NULL
;
5416 if (!EVPN_ENABLED(zvrf
)) {
5417 zlog_debug("EVPN GW-MACIP Adv for non-EVPN VRF %u",
5423 STREAM_GETC(s
, advertise
);
5424 STREAM_GET(&vni
, s
, 3);
5426 zevpn
= zebra_evpn_lookup(vni
);
5430 if (zevpn
->advertise_subnet
== advertise
)
5433 if (IS_ZEBRA_DEBUG_VXLAN
)
5434 zlog_debug("EVPN subnet Adv %s on VNI %d, currently %s",
5435 advertise
? "enabled" : "disabled", vni
,
5436 zevpn
->advertise_subnet
? "enabled" : "disabled");
5439 zevpn
->advertise_subnet
= advertise
;
5441 ifp
= zevpn
->vxlan_if
;
5447 /* If down or not mapped to a bridge, we're done. */
5448 if (!if_is_operative(ifp
) || !zif
->brslave_info
.br_if
)
5451 zl2_info_vni
= zebra_vxlan_if_vni_find(zif
, vni
);
5455 vlan_if
= zvni_map_to_svi(zl2_info_vni
->access_vlan
,
5456 zif
->brslave_info
.br_if
);
5460 if (zevpn
->advertise_subnet
)
5461 zebra_evpn_advertise_subnet(zevpn
, vlan_if
, 1);
5463 zebra_evpn_advertise_subnet(zevpn
, vlan_if
, 0);
5470 * Handle message from client to enable/disable advertisement of g/w macip
5473 void zebra_vxlan_advertise_gw_macip(ZAPI_HANDLER_ARGS
)
5478 struct zebra_evpn
*zevpn
= NULL
;
5479 struct interface
*ifp
= NULL
;
5481 if (!EVPN_ENABLED(zvrf
)) {
5482 zlog_debug("EVPN GW-MACIP Adv for non-EVPN VRF %u",
5488 STREAM_GETC(s
, advertise
);
5489 STREAM_GETL(s
, vni
);
5492 if (IS_ZEBRA_DEBUG_VXLAN
)
5493 zlog_debug("EVPN gateway macip Adv %s, currently %s",
5494 advertise
? "enabled" : "disabled",
5495 advertise_gw_macip_enabled(NULL
)
5499 if (zvrf
->advertise_gw_macip
== advertise
)
5502 zvrf
->advertise_gw_macip
= advertise
;
5504 if (advertise_gw_macip_enabled(zevpn
))
5505 hash_iterate(zvrf
->evpn_table
,
5506 zebra_evpn_gw_macip_add_for_evpn_hash
,
5509 hash_iterate(zvrf
->evpn_table
,
5510 zebra_evpn_gw_macip_del_for_evpn_hash
,
5514 struct zebra_if
*zif
= NULL
;
5515 struct interface
*vlan_if
= NULL
;
5516 struct interface
*vrr_if
= NULL
;
5517 struct zebra_vxlan_vni
*zl2_info_vni
= NULL
;
5520 zevpn
= zebra_evpn_lookup(vni
);
5524 if (IS_ZEBRA_DEBUG_VXLAN
)
5526 "EVPN gateway macip Adv %s on VNI %d, currently %s",
5527 advertise
? "enabled" : "disabled", vni
,
5528 advertise_gw_macip_enabled(zevpn
) ? "enabled"
5531 old_advertise
= advertise_gw_macip_enabled(zevpn
);
5533 zevpn
->advertise_gw_macip
= advertise
;
5534 if (advertise_gw_macip_enabled(zevpn
) == old_advertise
)
5537 ifp
= zevpn
->vxlan_if
;
5543 /* If down or not mapped to a bridge, we're done. */
5544 if (!if_is_operative(ifp
) || !zif
->brslave_info
.br_if
)
5547 zl2_info_vni
= zebra_vxlan_if_vni_find(zif
, vni
);
5551 vlan_if
= zvni_map_to_svi(zl2_info_vni
->access_vlan
,
5552 zif
->brslave_info
.br_if
);
5556 if (advertise_gw_macip_enabled(zevpn
)) {
5557 /* Add primary SVI MAC-IP */
5558 zebra_evpn_add_macip_for_intf(vlan_if
, zevpn
);
5560 /* Add VRR MAC-IP - if any*/
5561 vrr_if
= zebra_get_vrr_intf_for_svi(vlan_if
);
5563 zebra_evpn_add_macip_for_intf(vrr_if
, zevpn
);
5565 /* Del primary MAC-IP */
5566 zebra_evpn_del_macip_for_intf(vlan_if
, zevpn
);
5568 /* Del VRR MAC-IP - if any*/
5569 vrr_if
= zebra_get_vrr_intf_for_svi(vlan_if
);
5571 zebra_evpn_del_macip_for_intf(vrr_if
, zevpn
);
5579 static int macfdb_read_ns(struct ns
*ns
,
5580 void *_in_param
__attribute__((unused
)),
5581 void **out_param
__attribute__((unused
)))
5583 struct zebra_ns
*zns
= ns
->info
;
5586 return NS_WALK_CONTINUE
;
5589 static int neigh_read_ns(struct ns
*ns
,
5590 void *_in_param
__attribute__((unused
)),
5591 void **out_param
__attribute__((unused
)))
5593 struct zebra_ns
*zns
= ns
->info
;
5596 return NS_WALK_CONTINUE
;
5600 * Handle message from client to learn (or stop learning) about VNIs and MACs.
5601 * When enabled, the VNI hash table will be built and MAC FDB table read;
5602 * when disabled, the entries should be deleted and remote VTEPs and MACs
5603 * uninstalled from the kernel.
5604 * This also informs the setting for BUM handling at the time this change
5605 * occurs; it is relevant only when specifying "learn".
5607 void zebra_vxlan_advertise_all_vni(ZAPI_HANDLER_ARGS
)
5609 struct stream
*s
= NULL
;
5611 enum vxlan_flood_control flood_ctrl
;
5613 /* Mismatch between EVPN VRF and current VRF (should be prevented by
5615 if (is_evpn_enabled() && !EVPN_ENABLED(zvrf
))
5619 STREAM_GETC(s
, advertise
);
5620 STREAM_GETC(s
, flood_ctrl
);
5622 if (IS_ZEBRA_DEBUG_VXLAN
)
5623 zlog_debug("EVPN VRF %s(%u) VNI Adv %s, currently %s, flood control %u",
5624 zvrf_name(zvrf
), zvrf_id(zvrf
),
5625 advertise
? "enabled" : "disabled",
5626 is_evpn_enabled() ? "enabled" : "disabled",
5629 if (zvrf
->advertise_all_vni
== advertise
)
5632 zvrf
->advertise_all_vni
= advertise
;
5633 if (EVPN_ENABLED(zvrf
)) {
5634 zrouter
.evpn_vrf
= zvrf
;
5636 /* Note BUM handling */
5637 zvrf
->vxlan_flood_ctrl
= flood_ctrl
;
5639 /* Replay all ESs */
5640 zebra_evpn_es_send_all_to_client(true /* add */);
5642 /* Build EVPN hash table and inform BGP. */
5643 zevpn_build_hash_table();
5645 /* Add all SVI (L3 GW) MACs to BGP*/
5646 hash_iterate(zvrf
->evpn_table
,
5647 zebra_evpn_gw_macip_add_for_evpn_hash
, NULL
);
5649 /* Read the MAC FDB */
5650 ns_walk_func(macfdb_read_ns
, NULL
, NULL
);
5652 /* Read neighbors */
5653 ns_walk_func(neigh_read_ns
, NULL
, NULL
);
5655 /* Cleanup VTEPs for all EVPNs - uninstall from
5656 * kernel and free entries.
5658 hash_iterate(zvrf
->evpn_table
, zebra_evpn_vxlan_cleanup_all
,
5661 /* Delete all ESs in BGP */
5662 zebra_evpn_es_send_all_to_client(false /* add */);
5664 /* cleanup all l3vnis */
5665 hash_iterate(zrouter
.l3vni_table
, zl3vni_cleanup_all
, NULL
);
5667 /* Mark as "no EVPN VRF" */
5668 zrouter
.evpn_vrf
= NULL
;
5676 * Allocate EVPN hash table for this VRF and do other initialization.
5677 * NOTE: Currently supported only for default VRF.
5679 void zebra_vxlan_init_tables(struct zebra_vrf
*zvrf
)
5686 snprintf(buffer
, sizeof(buffer
), "Zebra VRF EVPN Table: %s",
5688 zvrf
->evpn_table
= hash_create_size(8, zebra_evpn_hash_keymake
,
5689 zebra_evpn_hash_cmp
, buffer
);
5691 snprintf(buffer
, sizeof(buffer
), "Zebra VxLAN SG Table: %s",
5693 zvrf
->vxlan_sg_table
= hash_create_size(8, zebra_vxlan_sg_hash_key_make
,
5694 zebra_vxlan_sg_hash_eq
, buffer
);
5697 /* Cleanup EVPN info, but don't free the table. */
5698 void zebra_vxlan_cleanup_tables(struct zebra_vrf
*zvrf
)
5700 struct zebra_vrf
*evpn_zvrf
= zebra_vrf_get_evpn();
5702 hash_iterate(zvrf
->evpn_table
, zebra_evpn_vxlan_cleanup_all
, zvrf
);
5703 zebra_vxlan_cleanup_sg_table(zvrf
);
5705 if (zvrf
== evpn_zvrf
)
5706 zebra_evpn_es_cleanup();
5709 /* Close all EVPN handling */
5710 void zebra_vxlan_close_tables(struct zebra_vrf
*zvrf
)
5714 hash_iterate(zvrf
->evpn_table
, zebra_evpn_vxlan_cleanup_all
, zvrf
);
5715 hash_free(zvrf
->evpn_table
);
5716 if (zvrf
->vxlan_sg_table
) {
5717 zebra_vxlan_cleanup_sg_table(zvrf
);
5718 hash_free(zvrf
->vxlan_sg_table
);
5719 zvrf
->vxlan_sg_table
= NULL
;
5723 /* init the l3vni table */
5724 void zebra_vxlan_init(void)
5726 zrouter
.l3vni_table
= hash_create(l3vni_hash_keymake
, l3vni_hash_cmp
,
5727 "Zebra VRF L3 VNI table");
5729 svd_nh_table
= zebra_neigh_db_create("Zebra SVD next-hop table");
5731 zrouter
.evpn_vrf
= NULL
;
5732 zebra_evpn_mh_init();
5735 /* free l3vni table */
5736 void zebra_vxlan_disable(void)
5738 hash_free(zrouter
.l3vni_table
);
5739 zebra_evpn_mh_terminate();
5742 /* get the l3vni svi ifindex */
5743 ifindex_t
get_l3vni_svi_ifindex(vrf_id_t vrf_id
)
5745 struct zebra_l3vni
*zl3vni
= NULL
;
5747 zl3vni
= zl3vni_from_vrf(vrf_id
);
5748 if (!zl3vni
|| !is_l3vni_oper_up(zl3vni
))
5751 return zl3vni
->svi_if
->ifindex
;
5754 /* get the l3vni vxlan ifindex */
5755 ifindex_t
get_l3vni_vxlan_ifindex(vrf_id_t vrf_id
)
5757 struct zebra_l3vni
*zl3vni
= NULL
;
5759 zl3vni
= zl3vni_from_vrf(vrf_id
);
5760 if (!zl3vni
|| !is_l3vni_oper_up(zl3vni
))
5763 return zl3vni
->vxlan_if
->ifindex
;
5766 /* get the l3vni vni */
5767 vni_t
get_l3vni_vni(vrf_id_t vrf_id
)
5769 struct zebra_l3vni
*zl3vni
= NULL
;
5771 zl3vni
= zl3vni_from_vrf(vrf_id
);
5772 if (!zl3vni
|| !is_l3vni_oper_up(zl3vni
))
5778 /* is the vrf l3vni SVD backed? */
5779 bool is_vrf_l3vni_svd_backed(vrf_id_t vrf_id
)
5781 struct zebra_l3vni
*zl3vni
= NULL
;
5783 zl3vni
= zl3vni_from_vrf(vrf_id
);
5784 if (!zl3vni
|| !is_l3vni_oper_up(zl3vni
))
5787 return IS_ZL3VNI_SVD_BACKED(zl3vni
);
5790 /************************** vxlan SG cache management ************************/
5791 /* Inform PIM about the mcast group */
5792 static int zebra_vxlan_sg_send(struct zebra_vrf
*zvrf
,
5793 struct prefix_sg
*sg
,
5794 char *sg_str
, uint16_t cmd
)
5796 struct zserv
*client
= NULL
;
5797 struct stream
*s
= NULL
;
5799 client
= zserv_find_client(ZEBRA_ROUTE_PIM
, 0);
5803 if (!CHECK_FLAG(zvrf
->flags
, ZEBRA_PIM_SEND_VXLAN_SG
))
5806 s
= stream_new(ZEBRA_MAX_PACKET_SIZ
);
5808 zclient_create_header(s
, cmd
, VRF_DEFAULT
);
5809 stream_putl(s
, IPV4_MAX_BYTELEN
);
5810 stream_put(s
, &sg
->src
.s_addr
, IPV4_MAX_BYTELEN
);
5811 stream_put(s
, &sg
->grp
.s_addr
, IPV4_MAX_BYTELEN
);
5813 /* Write packet size. */
5814 stream_putw_at(s
, 0, stream_get_endp(s
));
5816 if (IS_ZEBRA_DEBUG_VXLAN
)
5819 (cmd
== ZEBRA_VXLAN_SG_ADD
) ? "add" : "del", sg_str
,
5820 zebra_route_string(client
->proto
));
5822 if (cmd
== ZEBRA_VXLAN_SG_ADD
)
5823 client
->vxlan_sg_add_cnt
++;
5825 client
->vxlan_sg_del_cnt
++;
5827 return zserv_send_message(client
, s
);
5830 static unsigned int zebra_vxlan_sg_hash_key_make(const void *p
)
5832 const struct zebra_vxlan_sg
*vxlan_sg
= p
;
5834 return (jhash_2words(vxlan_sg
->sg
.src
.s_addr
,
5835 vxlan_sg
->sg
.grp
.s_addr
, 0));
5838 static bool zebra_vxlan_sg_hash_eq(const void *p1
, const void *p2
)
5840 const struct zebra_vxlan_sg
*sg1
= p1
;
5841 const struct zebra_vxlan_sg
*sg2
= p2
;
5843 return ((sg1
->sg
.src
.s_addr
== sg2
->sg
.src
.s_addr
)
5844 && (sg1
->sg
.grp
.s_addr
== sg2
->sg
.grp
.s_addr
));
5847 static struct zebra_vxlan_sg
*zebra_vxlan_sg_new(struct zebra_vrf
*zvrf
,
5848 struct prefix_sg
*sg
)
5850 struct zebra_vxlan_sg
*vxlan_sg
;
5852 vxlan_sg
= XCALLOC(MTYPE_ZVXLAN_SG
, sizeof(*vxlan_sg
));
5854 vxlan_sg
->zvrf
= zvrf
;
5856 prefix_sg2str(sg
, vxlan_sg
->sg_str
);
5858 vxlan_sg
= hash_get(zvrf
->vxlan_sg_table
, vxlan_sg
, hash_alloc_intern
);
5860 if (IS_ZEBRA_DEBUG_VXLAN
)
5861 zlog_debug("vxlan SG %s created", vxlan_sg
->sg_str
);
5866 static struct zebra_vxlan_sg
*zebra_vxlan_sg_find(struct zebra_vrf
*zvrf
,
5867 struct prefix_sg
*sg
)
5869 struct zebra_vxlan_sg lookup
;
5872 return hash_lookup(zvrf
->vxlan_sg_table
, &lookup
);
5875 static struct zebra_vxlan_sg
*zebra_vxlan_sg_add(struct zebra_vrf
*zvrf
,
5876 struct prefix_sg
*sg
)
5878 struct zebra_vxlan_sg
*vxlan_sg
;
5879 struct zebra_vxlan_sg
*parent
= NULL
;
5882 vxlan_sg
= zebra_vxlan_sg_find(zvrf
, sg
);
5886 /* create a *G entry for every BUM group implicitly -
5887 * 1. The SG entry is used by pimd to setup the vxlan-origination-mroute
5888 * 2. the XG entry is used by pimd to setup the
5889 * vxlan-termination-mroute
5891 if (sg
->src
.s_addr
!= INADDR_ANY
) {
5892 memset(&sip
, 0, sizeof(sip
));
5893 parent
= zebra_vxlan_sg_do_ref(zvrf
, sip
, sg
->grp
);
5898 vxlan_sg
= zebra_vxlan_sg_new(zvrf
, sg
);
5900 zebra_vxlan_sg_send(zvrf
, sg
, vxlan_sg
->sg_str
,
5901 ZEBRA_VXLAN_SG_ADD
);
5906 static void zebra_vxlan_sg_del(struct zebra_vxlan_sg
*vxlan_sg
)
5909 struct zebra_vrf
*zvrf
;
5911 zvrf
= vrf_info_lookup(VRF_DEFAULT
);
5915 /* On SG entry deletion remove the reference to its parent XG
5918 if (vxlan_sg
->sg
.src
.s_addr
!= INADDR_ANY
) {
5919 memset(&sip
, 0, sizeof(sip
));
5920 zebra_vxlan_sg_do_deref(zvrf
, sip
, vxlan_sg
->sg
.grp
);
5923 zebra_vxlan_sg_send(zvrf
, &vxlan_sg
->sg
,
5924 vxlan_sg
->sg_str
, ZEBRA_VXLAN_SG_DEL
);
5926 hash_release(vxlan_sg
->zvrf
->vxlan_sg_table
, vxlan_sg
);
5928 if (IS_ZEBRA_DEBUG_VXLAN
)
5929 zlog_debug("VXLAN SG %s deleted", vxlan_sg
->sg_str
);
5931 XFREE(MTYPE_ZVXLAN_SG
, vxlan_sg
);
5934 static void zebra_vxlan_sg_do_deref(struct zebra_vrf
*zvrf
,
5935 struct in_addr sip
, struct in_addr mcast_grp
)
5937 struct zebra_vxlan_sg
*vxlan_sg
;
5938 struct prefix_sg sg
;
5940 sg
.family
= AF_INET
;
5941 sg
.prefixlen
= IPV4_MAX_BYTELEN
;
5944 vxlan_sg
= zebra_vxlan_sg_find(zvrf
, &sg
);
5948 if (vxlan_sg
->ref_cnt
)
5949 --vxlan_sg
->ref_cnt
;
5951 if (!vxlan_sg
->ref_cnt
)
5952 zebra_vxlan_sg_del(vxlan_sg
);
5955 static struct zebra_vxlan_sg
*zebra_vxlan_sg_do_ref(struct zebra_vrf
*zvrf
,
5957 struct in_addr mcast_grp
)
5959 struct zebra_vxlan_sg
*vxlan_sg
;
5960 struct prefix_sg sg
;
5962 sg
.family
= AF_INET
;
5963 sg
.prefixlen
= IPV4_MAX_BYTELEN
;
5966 vxlan_sg
= zebra_vxlan_sg_add(zvrf
, &sg
);
5968 ++vxlan_sg
->ref_cnt
;
5973 void zebra_vxlan_sg_deref(struct in_addr local_vtep_ip
,
5974 struct in_addr mcast_grp
)
5976 struct zebra_vrf
*zvrf
;
5978 if (local_vtep_ip
.s_addr
== INADDR_ANY
5979 || mcast_grp
.s_addr
== INADDR_ANY
)
5982 zvrf
= vrf_info_lookup(VRF_DEFAULT
);
5986 zebra_vxlan_sg_do_deref(zvrf
, local_vtep_ip
, mcast_grp
);
5989 void zebra_vxlan_sg_ref(struct in_addr local_vtep_ip
, struct in_addr mcast_grp
)
5991 struct zebra_vrf
*zvrf
;
5993 if (local_vtep_ip
.s_addr
== INADDR_ANY
5994 || mcast_grp
.s_addr
== INADDR_ANY
)
5997 zvrf
= vrf_info_lookup(VRF_DEFAULT
);
6000 zebra_vxlan_sg_do_ref(zvrf
, local_vtep_ip
, mcast_grp
);
6003 static void zebra_vxlan_xg_pre_cleanup(struct hash_bucket
*bucket
, void *arg
)
6005 struct zebra_vxlan_sg
*vxlan_sg
= (struct zebra_vxlan_sg
*)bucket
->data
;
6007 /* increment the ref count against (*,G) to prevent them from being
6010 if (vxlan_sg
->sg
.src
.s_addr
== INADDR_ANY
)
6011 ++vxlan_sg
->ref_cnt
;
6014 static void zebra_vxlan_xg_post_cleanup(struct hash_bucket
*bucket
, void *arg
)
6016 struct zebra_vxlan_sg
*vxlan_sg
= (struct zebra_vxlan_sg
*)bucket
->data
;
6018 /* decrement the dummy ref count against (*,G) to delete them */
6019 if (vxlan_sg
->sg
.src
.s_addr
== INADDR_ANY
) {
6020 if (vxlan_sg
->ref_cnt
)
6021 --vxlan_sg
->ref_cnt
;
6022 if (!vxlan_sg
->ref_cnt
)
6023 zebra_vxlan_sg_del(vxlan_sg
);
6027 static void zebra_vxlan_sg_cleanup(struct hash_bucket
*bucket
, void *arg
)
6029 struct zebra_vxlan_sg
*vxlan_sg
= (struct zebra_vxlan_sg
*)bucket
->data
;
6031 zebra_vxlan_sg_del(vxlan_sg
);
6034 static void zebra_vxlan_cleanup_sg_table(struct zebra_vrf
*zvrf
)
6036 /* increment the ref count against (*,G) to prevent them from being
6039 hash_iterate(zvrf
->vxlan_sg_table
, zebra_vxlan_xg_pre_cleanup
, NULL
);
6041 hash_iterate(zvrf
->vxlan_sg_table
, zebra_vxlan_sg_cleanup
, NULL
);
6043 /* decrement the dummy ref count against the XG entries */
6044 hash_iterate(zvrf
->vxlan_sg_table
, zebra_vxlan_xg_post_cleanup
, NULL
);
6047 static void zebra_vxlan_sg_replay_send(struct hash_bucket
*bucket
, void *arg
)
6049 struct zebra_vxlan_sg
*vxlan_sg
= (struct zebra_vxlan_sg
*)bucket
->data
;
6051 zebra_vxlan_sg_send(vxlan_sg
->zvrf
, &vxlan_sg
->sg
,
6052 vxlan_sg
->sg_str
, ZEBRA_VXLAN_SG_ADD
);
6055 /* Handle message from client to replay vxlan SG entries */
6056 void zebra_vxlan_sg_replay(ZAPI_HANDLER_ARGS
)
6058 if (IS_ZEBRA_DEBUG_VXLAN
)
6059 zlog_debug("VxLAN SG updates to PIM, start");
6061 SET_FLAG(zvrf
->flags
, ZEBRA_PIM_SEND_VXLAN_SG
);
6063 if (!EVPN_ENABLED(zvrf
)) {
6064 if (IS_ZEBRA_DEBUG_VXLAN
)
6065 zlog_debug("VxLAN SG replay request on unexpected vrf %d",
6070 hash_iterate(zvrf
->vxlan_sg_table
, zebra_vxlan_sg_replay_send
, NULL
);
6074 /* Cleanup EVPN configuration of a specific VRF */
6075 static void zebra_evpn_vrf_cfg_cleanup(struct zebra_vrf
*zvrf
)
6077 struct zebra_l3vni
*zl3vni
= NULL
;
6079 zvrf
->advertise_all_vni
= 0;
6080 zvrf
->advertise_gw_macip
= 0;
6081 zvrf
->advertise_svi_macip
= 0;
6082 zvrf
->vxlan_flood_ctrl
= VXLAN_FLOOD_HEAD_END_REPL
;
6084 hash_iterate(zvrf
->evpn_table
, zebra_evpn_cfg_cleanup
, NULL
);
6087 zl3vni
= zl3vni_lookup(zvrf
->l3vni
);
6089 /* delete and uninstall all rmacs */
6090 hash_iterate(zl3vni
->rmac_table
, zl3vni_del_rmac_hash_entry
,
6092 /* delete and uninstall all next-hops */
6093 hash_iterate(zl3vni
->nh_table
, zl3vni_del_nh_hash_entry
,
6098 /* Cleanup BGP EVPN configuration upon client disconnect */
6099 static int zebra_evpn_bgp_cfg_clean_up(struct zserv
*client
)
6102 struct zebra_vrf
*zvrf
;
6104 RB_FOREACH (vrf
, vrf_id_head
, &vrfs_by_id
) {
6107 zebra_evpn_vrf_cfg_cleanup(zvrf
);
6113 static int zebra_evpn_pim_cfg_clean_up(struct zserv
*client
)
6115 struct zebra_vrf
*zvrf
= zebra_vrf_get_evpn();
6117 if (CHECK_FLAG(zvrf
->flags
, ZEBRA_PIM_SEND_VXLAN_SG
)) {
6118 if (IS_ZEBRA_DEBUG_VXLAN
)
6119 zlog_debug("VxLAN SG updates to PIM, stop");
6120 UNSET_FLAG(zvrf
->flags
, ZEBRA_PIM_SEND_VXLAN_SG
);
6126 static int zebra_evpn_cfg_clean_up(struct zserv
*client
)
6128 if (client
->proto
== ZEBRA_ROUTE_BGP
)
6129 return zebra_evpn_bgp_cfg_clean_up(client
);
6131 if (client
->proto
== ZEBRA_ROUTE_PIM
)
6132 return zebra_evpn_pim_cfg_clean_up(client
);
6138 * Handle results for vxlan dataplane operations.
6140 extern void zebra_vxlan_handle_result(struct zebra_dplane_ctx
*ctx
)
6145 /* Config knob for accepting lower sequence numbers */
6146 void zebra_vxlan_set_accept_bgp_seq(bool set
)
6148 accept_bgp_seq
= set
;
6151 bool zebra_vxlan_get_accept_bgp_seq(void)
6153 return accept_bgp_seq
;
6156 /* Cleanup BGP EVPN configuration upon client disconnect */
6157 extern void zebra_evpn_init(void)
6159 hook_register(zserv_client_close
, zebra_evpn_cfg_clean_up
);