2 * Zebra EVPN for VxLAN code
3 * Copyright (C) 2016, 2017 Cumulus Networks, Inc.
5 * This file is part of FRR.
7 * FRR is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation; either version 2, or (at your option) any
12 * FRR is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with FRR; see the file COPYING. If not, write to the Free
19 * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
37 #include <linux/neighbour.h>
39 #include "lib/printfrr.h"
41 #include "zebra/zebra_router.h"
42 #include "zebra/debug.h"
43 #include "zebra/interface.h"
44 #include "zebra/rib.h"
46 #include "zebra/rt_netlink.h"
47 #include "zebra/zebra_errors.h"
48 #include "zebra/zebra_l2.h"
49 #include "zebra/zebra_ns.h"
50 #include "zebra/zebra_vrf.h"
51 #include "zebra/zebra_vxlan.h"
52 #include "zebra/zebra_vxlan_private.h"
53 #include "zebra/zebra_evpn.h"
54 #include "zebra/zebra_evpn_mac.h"
55 #include "zebra/zebra_evpn_neigh.h"
56 #include "zebra/zebra_evpn_mh.h"
57 #include "zebra/zebra_evpn_vxlan.h"
58 #include "zebra/zebra_router.h"
60 DEFINE_MTYPE_STATIC(ZEBRA
, HOST_PREFIX
, "host prefix");
61 DEFINE_MTYPE_STATIC(ZEBRA
, ZL3VNI
, "L3 VNI hash");
62 DEFINE_MTYPE_STATIC(ZEBRA
, L3VNI_MAC
, "EVPN L3VNI MAC");
63 DEFINE_MTYPE_STATIC(ZEBRA
, L3NEIGH
, "EVPN Neighbor");
64 DEFINE_MTYPE_STATIC(ZEBRA
, ZVXLAN_SG
, "zebra VxLAN multicast group");
65 DEFINE_MTYPE_STATIC(ZEBRA
, EVPN_VTEP
, "zebra VxLAN VTEP IP");
67 DEFINE_HOOK(zebra_rmac_update
,
68 (struct zebra_mac
* rmac
, struct zebra_l3vni
*zl3vni
, bool delete,
70 (rmac
, zl3vni
, delete, reason
));
73 static bool accept_bgp_seq
= true;
75 /* static function declarations */
76 static void zevpn_print_neigh_hash_all_evpn(struct hash_bucket
*bucket
,
78 static void zl3vni_print_nh(struct zebra_neigh
*n
, struct vty
*vty
,
80 static void zl3vni_print_rmac(struct zebra_mac
*zrmac
, struct vty
*vty
,
82 static void zevpn_print_mac_hash_all_evpn(struct hash_bucket
*bucket
, void *ctxt
);
84 /* l3-vni next-hop neigh related APIs */
85 static struct zebra_neigh
*zl3vni_nh_lookup(struct zebra_l3vni
*zl3vni
,
86 const struct ipaddr
*ip
);
87 static void *zl3vni_nh_alloc(void *p
);
88 static struct zebra_neigh
*zl3vni_nh_add(struct zebra_l3vni
*zl3vni
,
89 const struct ipaddr
*vtep_ip
,
90 const struct ethaddr
*rmac
);
91 static int zl3vni_nh_del(struct zebra_l3vni
*zl3vni
, struct zebra_neigh
*n
);
92 static int zl3vni_nh_install(struct zebra_l3vni
*zl3vni
, struct zebra_neigh
*n
);
93 static int zl3vni_nh_uninstall(struct zebra_l3vni
*zl3vni
,
94 struct zebra_neigh
*n
);
96 /* l3-vni rmac related APIs */
97 static void zl3vni_print_rmac_hash(struct hash_bucket
*, void *);
98 static struct zebra_mac
*zl3vni_rmac_lookup(struct zebra_l3vni
*zl3vni
,
99 const struct ethaddr
*rmac
);
100 static void *zl3vni_rmac_alloc(void *p
);
101 static struct zebra_mac
*zl3vni_rmac_add(struct zebra_l3vni
*zl3vni
,
102 const struct ethaddr
*rmac
);
103 static int zl3vni_rmac_del(struct zebra_l3vni
*zl3vni
, struct zebra_mac
*zrmac
);
104 static int zl3vni_rmac_install(struct zebra_l3vni
*zl3vni
,
105 struct zebra_mac
*zrmac
);
106 static int zl3vni_rmac_uninstall(struct zebra_l3vni
*zl3vni
,
107 struct zebra_mac
*zrmac
);
109 /* l3-vni related APIs*/
110 static void *zl3vni_alloc(void *p
);
111 static struct zebra_l3vni
*zl3vni_add(vni_t vni
, vrf_id_t vrf_id
);
112 static int zl3vni_del(struct zebra_l3vni
*zl3vni
);
114 static void zevpn_build_hash_table(void);
115 static unsigned int zebra_vxlan_sg_hash_key_make(const void *p
);
116 static bool zebra_vxlan_sg_hash_eq(const void *p1
, const void *p2
);
117 static void zebra_vxlan_sg_do_deref(struct zebra_vrf
*zvrf
,
118 struct in_addr sip
, struct in_addr mcast_grp
);
119 static struct zebra_vxlan_sg
*zebra_vxlan_sg_do_ref(struct zebra_vrf
*vrf
,
121 struct in_addr mcast_grp
);
122 static void zebra_vxlan_cleanup_sg_table(struct zebra_vrf
*zvrf
);
124 bool zebra_evpn_do_dup_addr_detect(struct zebra_vrf
*zvrf
)
126 return zvrf
->dup_addr_detect
&& zebra_evpn_mh_do_dup_addr_detect();
129 /* Private functions */
130 static int host_rb_entry_compare(const struct host_rb_entry
*hle1
,
131 const struct host_rb_entry
*hle2
)
133 if (hle1
->p
.family
< hle2
->p
.family
)
136 if (hle1
->p
.family
> hle2
->p
.family
)
139 if (hle1
->p
.prefixlen
< hle2
->p
.prefixlen
)
142 if (hle1
->p
.prefixlen
> hle2
->p
.prefixlen
)
145 if (hle1
->p
.family
== AF_INET
) {
146 if (hle1
->p
.u
.prefix4
.s_addr
< hle2
->p
.u
.prefix4
.s_addr
)
149 if (hle1
->p
.u
.prefix4
.s_addr
> hle2
->p
.u
.prefix4
.s_addr
)
153 } else if (hle1
->p
.family
== AF_INET6
) {
154 return memcmp(&hle1
->p
.u
.prefix6
, &hle2
->p
.u
.prefix6
,
156 } else if (hle1
->p
.family
== AF_EVPN
) {
160 /* two (v4/v6) dummy prefixes of route_type BGP_EVPN_AD_ROUTE
161 * are used for all nexthops associated with a non-zero ESI
163 family1
= is_evpn_prefix_ipaddr_v4(
164 (const struct prefix_evpn
*)&hle1
->p
)
167 family2
= is_evpn_prefix_ipaddr_v4(
168 (const struct prefix_evpn
*)&hle2
->p
)
173 if (family1
< family2
)
176 if (family1
> family2
)
181 zlog_debug("%s: Unexpected family type: %d", __func__
,
186 RB_GENERATE(host_rb_tree_entry
, host_rb_entry
, hl_entry
, host_rb_entry_compare
);
188 static uint32_t rb_host_count(struct host_rb_tree_entry
*hrbe
)
190 struct host_rb_entry
*hle
;
193 RB_FOREACH (hle
, host_rb_tree_entry
, hrbe
)
199 static int l3vni_rmac_nh_list_cmp(void *p1
, void *p2
)
201 const struct ipaddr
*vtep_ip1
= p1
;
202 const struct ipaddr
*vtep_ip2
= p2
;
204 return !ipaddr_cmp(vtep_ip1
, vtep_ip2
);
207 static void l3vni_rmac_nh_free(struct ipaddr
*vtep_ip
)
209 XFREE(MTYPE_EVPN_VTEP
, vtep_ip
);
212 static void l3vni_rmac_nh_list_nh_delete(struct zebra_l3vni
*zl3vni
,
213 struct zebra_mac
*zrmac
,
214 struct ipaddr
*vtep_ip
)
216 struct listnode
*node
= NULL
, *nnode
= NULL
;
217 struct ipaddr
*vtep
= NULL
;
219 for (ALL_LIST_ELEMENTS(zrmac
->nh_list
, node
, nnode
, vtep
)) {
220 if (ipaddr_cmp(vtep
, vtep_ip
) == 0)
225 l3vni_rmac_nh_free(vtep
);
226 list_delete_node(zrmac
->nh_list
, node
);
231 * Print neighbors for all EVPN.
233 static void zevpn_print_neigh_hash_all_evpn(struct hash_bucket
*bucket
,
237 json_object
*json
= NULL
, *json_evpn
= NULL
;
238 struct zebra_evpn
*zevpn
;
240 struct neigh_walk_ctx wctx
;
241 char vni_str
[VNI_STR_LEN
];
244 vty
= (struct vty
*)args
[0];
245 json
= (json_object
*)args
[1];
246 print_dup
= (uint32_t)(uintptr_t)args
[2];
248 zevpn
= (struct zebra_evpn
*)bucket
->data
;
250 num_neigh
= hashcount(zevpn
->neigh_table
);
253 num_neigh
= num_dup_detected_neighs(zevpn
);
257 "\nVNI %u #ARP (IPv4 and IPv6, local and remote) %u\n\n",
258 zevpn
->vni
, num_neigh
);
260 json_evpn
= json_object_new_object();
261 json_object_int_add(json_evpn
, "numArpNd", num_neigh
);
262 snprintf(vni_str
, VNI_STR_LEN
, "%u", zevpn
->vni
);
267 json_object_object_add(json
, vni_str
, json_evpn
);
271 /* Since we have IPv6 addresses to deal with which can vary widely in
272 * size, we try to be a bit more elegant in display by first computing
275 memset(&wctx
, 0, sizeof(wctx
));
278 wctx
.addr_width
= 15;
279 wctx
.json
= json_evpn
;
280 hash_iterate(zevpn
->neigh_table
, zebra_evpn_find_neigh_addr_width
,
284 zebra_evpn_print_neigh_hdr(vty
, &wctx
);
287 hash_iterate(zevpn
->neigh_table
,
288 zebra_evpn_print_dad_neigh_hash
, &wctx
);
290 hash_iterate(zevpn
->neigh_table
, zebra_evpn_print_neigh_hash
,
294 json_object_object_add(json
, vni_str
, json_evpn
);
298 * Print neighbors for all EVPNs in detail.
300 static void zevpn_print_neigh_hash_all_evpn_detail(struct hash_bucket
*bucket
,
304 json_object
*json
= NULL
, *json_evpn
= NULL
;
305 struct zebra_evpn
*zevpn
;
307 struct neigh_walk_ctx wctx
;
308 char vni_str
[VNI_STR_LEN
];
311 vty
= (struct vty
*)args
[0];
312 json
= (json_object
*)args
[1];
313 print_dup
= (uint32_t)(uintptr_t)args
[2];
315 zevpn
= (struct zebra_evpn
*)bucket
->data
;
318 vty_out(vty
, "{}\n");
321 num_neigh
= hashcount(zevpn
->neigh_table
);
323 if (print_dup
&& num_dup_detected_neighs(zevpn
) == 0)
328 "\nVNI %u #ARP (IPv4 and IPv6, local and remote) %u\n\n",
329 zevpn
->vni
, num_neigh
);
331 json_evpn
= json_object_new_object();
332 json_object_int_add(json_evpn
, "numArpNd", num_neigh
);
333 snprintf(vni_str
, VNI_STR_LEN
, "%u", zevpn
->vni
);
337 json_object_object_add(json
, vni_str
, json_evpn
);
341 memset(&wctx
, 0, sizeof(wctx
));
344 wctx
.addr_width
= 15;
345 wctx
.json
= json_evpn
;
348 hash_iterate(zevpn
->neigh_table
,
349 zebra_evpn_print_dad_neigh_hash_detail
, &wctx
);
351 hash_iterate(zevpn
->neigh_table
,
352 zebra_evpn_print_neigh_hash_detail
, &wctx
);
355 json_object_object_add(json
, vni_str
, json_evpn
);
358 /* print a specific next hop for an l3vni */
359 static void zl3vni_print_nh(struct zebra_neigh
*n
, struct vty
*vty
,
362 char buf1
[ETHER_ADDR_STRLEN
];
363 char buf2
[INET6_ADDRSTRLEN
];
364 json_object
*json_hosts
= NULL
;
365 struct host_rb_entry
*hle
;
368 vty_out(vty
, "Ip: %s\n",
369 ipaddr2str(&n
->ip
, buf2
, sizeof(buf2
)));
370 vty_out(vty
, " RMAC: %s\n",
371 prefix_mac2str(&n
->emac
, buf1
, sizeof(buf1
)));
372 vty_out(vty
, " Refcount: %d\n",
373 rb_host_count(&n
->host_rb
));
374 vty_out(vty
, " Prefixes:\n");
375 RB_FOREACH (hle
, host_rb_tree_entry
, &n
->host_rb
)
376 vty_out(vty
, " %pFX\n", &hle
->p
);
378 json_hosts
= json_object_new_array();
379 json_object_string_add(
380 json
, "ip", ipaddr2str(&(n
->ip
), buf2
, sizeof(buf2
)));
381 json_object_string_add(
383 prefix_mac2str(&n
->emac
, buf2
, sizeof(buf2
)));
384 json_object_int_add(json
, "refCount",
385 rb_host_count(&n
->host_rb
));
386 RB_FOREACH (hle
, host_rb_tree_entry
, &n
->host_rb
)
387 json_object_array_add(json_hosts
,
388 json_object_new_string(prefix2str(
389 &hle
->p
, buf2
, sizeof(buf2
))));
390 json_object_object_add(json
, "prefixList", json_hosts
);
394 /* Print a specific RMAC entry */
395 static void zl3vni_print_rmac(struct zebra_mac
*zrmac
, struct vty
*vty
,
398 struct listnode
*node
= NULL
;
399 struct ipaddr
*vtep
= NULL
;
400 json_object
*json_nhs
= NULL
;
403 vty_out(vty
, "MAC: %pEA\n", &zrmac
->macaddr
);
404 vty_out(vty
, " Remote VTEP: %pI4\n",
405 &zrmac
->fwd_info
.r_vtep_ip
);
407 json_nhs
= json_object_new_array();
408 json_object_string_addf(json
, "routerMac", "%pEA",
410 json_object_string_addf(json
, "vtepIp", "%pI4",
411 &zrmac
->fwd_info
.r_vtep_ip
);
412 for (ALL_LIST_ELEMENTS_RO(zrmac
->nh_list
, node
, vtep
)) {
413 json_object_array_add(json_nhs
, json_object_new_stringf(
416 json_object_object_add(json
, "nexthops", json_nhs
);
421 * Print MACs for all EVPNs.
423 static void zevpn_print_mac_hash_all_evpn(struct hash_bucket
*bucket
, void *ctxt
)
426 json_object
*json
= NULL
, *json_evpn
= NULL
;
427 json_object
*json_mac
= NULL
;
428 struct zebra_evpn
*zevpn
;
430 struct mac_walk_ctx
*wctx
= ctxt
;
431 char vni_str
[VNI_STR_LEN
];
436 zevpn
= (struct zebra_evpn
*)bucket
->data
;
439 /*We are iterating over a new VNI, set the count to 0*/
442 num_macs
= num_valid_macs(zevpn
);
447 num_macs
= num_dup_detected_macs(zevpn
);
450 json_evpn
= json_object_new_object();
451 json_mac
= json_object_new_object();
452 snprintf(vni_str
, VNI_STR_LEN
, "%u", zevpn
->vni
);
455 if (!CHECK_FLAG(wctx
->flags
, SHOW_REMOTE_MAC_FROM_VTEP
)) {
457 vty_out(vty
, "\nVNI %u #MACs (local and remote) %u\n\n",
458 zevpn
->vni
, num_macs
);
460 "Flags: N=sync-neighs, I=local-inactive, P=peer-active, X=peer-proxy\n");
461 vty_out(vty
, "%-17s %-6s %-5s %-30s %-5s %s\n", "MAC",
462 "Type", "Flags", "Intf/Remote ES/VTEP",
465 json_object_int_add(json_evpn
, "numMacs", num_macs
);
470 json_object_int_add(json_evpn
, "numMacs", num_macs
);
471 json_object_object_add(json
, vni_str
, json_evpn
);
476 /* assign per-evpn to wctx->json object to fill macs
477 * under the evpn. Re-assign primary json object to fill
478 * next evpn information.
480 wctx
->json
= json_mac
;
482 hash_iterate(zevpn
->mac_table
, zebra_evpn_print_dad_mac_hash
,
485 hash_iterate(zevpn
->mac_table
, zebra_evpn_print_mac_hash
, wctx
);
489 json_object_object_add(json_evpn
, "macs", json_mac
);
490 json_object_object_add(json
, vni_str
, json_evpn
);
495 * Print MACs in detail for all EVPNs.
497 static void zevpn_print_mac_hash_all_evpn_detail(struct hash_bucket
*bucket
,
501 json_object
*json
= NULL
, *json_evpn
= NULL
;
502 json_object
*json_mac
= NULL
;
503 struct zebra_evpn
*zevpn
;
505 struct mac_walk_ctx
*wctx
= ctxt
;
506 char vni_str
[VNI_STR_LEN
];
511 zevpn
= (struct zebra_evpn
*)bucket
->data
;
514 vty_out(vty
, "{}\n");
519 /*We are iterating over a new EVPN, set the count to 0*/
522 num_macs
= num_valid_macs(zevpn
);
526 if (wctx
->print_dup
&& (num_dup_detected_macs(zevpn
) == 0))
530 json_evpn
= json_object_new_object();
531 json_mac
= json_object_new_object();
532 snprintf(vni_str
, VNI_STR_LEN
, "%u", zevpn
->vni
);
535 if (!CHECK_FLAG(wctx
->flags
, SHOW_REMOTE_MAC_FROM_VTEP
)) {
537 vty_out(vty
, "\nVNI %u #MACs (local and remote) %u\n\n",
538 zevpn
->vni
, num_macs
);
540 json_object_int_add(json_evpn
, "numMacs", num_macs
);
542 /* assign per-evpn to wctx->json object to fill macs
543 * under the evpn. Re-assign primary json object to fill
544 * next evpn information.
546 wctx
->json
= json_mac
;
548 hash_iterate(zevpn
->mac_table
,
549 zebra_evpn_print_dad_mac_hash_detail
, wctx
);
551 hash_iterate(zevpn
->mac_table
, zebra_evpn_print_mac_hash_detail
,
556 json_object_object_add(json_evpn
, "macs", json_mac
);
557 json_object_object_add(json
, vni_str
, json_evpn
);
561 static void zl3vni_print_nh_hash(struct hash_bucket
*bucket
, void *ctx
)
563 struct nh_walk_ctx
*wctx
= NULL
;
564 struct vty
*vty
= NULL
;
565 struct json_object
*json_evpn
= NULL
;
566 struct json_object
*json_nh
= NULL
;
567 struct zebra_neigh
*n
= NULL
;
568 char buf1
[ETHER_ADDR_STRLEN
];
569 char buf2
[INET6_ADDRSTRLEN
];
571 wctx
= (struct nh_walk_ctx
*)ctx
;
573 json_evpn
= wctx
->json
;
575 json_nh
= json_object_new_object();
576 n
= (struct zebra_neigh
*)bucket
->data
;
579 vty_out(vty
, "%-15s %-17s\n",
580 ipaddr2str(&(n
->ip
), buf2
, sizeof(buf2
)),
581 prefix_mac2str(&n
->emac
, buf1
, sizeof(buf1
)));
583 json_object_string_add(json_nh
, "nexthopIp",
584 ipaddr2str(&n
->ip
, buf2
, sizeof(buf2
)));
585 json_object_string_add(
586 json_nh
, "routerMac",
587 prefix_mac2str(&n
->emac
, buf1
, sizeof(buf1
)));
588 json_object_object_add(json_evpn
,
589 ipaddr2str(&(n
->ip
), buf2
, sizeof(buf2
)),
594 static void zl3vni_print_nh_hash_all_vni(struct hash_bucket
*bucket
,
597 struct vty
*vty
= NULL
;
598 json_object
*json
= NULL
;
599 json_object
*json_evpn
= NULL
;
600 struct zebra_l3vni
*zl3vni
= NULL
;
602 struct nh_walk_ctx wctx
;
603 char vni_str
[VNI_STR_LEN
];
605 vty
= (struct vty
*)args
[0];
606 json
= (struct json_object
*)args
[1];
608 zl3vni
= (struct zebra_l3vni
*)bucket
->data
;
610 num_nh
= hashcount(zl3vni
->nh_table
);
615 json_evpn
= json_object_new_object();
616 snprintf(vni_str
, VNI_STR_LEN
, "%u", zl3vni
->vni
);
620 vty_out(vty
, "\nVNI %u #Next-Hops %u\n\n", zl3vni
->vni
, num_nh
);
621 vty_out(vty
, "%-15s %-17s\n", "IP", "RMAC");
623 json_object_int_add(json_evpn
, "numNextHops", num_nh
);
625 memset(&wctx
, 0, sizeof(wctx
));
627 wctx
.json
= json_evpn
;
628 hash_iterate(zl3vni
->nh_table
, zl3vni_print_nh_hash
, &wctx
);
630 json_object_object_add(json
, vni_str
, json_evpn
);
633 static void zl3vni_print_rmac_hash_all_vni(struct hash_bucket
*bucket
,
636 struct vty
*vty
= NULL
;
637 json_object
*json
= NULL
;
638 json_object
*json_evpn
= NULL
;
639 struct zebra_l3vni
*zl3vni
= NULL
;
641 struct rmac_walk_ctx wctx
;
642 char vni_str
[VNI_STR_LEN
];
644 vty
= (struct vty
*)args
[0];
645 json
= (struct json_object
*)args
[1];
647 zl3vni
= (struct zebra_l3vni
*)bucket
->data
;
649 num_rmacs
= hashcount(zl3vni
->rmac_table
);
654 json_evpn
= json_object_new_object();
655 snprintf(vni_str
, VNI_STR_LEN
, "%u", zl3vni
->vni
);
659 vty_out(vty
, "\nVNI %u #RMACs %u\n\n", zl3vni
->vni
, num_rmacs
);
660 vty_out(vty
, "%-17s %-21s\n", "RMAC", "Remote VTEP");
662 json_object_int_add(json_evpn
, "numRmacs", num_rmacs
);
664 /* assign per-vni to wctx->json object to fill macs
665 * under the vni. Re-assign primary json object to fill
666 * next vni information.
668 memset(&wctx
, 0, sizeof(wctx
));
670 wctx
.json
= json_evpn
;
671 hash_iterate(zl3vni
->rmac_table
, zl3vni_print_rmac_hash
, &wctx
);
673 json_object_object_add(json
, vni_str
, json_evpn
);
676 static void zl3vni_print_rmac_hash(struct hash_bucket
*bucket
, void *ctx
)
678 struct zebra_mac
*zrmac
= NULL
;
679 struct rmac_walk_ctx
*wctx
= NULL
;
680 struct vty
*vty
= NULL
;
681 struct json_object
*json
= NULL
;
682 struct json_object
*json_rmac
= NULL
;
683 char buf
[PREFIX_STRLEN
];
685 wctx
= (struct rmac_walk_ctx
*)ctx
;
689 json_rmac
= json_object_new_object();
690 zrmac
= (struct zebra_mac
*)bucket
->data
;
693 vty_out(vty
, "%-17s %-21pI4\n",
694 prefix_mac2str(&zrmac
->macaddr
, buf
, sizeof(buf
)),
695 &zrmac
->fwd_info
.r_vtep_ip
);
697 json_object_string_add(
698 json_rmac
, "routerMac",
699 prefix_mac2str(&zrmac
->macaddr
, buf
, sizeof(buf
)));
700 json_object_string_addf(json_rmac
, "vtepIp", "%pI4",
701 &zrmac
->fwd_info
.r_vtep_ip
);
702 json_object_object_add(
703 json
, prefix_mac2str(&zrmac
->macaddr
, buf
, sizeof(buf
)),
708 /* print a specific L3 VNI entry */
709 static void zl3vni_print(struct zebra_l3vni
*zl3vni
, void **ctx
)
711 char buf
[PREFIX_STRLEN
];
712 struct vty
*vty
= NULL
;
713 json_object
*json
= NULL
;
714 struct zebra_evpn
*zevpn
= NULL
;
715 json_object
*json_evpn_list
= NULL
;
716 struct listnode
*node
= NULL
, *nnode
= NULL
;
722 vty_out(vty
, "VNI: %u\n", zl3vni
->vni
);
723 vty_out(vty
, " Type: %s\n", "L3");
724 vty_out(vty
, " Tenant VRF: %s\n", zl3vni_vrf_name(zl3vni
));
725 vty_out(vty
, " Local Vtep Ip: %pI4\n",
726 &zl3vni
->local_vtep_ip
);
727 vty_out(vty
, " Vxlan-Intf: %s\n",
728 zl3vni_vxlan_if_name(zl3vni
));
729 vty_out(vty
, " SVI-If: %s\n", zl3vni_svi_if_name(zl3vni
));
730 vty_out(vty
, " State: %s\n", zl3vni_state2str(zl3vni
));
731 vty_out(vty
, " VNI Filter: %s\n",
732 CHECK_FLAG(zl3vni
->filter
, PREFIX_ROUTES_ONLY
)
733 ? "prefix-routes-only"
735 vty_out(vty
, " System MAC: %s\n",
736 zl3vni_sysmac2str(zl3vni
, buf
, sizeof(buf
)));
737 vty_out(vty
, " Router MAC: %s\n",
738 zl3vni_rmac2str(zl3vni
, buf
, sizeof(buf
)));
739 vty_out(vty
, " L2 VNIs: ");
740 for (ALL_LIST_ELEMENTS(zl3vni
->l2vnis
, node
, nnode
, zevpn
))
741 vty_out(vty
, "%u ", zevpn
->vni
);
744 json_evpn_list
= json_object_new_array();
745 json_object_int_add(json
, "vni", zl3vni
->vni
);
746 json_object_string_add(json
, "type", "L3");
747 #if CONFDATE > 20240210
748 CPP_NOTICE("Drop `vrf` from JSON outputs")
750 json_object_string_add(json
, "vrf", zl3vni_vrf_name(zl3vni
));
751 json_object_string_add(json
, "tenantVrf",
752 zl3vni_vrf_name(zl3vni
));
753 json_object_string_addf(json
, "localVtepIp", "%pI4",
754 &zl3vni
->local_vtep_ip
);
755 json_object_string_add(json
, "vxlanIntf",
756 zl3vni_vxlan_if_name(zl3vni
));
757 json_object_string_add(json
, "sviIntf",
758 zl3vni_svi_if_name(zl3vni
));
759 json_object_string_add(json
, "state", zl3vni_state2str(zl3vni
));
760 json_object_string_add(
762 zl3vni_sysmac2str(zl3vni
, buf
, sizeof(buf
)));
763 json_object_string_add(
765 zl3vni_rmac2str(zl3vni
, buf
, sizeof(buf
)));
766 json_object_string_add(
768 CHECK_FLAG(zl3vni
->filter
, PREFIX_ROUTES_ONLY
)
769 ? "prefix-routes-only"
771 for (ALL_LIST_ELEMENTS(zl3vni
->l2vnis
, node
, nnode
, zevpn
)) {
772 json_object_array_add(json_evpn_list
,
773 json_object_new_int(zevpn
->vni
));
775 json_object_object_add(json
, "l2Vnis", json_evpn_list
);
779 /* print a L3 VNI hash entry */
780 static void zl3vni_print_hash(struct hash_bucket
*bucket
, void *ctx
[])
782 struct vty
*vty
= NULL
;
783 json_object
*json
= NULL
;
784 json_object
*json_evpn
= NULL
;
785 struct zebra_l3vni
*zl3vni
= NULL
;
787 vty
= (struct vty
*)ctx
[0];
788 json
= (json_object
*)ctx
[1];
790 zl3vni
= (struct zebra_l3vni
*)bucket
->data
;
793 vty_out(vty
, "%-10u %-4s %-21s %-8lu %-8lu %-15s %-37s\n",
794 zl3vni
->vni
, "L3", zl3vni_vxlan_if_name(zl3vni
),
795 hashcount(zl3vni
->rmac_table
),
796 hashcount(zl3vni
->nh_table
), "n/a",
797 zl3vni_vrf_name(zl3vni
));
799 char vni_str
[VNI_STR_LEN
];
801 snprintf(vni_str
, VNI_STR_LEN
, "%u", zl3vni
->vni
);
802 json_evpn
= json_object_new_object();
803 json_object_int_add(json_evpn
, "vni", zl3vni
->vni
);
804 json_object_string_add(json_evpn
, "vxlanIf",
805 zl3vni_vxlan_if_name(zl3vni
));
806 json_object_int_add(json_evpn
, "numMacs",
807 hashcount(zl3vni
->rmac_table
));
808 json_object_int_add(json_evpn
, "numArpNd",
809 hashcount(zl3vni
->nh_table
));
810 json_object_string_add(json_evpn
, "numRemoteVteps", "n/a");
811 json_object_string_add(json_evpn
, "type", "L3");
812 json_object_string_add(json_evpn
, "tenantVrf",
813 zl3vni_vrf_name(zl3vni
));
814 json_object_object_add(json
, vni_str
, json_evpn
);
818 /* print a L3 VNI hash entry in detail*/
819 static void zl3vni_print_hash_detail(struct hash_bucket
*bucket
, void *data
)
821 struct vty
*vty
= NULL
;
822 struct zebra_l3vni
*zl3vni
= NULL
;
823 json_object
*json_array
= NULL
;
824 bool use_json
= false;
825 struct zebra_evpn_show
*zes
= data
;
828 json_array
= zes
->json
;
829 use_json
= zes
->use_json
;
831 zl3vni
= (struct zebra_l3vni
*)bucket
->data
;
833 zebra_vxlan_print_vni(vty
, zes
->zvrf
, zl3vni
->vni
,
834 use_json
, json_array
);
840 static int zvni_map_to_svi_ns(struct ns
*ns
,
844 struct zebra_ns
*zns
= ns
->info
;
845 struct route_node
*rn
;
846 struct zebra_from_svi_param
*in_param
=
847 (struct zebra_from_svi_param
*)_in_param
;
848 struct zebra_l2info_vlan
*vl
;
849 struct interface
*tmp_if
= NULL
;
850 struct interface
**p_ifp
= (struct interface
**)_p_ifp
;
851 struct zebra_if
*zif
;
853 assert(in_param
&& p_ifp
);
855 /* TODO: Optimize with a hash. */
856 for (rn
= route_top(zns
->if_table
); rn
; rn
= route_next(rn
)) {
857 tmp_if
= (struct interface
*)rn
->info
;
858 /* Check oper status of the SVI. */
859 if (!tmp_if
|| !if_is_operative(tmp_if
))
862 if (!zif
|| zif
->zif_type
!= ZEBRA_IF_VLAN
863 || zif
->link
!= in_param
->br_if
)
865 vl
= (struct zebra_l2info_vlan
*)&zif
->l2info
.vl
;
867 if (vl
->vid
== in_param
->vid
) {
872 return NS_WALK_CONTINUE
;
875 /* Map to SVI on bridge corresponding to specified VLAN. This can be one
877 * (a) In the case of a VLAN-aware bridge, the SVI is a L3 VLAN interface
878 * linked to the bridge
879 * (b) In the case of a VLAN-unaware bridge, the SVI is the bridge interface
882 struct interface
*zvni_map_to_svi(vlanid_t vid
, struct interface
*br_if
)
884 struct interface
*tmp_if
= NULL
;
885 struct zebra_if
*zif
;
886 struct zebra_from_svi_param in_param
;
887 struct interface
**p_ifp
;
888 /* Defensive check, caller expected to invoke only with valid bridge. */
892 /* Determine if bridge is VLAN-aware or not */
895 in_param
.bridge_vlan_aware
= IS_ZEBRA_IF_BRIDGE_VLAN_AWARE(zif
);
896 /* Check oper status of the SVI. */
897 if (!in_param
.bridge_vlan_aware
)
898 return if_is_operative(br_if
) ? br_if
: NULL
;
901 in_param
.br_if
= br_if
;
904 /* Identify corresponding VLAN interface. */
905 ns_walk_func(zvni_map_to_svi_ns
, (void *)&in_param
,
910 int zebra_evpn_vxlan_del(struct zebra_evpn
*zevpn
)
912 zevpn_vxlan_if_set(zevpn
, zevpn
->vxlan_if
, false /* set */);
914 /* Remove references to the BUM mcast grp */
915 zebra_vxlan_sg_deref(zevpn
->local_vtep_ip
, zevpn
->mcast_grp
);
917 return zebra_evpn_del(zevpn
);
920 static int zevpn_build_vni_hash_table(struct zebra_if
*zif
,
921 struct zebra_vxlan_vni
*vnip
, void *arg
)
924 struct zebra_evpn
*zevpn
;
925 struct zebra_l3vni
*zl3vni
;
926 struct interface
*ifp
;
927 struct zebra_l2info_vxlan
*vxl
;
930 vxl
= &zif
->l2info
.vxl
;
933 if (IS_ZEBRA_DEBUG_VXLAN
)
934 zlog_debug("Build vni table for vni %u for Intf %s", vni
,
937 /* L3-VNI and L2-VNI are handled seperately */
938 zl3vni
= zl3vni_lookup(vni
);
941 if (IS_ZEBRA_DEBUG_VXLAN
)
943 "create L3-VNI hash for Intf %s(%u) L3-VNI %u",
944 ifp
->name
, ifp
->ifindex
, vni
);
946 /* associate with vxlan_if */
947 zl3vni
->local_vtep_ip
= vxl
->vtep_ip
;
948 zl3vni
->vxlan_if
= ifp
;
951 * we need to associate with SVI.
952 * we can associate with svi-if only after association
953 * with vxlan-intf is complete
955 zl3vni
->svi_if
= zl3vni_map_to_svi_if(zl3vni
);
957 /* Associate l3vni to mac-vlan and extract VRR MAC */
958 zl3vni
->mac_vlan_if
= zl3vni_map_to_mac_vlan_if(zl3vni
);
960 if (IS_ZEBRA_DEBUG_VXLAN
)
962 "create l3vni %u svi_if %s mac_vlan_if %s", vni
,
963 zl3vni
->svi_if
? zl3vni
->svi_if
->name
: "NIL",
964 zl3vni
->mac_vlan_if
? zl3vni
->mac_vlan_if
->name
967 if (is_l3vni_oper_up(zl3vni
))
968 zebra_vxlan_process_l3vni_oper_up(zl3vni
);
971 struct interface
*vlan_if
= NULL
;
973 if (IS_ZEBRA_DEBUG_VXLAN
)
975 "Create L2-VNI hash for intf %s(%u) L2-VNI %u local IP %pI4",
976 ifp
->name
, ifp
->ifindex
, vni
, &vxl
->vtep_ip
);
978 /* EVPN hash entry is expected to exist, if the BGP process is
980 zevpn
= zebra_evpn_lookup(vni
);
983 "EVPN hash already present for IF %s(%u) L2-VNI %u",
984 ifp
->name
, ifp
->ifindex
, vni
);
987 * Inform BGP if intf is up and mapped to
990 if (if_is_operative(ifp
) && zif
->brslave_info
.br_if
)
991 zebra_evpn_send_add_to_client(zevpn
);
993 /* Send Local MAC-entries to client */
994 zebra_evpn_send_mac_list_to_client(zevpn
);
996 /* Send Loval Neighbor entries to client */
997 zebra_evpn_send_neigh_to_client(zevpn
);
999 zevpn
= zebra_evpn_add(vni
);
1002 "Failed to add EVPN hash, IF %s(%u) L2-VNI %u",
1003 ifp
->name
, ifp
->ifindex
, vni
);
1007 if (zevpn
->local_vtep_ip
.s_addr
!= vxl
->vtep_ip
.s_addr
1008 || zevpn
->mcast_grp
.s_addr
1009 != vnip
->mcast_grp
.s_addr
) {
1010 zebra_vxlan_sg_deref(zevpn
->local_vtep_ip
,
1012 zebra_vxlan_sg_ref(vxl
->vtep_ip
,
1014 zevpn
->local_vtep_ip
= vxl
->vtep_ip
;
1015 zevpn
->mcast_grp
= vnip
->mcast_grp
;
1016 /* on local vtep-ip check if ES
1017 * orig-ip needs to be updated
1019 zebra_evpn_es_set_base_evpn(zevpn
);
1021 zevpn_vxlan_if_set(zevpn
, ifp
, true /* set */);
1022 vlan_if
= zvni_map_to_svi(vnip
->access_vlan
,
1023 zif
->brslave_info
.br_if
);
1025 zevpn
->svi_if
= vlan_if
;
1026 zevpn
->vrf_id
= vlan_if
->vrf
->vrf_id
;
1027 zl3vni
= zl3vni_from_vrf(vlan_if
->vrf
->vrf_id
);
1029 listnode_add_sort(zl3vni
->l2vnis
,
1034 * Inform BGP if intf is up and mapped to
1037 if (if_is_operative(ifp
) && zif
->brslave_info
.br_if
)
1038 zebra_evpn_send_add_to_client(zevpn
);
1045 static int zevpn_build_hash_table_zns(struct ns
*ns
,
1046 void *param_in
__attribute__((unused
)),
1047 void **param_out
__attribute__((unused
)))
1049 struct zebra_ns
*zns
= ns
->info
;
1050 struct route_node
*rn
;
1051 struct interface
*ifp
;
1052 struct zebra_vrf
*zvrf
;
1054 zvrf
= zebra_vrf_get_evpn();
1056 /* Walk VxLAN interfaces and create EVPN hash. */
1057 for (rn
= route_top(zns
->if_table
); rn
; rn
= route_next(rn
)) {
1058 struct zebra_if
*zif
;
1059 struct zebra_l2info_vxlan
*vxl
;
1061 ifp
= (struct interface
*)rn
->info
;
1065 if (!zif
|| zif
->zif_type
!= ZEBRA_IF_VXLAN
)
1068 vxl
= &zif
->l2info
.vxl
;
1069 /* link of VXLAN interface should be in zebra_evpn_vrf */
1070 if (zvrf
->zns
->ns_id
!= vxl
->link_nsid
) {
1071 if (IS_ZEBRA_DEBUG_VXLAN
)
1073 "Intf %s(%u) link not in same "
1074 "namespace than BGP EVPN core instance ",
1075 ifp
->name
, ifp
->ifindex
);
1079 if (IS_ZEBRA_DEBUG_VXLAN
)
1080 zlog_debug("Building vni table for %s-if %s",
1081 IS_ZEBRA_VXLAN_IF_VNI(zif
) ? "vni" : "svd",
1084 zebra_vxlan_if_vni_iterate(zif
, zevpn_build_vni_hash_table
,
1087 return NS_WALK_CONTINUE
;
1091 * Build the VNI hash table by going over the VxLAN interfaces. This
1092 * is called when EVPN (advertise-all-vni) is enabled.
1095 static void zevpn_build_hash_table(void)
1097 ns_walk_func(zevpn_build_hash_table_zns
, NULL
, NULL
);
1101 * Cleanup EVPN/VTEP and update kernel
1103 static void zebra_evpn_vxlan_cleanup_all(struct hash_bucket
*bucket
, void *arg
)
1105 struct zebra_evpn
*zevpn
= NULL
;
1106 struct zebra_l3vni
*zl3vni
= NULL
;
1108 zevpn
= (struct zebra_evpn
*)bucket
->data
;
1110 /* remove l2vni from l2vni's tenant-vrf l3-vni list */
1111 zl3vni
= zl3vni_from_vrf(zevpn
->vrf_id
);
1113 listnode_delete(zl3vni
->l2vnis
, zevpn
);
1115 zebra_evpn_cleanup_all(bucket
, arg
);
1119 static void zl3vni_cleanup_all(struct hash_bucket
*bucket
, void *args
)
1121 struct zebra_l3vni
*zl3vni
= NULL
;
1123 zl3vni
= (struct zebra_l3vni
*)bucket
->data
;
1125 zebra_vxlan_process_l3vni_oper_down(zl3vni
);
1128 static void rb_find_or_add_host(struct host_rb_tree_entry
*hrbe
,
1129 const struct prefix
*host
)
1131 struct host_rb_entry lookup
;
1132 struct host_rb_entry
*hle
;
1134 memset(&lookup
, 0, sizeof(lookup
));
1135 memcpy(&lookup
.p
, host
, sizeof(*host
));
1137 hle
= RB_FIND(host_rb_tree_entry
, hrbe
, &lookup
);
1141 hle
= XCALLOC(MTYPE_HOST_PREFIX
, sizeof(struct host_rb_entry
));
1142 memcpy(hle
, &lookup
, sizeof(lookup
));
1144 RB_INSERT(host_rb_tree_entry
, hrbe
, hle
);
1147 static void rb_delete_host(struct host_rb_tree_entry
*hrbe
, struct prefix
*host
)
1149 struct host_rb_entry lookup
;
1150 struct host_rb_entry
*hle
;
1152 memset(&lookup
, 0, sizeof(lookup
));
1153 memcpy(&lookup
.p
, host
, sizeof(*host
));
1155 hle
= RB_FIND(host_rb_tree_entry
, hrbe
, &lookup
);
1157 RB_REMOVE(host_rb_tree_entry
, hrbe
, hle
);
1158 XFREE(MTYPE_HOST_PREFIX
, hle
);
1165 * Look up MAC hash entry.
1167 static struct zebra_mac
*zl3vni_rmac_lookup(struct zebra_l3vni
*zl3vni
,
1168 const struct ethaddr
*rmac
)
1170 struct zebra_mac tmp
;
1171 struct zebra_mac
*pmac
;
1173 memset(&tmp
, 0, sizeof(tmp
));
1174 memcpy(&tmp
.macaddr
, rmac
, ETH_ALEN
);
1175 pmac
= hash_lookup(zl3vni
->rmac_table
, &tmp
);
1181 * Callback to allocate RMAC hash entry.
1183 static void *zl3vni_rmac_alloc(void *p
)
1185 const struct zebra_mac
*tmp_rmac
= p
;
1186 struct zebra_mac
*zrmac
;
1188 zrmac
= XCALLOC(MTYPE_L3VNI_MAC
, sizeof(struct zebra_mac
));
1191 return ((void *)zrmac
);
1195 * Add RMAC entry to l3-vni
1197 static struct zebra_mac
*zl3vni_rmac_add(struct zebra_l3vni
*zl3vni
,
1198 const struct ethaddr
*rmac
)
1200 struct zebra_mac tmp_rmac
;
1201 struct zebra_mac
*zrmac
= NULL
;
1203 memset(&tmp_rmac
, 0, sizeof(tmp_rmac
));
1204 memcpy(&tmp_rmac
.macaddr
, rmac
, ETH_ALEN
);
1205 zrmac
= hash_get(zl3vni
->rmac_table
, &tmp_rmac
, zl3vni_rmac_alloc
);
1206 zrmac
->nh_list
= list_new();
1207 zrmac
->nh_list
->cmp
= (int (*)(void *, void *))l3vni_rmac_nh_list_cmp
;
1208 zrmac
->nh_list
->del
= (void (*)(void *))l3vni_rmac_nh_free
;
1210 SET_FLAG(zrmac
->flags
, ZEBRA_MAC_REMOTE
);
1211 SET_FLAG(zrmac
->flags
, ZEBRA_MAC_REMOTE_RMAC
);
1219 static int zl3vni_rmac_del(struct zebra_l3vni
*zl3vni
, struct zebra_mac
*zrmac
)
1221 struct zebra_mac
*tmp_rmac
;
1223 /* free the list of nh list*/
1224 list_delete(&zrmac
->nh_list
);
1226 tmp_rmac
= hash_release(zl3vni
->rmac_table
, zrmac
);
1227 XFREE(MTYPE_L3VNI_MAC
, tmp_rmac
);
1233 * Install remote RMAC into the forwarding plane.
1235 static int zl3vni_rmac_install(struct zebra_l3vni
*zl3vni
,
1236 struct zebra_mac
*zrmac
)
1238 const struct zebra_if
*zif
= NULL
, *br_zif
= NULL
;
1239 const struct zebra_vxlan_vni
*vni
;
1240 const struct interface
*br_ifp
;
1241 enum zebra_dplane_result res
;
1244 if (!(CHECK_FLAG(zrmac
->flags
, ZEBRA_MAC_REMOTE
))
1245 || !(CHECK_FLAG(zrmac
->flags
, ZEBRA_MAC_REMOTE_RMAC
)))
1248 zif
= zl3vni
->vxlan_if
->info
;
1252 br_ifp
= zif
->brslave_info
.br_if
;
1256 vni
= zebra_vxlan_if_vni_find(zif
, zl3vni
->vni
);
1258 br_zif
= (const struct zebra_if
*)br_ifp
->info
;
1260 if (IS_ZEBRA_IF_BRIDGE_VLAN_AWARE(br_zif
))
1261 vid
= vni
->access_vlan
;
1265 res
= dplane_rem_mac_add(zl3vni
->vxlan_if
, br_ifp
, vid
, &zrmac
->macaddr
,
1266 vni
->vni
, zrmac
->fwd_info
.r_vtep_ip
, 0, 0,
1267 false /*was_static*/);
1268 if (res
!= ZEBRA_DPLANE_REQUEST_FAILURE
)
1275 * Uninstall remote RMAC from the forwarding plane.
1277 static int zl3vni_rmac_uninstall(struct zebra_l3vni
*zl3vni
,
1278 struct zebra_mac
*zrmac
)
1280 const struct zebra_if
*zif
= NULL
, *br_zif
;
1281 const struct zebra_vxlan_vni
*vni
;
1282 const struct interface
*br_ifp
;
1284 enum zebra_dplane_result res
;
1286 if (!(CHECK_FLAG(zrmac
->flags
, ZEBRA_MAC_REMOTE
))
1287 || !(CHECK_FLAG(zrmac
->flags
, ZEBRA_MAC_REMOTE_RMAC
)))
1290 if (!zl3vni
->vxlan_if
) {
1291 if (IS_ZEBRA_DEBUG_VXLAN
)
1293 "RMAC %pEA on L3-VNI %u hash %p couldn't be uninstalled - no vxlan_if",
1294 &zrmac
->macaddr
, zl3vni
->vni
, zl3vni
);
1298 zif
= zl3vni
->vxlan_if
->info
;
1302 br_ifp
= zif
->brslave_info
.br_if
;
1306 vni
= zebra_vxlan_if_vni_find(zif
, zl3vni
->vni
);
1308 br_zif
= (const struct zebra_if
*)br_ifp
->info
;
1309 if (IS_ZEBRA_IF_BRIDGE_VLAN_AWARE(br_zif
))
1310 vid
= vni
->access_vlan
;
1314 res
= dplane_rem_mac_del(zl3vni
->vxlan_if
, br_ifp
, vid
, &zrmac
->macaddr
,
1315 vni
->vni
, zrmac
->fwd_info
.r_vtep_ip
);
1316 if (res
!= ZEBRA_DPLANE_REQUEST_FAILURE
)
1322 /* handle rmac add */
1323 static int zl3vni_remote_rmac_add(struct zebra_l3vni
*zl3vni
,
1324 const struct ethaddr
*rmac
,
1325 const struct ipaddr
*vtep_ip
)
1327 struct zebra_mac
*zrmac
= NULL
;
1328 struct ipaddr
*vtep
= NULL
;
1330 zrmac
= zl3vni_rmac_lookup(zl3vni
, rmac
);
1333 /* Create the RMAC entry, or update its vtep, if necessary. */
1334 zrmac
= zl3vni_rmac_add(zl3vni
, rmac
);
1337 "Failed to add RMAC %pEA L3VNI %u Remote VTEP %pIA",
1338 rmac
, zl3vni
->vni
, vtep_ip
);
1341 memset(&zrmac
->fwd_info
, 0, sizeof(zrmac
->fwd_info
));
1342 zrmac
->fwd_info
.r_vtep_ip
= vtep_ip
->ipaddr_v4
;
1344 vtep
= XCALLOC(MTYPE_EVPN_VTEP
, sizeof(struct ipaddr
));
1345 memcpy(vtep
, vtep_ip
, sizeof(struct ipaddr
));
1346 if (!listnode_add_sort_nodup(zrmac
->nh_list
, (void *)vtep
))
1347 XFREE(MTYPE_EVPN_VTEP
, vtep
);
1349 /* Send RMAC for FPM processing */
1350 hook_call(zebra_rmac_update
, zrmac
, zl3vni
, false,
1353 /* install rmac in kernel */
1354 zl3vni_rmac_install(zl3vni
, zrmac
);
1355 } else if (!IPV4_ADDR_SAME(&zrmac
->fwd_info
.r_vtep_ip
,
1356 &vtep_ip
->ipaddr_v4
)) {
1357 if (IS_ZEBRA_DEBUG_VXLAN
)
1359 "L3VNI %u Remote VTEP change(%pI4 -> %pIA) for RMAC %pEA",
1360 zl3vni
->vni
, &zrmac
->fwd_info
.r_vtep_ip
,
1363 zrmac
->fwd_info
.r_vtep_ip
= vtep_ip
->ipaddr_v4
;
1365 vtep
= XCALLOC(MTYPE_EVPN_VTEP
, sizeof(struct ipaddr
));
1366 memcpy(vtep
, vtep_ip
, sizeof(struct ipaddr
));
1367 if (!listnode_add_sort_nodup(zrmac
->nh_list
, (void *)vtep
))
1368 XFREE(MTYPE_EVPN_VTEP
, vtep
);
1370 /* install rmac in kernel */
1371 zl3vni_rmac_install(zl3vni
, zrmac
);
1378 /* handle rmac delete */
1379 static void zl3vni_remote_rmac_del(struct zebra_l3vni
*zl3vni
,
1380 struct zebra_mac
*zrmac
,
1381 struct ipaddr
*vtep_ip
)
1383 struct ipaddr ipv4_vtep
;
1385 if (!zl3vni_nh_lookup(zl3vni
, vtep_ip
)) {
1386 memset(&ipv4_vtep
, 0, sizeof(ipv4_vtep
));
1387 ipv4_vtep
.ipa_type
= IPADDR_V4
;
1388 if (vtep_ip
->ipa_type
== IPADDR_V6
)
1389 ipv4_mapped_ipv6_to_ipv4(&vtep_ip
->ipaddr_v6
,
1390 &ipv4_vtep
.ipaddr_v4
);
1392 memcpy(&(ipv4_vtep
.ipaddr_v4
), &vtep_ip
->ipaddr_v4
,
1393 sizeof(struct in_addr
));
1395 /* remove nh from rmac's list */
1396 l3vni_rmac_nh_list_nh_delete(zl3vni
, zrmac
, &ipv4_vtep
);
1397 /* delete nh is same as current selected, fall back to
1398 * one present in the list
1400 if (IPV4_ADDR_SAME(&zrmac
->fwd_info
.r_vtep_ip
,
1401 &ipv4_vtep
.ipaddr_v4
) &&
1402 listcount(zrmac
->nh_list
)) {
1403 struct ipaddr
*vtep
;
1405 vtep
= listgetdata(listhead(zrmac
->nh_list
));
1406 zrmac
->fwd_info
.r_vtep_ip
= vtep
->ipaddr_v4
;
1407 if (IS_ZEBRA_DEBUG_VXLAN
)
1409 "L3VNI %u Remote VTEP nh change(%pIA -> %pI4) for RMAC %pEA",
1410 zl3vni
->vni
, &ipv4_vtep
,
1411 &zrmac
->fwd_info
.r_vtep_ip
,
1414 /* install rmac in kernel */
1415 zl3vni_rmac_install(zl3vni
, zrmac
);
1418 if (!listcount(zrmac
->nh_list
)) {
1419 /* uninstall from kernel */
1420 zl3vni_rmac_uninstall(zl3vni
, zrmac
);
1422 /* Send RMAC for FPM processing */
1423 hook_call(zebra_rmac_update
, zrmac
, zl3vni
, true,
1426 if (IS_ZEBRA_DEBUG_VXLAN
)
1428 "L3VNI %u RMAC %pEA vtep_ip %pIA delete",
1429 zl3vni
->vni
, &zrmac
->macaddr
, vtep_ip
);
1431 /* del the rmac entry */
1432 zl3vni_rmac_del(zl3vni
, zrmac
);
1438 * Look up nh hash entry on a l3-vni.
1440 static struct zebra_neigh
*zl3vni_nh_lookup(struct zebra_l3vni
*zl3vni
,
1441 const struct ipaddr
*ip
)
1443 struct zebra_neigh tmp
;
1444 struct zebra_neigh
*n
;
1446 memset(&tmp
, 0, sizeof(tmp
));
1447 memcpy(&tmp
.ip
, ip
, sizeof(struct ipaddr
));
1448 n
= hash_lookup(zl3vni
->nh_table
, &tmp
);
1455 * Callback to allocate NH hash entry on L3-VNI.
1457 static void *zl3vni_nh_alloc(void *p
)
1459 const struct zebra_neigh
*tmp_n
= p
;
1460 struct zebra_neigh
*n
;
1462 n
= XCALLOC(MTYPE_L3NEIGH
, sizeof(struct zebra_neigh
));
1469 * Add neighbor entry.
1471 static struct zebra_neigh
*zl3vni_nh_add(struct zebra_l3vni
*zl3vni
,
1472 const struct ipaddr
*ip
,
1473 const struct ethaddr
*mac
)
1475 struct zebra_neigh tmp_n
;
1476 struct zebra_neigh
*n
= NULL
;
1478 memset(&tmp_n
, 0, sizeof(tmp_n
));
1479 memcpy(&tmp_n
.ip
, ip
, sizeof(struct ipaddr
));
1480 n
= hash_get(zl3vni
->nh_table
, &tmp_n
, zl3vni_nh_alloc
);
1482 RB_INIT(host_rb_tree_entry
, &n
->host_rb
);
1484 memcpy(&n
->emac
, mac
, ETH_ALEN
);
1485 SET_FLAG(n
->flags
, ZEBRA_NEIGH_REMOTE
);
1486 SET_FLAG(n
->flags
, ZEBRA_NEIGH_REMOTE_NH
);
1492 * Delete neighbor entry.
1494 static int zl3vni_nh_del(struct zebra_l3vni
*zl3vni
, struct zebra_neigh
*n
)
1496 struct zebra_neigh
*tmp_n
;
1497 struct host_rb_entry
*hle
;
1499 while (!RB_EMPTY(host_rb_tree_entry
, &n
->host_rb
)) {
1500 hle
= RB_ROOT(host_rb_tree_entry
, &n
->host_rb
);
1502 RB_REMOVE(host_rb_tree_entry
, &n
->host_rb
, hle
);
1503 XFREE(MTYPE_HOST_PREFIX
, hle
);
1506 tmp_n
= hash_release(zl3vni
->nh_table
, n
);
1507 XFREE(MTYPE_L3NEIGH
, tmp_n
);
1513 * Install remote nh as neigh into the kernel.
1515 static int zl3vni_nh_install(struct zebra_l3vni
*zl3vni
, struct zebra_neigh
*n
)
1520 if (!is_l3vni_oper_up(zl3vni
))
1523 if (!(n
->flags
& ZEBRA_NEIGH_REMOTE
)
1524 || !(n
->flags
& ZEBRA_NEIGH_REMOTE_NH
))
1527 flags
= DPLANE_NTF_EXT_LEARNED
;
1528 if (n
->flags
& ZEBRA_NEIGH_ROUTER_FLAG
)
1529 flags
|= DPLANE_NTF_ROUTER
;
1531 dplane_rem_neigh_add(zl3vni
->svi_if
, &n
->ip
, &n
->emac
, flags
,
1532 false /*was_static*/);
1538 * Uninstall remote nh from the kernel.
1540 static int zl3vni_nh_uninstall(struct zebra_l3vni
*zl3vni
,
1541 struct zebra_neigh
*n
)
1543 if (!(n
->flags
& ZEBRA_NEIGH_REMOTE
)
1544 || !(n
->flags
& ZEBRA_NEIGH_REMOTE_NH
))
1547 if (!zl3vni
->svi_if
|| !if_is_operative(zl3vni
->svi_if
))
1550 dplane_rem_neigh_delete(zl3vni
->svi_if
, &n
->ip
);
1555 /* add remote vtep as a neigh entry */
1556 static int zl3vni_remote_nh_add(struct zebra_l3vni
*zl3vni
,
1557 const struct ipaddr
*vtep_ip
,
1558 const struct ethaddr
*rmac
,
1559 const struct prefix
*host_prefix
)
1561 struct zebra_neigh
*nh
= NULL
;
1563 /* Create the next hop entry, or update its mac, if necessary. */
1564 nh
= zl3vni_nh_lookup(zl3vni
, vtep_ip
);
1566 nh
= zl3vni_nh_add(zl3vni
, vtep_ip
, rmac
);
1569 "Failed to add NH %pIA as Neigh (RMAC %pEA L3-VNI %u prefix %pFX)",
1570 vtep_ip
, rmac
, zl3vni
->vni
, host_prefix
);
1574 /* install the nh neigh in kernel */
1575 zl3vni_nh_install(zl3vni
, nh
);
1576 } else if (memcmp(&nh
->emac
, rmac
, ETH_ALEN
) != 0) {
1577 if (IS_ZEBRA_DEBUG_VXLAN
)
1579 "L3VNI %u RMAC change(%pEA --> %pEA) for nexthop %pIA, prefix %pFX",
1580 zl3vni
->vni
, &nh
->emac
, rmac
, vtep_ip
,
1583 memcpy(&nh
->emac
, rmac
, ETH_ALEN
);
1584 /* install (update) the nh neigh in kernel */
1585 zl3vni_nh_install(zl3vni
, nh
);
1588 rb_find_or_add_host(&nh
->host_rb
, host_prefix
);
1593 /* handle nh neigh delete */
1594 static void zl3vni_remote_nh_del(struct zebra_l3vni
*zl3vni
,
1595 struct zebra_neigh
*nh
,
1596 struct prefix
*host_prefix
)
1598 rb_delete_host(&nh
->host_rb
, host_prefix
);
1600 if (RB_EMPTY(host_rb_tree_entry
, &nh
->host_rb
)) {
1601 /* uninstall from kernel */
1602 zl3vni_nh_uninstall(zl3vni
, nh
);
1604 /* delete the nh entry */
1605 zl3vni_nh_del(zl3vni
, nh
);
1609 /* handle neigh update from kernel - the only thing of interest is to
1610 * readd stale entries.
1612 static int zl3vni_local_nh_add_update(struct zebra_l3vni
*zl3vni
,
1613 struct ipaddr
*ip
, uint16_t state
)
1616 struct zebra_neigh
*n
= NULL
;
1618 n
= zl3vni_nh_lookup(zl3vni
, ip
);
1622 /* all next hop neigh are remote and installed by frr.
1623 * If the kernel has aged this entry, re-install.
1625 if (state
& NUD_STALE
)
1626 zl3vni_nh_install(zl3vni
, n
);
1631 /* handle neigh delete from kernel */
1632 static int zl3vni_local_nh_del(struct zebra_l3vni
*zl3vni
, struct ipaddr
*ip
)
1634 struct zebra_neigh
*n
= NULL
;
1636 n
= zl3vni_nh_lookup(zl3vni
, ip
);
1640 /* all next hop neigh are remote and installed by frr.
1641 * If we get an age out notification for these neigh entries, we have to
1644 zl3vni_nh_install(zl3vni
, n
);
1650 * Hash function for L3 VNI.
1652 static unsigned int l3vni_hash_keymake(const void *p
)
1654 const struct zebra_l3vni
*zl3vni
= p
;
1656 return jhash_1word(zl3vni
->vni
, 0);
1660 * Compare 2 L3 VNI hash entries.
1662 static bool l3vni_hash_cmp(const void *p1
, const void *p2
)
1664 const struct zebra_l3vni
*zl3vni1
= p1
;
1665 const struct zebra_l3vni
*zl3vni2
= p2
;
1667 return (zl3vni1
->vni
== zl3vni2
->vni
);
1671 * Callback to allocate L3 VNI hash entry.
1673 static void *zl3vni_alloc(void *p
)
1675 struct zebra_l3vni
*zl3vni
= NULL
;
1676 const struct zebra_l3vni
*tmp_l3vni
= p
;
1678 zl3vni
= XCALLOC(MTYPE_ZL3VNI
, sizeof(struct zebra_l3vni
));
1679 zl3vni
->vni
= tmp_l3vni
->vni
;
1680 return ((void *)zl3vni
);
1684 * Look up L3 VNI hash entry.
1686 struct zebra_l3vni
*zl3vni_lookup(vni_t vni
)
1688 struct zebra_l3vni tmp_l3vni
;
1689 struct zebra_l3vni
*zl3vni
= NULL
;
1691 memset(&tmp_l3vni
, 0, sizeof(tmp_l3vni
));
1692 tmp_l3vni
.vni
= vni
;
1693 zl3vni
= hash_lookup(zrouter
.l3vni_table
, &tmp_l3vni
);
1699 * Add L3 VNI hash entry.
1701 static struct zebra_l3vni
*zl3vni_add(vni_t vni
, vrf_id_t vrf_id
)
1703 struct zebra_l3vni tmp_zl3vni
;
1704 struct zebra_l3vni
*zl3vni
= NULL
;
1706 memset(&tmp_zl3vni
, 0, sizeof(tmp_zl3vni
));
1707 tmp_zl3vni
.vni
= vni
;
1709 zl3vni
= hash_get(zrouter
.l3vni_table
, &tmp_zl3vni
, zl3vni_alloc
);
1711 zl3vni
->vrf_id
= vrf_id
;
1712 zl3vni
->svi_if
= NULL
;
1713 zl3vni
->vxlan_if
= NULL
;
1714 zl3vni
->l2vnis
= list_new();
1715 zl3vni
->l2vnis
->cmp
= zebra_evpn_list_cmp
;
1717 /* Create hash table for remote RMAC */
1718 zl3vni
->rmac_table
= zebra_mac_db_create("Zebra L3-VNI RMAC-Table");
1720 /* Create hash table for neighbors */
1721 zl3vni
->nh_table
= zebra_neigh_db_create("Zebra L3-VNI next-hop table");
1727 * Delete L3 VNI hash entry.
1729 static int zl3vni_del(struct zebra_l3vni
*zl3vni
)
1731 struct zebra_l3vni
*tmp_zl3vni
;
1733 /* free the list of l2vnis */
1734 list_delete(&zl3vni
->l2vnis
);
1735 zl3vni
->l2vnis
= NULL
;
1737 /* Free the rmac table */
1738 hash_free(zl3vni
->rmac_table
);
1739 zl3vni
->rmac_table
= NULL
;
1741 /* Free the nh table */
1742 hash_free(zl3vni
->nh_table
);
1743 zl3vni
->nh_table
= NULL
;
1745 /* Free the VNI hash entry and allocated memory. */
1746 tmp_zl3vni
= hash_release(zrouter
.l3vni_table
, zl3vni
);
1747 XFREE(MTYPE_ZL3VNI
, tmp_zl3vni
);
1752 static int zl3vni_map_to_vxlan_if_ns(struct ns
*ns
,
1756 struct zebra_ns
*zns
= ns
->info
;
1757 struct zebra_l3vni
*zl3vni
= (struct zebra_l3vni
*)_zl3vni
;
1758 struct route_node
*rn
= NULL
;
1759 struct interface
*ifp
= NULL
;
1760 struct zebra_vrf
*zvrf
;
1762 zvrf
= zebra_vrf_get_evpn();
1766 /* loop through all vxlan-interface */
1767 for (rn
= route_top(zns
->if_table
); rn
; rn
= route_next(rn
)) {
1769 struct zebra_if
*zif
= NULL
;
1770 struct zebra_l2info_vxlan
*vxl
;
1771 struct zebra_vxlan_vni
*vni
= NULL
;
1773 ifp
= (struct interface
*)rn
->info
;
1778 if (!zif
|| zif
->zif_type
!= ZEBRA_IF_VXLAN
)
1781 vxl
= &zif
->l2info
.vxl
;
1782 vni
= zebra_vxlan_if_vni_find(zif
, zl3vni
->vni
);
1783 if (vni
->vni
!= zl3vni
->vni
)
1786 /* link of VXLAN interface should be in zebra_evpn_vrf */
1787 if (zvrf
->zns
->ns_id
!= vxl
->link_nsid
) {
1788 if (IS_ZEBRA_DEBUG_VXLAN
)
1790 "Intf %s(%u) VNI %u, link not in same "
1791 "namespace than BGP EVPN core instance ",
1792 ifp
->name
, ifp
->ifindex
, vni
->vni
);
1797 zl3vni
->local_vtep_ip
= zif
->l2info
.vxl
.vtep_ip
;
1798 *_pifp
= (void *)ifp
;
1799 return NS_WALK_STOP
;
1802 return NS_WALK_CONTINUE
;
1805 struct interface
*zl3vni_map_to_vxlan_if(struct zebra_l3vni
*zl3vni
)
1807 struct interface
**p_ifp
;
1808 struct interface
*ifp
= NULL
;
1812 ns_walk_func(zl3vni_map_to_vxlan_if_ns
,
1813 (void *)zl3vni
, (void **)p_ifp
);
1817 struct interface
*zl3vni_map_to_svi_if(struct zebra_l3vni
*zl3vni
)
1819 struct zebra_if
*zif
= NULL
; /* zebra_if for vxlan_if */
1820 struct zebra_vxlan_vni
*vni
= NULL
; /* vni info in vxlan_if */
1825 if (!zl3vni
->vxlan_if
)
1828 zif
= zl3vni
->vxlan_if
->info
;
1832 vni
= zebra_vxlan_if_vni_find(zif
, zl3vni
->vni
);
1836 return zvni_map_to_svi(vni
->access_vlan
, zif
->brslave_info
.br_if
);
1839 struct interface
*zl3vni_map_to_mac_vlan_if(struct zebra_l3vni
*zl3vni
)
1841 struct zebra_if
*zif
= NULL
; /* zebra_if for vxlan_if */
1846 if (!zl3vni
->vxlan_if
)
1849 zif
= zl3vni
->vxlan_if
->info
;
1853 return zebra_evpn_map_to_macvlan(zif
->brslave_info
.br_if
,
1858 struct zebra_l3vni
*zl3vni_from_vrf(vrf_id_t vrf_id
)
1860 struct zebra_vrf
*zvrf
= NULL
;
1862 zvrf
= zebra_vrf_lookup_by_id(vrf_id
);
1866 return zl3vni_lookup(zvrf
->l3vni
);
1869 static int zl3vni_from_svi_ns(struct ns
*ns
, void *_in_param
, void **_p_zl3vni
)
1871 struct zebra_ns
*zns
= ns
->info
;
1872 struct zebra_l3vni
**p_zl3vni
= (struct zebra_l3vni
**)_p_zl3vni
;
1873 struct zebra_from_svi_param
*in_param
=
1874 (struct zebra_from_svi_param
*)_in_param
;
1875 struct route_node
*rn
= NULL
;
1876 struct interface
*tmp_if
= NULL
;
1877 struct zebra_if
*zif
= NULL
;
1878 struct zebra_vxlan_vni
*vni
= NULL
;
1880 assert(in_param
&& p_zl3vni
);
1882 /* loop through all vxlan-interface */
1883 for (rn
= route_top(zns
->if_table
); rn
; rn
= route_next(rn
)) {
1884 tmp_if
= (struct interface
*)rn
->info
;
1888 if (!zif
|| zif
->zif_type
!= ZEBRA_IF_VXLAN
)
1890 if (!if_is_operative(tmp_if
))
1893 if (zif
->brslave_info
.br_if
!= in_param
->br_if
)
1896 vni
= zebra_vxlan_if_access_vlan_find(zif
, in_param
->bridge_vlan_aware
,
1898 if (!in_param
->bridge_vlan_aware
|| vni
) {
1899 *p_zl3vni
= zl3vni_lookup(vni
->vni
);
1900 return NS_WALK_STOP
;
1904 return NS_WALK_CONTINUE
;
1908 * Map SVI and associated bridge to a VNI. This is invoked upon getting
1909 * neighbor notifications, to see if they are of interest.
1911 static struct zebra_l3vni
*zl3vni_from_svi(struct interface
*ifp
,
1912 struct interface
*br_if
)
1914 struct zebra_l3vni
*zl3vni
= NULL
;
1915 struct zebra_if
*zif
= NULL
;
1916 struct zebra_from_svi_param in_param
= {};
1917 struct zebra_l3vni
**p_zl3vni
;
1922 /* Make sure the linked interface is a bridge. */
1923 if (!IS_ZEBRA_IF_BRIDGE(br_if
))
1925 in_param
.br_if
= br_if
;
1927 /* Determine if bridge is VLAN-aware or not */
1930 in_param
.bridge_vlan_aware
= IS_ZEBRA_IF_BRIDGE_VLAN_AWARE(zif
);
1931 if (in_param
.bridge_vlan_aware
) {
1932 struct zebra_l2info_vlan
*vl
;
1934 if (!IS_ZEBRA_IF_VLAN(ifp
))
1939 vl
= &zif
->l2info
.vl
;
1940 in_param
.vid
= vl
->vid
;
1943 /* See if this interface (or interface plus VLAN Id) maps to a VxLAN */
1944 /* TODO: Optimize with a hash. */
1948 ns_walk_func(zl3vni_from_svi_ns
, (void *)&in_param
, (void **)p_zl3vni
);
1952 vni_t
vni_id_from_svi(struct interface
*ifp
, struct interface
*br_if
)
1955 struct zebra_evpn
*zevpn
= NULL
;
1956 struct zebra_l3vni
*zl3vni
= NULL
;
1958 /* Check if an L3VNI belongs to this SVI interface.
1959 * If not, check if an L2VNI belongs to this SVI interface.
1961 zl3vni
= zl3vni_from_svi(ifp
, br_if
);
1965 zevpn
= zebra_evpn_from_svi(ifp
, br_if
);
1973 static inline void zl3vni_get_vrr_rmac(struct zebra_l3vni
*zl3vni
,
1974 struct ethaddr
*rmac
)
1979 if (!is_l3vni_oper_up(zl3vni
))
1982 if (zl3vni
->mac_vlan_if
&& if_is_operative(zl3vni
->mac_vlan_if
))
1983 memcpy(rmac
->octet
, zl3vni
->mac_vlan_if
->hw_addr
, ETH_ALEN
);
1987 * Inform BGP about l3-vni.
1989 static int zl3vni_send_add_to_client(struct zebra_l3vni
*zl3vni
)
1991 struct stream
*s
= NULL
;
1992 struct zserv
*client
= NULL
;
1993 struct ethaddr svi_rmac
, vrr_rmac
= {.octet
= {0} };
1994 struct zebra_vrf
*zvrf
;
1995 bool is_anycast_mac
= true;
1997 client
= zserv_find_client(ZEBRA_ROUTE_BGP
, 0);
1998 /* BGP may not be running. */
2002 zvrf
= zebra_vrf_lookup_by_id(zl3vni
->vrf_id
);
2005 /* get the svi and vrr rmac values */
2006 memset(&svi_rmac
, 0, sizeof(svi_rmac
));
2007 zl3vni_get_svi_rmac(zl3vni
, &svi_rmac
);
2008 zl3vni_get_vrr_rmac(zl3vni
, &vrr_rmac
);
2010 /* In absence of vrr mac use svi mac as anycast MAC value */
2011 if (is_zero_mac(&vrr_rmac
)) {
2012 memcpy(&vrr_rmac
, &svi_rmac
, ETH_ALEN
);
2013 is_anycast_mac
= false;
2016 s
= stream_new(ZEBRA_MAX_PACKET_SIZ
);
2018 /* The message is used for both vni add and/or update like
2019 * vrr mac is added for l3vni SVI.
2021 zclient_create_header(s
, ZEBRA_L3VNI_ADD
, zl3vni_vrf_id(zl3vni
));
2022 stream_putl(s
, zl3vni
->vni
);
2023 stream_put(s
, &svi_rmac
, sizeof(struct ethaddr
));
2024 stream_put_in_addr(s
, &zl3vni
->local_vtep_ip
);
2025 stream_put(s
, &zl3vni
->filter
, sizeof(int));
2026 stream_putl(s
, zl3vni
->svi_if
->ifindex
);
2027 stream_put(s
, &vrr_rmac
, sizeof(struct ethaddr
));
2028 stream_putl(s
, is_anycast_mac
);
2030 /* Write packet size. */
2031 stream_putw_at(s
, 0, stream_get_endp(s
));
2033 if (IS_ZEBRA_DEBUG_VXLAN
)
2035 "Send L3_VNI_ADD %u VRF %s RMAC %pEA VRR %pEA local-ip %pI4 filter %s to %s",
2036 zl3vni
->vni
, vrf_id_to_name(zl3vni_vrf_id(zl3vni
)),
2037 &svi_rmac
, &vrr_rmac
, &zl3vni
->local_vtep_ip
,
2038 CHECK_FLAG(zl3vni
->filter
, PREFIX_ROUTES_ONLY
)
2039 ? "prefix-routes-only"
2041 zebra_route_string(client
->proto
));
2043 client
->l3vniadd_cnt
++;
2044 return zserv_send_message(client
, s
);
2048 * Inform BGP about local l3-VNI deletion.
2050 static int zl3vni_send_del_to_client(struct zebra_l3vni
*zl3vni
)
2052 struct stream
*s
= NULL
;
2053 struct zserv
*client
= NULL
;
2055 client
= zserv_find_client(ZEBRA_ROUTE_BGP
, 0);
2056 /* BGP may not be running. */
2060 s
= stream_new(ZEBRA_MAX_PACKET_SIZ
);
2062 zclient_create_header(s
, ZEBRA_L3VNI_DEL
, zl3vni_vrf_id(zl3vni
));
2063 stream_putl(s
, zl3vni
->vni
);
2065 /* Write packet size. */
2066 stream_putw_at(s
, 0, stream_get_endp(s
));
2068 if (IS_ZEBRA_DEBUG_VXLAN
)
2069 zlog_debug("Send L3_VNI_DEL %u VRF %s to %s", zl3vni
->vni
,
2070 vrf_id_to_name(zl3vni_vrf_id(zl3vni
)),
2071 zebra_route_string(client
->proto
));
2073 client
->l3vnidel_cnt
++;
2074 return zserv_send_message(client
, s
);
2077 void zebra_vxlan_process_l3vni_oper_up(struct zebra_l3vni
*zl3vni
)
2082 /* send l3vni add to BGP */
2083 zl3vni_send_add_to_client(zl3vni
);
2086 void zebra_vxlan_process_l3vni_oper_down(struct zebra_l3vni
*zl3vni
)
2091 /* send l3-vni del to BGP*/
2092 zl3vni_send_del_to_client(zl3vni
);
2095 static void zevpn_add_to_l3vni_list(struct hash_bucket
*bucket
, void *ctxt
)
2097 struct zebra_evpn
*zevpn
= (struct zebra_evpn
*)bucket
->data
;
2098 struct zebra_l3vni
*zl3vni
= (struct zebra_l3vni
*)ctxt
;
2100 if (zevpn
->vrf_id
== zl3vni_vrf_id(zl3vni
))
2101 listnode_add_sort(zl3vni
->l2vnis
, zevpn
);
2105 * Handle transition of vni from l2 to l3 and vice versa.
2106 * This function handles only the L2VNI add/delete part of
2107 * the above transition.
2108 * L3VNI add/delete is handled by the calling functions.
2110 static int zebra_vxlan_handle_vni_transition(struct zebra_vrf
*zvrf
, vni_t vni
,
2113 struct zebra_evpn
*zevpn
= NULL
;
2114 struct zebra_l3vni
*zl3vni
= NULL
;
2116 /* There is a possibility that VNI notification was already received
2117 * from kernel and we programmed it as L2-VNI
2118 * In such a case we need to delete this L2-VNI first, so
2119 * that it can be reprogrammed as L3-VNI in the system. It is also
2120 * possible that the vrf-vni mapping is removed from FRR while the vxlan
2121 * interface is still present in kernel. In this case to keep it
2122 * symmetric, we will delete the l3-vni and reprogram it as l2-vni
2125 /* Locate hash entry */
2126 zevpn
= zebra_evpn_lookup(vni
);
2130 if (IS_ZEBRA_DEBUG_VXLAN
)
2131 zlog_debug("Del L2-VNI %u - transition to L3-VNI", vni
);
2133 /* Delete EVPN from BGP. */
2134 zebra_evpn_send_del_to_client(zevpn
);
2136 zebra_evpn_neigh_del_all(zevpn
, 0, 0, DEL_ALL_NEIGH
);
2137 zebra_evpn_mac_del_all(zevpn
, 0, 0, DEL_ALL_MAC
);
2139 /* Free up all remote VTEPs, if any. */
2140 zebra_evpn_vtep_del_all(zevpn
, 1);
2142 zl3vni
= zl3vni_from_vrf(zevpn
->vrf_id
);
2144 listnode_delete(zl3vni
->l2vnis
, zevpn
);
2146 /* Delete the hash entry. */
2147 if (zebra_evpn_vxlan_del(zevpn
)) {
2148 flog_err(EC_ZEBRA_VNI_DEL_FAILED
,
2149 "Failed to del EVPN hash %p, VNI %u", zevpn
,
2154 struct zebra_ns
*zns
;
2155 struct route_node
*rn
;
2156 struct interface
*ifp
;
2157 struct zebra_if
*zif
;
2158 struct zebra_vxlan_vni
*vnip
;
2159 struct zebra_l2info_vxlan
*vxl
;
2160 struct interface
*vlan_if
;
2163 if (IS_ZEBRA_DEBUG_VXLAN
)
2164 zlog_debug("Adding L2-VNI %u - transition from L3-VNI",
2167 /* Find VxLAN interface for this VNI. */
2168 zns
= zebra_ns_lookup(NS_DEFAULT
);
2169 for (rn
= route_top(zns
->if_table
); rn
; rn
= route_next(rn
)) {
2170 ifp
= (struct interface
*)rn
->info
;
2174 if (!zif
|| zif
->zif_type
!= ZEBRA_IF_VXLAN
)
2177 vxl
= &zif
->l2info
.vxl
;
2178 vnip
= zebra_vxlan_if_vni_find(zif
, vni
);
2186 if (IS_ZEBRA_DEBUG_VXLAN
)
2188 "Adding L2-VNI - Failed to find VxLAN interface for VNI %u",
2193 /* Create VNI hash entry for L2VNI */
2194 zevpn
= zebra_evpn_lookup(vni
);
2198 zevpn
= zebra_evpn_add(vni
);
2200 /* Find bridge interface for the VNI */
2201 vlan_if
= zvni_map_to_svi(vnip
->access_vlan
,
2202 zif
->brslave_info
.br_if
);
2204 zevpn
->vrf_id
= vlan_if
->vrf
->vrf_id
;
2205 zl3vni
= zl3vni_from_vrf(vlan_if
->vrf
->vrf_id
);
2207 listnode_add_sort_nodup(zl3vni
->l2vnis
, zevpn
);
2210 zevpn
->vxlan_if
= ifp
;
2211 zevpn
->local_vtep_ip
= vxl
->vtep_ip
;
2213 /* Inform BGP if the VNI is up and mapped to a bridge. */
2214 if (if_is_operative(ifp
) && zif
->brslave_info
.br_if
) {
2215 zebra_evpn_send_add_to_client(zevpn
);
2216 zebra_evpn_read_mac_neigh(zevpn
, ifp
);
2223 /* delete and uninstall rmac hash entry */
2224 static void zl3vni_del_rmac_hash_entry(struct hash_bucket
*bucket
, void *ctx
)
2226 struct zebra_mac
*zrmac
= NULL
;
2227 struct zebra_l3vni
*zl3vni
= NULL
;
2229 zrmac
= (struct zebra_mac
*)bucket
->data
;
2230 zl3vni
= (struct zebra_l3vni
*)ctx
;
2231 zl3vni_rmac_uninstall(zl3vni
, zrmac
);
2233 /* Send RMAC for FPM processing */
2234 hook_call(zebra_rmac_update
, zrmac
, zl3vni
, true, "RMAC deleted");
2236 zl3vni_rmac_del(zl3vni
, zrmac
);
2239 /* delete and uninstall nh hash entry */
2240 static void zl3vni_del_nh_hash_entry(struct hash_bucket
*bucket
, void *ctx
)
2242 struct zebra_neigh
*n
= NULL
;
2243 struct zebra_l3vni
*zl3vni
= NULL
;
2245 n
= (struct zebra_neigh
*)bucket
->data
;
2246 zl3vni
= (struct zebra_l3vni
*)ctx
;
2247 zl3vni_nh_uninstall(zl3vni
, n
);
2248 zl3vni_nh_del(zl3vni
, n
);
2251 /* re-add remote rmac if needed */
2252 static int zebra_vxlan_readd_remote_rmac(struct zebra_l3vni
*zl3vni
,
2253 struct ethaddr
*rmac
)
2255 struct zebra_mac
*zrmac
= NULL
;
2257 zrmac
= zl3vni_rmac_lookup(zl3vni
, rmac
);
2261 if (IS_ZEBRA_DEBUG_VXLAN
)
2262 zlog_debug("Del remote RMAC %pEA L3VNI %u - readd",
2265 zl3vni_rmac_install(zl3vni
, zrmac
);
2269 /* Public functions */
2271 int is_l3vni_for_prefix_routes_only(vni_t vni
)
2273 struct zebra_l3vni
*zl3vni
= NULL
;
2275 zl3vni
= zl3vni_lookup(vni
);
2279 return CHECK_FLAG(zl3vni
->filter
, PREFIX_ROUTES_ONLY
) ? 1 : 0;
2282 /* handle evpn route in vrf table */
2283 void zebra_vxlan_evpn_vrf_route_add(vrf_id_t vrf_id
, const struct ethaddr
*rmac
,
2284 const struct ipaddr
*vtep_ip
,
2285 const struct prefix
*host_prefix
)
2287 struct zebra_l3vni
*zl3vni
= NULL
;
2288 struct ipaddr ipv4_vtep
;
2290 zl3vni
= zl3vni_from_vrf(vrf_id
);
2291 if (!zl3vni
|| !is_l3vni_oper_up(zl3vni
))
2295 * add the next hop neighbor -
2296 * neigh to be installed is the ipv6 nexthop neigh
2298 zl3vni_remote_nh_add(zl3vni
, vtep_ip
, rmac
, host_prefix
);
2301 * if the remote vtep is a ipv4 mapped ipv6 address convert it to ipv4
2302 * address. Rmac is programmed against the ipv4 vtep because we only
2303 * support ipv4 tunnels in the h/w right now
2305 memset(&ipv4_vtep
, 0, sizeof(ipv4_vtep
));
2306 ipv4_vtep
.ipa_type
= IPADDR_V4
;
2307 if (vtep_ip
->ipa_type
== IPADDR_V6
)
2308 ipv4_mapped_ipv6_to_ipv4(&vtep_ip
->ipaddr_v6
,
2309 &(ipv4_vtep
.ipaddr_v4
));
2311 memcpy(&(ipv4_vtep
.ipaddr_v4
), &vtep_ip
->ipaddr_v4
,
2312 sizeof(struct in_addr
));
2315 * add the rmac - remote rmac to be installed is against the ipv4
2318 zl3vni_remote_rmac_add(zl3vni
, rmac
, &ipv4_vtep
);
2321 /* handle evpn vrf route delete */
2322 void zebra_vxlan_evpn_vrf_route_del(vrf_id_t vrf_id
,
2323 struct ipaddr
*vtep_ip
,
2324 struct prefix
*host_prefix
)
2326 struct zebra_l3vni
*zl3vni
= NULL
;
2327 struct zebra_neigh
*nh
= NULL
;
2328 struct zebra_mac
*zrmac
= NULL
;
2330 zl3vni
= zl3vni_from_vrf(vrf_id
);
2334 /* find the next hop entry and rmac entry */
2335 nh
= zl3vni_nh_lookup(zl3vni
, vtep_ip
);
2338 zrmac
= zl3vni_rmac_lookup(zl3vni
, &nh
->emac
);
2340 /* delete the next hop entry */
2341 zl3vni_remote_nh_del(zl3vni
, nh
, host_prefix
);
2343 /* delete the rmac entry */
2345 zl3vni_remote_rmac_del(zl3vni
, zrmac
, vtep_ip
);
2348 void zebra_vxlan_print_specific_rmac_l3vni(struct vty
*vty
, vni_t l3vni
,
2349 struct ethaddr
*rmac
, bool use_json
)
2351 struct zebra_l3vni
*zl3vni
= NULL
;
2352 struct zebra_mac
*zrmac
= NULL
;
2353 json_object
*json
= NULL
;
2355 if (!is_evpn_enabled()) {
2357 vty_out(vty
, "{}\n");
2362 json
= json_object_new_object();
2364 zl3vni
= zl3vni_lookup(l3vni
);
2367 vty_out(vty
, "{}\n");
2369 vty_out(vty
, "%% L3-VNI %u doesn't exist\n", l3vni
);
2373 zrmac
= zl3vni_rmac_lookup(zl3vni
, rmac
);
2376 vty_out(vty
, "{}\n");
2379 "%% Requested RMAC doesn't exist in L3-VNI %u\n",
2384 zl3vni_print_rmac(zrmac
, vty
, json
);
2387 vty_json(vty
, json
);
2390 void zebra_vxlan_print_rmacs_l3vni(struct vty
*vty
, vni_t l3vni
, bool use_json
)
2392 struct zebra_l3vni
*zl3vni
;
2394 struct rmac_walk_ctx wctx
;
2395 json_object
*json
= NULL
;
2397 if (!is_evpn_enabled())
2400 zl3vni
= zl3vni_lookup(l3vni
);
2403 vty_out(vty
, "{}\n");
2405 vty_out(vty
, "%% L3-VNI %u does not exist\n", l3vni
);
2408 num_rmacs
= hashcount(zl3vni
->rmac_table
);
2413 json
= json_object_new_object();
2415 memset(&wctx
, 0, sizeof(wctx
));
2419 vty_out(vty
, "Number of Remote RMACs known for this VNI: %u\n",
2421 vty_out(vty
, "%-17s %-21s\n", "MAC", "Remote VTEP");
2423 json_object_int_add(json
, "numRmacs", num_rmacs
);
2425 hash_iterate(zl3vni
->rmac_table
, zl3vni_print_rmac_hash
, &wctx
);
2428 vty_json(vty
, json
);
2431 void zebra_vxlan_print_rmacs_all_l3vni(struct vty
*vty
, bool use_json
)
2433 json_object
*json
= NULL
;
2436 if (!is_evpn_enabled()) {
2438 vty_out(vty
, "{}\n");
2443 json
= json_object_new_object();
2447 hash_iterate(zrouter
.l3vni_table
,
2448 (void (*)(struct hash_bucket
*,
2449 void *))zl3vni_print_rmac_hash_all_vni
,
2453 vty_json(vty
, json
);
2456 void zebra_vxlan_print_specific_nh_l3vni(struct vty
*vty
, vni_t l3vni
,
2457 struct ipaddr
*ip
, bool use_json
)
2459 struct zebra_l3vni
*zl3vni
= NULL
;
2460 struct zebra_neigh
*n
= NULL
;
2461 json_object
*json
= NULL
;
2463 if (!is_evpn_enabled()) {
2465 vty_out(vty
, "{}\n");
2470 json
= json_object_new_object();
2472 zl3vni
= zl3vni_lookup(l3vni
);
2475 vty_out(vty
, "{}\n");
2477 vty_out(vty
, "%% L3-VNI %u does not exist\n", l3vni
);
2481 n
= zl3vni_nh_lookup(zl3vni
, ip
);
2484 vty_out(vty
, "{}\n");
2487 "%% Requested next-hop not present for L3-VNI %u",
2492 zl3vni_print_nh(n
, vty
, json
);
2495 vty_json(vty
, json
);
2498 void zebra_vxlan_print_nh_l3vni(struct vty
*vty
, vni_t l3vni
, bool use_json
)
2501 struct nh_walk_ctx wctx
;
2502 json_object
*json
= NULL
;
2503 struct zebra_l3vni
*zl3vni
= NULL
;
2505 if (!is_evpn_enabled())
2508 zl3vni
= zl3vni_lookup(l3vni
);
2511 vty_out(vty
, "{}\n");
2513 vty_out(vty
, "%% L3-VNI %u does not exist\n", l3vni
);
2517 num_nh
= hashcount(zl3vni
->nh_table
);
2522 json
= json_object_new_object();
2527 vty_out(vty
, "Number of NH Neighbors known for this VNI: %u\n",
2529 vty_out(vty
, "%-15s %-17s\n", "IP", "RMAC");
2531 json_object_int_add(json
, "numNextHops", num_nh
);
2533 hash_iterate(zl3vni
->nh_table
, zl3vni_print_nh_hash
, &wctx
);
2536 vty_json(vty
, json
);
2539 void zebra_vxlan_print_nh_all_l3vni(struct vty
*vty
, bool use_json
)
2541 json_object
*json
= NULL
;
2544 if (!is_evpn_enabled()) {
2546 vty_out(vty
, "{}\n");
2551 json
= json_object_new_object();
2555 hash_iterate(zrouter
.l3vni_table
,
2556 (void (*)(struct hash_bucket
*,
2557 void *))zl3vni_print_nh_hash_all_vni
,
2561 vty_json(vty
, json
);
2565 * Display L3 VNI information (VTY command handler).
2567 void zebra_vxlan_print_l3vni(struct vty
*vty
, vni_t vni
, bool use_json
)
2570 json_object
*json
= NULL
;
2571 struct zebra_l3vni
*zl3vni
= NULL
;
2573 if (!is_evpn_enabled()) {
2575 vty_out(vty
, "{}\n");
2579 zl3vni
= zl3vni_lookup(vni
);
2582 vty_out(vty
, "{}\n");
2584 vty_out(vty
, "%% VNI %u does not exist\n", vni
);
2589 json
= json_object_new_object();
2593 zl3vni_print(zl3vni
, (void *)args
);
2596 vty_json(vty
, json
);
2599 void zebra_vxlan_print_vrf_vni(struct vty
*vty
, struct zebra_vrf
*zvrf
,
2600 json_object
*json_vrfs
)
2602 char buf
[ETHER_ADDR_STRLEN
];
2603 struct zebra_l3vni
*zl3vni
= NULL
;
2605 zl3vni
= zl3vni_lookup(zvrf
->l3vni
);
2610 vty_out(vty
, "%-37s %-10u %-20s %-20s %-5s %-18s\n",
2611 zvrf_name(zvrf
), zl3vni
->vni
,
2612 zl3vni_vxlan_if_name(zl3vni
),
2613 zl3vni_svi_if_name(zl3vni
), zl3vni_state2str(zl3vni
),
2614 zl3vni_rmac2str(zl3vni
, buf
, sizeof(buf
)));
2616 json_object
*json_vrf
= NULL
;
2618 json_vrf
= json_object_new_object();
2619 json_object_string_add(json_vrf
, "vrf", zvrf_name(zvrf
));
2620 json_object_int_add(json_vrf
, "vni", zl3vni
->vni
);
2621 json_object_string_add(json_vrf
, "vxlanIntf",
2622 zl3vni_vxlan_if_name(zl3vni
));
2623 json_object_string_add(json_vrf
, "sviIntf",
2624 zl3vni_svi_if_name(zl3vni
));
2625 json_object_string_add(json_vrf
, "state",
2626 zl3vni_state2str(zl3vni
));
2627 json_object_string_add(
2628 json_vrf
, "routerMac",
2629 zl3vni_rmac2str(zl3vni
, buf
, sizeof(buf
)));
2630 json_object_array_add(json_vrfs
, json_vrf
);
2635 * Display Neighbors for a VNI (VTY command handler).
2637 void zebra_vxlan_print_neigh_vni(struct vty
*vty
, struct zebra_vrf
*zvrf
,
2638 vni_t vni
, bool use_json
)
2640 struct zebra_evpn
*zevpn
;
2642 struct neigh_walk_ctx wctx
;
2643 json_object
*json
= NULL
;
2645 if (!is_evpn_enabled())
2647 zevpn
= zebra_evpn_lookup(vni
);
2650 vty_out(vty
, "{}\n");
2652 vty_out(vty
, "%% VNI %u does not exist\n", vni
);
2655 num_neigh
= hashcount(zevpn
->neigh_table
);
2660 json
= json_object_new_object();
2662 /* Since we have IPv6 addresses to deal with which can vary widely in
2663 * size, we try to be a bit more elegant in display by first computing
2664 * the maximum width.
2666 memset(&wctx
, 0, sizeof(wctx
));
2669 wctx
.addr_width
= 15;
2671 hash_iterate(zevpn
->neigh_table
, zebra_evpn_find_neigh_addr_width
,
2676 "Number of ARPs (local and remote) known for this VNI: %u\n",
2678 zebra_evpn_print_neigh_hdr(vty
, &wctx
);
2680 json_object_int_add(json
, "numArpNd", num_neigh
);
2682 hash_iterate(zevpn
->neigh_table
, zebra_evpn_print_neigh_hash
, &wctx
);
2684 vty_json(vty
, json
);
2688 * Display neighbors across all VNIs (VTY command handler).
2690 void zebra_vxlan_print_neigh_all_vni(struct vty
*vty
, struct zebra_vrf
*zvrf
,
2691 bool print_dup
, bool use_json
)
2693 json_object
*json
= NULL
;
2696 if (!is_evpn_enabled())
2700 json
= json_object_new_object();
2704 args
[2] = (void *)(ptrdiff_t)print_dup
;
2706 hash_iterate(zvrf
->evpn_table
,
2707 (void (*)(struct hash_bucket
*,
2708 void *))zevpn_print_neigh_hash_all_evpn
,
2711 vty_json(vty
, json
);
2715 * Display neighbors across all VNIs in detail(VTY command handler).
2717 void zebra_vxlan_print_neigh_all_vni_detail(struct vty
*vty
,
2718 struct zebra_vrf
*zvrf
,
2719 bool print_dup
, bool use_json
)
2721 json_object
*json
= NULL
;
2724 if (!is_evpn_enabled())
2728 json
= json_object_new_object();
2732 args
[2] = (void *)(ptrdiff_t)print_dup
;
2734 hash_iterate(zvrf
->evpn_table
,
2735 (void (*)(struct hash_bucket
*,
2736 void *))zevpn_print_neigh_hash_all_evpn_detail
,
2739 vty_json(vty
, json
);
2743 * Display specific neighbor for a VNI, if present (VTY command handler).
2745 void zebra_vxlan_print_specific_neigh_vni(struct vty
*vty
,
2746 struct zebra_vrf
*zvrf
, vni_t vni
,
2747 struct ipaddr
*ip
, bool use_json
)
2749 struct zebra_evpn
*zevpn
;
2750 struct zebra_neigh
*n
;
2751 json_object
*json
= NULL
;
2753 if (!is_evpn_enabled())
2755 zevpn
= zebra_evpn_lookup(vni
);
2758 vty_out(vty
, "{}\n");
2760 vty_out(vty
, "%% VNI %u does not exist\n", vni
);
2763 n
= zebra_evpn_neigh_lookup(zevpn
, ip
);
2767 "%% Requested neighbor does not exist in VNI %u\n",
2772 json
= json_object_new_object();
2774 zebra_evpn_print_neigh(n
, vty
, json
);
2777 vty_json(vty
, json
);
2781 * Display neighbors for a VNI from specific VTEP (VTY command handler).
2782 * By definition, these are remote neighbors.
2784 void zebra_vxlan_print_neigh_vni_vtep(struct vty
*vty
, struct zebra_vrf
*zvrf
,
2785 vni_t vni
, struct in_addr vtep_ip
,
2788 struct zebra_evpn
*zevpn
;
2790 struct neigh_walk_ctx wctx
;
2791 json_object
*json
= NULL
;
2793 if (!is_evpn_enabled())
2795 zevpn
= zebra_evpn_lookup(vni
);
2798 vty_out(vty
, "{}\n");
2800 vty_out(vty
, "%% VNI %u does not exist\n", vni
);
2803 num_neigh
= hashcount(zevpn
->neigh_table
);
2808 json
= json_object_new_object();
2810 memset(&wctx
, 0, sizeof(wctx
));
2813 wctx
.addr_width
= 15;
2814 wctx
.flags
= SHOW_REMOTE_NEIGH_FROM_VTEP
;
2815 wctx
.r_vtep_ip
= vtep_ip
;
2817 hash_iterate(zevpn
->neigh_table
, zebra_evpn_find_neigh_addr_width
,
2819 hash_iterate(zevpn
->neigh_table
, zebra_evpn_print_neigh_hash
, &wctx
);
2822 vty_json(vty
, json
);
2826 * Display Duplicate detected Neighbors for a VNI
2827 * (VTY command handler).
2829 void zebra_vxlan_print_neigh_vni_dad(struct vty
*vty
,
2830 struct zebra_vrf
*zvrf
,
2834 struct zebra_evpn
*zevpn
;
2836 struct neigh_walk_ctx wctx
;
2837 json_object
*json
= NULL
;
2839 if (!is_evpn_enabled())
2842 zevpn
= zebra_evpn_lookup(vni
);
2844 vty_out(vty
, "%% VNI %u does not exist\n", vni
);
2848 num_neigh
= hashcount(zevpn
->neigh_table
);
2852 num_neigh
= num_dup_detected_neighs(zevpn
);
2857 json
= json_object_new_object();
2859 /* Since we have IPv6 addresses to deal with which can vary widely in
2860 * size, we try to be a bit more elegant in display by first computing
2861 * the maximum width.
2863 memset(&wctx
, 0, sizeof(wctx
));
2866 wctx
.addr_width
= 15;
2868 hash_iterate(zevpn
->neigh_table
, zebra_evpn_find_neigh_addr_width
,
2873 "Number of ARPs (local and remote) known for this VNI: %u\n",
2875 vty_out(vty
, "%*s %-6s %-8s %-17s %-30s\n",
2876 -wctx
.addr_width
, "IP", "Type",
2877 "State", "MAC", "Remote ES/VTEP");
2879 json_object_int_add(json
, "numArpNd", num_neigh
);
2881 hash_iterate(zevpn
->neigh_table
, zebra_evpn_print_dad_neigh_hash
,
2885 vty_json(vty
, json
);
2889 * Display MACs for a VNI (VTY command handler).
2891 void zebra_vxlan_print_macs_vni(struct vty
*vty
, struct zebra_vrf
*zvrf
,
2892 vni_t vni
, bool use_json
, bool detail
)
2894 struct zebra_evpn
*zevpn
;
2896 struct mac_walk_ctx wctx
;
2897 json_object
*json
= NULL
;
2898 json_object
*json_mac
= NULL
;
2900 if (!is_evpn_enabled())
2902 zevpn
= zebra_evpn_lookup(vni
);
2905 vty_out(vty
, "{}\n");
2907 vty_out(vty
, "%% VNI %u does not exist\n", vni
);
2910 num_macs
= num_valid_macs(zevpn
);
2915 json
= json_object_new_object();
2916 json_mac
= json_object_new_object();
2919 memset(&wctx
, 0, sizeof(wctx
));
2922 wctx
.json
= json_mac
;
2926 vty_out(vty
, "\nVNI %u #MACs (local and remote) %u\n\n",
2927 zevpn
->vni
, num_macs
);
2930 "Number of MACs (local and remote) known for this VNI: %u\n",
2933 "Flags: N=sync-neighs, I=local-inactive, P=peer-active, X=peer-proxy\n");
2934 vty_out(vty
, "%-17s %-6s %-5s %-30s %-5s %s\n", "MAC",
2935 "Type", "Flags", "Intf/Remote ES/VTEP", "VLAN",
2939 json_object_int_add(json
, "numMacs", num_macs
);
2942 hash_iterate(zevpn
->mac_table
, zebra_evpn_print_mac_hash_detail
,
2945 hash_iterate(zevpn
->mac_table
, zebra_evpn_print_mac_hash
,
2949 json_object_object_add(json
, "macs", json_mac
);
2950 vty_json(vty
, json
);
2955 * Display MACs for all VNIs (VTY command handler).
2957 void zebra_vxlan_print_macs_all_vni(struct vty
*vty
, struct zebra_vrf
*zvrf
,
2958 bool print_dup
, bool use_json
)
2960 struct mac_walk_ctx wctx
;
2961 json_object
*json
= NULL
;
2963 if (!is_evpn_enabled()) {
2965 vty_out(vty
, "{}\n");
2969 json
= json_object_new_object();
2971 memset(&wctx
, 0, sizeof(wctx
));
2974 wctx
.print_dup
= print_dup
;
2975 hash_iterate(zvrf
->evpn_table
, zevpn_print_mac_hash_all_evpn
, &wctx
);
2978 vty_json(vty
, json
);
2982 * Display MACs in detail for all VNIs (VTY command handler).
2984 void zebra_vxlan_print_macs_all_vni_detail(struct vty
*vty
,
2985 struct zebra_vrf
*zvrf
,
2986 bool print_dup
, bool use_json
)
2988 struct mac_walk_ctx wctx
;
2989 json_object
*json
= NULL
;
2991 if (!is_evpn_enabled()) {
2993 vty_out(vty
, "{}\n");
2997 json
= json_object_new_object();
2999 memset(&wctx
, 0, sizeof(wctx
));
3002 wctx
.print_dup
= print_dup
;
3003 hash_iterate(zvrf
->evpn_table
, zevpn_print_mac_hash_all_evpn_detail
,
3007 vty_json(vty
, json
);
3011 * Display MACs for all VNIs (VTY command handler).
3013 void zebra_vxlan_print_macs_all_vni_vtep(struct vty
*vty
,
3014 struct zebra_vrf
*zvrf
,
3015 struct in_addr vtep_ip
, bool use_json
)
3017 struct mac_walk_ctx wctx
;
3018 json_object
*json
= NULL
;
3020 if (!is_evpn_enabled())
3024 json
= json_object_new_object();
3026 memset(&wctx
, 0, sizeof(wctx
));
3028 wctx
.flags
= SHOW_REMOTE_MAC_FROM_VTEP
;
3029 wctx
.r_vtep_ip
= vtep_ip
;
3031 hash_iterate(zvrf
->evpn_table
, zevpn_print_mac_hash_all_evpn
, &wctx
);
3034 vty_json(vty
, json
);
3038 * Display specific MAC for a VNI, if present (VTY command handler).
3040 void zebra_vxlan_print_specific_mac_vni(struct vty
*vty
, struct zebra_vrf
*zvrf
,
3041 vni_t vni
, struct ethaddr
*macaddr
,
3044 struct zebra_evpn
*zevpn
;
3045 struct zebra_mac
*mac
;
3046 json_object
*json
= NULL
;
3048 if (!is_evpn_enabled())
3051 zevpn
= zebra_evpn_lookup(vni
);
3054 vty_out(vty
, "{}\n");
3056 vty_out(vty
, "%% VNI %u does not exist\n", vni
);
3059 mac
= zebra_evpn_mac_lookup(zevpn
, macaddr
);
3062 vty_out(vty
, "{}\n");
3065 "%% Requested MAC does not exist in VNI %u\n",
3071 json
= json_object_new_object();
3073 zebra_evpn_print_mac(mac
, vty
, json
);
3075 vty_json(vty
, json
);
3078 /* Print Duplicate MACs per VNI */
3079 void zebra_vxlan_print_macs_vni_dad(struct vty
*vty
,
3080 struct zebra_vrf
*zvrf
,
3081 vni_t vni
, bool use_json
)
3083 struct zebra_evpn
*zevpn
;
3084 struct mac_walk_ctx wctx
;
3086 json_object
*json
= NULL
;
3087 json_object
*json_mac
= NULL
;
3089 if (!is_evpn_enabled())
3092 zevpn
= zebra_evpn_lookup(vni
);
3094 vty_out(vty
, "%% VNI %u does not exist\n", vni
);
3098 num_macs
= num_valid_macs(zevpn
);
3102 num_macs
= num_dup_detected_macs(zevpn
);
3107 json
= json_object_new_object();
3108 json_mac
= json_object_new_object();
3111 memset(&wctx
, 0, sizeof(wctx
));
3114 wctx
.json
= json_mac
;
3118 "Number of MACs (local and remote) known for this VNI: %u\n",
3120 vty_out(vty
, "%-17s %-6s %-5s %-30s %-5s\n", "MAC", "Type",
3121 "Flags", "Intf/Remote ES/VTEP", "VLAN");
3123 json_object_int_add(json
, "numMacs", num_macs
);
3125 hash_iterate(zevpn
->mac_table
, zebra_evpn_print_dad_mac_hash
, &wctx
);
3128 json_object_object_add(json
, "macs", json_mac
);
3129 vty_json(vty
, json
);
3134 int zebra_vxlan_clear_dup_detect_vni_mac(struct zebra_vrf
*zvrf
, vni_t vni
,
3135 struct ethaddr
*macaddr
, char *errmsg
,
3138 struct zebra_evpn
*zevpn
;
3139 struct zebra_mac
*mac
;
3140 struct listnode
*node
= NULL
;
3141 struct zebra_neigh
*nbr
= NULL
;
3143 if (!is_evpn_enabled())
3146 zevpn
= zebra_evpn_lookup(vni
);
3148 snprintfrr(errmsg
, errmsg_len
, "VNI %u does not exist", vni
);
3152 mac
= zebra_evpn_mac_lookup(zevpn
, macaddr
);
3154 snprintf(errmsg
, errmsg_len
,
3155 "Requested MAC does not exist in VNI %u\n", vni
);
3159 if (!CHECK_FLAG(mac
->flags
, ZEBRA_MAC_DUPLICATE
)) {
3160 snprintfrr(errmsg
, errmsg_len
,
3161 "Requested MAC is not duplicate detected\n");
3165 /* Remove all IPs as duplicate associcated with this MAC */
3166 for (ALL_LIST_ELEMENTS_RO(mac
->neigh_list
, node
, nbr
)) {
3167 /* For local neigh mark inactive so MACIP update is generated
3168 * to BGP. This is a scenario where MAC update received
3169 * and detected as duplicate which marked neigh as duplicate.
3170 * Later local neigh update did not get a chance to relay
3171 * to BGP. Similarly remote macip update, neigh needs to be
3172 * installed locally.
3174 if (zvrf
->dad_freeze
&&
3175 CHECK_FLAG(nbr
->flags
, ZEBRA_NEIGH_DUPLICATE
)) {
3176 if (CHECK_FLAG(nbr
->flags
, ZEBRA_NEIGH_LOCAL
))
3177 ZEBRA_NEIGH_SET_INACTIVE(nbr
);
3178 else if (CHECK_FLAG(nbr
->flags
, ZEBRA_NEIGH_REMOTE
))
3179 zebra_evpn_rem_neigh_install(
3180 zevpn
, nbr
, false /*was_static*/);
3183 UNSET_FLAG(nbr
->flags
, ZEBRA_NEIGH_DUPLICATE
);
3185 nbr
->detect_start_time
.tv_sec
= 0;
3186 nbr
->dad_dup_detect_time
= 0;
3189 UNSET_FLAG(mac
->flags
, ZEBRA_MAC_DUPLICATE
);
3191 mac
->detect_start_time
.tv_sec
= 0;
3192 mac
->detect_start_time
.tv_usec
= 0;
3193 mac
->dad_dup_detect_time
= 0;
3194 THREAD_OFF(mac
->dad_mac_auto_recovery_timer
);
3196 /* warn-only action return */
3197 if (!zvrf
->dad_freeze
)
3200 /* Local: Notify Peer VTEPs, Remote: Install the entry */
3201 if (CHECK_FLAG(mac
->flags
, ZEBRA_MAC_LOCAL
)) {
3203 if (zebra_evpn_mac_send_add_to_client(zevpn
->vni
, &mac
->macaddr
,
3204 mac
->flags
, mac
->loc_seq
,
3208 /* Process all neighbors associated with this MAC. */
3209 zebra_evpn_process_neigh_on_local_mac_change(zevpn
, mac
, 0,
3212 } else if (CHECK_FLAG(mac
->flags
, ZEBRA_MAC_REMOTE
)) {
3213 zebra_evpn_process_neigh_on_remote_mac_add(zevpn
, mac
);
3215 /* Install the entry. */
3216 zebra_evpn_rem_mac_install(zevpn
, mac
, false /* was_static */);
3222 int zebra_vxlan_clear_dup_detect_vni_ip(struct zebra_vrf
*zvrf
, vni_t vni
,
3223 struct ipaddr
*ip
, char *errmsg
,
3226 struct zebra_evpn
*zevpn
;
3227 struct zebra_neigh
*nbr
;
3228 struct zebra_mac
*mac
;
3229 char buf
[INET6_ADDRSTRLEN
];
3230 char buf2
[ETHER_ADDR_STRLEN
];
3232 if (!is_evpn_enabled())
3235 zevpn
= zebra_evpn_lookup(vni
);
3237 snprintfrr(errmsg
, errmsg_len
, "VNI %u does not exist\n", vni
);
3241 nbr
= zebra_evpn_neigh_lookup(zevpn
, ip
);
3243 snprintfrr(errmsg
, errmsg_len
,
3244 "Requested host IP does not exist in VNI %u\n", vni
);
3248 ipaddr2str(&nbr
->ip
, buf
, sizeof(buf
));
3250 if (!CHECK_FLAG(nbr
->flags
, ZEBRA_NEIGH_DUPLICATE
)) {
3251 snprintfrr(errmsg
, errmsg_len
,
3252 "Requested host IP %s is not duplicate detected\n",
3257 mac
= zebra_evpn_mac_lookup(zevpn
, &nbr
->emac
);
3259 if (CHECK_FLAG(mac
->flags
, ZEBRA_MAC_DUPLICATE
)) {
3262 "Requested IP's associated MAC %s is still in duplicate state\n",
3263 prefix_mac2str(&nbr
->emac
, buf2
, sizeof(buf2
)));
3267 if (IS_ZEBRA_DEBUG_VXLAN
)
3268 zlog_debug("%s: clear neigh %s in dup state, flags 0x%x seq %u",
3269 __func__
, buf
, nbr
->flags
, nbr
->loc_seq
);
3271 UNSET_FLAG(nbr
->flags
, ZEBRA_NEIGH_DUPLICATE
);
3273 nbr
->detect_start_time
.tv_sec
= 0;
3274 nbr
->detect_start_time
.tv_usec
= 0;
3275 nbr
->dad_dup_detect_time
= 0;
3276 THREAD_OFF(nbr
->dad_ip_auto_recovery_timer
);
3278 if (!!CHECK_FLAG(nbr
->flags
, ZEBRA_NEIGH_LOCAL
)) {
3279 zebra_evpn_neigh_send_add_to_client(zevpn
->vni
, ip
, &nbr
->emac
,
3280 nbr
->mac
, nbr
->flags
,
3282 } else if (!!CHECK_FLAG(nbr
->flags
, ZEBRA_NEIGH_REMOTE
)) {
3283 zebra_evpn_rem_neigh_install(zevpn
, nbr
, false /*was_static*/);
3289 static void zevpn_clear_dup_mac_hash(struct hash_bucket
*bucket
, void *ctxt
)
3291 struct mac_walk_ctx
*wctx
= ctxt
;
3292 struct zebra_mac
*mac
;
3293 struct zebra_evpn
*zevpn
;
3294 struct listnode
*node
= NULL
;
3295 struct zebra_neigh
*nbr
= NULL
;
3297 mac
= (struct zebra_mac
*)bucket
->data
;
3301 zevpn
= wctx
->zevpn
;
3303 if (!CHECK_FLAG(mac
->flags
, ZEBRA_MAC_DUPLICATE
))
3306 UNSET_FLAG(mac
->flags
, ZEBRA_MAC_DUPLICATE
);
3308 mac
->detect_start_time
.tv_sec
= 0;
3309 mac
->detect_start_time
.tv_usec
= 0;
3310 mac
->dad_dup_detect_time
= 0;
3311 THREAD_OFF(mac
->dad_mac_auto_recovery_timer
);
3313 /* Remove all IPs as duplicate associcated with this MAC */
3314 for (ALL_LIST_ELEMENTS_RO(mac
->neigh_list
, node
, nbr
)) {
3315 if (CHECK_FLAG(nbr
->flags
, ZEBRA_NEIGH_LOCAL
)
3317 ZEBRA_NEIGH_SET_INACTIVE(nbr
);
3319 UNSET_FLAG(nbr
->flags
, ZEBRA_NEIGH_DUPLICATE
);
3321 nbr
->detect_start_time
.tv_sec
= 0;
3322 nbr
->dad_dup_detect_time
= 0;
3325 /* Local: Notify Peer VTEPs, Remote: Install the entry */
3326 if (CHECK_FLAG(mac
->flags
, ZEBRA_MAC_LOCAL
)) {
3328 if (zebra_evpn_mac_send_add_to_client(zevpn
->vni
, &mac
->macaddr
,
3329 mac
->flags
, mac
->loc_seq
,
3333 /* Process all neighbors associated with this MAC. */
3334 zebra_evpn_process_neigh_on_local_mac_change(zevpn
, mac
, 0,
3337 } else if (CHECK_FLAG(mac
->flags
, ZEBRA_MAC_REMOTE
)) {
3338 zebra_evpn_process_neigh_on_remote_mac_add(zevpn
, mac
);
3340 /* Install the entry. */
3341 zebra_evpn_rem_mac_install(zevpn
, mac
, false /* was_static */);
3345 static void zevpn_clear_dup_detect_hash_vni_all(struct hash_bucket
*bucket
,
3348 struct zebra_evpn
*zevpn
;
3349 struct zebra_vrf
*zvrf
;
3350 struct mac_walk_ctx m_wctx
;
3351 struct neigh_walk_ctx n_wctx
;
3353 zevpn
= (struct zebra_evpn
*)bucket
->data
;
3357 zvrf
= (struct zebra_vrf
*)args
[0];
3359 if (hashcount(zevpn
->neigh_table
)) {
3360 memset(&n_wctx
, 0, sizeof(n_wctx
));
3361 n_wctx
.zevpn
= zevpn
;
3363 hash_iterate(zevpn
->neigh_table
,
3364 zebra_evpn_clear_dup_neigh_hash
, &n_wctx
);
3367 if (num_valid_macs(zevpn
)) {
3368 memset(&m_wctx
, 0, sizeof(m_wctx
));
3369 m_wctx
.zevpn
= zevpn
;
3371 hash_iterate(zevpn
->mac_table
, zevpn_clear_dup_mac_hash
, &m_wctx
);
3376 int zebra_vxlan_clear_dup_detect_vni_all(struct zebra_vrf
*zvrf
)
3380 if (!is_evpn_enabled())
3385 hash_iterate(zvrf
->evpn_table
,
3386 (void (*)(struct hash_bucket
*, void *))
3387 zevpn_clear_dup_detect_hash_vni_all
, args
);
3392 int zebra_vxlan_clear_dup_detect_vni(struct zebra_vrf
*zvrf
, vni_t vni
)
3394 struct zebra_evpn
*zevpn
;
3395 struct mac_walk_ctx m_wctx
;
3396 struct neigh_walk_ctx n_wctx
;
3398 if (!is_evpn_enabled())
3401 zevpn
= zebra_evpn_lookup(vni
);
3403 zlog_warn("VNI %u does not exist", vni
);
3407 if (hashcount(zevpn
->neigh_table
)) {
3408 memset(&n_wctx
, 0, sizeof(n_wctx
));
3409 n_wctx
.zevpn
= zevpn
;
3411 hash_iterate(zevpn
->neigh_table
,
3412 zebra_evpn_clear_dup_neigh_hash
, &n_wctx
);
3415 if (num_valid_macs(zevpn
)) {
3416 memset(&m_wctx
, 0, sizeof(m_wctx
));
3417 m_wctx
.zevpn
= zevpn
;
3419 hash_iterate(zevpn
->mac_table
, zevpn_clear_dup_mac_hash
, &m_wctx
);
3426 * Display MACs for a VNI from specific VTEP (VTY command handler).
3428 void zebra_vxlan_print_macs_vni_vtep(struct vty
*vty
, struct zebra_vrf
*zvrf
,
3429 vni_t vni
, struct in_addr vtep_ip
,
3432 struct zebra_evpn
*zevpn
;
3434 struct mac_walk_ctx wctx
;
3435 json_object
*json
= NULL
;
3436 json_object
*json_mac
= NULL
;
3438 if (!is_evpn_enabled())
3440 zevpn
= zebra_evpn_lookup(vni
);
3443 vty_out(vty
, "{}\n");
3445 vty_out(vty
, "%% VNI %u does not exist\n", vni
);
3448 num_macs
= num_valid_macs(zevpn
);
3453 json
= json_object_new_object();
3454 json_mac
= json_object_new_object();
3457 memset(&wctx
, 0, sizeof(wctx
));
3460 wctx
.flags
= SHOW_REMOTE_MAC_FROM_VTEP
;
3461 wctx
.r_vtep_ip
= vtep_ip
;
3462 wctx
.json
= json_mac
;
3463 hash_iterate(zevpn
->mac_table
, zebra_evpn_print_mac_hash
, &wctx
);
3466 json_object_int_add(json
, "numMacs", wctx
.count
);
3468 json_object_object_add(json
, "macs", json_mac
);
3469 vty_json(vty
, json
);
3475 * Display VNI information (VTY command handler).
3477 * use_json flag indicates that output should be in JSON format.
3478 * json_array is non NULL when JSON output needs to be aggregated (by the
3479 * caller) and then printed, otherwise, JSON evpn vni info is printed
3482 void zebra_vxlan_print_vni(struct vty
*vty
, struct zebra_vrf
*zvrf
, vni_t vni
,
3483 bool use_json
, json_object
*json_array
)
3485 json_object
*json
= NULL
;
3487 struct zebra_l3vni
*zl3vni
= NULL
;
3488 struct zebra_evpn
*zevpn
= NULL
;
3490 if (!is_evpn_enabled())
3494 json
= json_object_new_object();
3499 zl3vni
= zl3vni_lookup(vni
);
3501 zl3vni_print(zl3vni
, (void *)args
);
3503 zevpn
= zebra_evpn_lookup(vni
);
3505 zebra_evpn_print(zevpn
, (void *)args
);
3507 vty_out(vty
, "%% VNI %u does not exist\n", vni
);
3512 * Each "json" object contains info about 1 VNI.
3513 * When "json_array" is non-null, we aggreggate the json output
3514 * into json_array and print it as a JSON array.
3517 json_object_array_add(json_array
, json
);
3519 vty_json(vty
, json
);
3523 /* Display all global details for EVPN */
3524 void zebra_vxlan_print_evpn(struct vty
*vty
, bool uj
)
3529 json_object
*json
= NULL
;
3530 struct zebra_vrf
*zvrf
= NULL
;
3532 if (!is_evpn_enabled())
3535 zvrf
= zebra_vrf_get_evpn();
3537 num_l3vnis
= hashcount(zrouter
.l3vni_table
);
3538 num_l2vnis
= hashcount(zvrf
->evpn_table
);
3539 num_vnis
= num_l2vnis
+ num_l3vnis
;
3542 json
= json_object_new_object();
3543 json_object_string_add(json
, "advertiseGatewayMacip",
3544 zvrf
->advertise_gw_macip
? "Yes" : "No");
3545 json_object_string_add(json
, "advertiseSviMacip",
3546 zvrf
->advertise_svi_macip
? "Yes"
3548 json_object_string_add(json
, "advertiseSviMac",
3549 zebra_evpn_mh_do_adv_svi_mac() ? "Yes"
3551 json_object_int_add(json
, "numVnis", num_vnis
);
3552 json_object_int_add(json
, "numL2Vnis", num_l2vnis
);
3553 json_object_int_add(json
, "numL3Vnis", num_l3vnis
);
3554 if (zebra_evpn_do_dup_addr_detect(zvrf
))
3555 json_object_boolean_true_add(json
,
3556 "isDuplicateAddrDetection");
3558 json_object_boolean_false_add(json
,
3559 "isDuplicateAddrDetection");
3560 json_object_int_add(json
, "maxMoves", zvrf
->dad_max_moves
);
3561 json_object_int_add(json
, "detectionTime", zvrf
->dad_time
);
3562 json_object_int_add(json
, "detectionFreezeTime",
3563 zvrf
->dad_freeze_time
);
3564 zebra_evpn_mh_json(json
);
3566 vty_out(vty
, "L2 VNIs: %u\n", num_l2vnis
);
3567 vty_out(vty
, "L3 VNIs: %u\n", num_l3vnis
);
3568 vty_out(vty
, "Advertise gateway mac-ip: %s\n",
3569 zvrf
->advertise_gw_macip
? "Yes" : "No");
3570 vty_out(vty
, "Advertise svi mac-ip: %s\n",
3571 zvrf
->advertise_svi_macip
? "Yes" : "No");
3572 vty_out(vty
, "Advertise svi mac: %s\n",
3573 zebra_evpn_mh_do_adv_svi_mac() ? "Yes" : "No");
3574 vty_out(vty
, "Duplicate address detection: %s\n",
3575 zebra_evpn_do_dup_addr_detect(zvrf
) ? "Enable"
3577 vty_out(vty
, " Detection max-moves %u, time %d\n",
3578 zvrf
->dad_max_moves
, zvrf
->dad_time
);
3579 if (zvrf
->dad_freeze
) {
3580 if (zvrf
->dad_freeze_time
)
3581 vty_out(vty
, " Detection freeze %u\n",
3582 zvrf
->dad_freeze_time
);
3584 vty_out(vty
, " Detection freeze %s\n",
3587 zebra_evpn_mh_print(vty
);
3591 vty_json(vty
, json
);
3595 * Display VNI hash table (VTY command handler).
3597 void zebra_vxlan_print_vnis(struct vty
*vty
, struct zebra_vrf
*zvrf
,
3600 json_object
*json
= NULL
;
3603 if (!is_evpn_enabled())
3607 json
= json_object_new_object();
3609 vty_out(vty
, "%-10s %-4s %-21s %-8s %-8s %-15s %-37s\n", "VNI",
3610 "Type", "VxLAN IF", "# MACs", "# ARPs",
3611 "# Remote VTEPs", "Tenant VRF");
3616 /* Display all L2-VNIs */
3619 (void (*)(struct hash_bucket
*, void *))zebra_evpn_print_hash
,
3622 /* Display all L3-VNIs */
3623 hash_iterate(zrouter
.l3vni_table
,
3624 (void (*)(struct hash_bucket
*, void *))zl3vni_print_hash
,
3628 vty_json(vty
, json
);
3631 void zebra_vxlan_dup_addr_detection(ZAPI_HANDLER_ARGS
)
3635 uint32_t max_moves
= 0;
3636 uint32_t freeze_time
= 0;
3637 bool dup_addr_detect
= false;
3638 bool freeze
= false;
3639 bool old_addr_detect
;
3642 STREAM_GETL(s
, dup_addr_detect
);
3643 STREAM_GETL(s
, time
);
3644 STREAM_GETL(s
, max_moves
);
3645 STREAM_GETL(s
, freeze
);
3646 STREAM_GETL(s
, freeze_time
);
3648 old_addr_detect
= zebra_evpn_do_dup_addr_detect(zvrf
);
3649 zvrf
->dup_addr_detect
= dup_addr_detect
;
3650 dup_addr_detect
= zebra_evpn_do_dup_addr_detect(zvrf
);
3652 /* DAD previous state was enabled, and new state is disable,
3653 * clear all duplicate detected addresses.
3655 if (old_addr_detect
&& !dup_addr_detect
)
3656 zebra_vxlan_clear_dup_detect_vni_all(zvrf
);
3658 zvrf
->dad_time
= time
;
3659 zvrf
->dad_max_moves
= max_moves
;
3660 zvrf
->dad_freeze
= freeze
;
3661 zvrf
->dad_freeze_time
= freeze_time
;
3663 if (IS_ZEBRA_DEBUG_VXLAN
)
3665 "VRF %s duplicate detect %s max_moves %u timeout %u freeze %s freeze_time %u",
3666 vrf_id_to_name(zvrf
->vrf
->vrf_id
),
3667 dup_addr_detect
? "enable" : "disable",
3668 zvrf
->dad_max_moves
, zvrf
->dad_time
,
3669 zvrf
->dad_freeze
? "enable" : "disable",
3670 zvrf
->dad_freeze_time
);
3677 * Display VNI hash table in detail(VTY command handler).
3679 void zebra_vxlan_print_vnis_detail(struct vty
*vty
, struct zebra_vrf
*zvrf
,
3682 json_object
*json_array
= NULL
;
3683 struct zebra_ns
*zns
= NULL
;
3684 struct zebra_evpn_show zes
;
3686 if (!is_evpn_enabled())
3689 zns
= zebra_ns_lookup(NS_DEFAULT
);
3694 json_array
= json_object_new_array();
3697 zes
.json
= json_array
;
3699 zes
.use_json
= use_json
;
3701 /* Display all L2-VNIs */
3702 hash_iterate(zvrf
->evpn_table
,
3703 (void (*)(struct hash_bucket
*,
3704 void *))zebra_evpn_print_hash_detail
,
3707 /* Display all L3-VNIs */
3708 hash_iterate(zrouter
.l3vni_table
,
3709 (void (*)(struct hash_bucket
*,
3710 void *))zl3vni_print_hash_detail
,
3714 vty_json(vty
, json_array
);
3718 * Handle neighbor delete notification from the kernel (on a VLAN device
3719 * / L3 interface). This may result in either the neighbor getting deleted
3720 * from our database or being re-added to the kernel (if it is a valid
3723 int zebra_vxlan_handle_kernel_neigh_del(struct interface
*ifp
,
3724 struct interface
*link_if
,
3727 struct zebra_evpn
*zevpn
= NULL
;
3728 struct zebra_l3vni
*zl3vni
= NULL
;
3730 /* check if this is a remote neigh entry corresponding to remote
3733 zl3vni
= zl3vni_from_svi(ifp
, link_if
);
3735 return zl3vni_local_nh_del(zl3vni
, ip
);
3737 /* We are only interested in neighbors on an SVI that resides on top
3738 * of a VxLAN bridge.
3740 zevpn
= zebra_evpn_from_svi(ifp
, link_if
);
3742 if (IS_ZEBRA_DEBUG_VXLAN
)
3744 "%s: Del neighbor %pIA EVPN is not present for interface %s",
3745 __func__
, ip
, ifp
->name
);
3749 if (!zevpn
->vxlan_if
) {
3751 "VNI %u hash %p doesn't have intf upon local neighbor DEL",
3756 if (IS_ZEBRA_DEBUG_VXLAN
)
3757 zlog_debug("Del neighbor %pIA intf %s(%u) -> L2-VNI %u",
3758 ip
, ifp
->name
, ifp
->ifindex
, zevpn
->vni
);
3760 return zebra_evpn_neigh_del_ip(zevpn
, ip
);
3764 * Handle neighbor add or update notification from the kernel (on a VLAN
3765 * device / L3 interface). This is typically for a local neighbor but can
3766 * also be for a remote neighbor (e.g., ageout notification). It could
3767 * also be a "move" scenario.
3769 int zebra_vxlan_handle_kernel_neigh_update(struct interface
*ifp
,
3770 struct interface
*link_if
,
3772 struct ethaddr
*macaddr
,
3776 bool local_inactive
, bool dp_static
)
3778 struct zebra_evpn
*zevpn
= NULL
;
3779 struct zebra_l3vni
*zl3vni
= NULL
;
3781 /* check if this is a remote neigh entry corresponding to remote
3784 zl3vni
= zl3vni_from_svi(ifp
, link_if
);
3786 return zl3vni_local_nh_add_update(zl3vni
, ip
, state
);
3788 /* We are only interested in neighbors on an SVI that resides on top
3789 * of a VxLAN bridge.
3791 zevpn
= zebra_evpn_from_svi(ifp
, link_if
);
3795 if (IS_ZEBRA_DEBUG_VXLAN
|| IS_ZEBRA_DEBUG_EVPN_MH_NEIGH
)
3797 "Add/Update neighbor %pIA MAC %pEA intf %s(%u) state 0x%x %s%s%s%s-> L2-VNI %u",
3798 ip
, macaddr
, ifp
->name
,
3799 ifp
->ifindex
, state
, is_ext
? "ext-learned " : "",
3800 is_router
? "router " : "",
3801 local_inactive
? "local_inactive " : "",
3802 dp_static
? "peer_sync " : "", zevpn
->vni
);
3804 /* Is this about a local neighbor or a remote one? */
3806 return zebra_evpn_local_neigh_update(zevpn
, ifp
, ip
, macaddr
,
3807 is_router
, local_inactive
,
3810 return zebra_evpn_remote_neigh_update(zevpn
, ifp
, ip
, macaddr
, state
);
3814 zebra_vxlan_remote_macip_helper(bool add
, struct stream
*s
, vni_t
*vni
,
3815 struct ethaddr
*macaddr
, uint16_t *ipa_len
,
3816 struct ipaddr
*ip
, struct in_addr
*vtep_ip
,
3817 uint8_t *flags
, uint32_t *seq
, esi_t
*esi
)
3822 * Obtain each remote MACIP and process.
3823 * Message contains VNI, followed by MAC followed by IP (if any)
3824 * followed by remote VTEP IP.
3826 memset(ip
, 0, sizeof(*ip
));
3827 STREAM_GETL(s
, *vni
);
3828 STREAM_GET(macaddr
->octet
, s
, ETH_ALEN
);
3829 STREAM_GETW(s
, *ipa_len
);
3832 if (*ipa_len
== IPV4_MAX_BYTELEN
)
3833 ip
->ipa_type
= IPADDR_V4
;
3834 else if (*ipa_len
== IPV6_MAX_BYTELEN
)
3835 ip
->ipa_type
= IPADDR_V6
;
3837 if (IS_ZEBRA_DEBUG_VXLAN
)
3839 "ipa_len *must* be %d or %d bytes in length not %d",
3840 IPV4_MAX_BYTELEN
, IPV6_MAX_BYTELEN
,
3842 goto stream_failure
;
3845 STREAM_GET(&ip
->ip
.addr
, s
, *ipa_len
);
3847 l
+= 4 + ETH_ALEN
+ 4 + *ipa_len
;
3848 STREAM_GET(&vtep_ip
->s_addr
, s
, IPV4_MAX_BYTELEN
);
3849 l
+= IPV4_MAX_BYTELEN
;
3852 STREAM_GETC(s
, *flags
);
3853 STREAM_GETL(s
, *seq
);
3855 STREAM_GET(esi
, s
, sizeof(esi_t
));
3866 * Handle message from client to delete a remote MACIP for a VNI.
3868 void zebra_vxlan_remote_macip_del(ZAPI_HANDLER_ARGS
)
3872 struct ethaddr macaddr
;
3874 struct in_addr vtep_ip
;
3875 uint16_t l
= 0, ipa_len
;
3876 char buf1
[INET6_ADDRSTRLEN
];
3880 while (l
< hdr
->length
) {
3881 int res_length
= zebra_vxlan_remote_macip_helper(
3882 false, s
, &vni
, &macaddr
, &ipa_len
, &ip
, &vtep_ip
, NULL
,
3885 if (res_length
== -1)
3886 goto stream_failure
;
3889 if (IS_ZEBRA_DEBUG_VXLAN
)
3891 "Recv MACIP DEL VNI %u MAC %pEA%s%s Remote VTEP %pI4 from %s",
3893 ipa_len
? " IP " : "",
3895 ipaddr2str(&ip
, buf1
, sizeof(buf1
)) : "",
3896 &vtep_ip
, zebra_route_string(client
->proto
));
3898 /* Enqueue to workqueue for processing */
3899 zebra_rib_queue_evpn_rem_macip_del(vni
, &macaddr
, &ip
, vtep_ip
);
3907 * Handle message from client to add a remote MACIP for a VNI. This
3908 * could be just the add of a MAC address or the add of a neighbor
3911 void zebra_vxlan_remote_macip_add(ZAPI_HANDLER_ARGS
)
3915 struct ethaddr macaddr
;
3917 struct in_addr vtep_ip
;
3918 uint16_t l
= 0, ipa_len
;
3921 char buf1
[INET6_ADDRSTRLEN
];
3923 char esi_buf
[ESI_STR_LEN
];
3925 if (!EVPN_ENABLED(zvrf
)) {
3926 zlog_debug("EVPN not enabled, ignoring remote MACIP ADD");
3932 while (l
< hdr
->length
) {
3934 int res_length
= zebra_vxlan_remote_macip_helper(
3935 true, s
, &vni
, &macaddr
, &ipa_len
, &ip
, &vtep_ip
,
3936 &flags
, &seq
, &esi
);
3938 if (res_length
== -1)
3939 goto stream_failure
;
3942 if (IS_ZEBRA_DEBUG_VXLAN
) {
3943 if (memcmp(&esi
, zero_esi
, sizeof(esi_t
)))
3944 esi_to_str(&esi
, esi_buf
, sizeof(esi_buf
));
3946 strlcpy(esi_buf
, "-", ESI_STR_LEN
);
3948 "Recv %sMACIP ADD VNI %u MAC %pEA%s%s flags 0x%x seq %u VTEP %pI4 ESI %s from %s",
3949 (flags
& ZEBRA_MACIP_TYPE_SYNC_PATH
) ?
3952 ipa_len
? " IP " : "",
3954 ipaddr2str(&ip
, buf1
, sizeof(buf1
)) : "",
3955 flags
, seq
, &vtep_ip
, esi_buf
,
3956 zebra_route_string(client
->proto
));
3959 /* Enqueue to workqueue for processing */
3960 zebra_rib_queue_evpn_rem_macip_add(vni
, &macaddr
, &ip
, flags
,
3961 seq
, vtep_ip
, &esi
);
3969 * Handle remote vtep delete by kernel; re-add the vtep if we have it
3971 int zebra_vxlan_check_readd_vtep(struct interface
*ifp
, vni_t vni
,
3972 struct in_addr vtep_ip
)
3974 struct zebra_if
*zif
;
3975 struct zebra_vrf
*zvrf
= NULL
;
3976 struct zebra_evpn
*zevpn
= NULL
;
3977 struct zebra_vtep
*zvtep
= NULL
;
3978 struct zebra_vxlan_vni
*vnip
;
3983 /* If EVPN is not enabled, nothing to do. */
3984 if (!is_evpn_enabled())
3987 /* Locate VRF corresponding to interface. */
3988 zvrf
= ifp
->vrf
->info
;
3992 vnip
= zebra_vxlan_if_vni_find(zif
, vni
);
3996 /* Locate hash entry; it is expected to exist. */
3997 zevpn
= zebra_evpn_lookup(vni
);
4001 /* If the remote vtep entry doesn't exists nothing to do */
4002 zvtep
= zebra_evpn_vtep_find(zevpn
, &vtep_ip
);
4006 if (IS_ZEBRA_DEBUG_VXLAN
)
4008 "Del MAC for remote VTEP %pI4 intf %s(%u) VNI %u - readd",
4009 &vtep_ip
, ifp
->name
, ifp
->ifindex
, vni
);
4011 zebra_evpn_vtep_install(zevpn
, zvtep
);
4016 * Handle notification of MAC add/update over VxLAN. If the kernel is notifying
4017 * us, this must involve a multihoming scenario. Treat this as implicit delete
4018 * of any prior local MAC.
4020 static int zebra_vxlan_check_del_local_mac(struct interface
*ifp
,
4021 struct interface
*br_if
,
4022 struct ethaddr
*macaddr
,
4023 vlanid_t vid
, vni_t vni
)
4025 struct zebra_if
*zif
;
4026 struct zebra_evpn
*zevpn
;
4027 struct zebra_mac
*mac
;
4032 /* Check if EVPN is enabled. */
4033 if (!is_evpn_enabled())
4036 /* Locate hash entry; it is expected to exist. */
4037 zevpn
= zebra_evpn_lookup(vni
);
4041 /* If entry doesn't exist, nothing to do. */
4042 mac
= zebra_evpn_mac_lookup(zevpn
, macaddr
);
4046 /* Is it a local entry? */
4047 if (!CHECK_FLAG(mac
->flags
, ZEBRA_MAC_LOCAL
))
4050 if (IS_ZEBRA_DEBUG_VXLAN
)
4052 "Add/update remote MAC %pEA intf %s(%u) VNI %u flags 0x%x - del local",
4053 macaddr
, ifp
->name
, ifp
->ifindex
, vni
, mac
->flags
);
4055 /* Remove MAC from BGP. */
4056 zebra_evpn_mac_send_del_to_client(zevpn
->vni
, macaddr
, mac
->flags
,
4060 * If there are no neigh associated with the mac delete the mac
4061 * else mark it as AUTO for forward reference
4063 if (!listcount(mac
->neigh_list
)) {
4064 zebra_evpn_mac_del(zevpn
, mac
);
4066 zebra_evpn_mac_clear_fwd_info(mac
);
4067 UNSET_FLAG(mac
->flags
, ZEBRA_MAC_ALL_LOCAL_FLAGS
);
4068 UNSET_FLAG(mac
->flags
, ZEBRA_MAC_STICKY
);
4069 SET_FLAG(mac
->flags
, ZEBRA_MAC_AUTO
);
4075 /* MAC notification from the dataplane with a network dest port -
4076 * 1. This can be a local MAC on a down ES (if fast-failover is not possible
4077 * 2. Or it can be a remote MAC
4079 int zebra_vxlan_dp_network_mac_add(struct interface
*ifp
,
4080 struct interface
*br_if
,
4081 struct ethaddr
*macaddr
, vlanid_t vid
,
4082 vni_t vni
, uint32_t nhg_id
, bool sticky
,
4085 struct zebra_evpn_es
*es
;
4086 struct interface
*acc_ifp
;
4088 /* If netlink message is with vid, it will have no nexthop.
4092 if (IS_ZEBRA_DEBUG_VXLAN
|| IS_ZEBRA_DEBUG_EVPN_MH_MAC
)
4093 zlog_debug("dpAdd MAC %pEA VID %u - ignore as no nhid",
4098 /* Get vxlan's vid for netlink message has no it. */
4099 vid
= ((struct zebra_if
*)ifp
->info
)->l2info
.vxl
.access_vlan
;
4101 /* if remote mac delete the local entry */
4102 if (!nhg_id
|| !zebra_evpn_nhg_is_local_es(nhg_id
, &es
)
4103 || !zebra_evpn_es_local_mac_via_network_port(es
)) {
4104 if (IS_ZEBRA_DEBUG_VXLAN
|| IS_ZEBRA_DEBUG_EVPN_MH_MAC
)
4105 zlog_debug("dpAdd remote MAC %pEA VID %u", macaddr
,
4107 return zebra_vxlan_check_del_local_mac(ifp
, br_if
, macaddr
, vid
,
4111 /* If local MAC on a down local ES translate the network-mac-add
4112 * to a local-active-mac-add
4114 if (IS_ZEBRA_DEBUG_VXLAN
|| IS_ZEBRA_DEBUG_EVPN_MH_MAC
)
4115 zlog_debug("dpAdd local-nw-MAC %pEA VID %u", macaddr
, vid
);
4116 acc_ifp
= es
->zif
->ifp
;
4117 return zebra_vxlan_local_mac_add_update(
4118 acc_ifp
, br_if
, macaddr
, vid
, sticky
,
4119 false /* local_inactive */, dp_static
);
4123 * Handle network MAC delete by kernel -
4124 * 1. readd the remote MAC if we have it
4125 * 2. local MAC with does ES may also need to be re-installed
4127 int zebra_vxlan_dp_network_mac_del(struct interface
*ifp
,
4128 struct interface
*br_if
,
4129 struct ethaddr
*macaddr
, vlanid_t vid
,
4132 struct zebra_if
*zif
= NULL
;
4133 struct zebra_evpn
*zevpn
= NULL
;
4134 struct zebra_l3vni
*zl3vni
= NULL
;
4135 struct zebra_mac
*mac
= NULL
;
4140 /* Check if EVPN is enabled. */
4141 if (!is_evpn_enabled())
4144 /* check if this is a remote RMAC and readd simillar to remote macs */
4145 zl3vni
= zl3vni_lookup(vni
);
4147 return zebra_vxlan_readd_remote_rmac(zl3vni
, macaddr
);
4149 /* Locate hash entry; it is expected to exist. */
4150 zevpn
= zebra_evpn_lookup(vni
);
4154 /* If entry doesn't exist, nothing to do. */
4155 mac
= zebra_evpn_mac_lookup(zevpn
, macaddr
);
4159 if (CHECK_FLAG(mac
->flags
, ZEBRA_MAC_REMOTE
)) {
4160 /* If remote entry simply re-install */
4161 if (IS_ZEBRA_DEBUG_VXLAN
|| IS_ZEBRA_DEBUG_EVPN_MH_MAC
)
4163 "dpDel remote MAC %pEA intf %s(%u) VNI %u - readd",
4164 macaddr
, ifp
->name
, ifp
->ifindex
, vni
);
4165 zebra_evpn_rem_mac_install(zevpn
, mac
, false /* was_static */);
4166 } else if (CHECK_FLAG(mac
->flags
, ZEBRA_MAC_LOCAL
) && mac
->es
4167 && zebra_evpn_es_local_mac_via_network_port(mac
->es
)) {
4168 /* If local entry via nw-port call local-del which will
4169 * re-install entry in the dataplane is needed
4171 if (IS_ZEBRA_DEBUG_VXLAN
|| IS_ZEBRA_DEBUG_EVPN_MH_MAC
)
4172 zlog_debug("dpDel local-nw-MAC %pEA VNI %u", macaddr
,
4175 zebra_evpn_del_local_mac(zevpn
, mac
, false);
4182 * Handle local MAC delete (on a port or VLAN corresponding to this VNI).
4184 int zebra_vxlan_local_mac_del(struct interface
*ifp
, struct interface
*br_if
,
4185 struct ethaddr
*macaddr
, vlanid_t vid
)
4187 struct zebra_evpn
*zevpn
;
4188 struct zebra_mac
*mac
;
4190 /* We are interested in MACs only on ports or (port, VLAN) that
4193 zevpn
= zebra_evpn_map_vlan(ifp
, br_if
, vid
);
4196 if (!zevpn
->vxlan_if
) {
4198 "VNI %u hash %p doesn't have intf upon local MAC DEL",
4203 /* If entry doesn't exist, nothing to do. */
4204 mac
= zebra_evpn_mac_lookup(zevpn
, macaddr
);
4208 /* Is it a local entry? */
4209 if (!CHECK_FLAG(mac
->flags
, ZEBRA_MAC_LOCAL
))
4212 return zebra_evpn_del_local_mac(zevpn
, mac
, false);
4216 * Handle local MAC add (on a port or VLAN corresponding to this VNI).
4218 int zebra_vxlan_local_mac_add_update(struct interface
*ifp
,
4219 struct interface
*br_if
,
4220 struct ethaddr
*macaddr
, vlanid_t vid
,
4221 bool sticky
, bool local_inactive
,
4224 struct zebra_evpn
*zevpn
;
4225 struct zebra_vrf
*zvrf
;
4229 /* We are interested in MACs only on ports or (port, VLAN) that
4232 zevpn
= zebra_evpn_map_vlan(ifp
, br_if
, vid
);
4234 if (IS_ZEBRA_DEBUG_VXLAN
)
4236 " Add/Update %sMAC %pEA intf %s(%u) VID %u, could not find EVPN",
4237 sticky
? "sticky " : "", macaddr
,
4238 ifp
->name
, ifp
->ifindex
, vid
);
4242 if (!zevpn
->vxlan_if
) {
4243 if (IS_ZEBRA_DEBUG_VXLAN
)
4245 " VNI %u hash %p doesn't have intf upon local MAC ADD",
4250 zvrf
= zebra_vrf_get_evpn();
4251 return zebra_evpn_add_update_local_mac(zvrf
, zevpn
, ifp
, macaddr
, vid
,
4252 sticky
, local_inactive
,
4257 * Handle message from client to delete a remote VTEP for an EVPN.
4259 void zebra_vxlan_remote_vtep_del_zapi(ZAPI_HANDLER_ARGS
)
4262 unsigned short l
= 0;
4264 struct in_addr vtep_ip
;
4266 if (!is_evpn_enabled()) {
4268 "%s: EVPN is not enabled yet we have received a VTEP DEL msg",
4273 if (!EVPN_ENABLED(zvrf
)) {
4274 zlog_debug("Recv VTEP DEL zapi for non-EVPN VRF %u",
4281 while (l
< hdr
->length
) {
4282 int flood_control
__attribute__((unused
));
4284 /* Obtain each remote VTEP and process. */
4285 STREAM_GETL(s
, vni
);
4287 STREAM_GET(&vtep_ip
.s_addr
, s
, IPV4_MAX_BYTELEN
);
4288 l
+= IPV4_MAX_BYTELEN
;
4290 /* Flood control is intentionally ignored right now */
4291 STREAM_GETL(s
, flood_control
);
4294 if (IS_ZEBRA_DEBUG_VXLAN
)
4295 zlog_debug("Recv VTEP DEL %pI4 VNI %u from %s",
4297 zebra_route_string(client
->proto
));
4299 /* Enqueue for processing */
4300 zebra_rib_queue_evpn_rem_vtep_del(zvrf_id(zvrf
), vni
, vtep_ip
);
4308 * Handle message from client to delete a remote VTEP for an EVPN.
4310 void zebra_vxlan_remote_vtep_del(vrf_id_t vrf_id
, vni_t vni
,
4311 struct in_addr vtep_ip
)
4313 struct zebra_evpn
*zevpn
;
4314 struct zebra_vtep
*zvtep
;
4315 struct interface
*ifp
;
4316 struct zebra_if
*zif
;
4317 struct zebra_vrf
*zvrf
;
4319 if (!is_evpn_enabled()) {
4320 zlog_debug("%s: Can't process vtep del: EVPN is not enabled",
4325 zvrf
= zebra_vrf_lookup_by_id(vrf_id
);
4329 if (!EVPN_ENABLED(zvrf
)) {
4330 zlog_debug("Can't process VTEP DEL for non-EVPN VRF %u",
4335 /* Locate VNI hash entry - expected to exist. */
4336 zevpn
= zebra_evpn_lookup(vni
);
4338 if (IS_ZEBRA_DEBUG_VXLAN
)
4340 "Failed to locate VNI hash for remote VTEP DEL, VNI %u",
4345 ifp
= zevpn
->vxlan_if
;
4348 "VNI %u hash %p doesn't have intf upon remote VTEP DEL",
4354 /* If down or not mapped to a bridge, we're done. */
4355 if (!if_is_operative(ifp
) || !zif
->brslave_info
.br_if
)
4358 /* If the remote VTEP does not exist, there's nothing more to
4360 * Otherwise, uninstall any remote MACs pointing to this VTEP
4361 * and then, the VTEP entry itself and remove it.
4363 zvtep
= zebra_evpn_vtep_find(zevpn
, &vtep_ip
);
4367 zebra_evpn_vtep_uninstall(zevpn
, &vtep_ip
);
4368 zebra_evpn_vtep_del(zevpn
, zvtep
);
4372 * Handle message from client to add a remote VTEP for an EVPN.
4374 void zebra_vxlan_remote_vtep_add(vrf_id_t vrf_id
, vni_t vni
,
4375 struct in_addr vtep_ip
, int flood_control
)
4377 struct zebra_evpn
*zevpn
;
4378 struct interface
*ifp
;
4379 struct zebra_if
*zif
;
4380 struct zebra_vtep
*zvtep
;
4381 struct zebra_vrf
*zvrf
;
4383 if (!is_evpn_enabled()) {
4384 zlog_debug("%s: EVPN not enabled: can't process a VTEP ADD",
4389 zvrf
= zebra_vrf_lookup_by_id(vrf_id
);
4393 if (!EVPN_ENABLED(zvrf
)) {
4394 zlog_debug("Can't process VTEP ADD for non-EVPN VRF %u",
4399 /* Locate VNI hash entry - expected to exist. */
4400 zevpn
= zebra_evpn_lookup(vni
);
4403 EC_ZEBRA_VTEP_ADD_FAILED
,
4404 "Failed to locate EVPN hash upon remote VTEP ADD, VNI %u",
4409 ifp
= zevpn
->vxlan_if
;
4412 EC_ZEBRA_VTEP_ADD_FAILED
,
4413 "VNI %u hash %p doesn't have intf upon remote VTEP ADD",
4420 /* If down or not mapped to a bridge, we're done. */
4421 if (!if_is_operative(ifp
) || !zif
->brslave_info
.br_if
)
4424 zvtep
= zebra_evpn_vtep_find(zevpn
, &vtep_ip
);
4426 /* If the remote VTEP already exists check if
4427 * the flood mode has changed
4429 if (zvtep
->flood_control
!= flood_control
) {
4430 if (zvtep
->flood_control
== VXLAN_FLOOD_DISABLED
)
4431 /* old mode was head-end-replication but
4432 * is no longer; get rid of the HER fdb
4433 * entry installed before
4435 zebra_evpn_vtep_uninstall(zevpn
, &vtep_ip
);
4436 zvtep
->flood_control
= flood_control
;
4437 zebra_evpn_vtep_install(zevpn
, zvtep
);
4440 zvtep
= zebra_evpn_vtep_add(zevpn
, &vtep_ip
, flood_control
);
4442 zebra_evpn_vtep_install(zevpn
, zvtep
);
4444 flog_err(EC_ZEBRA_VTEP_ADD_FAILED
,
4445 "Failed to add remote VTEP, VNI %u zevpn %p",
4451 * Handle message from client to add a remote VTEP for an EVPN.
4453 void zebra_vxlan_remote_vtep_add_zapi(ZAPI_HANDLER_ARGS
)
4456 unsigned short l
= 0;
4458 struct in_addr vtep_ip
;
4461 if (!is_evpn_enabled()) {
4463 "%s: EVPN not enabled yet we received a VTEP ADD zapi msg",
4468 if (!EVPN_ENABLED(zvrf
)) {
4469 zlog_debug("Recv VTEP ADD zapi for non-EVPN VRF %u",
4476 while (l
< hdr
->length
) {
4477 /* Obtain each remote VTEP and process. */
4478 STREAM_GETL(s
, vni
);
4480 STREAM_GET(&vtep_ip
.s_addr
, s
, IPV4_MAX_BYTELEN
);
4481 STREAM_GETL(s
, flood_control
);
4482 l
+= IPV4_MAX_BYTELEN
+ 4;
4484 if (IS_ZEBRA_DEBUG_VXLAN
)
4485 zlog_debug("Recv VTEP ADD %pI4 VNI %u flood %d from %s",
4486 &vtep_ip
, vni
, flood_control
,
4487 zebra_route_string(client
->proto
));
4489 /* Enqueue for processing */
4490 zebra_rib_queue_evpn_rem_vtep_add(zvrf_id(zvrf
), vni
, vtep_ip
,
4499 * Add/Del gateway macip to evpn
4501 * 1. SVI interface on a vlan aware bridge
4502 * 2. SVI interface on a vlan unaware bridge
4503 * 3. vrr interface (MACVLAN) associated to a SVI
4504 * We advertise macip routes for an interface if it is associated to VxLan vlan
4506 int zebra_vxlan_add_del_gw_macip(struct interface
*ifp
, const struct prefix
*p
,
4510 struct ethaddr macaddr
;
4511 struct zebra_evpn
*zevpn
= NULL
;
4513 memset(&ip
, 0, sizeof(ip
));
4514 memset(&macaddr
, 0, sizeof(macaddr
));
4516 /* Check if EVPN is enabled. */
4517 if (!is_evpn_enabled())
4520 if (IS_ZEBRA_IF_MACVLAN(ifp
)) {
4521 struct interface
*svi_if
=
4522 NULL
; /* SVI corresponding to the MACVLAN */
4523 struct zebra_if
*ifp_zif
=
4524 NULL
; /* Zebra daemon specific info for MACVLAN */
4525 struct zebra_if
*svi_if_zif
=
4526 NULL
; /* Zebra daemon specific info for SVI*/
4528 ifp_zif
= ifp
->info
;
4533 * for a MACVLAN interface the link represents the svi_if
4535 svi_if
= if_lookup_by_index_per_ns(zebra_ns_lookup(NS_DEFAULT
),
4536 ifp_zif
->link_ifindex
);
4538 zlog_debug("MACVLAN %s(%u) without link information",
4539 ifp
->name
, ifp
->ifindex
);
4543 if (IS_ZEBRA_IF_VLAN(svi_if
)) {
4545 * If it is a vlan aware bridge then the link gives the
4546 * bridge information
4548 struct interface
*svi_if_link
= NULL
;
4550 svi_if_zif
= svi_if
->info
;
4552 svi_if_link
= if_lookup_by_index_per_ns(
4553 zebra_ns_lookup(NS_DEFAULT
),
4554 svi_if_zif
->link_ifindex
);
4555 zevpn
= zebra_evpn_from_svi(svi_if
,
4558 } else if (IS_ZEBRA_IF_BRIDGE(svi_if
)) {
4560 * If it is a vlan unaware bridge then svi is the bridge
4563 zevpn
= zebra_evpn_from_svi(svi_if
, svi_if
);
4565 } else if (IS_ZEBRA_IF_VLAN(ifp
)) {
4566 struct zebra_if
*svi_if_zif
=
4567 NULL
; /* Zebra daemon specific info for SVI */
4568 struct interface
*svi_if_link
=
4569 NULL
; /* link info for the SVI = bridge info */
4571 svi_if_zif
= ifp
->info
;
4573 svi_if_link
= if_lookup_by_index_per_ns(
4574 zebra_ns_lookup(NS_DEFAULT
),
4575 svi_if_zif
->link_ifindex
);
4577 zevpn
= zebra_evpn_from_svi(ifp
, svi_if_link
);
4579 } else if (IS_ZEBRA_IF_BRIDGE(ifp
)) {
4580 zevpn
= zebra_evpn_from_svi(ifp
, ifp
);
4586 if (!zevpn
->vxlan_if
) {
4587 zlog_debug("VNI %u hash %p doesn't have intf upon MACVLAN up",
4592 /* VRR IP is advertised only if gw-macip-adv-enabled */
4593 if (IS_ZEBRA_IF_MACVLAN(ifp
)) {
4594 if (!advertise_gw_macip_enabled(zevpn
))
4597 /* SVI IP is advertised if gw or svi macip-adv-enabled */
4598 if (!advertise_svi_macip_enabled(zevpn
)
4599 && !advertise_gw_macip_enabled(zevpn
))
4603 memcpy(&macaddr
.octet
, ifp
->hw_addr
, ETH_ALEN
);
4605 if (p
->family
== AF_INET
) {
4606 ip
.ipa_type
= IPADDR_V4
;
4607 memcpy(&(ip
.ipaddr_v4
), &(p
->u
.prefix4
),
4608 sizeof(struct in_addr
));
4609 } else if (p
->family
== AF_INET6
) {
4610 ip
.ipa_type
= IPADDR_V6
;
4611 memcpy(&(ip
.ipaddr_v6
), &(p
->u
.prefix6
),
4612 sizeof(struct in6_addr
));
4617 zebra_evpn_gw_macip_add(ifp
, zevpn
, &macaddr
, &ip
);
4619 zebra_evpn_gw_macip_del(ifp
, zevpn
, &ip
);
4625 * Handle SVI interface going down.
4626 * SVI can be associated to either L3-VNI or L2-VNI.
4627 * For L2-VNI: At this point, this is a NOP since
4628 * the kernel deletes the neighbor entries on this SVI (if any).
4629 * We only need to update the vrf corresponding to zevpn.
4630 * For L3-VNI: L3-VNI is operationally down, update mac-ip routes and delete
4633 int zebra_vxlan_svi_down(struct interface
*ifp
, struct interface
*link_if
)
4635 struct zebra_l3vni
*zl3vni
= NULL
;
4637 zl3vni
= zl3vni_from_svi(ifp
, link_if
);
4640 /* process l3-vni down */
4641 zebra_vxlan_process_l3vni_oper_down(zl3vni
);
4643 /* remove association with svi-if */
4644 zl3vni
->svi_if
= NULL
;
4646 struct zebra_evpn
*zevpn
= NULL
;
4648 /* Unlink the SVI from the access VLAN */
4649 zebra_evpn_acc_bd_svi_set(ifp
->info
, link_if
->info
, false);
4651 /* since we dont have svi corresponding to zevpn, we associate it
4652 * to default vrf. Note: the corresponding neigh entries on the
4653 * SVI would have already been deleted */
4654 zevpn
= zebra_evpn_from_svi(ifp
, link_if
);
4657 /* remove from l3-vni list */
4658 zl3vni
= zl3vni_from_vrf(zevpn
->vrf_id
);
4660 listnode_delete(zl3vni
->l2vnis
, zevpn
);
4662 zevpn
->svi_if
= NULL
;
4663 zevpn
->vrf_id
= VRF_DEFAULT
;
4665 /* update the tenant vrf in BGP */
4666 if (if_is_operative(zevpn
->vxlan_if
))
4667 zebra_evpn_send_add_to_client(zevpn
);
4674 * Handle SVI interface coming up.
4675 * SVI can be associated to L3-VNI (l3vni vxlan interface) or L2-VNI (l2-vni
4677 * For L2-VNI: we need to install any remote neighbors entried (used for
4679 * For L3-VNI: SVI will be used to get the rmac to be used with L3-VNI
4681 int zebra_vxlan_svi_up(struct interface
*ifp
, struct interface
*link_if
)
4683 struct zebra_evpn
*zevpn
= NULL
;
4684 struct zebra_l3vni
*zl3vni
= NULL
;
4686 zl3vni
= zl3vni_from_svi(ifp
, link_if
);
4689 /* associate with svi */
4690 zl3vni
->svi_if
= ifp
;
4692 /* process oper-up */
4693 if (is_l3vni_oper_up(zl3vni
))
4694 zebra_vxlan_process_l3vni_oper_up(zl3vni
);
4697 /* process SVI up for l2-vni */
4698 struct neigh_walk_ctx n_wctx
;
4700 zevpn
= zebra_evpn_from_svi(ifp
, link_if
);
4704 if (!zevpn
->vxlan_if
) {
4706 "VNI %u hash %p doesn't have intf upon SVI up",
4711 if (IS_ZEBRA_DEBUG_VXLAN
)
4713 "SVI %s(%u) VNI %u VRF %s is UP, installing neighbors",
4714 ifp
->name
, ifp
->ifindex
, zevpn
->vni
,
4717 /* update the vrf information for l2-vni and inform bgp */
4718 zevpn
->svi_if
= ifp
;
4719 zevpn
->vrf_id
= ifp
->vrf
->vrf_id
;
4721 zl3vni
= zl3vni_from_vrf(zevpn
->vrf_id
);
4723 listnode_add_sort_nodup(zl3vni
->l2vnis
, zevpn
);
4725 if (if_is_operative(zevpn
->vxlan_if
))
4726 zebra_evpn_send_add_to_client(zevpn
);
4728 /* Install any remote neighbors for this VNI. */
4729 memset(&n_wctx
, 0, sizeof(n_wctx
));
4730 n_wctx
.zevpn
= zevpn
;
4731 hash_iterate(zevpn
->neigh_table
, zebra_evpn_install_neigh_hash
,
4734 /* Link the SVI from the access VLAN */
4735 zebra_evpn_acc_bd_svi_set(ifp
->info
, link_if
->info
, true);
4737 /* Update MACIP routes created by advertise-svi-ip */
4738 if (advertise_svi_macip_enabled(zevpn
)) {
4739 zebra_evpn_del_macip_for_intf(ifp
, zevpn
);
4740 zebra_evpn_add_macip_for_intf(ifp
, zevpn
);
4748 * Handle MAC-VLAN interface going down.
4749 * L3VNI: When MAC-VLAN interface goes down,
4750 * find its associated SVI and update type2/type-5 routes
4753 void zebra_vxlan_macvlan_down(struct interface
*ifp
)
4755 struct zebra_l3vni
*zl3vni
= NULL
;
4756 struct zebra_if
*zif
, *link_zif
;
4757 struct interface
*link_ifp
, *link_if
;
4761 link_ifp
= zif
->link
;
4763 if (IS_ZEBRA_DEBUG_VXLAN
)
4765 "macvlan parent link is not found. Parent index %d ifp %s",
4767 ifindex2ifname(zif
->link_ifindex
,
4771 link_zif
= link_ifp
->info
;
4774 link_if
= if_lookup_by_index_per_ns(zebra_ns_lookup(NS_DEFAULT
),
4775 link_zif
->link_ifindex
);
4777 zl3vni
= zl3vni_from_svi(link_ifp
, link_if
);
4779 zl3vni
->mac_vlan_if
= NULL
;
4780 if (is_l3vni_oper_up(zl3vni
))
4781 zebra_vxlan_process_l3vni_oper_up(zl3vni
);
4786 * Handle MAC-VLAN interface going up.
4787 * L3VNI: When MAC-VLAN interface comes up,
4788 * find its associated SVI and update type-2 routes
4789 * with MAC-VLAN's MAC as RMAC and for type-5 routes
4790 * use SVI's MAC as RMAC.
4792 void zebra_vxlan_macvlan_up(struct interface
*ifp
)
4794 struct zebra_l3vni
*zl3vni
= NULL
;
4795 struct zebra_if
*zif
, *link_zif
;
4796 struct interface
*link_ifp
, *link_if
;
4800 link_ifp
= zif
->link
;
4801 link_zif
= link_ifp
->info
;
4804 link_if
= if_lookup_by_index_per_ns(zebra_ns_lookup(NS_DEFAULT
),
4805 link_zif
->link_ifindex
);
4806 zl3vni
= zl3vni_from_svi(link_ifp
, link_if
);
4808 /* associate with macvlan (VRR) interface */
4809 zl3vni
->mac_vlan_if
= ifp
;
4811 /* process oper-up */
4812 if (is_l3vni_oper_up(zl3vni
))
4813 zebra_vxlan_process_l3vni_oper_up(zl3vni
);
4817 int zebra_vxlan_process_vrf_vni_cmd(struct zebra_vrf
*zvrf
, vni_t vni
,
4818 char *err
, int err_str_sz
, int filter
,
4821 struct zebra_l3vni
*zl3vni
= NULL
;
4822 struct zebra_vrf
*zvrf_evpn
= NULL
;
4824 zvrf_evpn
= zebra_vrf_get_evpn();
4826 if (IS_ZEBRA_DEBUG_VXLAN
)
4827 zlog_debug("vrf %s vni %u %s", zvrf_name(zvrf
), vni
,
4828 add
? "ADD" : "DEL");
4831 /* check if the vni is already present under zvrf */
4833 snprintf(err
, err_str_sz
,
4834 "VNI is already configured under the vrf");
4838 /* check if this VNI is already present in the system */
4839 zl3vni
= zl3vni_lookup(vni
);
4841 snprintf(err
, err_str_sz
,
4842 "VNI is already configured as L3-VNI");
4846 /* Remove L2VNI if present */
4847 zebra_vxlan_handle_vni_transition(zvrf
, vni
, add
);
4849 /* add the L3-VNI to the global table */
4850 zl3vni
= zl3vni_add(vni
, zvrf_id(zvrf
));
4852 /* associate the vrf with vni */
4855 /* set the filter in l3vni to denote if we are using l3vni only
4859 SET_FLAG(zl3vni
->filter
, PREFIX_ROUTES_ONLY
);
4861 /* associate with vxlan-intf;
4862 * we need to associate with the vxlan-intf first
4864 zl3vni
->vxlan_if
= zl3vni_map_to_vxlan_if(zl3vni
);
4866 /* associate with corresponding SVI interface, we can associate
4867 * with svi-if only after vxlan interface association is
4870 zl3vni
->svi_if
= zl3vni_map_to_svi_if(zl3vni
);
4872 zl3vni
->mac_vlan_if
= zl3vni_map_to_mac_vlan_if(zl3vni
);
4874 if (IS_ZEBRA_DEBUG_VXLAN
)
4876 "%s: l3vni %u svi_if %s mac_vlan_if %s",
4878 zl3vni
->svi_if
? zl3vni
->svi_if
->name
: "NIL",
4879 zl3vni
->mac_vlan_if
? zl3vni
->mac_vlan_if
->name
4882 /* formulate l2vni list */
4883 hash_iterate(zvrf_evpn
->evpn_table
, zevpn_add_to_l3vni_list
,
4886 if (is_l3vni_oper_up(zl3vni
))
4887 zebra_vxlan_process_l3vni_oper_up(zl3vni
);
4890 zl3vni
= zl3vni_lookup(vni
);
4892 snprintf(err
, err_str_sz
, "VNI doesn't exist");
4896 if (zvrf
->l3vni
!= vni
) {
4897 snprintf(err
, err_str_sz
,
4898 "VNI %d doesn't exist in VRF: %s",
4899 vni
, zvrf
->vrf
->name
);
4903 if (filter
&& !CHECK_FLAG(zl3vni
->filter
, PREFIX_ROUTES_ONLY
)) {
4904 snprintf(err
, ERR_STR_SZ
,
4905 "prefix-routes-only is not set for the vni");
4909 zebra_vxlan_process_l3vni_oper_down(zl3vni
);
4911 /* delete and uninstall all rmacs */
4912 hash_iterate(zl3vni
->rmac_table
, zl3vni_del_rmac_hash_entry
,
4915 /* delete and uninstall all next-hops */
4916 hash_iterate(zl3vni
->nh_table
, zl3vni_del_nh_hash_entry
,
4922 /* Add L2VNI for this VNI */
4923 zebra_vxlan_handle_vni_transition(zvrf
, vni
, add
);
4928 int zebra_vxlan_vrf_enable(struct zebra_vrf
*zvrf
)
4930 struct zebra_l3vni
*zl3vni
= NULL
;
4933 zl3vni
= zl3vni_lookup(zvrf
->l3vni
);
4937 zl3vni
->vrf_id
= zvrf_id(zvrf
);
4938 if (is_l3vni_oper_up(zl3vni
))
4939 zebra_vxlan_process_l3vni_oper_up(zl3vni
);
4943 int zebra_vxlan_vrf_disable(struct zebra_vrf
*zvrf
)
4945 struct zebra_l3vni
*zl3vni
= NULL
;
4948 zl3vni
= zl3vni_lookup(zvrf
->l3vni
);
4952 zebra_vxlan_process_l3vni_oper_down(zl3vni
);
4954 /* delete and uninstall all rmacs */
4955 hash_iterate(zl3vni
->rmac_table
, zl3vni_del_rmac_hash_entry
, zl3vni
);
4956 /* delete and uninstall all next-hops */
4957 hash_iterate(zl3vni
->nh_table
, zl3vni_del_nh_hash_entry
, zl3vni
);
4959 zl3vni
->vrf_id
= VRF_UNKNOWN
;
4964 int zebra_vxlan_vrf_delete(struct zebra_vrf
*zvrf
)
4966 struct zebra_l3vni
*zl3vni
= NULL
;
4970 zl3vni
= zl3vni_lookup(zvrf
->l3vni
);
4976 zebra_vxlan_handle_vni_transition(zvrf
, vni
, 0);
4982 * Handle message from client to specify the flooding mechanism for
4983 * BUM packets. The default is to do head-end (ingress) replication
4984 * and the other supported option is to disable it. This applies to
4985 * all BUM traffic and disabling it applies to both the transmit and
4986 * receive direction.
4988 void zebra_vxlan_flood_control(ZAPI_HANDLER_ARGS
)
4991 enum vxlan_flood_control flood_ctrl
;
4993 if (!EVPN_ENABLED(zvrf
)) {
4994 zlog_err("EVPN flood control for non-EVPN VRF %u",
5000 STREAM_GETC(s
, flood_ctrl
);
5002 if (IS_ZEBRA_DEBUG_VXLAN
)
5003 zlog_debug("EVPN flood control %u, currently %u",
5004 flood_ctrl
, zvrf
->vxlan_flood_ctrl
);
5006 if (zvrf
->vxlan_flood_ctrl
== flood_ctrl
)
5009 zvrf
->vxlan_flood_ctrl
= flood_ctrl
;
5011 /* Install or uninstall flood entries corresponding to
5014 hash_iterate(zvrf
->evpn_table
, zebra_evpn_handle_flooding_remote_vteps
,
5022 * Handle message from client to enable/disable advertisement of svi macip
5025 void zebra_vxlan_advertise_svi_macip(ZAPI_HANDLER_ARGS
)
5030 struct zebra_evpn
*zevpn
= NULL
;
5031 struct interface
*ifp
= NULL
;
5033 if (!EVPN_ENABLED(zvrf
)) {
5034 zlog_debug("EVPN SVI-MACIP Adv for non-EVPN VRF %u",
5040 STREAM_GETC(s
, advertise
);
5041 STREAM_GETL(s
, vni
);
5044 if (IS_ZEBRA_DEBUG_VXLAN
)
5045 zlog_debug("EVPN SVI-MACIP Adv %s, currently %s",
5046 advertise
? "enabled" : "disabled",
5047 advertise_svi_macip_enabled(NULL
)
5051 if (zvrf
->advertise_svi_macip
== advertise
)
5056 zvrf
->advertise_svi_macip
= advertise
;
5057 hash_iterate(zvrf
->evpn_table
,
5058 zebra_evpn_gw_macip_add_for_evpn_hash
,
5061 hash_iterate(zvrf
->evpn_table
,
5062 zebra_evpn_svi_macip_del_for_evpn_hash
,
5064 zvrf
->advertise_svi_macip
= advertise
;
5068 struct zebra_if
*zif
= NULL
;
5069 struct interface
*vlan_if
= NULL
;
5070 struct zebra_vxlan_vni
*zl2_info_vni
;
5073 zevpn
= zebra_evpn_lookup(vni
);
5077 if (IS_ZEBRA_DEBUG_VXLAN
)
5079 "EVPN SVI macip Adv %s on VNI %d, currently %s",
5080 advertise
? "enabled" : "disabled", vni
,
5081 advertise_svi_macip_enabled(zevpn
)
5085 old_advertise
= advertise_svi_macip_enabled(zevpn
);
5087 /* Store flag even though SVI is not present.
5088 * Once SVI comes up triggers self MAC-IP route add.
5090 zevpn
->advertise_svi_macip
= advertise
;
5091 if (advertise_svi_macip_enabled(zevpn
) == old_advertise
)
5094 ifp
= zevpn
->vxlan_if
;
5100 /* If down or not mapped to a bridge, we're done. */
5101 if (!if_is_operative(ifp
) || !zif
->brslave_info
.br_if
)
5104 zl2_info_vni
= zebra_vxlan_if_vni_find(zif
, vni
);
5108 vlan_if
= zvni_map_to_svi(zl2_info_vni
->access_vlan
,
5109 zif
->brslave_info
.br_if
);
5114 /* Add primary SVI MAC-IP */
5115 zebra_evpn_add_macip_for_intf(vlan_if
, zevpn
);
5117 /* Del primary SVI MAC-IP */
5118 zebra_evpn_del_macip_for_intf(vlan_if
, zevpn
);
5127 * Handle message from client to enable/disable advertisement of g/w macip
5130 void zebra_vxlan_advertise_subnet(ZAPI_HANDLER_ARGS
)
5135 struct zebra_evpn
*zevpn
= NULL
;
5136 struct interface
*ifp
= NULL
;
5137 struct zebra_if
*zif
= NULL
;
5138 struct interface
*vlan_if
= NULL
;
5139 struct zebra_vxlan_vni
*zl2_info_vni
= NULL
;
5141 if (!EVPN_ENABLED(zvrf
)) {
5142 zlog_debug("EVPN GW-MACIP Adv for non-EVPN VRF %u",
5148 STREAM_GETC(s
, advertise
);
5149 STREAM_GET(&vni
, s
, 3);
5151 zevpn
= zebra_evpn_lookup(vni
);
5155 if (zevpn
->advertise_subnet
== advertise
)
5158 if (IS_ZEBRA_DEBUG_VXLAN
)
5159 zlog_debug("EVPN subnet Adv %s on VNI %d, currently %s",
5160 advertise
? "enabled" : "disabled", vni
,
5161 zevpn
->advertise_subnet
? "enabled" : "disabled");
5164 zevpn
->advertise_subnet
= advertise
;
5166 ifp
= zevpn
->vxlan_if
;
5172 /* If down or not mapped to a bridge, we're done. */
5173 if (!if_is_operative(ifp
) || !zif
->brslave_info
.br_if
)
5176 zl2_info_vni
= zebra_vxlan_if_vni_find(zif
, vni
);
5180 vlan_if
= zvni_map_to_svi(zl2_info_vni
->access_vlan
,
5181 zif
->brslave_info
.br_if
);
5185 if (zevpn
->advertise_subnet
)
5186 zebra_evpn_advertise_subnet(zevpn
, vlan_if
, 1);
5188 zebra_evpn_advertise_subnet(zevpn
, vlan_if
, 0);
5195 * Handle message from client to enable/disable advertisement of g/w macip
5198 void zebra_vxlan_advertise_gw_macip(ZAPI_HANDLER_ARGS
)
5203 struct zebra_evpn
*zevpn
= NULL
;
5204 struct interface
*ifp
= NULL
;
5206 if (!EVPN_ENABLED(zvrf
)) {
5207 zlog_debug("EVPN GW-MACIP Adv for non-EVPN VRF %u",
5213 STREAM_GETC(s
, advertise
);
5214 STREAM_GETL(s
, vni
);
5217 if (IS_ZEBRA_DEBUG_VXLAN
)
5218 zlog_debug("EVPN gateway macip Adv %s, currently %s",
5219 advertise
? "enabled" : "disabled",
5220 advertise_gw_macip_enabled(NULL
)
5224 if (zvrf
->advertise_gw_macip
== advertise
)
5227 zvrf
->advertise_gw_macip
= advertise
;
5229 if (advertise_gw_macip_enabled(zevpn
))
5230 hash_iterate(zvrf
->evpn_table
,
5231 zebra_evpn_gw_macip_add_for_evpn_hash
,
5234 hash_iterate(zvrf
->evpn_table
,
5235 zebra_evpn_gw_macip_del_for_evpn_hash
,
5239 struct zebra_if
*zif
= NULL
;
5240 struct interface
*vlan_if
= NULL
;
5241 struct interface
*vrr_if
= NULL
;
5242 struct zebra_vxlan_vni
*zl2_info_vni
= NULL
;
5245 zevpn
= zebra_evpn_lookup(vni
);
5249 if (IS_ZEBRA_DEBUG_VXLAN
)
5251 "EVPN gateway macip Adv %s on VNI %d, currently %s",
5252 advertise
? "enabled" : "disabled", vni
,
5253 advertise_gw_macip_enabled(zevpn
) ? "enabled"
5256 old_advertise
= advertise_gw_macip_enabled(zevpn
);
5258 zevpn
->advertise_gw_macip
= advertise
;
5259 if (advertise_gw_macip_enabled(zevpn
) == old_advertise
)
5262 ifp
= zevpn
->vxlan_if
;
5268 /* If down or not mapped to a bridge, we're done. */
5269 if (!if_is_operative(ifp
) || !zif
->brslave_info
.br_if
)
5272 zl2_info_vni
= zebra_vxlan_if_vni_find(zif
, vni
);
5276 vlan_if
= zvni_map_to_svi(zl2_info_vni
->access_vlan
,
5277 zif
->brslave_info
.br_if
);
5281 if (advertise_gw_macip_enabled(zevpn
)) {
5282 /* Add primary SVI MAC-IP */
5283 zebra_evpn_add_macip_for_intf(vlan_if
, zevpn
);
5285 /* Add VRR MAC-IP - if any*/
5286 vrr_if
= zebra_get_vrr_intf_for_svi(vlan_if
);
5288 zebra_evpn_add_macip_for_intf(vrr_if
, zevpn
);
5290 /* Del primary MAC-IP */
5291 zebra_evpn_del_macip_for_intf(vlan_if
, zevpn
);
5293 /* Del VRR MAC-IP - if any*/
5294 vrr_if
= zebra_get_vrr_intf_for_svi(vlan_if
);
5296 zebra_evpn_del_macip_for_intf(vrr_if
, zevpn
);
5304 static int macfdb_read_ns(struct ns
*ns
,
5305 void *_in_param
__attribute__((unused
)),
5306 void **out_param
__attribute__((unused
)))
5308 struct zebra_ns
*zns
= ns
->info
;
5311 return NS_WALK_CONTINUE
;
5314 static int neigh_read_ns(struct ns
*ns
,
5315 void *_in_param
__attribute__((unused
)),
5316 void **out_param
__attribute__((unused
)))
5318 struct zebra_ns
*zns
= ns
->info
;
5321 return NS_WALK_CONTINUE
;
5325 * Handle message from client to learn (or stop learning) about VNIs and MACs.
5326 * When enabled, the VNI hash table will be built and MAC FDB table read;
5327 * when disabled, the entries should be deleted and remote VTEPs and MACs
5328 * uninstalled from the kernel.
5329 * This also informs the setting for BUM handling at the time this change
5330 * occurs; it is relevant only when specifying "learn".
5332 void zebra_vxlan_advertise_all_vni(ZAPI_HANDLER_ARGS
)
5334 struct stream
*s
= NULL
;
5336 enum vxlan_flood_control flood_ctrl
;
5338 /* Mismatch between EVPN VRF and current VRF (should be prevented by
5340 if (is_evpn_enabled() && !EVPN_ENABLED(zvrf
))
5344 STREAM_GETC(s
, advertise
);
5345 STREAM_GETC(s
, flood_ctrl
);
5347 if (IS_ZEBRA_DEBUG_VXLAN
)
5348 zlog_debug("EVPN VRF %s(%u) VNI Adv %s, currently %s, flood control %u",
5349 zvrf_name(zvrf
), zvrf_id(zvrf
),
5350 advertise
? "enabled" : "disabled",
5351 is_evpn_enabled() ? "enabled" : "disabled",
5354 if (zvrf
->advertise_all_vni
== advertise
)
5357 zvrf
->advertise_all_vni
= advertise
;
5358 if (EVPN_ENABLED(zvrf
)) {
5359 zrouter
.evpn_vrf
= zvrf
;
5361 /* Note BUM handling */
5362 zvrf
->vxlan_flood_ctrl
= flood_ctrl
;
5364 /* Replay all ESs */
5365 zebra_evpn_es_send_all_to_client(true /* add */);
5367 /* Build EVPN hash table and inform BGP. */
5368 zevpn_build_hash_table();
5370 /* Add all SVI (L3 GW) MACs to BGP*/
5371 hash_iterate(zvrf
->evpn_table
,
5372 zebra_evpn_gw_macip_add_for_evpn_hash
, NULL
);
5374 /* Read the MAC FDB */
5375 ns_walk_func(macfdb_read_ns
, NULL
, NULL
);
5377 /* Read neighbors */
5378 ns_walk_func(neigh_read_ns
, NULL
, NULL
);
5380 /* Cleanup VTEPs for all EVPNs - uninstall from
5381 * kernel and free entries.
5383 hash_iterate(zvrf
->evpn_table
, zebra_evpn_vxlan_cleanup_all
,
5386 /* Delete all ESs in BGP */
5387 zebra_evpn_es_send_all_to_client(false /* add */);
5389 /* cleanup all l3vnis */
5390 hash_iterate(zrouter
.l3vni_table
, zl3vni_cleanup_all
, NULL
);
5392 /* Mark as "no EVPN VRF" */
5393 zrouter
.evpn_vrf
= NULL
;
5401 * Allocate EVPN hash table for this VRF and do other initialization.
5402 * NOTE: Currently supported only for default VRF.
5404 void zebra_vxlan_init_tables(struct zebra_vrf
*zvrf
)
5411 snprintf(buffer
, sizeof(buffer
), "Zebra VRF EVPN Table: %s",
5413 zvrf
->evpn_table
= hash_create_size(8, zebra_evpn_hash_keymake
,
5414 zebra_evpn_hash_cmp
, buffer
);
5416 snprintf(buffer
, sizeof(buffer
), "Zebra VxLAN SG Table: %s",
5418 zvrf
->vxlan_sg_table
= hash_create_size(8, zebra_vxlan_sg_hash_key_make
,
5419 zebra_vxlan_sg_hash_eq
, buffer
);
5422 /* Cleanup EVPN info, but don't free the table. */
5423 void zebra_vxlan_cleanup_tables(struct zebra_vrf
*zvrf
)
5425 struct zebra_vrf
*evpn_zvrf
= zebra_vrf_get_evpn();
5427 hash_iterate(zvrf
->evpn_table
, zebra_evpn_vxlan_cleanup_all
, zvrf
);
5428 zebra_vxlan_cleanup_sg_table(zvrf
);
5430 if (zvrf
== evpn_zvrf
)
5431 zebra_evpn_es_cleanup();
5434 /* Close all EVPN handling */
5435 void zebra_vxlan_close_tables(struct zebra_vrf
*zvrf
)
5439 hash_iterate(zvrf
->evpn_table
, zebra_evpn_vxlan_cleanup_all
, zvrf
);
5440 hash_free(zvrf
->evpn_table
);
5441 if (zvrf
->vxlan_sg_table
) {
5442 zebra_vxlan_cleanup_sg_table(zvrf
);
5443 hash_free(zvrf
->vxlan_sg_table
);
5444 zvrf
->vxlan_sg_table
= NULL
;
5448 /* init the l3vni table */
5449 void zebra_vxlan_init(void)
5451 zrouter
.l3vni_table
= hash_create(l3vni_hash_keymake
, l3vni_hash_cmp
,
5452 "Zebra VRF L3 VNI table");
5453 zrouter
.evpn_vrf
= NULL
;
5454 zebra_evpn_mh_init();
5457 /* free l3vni table */
5458 void zebra_vxlan_disable(void)
5460 hash_free(zrouter
.l3vni_table
);
5461 zebra_evpn_mh_terminate();
5464 /* get the l3vni svi ifindex */
5465 ifindex_t
get_l3vni_svi_ifindex(vrf_id_t vrf_id
)
5467 struct zebra_l3vni
*zl3vni
= NULL
;
5469 zl3vni
= zl3vni_from_vrf(vrf_id
);
5470 if (!zl3vni
|| !is_l3vni_oper_up(zl3vni
))
5473 return zl3vni
->svi_if
->ifindex
;
5476 /************************** vxlan SG cache management ************************/
5477 /* Inform PIM about the mcast group */
5478 static int zebra_vxlan_sg_send(struct zebra_vrf
*zvrf
,
5479 struct prefix_sg
*sg
,
5480 char *sg_str
, uint16_t cmd
)
5482 struct zserv
*client
= NULL
;
5483 struct stream
*s
= NULL
;
5485 client
= zserv_find_client(ZEBRA_ROUTE_PIM
, 0);
5489 if (!CHECK_FLAG(zvrf
->flags
, ZEBRA_PIM_SEND_VXLAN_SG
))
5492 s
= stream_new(ZEBRA_MAX_PACKET_SIZ
);
5494 zclient_create_header(s
, cmd
, VRF_DEFAULT
);
5495 stream_putl(s
, IPV4_MAX_BYTELEN
);
5496 stream_put(s
, &sg
->src
.s_addr
, IPV4_MAX_BYTELEN
);
5497 stream_put(s
, &sg
->grp
.s_addr
, IPV4_MAX_BYTELEN
);
5499 /* Write packet size. */
5500 stream_putw_at(s
, 0, stream_get_endp(s
));
5502 if (IS_ZEBRA_DEBUG_VXLAN
)
5505 (cmd
== ZEBRA_VXLAN_SG_ADD
) ? "add" : "del", sg_str
,
5506 zebra_route_string(client
->proto
));
5508 if (cmd
== ZEBRA_VXLAN_SG_ADD
)
5509 client
->vxlan_sg_add_cnt
++;
5511 client
->vxlan_sg_del_cnt
++;
5513 return zserv_send_message(client
, s
);
5516 static unsigned int zebra_vxlan_sg_hash_key_make(const void *p
)
5518 const struct zebra_vxlan_sg
*vxlan_sg
= p
;
5520 return (jhash_2words(vxlan_sg
->sg
.src
.s_addr
,
5521 vxlan_sg
->sg
.grp
.s_addr
, 0));
5524 static bool zebra_vxlan_sg_hash_eq(const void *p1
, const void *p2
)
5526 const struct zebra_vxlan_sg
*sg1
= p1
;
5527 const struct zebra_vxlan_sg
*sg2
= p2
;
5529 return ((sg1
->sg
.src
.s_addr
== sg2
->sg
.src
.s_addr
)
5530 && (sg1
->sg
.grp
.s_addr
== sg2
->sg
.grp
.s_addr
));
5533 static struct zebra_vxlan_sg
*zebra_vxlan_sg_new(struct zebra_vrf
*zvrf
,
5534 struct prefix_sg
*sg
)
5536 struct zebra_vxlan_sg
*vxlan_sg
;
5538 vxlan_sg
= XCALLOC(MTYPE_ZVXLAN_SG
, sizeof(*vxlan_sg
));
5540 vxlan_sg
->zvrf
= zvrf
;
5542 prefix_sg2str(sg
, vxlan_sg
->sg_str
);
5544 vxlan_sg
= hash_get(zvrf
->vxlan_sg_table
, vxlan_sg
, hash_alloc_intern
);
5546 if (IS_ZEBRA_DEBUG_VXLAN
)
5547 zlog_debug("vxlan SG %s created", vxlan_sg
->sg_str
);
5552 static struct zebra_vxlan_sg
*zebra_vxlan_sg_find(struct zebra_vrf
*zvrf
,
5553 struct prefix_sg
*sg
)
5555 struct zebra_vxlan_sg lookup
;
5558 return hash_lookup(zvrf
->vxlan_sg_table
, &lookup
);
5561 static struct zebra_vxlan_sg
*zebra_vxlan_sg_add(struct zebra_vrf
*zvrf
,
5562 struct prefix_sg
*sg
)
5564 struct zebra_vxlan_sg
*vxlan_sg
;
5565 struct zebra_vxlan_sg
*parent
= NULL
;
5568 vxlan_sg
= zebra_vxlan_sg_find(zvrf
, sg
);
5572 /* create a *G entry for every BUM group implicitly -
5573 * 1. The SG entry is used by pimd to setup the vxlan-origination-mroute
5574 * 2. the XG entry is used by pimd to setup the
5575 * vxlan-termination-mroute
5577 if (sg
->src
.s_addr
!= INADDR_ANY
) {
5578 memset(&sip
, 0, sizeof(sip
));
5579 parent
= zebra_vxlan_sg_do_ref(zvrf
, sip
, sg
->grp
);
5584 vxlan_sg
= zebra_vxlan_sg_new(zvrf
, sg
);
5586 zebra_vxlan_sg_send(zvrf
, sg
, vxlan_sg
->sg_str
,
5587 ZEBRA_VXLAN_SG_ADD
);
5592 static void zebra_vxlan_sg_del(struct zebra_vxlan_sg
*vxlan_sg
)
5595 struct zebra_vrf
*zvrf
;
5597 zvrf
= vrf_info_lookup(VRF_DEFAULT
);
5601 /* On SG entry deletion remove the reference to its parent XG
5604 if (vxlan_sg
->sg
.src
.s_addr
!= INADDR_ANY
) {
5605 memset(&sip
, 0, sizeof(sip
));
5606 zebra_vxlan_sg_do_deref(zvrf
, sip
, vxlan_sg
->sg
.grp
);
5609 zebra_vxlan_sg_send(zvrf
, &vxlan_sg
->sg
,
5610 vxlan_sg
->sg_str
, ZEBRA_VXLAN_SG_DEL
);
5612 hash_release(vxlan_sg
->zvrf
->vxlan_sg_table
, vxlan_sg
);
5614 if (IS_ZEBRA_DEBUG_VXLAN
)
5615 zlog_debug("VXLAN SG %s deleted", vxlan_sg
->sg_str
);
5617 XFREE(MTYPE_ZVXLAN_SG
, vxlan_sg
);
5620 static void zebra_vxlan_sg_do_deref(struct zebra_vrf
*zvrf
,
5621 struct in_addr sip
, struct in_addr mcast_grp
)
5623 struct zebra_vxlan_sg
*vxlan_sg
;
5624 struct prefix_sg sg
;
5626 sg
.family
= AF_INET
;
5627 sg
.prefixlen
= IPV4_MAX_BYTELEN
;
5630 vxlan_sg
= zebra_vxlan_sg_find(zvrf
, &sg
);
5634 if (vxlan_sg
->ref_cnt
)
5635 --vxlan_sg
->ref_cnt
;
5637 if (!vxlan_sg
->ref_cnt
)
5638 zebra_vxlan_sg_del(vxlan_sg
);
5641 static struct zebra_vxlan_sg
*zebra_vxlan_sg_do_ref(struct zebra_vrf
*zvrf
,
5643 struct in_addr mcast_grp
)
5645 struct zebra_vxlan_sg
*vxlan_sg
;
5646 struct prefix_sg sg
;
5648 sg
.family
= AF_INET
;
5649 sg
.prefixlen
= IPV4_MAX_BYTELEN
;
5652 vxlan_sg
= zebra_vxlan_sg_add(zvrf
, &sg
);
5654 ++vxlan_sg
->ref_cnt
;
5659 void zebra_vxlan_sg_deref(struct in_addr local_vtep_ip
,
5660 struct in_addr mcast_grp
)
5662 struct zebra_vrf
*zvrf
;
5664 if (local_vtep_ip
.s_addr
== INADDR_ANY
5665 || mcast_grp
.s_addr
== INADDR_ANY
)
5668 zvrf
= vrf_info_lookup(VRF_DEFAULT
);
5672 zebra_vxlan_sg_do_deref(zvrf
, local_vtep_ip
, mcast_grp
);
5675 void zebra_vxlan_sg_ref(struct in_addr local_vtep_ip
, struct in_addr mcast_grp
)
5677 struct zebra_vrf
*zvrf
;
5679 if (local_vtep_ip
.s_addr
== INADDR_ANY
5680 || mcast_grp
.s_addr
== INADDR_ANY
)
5683 zvrf
= vrf_info_lookup(VRF_DEFAULT
);
5686 zebra_vxlan_sg_do_ref(zvrf
, local_vtep_ip
, mcast_grp
);
5689 static void zebra_vxlan_xg_pre_cleanup(struct hash_bucket
*bucket
, void *arg
)
5691 struct zebra_vxlan_sg
*vxlan_sg
= (struct zebra_vxlan_sg
*)bucket
->data
;
5693 /* increment the ref count against (*,G) to prevent them from being
5696 if (vxlan_sg
->sg
.src
.s_addr
== INADDR_ANY
)
5697 ++vxlan_sg
->ref_cnt
;
5700 static void zebra_vxlan_xg_post_cleanup(struct hash_bucket
*bucket
, void *arg
)
5702 struct zebra_vxlan_sg
*vxlan_sg
= (struct zebra_vxlan_sg
*)bucket
->data
;
5704 /* decrement the dummy ref count against (*,G) to delete them */
5705 if (vxlan_sg
->sg
.src
.s_addr
== INADDR_ANY
) {
5706 if (vxlan_sg
->ref_cnt
)
5707 --vxlan_sg
->ref_cnt
;
5708 if (!vxlan_sg
->ref_cnt
)
5709 zebra_vxlan_sg_del(vxlan_sg
);
5713 static void zebra_vxlan_sg_cleanup(struct hash_bucket
*bucket
, void *arg
)
5715 struct zebra_vxlan_sg
*vxlan_sg
= (struct zebra_vxlan_sg
*)bucket
->data
;
5717 zebra_vxlan_sg_del(vxlan_sg
);
5720 static void zebra_vxlan_cleanup_sg_table(struct zebra_vrf
*zvrf
)
5722 /* increment the ref count against (*,G) to prevent them from being
5725 hash_iterate(zvrf
->vxlan_sg_table
, zebra_vxlan_xg_pre_cleanup
, NULL
);
5727 hash_iterate(zvrf
->vxlan_sg_table
, zebra_vxlan_sg_cleanup
, NULL
);
5729 /* decrement the dummy ref count against the XG entries */
5730 hash_iterate(zvrf
->vxlan_sg_table
, zebra_vxlan_xg_post_cleanup
, NULL
);
5733 static void zebra_vxlan_sg_replay_send(struct hash_bucket
*bucket
, void *arg
)
5735 struct zebra_vxlan_sg
*vxlan_sg
= (struct zebra_vxlan_sg
*)bucket
->data
;
5737 zebra_vxlan_sg_send(vxlan_sg
->zvrf
, &vxlan_sg
->sg
,
5738 vxlan_sg
->sg_str
, ZEBRA_VXLAN_SG_ADD
);
5741 /* Handle message from client to replay vxlan SG entries */
5742 void zebra_vxlan_sg_replay(ZAPI_HANDLER_ARGS
)
5744 if (IS_ZEBRA_DEBUG_VXLAN
)
5745 zlog_debug("VxLAN SG updates to PIM, start");
5747 SET_FLAG(zvrf
->flags
, ZEBRA_PIM_SEND_VXLAN_SG
);
5749 if (!EVPN_ENABLED(zvrf
)) {
5750 if (IS_ZEBRA_DEBUG_VXLAN
)
5751 zlog_debug("VxLAN SG replay request on unexpected vrf %d",
5756 hash_iterate(zvrf
->vxlan_sg_table
, zebra_vxlan_sg_replay_send
, NULL
);
5760 /* Cleanup EVPN configuration of a specific VRF */
5761 static void zebra_evpn_vrf_cfg_cleanup(struct zebra_vrf
*zvrf
)
5763 struct zebra_l3vni
*zl3vni
= NULL
;
5765 zvrf
->advertise_all_vni
= 0;
5766 zvrf
->advertise_gw_macip
= 0;
5767 zvrf
->advertise_svi_macip
= 0;
5768 zvrf
->vxlan_flood_ctrl
= VXLAN_FLOOD_HEAD_END_REPL
;
5770 hash_iterate(zvrf
->evpn_table
, zebra_evpn_cfg_cleanup
, NULL
);
5773 zl3vni
= zl3vni_lookup(zvrf
->l3vni
);
5775 /* delete and uninstall all rmacs */
5776 hash_iterate(zl3vni
->rmac_table
, zl3vni_del_rmac_hash_entry
,
5778 /* delete and uninstall all next-hops */
5779 hash_iterate(zl3vni
->nh_table
, zl3vni_del_nh_hash_entry
,
5784 /* Cleanup BGP EVPN configuration upon client disconnect */
5785 static int zebra_evpn_bgp_cfg_clean_up(struct zserv
*client
)
5788 struct zebra_vrf
*zvrf
;
5790 RB_FOREACH (vrf
, vrf_id_head
, &vrfs_by_id
) {
5793 zebra_evpn_vrf_cfg_cleanup(zvrf
);
5799 static int zebra_evpn_pim_cfg_clean_up(struct zserv
*client
)
5801 struct zebra_vrf
*zvrf
= zebra_vrf_get_evpn();
5803 if (CHECK_FLAG(zvrf
->flags
, ZEBRA_PIM_SEND_VXLAN_SG
)) {
5804 if (IS_ZEBRA_DEBUG_VXLAN
)
5805 zlog_debug("VxLAN SG updates to PIM, stop");
5806 UNSET_FLAG(zvrf
->flags
, ZEBRA_PIM_SEND_VXLAN_SG
);
5812 static int zebra_evpn_cfg_clean_up(struct zserv
*client
)
5814 if (client
->proto
== ZEBRA_ROUTE_BGP
)
5815 return zebra_evpn_bgp_cfg_clean_up(client
);
5817 if (client
->proto
== ZEBRA_ROUTE_PIM
)
5818 return zebra_evpn_pim_cfg_clean_up(client
);
5824 * Handle results for vxlan dataplane operations.
5826 extern void zebra_vxlan_handle_result(struct zebra_dplane_ctx
*ctx
)
5831 /* Config knob for accepting lower sequence numbers */
5832 void zebra_vxlan_set_accept_bgp_seq(bool set
)
5834 accept_bgp_seq
= set
;
5837 bool zebra_vxlan_get_accept_bgp_seq(void)
5839 return accept_bgp_seq
;
5842 /* Cleanup BGP EVPN configuration upon client disconnect */
5843 extern void zebra_evpn_init(void)
5845 hook_register(zserv_client_close
, zebra_evpn_cfg_clean_up
);