1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Zebra EVPN for VxLAN code
4 * Copyright (C) 2016, 2017 Cumulus Networks, Inc.
21 #include <linux/neighbour.h>
23 #include "lib/printfrr.h"
25 #include "zebra/zebra_router.h"
26 #include "zebra/debug.h"
27 #include "zebra/interface.h"
28 #include "zebra/rib.h"
30 #include "zebra/rt_netlink.h"
31 #include "zebra/zebra_errors.h"
32 #include "zebra/zebra_l2.h"
33 #include "zebra/zebra_l2_bridge_if.h"
34 #include "zebra/zebra_ns.h"
35 #include "zebra/zebra_vrf.h"
36 #include "zebra/zebra_vxlan.h"
37 #include "zebra/zebra_vxlan_private.h"
38 #include "zebra/zebra_evpn.h"
39 #include "zebra/zebra_evpn_mac.h"
40 #include "zebra/zebra_evpn_neigh.h"
41 #include "zebra/zebra_evpn_mh.h"
42 #include "zebra/zebra_evpn_vxlan.h"
43 #include "zebra/zebra_router.h"
45 DEFINE_MTYPE_STATIC(ZEBRA
, HOST_PREFIX
, "host prefix");
46 DEFINE_MTYPE_STATIC(ZEBRA
, ZL3VNI
, "L3 VNI hash");
47 DEFINE_MTYPE_STATIC(ZEBRA
, L3VNI_MAC
, "EVPN L3VNI MAC");
48 DEFINE_MTYPE_STATIC(ZEBRA
, L3NEIGH
, "EVPN Neighbor");
49 DEFINE_MTYPE_STATIC(ZEBRA
, ZVXLAN_SG
, "zebra VxLAN multicast group");
50 DEFINE_MTYPE_STATIC(ZEBRA
, EVPN_VTEP
, "zebra VxLAN VTEP IP");
52 DEFINE_HOOK(zebra_rmac_update
,
53 (struct zebra_mac
* rmac
, struct zebra_l3vni
*zl3vni
, bool delete,
55 (rmac
, zl3vni
, delete, reason
));
58 static bool accept_bgp_seq
= true;
60 /* Single VXlan Device Global Neigh Table */
61 struct hash
*svd_nh_table
;
63 /* static function declarations */
64 static void zevpn_print_neigh_hash_all_evpn(struct hash_bucket
*bucket
,
66 static void zl3vni_print_nh(struct zebra_neigh
*n
, struct vty
*vty
,
68 static void zl3vni_print_rmac(struct zebra_mac
*zrmac
, struct vty
*vty
,
70 static void zevpn_print_mac_hash_all_evpn(struct hash_bucket
*bucket
, void *ctxt
);
72 /* l3-vni next-hop neigh related APIs */
73 static struct zebra_neigh
*zl3vni_nh_lookup(struct zebra_l3vni
*zl3vni
,
74 const struct ipaddr
*ip
);
75 static void *zl3vni_nh_alloc(void *p
);
76 static struct zebra_neigh
*zl3vni_nh_add(struct zebra_l3vni
*zl3vni
,
77 const struct ipaddr
*vtep_ip
,
78 const struct ethaddr
*rmac
);
79 static int zl3vni_nh_del(struct zebra_l3vni
*zl3vni
, struct zebra_neigh
*n
);
80 static int zl3vni_nh_install(struct zebra_l3vni
*zl3vni
, struct zebra_neigh
*n
);
81 static int zl3vni_nh_uninstall(struct zebra_l3vni
*zl3vni
,
82 struct zebra_neigh
*n
);
83 static struct zebra_neigh
*svd_nh_add(const struct ipaddr
*vtep_ip
,
84 const struct ethaddr
*rmac
);
85 static int svd_nh_del(struct zebra_neigh
*n
);
86 static int svd_nh_install(struct zebra_l3vni
*zl3vni
, struct zebra_neigh
*n
);
87 static int svd_nh_uninstall(struct zebra_l3vni
*zl3vni
, struct zebra_neigh
*n
);
89 /* l3-vni rmac related APIs */
90 static void zl3vni_print_rmac_hash(struct hash_bucket
*, void *);
91 static struct zebra_mac
*zl3vni_rmac_lookup(struct zebra_l3vni
*zl3vni
,
92 const struct ethaddr
*rmac
);
93 static void *zl3vni_rmac_alloc(void *p
);
94 static struct zebra_mac
*zl3vni_rmac_add(struct zebra_l3vni
*zl3vni
,
95 const struct ethaddr
*rmac
);
96 static int zl3vni_rmac_del(struct zebra_l3vni
*zl3vni
, struct zebra_mac
*zrmac
);
97 static int zl3vni_rmac_install(struct zebra_l3vni
*zl3vni
,
98 struct zebra_mac
*zrmac
);
99 static int zl3vni_rmac_uninstall(struct zebra_l3vni
*zl3vni
,
100 struct zebra_mac
*zrmac
);
102 /* l3-vni related APIs*/
103 static void *zl3vni_alloc(void *p
);
104 static struct zebra_l3vni
*zl3vni_add(vni_t vni
, vrf_id_t vrf_id
);
105 static int zl3vni_del(struct zebra_l3vni
*zl3vni
);
107 static void zevpn_build_hash_table(void);
108 static unsigned int zebra_vxlan_sg_hash_key_make(const void *p
);
109 static bool zebra_vxlan_sg_hash_eq(const void *p1
, const void *p2
);
110 static void zebra_vxlan_sg_do_deref(struct zebra_vrf
*zvrf
,
111 struct in_addr sip
, struct in_addr mcast_grp
);
112 static struct zebra_vxlan_sg
*zebra_vxlan_sg_do_ref(struct zebra_vrf
*vrf
,
114 struct in_addr mcast_grp
);
115 static void zebra_vxlan_cleanup_sg_table(struct zebra_vrf
*zvrf
);
117 bool zebra_evpn_do_dup_addr_detect(struct zebra_vrf
*zvrf
)
119 return zvrf
->dup_addr_detect
&& zebra_evpn_mh_do_dup_addr_detect();
122 /* Private functions */
123 static int host_rb_entry_compare(const struct host_rb_entry
*hle1
,
124 const struct host_rb_entry
*hle2
)
126 if (hle1
->p
.family
< hle2
->p
.family
)
129 if (hle1
->p
.family
> hle2
->p
.family
)
132 if (hle1
->p
.prefixlen
< hle2
->p
.prefixlen
)
135 if (hle1
->p
.prefixlen
> hle2
->p
.prefixlen
)
138 if (hle1
->p
.family
== AF_INET
) {
139 if (hle1
->p
.u
.prefix4
.s_addr
< hle2
->p
.u
.prefix4
.s_addr
)
142 if (hle1
->p
.u
.prefix4
.s_addr
> hle2
->p
.u
.prefix4
.s_addr
)
146 } else if (hle1
->p
.family
== AF_INET6
) {
147 return memcmp(&hle1
->p
.u
.prefix6
, &hle2
->p
.u
.prefix6
,
149 } else if (hle1
->p
.family
== AF_EVPN
) {
153 /* two (v4/v6) dummy prefixes of route_type BGP_EVPN_AD_ROUTE
154 * are used for all nexthops associated with a non-zero ESI
156 family1
= is_evpn_prefix_ipaddr_v4(
157 (const struct prefix_evpn
*)&hle1
->p
)
160 family2
= is_evpn_prefix_ipaddr_v4(
161 (const struct prefix_evpn
*)&hle2
->p
)
166 if (family1
< family2
)
169 if (family1
> family2
)
174 zlog_debug("%s: Unexpected family type: %d", __func__
,
179 RB_GENERATE(host_rb_tree_entry
, host_rb_entry
, hl_entry
, host_rb_entry_compare
);
181 static uint32_t rb_host_count(struct host_rb_tree_entry
*hrbe
)
183 struct host_rb_entry
*hle
;
186 RB_FOREACH (hle
, host_rb_tree_entry
, hrbe
)
192 static int l3vni_rmac_nh_list_cmp(void *p1
, void *p2
)
194 const struct ipaddr
*vtep_ip1
= p1
;
195 const struct ipaddr
*vtep_ip2
= p2
;
197 return !ipaddr_cmp(vtep_ip1
, vtep_ip2
);
200 static void l3vni_rmac_nh_free(struct ipaddr
*vtep_ip
)
202 XFREE(MTYPE_EVPN_VTEP
, vtep_ip
);
205 static void l3vni_rmac_nh_list_nh_delete(struct zebra_l3vni
*zl3vni
,
206 struct zebra_mac
*zrmac
,
207 struct ipaddr
*vtep_ip
)
209 struct listnode
*node
= NULL
, *nnode
= NULL
;
210 struct ipaddr
*vtep
= NULL
;
212 for (ALL_LIST_ELEMENTS(zrmac
->nh_list
, node
, nnode
, vtep
)) {
213 if (ipaddr_cmp(vtep
, vtep_ip
) == 0)
218 l3vni_rmac_nh_free(vtep
);
219 list_delete_node(zrmac
->nh_list
, node
);
224 * Print neighbors for all EVPN.
226 static void zevpn_print_neigh_hash_all_evpn(struct hash_bucket
*bucket
,
230 json_object
*json
= NULL
, *json_evpn
= NULL
;
231 struct zebra_evpn
*zevpn
;
233 struct neigh_walk_ctx wctx
;
234 char vni_str
[VNI_STR_LEN
];
237 vty
= (struct vty
*)args
[0];
238 json
= (json_object
*)args
[1];
239 print_dup
= (uint32_t)(uintptr_t)args
[2];
241 zevpn
= (struct zebra_evpn
*)bucket
->data
;
243 num_neigh
= hashcount(zevpn
->neigh_table
);
246 num_neigh
= num_dup_detected_neighs(zevpn
);
250 "\nVNI %u #ARP (IPv4 and IPv6, local and remote) %u\n\n",
251 zevpn
->vni
, num_neigh
);
253 json_evpn
= json_object_new_object();
254 json_object_int_add(json_evpn
, "numArpNd", num_neigh
);
255 snprintf(vni_str
, VNI_STR_LEN
, "%u", zevpn
->vni
);
260 json_object_object_add(json
, vni_str
, json_evpn
);
264 /* Since we have IPv6 addresses to deal with which can vary widely in
265 * size, we try to be a bit more elegant in display by first computing
268 memset(&wctx
, 0, sizeof(wctx
));
271 wctx
.addr_width
= 15;
272 wctx
.json
= json_evpn
;
273 hash_iterate(zevpn
->neigh_table
, zebra_evpn_find_neigh_addr_width
,
277 zebra_evpn_print_neigh_hdr(vty
, &wctx
);
280 hash_iterate(zevpn
->neigh_table
,
281 zebra_evpn_print_dad_neigh_hash
, &wctx
);
283 hash_iterate(zevpn
->neigh_table
, zebra_evpn_print_neigh_hash
,
287 json_object_object_add(json
, vni_str
, json_evpn
);
291 * Print neighbors for all EVPNs in detail.
293 static void zevpn_print_neigh_hash_all_evpn_detail(struct hash_bucket
*bucket
,
297 json_object
*json
= NULL
, *json_evpn
= NULL
;
298 struct zebra_evpn
*zevpn
;
300 struct neigh_walk_ctx wctx
;
301 char vni_str
[VNI_STR_LEN
];
304 vty
= (struct vty
*)args
[0];
305 json
= (json_object
*)args
[1];
306 print_dup
= (uint32_t)(uintptr_t)args
[2];
308 zevpn
= (struct zebra_evpn
*)bucket
->data
;
311 vty_out(vty
, "{}\n");
314 num_neigh
= hashcount(zevpn
->neigh_table
);
316 if (print_dup
&& num_dup_detected_neighs(zevpn
) == 0)
321 "\nVNI %u #ARP (IPv4 and IPv6, local and remote) %u\n\n",
322 zevpn
->vni
, num_neigh
);
324 json_evpn
= json_object_new_object();
325 json_object_int_add(json_evpn
, "numArpNd", num_neigh
);
326 snprintf(vni_str
, VNI_STR_LEN
, "%u", zevpn
->vni
);
330 json_object_object_add(json
, vni_str
, json_evpn
);
334 memset(&wctx
, 0, sizeof(wctx
));
337 wctx
.addr_width
= 15;
338 wctx
.json
= json_evpn
;
341 hash_iterate(zevpn
->neigh_table
,
342 zebra_evpn_print_dad_neigh_hash_detail
, &wctx
);
344 hash_iterate(zevpn
->neigh_table
,
345 zebra_evpn_print_neigh_hash_detail
, &wctx
);
348 json_object_object_add(json
, vni_str
, json_evpn
);
351 /* print a specific next hop for an l3vni */
352 static void zl3vni_print_nh(struct zebra_neigh
*n
, struct vty
*vty
,
355 char buf1
[ETHER_ADDR_STRLEN
];
356 char buf2
[INET6_ADDRSTRLEN
];
357 json_object
*json_hosts
= NULL
;
358 struct host_rb_entry
*hle
;
361 vty_out(vty
, "Ip: %s\n",
362 ipaddr2str(&n
->ip
, buf2
, sizeof(buf2
)));
363 vty_out(vty
, " RMAC: %s\n",
364 prefix_mac2str(&n
->emac
, buf1
, sizeof(buf1
)));
367 vty_out(vty
, " Refcount: %u\n", n
->refcnt
);
369 vty_out(vty
, " Refcount: %d\n",
370 rb_host_count(&n
->host_rb
));
371 vty_out(vty
, " Prefixes:\n");
372 RB_FOREACH (hle
, host_rb_tree_entry
, &n
->host_rb
)
373 vty_out(vty
, " %pFX\n", &hle
->p
);
376 json_hosts
= json_object_new_array();
377 json_object_string_add(
378 json
, "ip", ipaddr2str(&(n
->ip
), buf2
, sizeof(buf2
)));
379 json_object_string_add(
381 prefix_mac2str(&n
->emac
, buf2
, sizeof(buf2
)));
384 json_object_int_add(json
, "refCount", n
->refcnt
);
386 json_object_int_add(json
, "refCount",
387 rb_host_count(&n
->host_rb
));
388 RB_FOREACH (hle
, host_rb_tree_entry
, &n
->host_rb
)
389 json_object_array_add(
391 json_object_new_string(prefix2str(
392 &hle
->p
, buf2
, sizeof(buf2
))));
393 json_object_object_add(json
, "prefixList", json_hosts
);
398 /* Print a specific RMAC entry */
399 static void zl3vni_print_rmac(struct zebra_mac
*zrmac
, struct vty
*vty
,
402 struct listnode
*node
= NULL
;
403 struct ipaddr
*vtep
= NULL
;
404 json_object
*json_nhs
= NULL
;
407 vty_out(vty
, "MAC: %pEA\n", &zrmac
->macaddr
);
408 vty_out(vty
, " Remote VTEP: %pI4\n",
409 &zrmac
->fwd_info
.r_vtep_ip
);
411 json_nhs
= json_object_new_array();
412 json_object_string_addf(json
, "routerMac", "%pEA",
414 json_object_string_addf(json
, "vtepIp", "%pI4",
415 &zrmac
->fwd_info
.r_vtep_ip
);
416 for (ALL_LIST_ELEMENTS_RO(zrmac
->nh_list
, node
, vtep
)) {
417 json_object_array_add(json_nhs
, json_object_new_stringf(
420 json_object_object_add(json
, "nexthops", json_nhs
);
425 * Print MACs for all EVPNs.
427 static void zevpn_print_mac_hash_all_evpn(struct hash_bucket
*bucket
, void *ctxt
)
430 json_object
*json
= NULL
, *json_evpn
= NULL
;
431 json_object
*json_mac
= NULL
;
432 struct zebra_evpn
*zevpn
;
434 struct mac_walk_ctx
*wctx
= ctxt
;
435 char vni_str
[VNI_STR_LEN
];
440 zevpn
= (struct zebra_evpn
*)bucket
->data
;
443 /*We are iterating over a new VNI, set the count to 0*/
446 num_macs
= num_valid_macs(zevpn
);
451 num_macs
= num_dup_detected_macs(zevpn
);
454 json_evpn
= json_object_new_object();
455 json_mac
= json_object_new_object();
456 snprintf(vni_str
, VNI_STR_LEN
, "%u", zevpn
->vni
);
459 if (!CHECK_FLAG(wctx
->flags
, SHOW_REMOTE_MAC_FROM_VTEP
)) {
461 vty_out(vty
, "\nVNI %u #MACs (local and remote) %u\n\n",
462 zevpn
->vni
, num_macs
);
464 "Flags: N=sync-neighs, I=local-inactive, P=peer-active, X=peer-proxy\n");
465 vty_out(vty
, "%-17s %-6s %-5s %-30s %-5s %s\n", "MAC",
466 "Type", "Flags", "Intf/Remote ES/VTEP",
469 json_object_int_add(json_evpn
, "numMacs", num_macs
);
474 json_object_int_add(json_evpn
, "numMacs", num_macs
);
475 json_object_object_add(json
, vni_str
, json_evpn
);
480 /* assign per-evpn to wctx->json object to fill macs
481 * under the evpn. Re-assign primary json object to fill
482 * next evpn information.
484 wctx
->json
= json_mac
;
486 hash_iterate(zevpn
->mac_table
, zebra_evpn_print_dad_mac_hash
,
489 hash_iterate(zevpn
->mac_table
, zebra_evpn_print_mac_hash
, wctx
);
493 json_object_object_add(json_evpn
, "macs", json_mac
);
494 json_object_object_add(json
, vni_str
, json_evpn
);
499 * Print MACs in detail for all EVPNs.
501 static void zevpn_print_mac_hash_all_evpn_detail(struct hash_bucket
*bucket
,
505 json_object
*json
= NULL
, *json_evpn
= NULL
;
506 json_object
*json_mac
= NULL
;
507 struct zebra_evpn
*zevpn
;
509 struct mac_walk_ctx
*wctx
= ctxt
;
510 char vni_str
[VNI_STR_LEN
];
515 zevpn
= (struct zebra_evpn
*)bucket
->data
;
518 vty_out(vty
, "{}\n");
523 /*We are iterating over a new EVPN, set the count to 0*/
526 num_macs
= num_valid_macs(zevpn
);
530 if (wctx
->print_dup
&& (num_dup_detected_macs(zevpn
) == 0))
534 json_evpn
= json_object_new_object();
535 json_mac
= json_object_new_object();
536 snprintf(vni_str
, VNI_STR_LEN
, "%u", zevpn
->vni
);
539 if (!CHECK_FLAG(wctx
->flags
, SHOW_REMOTE_MAC_FROM_VTEP
)) {
541 vty_out(vty
, "\nVNI %u #MACs (local and remote) %u\n\n",
542 zevpn
->vni
, num_macs
);
544 json_object_int_add(json_evpn
, "numMacs", num_macs
);
546 /* assign per-evpn to wctx->json object to fill macs
547 * under the evpn. Re-assign primary json object to fill
548 * next evpn information.
550 wctx
->json
= json_mac
;
552 hash_iterate(zevpn
->mac_table
,
553 zebra_evpn_print_dad_mac_hash_detail
, wctx
);
555 hash_iterate(zevpn
->mac_table
, zebra_evpn_print_mac_hash_detail
,
560 json_object_object_add(json_evpn
, "macs", json_mac
);
561 json_object_object_add(json
, vni_str
, json_evpn
);
565 static void zl3vni_print_nh_hash(struct hash_bucket
*bucket
, void *ctx
)
567 struct nh_walk_ctx
*wctx
= NULL
;
568 struct vty
*vty
= NULL
;
569 struct json_object
*json_evpn
= NULL
;
570 struct json_object
*json_nh
= NULL
;
571 struct zebra_neigh
*n
= NULL
;
572 char buf1
[ETHER_ADDR_STRLEN
];
573 char buf2
[INET6_ADDRSTRLEN
];
575 wctx
= (struct nh_walk_ctx
*)ctx
;
577 json_evpn
= wctx
->json
;
579 json_nh
= json_object_new_object();
580 n
= (struct zebra_neigh
*)bucket
->data
;
583 vty_out(vty
, "%-15s %-17s\n",
584 ipaddr2str(&(n
->ip
), buf2
, sizeof(buf2
)),
585 prefix_mac2str(&n
->emac
, buf1
, sizeof(buf1
)));
587 json_object_string_add(json_nh
, "nexthopIp",
588 ipaddr2str(&n
->ip
, buf2
, sizeof(buf2
)));
589 json_object_string_add(
590 json_nh
, "routerMac",
591 prefix_mac2str(&n
->emac
, buf1
, sizeof(buf1
)));
592 json_object_object_add(json_evpn
,
593 ipaddr2str(&(n
->ip
), buf2
, sizeof(buf2
)),
598 static void zl3vni_print_nh_all_table(struct hash
*nh_table
, vni_t vni
,
599 struct vty
*vty
, json_object
*json
)
602 struct nh_walk_ctx wctx
;
603 char vni_str
[VNI_STR_LEN
];
604 json_object
*json_evpn
= NULL
;
606 const char *svd_str
= "Global SVD Table";
611 num_nh
= hashcount(nh_table
);
617 json_evpn
= json_object_new_object();
619 snprintf(vni_str
, VNI_STR_LEN
, "%u", vni
);
624 vty_out(vty
, "\n%s #Next-Hops %u\n\n", svd_str
, num_nh
);
626 vty_out(vty
, "\nVNI %u #Next-Hops %u\n\n", vni
, num_nh
);
628 vty_out(vty
, "%-15s %-17s\n", "IP", "RMAC");
630 json_object_int_add(json_evpn
, "numNextHops", num_nh
);
632 memset(&wctx
, 0, sizeof(wctx
));
634 wctx
.json
= json_evpn
;
635 hash_iterate(nh_table
, zl3vni_print_nh_hash
, &wctx
);
637 json_object_object_add(json
, vni_str
, json_evpn
);
640 static void zl3vni_print_nh_hash_all_vni(struct hash_bucket
*bucket
,
643 struct vty
*vty
= NULL
;
644 json_object
*json
= NULL
;
645 struct zebra_l3vni
*zl3vni
= NULL
;
647 vty
= (struct vty
*)args
[0];
648 json
= (struct json_object
*)args
[1];
650 zl3vni
= (struct zebra_l3vni
*)bucket
->data
;
652 zl3vni_print_nh_all_table(zl3vni
->nh_table
, zl3vni
->vni
, vty
, json
);
655 static void zl3vni_print_rmac_hash_all_vni(struct hash_bucket
*bucket
,
658 struct vty
*vty
= NULL
;
659 json_object
*json
= NULL
;
660 json_object
*json_evpn
= NULL
;
661 struct zebra_l3vni
*zl3vni
= NULL
;
663 struct rmac_walk_ctx wctx
;
664 char vni_str
[VNI_STR_LEN
];
666 vty
= (struct vty
*)args
[0];
667 json
= (struct json_object
*)args
[1];
669 zl3vni
= (struct zebra_l3vni
*)bucket
->data
;
671 num_rmacs
= hashcount(zl3vni
->rmac_table
);
676 json_evpn
= json_object_new_object();
677 snprintf(vni_str
, VNI_STR_LEN
, "%u", zl3vni
->vni
);
681 vty_out(vty
, "\nVNI %u #RMACs %u\n\n", zl3vni
->vni
, num_rmacs
);
682 vty_out(vty
, "%-17s %-21s\n", "RMAC", "Remote VTEP");
684 json_object_int_add(json_evpn
, "numRmacs", num_rmacs
);
686 /* assign per-vni to wctx->json object to fill macs
687 * under the vni. Re-assign primary json object to fill
688 * next vni information.
690 memset(&wctx
, 0, sizeof(wctx
));
692 wctx
.json
= json_evpn
;
693 hash_iterate(zl3vni
->rmac_table
, zl3vni_print_rmac_hash
, &wctx
);
695 json_object_object_add(json
, vni_str
, json_evpn
);
698 static void zl3vni_print_rmac_hash(struct hash_bucket
*bucket
, void *ctx
)
700 struct zebra_mac
*zrmac
= NULL
;
701 struct rmac_walk_ctx
*wctx
= NULL
;
702 struct vty
*vty
= NULL
;
703 struct json_object
*json
= NULL
;
704 struct json_object
*json_rmac
= NULL
;
705 char buf
[PREFIX_STRLEN
];
707 wctx
= (struct rmac_walk_ctx
*)ctx
;
711 json_rmac
= json_object_new_object();
712 zrmac
= (struct zebra_mac
*)bucket
->data
;
715 vty_out(vty
, "%-17s %-21pI4\n",
716 prefix_mac2str(&zrmac
->macaddr
, buf
, sizeof(buf
)),
717 &zrmac
->fwd_info
.r_vtep_ip
);
719 json_object_string_add(
720 json_rmac
, "routerMac",
721 prefix_mac2str(&zrmac
->macaddr
, buf
, sizeof(buf
)));
722 json_object_string_addf(json_rmac
, "vtepIp", "%pI4",
723 &zrmac
->fwd_info
.r_vtep_ip
);
724 json_object_object_add(
725 json
, prefix_mac2str(&zrmac
->macaddr
, buf
, sizeof(buf
)),
730 /* print a specific L3 VNI entry */
731 static void zl3vni_print(struct zebra_l3vni
*zl3vni
, void **ctx
)
733 char buf
[PREFIX_STRLEN
];
734 struct vty
*vty
= NULL
;
735 json_object
*json
= NULL
;
736 struct zebra_evpn
*zevpn
= NULL
;
737 json_object
*json_evpn_list
= NULL
;
738 struct listnode
*node
= NULL
, *nnode
= NULL
;
744 vty_out(vty
, "VNI: %u\n", zl3vni
->vni
);
745 vty_out(vty
, " Type: %s\n", "L3");
746 vty_out(vty
, " Tenant VRF: %s\n", zl3vni_vrf_name(zl3vni
));
747 vty_out(vty
, " Vlan: %u\n", zl3vni
->vid
);
748 vty_out(vty
, " Bridge: %s\n",
749 zl3vni
->bridge_if
? zl3vni
->bridge_if
->name
: "-");
750 vty_out(vty
, " Local Vtep Ip: %pI4\n",
751 &zl3vni
->local_vtep_ip
);
752 vty_out(vty
, " Vxlan-Intf: %s\n",
753 zl3vni_vxlan_if_name(zl3vni
));
754 vty_out(vty
, " SVI-If: %s\n", zl3vni_svi_if_name(zl3vni
));
755 vty_out(vty
, " State: %s\n", zl3vni_state2str(zl3vni
));
756 vty_out(vty
, " VNI Filter: %s\n",
757 CHECK_FLAG(zl3vni
->filter
, PREFIX_ROUTES_ONLY
)
758 ? "prefix-routes-only"
760 vty_out(vty
, " System MAC: %s\n",
761 zl3vni_sysmac2str(zl3vni
, buf
, sizeof(buf
)));
762 vty_out(vty
, " Router MAC: %s\n",
763 zl3vni_rmac2str(zl3vni
, buf
, sizeof(buf
)));
764 vty_out(vty
, " L2 VNIs: ");
765 for (ALL_LIST_ELEMENTS(zl3vni
->l2vnis
, node
, nnode
, zevpn
))
766 vty_out(vty
, "%u ", zevpn
->vni
);
769 json_evpn_list
= json_object_new_array();
770 json_object_int_add(json
, "vni", zl3vni
->vni
);
771 json_object_string_add(json
, "type", "L3");
772 #if CONFDATE > 20240210
773 CPP_NOTICE("Drop `vrf` from JSON outputs")
775 json_object_string_add(json
, "vrf", zl3vni_vrf_name(zl3vni
));
776 json_object_string_add(json
, "tenantVrf",
777 zl3vni_vrf_name(zl3vni
));
778 json_object_string_addf(json
, "localVtepIp", "%pI4",
779 &zl3vni
->local_vtep_ip
);
780 json_object_string_add(json
, "vxlanIntf",
781 zl3vni_vxlan_if_name(zl3vni
));
782 json_object_string_add(json
, "sviIntf",
783 zl3vni_svi_if_name(zl3vni
));
784 json_object_string_add(json
, "state", zl3vni_state2str(zl3vni
));
785 json_object_string_add(
787 zl3vni_sysmac2str(zl3vni
, buf
, sizeof(buf
)));
788 json_object_string_add(
790 zl3vni_rmac2str(zl3vni
, buf
, sizeof(buf
)));
791 json_object_string_add(
793 CHECK_FLAG(zl3vni
->filter
, PREFIX_ROUTES_ONLY
)
794 ? "prefix-routes-only"
796 for (ALL_LIST_ELEMENTS(zl3vni
->l2vnis
, node
, nnode
, zevpn
)) {
797 json_object_array_add(json_evpn_list
,
798 json_object_new_int(zevpn
->vni
));
800 json_object_object_add(json
, "l2Vnis", json_evpn_list
);
804 /* print a L3 VNI hash entry */
805 static void zl3vni_print_hash(struct hash_bucket
*bucket
, void *ctx
[])
807 struct vty
*vty
= NULL
;
808 json_object
*json
= NULL
;
809 json_object
*json_evpn
= NULL
;
810 struct zebra_l3vni
*zl3vni
= NULL
;
812 vty
= (struct vty
*)ctx
[0];
813 json
= (json_object
*)ctx
[1];
815 zl3vni
= (struct zebra_l3vni
*)bucket
->data
;
818 vty_out(vty
, "%-10u %-4s %-21s %-8lu %-8lu %-15s %-37s\n",
819 zl3vni
->vni
, "L3", zl3vni_vxlan_if_name(zl3vni
),
820 hashcount(zl3vni
->rmac_table
),
821 hashcount(zl3vni
->nh_table
), "n/a",
822 zl3vni_vrf_name(zl3vni
));
824 char vni_str
[VNI_STR_LEN
];
826 snprintf(vni_str
, VNI_STR_LEN
, "%u", zl3vni
->vni
);
827 json_evpn
= json_object_new_object();
828 json_object_int_add(json_evpn
, "vni", zl3vni
->vni
);
829 json_object_string_add(json_evpn
, "vxlanIf",
830 zl3vni_vxlan_if_name(zl3vni
));
831 json_object_int_add(json_evpn
, "numMacs",
832 hashcount(zl3vni
->rmac_table
));
833 json_object_int_add(json_evpn
, "numArpNd",
834 hashcount(zl3vni
->nh_table
));
835 json_object_string_add(json_evpn
, "numRemoteVteps", "n/a");
836 json_object_string_add(json_evpn
, "type", "L3");
837 json_object_string_add(json_evpn
, "tenantVrf",
838 zl3vni_vrf_name(zl3vni
));
839 json_object_object_add(json
, vni_str
, json_evpn
);
843 /* print a L3 VNI hash entry in detail*/
844 static void zl3vni_print_hash_detail(struct hash_bucket
*bucket
, void *data
)
846 struct vty
*vty
= NULL
;
847 struct zebra_l3vni
*zl3vni
= NULL
;
848 json_object
*json_array
= NULL
;
849 bool use_json
= false;
850 struct zebra_evpn_show
*zes
= data
;
853 json_array
= zes
->json
;
854 use_json
= zes
->use_json
;
856 zl3vni
= (struct zebra_l3vni
*)bucket
->data
;
858 zebra_vxlan_print_vni(vty
, zes
->zvrf
, zl3vni
->vni
,
859 use_json
, json_array
);
865 static int zvni_map_to_svi_ns(struct ns
*ns
,
869 struct zebra_ns
*zns
= ns
->info
;
870 struct route_node
*rn
;
871 struct zebra_from_svi_param
*in_param
=
872 (struct zebra_from_svi_param
*)_in_param
;
873 struct zebra_l2info_vlan
*vl
;
874 struct interface
*tmp_if
= NULL
;
875 struct interface
**p_ifp
= (struct interface
**)_p_ifp
;
876 struct zebra_if
*zif
;
878 assert(in_param
&& p_ifp
);
880 /* TODO: Optimize with a hash. */
881 for (rn
= route_top(zns
->if_table
); rn
; rn
= route_next(rn
)) {
882 tmp_if
= (struct interface
*)rn
->info
;
883 /* Check oper status of the SVI. */
884 if (!tmp_if
|| !if_is_operative(tmp_if
))
887 if (!zif
|| zif
->zif_type
!= ZEBRA_IF_VLAN
888 || zif
->link
!= in_param
->br_if
)
890 vl
= (struct zebra_l2info_vlan
*)&zif
->l2info
.vl
;
892 if (vl
->vid
== in_param
->vid
) {
897 return NS_WALK_CONTINUE
;
900 /* Map to SVI on bridge corresponding to specified VLAN. This can be one
902 * (a) In the case of a VLAN-aware bridge, the SVI is a L3 VLAN interface
903 * linked to the bridge
904 * (b) In the case of a VLAN-unaware bridge, the SVI is the bridge interface
907 struct interface
*zvni_map_to_svi(vlanid_t vid
, struct interface
*br_if
)
909 struct interface
*tmp_if
= NULL
;
910 struct zebra_if
*zif
;
911 struct zebra_from_svi_param in_param
;
912 struct interface
**p_ifp
;
913 /* Defensive check, caller expected to invoke only with valid bridge. */
917 /* Determine if bridge is VLAN-aware or not */
920 in_param
.bridge_vlan_aware
= IS_ZEBRA_IF_BRIDGE_VLAN_AWARE(zif
);
921 /* Check oper status of the SVI. */
922 if (!in_param
.bridge_vlan_aware
)
923 return if_is_operative(br_if
) ? br_if
: NULL
;
926 in_param
.br_if
= br_if
;
929 /* Identify corresponding VLAN interface. */
930 ns_walk_func(zvni_map_to_svi_ns
, (void *)&in_param
,
935 int zebra_evpn_vxlan_del(struct zebra_evpn
*zevpn
)
938 zevpn_vxlan_if_set(zevpn
, zevpn
->vxlan_if
, false /* set */);
939 zevpn_bridge_if_set(zevpn
, zevpn
->bridge_if
, false /* set */);
941 /* Remove references to the BUM mcast grp */
942 zebra_vxlan_sg_deref(zevpn
->local_vtep_ip
, zevpn
->mcast_grp
);
944 return zebra_evpn_del(zevpn
);
947 static int zevpn_build_vni_hash_table(struct zebra_if
*zif
,
948 struct zebra_vxlan_vni
*vnip
, void *arg
)
951 struct zebra_evpn
*zevpn
;
952 struct zebra_l3vni
*zl3vni
;
953 struct interface
*ifp
;
954 struct zebra_l2info_vxlan
*vxl
;
955 struct interface
*br_if
;
958 vxl
= &zif
->l2info
.vxl
;
961 if (IS_ZEBRA_DEBUG_VXLAN
)
962 zlog_debug("Build vni table for vni %u for Intf %s", vni
,
965 /* L3-VNI and L2-VNI are handled seperately */
966 zl3vni
= zl3vni_lookup(vni
);
969 if (IS_ZEBRA_DEBUG_VXLAN
)
971 "create L3-VNI hash for Intf %s(%u) L3-VNI %u",
972 ifp
->name
, ifp
->ifindex
, vni
);
974 /* associate with vxlan_if */
975 zl3vni
->local_vtep_ip
= vxl
->vtep_ip
;
976 zl3vni
->vxlan_if
= ifp
;
979 * we need to associate with SVI.
980 * we can associate with svi-if only after association
981 * with vxlan-intf is complete
983 zl3vni
->svi_if
= zl3vni_map_to_svi_if(zl3vni
);
985 /* Associate l3vni to mac-vlan and extract VRR MAC */
986 zl3vni
->mac_vlan_if
= zl3vni_map_to_mac_vlan_if(zl3vni
);
988 if (IS_ZEBRA_DEBUG_VXLAN
)
990 "create l3vni %u svi_if %s mac_vlan_if %s", vni
,
991 zl3vni
->svi_if
? zl3vni
->svi_if
->name
: "NIL",
992 zl3vni
->mac_vlan_if
? zl3vni
->mac_vlan_if
->name
995 if (is_l3vni_oper_up(zl3vni
))
996 zebra_vxlan_process_l3vni_oper_up(zl3vni
);
999 struct interface
*vlan_if
= NULL
;
1001 if (IS_ZEBRA_DEBUG_VXLAN
)
1003 "Create L2-VNI hash for intf %s(%u) L2-VNI %u local IP %pI4",
1004 ifp
->name
, ifp
->ifindex
, vni
, &vxl
->vtep_ip
);
1007 * EVPN hash entry is expected to exist, if the BGP process is
1010 zevpn
= zebra_evpn_lookup(vni
);
1013 "EVPN hash already present for IF %s(%u) L2-VNI %u",
1014 ifp
->name
, ifp
->ifindex
, vni
);
1017 * Inform BGP if intf is up and mapped to
1020 if (if_is_operative(ifp
) && zif
->brslave_info
.br_if
)
1021 zebra_evpn_send_add_to_client(zevpn
);
1023 /* Send Local MAC-entries to client */
1024 zebra_evpn_send_mac_list_to_client(zevpn
);
1026 /* Send Loval Neighbor entries to client */
1027 zebra_evpn_send_neigh_to_client(zevpn
);
1029 zevpn
= zebra_evpn_add(vni
);
1032 "Failed to add EVPN hash, IF %s(%u) L2-VNI %u",
1033 ifp
->name
, ifp
->ifindex
, vni
);
1037 if (zevpn
->local_vtep_ip
.s_addr
!=
1038 vxl
->vtep_ip
.s_addr
||
1039 zevpn
->mcast_grp
.s_addr
!= vnip
->mcast_grp
.s_addr
) {
1040 zebra_vxlan_sg_deref(zevpn
->local_vtep_ip
,
1042 zebra_vxlan_sg_ref(vxl
->vtep_ip
,
1044 zevpn
->local_vtep_ip
= vxl
->vtep_ip
;
1045 zevpn
->mcast_grp
= vnip
->mcast_grp
;
1046 /* on local vtep-ip check if ES
1047 * orig-ip needs to be updated
1049 zebra_evpn_es_set_base_evpn(zevpn
);
1051 zevpn_vxlan_if_set(zevpn
, ifp
, true /* set */);
1052 br_if
= zif
->brslave_info
.br_if
;
1053 zevpn_bridge_if_set(zevpn
, br_if
, true /* set */);
1054 vlan_if
= zvni_map_to_svi(vnip
->access_vlan
, br_if
);
1056 zevpn
->vid
= vnip
->access_vlan
;
1057 zevpn
->svi_if
= vlan_if
;
1058 zevpn
->vrf_id
= vlan_if
->vrf
->vrf_id
;
1059 zl3vni
= zl3vni_from_vrf(vlan_if
->vrf
->vrf_id
);
1061 listnode_add_sort(zl3vni
->l2vnis
,
1066 * Inform BGP if intf is up and mapped to
1069 if (if_is_operative(ifp
) && zif
->brslave_info
.br_if
)
1070 zebra_evpn_send_add_to_client(zevpn
);
1077 static int zevpn_build_hash_table_zns(struct ns
*ns
,
1078 void *param_in
__attribute__((unused
)),
1079 void **param_out
__attribute__((unused
)))
1081 struct zebra_ns
*zns
= ns
->info
;
1082 struct route_node
*rn
;
1083 struct interface
*ifp
;
1084 struct zebra_vrf
*zvrf
;
1086 zvrf
= zebra_vrf_get_evpn();
1088 /* Walk VxLAN interfaces and create EVPN hash. */
1089 for (rn
= route_top(zns
->if_table
); rn
; rn
= route_next(rn
)) {
1090 struct zebra_if
*zif
;
1091 struct zebra_l2info_vxlan
*vxl
;
1093 ifp
= (struct interface
*)rn
->info
;
1097 if (!zif
|| zif
->zif_type
!= ZEBRA_IF_VXLAN
)
1100 vxl
= &zif
->l2info
.vxl
;
1101 /* link of VXLAN interface should be in zebra_evpn_vrf */
1102 if (zvrf
->zns
->ns_id
!= vxl
->link_nsid
) {
1103 if (IS_ZEBRA_DEBUG_VXLAN
)
1105 "Intf %s(%u) link not in same "
1106 "namespace than BGP EVPN core instance ",
1107 ifp
->name
, ifp
->ifindex
);
1111 if (IS_ZEBRA_DEBUG_VXLAN
)
1112 zlog_debug("Building vni table for %s-if %s",
1113 IS_ZEBRA_VXLAN_IF_VNI(zif
) ? "vni" : "svd",
1116 zebra_vxlan_if_vni_iterate(zif
, zevpn_build_vni_hash_table
,
1119 return NS_WALK_CONTINUE
;
1123 * Build the VNI hash table by going over the VxLAN interfaces. This
1124 * is called when EVPN (advertise-all-vni) is enabled.
1127 static void zevpn_build_hash_table(void)
1129 ns_walk_func(zevpn_build_hash_table_zns
, NULL
, NULL
);
1133 * Cleanup EVPN/VTEP and update kernel
1135 static void zebra_evpn_vxlan_cleanup_all(struct hash_bucket
*bucket
, void *arg
)
1137 struct zebra_evpn
*zevpn
= NULL
;
1138 struct zebra_l3vni
*zl3vni
= NULL
;
1140 zevpn
= (struct zebra_evpn
*)bucket
->data
;
1142 /* remove l2vni from l2vni's tenant-vrf l3-vni list */
1143 zl3vni
= zl3vni_from_vrf(zevpn
->vrf_id
);
1145 listnode_delete(zl3vni
->l2vnis
, zevpn
);
1147 zebra_evpn_cleanup_all(bucket
, arg
);
1151 static void zl3vni_cleanup_all(struct hash_bucket
*bucket
, void *args
)
1153 struct zebra_l3vni
*zl3vni
= NULL
;
1155 zl3vni
= (struct zebra_l3vni
*)bucket
->data
;
1157 zebra_vxlan_process_l3vni_oper_down(zl3vni
);
1160 static void rb_find_or_add_host(struct host_rb_tree_entry
*hrbe
,
1161 const struct prefix
*host
)
1163 struct host_rb_entry lookup
;
1164 struct host_rb_entry
*hle
;
1166 memset(&lookup
, 0, sizeof(lookup
));
1167 memcpy(&lookup
.p
, host
, sizeof(*host
));
1169 hle
= RB_FIND(host_rb_tree_entry
, hrbe
, &lookup
);
1173 hle
= XCALLOC(MTYPE_HOST_PREFIX
, sizeof(struct host_rb_entry
));
1174 memcpy(hle
, &lookup
, sizeof(lookup
));
1176 RB_INSERT(host_rb_tree_entry
, hrbe
, hle
);
1179 static void rb_delete_host(struct host_rb_tree_entry
*hrbe
, struct prefix
*host
)
1181 struct host_rb_entry lookup
;
1182 struct host_rb_entry
*hle
;
1184 memset(&lookup
, 0, sizeof(lookup
));
1185 memcpy(&lookup
.p
, host
, sizeof(*host
));
1187 hle
= RB_FIND(host_rb_tree_entry
, hrbe
, &lookup
);
1189 RB_REMOVE(host_rb_tree_entry
, hrbe
, hle
);
1190 XFREE(MTYPE_HOST_PREFIX
, hle
);
1197 * Look up MAC hash entry.
1199 static struct zebra_mac
*zl3vni_rmac_lookup(struct zebra_l3vni
*zl3vni
,
1200 const struct ethaddr
*rmac
)
1202 struct zebra_mac tmp
;
1203 struct zebra_mac
*pmac
;
1205 memset(&tmp
, 0, sizeof(tmp
));
1206 memcpy(&tmp
.macaddr
, rmac
, ETH_ALEN
);
1207 pmac
= hash_lookup(zl3vni
->rmac_table
, &tmp
);
1213 * Callback to allocate RMAC hash entry.
1215 static void *zl3vni_rmac_alloc(void *p
)
1217 const struct zebra_mac
*tmp_rmac
= p
;
1218 struct zebra_mac
*zrmac
;
1220 zrmac
= XCALLOC(MTYPE_L3VNI_MAC
, sizeof(struct zebra_mac
));
1223 return ((void *)zrmac
);
1227 * Add RMAC entry to l3-vni
1229 static struct zebra_mac
*zl3vni_rmac_add(struct zebra_l3vni
*zl3vni
,
1230 const struct ethaddr
*rmac
)
1232 struct zebra_mac tmp_rmac
;
1233 struct zebra_mac
*zrmac
= NULL
;
1235 memset(&tmp_rmac
, 0, sizeof(tmp_rmac
));
1236 memcpy(&tmp_rmac
.macaddr
, rmac
, ETH_ALEN
);
1237 zrmac
= hash_get(zl3vni
->rmac_table
, &tmp_rmac
, zl3vni_rmac_alloc
);
1238 zrmac
->nh_list
= list_new();
1239 zrmac
->nh_list
->cmp
= (int (*)(void *, void *))l3vni_rmac_nh_list_cmp
;
1240 zrmac
->nh_list
->del
= (void (*)(void *))l3vni_rmac_nh_free
;
1242 SET_FLAG(zrmac
->flags
, ZEBRA_MAC_REMOTE
);
1243 SET_FLAG(zrmac
->flags
, ZEBRA_MAC_REMOTE_RMAC
);
1251 static int zl3vni_rmac_del(struct zebra_l3vni
*zl3vni
, struct zebra_mac
*zrmac
)
1253 struct zebra_mac
*tmp_rmac
;
1255 /* free the list of nh list*/
1256 list_delete(&zrmac
->nh_list
);
1258 tmp_rmac
= hash_release(zl3vni
->rmac_table
, zrmac
);
1259 XFREE(MTYPE_L3VNI_MAC
, tmp_rmac
);
1265 * Install remote RMAC into the forwarding plane.
1267 static int zl3vni_rmac_install(struct zebra_l3vni
*zl3vni
,
1268 struct zebra_mac
*zrmac
)
1270 const struct zebra_if
*zif
= NULL
, *br_zif
= NULL
;
1271 const struct zebra_vxlan_vni
*vni
;
1272 const struct interface
*br_ifp
;
1273 enum zebra_dplane_result res
;
1276 if (!(CHECK_FLAG(zrmac
->flags
, ZEBRA_MAC_REMOTE
))
1277 || !(CHECK_FLAG(zrmac
->flags
, ZEBRA_MAC_REMOTE_RMAC
)))
1280 zif
= zl3vni
->vxlan_if
->info
;
1284 br_ifp
= zif
->brslave_info
.br_if
;
1288 vni
= zebra_vxlan_if_vni_find(zif
, zl3vni
->vni
);
1290 br_zif
= (const struct zebra_if
*)br_ifp
->info
;
1292 if (IS_ZEBRA_IF_BRIDGE_VLAN_AWARE(br_zif
))
1293 vid
= vni
->access_vlan
;
1297 res
= dplane_rem_mac_add(zl3vni
->vxlan_if
, br_ifp
, vid
, &zrmac
->macaddr
,
1298 vni
->vni
, zrmac
->fwd_info
.r_vtep_ip
, 0, 0,
1299 false /*was_static*/);
1300 if (res
!= ZEBRA_DPLANE_REQUEST_FAILURE
)
1307 * Uninstall remote RMAC from the forwarding plane.
1309 static int zl3vni_rmac_uninstall(struct zebra_l3vni
*zl3vni
,
1310 struct zebra_mac
*zrmac
)
1312 const struct zebra_if
*zif
= NULL
, *br_zif
;
1313 const struct zebra_vxlan_vni
*vni
;
1314 const struct interface
*br_ifp
;
1316 enum zebra_dplane_result res
;
1318 if (!(CHECK_FLAG(zrmac
->flags
, ZEBRA_MAC_REMOTE
))
1319 || !(CHECK_FLAG(zrmac
->flags
, ZEBRA_MAC_REMOTE_RMAC
)))
1322 if (!zl3vni
->vxlan_if
) {
1323 if (IS_ZEBRA_DEBUG_VXLAN
)
1325 "RMAC %pEA on L3-VNI %u hash %p couldn't be uninstalled - no vxlan_if",
1326 &zrmac
->macaddr
, zl3vni
->vni
, zl3vni
);
1330 zif
= zl3vni
->vxlan_if
->info
;
1334 br_ifp
= zif
->brslave_info
.br_if
;
1338 vni
= zebra_vxlan_if_vni_find(zif
, zl3vni
->vni
);
1340 br_zif
= (const struct zebra_if
*)br_ifp
->info
;
1341 if (IS_ZEBRA_IF_BRIDGE_VLAN_AWARE(br_zif
))
1342 vid
= vni
->access_vlan
;
1346 res
= dplane_rem_mac_del(zl3vni
->vxlan_if
, br_ifp
, vid
, &zrmac
->macaddr
,
1347 vni
->vni
, zrmac
->fwd_info
.r_vtep_ip
);
1348 if (res
!= ZEBRA_DPLANE_REQUEST_FAILURE
)
1354 /* handle rmac add */
1355 static int zl3vni_remote_rmac_add(struct zebra_l3vni
*zl3vni
,
1356 const struct ethaddr
*rmac
,
1357 const struct ipaddr
*vtep_ip
)
1359 struct zebra_mac
*zrmac
= NULL
;
1360 struct ipaddr
*vtep
= NULL
;
1362 zrmac
= zl3vni_rmac_lookup(zl3vni
, rmac
);
1365 /* Create the RMAC entry, or update its vtep, if necessary. */
1366 zrmac
= zl3vni_rmac_add(zl3vni
, rmac
);
1369 "Failed to add RMAC %pEA L3VNI %u Remote VTEP %pIA",
1370 rmac
, zl3vni
->vni
, vtep_ip
);
1373 memset(&zrmac
->fwd_info
, 0, sizeof(zrmac
->fwd_info
));
1374 zrmac
->fwd_info
.r_vtep_ip
= vtep_ip
->ipaddr_v4
;
1376 vtep
= XCALLOC(MTYPE_EVPN_VTEP
, sizeof(struct ipaddr
));
1377 memcpy(vtep
, vtep_ip
, sizeof(struct ipaddr
));
1378 if (!listnode_add_sort_nodup(zrmac
->nh_list
, (void *)vtep
))
1379 XFREE(MTYPE_EVPN_VTEP
, vtep
);
1381 /* Send RMAC for FPM processing */
1382 hook_call(zebra_rmac_update
, zrmac
, zl3vni
, false,
1385 /* install rmac in kernel */
1386 zl3vni_rmac_install(zl3vni
, zrmac
);
1387 } else if (!IPV4_ADDR_SAME(&zrmac
->fwd_info
.r_vtep_ip
,
1388 &vtep_ip
->ipaddr_v4
)) {
1389 if (IS_ZEBRA_DEBUG_VXLAN
)
1391 "L3VNI %u Remote VTEP change(%pI4 -> %pIA) for RMAC %pEA",
1392 zl3vni
->vni
, &zrmac
->fwd_info
.r_vtep_ip
,
1395 zrmac
->fwd_info
.r_vtep_ip
= vtep_ip
->ipaddr_v4
;
1397 vtep
= XCALLOC(MTYPE_EVPN_VTEP
, sizeof(struct ipaddr
));
1398 memcpy(vtep
, vtep_ip
, sizeof(struct ipaddr
));
1399 if (!listnode_add_sort_nodup(zrmac
->nh_list
, (void *)vtep
))
1400 XFREE(MTYPE_EVPN_VTEP
, vtep
);
1402 /* install rmac in kernel */
1403 zl3vni_rmac_install(zl3vni
, zrmac
);
1410 /* handle rmac delete */
1411 static void zl3vni_remote_rmac_del(struct zebra_l3vni
*zl3vni
,
1412 struct zebra_mac
*zrmac
,
1413 struct ipaddr
*vtep_ip
)
1415 struct ipaddr ipv4_vtep
;
1417 if (!zl3vni_nh_lookup(zl3vni
, vtep_ip
)) {
1418 memset(&ipv4_vtep
, 0, sizeof(ipv4_vtep
));
1419 ipv4_vtep
.ipa_type
= IPADDR_V4
;
1420 if (vtep_ip
->ipa_type
== IPADDR_V6
)
1421 ipv4_mapped_ipv6_to_ipv4(&vtep_ip
->ipaddr_v6
,
1422 &ipv4_vtep
.ipaddr_v4
);
1424 memcpy(&(ipv4_vtep
.ipaddr_v4
), &vtep_ip
->ipaddr_v4
,
1425 sizeof(struct in_addr
));
1427 /* remove nh from rmac's list */
1428 l3vni_rmac_nh_list_nh_delete(zl3vni
, zrmac
, &ipv4_vtep
);
1429 /* delete nh is same as current selected, fall back to
1430 * one present in the list
1432 if (IPV4_ADDR_SAME(&zrmac
->fwd_info
.r_vtep_ip
,
1433 &ipv4_vtep
.ipaddr_v4
) &&
1434 listcount(zrmac
->nh_list
)) {
1435 struct ipaddr
*vtep
;
1437 vtep
= listgetdata(listhead(zrmac
->nh_list
));
1438 zrmac
->fwd_info
.r_vtep_ip
= vtep
->ipaddr_v4
;
1439 if (IS_ZEBRA_DEBUG_VXLAN
)
1441 "L3VNI %u Remote VTEP nh change(%pIA -> %pI4) for RMAC %pEA",
1442 zl3vni
->vni
, &ipv4_vtep
,
1443 &zrmac
->fwd_info
.r_vtep_ip
,
1446 /* install rmac in kernel */
1447 zl3vni_rmac_install(zl3vni
, zrmac
);
1450 if (!listcount(zrmac
->nh_list
)) {
1451 /* uninstall from kernel */
1452 zl3vni_rmac_uninstall(zl3vni
, zrmac
);
1454 /* Send RMAC for FPM processing */
1455 hook_call(zebra_rmac_update
, zrmac
, zl3vni
, true,
1458 if (IS_ZEBRA_DEBUG_VXLAN
)
1460 "L3VNI %u RMAC %pEA vtep_ip %pIA delete",
1461 zl3vni
->vni
, &zrmac
->macaddr
, vtep_ip
);
1463 /* del the rmac entry */
1464 zl3vni_rmac_del(zl3vni
, zrmac
);
1470 * Common code for look up of nh hash entry.
1472 static struct zebra_neigh
*_nh_lookup(struct zebra_l3vni
*zl3vni
,
1473 const struct ipaddr
*ip
)
1475 struct zebra_neigh tmp
;
1476 struct zebra_neigh
*n
;
1478 memset(&tmp
, 0, sizeof(tmp
));
1479 memcpy(&tmp
.ip
, ip
, sizeof(struct ipaddr
));
1482 n
= hash_lookup(zl3vni
->nh_table
, &tmp
);
1484 n
= hash_lookup(svd_nh_table
, &tmp
);
1490 * Look up nh hash entry on a l3-vni.
1492 static struct zebra_neigh
*zl3vni_nh_lookup(struct zebra_l3vni
*zl3vni
,
1493 const struct ipaddr
*ip
)
1495 return _nh_lookup(zl3vni
, ip
);
1499 * Look up nh hash entry on a SVD.
1501 static struct zebra_neigh
*svd_nh_lookup(const struct ipaddr
*ip
)
1503 return _nh_lookup(NULL
, ip
);
1507 * Callback to allocate NH hash entry on L3-VNI.
1509 static void *zl3vni_nh_alloc(void *p
)
1511 const struct zebra_neigh
*tmp_n
= p
;
1512 struct zebra_neigh
*n
;
1514 n
= XCALLOC(MTYPE_L3NEIGH
, sizeof(struct zebra_neigh
));
1521 * Common code for neigh add.
1523 static struct zebra_neigh
*_nh_add(struct zebra_l3vni
*zl3vni
,
1524 const struct ipaddr
*ip
,
1525 const struct ethaddr
*mac
)
1527 struct zebra_neigh tmp_n
;
1528 struct zebra_neigh
*n
= NULL
;
1530 memset(&tmp_n
, 0, sizeof(tmp_n
));
1531 memcpy(&tmp_n
.ip
, ip
, sizeof(struct ipaddr
));
1534 n
= hash_get(zl3vni
->nh_table
, &tmp_n
, zl3vni_nh_alloc
);
1536 n
= hash_get(svd_nh_table
, &tmp_n
, zl3vni_nh_alloc
);
1540 RB_INIT(host_rb_tree_entry
, &n
->host_rb
);
1542 memcpy(&n
->emac
, mac
, ETH_ALEN
);
1543 SET_FLAG(n
->flags
, ZEBRA_NEIGH_REMOTE
);
1544 SET_FLAG(n
->flags
, ZEBRA_NEIGH_REMOTE_NH
);
1550 * Add neighbor entry.
1552 static struct zebra_neigh
*zl3vni_nh_add(struct zebra_l3vni
*zl3vni
,
1553 const struct ipaddr
*ip
,
1554 const struct ethaddr
*mac
)
1556 return _nh_add(zl3vni
, ip
, mac
);
1560 * Delete neighbor entry.
1562 static int zl3vni_nh_del(struct zebra_l3vni
*zl3vni
, struct zebra_neigh
*n
)
1564 struct zebra_neigh
*tmp_n
;
1565 struct host_rb_entry
*hle
;
1567 while (!RB_EMPTY(host_rb_tree_entry
, &n
->host_rb
)) {
1568 hle
= RB_ROOT(host_rb_tree_entry
, &n
->host_rb
);
1570 RB_REMOVE(host_rb_tree_entry
, &n
->host_rb
, hle
);
1571 XFREE(MTYPE_HOST_PREFIX
, hle
);
1574 tmp_n
= hash_release(zl3vni
->nh_table
, n
);
1575 XFREE(MTYPE_L3NEIGH
, tmp_n
);
1581 * Add Single VXlan Device neighbor entry.
1583 static struct zebra_neigh
*svd_nh_add(const struct ipaddr
*ip
,
1584 const struct ethaddr
*mac
)
1586 return _nh_add(NULL
, ip
, mac
);
1590 * Del Single VXlan Device neighbor entry.
1592 static int svd_nh_del(struct zebra_neigh
*n
)
1597 hash_release(svd_nh_table
, n
);
1598 XFREE(MTYPE_L3NEIGH
, n
);
1604 * Common code to install remote nh as neigh into the kernel.
1606 static int _nh_install(struct zebra_l3vni
*zl3vni
, struct interface
*ifp
,
1607 struct zebra_neigh
*n
)
1612 if (zl3vni
&& !is_l3vni_oper_up(zl3vni
))
1615 if (!(n
->flags
& ZEBRA_NEIGH_REMOTE
)
1616 || !(n
->flags
& ZEBRA_NEIGH_REMOTE_NH
))
1619 flags
= DPLANE_NTF_EXT_LEARNED
;
1620 if (n
->flags
& ZEBRA_NEIGH_ROUTER_FLAG
)
1621 flags
|= DPLANE_NTF_ROUTER
;
1623 dplane_rem_neigh_add(ifp
, &n
->ip
, &n
->emac
, flags
,
1624 false /*was_static*/);
1630 * Common code to uninstall remote nh from the kernel.
1632 static int _nh_uninstall(struct interface
*ifp
, struct zebra_neigh
*n
)
1634 if (!(n
->flags
& ZEBRA_NEIGH_REMOTE
)
1635 || !(n
->flags
& ZEBRA_NEIGH_REMOTE_NH
))
1638 if (!ifp
|| !if_is_operative(ifp
))
1641 dplane_rem_neigh_delete(ifp
, &n
->ip
);
1647 * Install remote nh as neigh into the kernel.
1649 static int zl3vni_nh_install(struct zebra_l3vni
*zl3vni
, struct zebra_neigh
*n
)
1651 return _nh_install(zl3vni
, zl3vni
->svi_if
, n
);
1655 * Uninstall remote nh from the kernel.
1657 static int zl3vni_nh_uninstall(struct zebra_l3vni
*zl3vni
,
1658 struct zebra_neigh
*n
)
1660 return _nh_uninstall(zl3vni
->svi_if
, n
);
1664 * Install SVD remote nh as neigh into the kernel.
1666 static int svd_nh_install(struct zebra_l3vni
*zl3vni
, struct zebra_neigh
*n
)
1668 return _nh_install(zl3vni
, zl3vni
->vxlan_if
, n
);
1672 * Uninstall SVD remote nh from the kernel.
1674 static int svd_nh_uninstall(struct zebra_l3vni
*zl3vni
, struct zebra_neigh
*n
)
1676 return _nh_uninstall(zl3vni
->vxlan_if
, n
);
1679 /* Add remote vtep as a neigh entry */
1680 static int zl3vni_remote_nh_add(struct zebra_l3vni
*zl3vni
,
1681 const struct ipaddr
*vtep_ip
,
1682 const struct ethaddr
*rmac
,
1683 const struct prefix
*host_prefix
)
1685 struct zebra_neigh
*nh
= NULL
;
1687 /* Create the next hop entry, or update its mac, if necessary. */
1688 nh
= zl3vni_nh_lookup(zl3vni
, vtep_ip
);
1690 nh
= zl3vni_nh_add(zl3vni
, vtep_ip
, rmac
);
1693 "Failed to add NH %pIA as Neigh (RMAC %pEA L3-VNI %u prefix %pFX)",
1694 vtep_ip
, rmac
, zl3vni
->vni
, host_prefix
);
1698 /* install the nh neigh in kernel */
1699 zl3vni_nh_install(zl3vni
, nh
);
1700 } else if (memcmp(&nh
->emac
, rmac
, ETH_ALEN
) != 0) {
1701 if (IS_ZEBRA_DEBUG_VXLAN
)
1703 "L3VNI %u RMAC change(%pEA --> %pEA) for nexthop %pIA, prefix %pFX",
1704 zl3vni
->vni
, &nh
->emac
, rmac
, vtep_ip
,
1707 memcpy(&nh
->emac
, rmac
, ETH_ALEN
);
1708 /* install (update) the nh neigh in kernel */
1709 zl3vni_nh_install(zl3vni
, nh
);
1712 rb_find_or_add_host(&nh
->host_rb
, host_prefix
);
1717 /* Del remote vtep as a neigh entry */
1718 static void zl3vni_remote_nh_del(struct zebra_l3vni
*zl3vni
,
1719 struct zebra_neigh
*nh
,
1720 struct prefix
*host_prefix
)
1722 rb_delete_host(&nh
->host_rb
, host_prefix
);
1724 if (RB_EMPTY(host_rb_tree_entry
, &nh
->host_rb
)) {
1725 /* uninstall from kernel */
1726 zl3vni_nh_uninstall(zl3vni
, nh
);
1728 /* delete the nh entry */
1729 zl3vni_nh_del(zl3vni
, nh
);
1733 /* Add remote vtep as a SVD neigh entry */
1734 static int svd_remote_nh_add(struct zebra_l3vni
*zl3vni
,
1735 const struct ipaddr
*vtep_ip
,
1736 const struct ethaddr
*rmac
,
1737 const struct prefix
*host_prefix
)
1739 struct zebra_neigh
*nh
= NULL
;
1741 /* SVD backed VNI check */
1742 if (!IS_ZL3VNI_SVD_BACKED(zl3vni
))
1745 /* Create the SVD next hop entry, or update its mac, if necessary. */
1746 nh
= svd_nh_lookup(vtep_ip
);
1748 nh
= svd_nh_add(vtep_ip
, rmac
);
1751 "Failed to add NH %pIA as SVD Neigh (RMAC %pEA prefix %pFX)",
1752 vtep_ip
, rmac
, host_prefix
);
1756 } else if (memcmp(&nh
->emac
, rmac
, ETH_ALEN
) != 0) {
1757 if (IS_ZEBRA_DEBUG_VXLAN
)
1759 "SVD RMAC change(%pEA --> %pEA) for nexthop %pIA, prefix %pFX",
1760 &nh
->emac
, rmac
, vtep_ip
, host_prefix
);
1762 memcpy(&nh
->emac
, rmac
, ETH_ALEN
);
1763 /* install (update) the nh neigh in kernel */
1764 svd_nh_install(zl3vni
, nh
);
1766 /* Don't increment refcnt change */
1772 if (IS_ZEBRA_DEBUG_VXLAN
)
1773 zlog_debug("SVD NH ADD refcnt (%u) for nexthop %pIA",
1774 nh
->refcnt
, vtep_ip
);
1777 * Install the nh neigh in kernel if this is the first time we
1780 if (nh
->refcnt
== 1)
1781 svd_nh_install(zl3vni
, nh
);
1786 /* Del remote vtep as a SVD neigh entry */
1787 static int svd_remote_nh_del(struct zebra_l3vni
*zl3vni
,
1788 const struct ipaddr
*vtep_ip
)
1790 struct zebra_neigh
*nh
;
1792 /* SVD backed VNI check */
1793 if (!IS_ZL3VNI_SVD_BACKED(zl3vni
))
1796 nh
= svd_nh_lookup(vtep_ip
);
1798 zlog_debug("Failed to del NH %pIA as SVD Neigh", vtep_ip
);
1805 if (IS_ZEBRA_DEBUG_VXLAN
)
1806 zlog_debug("SVD NH Del refcnt (%u) for nexthop %pIA",
1807 nh
->refcnt
, vtep_ip
);
1809 /* Last refcnt on NH, remove it completely. */
1810 if (nh
->refcnt
== 0) {
1811 svd_nh_uninstall(zl3vni
, nh
);
1818 /* handle neigh update from kernel - the only thing of interest is to
1819 * readd stale entries.
1821 static int zl3vni_local_nh_add_update(struct zebra_l3vni
*zl3vni
,
1822 struct ipaddr
*ip
, uint16_t state
)
1825 struct zebra_neigh
*n
= NULL
;
1827 n
= zl3vni_nh_lookup(zl3vni
, ip
);
1831 /* all next hop neigh are remote and installed by frr.
1832 * If the kernel has aged this entry, re-install.
1834 if (state
& NUD_STALE
)
1835 zl3vni_nh_install(zl3vni
, n
);
1840 /* handle neigh delete from kernel */
1841 static int zl3vni_local_nh_del(struct zebra_l3vni
*zl3vni
, struct ipaddr
*ip
)
1843 struct zebra_neigh
*n
= NULL
;
1845 n
= zl3vni_nh_lookup(zl3vni
, ip
);
1849 /* all next hop neigh are remote and installed by frr.
1850 * If we get an age out notification for these neigh entries, we have to
1853 zl3vni_nh_install(zl3vni
, n
);
1859 * Hash function for L3 VNI.
1861 static unsigned int l3vni_hash_keymake(const void *p
)
1863 const struct zebra_l3vni
*zl3vni
= p
;
1865 return jhash_1word(zl3vni
->vni
, 0);
1869 * Compare 2 L3 VNI hash entries.
1871 static bool l3vni_hash_cmp(const void *p1
, const void *p2
)
1873 const struct zebra_l3vni
*zl3vni1
= p1
;
1874 const struct zebra_l3vni
*zl3vni2
= p2
;
1876 return (zl3vni1
->vni
== zl3vni2
->vni
);
1880 * Callback to allocate L3 VNI hash entry.
1882 static void *zl3vni_alloc(void *p
)
1884 struct zebra_l3vni
*zl3vni
= NULL
;
1885 const struct zebra_l3vni
*tmp_l3vni
= p
;
1887 zl3vni
= XCALLOC(MTYPE_ZL3VNI
, sizeof(struct zebra_l3vni
));
1888 zl3vni
->vni
= tmp_l3vni
->vni
;
1889 return ((void *)zl3vni
);
1893 * Look up L3 VNI hash entry.
1895 struct zebra_l3vni
*zl3vni_lookup(vni_t vni
)
1897 struct zebra_l3vni tmp_l3vni
;
1898 struct zebra_l3vni
*zl3vni
= NULL
;
1900 memset(&tmp_l3vni
, 0, sizeof(tmp_l3vni
));
1901 tmp_l3vni
.vni
= vni
;
1902 zl3vni
= hash_lookup(zrouter
.l3vni_table
, &tmp_l3vni
);
1908 * Add L3 VNI hash entry.
1910 static struct zebra_l3vni
*zl3vni_add(vni_t vni
, vrf_id_t vrf_id
)
1912 struct zebra_l3vni tmp_zl3vni
;
1913 struct zebra_l3vni
*zl3vni
= NULL
;
1915 memset(&tmp_zl3vni
, 0, sizeof(tmp_zl3vni
));
1916 tmp_zl3vni
.vni
= vni
;
1918 zl3vni
= hash_get(zrouter
.l3vni_table
, &tmp_zl3vni
, zl3vni_alloc
);
1920 zl3vni
->vrf_id
= vrf_id
;
1921 zl3vni
->svi_if
= NULL
;
1922 zl3vni
->vxlan_if
= NULL
;
1923 zl3vni
->l2vnis
= list_new();
1924 zl3vni
->l2vnis
->cmp
= zebra_evpn_list_cmp
;
1926 /* Create hash table for remote RMAC */
1927 zl3vni
->rmac_table
= zebra_mac_db_create("Zebra L3-VNI RMAC-Table");
1929 /* Create hash table for neighbors */
1930 zl3vni
->nh_table
= zebra_neigh_db_create("Zebra L3-VNI next-hop table");
1936 * Delete L3 VNI hash entry.
1938 static int zl3vni_del(struct zebra_l3vni
*zl3vni
)
1940 struct zebra_l3vni
*tmp_zl3vni
;
1942 /* free the list of l2vnis */
1943 list_delete(&zl3vni
->l2vnis
);
1944 zl3vni
->l2vnis
= NULL
;
1946 /* Free the rmac table */
1947 hash_free(zl3vni
->rmac_table
);
1948 zl3vni
->rmac_table
= NULL
;
1950 /* Free the nh table */
1951 hash_free(zl3vni
->nh_table
);
1952 zl3vni
->nh_table
= NULL
;
1954 /* Free the VNI hash entry and allocated memory. */
1955 tmp_zl3vni
= hash_release(zrouter
.l3vni_table
, zl3vni
);
1956 XFREE(MTYPE_ZL3VNI
, tmp_zl3vni
);
1961 static int zl3vni_map_to_vxlan_if_ns(struct ns
*ns
,
1965 struct zebra_ns
*zns
= ns
->info
;
1966 struct zebra_l3vni
*zl3vni
= (struct zebra_l3vni
*)_zl3vni
;
1967 struct route_node
*rn
= NULL
;
1968 struct interface
*ifp
= NULL
;
1969 struct zebra_vrf
*zvrf
;
1971 zvrf
= zebra_vrf_get_evpn();
1975 /* loop through all vxlan-interface */
1976 for (rn
= route_top(zns
->if_table
); rn
; rn
= route_next(rn
)) {
1978 struct zebra_if
*zif
= NULL
;
1979 struct zebra_l2info_vxlan
*vxl
;
1980 struct zebra_vxlan_vni
*vni
= NULL
;
1982 ifp
= (struct interface
*)rn
->info
;
1987 if (!zif
|| zif
->zif_type
!= ZEBRA_IF_VXLAN
)
1990 vxl
= &zif
->l2info
.vxl
;
1991 vni
= zebra_vxlan_if_vni_find(zif
, zl3vni
->vni
);
1992 if (!vni
|| vni
->vni
!= zl3vni
->vni
)
1995 /* link of VXLAN interface should be in zebra_evpn_vrf */
1996 if (zvrf
->zns
->ns_id
!= vxl
->link_nsid
) {
1997 if (IS_ZEBRA_DEBUG_VXLAN
)
1999 "Intf %s(%u) VNI %u, link not in same "
2000 "namespace than BGP EVPN core instance ",
2001 ifp
->name
, ifp
->ifindex
, vni
->vni
);
2006 zl3vni
->local_vtep_ip
= zif
->l2info
.vxl
.vtep_ip
;
2007 *_pifp
= (void *)ifp
;
2008 return NS_WALK_STOP
;
2011 return NS_WALK_CONTINUE
;
2014 struct interface
*zl3vni_map_to_vxlan_if(struct zebra_l3vni
*zl3vni
)
2016 struct interface
**p_ifp
;
2017 struct interface
*ifp
= NULL
;
2021 ns_walk_func(zl3vni_map_to_vxlan_if_ns
,
2022 (void *)zl3vni
, (void **)p_ifp
);
2026 struct interface
*zl3vni_map_to_svi_if(struct zebra_l3vni
*zl3vni
)
2028 struct zebra_if
*zif
= NULL
; /* zebra_if for vxlan_if */
2029 struct zebra_vxlan_vni
*vni
= NULL
; /* vni info in vxlan_if */
2034 if (!zl3vni
->vxlan_if
)
2037 zif
= zl3vni
->vxlan_if
->info
;
2041 vni
= zebra_vxlan_if_vni_find(zif
, zl3vni
->vni
);
2045 return zvni_map_to_svi(vni
->access_vlan
, zif
->brslave_info
.br_if
);
2048 struct interface
*zl3vni_map_to_mac_vlan_if(struct zebra_l3vni
*zl3vni
)
2050 struct zebra_if
*zif
= NULL
; /* zebra_if for vxlan_if */
2055 if (!zl3vni
->vxlan_if
)
2058 zif
= zl3vni
->vxlan_if
->info
;
2062 return zebra_evpn_map_to_macvlan(zif
->brslave_info
.br_if
,
2067 struct zebra_l3vni
*zl3vni_from_vrf(vrf_id_t vrf_id
)
2069 struct zebra_vrf
*zvrf
= NULL
;
2071 zvrf
= zebra_vrf_lookup_by_id(vrf_id
);
2075 return zl3vni_lookup(zvrf
->l3vni
);
2078 static int zl3vni_from_svi_ns(struct ns
*ns
, void *_in_param
, void **_p_zl3vni
)
2082 struct zebra_ns
*zns
= ns
->info
;
2083 struct zebra_l3vni
**p_zl3vni
= (struct zebra_l3vni
**)_p_zl3vni
;
2084 struct zebra_from_svi_param
*in_param
=
2085 (struct zebra_from_svi_param
*)_in_param
;
2086 struct route_node
*rn
= NULL
;
2087 struct interface
*tmp_if
= NULL
;
2088 struct zebra_if
*zif
= NULL
;
2089 struct zebra_if
*br_zif
= NULL
;
2091 assert(in_param
&& p_zl3vni
);
2093 br_zif
= in_param
->br_if
->info
;
2096 if (in_param
->bridge_vlan_aware
) {
2097 vni_id
= zebra_l2_bridge_if_vni_find(br_zif
, in_param
->vid
);
2101 /* loop through all vxlan-interface */
2102 for (rn
= route_top(zns
->if_table
); rn
; rn
= route_next(rn
)) {
2103 tmp_if
= (struct interface
*)rn
->info
;
2107 if (!zif
|| zif
->zif_type
!= ZEBRA_IF_VXLAN
)
2109 if (!if_is_operative(tmp_if
))
2112 if (zif
->brslave_info
.br_if
!= in_param
->br_if
)
2115 vni_id
= zebra_vxlan_if_access_vlan_vni_find(
2116 zif
, in_param
->br_if
);
2125 return NS_WALK_CONTINUE
;
2127 *p_zl3vni
= zl3vni_lookup(vni_id
);
2128 return NS_WALK_STOP
;
2132 * Map SVI and associated bridge to a VNI. This is invoked upon getting
2133 * neighbor notifications, to see if they are of interest.
2135 static struct zebra_l3vni
*zl3vni_from_svi(struct interface
*ifp
,
2136 struct interface
*br_if
)
2138 struct zebra_l3vni
*zl3vni
= NULL
;
2139 struct zebra_if
*zif
= NULL
;
2140 struct zebra_from_svi_param in_param
= {};
2141 struct zebra_l3vni
**p_zl3vni
;
2146 /* Make sure the linked interface is a bridge. */
2147 if (!IS_ZEBRA_IF_BRIDGE(br_if
))
2149 in_param
.br_if
= br_if
;
2151 /* Determine if bridge is VLAN-aware or not */
2154 in_param
.bridge_vlan_aware
= IS_ZEBRA_IF_BRIDGE_VLAN_AWARE(zif
);
2155 if (in_param
.bridge_vlan_aware
) {
2156 struct zebra_l2info_vlan
*vl
;
2158 if (!IS_ZEBRA_IF_VLAN(ifp
))
2163 vl
= &zif
->l2info
.vl
;
2164 in_param
.vid
= vl
->vid
;
2167 /* See if this interface (or interface plus VLAN Id) maps to a VxLAN */
2168 /* TODO: Optimize with a hash. */
2172 ns_walk_func(zl3vni_from_svi_ns
, (void *)&in_param
, (void **)p_zl3vni
);
2176 vni_t
vni_id_from_svi(struct interface
*ifp
, struct interface
*br_if
)
2179 struct zebra_evpn
*zevpn
= NULL
;
2180 struct zebra_l3vni
*zl3vni
= NULL
;
2182 /* Check if an L3VNI belongs to this SVI interface.
2183 * If not, check if an L2VNI belongs to this SVI interface.
2185 zl3vni
= zl3vni_from_svi(ifp
, br_if
);
2189 zevpn
= zebra_evpn_from_svi(ifp
, br_if
);
2197 static inline void zl3vni_get_vrr_rmac(struct zebra_l3vni
*zl3vni
,
2198 struct ethaddr
*rmac
)
2203 if (!is_l3vni_oper_up(zl3vni
))
2206 if (zl3vni
->mac_vlan_if
&& if_is_operative(zl3vni
->mac_vlan_if
))
2207 memcpy(rmac
->octet
, zl3vni
->mac_vlan_if
->hw_addr
, ETH_ALEN
);
2211 * Inform BGP about l3-vni.
2213 static int zl3vni_send_add_to_client(struct zebra_l3vni
*zl3vni
)
2215 struct stream
*s
= NULL
;
2216 struct zserv
*client
= NULL
;
2217 struct ethaddr svi_rmac
, vrr_rmac
= {.octet
= {0} };
2218 struct zebra_vrf
*zvrf
;
2219 bool is_anycast_mac
= true;
2221 client
= zserv_find_client(ZEBRA_ROUTE_BGP
, 0);
2222 /* BGP may not be running. */
2226 zvrf
= zebra_vrf_lookup_by_id(zl3vni
->vrf_id
);
2229 /* get the svi and vrr rmac values */
2230 memset(&svi_rmac
, 0, sizeof(svi_rmac
));
2231 zl3vni_get_svi_rmac(zl3vni
, &svi_rmac
);
2232 zl3vni_get_vrr_rmac(zl3vni
, &vrr_rmac
);
2234 /* In absence of vrr mac use svi mac as anycast MAC value */
2235 if (is_zero_mac(&vrr_rmac
)) {
2236 memcpy(&vrr_rmac
, &svi_rmac
, ETH_ALEN
);
2237 is_anycast_mac
= false;
2240 s
= stream_new(ZEBRA_MAX_PACKET_SIZ
);
2242 /* The message is used for both vni add and/or update like
2243 * vrr mac is added for l3vni SVI.
2245 zclient_create_header(s
, ZEBRA_L3VNI_ADD
, zl3vni_vrf_id(zl3vni
));
2246 stream_putl(s
, zl3vni
->vni
);
2247 stream_put(s
, &svi_rmac
, sizeof(struct ethaddr
));
2248 stream_put_in_addr(s
, &zl3vni
->local_vtep_ip
);
2249 stream_put(s
, &zl3vni
->filter
, sizeof(int));
2250 stream_putl(s
, zl3vni
->svi_if
->ifindex
);
2251 stream_put(s
, &vrr_rmac
, sizeof(struct ethaddr
));
2252 stream_putl(s
, is_anycast_mac
);
2254 /* Write packet size. */
2255 stream_putw_at(s
, 0, stream_get_endp(s
));
2257 if (IS_ZEBRA_DEBUG_VXLAN
)
2259 "Send L3_VNI_ADD %u VRF %s RMAC %pEA VRR %pEA local-ip %pI4 filter %s to %s",
2260 zl3vni
->vni
, vrf_id_to_name(zl3vni_vrf_id(zl3vni
)),
2261 &svi_rmac
, &vrr_rmac
, &zl3vni
->local_vtep_ip
,
2262 CHECK_FLAG(zl3vni
->filter
, PREFIX_ROUTES_ONLY
)
2263 ? "prefix-routes-only"
2265 zebra_route_string(client
->proto
));
2267 client
->l3vniadd_cnt
++;
2268 return zserv_send_message(client
, s
);
2272 * Inform BGP about local l3-VNI deletion.
2274 static int zl3vni_send_del_to_client(struct zebra_l3vni
*zl3vni
)
2276 struct stream
*s
= NULL
;
2277 struct zserv
*client
= NULL
;
2279 client
= zserv_find_client(ZEBRA_ROUTE_BGP
, 0);
2280 /* BGP may not be running. */
2284 s
= stream_new(ZEBRA_MAX_PACKET_SIZ
);
2286 zclient_create_header(s
, ZEBRA_L3VNI_DEL
, zl3vni_vrf_id(zl3vni
));
2287 stream_putl(s
, zl3vni
->vni
);
2289 /* Write packet size. */
2290 stream_putw_at(s
, 0, stream_get_endp(s
));
2292 if (IS_ZEBRA_DEBUG_VXLAN
)
2293 zlog_debug("Send L3_VNI_DEL %u VRF %s to %s", zl3vni
->vni
,
2294 vrf_id_to_name(zl3vni_vrf_id(zl3vni
)),
2295 zebra_route_string(client
->proto
));
2297 client
->l3vnidel_cnt
++;
2298 return zserv_send_message(client
, s
);
2301 void zebra_vxlan_process_l3vni_oper_up(struct zebra_l3vni
*zl3vni
)
2306 /* send l3vni add to BGP */
2307 zl3vni_send_add_to_client(zl3vni
);
2310 void zebra_vxlan_process_l3vni_oper_down(struct zebra_l3vni
*zl3vni
)
2315 /* send l3-vni del to BGP*/
2316 zl3vni_send_del_to_client(zl3vni
);
2319 static void zevpn_add_to_l3vni_list(struct hash_bucket
*bucket
, void *ctxt
)
2321 struct zebra_evpn
*zevpn
= (struct zebra_evpn
*)bucket
->data
;
2322 struct zebra_l3vni
*zl3vni
= (struct zebra_l3vni
*)ctxt
;
2324 if (zevpn
->vrf_id
== zl3vni_vrf_id(zl3vni
))
2325 listnode_add_sort(zl3vni
->l2vnis
, zevpn
);
2329 * Handle transition of vni from l2 to l3 and vice versa.
2330 * This function handles only the L2VNI add/delete part of
2331 * the above transition.
2332 * L3VNI add/delete is handled by the calling functions.
2334 static int zebra_vxlan_handle_vni_transition(struct zebra_vrf
*zvrf
, vni_t vni
,
2337 struct zebra_evpn
*zevpn
= NULL
;
2338 struct zebra_l3vni
*zl3vni
= NULL
;
2340 /* There is a possibility that VNI notification was already received
2341 * from kernel and we programmed it as L2-VNI
2342 * In such a case we need to delete this L2-VNI first, so
2343 * that it can be reprogrammed as L3-VNI in the system. It is also
2344 * possible that the vrf-vni mapping is removed from FRR while the vxlan
2345 * interface is still present in kernel. In this case to keep it
2346 * symmetric, we will delete the l3-vni and reprogram it as l2-vni
2349 /* Locate hash entry */
2350 zevpn
= zebra_evpn_lookup(vni
);
2354 if (IS_ZEBRA_DEBUG_VXLAN
)
2355 zlog_debug("Del L2-VNI %u - transition to L3-VNI", vni
);
2357 /* Delete EVPN from BGP. */
2358 zebra_evpn_send_del_to_client(zevpn
);
2360 zebra_evpn_neigh_del_all(zevpn
, 0, 0, DEL_ALL_NEIGH
);
2361 zebra_evpn_mac_del_all(zevpn
, 0, 0, DEL_ALL_MAC
);
2363 /* Free up all remote VTEPs, if any. */
2364 zebra_evpn_vtep_del_all(zevpn
, 1);
2366 zl3vni
= zl3vni_from_vrf(zevpn
->vrf_id
);
2368 listnode_delete(zl3vni
->l2vnis
, zevpn
);
2370 /* Delete the hash entry. */
2371 if (zebra_evpn_vxlan_del(zevpn
)) {
2372 flog_err(EC_ZEBRA_VNI_DEL_FAILED
,
2373 "Failed to del EVPN hash %p, VNI %u", zevpn
,
2378 struct zebra_ns
*zns
;
2379 struct route_node
*rn
;
2380 struct interface
*ifp
;
2381 struct zebra_if
*zif
;
2382 struct zebra_vxlan_vni
*vnip
;
2383 struct zebra_l2info_vxlan
*vxl
;
2384 struct interface
*vlan_if
;
2387 if (IS_ZEBRA_DEBUG_VXLAN
)
2388 zlog_debug("Adding L2-VNI %u - transition from L3-VNI",
2391 /* Find VxLAN interface for this VNI. */
2392 zns
= zebra_ns_lookup(NS_DEFAULT
);
2393 for (rn
= route_top(zns
->if_table
); rn
; rn
= route_next(rn
)) {
2394 ifp
= (struct interface
*)rn
->info
;
2398 if (!zif
|| zif
->zif_type
!= ZEBRA_IF_VXLAN
)
2401 vxl
= &zif
->l2info
.vxl
;
2402 vnip
= zebra_vxlan_if_vni_find(zif
, vni
);
2410 if (IS_ZEBRA_DEBUG_VXLAN
)
2412 "Adding L2-VNI - Failed to find VxLAN interface for VNI %u",
2417 /* Create VNI hash entry for L2VNI */
2418 zevpn
= zebra_evpn_lookup(vni
);
2422 zevpn
= zebra_evpn_add(vni
);
2424 /* Find bridge interface for the VNI */
2425 vlan_if
= zvni_map_to_svi(vnip
->access_vlan
,
2426 zif
->brslave_info
.br_if
);
2428 zevpn
->vrf_id
= vlan_if
->vrf
->vrf_id
;
2429 zl3vni
= zl3vni_from_vrf(vlan_if
->vrf
->vrf_id
);
2431 listnode_add_sort_nodup(zl3vni
->l2vnis
, zevpn
);
2434 zevpn
->vxlan_if
= ifp
;
2435 zevpn
->local_vtep_ip
= vxl
->vtep_ip
;
2437 /* Inform BGP if the VNI is up and mapped to a bridge. */
2438 if (if_is_operative(ifp
) && zif
->brslave_info
.br_if
) {
2439 zebra_evpn_send_add_to_client(zevpn
);
2440 zebra_evpn_read_mac_neigh(zevpn
, ifp
);
2447 /* delete and uninstall rmac hash entry */
2448 static void zl3vni_del_rmac_hash_entry(struct hash_bucket
*bucket
, void *ctx
)
2450 struct zebra_mac
*zrmac
= NULL
;
2451 struct zebra_l3vni
*zl3vni
= NULL
;
2453 zrmac
= (struct zebra_mac
*)bucket
->data
;
2454 zl3vni
= (struct zebra_l3vni
*)ctx
;
2455 zl3vni_rmac_uninstall(zl3vni
, zrmac
);
2457 /* Send RMAC for FPM processing */
2458 hook_call(zebra_rmac_update
, zrmac
, zl3vni
, true, "RMAC deleted");
2460 zl3vni_rmac_del(zl3vni
, zrmac
);
2463 /* delete and uninstall nh hash entry */
2464 static void zl3vni_del_nh_hash_entry(struct hash_bucket
*bucket
, void *ctx
)
2466 struct zebra_neigh
*n
= NULL
;
2467 struct zebra_l3vni
*zl3vni
= NULL
;
2469 n
= (struct zebra_neigh
*)bucket
->data
;
2470 zl3vni
= (struct zebra_l3vni
*)ctx
;
2471 zl3vni_nh_uninstall(zl3vni
, n
);
2472 zl3vni_nh_del(zl3vni
, n
);
2475 /* re-add remote rmac if needed */
2476 static int zebra_vxlan_readd_remote_rmac(struct zebra_l3vni
*zl3vni
,
2477 struct ethaddr
*rmac
)
2479 struct zebra_mac
*zrmac
= NULL
;
2481 zrmac
= zl3vni_rmac_lookup(zl3vni
, rmac
);
2485 if (IS_ZEBRA_DEBUG_VXLAN
)
2486 zlog_debug("Del remote RMAC %pEA L3VNI %u - readd",
2489 zl3vni_rmac_install(zl3vni
, zrmac
);
2493 /* Public functions */
2495 int is_l3vni_for_prefix_routes_only(vni_t vni
)
2497 struct zebra_l3vni
*zl3vni
= NULL
;
2499 zl3vni
= zl3vni_lookup(vni
);
2503 return CHECK_FLAG(zl3vni
->filter
, PREFIX_ROUTES_ONLY
) ? 1 : 0;
2506 /* handle evpn route in vrf table */
2507 void zebra_vxlan_evpn_vrf_route_add(vrf_id_t vrf_id
, const struct ethaddr
*rmac
,
2508 const struct ipaddr
*vtep_ip
,
2509 const struct prefix
*host_prefix
)
2511 struct zebra_l3vni
*zl3vni
= NULL
;
2512 struct ipaddr ipv4_vtep
;
2514 zl3vni
= zl3vni_from_vrf(vrf_id
);
2515 if (!zl3vni
|| !is_l3vni_oper_up(zl3vni
))
2519 * add the next hop neighbor -
2520 * neigh to be installed is the ipv6 nexthop neigh
2522 zl3vni_remote_nh_add(zl3vni
, vtep_ip
, rmac
, host_prefix
);
2524 /* Add SVD next hop neighbor */
2525 svd_remote_nh_add(zl3vni
, vtep_ip
, rmac
, host_prefix
);
2528 * if the remote vtep is a ipv4 mapped ipv6 address convert it to ipv4
2529 * address. Rmac is programmed against the ipv4 vtep because we only
2530 * support ipv4 tunnels in the h/w right now
2532 memset(&ipv4_vtep
, 0, sizeof(ipv4_vtep
));
2533 ipv4_vtep
.ipa_type
= IPADDR_V4
;
2534 if (vtep_ip
->ipa_type
== IPADDR_V6
)
2535 ipv4_mapped_ipv6_to_ipv4(&vtep_ip
->ipaddr_v6
,
2536 &(ipv4_vtep
.ipaddr_v4
));
2538 memcpy(&(ipv4_vtep
.ipaddr_v4
), &vtep_ip
->ipaddr_v4
,
2539 sizeof(struct in_addr
));
2542 * add the rmac - remote rmac to be installed is against the ipv4
2545 zl3vni_remote_rmac_add(zl3vni
, rmac
, &ipv4_vtep
);
2548 /* handle evpn vrf route delete */
2549 void zebra_vxlan_evpn_vrf_route_del(vrf_id_t vrf_id
,
2550 struct ipaddr
*vtep_ip
,
2551 struct prefix
*host_prefix
)
2553 struct zebra_l3vni
*zl3vni
= NULL
;
2554 struct zebra_neigh
*nh
= NULL
;
2555 struct zebra_mac
*zrmac
= NULL
;
2557 zl3vni
= zl3vni_from_vrf(vrf_id
);
2561 /* find the next hop entry and rmac entry */
2562 nh
= zl3vni_nh_lookup(zl3vni
, vtep_ip
);
2565 zrmac
= zl3vni_rmac_lookup(zl3vni
, &nh
->emac
);
2567 /* delete the next hop entry */
2568 zl3vni_remote_nh_del(zl3vni
, nh
, host_prefix
);
2570 /* Delete SVD next hop entry */
2571 svd_remote_nh_del(zl3vni
, vtep_ip
);
2573 /* delete the rmac entry */
2575 zl3vni_remote_rmac_del(zl3vni
, zrmac
, vtep_ip
);
2578 void zebra_vxlan_print_specific_rmac_l3vni(struct vty
*vty
, vni_t l3vni
,
2579 struct ethaddr
*rmac
, bool use_json
)
2581 struct zebra_l3vni
*zl3vni
= NULL
;
2582 struct zebra_mac
*zrmac
= NULL
;
2583 json_object
*json
= NULL
;
2586 json
= json_object_new_object();
2588 if (!is_evpn_enabled()) {
2589 vty_json(vty
, json
);
2593 zl3vni
= zl3vni_lookup(l3vni
);
2596 vty_json(vty
, json
);
2598 vty_out(vty
, "%% L3-VNI %u doesn't exist\n", l3vni
);
2602 zrmac
= zl3vni_rmac_lookup(zl3vni
, rmac
);
2605 vty_json(vty
, json
);
2608 "%% Requested RMAC doesn't exist in L3-VNI %u\n",
2613 zl3vni_print_rmac(zrmac
, vty
, json
);
2616 vty_json(vty
, json
);
2619 void zebra_vxlan_print_rmacs_l3vni(struct vty
*vty
, vni_t l3vni
, bool use_json
)
2621 struct zebra_l3vni
*zl3vni
;
2623 struct rmac_walk_ctx wctx
;
2624 json_object
*json
= NULL
;
2627 json
= json_object_new_object();
2629 if (!is_evpn_enabled()) {
2630 vty_json(vty
, json
);
2634 zl3vni
= zl3vni_lookup(l3vni
);
2637 vty_json(vty
, json
);
2639 vty_out(vty
, "%% L3-VNI %u does not exist\n", l3vni
);
2642 num_rmacs
= hashcount(zl3vni
->rmac_table
);
2646 memset(&wctx
, 0, sizeof(wctx
));
2650 vty_out(vty
, "Number of Remote RMACs known for this VNI: %u\n",
2652 vty_out(vty
, "%-17s %-21s\n", "MAC", "Remote VTEP");
2654 json_object_int_add(json
, "numRmacs", num_rmacs
);
2656 hash_iterate(zl3vni
->rmac_table
, zl3vni_print_rmac_hash
, &wctx
);
2659 vty_json(vty
, json
);
2662 void zebra_vxlan_print_rmacs_all_l3vni(struct vty
*vty
, bool use_json
)
2664 json_object
*json
= NULL
;
2668 json
= json_object_new_object();
2670 if (!is_evpn_enabled()) {
2671 vty_json(vty
, json
);
2677 hash_iterate(zrouter
.l3vni_table
,
2678 (void (*)(struct hash_bucket
*,
2679 void *))zl3vni_print_rmac_hash_all_vni
,
2683 vty_json(vty
, json
);
2686 void zebra_vxlan_print_specific_nh_l3vni(struct vty
*vty
, vni_t l3vni
,
2687 struct ipaddr
*ip
, bool use_json
)
2689 struct zebra_l3vni
*zl3vni
= NULL
;
2690 struct zebra_neigh
*n
= NULL
;
2691 json_object
*json
= NULL
;
2694 json
= json_object_new_object();
2696 if (!is_evpn_enabled()) {
2697 vty_json(vty
, json
);
2701 /* If vni=0 passed, assume svd lookup */
2703 n
= svd_nh_lookup(ip
);
2705 zl3vni
= zl3vni_lookup(l3vni
);
2708 vty_out(vty
, "{}\n");
2710 vty_out(vty
, "%% L3-VNI %u does not exist\n",
2715 n
= zl3vni_nh_lookup(zl3vni
, ip
);
2720 vty_out(vty
, "{}\n");
2723 "%% Requested next-hop not present for L3-VNI %u\n",
2728 zl3vni_print_nh(n
, vty
, json
);
2731 vty_json(vty
, json
);
2734 static void l3vni_print_nh_table(struct hash
*nh_table
, struct vty
*vty
,
2738 struct nh_walk_ctx wctx
;
2739 json_object
*json
= NULL
;
2741 num_nh
= hashcount(nh_table
);
2746 json
= json_object_new_object();
2751 vty_out(vty
, "Number of NH Neighbors known for this VNI: %u\n",
2753 vty_out(vty
, "%-15s %-17s\n", "IP", "RMAC");
2755 json_object_int_add(json
, "numNextHops", num_nh
);
2757 hash_iterate(nh_table
, zl3vni_print_nh_hash
, &wctx
);
2760 vty_json(vty
, json
);
2763 void zebra_vxlan_print_nh_l3vni(struct vty
*vty
, vni_t l3vni
, bool use_json
)
2765 struct zebra_l3vni
*zl3vni
= NULL
;
2767 if (!is_evpn_enabled()) {
2769 vty_out(vty
, "{}\n");
2773 zl3vni
= zl3vni_lookup(l3vni
);
2776 vty_out(vty
, "{}\n");
2778 vty_out(vty
, "%% L3-VNI %u does not exist\n", l3vni
);
2782 l3vni_print_nh_table(zl3vni
->nh_table
, vty
, use_json
);
2785 void zebra_vxlan_print_nh_svd(struct vty
*vty
, bool use_json
)
2787 if (!is_evpn_enabled()) {
2789 vty_out(vty
, "{}\n");
2793 l3vni_print_nh_table(svd_nh_table
, vty
, use_json
);
2796 void zebra_vxlan_print_nh_all_l3vni(struct vty
*vty
, bool use_json
)
2798 json_object
*json
= NULL
;
2802 json
= json_object_new_object();
2804 if (!is_evpn_enabled()) {
2805 vty_json(vty
, json
);
2811 hash_iterate(zrouter
.l3vni_table
,
2812 (void (*)(struct hash_bucket
*,
2813 void *))zl3vni_print_nh_hash_all_vni
,
2817 vty_json(vty
, json
);
2821 * Display L3 VNI information (VTY command handler).
2823 void zebra_vxlan_print_l3vni(struct vty
*vty
, vni_t vni
, bool use_json
)
2826 json_object
*json
= NULL
;
2827 struct zebra_l3vni
*zl3vni
= NULL
;
2830 json
= json_object_new_object();
2832 if (!is_evpn_enabled()) {
2833 vty_json(vty
, json
);
2837 zl3vni
= zl3vni_lookup(vni
);
2840 vty_json(vty
, json
);
2842 vty_out(vty
, "%% VNI %u does not exist\n", vni
);
2848 zl3vni_print(zl3vni
, (void *)args
);
2851 vty_json(vty
, json
);
2854 void zebra_vxlan_print_vrf_vni(struct vty
*vty
, struct zebra_vrf
*zvrf
,
2855 json_object
*json_vrfs
)
2857 char buf
[ETHER_ADDR_STRLEN
];
2858 struct zebra_l3vni
*zl3vni
= NULL
;
2860 zl3vni
= zl3vni_lookup(zvrf
->l3vni
);
2865 vty_out(vty
, "%-37s %-10u %-20s %-20s %-5s %-18s\n",
2866 zvrf_name(zvrf
), zl3vni
->vni
,
2867 zl3vni_vxlan_if_name(zl3vni
),
2868 zl3vni_svi_if_name(zl3vni
), zl3vni_state2str(zl3vni
),
2869 zl3vni_rmac2str(zl3vni
, buf
, sizeof(buf
)));
2871 json_object
*json_vrf
= NULL
;
2873 json_vrf
= json_object_new_object();
2874 json_object_string_add(json_vrf
, "vrf", zvrf_name(zvrf
));
2875 json_object_int_add(json_vrf
, "vni", zl3vni
->vni
);
2876 json_object_string_add(json_vrf
, "vxlanIntf",
2877 zl3vni_vxlan_if_name(zl3vni
));
2878 json_object_string_add(json_vrf
, "sviIntf",
2879 zl3vni_svi_if_name(zl3vni
));
2880 json_object_string_add(json_vrf
, "state",
2881 zl3vni_state2str(zl3vni
));
2882 json_object_string_add(
2883 json_vrf
, "routerMac",
2884 zl3vni_rmac2str(zl3vni
, buf
, sizeof(buf
)));
2885 json_object_array_add(json_vrfs
, json_vrf
);
2890 * Display Neighbors for a VNI (VTY command handler).
2892 void zebra_vxlan_print_neigh_vni(struct vty
*vty
, struct zebra_vrf
*zvrf
,
2893 vni_t vni
, bool use_json
)
2895 struct zebra_evpn
*zevpn
;
2897 struct neigh_walk_ctx wctx
;
2898 json_object
*json
= NULL
;
2901 json
= json_object_new_object();
2903 if (!is_evpn_enabled()) {
2904 vty_json(vty
, json
);
2908 zevpn
= zebra_evpn_lookup(vni
);
2911 vty_json(vty
, json
);
2913 vty_out(vty
, "%% VNI %u does not exist\n", vni
);
2916 num_neigh
= hashcount(zevpn
->neigh_table
);
2920 /* Since we have IPv6 addresses to deal with which can vary widely in
2921 * size, we try to be a bit more elegant in display by first computing
2922 * the maximum width.
2924 memset(&wctx
, 0, sizeof(wctx
));
2927 wctx
.addr_width
= 15;
2929 hash_iterate(zevpn
->neigh_table
, zebra_evpn_find_neigh_addr_width
,
2934 "Number of ARPs (local and remote) known for this VNI: %u\n",
2936 zebra_evpn_print_neigh_hdr(vty
, &wctx
);
2938 json_object_int_add(json
, "numArpNd", num_neigh
);
2940 hash_iterate(zevpn
->neigh_table
, zebra_evpn_print_neigh_hash
, &wctx
);
2942 vty_json(vty
, json
);
2946 * Display neighbors across all VNIs (VTY command handler).
2948 void zebra_vxlan_print_neigh_all_vni(struct vty
*vty
, struct zebra_vrf
*zvrf
,
2949 bool print_dup
, bool use_json
)
2951 json_object
*json
= NULL
;
2955 json
= json_object_new_object();
2957 if (!is_evpn_enabled()) {
2958 vty_json(vty
, json
);
2964 args
[2] = (void *)(ptrdiff_t)print_dup
;
2966 hash_iterate(zvrf
->evpn_table
,
2967 (void (*)(struct hash_bucket
*,
2968 void *))zevpn_print_neigh_hash_all_evpn
,
2971 vty_json(vty
, json
);
2975 * Display neighbors across all VNIs in detail(VTY command handler).
2977 void zebra_vxlan_print_neigh_all_vni_detail(struct vty
*vty
,
2978 struct zebra_vrf
*zvrf
,
2979 bool print_dup
, bool use_json
)
2981 json_object
*json
= NULL
;
2985 json
= json_object_new_object();
2987 if (!is_evpn_enabled()) {
2988 vty_json(vty
, json
);
2994 args
[2] = (void *)(ptrdiff_t)print_dup
;
2996 hash_iterate(zvrf
->evpn_table
,
2997 (void (*)(struct hash_bucket
*,
2998 void *))zevpn_print_neigh_hash_all_evpn_detail
,
3001 vty_json(vty
, json
);
3005 * Display specific neighbor for a VNI, if present (VTY command handler).
3007 void zebra_vxlan_print_specific_neigh_vni(struct vty
*vty
,
3008 struct zebra_vrf
*zvrf
, vni_t vni
,
3009 struct ipaddr
*ip
, bool use_json
)
3011 struct zebra_evpn
*zevpn
;
3012 struct zebra_neigh
*n
;
3013 json_object
*json
= NULL
;
3016 json
= json_object_new_object();
3018 if (!is_evpn_enabled()) {
3019 vty_json(vty
, json
);
3023 zevpn
= zebra_evpn_lookup(vni
);
3026 vty_json(vty
, json
);
3028 vty_out(vty
, "%% VNI %u does not exist\n", vni
);
3031 n
= zebra_evpn_neigh_lookup(zevpn
, ip
);
3035 "%% Requested neighbor does not exist in VNI %u\n",
3040 zebra_evpn_print_neigh(n
, vty
, json
);
3043 vty_json(vty
, json
);
3047 * Display neighbors for a VNI from specific VTEP (VTY command handler).
3048 * By definition, these are remote neighbors.
3050 void zebra_vxlan_print_neigh_vni_vtep(struct vty
*vty
, struct zebra_vrf
*zvrf
,
3051 vni_t vni
, struct in_addr vtep_ip
,
3054 struct zebra_evpn
*zevpn
;
3056 struct neigh_walk_ctx wctx
;
3057 json_object
*json
= NULL
;
3060 json
= json_object_new_object();
3062 if (!is_evpn_enabled()) {
3063 vty_json(vty
, json
);
3067 zevpn
= zebra_evpn_lookup(vni
);
3070 vty_json(vty
, json
);
3072 vty_out(vty
, "%% VNI %u does not exist\n", vni
);
3075 num_neigh
= hashcount(zevpn
->neigh_table
);
3079 memset(&wctx
, 0, sizeof(wctx
));
3082 wctx
.addr_width
= 15;
3083 wctx
.flags
= SHOW_REMOTE_NEIGH_FROM_VTEP
;
3084 wctx
.r_vtep_ip
= vtep_ip
;
3086 hash_iterate(zevpn
->neigh_table
, zebra_evpn_find_neigh_addr_width
,
3088 hash_iterate(zevpn
->neigh_table
, zebra_evpn_print_neigh_hash
, &wctx
);
3091 vty_json(vty
, json
);
3095 * Display Duplicate detected Neighbors for a VNI
3096 * (VTY command handler).
3098 void zebra_vxlan_print_neigh_vni_dad(struct vty
*vty
,
3099 struct zebra_vrf
*zvrf
,
3103 struct zebra_evpn
*zevpn
;
3105 struct neigh_walk_ctx wctx
;
3106 json_object
*json
= NULL
;
3109 json
= json_object_new_object();
3111 if (!is_evpn_enabled()) {
3112 vty_json(vty
, json
);
3116 zevpn
= zebra_evpn_lookup(vni
);
3119 vty_json(vty
, json
);
3121 vty_out(vty
, "%% VNI %u does not exist\n", vni
);
3125 num_neigh
= hashcount(zevpn
->neigh_table
);
3129 num_neigh
= num_dup_detected_neighs(zevpn
);
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 vty_out(vty
, "{}\n");
3180 zevpn
= zebra_evpn_lookup(vni
);
3183 vty_out(vty
, "{}\n");
3185 vty_out(vty
, "%% VNI %u does not exist\n", vni
);
3188 num_macs
= num_valid_macs(zevpn
);
3193 json
= json_object_new_object();
3194 json_mac
= json_object_new_object();
3197 memset(&wctx
, 0, sizeof(wctx
));
3200 wctx
.json
= json_mac
;
3204 vty_out(vty
, "\nVNI %u #MACs (local and remote) %u\n\n",
3205 zevpn
->vni
, num_macs
);
3208 "Number of MACs (local and remote) known for this VNI: %u\n",
3211 "Flags: N=sync-neighs, I=local-inactive, P=peer-active, X=peer-proxy\n");
3212 vty_out(vty
, "%-17s %-6s %-5s %-30s %-5s %s\n", "MAC",
3213 "Type", "Flags", "Intf/Remote ES/VTEP", "VLAN",
3217 json_object_int_add(json
, "numMacs", num_macs
);
3220 hash_iterate(zevpn
->mac_table
, zebra_evpn_print_mac_hash_detail
,
3223 hash_iterate(zevpn
->mac_table
, zebra_evpn_print_mac_hash
,
3227 json_object_object_add(json
, "macs", json_mac
);
3228 vty_json(vty
, json
);
3233 * Display MACs for all VNIs (VTY command handler).
3235 void zebra_vxlan_print_macs_all_vni(struct vty
*vty
, struct zebra_vrf
*zvrf
,
3236 bool print_dup
, bool use_json
)
3238 struct mac_walk_ctx wctx
;
3239 json_object
*json
= NULL
;
3242 json
= json_object_new_object();
3244 if (!is_evpn_enabled()) {
3245 vty_json(vty
, json
);
3249 memset(&wctx
, 0, sizeof(wctx
));
3252 wctx
.print_dup
= print_dup
;
3253 hash_iterate(zvrf
->evpn_table
, zevpn_print_mac_hash_all_evpn
, &wctx
);
3256 vty_json(vty
, json
);
3260 * Display MACs in detail for all VNIs (VTY command handler).
3262 void zebra_vxlan_print_macs_all_vni_detail(struct vty
*vty
,
3263 struct zebra_vrf
*zvrf
,
3264 bool print_dup
, bool use_json
)
3266 struct mac_walk_ctx wctx
;
3267 json_object
*json
= NULL
;
3270 json
= json_object_new_object();
3272 if (!is_evpn_enabled()) {
3273 vty_json(vty
, json
);
3277 memset(&wctx
, 0, sizeof(wctx
));
3280 wctx
.print_dup
= print_dup
;
3281 hash_iterate(zvrf
->evpn_table
, zevpn_print_mac_hash_all_evpn_detail
,
3285 vty_json(vty
, json
);
3289 * Display MACs for all VNIs (VTY command handler).
3291 void zebra_vxlan_print_macs_all_vni_vtep(struct vty
*vty
,
3292 struct zebra_vrf
*zvrf
,
3293 struct in_addr vtep_ip
, bool use_json
)
3295 struct mac_walk_ctx wctx
;
3296 json_object
*json
= NULL
;
3299 json
= json_object_new_object();
3301 if (!is_evpn_enabled()) {
3302 vty_json(vty
, json
);
3306 memset(&wctx
, 0, sizeof(wctx
));
3308 wctx
.flags
= SHOW_REMOTE_MAC_FROM_VTEP
;
3309 wctx
.r_vtep_ip
= vtep_ip
;
3311 hash_iterate(zvrf
->evpn_table
, zevpn_print_mac_hash_all_evpn
, &wctx
);
3314 vty_json(vty
, json
);
3318 * Display specific MAC for a VNI, if present (VTY command handler).
3320 void zebra_vxlan_print_specific_mac_vni(struct vty
*vty
, struct zebra_vrf
*zvrf
,
3321 vni_t vni
, struct ethaddr
*macaddr
,
3324 struct zebra_evpn
*zevpn
;
3325 struct zebra_mac
*mac
;
3326 json_object
*json
= NULL
;
3329 json
= json_object_new_object();
3331 if (!is_evpn_enabled()) {
3332 vty_json(vty
, json
);
3336 zevpn
= zebra_evpn_lookup(vni
);
3339 vty_json(vty
, json
);
3341 vty_out(vty
, "%% VNI %u does not exist\n", vni
);
3344 mac
= zebra_evpn_mac_lookup(zevpn
, macaddr
);
3347 vty_json(vty
, json
);
3350 "%% Requested MAC does not exist in VNI %u\n",
3355 zebra_evpn_print_mac(mac
, vty
, json
);
3358 vty_json(vty
, json
);
3361 /* Print Duplicate MACs per VNI */
3362 void zebra_vxlan_print_macs_vni_dad(struct vty
*vty
,
3363 struct zebra_vrf
*zvrf
,
3364 vni_t vni
, bool use_json
)
3366 struct zebra_evpn
*zevpn
;
3367 struct mac_walk_ctx wctx
;
3369 json_object
*json
= NULL
;
3370 json_object
*json_mac
= NULL
;
3372 if (!is_evpn_enabled())
3375 zevpn
= zebra_evpn_lookup(vni
);
3377 vty_out(vty
, "%% VNI %u does not exist\n", vni
);
3381 num_macs
= num_valid_macs(zevpn
);
3385 num_macs
= num_dup_detected_macs(zevpn
);
3390 json
= json_object_new_object();
3391 json_mac
= json_object_new_object();
3394 memset(&wctx
, 0, sizeof(wctx
));
3397 wctx
.json
= json_mac
;
3401 "Number of MACs (local and remote) known for this VNI: %u\n",
3403 vty_out(vty
, "%-17s %-6s %-5s %-30s %-5s\n", "MAC", "Type",
3404 "Flags", "Intf/Remote ES/VTEP", "VLAN");
3406 json_object_int_add(json
, "numMacs", num_macs
);
3408 hash_iterate(zevpn
->mac_table
, zebra_evpn_print_dad_mac_hash
, &wctx
);
3411 json_object_object_add(json
, "macs", json_mac
);
3412 vty_json(vty
, json
);
3417 int zebra_vxlan_clear_dup_detect_vni_mac(struct zebra_vrf
*zvrf
, vni_t vni
,
3418 struct ethaddr
*macaddr
, char *errmsg
,
3421 struct zebra_evpn
*zevpn
;
3422 struct zebra_mac
*mac
;
3423 struct listnode
*node
= NULL
;
3424 struct zebra_neigh
*nbr
= NULL
;
3426 if (!is_evpn_enabled())
3429 zevpn
= zebra_evpn_lookup(vni
);
3431 snprintfrr(errmsg
, errmsg_len
, "VNI %u does not exist", vni
);
3435 mac
= zebra_evpn_mac_lookup(zevpn
, macaddr
);
3437 snprintf(errmsg
, errmsg_len
,
3438 "Requested MAC does not exist in VNI %u\n", vni
);
3442 if (!CHECK_FLAG(mac
->flags
, ZEBRA_MAC_DUPLICATE
)) {
3443 snprintfrr(errmsg
, errmsg_len
,
3444 "Requested MAC is not duplicate detected\n");
3448 /* Remove all IPs as duplicate associcated with this MAC */
3449 for (ALL_LIST_ELEMENTS_RO(mac
->neigh_list
, node
, nbr
)) {
3450 /* For local neigh mark inactive so MACIP update is generated
3451 * to BGP. This is a scenario where MAC update received
3452 * and detected as duplicate which marked neigh as duplicate.
3453 * Later local neigh update did not get a chance to relay
3454 * to BGP. Similarly remote macip update, neigh needs to be
3455 * installed locally.
3457 if (zvrf
->dad_freeze
&&
3458 CHECK_FLAG(nbr
->flags
, ZEBRA_NEIGH_DUPLICATE
)) {
3459 if (CHECK_FLAG(nbr
->flags
, ZEBRA_NEIGH_LOCAL
))
3460 ZEBRA_NEIGH_SET_INACTIVE(nbr
);
3461 else if (CHECK_FLAG(nbr
->flags
, ZEBRA_NEIGH_REMOTE
))
3462 zebra_evpn_rem_neigh_install(
3463 zevpn
, nbr
, false /*was_static*/);
3466 UNSET_FLAG(nbr
->flags
, ZEBRA_NEIGH_DUPLICATE
);
3468 nbr
->detect_start_time
.tv_sec
= 0;
3469 nbr
->dad_dup_detect_time
= 0;
3472 UNSET_FLAG(mac
->flags
, ZEBRA_MAC_DUPLICATE
);
3474 mac
->detect_start_time
.tv_sec
= 0;
3475 mac
->detect_start_time
.tv_usec
= 0;
3476 mac
->dad_dup_detect_time
= 0;
3477 EVENT_OFF(mac
->dad_mac_auto_recovery_timer
);
3479 /* warn-only action return */
3480 if (!zvrf
->dad_freeze
)
3483 /* Local: Notify Peer VTEPs, Remote: Install the entry */
3484 if (CHECK_FLAG(mac
->flags
, ZEBRA_MAC_LOCAL
)) {
3486 if (zebra_evpn_mac_send_add_to_client(zevpn
->vni
, &mac
->macaddr
,
3487 mac
->flags
, mac
->loc_seq
,
3491 /* Process all neighbors associated with this MAC. */
3492 zebra_evpn_process_neigh_on_local_mac_change(zevpn
, mac
, 0,
3495 } else if (CHECK_FLAG(mac
->flags
, ZEBRA_MAC_REMOTE
)) {
3496 zebra_evpn_process_neigh_on_remote_mac_add(zevpn
, mac
);
3498 /* Install the entry. */
3499 zebra_evpn_rem_mac_install(zevpn
, mac
, false /* was_static */);
3505 int zebra_vxlan_clear_dup_detect_vni_ip(struct zebra_vrf
*zvrf
, vni_t vni
,
3506 struct ipaddr
*ip
, char *errmsg
,
3509 struct zebra_evpn
*zevpn
;
3510 struct zebra_neigh
*nbr
;
3511 struct zebra_mac
*mac
;
3512 char buf
[INET6_ADDRSTRLEN
];
3513 char buf2
[ETHER_ADDR_STRLEN
];
3515 if (!is_evpn_enabled())
3518 zevpn
= zebra_evpn_lookup(vni
);
3520 snprintfrr(errmsg
, errmsg_len
, "VNI %u does not exist\n", vni
);
3524 nbr
= zebra_evpn_neigh_lookup(zevpn
, ip
);
3526 snprintfrr(errmsg
, errmsg_len
,
3527 "Requested host IP does not exist in VNI %u\n", vni
);
3531 ipaddr2str(&nbr
->ip
, buf
, sizeof(buf
));
3533 if (!CHECK_FLAG(nbr
->flags
, ZEBRA_NEIGH_DUPLICATE
)) {
3534 snprintfrr(errmsg
, errmsg_len
,
3535 "Requested host IP %s is not duplicate detected\n",
3540 mac
= zebra_evpn_mac_lookup(zevpn
, &nbr
->emac
);
3542 if (CHECK_FLAG(mac
->flags
, ZEBRA_MAC_DUPLICATE
)) {
3545 "Requested IP's associated MAC %s is still in duplicate state\n",
3546 prefix_mac2str(&nbr
->emac
, buf2
, sizeof(buf2
)));
3550 if (IS_ZEBRA_DEBUG_VXLAN
)
3551 zlog_debug("%s: clear neigh %s in dup state, flags 0x%x seq %u",
3552 __func__
, buf
, nbr
->flags
, nbr
->loc_seq
);
3554 UNSET_FLAG(nbr
->flags
, ZEBRA_NEIGH_DUPLICATE
);
3556 nbr
->detect_start_time
.tv_sec
= 0;
3557 nbr
->detect_start_time
.tv_usec
= 0;
3558 nbr
->dad_dup_detect_time
= 0;
3559 EVENT_OFF(nbr
->dad_ip_auto_recovery_timer
);
3561 if (!!CHECK_FLAG(nbr
->flags
, ZEBRA_NEIGH_LOCAL
)) {
3562 zebra_evpn_neigh_send_add_to_client(zevpn
->vni
, ip
, &nbr
->emac
,
3563 nbr
->mac
, nbr
->flags
,
3565 } else if (!!CHECK_FLAG(nbr
->flags
, ZEBRA_NEIGH_REMOTE
)) {
3566 zebra_evpn_rem_neigh_install(zevpn
, nbr
, false /*was_static*/);
3572 static void zevpn_clear_dup_mac_hash(struct hash_bucket
*bucket
, void *ctxt
)
3574 struct mac_walk_ctx
*wctx
= ctxt
;
3575 struct zebra_mac
*mac
;
3576 struct zebra_evpn
*zevpn
;
3577 struct listnode
*node
= NULL
;
3578 struct zebra_neigh
*nbr
= NULL
;
3580 mac
= (struct zebra_mac
*)bucket
->data
;
3584 zevpn
= wctx
->zevpn
;
3586 if (!CHECK_FLAG(mac
->flags
, ZEBRA_MAC_DUPLICATE
))
3589 UNSET_FLAG(mac
->flags
, ZEBRA_MAC_DUPLICATE
);
3591 mac
->detect_start_time
.tv_sec
= 0;
3592 mac
->detect_start_time
.tv_usec
= 0;
3593 mac
->dad_dup_detect_time
= 0;
3594 EVENT_OFF(mac
->dad_mac_auto_recovery_timer
);
3596 /* Remove all IPs as duplicate associcated with this MAC */
3597 for (ALL_LIST_ELEMENTS_RO(mac
->neigh_list
, node
, nbr
)) {
3598 if (CHECK_FLAG(nbr
->flags
, ZEBRA_NEIGH_LOCAL
)
3600 ZEBRA_NEIGH_SET_INACTIVE(nbr
);
3602 UNSET_FLAG(nbr
->flags
, ZEBRA_NEIGH_DUPLICATE
);
3604 nbr
->detect_start_time
.tv_sec
= 0;
3605 nbr
->dad_dup_detect_time
= 0;
3608 /* Local: Notify Peer VTEPs, Remote: Install the entry */
3609 if (CHECK_FLAG(mac
->flags
, ZEBRA_MAC_LOCAL
)) {
3611 if (zebra_evpn_mac_send_add_to_client(zevpn
->vni
, &mac
->macaddr
,
3612 mac
->flags
, mac
->loc_seq
,
3616 /* Process all neighbors associated with this MAC. */
3617 zebra_evpn_process_neigh_on_local_mac_change(zevpn
, mac
, 0,
3620 } else if (CHECK_FLAG(mac
->flags
, ZEBRA_MAC_REMOTE
)) {
3621 zebra_evpn_process_neigh_on_remote_mac_add(zevpn
, mac
);
3623 /* Install the entry. */
3624 zebra_evpn_rem_mac_install(zevpn
, mac
, false /* was_static */);
3628 static void zevpn_clear_dup_detect_hash_vni_all(struct hash_bucket
*bucket
,
3631 struct zebra_evpn
*zevpn
;
3632 struct zebra_vrf
*zvrf
;
3633 struct mac_walk_ctx m_wctx
;
3634 struct neigh_walk_ctx n_wctx
;
3636 zevpn
= (struct zebra_evpn
*)bucket
->data
;
3640 zvrf
= (struct zebra_vrf
*)args
[0];
3642 if (hashcount(zevpn
->neigh_table
)) {
3643 memset(&n_wctx
, 0, sizeof(n_wctx
));
3644 n_wctx
.zevpn
= zevpn
;
3646 hash_iterate(zevpn
->neigh_table
,
3647 zebra_evpn_clear_dup_neigh_hash
, &n_wctx
);
3650 if (num_valid_macs(zevpn
)) {
3651 memset(&m_wctx
, 0, sizeof(m_wctx
));
3652 m_wctx
.zevpn
= zevpn
;
3654 hash_iterate(zevpn
->mac_table
, zevpn_clear_dup_mac_hash
, &m_wctx
);
3659 int zebra_vxlan_clear_dup_detect_vni_all(struct zebra_vrf
*zvrf
)
3663 if (!is_evpn_enabled())
3668 hash_iterate(zvrf
->evpn_table
,
3669 (void (*)(struct hash_bucket
*, void *))
3670 zevpn_clear_dup_detect_hash_vni_all
, args
);
3675 int zebra_vxlan_clear_dup_detect_vni(struct zebra_vrf
*zvrf
, vni_t vni
)
3677 struct zebra_evpn
*zevpn
;
3678 struct mac_walk_ctx m_wctx
;
3679 struct neigh_walk_ctx n_wctx
;
3681 if (!is_evpn_enabled())
3684 zevpn
= zebra_evpn_lookup(vni
);
3686 zlog_warn("VNI %u does not exist", vni
);
3690 if (hashcount(zevpn
->neigh_table
)) {
3691 memset(&n_wctx
, 0, sizeof(n_wctx
));
3692 n_wctx
.zevpn
= zevpn
;
3694 hash_iterate(zevpn
->neigh_table
,
3695 zebra_evpn_clear_dup_neigh_hash
, &n_wctx
);
3698 if (num_valid_macs(zevpn
)) {
3699 memset(&m_wctx
, 0, sizeof(m_wctx
));
3700 m_wctx
.zevpn
= zevpn
;
3702 hash_iterate(zevpn
->mac_table
, zevpn_clear_dup_mac_hash
, &m_wctx
);
3709 * Display MACs for a VNI from specific VTEP (VTY command handler).
3711 void zebra_vxlan_print_macs_vni_vtep(struct vty
*vty
, struct zebra_vrf
*zvrf
,
3712 vni_t vni
, struct in_addr vtep_ip
,
3715 struct zebra_evpn
*zevpn
;
3717 struct mac_walk_ctx wctx
;
3718 json_object
*json
= NULL
;
3719 json_object
*json_mac
= NULL
;
3721 if (!is_evpn_enabled()) {
3722 vty_json(vty
, json
);
3726 zevpn
= zebra_evpn_lookup(vni
);
3729 vty_out(vty
, "{}\n");
3731 vty_out(vty
, "%% VNI %u does not exist\n", vni
);
3734 num_macs
= num_valid_macs(zevpn
);
3739 json
= json_object_new_object();
3740 json_mac
= json_object_new_object();
3743 memset(&wctx
, 0, sizeof(wctx
));
3746 wctx
.flags
= SHOW_REMOTE_MAC_FROM_VTEP
;
3747 wctx
.r_vtep_ip
= vtep_ip
;
3748 wctx
.json
= json_mac
;
3749 hash_iterate(zevpn
->mac_table
, zebra_evpn_print_mac_hash
, &wctx
);
3752 json_object_int_add(json
, "numMacs", wctx
.count
);
3754 json_object_object_add(json
, "macs", json_mac
);
3755 vty_json(vty
, json
);
3761 * Display VNI information (VTY command handler).
3763 * use_json flag indicates that output should be in JSON format.
3764 * json_array is non NULL when JSON output needs to be aggregated (by the
3765 * caller) and then printed, otherwise, JSON evpn vni info is printed
3768 void zebra_vxlan_print_vni(struct vty
*vty
, struct zebra_vrf
*zvrf
, vni_t vni
,
3769 bool use_json
, json_object
*json_array
)
3771 json_object
*json
= NULL
;
3773 struct zebra_l3vni
*zl3vni
= NULL
;
3774 struct zebra_evpn
*zevpn
= NULL
;
3777 json
= json_object_new_object();
3779 if (!is_evpn_enabled()) {
3780 vty_json(vty
, json
);
3787 zl3vni
= zl3vni_lookup(vni
);
3789 zl3vni_print(zl3vni
, (void *)args
);
3791 zevpn
= zebra_evpn_lookup(vni
);
3793 zebra_evpn_print(zevpn
, (void *)args
);
3795 vty_out(vty
, "%% VNI %u does not exist\n", vni
);
3800 * Each "json" object contains info about 1 VNI.
3801 * When "json_array" is non-null, we aggreggate the json output
3802 * into json_array and print it as a JSON array.
3805 json_object_array_add(json_array
, json
);
3807 vty_json(vty
, json
);
3811 /* Display all global details for EVPN */
3812 void zebra_vxlan_print_evpn(struct vty
*vty
, bool uj
)
3817 json_object
*json
= NULL
;
3818 struct zebra_vrf
*zvrf
= NULL
;
3821 json
= json_object_new_object();
3823 if (!is_evpn_enabled()) {
3824 vty_json(vty
, json
);
3828 zvrf
= zebra_vrf_get_evpn();
3830 num_l3vnis
= hashcount(zrouter
.l3vni_table
);
3831 num_l2vnis
= hashcount(zvrf
->evpn_table
);
3832 num_vnis
= num_l2vnis
+ num_l3vnis
;
3835 json_object_string_add(json
, "advertiseGatewayMacip",
3836 zvrf
->advertise_gw_macip
? "Yes" : "No");
3837 json_object_string_add(json
, "advertiseSviMacip",
3838 zvrf
->advertise_svi_macip
? "Yes"
3840 json_object_string_add(json
, "advertiseSviMac",
3841 zebra_evpn_mh_do_adv_svi_mac() ? "Yes"
3843 json_object_int_add(json
, "numVnis", num_vnis
);
3844 json_object_int_add(json
, "numL2Vnis", num_l2vnis
);
3845 json_object_int_add(json
, "numL3Vnis", num_l3vnis
);
3846 if (zebra_evpn_do_dup_addr_detect(zvrf
))
3847 json_object_boolean_true_add(json
,
3848 "isDuplicateAddrDetection");
3850 json_object_boolean_false_add(json
,
3851 "isDuplicateAddrDetection");
3852 json_object_int_add(json
, "maxMoves", zvrf
->dad_max_moves
);
3853 json_object_int_add(json
, "detectionTime", zvrf
->dad_time
);
3854 json_object_int_add(json
, "detectionFreezeTime",
3855 zvrf
->dad_freeze_time
);
3856 json_object_boolean_add(json
, "isDetectionFreeze",
3858 zebra_evpn_mh_json(json
);
3860 vty_out(vty
, "L2 VNIs: %u\n", num_l2vnis
);
3861 vty_out(vty
, "L3 VNIs: %u\n", num_l3vnis
);
3862 vty_out(vty
, "Advertise gateway mac-ip: %s\n",
3863 zvrf
->advertise_gw_macip
? "Yes" : "No");
3864 vty_out(vty
, "Advertise svi mac-ip: %s\n",
3865 zvrf
->advertise_svi_macip
? "Yes" : "No");
3866 vty_out(vty
, "Advertise svi mac: %s\n",
3867 zebra_evpn_mh_do_adv_svi_mac() ? "Yes" : "No");
3868 vty_out(vty
, "Duplicate address detection: %s\n",
3869 zebra_evpn_do_dup_addr_detect(zvrf
) ? "Enable"
3871 vty_out(vty
, " Detection max-moves %u, time %d\n",
3872 zvrf
->dad_max_moves
, zvrf
->dad_time
);
3873 if (zvrf
->dad_freeze
) {
3874 if (zvrf
->dad_freeze_time
)
3875 vty_out(vty
, " Detection freeze %u\n",
3876 zvrf
->dad_freeze_time
);
3878 vty_out(vty
, " Detection freeze %s\n",
3881 zebra_evpn_mh_print(vty
);
3885 vty_json(vty
, json
);
3889 * Display VNI hash table (VTY command handler).
3891 void zebra_vxlan_print_vnis(struct vty
*vty
, struct zebra_vrf
*zvrf
,
3894 json_object
*json
= NULL
;
3898 json
= json_object_new_object();
3900 if (!is_evpn_enabled()) {
3901 vty_json(vty
, json
);
3906 vty_out(vty
, "%-10s %-4s %-21s %-8s %-8s %-15s %-37s\n", "VNI",
3907 "Type", "VxLAN IF", "# MACs", "# ARPs",
3908 "# Remote VTEPs", "Tenant VRF");
3913 /* Display all L2-VNIs */
3916 (void (*)(struct hash_bucket
*, void *))zebra_evpn_print_hash
,
3919 /* Display all L3-VNIs */
3920 hash_iterate(zrouter
.l3vni_table
,
3921 (void (*)(struct hash_bucket
*, void *))zl3vni_print_hash
,
3925 vty_json(vty
, json
);
3928 void zebra_vxlan_dup_addr_detection(ZAPI_HANDLER_ARGS
)
3932 uint32_t max_moves
= 0;
3933 uint32_t freeze_time
= 0;
3934 bool dup_addr_detect
= false;
3935 bool freeze
= false;
3936 bool old_addr_detect
;
3939 STREAM_GETL(s
, dup_addr_detect
);
3940 STREAM_GETL(s
, time
);
3941 STREAM_GETL(s
, max_moves
);
3942 STREAM_GETL(s
, freeze
);
3943 STREAM_GETL(s
, freeze_time
);
3945 old_addr_detect
= zebra_evpn_do_dup_addr_detect(zvrf
);
3946 zvrf
->dup_addr_detect
= dup_addr_detect
;
3947 dup_addr_detect
= zebra_evpn_do_dup_addr_detect(zvrf
);
3949 /* DAD previous state was enabled, and new state is disable,
3950 * clear all duplicate detected addresses.
3952 if (old_addr_detect
&& !dup_addr_detect
)
3953 zebra_vxlan_clear_dup_detect_vni_all(zvrf
);
3955 zvrf
->dad_time
= time
;
3956 zvrf
->dad_max_moves
= max_moves
;
3957 zvrf
->dad_freeze
= freeze
;
3958 zvrf
->dad_freeze_time
= freeze_time
;
3960 if (IS_ZEBRA_DEBUG_VXLAN
)
3962 "VRF %s duplicate detect %s max_moves %u timeout %u freeze %s freeze_time %u",
3963 vrf_id_to_name(zvrf
->vrf
->vrf_id
),
3964 dup_addr_detect
? "enable" : "disable",
3965 zvrf
->dad_max_moves
, zvrf
->dad_time
,
3966 zvrf
->dad_freeze
? "enable" : "disable",
3967 zvrf
->dad_freeze_time
);
3974 * Display VNI hash table in detail(VTY command handler).
3976 void zebra_vxlan_print_vnis_detail(struct vty
*vty
, struct zebra_vrf
*zvrf
,
3979 json_object
*json_array
= NULL
;
3980 struct zebra_ns
*zns
= NULL
;
3981 struct zebra_evpn_show zes
;
3983 if (!is_evpn_enabled()) {
3985 vty_out(vty
, "{}\n");
3989 zns
= zebra_ns_lookup(NS_DEFAULT
);
3994 json_array
= json_object_new_array();
3997 zes
.json
= json_array
;
3999 zes
.use_json
= use_json
;
4001 /* Display all L2-VNIs */
4002 hash_iterate(zvrf
->evpn_table
,
4003 (void (*)(struct hash_bucket
*,
4004 void *))zebra_evpn_print_hash_detail
,
4007 /* Display all L3-VNIs */
4008 hash_iterate(zrouter
.l3vni_table
,
4009 (void (*)(struct hash_bucket
*,
4010 void *))zl3vni_print_hash_detail
,
4014 vty_json(vty
, json_array
);
4018 * Handle neighbor delete notification from the kernel (on a VLAN device
4019 * / L3 interface). This may result in either the neighbor getting deleted
4020 * from our database or being re-added to the kernel (if it is a valid
4023 int zebra_vxlan_handle_kernel_neigh_del(struct interface
*ifp
,
4024 struct interface
*link_if
,
4027 struct zebra_evpn
*zevpn
= NULL
;
4028 struct zebra_l3vni
*zl3vni
= NULL
;
4030 /* check if this is a remote neigh entry corresponding to remote
4033 zl3vni
= zl3vni_from_svi(ifp
, link_if
);
4035 return zl3vni_local_nh_del(zl3vni
, ip
);
4037 /* We are only interested in neighbors on an SVI that resides on top
4038 * of a VxLAN bridge.
4040 zevpn
= zebra_evpn_from_svi(ifp
, link_if
);
4042 if (IS_ZEBRA_DEBUG_VXLAN
)
4044 "%s: Del neighbor %pIA EVPN is not present for interface %s",
4045 __func__
, ip
, ifp
->name
);
4049 if (!zevpn
->vxlan_if
) {
4051 "VNI %u hash %p doesn't have intf upon local neighbor DEL",
4056 if (IS_ZEBRA_DEBUG_VXLAN
)
4057 zlog_debug("Del neighbor %pIA intf %s(%u) -> L2-VNI %u",
4058 ip
, ifp
->name
, ifp
->ifindex
, zevpn
->vni
);
4060 return zebra_evpn_neigh_del_ip(zevpn
, ip
);
4064 * Handle neighbor add or update notification from the kernel (on a VLAN
4065 * device / L3 interface). This is typically for a local neighbor but can
4066 * also be for a remote neighbor (e.g., ageout notification). It could
4067 * also be a "move" scenario.
4069 int zebra_vxlan_handle_kernel_neigh_update(struct interface
*ifp
,
4070 struct interface
*link_if
,
4072 struct ethaddr
*macaddr
,
4076 bool local_inactive
, bool dp_static
)
4078 struct zebra_evpn
*zevpn
= NULL
;
4079 struct zebra_l3vni
*zl3vni
= NULL
;
4081 /* check if this is a remote neigh entry corresponding to remote
4084 zl3vni
= zl3vni_from_svi(ifp
, link_if
);
4086 return zl3vni_local_nh_add_update(zl3vni
, ip
, state
);
4088 /* We are only interested in neighbors on an SVI that resides on top
4089 * of a VxLAN bridge.
4091 zevpn
= zebra_evpn_from_svi(ifp
, link_if
);
4095 if (IS_ZEBRA_DEBUG_VXLAN
|| IS_ZEBRA_DEBUG_EVPN_MH_NEIGH
)
4097 "Add/Update neighbor %pIA MAC %pEA intf %s(%u) state 0x%x %s%s%s%s-> L2-VNI %u",
4098 ip
, macaddr
, ifp
->name
,
4099 ifp
->ifindex
, state
, is_ext
? "ext-learned " : "",
4100 is_router
? "router " : "",
4101 local_inactive
? "local_inactive " : "",
4102 dp_static
? "peer_sync " : "", zevpn
->vni
);
4104 /* Is this about a local neighbor or a remote one? */
4106 return zebra_evpn_local_neigh_update(zevpn
, ifp
, ip
, macaddr
,
4107 is_router
, local_inactive
,
4110 return zebra_evpn_remote_neigh_update(zevpn
, ifp
, ip
, macaddr
, state
);
4114 zebra_vxlan_remote_macip_helper(bool add
, struct stream
*s
, vni_t
*vni
,
4115 struct ethaddr
*macaddr
, uint16_t *ipa_len
,
4116 struct ipaddr
*ip
, struct in_addr
*vtep_ip
,
4117 uint8_t *flags
, uint32_t *seq
, esi_t
*esi
)
4122 * Obtain each remote MACIP and process.
4123 * Message contains VNI, followed by MAC followed by IP (if any)
4124 * followed by remote VTEP IP.
4126 memset(ip
, 0, sizeof(*ip
));
4127 STREAM_GETL(s
, *vni
);
4128 STREAM_GET(macaddr
->octet
, s
, ETH_ALEN
);
4129 STREAM_GETW(s
, *ipa_len
);
4132 if (*ipa_len
== IPV4_MAX_BYTELEN
)
4133 ip
->ipa_type
= IPADDR_V4
;
4134 else if (*ipa_len
== IPV6_MAX_BYTELEN
)
4135 ip
->ipa_type
= IPADDR_V6
;
4137 if (IS_ZEBRA_DEBUG_VXLAN
)
4139 "ipa_len *must* be %d or %d bytes in length not %d",
4140 IPV4_MAX_BYTELEN
, IPV6_MAX_BYTELEN
,
4142 goto stream_failure
;
4145 STREAM_GET(&ip
->ip
.addr
, s
, *ipa_len
);
4147 l
+= 4 + ETH_ALEN
+ 4 + *ipa_len
;
4148 STREAM_GET(&vtep_ip
->s_addr
, s
, IPV4_MAX_BYTELEN
);
4149 l
+= IPV4_MAX_BYTELEN
;
4152 STREAM_GETC(s
, *flags
);
4153 STREAM_GETL(s
, *seq
);
4155 STREAM_GET(esi
, s
, sizeof(esi_t
));
4166 * Handle message from client to delete a remote MACIP for a VNI.
4168 void zebra_vxlan_remote_macip_del(ZAPI_HANDLER_ARGS
)
4172 struct ethaddr macaddr
;
4174 struct in_addr vtep_ip
;
4175 uint16_t l
= 0, ipa_len
;
4176 char buf1
[INET6_ADDRSTRLEN
];
4180 while (l
< hdr
->length
) {
4181 int res_length
= zebra_vxlan_remote_macip_helper(
4182 false, s
, &vni
, &macaddr
, &ipa_len
, &ip
, &vtep_ip
, NULL
,
4185 if (res_length
== -1)
4186 goto stream_failure
;
4189 if (IS_ZEBRA_DEBUG_VXLAN
)
4191 "Recv MACIP DEL VNI %u MAC %pEA%s%s Remote VTEP %pI4 from %s",
4193 ipa_len
? " IP " : "",
4195 ipaddr2str(&ip
, buf1
, sizeof(buf1
)) : "",
4196 &vtep_ip
, zebra_route_string(client
->proto
));
4198 /* Enqueue to workqueue for processing */
4199 zebra_rib_queue_evpn_rem_macip_del(vni
, &macaddr
, &ip
, vtep_ip
);
4207 * Handle message from client to add a remote MACIP for a VNI. This
4208 * could be just the add of a MAC address or the add of a neighbor
4211 void zebra_vxlan_remote_macip_add(ZAPI_HANDLER_ARGS
)
4215 struct ethaddr macaddr
;
4217 struct in_addr vtep_ip
;
4218 uint16_t l
= 0, ipa_len
;
4221 char buf1
[INET6_ADDRSTRLEN
];
4223 char esi_buf
[ESI_STR_LEN
];
4225 if (!EVPN_ENABLED(zvrf
)) {
4226 zlog_debug("EVPN not enabled, ignoring remote MACIP ADD");
4232 while (l
< hdr
->length
) {
4234 int res_length
= zebra_vxlan_remote_macip_helper(
4235 true, s
, &vni
, &macaddr
, &ipa_len
, &ip
, &vtep_ip
,
4236 &flags
, &seq
, &esi
);
4238 if (res_length
== -1)
4239 goto stream_failure
;
4242 if (IS_ZEBRA_DEBUG_VXLAN
) {
4243 if (memcmp(&esi
, zero_esi
, sizeof(esi_t
)))
4244 esi_to_str(&esi
, esi_buf
, sizeof(esi_buf
));
4246 strlcpy(esi_buf
, "-", ESI_STR_LEN
);
4248 "Recv %sMACIP ADD VNI %u MAC %pEA%s%s flags 0x%x seq %u VTEP %pI4 ESI %s from %s",
4249 (flags
& ZEBRA_MACIP_TYPE_SYNC_PATH
) ?
4252 ipa_len
? " IP " : "",
4254 ipaddr2str(&ip
, buf1
, sizeof(buf1
)) : "",
4255 flags
, seq
, &vtep_ip
, esi_buf
,
4256 zebra_route_string(client
->proto
));
4259 /* Enqueue to workqueue for processing */
4260 zebra_rib_queue_evpn_rem_macip_add(vni
, &macaddr
, &ip
, flags
,
4261 seq
, vtep_ip
, &esi
);
4269 * Handle remote vtep delete by kernel; re-add the vtep if we have it
4271 int zebra_vxlan_check_readd_vtep(struct interface
*ifp
, vni_t vni
,
4272 struct in_addr vtep_ip
)
4274 struct zebra_if
*zif
;
4275 struct zebra_vrf
*zvrf
= NULL
;
4276 struct zebra_evpn
*zevpn
= NULL
;
4277 struct zebra_vtep
*zvtep
= NULL
;
4278 struct zebra_vxlan_vni
*vnip
;
4283 /* If EVPN is not enabled, nothing to do. */
4284 if (!is_evpn_enabled())
4287 /* Locate VRF corresponding to interface. */
4288 zvrf
= ifp
->vrf
->info
;
4292 vnip
= zebra_vxlan_if_vni_find(zif
, vni
);
4296 /* Locate hash entry; it is expected to exist. */
4297 zevpn
= zebra_evpn_lookup(vni
);
4301 /* If the remote vtep entry doesn't exists nothing to do */
4302 zvtep
= zebra_evpn_vtep_find(zevpn
, &vtep_ip
);
4306 if (IS_ZEBRA_DEBUG_VXLAN
)
4308 "Del MAC for remote VTEP %pI4 intf %s(%u) VNI %u - readd",
4309 &vtep_ip
, ifp
->name
, ifp
->ifindex
, vni
);
4311 zebra_evpn_vtep_install(zevpn
, zvtep
);
4316 * Handle notification of MAC add/update over VxLAN. If the kernel is notifying
4317 * us, this must involve a multihoming scenario. Treat this as implicit delete
4318 * of any prior local MAC.
4320 static int zebra_vxlan_check_del_local_mac(struct interface
*ifp
,
4321 struct interface
*br_if
,
4322 struct ethaddr
*macaddr
,
4323 vlanid_t vid
, vni_t vni
)
4325 struct zebra_if
*zif
;
4326 struct zebra_evpn
*zevpn
;
4327 struct zebra_mac
*mac
;
4332 /* Check if EVPN is enabled. */
4333 if (!is_evpn_enabled())
4336 /* Locate hash entry; it is expected to exist. */
4337 zevpn
= zebra_evpn_lookup(vni
);
4341 /* If entry doesn't exist, nothing to do. */
4342 mac
= zebra_evpn_mac_lookup(zevpn
, macaddr
);
4346 /* Is it a local entry? */
4347 if (!CHECK_FLAG(mac
->flags
, ZEBRA_MAC_LOCAL
))
4350 if (IS_ZEBRA_DEBUG_VXLAN
)
4352 "Add/update remote MAC %pEA intf %s(%u) VNI %u flags 0x%x - del local",
4353 macaddr
, ifp
->name
, ifp
->ifindex
, vni
, mac
->flags
);
4355 /* Remove MAC from BGP. */
4356 zebra_evpn_mac_send_del_to_client(zevpn
->vni
, macaddr
, mac
->flags
,
4360 * If there are no neigh associated with the mac delete the mac
4361 * else mark it as AUTO for forward reference
4363 if (!listcount(mac
->neigh_list
)) {
4364 zebra_evpn_mac_del(zevpn
, mac
);
4366 zebra_evpn_mac_clear_fwd_info(mac
);
4367 UNSET_FLAG(mac
->flags
, ZEBRA_MAC_ALL_LOCAL_FLAGS
);
4368 UNSET_FLAG(mac
->flags
, ZEBRA_MAC_STICKY
);
4369 SET_FLAG(mac
->flags
, ZEBRA_MAC_AUTO
);
4375 /* MAC notification from the dataplane with a network dest port -
4376 * 1. This can be a local MAC on a down ES (if fast-failover is not possible
4377 * 2. Or it can be a remote MAC
4379 int zebra_vxlan_dp_network_mac_add(struct interface
*ifp
,
4380 struct interface
*br_if
,
4381 struct ethaddr
*macaddr
, vlanid_t vid
,
4382 vni_t vni
, uint32_t nhg_id
, bool sticky
,
4385 struct zebra_evpn_es
*es
;
4386 struct interface
*acc_ifp
;
4388 /* If netlink message is with vid, it will have no nexthop.
4392 if (IS_ZEBRA_DEBUG_VXLAN
|| IS_ZEBRA_DEBUG_EVPN_MH_MAC
)
4393 zlog_debug("dpAdd MAC %pEA VID %u - ignore as no nhid",
4398 /* Get vxlan's vid for netlink message has no it. */
4399 vid
= ((struct zebra_if
*)ifp
->info
)
4400 ->l2info
.vxl
.vni_info
.vni
.access_vlan
;
4402 /* if remote mac delete the local entry */
4403 if (!nhg_id
|| !zebra_evpn_nhg_is_local_es(nhg_id
, &es
)
4404 || !zebra_evpn_es_local_mac_via_network_port(es
)) {
4405 if (IS_ZEBRA_DEBUG_VXLAN
|| IS_ZEBRA_DEBUG_EVPN_MH_MAC
)
4406 zlog_debug("dpAdd remote MAC %pEA VID %u", macaddr
,
4408 return zebra_vxlan_check_del_local_mac(ifp
, br_if
, macaddr
, vid
,
4412 /* If local MAC on a down local ES translate the network-mac-add
4413 * to a local-active-mac-add
4415 if (IS_ZEBRA_DEBUG_VXLAN
|| IS_ZEBRA_DEBUG_EVPN_MH_MAC
)
4416 zlog_debug("dpAdd local-nw-MAC %pEA VID %u", macaddr
, vid
);
4417 acc_ifp
= es
->zif
->ifp
;
4418 return zebra_vxlan_local_mac_add_update(
4419 acc_ifp
, br_if
, macaddr
, vid
, sticky
,
4420 false /* local_inactive */, dp_static
);
4424 * Handle network MAC delete by kernel -
4425 * 1. readd the remote MAC if we have it
4426 * 2. local MAC with does ES may also need to be re-installed
4428 int zebra_vxlan_dp_network_mac_del(struct interface
*ifp
,
4429 struct interface
*br_if
,
4430 struct ethaddr
*macaddr
, vlanid_t vid
,
4433 struct zebra_if
*zif
= NULL
;
4434 struct zebra_evpn
*zevpn
= NULL
;
4435 struct zebra_l3vni
*zl3vni
= NULL
;
4436 struct zebra_mac
*mac
= NULL
;
4441 /* Check if EVPN is enabled. */
4442 if (!is_evpn_enabled())
4445 /* check if this is a remote RMAC and readd simillar to remote macs */
4446 zl3vni
= zl3vni_lookup(vni
);
4448 return zebra_vxlan_readd_remote_rmac(zl3vni
, macaddr
);
4450 /* Locate hash entry; it is expected to exist. */
4451 zevpn
= zebra_evpn_lookup(vni
);
4455 /* If entry doesn't exist, nothing to do. */
4456 mac
= zebra_evpn_mac_lookup(zevpn
, macaddr
);
4460 if (CHECK_FLAG(mac
->flags
, ZEBRA_MAC_REMOTE
)) {
4461 /* If remote entry simply re-install */
4462 if (IS_ZEBRA_DEBUG_VXLAN
|| IS_ZEBRA_DEBUG_EVPN_MH_MAC
)
4464 "dpDel remote MAC %pEA intf %s(%u) VNI %u - readd",
4465 macaddr
, ifp
->name
, ifp
->ifindex
, vni
);
4466 zebra_evpn_rem_mac_install(zevpn
, mac
, false /* was_static */);
4467 } else if (CHECK_FLAG(mac
->flags
, ZEBRA_MAC_LOCAL
) && mac
->es
4468 && zebra_evpn_es_local_mac_via_network_port(mac
->es
)) {
4469 /* If local entry via nw-port call local-del which will
4470 * re-install entry in the dataplane is needed
4472 if (IS_ZEBRA_DEBUG_VXLAN
|| IS_ZEBRA_DEBUG_EVPN_MH_MAC
)
4473 zlog_debug("dpDel local-nw-MAC %pEA VNI %u", macaddr
,
4476 zebra_evpn_del_local_mac(zevpn
, mac
, false);
4483 * Handle local MAC delete (on a port or VLAN corresponding to this VNI).
4485 int zebra_vxlan_local_mac_del(struct interface
*ifp
, struct interface
*br_if
,
4486 struct ethaddr
*macaddr
, vlanid_t vid
)
4488 struct zebra_evpn
*zevpn
;
4489 struct zebra_mac
*mac
;
4491 /* We are interested in MACs only on ports or (port, VLAN) that
4494 zevpn
= zebra_evpn_map_vlan(ifp
, br_if
, vid
);
4497 if (!zevpn
->vxlan_if
) {
4499 "VNI %u hash %p doesn't have intf upon local MAC DEL",
4504 /* If entry doesn't exist, nothing to do. */
4505 mac
= zebra_evpn_mac_lookup(zevpn
, macaddr
);
4509 /* Is it a local entry? */
4510 if (!CHECK_FLAG(mac
->flags
, ZEBRA_MAC_LOCAL
))
4513 return zebra_evpn_del_local_mac(zevpn
, mac
, false);
4517 * Handle local MAC add (on a port or VLAN corresponding to this VNI).
4519 int zebra_vxlan_local_mac_add_update(struct interface
*ifp
,
4520 struct interface
*br_if
,
4521 struct ethaddr
*macaddr
, vlanid_t vid
,
4522 bool sticky
, bool local_inactive
,
4525 struct zebra_evpn
*zevpn
;
4526 struct zebra_vrf
*zvrf
;
4530 /* We are interested in MACs only on ports or (port, VLAN) that
4533 zevpn
= zebra_evpn_map_vlan(ifp
, br_if
, vid
);
4535 if (IS_ZEBRA_DEBUG_VXLAN
)
4537 " Add/Update %sMAC %pEA intf %s(%u) VID %u, could not find EVPN",
4538 sticky
? "sticky " : "", macaddr
,
4539 ifp
->name
, ifp
->ifindex
, vid
);
4543 if (!zevpn
->vxlan_if
) {
4544 if (IS_ZEBRA_DEBUG_VXLAN
)
4546 " VNI %u hash %p doesn't have intf upon local MAC ADD",
4551 zvrf
= zebra_vrf_get_evpn();
4552 return zebra_evpn_add_update_local_mac(zvrf
, zevpn
, ifp
, macaddr
, vid
,
4553 sticky
, local_inactive
,
4558 * Handle message from client to delete a remote VTEP for an EVPN.
4560 void zebra_vxlan_remote_vtep_del_zapi(ZAPI_HANDLER_ARGS
)
4563 unsigned short l
= 0;
4565 struct in_addr vtep_ip
;
4567 if (!is_evpn_enabled()) {
4569 "%s: EVPN is not enabled yet we have received a VTEP DEL msg",
4574 if (!EVPN_ENABLED(zvrf
)) {
4575 zlog_debug("Recv VTEP DEL zapi for non-EVPN VRF %u",
4582 while (l
< hdr
->length
) {
4583 int flood_control
__attribute__((unused
));
4585 /* Obtain each remote VTEP and process. */
4586 STREAM_GETL(s
, vni
);
4588 STREAM_GET(&vtep_ip
.s_addr
, s
, IPV4_MAX_BYTELEN
);
4589 l
+= IPV4_MAX_BYTELEN
;
4591 /* Flood control is intentionally ignored right now */
4592 STREAM_GETL(s
, flood_control
);
4595 if (IS_ZEBRA_DEBUG_VXLAN
)
4596 zlog_debug("Recv VTEP DEL %pI4 VNI %u from %s",
4598 zebra_route_string(client
->proto
));
4600 /* Enqueue for processing */
4601 zebra_rib_queue_evpn_rem_vtep_del(zvrf_id(zvrf
), vni
, vtep_ip
);
4609 * Handle message from client to delete a remote VTEP for an EVPN.
4611 void zebra_vxlan_remote_vtep_del(vrf_id_t vrf_id
, vni_t vni
,
4612 struct in_addr vtep_ip
)
4614 struct zebra_evpn
*zevpn
;
4615 struct zebra_vtep
*zvtep
;
4616 struct interface
*ifp
;
4617 struct zebra_if
*zif
;
4618 struct zebra_vrf
*zvrf
;
4620 if (!is_evpn_enabled()) {
4621 zlog_debug("%s: Can't process vtep del: EVPN is not enabled",
4626 zvrf
= zebra_vrf_lookup_by_id(vrf_id
);
4630 if (!EVPN_ENABLED(zvrf
)) {
4631 zlog_debug("Can't process VTEP DEL for non-EVPN VRF %u",
4636 /* Locate VNI hash entry - expected to exist. */
4637 zevpn
= zebra_evpn_lookup(vni
);
4639 if (IS_ZEBRA_DEBUG_VXLAN
)
4641 "Failed to locate VNI hash for remote VTEP DEL, VNI %u",
4646 ifp
= zevpn
->vxlan_if
;
4649 "VNI %u hash %p doesn't have intf upon remote VTEP DEL",
4655 /* If down or not mapped to a bridge, we're done. */
4656 if (!if_is_operative(ifp
) || !zif
->brslave_info
.br_if
)
4659 /* If the remote VTEP does not exist, there's nothing more to
4661 * Otherwise, uninstall any remote MACs pointing to this VTEP
4662 * and then, the VTEP entry itself and remove it.
4664 zvtep
= zebra_evpn_vtep_find(zevpn
, &vtep_ip
);
4668 zebra_evpn_vtep_uninstall(zevpn
, &vtep_ip
);
4669 zebra_evpn_vtep_del(zevpn
, zvtep
);
4673 * Handle message from client to add a remote VTEP for an EVPN.
4675 void zebra_vxlan_remote_vtep_add(vrf_id_t vrf_id
, vni_t vni
,
4676 struct in_addr vtep_ip
, int flood_control
)
4678 struct zebra_evpn
*zevpn
;
4679 struct interface
*ifp
;
4680 struct zebra_if
*zif
;
4681 struct zebra_vtep
*zvtep
;
4682 struct zebra_vrf
*zvrf
;
4684 if (!is_evpn_enabled()) {
4685 zlog_debug("%s: EVPN not enabled: can't process a VTEP ADD",
4690 zvrf
= zebra_vrf_lookup_by_id(vrf_id
);
4694 if (!EVPN_ENABLED(zvrf
)) {
4695 zlog_debug("Can't process VTEP ADD for non-EVPN VRF %u",
4700 /* Locate VNI hash entry - expected to exist. */
4701 zevpn
= zebra_evpn_lookup(vni
);
4704 EC_ZEBRA_VTEP_ADD_FAILED
,
4705 "Failed to locate EVPN hash upon remote VTEP ADD, VNI %u",
4710 ifp
= zevpn
->vxlan_if
;
4713 EC_ZEBRA_VTEP_ADD_FAILED
,
4714 "VNI %u hash %p doesn't have intf upon remote VTEP ADD",
4721 /* If down or not mapped to a bridge, we're done. */
4722 if (!if_is_operative(ifp
) || !zif
->brslave_info
.br_if
)
4725 zvtep
= zebra_evpn_vtep_find(zevpn
, &vtep_ip
);
4727 /* If the remote VTEP already exists check if
4728 * the flood mode has changed
4730 if (zvtep
->flood_control
!= flood_control
) {
4731 if (zvtep
->flood_control
== VXLAN_FLOOD_DISABLED
)
4732 /* old mode was head-end-replication but
4733 * is no longer; get rid of the HER fdb
4734 * entry installed before
4736 zebra_evpn_vtep_uninstall(zevpn
, &vtep_ip
);
4737 zvtep
->flood_control
= flood_control
;
4738 zebra_evpn_vtep_install(zevpn
, zvtep
);
4741 zvtep
= zebra_evpn_vtep_add(zevpn
, &vtep_ip
, flood_control
);
4743 zebra_evpn_vtep_install(zevpn
, zvtep
);
4745 flog_err(EC_ZEBRA_VTEP_ADD_FAILED
,
4746 "Failed to add remote VTEP, VNI %u zevpn %p",
4752 * Handle message from client to add a remote VTEP for an EVPN.
4754 void zebra_vxlan_remote_vtep_add_zapi(ZAPI_HANDLER_ARGS
)
4757 unsigned short l
= 0;
4759 struct in_addr vtep_ip
;
4762 if (!is_evpn_enabled()) {
4764 "%s: EVPN not enabled yet we received a VTEP ADD zapi msg",
4769 if (!EVPN_ENABLED(zvrf
)) {
4770 zlog_debug("Recv VTEP ADD zapi for non-EVPN VRF %u",
4777 while (l
< hdr
->length
) {
4778 /* Obtain each remote VTEP and process. */
4779 STREAM_GETL(s
, vni
);
4781 STREAM_GET(&vtep_ip
.s_addr
, s
, IPV4_MAX_BYTELEN
);
4782 STREAM_GETL(s
, flood_control
);
4783 l
+= IPV4_MAX_BYTELEN
+ 4;
4785 if (IS_ZEBRA_DEBUG_VXLAN
)
4786 zlog_debug("Recv VTEP ADD %pI4 VNI %u flood %d from %s",
4787 &vtep_ip
, vni
, flood_control
,
4788 zebra_route_string(client
->proto
));
4790 /* Enqueue for processing */
4791 zebra_rib_queue_evpn_rem_vtep_add(zvrf_id(zvrf
), vni
, vtep_ip
,
4800 * Add/Del gateway macip to evpn
4802 * 1. SVI interface on a vlan aware bridge
4803 * 2. SVI interface on a vlan unaware bridge
4804 * 3. vrr interface (MACVLAN) associated to a SVI
4805 * We advertise macip routes for an interface if it is associated to VxLan vlan
4807 int zebra_vxlan_add_del_gw_macip(struct interface
*ifp
, const struct prefix
*p
,
4811 struct ethaddr macaddr
;
4812 struct zebra_evpn
*zevpn
= NULL
;
4814 memset(&ip
, 0, sizeof(ip
));
4815 memset(&macaddr
, 0, sizeof(macaddr
));
4817 /* Check if EVPN is enabled. */
4818 if (!is_evpn_enabled())
4821 if (IS_ZEBRA_IF_MACVLAN(ifp
)) {
4822 struct interface
*svi_if
=
4823 NULL
; /* SVI corresponding to the MACVLAN */
4824 struct zebra_if
*ifp_zif
=
4825 NULL
; /* Zebra daemon specific info for MACVLAN */
4826 struct zebra_if
*svi_if_zif
=
4827 NULL
; /* Zebra daemon specific info for SVI*/
4829 ifp_zif
= ifp
->info
;
4834 * for a MACVLAN interface the link represents the svi_if
4836 svi_if
= if_lookup_by_index_per_ns(zebra_ns_lookup(NS_DEFAULT
),
4837 ifp_zif
->link_ifindex
);
4839 zlog_debug("MACVLAN %s(%u) without link information",
4840 ifp
->name
, ifp
->ifindex
);
4844 if (IS_ZEBRA_IF_VLAN(svi_if
)) {
4846 * If it is a vlan aware bridge then the link gives the
4847 * bridge information
4849 struct interface
*svi_if_link
= NULL
;
4851 svi_if_zif
= svi_if
->info
;
4853 svi_if_link
= if_lookup_by_index_per_ns(
4854 zebra_ns_lookup(NS_DEFAULT
),
4855 svi_if_zif
->link_ifindex
);
4856 zevpn
= zebra_evpn_from_svi(svi_if
,
4859 } else if (IS_ZEBRA_IF_BRIDGE(svi_if
)) {
4861 * If it is a vlan unaware bridge then svi is the bridge
4864 zevpn
= zebra_evpn_from_svi(svi_if
, svi_if
);
4866 } else if (IS_ZEBRA_IF_VLAN(ifp
)) {
4867 struct zebra_if
*svi_if_zif
=
4868 NULL
; /* Zebra daemon specific info for SVI */
4869 struct interface
*svi_if_link
=
4870 NULL
; /* link info for the SVI = bridge info */
4872 svi_if_zif
= ifp
->info
;
4874 svi_if_link
= if_lookup_by_index_per_ns(
4875 zebra_ns_lookup(NS_DEFAULT
),
4876 svi_if_zif
->link_ifindex
);
4878 zevpn
= zebra_evpn_from_svi(ifp
, svi_if_link
);
4880 } else if (IS_ZEBRA_IF_BRIDGE(ifp
)) {
4881 zevpn
= zebra_evpn_from_svi(ifp
, ifp
);
4887 if (!zevpn
->vxlan_if
) {
4888 zlog_debug("VNI %u hash %p doesn't have intf upon MACVLAN up",
4893 /* VRR IP is advertised only if gw-macip-adv-enabled */
4894 if (IS_ZEBRA_IF_MACVLAN(ifp
)) {
4895 if (!advertise_gw_macip_enabled(zevpn
))
4898 /* SVI IP is advertised if gw or svi macip-adv-enabled */
4899 if (!advertise_svi_macip_enabled(zevpn
)
4900 && !advertise_gw_macip_enabled(zevpn
))
4904 memcpy(&macaddr
.octet
, ifp
->hw_addr
, ETH_ALEN
);
4906 if (p
->family
== AF_INET
) {
4907 ip
.ipa_type
= IPADDR_V4
;
4908 memcpy(&(ip
.ipaddr_v4
), &(p
->u
.prefix4
),
4909 sizeof(struct in_addr
));
4910 } else if (p
->family
== AF_INET6
) {
4911 ip
.ipa_type
= IPADDR_V6
;
4912 memcpy(&(ip
.ipaddr_v6
), &(p
->u
.prefix6
),
4913 sizeof(struct in6_addr
));
4918 zebra_evpn_gw_macip_add(ifp
, zevpn
, &macaddr
, &ip
);
4920 zebra_evpn_gw_macip_del(ifp
, zevpn
, &ip
);
4926 * Handle SVI interface going down.
4927 * SVI can be associated to either L3-VNI or L2-VNI.
4928 * For L2-VNI: At this point, this is a NOP since
4929 * the kernel deletes the neighbor entries on this SVI (if any).
4930 * We only need to update the vrf corresponding to zevpn.
4931 * For L3-VNI: L3-VNI is operationally down, update mac-ip routes and delete
4934 int zebra_vxlan_svi_down(struct interface
*ifp
, struct interface
*link_if
)
4936 struct zebra_l3vni
*zl3vni
= NULL
;
4938 zl3vni
= zl3vni_from_svi(ifp
, link_if
);
4941 /* process l3-vni down */
4942 zebra_vxlan_process_l3vni_oper_down(zl3vni
);
4944 /* remove association with svi-if */
4945 zl3vni
->svi_if
= NULL
;
4947 struct zebra_evpn
*zevpn
= NULL
;
4949 /* Unlink the SVI from the access VLAN */
4950 zebra_evpn_acc_bd_svi_set(ifp
->info
, link_if
->info
, false);
4952 /* since we dont have svi corresponding to zevpn, we associate it
4953 * to default vrf. Note: the corresponding neigh entries on the
4954 * SVI would have already been deleted */
4955 zevpn
= zebra_evpn_from_svi(ifp
, link_if
);
4958 /* remove from l3-vni list */
4959 zl3vni
= zl3vni_from_vrf(zevpn
->vrf_id
);
4961 listnode_delete(zl3vni
->l2vnis
, zevpn
);
4963 zevpn
->svi_if
= NULL
;
4964 zevpn
->vrf_id
= VRF_DEFAULT
;
4966 /* update the tenant vrf in BGP */
4967 if (if_is_operative(zevpn
->vxlan_if
))
4968 zebra_evpn_send_add_to_client(zevpn
);
4975 * Handle SVI interface coming up.
4976 * SVI can be associated to L3-VNI (l3vni vxlan interface) or L2-VNI (l2-vni
4978 * For L2-VNI: we need to install any remote neighbors entried (used for
4980 * For L3-VNI: SVI will be used to get the rmac to be used with L3-VNI
4982 int zebra_vxlan_svi_up(struct interface
*ifp
, struct interface
*link_if
)
4984 struct zebra_evpn
*zevpn
= NULL
;
4985 struct zebra_l3vni
*zl3vni
= NULL
;
4987 zl3vni
= zl3vni_from_svi(ifp
, link_if
);
4990 /* associate with svi */
4991 zl3vni
->svi_if
= ifp
;
4993 /* process oper-up */
4994 if (is_l3vni_oper_up(zl3vni
))
4995 zebra_vxlan_process_l3vni_oper_up(zl3vni
);
4998 /* process SVI up for l2-vni */
4999 struct neigh_walk_ctx n_wctx
;
5001 zevpn
= zebra_evpn_from_svi(ifp
, link_if
);
5005 if (!zevpn
->vxlan_if
) {
5007 "VNI %u hash %p doesn't have intf upon SVI up",
5012 if (IS_ZEBRA_DEBUG_VXLAN
)
5014 "SVI %s(%u) VNI %u VRF %s is UP, installing neighbors",
5015 ifp
->name
, ifp
->ifindex
, zevpn
->vni
,
5018 /* update the vrf information for l2-vni and inform bgp */
5019 zevpn
->svi_if
= ifp
;
5020 zevpn
->vrf_id
= ifp
->vrf
->vrf_id
;
5022 zl3vni
= zl3vni_from_vrf(zevpn
->vrf_id
);
5024 listnode_add_sort_nodup(zl3vni
->l2vnis
, zevpn
);
5026 if (if_is_operative(zevpn
->vxlan_if
))
5027 zebra_evpn_send_add_to_client(zevpn
);
5029 /* Install any remote neighbors for this VNI. */
5030 memset(&n_wctx
, 0, sizeof(n_wctx
));
5031 n_wctx
.zevpn
= zevpn
;
5032 hash_iterate(zevpn
->neigh_table
, zebra_evpn_install_neigh_hash
,
5035 /* Link the SVI from the access VLAN */
5036 zebra_evpn_acc_bd_svi_set(ifp
->info
, link_if
->info
, true);
5038 /* Update MACIP routes created by advertise-svi-ip */
5039 if (advertise_svi_macip_enabled(zevpn
)) {
5040 zebra_evpn_del_macip_for_intf(ifp
, zevpn
);
5041 zebra_evpn_add_macip_for_intf(ifp
, zevpn
);
5049 * Handle MAC-VLAN interface going down.
5050 * L3VNI: When MAC-VLAN interface goes down,
5051 * find its associated SVI and update type2/type-5 routes
5054 void zebra_vxlan_macvlan_down(struct interface
*ifp
)
5056 struct zebra_l3vni
*zl3vni
= NULL
;
5057 struct zebra_if
*zif
, *link_zif
;
5058 struct interface
*link_ifp
, *link_if
;
5062 link_ifp
= zif
->link
;
5064 if (IS_ZEBRA_DEBUG_VXLAN
)
5066 "macvlan parent link is not found. Parent index %d ifp %s",
5068 ifindex2ifname(zif
->link_ifindex
,
5072 link_zif
= link_ifp
->info
;
5075 link_if
= if_lookup_by_index_per_ns(zebra_ns_lookup(NS_DEFAULT
),
5076 link_zif
->link_ifindex
);
5078 zl3vni
= zl3vni_from_svi(link_ifp
, link_if
);
5080 zl3vni
->mac_vlan_if
= NULL
;
5081 if (is_l3vni_oper_up(zl3vni
))
5082 zebra_vxlan_process_l3vni_oper_up(zl3vni
);
5087 * Handle MAC-VLAN interface going up.
5088 * L3VNI: When MAC-VLAN interface comes up,
5089 * find its associated SVI and update type-2 routes
5090 * with MAC-VLAN's MAC as RMAC and for type-5 routes
5091 * use SVI's MAC as RMAC.
5093 void zebra_vxlan_macvlan_up(struct interface
*ifp
)
5095 struct zebra_l3vni
*zl3vni
= NULL
;
5096 struct zebra_if
*zif
, *link_zif
;
5097 struct interface
*link_ifp
, *link_if
;
5101 link_ifp
= zif
->link
;
5102 link_zif
= link_ifp
->info
;
5105 link_if
= if_lookup_by_index_per_ns(zebra_ns_lookup(NS_DEFAULT
),
5106 link_zif
->link_ifindex
);
5107 zl3vni
= zl3vni_from_svi(link_ifp
, link_if
);
5109 /* associate with macvlan (VRR) interface */
5110 zl3vni
->mac_vlan_if
= ifp
;
5112 /* process oper-up */
5113 if (is_l3vni_oper_up(zl3vni
))
5114 zebra_vxlan_process_l3vni_oper_up(zl3vni
);
5118 int zebra_vxlan_process_vrf_vni_cmd(struct zebra_vrf
*zvrf
, vni_t vni
,
5119 char *err
, int err_str_sz
, int filter
,
5122 struct zebra_l3vni
*zl3vni
= NULL
;
5123 struct zebra_vrf
*zvrf_evpn
= NULL
;
5125 zvrf_evpn
= zebra_vrf_get_evpn();
5127 if (IS_ZEBRA_DEBUG_VXLAN
)
5128 zlog_debug("vrf %s vni %u %s", zvrf_name(zvrf
), vni
,
5129 add
? "ADD" : "DEL");
5132 /* check if the vni is already present under zvrf */
5134 snprintf(err
, err_str_sz
,
5135 "VNI is already configured under the vrf");
5139 /* check if this VNI is already present in the system */
5140 zl3vni
= zl3vni_lookup(vni
);
5142 snprintf(err
, err_str_sz
,
5143 "VNI is already configured as L3-VNI");
5147 /* Remove L2VNI if present */
5148 zebra_vxlan_handle_vni_transition(zvrf
, vni
, add
);
5150 /* add the L3-VNI to the global table */
5151 zl3vni
= zl3vni_add(vni
, zvrf_id(zvrf
));
5153 /* associate the vrf with vni */
5156 /* set the filter in l3vni to denote if we are using l3vni only
5160 SET_FLAG(zl3vni
->filter
, PREFIX_ROUTES_ONLY
);
5162 /* associate with vxlan-intf;
5163 * we need to associate with the vxlan-intf first
5165 zl3vni
->vxlan_if
= zl3vni_map_to_vxlan_if(zl3vni
);
5167 /* associate with corresponding SVI interface, we can associate
5168 * with svi-if only after vxlan interface association is
5171 zl3vni
->svi_if
= zl3vni_map_to_svi_if(zl3vni
);
5173 zl3vni
->mac_vlan_if
= zl3vni_map_to_mac_vlan_if(zl3vni
);
5175 if (IS_ZEBRA_DEBUG_VXLAN
)
5177 "%s: l3vni %u svi_if %s mac_vlan_if %s",
5179 zl3vni
->svi_if
? zl3vni
->svi_if
->name
: "NIL",
5180 zl3vni
->mac_vlan_if
? zl3vni
->mac_vlan_if
->name
5183 /* formulate l2vni list */
5184 hash_iterate(zvrf_evpn
->evpn_table
, zevpn_add_to_l3vni_list
,
5187 if (is_l3vni_oper_up(zl3vni
))
5188 zebra_vxlan_process_l3vni_oper_up(zl3vni
);
5191 zl3vni
= zl3vni_lookup(vni
);
5193 snprintf(err
, err_str_sz
, "VNI doesn't exist");
5197 if (zvrf
->l3vni
!= vni
) {
5198 snprintf(err
, err_str_sz
,
5199 "VNI %d doesn't exist in VRF: %s",
5200 vni
, zvrf
->vrf
->name
);
5204 if (filter
&& !CHECK_FLAG(zl3vni
->filter
, PREFIX_ROUTES_ONLY
)) {
5205 snprintf(err
, ERR_STR_SZ
,
5206 "prefix-routes-only is not set for the vni");
5210 zebra_vxlan_process_l3vni_oper_down(zl3vni
);
5212 /* delete and uninstall all rmacs */
5213 hash_iterate(zl3vni
->rmac_table
, zl3vni_del_rmac_hash_entry
,
5216 /* delete and uninstall all next-hops */
5217 hash_iterate(zl3vni
->nh_table
, zl3vni_del_nh_hash_entry
,
5223 /* Add L2VNI for this VNI */
5224 zebra_vxlan_handle_vni_transition(zvrf
, vni
, add
);
5229 int zebra_vxlan_vrf_enable(struct zebra_vrf
*zvrf
)
5231 struct zebra_l3vni
*zl3vni
= NULL
;
5234 zl3vni
= zl3vni_lookup(zvrf
->l3vni
);
5238 zl3vni
->vrf_id
= zvrf_id(zvrf
);
5239 if (is_l3vni_oper_up(zl3vni
))
5240 zebra_vxlan_process_l3vni_oper_up(zl3vni
);
5244 int zebra_vxlan_vrf_disable(struct zebra_vrf
*zvrf
)
5246 struct zebra_l3vni
*zl3vni
= NULL
;
5249 zl3vni
= zl3vni_lookup(zvrf
->l3vni
);
5253 zebra_vxlan_process_l3vni_oper_down(zl3vni
);
5255 /* delete and uninstall all rmacs */
5256 hash_iterate(zl3vni
->rmac_table
, zl3vni_del_rmac_hash_entry
, zl3vni
);
5257 /* delete and uninstall all next-hops */
5258 hash_iterate(zl3vni
->nh_table
, zl3vni_del_nh_hash_entry
, zl3vni
);
5260 zl3vni
->vrf_id
= VRF_UNKNOWN
;
5265 int zebra_vxlan_vrf_delete(struct zebra_vrf
*zvrf
)
5267 struct zebra_l3vni
*zl3vni
= NULL
;
5271 zl3vni
= zl3vni_lookup(zvrf
->l3vni
);
5277 zebra_vxlan_handle_vni_transition(zvrf
, vni
, 0);
5283 * Handle message from client to specify the flooding mechanism for
5284 * BUM packets. The default is to do head-end (ingress) replication
5285 * and the other supported option is to disable it. This applies to
5286 * all BUM traffic and disabling it applies to both the transmit and
5287 * receive direction.
5289 void zebra_vxlan_flood_control(ZAPI_HANDLER_ARGS
)
5292 enum vxlan_flood_control flood_ctrl
;
5294 if (!EVPN_ENABLED(zvrf
)) {
5295 zlog_err("EVPN flood control for non-EVPN VRF %u",
5301 STREAM_GETC(s
, flood_ctrl
);
5303 if (IS_ZEBRA_DEBUG_VXLAN
)
5304 zlog_debug("EVPN flood control %u, currently %u",
5305 flood_ctrl
, zvrf
->vxlan_flood_ctrl
);
5307 if (zvrf
->vxlan_flood_ctrl
== flood_ctrl
)
5310 zvrf
->vxlan_flood_ctrl
= flood_ctrl
;
5312 /* Install or uninstall flood entries corresponding to
5315 hash_iterate(zvrf
->evpn_table
, zebra_evpn_handle_flooding_remote_vteps
,
5323 * Handle message from client to enable/disable advertisement of svi macip
5326 void zebra_vxlan_advertise_svi_macip(ZAPI_HANDLER_ARGS
)
5331 struct zebra_evpn
*zevpn
= NULL
;
5332 struct interface
*ifp
= NULL
;
5334 if (!EVPN_ENABLED(zvrf
)) {
5335 zlog_debug("EVPN SVI-MACIP Adv for non-EVPN VRF %u",
5341 STREAM_GETC(s
, advertise
);
5342 STREAM_GETL(s
, vni
);
5345 if (IS_ZEBRA_DEBUG_VXLAN
)
5346 zlog_debug("EVPN SVI-MACIP Adv %s, currently %s",
5347 advertise
? "enabled" : "disabled",
5348 advertise_svi_macip_enabled(NULL
)
5352 if (zvrf
->advertise_svi_macip
== advertise
)
5357 zvrf
->advertise_svi_macip
= advertise
;
5358 hash_iterate(zvrf
->evpn_table
,
5359 zebra_evpn_gw_macip_add_for_evpn_hash
,
5362 hash_iterate(zvrf
->evpn_table
,
5363 zebra_evpn_svi_macip_del_for_evpn_hash
,
5365 zvrf
->advertise_svi_macip
= advertise
;
5369 struct zebra_if
*zif
= NULL
;
5370 struct interface
*vlan_if
= NULL
;
5371 struct zebra_vxlan_vni
*zl2_info_vni
;
5374 zevpn
= zebra_evpn_lookup(vni
);
5378 if (IS_ZEBRA_DEBUG_VXLAN
)
5380 "EVPN SVI macip Adv %s on VNI %d, currently %s",
5381 advertise
? "enabled" : "disabled", vni
,
5382 advertise_svi_macip_enabled(zevpn
)
5386 old_advertise
= advertise_svi_macip_enabled(zevpn
);
5388 /* Store flag even though SVI is not present.
5389 * Once SVI comes up triggers self MAC-IP route add.
5391 zevpn
->advertise_svi_macip
= advertise
;
5392 if (advertise_svi_macip_enabled(zevpn
) == old_advertise
)
5395 ifp
= zevpn
->vxlan_if
;
5401 /* If down or not mapped to a bridge, we're done. */
5402 if (!if_is_operative(ifp
) || !zif
->brslave_info
.br_if
)
5405 zl2_info_vni
= zebra_vxlan_if_vni_find(zif
, vni
);
5409 vlan_if
= zvni_map_to_svi(zl2_info_vni
->access_vlan
,
5410 zif
->brslave_info
.br_if
);
5415 /* Add primary SVI MAC-IP */
5416 zebra_evpn_add_macip_for_intf(vlan_if
, zevpn
);
5418 /* Del primary SVI MAC-IP */
5419 zebra_evpn_del_macip_for_intf(vlan_if
, zevpn
);
5428 * Handle message from client to enable/disable advertisement of g/w macip
5431 void zebra_vxlan_advertise_subnet(ZAPI_HANDLER_ARGS
)
5436 struct zebra_evpn
*zevpn
= NULL
;
5437 struct interface
*ifp
= NULL
;
5438 struct zebra_if
*zif
= NULL
;
5439 struct interface
*vlan_if
= NULL
;
5440 struct zebra_vxlan_vni
*zl2_info_vni
= NULL
;
5442 if (!EVPN_ENABLED(zvrf
)) {
5443 zlog_debug("EVPN GW-MACIP Adv for non-EVPN VRF %u",
5449 STREAM_GETC(s
, advertise
);
5450 STREAM_GET(&vni
, s
, 3);
5452 zevpn
= zebra_evpn_lookup(vni
);
5456 if (zevpn
->advertise_subnet
== advertise
)
5459 if (IS_ZEBRA_DEBUG_VXLAN
)
5460 zlog_debug("EVPN subnet Adv %s on VNI %d, currently %s",
5461 advertise
? "enabled" : "disabled", vni
,
5462 zevpn
->advertise_subnet
? "enabled" : "disabled");
5465 zevpn
->advertise_subnet
= advertise
;
5467 ifp
= zevpn
->vxlan_if
;
5473 /* If down or not mapped to a bridge, we're done. */
5474 if (!if_is_operative(ifp
) || !zif
->brslave_info
.br_if
)
5477 zl2_info_vni
= zebra_vxlan_if_vni_find(zif
, vni
);
5481 vlan_if
= zvni_map_to_svi(zl2_info_vni
->access_vlan
,
5482 zif
->brslave_info
.br_if
);
5486 if (zevpn
->advertise_subnet
)
5487 zebra_evpn_advertise_subnet(zevpn
, vlan_if
, 1);
5489 zebra_evpn_advertise_subnet(zevpn
, vlan_if
, 0);
5496 * Handle message from client to enable/disable advertisement of g/w macip
5499 void zebra_vxlan_advertise_gw_macip(ZAPI_HANDLER_ARGS
)
5504 struct zebra_evpn
*zevpn
= NULL
;
5505 struct interface
*ifp
= NULL
;
5507 if (!EVPN_ENABLED(zvrf
)) {
5508 zlog_debug("EVPN GW-MACIP Adv for non-EVPN VRF %u",
5514 STREAM_GETC(s
, advertise
);
5515 STREAM_GETL(s
, vni
);
5518 if (IS_ZEBRA_DEBUG_VXLAN
)
5519 zlog_debug("EVPN gateway macip Adv %s, currently %s",
5520 advertise
? "enabled" : "disabled",
5521 advertise_gw_macip_enabled(NULL
)
5525 if (zvrf
->advertise_gw_macip
== advertise
)
5528 zvrf
->advertise_gw_macip
= advertise
;
5530 if (advertise_gw_macip_enabled(zevpn
))
5531 hash_iterate(zvrf
->evpn_table
,
5532 zebra_evpn_gw_macip_add_for_evpn_hash
,
5535 hash_iterate(zvrf
->evpn_table
,
5536 zebra_evpn_gw_macip_del_for_evpn_hash
,
5540 struct zebra_if
*zif
= NULL
;
5541 struct interface
*vlan_if
= NULL
;
5542 struct interface
*vrr_if
= NULL
;
5543 struct zebra_vxlan_vni
*zl2_info_vni
= NULL
;
5546 zevpn
= zebra_evpn_lookup(vni
);
5550 if (IS_ZEBRA_DEBUG_VXLAN
)
5552 "EVPN gateway macip Adv %s on VNI %d, currently %s",
5553 advertise
? "enabled" : "disabled", vni
,
5554 advertise_gw_macip_enabled(zevpn
) ? "enabled"
5557 old_advertise
= advertise_gw_macip_enabled(zevpn
);
5559 zevpn
->advertise_gw_macip
= advertise
;
5560 if (advertise_gw_macip_enabled(zevpn
) == old_advertise
)
5563 ifp
= zevpn
->vxlan_if
;
5569 /* If down or not mapped to a bridge, we're done. */
5570 if (!if_is_operative(ifp
) || !zif
->brslave_info
.br_if
)
5573 zl2_info_vni
= zebra_vxlan_if_vni_find(zif
, vni
);
5577 vlan_if
= zvni_map_to_svi(zl2_info_vni
->access_vlan
,
5578 zif
->brslave_info
.br_if
);
5582 if (advertise_gw_macip_enabled(zevpn
)) {
5583 /* Add primary SVI MAC-IP */
5584 zebra_evpn_add_macip_for_intf(vlan_if
, zevpn
);
5586 /* Add VRR MAC-IP - if any*/
5587 vrr_if
= zebra_get_vrr_intf_for_svi(vlan_if
);
5589 zebra_evpn_add_macip_for_intf(vrr_if
, zevpn
);
5591 /* Del primary MAC-IP */
5592 zebra_evpn_del_macip_for_intf(vlan_if
, zevpn
);
5594 /* Del VRR MAC-IP - if any*/
5595 vrr_if
= zebra_get_vrr_intf_for_svi(vlan_if
);
5597 zebra_evpn_del_macip_for_intf(vrr_if
, zevpn
);
5605 static int macfdb_read_ns(struct ns
*ns
,
5606 void *_in_param
__attribute__((unused
)),
5607 void **out_param
__attribute__((unused
)))
5609 struct zebra_ns
*zns
= ns
->info
;
5612 return NS_WALK_CONTINUE
;
5615 static int neigh_read_ns(struct ns
*ns
,
5616 void *_in_param
__attribute__((unused
)),
5617 void **out_param
__attribute__((unused
)))
5619 struct zebra_ns
*zns
= ns
->info
;
5622 return NS_WALK_CONTINUE
;
5626 * Handle message from client to learn (or stop learning) about VNIs and MACs.
5627 * When enabled, the VNI hash table will be built and MAC FDB table read;
5628 * when disabled, the entries should be deleted and remote VTEPs and MACs
5629 * uninstalled from the kernel.
5630 * This also informs the setting for BUM handling at the time this change
5631 * occurs; it is relevant only when specifying "learn".
5633 void zebra_vxlan_advertise_all_vni(ZAPI_HANDLER_ARGS
)
5635 struct stream
*s
= NULL
;
5637 enum vxlan_flood_control flood_ctrl
;
5639 /* Mismatch between EVPN VRF and current VRF (should be prevented by
5641 if (is_evpn_enabled() && !EVPN_ENABLED(zvrf
))
5645 STREAM_GETC(s
, advertise
);
5646 STREAM_GETC(s
, flood_ctrl
);
5648 if (IS_ZEBRA_DEBUG_VXLAN
)
5649 zlog_debug("EVPN VRF %s(%u) VNI Adv %s, currently %s, flood control %u",
5650 zvrf_name(zvrf
), zvrf_id(zvrf
),
5651 advertise
? "enabled" : "disabled",
5652 is_evpn_enabled() ? "enabled" : "disabled",
5655 if (zvrf
->advertise_all_vni
== advertise
)
5658 zvrf
->advertise_all_vni
= advertise
;
5659 if (EVPN_ENABLED(zvrf
)) {
5660 zrouter
.evpn_vrf
= zvrf
;
5662 /* Note BUM handling */
5663 zvrf
->vxlan_flood_ctrl
= flood_ctrl
;
5665 /* Replay all ESs */
5666 zebra_evpn_es_send_all_to_client(true /* add */);
5668 /* Build EVPN hash table and inform BGP. */
5669 zevpn_build_hash_table();
5671 /* Add all SVI (L3 GW) MACs to BGP*/
5672 hash_iterate(zvrf
->evpn_table
,
5673 zebra_evpn_gw_macip_add_for_evpn_hash
, NULL
);
5675 /* Read the MAC FDB */
5676 ns_walk_func(macfdb_read_ns
, NULL
, NULL
);
5678 /* Read neighbors */
5679 ns_walk_func(neigh_read_ns
, NULL
, NULL
);
5681 /* Cleanup VTEPs for all EVPNs - uninstall from
5682 * kernel and free entries.
5684 hash_iterate(zvrf
->evpn_table
, zebra_evpn_vxlan_cleanup_all
,
5687 /* Delete all ESs in BGP */
5688 zebra_evpn_es_send_all_to_client(false /* add */);
5690 /* cleanup all l3vnis */
5691 hash_iterate(zrouter
.l3vni_table
, zl3vni_cleanup_all
, NULL
);
5693 /* Mark as "no EVPN VRF" */
5694 zrouter
.evpn_vrf
= NULL
;
5702 * Allocate EVPN hash table for this VRF and do other initialization.
5703 * NOTE: Currently supported only for default VRF.
5705 void zebra_vxlan_init_tables(struct zebra_vrf
*zvrf
)
5712 snprintf(buffer
, sizeof(buffer
), "Zebra VRF EVPN Table: %s",
5714 zvrf
->evpn_table
= hash_create_size(8, zebra_evpn_hash_keymake
,
5715 zebra_evpn_hash_cmp
, buffer
);
5717 snprintf(buffer
, sizeof(buffer
), "Zebra VxLAN SG Table: %s",
5719 zvrf
->vxlan_sg_table
= hash_create_size(8, zebra_vxlan_sg_hash_key_make
,
5720 zebra_vxlan_sg_hash_eq
, buffer
);
5723 /* Cleanup EVPN info, but don't free the table. */
5724 void zebra_vxlan_cleanup_tables(struct zebra_vrf
*zvrf
)
5726 struct zebra_vrf
*evpn_zvrf
= zebra_vrf_get_evpn();
5728 hash_iterate(zvrf
->evpn_table
, zebra_evpn_vxlan_cleanup_all
, zvrf
);
5729 zebra_vxlan_cleanup_sg_table(zvrf
);
5731 if (zvrf
== evpn_zvrf
)
5732 zebra_evpn_es_cleanup();
5735 /* Close all EVPN handling */
5736 void zebra_vxlan_close_tables(struct zebra_vrf
*zvrf
)
5740 hash_iterate(zvrf
->evpn_table
, zebra_evpn_vxlan_cleanup_all
, zvrf
);
5741 hash_free(zvrf
->evpn_table
);
5742 if (zvrf
->vxlan_sg_table
) {
5743 zebra_vxlan_cleanup_sg_table(zvrf
);
5744 hash_free(zvrf
->vxlan_sg_table
);
5745 zvrf
->vxlan_sg_table
= NULL
;
5749 /* init the l3vni table */
5750 void zebra_vxlan_init(void)
5752 zrouter
.l3vni_table
= hash_create(l3vni_hash_keymake
, l3vni_hash_cmp
,
5753 "Zebra VRF L3 VNI table");
5755 svd_nh_table
= zebra_neigh_db_create("Zebra SVD next-hop table");
5757 zrouter
.evpn_vrf
= NULL
;
5758 zebra_evpn_mh_init();
5761 /* free l3vni table */
5762 void zebra_vxlan_disable(void)
5764 hash_free(zrouter
.l3vni_table
);
5765 zebra_evpn_mh_terminate();
5768 /* get the l3vni svi ifindex */
5769 ifindex_t
get_l3vni_svi_ifindex(vrf_id_t vrf_id
)
5771 struct zebra_l3vni
*zl3vni
= NULL
;
5773 zl3vni
= zl3vni_from_vrf(vrf_id
);
5774 if (!zl3vni
|| !is_l3vni_oper_up(zl3vni
))
5777 return zl3vni
->svi_if
->ifindex
;
5780 /* get the l3vni vxlan ifindex */
5781 ifindex_t
get_l3vni_vxlan_ifindex(vrf_id_t vrf_id
)
5783 struct zebra_l3vni
*zl3vni
= NULL
;
5785 zl3vni
= zl3vni_from_vrf(vrf_id
);
5786 if (!zl3vni
|| !is_l3vni_oper_up(zl3vni
))
5789 return zl3vni
->vxlan_if
->ifindex
;
5792 /* get the l3vni vni */
5793 vni_t
get_l3vni_vni(vrf_id_t vrf_id
)
5795 struct zebra_l3vni
*zl3vni
= NULL
;
5797 zl3vni
= zl3vni_from_vrf(vrf_id
);
5798 if (!zl3vni
|| !is_l3vni_oper_up(zl3vni
))
5804 /* is the vrf l3vni SVD backed? */
5805 bool is_vrf_l3vni_svd_backed(vrf_id_t vrf_id
)
5807 struct zebra_l3vni
*zl3vni
= NULL
;
5809 zl3vni
= zl3vni_from_vrf(vrf_id
);
5810 if (!zl3vni
|| !is_l3vni_oper_up(zl3vni
))
5813 return IS_ZL3VNI_SVD_BACKED(zl3vni
);
5816 /************************** vxlan SG cache management ************************/
5817 /* Inform PIM about the mcast group */
5818 static int zebra_vxlan_sg_send(struct zebra_vrf
*zvrf
,
5819 struct prefix_sg
*sg
,
5820 char *sg_str
, uint16_t cmd
)
5822 struct zserv
*client
= NULL
;
5823 struct stream
*s
= NULL
;
5825 client
= zserv_find_client(ZEBRA_ROUTE_PIM
, 0);
5829 if (!CHECK_FLAG(zvrf
->flags
, ZEBRA_PIM_SEND_VXLAN_SG
))
5832 s
= stream_new(ZEBRA_MAX_PACKET_SIZ
);
5834 zclient_create_header(s
, cmd
, VRF_DEFAULT
);
5835 stream_putl(s
, IPV4_MAX_BYTELEN
);
5836 stream_put(s
, &sg
->src
.s_addr
, IPV4_MAX_BYTELEN
);
5837 stream_put(s
, &sg
->grp
.s_addr
, IPV4_MAX_BYTELEN
);
5839 /* Write packet size. */
5840 stream_putw_at(s
, 0, stream_get_endp(s
));
5842 if (IS_ZEBRA_DEBUG_VXLAN
)
5845 (cmd
== ZEBRA_VXLAN_SG_ADD
) ? "add" : "del", sg_str
,
5846 zebra_route_string(client
->proto
));
5848 if (cmd
== ZEBRA_VXLAN_SG_ADD
)
5849 client
->vxlan_sg_add_cnt
++;
5851 client
->vxlan_sg_del_cnt
++;
5853 return zserv_send_message(client
, s
);
5856 static unsigned int zebra_vxlan_sg_hash_key_make(const void *p
)
5858 const struct zebra_vxlan_sg
*vxlan_sg
= p
;
5860 return (jhash_2words(vxlan_sg
->sg
.src
.s_addr
,
5861 vxlan_sg
->sg
.grp
.s_addr
, 0));
5864 static bool zebra_vxlan_sg_hash_eq(const void *p1
, const void *p2
)
5866 const struct zebra_vxlan_sg
*sg1
= p1
;
5867 const struct zebra_vxlan_sg
*sg2
= p2
;
5869 return ((sg1
->sg
.src
.s_addr
== sg2
->sg
.src
.s_addr
)
5870 && (sg1
->sg
.grp
.s_addr
== sg2
->sg
.grp
.s_addr
));
5873 static struct zebra_vxlan_sg
*zebra_vxlan_sg_new(struct zebra_vrf
*zvrf
,
5874 struct prefix_sg
*sg
)
5876 struct zebra_vxlan_sg
*vxlan_sg
;
5878 vxlan_sg
= XCALLOC(MTYPE_ZVXLAN_SG
, sizeof(*vxlan_sg
));
5880 vxlan_sg
->zvrf
= zvrf
;
5882 prefix_sg2str(sg
, vxlan_sg
->sg_str
);
5884 vxlan_sg
= hash_get(zvrf
->vxlan_sg_table
, vxlan_sg
, hash_alloc_intern
);
5886 if (IS_ZEBRA_DEBUG_VXLAN
)
5887 zlog_debug("vxlan SG %s created", vxlan_sg
->sg_str
);
5892 static struct zebra_vxlan_sg
*zebra_vxlan_sg_find(struct zebra_vrf
*zvrf
,
5893 struct prefix_sg
*sg
)
5895 struct zebra_vxlan_sg lookup
;
5898 return hash_lookup(zvrf
->vxlan_sg_table
, &lookup
);
5901 static struct zebra_vxlan_sg
*zebra_vxlan_sg_add(struct zebra_vrf
*zvrf
,
5902 struct prefix_sg
*sg
)
5904 struct zebra_vxlan_sg
*vxlan_sg
;
5905 struct zebra_vxlan_sg
*parent
= NULL
;
5908 vxlan_sg
= zebra_vxlan_sg_find(zvrf
, sg
);
5912 /* create a *G entry for every BUM group implicitly -
5913 * 1. The SG entry is used by pimd to setup the vxlan-origination-mroute
5914 * 2. the XG entry is used by pimd to setup the
5915 * vxlan-termination-mroute
5917 if (sg
->src
.s_addr
!= INADDR_ANY
) {
5918 memset(&sip
, 0, sizeof(sip
));
5919 parent
= zebra_vxlan_sg_do_ref(zvrf
, sip
, sg
->grp
);
5924 vxlan_sg
= zebra_vxlan_sg_new(zvrf
, sg
);
5926 zebra_vxlan_sg_send(zvrf
, sg
, vxlan_sg
->sg_str
,
5927 ZEBRA_VXLAN_SG_ADD
);
5932 static void zebra_vxlan_sg_del(struct zebra_vxlan_sg
*vxlan_sg
)
5935 struct zebra_vrf
*zvrf
;
5937 zvrf
= vrf_info_lookup(VRF_DEFAULT
);
5941 /* On SG entry deletion remove the reference to its parent XG
5944 if (vxlan_sg
->sg
.src
.s_addr
!= INADDR_ANY
) {
5945 memset(&sip
, 0, sizeof(sip
));
5946 zebra_vxlan_sg_do_deref(zvrf
, sip
, vxlan_sg
->sg
.grp
);
5949 zebra_vxlan_sg_send(zvrf
, &vxlan_sg
->sg
,
5950 vxlan_sg
->sg_str
, ZEBRA_VXLAN_SG_DEL
);
5952 hash_release(vxlan_sg
->zvrf
->vxlan_sg_table
, vxlan_sg
);
5954 if (IS_ZEBRA_DEBUG_VXLAN
)
5955 zlog_debug("VXLAN SG %s deleted", vxlan_sg
->sg_str
);
5957 XFREE(MTYPE_ZVXLAN_SG
, vxlan_sg
);
5960 static void zebra_vxlan_sg_do_deref(struct zebra_vrf
*zvrf
,
5961 struct in_addr sip
, struct in_addr mcast_grp
)
5963 struct zebra_vxlan_sg
*vxlan_sg
;
5964 struct prefix_sg sg
;
5966 sg
.family
= AF_INET
;
5967 sg
.prefixlen
= IPV4_MAX_BYTELEN
;
5970 vxlan_sg
= zebra_vxlan_sg_find(zvrf
, &sg
);
5974 if (vxlan_sg
->ref_cnt
)
5975 --vxlan_sg
->ref_cnt
;
5977 if (!vxlan_sg
->ref_cnt
)
5978 zebra_vxlan_sg_del(vxlan_sg
);
5981 static struct zebra_vxlan_sg
*zebra_vxlan_sg_do_ref(struct zebra_vrf
*zvrf
,
5983 struct in_addr mcast_grp
)
5985 struct zebra_vxlan_sg
*vxlan_sg
;
5986 struct prefix_sg sg
;
5988 sg
.family
= AF_INET
;
5989 sg
.prefixlen
= IPV4_MAX_BYTELEN
;
5992 vxlan_sg
= zebra_vxlan_sg_add(zvrf
, &sg
);
5994 ++vxlan_sg
->ref_cnt
;
5999 void zebra_vxlan_sg_deref(struct in_addr local_vtep_ip
,
6000 struct in_addr mcast_grp
)
6002 struct zebra_vrf
*zvrf
;
6004 if (local_vtep_ip
.s_addr
== INADDR_ANY
6005 || mcast_grp
.s_addr
== INADDR_ANY
)
6008 zvrf
= vrf_info_lookup(VRF_DEFAULT
);
6012 zebra_vxlan_sg_do_deref(zvrf
, local_vtep_ip
, mcast_grp
);
6015 void zebra_vxlan_sg_ref(struct in_addr local_vtep_ip
, struct in_addr mcast_grp
)
6017 struct zebra_vrf
*zvrf
;
6019 if (local_vtep_ip
.s_addr
== INADDR_ANY
6020 || mcast_grp
.s_addr
== INADDR_ANY
)
6023 zvrf
= vrf_info_lookup(VRF_DEFAULT
);
6026 zebra_vxlan_sg_do_ref(zvrf
, local_vtep_ip
, mcast_grp
);
6029 static void zebra_vxlan_xg_pre_cleanup(struct hash_bucket
*bucket
, void *arg
)
6031 struct zebra_vxlan_sg
*vxlan_sg
= (struct zebra_vxlan_sg
*)bucket
->data
;
6033 /* increment the ref count against (*,G) to prevent them from being
6036 if (vxlan_sg
->sg
.src
.s_addr
== INADDR_ANY
)
6037 ++vxlan_sg
->ref_cnt
;
6040 static void zebra_vxlan_xg_post_cleanup(struct hash_bucket
*bucket
, void *arg
)
6042 struct zebra_vxlan_sg
*vxlan_sg
= (struct zebra_vxlan_sg
*)bucket
->data
;
6044 /* decrement the dummy ref count against (*,G) to delete them */
6045 if (vxlan_sg
->sg
.src
.s_addr
== INADDR_ANY
) {
6046 if (vxlan_sg
->ref_cnt
)
6047 --vxlan_sg
->ref_cnt
;
6048 if (!vxlan_sg
->ref_cnt
)
6049 zebra_vxlan_sg_del(vxlan_sg
);
6053 static void zebra_vxlan_sg_cleanup(struct hash_bucket
*bucket
, void *arg
)
6055 struct zebra_vxlan_sg
*vxlan_sg
= (struct zebra_vxlan_sg
*)bucket
->data
;
6057 zebra_vxlan_sg_del(vxlan_sg
);
6060 static void zebra_vxlan_cleanup_sg_table(struct zebra_vrf
*zvrf
)
6062 /* increment the ref count against (*,G) to prevent them from being
6065 hash_iterate(zvrf
->vxlan_sg_table
, zebra_vxlan_xg_pre_cleanup
, NULL
);
6067 hash_iterate(zvrf
->vxlan_sg_table
, zebra_vxlan_sg_cleanup
, NULL
);
6069 /* decrement the dummy ref count against the XG entries */
6070 hash_iterate(zvrf
->vxlan_sg_table
, zebra_vxlan_xg_post_cleanup
, NULL
);
6073 static void zebra_vxlan_sg_replay_send(struct hash_bucket
*bucket
, void *arg
)
6075 struct zebra_vxlan_sg
*vxlan_sg
= (struct zebra_vxlan_sg
*)bucket
->data
;
6077 zebra_vxlan_sg_send(vxlan_sg
->zvrf
, &vxlan_sg
->sg
,
6078 vxlan_sg
->sg_str
, ZEBRA_VXLAN_SG_ADD
);
6081 /* Handle message from client to replay vxlan SG entries */
6082 void zebra_vxlan_sg_replay(ZAPI_HANDLER_ARGS
)
6084 if (IS_ZEBRA_DEBUG_VXLAN
)
6085 zlog_debug("VxLAN SG updates to PIM, start");
6087 SET_FLAG(zvrf
->flags
, ZEBRA_PIM_SEND_VXLAN_SG
);
6089 if (!EVPN_ENABLED(zvrf
)) {
6090 if (IS_ZEBRA_DEBUG_VXLAN
)
6091 zlog_debug("VxLAN SG replay request on unexpected vrf %d",
6096 hash_iterate(zvrf
->vxlan_sg_table
, zebra_vxlan_sg_replay_send
, NULL
);
6100 /* Cleanup EVPN configuration of a specific VRF */
6101 static void zebra_evpn_vrf_cfg_cleanup(struct zebra_vrf
*zvrf
)
6103 struct zebra_l3vni
*zl3vni
= NULL
;
6105 zvrf
->advertise_all_vni
= 0;
6106 zvrf
->advertise_gw_macip
= 0;
6107 zvrf
->advertise_svi_macip
= 0;
6108 zvrf
->vxlan_flood_ctrl
= VXLAN_FLOOD_HEAD_END_REPL
;
6110 hash_iterate(zvrf
->evpn_table
, zebra_evpn_cfg_cleanup
, NULL
);
6113 zl3vni
= zl3vni_lookup(zvrf
->l3vni
);
6115 /* delete and uninstall all rmacs */
6116 hash_iterate(zl3vni
->rmac_table
, zl3vni_del_rmac_hash_entry
,
6118 /* delete and uninstall all next-hops */
6119 hash_iterate(zl3vni
->nh_table
, zl3vni_del_nh_hash_entry
,
6124 /* Cleanup BGP EVPN configuration upon client disconnect */
6125 static int zebra_evpn_bgp_cfg_clean_up(struct zserv
*client
)
6128 struct zebra_vrf
*zvrf
;
6130 RB_FOREACH (vrf
, vrf_id_head
, &vrfs_by_id
) {
6133 zebra_evpn_vrf_cfg_cleanup(zvrf
);
6139 static int zebra_evpn_pim_cfg_clean_up(struct zserv
*client
)
6141 struct zebra_vrf
*zvrf
= zebra_vrf_get_evpn();
6143 if (CHECK_FLAG(zvrf
->flags
, ZEBRA_PIM_SEND_VXLAN_SG
)) {
6144 if (IS_ZEBRA_DEBUG_VXLAN
)
6145 zlog_debug("VxLAN SG updates to PIM, stop");
6146 UNSET_FLAG(zvrf
->flags
, ZEBRA_PIM_SEND_VXLAN_SG
);
6152 static int zebra_evpn_cfg_clean_up(struct zserv
*client
)
6154 if (client
->proto
== ZEBRA_ROUTE_BGP
)
6155 return zebra_evpn_bgp_cfg_clean_up(client
);
6157 if (client
->proto
== ZEBRA_ROUTE_PIM
)
6158 return zebra_evpn_pim_cfg_clean_up(client
);
6164 * Handle results for vxlan dataplane operations.
6166 extern void zebra_vxlan_handle_result(struct zebra_dplane_ctx
*ctx
)
6171 /* Config knob for accepting lower sequence numbers */
6172 void zebra_vxlan_set_accept_bgp_seq(bool set
)
6174 accept_bgp_seq
= set
;
6177 bool zebra_vxlan_get_accept_bgp_seq(void)
6179 return accept_bgp_seq
;
6182 /* Cleanup BGP EVPN configuration upon client disconnect */
6183 extern void zebra_evpn_init(void)
6185 hook_register(zserv_client_close
, zebra_evpn_cfg_clean_up
);