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_evpn.h"
53 #include "zebra/zebra_evpn_mac.h"
54 #include "zebra/zebra_evpn_neigh.h"
55 #include "zebra/zebra_vxlan_private.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
);
113 static void zebra_vxlan_process_l3vni_oper_up(struct zebra_l3vni
*zl3vni
);
114 static void zebra_vxlan_process_l3vni_oper_down(struct zebra_l3vni
*zl3vni
);
116 static void zevpn_build_hash_table(void);
117 static unsigned int zebra_vxlan_sg_hash_key_make(const void *p
);
118 static bool zebra_vxlan_sg_hash_eq(const void *p1
, const void *p2
);
119 static void zebra_vxlan_sg_do_deref(struct zebra_vrf
*zvrf
,
120 struct in_addr sip
, struct in_addr mcast_grp
);
121 static struct zebra_vxlan_sg
*zebra_vxlan_sg_do_ref(struct zebra_vrf
*vrf
,
123 struct in_addr mcast_grp
);
124 static void zebra_vxlan_sg_deref(struct in_addr local_vtep_ip
,
125 struct in_addr mcast_grp
);
126 static void zebra_vxlan_sg_ref(struct in_addr local_vtep_ip
,
127 struct in_addr mcast_grp
);
128 static void zebra_vxlan_cleanup_sg_table(struct zebra_vrf
*zvrf
);
130 bool zebra_evpn_do_dup_addr_detect(struct zebra_vrf
*zvrf
)
132 return zvrf
->dup_addr_detect
&& zebra_evpn_mh_do_dup_addr_detect();
135 /* Private functions */
136 static int host_rb_entry_compare(const struct host_rb_entry
*hle1
,
137 const struct host_rb_entry
*hle2
)
139 if (hle1
->p
.family
< hle2
->p
.family
)
142 if (hle1
->p
.family
> hle2
->p
.family
)
145 if (hle1
->p
.prefixlen
< hle2
->p
.prefixlen
)
148 if (hle1
->p
.prefixlen
> hle2
->p
.prefixlen
)
151 if (hle1
->p
.family
== AF_INET
) {
152 if (hle1
->p
.u
.prefix4
.s_addr
< hle2
->p
.u
.prefix4
.s_addr
)
155 if (hle1
->p
.u
.prefix4
.s_addr
> hle2
->p
.u
.prefix4
.s_addr
)
159 } else if (hle1
->p
.family
== AF_INET6
) {
160 return memcmp(&hle1
->p
.u
.prefix6
, &hle2
->p
.u
.prefix6
,
162 } else if (hle1
->p
.family
== AF_EVPN
) {
166 /* two (v4/v6) dummy prefixes of route_type BGP_EVPN_AD_ROUTE
167 * are used for all nexthops associated with a non-zero ESI
169 family1
= is_evpn_prefix_ipaddr_v4(
170 (const struct prefix_evpn
*)&hle1
->p
)
173 family2
= is_evpn_prefix_ipaddr_v4(
174 (const struct prefix_evpn
*)&hle2
->p
)
179 if (family1
< family2
)
182 if (family1
> family2
)
187 zlog_debug("%s: Unexpected family type: %d", __func__
,
192 RB_GENERATE(host_rb_tree_entry
, host_rb_entry
, hl_entry
, host_rb_entry_compare
);
194 static uint32_t rb_host_count(struct host_rb_tree_entry
*hrbe
)
196 struct host_rb_entry
*hle
;
199 RB_FOREACH (hle
, host_rb_tree_entry
, hrbe
)
205 static int l3vni_rmac_nh_list_cmp(void *p1
, void *p2
)
207 const struct ipaddr
*vtep_ip1
= p1
;
208 const struct ipaddr
*vtep_ip2
= p2
;
210 return !ipaddr_cmp(vtep_ip1
, vtep_ip2
);
213 static void l3vni_rmac_nh_free(struct ipaddr
*vtep_ip
)
215 XFREE(MTYPE_EVPN_VTEP
, vtep_ip
);
218 static void l3vni_rmac_nh_list_nh_delete(struct zebra_l3vni
*zl3vni
,
219 struct zebra_mac
*zrmac
,
220 struct ipaddr
*vtep_ip
)
222 struct listnode
*node
= NULL
, *nnode
= NULL
;
223 struct ipaddr
*vtep
= NULL
;
225 for (ALL_LIST_ELEMENTS(zrmac
->nh_list
, node
, nnode
, vtep
)) {
226 if (ipaddr_cmp(vtep
, vtep_ip
) == 0)
231 l3vni_rmac_nh_free(vtep
);
232 list_delete_node(zrmac
->nh_list
, node
);
237 * Print neighbors for all EVPN.
239 static void zevpn_print_neigh_hash_all_evpn(struct hash_bucket
*bucket
,
243 json_object
*json
= NULL
, *json_evpn
= NULL
;
244 struct zebra_evpn
*zevpn
;
246 struct neigh_walk_ctx wctx
;
247 char vni_str
[VNI_STR_LEN
];
250 vty
= (struct vty
*)args
[0];
251 json
= (json_object
*)args
[1];
252 print_dup
= (uint32_t)(uintptr_t)args
[2];
254 zevpn
= (struct zebra_evpn
*)bucket
->data
;
256 num_neigh
= hashcount(zevpn
->neigh_table
);
259 num_neigh
= num_dup_detected_neighs(zevpn
);
263 "\nVNI %u #ARP (IPv4 and IPv6, local and remote) %u\n\n",
264 zevpn
->vni
, num_neigh
);
266 json_evpn
= json_object_new_object();
267 json_object_int_add(json_evpn
, "numArpNd", num_neigh
);
268 snprintf(vni_str
, VNI_STR_LEN
, "%u", zevpn
->vni
);
273 json_object_object_add(json
, vni_str
, json_evpn
);
277 /* Since we have IPv6 addresses to deal with which can vary widely in
278 * size, we try to be a bit more elegant in display by first computing
281 memset(&wctx
, 0, sizeof(wctx
));
284 wctx
.addr_width
= 15;
285 wctx
.json
= json_evpn
;
286 hash_iterate(zevpn
->neigh_table
, zebra_evpn_find_neigh_addr_width
,
290 zebra_evpn_print_neigh_hdr(vty
, &wctx
);
293 hash_iterate(zevpn
->neigh_table
,
294 zebra_evpn_print_dad_neigh_hash
, &wctx
);
296 hash_iterate(zevpn
->neigh_table
, zebra_evpn_print_neigh_hash
,
300 json_object_object_add(json
, vni_str
, json_evpn
);
304 * Print neighbors for all EVPNs in detail.
306 static void zevpn_print_neigh_hash_all_evpn_detail(struct hash_bucket
*bucket
,
310 json_object
*json
= NULL
, *json_evpn
= NULL
;
311 struct zebra_evpn
*zevpn
;
313 struct neigh_walk_ctx wctx
;
314 char vni_str
[VNI_STR_LEN
];
317 vty
= (struct vty
*)args
[0];
318 json
= (json_object
*)args
[1];
319 print_dup
= (uint32_t)(uintptr_t)args
[2];
321 zevpn
= (struct zebra_evpn
*)bucket
->data
;
324 vty_out(vty
, "{}\n");
327 num_neigh
= hashcount(zevpn
->neigh_table
);
329 if (print_dup
&& num_dup_detected_neighs(zevpn
) == 0)
334 "\nVNI %u #ARP (IPv4 and IPv6, local and remote) %u\n\n",
335 zevpn
->vni
, num_neigh
);
337 json_evpn
= json_object_new_object();
338 json_object_int_add(json_evpn
, "numArpNd", num_neigh
);
339 snprintf(vni_str
, VNI_STR_LEN
, "%u", zevpn
->vni
);
343 json_object_object_add(json
, vni_str
, json_evpn
);
347 memset(&wctx
, 0, sizeof(wctx
));
350 wctx
.addr_width
= 15;
351 wctx
.json
= json_evpn
;
354 hash_iterate(zevpn
->neigh_table
,
355 zebra_evpn_print_dad_neigh_hash_detail
, &wctx
);
357 hash_iterate(zevpn
->neigh_table
,
358 zebra_evpn_print_neigh_hash_detail
, &wctx
);
361 json_object_object_add(json
, vni_str
, json_evpn
);
364 /* print a specific next hop for an l3vni */
365 static void zl3vni_print_nh(struct zebra_neigh
*n
, struct vty
*vty
,
368 char buf1
[ETHER_ADDR_STRLEN
];
369 char buf2
[INET6_ADDRSTRLEN
];
370 json_object
*json_hosts
= NULL
;
371 struct host_rb_entry
*hle
;
374 vty_out(vty
, "Ip: %s\n",
375 ipaddr2str(&n
->ip
, buf2
, sizeof(buf2
)));
376 vty_out(vty
, " RMAC: %s\n",
377 prefix_mac2str(&n
->emac
, buf1
, sizeof(buf1
)));
378 vty_out(vty
, " Refcount: %d\n",
379 rb_host_count(&n
->host_rb
));
380 vty_out(vty
, " Prefixes:\n");
381 RB_FOREACH (hle
, host_rb_tree_entry
, &n
->host_rb
)
382 vty_out(vty
, " %pFX\n", &hle
->p
);
384 json_hosts
= json_object_new_array();
385 json_object_string_add(
386 json
, "ip", ipaddr2str(&(n
->ip
), buf2
, sizeof(buf2
)));
387 json_object_string_add(
389 prefix_mac2str(&n
->emac
, buf2
, sizeof(buf2
)));
390 json_object_int_add(json
, "refCount",
391 rb_host_count(&n
->host_rb
));
392 RB_FOREACH (hle
, host_rb_tree_entry
, &n
->host_rb
)
393 json_object_array_add(json_hosts
,
394 json_object_new_string(prefix2str(
395 &hle
->p
, buf2
, sizeof(buf2
))));
396 json_object_object_add(json
, "prefixList", json_hosts
);
400 /* Print a specific RMAC entry */
401 static void zl3vni_print_rmac(struct zebra_mac
*zrmac
, struct vty
*vty
,
404 struct listnode
*node
= NULL
;
405 struct ipaddr
*vtep
= NULL
;
406 json_object
*json_nhs
= NULL
;
409 vty_out(vty
, "MAC: %pEA\n", &zrmac
->macaddr
);
410 vty_out(vty
, " Remote VTEP: %pI4\n",
411 &zrmac
->fwd_info
.r_vtep_ip
);
413 json_nhs
= json_object_new_array();
414 json_object_string_addf(json
, "routerMac", "%pEA",
416 json_object_string_addf(json
, "vtepIp", "%pI4",
417 &zrmac
->fwd_info
.r_vtep_ip
);
418 for (ALL_LIST_ELEMENTS_RO(zrmac
->nh_list
, node
, vtep
)) {
419 json_object_array_add(json_nhs
, json_object_new_stringf(
422 json_object_object_add(json
, "nexthops", json_nhs
);
427 * Print MACs for all EVPNs.
429 static void zevpn_print_mac_hash_all_evpn(struct hash_bucket
*bucket
, void *ctxt
)
432 json_object
*json
= NULL
, *json_evpn
= NULL
;
433 json_object
*json_mac
= NULL
;
434 struct zebra_evpn
*zevpn
;
436 struct mac_walk_ctx
*wctx
= ctxt
;
437 char vni_str
[VNI_STR_LEN
];
442 zevpn
= (struct zebra_evpn
*)bucket
->data
;
445 /*We are iterating over a new VNI, set the count to 0*/
448 num_macs
= num_valid_macs(zevpn
);
453 num_macs
= num_dup_detected_macs(zevpn
);
456 json_evpn
= json_object_new_object();
457 json_mac
= json_object_new_object();
458 snprintf(vni_str
, VNI_STR_LEN
, "%u", zevpn
->vni
);
461 if (!CHECK_FLAG(wctx
->flags
, SHOW_REMOTE_MAC_FROM_VTEP
)) {
463 vty_out(vty
, "\nVNI %u #MACs (local and remote) %u\n\n",
464 zevpn
->vni
, num_macs
);
466 "Flags: N=sync-neighs, I=local-inactive, P=peer-active, X=peer-proxy\n");
467 vty_out(vty
, "%-17s %-6s %-5s %-30s %-5s %s\n", "MAC",
468 "Type", "Flags", "Intf/Remote ES/VTEP",
471 json_object_int_add(json_evpn
, "numMacs", num_macs
);
476 json_object_int_add(json_evpn
, "numMacs", num_macs
);
477 json_object_object_add(json
, vni_str
, json_evpn
);
482 /* assign per-evpn to wctx->json object to fill macs
483 * under the evpn. Re-assign primary json object to fill
484 * next evpn information.
486 wctx
->json
= json_mac
;
488 hash_iterate(zevpn
->mac_table
, zebra_evpn_print_dad_mac_hash
,
491 hash_iterate(zevpn
->mac_table
, zebra_evpn_print_mac_hash
, wctx
);
495 json_object_object_add(json_evpn
, "macs", json_mac
);
496 json_object_object_add(json
, vni_str
, json_evpn
);
501 * Print MACs in detail for all EVPNs.
503 static void zevpn_print_mac_hash_all_evpn_detail(struct hash_bucket
*bucket
,
507 json_object
*json
= NULL
, *json_evpn
= NULL
;
508 json_object
*json_mac
= NULL
;
509 struct zebra_evpn
*zevpn
;
511 struct mac_walk_ctx
*wctx
= ctxt
;
512 char vni_str
[VNI_STR_LEN
];
517 zevpn
= (struct zebra_evpn
*)bucket
->data
;
520 vty_out(vty
, "{}\n");
525 /*We are iterating over a new EVPN, set the count to 0*/
528 num_macs
= num_valid_macs(zevpn
);
532 if (wctx
->print_dup
&& (num_dup_detected_macs(zevpn
) == 0))
536 json_evpn
= json_object_new_object();
537 json_mac
= json_object_new_object();
538 snprintf(vni_str
, VNI_STR_LEN
, "%u", zevpn
->vni
);
541 if (!CHECK_FLAG(wctx
->flags
, SHOW_REMOTE_MAC_FROM_VTEP
)) {
543 vty_out(vty
, "\nVNI %u #MACs (local and remote) %u\n\n",
544 zevpn
->vni
, num_macs
);
546 json_object_int_add(json_evpn
, "numMacs", num_macs
);
548 /* assign per-evpn to wctx->json object to fill macs
549 * under the evpn. Re-assign primary json object to fill
550 * next evpn information.
552 wctx
->json
= json_mac
;
554 hash_iterate(zevpn
->mac_table
,
555 zebra_evpn_print_dad_mac_hash_detail
, wctx
);
557 hash_iterate(zevpn
->mac_table
, zebra_evpn_print_mac_hash_detail
,
562 json_object_object_add(json_evpn
, "macs", json_mac
);
563 json_object_object_add(json
, vni_str
, json_evpn
);
567 static void zl3vni_print_nh_hash(struct hash_bucket
*bucket
, void *ctx
)
569 struct nh_walk_ctx
*wctx
= NULL
;
570 struct vty
*vty
= NULL
;
571 struct json_object
*json_evpn
= NULL
;
572 struct json_object
*json_nh
= NULL
;
573 struct zebra_neigh
*n
= NULL
;
574 char buf1
[ETHER_ADDR_STRLEN
];
575 char buf2
[INET6_ADDRSTRLEN
];
577 wctx
= (struct nh_walk_ctx
*)ctx
;
579 json_evpn
= wctx
->json
;
581 json_nh
= json_object_new_object();
582 n
= (struct zebra_neigh
*)bucket
->data
;
585 vty_out(vty
, "%-15s %-17s\n",
586 ipaddr2str(&(n
->ip
), buf2
, sizeof(buf2
)),
587 prefix_mac2str(&n
->emac
, buf1
, sizeof(buf1
)));
589 json_object_string_add(json_nh
, "nexthopIp",
590 ipaddr2str(&n
->ip
, buf2
, sizeof(buf2
)));
591 json_object_string_add(
592 json_nh
, "routerMac",
593 prefix_mac2str(&n
->emac
, buf1
, sizeof(buf1
)));
594 json_object_object_add(json_evpn
,
595 ipaddr2str(&(n
->ip
), buf2
, sizeof(buf2
)),
600 static void zl3vni_print_nh_hash_all_vni(struct hash_bucket
*bucket
,
603 struct vty
*vty
= NULL
;
604 json_object
*json
= NULL
;
605 json_object
*json_evpn
= NULL
;
606 struct zebra_l3vni
*zl3vni
= NULL
;
608 struct nh_walk_ctx wctx
;
609 char vni_str
[VNI_STR_LEN
];
611 vty
= (struct vty
*)args
[0];
612 json
= (struct json_object
*)args
[1];
614 zl3vni
= (struct zebra_l3vni
*)bucket
->data
;
616 num_nh
= hashcount(zl3vni
->nh_table
);
621 json_evpn
= json_object_new_object();
622 snprintf(vni_str
, VNI_STR_LEN
, "%u", zl3vni
->vni
);
626 vty_out(vty
, "\nVNI %u #Next-Hops %u\n\n", zl3vni
->vni
, num_nh
);
627 vty_out(vty
, "%-15s %-17s\n", "IP", "RMAC");
629 json_object_int_add(json_evpn
, "numNextHops", num_nh
);
631 memset(&wctx
, 0, sizeof(wctx
));
633 wctx
.json
= json_evpn
;
634 hash_iterate(zl3vni
->nh_table
, zl3vni_print_nh_hash
, &wctx
);
636 json_object_object_add(json
, vni_str
, json_evpn
);
639 static void zl3vni_print_rmac_hash_all_vni(struct hash_bucket
*bucket
,
642 struct vty
*vty
= NULL
;
643 json_object
*json
= NULL
;
644 json_object
*json_evpn
= NULL
;
645 struct zebra_l3vni
*zl3vni
= NULL
;
647 struct rmac_walk_ctx wctx
;
648 char vni_str
[VNI_STR_LEN
];
650 vty
= (struct vty
*)args
[0];
651 json
= (struct json_object
*)args
[1];
653 zl3vni
= (struct zebra_l3vni
*)bucket
->data
;
655 num_rmacs
= hashcount(zl3vni
->rmac_table
);
660 json_evpn
= json_object_new_object();
661 snprintf(vni_str
, VNI_STR_LEN
, "%u", zl3vni
->vni
);
665 vty_out(vty
, "\nVNI %u #RMACs %u\n\n", zl3vni
->vni
, num_rmacs
);
666 vty_out(vty
, "%-17s %-21s\n", "RMAC", "Remote VTEP");
668 json_object_int_add(json_evpn
, "numRmacs", num_rmacs
);
670 /* assign per-vni to wctx->json object to fill macs
671 * under the vni. Re-assign primary json object to fill
672 * next vni information.
674 memset(&wctx
, 0, sizeof(wctx
));
676 wctx
.json
= json_evpn
;
677 hash_iterate(zl3vni
->rmac_table
, zl3vni_print_rmac_hash
, &wctx
);
679 json_object_object_add(json
, vni_str
, json_evpn
);
682 static void zl3vni_print_rmac_hash(struct hash_bucket
*bucket
, void *ctx
)
684 struct zebra_mac
*zrmac
= NULL
;
685 struct rmac_walk_ctx
*wctx
= NULL
;
686 struct vty
*vty
= NULL
;
687 struct json_object
*json
= NULL
;
688 struct json_object
*json_rmac
= NULL
;
689 char buf
[PREFIX_STRLEN
];
691 wctx
= (struct rmac_walk_ctx
*)ctx
;
695 json_rmac
= json_object_new_object();
696 zrmac
= (struct zebra_mac
*)bucket
->data
;
699 vty_out(vty
, "%-17s %-21pI4\n",
700 prefix_mac2str(&zrmac
->macaddr
, buf
, sizeof(buf
)),
701 &zrmac
->fwd_info
.r_vtep_ip
);
703 json_object_string_add(
704 json_rmac
, "routerMac",
705 prefix_mac2str(&zrmac
->macaddr
, buf
, sizeof(buf
)));
706 json_object_string_addf(json_rmac
, "vtepIp", "%pI4",
707 &zrmac
->fwd_info
.r_vtep_ip
);
708 json_object_object_add(
709 json
, prefix_mac2str(&zrmac
->macaddr
, buf
, sizeof(buf
)),
714 /* print a specific L3 VNI entry */
715 static void zl3vni_print(struct zebra_l3vni
*zl3vni
, void **ctx
)
717 char buf
[PREFIX_STRLEN
];
718 struct vty
*vty
= NULL
;
719 json_object
*json
= NULL
;
720 struct zebra_evpn
*zevpn
= NULL
;
721 json_object
*json_evpn_list
= NULL
;
722 struct listnode
*node
= NULL
, *nnode
= NULL
;
728 vty_out(vty
, "VNI: %u\n", zl3vni
->vni
);
729 vty_out(vty
, " Type: %s\n", "L3");
730 vty_out(vty
, " Tenant VRF: %s\n", zl3vni_vrf_name(zl3vni
));
731 vty_out(vty
, " Local Vtep Ip: %pI4\n",
732 &zl3vni
->local_vtep_ip
);
733 vty_out(vty
, " Vxlan-Intf: %s\n",
734 zl3vni_vxlan_if_name(zl3vni
));
735 vty_out(vty
, " SVI-If: %s\n", zl3vni_svi_if_name(zl3vni
));
736 vty_out(vty
, " State: %s\n", zl3vni_state2str(zl3vni
));
737 vty_out(vty
, " VNI Filter: %s\n",
738 CHECK_FLAG(zl3vni
->filter
, PREFIX_ROUTES_ONLY
)
739 ? "prefix-routes-only"
741 vty_out(vty
, " System MAC: %s\n",
742 zl3vni_sysmac2str(zl3vni
, buf
, sizeof(buf
)));
743 vty_out(vty
, " Router MAC: %s\n",
744 zl3vni_rmac2str(zl3vni
, buf
, sizeof(buf
)));
745 vty_out(vty
, " L2 VNIs: ");
746 for (ALL_LIST_ELEMENTS(zl3vni
->l2vnis
, node
, nnode
, zevpn
))
747 vty_out(vty
, "%u ", zevpn
->vni
);
750 json_evpn_list
= json_object_new_array();
751 json_object_int_add(json
, "vni", zl3vni
->vni
);
752 json_object_string_add(json
, "type", "L3");
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(json
, "vrf", zl3vni_vrf_name(zl3vni
));
761 json_object_string_add(
763 zl3vni_sysmac2str(zl3vni
, buf
, sizeof(buf
)));
764 json_object_string_add(
766 zl3vni_rmac2str(zl3vni
, buf
, sizeof(buf
)));
767 json_object_string_add(
769 CHECK_FLAG(zl3vni
->filter
, PREFIX_ROUTES_ONLY
)
770 ? "prefix-routes-only"
772 for (ALL_LIST_ELEMENTS(zl3vni
->l2vnis
, node
, nnode
, zevpn
)) {
773 json_object_array_add(json_evpn_list
,
774 json_object_new_int(zevpn
->vni
));
776 json_object_object_add(json
, "l2Vnis", json_evpn_list
);
780 /* print a L3 VNI hash entry */
781 static void zl3vni_print_hash(struct hash_bucket
*bucket
, void *ctx
[])
783 struct vty
*vty
= NULL
;
784 json_object
*json
= NULL
;
785 json_object
*json_evpn
= NULL
;
786 struct zebra_l3vni
*zl3vni
= NULL
;
788 vty
= (struct vty
*)ctx
[0];
789 json
= (json_object
*)ctx
[1];
791 zl3vni
= (struct zebra_l3vni
*)bucket
->data
;
794 vty_out(vty
, "%-10u %-4s %-21s %-8lu %-8lu %-15s %-37s\n",
795 zl3vni
->vni
, "L3", zl3vni_vxlan_if_name(zl3vni
),
796 hashcount(zl3vni
->rmac_table
),
797 hashcount(zl3vni
->nh_table
), "n/a",
798 zl3vni_vrf_name(zl3vni
));
800 char vni_str
[VNI_STR_LEN
];
802 snprintf(vni_str
, VNI_STR_LEN
, "%u", zl3vni
->vni
);
803 json_evpn
= json_object_new_object();
804 json_object_int_add(json_evpn
, "vni", zl3vni
->vni
);
805 json_object_string_add(json_evpn
, "vxlanIf",
806 zl3vni_vxlan_if_name(zl3vni
));
807 json_object_int_add(json_evpn
, "numMacs",
808 hashcount(zl3vni
->rmac_table
));
809 json_object_int_add(json_evpn
, "numArpNd",
810 hashcount(zl3vni
->nh_table
));
811 json_object_string_add(json_evpn
, "numRemoteVteps", "n/a");
812 json_object_string_add(json_evpn
, "type", "L3");
813 json_object_string_add(json_evpn
, "tenantVrf",
814 zl3vni_vrf_name(zl3vni
));
815 json_object_object_add(json
, vni_str
, json_evpn
);
819 /* print a L3 VNI hash entry in detail*/
820 static void zl3vni_print_hash_detail(struct hash_bucket
*bucket
, void *data
)
822 struct vty
*vty
= NULL
;
823 struct zebra_l3vni
*zl3vni
= NULL
;
824 json_object
*json_array
= NULL
;
825 bool use_json
= false;
826 struct zebra_evpn_show
*zes
= data
;
829 json_array
= zes
->json
;
830 use_json
= zes
->use_json
;
832 zl3vni
= (struct zebra_l3vni
*)bucket
->data
;
834 zebra_vxlan_print_vni(vty
, zes
->zvrf
, zl3vni
->vni
,
835 use_json
, json_array
);
841 static int zvni_map_to_svi_ns(struct ns
*ns
,
845 struct zebra_ns
*zns
= ns
->info
;
846 struct route_node
*rn
;
847 struct zebra_from_svi_param
*in_param
=
848 (struct zebra_from_svi_param
*)_in_param
;
849 struct zebra_l2info_vlan
*vl
;
850 struct interface
*tmp_if
= NULL
;
851 struct interface
**p_ifp
= (struct interface
**)_p_ifp
;
852 struct zebra_if
*zif
;
854 assert(in_param
&& p_ifp
);
856 /* TODO: Optimize with a hash. */
857 for (rn
= route_top(zns
->if_table
); rn
; rn
= route_next(rn
)) {
858 tmp_if
= (struct interface
*)rn
->info
;
859 /* Check oper status of the SVI. */
860 if (!tmp_if
|| !if_is_operative(tmp_if
))
863 if (!zif
|| zif
->zif_type
!= ZEBRA_IF_VLAN
864 || zif
->link
!= in_param
->br_if
)
866 vl
= (struct zebra_l2info_vlan
*)&zif
->l2info
.vl
;
868 if (vl
->vid
== in_param
->vid
) {
873 return NS_WALK_CONTINUE
;
876 /* Map to SVI on bridge corresponding to specified VLAN. This can be one
878 * (a) In the case of a VLAN-aware bridge, the SVI is a L3 VLAN interface
879 * linked to the bridge
880 * (b) In the case of a VLAN-unaware bridge, the SVI is the bridge interface
883 struct interface
*zvni_map_to_svi(vlanid_t vid
, struct interface
*br_if
)
885 struct interface
*tmp_if
= NULL
;
886 struct zebra_if
*zif
;
887 struct zebra_l2info_bridge
*br
;
888 struct zebra_from_svi_param in_param
;
889 struct interface
**p_ifp
;
890 /* Defensive check, caller expected to invoke only with valid bridge. */
894 /* Determine if bridge is VLAN-aware or not */
897 br
= &zif
->l2info
.br
;
898 in_param
.bridge_vlan_aware
= br
->vlan_aware
;
899 /* Check oper status of the SVI. */
900 if (!in_param
.bridge_vlan_aware
)
901 return if_is_operative(br_if
) ? br_if
: NULL
;
904 in_param
.br_if
= br_if
;
907 /* Identify corresponding VLAN interface. */
908 ns_walk_func(zvni_map_to_svi_ns
, (void *)&in_param
,
913 static int zebra_evpn_vxlan_del(struct zebra_evpn
*zevpn
)
915 zevpn_vxlan_if_set(zevpn
, zevpn
->vxlan_if
, false /* set */);
917 /* Remove references to the BUM mcast grp */
918 zebra_vxlan_sg_deref(zevpn
->local_vtep_ip
, zevpn
->mcast_grp
);
920 return zebra_evpn_del(zevpn
);
923 static int zevpn_build_hash_table_zns(struct ns
*ns
,
924 void *param_in
__attribute__((unused
)),
925 void **param_out
__attribute__((unused
)))
927 struct zebra_ns
*zns
= ns
->info
;
928 struct route_node
*rn
;
929 struct interface
*ifp
;
930 struct zebra_vrf
*zvrf
;
932 zvrf
= zebra_vrf_get_evpn();
934 /* Walk VxLAN interfaces and create EVPN hash. */
935 for (rn
= route_top(zns
->if_table
); rn
; rn
= route_next(rn
)) {
937 struct zebra_evpn
*zevpn
= NULL
;
938 struct zebra_l3vni
*zl3vni
= NULL
;
939 struct zebra_if
*zif
;
940 struct zebra_l2info_vxlan
*vxl
;
942 ifp
= (struct interface
*)rn
->info
;
946 if (!zif
|| zif
->zif_type
!= ZEBRA_IF_VXLAN
)
949 vxl
= &zif
->l2info
.vxl
;
951 /* link of VXLAN interface should be in zebra_evpn_vrf */
952 if (zvrf
->zns
->ns_id
!= vxl
->link_nsid
) {
953 if (IS_ZEBRA_DEBUG_VXLAN
)
955 "Intf %s(%u) VNI %u, link not in same "
956 "namespace than BGP EVPN core instance ",
957 ifp
->name
, ifp
->ifindex
, vni
);
960 /* L3-VNI and L2-VNI are handled seperately */
961 zl3vni
= zl3vni_lookup(vni
);
964 if (IS_ZEBRA_DEBUG_VXLAN
)
966 "create L3-VNI hash for Intf %s(%u) L3-VNI %u",
967 ifp
->name
, ifp
->ifindex
, vni
);
969 /* associate with vxlan_if */
970 zl3vni
->local_vtep_ip
= vxl
->vtep_ip
;
971 zl3vni
->vxlan_if
= ifp
;
974 * we need to associate with SVI.
975 * we can associate with svi-if only after association
976 * with vxlan-intf is complete
978 zl3vni
->svi_if
= zl3vni_map_to_svi_if(zl3vni
);
980 /* Associate l3vni to mac-vlan and extract VRR MAC */
981 zl3vni
->mac_vlan_if
= zl3vni_map_to_mac_vlan_if(zl3vni
);
983 if (IS_ZEBRA_DEBUG_VXLAN
)
984 zlog_debug("create l3vni %u svi_if %s mac_vlan_if %s",
985 vni
, zl3vni
->svi_if
? zl3vni
->svi_if
->name
987 zl3vni
->mac_vlan_if
?
988 zl3vni
->mac_vlan_if
->name
: "NIL");
990 if (is_l3vni_oper_up(zl3vni
))
991 zebra_vxlan_process_l3vni_oper_up(zl3vni
);
994 struct interface
*vlan_if
= NULL
;
996 if (IS_ZEBRA_DEBUG_VXLAN
)
998 "Create L2-VNI hash for intf %s(%u) L2-VNI %u local IP %pI4",
999 ifp
->name
, ifp
->ifindex
, vni
,
1002 /* EVPN hash entry is expected to exist, if the BGP process is killed */
1003 zevpn
= zebra_evpn_lookup(vni
);
1006 "EVPN hash already present for IF %s(%u) L2-VNI %u",
1007 ifp
->name
, ifp
->ifindex
, vni
);
1010 * Inform BGP if intf is up and mapped to
1013 if (if_is_operative(ifp
) &&
1014 zif
->brslave_info
.br_if
)
1015 zebra_evpn_send_add_to_client(zevpn
);
1017 /* Send Local MAC-entries to client */
1018 zebra_evpn_send_mac_list_to_client(zevpn
);
1020 /* Send Loval Neighbor entries to client */
1021 zebra_evpn_send_neigh_to_client(zevpn
);
1023 zevpn
= zebra_evpn_add(vni
);
1026 "Failed to add EVPN hash, IF %s(%u) L2-VNI %u",
1027 ifp
->name
, ifp
->ifindex
, vni
);
1028 return NS_WALK_CONTINUE
;
1031 if (zevpn
->local_vtep_ip
.s_addr
!=
1032 vxl
->vtep_ip
.s_addr
||
1033 zevpn
->mcast_grp
.s_addr
!=
1034 vxl
->mcast_grp
.s_addr
) {
1035 zebra_vxlan_sg_deref(
1036 zevpn
->local_vtep_ip
,
1038 zebra_vxlan_sg_ref(vxl
->vtep_ip
,
1040 zevpn
->local_vtep_ip
= vxl
->vtep_ip
;
1041 zevpn
->mcast_grp
= vxl
->mcast_grp
;
1042 /* on local vtep-ip check if ES
1043 * orig-ip needs to be updated
1045 zebra_evpn_es_set_base_evpn(zevpn
);
1047 zevpn_vxlan_if_set(zevpn
, ifp
, true /* set */);
1048 vlan_if
= zvni_map_to_svi(
1050 zif
->brslave_info
.br_if
);
1052 zevpn
->svi_if
= vlan_if
;
1053 zevpn
->vrf_id
= vlan_if
->vrf
->vrf_id
;
1054 zl3vni
= zl3vni_from_vrf(
1055 vlan_if
->vrf
->vrf_id
);
1058 zl3vni
->l2vnis
, zevpn
);
1062 * Inform BGP if intf is up and mapped to
1065 if (if_is_operative(ifp
) &&
1066 zif
->brslave_info
.br_if
)
1067 zebra_evpn_send_add_to_client(zevpn
);
1071 return NS_WALK_CONTINUE
;
1075 * Build the VNI hash table by going over the VxLAN interfaces. This
1076 * is called when EVPN (advertise-all-vni) is enabled.
1079 static void zevpn_build_hash_table(void)
1081 ns_walk_func(zevpn_build_hash_table_zns
, NULL
, NULL
);
1085 * Cleanup EVPN/VTEP and update kernel
1087 static void zebra_evpn_vxlan_cleanup_all(struct hash_bucket
*bucket
, void *arg
)
1089 struct zebra_evpn
*zevpn
= NULL
;
1090 struct zebra_l3vni
*zl3vni
= NULL
;
1092 zevpn
= (struct zebra_evpn
*)bucket
->data
;
1094 /* remove l2vni from l2vni's tenant-vrf l3-vni list */
1095 zl3vni
= zl3vni_from_vrf(zevpn
->vrf_id
);
1097 listnode_delete(zl3vni
->l2vnis
, zevpn
);
1099 zebra_evpn_cleanup_all(bucket
, arg
);
1103 static void zl3vni_cleanup_all(struct hash_bucket
*bucket
, void *args
)
1105 struct zebra_l3vni
*zl3vni
= NULL
;
1107 zl3vni
= (struct zebra_l3vni
*)bucket
->data
;
1109 zebra_vxlan_process_l3vni_oper_down(zl3vni
);
1112 static void rb_find_or_add_host(struct host_rb_tree_entry
*hrbe
,
1113 const struct prefix
*host
)
1115 struct host_rb_entry lookup
;
1116 struct host_rb_entry
*hle
;
1118 memset(&lookup
, 0, sizeof(lookup
));
1119 memcpy(&lookup
.p
, host
, sizeof(*host
));
1121 hle
= RB_FIND(host_rb_tree_entry
, hrbe
, &lookup
);
1125 hle
= XCALLOC(MTYPE_HOST_PREFIX
, sizeof(struct host_rb_entry
));
1126 memcpy(hle
, &lookup
, sizeof(lookup
));
1128 RB_INSERT(host_rb_tree_entry
, hrbe
, hle
);
1131 static void rb_delete_host(struct host_rb_tree_entry
*hrbe
, struct prefix
*host
)
1133 struct host_rb_entry lookup
;
1134 struct host_rb_entry
*hle
;
1136 memset(&lookup
, 0, sizeof(lookup
));
1137 memcpy(&lookup
.p
, host
, sizeof(*host
));
1139 hle
= RB_FIND(host_rb_tree_entry
, hrbe
, &lookup
);
1141 RB_REMOVE(host_rb_tree_entry
, hrbe
, hle
);
1142 XFREE(MTYPE_HOST_PREFIX
, hle
);
1149 * Look up MAC hash entry.
1151 static struct zebra_mac
*zl3vni_rmac_lookup(struct zebra_l3vni
*zl3vni
,
1152 const struct ethaddr
*rmac
)
1154 struct zebra_mac tmp
;
1155 struct zebra_mac
*pmac
;
1157 memset(&tmp
, 0, sizeof(tmp
));
1158 memcpy(&tmp
.macaddr
, rmac
, ETH_ALEN
);
1159 pmac
= hash_lookup(zl3vni
->rmac_table
, &tmp
);
1165 * Callback to allocate RMAC hash entry.
1167 static void *zl3vni_rmac_alloc(void *p
)
1169 const struct zebra_mac
*tmp_rmac
= p
;
1170 struct zebra_mac
*zrmac
;
1172 zrmac
= XCALLOC(MTYPE_L3VNI_MAC
, sizeof(struct zebra_mac
));
1175 return ((void *)zrmac
);
1179 * Add RMAC entry to l3-vni
1181 static struct zebra_mac
*zl3vni_rmac_add(struct zebra_l3vni
*zl3vni
,
1182 const struct ethaddr
*rmac
)
1184 struct zebra_mac tmp_rmac
;
1185 struct zebra_mac
*zrmac
= NULL
;
1187 memset(&tmp_rmac
, 0, sizeof(tmp_rmac
));
1188 memcpy(&tmp_rmac
.macaddr
, rmac
, ETH_ALEN
);
1189 zrmac
= hash_get(zl3vni
->rmac_table
, &tmp_rmac
, zl3vni_rmac_alloc
);
1190 zrmac
->nh_list
= list_new();
1191 zrmac
->nh_list
->cmp
= (int (*)(void *, void *))l3vni_rmac_nh_list_cmp
;
1192 zrmac
->nh_list
->del
= (void (*)(void *))l3vni_rmac_nh_free
;
1194 SET_FLAG(zrmac
->flags
, ZEBRA_MAC_REMOTE
);
1195 SET_FLAG(zrmac
->flags
, ZEBRA_MAC_REMOTE_RMAC
);
1203 static int zl3vni_rmac_del(struct zebra_l3vni
*zl3vni
, struct zebra_mac
*zrmac
)
1205 struct zebra_mac
*tmp_rmac
;
1207 /* free the list of nh list*/
1208 list_delete(&zrmac
->nh_list
);
1210 tmp_rmac
= hash_release(zl3vni
->rmac_table
, zrmac
);
1211 XFREE(MTYPE_L3VNI_MAC
, tmp_rmac
);
1217 * Install remote RMAC into the forwarding plane.
1219 static int zl3vni_rmac_install(struct zebra_l3vni
*zl3vni
,
1220 struct zebra_mac
*zrmac
)
1222 const struct zebra_if
*zif
= NULL
, *br_zif
= NULL
;
1223 const struct zebra_l2info_vxlan
*vxl
= NULL
;
1224 const struct interface
*br_ifp
;
1225 enum zebra_dplane_result res
;
1228 if (!(CHECK_FLAG(zrmac
->flags
, ZEBRA_MAC_REMOTE
))
1229 || !(CHECK_FLAG(zrmac
->flags
, ZEBRA_MAC_REMOTE_RMAC
)))
1232 zif
= zl3vni
->vxlan_if
->info
;
1236 br_ifp
= zif
->brslave_info
.br_if
;
1240 vxl
= &zif
->l2info
.vxl
;
1242 br_zif
= (const struct zebra_if
*)br_ifp
->info
;
1244 if (IS_ZEBRA_IF_BRIDGE_VLAN_AWARE(br_zif
))
1245 vid
= vxl
->access_vlan
;
1249 res
= dplane_rem_mac_add(zl3vni
->vxlan_if
, br_ifp
, vid
,
1250 &zrmac
->macaddr
, zrmac
->fwd_info
.r_vtep_ip
, 0, 0,
1251 false /*was_static*/);
1252 if (res
!= ZEBRA_DPLANE_REQUEST_FAILURE
)
1259 * Uninstall remote RMAC from the forwarding plane.
1261 static int zl3vni_rmac_uninstall(struct zebra_l3vni
*zl3vni
,
1262 struct zebra_mac
*zrmac
)
1264 const struct zebra_if
*zif
= NULL
, *br_zif
;
1265 const struct zebra_l2info_vxlan
*vxl
= NULL
;
1266 const struct interface
*br_ifp
;
1268 enum zebra_dplane_result res
;
1270 if (!(CHECK_FLAG(zrmac
->flags
, ZEBRA_MAC_REMOTE
))
1271 || !(CHECK_FLAG(zrmac
->flags
, ZEBRA_MAC_REMOTE_RMAC
)))
1274 if (!zl3vni
->vxlan_if
) {
1275 if (IS_ZEBRA_DEBUG_VXLAN
)
1277 "RMAC %pEA on L3-VNI %u hash %p couldn't be uninstalled - no vxlan_if",
1278 &zrmac
->macaddr
, zl3vni
->vni
, zl3vni
);
1282 zif
= zl3vni
->vxlan_if
->info
;
1286 br_ifp
= zif
->brslave_info
.br_if
;
1290 vxl
= &zif
->l2info
.vxl
;
1292 br_zif
= (const struct zebra_if
*)br_ifp
->info
;
1293 if (IS_ZEBRA_IF_BRIDGE_VLAN_AWARE(br_zif
))
1294 vid
= vxl
->access_vlan
;
1298 res
= dplane_rem_mac_del(zl3vni
->vxlan_if
, br_ifp
, vid
,
1299 &zrmac
->macaddr
, zrmac
->fwd_info
.r_vtep_ip
);
1300 if (res
!= ZEBRA_DPLANE_REQUEST_FAILURE
)
1306 /* handle rmac add */
1307 static int zl3vni_remote_rmac_add(struct zebra_l3vni
*zl3vni
,
1308 const struct ethaddr
*rmac
,
1309 const struct ipaddr
*vtep_ip
)
1311 struct zebra_mac
*zrmac
= NULL
;
1312 struct ipaddr
*vtep
= NULL
;
1314 zrmac
= zl3vni_rmac_lookup(zl3vni
, rmac
);
1317 /* Create the RMAC entry, or update its vtep, if necessary. */
1318 zrmac
= zl3vni_rmac_add(zl3vni
, rmac
);
1321 "Failed to add RMAC %pEA L3VNI %u Remote VTEP %pIA",
1322 rmac
, zl3vni
->vni
, vtep_ip
);
1325 memset(&zrmac
->fwd_info
, 0, sizeof(zrmac
->fwd_info
));
1326 zrmac
->fwd_info
.r_vtep_ip
= vtep_ip
->ipaddr_v4
;
1328 vtep
= XCALLOC(MTYPE_EVPN_VTEP
, sizeof(struct ipaddr
));
1329 memcpy(vtep
, vtep_ip
, sizeof(struct ipaddr
));
1330 if (!listnode_add_sort_nodup(zrmac
->nh_list
, (void *)vtep
))
1331 XFREE(MTYPE_EVPN_VTEP
, vtep
);
1333 /* Send RMAC for FPM processing */
1334 hook_call(zebra_rmac_update
, zrmac
, zl3vni
, false,
1337 /* install rmac in kernel */
1338 zl3vni_rmac_install(zl3vni
, zrmac
);
1339 } else if (!IPV4_ADDR_SAME(&zrmac
->fwd_info
.r_vtep_ip
,
1340 &vtep_ip
->ipaddr_v4
)) {
1341 if (IS_ZEBRA_DEBUG_VXLAN
)
1343 "L3VNI %u Remote VTEP change(%pI4 -> %pIA) for RMAC %pEA",
1344 zl3vni
->vni
, &zrmac
->fwd_info
.r_vtep_ip
,
1347 zrmac
->fwd_info
.r_vtep_ip
= vtep_ip
->ipaddr_v4
;
1349 vtep
= XCALLOC(MTYPE_EVPN_VTEP
, sizeof(struct ipaddr
));
1350 memcpy(vtep
, vtep_ip
, sizeof(struct ipaddr
));
1351 if (!listnode_add_sort_nodup(zrmac
->nh_list
, (void *)vtep
))
1352 XFREE(MTYPE_EVPN_VTEP
, vtep
);
1354 /* install rmac in kernel */
1355 zl3vni_rmac_install(zl3vni
, zrmac
);
1362 /* handle rmac delete */
1363 static void zl3vni_remote_rmac_del(struct zebra_l3vni
*zl3vni
,
1364 struct zebra_mac
*zrmac
,
1365 struct ipaddr
*vtep_ip
)
1367 struct ipaddr ipv4_vtep
;
1369 if (!zl3vni_nh_lookup(zl3vni
, vtep_ip
)) {
1370 memset(&ipv4_vtep
, 0, sizeof(ipv4_vtep
));
1371 ipv4_vtep
.ipa_type
= IPADDR_V4
;
1372 if (vtep_ip
->ipa_type
== IPADDR_V6
)
1373 ipv4_mapped_ipv6_to_ipv4(&vtep_ip
->ipaddr_v6
,
1374 &ipv4_vtep
.ipaddr_v4
);
1376 memcpy(&(ipv4_vtep
.ipaddr_v4
), &vtep_ip
->ipaddr_v4
,
1377 sizeof(struct in_addr
));
1379 /* remove nh from rmac's list */
1380 l3vni_rmac_nh_list_nh_delete(zl3vni
, zrmac
, &ipv4_vtep
);
1381 /* delete nh is same as current selected, fall back to
1382 * one present in the list
1384 if (IPV4_ADDR_SAME(&zrmac
->fwd_info
.r_vtep_ip
,
1385 &ipv4_vtep
.ipaddr_v4
) &&
1386 listcount(zrmac
->nh_list
)) {
1387 struct ipaddr
*vtep
;
1389 vtep
= listgetdata(listhead(zrmac
->nh_list
));
1390 zrmac
->fwd_info
.r_vtep_ip
= vtep
->ipaddr_v4
;
1391 if (IS_ZEBRA_DEBUG_VXLAN
)
1393 "L3VNI %u Remote VTEP nh change(%pIA -> %pI4) for RMAC %pEA",
1394 zl3vni
->vni
, &ipv4_vtep
,
1395 &zrmac
->fwd_info
.r_vtep_ip
,
1398 /* install rmac in kernel */
1399 zl3vni_rmac_install(zl3vni
, zrmac
);
1402 if (!listcount(zrmac
->nh_list
)) {
1403 /* uninstall from kernel */
1404 zl3vni_rmac_uninstall(zl3vni
, zrmac
);
1406 /* Send RMAC for FPM processing */
1407 hook_call(zebra_rmac_update
, zrmac
, zl3vni
, true,
1410 if (IS_ZEBRA_DEBUG_VXLAN
)
1412 "L3VNI %u RMAC %pEA vtep_ip %pIA delete",
1413 zl3vni
->vni
, &zrmac
->macaddr
, vtep_ip
);
1415 /* del the rmac entry */
1416 zl3vni_rmac_del(zl3vni
, zrmac
);
1422 * Look up nh hash entry on a l3-vni.
1424 static struct zebra_neigh
*zl3vni_nh_lookup(struct zebra_l3vni
*zl3vni
,
1425 const struct ipaddr
*ip
)
1427 struct zebra_neigh tmp
;
1428 struct zebra_neigh
*n
;
1430 memset(&tmp
, 0, sizeof(tmp
));
1431 memcpy(&tmp
.ip
, ip
, sizeof(struct ipaddr
));
1432 n
= hash_lookup(zl3vni
->nh_table
, &tmp
);
1439 * Callback to allocate NH hash entry on L3-VNI.
1441 static void *zl3vni_nh_alloc(void *p
)
1443 const struct zebra_neigh
*tmp_n
= p
;
1444 struct zebra_neigh
*n
;
1446 n
= XCALLOC(MTYPE_L3NEIGH
, sizeof(struct zebra_neigh
));
1453 * Add neighbor entry.
1455 static struct zebra_neigh
*zl3vni_nh_add(struct zebra_l3vni
*zl3vni
,
1456 const struct ipaddr
*ip
,
1457 const struct ethaddr
*mac
)
1459 struct zebra_neigh tmp_n
;
1460 struct zebra_neigh
*n
= NULL
;
1462 memset(&tmp_n
, 0, sizeof(tmp_n
));
1463 memcpy(&tmp_n
.ip
, ip
, sizeof(struct ipaddr
));
1464 n
= hash_get(zl3vni
->nh_table
, &tmp_n
, zl3vni_nh_alloc
);
1466 RB_INIT(host_rb_tree_entry
, &n
->host_rb
);
1468 memcpy(&n
->emac
, mac
, ETH_ALEN
);
1469 SET_FLAG(n
->flags
, ZEBRA_NEIGH_REMOTE
);
1470 SET_FLAG(n
->flags
, ZEBRA_NEIGH_REMOTE_NH
);
1476 * Delete neighbor entry.
1478 static int zl3vni_nh_del(struct zebra_l3vni
*zl3vni
, struct zebra_neigh
*n
)
1480 struct zebra_neigh
*tmp_n
;
1481 struct host_rb_entry
*hle
;
1483 while (!RB_EMPTY(host_rb_tree_entry
, &n
->host_rb
)) {
1484 hle
= RB_ROOT(host_rb_tree_entry
, &n
->host_rb
);
1486 RB_REMOVE(host_rb_tree_entry
, &n
->host_rb
, hle
);
1487 XFREE(MTYPE_HOST_PREFIX
, hle
);
1490 tmp_n
= hash_release(zl3vni
->nh_table
, n
);
1491 XFREE(MTYPE_L3NEIGH
, tmp_n
);
1497 * Install remote nh as neigh into the kernel.
1499 static int zl3vni_nh_install(struct zebra_l3vni
*zl3vni
, struct zebra_neigh
*n
)
1504 if (!is_l3vni_oper_up(zl3vni
))
1507 if (!(n
->flags
& ZEBRA_NEIGH_REMOTE
)
1508 || !(n
->flags
& ZEBRA_NEIGH_REMOTE_NH
))
1511 flags
= DPLANE_NTF_EXT_LEARNED
;
1512 if (n
->flags
& ZEBRA_NEIGH_ROUTER_FLAG
)
1513 flags
|= DPLANE_NTF_ROUTER
;
1515 dplane_rem_neigh_add(zl3vni
->svi_if
, &n
->ip
, &n
->emac
, flags
,
1516 false /*was_static*/);
1522 * Uninstall remote nh from the kernel.
1524 static int zl3vni_nh_uninstall(struct zebra_l3vni
*zl3vni
,
1525 struct zebra_neigh
*n
)
1527 if (!(n
->flags
& ZEBRA_NEIGH_REMOTE
)
1528 || !(n
->flags
& ZEBRA_NEIGH_REMOTE_NH
))
1531 if (!zl3vni
->svi_if
|| !if_is_operative(zl3vni
->svi_if
))
1534 dplane_rem_neigh_delete(zl3vni
->svi_if
, &n
->ip
);
1539 /* add remote vtep as a neigh entry */
1540 static int zl3vni_remote_nh_add(struct zebra_l3vni
*zl3vni
,
1541 const struct ipaddr
*vtep_ip
,
1542 const struct ethaddr
*rmac
,
1543 const struct prefix
*host_prefix
)
1545 struct zebra_neigh
*nh
= NULL
;
1547 /* Create the next hop entry, or update its mac, if necessary. */
1548 nh
= zl3vni_nh_lookup(zl3vni
, vtep_ip
);
1550 nh
= zl3vni_nh_add(zl3vni
, vtep_ip
, rmac
);
1553 "Failed to add NH %pIA as Neigh (RMAC %pEA L3-VNI %u prefix %pFX)",
1554 vtep_ip
, rmac
, zl3vni
->vni
, host_prefix
);
1558 /* install the nh neigh in kernel */
1559 zl3vni_nh_install(zl3vni
, nh
);
1560 } else if (memcmp(&nh
->emac
, rmac
, ETH_ALEN
) != 0) {
1561 if (IS_ZEBRA_DEBUG_VXLAN
)
1563 "L3VNI %u RMAC change(%pEA --> %pEA) for nexthop %pIA, prefix %pFX",
1564 zl3vni
->vni
, &nh
->emac
, rmac
, vtep_ip
,
1567 memcpy(&nh
->emac
, rmac
, ETH_ALEN
);
1568 /* install (update) the nh neigh in kernel */
1569 zl3vni_nh_install(zl3vni
, nh
);
1572 rb_find_or_add_host(&nh
->host_rb
, host_prefix
);
1577 /* handle nh neigh delete */
1578 static void zl3vni_remote_nh_del(struct zebra_l3vni
*zl3vni
,
1579 struct zebra_neigh
*nh
,
1580 struct prefix
*host_prefix
)
1582 rb_delete_host(&nh
->host_rb
, host_prefix
);
1584 if (RB_EMPTY(host_rb_tree_entry
, &nh
->host_rb
)) {
1585 /* uninstall from kernel */
1586 zl3vni_nh_uninstall(zl3vni
, nh
);
1588 /* delete the nh entry */
1589 zl3vni_nh_del(zl3vni
, nh
);
1593 /* handle neigh update from kernel - the only thing of interest is to
1594 * readd stale entries.
1596 static int zl3vni_local_nh_add_update(struct zebra_l3vni
*zl3vni
,
1597 struct ipaddr
*ip
, uint16_t state
)
1600 struct zebra_neigh
*n
= NULL
;
1602 n
= zl3vni_nh_lookup(zl3vni
, ip
);
1606 /* all next hop neigh are remote and installed by frr.
1607 * If the kernel has aged this entry, re-install.
1609 if (state
& NUD_STALE
)
1610 zl3vni_nh_install(zl3vni
, n
);
1615 /* handle neigh delete from kernel */
1616 static int zl3vni_local_nh_del(struct zebra_l3vni
*zl3vni
, struct ipaddr
*ip
)
1618 struct zebra_neigh
*n
= NULL
;
1620 n
= zl3vni_nh_lookup(zl3vni
, ip
);
1624 /* all next hop neigh are remote and installed by frr.
1625 * If we get an age out notification for these neigh entries, we have to
1628 zl3vni_nh_install(zl3vni
, n
);
1634 * Hash function for L3 VNI.
1636 static unsigned int l3vni_hash_keymake(const void *p
)
1638 const struct zebra_l3vni
*zl3vni
= p
;
1640 return jhash_1word(zl3vni
->vni
, 0);
1644 * Compare 2 L3 VNI hash entries.
1646 static bool l3vni_hash_cmp(const void *p1
, const void *p2
)
1648 const struct zebra_l3vni
*zl3vni1
= p1
;
1649 const struct zebra_l3vni
*zl3vni2
= p2
;
1651 return (zl3vni1
->vni
== zl3vni2
->vni
);
1655 * Callback to allocate L3 VNI hash entry.
1657 static void *zl3vni_alloc(void *p
)
1659 struct zebra_l3vni
*zl3vni
= NULL
;
1660 const struct zebra_l3vni
*tmp_l3vni
= p
;
1662 zl3vni
= XCALLOC(MTYPE_ZL3VNI
, sizeof(struct zebra_l3vni
));
1663 zl3vni
->vni
= tmp_l3vni
->vni
;
1664 return ((void *)zl3vni
);
1668 * Look up L3 VNI hash entry.
1670 struct zebra_l3vni
*zl3vni_lookup(vni_t vni
)
1672 struct zebra_l3vni tmp_l3vni
;
1673 struct zebra_l3vni
*zl3vni
= NULL
;
1675 memset(&tmp_l3vni
, 0, sizeof(tmp_l3vni
));
1676 tmp_l3vni
.vni
= vni
;
1677 zl3vni
= hash_lookup(zrouter
.l3vni_table
, &tmp_l3vni
);
1683 * Add L3 VNI hash entry.
1685 static struct zebra_l3vni
*zl3vni_add(vni_t vni
, vrf_id_t vrf_id
)
1687 struct zebra_l3vni tmp_zl3vni
;
1688 struct zebra_l3vni
*zl3vni
= NULL
;
1690 memset(&tmp_zl3vni
, 0, sizeof(tmp_zl3vni
));
1691 tmp_zl3vni
.vni
= vni
;
1693 zl3vni
= hash_get(zrouter
.l3vni_table
, &tmp_zl3vni
, zl3vni_alloc
);
1695 zl3vni
->vrf_id
= vrf_id
;
1696 zl3vni
->svi_if
= NULL
;
1697 zl3vni
->vxlan_if
= NULL
;
1698 zl3vni
->l2vnis
= list_new();
1699 zl3vni
->l2vnis
->cmp
= zebra_evpn_list_cmp
;
1701 /* Create hash table for remote RMAC */
1702 zl3vni
->rmac_table
= zebra_mac_db_create("Zebra L3-VNI RMAC-Table");
1704 /* Create hash table for neighbors */
1705 zl3vni
->nh_table
= zebra_neigh_db_create("Zebra L3-VNI next-hop table");
1711 * Delete L3 VNI hash entry.
1713 static int zl3vni_del(struct zebra_l3vni
*zl3vni
)
1715 struct zebra_l3vni
*tmp_zl3vni
;
1717 /* free the list of l2vnis */
1718 list_delete(&zl3vni
->l2vnis
);
1719 zl3vni
->l2vnis
= NULL
;
1721 /* Free the rmac table */
1722 hash_free(zl3vni
->rmac_table
);
1723 zl3vni
->rmac_table
= NULL
;
1725 /* Free the nh table */
1726 hash_free(zl3vni
->nh_table
);
1727 zl3vni
->nh_table
= NULL
;
1729 /* Free the VNI hash entry and allocated memory. */
1730 tmp_zl3vni
= hash_release(zrouter
.l3vni_table
, zl3vni
);
1731 XFREE(MTYPE_ZL3VNI
, tmp_zl3vni
);
1736 static int zl3vni_map_to_vxlan_if_ns(struct ns
*ns
,
1740 struct zebra_ns
*zns
= ns
->info
;
1741 struct zebra_l3vni
*zl3vni
= (struct zebra_l3vni
*)_zl3vni
;
1742 struct route_node
*rn
= NULL
;
1743 struct interface
*ifp
= NULL
;
1744 struct zebra_vrf
*zvrf
;
1746 zvrf
= zebra_vrf_get_evpn();
1750 /* loop through all vxlan-interface */
1751 for (rn
= route_top(zns
->if_table
); rn
; rn
= route_next(rn
)) {
1753 struct zebra_if
*zif
= NULL
;
1754 struct zebra_l2info_vxlan
*vxl
= NULL
;
1756 ifp
= (struct interface
*)rn
->info
;
1761 if (!zif
|| zif
->zif_type
!= ZEBRA_IF_VXLAN
)
1764 vxl
= &zif
->l2info
.vxl
;
1765 if (vxl
->vni
!= zl3vni
->vni
)
1768 /* link of VXLAN interface should be in zebra_evpn_vrf */
1769 if (zvrf
->zns
->ns_id
!= vxl
->link_nsid
) {
1770 if (IS_ZEBRA_DEBUG_VXLAN
)
1772 "Intf %s(%u) VNI %u, link not in same "
1773 "namespace than BGP EVPN core instance ",
1774 ifp
->name
, ifp
->ifindex
, vxl
->vni
);
1779 zl3vni
->local_vtep_ip
= vxl
->vtep_ip
;
1780 *_pifp
= (void *)ifp
;
1781 return NS_WALK_STOP
;
1784 return NS_WALK_CONTINUE
;
1787 struct interface
*zl3vni_map_to_vxlan_if(struct zebra_l3vni
*zl3vni
)
1789 struct interface
**p_ifp
;
1790 struct interface
*ifp
= NULL
;
1794 ns_walk_func(zl3vni_map_to_vxlan_if_ns
,
1795 (void *)zl3vni
, (void **)p_ifp
);
1799 struct interface
*zl3vni_map_to_svi_if(struct zebra_l3vni
*zl3vni
)
1801 struct zebra_if
*zif
= NULL
; /* zebra_if for vxlan_if */
1802 struct zebra_l2info_vxlan
*vxl
= NULL
; /* l2 info for vxlan_if */
1807 if (!zl3vni
->vxlan_if
)
1810 zif
= zl3vni
->vxlan_if
->info
;
1814 vxl
= &zif
->l2info
.vxl
;
1816 return zvni_map_to_svi(vxl
->access_vlan
, zif
->brslave_info
.br_if
);
1819 struct interface
*zl3vni_map_to_mac_vlan_if(struct zebra_l3vni
*zl3vni
)
1821 struct zebra_if
*zif
= NULL
; /* zebra_if for vxlan_if */
1826 if (!zl3vni
->vxlan_if
)
1829 zif
= zl3vni
->vxlan_if
->info
;
1833 return zebra_evpn_map_to_macvlan(zif
->brslave_info
.br_if
,
1838 struct zebra_l3vni
*zl3vni_from_vrf(vrf_id_t vrf_id
)
1840 struct zebra_vrf
*zvrf
= NULL
;
1842 zvrf
= zebra_vrf_lookup_by_id(vrf_id
);
1846 return zl3vni_lookup(zvrf
->l3vni
);
1849 static int zl3vni_from_svi_ns(struct ns
*ns
, void *_in_param
, void **_p_zl3vni
)
1851 struct zebra_ns
*zns
= ns
->info
;
1852 struct zebra_l3vni
**p_zl3vni
= (struct zebra_l3vni
**)_p_zl3vni
;
1853 struct zebra_from_svi_param
*in_param
=
1854 (struct zebra_from_svi_param
*)_in_param
;
1855 struct route_node
*rn
= NULL
;
1856 struct interface
*tmp_if
= NULL
;
1857 struct zebra_if
*zif
= NULL
;
1858 struct zebra_l2info_vxlan
*vxl
= NULL
;
1860 assert(in_param
&& p_zl3vni
);
1862 /* loop through all vxlan-interface */
1863 for (rn
= route_top(zns
->if_table
); rn
; rn
= route_next(rn
)) {
1864 tmp_if
= (struct interface
*)rn
->info
;
1868 if (!zif
|| zif
->zif_type
!= ZEBRA_IF_VXLAN
)
1870 if (!if_is_operative(tmp_if
))
1872 vxl
= &zif
->l2info
.vxl
;
1874 if (zif
->brslave_info
.br_if
!= in_param
->br_if
)
1877 if (!in_param
->bridge_vlan_aware
1878 || vxl
->access_vlan
== in_param
->vid
) {
1879 *p_zl3vni
= zl3vni_lookup(vxl
->vni
);
1880 return NS_WALK_STOP
;
1884 return NS_WALK_CONTINUE
;
1888 * Map SVI and associated bridge to a VNI. This is invoked upon getting
1889 * neighbor notifications, to see if they are of interest.
1891 static struct zebra_l3vni
*zl3vni_from_svi(struct interface
*ifp
,
1892 struct interface
*br_if
)
1894 struct zebra_l3vni
*zl3vni
= NULL
;
1895 struct zebra_if
*zif
= NULL
;
1896 struct zebra_l2info_bridge
*br
= NULL
;
1897 struct zebra_from_svi_param in_param
= {};
1898 struct zebra_l3vni
**p_zl3vni
;
1903 /* Make sure the linked interface is a bridge. */
1904 if (!IS_ZEBRA_IF_BRIDGE(br_if
))
1906 in_param
.br_if
= br_if
;
1908 /* Determine if bridge is VLAN-aware or not */
1911 br
= &zif
->l2info
.br
;
1912 in_param
.bridge_vlan_aware
= br
->vlan_aware
;
1913 if (in_param
.bridge_vlan_aware
) {
1914 struct zebra_l2info_vlan
*vl
;
1916 if (!IS_ZEBRA_IF_VLAN(ifp
))
1921 vl
= &zif
->l2info
.vl
;
1922 in_param
.vid
= vl
->vid
;
1925 /* See if this interface (or interface plus VLAN Id) maps to a VxLAN */
1926 /* TODO: Optimize with a hash. */
1930 ns_walk_func(zl3vni_from_svi_ns
, (void *)&in_param
, (void **)p_zl3vni
);
1934 vni_t
vni_id_from_svi(struct interface
*ifp
, struct interface
*br_if
)
1937 struct zebra_evpn
*zevpn
= NULL
;
1938 struct zebra_l3vni
*zl3vni
= NULL
;
1940 /* Check if an L3VNI belongs to this SVI interface.
1941 * If not, check if an L2VNI belongs to this SVI interface.
1943 zl3vni
= zl3vni_from_svi(ifp
, br_if
);
1947 zevpn
= zebra_evpn_from_svi(ifp
, br_if
);
1955 static inline void zl3vni_get_vrr_rmac(struct zebra_l3vni
*zl3vni
,
1956 struct ethaddr
*rmac
)
1961 if (!is_l3vni_oper_up(zl3vni
))
1964 if (zl3vni
->mac_vlan_if
&& if_is_operative(zl3vni
->mac_vlan_if
))
1965 memcpy(rmac
->octet
, zl3vni
->mac_vlan_if
->hw_addr
, ETH_ALEN
);
1969 * Inform BGP about l3-vni.
1971 static int zl3vni_send_add_to_client(struct zebra_l3vni
*zl3vni
)
1973 struct stream
*s
= NULL
;
1974 struct zserv
*client
= NULL
;
1975 struct ethaddr svi_rmac
, vrr_rmac
= {.octet
= {0} };
1976 struct zebra_vrf
*zvrf
;
1977 bool is_anycast_mac
= true;
1979 client
= zserv_find_client(ZEBRA_ROUTE_BGP
, 0);
1980 /* BGP may not be running. */
1984 zvrf
= zebra_vrf_lookup_by_id(zl3vni
->vrf_id
);
1987 /* get the svi and vrr rmac values */
1988 memset(&svi_rmac
, 0, sizeof(svi_rmac
));
1989 zl3vni_get_svi_rmac(zl3vni
, &svi_rmac
);
1990 zl3vni_get_vrr_rmac(zl3vni
, &vrr_rmac
);
1992 /* In absence of vrr mac use svi mac as anycast MAC value */
1993 if (is_zero_mac(&vrr_rmac
)) {
1994 memcpy(&vrr_rmac
, &svi_rmac
, ETH_ALEN
);
1995 is_anycast_mac
= false;
1998 s
= stream_new(ZEBRA_MAX_PACKET_SIZ
);
2000 /* The message is used for both vni add and/or update like
2001 * vrr mac is added for l3vni SVI.
2003 zclient_create_header(s
, ZEBRA_L3VNI_ADD
, zl3vni_vrf_id(zl3vni
));
2004 stream_putl(s
, zl3vni
->vni
);
2005 stream_put(s
, &svi_rmac
, sizeof(struct ethaddr
));
2006 stream_put_in_addr(s
, &zl3vni
->local_vtep_ip
);
2007 stream_put(s
, &zl3vni
->filter
, sizeof(int));
2008 stream_putl(s
, zl3vni
->svi_if
->ifindex
);
2009 stream_put(s
, &vrr_rmac
, sizeof(struct ethaddr
));
2010 stream_putl(s
, is_anycast_mac
);
2012 /* Write packet size. */
2013 stream_putw_at(s
, 0, stream_get_endp(s
));
2015 if (IS_ZEBRA_DEBUG_VXLAN
)
2017 "Send L3_VNI_ADD %u VRF %s RMAC %pEA VRR %pEA local-ip %pI4 filter %s to %s",
2018 zl3vni
->vni
, vrf_id_to_name(zl3vni_vrf_id(zl3vni
)),
2019 &svi_rmac
, &vrr_rmac
, &zl3vni
->local_vtep_ip
,
2020 CHECK_FLAG(zl3vni
->filter
, PREFIX_ROUTES_ONLY
)
2021 ? "prefix-routes-only"
2023 zebra_route_string(client
->proto
));
2025 client
->l3vniadd_cnt
++;
2026 return zserv_send_message(client
, s
);
2030 * Inform BGP about local l3-VNI deletion.
2032 static int zl3vni_send_del_to_client(struct zebra_l3vni
*zl3vni
)
2034 struct stream
*s
= NULL
;
2035 struct zserv
*client
= NULL
;
2037 client
= zserv_find_client(ZEBRA_ROUTE_BGP
, 0);
2038 /* BGP may not be running. */
2042 s
= stream_new(ZEBRA_MAX_PACKET_SIZ
);
2044 zclient_create_header(s
, ZEBRA_L3VNI_DEL
, zl3vni_vrf_id(zl3vni
));
2045 stream_putl(s
, zl3vni
->vni
);
2047 /* Write packet size. */
2048 stream_putw_at(s
, 0, stream_get_endp(s
));
2050 if (IS_ZEBRA_DEBUG_VXLAN
)
2051 zlog_debug("Send L3_VNI_DEL %u VRF %s to %s", zl3vni
->vni
,
2052 vrf_id_to_name(zl3vni_vrf_id(zl3vni
)),
2053 zebra_route_string(client
->proto
));
2055 client
->l3vnidel_cnt
++;
2056 return zserv_send_message(client
, s
);
2059 static void zebra_vxlan_process_l3vni_oper_up(struct zebra_l3vni
*zl3vni
)
2064 /* send l3vni add to BGP */
2065 zl3vni_send_add_to_client(zl3vni
);
2068 static void zebra_vxlan_process_l3vni_oper_down(struct zebra_l3vni
*zl3vni
)
2073 /* send l3-vni del to BGP*/
2074 zl3vni_send_del_to_client(zl3vni
);
2077 static void zevpn_add_to_l3vni_list(struct hash_bucket
*bucket
, void *ctxt
)
2079 struct zebra_evpn
*zevpn
= (struct zebra_evpn
*)bucket
->data
;
2080 struct zebra_l3vni
*zl3vni
= (struct zebra_l3vni
*)ctxt
;
2082 if (zevpn
->vrf_id
== zl3vni_vrf_id(zl3vni
))
2083 listnode_add_sort(zl3vni
->l2vnis
, zevpn
);
2087 * Handle transition of vni from l2 to l3 and vice versa.
2088 * This function handles only the L2VNI add/delete part of
2089 * the above transition.
2090 * L3VNI add/delete is handled by the calling functions.
2092 static int zebra_vxlan_handle_vni_transition(struct zebra_vrf
*zvrf
, vni_t vni
,
2095 struct zebra_evpn
*zevpn
= NULL
;
2096 struct zebra_l3vni
*zl3vni
= NULL
;
2098 /* There is a possibility that VNI notification was already received
2099 * from kernel and we programmed it as L2-VNI
2100 * In such a case we need to delete this L2-VNI first, so
2101 * that it can be reprogrammed as L3-VNI in the system. It is also
2102 * possible that the vrf-vni mapping is removed from FRR while the vxlan
2103 * interface is still present in kernel. In this case to keep it
2104 * symmetric, we will delete the l3-vni and reprogram it as l2-vni
2107 /* Locate hash entry */
2108 zevpn
= zebra_evpn_lookup(vni
);
2112 if (IS_ZEBRA_DEBUG_VXLAN
)
2113 zlog_debug("Del L2-VNI %u - transition to L3-VNI", vni
);
2115 /* Delete EVPN from BGP. */
2116 zebra_evpn_send_del_to_client(zevpn
);
2118 zebra_evpn_neigh_del_all(zevpn
, 0, 0, DEL_ALL_NEIGH
);
2119 zebra_evpn_mac_del_all(zevpn
, 0, 0, DEL_ALL_MAC
);
2121 /* Free up all remote VTEPs, if any. */
2122 zebra_evpn_vtep_del_all(zevpn
, 1);
2124 zl3vni
= zl3vni_from_vrf(zevpn
->vrf_id
);
2126 listnode_delete(zl3vni
->l2vnis
, zevpn
);
2128 /* Delete the hash entry. */
2129 if (zebra_evpn_vxlan_del(zevpn
)) {
2130 flog_err(EC_ZEBRA_VNI_DEL_FAILED
,
2131 "Failed to del EVPN hash %p, VNI %u", zevpn
,
2136 struct zebra_ns
*zns
;
2137 struct route_node
*rn
;
2138 struct interface
*ifp
;
2139 struct zebra_if
*zif
;
2140 struct zebra_l2info_vxlan
*vxl
;
2141 struct interface
*vlan_if
;
2144 if (IS_ZEBRA_DEBUG_VXLAN
)
2145 zlog_debug("Adding L2-VNI %u - transition from L3-VNI",
2148 /* Find VxLAN interface for this VNI. */
2149 zns
= zebra_ns_lookup(NS_DEFAULT
);
2150 for (rn
= route_top(zns
->if_table
); rn
; rn
= route_next(rn
)) {
2151 ifp
= (struct interface
*)rn
->info
;
2155 if (!zif
|| zif
->zif_type
!= ZEBRA_IF_VXLAN
)
2158 vxl
= &zif
->l2info
.vxl
;
2159 if (vxl
->vni
== vni
) {
2166 if (IS_ZEBRA_DEBUG_VXLAN
)
2168 "Adding L2-VNI - Failed to find VxLAN interface for VNI %u",
2173 /* Create VNI hash entry for L2VNI */
2174 zevpn
= zebra_evpn_lookup(vni
);
2178 zevpn
= zebra_evpn_add(vni
);
2180 /* Find bridge interface for the VNI */
2181 vlan_if
= zvni_map_to_svi(vxl
->access_vlan
,
2182 zif
->brslave_info
.br_if
);
2184 zevpn
->vrf_id
= vlan_if
->vrf
->vrf_id
;
2185 zl3vni
= zl3vni_from_vrf(vlan_if
->vrf
->vrf_id
);
2187 listnode_add_sort_nodup(zl3vni
->l2vnis
, zevpn
);
2190 zevpn
->vxlan_if
= ifp
;
2191 zevpn
->local_vtep_ip
= vxl
->vtep_ip
;
2193 /* Inform BGP if the VNI is up and mapped to a bridge. */
2194 if (if_is_operative(ifp
) && zif
->brslave_info
.br_if
) {
2195 zebra_evpn_send_add_to_client(zevpn
);
2196 zebra_evpn_read_mac_neigh(zevpn
, ifp
);
2203 /* delete and uninstall rmac hash entry */
2204 static void zl3vni_del_rmac_hash_entry(struct hash_bucket
*bucket
, void *ctx
)
2206 struct zebra_mac
*zrmac
= NULL
;
2207 struct zebra_l3vni
*zl3vni
= NULL
;
2209 zrmac
= (struct zebra_mac
*)bucket
->data
;
2210 zl3vni
= (struct zebra_l3vni
*)ctx
;
2211 zl3vni_rmac_uninstall(zl3vni
, zrmac
);
2213 /* Send RMAC for FPM processing */
2214 hook_call(zebra_rmac_update
, zrmac
, zl3vni
, true, "RMAC deleted");
2216 zl3vni_rmac_del(zl3vni
, zrmac
);
2219 /* delete and uninstall nh hash entry */
2220 static void zl3vni_del_nh_hash_entry(struct hash_bucket
*bucket
, void *ctx
)
2222 struct zebra_neigh
*n
= NULL
;
2223 struct zebra_l3vni
*zl3vni
= NULL
;
2225 n
= (struct zebra_neigh
*)bucket
->data
;
2226 zl3vni
= (struct zebra_l3vni
*)ctx
;
2227 zl3vni_nh_uninstall(zl3vni
, n
);
2228 zl3vni_nh_del(zl3vni
, n
);
2231 /* re-add remote rmac if needed */
2232 static int zebra_vxlan_readd_remote_rmac(struct zebra_l3vni
*zl3vni
,
2233 struct ethaddr
*rmac
)
2235 struct zebra_mac
*zrmac
= NULL
;
2237 zrmac
= zl3vni_rmac_lookup(zl3vni
, rmac
);
2241 if (IS_ZEBRA_DEBUG_VXLAN
)
2242 zlog_debug("Del remote RMAC %pEA L3VNI %u - readd",
2245 zl3vni_rmac_install(zl3vni
, zrmac
);
2249 /* Public functions */
2251 int is_l3vni_for_prefix_routes_only(vni_t vni
)
2253 struct zebra_l3vni
*zl3vni
= NULL
;
2255 zl3vni
= zl3vni_lookup(vni
);
2259 return CHECK_FLAG(zl3vni
->filter
, PREFIX_ROUTES_ONLY
) ? 1 : 0;
2262 /* handle evpn route in vrf table */
2263 void zebra_vxlan_evpn_vrf_route_add(vrf_id_t vrf_id
, const struct ethaddr
*rmac
,
2264 const struct ipaddr
*vtep_ip
,
2265 const struct prefix
*host_prefix
)
2267 struct zebra_l3vni
*zl3vni
= NULL
;
2268 struct ipaddr ipv4_vtep
;
2270 zl3vni
= zl3vni_from_vrf(vrf_id
);
2271 if (!zl3vni
|| !is_l3vni_oper_up(zl3vni
))
2275 * add the next hop neighbor -
2276 * neigh to be installed is the ipv6 nexthop neigh
2278 zl3vni_remote_nh_add(zl3vni
, vtep_ip
, rmac
, host_prefix
);
2281 * if the remote vtep is a ipv4 mapped ipv6 address convert it to ipv4
2282 * address. Rmac is programmed against the ipv4 vtep because we only
2283 * support ipv4 tunnels in the h/w right now
2285 memset(&ipv4_vtep
, 0, sizeof(ipv4_vtep
));
2286 ipv4_vtep
.ipa_type
= IPADDR_V4
;
2287 if (vtep_ip
->ipa_type
== IPADDR_V6
)
2288 ipv4_mapped_ipv6_to_ipv4(&vtep_ip
->ipaddr_v6
,
2289 &(ipv4_vtep
.ipaddr_v4
));
2291 memcpy(&(ipv4_vtep
.ipaddr_v4
), &vtep_ip
->ipaddr_v4
,
2292 sizeof(struct in_addr
));
2295 * add the rmac - remote rmac to be installed is against the ipv4
2298 zl3vni_remote_rmac_add(zl3vni
, rmac
, &ipv4_vtep
);
2301 /* handle evpn vrf route delete */
2302 void zebra_vxlan_evpn_vrf_route_del(vrf_id_t vrf_id
,
2303 struct ipaddr
*vtep_ip
,
2304 struct prefix
*host_prefix
)
2306 struct zebra_l3vni
*zl3vni
= NULL
;
2307 struct zebra_neigh
*nh
= NULL
;
2308 struct zebra_mac
*zrmac
= NULL
;
2310 zl3vni
= zl3vni_from_vrf(vrf_id
);
2314 /* find the next hop entry and rmac entry */
2315 nh
= zl3vni_nh_lookup(zl3vni
, vtep_ip
);
2318 zrmac
= zl3vni_rmac_lookup(zl3vni
, &nh
->emac
);
2320 /* delete the next hop entry */
2321 zl3vni_remote_nh_del(zl3vni
, nh
, host_prefix
);
2323 /* delete the rmac entry */
2325 zl3vni_remote_rmac_del(zl3vni
, zrmac
, vtep_ip
);
2328 void zebra_vxlan_print_specific_rmac_l3vni(struct vty
*vty
, vni_t l3vni
,
2329 struct ethaddr
*rmac
, bool use_json
)
2331 struct zebra_l3vni
*zl3vni
= NULL
;
2332 struct zebra_mac
*zrmac
= NULL
;
2333 json_object
*json
= NULL
;
2335 if (!is_evpn_enabled()) {
2337 vty_out(vty
, "{}\n");
2342 json
= json_object_new_object();
2344 zl3vni
= zl3vni_lookup(l3vni
);
2347 vty_out(vty
, "{}\n");
2349 vty_out(vty
, "%% L3-VNI %u doesn't exist\n", l3vni
);
2353 zrmac
= zl3vni_rmac_lookup(zl3vni
, rmac
);
2356 vty_out(vty
, "{}\n");
2359 "%% Requested RMAC doesn't exist in L3-VNI %u\n",
2364 zl3vni_print_rmac(zrmac
, vty
, json
);
2367 vty_json(vty
, json
);
2370 void zebra_vxlan_print_rmacs_l3vni(struct vty
*vty
, vni_t l3vni
, bool use_json
)
2372 struct zebra_l3vni
*zl3vni
;
2374 struct rmac_walk_ctx wctx
;
2375 json_object
*json
= NULL
;
2377 if (!is_evpn_enabled())
2380 zl3vni
= zl3vni_lookup(l3vni
);
2383 vty_out(vty
, "{}\n");
2385 vty_out(vty
, "%% L3-VNI %u does not exist\n", l3vni
);
2388 num_rmacs
= hashcount(zl3vni
->rmac_table
);
2393 json
= json_object_new_object();
2395 memset(&wctx
, 0, sizeof(wctx
));
2399 vty_out(vty
, "Number of Remote RMACs known for this VNI: %u\n",
2401 vty_out(vty
, "%-17s %-21s\n", "MAC", "Remote VTEP");
2403 json_object_int_add(json
, "numRmacs", num_rmacs
);
2405 hash_iterate(zl3vni
->rmac_table
, zl3vni_print_rmac_hash
, &wctx
);
2408 vty_json(vty
, json
);
2411 void zebra_vxlan_print_rmacs_all_l3vni(struct vty
*vty
, bool use_json
)
2413 json_object
*json
= NULL
;
2416 if (!is_evpn_enabled()) {
2418 vty_out(vty
, "{}\n");
2423 json
= json_object_new_object();
2427 hash_iterate(zrouter
.l3vni_table
,
2428 (void (*)(struct hash_bucket
*,
2429 void *))zl3vni_print_rmac_hash_all_vni
,
2433 vty_json(vty
, json
);
2436 void zebra_vxlan_print_specific_nh_l3vni(struct vty
*vty
, vni_t l3vni
,
2437 struct ipaddr
*ip
, bool use_json
)
2439 struct zebra_l3vni
*zl3vni
= NULL
;
2440 struct zebra_neigh
*n
= NULL
;
2441 json_object
*json
= NULL
;
2443 if (!is_evpn_enabled()) {
2445 vty_out(vty
, "{}\n");
2450 json
= json_object_new_object();
2452 zl3vni
= zl3vni_lookup(l3vni
);
2455 vty_out(vty
, "{}\n");
2457 vty_out(vty
, "%% L3-VNI %u does not exist\n", l3vni
);
2461 n
= zl3vni_nh_lookup(zl3vni
, ip
);
2464 vty_out(vty
, "{}\n");
2467 "%% Requested next-hop not present for L3-VNI %u",
2472 zl3vni_print_nh(n
, vty
, json
);
2475 vty_json(vty
, json
);
2478 void zebra_vxlan_print_nh_l3vni(struct vty
*vty
, vni_t l3vni
, bool use_json
)
2481 struct nh_walk_ctx wctx
;
2482 json_object
*json
= NULL
;
2483 struct zebra_l3vni
*zl3vni
= NULL
;
2485 if (!is_evpn_enabled())
2488 zl3vni
= zl3vni_lookup(l3vni
);
2491 vty_out(vty
, "{}\n");
2493 vty_out(vty
, "%% L3-VNI %u does not exist\n", l3vni
);
2497 num_nh
= hashcount(zl3vni
->nh_table
);
2502 json
= json_object_new_object();
2507 vty_out(vty
, "Number of NH Neighbors known for this VNI: %u\n",
2509 vty_out(vty
, "%-15s %-17s\n", "IP", "RMAC");
2511 json_object_int_add(json
, "numNextHops", num_nh
);
2513 hash_iterate(zl3vni
->nh_table
, zl3vni_print_nh_hash
, &wctx
);
2516 vty_json(vty
, json
);
2519 void zebra_vxlan_print_nh_all_l3vni(struct vty
*vty
, bool use_json
)
2521 json_object
*json
= NULL
;
2524 if (!is_evpn_enabled()) {
2526 vty_out(vty
, "{}\n");
2531 json
= json_object_new_object();
2535 hash_iterate(zrouter
.l3vni_table
,
2536 (void (*)(struct hash_bucket
*,
2537 void *))zl3vni_print_nh_hash_all_vni
,
2541 vty_json(vty
, json
);
2545 * Display L3 VNI information (VTY command handler).
2547 void zebra_vxlan_print_l3vni(struct vty
*vty
, vni_t vni
, bool use_json
)
2550 json_object
*json
= NULL
;
2551 struct zebra_l3vni
*zl3vni
= NULL
;
2553 if (!is_evpn_enabled()) {
2555 vty_out(vty
, "{}\n");
2559 zl3vni
= zl3vni_lookup(vni
);
2562 vty_out(vty
, "{}\n");
2564 vty_out(vty
, "%% VNI %u does not exist\n", vni
);
2569 json
= json_object_new_object();
2573 zl3vni_print(zl3vni
, (void *)args
);
2576 vty_json(vty
, json
);
2579 void zebra_vxlan_print_vrf_vni(struct vty
*vty
, struct zebra_vrf
*zvrf
,
2580 json_object
*json_vrfs
)
2582 char buf
[ETHER_ADDR_STRLEN
];
2583 struct zebra_l3vni
*zl3vni
= NULL
;
2585 zl3vni
= zl3vni_lookup(zvrf
->l3vni
);
2590 vty_out(vty
, "%-37s %-10u %-20s %-20s %-5s %-18s\n",
2591 zvrf_name(zvrf
), zl3vni
->vni
,
2592 zl3vni_vxlan_if_name(zl3vni
),
2593 zl3vni_svi_if_name(zl3vni
), zl3vni_state2str(zl3vni
),
2594 zl3vni_rmac2str(zl3vni
, buf
, sizeof(buf
)));
2596 json_object
*json_vrf
= NULL
;
2598 json_vrf
= json_object_new_object();
2599 json_object_string_add(json_vrf
, "vrf", zvrf_name(zvrf
));
2600 json_object_int_add(json_vrf
, "vni", zl3vni
->vni
);
2601 json_object_string_add(json_vrf
, "vxlanIntf",
2602 zl3vni_vxlan_if_name(zl3vni
));
2603 json_object_string_add(json_vrf
, "sviIntf",
2604 zl3vni_svi_if_name(zl3vni
));
2605 json_object_string_add(json_vrf
, "state",
2606 zl3vni_state2str(zl3vni
));
2607 json_object_string_add(
2608 json_vrf
, "routerMac",
2609 zl3vni_rmac2str(zl3vni
, buf
, sizeof(buf
)));
2610 json_object_array_add(json_vrfs
, json_vrf
);
2615 * Display Neighbors for a VNI (VTY command handler).
2617 void zebra_vxlan_print_neigh_vni(struct vty
*vty
, struct zebra_vrf
*zvrf
,
2618 vni_t vni
, bool use_json
)
2620 struct zebra_evpn
*zevpn
;
2622 struct neigh_walk_ctx wctx
;
2623 json_object
*json
= NULL
;
2625 if (!is_evpn_enabled())
2627 zevpn
= zebra_evpn_lookup(vni
);
2630 vty_out(vty
, "{}\n");
2632 vty_out(vty
, "%% VNI %u does not exist\n", vni
);
2635 num_neigh
= hashcount(zevpn
->neigh_table
);
2640 json
= json_object_new_object();
2642 /* Since we have IPv6 addresses to deal with which can vary widely in
2643 * size, we try to be a bit more elegant in display by first computing
2644 * the maximum width.
2646 memset(&wctx
, 0, sizeof(wctx
));
2649 wctx
.addr_width
= 15;
2651 hash_iterate(zevpn
->neigh_table
, zebra_evpn_find_neigh_addr_width
,
2656 "Number of ARPs (local and remote) known for this VNI: %u\n",
2658 zebra_evpn_print_neigh_hdr(vty
, &wctx
);
2660 json_object_int_add(json
, "numArpNd", num_neigh
);
2662 hash_iterate(zevpn
->neigh_table
, zebra_evpn_print_neigh_hash
, &wctx
);
2664 vty_json(vty
, json
);
2668 * Display neighbors across all VNIs (VTY command handler).
2670 void zebra_vxlan_print_neigh_all_vni(struct vty
*vty
, struct zebra_vrf
*zvrf
,
2671 bool print_dup
, bool use_json
)
2673 json_object
*json
= NULL
;
2676 if (!is_evpn_enabled())
2680 json
= json_object_new_object();
2684 args
[2] = (void *)(ptrdiff_t)print_dup
;
2686 hash_iterate(zvrf
->evpn_table
,
2687 (void (*)(struct hash_bucket
*,
2688 void *))zevpn_print_neigh_hash_all_evpn
,
2691 vty_json(vty
, json
);
2695 * Display neighbors across all VNIs in detail(VTY command handler).
2697 void zebra_vxlan_print_neigh_all_vni_detail(struct vty
*vty
,
2698 struct zebra_vrf
*zvrf
,
2699 bool print_dup
, bool use_json
)
2701 json_object
*json
= NULL
;
2704 if (!is_evpn_enabled())
2708 json
= json_object_new_object();
2712 args
[2] = (void *)(ptrdiff_t)print_dup
;
2714 hash_iterate(zvrf
->evpn_table
,
2715 (void (*)(struct hash_bucket
*,
2716 void *))zevpn_print_neigh_hash_all_evpn_detail
,
2719 vty_json(vty
, json
);
2723 * Display specific neighbor for a VNI, if present (VTY command handler).
2725 void zebra_vxlan_print_specific_neigh_vni(struct vty
*vty
,
2726 struct zebra_vrf
*zvrf
, vni_t vni
,
2727 struct ipaddr
*ip
, bool use_json
)
2729 struct zebra_evpn
*zevpn
;
2730 struct zebra_neigh
*n
;
2731 json_object
*json
= NULL
;
2733 if (!is_evpn_enabled())
2735 zevpn
= zebra_evpn_lookup(vni
);
2738 vty_out(vty
, "{}\n");
2740 vty_out(vty
, "%% VNI %u does not exist\n", vni
);
2743 n
= zebra_evpn_neigh_lookup(zevpn
, ip
);
2747 "%% Requested neighbor does not exist in VNI %u\n",
2752 json
= json_object_new_object();
2754 zebra_evpn_print_neigh(n
, vty
, json
);
2757 vty_json(vty
, json
);
2761 * Display neighbors for a VNI from specific VTEP (VTY command handler).
2762 * By definition, these are remote neighbors.
2764 void zebra_vxlan_print_neigh_vni_vtep(struct vty
*vty
, struct zebra_vrf
*zvrf
,
2765 vni_t vni
, struct in_addr vtep_ip
,
2768 struct zebra_evpn
*zevpn
;
2770 struct neigh_walk_ctx wctx
;
2771 json_object
*json
= NULL
;
2773 if (!is_evpn_enabled())
2775 zevpn
= zebra_evpn_lookup(vni
);
2778 vty_out(vty
, "{}\n");
2780 vty_out(vty
, "%% VNI %u does not exist\n", vni
);
2783 num_neigh
= hashcount(zevpn
->neigh_table
);
2788 json
= json_object_new_object();
2790 memset(&wctx
, 0, sizeof(wctx
));
2793 wctx
.addr_width
= 15;
2794 wctx
.flags
= SHOW_REMOTE_NEIGH_FROM_VTEP
;
2795 wctx
.r_vtep_ip
= vtep_ip
;
2797 hash_iterate(zevpn
->neigh_table
, zebra_evpn_find_neigh_addr_width
,
2799 hash_iterate(zevpn
->neigh_table
, zebra_evpn_print_neigh_hash
, &wctx
);
2802 vty_json(vty
, json
);
2806 * Display Duplicate detected Neighbors for a VNI
2807 * (VTY command handler).
2809 void zebra_vxlan_print_neigh_vni_dad(struct vty
*vty
,
2810 struct zebra_vrf
*zvrf
,
2814 struct zebra_evpn
*zevpn
;
2816 struct neigh_walk_ctx wctx
;
2817 json_object
*json
= NULL
;
2819 if (!is_evpn_enabled())
2822 zevpn
= zebra_evpn_lookup(vni
);
2824 vty_out(vty
, "%% VNI %u does not exist\n", vni
);
2828 num_neigh
= hashcount(zevpn
->neigh_table
);
2832 num_neigh
= num_dup_detected_neighs(zevpn
);
2837 json
= json_object_new_object();
2839 /* Since we have IPv6 addresses to deal with which can vary widely in
2840 * size, we try to be a bit more elegant in display by first computing
2841 * the maximum width.
2843 memset(&wctx
, 0, sizeof(wctx
));
2846 wctx
.addr_width
= 15;
2848 hash_iterate(zevpn
->neigh_table
, zebra_evpn_find_neigh_addr_width
,
2853 "Number of ARPs (local and remote) known for this VNI: %u\n",
2855 vty_out(vty
, "%*s %-6s %-8s %-17s %-30s\n",
2856 -wctx
.addr_width
, "IP", "Type",
2857 "State", "MAC", "Remote ES/VTEP");
2859 json_object_int_add(json
, "numArpNd", num_neigh
);
2861 hash_iterate(zevpn
->neigh_table
, zebra_evpn_print_dad_neigh_hash
,
2865 vty_json(vty
, json
);
2869 * Display MACs for a VNI (VTY command handler).
2871 void zebra_vxlan_print_macs_vni(struct vty
*vty
, struct zebra_vrf
*zvrf
,
2872 vni_t vni
, bool use_json
, bool detail
)
2874 struct zebra_evpn
*zevpn
;
2876 struct mac_walk_ctx wctx
;
2877 json_object
*json
= NULL
;
2878 json_object
*json_mac
= NULL
;
2880 if (!is_evpn_enabled())
2882 zevpn
= zebra_evpn_lookup(vni
);
2885 vty_out(vty
, "{}\n");
2887 vty_out(vty
, "%% VNI %u does not exist\n", vni
);
2890 num_macs
= num_valid_macs(zevpn
);
2895 json
= json_object_new_object();
2896 json_mac
= json_object_new_object();
2899 memset(&wctx
, 0, sizeof(wctx
));
2902 wctx
.json
= json_mac
;
2906 vty_out(vty
, "\nVNI %u #MACs (local and remote) %u\n\n",
2907 zevpn
->vni
, num_macs
);
2910 "Number of MACs (local and remote) known for this VNI: %u\n",
2913 "Flags: N=sync-neighs, I=local-inactive, P=peer-active, X=peer-proxy\n");
2914 vty_out(vty
, "%-17s %-6s %-5s %-30s %-5s %s\n", "MAC",
2915 "Type", "Flags", "Intf/Remote ES/VTEP", "VLAN",
2919 json_object_int_add(json
, "numMacs", num_macs
);
2922 hash_iterate(zevpn
->mac_table
, zebra_evpn_print_mac_hash_detail
,
2925 hash_iterate(zevpn
->mac_table
, zebra_evpn_print_mac_hash
,
2929 json_object_object_add(json
, "macs", json_mac
);
2930 vty_json(vty
, json
);
2935 * Display MACs for all VNIs (VTY command handler).
2937 void zebra_vxlan_print_macs_all_vni(struct vty
*vty
, struct zebra_vrf
*zvrf
,
2938 bool print_dup
, bool use_json
)
2940 struct mac_walk_ctx wctx
;
2941 json_object
*json
= NULL
;
2943 if (!is_evpn_enabled()) {
2945 vty_out(vty
, "{}\n");
2949 json
= json_object_new_object();
2951 memset(&wctx
, 0, sizeof(wctx
));
2954 wctx
.print_dup
= print_dup
;
2955 hash_iterate(zvrf
->evpn_table
, zevpn_print_mac_hash_all_evpn
, &wctx
);
2958 vty_json(vty
, json
);
2962 * Display MACs in detail for all VNIs (VTY command handler).
2964 void zebra_vxlan_print_macs_all_vni_detail(struct vty
*vty
,
2965 struct zebra_vrf
*zvrf
,
2966 bool print_dup
, bool use_json
)
2968 struct mac_walk_ctx wctx
;
2969 json_object
*json
= NULL
;
2971 if (!is_evpn_enabled()) {
2973 vty_out(vty
, "{}\n");
2977 json
= json_object_new_object();
2979 memset(&wctx
, 0, sizeof(wctx
));
2982 wctx
.print_dup
= print_dup
;
2983 hash_iterate(zvrf
->evpn_table
, zevpn_print_mac_hash_all_evpn_detail
,
2987 vty_json(vty
, json
);
2991 * Display MACs for all VNIs (VTY command handler).
2993 void zebra_vxlan_print_macs_all_vni_vtep(struct vty
*vty
,
2994 struct zebra_vrf
*zvrf
,
2995 struct in_addr vtep_ip
, bool use_json
)
2997 struct mac_walk_ctx wctx
;
2998 json_object
*json
= NULL
;
3000 if (!is_evpn_enabled())
3004 json
= json_object_new_object();
3006 memset(&wctx
, 0, sizeof(wctx
));
3008 wctx
.flags
= SHOW_REMOTE_MAC_FROM_VTEP
;
3009 wctx
.r_vtep_ip
= vtep_ip
;
3011 hash_iterate(zvrf
->evpn_table
, zevpn_print_mac_hash_all_evpn
, &wctx
);
3014 vty_json(vty
, json
);
3018 * Display specific MAC for a VNI, if present (VTY command handler).
3020 void zebra_vxlan_print_specific_mac_vni(struct vty
*vty
, struct zebra_vrf
*zvrf
,
3021 vni_t vni
, struct ethaddr
*macaddr
,
3024 struct zebra_evpn
*zevpn
;
3025 struct zebra_mac
*mac
;
3026 json_object
*json
= NULL
;
3028 if (!is_evpn_enabled())
3031 zevpn
= zebra_evpn_lookup(vni
);
3034 vty_out(vty
, "{}\n");
3036 vty_out(vty
, "%% VNI %u does not exist\n", vni
);
3039 mac
= zebra_evpn_mac_lookup(zevpn
, macaddr
);
3042 vty_out(vty
, "{}\n");
3045 "%% Requested MAC does not exist in VNI %u\n",
3051 json
= json_object_new_object();
3053 zebra_evpn_print_mac(mac
, vty
, json
);
3055 vty_json(vty
, json
);
3058 /* Print Duplicate MACs per VNI */
3059 void zebra_vxlan_print_macs_vni_dad(struct vty
*vty
,
3060 struct zebra_vrf
*zvrf
,
3061 vni_t vni
, bool use_json
)
3063 struct zebra_evpn
*zevpn
;
3064 struct mac_walk_ctx wctx
;
3066 json_object
*json
= NULL
;
3067 json_object
*json_mac
= NULL
;
3069 if (!is_evpn_enabled())
3072 zevpn
= zebra_evpn_lookup(vni
);
3074 vty_out(vty
, "%% VNI %u does not exist\n", vni
);
3078 num_macs
= num_valid_macs(zevpn
);
3082 num_macs
= num_dup_detected_macs(zevpn
);
3087 json
= json_object_new_object();
3088 json_mac
= json_object_new_object();
3091 memset(&wctx
, 0, sizeof(wctx
));
3094 wctx
.json
= json_mac
;
3098 "Number of MACs (local and remote) known for this VNI: %u\n",
3100 vty_out(vty
, "%-17s %-6s %-5s %-30s %-5s\n", "MAC", "Type",
3101 "Flags", "Intf/Remote ES/VTEP", "VLAN");
3103 json_object_int_add(json
, "numMacs", num_macs
);
3105 hash_iterate(zevpn
->mac_table
, zebra_evpn_print_dad_mac_hash
, &wctx
);
3108 json_object_object_add(json
, "macs", json_mac
);
3109 vty_json(vty
, json
);
3114 int zebra_vxlan_clear_dup_detect_vni_mac(struct zebra_vrf
*zvrf
, vni_t vni
,
3115 struct ethaddr
*macaddr
, char *errmsg
,
3118 struct zebra_evpn
*zevpn
;
3119 struct zebra_mac
*mac
;
3120 struct listnode
*node
= NULL
;
3121 struct zebra_neigh
*nbr
= NULL
;
3123 if (!is_evpn_enabled())
3126 zevpn
= zebra_evpn_lookup(vni
);
3128 snprintfrr(errmsg
, errmsg_len
, "VNI %u does not exist", vni
);
3132 mac
= zebra_evpn_mac_lookup(zevpn
, macaddr
);
3134 snprintf(errmsg
, errmsg_len
,
3135 "Requested MAC does not exist in VNI %u\n", vni
);
3139 if (!CHECK_FLAG(mac
->flags
, ZEBRA_MAC_DUPLICATE
)) {
3140 snprintfrr(errmsg
, errmsg_len
,
3141 "Requested MAC is not duplicate detected\n");
3145 /* Remove all IPs as duplicate associcated with this MAC */
3146 for (ALL_LIST_ELEMENTS_RO(mac
->neigh_list
, node
, nbr
)) {
3147 /* For local neigh mark inactive so MACIP update is generated
3148 * to BGP. This is a scenario where MAC update received
3149 * and detected as duplicate which marked neigh as duplicate.
3150 * Later local neigh update did not get a chance to relay
3151 * to BGP. Similarly remote macip update, neigh needs to be
3152 * installed locally.
3154 if (zvrf
->dad_freeze
&&
3155 CHECK_FLAG(nbr
->flags
, ZEBRA_NEIGH_DUPLICATE
)) {
3156 if (CHECK_FLAG(nbr
->flags
, ZEBRA_NEIGH_LOCAL
))
3157 ZEBRA_NEIGH_SET_INACTIVE(nbr
);
3158 else if (CHECK_FLAG(nbr
->flags
, ZEBRA_NEIGH_REMOTE
))
3159 zebra_evpn_rem_neigh_install(
3160 zevpn
, nbr
, false /*was_static*/);
3163 UNSET_FLAG(nbr
->flags
, ZEBRA_NEIGH_DUPLICATE
);
3165 nbr
->detect_start_time
.tv_sec
= 0;
3166 nbr
->dad_dup_detect_time
= 0;
3169 UNSET_FLAG(mac
->flags
, ZEBRA_MAC_DUPLICATE
);
3171 mac
->detect_start_time
.tv_sec
= 0;
3172 mac
->detect_start_time
.tv_usec
= 0;
3173 mac
->dad_dup_detect_time
= 0;
3174 THREAD_OFF(mac
->dad_mac_auto_recovery_timer
);
3176 /* warn-only action return */
3177 if (!zvrf
->dad_freeze
)
3180 /* Local: Notify Peer VTEPs, Remote: Install the entry */
3181 if (CHECK_FLAG(mac
->flags
, ZEBRA_MAC_LOCAL
)) {
3183 if (zebra_evpn_mac_send_add_to_client(zevpn
->vni
, &mac
->macaddr
,
3184 mac
->flags
, mac
->loc_seq
,
3188 /* Process all neighbors associated with this MAC. */
3189 zebra_evpn_process_neigh_on_local_mac_change(zevpn
, mac
, 0,
3192 } else if (CHECK_FLAG(mac
->flags
, ZEBRA_MAC_REMOTE
)) {
3193 zebra_evpn_process_neigh_on_remote_mac_add(zevpn
, mac
);
3195 /* Install the entry. */
3196 zebra_evpn_rem_mac_install(zevpn
, mac
, false /* was_static */);
3202 int zebra_vxlan_clear_dup_detect_vni_ip(struct zebra_vrf
*zvrf
, vni_t vni
,
3203 struct ipaddr
*ip
, char *errmsg
,
3206 struct zebra_evpn
*zevpn
;
3207 struct zebra_neigh
*nbr
;
3208 struct zebra_mac
*mac
;
3209 char buf
[INET6_ADDRSTRLEN
];
3210 char buf2
[ETHER_ADDR_STRLEN
];
3212 if (!is_evpn_enabled())
3215 zevpn
= zebra_evpn_lookup(vni
);
3217 snprintfrr(errmsg
, errmsg_len
, "VNI %u does not exist\n", vni
);
3221 nbr
= zebra_evpn_neigh_lookup(zevpn
, ip
);
3223 snprintfrr(errmsg
, errmsg_len
,
3224 "Requested host IP does not exist in VNI %u\n", vni
);
3228 ipaddr2str(&nbr
->ip
, buf
, sizeof(buf
));
3230 if (!CHECK_FLAG(nbr
->flags
, ZEBRA_NEIGH_DUPLICATE
)) {
3231 snprintfrr(errmsg
, errmsg_len
,
3232 "Requested host IP %s is not duplicate detected\n",
3237 mac
= zebra_evpn_mac_lookup(zevpn
, &nbr
->emac
);
3239 if (CHECK_FLAG(mac
->flags
, ZEBRA_MAC_DUPLICATE
)) {
3242 "Requested IP's associated MAC %s is still in duplicate state\n",
3243 prefix_mac2str(&nbr
->emac
, buf2
, sizeof(buf2
)));
3247 if (IS_ZEBRA_DEBUG_VXLAN
)
3248 zlog_debug("%s: clear neigh %s in dup state, flags 0x%x seq %u",
3249 __func__
, buf
, nbr
->flags
, nbr
->loc_seq
);
3251 UNSET_FLAG(nbr
->flags
, ZEBRA_NEIGH_DUPLICATE
);
3253 nbr
->detect_start_time
.tv_sec
= 0;
3254 nbr
->detect_start_time
.tv_usec
= 0;
3255 nbr
->dad_dup_detect_time
= 0;
3256 THREAD_OFF(nbr
->dad_ip_auto_recovery_timer
);
3258 if (!!CHECK_FLAG(nbr
->flags
, ZEBRA_NEIGH_LOCAL
)) {
3259 zebra_evpn_neigh_send_add_to_client(zevpn
->vni
, ip
, &nbr
->emac
,
3260 nbr
->mac
, nbr
->flags
,
3262 } else if (!!CHECK_FLAG(nbr
->flags
, ZEBRA_NEIGH_REMOTE
)) {
3263 zebra_evpn_rem_neigh_install(zevpn
, nbr
, false /*was_static*/);
3269 static void zevpn_clear_dup_mac_hash(struct hash_bucket
*bucket
, void *ctxt
)
3271 struct mac_walk_ctx
*wctx
= ctxt
;
3272 struct zebra_mac
*mac
;
3273 struct zebra_evpn
*zevpn
;
3274 struct listnode
*node
= NULL
;
3275 struct zebra_neigh
*nbr
= NULL
;
3277 mac
= (struct zebra_mac
*)bucket
->data
;
3281 zevpn
= wctx
->zevpn
;
3283 if (!CHECK_FLAG(mac
->flags
, ZEBRA_MAC_DUPLICATE
))
3286 UNSET_FLAG(mac
->flags
, ZEBRA_MAC_DUPLICATE
);
3288 mac
->detect_start_time
.tv_sec
= 0;
3289 mac
->detect_start_time
.tv_usec
= 0;
3290 mac
->dad_dup_detect_time
= 0;
3291 THREAD_OFF(mac
->dad_mac_auto_recovery_timer
);
3293 /* Remove all IPs as duplicate associcated with this MAC */
3294 for (ALL_LIST_ELEMENTS_RO(mac
->neigh_list
, node
, nbr
)) {
3295 if (CHECK_FLAG(nbr
->flags
, ZEBRA_NEIGH_LOCAL
)
3297 ZEBRA_NEIGH_SET_INACTIVE(nbr
);
3299 UNSET_FLAG(nbr
->flags
, ZEBRA_NEIGH_DUPLICATE
);
3301 nbr
->detect_start_time
.tv_sec
= 0;
3302 nbr
->dad_dup_detect_time
= 0;
3305 /* Local: Notify Peer VTEPs, Remote: Install the entry */
3306 if (CHECK_FLAG(mac
->flags
, ZEBRA_MAC_LOCAL
)) {
3308 if (zebra_evpn_mac_send_add_to_client(zevpn
->vni
, &mac
->macaddr
,
3309 mac
->flags
, mac
->loc_seq
,
3313 /* Process all neighbors associated with this MAC. */
3314 zebra_evpn_process_neigh_on_local_mac_change(zevpn
, mac
, 0,
3317 } else if (CHECK_FLAG(mac
->flags
, ZEBRA_MAC_REMOTE
)) {
3318 zebra_evpn_process_neigh_on_remote_mac_add(zevpn
, mac
);
3320 /* Install the entry. */
3321 zebra_evpn_rem_mac_install(zevpn
, mac
, false /* was_static */);
3325 static void zevpn_clear_dup_detect_hash_vni_all(struct hash_bucket
*bucket
,
3328 struct zebra_evpn
*zevpn
;
3329 struct zebra_vrf
*zvrf
;
3330 struct mac_walk_ctx m_wctx
;
3331 struct neigh_walk_ctx n_wctx
;
3333 zevpn
= (struct zebra_evpn
*)bucket
->data
;
3337 zvrf
= (struct zebra_vrf
*)args
[0];
3339 if (hashcount(zevpn
->neigh_table
)) {
3340 memset(&n_wctx
, 0, sizeof(n_wctx
));
3341 n_wctx
.zevpn
= zevpn
;
3343 hash_iterate(zevpn
->neigh_table
,
3344 zebra_evpn_clear_dup_neigh_hash
, &n_wctx
);
3347 if (num_valid_macs(zevpn
)) {
3348 memset(&m_wctx
, 0, sizeof(m_wctx
));
3349 m_wctx
.zevpn
= zevpn
;
3351 hash_iterate(zevpn
->mac_table
, zevpn_clear_dup_mac_hash
, &m_wctx
);
3356 int zebra_vxlan_clear_dup_detect_vni_all(struct zebra_vrf
*zvrf
)
3360 if (!is_evpn_enabled())
3365 hash_iterate(zvrf
->evpn_table
,
3366 (void (*)(struct hash_bucket
*, void *))
3367 zevpn_clear_dup_detect_hash_vni_all
, args
);
3372 int zebra_vxlan_clear_dup_detect_vni(struct zebra_vrf
*zvrf
, vni_t vni
)
3374 struct zebra_evpn
*zevpn
;
3375 struct mac_walk_ctx m_wctx
;
3376 struct neigh_walk_ctx n_wctx
;
3378 if (!is_evpn_enabled())
3381 zevpn
= zebra_evpn_lookup(vni
);
3383 zlog_warn("VNI %u does not exist", vni
);
3387 if (hashcount(zevpn
->neigh_table
)) {
3388 memset(&n_wctx
, 0, sizeof(n_wctx
));
3389 n_wctx
.zevpn
= zevpn
;
3391 hash_iterate(zevpn
->neigh_table
,
3392 zebra_evpn_clear_dup_neigh_hash
, &n_wctx
);
3395 if (num_valid_macs(zevpn
)) {
3396 memset(&m_wctx
, 0, sizeof(m_wctx
));
3397 m_wctx
.zevpn
= zevpn
;
3399 hash_iterate(zevpn
->mac_table
, zevpn_clear_dup_mac_hash
, &m_wctx
);
3406 * Display MACs for a VNI from specific VTEP (VTY command handler).
3408 void zebra_vxlan_print_macs_vni_vtep(struct vty
*vty
, struct zebra_vrf
*zvrf
,
3409 vni_t vni
, struct in_addr vtep_ip
,
3412 struct zebra_evpn
*zevpn
;
3414 struct mac_walk_ctx wctx
;
3415 json_object
*json
= NULL
;
3416 json_object
*json_mac
= NULL
;
3418 if (!is_evpn_enabled())
3420 zevpn
= zebra_evpn_lookup(vni
);
3423 vty_out(vty
, "{}\n");
3425 vty_out(vty
, "%% VNI %u does not exist\n", vni
);
3428 num_macs
= num_valid_macs(zevpn
);
3433 json
= json_object_new_object();
3434 json_mac
= json_object_new_object();
3437 memset(&wctx
, 0, sizeof(wctx
));
3440 wctx
.flags
= SHOW_REMOTE_MAC_FROM_VTEP
;
3441 wctx
.r_vtep_ip
= vtep_ip
;
3442 wctx
.json
= json_mac
;
3443 hash_iterate(zevpn
->mac_table
, zebra_evpn_print_mac_hash
, &wctx
);
3446 json_object_int_add(json
, "numMacs", wctx
.count
);
3448 json_object_object_add(json
, "macs", json_mac
);
3449 vty_json(vty
, json
);
3455 * Display VNI information (VTY command handler).
3457 * use_json flag indicates that output should be in JSON format.
3458 * json_array is non NULL when JSON output needs to be aggregated (by the
3459 * caller) and then printed, otherwise, JSON evpn vni info is printed
3462 void zebra_vxlan_print_vni(struct vty
*vty
, struct zebra_vrf
*zvrf
, vni_t vni
,
3463 bool use_json
, json_object
*json_array
)
3465 json_object
*json
= NULL
;
3467 struct zebra_l3vni
*zl3vni
= NULL
;
3468 struct zebra_evpn
*zevpn
= NULL
;
3470 if (!is_evpn_enabled())
3474 json
= json_object_new_object();
3479 zl3vni
= zl3vni_lookup(vni
);
3481 zl3vni_print(zl3vni
, (void *)args
);
3483 zevpn
= zebra_evpn_lookup(vni
);
3485 zebra_evpn_print(zevpn
, (void *)args
);
3487 vty_out(vty
, "%% VNI %u does not exist\n", vni
);
3492 * Each "json" object contains info about 1 VNI.
3493 * When "json_array" is non-null, we aggreggate the json output
3494 * into json_array and print it as a JSON array.
3497 json_object_array_add(json_array
, json
);
3499 vty_json(vty
, json
);
3503 /* Display all global details for EVPN */
3504 void zebra_vxlan_print_evpn(struct vty
*vty
, bool uj
)
3509 json_object
*json
= NULL
;
3510 struct zebra_vrf
*zvrf
= NULL
;
3512 if (!is_evpn_enabled())
3515 zvrf
= zebra_vrf_get_evpn();
3517 num_l3vnis
= hashcount(zrouter
.l3vni_table
);
3518 num_l2vnis
= hashcount(zvrf
->evpn_table
);
3519 num_vnis
= num_l2vnis
+ num_l3vnis
;
3522 json
= json_object_new_object();
3523 json_object_string_add(json
, "advertiseGatewayMacip",
3524 zvrf
->advertise_gw_macip
? "Yes" : "No");
3525 json_object_string_add(json
, "advertiseSviMacip",
3526 zvrf
->advertise_svi_macip
? "Yes"
3528 json_object_string_add(json
, "advertiseSviMac",
3529 zebra_evpn_mh_do_adv_svi_mac() ? "Yes"
3531 json_object_int_add(json
, "numVnis", num_vnis
);
3532 json_object_int_add(json
, "numL2Vnis", num_l2vnis
);
3533 json_object_int_add(json
, "numL3Vnis", num_l3vnis
);
3534 if (zebra_evpn_do_dup_addr_detect(zvrf
))
3535 json_object_boolean_true_add(json
,
3536 "isDuplicateAddrDetection");
3538 json_object_boolean_false_add(json
,
3539 "isDuplicateAddrDetection");
3540 json_object_int_add(json
, "maxMoves", zvrf
->dad_max_moves
);
3541 json_object_int_add(json
, "detectionTime", zvrf
->dad_time
);
3542 json_object_int_add(json
, "detectionFreezeTime",
3543 zvrf
->dad_freeze_time
);
3544 zebra_evpn_mh_json(json
);
3546 vty_out(vty
, "L2 VNIs: %u\n", num_l2vnis
);
3547 vty_out(vty
, "L3 VNIs: %u\n", num_l3vnis
);
3548 vty_out(vty
, "Advertise gateway mac-ip: %s\n",
3549 zvrf
->advertise_gw_macip
? "Yes" : "No");
3550 vty_out(vty
, "Advertise svi mac-ip: %s\n",
3551 zvrf
->advertise_svi_macip
? "Yes" : "No");
3552 vty_out(vty
, "Advertise svi mac: %s\n",
3553 zebra_evpn_mh_do_adv_svi_mac() ? "Yes" : "No");
3554 vty_out(vty
, "Duplicate address detection: %s\n",
3555 zebra_evpn_do_dup_addr_detect(zvrf
) ? "Enable"
3557 vty_out(vty
, " Detection max-moves %u, time %d\n",
3558 zvrf
->dad_max_moves
, zvrf
->dad_time
);
3559 if (zvrf
->dad_freeze
) {
3560 if (zvrf
->dad_freeze_time
)
3561 vty_out(vty
, " Detection freeze %u\n",
3562 zvrf
->dad_freeze_time
);
3564 vty_out(vty
, " Detection freeze %s\n",
3567 zebra_evpn_mh_print(vty
);
3571 vty_json(vty
, json
);
3575 * Display VNI hash table (VTY command handler).
3577 void zebra_vxlan_print_vnis(struct vty
*vty
, struct zebra_vrf
*zvrf
,
3580 json_object
*json
= NULL
;
3583 if (!is_evpn_enabled())
3587 json
= json_object_new_object();
3589 vty_out(vty
, "%-10s %-4s %-21s %-8s %-8s %-15s %-37s\n", "VNI",
3590 "Type", "VxLAN IF", "# MACs", "# ARPs",
3591 "# Remote VTEPs", "Tenant VRF");
3596 /* Display all L2-VNIs */
3599 (void (*)(struct hash_bucket
*, void *))zebra_evpn_print_hash
,
3602 /* Display all L3-VNIs */
3603 hash_iterate(zrouter
.l3vni_table
,
3604 (void (*)(struct hash_bucket
*, void *))zl3vni_print_hash
,
3608 vty_json(vty
, json
);
3611 void zebra_vxlan_dup_addr_detection(ZAPI_HANDLER_ARGS
)
3615 uint32_t max_moves
= 0;
3616 uint32_t freeze_time
= 0;
3617 bool dup_addr_detect
= false;
3618 bool freeze
= false;
3619 bool old_addr_detect
;
3622 STREAM_GETL(s
, dup_addr_detect
);
3623 STREAM_GETL(s
, time
);
3624 STREAM_GETL(s
, max_moves
);
3625 STREAM_GETL(s
, freeze
);
3626 STREAM_GETL(s
, freeze_time
);
3628 old_addr_detect
= zebra_evpn_do_dup_addr_detect(zvrf
);
3629 zvrf
->dup_addr_detect
= dup_addr_detect
;
3630 dup_addr_detect
= zebra_evpn_do_dup_addr_detect(zvrf
);
3632 /* DAD previous state was enabled, and new state is disable,
3633 * clear all duplicate detected addresses.
3635 if (old_addr_detect
&& !dup_addr_detect
)
3636 zebra_vxlan_clear_dup_detect_vni_all(zvrf
);
3638 zvrf
->dad_time
= time
;
3639 zvrf
->dad_max_moves
= max_moves
;
3640 zvrf
->dad_freeze
= freeze
;
3641 zvrf
->dad_freeze_time
= freeze_time
;
3643 if (IS_ZEBRA_DEBUG_VXLAN
)
3645 "VRF %s duplicate detect %s max_moves %u timeout %u freeze %s freeze_time %u",
3646 vrf_id_to_name(zvrf
->vrf
->vrf_id
),
3647 dup_addr_detect
? "enable" : "disable",
3648 zvrf
->dad_max_moves
, zvrf
->dad_time
,
3649 zvrf
->dad_freeze
? "enable" : "disable",
3650 zvrf
->dad_freeze_time
);
3657 * Display VNI hash table in detail(VTY command handler).
3659 void zebra_vxlan_print_vnis_detail(struct vty
*vty
, struct zebra_vrf
*zvrf
,
3662 json_object
*json_array
= NULL
;
3663 struct zebra_ns
*zns
= NULL
;
3664 struct zebra_evpn_show zes
;
3666 if (!is_evpn_enabled())
3669 zns
= zebra_ns_lookup(NS_DEFAULT
);
3674 json_array
= json_object_new_array();
3677 zes
.json
= json_array
;
3679 zes
.use_json
= use_json
;
3681 /* Display all L2-VNIs */
3682 hash_iterate(zvrf
->evpn_table
,
3683 (void (*)(struct hash_bucket
*,
3684 void *))zebra_evpn_print_hash_detail
,
3687 /* Display all L3-VNIs */
3688 hash_iterate(zrouter
.l3vni_table
,
3689 (void (*)(struct hash_bucket
*,
3690 void *))zl3vni_print_hash_detail
,
3694 vty_json(vty
, json_array
);
3698 * Handle neighbor delete notification from the kernel (on a VLAN device
3699 * / L3 interface). This may result in either the neighbor getting deleted
3700 * from our database or being re-added to the kernel (if it is a valid
3703 int zebra_vxlan_handle_kernel_neigh_del(struct interface
*ifp
,
3704 struct interface
*link_if
,
3707 struct zebra_evpn
*zevpn
= NULL
;
3708 struct zebra_l3vni
*zl3vni
= NULL
;
3710 /* check if this is a remote neigh entry corresponding to remote
3713 zl3vni
= zl3vni_from_svi(ifp
, link_if
);
3715 return zl3vni_local_nh_del(zl3vni
, ip
);
3717 /* We are only interested in neighbors on an SVI that resides on top
3718 * of a VxLAN bridge.
3720 zevpn
= zebra_evpn_from_svi(ifp
, link_if
);
3722 if (IS_ZEBRA_DEBUG_VXLAN
)
3724 "%s: Del neighbor %pIA EVPN is not present for interface %s",
3725 __func__
, ip
, ifp
->name
);
3729 if (!zevpn
->vxlan_if
) {
3731 "VNI %u hash %p doesn't have intf upon local neighbor DEL",
3736 if (IS_ZEBRA_DEBUG_VXLAN
)
3737 zlog_debug("Del neighbor %pIA intf %s(%u) -> L2-VNI %u",
3738 ip
, ifp
->name
, ifp
->ifindex
, zevpn
->vni
);
3740 return zebra_evpn_neigh_del_ip(zevpn
, ip
);
3744 * Handle neighbor add or update notification from the kernel (on a VLAN
3745 * device / L3 interface). This is typically for a local neighbor but can
3746 * also be for a remote neighbor (e.g., ageout notification). It could
3747 * also be a "move" scenario.
3749 int zebra_vxlan_handle_kernel_neigh_update(struct interface
*ifp
,
3750 struct interface
*link_if
,
3752 struct ethaddr
*macaddr
,
3756 bool local_inactive
, bool dp_static
)
3758 struct zebra_evpn
*zevpn
= NULL
;
3759 struct zebra_l3vni
*zl3vni
= NULL
;
3761 /* check if this is a remote neigh entry corresponding to remote
3764 zl3vni
= zl3vni_from_svi(ifp
, link_if
);
3766 return zl3vni_local_nh_add_update(zl3vni
, ip
, state
);
3768 /* We are only interested in neighbors on an SVI that resides on top
3769 * of a VxLAN bridge.
3771 zevpn
= zebra_evpn_from_svi(ifp
, link_if
);
3775 if (IS_ZEBRA_DEBUG_VXLAN
|| IS_ZEBRA_DEBUG_EVPN_MH_NEIGH
)
3777 "Add/Update neighbor %pIA MAC %pEA intf %s(%u) state 0x%x %s%s%s%s-> L2-VNI %u",
3778 ip
, macaddr
, ifp
->name
,
3779 ifp
->ifindex
, state
, is_ext
? "ext-learned " : "",
3780 is_router
? "router " : "",
3781 local_inactive
? "local_inactive " : "",
3782 dp_static
? "peer_sync " : "", zevpn
->vni
);
3784 /* Is this about a local neighbor or a remote one? */
3786 return zebra_evpn_local_neigh_update(zevpn
, ifp
, ip
, macaddr
,
3787 is_router
, local_inactive
,
3790 return zebra_evpn_remote_neigh_update(zevpn
, ifp
, ip
, macaddr
, state
);
3794 zebra_vxlan_remote_macip_helper(bool add
, struct stream
*s
, vni_t
*vni
,
3795 struct ethaddr
*macaddr
, uint16_t *ipa_len
,
3796 struct ipaddr
*ip
, struct in_addr
*vtep_ip
,
3797 uint8_t *flags
, uint32_t *seq
, esi_t
*esi
)
3802 * Obtain each remote MACIP and process.
3803 * Message contains VNI, followed by MAC followed by IP (if any)
3804 * followed by remote VTEP IP.
3806 memset(ip
, 0, sizeof(*ip
));
3807 STREAM_GETL(s
, *vni
);
3808 STREAM_GET(macaddr
->octet
, s
, ETH_ALEN
);
3809 STREAM_GETW(s
, *ipa_len
);
3812 if (*ipa_len
== IPV4_MAX_BYTELEN
)
3813 ip
->ipa_type
= IPADDR_V4
;
3814 else if (*ipa_len
== IPV6_MAX_BYTELEN
)
3815 ip
->ipa_type
= IPADDR_V6
;
3817 if (IS_ZEBRA_DEBUG_VXLAN
)
3819 "ipa_len *must* be %d or %d bytes in length not %d",
3820 IPV4_MAX_BYTELEN
, IPV6_MAX_BYTELEN
,
3822 goto stream_failure
;
3825 STREAM_GET(&ip
->ip
.addr
, s
, *ipa_len
);
3827 l
+= 4 + ETH_ALEN
+ 4 + *ipa_len
;
3828 STREAM_GET(&vtep_ip
->s_addr
, s
, IPV4_MAX_BYTELEN
);
3829 l
+= IPV4_MAX_BYTELEN
;
3832 STREAM_GETC(s
, *flags
);
3833 STREAM_GETL(s
, *seq
);
3835 STREAM_GET(esi
, s
, sizeof(esi_t
));
3846 * Handle message from client to delete a remote MACIP for a VNI.
3848 void zebra_vxlan_remote_macip_del(ZAPI_HANDLER_ARGS
)
3852 struct ethaddr macaddr
;
3854 struct in_addr vtep_ip
;
3855 uint16_t l
= 0, ipa_len
;
3856 char buf1
[INET6_ADDRSTRLEN
];
3860 while (l
< hdr
->length
) {
3861 int res_length
= zebra_vxlan_remote_macip_helper(
3862 false, s
, &vni
, &macaddr
, &ipa_len
, &ip
, &vtep_ip
, NULL
,
3865 if (res_length
== -1)
3866 goto stream_failure
;
3869 if (IS_ZEBRA_DEBUG_VXLAN
)
3871 "Recv MACIP DEL VNI %u MAC %pEA%s%s Remote VTEP %pI4 from %s",
3873 ipa_len
? " IP " : "",
3875 ipaddr2str(&ip
, buf1
, sizeof(buf1
)) : "",
3876 &vtep_ip
, zebra_route_string(client
->proto
));
3878 /* Enqueue to workqueue for processing */
3879 zebra_rib_queue_evpn_rem_macip_del(vni
, &macaddr
, &ip
, vtep_ip
);
3887 * Handle message from client to add a remote MACIP for a VNI. This
3888 * could be just the add of a MAC address or the add of a neighbor
3891 void zebra_vxlan_remote_macip_add(ZAPI_HANDLER_ARGS
)
3895 struct ethaddr macaddr
;
3897 struct in_addr vtep_ip
;
3898 uint16_t l
= 0, ipa_len
;
3901 char buf1
[INET6_ADDRSTRLEN
];
3903 char esi_buf
[ESI_STR_LEN
];
3905 if (!EVPN_ENABLED(zvrf
)) {
3906 zlog_debug("EVPN not enabled, ignoring remote MACIP ADD");
3912 while (l
< hdr
->length
) {
3914 int res_length
= zebra_vxlan_remote_macip_helper(
3915 true, s
, &vni
, &macaddr
, &ipa_len
, &ip
, &vtep_ip
,
3916 &flags
, &seq
, &esi
);
3918 if (res_length
== -1)
3919 goto stream_failure
;
3922 if (IS_ZEBRA_DEBUG_VXLAN
) {
3923 if (memcmp(&esi
, zero_esi
, sizeof(esi_t
)))
3924 esi_to_str(&esi
, esi_buf
, sizeof(esi_buf
));
3926 strlcpy(esi_buf
, "-", ESI_STR_LEN
);
3928 "Recv %sMACIP ADD VNI %u MAC %pEA%s%s flags 0x%x seq %u VTEP %pI4 ESI %s from %s",
3929 (flags
& ZEBRA_MACIP_TYPE_SYNC_PATH
) ?
3932 ipa_len
? " IP " : "",
3934 ipaddr2str(&ip
, buf1
, sizeof(buf1
)) : "",
3935 flags
, seq
, &vtep_ip
, esi_buf
,
3936 zebra_route_string(client
->proto
));
3939 /* Enqueue to workqueue for processing */
3940 zebra_rib_queue_evpn_rem_macip_add(vni
, &macaddr
, &ip
, flags
,
3941 seq
, vtep_ip
, &esi
);
3949 * Handle remote vtep delete by kernel; re-add the vtep if we have it
3951 int zebra_vxlan_check_readd_vtep(struct interface
*ifp
,
3952 struct in_addr vtep_ip
)
3954 struct zebra_if
*zif
;
3955 struct zebra_vrf
*zvrf
= NULL
;
3956 struct zebra_l2info_vxlan
*vxl
;
3958 struct zebra_evpn
*zevpn
= NULL
;
3959 struct zebra_vtep
*zvtep
= NULL
;
3963 vxl
= &zif
->l2info
.vxl
;
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 /* Locate hash entry; it is expected to exist. */
3976 zevpn
= zebra_evpn_lookup(vni
);
3980 /* If the remote vtep entry doesn't exists nothing to do */
3981 zvtep
= zebra_evpn_vtep_find(zevpn
, &vtep_ip
);
3985 if (IS_ZEBRA_DEBUG_VXLAN
)
3987 "Del MAC for remote VTEP %pI4 intf %s(%u) VNI %u - readd",
3988 &vtep_ip
, ifp
->name
, ifp
->ifindex
, vni
);
3990 zebra_evpn_vtep_install(zevpn
, zvtep
);
3995 * Handle notification of MAC add/update over VxLAN. If the kernel is notifying
3996 * us, this must involve a multihoming scenario. Treat this as implicit delete
3997 * of any prior local MAC.
3999 static int zebra_vxlan_check_del_local_mac(struct interface
*ifp
,
4000 struct interface
*br_if
,
4001 struct ethaddr
*macaddr
,
4004 struct zebra_if
*zif
;
4005 struct zebra_l2info_vxlan
*vxl
;
4007 struct zebra_evpn
*zevpn
;
4008 struct zebra_mac
*mac
;
4012 vxl
= &zif
->l2info
.vxl
;
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 uint32_t nhg_id
, bool sticky
, bool dp_static
)
4067 struct zebra_evpn_es
*es
;
4068 struct interface
*acc_ifp
;
4070 /* If netlink message is with vid, it will have no nexthop.
4074 if (IS_ZEBRA_DEBUG_VXLAN
|| IS_ZEBRA_DEBUG_EVPN_MH_MAC
)
4075 zlog_debug("dpAdd MAC %pEA VID %u - ignore as no nhid",
4080 /* Get vxlan's vid for netlink message has no it. */
4081 vid
= ((struct zebra_if
*)ifp
->info
)->l2info
.vxl
.access_vlan
;
4083 /* if remote mac delete the local entry */
4084 if (!nhg_id
|| !zebra_evpn_nhg_is_local_es(nhg_id
, &es
)
4085 || !zebra_evpn_es_local_mac_via_network_port(es
)) {
4086 if (IS_ZEBRA_DEBUG_VXLAN
|| IS_ZEBRA_DEBUG_EVPN_MH_MAC
)
4087 zlog_debug("dpAdd remote MAC %pEA VID %u", macaddr
,
4089 return zebra_vxlan_check_del_local_mac(ifp
, br_if
, macaddr
,
4093 /* If local MAC on a down local ES translate the network-mac-add
4094 * to a local-active-mac-add
4096 if (IS_ZEBRA_DEBUG_VXLAN
|| IS_ZEBRA_DEBUG_EVPN_MH_MAC
)
4097 zlog_debug("dpAdd local-nw-MAC %pEA VID %u", macaddr
, vid
);
4098 acc_ifp
= es
->zif
->ifp
;
4099 return zebra_vxlan_local_mac_add_update(
4100 acc_ifp
, br_if
, macaddr
, vid
, sticky
,
4101 false /* local_inactive */, dp_static
);
4105 * Handle network MAC delete by kernel -
4106 * 1. readd the remote MAC if we have it
4107 * 2. local MAC with does ES may also need to be re-installed
4109 int zebra_vxlan_dp_network_mac_del(struct interface
*ifp
,
4110 struct interface
*br_if
,
4111 struct ethaddr
*macaddr
, vlanid_t vid
)
4113 struct zebra_if
*zif
= NULL
;
4114 struct zebra_l2info_vxlan
*vxl
= NULL
;
4116 struct zebra_evpn
*zevpn
= NULL
;
4117 struct zebra_l3vni
*zl3vni
= NULL
;
4118 struct zebra_mac
*mac
= NULL
;
4122 vxl
= &zif
->l2info
.vxl
;
4125 /* Check if EVPN is enabled. */
4126 if (!is_evpn_enabled())
4129 /* check if this is a remote RMAC and readd simillar to remote macs */
4130 zl3vni
= zl3vni_lookup(vni
);
4132 return zebra_vxlan_readd_remote_rmac(zl3vni
, macaddr
);
4134 /* Locate hash entry; it is expected to exist. */
4135 zevpn
= zebra_evpn_lookup(vni
);
4139 /* If entry doesn't exist, nothing to do. */
4140 mac
= zebra_evpn_mac_lookup(zevpn
, macaddr
);
4144 if (CHECK_FLAG(mac
->flags
, ZEBRA_MAC_REMOTE
)) {
4145 /* If remote entry simply re-install */
4146 if (IS_ZEBRA_DEBUG_VXLAN
|| IS_ZEBRA_DEBUG_EVPN_MH_MAC
)
4148 "dpDel remote MAC %pEA intf %s(%u) VNI %u - readd",
4149 macaddr
, ifp
->name
, ifp
->ifindex
, vni
);
4150 zebra_evpn_rem_mac_install(zevpn
, mac
, false /* was_static */);
4151 } else if (CHECK_FLAG(mac
->flags
, ZEBRA_MAC_LOCAL
) && mac
->es
4152 && zebra_evpn_es_local_mac_via_network_port(mac
->es
)) {
4153 /* If local entry via nw-port call local-del which will
4154 * re-install entry in the dataplane is needed
4156 if (IS_ZEBRA_DEBUG_VXLAN
|| IS_ZEBRA_DEBUG_EVPN_MH_MAC
)
4157 zlog_debug("dpDel local-nw-MAC %pEA VNI %u", macaddr
,
4160 zebra_evpn_del_local_mac(zevpn
, mac
, false);
4167 * Handle local MAC delete (on a port or VLAN corresponding to this VNI).
4169 int zebra_vxlan_local_mac_del(struct interface
*ifp
, struct interface
*br_if
,
4170 struct ethaddr
*macaddr
, vlanid_t vid
)
4172 struct zebra_evpn
*zevpn
;
4173 struct zebra_mac
*mac
;
4175 /* We are interested in MACs only on ports or (port, VLAN) that
4178 zevpn
= zebra_evpn_map_vlan(ifp
, br_if
, vid
);
4181 if (!zevpn
->vxlan_if
) {
4183 "VNI %u hash %p doesn't have intf upon local MAC DEL",
4188 /* If entry doesn't exist, nothing to do. */
4189 mac
= zebra_evpn_mac_lookup(zevpn
, macaddr
);
4193 /* Is it a local entry? */
4194 if (!CHECK_FLAG(mac
->flags
, ZEBRA_MAC_LOCAL
))
4197 return zebra_evpn_del_local_mac(zevpn
, mac
, false);
4201 * Handle local MAC add (on a port or VLAN corresponding to this VNI).
4203 int zebra_vxlan_local_mac_add_update(struct interface
*ifp
,
4204 struct interface
*br_if
,
4205 struct ethaddr
*macaddr
, vlanid_t vid
,
4206 bool sticky
, bool local_inactive
,
4209 struct zebra_evpn
*zevpn
;
4210 struct zebra_vrf
*zvrf
;
4214 /* We are interested in MACs only on ports or (port, VLAN) that
4217 zevpn
= zebra_evpn_map_vlan(ifp
, br_if
, vid
);
4219 if (IS_ZEBRA_DEBUG_VXLAN
)
4221 " Add/Update %sMAC %pEA intf %s(%u) VID %u, could not find EVPN",
4222 sticky
? "sticky " : "", macaddr
,
4223 ifp
->name
, ifp
->ifindex
, vid
);
4227 if (!zevpn
->vxlan_if
) {
4228 if (IS_ZEBRA_DEBUG_VXLAN
)
4230 " VNI %u hash %p doesn't have intf upon local MAC ADD",
4235 zvrf
= zebra_vrf_get_evpn();
4236 return zebra_evpn_add_update_local_mac(zvrf
, zevpn
, ifp
, macaddr
, vid
,
4237 sticky
, local_inactive
,
4242 * Handle message from client to delete a remote VTEP for an EVPN.
4244 void zebra_vxlan_remote_vtep_del_zapi(ZAPI_HANDLER_ARGS
)
4247 unsigned short l
= 0;
4249 struct in_addr vtep_ip
;
4251 if (!is_evpn_enabled()) {
4253 "%s: EVPN is not enabled yet we have received a VTEP DEL msg",
4258 if (!EVPN_ENABLED(zvrf
)) {
4259 zlog_debug("Recv VTEP DEL zapi for non-EVPN VRF %u",
4266 while (l
< hdr
->length
) {
4267 int flood_control
__attribute__((unused
));
4269 /* Obtain each remote VTEP and process. */
4270 STREAM_GETL(s
, vni
);
4272 STREAM_GET(&vtep_ip
.s_addr
, s
, IPV4_MAX_BYTELEN
);
4273 l
+= IPV4_MAX_BYTELEN
;
4275 /* Flood control is intentionally ignored right now */
4276 STREAM_GETL(s
, flood_control
);
4279 if (IS_ZEBRA_DEBUG_VXLAN
)
4280 zlog_debug("Recv VTEP DEL %pI4 VNI %u from %s",
4282 zebra_route_string(client
->proto
));
4284 /* Enqueue for processing */
4285 zebra_rib_queue_evpn_rem_vtep_del(zvrf_id(zvrf
), vni
, vtep_ip
);
4293 * Handle message from client to delete a remote VTEP for an EVPN.
4295 void zebra_vxlan_remote_vtep_del(vrf_id_t vrf_id
, vni_t vni
,
4296 struct in_addr vtep_ip
)
4298 struct zebra_evpn
*zevpn
;
4299 struct zebra_vtep
*zvtep
;
4300 struct interface
*ifp
;
4301 struct zebra_if
*zif
;
4302 struct zebra_vrf
*zvrf
;
4304 if (!is_evpn_enabled()) {
4305 zlog_debug("%s: Can't process vtep del: EVPN is not enabled",
4310 zvrf
= zebra_vrf_lookup_by_id(vrf_id
);
4314 if (!EVPN_ENABLED(zvrf
)) {
4315 zlog_debug("Can't process VTEP DEL for non-EVPN VRF %u",
4320 /* Locate VNI hash entry - expected to exist. */
4321 zevpn
= zebra_evpn_lookup(vni
);
4323 if (IS_ZEBRA_DEBUG_VXLAN
)
4325 "Failed to locate VNI hash for remote VTEP DEL, VNI %u",
4330 ifp
= zevpn
->vxlan_if
;
4333 "VNI %u hash %p doesn't have intf upon remote VTEP DEL",
4339 /* If down or not mapped to a bridge, we're done. */
4340 if (!if_is_operative(ifp
) || !zif
->brslave_info
.br_if
)
4343 /* If the remote VTEP does not exist, there's nothing more to
4345 * Otherwise, uninstall any remote MACs pointing to this VTEP
4346 * and then, the VTEP entry itself and remove it.
4348 zvtep
= zebra_evpn_vtep_find(zevpn
, &vtep_ip
);
4352 zebra_evpn_vtep_uninstall(zevpn
, &vtep_ip
);
4353 zebra_evpn_vtep_del(zevpn
, zvtep
);
4357 * Handle message from client to add a remote VTEP for an EVPN.
4359 void zebra_vxlan_remote_vtep_add(vrf_id_t vrf_id
, vni_t vni
,
4360 struct in_addr vtep_ip
, int flood_control
)
4362 struct zebra_evpn
*zevpn
;
4363 struct interface
*ifp
;
4364 struct zebra_if
*zif
;
4365 struct zebra_vtep
*zvtep
;
4366 struct zebra_vrf
*zvrf
;
4368 if (!is_evpn_enabled()) {
4369 zlog_debug("%s: EVPN not enabled: can't process a VTEP ADD",
4374 zvrf
= zebra_vrf_lookup_by_id(vrf_id
);
4378 if (!EVPN_ENABLED(zvrf
)) {
4379 zlog_debug("Can't process VTEP ADD for non-EVPN VRF %u",
4384 /* Locate VNI hash entry - expected to exist. */
4385 zevpn
= zebra_evpn_lookup(vni
);
4388 EC_ZEBRA_VTEP_ADD_FAILED
,
4389 "Failed to locate EVPN hash upon remote VTEP ADD, VNI %u",
4394 ifp
= zevpn
->vxlan_if
;
4397 EC_ZEBRA_VTEP_ADD_FAILED
,
4398 "VNI %u hash %p doesn't have intf upon remote VTEP ADD",
4405 /* If down or not mapped to a bridge, we're done. */
4406 if (!if_is_operative(ifp
) || !zif
->brslave_info
.br_if
)
4409 zvtep
= zebra_evpn_vtep_find(zevpn
, &vtep_ip
);
4411 /* If the remote VTEP already exists check if
4412 * the flood mode has changed
4414 if (zvtep
->flood_control
!= flood_control
) {
4415 if (zvtep
->flood_control
== VXLAN_FLOOD_DISABLED
)
4416 /* old mode was head-end-replication but
4417 * is no longer; get rid of the HER fdb
4418 * entry installed before
4420 zebra_evpn_vtep_uninstall(zevpn
, &vtep_ip
);
4421 zvtep
->flood_control
= flood_control
;
4422 zebra_evpn_vtep_install(zevpn
, zvtep
);
4425 zvtep
= zebra_evpn_vtep_add(zevpn
, &vtep_ip
, flood_control
);
4427 zebra_evpn_vtep_install(zevpn
, zvtep
);
4429 flog_err(EC_ZEBRA_VTEP_ADD_FAILED
,
4430 "Failed to add remote VTEP, VNI %u zevpn %p",
4436 * Handle message from client to add a remote VTEP for an EVPN.
4438 void zebra_vxlan_remote_vtep_add_zapi(ZAPI_HANDLER_ARGS
)
4441 unsigned short l
= 0;
4443 struct in_addr vtep_ip
;
4446 if (!is_evpn_enabled()) {
4448 "%s: EVPN not enabled yet we received a VTEP ADD zapi msg",
4453 if (!EVPN_ENABLED(zvrf
)) {
4454 zlog_debug("Recv VTEP ADD zapi for non-EVPN VRF %u",
4461 while (l
< hdr
->length
) {
4462 /* Obtain each remote VTEP and process. */
4463 STREAM_GETL(s
, vni
);
4465 STREAM_GET(&vtep_ip
.s_addr
, s
, IPV4_MAX_BYTELEN
);
4466 STREAM_GETL(s
, flood_control
);
4467 l
+= IPV4_MAX_BYTELEN
+ 4;
4469 if (IS_ZEBRA_DEBUG_VXLAN
)
4470 zlog_debug("Recv VTEP ADD %pI4 VNI %u flood %d from %s",
4471 &vtep_ip
, vni
, flood_control
,
4472 zebra_route_string(client
->proto
));
4474 /* Enqueue for processing */
4475 zebra_rib_queue_evpn_rem_vtep_add(zvrf_id(zvrf
), vni
, vtep_ip
,
4484 * Add/Del gateway macip to evpn
4486 * 1. SVI interface on a vlan aware bridge
4487 * 2. SVI interface on a vlan unaware bridge
4488 * 3. vrr interface (MACVLAN) associated to a SVI
4489 * We advertise macip routes for an interface if it is associated to VxLan vlan
4491 int zebra_vxlan_add_del_gw_macip(struct interface
*ifp
, const struct prefix
*p
,
4495 struct ethaddr macaddr
;
4496 struct zebra_evpn
*zevpn
= NULL
;
4498 memset(&ip
, 0, sizeof(ip
));
4499 memset(&macaddr
, 0, sizeof(macaddr
));
4501 /* Check if EVPN is enabled. */
4502 if (!is_evpn_enabled())
4505 if (IS_ZEBRA_IF_MACVLAN(ifp
)) {
4506 struct interface
*svi_if
=
4507 NULL
; /* SVI corresponding to the MACVLAN */
4508 struct zebra_if
*ifp_zif
=
4509 NULL
; /* Zebra daemon specific info for MACVLAN */
4510 struct zebra_if
*svi_if_zif
=
4511 NULL
; /* Zebra daemon specific info for SVI*/
4513 ifp_zif
= ifp
->info
;
4518 * for a MACVLAN interface the link represents the svi_if
4520 svi_if
= if_lookup_by_index_per_ns(zebra_ns_lookup(NS_DEFAULT
),
4521 ifp_zif
->link_ifindex
);
4523 zlog_debug("MACVLAN %s(%u) without link information",
4524 ifp
->name
, ifp
->ifindex
);
4528 if (IS_ZEBRA_IF_VLAN(svi_if
)) {
4530 * If it is a vlan aware bridge then the link gives the
4531 * bridge information
4533 struct interface
*svi_if_link
= NULL
;
4535 svi_if_zif
= svi_if
->info
;
4537 svi_if_link
= if_lookup_by_index_per_ns(
4538 zebra_ns_lookup(NS_DEFAULT
),
4539 svi_if_zif
->link_ifindex
);
4540 zevpn
= zebra_evpn_from_svi(svi_if
,
4543 } else if (IS_ZEBRA_IF_BRIDGE(svi_if
)) {
4545 * If it is a vlan unaware bridge then svi is the bridge
4548 zevpn
= zebra_evpn_from_svi(svi_if
, svi_if
);
4550 } else if (IS_ZEBRA_IF_VLAN(ifp
)) {
4551 struct zebra_if
*svi_if_zif
=
4552 NULL
; /* Zebra daemon specific info for SVI */
4553 struct interface
*svi_if_link
=
4554 NULL
; /* link info for the SVI = bridge info */
4556 svi_if_zif
= ifp
->info
;
4558 svi_if_link
= if_lookup_by_index_per_ns(
4559 zebra_ns_lookup(NS_DEFAULT
),
4560 svi_if_zif
->link_ifindex
);
4562 zevpn
= zebra_evpn_from_svi(ifp
, svi_if_link
);
4564 } else if (IS_ZEBRA_IF_BRIDGE(ifp
)) {
4565 zevpn
= zebra_evpn_from_svi(ifp
, ifp
);
4571 if (!zevpn
->vxlan_if
) {
4572 zlog_debug("VNI %u hash %p doesn't have intf upon MACVLAN up",
4577 /* VRR IP is advertised only if gw-macip-adv-enabled */
4578 if (IS_ZEBRA_IF_MACVLAN(ifp
)) {
4579 if (!advertise_gw_macip_enabled(zevpn
))
4582 /* SVI IP is advertised if gw or svi macip-adv-enabled */
4583 if (!advertise_svi_macip_enabled(zevpn
)
4584 && !advertise_gw_macip_enabled(zevpn
))
4588 memcpy(&macaddr
.octet
, ifp
->hw_addr
, ETH_ALEN
);
4590 if (p
->family
== AF_INET
) {
4591 ip
.ipa_type
= IPADDR_V4
;
4592 memcpy(&(ip
.ipaddr_v4
), &(p
->u
.prefix4
),
4593 sizeof(struct in_addr
));
4594 } else if (p
->family
== AF_INET6
) {
4595 ip
.ipa_type
= IPADDR_V6
;
4596 memcpy(&(ip
.ipaddr_v6
), &(p
->u
.prefix6
),
4597 sizeof(struct in6_addr
));
4602 zebra_evpn_gw_macip_add(ifp
, zevpn
, &macaddr
, &ip
);
4604 zebra_evpn_gw_macip_del(ifp
, zevpn
, &ip
);
4610 * Handle SVI interface going down.
4611 * SVI can be associated to either L3-VNI or L2-VNI.
4612 * For L2-VNI: At this point, this is a NOP since
4613 * the kernel deletes the neighbor entries on this SVI (if any).
4614 * We only need to update the vrf corresponding to zevpn.
4615 * For L3-VNI: L3-VNI is operationally down, update mac-ip routes and delete
4618 int zebra_vxlan_svi_down(struct interface
*ifp
, struct interface
*link_if
)
4620 struct zebra_l3vni
*zl3vni
= NULL
;
4622 zl3vni
= zl3vni_from_svi(ifp
, link_if
);
4625 /* process l3-vni down */
4626 zebra_vxlan_process_l3vni_oper_down(zl3vni
);
4628 /* remove association with svi-if */
4629 zl3vni
->svi_if
= NULL
;
4631 struct zebra_evpn
*zevpn
= NULL
;
4633 /* Unlink the SVI from the access VLAN */
4634 zebra_evpn_acc_bd_svi_set(ifp
->info
, link_if
->info
, false);
4636 /* since we dont have svi corresponding to zevpn, we associate it
4637 * to default vrf. Note: the corresponding neigh entries on the
4638 * SVI would have already been deleted */
4639 zevpn
= zebra_evpn_from_svi(ifp
, link_if
);
4642 /* remove from l3-vni list */
4643 zl3vni
= zl3vni_from_vrf(zevpn
->vrf_id
);
4645 listnode_delete(zl3vni
->l2vnis
, zevpn
);
4647 zevpn
->svi_if
= NULL
;
4648 zevpn
->vrf_id
= VRF_DEFAULT
;
4650 /* update the tenant vrf in BGP */
4651 if (if_is_operative(zevpn
->vxlan_if
))
4652 zebra_evpn_send_add_to_client(zevpn
);
4659 * Handle SVI interface coming up.
4660 * SVI can be associated to L3-VNI (l3vni vxlan interface) or L2-VNI (l2-vni
4662 * For L2-VNI: we need to install any remote neighbors entried (used for
4664 * For L3-VNI: SVI will be used to get the rmac to be used with L3-VNI
4666 int zebra_vxlan_svi_up(struct interface
*ifp
, struct interface
*link_if
)
4668 struct zebra_evpn
*zevpn
= NULL
;
4669 struct zebra_l3vni
*zl3vni
= NULL
;
4671 zl3vni
= zl3vni_from_svi(ifp
, link_if
);
4674 /* associate with svi */
4675 zl3vni
->svi_if
= ifp
;
4677 /* process oper-up */
4678 if (is_l3vni_oper_up(zl3vni
))
4679 zebra_vxlan_process_l3vni_oper_up(zl3vni
);
4682 /* process SVI up for l2-vni */
4683 struct neigh_walk_ctx n_wctx
;
4685 zevpn
= zebra_evpn_from_svi(ifp
, link_if
);
4689 if (!zevpn
->vxlan_if
) {
4691 "VNI %u hash %p doesn't have intf upon SVI up",
4696 if (IS_ZEBRA_DEBUG_VXLAN
)
4698 "SVI %s(%u) VNI %u VRF %s is UP, installing neighbors",
4699 ifp
->name
, ifp
->ifindex
, zevpn
->vni
,
4702 /* update the vrf information for l2-vni and inform bgp */
4703 zevpn
->svi_if
= ifp
;
4704 zevpn
->vrf_id
= ifp
->vrf
->vrf_id
;
4706 zl3vni
= zl3vni_from_vrf(zevpn
->vrf_id
);
4708 listnode_add_sort_nodup(zl3vni
->l2vnis
, zevpn
);
4710 if (if_is_operative(zevpn
->vxlan_if
))
4711 zebra_evpn_send_add_to_client(zevpn
);
4713 /* Install any remote neighbors for this VNI. */
4714 memset(&n_wctx
, 0, sizeof(n_wctx
));
4715 n_wctx
.zevpn
= zevpn
;
4716 hash_iterate(zevpn
->neigh_table
, zebra_evpn_install_neigh_hash
,
4719 /* Link the SVI from the access VLAN */
4720 zebra_evpn_acc_bd_svi_set(ifp
->info
, link_if
->info
, true);
4722 /* Update MACIP routes created by advertise-svi-ip */
4723 if (advertise_svi_macip_enabled(zevpn
)) {
4724 zebra_evpn_del_macip_for_intf(ifp
, zevpn
);
4725 zebra_evpn_add_macip_for_intf(ifp
, zevpn
);
4733 * Handle MAC-VLAN interface going down.
4734 * L3VNI: When MAC-VLAN interface goes down,
4735 * find its associated SVI and update type2/type-5 routes
4738 void zebra_vxlan_macvlan_down(struct interface
*ifp
)
4740 struct zebra_l3vni
*zl3vni
= NULL
;
4741 struct zebra_if
*zif
, *link_zif
;
4742 struct interface
*link_ifp
, *link_if
;
4746 link_ifp
= zif
->link
;
4748 if (IS_ZEBRA_DEBUG_VXLAN
)
4750 "macvlan parent link is not found. Parent index %d ifp %s",
4752 ifindex2ifname(zif
->link_ifindex
,
4756 link_zif
= link_ifp
->info
;
4759 link_if
= if_lookup_by_index_per_ns(zebra_ns_lookup(NS_DEFAULT
),
4760 link_zif
->link_ifindex
);
4762 zl3vni
= zl3vni_from_svi(link_ifp
, link_if
);
4764 zl3vni
->mac_vlan_if
= NULL
;
4765 if (is_l3vni_oper_up(zl3vni
))
4766 zebra_vxlan_process_l3vni_oper_up(zl3vni
);
4771 * Handle MAC-VLAN interface going up.
4772 * L3VNI: When MAC-VLAN interface comes up,
4773 * find its associated SVI and update type-2 routes
4774 * with MAC-VLAN's MAC as RMAC and for type-5 routes
4775 * use SVI's MAC as RMAC.
4777 void zebra_vxlan_macvlan_up(struct interface
*ifp
)
4779 struct zebra_l3vni
*zl3vni
= NULL
;
4780 struct zebra_if
*zif
, *link_zif
;
4781 struct interface
*link_ifp
, *link_if
;
4785 link_ifp
= zif
->link
;
4786 link_zif
= link_ifp
->info
;
4789 link_if
= if_lookup_by_index_per_ns(zebra_ns_lookup(NS_DEFAULT
),
4790 link_zif
->link_ifindex
);
4791 zl3vni
= zl3vni_from_svi(link_ifp
, link_if
);
4793 /* associate with macvlan (VRR) interface */
4794 zl3vni
->mac_vlan_if
= ifp
;
4796 /* process oper-up */
4797 if (is_l3vni_oper_up(zl3vni
))
4798 zebra_vxlan_process_l3vni_oper_up(zl3vni
);
4803 * Handle VxLAN interface down
4805 int zebra_vxlan_if_down(struct interface
*ifp
)
4808 struct zebra_if
*zif
= NULL
;
4809 struct zebra_l2info_vxlan
*vxl
= NULL
;
4810 struct zebra_l3vni
*zl3vni
= NULL
;
4811 struct zebra_evpn
*zevpn
;
4813 /* Check if EVPN is enabled. */
4814 if (!is_evpn_enabled())
4819 vxl
= &zif
->l2info
.vxl
;
4822 zl3vni
= zl3vni_lookup(vni
);
4824 /* process-if-down for l3-vni */
4825 if (IS_ZEBRA_DEBUG_VXLAN
)
4826 zlog_debug("Intf %s(%u) L3-VNI %u is DOWN", ifp
->name
,
4829 zebra_vxlan_process_l3vni_oper_down(zl3vni
);
4831 /* process if-down for l2-vni */
4832 if (IS_ZEBRA_DEBUG_VXLAN
)
4833 zlog_debug("Intf %s(%u) L2-VNI %u is DOWN", ifp
->name
,
4836 /* Locate hash entry; it is expected to exist. */
4837 zevpn
= zebra_evpn_lookup(vni
);
4840 "Failed to locate VNI hash at DOWN, IF %s(%u) VNI %u",
4841 ifp
->name
, ifp
->ifindex
, vni
);
4845 assert(zevpn
->vxlan_if
== ifp
);
4847 /* remove from l3-vni list */
4848 zl3vni
= zl3vni_from_vrf(zevpn
->vrf_id
);
4850 listnode_delete(zl3vni
->l2vnis
, zevpn
);
4852 /* Delete this VNI from BGP. */
4853 zebra_evpn_send_del_to_client(zevpn
);
4855 /* Free up all neighbors and MACs, if any. */
4856 zebra_evpn_neigh_del_all(zevpn
, 1, 0, DEL_ALL_NEIGH
);
4857 zebra_evpn_mac_del_all(zevpn
, 1, 0, DEL_ALL_MAC
);
4859 /* Free up all remote VTEPs, if any. */
4860 zebra_evpn_vtep_del_all(zevpn
, 1);
4866 * Handle VxLAN interface up - update BGP if required.
4868 int zebra_vxlan_if_up(struct interface
*ifp
)
4871 struct zebra_if
*zif
= NULL
;
4872 struct zebra_l2info_vxlan
*vxl
= NULL
;
4873 struct zebra_evpn
*zevpn
= NULL
;
4874 struct zebra_l3vni
*zl3vni
= NULL
;
4876 /* Check if EVPN is enabled. */
4877 if (!is_evpn_enabled())
4882 vxl
= &zif
->l2info
.vxl
;
4885 zl3vni
= zl3vni_lookup(vni
);
4887 /* we need to associate with SVI, if any, we can associate with
4888 * svi-if only after association with vxlan-intf is complete
4890 zl3vni
->svi_if
= zl3vni_map_to_svi_if(zl3vni
);
4891 zl3vni
->mac_vlan_if
= zl3vni_map_to_mac_vlan_if(zl3vni
);
4893 if (IS_ZEBRA_DEBUG_VXLAN
)
4894 zlog_debug("Intf %s(%u) L3-VNI %u is UP svi_if %s mac_vlan_if %s"
4895 , ifp
->name
, ifp
->ifindex
, vni
,
4896 zl3vni
->svi_if
? zl3vni
->svi_if
->name
: "NIL",
4897 zl3vni
->mac_vlan_if
?
4898 zl3vni
->mac_vlan_if
->name
: "NIL");
4900 if (is_l3vni_oper_up(zl3vni
))
4901 zebra_vxlan_process_l3vni_oper_up(zl3vni
);
4903 /* Handle L2-VNI add */
4904 struct interface
*vlan_if
= NULL
;
4906 if (IS_ZEBRA_DEBUG_VXLAN
)
4907 zlog_debug("Intf %s(%u) L2-VNI %u is UP", ifp
->name
,
4910 /* Locate hash entry; it is expected to exist. */
4911 zevpn
= zebra_evpn_lookup(vni
);
4914 "Failed to locate EVPN hash at UP, IF %s(%u) VNI %u",
4915 ifp
->name
, ifp
->ifindex
, vni
);
4919 assert(zevpn
->vxlan_if
== ifp
);
4920 vlan_if
= zvni_map_to_svi(vxl
->access_vlan
,
4921 zif
->brslave_info
.br_if
);
4923 zevpn
->svi_if
= vlan_if
;
4924 zevpn
->vrf_id
= vlan_if
->vrf
->vrf_id
;
4925 zl3vni
= zl3vni_from_vrf(vlan_if
->vrf
->vrf_id
);
4927 listnode_add_sort_nodup(zl3vni
->l2vnis
, zevpn
);
4930 /* If part of a bridge, inform BGP about this VNI. */
4931 /* Also, read and populate local MACs and neighbors. */
4932 if (zif
->brslave_info
.br_if
) {
4933 zebra_evpn_send_add_to_client(zevpn
);
4934 zebra_evpn_read_mac_neigh(zevpn
, ifp
);
4942 * Handle VxLAN interface delete. Locate and remove entry in hash table
4943 * and update BGP, if required.
4945 int zebra_vxlan_if_del(struct interface
*ifp
)
4948 struct zebra_if
*zif
= NULL
;
4949 struct zebra_l2info_vxlan
*vxl
= NULL
;
4950 struct zebra_evpn
*zevpn
= NULL
;
4951 struct zebra_l3vni
*zl3vni
= NULL
;
4953 /* Check if EVPN is enabled. */
4954 if (!is_evpn_enabled())
4959 vxl
= &zif
->l2info
.vxl
;
4962 zl3vni
= zl3vni_lookup(vni
);
4965 if (IS_ZEBRA_DEBUG_VXLAN
)
4966 zlog_debug("Del L3-VNI %u intf %s(%u)", vni
, ifp
->name
,
4969 /* process oper-down for l3-vni */
4970 zebra_vxlan_process_l3vni_oper_down(zl3vni
);
4972 /* remove the association with vxlan_if */
4973 memset(&zl3vni
->local_vtep_ip
, 0, sizeof(struct in_addr
));
4974 zl3vni
->vxlan_if
= NULL
;
4977 /* process if-del for l2-vni*/
4978 if (IS_ZEBRA_DEBUG_VXLAN
)
4979 zlog_debug("Del L2-VNI %u intf %s(%u)", vni
, ifp
->name
,
4982 /* Locate hash entry; it is expected to exist. */
4983 zevpn
= zebra_evpn_lookup(vni
);
4986 "Failed to locate VNI hash at del, IF %s(%u) VNI %u",
4987 ifp
->name
, ifp
->ifindex
, vni
);
4991 /* remove from l3-vni list */
4992 zl3vni
= zl3vni_from_vrf(zevpn
->vrf_id
);
4994 listnode_delete(zl3vni
->l2vnis
, zevpn
);
4995 /* Delete VNI from BGP. */
4996 zebra_evpn_send_del_to_client(zevpn
);
4998 /* Free up all neighbors and MAC, if any. */
4999 zebra_evpn_neigh_del_all(zevpn
, 0, 0, DEL_ALL_NEIGH
);
5000 zebra_evpn_mac_del_all(zevpn
, 0, 0, DEL_ALL_MAC
);
5002 /* Free up all remote VTEPs, if any. */
5003 zebra_evpn_vtep_del_all(zevpn
, 0);
5005 /* Delete the hash entry. */
5006 if (zebra_evpn_vxlan_del(zevpn
)) {
5007 flog_err(EC_ZEBRA_VNI_DEL_FAILED
,
5008 "Failed to del EVPN hash %p, IF %s(%u) VNI %u",
5009 zevpn
, ifp
->name
, ifp
->ifindex
, zevpn
->vni
);
5017 * Handle VxLAN interface update - change to tunnel IP, master or VLAN.
5019 int zebra_vxlan_if_update(struct interface
*ifp
, uint16_t chgflags
)
5022 struct zebra_if
*zif
= NULL
;
5023 struct zebra_l2info_vxlan
*vxl
= NULL
;
5024 struct zebra_evpn
*zevpn
= NULL
;
5025 struct zebra_l3vni
*zl3vni
= NULL
;
5026 struct interface
*vlan_if
= NULL
;
5028 /* Check if EVPN is enabled. */
5029 if (!is_evpn_enabled())
5034 vxl
= &zif
->l2info
.vxl
;
5037 zl3vni
= zl3vni_lookup(vni
);
5040 if (IS_ZEBRA_DEBUG_VXLAN
)
5042 "Update L3-VNI %u intf %s(%u) VLAN %u local IP %pI4 master %u chg 0x%x",
5043 vni
, ifp
->name
, ifp
->ifindex
, vxl
->access_vlan
,
5045 zif
->brslave_info
.bridge_ifindex
, chgflags
);
5047 /* Removed from bridge? Cleanup and return */
5048 if ((chgflags
& ZEBRA_VXLIF_MASTER_CHANGE
)
5049 && (zif
->brslave_info
.bridge_ifindex
== IFINDEX_INTERNAL
)) {
5050 zebra_vxlan_process_l3vni_oper_down(zl3vni
);
5054 if ((chgflags
& ZEBRA_VXLIF_MASTER_MAC_CHANGE
)
5055 && if_is_operative(ifp
) && is_l3vni_oper_up(zl3vni
)) {
5056 zebra_vxlan_process_l3vni_oper_down(zl3vni
);
5057 zebra_vxlan_process_l3vni_oper_up(zl3vni
);
5061 /* access-vlan change - process oper down, associate with new
5062 * svi_if and then process oper up again
5064 if (chgflags
& ZEBRA_VXLIF_VLAN_CHANGE
) {
5065 if (if_is_operative(ifp
)) {
5066 zebra_vxlan_process_l3vni_oper_down(zl3vni
);
5067 zl3vni
->svi_if
= NULL
;
5068 zl3vni
->svi_if
= zl3vni_map_to_svi_if(zl3vni
);
5069 zl3vni
->mac_vlan_if
=
5070 zl3vni_map_to_mac_vlan_if(zl3vni
);
5071 zl3vni
->local_vtep_ip
= vxl
->vtep_ip
;
5072 if (is_l3vni_oper_up(zl3vni
))
5073 zebra_vxlan_process_l3vni_oper_up(
5079 * local-ip change - process oper down, associate with new
5080 * local-ip and then process oper up again
5082 if (chgflags
& ZEBRA_VXLIF_LOCAL_IP_CHANGE
) {
5083 if (if_is_operative(ifp
)) {
5084 zebra_vxlan_process_l3vni_oper_down(zl3vni
);
5085 zl3vni
->local_vtep_ip
= vxl
->vtep_ip
;
5086 if (is_l3vni_oper_up(zl3vni
))
5087 zebra_vxlan_process_l3vni_oper_up(
5092 /* Update local tunnel IP. */
5093 zl3vni
->local_vtep_ip
= vxl
->vtep_ip
;
5095 /* if we have a valid new master, process l3-vni oper up */
5096 if (chgflags
& ZEBRA_VXLIF_MASTER_CHANGE
) {
5097 if (if_is_operative(ifp
) && is_l3vni_oper_up(zl3vni
))
5098 zebra_vxlan_process_l3vni_oper_up(zl3vni
);
5102 /* Update VNI hash. */
5103 zevpn
= zebra_evpn_lookup(vni
);
5106 "Failed to find EVPN hash on update, IF %s(%u) VNI %u",
5107 ifp
->name
, ifp
->ifindex
, vni
);
5111 if (IS_ZEBRA_DEBUG_VXLAN
)
5113 "Update L2-VNI %u intf %s(%u) VLAN %u local IP %pI4 master %u chg 0x%x",
5114 vni
, ifp
->name
, ifp
->ifindex
, vxl
->access_vlan
,
5116 zif
->brslave_info
.bridge_ifindex
, chgflags
);
5118 /* Removed from bridge? Cleanup and return */
5119 if ((chgflags
& ZEBRA_VXLIF_MASTER_CHANGE
)
5120 && (zif
->brslave_info
.bridge_ifindex
== IFINDEX_INTERNAL
)) {
5121 /* Delete from client, remove all remote VTEPs */
5122 /* Also, free up all MACs and neighbors. */
5123 zevpn
->svi_if
= NULL
;
5124 zebra_evpn_send_del_to_client(zevpn
);
5125 zebra_evpn_neigh_del_all(zevpn
, 1, 0, DEL_ALL_NEIGH
);
5126 zebra_evpn_mac_del_all(zevpn
, 1, 0, DEL_ALL_MAC
);
5127 zebra_evpn_vtep_del_all(zevpn
, 1);
5131 /* Handle other changes. */
5132 if (chgflags
& ZEBRA_VXLIF_VLAN_CHANGE
) {
5133 /* Remove all existing local neigh and MACs for this VNI
5134 * (including from BGP)
5136 zebra_evpn_neigh_del_all(zevpn
, 0, 1, DEL_LOCAL_MAC
);
5137 zebra_evpn_mac_del_all(zevpn
, 0, 1, DEL_LOCAL_MAC
);
5140 if (zevpn
->local_vtep_ip
.s_addr
!= vxl
->vtep_ip
.s_addr
||
5141 zevpn
->mcast_grp
.s_addr
!= vxl
->mcast_grp
.s_addr
) {
5142 zebra_vxlan_sg_deref(zevpn
->local_vtep_ip
,
5144 zebra_vxlan_sg_ref(vxl
->vtep_ip
, vxl
->mcast_grp
);
5145 zevpn
->local_vtep_ip
= vxl
->vtep_ip
;
5146 zevpn
->mcast_grp
= vxl
->mcast_grp
;
5147 /* on local vtep-ip check if ES orig-ip
5148 * needs to be updated
5150 zebra_evpn_es_set_base_evpn(zevpn
);
5152 zevpn_vxlan_if_set(zevpn
, ifp
, true /* set */);
5153 vlan_if
= zvni_map_to_svi(vxl
->access_vlan
,
5154 zif
->brslave_info
.br_if
);
5156 zevpn
->svi_if
= vlan_if
;
5157 zevpn
->vrf_id
= vlan_if
->vrf
->vrf_id
;
5158 zl3vni
= zl3vni_from_vrf(vlan_if
->vrf
->vrf_id
);
5160 listnode_add_sort_nodup(zl3vni
->l2vnis
, zevpn
);
5163 /* Take further actions needed.
5164 * Note that if we are here, there is a change of interest.
5166 /* If down or not mapped to a bridge, we're done. */
5167 if (!if_is_operative(ifp
) || !zif
->brslave_info
.br_if
)
5170 /* Inform BGP, if there is a change of interest. */
5172 (ZEBRA_VXLIF_MASTER_CHANGE
| ZEBRA_VXLIF_LOCAL_IP_CHANGE
|
5173 ZEBRA_VXLIF_MCAST_GRP_CHANGE
| ZEBRA_VXLIF_VLAN_CHANGE
))
5174 zebra_evpn_send_add_to_client(zevpn
);
5176 /* If there is a valid new master or a VLAN mapping change,
5177 * read and populate local MACs and neighbors.
5178 * Also, reinstall any remote MACs and neighbors
5179 * for this VNI (based on new VLAN).
5181 if (chgflags
& ZEBRA_VXLIF_MASTER_CHANGE
)
5182 zebra_evpn_read_mac_neigh(zevpn
, ifp
);
5183 else if (chgflags
& ZEBRA_VXLIF_VLAN_CHANGE
) {
5184 struct mac_walk_ctx m_wctx
;
5185 struct neigh_walk_ctx n_wctx
;
5187 zebra_evpn_read_mac_neigh(zevpn
, ifp
);
5189 memset(&m_wctx
, 0, sizeof(m_wctx
));
5190 m_wctx
.zevpn
= zevpn
;
5191 hash_iterate(zevpn
->mac_table
,
5192 zebra_evpn_install_mac_hash
, &m_wctx
);
5194 memset(&n_wctx
, 0, sizeof(n_wctx
));
5195 n_wctx
.zevpn
= zevpn
;
5196 hash_iterate(zevpn
->neigh_table
,
5197 zebra_evpn_install_neigh_hash
, &n_wctx
);
5205 * Handle VxLAN interface add.
5207 int zebra_vxlan_if_add(struct interface
*ifp
)
5210 struct zebra_if
*zif
= NULL
;
5211 struct zebra_l2info_vxlan
*vxl
= NULL
;
5212 struct zebra_evpn
*zevpn
= NULL
;
5213 struct zebra_l3vni
*zl3vni
= NULL
;
5215 /* Check if EVPN is enabled. */
5216 if (!is_evpn_enabled())
5221 vxl
= &zif
->l2info
.vxl
;
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
, vxl
->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
!= vxl
->mcast_grp
.s_addr
) {
5259 zebra_vxlan_sg_deref(zevpn
->local_vtep_ip
,
5261 zebra_vxlan_sg_ref(vxl
->vtep_ip
, vxl
->mcast_grp
);
5262 zevpn
->local_vtep_ip
= vxl
->vtep_ip
;
5263 zevpn
->mcast_grp
= vxl
->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(vxl
->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
, vxl
->access_vlan
,
5286 &vxl
->vtep_ip
, &vxl
->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 zebra_l2info_vxlan zl2_info
;
5556 struct interface
*vlan_if
= NULL
;
5558 zevpn
= zebra_evpn_lookup(vni
);
5562 if (IS_ZEBRA_DEBUG_VXLAN
)
5564 "EVPN SVI macip Adv %s on VNI %d , currently %s",
5565 advertise
? "enabled" : "disabled", vni
,
5566 advertise_svi_macip_enabled(zevpn
)
5570 if (zevpn
->advertise_svi_macip
== advertise
)
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
;
5578 ifp
= zevpn
->vxlan_if
;
5584 /* If down or not mapped to a bridge, we're done. */
5585 if (!if_is_operative(ifp
) || !zif
->brslave_info
.br_if
)
5588 zl2_info
= zif
->l2info
.vxl
;
5589 vlan_if
= zvni_map_to_svi(zl2_info
.access_vlan
,
5590 zif
->brslave_info
.br_if
);
5595 /* Add primary SVI MAC-IP */
5596 zebra_evpn_add_macip_for_intf(vlan_if
, zevpn
);
5598 /* Del primary SVI MAC-IP */
5599 zebra_evpn_del_macip_for_intf(vlan_if
, zevpn
);
5608 * Handle message from client to enable/disable advertisement of g/w macip
5611 void zebra_vxlan_advertise_subnet(ZAPI_HANDLER_ARGS
)
5616 struct zebra_evpn
*zevpn
= NULL
;
5617 struct interface
*ifp
= NULL
;
5618 struct zebra_if
*zif
= NULL
;
5619 struct zebra_l2info_vxlan zl2_info
;
5620 struct interface
*vlan_if
= NULL
;
5622 if (!EVPN_ENABLED(zvrf
)) {
5623 zlog_debug("EVPN GW-MACIP Adv for non-EVPN VRF %u",
5629 STREAM_GETC(s
, advertise
);
5630 STREAM_GET(&vni
, s
, 3);
5632 zevpn
= zebra_evpn_lookup(vni
);
5636 if (zevpn
->advertise_subnet
== advertise
)
5639 if (IS_ZEBRA_DEBUG_VXLAN
)
5640 zlog_debug("EVPN subnet Adv %s on VNI %d , currently %s",
5641 advertise
? "enabled" : "disabled", vni
,
5642 zevpn
->advertise_subnet
? "enabled" : "disabled");
5645 zevpn
->advertise_subnet
= advertise
;
5647 ifp
= zevpn
->vxlan_if
;
5653 /* If down or not mapped to a bridge, we're done. */
5654 if (!if_is_operative(ifp
) || !zif
->brslave_info
.br_if
)
5657 zl2_info
= zif
->l2info
.vxl
;
5660 zvni_map_to_svi(zl2_info
.access_vlan
, zif
->brslave_info
.br_if
);
5664 if (zevpn
->advertise_subnet
)
5665 zebra_evpn_advertise_subnet(zevpn
, vlan_if
, 1);
5667 zebra_evpn_advertise_subnet(zevpn
, vlan_if
, 0);
5674 * Handle message from client to enable/disable advertisement of g/w macip
5677 void zebra_vxlan_advertise_gw_macip(ZAPI_HANDLER_ARGS
)
5682 struct zebra_evpn
*zevpn
= NULL
;
5683 struct interface
*ifp
= NULL
;
5685 if (!EVPN_ENABLED(zvrf
)) {
5686 zlog_debug("EVPN GW-MACIP Adv for non-EVPN VRF %u",
5692 STREAM_GETC(s
, advertise
);
5693 STREAM_GETL(s
, vni
);
5696 if (IS_ZEBRA_DEBUG_VXLAN
)
5697 zlog_debug("EVPN gateway macip Adv %s, currently %s",
5698 advertise
? "enabled" : "disabled",
5699 advertise_gw_macip_enabled(NULL
)
5703 if (zvrf
->advertise_gw_macip
== advertise
)
5706 zvrf
->advertise_gw_macip
= advertise
;
5708 if (advertise_gw_macip_enabled(zevpn
))
5709 hash_iterate(zvrf
->evpn_table
,
5710 zebra_evpn_gw_macip_add_for_evpn_hash
,
5713 hash_iterate(zvrf
->evpn_table
,
5714 zebra_evpn_gw_macip_del_for_evpn_hash
,
5718 struct zebra_if
*zif
= NULL
;
5719 struct zebra_l2info_vxlan zl2_info
;
5720 struct interface
*vlan_if
= NULL
;
5721 struct interface
*vrr_if
= NULL
;
5723 zevpn
= zebra_evpn_lookup(vni
);
5727 if (IS_ZEBRA_DEBUG_VXLAN
)
5729 "EVPN gateway macip Adv %s on VNI %d , currently %s",
5730 advertise
? "enabled" : "disabled", vni
,
5731 advertise_gw_macip_enabled(zevpn
) ? "enabled"
5734 if (zevpn
->advertise_gw_macip
== advertise
)
5737 zevpn
->advertise_gw_macip
= advertise
;
5739 ifp
= zevpn
->vxlan_if
;
5745 /* If down or not mapped to a bridge, we're done. */
5746 if (!if_is_operative(ifp
) || !zif
->brslave_info
.br_if
)
5749 zl2_info
= zif
->l2info
.vxl
;
5751 vlan_if
= zvni_map_to_svi(zl2_info
.access_vlan
,
5752 zif
->brslave_info
.br_if
);
5756 if (advertise_gw_macip_enabled(zevpn
)) {
5757 /* Add primary SVI MAC-IP */
5758 zebra_evpn_add_macip_for_intf(vlan_if
, zevpn
);
5760 /* Add VRR MAC-IP - if any*/
5761 vrr_if
= zebra_get_vrr_intf_for_svi(vlan_if
);
5763 zebra_evpn_add_macip_for_intf(vrr_if
, zevpn
);
5765 /* Del primary MAC-IP */
5766 zebra_evpn_del_macip_for_intf(vlan_if
, zevpn
);
5768 /* Del VRR MAC-IP - if any*/
5769 vrr_if
= zebra_get_vrr_intf_for_svi(vlan_if
);
5771 zebra_evpn_del_macip_for_intf(vrr_if
, zevpn
);
5779 static int macfdb_read_ns(struct ns
*ns
,
5780 void *_in_param
__attribute__((unused
)),
5781 void **out_param
__attribute__((unused
)))
5783 struct zebra_ns
*zns
= ns
->info
;
5786 return NS_WALK_CONTINUE
;
5789 static int neigh_read_ns(struct ns
*ns
,
5790 void *_in_param
__attribute__((unused
)),
5791 void **out_param
__attribute__((unused
)))
5793 struct zebra_ns
*zns
= ns
->info
;
5796 return NS_WALK_CONTINUE
;
5800 * Handle message from client to learn (or stop learning) about VNIs and MACs.
5801 * When enabled, the VNI hash table will be built and MAC FDB table read;
5802 * when disabled, the entries should be deleted and remote VTEPs and MACs
5803 * uninstalled from the kernel.
5804 * This also informs the setting for BUM handling at the time this change
5805 * occurs; it is relevant only when specifying "learn".
5807 void zebra_vxlan_advertise_all_vni(ZAPI_HANDLER_ARGS
)
5809 struct stream
*s
= NULL
;
5811 enum vxlan_flood_control flood_ctrl
;
5813 /* Mismatch between EVPN VRF and current VRF (should be prevented by
5815 if (is_evpn_enabled() && !EVPN_ENABLED(zvrf
))
5819 STREAM_GETC(s
, advertise
);
5820 STREAM_GETC(s
, flood_ctrl
);
5822 if (IS_ZEBRA_DEBUG_VXLAN
)
5823 zlog_debug("EVPN VRF %s(%u) VNI Adv %s, currently %s, flood control %u",
5824 zvrf_name(zvrf
), zvrf_id(zvrf
),
5825 advertise
? "enabled" : "disabled",
5826 is_evpn_enabled() ? "enabled" : "disabled",
5829 if (zvrf
->advertise_all_vni
== advertise
)
5832 zvrf
->advertise_all_vni
= advertise
;
5833 if (EVPN_ENABLED(zvrf
)) {
5834 zrouter
.evpn_vrf
= zvrf
;
5836 /* Note BUM handling */
5837 zvrf
->vxlan_flood_ctrl
= flood_ctrl
;
5839 /* Replay all ESs */
5840 zebra_evpn_es_send_all_to_client(true /* add */);
5842 /* Build EVPN hash table and inform BGP. */
5843 zevpn_build_hash_table();
5845 /* Add all SVI (L3 GW) MACs to BGP*/
5846 hash_iterate(zvrf
->evpn_table
,
5847 zebra_evpn_gw_macip_add_for_evpn_hash
, NULL
);
5849 /* Read the MAC FDB */
5850 ns_walk_func(macfdb_read_ns
, NULL
, NULL
);
5852 /* Read neighbors */
5853 ns_walk_func(neigh_read_ns
, NULL
, NULL
);
5855 /* Cleanup VTEPs for all EVPNs - uninstall from
5856 * kernel and free entries.
5858 hash_iterate(zvrf
->evpn_table
, zebra_evpn_vxlan_cleanup_all
,
5861 /* Delete all ESs in BGP */
5862 zebra_evpn_es_send_all_to_client(false /* add */);
5864 /* cleanup all l3vnis */
5865 hash_iterate(zrouter
.l3vni_table
, zl3vni_cleanup_all
, NULL
);
5867 /* Mark as "no EVPN VRF" */
5868 zrouter
.evpn_vrf
= NULL
;
5876 * Allocate EVPN hash table for this VRF and do other initialization.
5877 * NOTE: Currently supported only for default VRF.
5879 void zebra_vxlan_init_tables(struct zebra_vrf
*zvrf
)
5886 snprintf(buffer
, sizeof(buffer
), "Zebra VRF EVPN Table: %s",
5888 zvrf
->evpn_table
= hash_create_size(8, zebra_evpn_hash_keymake
,
5889 zebra_evpn_hash_cmp
, buffer
);
5891 snprintf(buffer
, sizeof(buffer
), "Zebra VxLAN SG Table: %s",
5893 zvrf
->vxlan_sg_table
= hash_create_size(8, zebra_vxlan_sg_hash_key_make
,
5894 zebra_vxlan_sg_hash_eq
, buffer
);
5897 /* Cleanup EVPN info, but don't free the table. */
5898 void zebra_vxlan_cleanup_tables(struct zebra_vrf
*zvrf
)
5900 struct zebra_vrf
*evpn_zvrf
= zebra_vrf_get_evpn();
5902 hash_iterate(zvrf
->evpn_table
, zebra_evpn_vxlan_cleanup_all
, zvrf
);
5903 zebra_vxlan_cleanup_sg_table(zvrf
);
5905 if (zvrf
== evpn_zvrf
)
5906 zebra_evpn_es_cleanup();
5909 /* Close all EVPN handling */
5910 void zebra_vxlan_close_tables(struct zebra_vrf
*zvrf
)
5914 hash_iterate(zvrf
->evpn_table
, zebra_evpn_vxlan_cleanup_all
, zvrf
);
5915 hash_free(zvrf
->evpn_table
);
5916 if (zvrf
->vxlan_sg_table
) {
5917 zebra_vxlan_cleanup_sg_table(zvrf
);
5918 hash_free(zvrf
->vxlan_sg_table
);
5919 zvrf
->vxlan_sg_table
= NULL
;
5923 /* init the l3vni table */
5924 void zebra_vxlan_init(void)
5926 zrouter
.l3vni_table
= hash_create(l3vni_hash_keymake
, l3vni_hash_cmp
,
5927 "Zebra VRF L3 VNI table");
5928 zrouter
.evpn_vrf
= NULL
;
5929 zebra_evpn_mh_init();
5932 /* free l3vni table */
5933 void zebra_vxlan_disable(void)
5935 hash_free(zrouter
.l3vni_table
);
5936 zebra_evpn_mh_terminate();
5939 /* get the l3vni svi ifindex */
5940 ifindex_t
get_l3vni_svi_ifindex(vrf_id_t vrf_id
)
5942 struct zebra_l3vni
*zl3vni
= NULL
;
5944 zl3vni
= zl3vni_from_vrf(vrf_id
);
5945 if (!zl3vni
|| !is_l3vni_oper_up(zl3vni
))
5948 return zl3vni
->svi_if
->ifindex
;
5951 /************************** vxlan SG cache management ************************/
5952 /* Inform PIM about the mcast group */
5953 static int zebra_vxlan_sg_send(struct zebra_vrf
*zvrf
,
5954 struct prefix_sg
*sg
,
5955 char *sg_str
, uint16_t cmd
)
5957 struct zserv
*client
= NULL
;
5958 struct stream
*s
= NULL
;
5960 client
= zserv_find_client(ZEBRA_ROUTE_PIM
, 0);
5964 if (!CHECK_FLAG(zvrf
->flags
, ZEBRA_PIM_SEND_VXLAN_SG
))
5967 s
= stream_new(ZEBRA_MAX_PACKET_SIZ
);
5969 zclient_create_header(s
, cmd
, VRF_DEFAULT
);
5970 stream_putl(s
, IPV4_MAX_BYTELEN
);
5971 stream_put(s
, &sg
->src
.s_addr
, IPV4_MAX_BYTELEN
);
5972 stream_put(s
, &sg
->grp
.s_addr
, IPV4_MAX_BYTELEN
);
5974 /* Write packet size. */
5975 stream_putw_at(s
, 0, stream_get_endp(s
));
5977 if (IS_ZEBRA_DEBUG_VXLAN
)
5980 (cmd
== ZEBRA_VXLAN_SG_ADD
) ? "add" : "del", sg_str
,
5981 zebra_route_string(client
->proto
));
5983 if (cmd
== ZEBRA_VXLAN_SG_ADD
)
5984 client
->vxlan_sg_add_cnt
++;
5986 client
->vxlan_sg_del_cnt
++;
5988 return zserv_send_message(client
, s
);
5991 static unsigned int zebra_vxlan_sg_hash_key_make(const void *p
)
5993 const struct zebra_vxlan_sg
*vxlan_sg
= p
;
5995 return (jhash_2words(vxlan_sg
->sg
.src
.s_addr
,
5996 vxlan_sg
->sg
.grp
.s_addr
, 0));
5999 static bool zebra_vxlan_sg_hash_eq(const void *p1
, const void *p2
)
6001 const struct zebra_vxlan_sg
*sg1
= p1
;
6002 const struct zebra_vxlan_sg
*sg2
= p2
;
6004 return ((sg1
->sg
.src
.s_addr
== sg2
->sg
.src
.s_addr
)
6005 && (sg1
->sg
.grp
.s_addr
== sg2
->sg
.grp
.s_addr
));
6008 static struct zebra_vxlan_sg
*zebra_vxlan_sg_new(struct zebra_vrf
*zvrf
,
6009 struct prefix_sg
*sg
)
6011 struct zebra_vxlan_sg
*vxlan_sg
;
6013 vxlan_sg
= XCALLOC(MTYPE_ZVXLAN_SG
, sizeof(*vxlan_sg
));
6015 vxlan_sg
->zvrf
= zvrf
;
6017 prefix_sg2str(sg
, vxlan_sg
->sg_str
);
6019 vxlan_sg
= hash_get(zvrf
->vxlan_sg_table
, vxlan_sg
, hash_alloc_intern
);
6021 if (IS_ZEBRA_DEBUG_VXLAN
)
6022 zlog_debug("vxlan SG %s created", vxlan_sg
->sg_str
);
6027 static struct zebra_vxlan_sg
*zebra_vxlan_sg_find(struct zebra_vrf
*zvrf
,
6028 struct prefix_sg
*sg
)
6030 struct zebra_vxlan_sg lookup
;
6033 return hash_lookup(zvrf
->vxlan_sg_table
, &lookup
);
6036 static struct zebra_vxlan_sg
*zebra_vxlan_sg_add(struct zebra_vrf
*zvrf
,
6037 struct prefix_sg
*sg
)
6039 struct zebra_vxlan_sg
*vxlan_sg
;
6040 struct zebra_vxlan_sg
*parent
= NULL
;
6043 vxlan_sg
= zebra_vxlan_sg_find(zvrf
, sg
);
6047 /* create a *G entry for every BUM group implicitly -
6048 * 1. The SG entry is used by pimd to setup the vxlan-origination-mroute
6049 * 2. the XG entry is used by pimd to setup the
6050 * vxlan-termination-mroute
6052 if (sg
->src
.s_addr
!= INADDR_ANY
) {
6053 memset(&sip
, 0, sizeof(sip
));
6054 parent
= zebra_vxlan_sg_do_ref(zvrf
, sip
, sg
->grp
);
6059 vxlan_sg
= zebra_vxlan_sg_new(zvrf
, sg
);
6061 zebra_vxlan_sg_send(zvrf
, sg
, vxlan_sg
->sg_str
,
6062 ZEBRA_VXLAN_SG_ADD
);
6067 static void zebra_vxlan_sg_del(struct zebra_vxlan_sg
*vxlan_sg
)
6070 struct zebra_vrf
*zvrf
;
6072 zvrf
= vrf_info_lookup(VRF_DEFAULT
);
6076 /* On SG entry deletion remove the reference to its parent XG
6079 if (vxlan_sg
->sg
.src
.s_addr
!= INADDR_ANY
) {
6080 memset(&sip
, 0, sizeof(sip
));
6081 zebra_vxlan_sg_do_deref(zvrf
, sip
, vxlan_sg
->sg
.grp
);
6084 zebra_vxlan_sg_send(zvrf
, &vxlan_sg
->sg
,
6085 vxlan_sg
->sg_str
, ZEBRA_VXLAN_SG_DEL
);
6087 hash_release(vxlan_sg
->zvrf
->vxlan_sg_table
, vxlan_sg
);
6089 if (IS_ZEBRA_DEBUG_VXLAN
)
6090 zlog_debug("VXLAN SG %s deleted", vxlan_sg
->sg_str
);
6092 XFREE(MTYPE_ZVXLAN_SG
, vxlan_sg
);
6095 static void zebra_vxlan_sg_do_deref(struct zebra_vrf
*zvrf
,
6096 struct in_addr sip
, struct in_addr mcast_grp
)
6098 struct zebra_vxlan_sg
*vxlan_sg
;
6099 struct prefix_sg sg
;
6101 sg
.family
= AF_INET
;
6102 sg
.prefixlen
= IPV4_MAX_BYTELEN
;
6105 vxlan_sg
= zebra_vxlan_sg_find(zvrf
, &sg
);
6109 if (vxlan_sg
->ref_cnt
)
6110 --vxlan_sg
->ref_cnt
;
6112 if (!vxlan_sg
->ref_cnt
)
6113 zebra_vxlan_sg_del(vxlan_sg
);
6116 static struct zebra_vxlan_sg
*zebra_vxlan_sg_do_ref(struct zebra_vrf
*zvrf
,
6118 struct in_addr mcast_grp
)
6120 struct zebra_vxlan_sg
*vxlan_sg
;
6121 struct prefix_sg sg
;
6123 sg
.family
= AF_INET
;
6124 sg
.prefixlen
= IPV4_MAX_BYTELEN
;
6127 vxlan_sg
= zebra_vxlan_sg_add(zvrf
, &sg
);
6129 ++vxlan_sg
->ref_cnt
;
6134 static void zebra_vxlan_sg_deref(struct in_addr local_vtep_ip
,
6135 struct in_addr mcast_grp
)
6137 struct zebra_vrf
*zvrf
;
6139 if (local_vtep_ip
.s_addr
== INADDR_ANY
6140 || mcast_grp
.s_addr
== INADDR_ANY
)
6143 zvrf
= vrf_info_lookup(VRF_DEFAULT
);
6147 zebra_vxlan_sg_do_deref(zvrf
, local_vtep_ip
, mcast_grp
);
6150 static void zebra_vxlan_sg_ref(struct in_addr local_vtep_ip
,
6151 struct in_addr mcast_grp
)
6153 struct zebra_vrf
*zvrf
;
6155 if (local_vtep_ip
.s_addr
== INADDR_ANY
6156 || mcast_grp
.s_addr
== INADDR_ANY
)
6159 zvrf
= vrf_info_lookup(VRF_DEFAULT
);
6162 zebra_vxlan_sg_do_ref(zvrf
, local_vtep_ip
, mcast_grp
);
6165 static void zebra_vxlan_xg_pre_cleanup(struct hash_bucket
*bucket
, void *arg
)
6167 struct zebra_vxlan_sg
*vxlan_sg
= (struct zebra_vxlan_sg
*)bucket
->data
;
6169 /* increment the ref count against (*,G) to prevent them from being
6172 if (vxlan_sg
->sg
.src
.s_addr
== INADDR_ANY
)
6173 ++vxlan_sg
->ref_cnt
;
6176 static void zebra_vxlan_xg_post_cleanup(struct hash_bucket
*bucket
, void *arg
)
6178 struct zebra_vxlan_sg
*vxlan_sg
= (struct zebra_vxlan_sg
*)bucket
->data
;
6180 /* decrement the dummy ref count against (*,G) to delete them */
6181 if (vxlan_sg
->sg
.src
.s_addr
== INADDR_ANY
) {
6182 if (vxlan_sg
->ref_cnt
)
6183 --vxlan_sg
->ref_cnt
;
6184 if (!vxlan_sg
->ref_cnt
)
6185 zebra_vxlan_sg_del(vxlan_sg
);
6189 static void zebra_vxlan_sg_cleanup(struct hash_bucket
*bucket
, void *arg
)
6191 struct zebra_vxlan_sg
*vxlan_sg
= (struct zebra_vxlan_sg
*)bucket
->data
;
6193 zebra_vxlan_sg_del(vxlan_sg
);
6196 static void zebra_vxlan_cleanup_sg_table(struct zebra_vrf
*zvrf
)
6198 /* increment the ref count against (*,G) to prevent them from being
6201 hash_iterate(zvrf
->vxlan_sg_table
, zebra_vxlan_xg_pre_cleanup
, NULL
);
6203 hash_iterate(zvrf
->vxlan_sg_table
, zebra_vxlan_sg_cleanup
, NULL
);
6205 /* decrement the dummy ref count against the XG entries */
6206 hash_iterate(zvrf
->vxlan_sg_table
, zebra_vxlan_xg_post_cleanup
, NULL
);
6209 static void zebra_vxlan_sg_replay_send(struct hash_bucket
*bucket
, void *arg
)
6211 struct zebra_vxlan_sg
*vxlan_sg
= (struct zebra_vxlan_sg
*)bucket
->data
;
6213 zebra_vxlan_sg_send(vxlan_sg
->zvrf
, &vxlan_sg
->sg
,
6214 vxlan_sg
->sg_str
, ZEBRA_VXLAN_SG_ADD
);
6217 /* Handle message from client to replay vxlan SG entries */
6218 void zebra_vxlan_sg_replay(ZAPI_HANDLER_ARGS
)
6220 if (IS_ZEBRA_DEBUG_VXLAN
)
6221 zlog_debug("VxLAN SG updates to PIM, start");
6223 SET_FLAG(zvrf
->flags
, ZEBRA_PIM_SEND_VXLAN_SG
);
6225 if (!EVPN_ENABLED(zvrf
)) {
6226 if (IS_ZEBRA_DEBUG_VXLAN
)
6227 zlog_debug("VxLAN SG replay request on unexpected vrf %d",
6232 hash_iterate(zvrf
->vxlan_sg_table
, zebra_vxlan_sg_replay_send
, NULL
);
6236 /* Cleanup EVPN configuration of a specific VRF */
6237 static void zebra_evpn_vrf_cfg_cleanup(struct zebra_vrf
*zvrf
)
6239 struct zebra_l3vni
*zl3vni
= NULL
;
6241 zvrf
->advertise_all_vni
= 0;
6242 zvrf
->advertise_gw_macip
= 0;
6243 zvrf
->advertise_svi_macip
= 0;
6244 zvrf
->vxlan_flood_ctrl
= VXLAN_FLOOD_HEAD_END_REPL
;
6246 hash_iterate(zvrf
->evpn_table
, zebra_evpn_cfg_cleanup
, NULL
);
6249 zl3vni
= zl3vni_lookup(zvrf
->l3vni
);
6251 /* delete and uninstall all rmacs */
6252 hash_iterate(zl3vni
->rmac_table
, zl3vni_del_rmac_hash_entry
,
6254 /* delete and uninstall all next-hops */
6255 hash_iterate(zl3vni
->nh_table
, zl3vni_del_nh_hash_entry
,
6260 /* Cleanup BGP EVPN configuration upon client disconnect */
6261 static int zebra_evpn_bgp_cfg_clean_up(struct zserv
*client
)
6264 struct zebra_vrf
*zvrf
;
6266 RB_FOREACH (vrf
, vrf_id_head
, &vrfs_by_id
) {
6269 zebra_evpn_vrf_cfg_cleanup(zvrf
);
6275 static int zebra_evpn_pim_cfg_clean_up(struct zserv
*client
)
6277 struct zebra_vrf
*zvrf
= zebra_vrf_get_evpn();
6279 if (CHECK_FLAG(zvrf
->flags
, ZEBRA_PIM_SEND_VXLAN_SG
)) {
6280 if (IS_ZEBRA_DEBUG_VXLAN
)
6281 zlog_debug("VxLAN SG updates to PIM, stop");
6282 UNSET_FLAG(zvrf
->flags
, ZEBRA_PIM_SEND_VXLAN_SG
);
6288 static int zebra_evpn_cfg_clean_up(struct zserv
*client
)
6290 if (client
->proto
== ZEBRA_ROUTE_BGP
)
6291 return zebra_evpn_bgp_cfg_clean_up(client
);
6293 if (client
->proto
== ZEBRA_ROUTE_PIM
)
6294 return zebra_evpn_pim_cfg_clean_up(client
);
6300 * Handle results for vxlan dataplane operations.
6302 extern void zebra_vxlan_handle_result(struct zebra_dplane_ctx
*ctx
)
6307 /* Config knob for accepting lower sequence numbers */
6308 void zebra_vxlan_set_accept_bgp_seq(bool set
)
6310 accept_bgp_seq
= set
;
6313 bool zebra_vxlan_get_accept_bgp_seq(void)
6315 return accept_bgp_seq
;
6318 /* Cleanup BGP EVPN configuration upon client disconnect */
6319 extern void zebra_evpn_init(void)
6321 hook_register(zserv_client_close
, zebra_evpn_cfg_clean_up
);