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 static 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_hash_table_zns(struct ns
*ns
,
921 void *param_in
__attribute__((unused
)),
922 void **param_out
__attribute__((unused
)))
924 struct zebra_ns
*zns
= ns
->info
;
925 struct route_node
*rn
;
926 struct interface
*ifp
;
927 struct zebra_vrf
*zvrf
;
929 zvrf
= zebra_vrf_get_evpn();
931 /* Walk VxLAN interfaces and create EVPN hash. */
932 for (rn
= route_top(zns
->if_table
); rn
; rn
= route_next(rn
)) {
934 struct zebra_evpn
*zevpn
= NULL
;
935 struct zebra_l3vni
*zl3vni
= NULL
;
936 struct zebra_if
*zif
;
937 struct zebra_l2info_vxlan
*vxl
;
938 struct zebra_vxlan_vni
*vnip
;
940 ifp
= (struct interface
*)rn
->info
;
944 if (!zif
|| zif
->zif_type
!= ZEBRA_IF_VXLAN
)
947 vxl
= &zif
->l2info
.vxl
;
948 vnip
= zebra_vxlan_if_vni_find(zif
, 0);
950 /* link of VXLAN interface should be in zebra_evpn_vrf */
951 if (zvrf
->zns
->ns_id
!= vxl
->link_nsid
) {
952 if (IS_ZEBRA_DEBUG_VXLAN
)
954 "Intf %s(%u) VNI %u, link not in same "
955 "namespace than BGP EVPN core instance ",
956 ifp
->name
, ifp
->ifindex
, vni
);
959 /* L3-VNI and L2-VNI are handled seperately */
960 zl3vni
= zl3vni_lookup(vni
);
963 if (IS_ZEBRA_DEBUG_VXLAN
)
965 "create L3-VNI hash for Intf %s(%u) L3-VNI %u",
966 ifp
->name
, ifp
->ifindex
, vni
);
968 /* associate with vxlan_if */
969 zl3vni
->local_vtep_ip
= vxl
->vtep_ip
;
970 zl3vni
->vxlan_if
= ifp
;
973 * we need to associate with SVI.
974 * we can associate with svi-if only after association
975 * with vxlan-intf is complete
977 zl3vni
->svi_if
= zl3vni_map_to_svi_if(zl3vni
);
979 /* Associate l3vni to mac-vlan and extract VRR MAC */
980 zl3vni
->mac_vlan_if
= zl3vni_map_to_mac_vlan_if(zl3vni
);
982 if (IS_ZEBRA_DEBUG_VXLAN
)
983 zlog_debug("create l3vni %u svi_if %s mac_vlan_if %s",
984 vni
, zl3vni
->svi_if
? zl3vni
->svi_if
->name
986 zl3vni
->mac_vlan_if
?
987 zl3vni
->mac_vlan_if
->name
: "NIL");
989 if (is_l3vni_oper_up(zl3vni
))
990 zebra_vxlan_process_l3vni_oper_up(zl3vni
);
993 struct interface
*vlan_if
= NULL
;
995 if (IS_ZEBRA_DEBUG_VXLAN
)
997 "Create L2-VNI hash for intf %s(%u) L2-VNI %u local IP %pI4",
998 ifp
->name
, ifp
->ifindex
, vni
,
1001 /* EVPN hash entry is expected to exist, if the BGP process is killed */
1002 zevpn
= zebra_evpn_lookup(vni
);
1005 "EVPN hash already present for IF %s(%u) L2-VNI %u",
1006 ifp
->name
, ifp
->ifindex
, vni
);
1009 * Inform BGP if intf is up and mapped to
1012 if (if_is_operative(ifp
) &&
1013 zif
->brslave_info
.br_if
)
1014 zebra_evpn_send_add_to_client(zevpn
);
1016 /* Send Local MAC-entries to client */
1017 zebra_evpn_send_mac_list_to_client(zevpn
);
1019 /* Send Loval Neighbor entries to client */
1020 zebra_evpn_send_neigh_to_client(zevpn
);
1022 zevpn
= zebra_evpn_add(vni
);
1025 "Failed to add EVPN hash, IF %s(%u) L2-VNI %u",
1026 ifp
->name
, ifp
->ifindex
, vni
);
1027 return NS_WALK_CONTINUE
;
1030 if (zevpn
->local_vtep_ip
.s_addr
1031 != vxl
->vtep_ip
.s_addr
1032 || zevpn
->mcast_grp
.s_addr
1033 != vnip
->mcast_grp
.s_addr
) {
1034 zebra_vxlan_sg_deref(
1035 zevpn
->local_vtep_ip
,
1037 zebra_vxlan_sg_ref(vxl
->vtep_ip
,
1039 zevpn
->local_vtep_ip
= vxl
->vtep_ip
;
1040 zevpn
->mcast_grp
= vnip
->mcast_grp
;
1041 /* on local vtep-ip check if ES
1042 * orig-ip needs to be updated
1044 zebra_evpn_es_set_base_evpn(zevpn
);
1046 zevpn_vxlan_if_set(zevpn
, ifp
, true /* set */);
1047 vlan_if
= zvni_map_to_svi(
1049 zif
->brslave_info
.br_if
);
1051 zevpn
->svi_if
= vlan_if
;
1052 zevpn
->vrf_id
= vlan_if
->vrf
->vrf_id
;
1053 zl3vni
= zl3vni_from_vrf(
1054 vlan_if
->vrf
->vrf_id
);
1057 zl3vni
->l2vnis
, zevpn
);
1061 * Inform BGP if intf is up and mapped to
1064 if (if_is_operative(ifp
) &&
1065 zif
->brslave_info
.br_if
)
1066 zebra_evpn_send_add_to_client(zevpn
);
1070 return NS_WALK_CONTINUE
;
1074 * Build the VNI hash table by going over the VxLAN interfaces. This
1075 * is called when EVPN (advertise-all-vni) is enabled.
1078 static void zevpn_build_hash_table(void)
1080 ns_walk_func(zevpn_build_hash_table_zns
, NULL
, NULL
);
1084 * Cleanup EVPN/VTEP and update kernel
1086 static void zebra_evpn_vxlan_cleanup_all(struct hash_bucket
*bucket
, void *arg
)
1088 struct zebra_evpn
*zevpn
= NULL
;
1089 struct zebra_l3vni
*zl3vni
= NULL
;
1091 zevpn
= (struct zebra_evpn
*)bucket
->data
;
1093 /* remove l2vni from l2vni's tenant-vrf l3-vni list */
1094 zl3vni
= zl3vni_from_vrf(zevpn
->vrf_id
);
1096 listnode_delete(zl3vni
->l2vnis
, zevpn
);
1098 zebra_evpn_cleanup_all(bucket
, arg
);
1102 static void zl3vni_cleanup_all(struct hash_bucket
*bucket
, void *args
)
1104 struct zebra_l3vni
*zl3vni
= NULL
;
1106 zl3vni
= (struct zebra_l3vni
*)bucket
->data
;
1108 zebra_vxlan_process_l3vni_oper_down(zl3vni
);
1111 static void rb_find_or_add_host(struct host_rb_tree_entry
*hrbe
,
1112 const struct prefix
*host
)
1114 struct host_rb_entry lookup
;
1115 struct host_rb_entry
*hle
;
1117 memset(&lookup
, 0, sizeof(lookup
));
1118 memcpy(&lookup
.p
, host
, sizeof(*host
));
1120 hle
= RB_FIND(host_rb_tree_entry
, hrbe
, &lookup
);
1124 hle
= XCALLOC(MTYPE_HOST_PREFIX
, sizeof(struct host_rb_entry
));
1125 memcpy(hle
, &lookup
, sizeof(lookup
));
1127 RB_INSERT(host_rb_tree_entry
, hrbe
, hle
);
1130 static void rb_delete_host(struct host_rb_tree_entry
*hrbe
, struct prefix
*host
)
1132 struct host_rb_entry lookup
;
1133 struct host_rb_entry
*hle
;
1135 memset(&lookup
, 0, sizeof(lookup
));
1136 memcpy(&lookup
.p
, host
, sizeof(*host
));
1138 hle
= RB_FIND(host_rb_tree_entry
, hrbe
, &lookup
);
1140 RB_REMOVE(host_rb_tree_entry
, hrbe
, hle
);
1141 XFREE(MTYPE_HOST_PREFIX
, hle
);
1148 * Look up MAC hash entry.
1150 static struct zebra_mac
*zl3vni_rmac_lookup(struct zebra_l3vni
*zl3vni
,
1151 const struct ethaddr
*rmac
)
1153 struct zebra_mac tmp
;
1154 struct zebra_mac
*pmac
;
1156 memset(&tmp
, 0, sizeof(tmp
));
1157 memcpy(&tmp
.macaddr
, rmac
, ETH_ALEN
);
1158 pmac
= hash_lookup(zl3vni
->rmac_table
, &tmp
);
1164 * Callback to allocate RMAC hash entry.
1166 static void *zl3vni_rmac_alloc(void *p
)
1168 const struct zebra_mac
*tmp_rmac
= p
;
1169 struct zebra_mac
*zrmac
;
1171 zrmac
= XCALLOC(MTYPE_L3VNI_MAC
, sizeof(struct zebra_mac
));
1174 return ((void *)zrmac
);
1178 * Add RMAC entry to l3-vni
1180 static struct zebra_mac
*zl3vni_rmac_add(struct zebra_l3vni
*zl3vni
,
1181 const struct ethaddr
*rmac
)
1183 struct zebra_mac tmp_rmac
;
1184 struct zebra_mac
*zrmac
= NULL
;
1186 memset(&tmp_rmac
, 0, sizeof(tmp_rmac
));
1187 memcpy(&tmp_rmac
.macaddr
, rmac
, ETH_ALEN
);
1188 zrmac
= hash_get(zl3vni
->rmac_table
, &tmp_rmac
, zl3vni_rmac_alloc
);
1189 zrmac
->nh_list
= list_new();
1190 zrmac
->nh_list
->cmp
= (int (*)(void *, void *))l3vni_rmac_nh_list_cmp
;
1191 zrmac
->nh_list
->del
= (void (*)(void *))l3vni_rmac_nh_free
;
1193 SET_FLAG(zrmac
->flags
, ZEBRA_MAC_REMOTE
);
1194 SET_FLAG(zrmac
->flags
, ZEBRA_MAC_REMOTE_RMAC
);
1202 static int zl3vni_rmac_del(struct zebra_l3vni
*zl3vni
, struct zebra_mac
*zrmac
)
1204 struct zebra_mac
*tmp_rmac
;
1206 /* free the list of nh list*/
1207 list_delete(&zrmac
->nh_list
);
1209 tmp_rmac
= hash_release(zl3vni
->rmac_table
, zrmac
);
1210 XFREE(MTYPE_L3VNI_MAC
, tmp_rmac
);
1216 * Install remote RMAC into the forwarding plane.
1218 static int zl3vni_rmac_install(struct zebra_l3vni
*zl3vni
,
1219 struct zebra_mac
*zrmac
)
1221 const struct zebra_if
*zif
= NULL
, *br_zif
= NULL
;
1222 const struct zebra_vxlan_vni
*vni
;
1223 const struct interface
*br_ifp
;
1224 enum zebra_dplane_result res
;
1227 if (!(CHECK_FLAG(zrmac
->flags
, ZEBRA_MAC_REMOTE
))
1228 || !(CHECK_FLAG(zrmac
->flags
, ZEBRA_MAC_REMOTE_RMAC
)))
1231 zif
= zl3vni
->vxlan_if
->info
;
1235 br_ifp
= zif
->brslave_info
.br_if
;
1239 vni
= zebra_vxlan_if_vni_find(zif
, zl3vni
->vni
);
1241 br_zif
= (const struct zebra_if
*)br_ifp
->info
;
1243 if (IS_ZEBRA_IF_BRIDGE_VLAN_AWARE(br_zif
))
1244 vid
= vni
->access_vlan
;
1248 res
= dplane_rem_mac_add(zl3vni
->vxlan_if
, br_ifp
, vid
, &zrmac
->macaddr
,
1249 vni
->vni
, zrmac
->fwd_info
.r_vtep_ip
, 0, 0,
1250 false /*was_static*/);
1251 if (res
!= ZEBRA_DPLANE_REQUEST_FAILURE
)
1258 * Uninstall remote RMAC from the forwarding plane.
1260 static int zl3vni_rmac_uninstall(struct zebra_l3vni
*zl3vni
,
1261 struct zebra_mac
*zrmac
)
1263 const struct zebra_if
*zif
= NULL
, *br_zif
;
1264 const struct zebra_vxlan_vni
*vni
;
1265 const struct interface
*br_ifp
;
1267 enum zebra_dplane_result res
;
1269 if (!(CHECK_FLAG(zrmac
->flags
, ZEBRA_MAC_REMOTE
))
1270 || !(CHECK_FLAG(zrmac
->flags
, ZEBRA_MAC_REMOTE_RMAC
)))
1273 if (!zl3vni
->vxlan_if
) {
1274 if (IS_ZEBRA_DEBUG_VXLAN
)
1276 "RMAC %pEA on L3-VNI %u hash %p couldn't be uninstalled - no vxlan_if",
1277 &zrmac
->macaddr
, zl3vni
->vni
, zl3vni
);
1281 zif
= zl3vni
->vxlan_if
->info
;
1285 br_ifp
= zif
->brslave_info
.br_if
;
1289 vni
= zebra_vxlan_if_vni_find(zif
, zl3vni
->vni
);
1291 br_zif
= (const struct zebra_if
*)br_ifp
->info
;
1292 if (IS_ZEBRA_IF_BRIDGE_VLAN_AWARE(br_zif
))
1293 vid
= vni
->access_vlan
;
1297 res
= dplane_rem_mac_del(zl3vni
->vxlan_if
, br_ifp
, vid
, &zrmac
->macaddr
,
1298 vni
->vni
, zrmac
->fwd_info
.r_vtep_ip
);
1299 if (res
!= ZEBRA_DPLANE_REQUEST_FAILURE
)
1305 /* handle rmac add */
1306 static int zl3vni_remote_rmac_add(struct zebra_l3vni
*zl3vni
,
1307 const struct ethaddr
*rmac
,
1308 const struct ipaddr
*vtep_ip
)
1310 struct zebra_mac
*zrmac
= NULL
;
1311 struct ipaddr
*vtep
= NULL
;
1313 zrmac
= zl3vni_rmac_lookup(zl3vni
, rmac
);
1316 /* Create the RMAC entry, or update its vtep, if necessary. */
1317 zrmac
= zl3vni_rmac_add(zl3vni
, rmac
);
1320 "Failed to add RMAC %pEA L3VNI %u Remote VTEP %pIA",
1321 rmac
, zl3vni
->vni
, vtep_ip
);
1324 memset(&zrmac
->fwd_info
, 0, sizeof(zrmac
->fwd_info
));
1325 zrmac
->fwd_info
.r_vtep_ip
= vtep_ip
->ipaddr_v4
;
1327 vtep
= XCALLOC(MTYPE_EVPN_VTEP
, sizeof(struct ipaddr
));
1328 memcpy(vtep
, vtep_ip
, sizeof(struct ipaddr
));
1329 if (!listnode_add_sort_nodup(zrmac
->nh_list
, (void *)vtep
))
1330 XFREE(MTYPE_EVPN_VTEP
, vtep
);
1332 /* Send RMAC for FPM processing */
1333 hook_call(zebra_rmac_update
, zrmac
, zl3vni
, false,
1336 /* install rmac in kernel */
1337 zl3vni_rmac_install(zl3vni
, zrmac
);
1338 } else if (!IPV4_ADDR_SAME(&zrmac
->fwd_info
.r_vtep_ip
,
1339 &vtep_ip
->ipaddr_v4
)) {
1340 if (IS_ZEBRA_DEBUG_VXLAN
)
1342 "L3VNI %u Remote VTEP change(%pI4 -> %pIA) for RMAC %pEA",
1343 zl3vni
->vni
, &zrmac
->fwd_info
.r_vtep_ip
,
1346 zrmac
->fwd_info
.r_vtep_ip
= vtep_ip
->ipaddr_v4
;
1348 vtep
= XCALLOC(MTYPE_EVPN_VTEP
, sizeof(struct ipaddr
));
1349 memcpy(vtep
, vtep_ip
, sizeof(struct ipaddr
));
1350 if (!listnode_add_sort_nodup(zrmac
->nh_list
, (void *)vtep
))
1351 XFREE(MTYPE_EVPN_VTEP
, vtep
);
1353 /* install rmac in kernel */
1354 zl3vni_rmac_install(zl3vni
, zrmac
);
1361 /* handle rmac delete */
1362 static void zl3vni_remote_rmac_del(struct zebra_l3vni
*zl3vni
,
1363 struct zebra_mac
*zrmac
,
1364 struct ipaddr
*vtep_ip
)
1366 struct ipaddr ipv4_vtep
;
1368 if (!zl3vni_nh_lookup(zl3vni
, vtep_ip
)) {
1369 memset(&ipv4_vtep
, 0, sizeof(ipv4_vtep
));
1370 ipv4_vtep
.ipa_type
= IPADDR_V4
;
1371 if (vtep_ip
->ipa_type
== IPADDR_V6
)
1372 ipv4_mapped_ipv6_to_ipv4(&vtep_ip
->ipaddr_v6
,
1373 &ipv4_vtep
.ipaddr_v4
);
1375 memcpy(&(ipv4_vtep
.ipaddr_v4
), &vtep_ip
->ipaddr_v4
,
1376 sizeof(struct in_addr
));
1378 /* remove nh from rmac's list */
1379 l3vni_rmac_nh_list_nh_delete(zl3vni
, zrmac
, &ipv4_vtep
);
1380 /* delete nh is same as current selected, fall back to
1381 * one present in the list
1383 if (IPV4_ADDR_SAME(&zrmac
->fwd_info
.r_vtep_ip
,
1384 &ipv4_vtep
.ipaddr_v4
) &&
1385 listcount(zrmac
->nh_list
)) {
1386 struct ipaddr
*vtep
;
1388 vtep
= listgetdata(listhead(zrmac
->nh_list
));
1389 zrmac
->fwd_info
.r_vtep_ip
= vtep
->ipaddr_v4
;
1390 if (IS_ZEBRA_DEBUG_VXLAN
)
1392 "L3VNI %u Remote VTEP nh change(%pIA -> %pI4) for RMAC %pEA",
1393 zl3vni
->vni
, &ipv4_vtep
,
1394 &zrmac
->fwd_info
.r_vtep_ip
,
1397 /* install rmac in kernel */
1398 zl3vni_rmac_install(zl3vni
, zrmac
);
1401 if (!listcount(zrmac
->nh_list
)) {
1402 /* uninstall from kernel */
1403 zl3vni_rmac_uninstall(zl3vni
, zrmac
);
1405 /* Send RMAC for FPM processing */
1406 hook_call(zebra_rmac_update
, zrmac
, zl3vni
, true,
1409 if (IS_ZEBRA_DEBUG_VXLAN
)
1411 "L3VNI %u RMAC %pEA vtep_ip %pIA delete",
1412 zl3vni
->vni
, &zrmac
->macaddr
, vtep_ip
);
1414 /* del the rmac entry */
1415 zl3vni_rmac_del(zl3vni
, zrmac
);
1421 * Look up nh hash entry on a l3-vni.
1423 static struct zebra_neigh
*zl3vni_nh_lookup(struct zebra_l3vni
*zl3vni
,
1424 const struct ipaddr
*ip
)
1426 struct zebra_neigh tmp
;
1427 struct zebra_neigh
*n
;
1429 memset(&tmp
, 0, sizeof(tmp
));
1430 memcpy(&tmp
.ip
, ip
, sizeof(struct ipaddr
));
1431 n
= hash_lookup(zl3vni
->nh_table
, &tmp
);
1438 * Callback to allocate NH hash entry on L3-VNI.
1440 static void *zl3vni_nh_alloc(void *p
)
1442 const struct zebra_neigh
*tmp_n
= p
;
1443 struct zebra_neigh
*n
;
1445 n
= XCALLOC(MTYPE_L3NEIGH
, sizeof(struct zebra_neigh
));
1452 * Add neighbor entry.
1454 static struct zebra_neigh
*zl3vni_nh_add(struct zebra_l3vni
*zl3vni
,
1455 const struct ipaddr
*ip
,
1456 const struct ethaddr
*mac
)
1458 struct zebra_neigh tmp_n
;
1459 struct zebra_neigh
*n
= NULL
;
1461 memset(&tmp_n
, 0, sizeof(tmp_n
));
1462 memcpy(&tmp_n
.ip
, ip
, sizeof(struct ipaddr
));
1463 n
= hash_get(zl3vni
->nh_table
, &tmp_n
, zl3vni_nh_alloc
);
1465 RB_INIT(host_rb_tree_entry
, &n
->host_rb
);
1467 memcpy(&n
->emac
, mac
, ETH_ALEN
);
1468 SET_FLAG(n
->flags
, ZEBRA_NEIGH_REMOTE
);
1469 SET_FLAG(n
->flags
, ZEBRA_NEIGH_REMOTE_NH
);
1475 * Delete neighbor entry.
1477 static int zl3vni_nh_del(struct zebra_l3vni
*zl3vni
, struct zebra_neigh
*n
)
1479 struct zebra_neigh
*tmp_n
;
1480 struct host_rb_entry
*hle
;
1482 while (!RB_EMPTY(host_rb_tree_entry
, &n
->host_rb
)) {
1483 hle
= RB_ROOT(host_rb_tree_entry
, &n
->host_rb
);
1485 RB_REMOVE(host_rb_tree_entry
, &n
->host_rb
, hle
);
1486 XFREE(MTYPE_HOST_PREFIX
, hle
);
1489 tmp_n
= hash_release(zl3vni
->nh_table
, n
);
1490 XFREE(MTYPE_L3NEIGH
, tmp_n
);
1496 * Install remote nh as neigh into the kernel.
1498 static int zl3vni_nh_install(struct zebra_l3vni
*zl3vni
, struct zebra_neigh
*n
)
1503 if (!is_l3vni_oper_up(zl3vni
))
1506 if (!(n
->flags
& ZEBRA_NEIGH_REMOTE
)
1507 || !(n
->flags
& ZEBRA_NEIGH_REMOTE_NH
))
1510 flags
= DPLANE_NTF_EXT_LEARNED
;
1511 if (n
->flags
& ZEBRA_NEIGH_ROUTER_FLAG
)
1512 flags
|= DPLANE_NTF_ROUTER
;
1514 dplane_rem_neigh_add(zl3vni
->svi_if
, &n
->ip
, &n
->emac
, flags
,
1515 false /*was_static*/);
1521 * Uninstall remote nh from the kernel.
1523 static int zl3vni_nh_uninstall(struct zebra_l3vni
*zl3vni
,
1524 struct zebra_neigh
*n
)
1526 if (!(n
->flags
& ZEBRA_NEIGH_REMOTE
)
1527 || !(n
->flags
& ZEBRA_NEIGH_REMOTE_NH
))
1530 if (!zl3vni
->svi_if
|| !if_is_operative(zl3vni
->svi_if
))
1533 dplane_rem_neigh_delete(zl3vni
->svi_if
, &n
->ip
);
1538 /* add remote vtep as a neigh entry */
1539 static int zl3vni_remote_nh_add(struct zebra_l3vni
*zl3vni
,
1540 const struct ipaddr
*vtep_ip
,
1541 const struct ethaddr
*rmac
,
1542 const struct prefix
*host_prefix
)
1544 struct zebra_neigh
*nh
= NULL
;
1546 /* Create the next hop entry, or update its mac, if necessary. */
1547 nh
= zl3vni_nh_lookup(zl3vni
, vtep_ip
);
1549 nh
= zl3vni_nh_add(zl3vni
, vtep_ip
, rmac
);
1552 "Failed to add NH %pIA as Neigh (RMAC %pEA L3-VNI %u prefix %pFX)",
1553 vtep_ip
, rmac
, zl3vni
->vni
, host_prefix
);
1557 /* install the nh neigh in kernel */
1558 zl3vni_nh_install(zl3vni
, nh
);
1559 } else if (memcmp(&nh
->emac
, rmac
, ETH_ALEN
) != 0) {
1560 if (IS_ZEBRA_DEBUG_VXLAN
)
1562 "L3VNI %u RMAC change(%pEA --> %pEA) for nexthop %pIA, prefix %pFX",
1563 zl3vni
->vni
, &nh
->emac
, rmac
, vtep_ip
,
1566 memcpy(&nh
->emac
, rmac
, ETH_ALEN
);
1567 /* install (update) the nh neigh in kernel */
1568 zl3vni_nh_install(zl3vni
, nh
);
1571 rb_find_or_add_host(&nh
->host_rb
, host_prefix
);
1576 /* handle nh neigh delete */
1577 static void zl3vni_remote_nh_del(struct zebra_l3vni
*zl3vni
,
1578 struct zebra_neigh
*nh
,
1579 struct prefix
*host_prefix
)
1581 rb_delete_host(&nh
->host_rb
, host_prefix
);
1583 if (RB_EMPTY(host_rb_tree_entry
, &nh
->host_rb
)) {
1584 /* uninstall from kernel */
1585 zl3vni_nh_uninstall(zl3vni
, nh
);
1587 /* delete the nh entry */
1588 zl3vni_nh_del(zl3vni
, nh
);
1592 /* handle neigh update from kernel - the only thing of interest is to
1593 * readd stale entries.
1595 static int zl3vni_local_nh_add_update(struct zebra_l3vni
*zl3vni
,
1596 struct ipaddr
*ip
, uint16_t state
)
1599 struct zebra_neigh
*n
= NULL
;
1601 n
= zl3vni_nh_lookup(zl3vni
, ip
);
1605 /* all next hop neigh are remote and installed by frr.
1606 * If the kernel has aged this entry, re-install.
1608 if (state
& NUD_STALE
)
1609 zl3vni_nh_install(zl3vni
, n
);
1614 /* handle neigh delete from kernel */
1615 static int zl3vni_local_nh_del(struct zebra_l3vni
*zl3vni
, struct ipaddr
*ip
)
1617 struct zebra_neigh
*n
= NULL
;
1619 n
= zl3vni_nh_lookup(zl3vni
, ip
);
1623 /* all next hop neigh are remote and installed by frr.
1624 * If we get an age out notification for these neigh entries, we have to
1627 zl3vni_nh_install(zl3vni
, n
);
1633 * Hash function for L3 VNI.
1635 static unsigned int l3vni_hash_keymake(const void *p
)
1637 const struct zebra_l3vni
*zl3vni
= p
;
1639 return jhash_1word(zl3vni
->vni
, 0);
1643 * Compare 2 L3 VNI hash entries.
1645 static bool l3vni_hash_cmp(const void *p1
, const void *p2
)
1647 const struct zebra_l3vni
*zl3vni1
= p1
;
1648 const struct zebra_l3vni
*zl3vni2
= p2
;
1650 return (zl3vni1
->vni
== zl3vni2
->vni
);
1654 * Callback to allocate L3 VNI hash entry.
1656 static void *zl3vni_alloc(void *p
)
1658 struct zebra_l3vni
*zl3vni
= NULL
;
1659 const struct zebra_l3vni
*tmp_l3vni
= p
;
1661 zl3vni
= XCALLOC(MTYPE_ZL3VNI
, sizeof(struct zebra_l3vni
));
1662 zl3vni
->vni
= tmp_l3vni
->vni
;
1663 return ((void *)zl3vni
);
1667 * Look up L3 VNI hash entry.
1669 struct zebra_l3vni
*zl3vni_lookup(vni_t vni
)
1671 struct zebra_l3vni tmp_l3vni
;
1672 struct zebra_l3vni
*zl3vni
= NULL
;
1674 memset(&tmp_l3vni
, 0, sizeof(tmp_l3vni
));
1675 tmp_l3vni
.vni
= vni
;
1676 zl3vni
= hash_lookup(zrouter
.l3vni_table
, &tmp_l3vni
);
1682 * Add L3 VNI hash entry.
1684 static struct zebra_l3vni
*zl3vni_add(vni_t vni
, vrf_id_t vrf_id
)
1686 struct zebra_l3vni tmp_zl3vni
;
1687 struct zebra_l3vni
*zl3vni
= NULL
;
1689 memset(&tmp_zl3vni
, 0, sizeof(tmp_zl3vni
));
1690 tmp_zl3vni
.vni
= vni
;
1692 zl3vni
= hash_get(zrouter
.l3vni_table
, &tmp_zl3vni
, zl3vni_alloc
);
1694 zl3vni
->vrf_id
= vrf_id
;
1695 zl3vni
->svi_if
= NULL
;
1696 zl3vni
->vxlan_if
= NULL
;
1697 zl3vni
->l2vnis
= list_new();
1698 zl3vni
->l2vnis
->cmp
= zebra_evpn_list_cmp
;
1700 /* Create hash table for remote RMAC */
1701 zl3vni
->rmac_table
= zebra_mac_db_create("Zebra L3-VNI RMAC-Table");
1703 /* Create hash table for neighbors */
1704 zl3vni
->nh_table
= zebra_neigh_db_create("Zebra L3-VNI next-hop table");
1710 * Delete L3 VNI hash entry.
1712 static int zl3vni_del(struct zebra_l3vni
*zl3vni
)
1714 struct zebra_l3vni
*tmp_zl3vni
;
1716 /* free the list of l2vnis */
1717 list_delete(&zl3vni
->l2vnis
);
1718 zl3vni
->l2vnis
= NULL
;
1720 /* Free the rmac table */
1721 hash_free(zl3vni
->rmac_table
);
1722 zl3vni
->rmac_table
= NULL
;
1724 /* Free the nh table */
1725 hash_free(zl3vni
->nh_table
);
1726 zl3vni
->nh_table
= NULL
;
1728 /* Free the VNI hash entry and allocated memory. */
1729 tmp_zl3vni
= hash_release(zrouter
.l3vni_table
, zl3vni
);
1730 XFREE(MTYPE_ZL3VNI
, tmp_zl3vni
);
1735 static int zl3vni_map_to_vxlan_if_ns(struct ns
*ns
,
1739 struct zebra_ns
*zns
= ns
->info
;
1740 struct zebra_l3vni
*zl3vni
= (struct zebra_l3vni
*)_zl3vni
;
1741 struct route_node
*rn
= NULL
;
1742 struct interface
*ifp
= NULL
;
1743 struct zebra_vrf
*zvrf
;
1745 zvrf
= zebra_vrf_get_evpn();
1749 /* loop through all vxlan-interface */
1750 for (rn
= route_top(zns
->if_table
); rn
; rn
= route_next(rn
)) {
1752 struct zebra_if
*zif
= NULL
;
1753 struct zebra_l2info_vxlan
*vxl
;
1754 struct zebra_vxlan_vni
*vni
= NULL
;
1756 ifp
= (struct interface
*)rn
->info
;
1761 if (!zif
|| zif
->zif_type
!= ZEBRA_IF_VXLAN
)
1764 vxl
= &zif
->l2info
.vxl
;
1765 vni
= zebra_vxlan_if_vni_find(zif
, zl3vni
->vni
);
1766 if (vni
->vni
!= zl3vni
->vni
)
1769 /* link of VXLAN interface should be in zebra_evpn_vrf */
1770 if (zvrf
->zns
->ns_id
!= vxl
->link_nsid
) {
1771 if (IS_ZEBRA_DEBUG_VXLAN
)
1773 "Intf %s(%u) VNI %u, link not in same "
1774 "namespace than BGP EVPN core instance ",
1775 ifp
->name
, ifp
->ifindex
, vni
->vni
);
1780 zl3vni
->local_vtep_ip
= zif
->l2info
.vxl
.vtep_ip
;
1781 *_pifp
= (void *)ifp
;
1782 return NS_WALK_STOP
;
1785 return NS_WALK_CONTINUE
;
1788 struct interface
*zl3vni_map_to_vxlan_if(struct zebra_l3vni
*zl3vni
)
1790 struct interface
**p_ifp
;
1791 struct interface
*ifp
= NULL
;
1795 ns_walk_func(zl3vni_map_to_vxlan_if_ns
,
1796 (void *)zl3vni
, (void **)p_ifp
);
1800 struct interface
*zl3vni_map_to_svi_if(struct zebra_l3vni
*zl3vni
)
1802 struct zebra_if
*zif
= NULL
; /* zebra_if for vxlan_if */
1803 struct zebra_vxlan_vni
*vni
= NULL
; /* vni info in vxlan_if */
1808 if (!zl3vni
->vxlan_if
)
1811 zif
= zl3vni
->vxlan_if
->info
;
1815 vni
= zebra_vxlan_if_vni_find(zif
, zl3vni
->vni
);
1819 return zvni_map_to_svi(vni
->access_vlan
, zif
->brslave_info
.br_if
);
1822 struct interface
*zl3vni_map_to_mac_vlan_if(struct zebra_l3vni
*zl3vni
)
1824 struct zebra_if
*zif
= NULL
; /* zebra_if for vxlan_if */
1829 if (!zl3vni
->vxlan_if
)
1832 zif
= zl3vni
->vxlan_if
->info
;
1836 return zebra_evpn_map_to_macvlan(zif
->brslave_info
.br_if
,
1841 struct zebra_l3vni
*zl3vni_from_vrf(vrf_id_t vrf_id
)
1843 struct zebra_vrf
*zvrf
= NULL
;
1845 zvrf
= zebra_vrf_lookup_by_id(vrf_id
);
1849 return zl3vni_lookup(zvrf
->l3vni
);
1852 static int zl3vni_from_svi_ns(struct ns
*ns
, void *_in_param
, void **_p_zl3vni
)
1854 struct zebra_ns
*zns
= ns
->info
;
1855 struct zebra_l3vni
**p_zl3vni
= (struct zebra_l3vni
**)_p_zl3vni
;
1856 struct zebra_from_svi_param
*in_param
=
1857 (struct zebra_from_svi_param
*)_in_param
;
1858 struct route_node
*rn
= NULL
;
1859 struct interface
*tmp_if
= NULL
;
1860 struct zebra_if
*zif
= NULL
;
1861 struct zebra_vxlan_vni
*vni
= NULL
;
1863 assert(in_param
&& p_zl3vni
);
1865 /* loop through all vxlan-interface */
1866 for (rn
= route_top(zns
->if_table
); rn
; rn
= route_next(rn
)) {
1867 tmp_if
= (struct interface
*)rn
->info
;
1871 if (!zif
|| zif
->zif_type
!= ZEBRA_IF_VXLAN
)
1873 if (!if_is_operative(tmp_if
))
1876 if (zif
->brslave_info
.br_if
!= in_param
->br_if
)
1879 vni
= zebra_vxlan_if_access_vlan_find(zif
, in_param
->bridge_vlan_aware
,
1881 if (!in_param
->bridge_vlan_aware
|| vni
) {
1882 *p_zl3vni
= zl3vni_lookup(vni
->vni
);
1883 return NS_WALK_STOP
;
1887 return NS_WALK_CONTINUE
;
1891 * Map SVI and associated bridge to a VNI. This is invoked upon getting
1892 * neighbor notifications, to see if they are of interest.
1894 static struct zebra_l3vni
*zl3vni_from_svi(struct interface
*ifp
,
1895 struct interface
*br_if
)
1897 struct zebra_l3vni
*zl3vni
= NULL
;
1898 struct zebra_if
*zif
= NULL
;
1899 struct zebra_from_svi_param in_param
= {};
1900 struct zebra_l3vni
**p_zl3vni
;
1905 /* Make sure the linked interface is a bridge. */
1906 if (!IS_ZEBRA_IF_BRIDGE(br_if
))
1908 in_param
.br_if
= br_if
;
1910 /* Determine if bridge is VLAN-aware or not */
1913 in_param
.bridge_vlan_aware
= IS_ZEBRA_IF_BRIDGE_VLAN_AWARE(zif
);
1914 if (in_param
.bridge_vlan_aware
) {
1915 struct zebra_l2info_vlan
*vl
;
1917 if (!IS_ZEBRA_IF_VLAN(ifp
))
1922 vl
= &zif
->l2info
.vl
;
1923 in_param
.vid
= vl
->vid
;
1926 /* See if this interface (or interface plus VLAN Id) maps to a VxLAN */
1927 /* TODO: Optimize with a hash. */
1931 ns_walk_func(zl3vni_from_svi_ns
, (void *)&in_param
, (void **)p_zl3vni
);
1935 vni_t
vni_id_from_svi(struct interface
*ifp
, struct interface
*br_if
)
1938 struct zebra_evpn
*zevpn
= NULL
;
1939 struct zebra_l3vni
*zl3vni
= NULL
;
1941 /* Check if an L3VNI belongs to this SVI interface.
1942 * If not, check if an L2VNI belongs to this SVI interface.
1944 zl3vni
= zl3vni_from_svi(ifp
, br_if
);
1948 zevpn
= zebra_evpn_from_svi(ifp
, br_if
);
1956 static inline void zl3vni_get_vrr_rmac(struct zebra_l3vni
*zl3vni
,
1957 struct ethaddr
*rmac
)
1962 if (!is_l3vni_oper_up(zl3vni
))
1965 if (zl3vni
->mac_vlan_if
&& if_is_operative(zl3vni
->mac_vlan_if
))
1966 memcpy(rmac
->octet
, zl3vni
->mac_vlan_if
->hw_addr
, ETH_ALEN
);
1970 * Inform BGP about l3-vni.
1972 static int zl3vni_send_add_to_client(struct zebra_l3vni
*zl3vni
)
1974 struct stream
*s
= NULL
;
1975 struct zserv
*client
= NULL
;
1976 struct ethaddr svi_rmac
, vrr_rmac
= {.octet
= {0} };
1977 struct zebra_vrf
*zvrf
;
1978 bool is_anycast_mac
= true;
1980 client
= zserv_find_client(ZEBRA_ROUTE_BGP
, 0);
1981 /* BGP may not be running. */
1985 zvrf
= zebra_vrf_lookup_by_id(zl3vni
->vrf_id
);
1988 /* get the svi and vrr rmac values */
1989 memset(&svi_rmac
, 0, sizeof(svi_rmac
));
1990 zl3vni_get_svi_rmac(zl3vni
, &svi_rmac
);
1991 zl3vni_get_vrr_rmac(zl3vni
, &vrr_rmac
);
1993 /* In absence of vrr mac use svi mac as anycast MAC value */
1994 if (is_zero_mac(&vrr_rmac
)) {
1995 memcpy(&vrr_rmac
, &svi_rmac
, ETH_ALEN
);
1996 is_anycast_mac
= false;
1999 s
= stream_new(ZEBRA_MAX_PACKET_SIZ
);
2001 /* The message is used for both vni add and/or update like
2002 * vrr mac is added for l3vni SVI.
2004 zclient_create_header(s
, ZEBRA_L3VNI_ADD
, zl3vni_vrf_id(zl3vni
));
2005 stream_putl(s
, zl3vni
->vni
);
2006 stream_put(s
, &svi_rmac
, sizeof(struct ethaddr
));
2007 stream_put_in_addr(s
, &zl3vni
->local_vtep_ip
);
2008 stream_put(s
, &zl3vni
->filter
, sizeof(int));
2009 stream_putl(s
, zl3vni
->svi_if
->ifindex
);
2010 stream_put(s
, &vrr_rmac
, sizeof(struct ethaddr
));
2011 stream_putl(s
, is_anycast_mac
);
2013 /* Write packet size. */
2014 stream_putw_at(s
, 0, stream_get_endp(s
));
2016 if (IS_ZEBRA_DEBUG_VXLAN
)
2018 "Send L3_VNI_ADD %u VRF %s RMAC %pEA VRR %pEA local-ip %pI4 filter %s to %s",
2019 zl3vni
->vni
, vrf_id_to_name(zl3vni_vrf_id(zl3vni
)),
2020 &svi_rmac
, &vrr_rmac
, &zl3vni
->local_vtep_ip
,
2021 CHECK_FLAG(zl3vni
->filter
, PREFIX_ROUTES_ONLY
)
2022 ? "prefix-routes-only"
2024 zebra_route_string(client
->proto
));
2026 client
->l3vniadd_cnt
++;
2027 return zserv_send_message(client
, s
);
2031 * Inform BGP about local l3-VNI deletion.
2033 static int zl3vni_send_del_to_client(struct zebra_l3vni
*zl3vni
)
2035 struct stream
*s
= NULL
;
2036 struct zserv
*client
= NULL
;
2038 client
= zserv_find_client(ZEBRA_ROUTE_BGP
, 0);
2039 /* BGP may not be running. */
2043 s
= stream_new(ZEBRA_MAX_PACKET_SIZ
);
2045 zclient_create_header(s
, ZEBRA_L3VNI_DEL
, zl3vni_vrf_id(zl3vni
));
2046 stream_putl(s
, zl3vni
->vni
);
2048 /* Write packet size. */
2049 stream_putw_at(s
, 0, stream_get_endp(s
));
2051 if (IS_ZEBRA_DEBUG_VXLAN
)
2052 zlog_debug("Send L3_VNI_DEL %u VRF %s to %s", zl3vni
->vni
,
2053 vrf_id_to_name(zl3vni_vrf_id(zl3vni
)),
2054 zebra_route_string(client
->proto
));
2056 client
->l3vnidel_cnt
++;
2057 return zserv_send_message(client
, s
);
2060 void zebra_vxlan_process_l3vni_oper_up(struct zebra_l3vni
*zl3vni
)
2065 /* send l3vni add to BGP */
2066 zl3vni_send_add_to_client(zl3vni
);
2069 void zebra_vxlan_process_l3vni_oper_down(struct zebra_l3vni
*zl3vni
)
2074 /* send l3-vni del to BGP*/
2075 zl3vni_send_del_to_client(zl3vni
);
2078 static void zevpn_add_to_l3vni_list(struct hash_bucket
*bucket
, void *ctxt
)
2080 struct zebra_evpn
*zevpn
= (struct zebra_evpn
*)bucket
->data
;
2081 struct zebra_l3vni
*zl3vni
= (struct zebra_l3vni
*)ctxt
;
2083 if (zevpn
->vrf_id
== zl3vni_vrf_id(zl3vni
))
2084 listnode_add_sort(zl3vni
->l2vnis
, zevpn
);
2088 * Handle transition of vni from l2 to l3 and vice versa.
2089 * This function handles only the L2VNI add/delete part of
2090 * the above transition.
2091 * L3VNI add/delete is handled by the calling functions.
2093 static int zebra_vxlan_handle_vni_transition(struct zebra_vrf
*zvrf
, vni_t vni
,
2096 struct zebra_evpn
*zevpn
= NULL
;
2097 struct zebra_l3vni
*zl3vni
= NULL
;
2099 /* There is a possibility that VNI notification was already received
2100 * from kernel and we programmed it as L2-VNI
2101 * In such a case we need to delete this L2-VNI first, so
2102 * that it can be reprogrammed as L3-VNI in the system. It is also
2103 * possible that the vrf-vni mapping is removed from FRR while the vxlan
2104 * interface is still present in kernel. In this case to keep it
2105 * symmetric, we will delete the l3-vni and reprogram it as l2-vni
2108 /* Locate hash entry */
2109 zevpn
= zebra_evpn_lookup(vni
);
2113 if (IS_ZEBRA_DEBUG_VXLAN
)
2114 zlog_debug("Del L2-VNI %u - transition to L3-VNI", vni
);
2116 /* Delete EVPN from BGP. */
2117 zebra_evpn_send_del_to_client(zevpn
);
2119 zebra_evpn_neigh_del_all(zevpn
, 0, 0, DEL_ALL_NEIGH
);
2120 zebra_evpn_mac_del_all(zevpn
, 0, 0, DEL_ALL_MAC
);
2122 /* Free up all remote VTEPs, if any. */
2123 zebra_evpn_vtep_del_all(zevpn
, 1);
2125 zl3vni
= zl3vni_from_vrf(zevpn
->vrf_id
);
2127 listnode_delete(zl3vni
->l2vnis
, zevpn
);
2129 /* Delete the hash entry. */
2130 if (zebra_evpn_vxlan_del(zevpn
)) {
2131 flog_err(EC_ZEBRA_VNI_DEL_FAILED
,
2132 "Failed to del EVPN hash %p, VNI %u", zevpn
,
2137 struct zebra_ns
*zns
;
2138 struct route_node
*rn
;
2139 struct interface
*ifp
;
2140 struct zebra_if
*zif
;
2141 struct zebra_vxlan_vni
*vnip
;
2142 struct zebra_l2info_vxlan
*vxl
;
2143 struct interface
*vlan_if
;
2146 if (IS_ZEBRA_DEBUG_VXLAN
)
2147 zlog_debug("Adding L2-VNI %u - transition from L3-VNI",
2150 /* Find VxLAN interface for this VNI. */
2151 zns
= zebra_ns_lookup(NS_DEFAULT
);
2152 for (rn
= route_top(zns
->if_table
); rn
; rn
= route_next(rn
)) {
2153 ifp
= (struct interface
*)rn
->info
;
2157 if (!zif
|| zif
->zif_type
!= ZEBRA_IF_VXLAN
)
2160 vxl
= &zif
->l2info
.vxl
;
2161 vnip
= zebra_vxlan_if_vni_find(zif
, vni
);
2169 if (IS_ZEBRA_DEBUG_VXLAN
)
2171 "Adding L2-VNI - Failed to find VxLAN interface for VNI %u",
2176 /* Create VNI hash entry for L2VNI */
2177 zevpn
= zebra_evpn_lookup(vni
);
2181 zevpn
= zebra_evpn_add(vni
);
2183 /* Find bridge interface for the VNI */
2184 vlan_if
= zvni_map_to_svi(vnip
->access_vlan
,
2185 zif
->brslave_info
.br_if
);
2187 zevpn
->vrf_id
= vlan_if
->vrf
->vrf_id
;
2188 zl3vni
= zl3vni_from_vrf(vlan_if
->vrf
->vrf_id
);
2190 listnode_add_sort_nodup(zl3vni
->l2vnis
, zevpn
);
2193 zevpn
->vxlan_if
= ifp
;
2194 zevpn
->local_vtep_ip
= vxl
->vtep_ip
;
2196 /* Inform BGP if the VNI is up and mapped to a bridge. */
2197 if (if_is_operative(ifp
) && zif
->brslave_info
.br_if
) {
2198 zebra_evpn_send_add_to_client(zevpn
);
2199 zebra_evpn_read_mac_neigh(zevpn
, ifp
);
2206 /* delete and uninstall rmac hash entry */
2207 static void zl3vni_del_rmac_hash_entry(struct hash_bucket
*bucket
, void *ctx
)
2209 struct zebra_mac
*zrmac
= NULL
;
2210 struct zebra_l3vni
*zl3vni
= NULL
;
2212 zrmac
= (struct zebra_mac
*)bucket
->data
;
2213 zl3vni
= (struct zebra_l3vni
*)ctx
;
2214 zl3vni_rmac_uninstall(zl3vni
, zrmac
);
2216 /* Send RMAC for FPM processing */
2217 hook_call(zebra_rmac_update
, zrmac
, zl3vni
, true, "RMAC deleted");
2219 zl3vni_rmac_del(zl3vni
, zrmac
);
2222 /* delete and uninstall nh hash entry */
2223 static void zl3vni_del_nh_hash_entry(struct hash_bucket
*bucket
, void *ctx
)
2225 struct zebra_neigh
*n
= NULL
;
2226 struct zebra_l3vni
*zl3vni
= NULL
;
2228 n
= (struct zebra_neigh
*)bucket
->data
;
2229 zl3vni
= (struct zebra_l3vni
*)ctx
;
2230 zl3vni_nh_uninstall(zl3vni
, n
);
2231 zl3vni_nh_del(zl3vni
, n
);
2234 /* re-add remote rmac if needed */
2235 static int zebra_vxlan_readd_remote_rmac(struct zebra_l3vni
*zl3vni
,
2236 struct ethaddr
*rmac
)
2238 struct zebra_mac
*zrmac
= NULL
;
2240 zrmac
= zl3vni_rmac_lookup(zl3vni
, rmac
);
2244 if (IS_ZEBRA_DEBUG_VXLAN
)
2245 zlog_debug("Del remote RMAC %pEA L3VNI %u - readd",
2248 zl3vni_rmac_install(zl3vni
, zrmac
);
2252 /* Public functions */
2254 int is_l3vni_for_prefix_routes_only(vni_t vni
)
2256 struct zebra_l3vni
*zl3vni
= NULL
;
2258 zl3vni
= zl3vni_lookup(vni
);
2262 return CHECK_FLAG(zl3vni
->filter
, PREFIX_ROUTES_ONLY
) ? 1 : 0;
2265 /* handle evpn route in vrf table */
2266 void zebra_vxlan_evpn_vrf_route_add(vrf_id_t vrf_id
, const struct ethaddr
*rmac
,
2267 const struct ipaddr
*vtep_ip
,
2268 const struct prefix
*host_prefix
)
2270 struct zebra_l3vni
*zl3vni
= NULL
;
2271 struct ipaddr ipv4_vtep
;
2273 zl3vni
= zl3vni_from_vrf(vrf_id
);
2274 if (!zl3vni
|| !is_l3vni_oper_up(zl3vni
))
2278 * add the next hop neighbor -
2279 * neigh to be installed is the ipv6 nexthop neigh
2281 zl3vni_remote_nh_add(zl3vni
, vtep_ip
, rmac
, host_prefix
);
2284 * if the remote vtep is a ipv4 mapped ipv6 address convert it to ipv4
2285 * address. Rmac is programmed against the ipv4 vtep because we only
2286 * support ipv4 tunnels in the h/w right now
2288 memset(&ipv4_vtep
, 0, sizeof(ipv4_vtep
));
2289 ipv4_vtep
.ipa_type
= IPADDR_V4
;
2290 if (vtep_ip
->ipa_type
== IPADDR_V6
)
2291 ipv4_mapped_ipv6_to_ipv4(&vtep_ip
->ipaddr_v6
,
2292 &(ipv4_vtep
.ipaddr_v4
));
2294 memcpy(&(ipv4_vtep
.ipaddr_v4
), &vtep_ip
->ipaddr_v4
,
2295 sizeof(struct in_addr
));
2298 * add the rmac - remote rmac to be installed is against the ipv4
2301 zl3vni_remote_rmac_add(zl3vni
, rmac
, &ipv4_vtep
);
2304 /* handle evpn vrf route delete */
2305 void zebra_vxlan_evpn_vrf_route_del(vrf_id_t vrf_id
,
2306 struct ipaddr
*vtep_ip
,
2307 struct prefix
*host_prefix
)
2309 struct zebra_l3vni
*zl3vni
= NULL
;
2310 struct zebra_neigh
*nh
= NULL
;
2311 struct zebra_mac
*zrmac
= NULL
;
2313 zl3vni
= zl3vni_from_vrf(vrf_id
);
2317 /* find the next hop entry and rmac entry */
2318 nh
= zl3vni_nh_lookup(zl3vni
, vtep_ip
);
2321 zrmac
= zl3vni_rmac_lookup(zl3vni
, &nh
->emac
);
2323 /* delete the next hop entry */
2324 zl3vni_remote_nh_del(zl3vni
, nh
, host_prefix
);
2326 /* delete the rmac entry */
2328 zl3vni_remote_rmac_del(zl3vni
, zrmac
, vtep_ip
);
2331 void zebra_vxlan_print_specific_rmac_l3vni(struct vty
*vty
, vni_t l3vni
,
2332 struct ethaddr
*rmac
, bool use_json
)
2334 struct zebra_l3vni
*zl3vni
= NULL
;
2335 struct zebra_mac
*zrmac
= NULL
;
2336 json_object
*json
= NULL
;
2338 if (!is_evpn_enabled()) {
2340 vty_out(vty
, "{}\n");
2345 json
= json_object_new_object();
2347 zl3vni
= zl3vni_lookup(l3vni
);
2350 vty_out(vty
, "{}\n");
2352 vty_out(vty
, "%% L3-VNI %u doesn't exist\n", l3vni
);
2356 zrmac
= zl3vni_rmac_lookup(zl3vni
, rmac
);
2359 vty_out(vty
, "{}\n");
2362 "%% Requested RMAC doesn't exist in L3-VNI %u\n",
2367 zl3vni_print_rmac(zrmac
, vty
, json
);
2370 vty_json(vty
, json
);
2373 void zebra_vxlan_print_rmacs_l3vni(struct vty
*vty
, vni_t l3vni
, bool use_json
)
2375 struct zebra_l3vni
*zl3vni
;
2377 struct rmac_walk_ctx wctx
;
2378 json_object
*json
= NULL
;
2380 if (!is_evpn_enabled())
2383 zl3vni
= zl3vni_lookup(l3vni
);
2386 vty_out(vty
, "{}\n");
2388 vty_out(vty
, "%% L3-VNI %u does not exist\n", l3vni
);
2391 num_rmacs
= hashcount(zl3vni
->rmac_table
);
2396 json
= json_object_new_object();
2398 memset(&wctx
, 0, sizeof(wctx
));
2402 vty_out(vty
, "Number of Remote RMACs known for this VNI: %u\n",
2404 vty_out(vty
, "%-17s %-21s\n", "MAC", "Remote VTEP");
2406 json_object_int_add(json
, "numRmacs", num_rmacs
);
2408 hash_iterate(zl3vni
->rmac_table
, zl3vni_print_rmac_hash
, &wctx
);
2411 vty_json(vty
, json
);
2414 void zebra_vxlan_print_rmacs_all_l3vni(struct vty
*vty
, bool use_json
)
2416 json_object
*json
= NULL
;
2419 if (!is_evpn_enabled()) {
2421 vty_out(vty
, "{}\n");
2426 json
= json_object_new_object();
2430 hash_iterate(zrouter
.l3vni_table
,
2431 (void (*)(struct hash_bucket
*,
2432 void *))zl3vni_print_rmac_hash_all_vni
,
2436 vty_json(vty
, json
);
2439 void zebra_vxlan_print_specific_nh_l3vni(struct vty
*vty
, vni_t l3vni
,
2440 struct ipaddr
*ip
, bool use_json
)
2442 struct zebra_l3vni
*zl3vni
= NULL
;
2443 struct zebra_neigh
*n
= NULL
;
2444 json_object
*json
= NULL
;
2446 if (!is_evpn_enabled()) {
2448 vty_out(vty
, "{}\n");
2453 json
= json_object_new_object();
2455 zl3vni
= zl3vni_lookup(l3vni
);
2458 vty_out(vty
, "{}\n");
2460 vty_out(vty
, "%% L3-VNI %u does not exist\n", l3vni
);
2464 n
= zl3vni_nh_lookup(zl3vni
, ip
);
2467 vty_out(vty
, "{}\n");
2470 "%% Requested next-hop not present for L3-VNI %u",
2475 zl3vni_print_nh(n
, vty
, json
);
2478 vty_json(vty
, json
);
2481 void zebra_vxlan_print_nh_l3vni(struct vty
*vty
, vni_t l3vni
, bool use_json
)
2484 struct nh_walk_ctx wctx
;
2485 json_object
*json
= NULL
;
2486 struct zebra_l3vni
*zl3vni
= NULL
;
2488 if (!is_evpn_enabled())
2491 zl3vni
= zl3vni_lookup(l3vni
);
2494 vty_out(vty
, "{}\n");
2496 vty_out(vty
, "%% L3-VNI %u does not exist\n", l3vni
);
2500 num_nh
= hashcount(zl3vni
->nh_table
);
2505 json
= json_object_new_object();
2510 vty_out(vty
, "Number of NH Neighbors known for this VNI: %u\n",
2512 vty_out(vty
, "%-15s %-17s\n", "IP", "RMAC");
2514 json_object_int_add(json
, "numNextHops", num_nh
);
2516 hash_iterate(zl3vni
->nh_table
, zl3vni_print_nh_hash
, &wctx
);
2519 vty_json(vty
, json
);
2522 void zebra_vxlan_print_nh_all_l3vni(struct vty
*vty
, bool use_json
)
2524 json_object
*json
= NULL
;
2527 if (!is_evpn_enabled()) {
2529 vty_out(vty
, "{}\n");
2534 json
= json_object_new_object();
2538 hash_iterate(zrouter
.l3vni_table
,
2539 (void (*)(struct hash_bucket
*,
2540 void *))zl3vni_print_nh_hash_all_vni
,
2544 vty_json(vty
, json
);
2548 * Display L3 VNI information (VTY command handler).
2550 void zebra_vxlan_print_l3vni(struct vty
*vty
, vni_t vni
, bool use_json
)
2553 json_object
*json
= NULL
;
2554 struct zebra_l3vni
*zl3vni
= NULL
;
2556 if (!is_evpn_enabled()) {
2558 vty_out(vty
, "{}\n");
2562 zl3vni
= zl3vni_lookup(vni
);
2565 vty_out(vty
, "{}\n");
2567 vty_out(vty
, "%% VNI %u does not exist\n", vni
);
2572 json
= json_object_new_object();
2576 zl3vni_print(zl3vni
, (void *)args
);
2579 vty_json(vty
, json
);
2582 void zebra_vxlan_print_vrf_vni(struct vty
*vty
, struct zebra_vrf
*zvrf
,
2583 json_object
*json_vrfs
)
2585 char buf
[ETHER_ADDR_STRLEN
];
2586 struct zebra_l3vni
*zl3vni
= NULL
;
2588 zl3vni
= zl3vni_lookup(zvrf
->l3vni
);
2593 vty_out(vty
, "%-37s %-10u %-20s %-20s %-5s %-18s\n",
2594 zvrf_name(zvrf
), zl3vni
->vni
,
2595 zl3vni_vxlan_if_name(zl3vni
),
2596 zl3vni_svi_if_name(zl3vni
), zl3vni_state2str(zl3vni
),
2597 zl3vni_rmac2str(zl3vni
, buf
, sizeof(buf
)));
2599 json_object
*json_vrf
= NULL
;
2601 json_vrf
= json_object_new_object();
2602 json_object_string_add(json_vrf
, "vrf", zvrf_name(zvrf
));
2603 json_object_int_add(json_vrf
, "vni", zl3vni
->vni
);
2604 json_object_string_add(json_vrf
, "vxlanIntf",
2605 zl3vni_vxlan_if_name(zl3vni
));
2606 json_object_string_add(json_vrf
, "sviIntf",
2607 zl3vni_svi_if_name(zl3vni
));
2608 json_object_string_add(json_vrf
, "state",
2609 zl3vni_state2str(zl3vni
));
2610 json_object_string_add(
2611 json_vrf
, "routerMac",
2612 zl3vni_rmac2str(zl3vni
, buf
, sizeof(buf
)));
2613 json_object_array_add(json_vrfs
, json_vrf
);
2618 * Display Neighbors for a VNI (VTY command handler).
2620 void zebra_vxlan_print_neigh_vni(struct vty
*vty
, struct zebra_vrf
*zvrf
,
2621 vni_t vni
, bool use_json
)
2623 struct zebra_evpn
*zevpn
;
2625 struct neigh_walk_ctx wctx
;
2626 json_object
*json
= NULL
;
2628 if (!is_evpn_enabled())
2630 zevpn
= zebra_evpn_lookup(vni
);
2633 vty_out(vty
, "{}\n");
2635 vty_out(vty
, "%% VNI %u does not exist\n", vni
);
2638 num_neigh
= hashcount(zevpn
->neigh_table
);
2643 json
= json_object_new_object();
2645 /* Since we have IPv6 addresses to deal with which can vary widely in
2646 * size, we try to be a bit more elegant in display by first computing
2647 * the maximum width.
2649 memset(&wctx
, 0, sizeof(wctx
));
2652 wctx
.addr_width
= 15;
2654 hash_iterate(zevpn
->neigh_table
, zebra_evpn_find_neigh_addr_width
,
2659 "Number of ARPs (local and remote) known for this VNI: %u\n",
2661 zebra_evpn_print_neigh_hdr(vty
, &wctx
);
2663 json_object_int_add(json
, "numArpNd", num_neigh
);
2665 hash_iterate(zevpn
->neigh_table
, zebra_evpn_print_neigh_hash
, &wctx
);
2667 vty_json(vty
, json
);
2671 * Display neighbors across all VNIs (VTY command handler).
2673 void zebra_vxlan_print_neigh_all_vni(struct vty
*vty
, struct zebra_vrf
*zvrf
,
2674 bool print_dup
, bool use_json
)
2676 json_object
*json
= NULL
;
2679 if (!is_evpn_enabled())
2683 json
= json_object_new_object();
2687 args
[2] = (void *)(ptrdiff_t)print_dup
;
2689 hash_iterate(zvrf
->evpn_table
,
2690 (void (*)(struct hash_bucket
*,
2691 void *))zevpn_print_neigh_hash_all_evpn
,
2694 vty_json(vty
, json
);
2698 * Display neighbors across all VNIs in detail(VTY command handler).
2700 void zebra_vxlan_print_neigh_all_vni_detail(struct vty
*vty
,
2701 struct zebra_vrf
*zvrf
,
2702 bool print_dup
, bool use_json
)
2704 json_object
*json
= NULL
;
2707 if (!is_evpn_enabled())
2711 json
= json_object_new_object();
2715 args
[2] = (void *)(ptrdiff_t)print_dup
;
2717 hash_iterate(zvrf
->evpn_table
,
2718 (void (*)(struct hash_bucket
*,
2719 void *))zevpn_print_neigh_hash_all_evpn_detail
,
2722 vty_json(vty
, json
);
2726 * Display specific neighbor for a VNI, if present (VTY command handler).
2728 void zebra_vxlan_print_specific_neigh_vni(struct vty
*vty
,
2729 struct zebra_vrf
*zvrf
, vni_t vni
,
2730 struct ipaddr
*ip
, bool use_json
)
2732 struct zebra_evpn
*zevpn
;
2733 struct zebra_neigh
*n
;
2734 json_object
*json
= NULL
;
2736 if (!is_evpn_enabled())
2738 zevpn
= zebra_evpn_lookup(vni
);
2741 vty_out(vty
, "{}\n");
2743 vty_out(vty
, "%% VNI %u does not exist\n", vni
);
2746 n
= zebra_evpn_neigh_lookup(zevpn
, ip
);
2750 "%% Requested neighbor does not exist in VNI %u\n",
2755 json
= json_object_new_object();
2757 zebra_evpn_print_neigh(n
, vty
, json
);
2760 vty_json(vty
, json
);
2764 * Display neighbors for a VNI from specific VTEP (VTY command handler).
2765 * By definition, these are remote neighbors.
2767 void zebra_vxlan_print_neigh_vni_vtep(struct vty
*vty
, struct zebra_vrf
*zvrf
,
2768 vni_t vni
, struct in_addr vtep_ip
,
2771 struct zebra_evpn
*zevpn
;
2773 struct neigh_walk_ctx wctx
;
2774 json_object
*json
= NULL
;
2776 if (!is_evpn_enabled())
2778 zevpn
= zebra_evpn_lookup(vni
);
2781 vty_out(vty
, "{}\n");
2783 vty_out(vty
, "%% VNI %u does not exist\n", vni
);
2786 num_neigh
= hashcount(zevpn
->neigh_table
);
2791 json
= json_object_new_object();
2793 memset(&wctx
, 0, sizeof(wctx
));
2796 wctx
.addr_width
= 15;
2797 wctx
.flags
= SHOW_REMOTE_NEIGH_FROM_VTEP
;
2798 wctx
.r_vtep_ip
= vtep_ip
;
2800 hash_iterate(zevpn
->neigh_table
, zebra_evpn_find_neigh_addr_width
,
2802 hash_iterate(zevpn
->neigh_table
, zebra_evpn_print_neigh_hash
, &wctx
);
2805 vty_json(vty
, json
);
2809 * Display Duplicate detected Neighbors for a VNI
2810 * (VTY command handler).
2812 void zebra_vxlan_print_neigh_vni_dad(struct vty
*vty
,
2813 struct zebra_vrf
*zvrf
,
2817 struct zebra_evpn
*zevpn
;
2819 struct neigh_walk_ctx wctx
;
2820 json_object
*json
= NULL
;
2822 if (!is_evpn_enabled())
2825 zevpn
= zebra_evpn_lookup(vni
);
2827 vty_out(vty
, "%% VNI %u does not exist\n", vni
);
2831 num_neigh
= hashcount(zevpn
->neigh_table
);
2835 num_neigh
= num_dup_detected_neighs(zevpn
);
2840 json
= json_object_new_object();
2842 /* Since we have IPv6 addresses to deal with which can vary widely in
2843 * size, we try to be a bit more elegant in display by first computing
2844 * the maximum width.
2846 memset(&wctx
, 0, sizeof(wctx
));
2849 wctx
.addr_width
= 15;
2851 hash_iterate(zevpn
->neigh_table
, zebra_evpn_find_neigh_addr_width
,
2856 "Number of ARPs (local and remote) known for this VNI: %u\n",
2858 vty_out(vty
, "%*s %-6s %-8s %-17s %-30s\n",
2859 -wctx
.addr_width
, "IP", "Type",
2860 "State", "MAC", "Remote ES/VTEP");
2862 json_object_int_add(json
, "numArpNd", num_neigh
);
2864 hash_iterate(zevpn
->neigh_table
, zebra_evpn_print_dad_neigh_hash
,
2868 vty_json(vty
, json
);
2872 * Display MACs for a VNI (VTY command handler).
2874 void zebra_vxlan_print_macs_vni(struct vty
*vty
, struct zebra_vrf
*zvrf
,
2875 vni_t vni
, bool use_json
, bool detail
)
2877 struct zebra_evpn
*zevpn
;
2879 struct mac_walk_ctx wctx
;
2880 json_object
*json
= NULL
;
2881 json_object
*json_mac
= NULL
;
2883 if (!is_evpn_enabled())
2885 zevpn
= zebra_evpn_lookup(vni
);
2888 vty_out(vty
, "{}\n");
2890 vty_out(vty
, "%% VNI %u does not exist\n", vni
);
2893 num_macs
= num_valid_macs(zevpn
);
2898 json
= json_object_new_object();
2899 json_mac
= json_object_new_object();
2902 memset(&wctx
, 0, sizeof(wctx
));
2905 wctx
.json
= json_mac
;
2909 vty_out(vty
, "\nVNI %u #MACs (local and remote) %u\n\n",
2910 zevpn
->vni
, num_macs
);
2913 "Number of MACs (local and remote) known for this VNI: %u\n",
2916 "Flags: N=sync-neighs, I=local-inactive, P=peer-active, X=peer-proxy\n");
2917 vty_out(vty
, "%-17s %-6s %-5s %-30s %-5s %s\n", "MAC",
2918 "Type", "Flags", "Intf/Remote ES/VTEP", "VLAN",
2922 json_object_int_add(json
, "numMacs", num_macs
);
2925 hash_iterate(zevpn
->mac_table
, zebra_evpn_print_mac_hash_detail
,
2928 hash_iterate(zevpn
->mac_table
, zebra_evpn_print_mac_hash
,
2932 json_object_object_add(json
, "macs", json_mac
);
2933 vty_json(vty
, json
);
2938 * Display MACs for all VNIs (VTY command handler).
2940 void zebra_vxlan_print_macs_all_vni(struct vty
*vty
, struct zebra_vrf
*zvrf
,
2941 bool print_dup
, bool use_json
)
2943 struct mac_walk_ctx wctx
;
2944 json_object
*json
= NULL
;
2946 if (!is_evpn_enabled()) {
2948 vty_out(vty
, "{}\n");
2952 json
= json_object_new_object();
2954 memset(&wctx
, 0, sizeof(wctx
));
2957 wctx
.print_dup
= print_dup
;
2958 hash_iterate(zvrf
->evpn_table
, zevpn_print_mac_hash_all_evpn
, &wctx
);
2961 vty_json(vty
, json
);
2965 * Display MACs in detail for all VNIs (VTY command handler).
2967 void zebra_vxlan_print_macs_all_vni_detail(struct vty
*vty
,
2968 struct zebra_vrf
*zvrf
,
2969 bool print_dup
, bool use_json
)
2971 struct mac_walk_ctx wctx
;
2972 json_object
*json
= NULL
;
2974 if (!is_evpn_enabled()) {
2976 vty_out(vty
, "{}\n");
2980 json
= json_object_new_object();
2982 memset(&wctx
, 0, sizeof(wctx
));
2985 wctx
.print_dup
= print_dup
;
2986 hash_iterate(zvrf
->evpn_table
, zevpn_print_mac_hash_all_evpn_detail
,
2990 vty_json(vty
, json
);
2994 * Display MACs for all VNIs (VTY command handler).
2996 void zebra_vxlan_print_macs_all_vni_vtep(struct vty
*vty
,
2997 struct zebra_vrf
*zvrf
,
2998 struct in_addr vtep_ip
, bool use_json
)
3000 struct mac_walk_ctx wctx
;
3001 json_object
*json
= NULL
;
3003 if (!is_evpn_enabled())
3007 json
= json_object_new_object();
3009 memset(&wctx
, 0, sizeof(wctx
));
3011 wctx
.flags
= SHOW_REMOTE_MAC_FROM_VTEP
;
3012 wctx
.r_vtep_ip
= vtep_ip
;
3014 hash_iterate(zvrf
->evpn_table
, zevpn_print_mac_hash_all_evpn
, &wctx
);
3017 vty_json(vty
, json
);
3021 * Display specific MAC for a VNI, if present (VTY command handler).
3023 void zebra_vxlan_print_specific_mac_vni(struct vty
*vty
, struct zebra_vrf
*zvrf
,
3024 vni_t vni
, struct ethaddr
*macaddr
,
3027 struct zebra_evpn
*zevpn
;
3028 struct zebra_mac
*mac
;
3029 json_object
*json
= NULL
;
3031 if (!is_evpn_enabled())
3034 zevpn
= zebra_evpn_lookup(vni
);
3037 vty_out(vty
, "{}\n");
3039 vty_out(vty
, "%% VNI %u does not exist\n", vni
);
3042 mac
= zebra_evpn_mac_lookup(zevpn
, macaddr
);
3045 vty_out(vty
, "{}\n");
3048 "%% Requested MAC does not exist in VNI %u\n",
3054 json
= json_object_new_object();
3056 zebra_evpn_print_mac(mac
, vty
, json
);
3058 vty_json(vty
, json
);
3061 /* Print Duplicate MACs per VNI */
3062 void zebra_vxlan_print_macs_vni_dad(struct vty
*vty
,
3063 struct zebra_vrf
*zvrf
,
3064 vni_t vni
, bool use_json
)
3066 struct zebra_evpn
*zevpn
;
3067 struct mac_walk_ctx wctx
;
3069 json_object
*json
= NULL
;
3070 json_object
*json_mac
= NULL
;
3072 if (!is_evpn_enabled())
3075 zevpn
= zebra_evpn_lookup(vni
);
3077 vty_out(vty
, "%% VNI %u does not exist\n", vni
);
3081 num_macs
= num_valid_macs(zevpn
);
3085 num_macs
= num_dup_detected_macs(zevpn
);
3090 json
= json_object_new_object();
3091 json_mac
= json_object_new_object();
3094 memset(&wctx
, 0, sizeof(wctx
));
3097 wctx
.json
= json_mac
;
3101 "Number of MACs (local and remote) known for this VNI: %u\n",
3103 vty_out(vty
, "%-17s %-6s %-5s %-30s %-5s\n", "MAC", "Type",
3104 "Flags", "Intf/Remote ES/VTEP", "VLAN");
3106 json_object_int_add(json
, "numMacs", num_macs
);
3108 hash_iterate(zevpn
->mac_table
, zebra_evpn_print_dad_mac_hash
, &wctx
);
3111 json_object_object_add(json
, "macs", json_mac
);
3112 vty_json(vty
, json
);
3117 int zebra_vxlan_clear_dup_detect_vni_mac(struct zebra_vrf
*zvrf
, vni_t vni
,
3118 struct ethaddr
*macaddr
, char *errmsg
,
3121 struct zebra_evpn
*zevpn
;
3122 struct zebra_mac
*mac
;
3123 struct listnode
*node
= NULL
;
3124 struct zebra_neigh
*nbr
= NULL
;
3126 if (!is_evpn_enabled())
3129 zevpn
= zebra_evpn_lookup(vni
);
3131 snprintfrr(errmsg
, errmsg_len
, "VNI %u does not exist", vni
);
3135 mac
= zebra_evpn_mac_lookup(zevpn
, macaddr
);
3137 snprintf(errmsg
, errmsg_len
,
3138 "Requested MAC does not exist in VNI %u\n", vni
);
3142 if (!CHECK_FLAG(mac
->flags
, ZEBRA_MAC_DUPLICATE
)) {
3143 snprintfrr(errmsg
, errmsg_len
,
3144 "Requested MAC is not duplicate detected\n");
3148 /* Remove all IPs as duplicate associcated with this MAC */
3149 for (ALL_LIST_ELEMENTS_RO(mac
->neigh_list
, node
, nbr
)) {
3150 /* For local neigh mark inactive so MACIP update is generated
3151 * to BGP. This is a scenario where MAC update received
3152 * and detected as duplicate which marked neigh as duplicate.
3153 * Later local neigh update did not get a chance to relay
3154 * to BGP. Similarly remote macip update, neigh needs to be
3155 * installed locally.
3157 if (zvrf
->dad_freeze
&&
3158 CHECK_FLAG(nbr
->flags
, ZEBRA_NEIGH_DUPLICATE
)) {
3159 if (CHECK_FLAG(nbr
->flags
, ZEBRA_NEIGH_LOCAL
))
3160 ZEBRA_NEIGH_SET_INACTIVE(nbr
);
3161 else if (CHECK_FLAG(nbr
->flags
, ZEBRA_NEIGH_REMOTE
))
3162 zebra_evpn_rem_neigh_install(
3163 zevpn
, nbr
, false /*was_static*/);
3166 UNSET_FLAG(nbr
->flags
, ZEBRA_NEIGH_DUPLICATE
);
3168 nbr
->detect_start_time
.tv_sec
= 0;
3169 nbr
->dad_dup_detect_time
= 0;
3172 UNSET_FLAG(mac
->flags
, ZEBRA_MAC_DUPLICATE
);
3174 mac
->detect_start_time
.tv_sec
= 0;
3175 mac
->detect_start_time
.tv_usec
= 0;
3176 mac
->dad_dup_detect_time
= 0;
3177 THREAD_OFF(mac
->dad_mac_auto_recovery_timer
);
3179 /* warn-only action return */
3180 if (!zvrf
->dad_freeze
)
3183 /* Local: Notify Peer VTEPs, Remote: Install the entry */
3184 if (CHECK_FLAG(mac
->flags
, ZEBRA_MAC_LOCAL
)) {
3186 if (zebra_evpn_mac_send_add_to_client(zevpn
->vni
, &mac
->macaddr
,
3187 mac
->flags
, mac
->loc_seq
,
3191 /* Process all neighbors associated with this MAC. */
3192 zebra_evpn_process_neigh_on_local_mac_change(zevpn
, mac
, 0,
3195 } else if (CHECK_FLAG(mac
->flags
, ZEBRA_MAC_REMOTE
)) {
3196 zebra_evpn_process_neigh_on_remote_mac_add(zevpn
, mac
);
3198 /* Install the entry. */
3199 zebra_evpn_rem_mac_install(zevpn
, mac
, false /* was_static */);
3205 int zebra_vxlan_clear_dup_detect_vni_ip(struct zebra_vrf
*zvrf
, vni_t vni
,
3206 struct ipaddr
*ip
, char *errmsg
,
3209 struct zebra_evpn
*zevpn
;
3210 struct zebra_neigh
*nbr
;
3211 struct zebra_mac
*mac
;
3212 char buf
[INET6_ADDRSTRLEN
];
3213 char buf2
[ETHER_ADDR_STRLEN
];
3215 if (!is_evpn_enabled())
3218 zevpn
= zebra_evpn_lookup(vni
);
3220 snprintfrr(errmsg
, errmsg_len
, "VNI %u does not exist\n", vni
);
3224 nbr
= zebra_evpn_neigh_lookup(zevpn
, ip
);
3226 snprintfrr(errmsg
, errmsg_len
,
3227 "Requested host IP does not exist in VNI %u\n", vni
);
3231 ipaddr2str(&nbr
->ip
, buf
, sizeof(buf
));
3233 if (!CHECK_FLAG(nbr
->flags
, ZEBRA_NEIGH_DUPLICATE
)) {
3234 snprintfrr(errmsg
, errmsg_len
,
3235 "Requested host IP %s is not duplicate detected\n",
3240 mac
= zebra_evpn_mac_lookup(zevpn
, &nbr
->emac
);
3242 if (CHECK_FLAG(mac
->flags
, ZEBRA_MAC_DUPLICATE
)) {
3245 "Requested IP's associated MAC %s is still in duplicate state\n",
3246 prefix_mac2str(&nbr
->emac
, buf2
, sizeof(buf2
)));
3250 if (IS_ZEBRA_DEBUG_VXLAN
)
3251 zlog_debug("%s: clear neigh %s in dup state, flags 0x%x seq %u",
3252 __func__
, buf
, nbr
->flags
, nbr
->loc_seq
);
3254 UNSET_FLAG(nbr
->flags
, ZEBRA_NEIGH_DUPLICATE
);
3256 nbr
->detect_start_time
.tv_sec
= 0;
3257 nbr
->detect_start_time
.tv_usec
= 0;
3258 nbr
->dad_dup_detect_time
= 0;
3259 THREAD_OFF(nbr
->dad_ip_auto_recovery_timer
);
3261 if (!!CHECK_FLAG(nbr
->flags
, ZEBRA_NEIGH_LOCAL
)) {
3262 zebra_evpn_neigh_send_add_to_client(zevpn
->vni
, ip
, &nbr
->emac
,
3263 nbr
->mac
, nbr
->flags
,
3265 } else if (!!CHECK_FLAG(nbr
->flags
, ZEBRA_NEIGH_REMOTE
)) {
3266 zebra_evpn_rem_neigh_install(zevpn
, nbr
, false /*was_static*/);
3272 static void zevpn_clear_dup_mac_hash(struct hash_bucket
*bucket
, void *ctxt
)
3274 struct mac_walk_ctx
*wctx
= ctxt
;
3275 struct zebra_mac
*mac
;
3276 struct zebra_evpn
*zevpn
;
3277 struct listnode
*node
= NULL
;
3278 struct zebra_neigh
*nbr
= NULL
;
3280 mac
= (struct zebra_mac
*)bucket
->data
;
3284 zevpn
= wctx
->zevpn
;
3286 if (!CHECK_FLAG(mac
->flags
, ZEBRA_MAC_DUPLICATE
))
3289 UNSET_FLAG(mac
->flags
, ZEBRA_MAC_DUPLICATE
);
3291 mac
->detect_start_time
.tv_sec
= 0;
3292 mac
->detect_start_time
.tv_usec
= 0;
3293 mac
->dad_dup_detect_time
= 0;
3294 THREAD_OFF(mac
->dad_mac_auto_recovery_timer
);
3296 /* Remove all IPs as duplicate associcated with this MAC */
3297 for (ALL_LIST_ELEMENTS_RO(mac
->neigh_list
, node
, nbr
)) {
3298 if (CHECK_FLAG(nbr
->flags
, ZEBRA_NEIGH_LOCAL
)
3300 ZEBRA_NEIGH_SET_INACTIVE(nbr
);
3302 UNSET_FLAG(nbr
->flags
, ZEBRA_NEIGH_DUPLICATE
);
3304 nbr
->detect_start_time
.tv_sec
= 0;
3305 nbr
->dad_dup_detect_time
= 0;
3308 /* Local: Notify Peer VTEPs, Remote: Install the entry */
3309 if (CHECK_FLAG(mac
->flags
, ZEBRA_MAC_LOCAL
)) {
3311 if (zebra_evpn_mac_send_add_to_client(zevpn
->vni
, &mac
->macaddr
,
3312 mac
->flags
, mac
->loc_seq
,
3316 /* Process all neighbors associated with this MAC. */
3317 zebra_evpn_process_neigh_on_local_mac_change(zevpn
, mac
, 0,
3320 } else if (CHECK_FLAG(mac
->flags
, ZEBRA_MAC_REMOTE
)) {
3321 zebra_evpn_process_neigh_on_remote_mac_add(zevpn
, mac
);
3323 /* Install the entry. */
3324 zebra_evpn_rem_mac_install(zevpn
, mac
, false /* was_static */);
3328 static void zevpn_clear_dup_detect_hash_vni_all(struct hash_bucket
*bucket
,
3331 struct zebra_evpn
*zevpn
;
3332 struct zebra_vrf
*zvrf
;
3333 struct mac_walk_ctx m_wctx
;
3334 struct neigh_walk_ctx n_wctx
;
3336 zevpn
= (struct zebra_evpn
*)bucket
->data
;
3340 zvrf
= (struct zebra_vrf
*)args
[0];
3342 if (hashcount(zevpn
->neigh_table
)) {
3343 memset(&n_wctx
, 0, sizeof(n_wctx
));
3344 n_wctx
.zevpn
= zevpn
;
3346 hash_iterate(zevpn
->neigh_table
,
3347 zebra_evpn_clear_dup_neigh_hash
, &n_wctx
);
3350 if (num_valid_macs(zevpn
)) {
3351 memset(&m_wctx
, 0, sizeof(m_wctx
));
3352 m_wctx
.zevpn
= zevpn
;
3354 hash_iterate(zevpn
->mac_table
, zevpn_clear_dup_mac_hash
, &m_wctx
);
3359 int zebra_vxlan_clear_dup_detect_vni_all(struct zebra_vrf
*zvrf
)
3363 if (!is_evpn_enabled())
3368 hash_iterate(zvrf
->evpn_table
,
3369 (void (*)(struct hash_bucket
*, void *))
3370 zevpn_clear_dup_detect_hash_vni_all
, args
);
3375 int zebra_vxlan_clear_dup_detect_vni(struct zebra_vrf
*zvrf
, vni_t vni
)
3377 struct zebra_evpn
*zevpn
;
3378 struct mac_walk_ctx m_wctx
;
3379 struct neigh_walk_ctx n_wctx
;
3381 if (!is_evpn_enabled())
3384 zevpn
= zebra_evpn_lookup(vni
);
3386 zlog_warn("VNI %u does not exist", vni
);
3390 if (hashcount(zevpn
->neigh_table
)) {
3391 memset(&n_wctx
, 0, sizeof(n_wctx
));
3392 n_wctx
.zevpn
= zevpn
;
3394 hash_iterate(zevpn
->neigh_table
,
3395 zebra_evpn_clear_dup_neigh_hash
, &n_wctx
);
3398 if (num_valid_macs(zevpn
)) {
3399 memset(&m_wctx
, 0, sizeof(m_wctx
));
3400 m_wctx
.zevpn
= zevpn
;
3402 hash_iterate(zevpn
->mac_table
, zevpn_clear_dup_mac_hash
, &m_wctx
);
3409 * Display MACs for a VNI from specific VTEP (VTY command handler).
3411 void zebra_vxlan_print_macs_vni_vtep(struct vty
*vty
, struct zebra_vrf
*zvrf
,
3412 vni_t vni
, struct in_addr vtep_ip
,
3415 struct zebra_evpn
*zevpn
;
3417 struct mac_walk_ctx wctx
;
3418 json_object
*json
= NULL
;
3419 json_object
*json_mac
= NULL
;
3421 if (!is_evpn_enabled())
3423 zevpn
= zebra_evpn_lookup(vni
);
3426 vty_out(vty
, "{}\n");
3428 vty_out(vty
, "%% VNI %u does not exist\n", vni
);
3431 num_macs
= num_valid_macs(zevpn
);
3436 json
= json_object_new_object();
3437 json_mac
= json_object_new_object();
3440 memset(&wctx
, 0, sizeof(wctx
));
3443 wctx
.flags
= SHOW_REMOTE_MAC_FROM_VTEP
;
3444 wctx
.r_vtep_ip
= vtep_ip
;
3445 wctx
.json
= json_mac
;
3446 hash_iterate(zevpn
->mac_table
, zebra_evpn_print_mac_hash
, &wctx
);
3449 json_object_int_add(json
, "numMacs", wctx
.count
);
3451 json_object_object_add(json
, "macs", json_mac
);
3452 vty_json(vty
, json
);
3458 * Display VNI information (VTY command handler).
3460 * use_json flag indicates that output should be in JSON format.
3461 * json_array is non NULL when JSON output needs to be aggregated (by the
3462 * caller) and then printed, otherwise, JSON evpn vni info is printed
3465 void zebra_vxlan_print_vni(struct vty
*vty
, struct zebra_vrf
*zvrf
, vni_t vni
,
3466 bool use_json
, json_object
*json_array
)
3468 json_object
*json
= NULL
;
3470 struct zebra_l3vni
*zl3vni
= NULL
;
3471 struct zebra_evpn
*zevpn
= NULL
;
3473 if (!is_evpn_enabled())
3477 json
= json_object_new_object();
3482 zl3vni
= zl3vni_lookup(vni
);
3484 zl3vni_print(zl3vni
, (void *)args
);
3486 zevpn
= zebra_evpn_lookup(vni
);
3488 zebra_evpn_print(zevpn
, (void *)args
);
3490 vty_out(vty
, "%% VNI %u does not exist\n", vni
);
3495 * Each "json" object contains info about 1 VNI.
3496 * When "json_array" is non-null, we aggreggate the json output
3497 * into json_array and print it as a JSON array.
3500 json_object_array_add(json_array
, json
);
3502 vty_json(vty
, json
);
3506 /* Display all global details for EVPN */
3507 void zebra_vxlan_print_evpn(struct vty
*vty
, bool uj
)
3512 json_object
*json
= NULL
;
3513 struct zebra_vrf
*zvrf
= NULL
;
3515 if (!is_evpn_enabled())
3518 zvrf
= zebra_vrf_get_evpn();
3520 num_l3vnis
= hashcount(zrouter
.l3vni_table
);
3521 num_l2vnis
= hashcount(zvrf
->evpn_table
);
3522 num_vnis
= num_l2vnis
+ num_l3vnis
;
3525 json
= json_object_new_object();
3526 json_object_string_add(json
, "advertiseGatewayMacip",
3527 zvrf
->advertise_gw_macip
? "Yes" : "No");
3528 json_object_string_add(json
, "advertiseSviMacip",
3529 zvrf
->advertise_svi_macip
? "Yes"
3531 json_object_string_add(json
, "advertiseSviMac",
3532 zebra_evpn_mh_do_adv_svi_mac() ? "Yes"
3534 json_object_int_add(json
, "numVnis", num_vnis
);
3535 json_object_int_add(json
, "numL2Vnis", num_l2vnis
);
3536 json_object_int_add(json
, "numL3Vnis", num_l3vnis
);
3537 if (zebra_evpn_do_dup_addr_detect(zvrf
))
3538 json_object_boolean_true_add(json
,
3539 "isDuplicateAddrDetection");
3541 json_object_boolean_false_add(json
,
3542 "isDuplicateAddrDetection");
3543 json_object_int_add(json
, "maxMoves", zvrf
->dad_max_moves
);
3544 json_object_int_add(json
, "detectionTime", zvrf
->dad_time
);
3545 json_object_int_add(json
, "detectionFreezeTime",
3546 zvrf
->dad_freeze_time
);
3547 zebra_evpn_mh_json(json
);
3549 vty_out(vty
, "L2 VNIs: %u\n", num_l2vnis
);
3550 vty_out(vty
, "L3 VNIs: %u\n", num_l3vnis
);
3551 vty_out(vty
, "Advertise gateway mac-ip: %s\n",
3552 zvrf
->advertise_gw_macip
? "Yes" : "No");
3553 vty_out(vty
, "Advertise svi mac-ip: %s\n",
3554 zvrf
->advertise_svi_macip
? "Yes" : "No");
3555 vty_out(vty
, "Advertise svi mac: %s\n",
3556 zebra_evpn_mh_do_adv_svi_mac() ? "Yes" : "No");
3557 vty_out(vty
, "Duplicate address detection: %s\n",
3558 zebra_evpn_do_dup_addr_detect(zvrf
) ? "Enable"
3560 vty_out(vty
, " Detection max-moves %u, time %d\n",
3561 zvrf
->dad_max_moves
, zvrf
->dad_time
);
3562 if (zvrf
->dad_freeze
) {
3563 if (zvrf
->dad_freeze_time
)
3564 vty_out(vty
, " Detection freeze %u\n",
3565 zvrf
->dad_freeze_time
);
3567 vty_out(vty
, " Detection freeze %s\n",
3570 zebra_evpn_mh_print(vty
);
3574 vty_json(vty
, json
);
3578 * Display VNI hash table (VTY command handler).
3580 void zebra_vxlan_print_vnis(struct vty
*vty
, struct zebra_vrf
*zvrf
,
3583 json_object
*json
= NULL
;
3586 if (!is_evpn_enabled())
3590 json
= json_object_new_object();
3592 vty_out(vty
, "%-10s %-4s %-21s %-8s %-8s %-15s %-37s\n", "VNI",
3593 "Type", "VxLAN IF", "# MACs", "# ARPs",
3594 "# Remote VTEPs", "Tenant VRF");
3599 /* Display all L2-VNIs */
3602 (void (*)(struct hash_bucket
*, void *))zebra_evpn_print_hash
,
3605 /* Display all L3-VNIs */
3606 hash_iterate(zrouter
.l3vni_table
,
3607 (void (*)(struct hash_bucket
*, void *))zl3vni_print_hash
,
3611 vty_json(vty
, json
);
3614 void zebra_vxlan_dup_addr_detection(ZAPI_HANDLER_ARGS
)
3618 uint32_t max_moves
= 0;
3619 uint32_t freeze_time
= 0;
3620 bool dup_addr_detect
= false;
3621 bool freeze
= false;
3622 bool old_addr_detect
;
3625 STREAM_GETL(s
, dup_addr_detect
);
3626 STREAM_GETL(s
, time
);
3627 STREAM_GETL(s
, max_moves
);
3628 STREAM_GETL(s
, freeze
);
3629 STREAM_GETL(s
, freeze_time
);
3631 old_addr_detect
= zebra_evpn_do_dup_addr_detect(zvrf
);
3632 zvrf
->dup_addr_detect
= dup_addr_detect
;
3633 dup_addr_detect
= zebra_evpn_do_dup_addr_detect(zvrf
);
3635 /* DAD previous state was enabled, and new state is disable,
3636 * clear all duplicate detected addresses.
3638 if (old_addr_detect
&& !dup_addr_detect
)
3639 zebra_vxlan_clear_dup_detect_vni_all(zvrf
);
3641 zvrf
->dad_time
= time
;
3642 zvrf
->dad_max_moves
= max_moves
;
3643 zvrf
->dad_freeze
= freeze
;
3644 zvrf
->dad_freeze_time
= freeze_time
;
3646 if (IS_ZEBRA_DEBUG_VXLAN
)
3648 "VRF %s duplicate detect %s max_moves %u timeout %u freeze %s freeze_time %u",
3649 vrf_id_to_name(zvrf
->vrf
->vrf_id
),
3650 dup_addr_detect
? "enable" : "disable",
3651 zvrf
->dad_max_moves
, zvrf
->dad_time
,
3652 zvrf
->dad_freeze
? "enable" : "disable",
3653 zvrf
->dad_freeze_time
);
3660 * Display VNI hash table in detail(VTY command handler).
3662 void zebra_vxlan_print_vnis_detail(struct vty
*vty
, struct zebra_vrf
*zvrf
,
3665 json_object
*json_array
= NULL
;
3666 struct zebra_ns
*zns
= NULL
;
3667 struct zebra_evpn_show zes
;
3669 if (!is_evpn_enabled())
3672 zns
= zebra_ns_lookup(NS_DEFAULT
);
3677 json_array
= json_object_new_array();
3680 zes
.json
= json_array
;
3682 zes
.use_json
= use_json
;
3684 /* Display all L2-VNIs */
3685 hash_iterate(zvrf
->evpn_table
,
3686 (void (*)(struct hash_bucket
*,
3687 void *))zebra_evpn_print_hash_detail
,
3690 /* Display all L3-VNIs */
3691 hash_iterate(zrouter
.l3vni_table
,
3692 (void (*)(struct hash_bucket
*,
3693 void *))zl3vni_print_hash_detail
,
3697 vty_json(vty
, json_array
);
3701 * Handle neighbor delete notification from the kernel (on a VLAN device
3702 * / L3 interface). This may result in either the neighbor getting deleted
3703 * from our database or being re-added to the kernel (if it is a valid
3706 int zebra_vxlan_handle_kernel_neigh_del(struct interface
*ifp
,
3707 struct interface
*link_if
,
3710 struct zebra_evpn
*zevpn
= NULL
;
3711 struct zebra_l3vni
*zl3vni
= NULL
;
3713 /* check if this is a remote neigh entry corresponding to remote
3716 zl3vni
= zl3vni_from_svi(ifp
, link_if
);
3718 return zl3vni_local_nh_del(zl3vni
, ip
);
3720 /* We are only interested in neighbors on an SVI that resides on top
3721 * of a VxLAN bridge.
3723 zevpn
= zebra_evpn_from_svi(ifp
, link_if
);
3725 if (IS_ZEBRA_DEBUG_VXLAN
)
3727 "%s: Del neighbor %pIA EVPN is not present for interface %s",
3728 __func__
, ip
, ifp
->name
);
3732 if (!zevpn
->vxlan_if
) {
3734 "VNI %u hash %p doesn't have intf upon local neighbor DEL",
3739 if (IS_ZEBRA_DEBUG_VXLAN
)
3740 zlog_debug("Del neighbor %pIA intf %s(%u) -> L2-VNI %u",
3741 ip
, ifp
->name
, ifp
->ifindex
, zevpn
->vni
);
3743 return zebra_evpn_neigh_del_ip(zevpn
, ip
);
3747 * Handle neighbor add or update notification from the kernel (on a VLAN
3748 * device / L3 interface). This is typically for a local neighbor but can
3749 * also be for a remote neighbor (e.g., ageout notification). It could
3750 * also be a "move" scenario.
3752 int zebra_vxlan_handle_kernel_neigh_update(struct interface
*ifp
,
3753 struct interface
*link_if
,
3755 struct ethaddr
*macaddr
,
3759 bool local_inactive
, bool dp_static
)
3761 struct zebra_evpn
*zevpn
= NULL
;
3762 struct zebra_l3vni
*zl3vni
= NULL
;
3764 /* check if this is a remote neigh entry corresponding to remote
3767 zl3vni
= zl3vni_from_svi(ifp
, link_if
);
3769 return zl3vni_local_nh_add_update(zl3vni
, ip
, state
);
3771 /* We are only interested in neighbors on an SVI that resides on top
3772 * of a VxLAN bridge.
3774 zevpn
= zebra_evpn_from_svi(ifp
, link_if
);
3778 if (IS_ZEBRA_DEBUG_VXLAN
|| IS_ZEBRA_DEBUG_EVPN_MH_NEIGH
)
3780 "Add/Update neighbor %pIA MAC %pEA intf %s(%u) state 0x%x %s%s%s%s-> L2-VNI %u",
3781 ip
, macaddr
, ifp
->name
,
3782 ifp
->ifindex
, state
, is_ext
? "ext-learned " : "",
3783 is_router
? "router " : "",
3784 local_inactive
? "local_inactive " : "",
3785 dp_static
? "peer_sync " : "", zevpn
->vni
);
3787 /* Is this about a local neighbor or a remote one? */
3789 return zebra_evpn_local_neigh_update(zevpn
, ifp
, ip
, macaddr
,
3790 is_router
, local_inactive
,
3793 return zebra_evpn_remote_neigh_update(zevpn
, ifp
, ip
, macaddr
, state
);
3797 zebra_vxlan_remote_macip_helper(bool add
, struct stream
*s
, vni_t
*vni
,
3798 struct ethaddr
*macaddr
, uint16_t *ipa_len
,
3799 struct ipaddr
*ip
, struct in_addr
*vtep_ip
,
3800 uint8_t *flags
, uint32_t *seq
, esi_t
*esi
)
3805 * Obtain each remote MACIP and process.
3806 * Message contains VNI, followed by MAC followed by IP (if any)
3807 * followed by remote VTEP IP.
3809 memset(ip
, 0, sizeof(*ip
));
3810 STREAM_GETL(s
, *vni
);
3811 STREAM_GET(macaddr
->octet
, s
, ETH_ALEN
);
3812 STREAM_GETW(s
, *ipa_len
);
3815 if (*ipa_len
== IPV4_MAX_BYTELEN
)
3816 ip
->ipa_type
= IPADDR_V4
;
3817 else if (*ipa_len
== IPV6_MAX_BYTELEN
)
3818 ip
->ipa_type
= IPADDR_V6
;
3820 if (IS_ZEBRA_DEBUG_VXLAN
)
3822 "ipa_len *must* be %d or %d bytes in length not %d",
3823 IPV4_MAX_BYTELEN
, IPV6_MAX_BYTELEN
,
3825 goto stream_failure
;
3828 STREAM_GET(&ip
->ip
.addr
, s
, *ipa_len
);
3830 l
+= 4 + ETH_ALEN
+ 4 + *ipa_len
;
3831 STREAM_GET(&vtep_ip
->s_addr
, s
, IPV4_MAX_BYTELEN
);
3832 l
+= IPV4_MAX_BYTELEN
;
3835 STREAM_GETC(s
, *flags
);
3836 STREAM_GETL(s
, *seq
);
3838 STREAM_GET(esi
, s
, sizeof(esi_t
));
3849 * Handle message from client to delete a remote MACIP for a VNI.
3851 void zebra_vxlan_remote_macip_del(ZAPI_HANDLER_ARGS
)
3855 struct ethaddr macaddr
;
3857 struct in_addr vtep_ip
;
3858 uint16_t l
= 0, ipa_len
;
3859 char buf1
[INET6_ADDRSTRLEN
];
3863 while (l
< hdr
->length
) {
3864 int res_length
= zebra_vxlan_remote_macip_helper(
3865 false, s
, &vni
, &macaddr
, &ipa_len
, &ip
, &vtep_ip
, NULL
,
3868 if (res_length
== -1)
3869 goto stream_failure
;
3872 if (IS_ZEBRA_DEBUG_VXLAN
)
3874 "Recv MACIP DEL VNI %u MAC %pEA%s%s Remote VTEP %pI4 from %s",
3876 ipa_len
? " IP " : "",
3878 ipaddr2str(&ip
, buf1
, sizeof(buf1
)) : "",
3879 &vtep_ip
, zebra_route_string(client
->proto
));
3881 /* Enqueue to workqueue for processing */
3882 zebra_rib_queue_evpn_rem_macip_del(vni
, &macaddr
, &ip
, vtep_ip
);
3890 * Handle message from client to add a remote MACIP for a VNI. This
3891 * could be just the add of a MAC address or the add of a neighbor
3894 void zebra_vxlan_remote_macip_add(ZAPI_HANDLER_ARGS
)
3898 struct ethaddr macaddr
;
3900 struct in_addr vtep_ip
;
3901 uint16_t l
= 0, ipa_len
;
3904 char buf1
[INET6_ADDRSTRLEN
];
3906 char esi_buf
[ESI_STR_LEN
];
3908 if (!EVPN_ENABLED(zvrf
)) {
3909 zlog_debug("EVPN not enabled, ignoring remote MACIP ADD");
3915 while (l
< hdr
->length
) {
3917 int res_length
= zebra_vxlan_remote_macip_helper(
3918 true, s
, &vni
, &macaddr
, &ipa_len
, &ip
, &vtep_ip
,
3919 &flags
, &seq
, &esi
);
3921 if (res_length
== -1)
3922 goto stream_failure
;
3925 if (IS_ZEBRA_DEBUG_VXLAN
) {
3926 if (memcmp(&esi
, zero_esi
, sizeof(esi_t
)))
3927 esi_to_str(&esi
, esi_buf
, sizeof(esi_buf
));
3929 strlcpy(esi_buf
, "-", ESI_STR_LEN
);
3931 "Recv %sMACIP ADD VNI %u MAC %pEA%s%s flags 0x%x seq %u VTEP %pI4 ESI %s from %s",
3932 (flags
& ZEBRA_MACIP_TYPE_SYNC_PATH
) ?
3935 ipa_len
? " IP " : "",
3937 ipaddr2str(&ip
, buf1
, sizeof(buf1
)) : "",
3938 flags
, seq
, &vtep_ip
, esi_buf
,
3939 zebra_route_string(client
->proto
));
3942 /* Enqueue to workqueue for processing */
3943 zebra_rib_queue_evpn_rem_macip_add(vni
, &macaddr
, &ip
, flags
,
3944 seq
, vtep_ip
, &esi
);
3952 * Handle remote vtep delete by kernel; re-add the vtep if we have it
3954 int zebra_vxlan_check_readd_vtep(struct interface
*ifp
, vni_t vni
,
3955 struct in_addr vtep_ip
)
3957 struct zebra_if
*zif
;
3958 struct zebra_vrf
*zvrf
= NULL
;
3959 struct zebra_evpn
*zevpn
= NULL
;
3960 struct zebra_vtep
*zvtep
= NULL
;
3961 struct zebra_vxlan_vni
*vnip
;
3966 /* If EVPN is not enabled, nothing to do. */
3967 if (!is_evpn_enabled())
3970 /* Locate VRF corresponding to interface. */
3971 zvrf
= ifp
->vrf
->info
;
3975 vnip
= zebra_vxlan_if_vni_find(zif
, vni
);
3979 /* Locate hash entry; it is expected to exist. */
3980 zevpn
= zebra_evpn_lookup(vni
);
3984 /* If the remote vtep entry doesn't exists nothing to do */
3985 zvtep
= zebra_evpn_vtep_find(zevpn
, &vtep_ip
);
3989 if (IS_ZEBRA_DEBUG_VXLAN
)
3991 "Del MAC for remote VTEP %pI4 intf %s(%u) VNI %u - readd",
3992 &vtep_ip
, ifp
->name
, ifp
->ifindex
, vni
);
3994 zebra_evpn_vtep_install(zevpn
, zvtep
);
3999 * Handle notification of MAC add/update over VxLAN. If the kernel is notifying
4000 * us, this must involve a multihoming scenario. Treat this as implicit delete
4001 * of any prior local MAC.
4003 static int zebra_vxlan_check_del_local_mac(struct interface
*ifp
,
4004 struct interface
*br_if
,
4005 struct ethaddr
*macaddr
,
4006 vlanid_t vid
, vni_t vni
)
4008 struct zebra_if
*zif
;
4009 struct zebra_evpn
*zevpn
;
4010 struct zebra_mac
*mac
;
4015 /* Check if EVPN is enabled. */
4016 if (!is_evpn_enabled())
4019 /* Locate hash entry; it is expected to exist. */
4020 zevpn
= zebra_evpn_lookup(vni
);
4024 /* If entry doesn't exist, nothing to do. */
4025 mac
= zebra_evpn_mac_lookup(zevpn
, macaddr
);
4029 /* Is it a local entry? */
4030 if (!CHECK_FLAG(mac
->flags
, ZEBRA_MAC_LOCAL
))
4033 if (IS_ZEBRA_DEBUG_VXLAN
)
4035 "Add/update remote MAC %pEA intf %s(%u) VNI %u flags 0x%x - del local",
4036 macaddr
, ifp
->name
, ifp
->ifindex
, vni
, mac
->flags
);
4038 /* Remove MAC from BGP. */
4039 zebra_evpn_mac_send_del_to_client(zevpn
->vni
, macaddr
, mac
->flags
,
4043 * If there are no neigh associated with the mac delete the mac
4044 * else mark it as AUTO for forward reference
4046 if (!listcount(mac
->neigh_list
)) {
4047 zebra_evpn_mac_del(zevpn
, mac
);
4049 zebra_evpn_mac_clear_fwd_info(mac
);
4050 UNSET_FLAG(mac
->flags
, ZEBRA_MAC_ALL_LOCAL_FLAGS
);
4051 UNSET_FLAG(mac
->flags
, ZEBRA_MAC_STICKY
);
4052 SET_FLAG(mac
->flags
, ZEBRA_MAC_AUTO
);
4058 /* MAC notification from the dataplane with a network dest port -
4059 * 1. This can be a local MAC on a down ES (if fast-failover is not possible
4060 * 2. Or it can be a remote MAC
4062 int zebra_vxlan_dp_network_mac_add(struct interface
*ifp
,
4063 struct interface
*br_if
,
4064 struct ethaddr
*macaddr
, vlanid_t vid
,
4065 vni_t vni
, uint32_t nhg_id
, bool sticky
,
4068 struct zebra_evpn_es
*es
;
4069 struct interface
*acc_ifp
;
4071 /* If netlink message is with vid, it will have no nexthop.
4075 if (IS_ZEBRA_DEBUG_VXLAN
|| IS_ZEBRA_DEBUG_EVPN_MH_MAC
)
4076 zlog_debug("dpAdd MAC %pEA VID %u - ignore as no nhid",
4081 /* Get vxlan's vid for netlink message has no it. */
4082 vid
= ((struct zebra_if
*)ifp
->info
)->l2info
.vxl
.access_vlan
;
4084 /* if remote mac delete the local entry */
4085 if (!nhg_id
|| !zebra_evpn_nhg_is_local_es(nhg_id
, &es
)
4086 || !zebra_evpn_es_local_mac_via_network_port(es
)) {
4087 if (IS_ZEBRA_DEBUG_VXLAN
|| IS_ZEBRA_DEBUG_EVPN_MH_MAC
)
4088 zlog_debug("dpAdd remote MAC %pEA VID %u", macaddr
,
4090 return zebra_vxlan_check_del_local_mac(ifp
, br_if
, macaddr
, vid
,
4094 /* If local MAC on a down local ES translate the network-mac-add
4095 * to a local-active-mac-add
4097 if (IS_ZEBRA_DEBUG_VXLAN
|| IS_ZEBRA_DEBUG_EVPN_MH_MAC
)
4098 zlog_debug("dpAdd local-nw-MAC %pEA VID %u", macaddr
, vid
);
4099 acc_ifp
= es
->zif
->ifp
;
4100 return zebra_vxlan_local_mac_add_update(
4101 acc_ifp
, br_if
, macaddr
, vid
, sticky
,
4102 false /* local_inactive */, dp_static
);
4106 * Handle network MAC delete by kernel -
4107 * 1. readd the remote MAC if we have it
4108 * 2. local MAC with does ES may also need to be re-installed
4110 int zebra_vxlan_dp_network_mac_del(struct interface
*ifp
,
4111 struct interface
*br_if
,
4112 struct ethaddr
*macaddr
, vlanid_t vid
,
4115 struct zebra_if
*zif
= NULL
;
4116 struct zebra_evpn
*zevpn
= NULL
;
4117 struct zebra_l3vni
*zl3vni
= NULL
;
4118 struct zebra_mac
*mac
= NULL
;
4123 /* Check if EVPN is enabled. */
4124 if (!is_evpn_enabled())
4127 /* check if this is a remote RMAC and readd simillar to remote macs */
4128 zl3vni
= zl3vni_lookup(vni
);
4130 return zebra_vxlan_readd_remote_rmac(zl3vni
, macaddr
);
4132 /* Locate hash entry; it is expected to exist. */
4133 zevpn
= zebra_evpn_lookup(vni
);
4137 /* If entry doesn't exist, nothing to do. */
4138 mac
= zebra_evpn_mac_lookup(zevpn
, macaddr
);
4142 if (CHECK_FLAG(mac
->flags
, ZEBRA_MAC_REMOTE
)) {
4143 /* If remote entry simply re-install */
4144 if (IS_ZEBRA_DEBUG_VXLAN
|| IS_ZEBRA_DEBUG_EVPN_MH_MAC
)
4146 "dpDel remote MAC %pEA intf %s(%u) VNI %u - readd",
4147 macaddr
, ifp
->name
, ifp
->ifindex
, vni
);
4148 zebra_evpn_rem_mac_install(zevpn
, mac
, false /* was_static */);
4149 } else if (CHECK_FLAG(mac
->flags
, ZEBRA_MAC_LOCAL
) && mac
->es
4150 && zebra_evpn_es_local_mac_via_network_port(mac
->es
)) {
4151 /* If local entry via nw-port call local-del which will
4152 * re-install entry in the dataplane is needed
4154 if (IS_ZEBRA_DEBUG_VXLAN
|| IS_ZEBRA_DEBUG_EVPN_MH_MAC
)
4155 zlog_debug("dpDel local-nw-MAC %pEA VNI %u", macaddr
,
4158 zebra_evpn_del_local_mac(zevpn
, mac
, false);
4165 * Handle local MAC delete (on a port or VLAN corresponding to this VNI).
4167 int zebra_vxlan_local_mac_del(struct interface
*ifp
, struct interface
*br_if
,
4168 struct ethaddr
*macaddr
, vlanid_t vid
)
4170 struct zebra_evpn
*zevpn
;
4171 struct zebra_mac
*mac
;
4173 /* We are interested in MACs only on ports or (port, VLAN) that
4176 zevpn
= zebra_evpn_map_vlan(ifp
, br_if
, vid
);
4179 if (!zevpn
->vxlan_if
) {
4181 "VNI %u hash %p doesn't have intf upon local MAC DEL",
4186 /* If entry doesn't exist, nothing to do. */
4187 mac
= zebra_evpn_mac_lookup(zevpn
, macaddr
);
4191 /* Is it a local entry? */
4192 if (!CHECK_FLAG(mac
->flags
, ZEBRA_MAC_LOCAL
))
4195 return zebra_evpn_del_local_mac(zevpn
, mac
, false);
4199 * Handle local MAC add (on a port or VLAN corresponding to this VNI).
4201 int zebra_vxlan_local_mac_add_update(struct interface
*ifp
,
4202 struct interface
*br_if
,
4203 struct ethaddr
*macaddr
, vlanid_t vid
,
4204 bool sticky
, bool local_inactive
,
4207 struct zebra_evpn
*zevpn
;
4208 struct zebra_vrf
*zvrf
;
4212 /* We are interested in MACs only on ports or (port, VLAN) that
4215 zevpn
= zebra_evpn_map_vlan(ifp
, br_if
, vid
);
4217 if (IS_ZEBRA_DEBUG_VXLAN
)
4219 " Add/Update %sMAC %pEA intf %s(%u) VID %u, could not find EVPN",
4220 sticky
? "sticky " : "", macaddr
,
4221 ifp
->name
, ifp
->ifindex
, vid
);
4225 if (!zevpn
->vxlan_if
) {
4226 if (IS_ZEBRA_DEBUG_VXLAN
)
4228 " VNI %u hash %p doesn't have intf upon local MAC ADD",
4233 zvrf
= zebra_vrf_get_evpn();
4234 return zebra_evpn_add_update_local_mac(zvrf
, zevpn
, ifp
, macaddr
, vid
,
4235 sticky
, local_inactive
,
4240 * Handle message from client to delete a remote VTEP for an EVPN.
4242 void zebra_vxlan_remote_vtep_del_zapi(ZAPI_HANDLER_ARGS
)
4245 unsigned short l
= 0;
4247 struct in_addr vtep_ip
;
4249 if (!is_evpn_enabled()) {
4251 "%s: EVPN is not enabled yet we have received a VTEP DEL msg",
4256 if (!EVPN_ENABLED(zvrf
)) {
4257 zlog_debug("Recv VTEP DEL zapi for non-EVPN VRF %u",
4264 while (l
< hdr
->length
) {
4265 int flood_control
__attribute__((unused
));
4267 /* Obtain each remote VTEP and process. */
4268 STREAM_GETL(s
, vni
);
4270 STREAM_GET(&vtep_ip
.s_addr
, s
, IPV4_MAX_BYTELEN
);
4271 l
+= IPV4_MAX_BYTELEN
;
4273 /* Flood control is intentionally ignored right now */
4274 STREAM_GETL(s
, flood_control
);
4277 if (IS_ZEBRA_DEBUG_VXLAN
)
4278 zlog_debug("Recv VTEP DEL %pI4 VNI %u from %s",
4280 zebra_route_string(client
->proto
));
4282 /* Enqueue for processing */
4283 zebra_rib_queue_evpn_rem_vtep_del(zvrf_id(zvrf
), vni
, vtep_ip
);
4291 * Handle message from client to delete a remote VTEP for an EVPN.
4293 void zebra_vxlan_remote_vtep_del(vrf_id_t vrf_id
, vni_t vni
,
4294 struct in_addr vtep_ip
)
4296 struct zebra_evpn
*zevpn
;
4297 struct zebra_vtep
*zvtep
;
4298 struct interface
*ifp
;
4299 struct zebra_if
*zif
;
4300 struct zebra_vrf
*zvrf
;
4302 if (!is_evpn_enabled()) {
4303 zlog_debug("%s: Can't process vtep del: EVPN is not enabled",
4308 zvrf
= zebra_vrf_lookup_by_id(vrf_id
);
4312 if (!EVPN_ENABLED(zvrf
)) {
4313 zlog_debug("Can't process VTEP DEL for non-EVPN VRF %u",
4318 /* Locate VNI hash entry - expected to exist. */
4319 zevpn
= zebra_evpn_lookup(vni
);
4321 if (IS_ZEBRA_DEBUG_VXLAN
)
4323 "Failed to locate VNI hash for remote VTEP DEL, VNI %u",
4328 ifp
= zevpn
->vxlan_if
;
4331 "VNI %u hash %p doesn't have intf upon remote VTEP DEL",
4337 /* If down or not mapped to a bridge, we're done. */
4338 if (!if_is_operative(ifp
) || !zif
->brslave_info
.br_if
)
4341 /* If the remote VTEP does not exist, there's nothing more to
4343 * Otherwise, uninstall any remote MACs pointing to this VTEP
4344 * and then, the VTEP entry itself and remove it.
4346 zvtep
= zebra_evpn_vtep_find(zevpn
, &vtep_ip
);
4350 zebra_evpn_vtep_uninstall(zevpn
, &vtep_ip
);
4351 zebra_evpn_vtep_del(zevpn
, zvtep
);
4355 * Handle message from client to add a remote VTEP for an EVPN.
4357 void zebra_vxlan_remote_vtep_add(vrf_id_t vrf_id
, vni_t vni
,
4358 struct in_addr vtep_ip
, int flood_control
)
4360 struct zebra_evpn
*zevpn
;
4361 struct interface
*ifp
;
4362 struct zebra_if
*zif
;
4363 struct zebra_vtep
*zvtep
;
4364 struct zebra_vrf
*zvrf
;
4366 if (!is_evpn_enabled()) {
4367 zlog_debug("%s: EVPN not enabled: can't process a VTEP ADD",
4372 zvrf
= zebra_vrf_lookup_by_id(vrf_id
);
4376 if (!EVPN_ENABLED(zvrf
)) {
4377 zlog_debug("Can't process VTEP ADD for non-EVPN VRF %u",
4382 /* Locate VNI hash entry - expected to exist. */
4383 zevpn
= zebra_evpn_lookup(vni
);
4386 EC_ZEBRA_VTEP_ADD_FAILED
,
4387 "Failed to locate EVPN hash upon remote VTEP ADD, VNI %u",
4392 ifp
= zevpn
->vxlan_if
;
4395 EC_ZEBRA_VTEP_ADD_FAILED
,
4396 "VNI %u hash %p doesn't have intf upon remote VTEP ADD",
4403 /* If down or not mapped to a bridge, we're done. */
4404 if (!if_is_operative(ifp
) || !zif
->brslave_info
.br_if
)
4407 zvtep
= zebra_evpn_vtep_find(zevpn
, &vtep_ip
);
4409 /* If the remote VTEP already exists check if
4410 * the flood mode has changed
4412 if (zvtep
->flood_control
!= flood_control
) {
4413 if (zvtep
->flood_control
== VXLAN_FLOOD_DISABLED
)
4414 /* old mode was head-end-replication but
4415 * is no longer; get rid of the HER fdb
4416 * entry installed before
4418 zebra_evpn_vtep_uninstall(zevpn
, &vtep_ip
);
4419 zvtep
->flood_control
= flood_control
;
4420 zebra_evpn_vtep_install(zevpn
, zvtep
);
4423 zvtep
= zebra_evpn_vtep_add(zevpn
, &vtep_ip
, flood_control
);
4425 zebra_evpn_vtep_install(zevpn
, zvtep
);
4427 flog_err(EC_ZEBRA_VTEP_ADD_FAILED
,
4428 "Failed to add remote VTEP, VNI %u zevpn %p",
4434 * Handle message from client to add a remote VTEP for an EVPN.
4436 void zebra_vxlan_remote_vtep_add_zapi(ZAPI_HANDLER_ARGS
)
4439 unsigned short l
= 0;
4441 struct in_addr vtep_ip
;
4444 if (!is_evpn_enabled()) {
4446 "%s: EVPN not enabled yet we received a VTEP ADD zapi msg",
4451 if (!EVPN_ENABLED(zvrf
)) {
4452 zlog_debug("Recv VTEP ADD zapi for non-EVPN VRF %u",
4459 while (l
< hdr
->length
) {
4460 /* Obtain each remote VTEP and process. */
4461 STREAM_GETL(s
, vni
);
4463 STREAM_GET(&vtep_ip
.s_addr
, s
, IPV4_MAX_BYTELEN
);
4464 STREAM_GETL(s
, flood_control
);
4465 l
+= IPV4_MAX_BYTELEN
+ 4;
4467 if (IS_ZEBRA_DEBUG_VXLAN
)
4468 zlog_debug("Recv VTEP ADD %pI4 VNI %u flood %d from %s",
4469 &vtep_ip
, vni
, flood_control
,
4470 zebra_route_string(client
->proto
));
4472 /* Enqueue for processing */
4473 zebra_rib_queue_evpn_rem_vtep_add(zvrf_id(zvrf
), vni
, vtep_ip
,
4482 * Add/Del gateway macip to evpn
4484 * 1. SVI interface on a vlan aware bridge
4485 * 2. SVI interface on a vlan unaware bridge
4486 * 3. vrr interface (MACVLAN) associated to a SVI
4487 * We advertise macip routes for an interface if it is associated to VxLan vlan
4489 int zebra_vxlan_add_del_gw_macip(struct interface
*ifp
, const struct prefix
*p
,
4493 struct ethaddr macaddr
;
4494 struct zebra_evpn
*zevpn
= NULL
;
4496 memset(&ip
, 0, sizeof(ip
));
4497 memset(&macaddr
, 0, sizeof(macaddr
));
4499 /* Check if EVPN is enabled. */
4500 if (!is_evpn_enabled())
4503 if (IS_ZEBRA_IF_MACVLAN(ifp
)) {
4504 struct interface
*svi_if
=
4505 NULL
; /* SVI corresponding to the MACVLAN */
4506 struct zebra_if
*ifp_zif
=
4507 NULL
; /* Zebra daemon specific info for MACVLAN */
4508 struct zebra_if
*svi_if_zif
=
4509 NULL
; /* Zebra daemon specific info for SVI*/
4511 ifp_zif
= ifp
->info
;
4516 * for a MACVLAN interface the link represents the svi_if
4518 svi_if
= if_lookup_by_index_per_ns(zebra_ns_lookup(NS_DEFAULT
),
4519 ifp_zif
->link_ifindex
);
4521 zlog_debug("MACVLAN %s(%u) without link information",
4522 ifp
->name
, ifp
->ifindex
);
4526 if (IS_ZEBRA_IF_VLAN(svi_if
)) {
4528 * If it is a vlan aware bridge then the link gives the
4529 * bridge information
4531 struct interface
*svi_if_link
= NULL
;
4533 svi_if_zif
= svi_if
->info
;
4535 svi_if_link
= if_lookup_by_index_per_ns(
4536 zebra_ns_lookup(NS_DEFAULT
),
4537 svi_if_zif
->link_ifindex
);
4538 zevpn
= zebra_evpn_from_svi(svi_if
,
4541 } else if (IS_ZEBRA_IF_BRIDGE(svi_if
)) {
4543 * If it is a vlan unaware bridge then svi is the bridge
4546 zevpn
= zebra_evpn_from_svi(svi_if
, svi_if
);
4548 } else if (IS_ZEBRA_IF_VLAN(ifp
)) {
4549 struct zebra_if
*svi_if_zif
=
4550 NULL
; /* Zebra daemon specific info for SVI */
4551 struct interface
*svi_if_link
=
4552 NULL
; /* link info for the SVI = bridge info */
4554 svi_if_zif
= ifp
->info
;
4556 svi_if_link
= if_lookup_by_index_per_ns(
4557 zebra_ns_lookup(NS_DEFAULT
),
4558 svi_if_zif
->link_ifindex
);
4560 zevpn
= zebra_evpn_from_svi(ifp
, svi_if_link
);
4562 } else if (IS_ZEBRA_IF_BRIDGE(ifp
)) {
4563 zevpn
= zebra_evpn_from_svi(ifp
, ifp
);
4569 if (!zevpn
->vxlan_if
) {
4570 zlog_debug("VNI %u hash %p doesn't have intf upon MACVLAN up",
4575 /* VRR IP is advertised only if gw-macip-adv-enabled */
4576 if (IS_ZEBRA_IF_MACVLAN(ifp
)) {
4577 if (!advertise_gw_macip_enabled(zevpn
))
4580 /* SVI IP is advertised if gw or svi macip-adv-enabled */
4581 if (!advertise_svi_macip_enabled(zevpn
)
4582 && !advertise_gw_macip_enabled(zevpn
))
4586 memcpy(&macaddr
.octet
, ifp
->hw_addr
, ETH_ALEN
);
4588 if (p
->family
== AF_INET
) {
4589 ip
.ipa_type
= IPADDR_V4
;
4590 memcpy(&(ip
.ipaddr_v4
), &(p
->u
.prefix4
),
4591 sizeof(struct in_addr
));
4592 } else if (p
->family
== AF_INET6
) {
4593 ip
.ipa_type
= IPADDR_V6
;
4594 memcpy(&(ip
.ipaddr_v6
), &(p
->u
.prefix6
),
4595 sizeof(struct in6_addr
));
4600 zebra_evpn_gw_macip_add(ifp
, zevpn
, &macaddr
, &ip
);
4602 zebra_evpn_gw_macip_del(ifp
, zevpn
, &ip
);
4608 * Handle SVI interface going down.
4609 * SVI can be associated to either L3-VNI or L2-VNI.
4610 * For L2-VNI: At this point, this is a NOP since
4611 * the kernel deletes the neighbor entries on this SVI (if any).
4612 * We only need to update the vrf corresponding to zevpn.
4613 * For L3-VNI: L3-VNI is operationally down, update mac-ip routes and delete
4616 int zebra_vxlan_svi_down(struct interface
*ifp
, struct interface
*link_if
)
4618 struct zebra_l3vni
*zl3vni
= NULL
;
4620 zl3vni
= zl3vni_from_svi(ifp
, link_if
);
4623 /* process l3-vni down */
4624 zebra_vxlan_process_l3vni_oper_down(zl3vni
);
4626 /* remove association with svi-if */
4627 zl3vni
->svi_if
= NULL
;
4629 struct zebra_evpn
*zevpn
= NULL
;
4631 /* Unlink the SVI from the access VLAN */
4632 zebra_evpn_acc_bd_svi_set(ifp
->info
, link_if
->info
, false);
4634 /* since we dont have svi corresponding to zevpn, we associate it
4635 * to default vrf. Note: the corresponding neigh entries on the
4636 * SVI would have already been deleted */
4637 zevpn
= zebra_evpn_from_svi(ifp
, link_if
);
4640 /* remove from l3-vni list */
4641 zl3vni
= zl3vni_from_vrf(zevpn
->vrf_id
);
4643 listnode_delete(zl3vni
->l2vnis
, zevpn
);
4645 zevpn
->svi_if
= NULL
;
4646 zevpn
->vrf_id
= VRF_DEFAULT
;
4648 /* update the tenant vrf in BGP */
4649 if (if_is_operative(zevpn
->vxlan_if
))
4650 zebra_evpn_send_add_to_client(zevpn
);
4657 * Handle SVI interface coming up.
4658 * SVI can be associated to L3-VNI (l3vni vxlan interface) or L2-VNI (l2-vni
4660 * For L2-VNI: we need to install any remote neighbors entried (used for
4662 * For L3-VNI: SVI will be used to get the rmac to be used with L3-VNI
4664 int zebra_vxlan_svi_up(struct interface
*ifp
, struct interface
*link_if
)
4666 struct zebra_evpn
*zevpn
= NULL
;
4667 struct zebra_l3vni
*zl3vni
= NULL
;
4669 zl3vni
= zl3vni_from_svi(ifp
, link_if
);
4672 /* associate with svi */
4673 zl3vni
->svi_if
= ifp
;
4675 /* process oper-up */
4676 if (is_l3vni_oper_up(zl3vni
))
4677 zebra_vxlan_process_l3vni_oper_up(zl3vni
);
4680 /* process SVI up for l2-vni */
4681 struct neigh_walk_ctx n_wctx
;
4683 zevpn
= zebra_evpn_from_svi(ifp
, link_if
);
4687 if (!zevpn
->vxlan_if
) {
4689 "VNI %u hash %p doesn't have intf upon SVI up",
4694 if (IS_ZEBRA_DEBUG_VXLAN
)
4696 "SVI %s(%u) VNI %u VRF %s is UP, installing neighbors",
4697 ifp
->name
, ifp
->ifindex
, zevpn
->vni
,
4700 /* update the vrf information for l2-vni and inform bgp */
4701 zevpn
->svi_if
= ifp
;
4702 zevpn
->vrf_id
= ifp
->vrf
->vrf_id
;
4704 zl3vni
= zl3vni_from_vrf(zevpn
->vrf_id
);
4706 listnode_add_sort_nodup(zl3vni
->l2vnis
, zevpn
);
4708 if (if_is_operative(zevpn
->vxlan_if
))
4709 zebra_evpn_send_add_to_client(zevpn
);
4711 /* Install any remote neighbors for this VNI. */
4712 memset(&n_wctx
, 0, sizeof(n_wctx
));
4713 n_wctx
.zevpn
= zevpn
;
4714 hash_iterate(zevpn
->neigh_table
, zebra_evpn_install_neigh_hash
,
4717 /* Link the SVI from the access VLAN */
4718 zebra_evpn_acc_bd_svi_set(ifp
->info
, link_if
->info
, true);
4720 /* Update MACIP routes created by advertise-svi-ip */
4721 if (advertise_svi_macip_enabled(zevpn
)) {
4722 zebra_evpn_del_macip_for_intf(ifp
, zevpn
);
4723 zebra_evpn_add_macip_for_intf(ifp
, zevpn
);
4731 * Handle MAC-VLAN interface going down.
4732 * L3VNI: When MAC-VLAN interface goes down,
4733 * find its associated SVI and update type2/type-5 routes
4736 void zebra_vxlan_macvlan_down(struct interface
*ifp
)
4738 struct zebra_l3vni
*zl3vni
= NULL
;
4739 struct zebra_if
*zif
, *link_zif
;
4740 struct interface
*link_ifp
, *link_if
;
4744 link_ifp
= zif
->link
;
4746 if (IS_ZEBRA_DEBUG_VXLAN
)
4748 "macvlan parent link is not found. Parent index %d ifp %s",
4750 ifindex2ifname(zif
->link_ifindex
,
4754 link_zif
= link_ifp
->info
;
4757 link_if
= if_lookup_by_index_per_ns(zebra_ns_lookup(NS_DEFAULT
),
4758 link_zif
->link_ifindex
);
4760 zl3vni
= zl3vni_from_svi(link_ifp
, link_if
);
4762 zl3vni
->mac_vlan_if
= NULL
;
4763 if (is_l3vni_oper_up(zl3vni
))
4764 zebra_vxlan_process_l3vni_oper_up(zl3vni
);
4769 * Handle MAC-VLAN interface going up.
4770 * L3VNI: When MAC-VLAN interface comes up,
4771 * find its associated SVI and update type-2 routes
4772 * with MAC-VLAN's MAC as RMAC and for type-5 routes
4773 * use SVI's MAC as RMAC.
4775 void zebra_vxlan_macvlan_up(struct interface
*ifp
)
4777 struct zebra_l3vni
*zl3vni
= NULL
;
4778 struct zebra_if
*zif
, *link_zif
;
4779 struct interface
*link_ifp
, *link_if
;
4783 link_ifp
= zif
->link
;
4784 link_zif
= link_ifp
->info
;
4787 link_if
= if_lookup_by_index_per_ns(zebra_ns_lookup(NS_DEFAULT
),
4788 link_zif
->link_ifindex
);
4789 zl3vni
= zl3vni_from_svi(link_ifp
, link_if
);
4791 /* associate with macvlan (VRR) interface */
4792 zl3vni
->mac_vlan_if
= ifp
;
4794 /* process oper-up */
4795 if (is_l3vni_oper_up(zl3vni
))
4796 zebra_vxlan_process_l3vni_oper_up(zl3vni
);
4801 * Handle VxLAN interface down
4803 int zebra_vxlan_if_down(struct interface
*ifp
)
4806 struct zebra_if
*zif
= NULL
;
4807 struct zebra_l3vni
*zl3vni
= NULL
;
4808 struct zebra_evpn
*zevpn
;
4809 struct zebra_vxlan_vni
*vnip
;
4811 /* Check if EVPN is enabled. */
4812 if (!is_evpn_enabled())
4817 vnip
= zebra_vxlan_if_vni_find(zif
, 0);
4820 zl3vni
= zl3vni_lookup(vni
);
4822 /* process-if-down for l3-vni */
4823 if (IS_ZEBRA_DEBUG_VXLAN
)
4824 zlog_debug("Intf %s(%u) L3-VNI %u is DOWN", ifp
->name
,
4827 zebra_vxlan_process_l3vni_oper_down(zl3vni
);
4829 /* process if-down for l2-vni */
4830 if (IS_ZEBRA_DEBUG_VXLAN
)
4831 zlog_debug("Intf %s(%u) L2-VNI %u is DOWN", ifp
->name
,
4834 /* Locate hash entry; it is expected to exist. */
4835 zevpn
= zebra_evpn_lookup(vni
);
4838 "Failed to locate VNI hash at DOWN, IF %s(%u) VNI %u",
4839 ifp
->name
, ifp
->ifindex
, vni
);
4843 assert(zevpn
->vxlan_if
== ifp
);
4845 /* remove from l3-vni list */
4846 zl3vni
= zl3vni_from_vrf(zevpn
->vrf_id
);
4848 listnode_delete(zl3vni
->l2vnis
, zevpn
);
4850 /* Delete this VNI from BGP. */
4851 zebra_evpn_send_del_to_client(zevpn
);
4853 /* Free up all neighbors and MACs, if any. */
4854 zebra_evpn_neigh_del_all(zevpn
, 1, 0, DEL_ALL_NEIGH
);
4855 zebra_evpn_mac_del_all(zevpn
, 1, 0, DEL_ALL_MAC
);
4857 /* Free up all remote VTEPs, if any. */
4858 zebra_evpn_vtep_del_all(zevpn
, 1);
4864 * Handle VxLAN interface up - update BGP if required.
4866 int zebra_vxlan_if_up(struct interface
*ifp
)
4869 struct zebra_if
*zif
= NULL
;
4870 struct zebra_evpn
*zevpn
= NULL
;
4871 struct zebra_l3vni
*zl3vni
= NULL
;
4872 struct zebra_vxlan_vni
*vnip
;
4874 /* Check if EVPN is enabled. */
4875 if (!is_evpn_enabled())
4880 vnip
= zebra_vxlan_if_vni_find(zif
, 0);
4883 zl3vni
= zl3vni_lookup(vni
);
4885 /* we need to associate with SVI, if any, we can associate with
4886 * svi-if only after association with vxlan-intf is complete
4888 zl3vni
->svi_if
= zl3vni_map_to_svi_if(zl3vni
);
4889 zl3vni
->mac_vlan_if
= zl3vni_map_to_mac_vlan_if(zl3vni
);
4891 if (IS_ZEBRA_DEBUG_VXLAN
)
4892 zlog_debug("Intf %s(%u) L3-VNI %u is UP svi_if %s mac_vlan_if %s"
4893 , ifp
->name
, ifp
->ifindex
, vni
,
4894 zl3vni
->svi_if
? zl3vni
->svi_if
->name
: "NIL",
4895 zl3vni
->mac_vlan_if
?
4896 zl3vni
->mac_vlan_if
->name
: "NIL");
4898 if (is_l3vni_oper_up(zl3vni
))
4899 zebra_vxlan_process_l3vni_oper_up(zl3vni
);
4901 /* Handle L2-VNI add */
4902 struct interface
*vlan_if
= NULL
;
4904 if (IS_ZEBRA_DEBUG_VXLAN
)
4905 zlog_debug("Intf %s(%u) L2-VNI %u is UP", ifp
->name
,
4908 /* Locate hash entry; it is expected to exist. */
4909 zevpn
= zebra_evpn_lookup(vni
);
4912 "Failed to locate EVPN hash at UP, IF %s(%u) VNI %u",
4913 ifp
->name
, ifp
->ifindex
, vni
);
4917 assert(zevpn
->vxlan_if
== ifp
);
4918 vlan_if
= zvni_map_to_svi(vnip
->access_vlan
,
4919 zif
->brslave_info
.br_if
);
4921 zevpn
->svi_if
= vlan_if
;
4922 zevpn
->vrf_id
= vlan_if
->vrf
->vrf_id
;
4923 zl3vni
= zl3vni_from_vrf(vlan_if
->vrf
->vrf_id
);
4925 listnode_add_sort_nodup(zl3vni
->l2vnis
, zevpn
);
4928 /* If part of a bridge, inform BGP about this VNI. */
4929 /* Also, read and populate local MACs and neighbors. */
4930 if (zif
->brslave_info
.br_if
) {
4931 zebra_evpn_send_add_to_client(zevpn
);
4932 zebra_evpn_read_mac_neigh(zevpn
, ifp
);
4940 * Handle VxLAN interface delete. Locate and remove entry in hash table
4941 * and update BGP, if required.
4943 int zebra_vxlan_if_del(struct interface
*ifp
)
4946 struct zebra_if
*zif
= NULL
;
4947 struct zebra_evpn
*zevpn
= NULL
;
4948 struct zebra_l3vni
*zl3vni
= NULL
;
4949 struct zebra_vxlan_vni
*vnip
;
4951 /* Check if EVPN is enabled. */
4952 if (!is_evpn_enabled())
4957 vnip
= zebra_vxlan_if_vni_find(zif
, 0);
4960 zl3vni
= zl3vni_lookup(vni
);
4963 if (IS_ZEBRA_DEBUG_VXLAN
)
4964 zlog_debug("Del L3-VNI %u intf %s(%u)", vni
, ifp
->name
,
4967 /* process oper-down for l3-vni */
4968 zebra_vxlan_process_l3vni_oper_down(zl3vni
);
4970 /* remove the association with vxlan_if */
4971 memset(&zl3vni
->local_vtep_ip
, 0, sizeof(struct in_addr
));
4972 zl3vni
->vxlan_if
= NULL
;
4975 /* process if-del for l2-vni*/
4976 if (IS_ZEBRA_DEBUG_VXLAN
)
4977 zlog_debug("Del L2-VNI %u intf %s(%u)", vni
, ifp
->name
,
4980 /* Locate hash entry; it is expected to exist. */
4981 zevpn
= zebra_evpn_lookup(vni
);
4984 "Failed to locate VNI hash at del, IF %s(%u) VNI %u",
4985 ifp
->name
, ifp
->ifindex
, vni
);
4989 /* remove from l3-vni list */
4990 zl3vni
= zl3vni_from_vrf(zevpn
->vrf_id
);
4992 listnode_delete(zl3vni
->l2vnis
, zevpn
);
4993 /* Delete VNI from BGP. */
4994 zebra_evpn_send_del_to_client(zevpn
);
4996 /* Free up all neighbors and MAC, if any. */
4997 zebra_evpn_neigh_del_all(zevpn
, 0, 0, DEL_ALL_NEIGH
);
4998 zebra_evpn_mac_del_all(zevpn
, 0, 0, DEL_ALL_MAC
);
5000 /* Free up all remote VTEPs, if any. */
5001 zebra_evpn_vtep_del_all(zevpn
, 0);
5003 /* Delete the hash entry. */
5004 if (zebra_evpn_vxlan_del(zevpn
)) {
5005 flog_err(EC_ZEBRA_VNI_DEL_FAILED
,
5006 "Failed to del EVPN hash %p, IF %s(%u) VNI %u",
5007 zevpn
, ifp
->name
, ifp
->ifindex
, zevpn
->vni
);
5015 * Handle VxLAN interface update - change to tunnel IP, master or VLAN.
5017 int zebra_vxlan_if_update(struct interface
*ifp
, uint16_t chgflags
)
5020 struct zebra_if
*zif
= NULL
;
5021 struct zebra_l2info_vxlan
*vxl
= NULL
;
5022 struct zebra_evpn
*zevpn
= NULL
;
5023 struct zebra_l3vni
*zl3vni
= NULL
;
5024 struct interface
*vlan_if
= NULL
;
5025 struct zebra_vxlan_vni
*vnip
;
5027 /* Check if EVPN is enabled. */
5028 if (!is_evpn_enabled())
5033 vnip
= zebra_vxlan_if_vni_find(zif
, 0);
5036 zl3vni
= zl3vni_lookup(vni
);
5039 if (IS_ZEBRA_DEBUG_VXLAN
)
5041 "Update L3-VNI %u intf %s(%u) VLAN %u local IP %pI4 master %u chg 0x%x",
5042 vni
, ifp
->name
, ifp
->ifindex
, vnip
->access_vlan
,
5043 &vxl
->vtep_ip
, zif
->brslave_info
.bridge_ifindex
,
5046 /* Removed from bridge? Cleanup and return */
5047 if ((chgflags
& ZEBRA_VXLIF_MASTER_CHANGE
)
5048 && (zif
->brslave_info
.bridge_ifindex
== IFINDEX_INTERNAL
)) {
5049 zebra_vxlan_process_l3vni_oper_down(zl3vni
);
5053 if ((chgflags
& ZEBRA_VXLIF_MASTER_MAC_CHANGE
)
5054 && if_is_operative(ifp
) && is_l3vni_oper_up(zl3vni
)) {
5055 zebra_vxlan_process_l3vni_oper_down(zl3vni
);
5056 zebra_vxlan_process_l3vni_oper_up(zl3vni
);
5060 /* access-vlan change - process oper down, associate with new
5061 * svi_if and then process oper up again
5063 if (chgflags
& ZEBRA_VXLIF_VLAN_CHANGE
) {
5064 if (if_is_operative(ifp
)) {
5065 zebra_vxlan_process_l3vni_oper_down(zl3vni
);
5066 zl3vni
->svi_if
= NULL
;
5067 zl3vni
->svi_if
= zl3vni_map_to_svi_if(zl3vni
);
5068 zl3vni
->mac_vlan_if
=
5069 zl3vni_map_to_mac_vlan_if(zl3vni
);
5070 zl3vni
->local_vtep_ip
= vxl
->vtep_ip
;
5071 if (is_l3vni_oper_up(zl3vni
))
5072 zebra_vxlan_process_l3vni_oper_up(
5078 * local-ip change - process oper down, associate with new
5079 * local-ip and then process oper up again
5081 if (chgflags
& ZEBRA_VXLIF_LOCAL_IP_CHANGE
) {
5082 if (if_is_operative(ifp
)) {
5083 zebra_vxlan_process_l3vni_oper_down(zl3vni
);
5084 zl3vni
->local_vtep_ip
= vxl
->vtep_ip
;
5085 if (is_l3vni_oper_up(zl3vni
))
5086 zebra_vxlan_process_l3vni_oper_up(
5091 /* Update local tunnel IP. */
5092 zl3vni
->local_vtep_ip
= vxl
->vtep_ip
;
5094 /* if we have a valid new master, process l3-vni oper up */
5095 if (chgflags
& ZEBRA_VXLIF_MASTER_CHANGE
) {
5096 if (if_is_operative(ifp
) && is_l3vni_oper_up(zl3vni
))
5097 zebra_vxlan_process_l3vni_oper_up(zl3vni
);
5101 /* Update VNI hash. */
5102 zevpn
= zebra_evpn_lookup(vni
);
5105 "Failed to find EVPN hash on update, IF %s(%u) VNI %u",
5106 ifp
->name
, ifp
->ifindex
, vni
);
5110 if (IS_ZEBRA_DEBUG_VXLAN
)
5112 "Update L2-VNI %u intf %s(%u) VLAN %u local IP %pI4 master %u chg 0x%x",
5113 vni
, ifp
->name
, ifp
->ifindex
, vnip
->access_vlan
,
5114 &vxl
->vtep_ip
, zif
->brslave_info
.bridge_ifindex
,
5117 /* Removed from bridge? Cleanup and return */
5118 if ((chgflags
& ZEBRA_VXLIF_MASTER_CHANGE
)
5119 && (zif
->brslave_info
.bridge_ifindex
== IFINDEX_INTERNAL
)) {
5120 /* Delete from client, remove all remote VTEPs */
5121 /* Also, free up all MACs and neighbors. */
5122 zevpn
->svi_if
= NULL
;
5123 zebra_evpn_send_del_to_client(zevpn
);
5124 zebra_evpn_neigh_del_all(zevpn
, 1, 0, DEL_ALL_NEIGH
);
5125 zebra_evpn_mac_del_all(zevpn
, 1, 0, DEL_ALL_MAC
);
5126 zebra_evpn_vtep_del_all(zevpn
, 1);
5130 /* Handle other changes. */
5131 if (chgflags
& ZEBRA_VXLIF_VLAN_CHANGE
) {
5132 /* Remove all existing local neigh and MACs for this VNI
5133 * (including from BGP)
5135 zebra_evpn_neigh_del_all(zevpn
, 0, 1, DEL_LOCAL_MAC
);
5136 zebra_evpn_mac_del_all(zevpn
, 0, 1, DEL_LOCAL_MAC
);
5139 if (zevpn
->local_vtep_ip
.s_addr
!= vxl
->vtep_ip
.s_addr
5140 || zevpn
->mcast_grp
.s_addr
!= vnip
->mcast_grp
.s_addr
) {
5141 zebra_vxlan_sg_deref(zevpn
->local_vtep_ip
,
5143 zebra_vxlan_sg_ref(vxl
->vtep_ip
, vnip
->mcast_grp
);
5144 zevpn
->local_vtep_ip
= vxl
->vtep_ip
;
5145 zevpn
->mcast_grp
= vnip
->mcast_grp
;
5146 /* on local vtep-ip check if ES orig-ip
5147 * needs to be updated
5149 zebra_evpn_es_set_base_evpn(zevpn
);
5151 zevpn_vxlan_if_set(zevpn
, ifp
, true /* set */);
5152 vlan_if
= zvni_map_to_svi(vnip
->access_vlan
,
5153 zif
->brslave_info
.br_if
);
5155 zevpn
->svi_if
= vlan_if
;
5156 zevpn
->vrf_id
= vlan_if
->vrf
->vrf_id
;
5157 zl3vni
= zl3vni_from_vrf(vlan_if
->vrf
->vrf_id
);
5159 listnode_add_sort_nodup(zl3vni
->l2vnis
, zevpn
);
5162 /* Take further actions needed.
5163 * Note that if we are here, there is a change of interest.
5165 /* If down or not mapped to a bridge, we're done. */
5166 if (!if_is_operative(ifp
) || !zif
->brslave_info
.br_if
)
5169 /* Inform BGP, if there is a change of interest. */
5171 (ZEBRA_VXLIF_MASTER_CHANGE
| ZEBRA_VXLIF_LOCAL_IP_CHANGE
|
5172 ZEBRA_VXLIF_MCAST_GRP_CHANGE
| ZEBRA_VXLIF_VLAN_CHANGE
))
5173 zebra_evpn_send_add_to_client(zevpn
);
5175 /* If there is a valid new master or a VLAN mapping change,
5176 * read and populate local MACs and neighbors.
5177 * Also, reinstall any remote MACs and neighbors
5178 * for this VNI (based on new VLAN).
5180 if (chgflags
& ZEBRA_VXLIF_MASTER_CHANGE
)
5181 zebra_evpn_read_mac_neigh(zevpn
, ifp
);
5182 else if (chgflags
& ZEBRA_VXLIF_VLAN_CHANGE
) {
5183 struct mac_walk_ctx m_wctx
;
5184 struct neigh_walk_ctx n_wctx
;
5186 zebra_evpn_read_mac_neigh(zevpn
, ifp
);
5188 memset(&m_wctx
, 0, sizeof(m_wctx
));
5189 m_wctx
.zevpn
= zevpn
;
5190 hash_iterate(zevpn
->mac_table
,
5191 zebra_evpn_install_mac_hash
, &m_wctx
);
5193 memset(&n_wctx
, 0, sizeof(n_wctx
));
5194 n_wctx
.zevpn
= zevpn
;
5195 hash_iterate(zevpn
->neigh_table
,
5196 zebra_evpn_install_neigh_hash
, &n_wctx
);
5204 * Handle VxLAN interface add.
5206 int zebra_vxlan_if_add(struct interface
*ifp
)
5209 struct zebra_if
*zif
= NULL
;
5210 struct zebra_l2info_vxlan
*vxl
= NULL
;
5211 struct zebra_evpn
*zevpn
= NULL
;
5212 struct zebra_l3vni
*zl3vni
= NULL
;
5213 struct zebra_vxlan_vni
*vnip
;
5215 /* Check if EVPN is enabled. */
5216 if (!is_evpn_enabled())
5221 vnip
= zebra_vxlan_if_vni_find(zif
, 0);
5224 zl3vni
= zl3vni_lookup(vni
);
5227 /* process if-add for l3-vni*/
5228 if (IS_ZEBRA_DEBUG_VXLAN
)
5230 "Add L3-VNI %u intf %s(%u) VLAN %u local IP %pI4 master %u",
5231 vni
, ifp
->name
, ifp
->ifindex
, vnip
->access_vlan
,
5233 zif
->brslave_info
.bridge_ifindex
);
5235 /* associate with vxlan_if */
5236 zl3vni
->local_vtep_ip
= vxl
->vtep_ip
;
5237 zl3vni
->vxlan_if
= ifp
;
5239 /* Associate with SVI, if any. We can associate with svi-if only
5240 * after association with vxlan_if is complete */
5241 zl3vni
->svi_if
= zl3vni_map_to_svi_if(zl3vni
);
5243 zl3vni
->mac_vlan_if
= zl3vni_map_to_mac_vlan_if(zl3vni
);
5245 if (is_l3vni_oper_up(zl3vni
))
5246 zebra_vxlan_process_l3vni_oper_up(zl3vni
);
5249 /* process if-add for l2-vni */
5250 struct interface
*vlan_if
= NULL
;
5252 /* Create or update EVPN hash. */
5253 zevpn
= zebra_evpn_lookup(vni
);
5255 zevpn
= zebra_evpn_add(vni
);
5257 if (zevpn
->local_vtep_ip
.s_addr
!= vxl
->vtep_ip
.s_addr
5258 || zevpn
->mcast_grp
.s_addr
!= vnip
->mcast_grp
.s_addr
) {
5259 zebra_vxlan_sg_deref(zevpn
->local_vtep_ip
,
5261 zebra_vxlan_sg_ref(vxl
->vtep_ip
, vnip
->mcast_grp
);
5262 zevpn
->local_vtep_ip
= vxl
->vtep_ip
;
5263 zevpn
->mcast_grp
= vnip
->mcast_grp
;
5264 /* on local vtep-ip check if ES orig-ip
5265 * needs to be updated
5267 zebra_evpn_es_set_base_evpn(zevpn
);
5269 zevpn_vxlan_if_set(zevpn
, ifp
, true /* set */);
5270 vlan_if
= zvni_map_to_svi(vnip
->access_vlan
,
5271 zif
->brslave_info
.br_if
);
5273 zevpn
->svi_if
= vlan_if
;
5274 zevpn
->vrf_id
= vlan_if
->vrf
->vrf_id
;
5275 zl3vni
= zl3vni_from_vrf(vlan_if
->vrf
->vrf_id
);
5277 listnode_add_sort_nodup(zl3vni
->l2vnis
, zevpn
);
5280 if (IS_ZEBRA_DEBUG_VXLAN
)
5282 "Add L2-VNI %u VRF %s intf %s(%u) VLAN %u local IP %pI4 mcast_grp %pI4 master %u",
5284 vlan_if
? vlan_if
->vrf
->name
: VRF_DEFAULT_NAME
,
5285 ifp
->name
, ifp
->ifindex
, vnip
->access_vlan
,
5286 &vxl
->vtep_ip
, &vnip
->mcast_grp
,
5287 zif
->brslave_info
.bridge_ifindex
);
5289 /* If down or not mapped to a bridge, we're done. */
5290 if (!if_is_operative(ifp
) || !zif
->brslave_info
.br_if
)
5294 zebra_evpn_send_add_to_client(zevpn
);
5296 /* Read and populate local MACs and neighbors */
5297 zebra_evpn_read_mac_neigh(zevpn
, ifp
);
5303 int zebra_vxlan_process_vrf_vni_cmd(struct zebra_vrf
*zvrf
, vni_t vni
,
5304 char *err
, int err_str_sz
, int filter
,
5307 struct zebra_l3vni
*zl3vni
= NULL
;
5308 struct zebra_vrf
*zvrf_evpn
= NULL
;
5310 zvrf_evpn
= zebra_vrf_get_evpn();
5312 if (IS_ZEBRA_DEBUG_VXLAN
)
5313 zlog_debug("vrf %s vni %u %s", zvrf_name(zvrf
), vni
,
5314 add
? "ADD" : "DEL");
5317 /* check if the vni is already present under zvrf */
5319 snprintf(err
, err_str_sz
,
5320 "VNI is already configured under the vrf");
5324 /* check if this VNI is already present in the system */
5325 zl3vni
= zl3vni_lookup(vni
);
5327 snprintf(err
, err_str_sz
,
5328 "VNI is already configured as L3-VNI");
5332 /* Remove L2VNI if present */
5333 zebra_vxlan_handle_vni_transition(zvrf
, vni
, add
);
5335 /* add the L3-VNI to the global table */
5336 zl3vni
= zl3vni_add(vni
, zvrf_id(zvrf
));
5338 /* associate the vrf with vni */
5341 /* set the filter in l3vni to denote if we are using l3vni only
5345 SET_FLAG(zl3vni
->filter
, PREFIX_ROUTES_ONLY
);
5347 /* associate with vxlan-intf;
5348 * we need to associate with the vxlan-intf first
5350 zl3vni
->vxlan_if
= zl3vni_map_to_vxlan_if(zl3vni
);
5352 /* associate with corresponding SVI interface, we can associate
5353 * with svi-if only after vxlan interface association is
5356 zl3vni
->svi_if
= zl3vni_map_to_svi_if(zl3vni
);
5358 zl3vni
->mac_vlan_if
= zl3vni_map_to_mac_vlan_if(zl3vni
);
5360 if (IS_ZEBRA_DEBUG_VXLAN
)
5362 "%s: l3vni %u svi_if %s mac_vlan_if %s",
5364 zl3vni
->svi_if
? zl3vni
->svi_if
->name
: "NIL",
5365 zl3vni
->mac_vlan_if
? zl3vni
->mac_vlan_if
->name
5368 /* formulate l2vni list */
5369 hash_iterate(zvrf_evpn
->evpn_table
, zevpn_add_to_l3vni_list
,
5372 if (is_l3vni_oper_up(zl3vni
))
5373 zebra_vxlan_process_l3vni_oper_up(zl3vni
);
5376 zl3vni
= zl3vni_lookup(vni
);
5378 snprintf(err
, err_str_sz
, "VNI doesn't exist");
5382 if (zvrf
->l3vni
!= vni
) {
5383 snprintf(err
, err_str_sz
,
5384 "VNI %d doesn't exist in VRF: %s",
5385 vni
, zvrf
->vrf
->name
);
5389 if (filter
&& !CHECK_FLAG(zl3vni
->filter
, PREFIX_ROUTES_ONLY
)) {
5390 snprintf(err
, ERR_STR_SZ
,
5391 "prefix-routes-only is not set for the vni");
5395 zebra_vxlan_process_l3vni_oper_down(zl3vni
);
5397 /* delete and uninstall all rmacs */
5398 hash_iterate(zl3vni
->rmac_table
, zl3vni_del_rmac_hash_entry
,
5401 /* delete and uninstall all next-hops */
5402 hash_iterate(zl3vni
->nh_table
, zl3vni_del_nh_hash_entry
,
5408 /* Add L2VNI for this VNI */
5409 zebra_vxlan_handle_vni_transition(zvrf
, vni
, add
);
5414 int zebra_vxlan_vrf_enable(struct zebra_vrf
*zvrf
)
5416 struct zebra_l3vni
*zl3vni
= NULL
;
5419 zl3vni
= zl3vni_lookup(zvrf
->l3vni
);
5423 zl3vni
->vrf_id
= zvrf_id(zvrf
);
5424 if (is_l3vni_oper_up(zl3vni
))
5425 zebra_vxlan_process_l3vni_oper_up(zl3vni
);
5429 int zebra_vxlan_vrf_disable(struct zebra_vrf
*zvrf
)
5431 struct zebra_l3vni
*zl3vni
= NULL
;
5434 zl3vni
= zl3vni_lookup(zvrf
->l3vni
);
5438 zebra_vxlan_process_l3vni_oper_down(zl3vni
);
5440 /* delete and uninstall all rmacs */
5441 hash_iterate(zl3vni
->rmac_table
, zl3vni_del_rmac_hash_entry
, zl3vni
);
5442 /* delete and uninstall all next-hops */
5443 hash_iterate(zl3vni
->nh_table
, zl3vni_del_nh_hash_entry
, zl3vni
);
5445 zl3vni
->vrf_id
= VRF_UNKNOWN
;
5450 int zebra_vxlan_vrf_delete(struct zebra_vrf
*zvrf
)
5452 struct zebra_l3vni
*zl3vni
= NULL
;
5456 zl3vni
= zl3vni_lookup(zvrf
->l3vni
);
5462 zebra_vxlan_handle_vni_transition(zvrf
, vni
, 0);
5468 * Handle message from client to specify the flooding mechanism for
5469 * BUM packets. The default is to do head-end (ingress) replication
5470 * and the other supported option is to disable it. This applies to
5471 * all BUM traffic and disabling it applies to both the transmit and
5472 * receive direction.
5474 void zebra_vxlan_flood_control(ZAPI_HANDLER_ARGS
)
5477 enum vxlan_flood_control flood_ctrl
;
5479 if (!EVPN_ENABLED(zvrf
)) {
5480 zlog_err("EVPN flood control for non-EVPN VRF %u",
5486 STREAM_GETC(s
, flood_ctrl
);
5488 if (IS_ZEBRA_DEBUG_VXLAN
)
5489 zlog_debug("EVPN flood control %u, currently %u",
5490 flood_ctrl
, zvrf
->vxlan_flood_ctrl
);
5492 if (zvrf
->vxlan_flood_ctrl
== flood_ctrl
)
5495 zvrf
->vxlan_flood_ctrl
= flood_ctrl
;
5497 /* Install or uninstall flood entries corresponding to
5500 hash_iterate(zvrf
->evpn_table
, zebra_evpn_handle_flooding_remote_vteps
,
5508 * Handle message from client to enable/disable advertisement of svi macip
5511 void zebra_vxlan_advertise_svi_macip(ZAPI_HANDLER_ARGS
)
5516 struct zebra_evpn
*zevpn
= NULL
;
5517 struct interface
*ifp
= NULL
;
5519 if (!EVPN_ENABLED(zvrf
)) {
5520 zlog_debug("EVPN SVI-MACIP Adv for non-EVPN VRF %u",
5526 STREAM_GETC(s
, advertise
);
5527 STREAM_GETL(s
, vni
);
5530 if (IS_ZEBRA_DEBUG_VXLAN
)
5531 zlog_debug("EVPN SVI-MACIP Adv %s, currently %s",
5532 advertise
? "enabled" : "disabled",
5533 advertise_svi_macip_enabled(NULL
)
5537 if (zvrf
->advertise_svi_macip
== advertise
)
5542 zvrf
->advertise_svi_macip
= advertise
;
5543 hash_iterate(zvrf
->evpn_table
,
5544 zebra_evpn_gw_macip_add_for_evpn_hash
,
5547 hash_iterate(zvrf
->evpn_table
,
5548 zebra_evpn_svi_macip_del_for_evpn_hash
,
5550 zvrf
->advertise_svi_macip
= advertise
;
5554 struct zebra_if
*zif
= NULL
;
5555 struct interface
*vlan_if
= NULL
;
5556 struct zebra_vxlan_vni
*zl2_info_vni
;
5559 zevpn
= zebra_evpn_lookup(vni
);
5563 if (IS_ZEBRA_DEBUG_VXLAN
)
5565 "EVPN SVI macip Adv %s on VNI %d, currently %s",
5566 advertise
? "enabled" : "disabled", vni
,
5567 advertise_svi_macip_enabled(zevpn
)
5571 old_advertise
= advertise_svi_macip_enabled(zevpn
);
5573 /* Store flag even though SVI is not present.
5574 * Once SVI comes up triggers self MAC-IP route add.
5576 zevpn
->advertise_svi_macip
= advertise
;
5577 if (advertise_svi_macip_enabled(zevpn
) == old_advertise
)
5580 ifp
= zevpn
->vxlan_if
;
5586 /* If down or not mapped to a bridge, we're done. */
5587 if (!if_is_operative(ifp
) || !zif
->brslave_info
.br_if
)
5590 zl2_info_vni
= zebra_vxlan_if_vni_find(zif
, vni
);
5594 vlan_if
= zvni_map_to_svi(zl2_info_vni
->access_vlan
,
5595 zif
->brslave_info
.br_if
);
5600 /* Add primary SVI MAC-IP */
5601 zebra_evpn_add_macip_for_intf(vlan_if
, zevpn
);
5603 /* Del primary SVI MAC-IP */
5604 zebra_evpn_del_macip_for_intf(vlan_if
, zevpn
);
5613 * Handle message from client to enable/disable advertisement of g/w macip
5616 void zebra_vxlan_advertise_subnet(ZAPI_HANDLER_ARGS
)
5621 struct zebra_evpn
*zevpn
= NULL
;
5622 struct interface
*ifp
= NULL
;
5623 struct zebra_if
*zif
= NULL
;
5624 struct interface
*vlan_if
= NULL
;
5625 struct zebra_vxlan_vni
*zl2_info_vni
= NULL
;
5627 if (!EVPN_ENABLED(zvrf
)) {
5628 zlog_debug("EVPN GW-MACIP Adv for non-EVPN VRF %u",
5634 STREAM_GETC(s
, advertise
);
5635 STREAM_GET(&vni
, s
, 3);
5637 zevpn
= zebra_evpn_lookup(vni
);
5641 if (zevpn
->advertise_subnet
== advertise
)
5644 if (IS_ZEBRA_DEBUG_VXLAN
)
5645 zlog_debug("EVPN subnet Adv %s on VNI %d, currently %s",
5646 advertise
? "enabled" : "disabled", vni
,
5647 zevpn
->advertise_subnet
? "enabled" : "disabled");
5650 zevpn
->advertise_subnet
= advertise
;
5652 ifp
= zevpn
->vxlan_if
;
5658 /* If down or not mapped to a bridge, we're done. */
5659 if (!if_is_operative(ifp
) || !zif
->brslave_info
.br_if
)
5662 zl2_info_vni
= zebra_vxlan_if_vni_find(zif
, vni
);
5666 vlan_if
= zvni_map_to_svi(zl2_info_vni
->access_vlan
,
5667 zif
->brslave_info
.br_if
);
5671 if (zevpn
->advertise_subnet
)
5672 zebra_evpn_advertise_subnet(zevpn
, vlan_if
, 1);
5674 zebra_evpn_advertise_subnet(zevpn
, vlan_if
, 0);
5681 * Handle message from client to enable/disable advertisement of g/w macip
5684 void zebra_vxlan_advertise_gw_macip(ZAPI_HANDLER_ARGS
)
5689 struct zebra_evpn
*zevpn
= NULL
;
5690 struct interface
*ifp
= NULL
;
5692 if (!EVPN_ENABLED(zvrf
)) {
5693 zlog_debug("EVPN GW-MACIP Adv for non-EVPN VRF %u",
5699 STREAM_GETC(s
, advertise
);
5700 STREAM_GETL(s
, vni
);
5703 if (IS_ZEBRA_DEBUG_VXLAN
)
5704 zlog_debug("EVPN gateway macip Adv %s, currently %s",
5705 advertise
? "enabled" : "disabled",
5706 advertise_gw_macip_enabled(NULL
)
5710 if (zvrf
->advertise_gw_macip
== advertise
)
5713 zvrf
->advertise_gw_macip
= advertise
;
5715 if (advertise_gw_macip_enabled(zevpn
))
5716 hash_iterate(zvrf
->evpn_table
,
5717 zebra_evpn_gw_macip_add_for_evpn_hash
,
5720 hash_iterate(zvrf
->evpn_table
,
5721 zebra_evpn_gw_macip_del_for_evpn_hash
,
5725 struct zebra_if
*zif
= NULL
;
5726 struct interface
*vlan_if
= NULL
;
5727 struct interface
*vrr_if
= NULL
;
5728 struct zebra_vxlan_vni
*zl2_info_vni
= NULL
;
5731 zevpn
= zebra_evpn_lookup(vni
);
5735 if (IS_ZEBRA_DEBUG_VXLAN
)
5737 "EVPN gateway macip Adv %s on VNI %d, currently %s",
5738 advertise
? "enabled" : "disabled", vni
,
5739 advertise_gw_macip_enabled(zevpn
) ? "enabled"
5742 old_advertise
= advertise_gw_macip_enabled(zevpn
);
5744 zevpn
->advertise_gw_macip
= advertise
;
5745 if (advertise_gw_macip_enabled(zevpn
) == old_advertise
)
5748 ifp
= zevpn
->vxlan_if
;
5754 /* If down or not mapped to a bridge, we're done. */
5755 if (!if_is_operative(ifp
) || !zif
->brslave_info
.br_if
)
5758 zl2_info_vni
= zebra_vxlan_if_vni_find(zif
, vni
);
5762 vlan_if
= zvni_map_to_svi(zl2_info_vni
->access_vlan
,
5763 zif
->brslave_info
.br_if
);
5767 if (advertise_gw_macip_enabled(zevpn
)) {
5768 /* Add primary SVI MAC-IP */
5769 zebra_evpn_add_macip_for_intf(vlan_if
, zevpn
);
5771 /* Add VRR MAC-IP - if any*/
5772 vrr_if
= zebra_get_vrr_intf_for_svi(vlan_if
);
5774 zebra_evpn_add_macip_for_intf(vrr_if
, zevpn
);
5776 /* Del primary MAC-IP */
5777 zebra_evpn_del_macip_for_intf(vlan_if
, zevpn
);
5779 /* Del VRR MAC-IP - if any*/
5780 vrr_if
= zebra_get_vrr_intf_for_svi(vlan_if
);
5782 zebra_evpn_del_macip_for_intf(vrr_if
, zevpn
);
5790 static int macfdb_read_ns(struct ns
*ns
,
5791 void *_in_param
__attribute__((unused
)),
5792 void **out_param
__attribute__((unused
)))
5794 struct zebra_ns
*zns
= ns
->info
;
5797 return NS_WALK_CONTINUE
;
5800 static int neigh_read_ns(struct ns
*ns
,
5801 void *_in_param
__attribute__((unused
)),
5802 void **out_param
__attribute__((unused
)))
5804 struct zebra_ns
*zns
= ns
->info
;
5807 return NS_WALK_CONTINUE
;
5811 * Handle message from client to learn (or stop learning) about VNIs and MACs.
5812 * When enabled, the VNI hash table will be built and MAC FDB table read;
5813 * when disabled, the entries should be deleted and remote VTEPs and MACs
5814 * uninstalled from the kernel.
5815 * This also informs the setting for BUM handling at the time this change
5816 * occurs; it is relevant only when specifying "learn".
5818 void zebra_vxlan_advertise_all_vni(ZAPI_HANDLER_ARGS
)
5820 struct stream
*s
= NULL
;
5822 enum vxlan_flood_control flood_ctrl
;
5824 /* Mismatch between EVPN VRF and current VRF (should be prevented by
5826 if (is_evpn_enabled() && !EVPN_ENABLED(zvrf
))
5830 STREAM_GETC(s
, advertise
);
5831 STREAM_GETC(s
, flood_ctrl
);
5833 if (IS_ZEBRA_DEBUG_VXLAN
)
5834 zlog_debug("EVPN VRF %s(%u) VNI Adv %s, currently %s, flood control %u",
5835 zvrf_name(zvrf
), zvrf_id(zvrf
),
5836 advertise
? "enabled" : "disabled",
5837 is_evpn_enabled() ? "enabled" : "disabled",
5840 if (zvrf
->advertise_all_vni
== advertise
)
5843 zvrf
->advertise_all_vni
= advertise
;
5844 if (EVPN_ENABLED(zvrf
)) {
5845 zrouter
.evpn_vrf
= zvrf
;
5847 /* Note BUM handling */
5848 zvrf
->vxlan_flood_ctrl
= flood_ctrl
;
5850 /* Replay all ESs */
5851 zebra_evpn_es_send_all_to_client(true /* add */);
5853 /* Build EVPN hash table and inform BGP. */
5854 zevpn_build_hash_table();
5856 /* Add all SVI (L3 GW) MACs to BGP*/
5857 hash_iterate(zvrf
->evpn_table
,
5858 zebra_evpn_gw_macip_add_for_evpn_hash
, NULL
);
5860 /* Read the MAC FDB */
5861 ns_walk_func(macfdb_read_ns
, NULL
, NULL
);
5863 /* Read neighbors */
5864 ns_walk_func(neigh_read_ns
, NULL
, NULL
);
5866 /* Cleanup VTEPs for all EVPNs - uninstall from
5867 * kernel and free entries.
5869 hash_iterate(zvrf
->evpn_table
, zebra_evpn_vxlan_cleanup_all
,
5872 /* Delete all ESs in BGP */
5873 zebra_evpn_es_send_all_to_client(false /* add */);
5875 /* cleanup all l3vnis */
5876 hash_iterate(zrouter
.l3vni_table
, zl3vni_cleanup_all
, NULL
);
5878 /* Mark as "no EVPN VRF" */
5879 zrouter
.evpn_vrf
= NULL
;
5887 * Allocate EVPN hash table for this VRF and do other initialization.
5888 * NOTE: Currently supported only for default VRF.
5890 void zebra_vxlan_init_tables(struct zebra_vrf
*zvrf
)
5897 snprintf(buffer
, sizeof(buffer
), "Zebra VRF EVPN Table: %s",
5899 zvrf
->evpn_table
= hash_create_size(8, zebra_evpn_hash_keymake
,
5900 zebra_evpn_hash_cmp
, buffer
);
5902 snprintf(buffer
, sizeof(buffer
), "Zebra VxLAN SG Table: %s",
5904 zvrf
->vxlan_sg_table
= hash_create_size(8, zebra_vxlan_sg_hash_key_make
,
5905 zebra_vxlan_sg_hash_eq
, buffer
);
5908 /* Cleanup EVPN info, but don't free the table. */
5909 void zebra_vxlan_cleanup_tables(struct zebra_vrf
*zvrf
)
5911 struct zebra_vrf
*evpn_zvrf
= zebra_vrf_get_evpn();
5913 hash_iterate(zvrf
->evpn_table
, zebra_evpn_vxlan_cleanup_all
, zvrf
);
5914 zebra_vxlan_cleanup_sg_table(zvrf
);
5916 if (zvrf
== evpn_zvrf
)
5917 zebra_evpn_es_cleanup();
5920 /* Close all EVPN handling */
5921 void zebra_vxlan_close_tables(struct zebra_vrf
*zvrf
)
5925 hash_iterate(zvrf
->evpn_table
, zebra_evpn_vxlan_cleanup_all
, zvrf
);
5926 hash_free(zvrf
->evpn_table
);
5927 if (zvrf
->vxlan_sg_table
) {
5928 zebra_vxlan_cleanup_sg_table(zvrf
);
5929 hash_free(zvrf
->vxlan_sg_table
);
5930 zvrf
->vxlan_sg_table
= NULL
;
5934 /* init the l3vni table */
5935 void zebra_vxlan_init(void)
5937 zrouter
.l3vni_table
= hash_create(l3vni_hash_keymake
, l3vni_hash_cmp
,
5938 "Zebra VRF L3 VNI table");
5939 zrouter
.evpn_vrf
= NULL
;
5940 zebra_evpn_mh_init();
5943 /* free l3vni table */
5944 void zebra_vxlan_disable(void)
5946 hash_free(zrouter
.l3vni_table
);
5947 zebra_evpn_mh_terminate();
5950 /* get the l3vni svi ifindex */
5951 ifindex_t
get_l3vni_svi_ifindex(vrf_id_t vrf_id
)
5953 struct zebra_l3vni
*zl3vni
= NULL
;
5955 zl3vni
= zl3vni_from_vrf(vrf_id
);
5956 if (!zl3vni
|| !is_l3vni_oper_up(zl3vni
))
5959 return zl3vni
->svi_if
->ifindex
;
5962 /************************** vxlan SG cache management ************************/
5963 /* Inform PIM about the mcast group */
5964 static int zebra_vxlan_sg_send(struct zebra_vrf
*zvrf
,
5965 struct prefix_sg
*sg
,
5966 char *sg_str
, uint16_t cmd
)
5968 struct zserv
*client
= NULL
;
5969 struct stream
*s
= NULL
;
5971 client
= zserv_find_client(ZEBRA_ROUTE_PIM
, 0);
5975 if (!CHECK_FLAG(zvrf
->flags
, ZEBRA_PIM_SEND_VXLAN_SG
))
5978 s
= stream_new(ZEBRA_MAX_PACKET_SIZ
);
5980 zclient_create_header(s
, cmd
, VRF_DEFAULT
);
5981 stream_putl(s
, IPV4_MAX_BYTELEN
);
5982 stream_put(s
, &sg
->src
.s_addr
, IPV4_MAX_BYTELEN
);
5983 stream_put(s
, &sg
->grp
.s_addr
, IPV4_MAX_BYTELEN
);
5985 /* Write packet size. */
5986 stream_putw_at(s
, 0, stream_get_endp(s
));
5988 if (IS_ZEBRA_DEBUG_VXLAN
)
5991 (cmd
== ZEBRA_VXLAN_SG_ADD
) ? "add" : "del", sg_str
,
5992 zebra_route_string(client
->proto
));
5994 if (cmd
== ZEBRA_VXLAN_SG_ADD
)
5995 client
->vxlan_sg_add_cnt
++;
5997 client
->vxlan_sg_del_cnt
++;
5999 return zserv_send_message(client
, s
);
6002 static unsigned int zebra_vxlan_sg_hash_key_make(const void *p
)
6004 const struct zebra_vxlan_sg
*vxlan_sg
= p
;
6006 return (jhash_2words(vxlan_sg
->sg
.src
.s_addr
,
6007 vxlan_sg
->sg
.grp
.s_addr
, 0));
6010 static bool zebra_vxlan_sg_hash_eq(const void *p1
, const void *p2
)
6012 const struct zebra_vxlan_sg
*sg1
= p1
;
6013 const struct zebra_vxlan_sg
*sg2
= p2
;
6015 return ((sg1
->sg
.src
.s_addr
== sg2
->sg
.src
.s_addr
)
6016 && (sg1
->sg
.grp
.s_addr
== sg2
->sg
.grp
.s_addr
));
6019 static struct zebra_vxlan_sg
*zebra_vxlan_sg_new(struct zebra_vrf
*zvrf
,
6020 struct prefix_sg
*sg
)
6022 struct zebra_vxlan_sg
*vxlan_sg
;
6024 vxlan_sg
= XCALLOC(MTYPE_ZVXLAN_SG
, sizeof(*vxlan_sg
));
6026 vxlan_sg
->zvrf
= zvrf
;
6028 prefix_sg2str(sg
, vxlan_sg
->sg_str
);
6030 vxlan_sg
= hash_get(zvrf
->vxlan_sg_table
, vxlan_sg
, hash_alloc_intern
);
6032 if (IS_ZEBRA_DEBUG_VXLAN
)
6033 zlog_debug("vxlan SG %s created", vxlan_sg
->sg_str
);
6038 static struct zebra_vxlan_sg
*zebra_vxlan_sg_find(struct zebra_vrf
*zvrf
,
6039 struct prefix_sg
*sg
)
6041 struct zebra_vxlan_sg lookup
;
6044 return hash_lookup(zvrf
->vxlan_sg_table
, &lookup
);
6047 static struct zebra_vxlan_sg
*zebra_vxlan_sg_add(struct zebra_vrf
*zvrf
,
6048 struct prefix_sg
*sg
)
6050 struct zebra_vxlan_sg
*vxlan_sg
;
6051 struct zebra_vxlan_sg
*parent
= NULL
;
6054 vxlan_sg
= zebra_vxlan_sg_find(zvrf
, sg
);
6058 /* create a *G entry for every BUM group implicitly -
6059 * 1. The SG entry is used by pimd to setup the vxlan-origination-mroute
6060 * 2. the XG entry is used by pimd to setup the
6061 * vxlan-termination-mroute
6063 if (sg
->src
.s_addr
!= INADDR_ANY
) {
6064 memset(&sip
, 0, sizeof(sip
));
6065 parent
= zebra_vxlan_sg_do_ref(zvrf
, sip
, sg
->grp
);
6070 vxlan_sg
= zebra_vxlan_sg_new(zvrf
, sg
);
6072 zebra_vxlan_sg_send(zvrf
, sg
, vxlan_sg
->sg_str
,
6073 ZEBRA_VXLAN_SG_ADD
);
6078 static void zebra_vxlan_sg_del(struct zebra_vxlan_sg
*vxlan_sg
)
6081 struct zebra_vrf
*zvrf
;
6083 zvrf
= vrf_info_lookup(VRF_DEFAULT
);
6087 /* On SG entry deletion remove the reference to its parent XG
6090 if (vxlan_sg
->sg
.src
.s_addr
!= INADDR_ANY
) {
6091 memset(&sip
, 0, sizeof(sip
));
6092 zebra_vxlan_sg_do_deref(zvrf
, sip
, vxlan_sg
->sg
.grp
);
6095 zebra_vxlan_sg_send(zvrf
, &vxlan_sg
->sg
,
6096 vxlan_sg
->sg_str
, ZEBRA_VXLAN_SG_DEL
);
6098 hash_release(vxlan_sg
->zvrf
->vxlan_sg_table
, vxlan_sg
);
6100 if (IS_ZEBRA_DEBUG_VXLAN
)
6101 zlog_debug("VXLAN SG %s deleted", vxlan_sg
->sg_str
);
6103 XFREE(MTYPE_ZVXLAN_SG
, vxlan_sg
);
6106 static void zebra_vxlan_sg_do_deref(struct zebra_vrf
*zvrf
,
6107 struct in_addr sip
, struct in_addr mcast_grp
)
6109 struct zebra_vxlan_sg
*vxlan_sg
;
6110 struct prefix_sg sg
;
6112 sg
.family
= AF_INET
;
6113 sg
.prefixlen
= IPV4_MAX_BYTELEN
;
6116 vxlan_sg
= zebra_vxlan_sg_find(zvrf
, &sg
);
6120 if (vxlan_sg
->ref_cnt
)
6121 --vxlan_sg
->ref_cnt
;
6123 if (!vxlan_sg
->ref_cnt
)
6124 zebra_vxlan_sg_del(vxlan_sg
);
6127 static struct zebra_vxlan_sg
*zebra_vxlan_sg_do_ref(struct zebra_vrf
*zvrf
,
6129 struct in_addr mcast_grp
)
6131 struct zebra_vxlan_sg
*vxlan_sg
;
6132 struct prefix_sg sg
;
6134 sg
.family
= AF_INET
;
6135 sg
.prefixlen
= IPV4_MAX_BYTELEN
;
6138 vxlan_sg
= zebra_vxlan_sg_add(zvrf
, &sg
);
6140 ++vxlan_sg
->ref_cnt
;
6145 void zebra_vxlan_sg_deref(struct in_addr local_vtep_ip
,
6146 struct in_addr mcast_grp
)
6148 struct zebra_vrf
*zvrf
;
6150 if (local_vtep_ip
.s_addr
== INADDR_ANY
6151 || mcast_grp
.s_addr
== INADDR_ANY
)
6154 zvrf
= vrf_info_lookup(VRF_DEFAULT
);
6158 zebra_vxlan_sg_do_deref(zvrf
, local_vtep_ip
, mcast_grp
);
6161 void zebra_vxlan_sg_ref(struct in_addr local_vtep_ip
, struct in_addr mcast_grp
)
6163 struct zebra_vrf
*zvrf
;
6165 if (local_vtep_ip
.s_addr
== INADDR_ANY
6166 || mcast_grp
.s_addr
== INADDR_ANY
)
6169 zvrf
= vrf_info_lookup(VRF_DEFAULT
);
6172 zebra_vxlan_sg_do_ref(zvrf
, local_vtep_ip
, mcast_grp
);
6175 static void zebra_vxlan_xg_pre_cleanup(struct hash_bucket
*bucket
, void *arg
)
6177 struct zebra_vxlan_sg
*vxlan_sg
= (struct zebra_vxlan_sg
*)bucket
->data
;
6179 /* increment the ref count against (*,G) to prevent them from being
6182 if (vxlan_sg
->sg
.src
.s_addr
== INADDR_ANY
)
6183 ++vxlan_sg
->ref_cnt
;
6186 static void zebra_vxlan_xg_post_cleanup(struct hash_bucket
*bucket
, void *arg
)
6188 struct zebra_vxlan_sg
*vxlan_sg
= (struct zebra_vxlan_sg
*)bucket
->data
;
6190 /* decrement the dummy ref count against (*,G) to delete them */
6191 if (vxlan_sg
->sg
.src
.s_addr
== INADDR_ANY
) {
6192 if (vxlan_sg
->ref_cnt
)
6193 --vxlan_sg
->ref_cnt
;
6194 if (!vxlan_sg
->ref_cnt
)
6195 zebra_vxlan_sg_del(vxlan_sg
);
6199 static void zebra_vxlan_sg_cleanup(struct hash_bucket
*bucket
, void *arg
)
6201 struct zebra_vxlan_sg
*vxlan_sg
= (struct zebra_vxlan_sg
*)bucket
->data
;
6203 zebra_vxlan_sg_del(vxlan_sg
);
6206 static void zebra_vxlan_cleanup_sg_table(struct zebra_vrf
*zvrf
)
6208 /* increment the ref count against (*,G) to prevent them from being
6211 hash_iterate(zvrf
->vxlan_sg_table
, zebra_vxlan_xg_pre_cleanup
, NULL
);
6213 hash_iterate(zvrf
->vxlan_sg_table
, zebra_vxlan_sg_cleanup
, NULL
);
6215 /* decrement the dummy ref count against the XG entries */
6216 hash_iterate(zvrf
->vxlan_sg_table
, zebra_vxlan_xg_post_cleanup
, NULL
);
6219 static void zebra_vxlan_sg_replay_send(struct hash_bucket
*bucket
, void *arg
)
6221 struct zebra_vxlan_sg
*vxlan_sg
= (struct zebra_vxlan_sg
*)bucket
->data
;
6223 zebra_vxlan_sg_send(vxlan_sg
->zvrf
, &vxlan_sg
->sg
,
6224 vxlan_sg
->sg_str
, ZEBRA_VXLAN_SG_ADD
);
6227 /* Handle message from client to replay vxlan SG entries */
6228 void zebra_vxlan_sg_replay(ZAPI_HANDLER_ARGS
)
6230 if (IS_ZEBRA_DEBUG_VXLAN
)
6231 zlog_debug("VxLAN SG updates to PIM, start");
6233 SET_FLAG(zvrf
->flags
, ZEBRA_PIM_SEND_VXLAN_SG
);
6235 if (!EVPN_ENABLED(zvrf
)) {
6236 if (IS_ZEBRA_DEBUG_VXLAN
)
6237 zlog_debug("VxLAN SG replay request on unexpected vrf %d",
6242 hash_iterate(zvrf
->vxlan_sg_table
, zebra_vxlan_sg_replay_send
, NULL
);
6246 /* Cleanup EVPN configuration of a specific VRF */
6247 static void zebra_evpn_vrf_cfg_cleanup(struct zebra_vrf
*zvrf
)
6249 struct zebra_l3vni
*zl3vni
= NULL
;
6251 zvrf
->advertise_all_vni
= 0;
6252 zvrf
->advertise_gw_macip
= 0;
6253 zvrf
->advertise_svi_macip
= 0;
6254 zvrf
->vxlan_flood_ctrl
= VXLAN_FLOOD_HEAD_END_REPL
;
6256 hash_iterate(zvrf
->evpn_table
, zebra_evpn_cfg_cleanup
, NULL
);
6259 zl3vni
= zl3vni_lookup(zvrf
->l3vni
);
6261 /* delete and uninstall all rmacs */
6262 hash_iterate(zl3vni
->rmac_table
, zl3vni_del_rmac_hash_entry
,
6264 /* delete and uninstall all next-hops */
6265 hash_iterate(zl3vni
->nh_table
, zl3vni_del_nh_hash_entry
,
6270 /* Cleanup BGP EVPN configuration upon client disconnect */
6271 static int zebra_evpn_bgp_cfg_clean_up(struct zserv
*client
)
6274 struct zebra_vrf
*zvrf
;
6276 RB_FOREACH (vrf
, vrf_id_head
, &vrfs_by_id
) {
6279 zebra_evpn_vrf_cfg_cleanup(zvrf
);
6285 static int zebra_evpn_pim_cfg_clean_up(struct zserv
*client
)
6287 struct zebra_vrf
*zvrf
= zebra_vrf_get_evpn();
6289 if (CHECK_FLAG(zvrf
->flags
, ZEBRA_PIM_SEND_VXLAN_SG
)) {
6290 if (IS_ZEBRA_DEBUG_VXLAN
)
6291 zlog_debug("VxLAN SG updates to PIM, stop");
6292 UNSET_FLAG(zvrf
->flags
, ZEBRA_PIM_SEND_VXLAN_SG
);
6298 static int zebra_evpn_cfg_clean_up(struct zserv
*client
)
6300 if (client
->proto
== ZEBRA_ROUTE_BGP
)
6301 return zebra_evpn_bgp_cfg_clean_up(client
);
6303 if (client
->proto
== ZEBRA_ROUTE_PIM
)
6304 return zebra_evpn_pim_cfg_clean_up(client
);
6310 * Handle results for vxlan dataplane operations.
6312 extern void zebra_vxlan_handle_result(struct zebra_dplane_ctx
*ctx
)
6317 /* Config knob for accepting lower sequence numbers */
6318 void zebra_vxlan_set_accept_bgp_seq(bool set
)
6320 accept_bgp_seq
= set
;
6323 bool zebra_vxlan_get_accept_bgp_seq(void)
6325 return accept_bgp_seq
;
6328 /* Cleanup BGP EVPN configuration upon client disconnect */
6329 extern void zebra_evpn_init(void)
6331 hook_register(zserv_client_close
, zebra_evpn_cfg_clean_up
);