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
));
72 /* static function declarations */
73 static void zevpn_print_neigh_hash_all_evpn(struct hash_bucket
*bucket
,
75 static void zl3vni_print_nh(struct zebra_neigh
*n
, struct vty
*vty
,
77 static void zl3vni_print_rmac(struct zebra_mac
*zrmac
, struct vty
*vty
,
79 static void zevpn_print_mac_hash_all_evpn(struct hash_bucket
*bucket
, void *ctxt
);
81 /* l3-vni next-hop neigh related APIs */
82 static struct zebra_neigh
*zl3vni_nh_lookup(struct zebra_l3vni
*zl3vni
,
83 const struct ipaddr
*ip
);
84 static void *zl3vni_nh_alloc(void *p
);
85 static struct zebra_neigh
*zl3vni_nh_add(struct zebra_l3vni
*zl3vni
,
86 const struct ipaddr
*vtep_ip
,
87 const struct ethaddr
*rmac
);
88 static int zl3vni_nh_del(struct zebra_l3vni
*zl3vni
, struct zebra_neigh
*n
);
89 static int zl3vni_nh_install(struct zebra_l3vni
*zl3vni
, struct zebra_neigh
*n
);
90 static int zl3vni_nh_uninstall(struct zebra_l3vni
*zl3vni
,
91 struct zebra_neigh
*n
);
93 /* l3-vni rmac related APIs */
94 static void zl3vni_print_rmac_hash(struct hash_bucket
*, void *);
95 static struct zebra_mac
*zl3vni_rmac_lookup(struct zebra_l3vni
*zl3vni
,
96 const struct ethaddr
*rmac
);
97 static void *zl3vni_rmac_alloc(void *p
);
98 static struct zebra_mac
*zl3vni_rmac_add(struct zebra_l3vni
*zl3vni
,
99 const struct ethaddr
*rmac
);
100 static int zl3vni_rmac_del(struct zebra_l3vni
*zl3vni
, struct zebra_mac
*zrmac
);
101 static int zl3vni_rmac_install(struct zebra_l3vni
*zl3vni
,
102 struct zebra_mac
*zrmac
);
103 static int zl3vni_rmac_uninstall(struct zebra_l3vni
*zl3vni
,
104 struct zebra_mac
*zrmac
);
106 /* l3-vni related APIs*/
107 static void *zl3vni_alloc(void *p
);
108 static struct zebra_l3vni
*zl3vni_add(vni_t vni
, vrf_id_t vrf_id
);
109 static int zl3vni_del(struct zebra_l3vni
*zl3vni
);
110 static void zebra_vxlan_process_l3vni_oper_up(struct zebra_l3vni
*zl3vni
);
111 static void zebra_vxlan_process_l3vni_oper_down(struct zebra_l3vni
*zl3vni
);
113 static void zevpn_build_hash_table(void);
114 static unsigned int zebra_vxlan_sg_hash_key_make(const void *p
);
115 static bool zebra_vxlan_sg_hash_eq(const void *p1
, const void *p2
);
116 static void zebra_vxlan_sg_do_deref(struct zebra_vrf
*zvrf
,
117 struct in_addr sip
, struct in_addr mcast_grp
);
118 static struct zebra_vxlan_sg
*zebra_vxlan_sg_do_ref(struct zebra_vrf
*vrf
,
120 struct in_addr mcast_grp
);
121 static void zebra_vxlan_sg_deref(struct in_addr local_vtep_ip
,
122 struct in_addr mcast_grp
);
123 static void zebra_vxlan_sg_ref(struct in_addr local_vtep_ip
,
124 struct in_addr mcast_grp
);
125 static void zebra_vxlan_cleanup_sg_table(struct zebra_vrf
*zvrf
);
127 bool zebra_evpn_do_dup_addr_detect(struct zebra_vrf
*zvrf
)
129 return zvrf
->dup_addr_detect
&& zebra_evpn_mh_do_dup_addr_detect();
132 /* Private functions */
133 static int host_rb_entry_compare(const struct host_rb_entry
*hle1
,
134 const struct host_rb_entry
*hle2
)
136 if (hle1
->p
.family
< hle2
->p
.family
)
139 if (hle1
->p
.family
> hle2
->p
.family
)
142 if (hle1
->p
.prefixlen
< hle2
->p
.prefixlen
)
145 if (hle1
->p
.prefixlen
> hle2
->p
.prefixlen
)
148 if (hle1
->p
.family
== AF_INET
) {
149 if (hle1
->p
.u
.prefix4
.s_addr
< hle2
->p
.u
.prefix4
.s_addr
)
152 if (hle1
->p
.u
.prefix4
.s_addr
> hle2
->p
.u
.prefix4
.s_addr
)
156 } else if (hle1
->p
.family
== AF_INET6
) {
157 return memcmp(&hle1
->p
.u
.prefix6
, &hle2
->p
.u
.prefix6
,
159 } else if (hle1
->p
.family
== AF_EVPN
) {
163 /* two (v4/v6) dummy prefixes of route_type BGP_EVPN_AD_ROUTE
164 * are used for all nexthops associated with a non-zero ESI
166 family1
= is_evpn_prefix_ipaddr_v4(
167 (const struct prefix_evpn
*)&hle1
->p
)
170 family2
= is_evpn_prefix_ipaddr_v4(
171 (const struct prefix_evpn
*)&hle2
->p
)
176 if (family1
< family2
)
179 if (family1
> family2
)
184 zlog_debug("%s: Unexpected family type: %d", __func__
,
189 RB_GENERATE(host_rb_tree_entry
, host_rb_entry
, hl_entry
, host_rb_entry_compare
);
191 static uint32_t rb_host_count(struct host_rb_tree_entry
*hrbe
)
193 struct host_rb_entry
*hle
;
196 RB_FOREACH (hle
, host_rb_tree_entry
, hrbe
)
202 static int l3vni_rmac_nh_list_cmp(void *p1
, void *p2
)
204 const struct ipaddr
*vtep_ip1
= p1
;
205 const struct ipaddr
*vtep_ip2
= p2
;
207 return !ipaddr_cmp(vtep_ip1
, vtep_ip2
);
210 static void l3vni_rmac_nh_free(struct ipaddr
*vtep_ip
)
212 XFREE(MTYPE_EVPN_VTEP
, vtep_ip
);
215 static void l3vni_rmac_nh_list_nh_delete(struct zebra_l3vni
*zl3vni
,
216 struct zebra_mac
*zrmac
,
217 struct ipaddr
*vtep_ip
)
219 struct listnode
*node
= NULL
, *nnode
= NULL
;
220 struct ipaddr
*vtep
= NULL
;
222 for (ALL_LIST_ELEMENTS(zrmac
->nh_list
, node
, nnode
, vtep
)) {
223 if (ipaddr_cmp(vtep
, vtep_ip
) == 0)
228 l3vni_rmac_nh_free(vtep
);
229 list_delete_node(zrmac
->nh_list
, node
);
234 * Print neighbors for all EVPN.
236 static void zevpn_print_neigh_hash_all_evpn(struct hash_bucket
*bucket
,
240 json_object
*json
= NULL
, *json_evpn
= NULL
;
241 struct zebra_evpn
*zevpn
;
243 struct neigh_walk_ctx wctx
;
244 char vni_str
[VNI_STR_LEN
];
247 vty
= (struct vty
*)args
[0];
248 json
= (json_object
*)args
[1];
249 print_dup
= (uint32_t)(uintptr_t)args
[2];
251 zevpn
= (struct zebra_evpn
*)bucket
->data
;
253 num_neigh
= hashcount(zevpn
->neigh_table
);
256 num_neigh
= num_dup_detected_neighs(zevpn
);
260 "\nVNI %u #ARP (IPv4 and IPv6, local and remote) %u\n\n",
261 zevpn
->vni
, num_neigh
);
263 json_evpn
= json_object_new_object();
264 json_object_int_add(json_evpn
, "numArpNd", num_neigh
);
265 snprintf(vni_str
, VNI_STR_LEN
, "%u", zevpn
->vni
);
270 json_object_object_add(json
, vni_str
, json_evpn
);
274 /* Since we have IPv6 addresses to deal with which can vary widely in
275 * size, we try to be a bit more elegant in display by first computing
278 memset(&wctx
, 0, sizeof(wctx
));
281 wctx
.addr_width
= 15;
282 wctx
.json
= json_evpn
;
283 hash_iterate(zevpn
->neigh_table
, zebra_evpn_find_neigh_addr_width
,
287 zebra_evpn_print_neigh_hdr(vty
, &wctx
);
290 hash_iterate(zevpn
->neigh_table
,
291 zebra_evpn_print_dad_neigh_hash
, &wctx
);
293 hash_iterate(zevpn
->neigh_table
, zebra_evpn_print_neigh_hash
,
297 json_object_object_add(json
, vni_str
, json_evpn
);
301 * Print neighbors for all EVPNs in detail.
303 static void zevpn_print_neigh_hash_all_evpn_detail(struct hash_bucket
*bucket
,
307 json_object
*json
= NULL
, *json_evpn
= NULL
;
308 struct zebra_evpn
*zevpn
;
310 struct neigh_walk_ctx wctx
;
311 char vni_str
[VNI_STR_LEN
];
314 vty
= (struct vty
*)args
[0];
315 json
= (json_object
*)args
[1];
316 print_dup
= (uint32_t)(uintptr_t)args
[2];
318 zevpn
= (struct zebra_evpn
*)bucket
->data
;
321 vty_out(vty
, "{}\n");
324 num_neigh
= hashcount(zevpn
->neigh_table
);
326 if (print_dup
&& num_dup_detected_neighs(zevpn
) == 0)
331 "\nVNI %u #ARP (IPv4 and IPv6, local and remote) %u\n\n",
332 zevpn
->vni
, num_neigh
);
334 json_evpn
= json_object_new_object();
335 json_object_int_add(json_evpn
, "numArpNd", num_neigh
);
336 snprintf(vni_str
, VNI_STR_LEN
, "%u", zevpn
->vni
);
340 json_object_object_add(json
, vni_str
, json_evpn
);
344 memset(&wctx
, 0, sizeof(wctx
));
347 wctx
.addr_width
= 15;
348 wctx
.json
= json_evpn
;
351 hash_iterate(zevpn
->neigh_table
,
352 zebra_evpn_print_dad_neigh_hash_detail
, &wctx
);
354 hash_iterate(zevpn
->neigh_table
,
355 zebra_evpn_print_neigh_hash_detail
, &wctx
);
358 json_object_object_add(json
, vni_str
, json_evpn
);
361 /* print a specific next hop for an l3vni */
362 static void zl3vni_print_nh(struct zebra_neigh
*n
, struct vty
*vty
,
365 char buf1
[ETHER_ADDR_STRLEN
];
366 char buf2
[INET6_ADDRSTRLEN
];
367 json_object
*json_hosts
= NULL
;
368 struct host_rb_entry
*hle
;
371 vty_out(vty
, "Ip: %s\n",
372 ipaddr2str(&n
->ip
, buf2
, sizeof(buf2
)));
373 vty_out(vty
, " RMAC: %s\n",
374 prefix_mac2str(&n
->emac
, buf1
, sizeof(buf1
)));
375 vty_out(vty
, " Refcount: %d\n",
376 rb_host_count(&n
->host_rb
));
377 vty_out(vty
, " Prefixes:\n");
378 RB_FOREACH (hle
, host_rb_tree_entry
, &n
->host_rb
)
379 vty_out(vty
, " %pFX\n", &hle
->p
);
381 json_hosts
= json_object_new_array();
382 json_object_string_add(
383 json
, "ip", ipaddr2str(&(n
->ip
), buf2
, sizeof(buf2
)));
384 json_object_string_add(
386 prefix_mac2str(&n
->emac
, buf2
, sizeof(buf2
)));
387 json_object_int_add(json
, "refCount",
388 rb_host_count(&n
->host_rb
));
389 RB_FOREACH (hle
, host_rb_tree_entry
, &n
->host_rb
)
390 json_object_array_add(json_hosts
,
391 json_object_new_string(prefix2str(
392 &hle
->p
, buf2
, sizeof(buf2
))));
393 json_object_object_add(json
, "prefixList", json_hosts
);
397 /* Print a specific RMAC entry */
398 static void zl3vni_print_rmac(struct zebra_mac
*zrmac
, struct vty
*vty
,
401 struct listnode
*node
= NULL
;
402 struct ipaddr
*vtep
= NULL
;
403 json_object
*json_nhs
= NULL
;
406 vty_out(vty
, "MAC: %pEA\n", &zrmac
->macaddr
);
407 vty_out(vty
, " Remote VTEP: %pI4\n",
408 &zrmac
->fwd_info
.r_vtep_ip
);
410 json_nhs
= json_object_new_array();
411 json_object_string_addf(json
, "routerMac", "%pEA",
413 json_object_string_addf(json
, "vtepIp", "%pI4",
414 &zrmac
->fwd_info
.r_vtep_ip
);
415 for (ALL_LIST_ELEMENTS_RO(zrmac
->nh_list
, node
, vtep
)) {
416 json_object_array_add(json_nhs
, json_object_new_stringf(
419 json_object_object_add(json
, "nexthops", json_nhs
);
424 * Print MACs for all EVPNs.
426 static void zevpn_print_mac_hash_all_evpn(struct hash_bucket
*bucket
, void *ctxt
)
429 json_object
*json
= NULL
, *json_evpn
= NULL
;
430 json_object
*json_mac
= NULL
;
431 struct zebra_evpn
*zevpn
;
433 struct mac_walk_ctx
*wctx
= ctxt
;
434 char vni_str
[VNI_STR_LEN
];
439 zevpn
= (struct zebra_evpn
*)bucket
->data
;
442 /*We are iterating over a new VNI, set the count to 0*/
445 num_macs
= num_valid_macs(zevpn
);
450 num_macs
= num_dup_detected_macs(zevpn
);
453 json_evpn
= json_object_new_object();
454 json_mac
= json_object_new_object();
455 snprintf(vni_str
, VNI_STR_LEN
, "%u", zevpn
->vni
);
458 if (!CHECK_FLAG(wctx
->flags
, SHOW_REMOTE_MAC_FROM_VTEP
)) {
460 vty_out(vty
, "\nVNI %u #MACs (local and remote) %u\n\n",
461 zevpn
->vni
, num_macs
);
463 "Flags: N=sync-neighs, I=local-inactive, P=peer-active, X=peer-proxy\n");
464 vty_out(vty
, "%-17s %-6s %-5s %-30s %-5s %s\n", "MAC",
465 "Type", "Flags", "Intf/Remote ES/VTEP",
468 json_object_int_add(json_evpn
, "numMacs", num_macs
);
473 json_object_int_add(json_evpn
, "numMacs", num_macs
);
474 json_object_object_add(json
, vni_str
, json_evpn
);
479 /* assign per-evpn to wctx->json object to fill macs
480 * under the evpn. Re-assign primary json object to fill
481 * next evpn information.
483 wctx
->json
= json_mac
;
485 hash_iterate(zevpn
->mac_table
, zebra_evpn_print_dad_mac_hash
,
488 hash_iterate(zevpn
->mac_table
, zebra_evpn_print_mac_hash
, wctx
);
492 json_object_object_add(json_evpn
, "macs", json_mac
);
493 json_object_object_add(json
, vni_str
, json_evpn
);
498 * Print MACs in detail for all EVPNs.
500 static void zevpn_print_mac_hash_all_evpn_detail(struct hash_bucket
*bucket
,
504 json_object
*json
= NULL
, *json_evpn
= NULL
;
505 json_object
*json_mac
= NULL
;
506 struct zebra_evpn
*zevpn
;
508 struct mac_walk_ctx
*wctx
= ctxt
;
509 char vni_str
[VNI_STR_LEN
];
514 zevpn
= (struct zebra_evpn
*)bucket
->data
;
517 vty_out(vty
, "{}\n");
522 /*We are iterating over a new EVPN, set the count to 0*/
525 num_macs
= num_valid_macs(zevpn
);
529 if (wctx
->print_dup
&& (num_dup_detected_macs(zevpn
) == 0))
533 json_evpn
= json_object_new_object();
534 json_mac
= json_object_new_object();
535 snprintf(vni_str
, VNI_STR_LEN
, "%u", zevpn
->vni
);
538 if (!CHECK_FLAG(wctx
->flags
, SHOW_REMOTE_MAC_FROM_VTEP
)) {
540 vty_out(vty
, "\nVNI %u #MACs (local and remote) %u\n\n",
541 zevpn
->vni
, num_macs
);
543 json_object_int_add(json_evpn
, "numMacs", num_macs
);
545 /* assign per-evpn to wctx->json object to fill macs
546 * under the evpn. Re-assign primary json object to fill
547 * next evpn information.
549 wctx
->json
= json_mac
;
551 hash_iterate(zevpn
->mac_table
,
552 zebra_evpn_print_dad_mac_hash_detail
, wctx
);
554 hash_iterate(zevpn
->mac_table
, zebra_evpn_print_mac_hash_detail
,
559 json_object_object_add(json_evpn
, "macs", json_mac
);
560 json_object_object_add(json
, vni_str
, json_evpn
);
564 static void zl3vni_print_nh_hash(struct hash_bucket
*bucket
, void *ctx
)
566 struct nh_walk_ctx
*wctx
= NULL
;
567 struct vty
*vty
= NULL
;
568 struct json_object
*json_evpn
= NULL
;
569 struct json_object
*json_nh
= NULL
;
570 struct zebra_neigh
*n
= NULL
;
571 char buf1
[ETHER_ADDR_STRLEN
];
572 char buf2
[INET6_ADDRSTRLEN
];
574 wctx
= (struct nh_walk_ctx
*)ctx
;
576 json_evpn
= wctx
->json
;
578 json_nh
= json_object_new_object();
579 n
= (struct zebra_neigh
*)bucket
->data
;
582 vty_out(vty
, "%-15s %-17s\n",
583 ipaddr2str(&(n
->ip
), buf2
, sizeof(buf2
)),
584 prefix_mac2str(&n
->emac
, buf1
, sizeof(buf1
)));
586 json_object_string_add(json_nh
, "nexthopIp",
587 ipaddr2str(&n
->ip
, buf2
, sizeof(buf2
)));
588 json_object_string_add(
589 json_nh
, "routerMac",
590 prefix_mac2str(&n
->emac
, buf1
, sizeof(buf1
)));
591 json_object_object_add(json_evpn
,
592 ipaddr2str(&(n
->ip
), buf2
, sizeof(buf2
)),
597 static void zl3vni_print_nh_hash_all_vni(struct hash_bucket
*bucket
,
600 struct vty
*vty
= NULL
;
601 json_object
*json
= NULL
;
602 json_object
*json_evpn
= NULL
;
603 struct zebra_l3vni
*zl3vni
= NULL
;
605 struct nh_walk_ctx wctx
;
606 char vni_str
[VNI_STR_LEN
];
608 vty
= (struct vty
*)args
[0];
609 json
= (struct json_object
*)args
[1];
611 zl3vni
= (struct zebra_l3vni
*)bucket
->data
;
613 num_nh
= hashcount(zl3vni
->nh_table
);
618 json_evpn
= json_object_new_object();
619 snprintf(vni_str
, VNI_STR_LEN
, "%u", zl3vni
->vni
);
623 vty_out(vty
, "\nVNI %u #Next-Hops %u\n\n", zl3vni
->vni
, num_nh
);
624 vty_out(vty
, "%-15s %-17s\n", "IP", "RMAC");
626 json_object_int_add(json_evpn
, "numNextHops", num_nh
);
628 memset(&wctx
, 0, sizeof(wctx
));
630 wctx
.json
= json_evpn
;
631 hash_iterate(zl3vni
->nh_table
, zl3vni_print_nh_hash
, &wctx
);
633 json_object_object_add(json
, vni_str
, json_evpn
);
636 static void zl3vni_print_rmac_hash_all_vni(struct hash_bucket
*bucket
,
639 struct vty
*vty
= NULL
;
640 json_object
*json
= NULL
;
641 json_object
*json_evpn
= NULL
;
642 struct zebra_l3vni
*zl3vni
= NULL
;
644 struct rmac_walk_ctx wctx
;
645 char vni_str
[VNI_STR_LEN
];
647 vty
= (struct vty
*)args
[0];
648 json
= (struct json_object
*)args
[1];
650 zl3vni
= (struct zebra_l3vni
*)bucket
->data
;
652 num_rmacs
= hashcount(zl3vni
->rmac_table
);
657 json_evpn
= json_object_new_object();
658 snprintf(vni_str
, VNI_STR_LEN
, "%u", zl3vni
->vni
);
662 vty_out(vty
, "\nVNI %u #RMACs %u\n\n", zl3vni
->vni
, num_rmacs
);
663 vty_out(vty
, "%-17s %-21s\n", "RMAC", "Remote VTEP");
665 json_object_int_add(json_evpn
, "numRmacs", num_rmacs
);
667 /* assign per-vni to wctx->json object to fill macs
668 * under the vni. Re-assign primary json object to fill
669 * next vni information.
671 memset(&wctx
, 0, sizeof(wctx
));
673 wctx
.json
= json_evpn
;
674 hash_iterate(zl3vni
->rmac_table
, zl3vni_print_rmac_hash
, &wctx
);
676 json_object_object_add(json
, vni_str
, json_evpn
);
679 static void zl3vni_print_rmac_hash(struct hash_bucket
*bucket
, void *ctx
)
681 struct zebra_mac
*zrmac
= NULL
;
682 struct rmac_walk_ctx
*wctx
= NULL
;
683 struct vty
*vty
= NULL
;
684 struct json_object
*json
= NULL
;
685 struct json_object
*json_rmac
= NULL
;
686 char buf
[PREFIX_STRLEN
];
688 wctx
= (struct rmac_walk_ctx
*)ctx
;
692 json_rmac
= json_object_new_object();
693 zrmac
= (struct zebra_mac
*)bucket
->data
;
696 vty_out(vty
, "%-17s %-21pI4\n",
697 prefix_mac2str(&zrmac
->macaddr
, buf
, sizeof(buf
)),
698 &zrmac
->fwd_info
.r_vtep_ip
);
700 json_object_string_add(
701 json_rmac
, "routerMac",
702 prefix_mac2str(&zrmac
->macaddr
, buf
, sizeof(buf
)));
703 json_object_string_addf(json_rmac
, "vtepIp", "%pI4",
704 &zrmac
->fwd_info
.r_vtep_ip
);
705 json_object_object_add(
706 json
, prefix_mac2str(&zrmac
->macaddr
, buf
, sizeof(buf
)),
711 /* print a specific L3 VNI entry */
712 static void zl3vni_print(struct zebra_l3vni
*zl3vni
, void **ctx
)
714 char buf
[PREFIX_STRLEN
];
715 struct vty
*vty
= NULL
;
716 json_object
*json
= NULL
;
717 struct zebra_evpn
*zevpn
= NULL
;
718 json_object
*json_evpn_list
= NULL
;
719 struct listnode
*node
= NULL
, *nnode
= NULL
;
725 vty_out(vty
, "VNI: %u\n", zl3vni
->vni
);
726 vty_out(vty
, " Type: %s\n", "L3");
727 vty_out(vty
, " Tenant VRF: %s\n", zl3vni_vrf_name(zl3vni
));
728 vty_out(vty
, " Local Vtep Ip: %pI4\n",
729 &zl3vni
->local_vtep_ip
);
730 vty_out(vty
, " Vxlan-Intf: %s\n",
731 zl3vni_vxlan_if_name(zl3vni
));
732 vty_out(vty
, " SVI-If: %s\n", zl3vni_svi_if_name(zl3vni
));
733 vty_out(vty
, " State: %s\n", zl3vni_state2str(zl3vni
));
734 vty_out(vty
, " VNI Filter: %s\n",
735 CHECK_FLAG(zl3vni
->filter
, PREFIX_ROUTES_ONLY
)
736 ? "prefix-routes-only"
738 vty_out(vty
, " System MAC: %s\n",
739 zl3vni_sysmac2str(zl3vni
, buf
, sizeof(buf
)));
740 vty_out(vty
, " Router MAC: %s\n",
741 zl3vni_rmac2str(zl3vni
, buf
, sizeof(buf
)));
742 vty_out(vty
, " L2 VNIs: ");
743 for (ALL_LIST_ELEMENTS(zl3vni
->l2vnis
, node
, nnode
, zevpn
))
744 vty_out(vty
, "%u ", zevpn
->vni
);
747 json_evpn_list
= json_object_new_array();
748 json_object_int_add(json
, "vni", zl3vni
->vni
);
749 json_object_string_add(json
, "type", "L3");
750 json_object_string_addf(json
, "localVtepIp", "%pI4",
751 &zl3vni
->local_vtep_ip
);
752 json_object_string_add(json
, "vxlanIntf",
753 zl3vni_vxlan_if_name(zl3vni
));
754 json_object_string_add(json
, "sviIntf",
755 zl3vni_svi_if_name(zl3vni
));
756 json_object_string_add(json
, "state", zl3vni_state2str(zl3vni
));
757 json_object_string_add(json
, "vrf", zl3vni_vrf_name(zl3vni
));
758 json_object_string_add(
760 zl3vni_sysmac2str(zl3vni
, buf
, sizeof(buf
)));
761 json_object_string_add(
763 zl3vni_rmac2str(zl3vni
, buf
, sizeof(buf
)));
764 json_object_string_add(
766 CHECK_FLAG(zl3vni
->filter
, PREFIX_ROUTES_ONLY
)
767 ? "prefix-routes-only"
769 for (ALL_LIST_ELEMENTS(zl3vni
->l2vnis
, node
, nnode
, zevpn
)) {
770 json_object_array_add(json_evpn_list
,
771 json_object_new_int(zevpn
->vni
));
773 json_object_object_add(json
, "l2Vnis", json_evpn_list
);
777 /* print a L3 VNI hash entry */
778 static void zl3vni_print_hash(struct hash_bucket
*bucket
, void *ctx
[])
780 struct vty
*vty
= NULL
;
781 json_object
*json
= NULL
;
782 json_object
*json_evpn
= NULL
;
783 struct zebra_l3vni
*zl3vni
= NULL
;
785 vty
= (struct vty
*)ctx
[0];
786 json
= (json_object
*)ctx
[1];
788 zl3vni
= (struct zebra_l3vni
*)bucket
->data
;
791 vty_out(vty
, "%-10u %-4s %-21s %-8lu %-8lu %-15s %-37s\n",
792 zl3vni
->vni
, "L3", zl3vni_vxlan_if_name(zl3vni
),
793 hashcount(zl3vni
->rmac_table
),
794 hashcount(zl3vni
->nh_table
), "n/a",
795 zl3vni_vrf_name(zl3vni
));
797 char vni_str
[VNI_STR_LEN
];
799 snprintf(vni_str
, VNI_STR_LEN
, "%u", zl3vni
->vni
);
800 json_evpn
= json_object_new_object();
801 json_object_int_add(json_evpn
, "vni", zl3vni
->vni
);
802 json_object_string_add(json_evpn
, "vxlanIf",
803 zl3vni_vxlan_if_name(zl3vni
));
804 json_object_int_add(json_evpn
, "numMacs",
805 hashcount(zl3vni
->rmac_table
));
806 json_object_int_add(json_evpn
, "numArpNd",
807 hashcount(zl3vni
->nh_table
));
808 json_object_string_add(json_evpn
, "numRemoteVteps", "n/a");
809 json_object_string_add(json_evpn
, "type", "L3");
810 json_object_string_add(json_evpn
, "tenantVrf",
811 zl3vni_vrf_name(zl3vni
));
812 json_object_object_add(json
, vni_str
, json_evpn
);
816 /* print a L3 VNI hash entry in detail*/
817 static void zl3vni_print_hash_detail(struct hash_bucket
*bucket
, void *data
)
819 struct vty
*vty
= NULL
;
820 struct zebra_l3vni
*zl3vni
= NULL
;
821 json_object
*json_array
= NULL
;
822 bool use_json
= false;
823 struct zebra_evpn_show
*zes
= data
;
826 json_array
= zes
->json
;
827 use_json
= zes
->use_json
;
829 zl3vni
= (struct zebra_l3vni
*)bucket
->data
;
831 zebra_vxlan_print_vni(vty
, zes
->zvrf
, zl3vni
->vni
,
832 use_json
, json_array
);
838 static int zvni_map_to_svi_ns(struct ns
*ns
,
842 struct zebra_ns
*zns
= ns
->info
;
843 struct route_node
*rn
;
844 struct zebra_from_svi_param
*in_param
=
845 (struct zebra_from_svi_param
*)_in_param
;
846 struct zebra_l2info_vlan
*vl
;
847 struct interface
*tmp_if
= NULL
;
848 struct interface
**p_ifp
= (struct interface
**)_p_ifp
;
849 struct zebra_if
*zif
;
851 assert(in_param
&& p_ifp
);
853 /* TODO: Optimize with a hash. */
854 for (rn
= route_top(zns
->if_table
); rn
; rn
= route_next(rn
)) {
855 tmp_if
= (struct interface
*)rn
->info
;
856 /* Check oper status of the SVI. */
857 if (!tmp_if
|| !if_is_operative(tmp_if
))
860 if (!zif
|| zif
->zif_type
!= ZEBRA_IF_VLAN
861 || zif
->link
!= in_param
->br_if
)
863 vl
= (struct zebra_l2info_vlan
*)&zif
->l2info
.vl
;
865 if (vl
->vid
== in_param
->vid
) {
870 return NS_WALK_CONTINUE
;
873 /* Map to SVI on bridge corresponding to specified VLAN. This can be one
875 * (a) In the case of a VLAN-aware bridge, the SVI is a L3 VLAN interface
876 * linked to the bridge
877 * (b) In the case of a VLAN-unaware bridge, the SVI is the bridge interface
880 struct interface
*zvni_map_to_svi(vlanid_t vid
, struct interface
*br_if
)
882 struct interface
*tmp_if
= NULL
;
883 struct zebra_if
*zif
;
884 struct zebra_l2info_bridge
*br
;
885 struct zebra_from_svi_param in_param
;
886 struct interface
**p_ifp
;
887 /* Defensive check, caller expected to invoke only with valid bridge. */
891 /* Determine if bridge is VLAN-aware or not */
894 br
= &zif
->l2info
.br
;
895 in_param
.bridge_vlan_aware
= br
->vlan_aware
;
896 /* Check oper status of the SVI. */
897 if (!in_param
.bridge_vlan_aware
)
898 return if_is_operative(br_if
) ? br_if
: NULL
;
901 in_param
.br_if
= br_if
;
904 /* Identify corresponding VLAN interface. */
905 ns_walk_func(zvni_map_to_svi_ns
, (void *)&in_param
,
910 static int zebra_evpn_vxlan_del(struct zebra_evpn
*zevpn
)
912 zevpn_vxlan_if_set(zevpn
, zevpn
->vxlan_if
, false /* set */);
914 /* Remove references to the BUM mcast grp */
915 zebra_vxlan_sg_deref(zevpn
->local_vtep_ip
, zevpn
->mcast_grp
);
917 return zebra_evpn_del(zevpn
);
920 static int zevpn_build_hash_table_zns(struct ns
*ns
,
921 void *param_in
__attribute__((unused
)),
922 void **param_out
__attribute__((unused
)))
924 struct zebra_ns
*zns
= ns
->info
;
925 struct route_node
*rn
;
926 struct interface
*ifp
;
927 struct zebra_vrf
*zvrf
;
929 zvrf
= zebra_vrf_get_evpn();
931 /* Walk VxLAN interfaces and create EVPN hash. */
932 for (rn
= route_top(zns
->if_table
); rn
; rn
= route_next(rn
)) {
934 struct zebra_evpn
*zevpn
= NULL
;
935 struct zebra_l3vni
*zl3vni
= NULL
;
936 struct zebra_if
*zif
;
937 struct zebra_l2info_vxlan
*vxl
;
939 ifp
= (struct interface
*)rn
->info
;
943 if (!zif
|| zif
->zif_type
!= ZEBRA_IF_VXLAN
)
946 vxl
= &zif
->l2info
.vxl
;
948 /* link of VXLAN interface should be in zebra_evpn_vrf */
949 if (zvrf
->zns
->ns_id
!= vxl
->link_nsid
) {
950 if (IS_ZEBRA_DEBUG_VXLAN
)
952 "Intf %s(%u) VNI %u, link not in same "
953 "namespace than BGP EVPN core instance ",
954 ifp
->name
, ifp
->ifindex
, vni
);
957 /* L3-VNI and L2-VNI are handled seperately */
958 zl3vni
= zl3vni_lookup(vni
);
961 if (IS_ZEBRA_DEBUG_VXLAN
)
963 "create L3-VNI hash for Intf %s(%u) L3-VNI %u",
964 ifp
->name
, ifp
->ifindex
, vni
);
966 /* associate with vxlan_if */
967 zl3vni
->local_vtep_ip
= vxl
->vtep_ip
;
968 zl3vni
->vxlan_if
= ifp
;
971 * we need to associate with SVI.
972 * we can associate with svi-if only after association
973 * with vxlan-intf is complete
975 zl3vni
->svi_if
= zl3vni_map_to_svi_if(zl3vni
);
977 /* Associate l3vni to mac-vlan and extract VRR MAC */
978 zl3vni
->mac_vlan_if
= zl3vni_map_to_mac_vlan_if(zl3vni
);
980 if (IS_ZEBRA_DEBUG_VXLAN
)
981 zlog_debug("create l3vni %u svi_if %s mac_vlan_if %s",
982 vni
, zl3vni
->svi_if
? zl3vni
->svi_if
->name
984 zl3vni
->mac_vlan_if
?
985 zl3vni
->mac_vlan_if
->name
: "NIL");
987 if (is_l3vni_oper_up(zl3vni
))
988 zebra_vxlan_process_l3vni_oper_up(zl3vni
);
991 struct interface
*vlan_if
= NULL
;
993 if (IS_ZEBRA_DEBUG_VXLAN
)
995 "Create L2-VNI hash for intf %s(%u) L2-VNI %u local IP %pI4",
996 ifp
->name
, ifp
->ifindex
, vni
,
999 /* EVPN hash entry is expected to exist, if the BGP process is killed */
1000 zevpn
= zebra_evpn_lookup(vni
);
1003 "EVPN hash already present for IF %s(%u) L2-VNI %u",
1004 ifp
->name
, ifp
->ifindex
, vni
);
1007 * Inform BGP if intf is up and mapped to
1010 if (if_is_operative(ifp
) &&
1011 zif
->brslave_info
.br_if
)
1012 zebra_evpn_send_add_to_client(zevpn
);
1014 /* Send Local MAC-entries to client */
1015 zebra_evpn_send_mac_list_to_client(zevpn
);
1017 /* Send Loval Neighbor entries to client */
1018 zebra_evpn_send_neigh_to_client(zevpn
);
1020 zevpn
= zebra_evpn_add(vni
);
1023 "Failed to add EVPN hash, IF %s(%u) L2-VNI %u",
1024 ifp
->name
, ifp
->ifindex
, vni
);
1025 return NS_WALK_CONTINUE
;
1028 if (zevpn
->local_vtep_ip
.s_addr
!=
1029 vxl
->vtep_ip
.s_addr
||
1030 zevpn
->mcast_grp
.s_addr
!=
1031 vxl
->mcast_grp
.s_addr
) {
1032 zebra_vxlan_sg_deref(
1033 zevpn
->local_vtep_ip
,
1035 zebra_vxlan_sg_ref(vxl
->vtep_ip
,
1037 zevpn
->local_vtep_ip
= vxl
->vtep_ip
;
1038 zevpn
->mcast_grp
= vxl
->mcast_grp
;
1039 /* on local vtep-ip check if ES
1040 * orig-ip needs to be updated
1042 zebra_evpn_es_set_base_evpn(zevpn
);
1044 zevpn_vxlan_if_set(zevpn
, ifp
, true /* set */);
1045 vlan_if
= zvni_map_to_svi(
1047 zif
->brslave_info
.br_if
);
1049 zevpn
->svi_if
= vlan_if
;
1050 zevpn
->vrf_id
= vlan_if
->vrf
->vrf_id
;
1051 zl3vni
= zl3vni_from_vrf(
1052 vlan_if
->vrf
->vrf_id
);
1055 zl3vni
->l2vnis
, zevpn
);
1059 * Inform BGP if intf is up and mapped to
1062 if (if_is_operative(ifp
) &&
1063 zif
->brslave_info
.br_if
)
1064 zebra_evpn_send_add_to_client(zevpn
);
1068 return NS_WALK_CONTINUE
;
1072 * Build the VNI hash table by going over the VxLAN interfaces. This
1073 * is called when EVPN (advertise-all-vni) is enabled.
1076 static void zevpn_build_hash_table(void)
1078 ns_walk_func(zevpn_build_hash_table_zns
, NULL
, NULL
);
1082 * Cleanup EVPN/VTEP and update kernel
1084 static void zebra_evpn_vxlan_cleanup_all(struct hash_bucket
*bucket
, void *arg
)
1086 struct zebra_evpn
*zevpn
= NULL
;
1087 struct zebra_l3vni
*zl3vni
= NULL
;
1089 zevpn
= (struct zebra_evpn
*)bucket
->data
;
1091 /* remove l2vni from l2vni's tenant-vrf l3-vni list */
1092 zl3vni
= zl3vni_from_vrf(zevpn
->vrf_id
);
1094 listnode_delete(zl3vni
->l2vnis
, zevpn
);
1096 zebra_evpn_cleanup_all(bucket
, arg
);
1100 static void zl3vni_cleanup_all(struct hash_bucket
*bucket
, void *args
)
1102 struct zebra_l3vni
*zl3vni
= NULL
;
1104 zl3vni
= (struct zebra_l3vni
*)bucket
->data
;
1106 zebra_vxlan_process_l3vni_oper_down(zl3vni
);
1109 static void rb_find_or_add_host(struct host_rb_tree_entry
*hrbe
,
1110 const struct prefix
*host
)
1112 struct host_rb_entry lookup
;
1113 struct host_rb_entry
*hle
;
1115 memset(&lookup
, 0, sizeof(lookup
));
1116 memcpy(&lookup
.p
, host
, sizeof(*host
));
1118 hle
= RB_FIND(host_rb_tree_entry
, hrbe
, &lookup
);
1122 hle
= XCALLOC(MTYPE_HOST_PREFIX
, sizeof(struct host_rb_entry
));
1123 memcpy(hle
, &lookup
, sizeof(lookup
));
1125 RB_INSERT(host_rb_tree_entry
, hrbe
, hle
);
1128 static void rb_delete_host(struct host_rb_tree_entry
*hrbe
, struct prefix
*host
)
1130 struct host_rb_entry lookup
;
1131 struct host_rb_entry
*hle
;
1133 memset(&lookup
, 0, sizeof(lookup
));
1134 memcpy(&lookup
.p
, host
, sizeof(*host
));
1136 hle
= RB_FIND(host_rb_tree_entry
, hrbe
, &lookup
);
1138 RB_REMOVE(host_rb_tree_entry
, hrbe
, hle
);
1139 XFREE(MTYPE_HOST_PREFIX
, hle
);
1146 * Look up MAC hash entry.
1148 static struct zebra_mac
*zl3vni_rmac_lookup(struct zebra_l3vni
*zl3vni
,
1149 const struct ethaddr
*rmac
)
1151 struct zebra_mac tmp
;
1152 struct zebra_mac
*pmac
;
1154 memset(&tmp
, 0, sizeof(tmp
));
1155 memcpy(&tmp
.macaddr
, rmac
, ETH_ALEN
);
1156 pmac
= hash_lookup(zl3vni
->rmac_table
, &tmp
);
1162 * Callback to allocate RMAC hash entry.
1164 static void *zl3vni_rmac_alloc(void *p
)
1166 const struct zebra_mac
*tmp_rmac
= p
;
1167 struct zebra_mac
*zrmac
;
1169 zrmac
= XCALLOC(MTYPE_L3VNI_MAC
, sizeof(struct zebra_mac
));
1172 return ((void *)zrmac
);
1176 * Add RMAC entry to l3-vni
1178 static struct zebra_mac
*zl3vni_rmac_add(struct zebra_l3vni
*zl3vni
,
1179 const struct ethaddr
*rmac
)
1181 struct zebra_mac tmp_rmac
;
1182 struct zebra_mac
*zrmac
= NULL
;
1184 memset(&tmp_rmac
, 0, sizeof(tmp_rmac
));
1185 memcpy(&tmp_rmac
.macaddr
, rmac
, ETH_ALEN
);
1186 zrmac
= hash_get(zl3vni
->rmac_table
, &tmp_rmac
, zl3vni_rmac_alloc
);
1187 zrmac
->nh_list
= list_new();
1188 zrmac
->nh_list
->cmp
= (int (*)(void *, void *))l3vni_rmac_nh_list_cmp
;
1189 zrmac
->nh_list
->del
= (void (*)(void *))l3vni_rmac_nh_free
;
1191 SET_FLAG(zrmac
->flags
, ZEBRA_MAC_REMOTE
);
1192 SET_FLAG(zrmac
->flags
, ZEBRA_MAC_REMOTE_RMAC
);
1200 static int zl3vni_rmac_del(struct zebra_l3vni
*zl3vni
, struct zebra_mac
*zrmac
)
1202 struct zebra_mac
*tmp_rmac
;
1204 /* free the list of nh list*/
1205 list_delete(&zrmac
->nh_list
);
1207 tmp_rmac
= hash_release(zl3vni
->rmac_table
, zrmac
);
1208 XFREE(MTYPE_L3VNI_MAC
, tmp_rmac
);
1214 * Install remote RMAC into the forwarding plane.
1216 static int zl3vni_rmac_install(struct zebra_l3vni
*zl3vni
,
1217 struct zebra_mac
*zrmac
)
1219 const struct zebra_if
*zif
= NULL
, *br_zif
= NULL
;
1220 const struct zebra_l2info_vxlan
*vxl
= NULL
;
1221 const struct interface
*br_ifp
;
1222 enum zebra_dplane_result res
;
1225 if (!(CHECK_FLAG(zrmac
->flags
, ZEBRA_MAC_REMOTE
))
1226 || !(CHECK_FLAG(zrmac
->flags
, ZEBRA_MAC_REMOTE_RMAC
)))
1229 zif
= zl3vni
->vxlan_if
->info
;
1233 br_ifp
= zif
->brslave_info
.br_if
;
1237 vxl
= &zif
->l2info
.vxl
;
1239 br_zif
= (const struct zebra_if
*)br_ifp
->info
;
1241 if (IS_ZEBRA_IF_BRIDGE_VLAN_AWARE(br_zif
))
1242 vid
= vxl
->access_vlan
;
1246 res
= dplane_rem_mac_add(zl3vni
->vxlan_if
, br_ifp
, vid
,
1247 &zrmac
->macaddr
, zrmac
->fwd_info
.r_vtep_ip
, 0, 0,
1248 false /*was_static*/);
1249 if (res
!= ZEBRA_DPLANE_REQUEST_FAILURE
)
1256 * Uninstall remote RMAC from the forwarding plane.
1258 static int zl3vni_rmac_uninstall(struct zebra_l3vni
*zl3vni
,
1259 struct zebra_mac
*zrmac
)
1261 const struct zebra_if
*zif
= NULL
, *br_zif
;
1262 const struct zebra_l2info_vxlan
*vxl
= NULL
;
1263 const struct interface
*br_ifp
;
1265 enum zebra_dplane_result res
;
1267 if (!(CHECK_FLAG(zrmac
->flags
, ZEBRA_MAC_REMOTE
))
1268 || !(CHECK_FLAG(zrmac
->flags
, ZEBRA_MAC_REMOTE_RMAC
)))
1271 if (!zl3vni
->vxlan_if
) {
1272 if (IS_ZEBRA_DEBUG_VXLAN
)
1274 "RMAC %pEA on L3-VNI %u hash %p couldn't be uninstalled - no vxlan_if",
1275 &zrmac
->macaddr
, zl3vni
->vni
, zl3vni
);
1279 zif
= zl3vni
->vxlan_if
->info
;
1283 br_ifp
= zif
->brslave_info
.br_if
;
1287 vxl
= &zif
->l2info
.vxl
;
1289 br_zif
= (const struct zebra_if
*)br_ifp
->info
;
1290 if (IS_ZEBRA_IF_BRIDGE_VLAN_AWARE(br_zif
))
1291 vid
= vxl
->access_vlan
;
1295 res
= dplane_rem_mac_del(zl3vni
->vxlan_if
, br_ifp
, vid
,
1296 &zrmac
->macaddr
, zrmac
->fwd_info
.r_vtep_ip
);
1297 if (res
!= ZEBRA_DPLANE_REQUEST_FAILURE
)
1303 /* handle rmac add */
1304 static int zl3vni_remote_rmac_add(struct zebra_l3vni
*zl3vni
,
1305 const struct ethaddr
*rmac
,
1306 const struct ipaddr
*vtep_ip
)
1308 struct zebra_mac
*zrmac
= NULL
;
1309 struct ipaddr
*vtep
= NULL
;
1311 zrmac
= zl3vni_rmac_lookup(zl3vni
, rmac
);
1314 /* Create the RMAC entry, or update its vtep, if necessary. */
1315 zrmac
= zl3vni_rmac_add(zl3vni
, rmac
);
1318 "Failed to add RMAC %pEA L3VNI %u Remote VTEP %pIA",
1319 rmac
, zl3vni
->vni
, vtep_ip
);
1322 memset(&zrmac
->fwd_info
, 0, sizeof(zrmac
->fwd_info
));
1323 zrmac
->fwd_info
.r_vtep_ip
= vtep_ip
->ipaddr_v4
;
1325 vtep
= XCALLOC(MTYPE_EVPN_VTEP
, sizeof(struct ipaddr
));
1326 memcpy(vtep
, vtep_ip
, sizeof(struct ipaddr
));
1327 if (!listnode_add_sort_nodup(zrmac
->nh_list
, (void *)vtep
))
1328 XFREE(MTYPE_EVPN_VTEP
, vtep
);
1330 /* Send RMAC for FPM processing */
1331 hook_call(zebra_rmac_update
, zrmac
, zl3vni
, false,
1334 /* install rmac in kernel */
1335 zl3vni_rmac_install(zl3vni
, zrmac
);
1336 } else if (!IPV4_ADDR_SAME(&zrmac
->fwd_info
.r_vtep_ip
,
1337 &vtep_ip
->ipaddr_v4
)) {
1338 if (IS_ZEBRA_DEBUG_VXLAN
)
1340 "L3VNI %u Remote VTEP change(%pI4 -> %pIA) for RMAC %pEA",
1341 zl3vni
->vni
, &zrmac
->fwd_info
.r_vtep_ip
,
1344 zrmac
->fwd_info
.r_vtep_ip
= vtep_ip
->ipaddr_v4
;
1346 vtep
= XCALLOC(MTYPE_EVPN_VTEP
, sizeof(struct ipaddr
));
1347 memcpy(vtep
, vtep_ip
, sizeof(struct ipaddr
));
1348 if (!listnode_add_sort_nodup(zrmac
->nh_list
, (void *)vtep
))
1349 XFREE(MTYPE_EVPN_VTEP
, vtep
);
1351 /* install rmac in kernel */
1352 zl3vni_rmac_install(zl3vni
, zrmac
);
1359 /* handle rmac delete */
1360 static void zl3vni_remote_rmac_del(struct zebra_l3vni
*zl3vni
,
1361 struct zebra_mac
*zrmac
,
1362 struct ipaddr
*vtep_ip
)
1364 struct ipaddr ipv4_vtep
;
1366 if (!zl3vni_nh_lookup(zl3vni
, vtep_ip
)) {
1367 memset(&ipv4_vtep
, 0, sizeof(ipv4_vtep
));
1368 ipv4_vtep
.ipa_type
= IPADDR_V4
;
1369 if (vtep_ip
->ipa_type
== IPADDR_V6
)
1370 ipv4_mapped_ipv6_to_ipv4(&vtep_ip
->ipaddr_v6
,
1371 &ipv4_vtep
.ipaddr_v4
);
1373 memcpy(&(ipv4_vtep
.ipaddr_v4
), &vtep_ip
->ipaddr_v4
,
1374 sizeof(struct in_addr
));
1376 /* remove nh from rmac's list */
1377 l3vni_rmac_nh_list_nh_delete(zl3vni
, zrmac
, &ipv4_vtep
);
1378 /* delete nh is same as current selected, fall back to
1379 * one present in the list
1381 if (IPV4_ADDR_SAME(&zrmac
->fwd_info
.r_vtep_ip
,
1382 &ipv4_vtep
.ipaddr_v4
) &&
1383 listcount(zrmac
->nh_list
)) {
1384 struct ipaddr
*vtep
;
1386 vtep
= listgetdata(listhead(zrmac
->nh_list
));
1387 zrmac
->fwd_info
.r_vtep_ip
= vtep
->ipaddr_v4
;
1388 if (IS_ZEBRA_DEBUG_VXLAN
)
1390 "L3VNI %u Remote VTEP nh change(%pIA -> %pI4) for RMAC %pEA",
1391 zl3vni
->vni
, &ipv4_vtep
,
1392 &zrmac
->fwd_info
.r_vtep_ip
,
1395 /* install rmac in kernel */
1396 zl3vni_rmac_install(zl3vni
, zrmac
);
1399 if (!listcount(zrmac
->nh_list
)) {
1400 /* uninstall from kernel */
1401 zl3vni_rmac_uninstall(zl3vni
, zrmac
);
1403 /* Send RMAC for FPM processing */
1404 hook_call(zebra_rmac_update
, zrmac
, zl3vni
, true,
1407 if (IS_ZEBRA_DEBUG_VXLAN
)
1409 "L3VNI %u RMAC %pEA vtep_ip %pIA delete",
1410 zl3vni
->vni
, &zrmac
->macaddr
, vtep_ip
);
1412 /* del the rmac entry */
1413 zl3vni_rmac_del(zl3vni
, zrmac
);
1419 * Look up nh hash entry on a l3-vni.
1421 static struct zebra_neigh
*zl3vni_nh_lookup(struct zebra_l3vni
*zl3vni
,
1422 const struct ipaddr
*ip
)
1424 struct zebra_neigh tmp
;
1425 struct zebra_neigh
*n
;
1427 memset(&tmp
, 0, sizeof(tmp
));
1428 memcpy(&tmp
.ip
, ip
, sizeof(struct ipaddr
));
1429 n
= hash_lookup(zl3vni
->nh_table
, &tmp
);
1436 * Callback to allocate NH hash entry on L3-VNI.
1438 static void *zl3vni_nh_alloc(void *p
)
1440 const struct zebra_neigh
*tmp_n
= p
;
1441 struct zebra_neigh
*n
;
1443 n
= XCALLOC(MTYPE_L3NEIGH
, sizeof(struct zebra_neigh
));
1450 * Add neighbor entry.
1452 static struct zebra_neigh
*zl3vni_nh_add(struct zebra_l3vni
*zl3vni
,
1453 const struct ipaddr
*ip
,
1454 const struct ethaddr
*mac
)
1456 struct zebra_neigh tmp_n
;
1457 struct zebra_neigh
*n
= NULL
;
1459 memset(&tmp_n
, 0, sizeof(tmp_n
));
1460 memcpy(&tmp_n
.ip
, ip
, sizeof(struct ipaddr
));
1461 n
= hash_get(zl3vni
->nh_table
, &tmp_n
, zl3vni_nh_alloc
);
1463 RB_INIT(host_rb_tree_entry
, &n
->host_rb
);
1465 memcpy(&n
->emac
, mac
, ETH_ALEN
);
1466 SET_FLAG(n
->flags
, ZEBRA_NEIGH_REMOTE
);
1467 SET_FLAG(n
->flags
, ZEBRA_NEIGH_REMOTE_NH
);
1473 * Delete neighbor entry.
1475 static int zl3vni_nh_del(struct zebra_l3vni
*zl3vni
, struct zebra_neigh
*n
)
1477 struct zebra_neigh
*tmp_n
;
1478 struct host_rb_entry
*hle
;
1480 while (!RB_EMPTY(host_rb_tree_entry
, &n
->host_rb
)) {
1481 hle
= RB_ROOT(host_rb_tree_entry
, &n
->host_rb
);
1483 RB_REMOVE(host_rb_tree_entry
, &n
->host_rb
, hle
);
1484 XFREE(MTYPE_HOST_PREFIX
, hle
);
1487 tmp_n
= hash_release(zl3vni
->nh_table
, n
);
1488 XFREE(MTYPE_L3NEIGH
, tmp_n
);
1494 * Install remote nh as neigh into the kernel.
1496 static int zl3vni_nh_install(struct zebra_l3vni
*zl3vni
, struct zebra_neigh
*n
)
1501 if (!is_l3vni_oper_up(zl3vni
))
1504 if (!(n
->flags
& ZEBRA_NEIGH_REMOTE
)
1505 || !(n
->flags
& ZEBRA_NEIGH_REMOTE_NH
))
1508 flags
= DPLANE_NTF_EXT_LEARNED
;
1509 if (n
->flags
& ZEBRA_NEIGH_ROUTER_FLAG
)
1510 flags
|= DPLANE_NTF_ROUTER
;
1512 dplane_rem_neigh_add(zl3vni
->svi_if
, &n
->ip
, &n
->emac
, flags
,
1513 false /*was_static*/);
1519 * Uninstall remote nh from the kernel.
1521 static int zl3vni_nh_uninstall(struct zebra_l3vni
*zl3vni
,
1522 struct zebra_neigh
*n
)
1524 if (!(n
->flags
& ZEBRA_NEIGH_REMOTE
)
1525 || !(n
->flags
& ZEBRA_NEIGH_REMOTE_NH
))
1528 if (!zl3vni
->svi_if
|| !if_is_operative(zl3vni
->svi_if
))
1531 dplane_rem_neigh_delete(zl3vni
->svi_if
, &n
->ip
);
1536 /* add remote vtep as a neigh entry */
1537 static int zl3vni_remote_nh_add(struct zebra_l3vni
*zl3vni
,
1538 const struct ipaddr
*vtep_ip
,
1539 const struct ethaddr
*rmac
,
1540 const struct prefix
*host_prefix
)
1542 struct zebra_neigh
*nh
= NULL
;
1544 /* Create the next hop entry, or update its mac, if necessary. */
1545 nh
= zl3vni_nh_lookup(zl3vni
, vtep_ip
);
1547 nh
= zl3vni_nh_add(zl3vni
, vtep_ip
, rmac
);
1550 "Failed to add NH %pIA as Neigh (RMAC %pEA L3-VNI %u prefix %pFX)",
1551 vtep_ip
, rmac
, zl3vni
->vni
, host_prefix
);
1555 /* install the nh neigh in kernel */
1556 zl3vni_nh_install(zl3vni
, nh
);
1557 } else if (memcmp(&nh
->emac
, rmac
, ETH_ALEN
) != 0) {
1558 if (IS_ZEBRA_DEBUG_VXLAN
)
1560 "L3VNI %u RMAC change(%pEA --> %pEA) for nexthop %pIA, prefix %pFX",
1561 zl3vni
->vni
, &nh
->emac
, rmac
, vtep_ip
,
1564 memcpy(&nh
->emac
, rmac
, ETH_ALEN
);
1565 /* install (update) the nh neigh in kernel */
1566 zl3vni_nh_install(zl3vni
, nh
);
1569 rb_find_or_add_host(&nh
->host_rb
, host_prefix
);
1574 /* handle nh neigh delete */
1575 static void zl3vni_remote_nh_del(struct zebra_l3vni
*zl3vni
,
1576 struct zebra_neigh
*nh
,
1577 struct prefix
*host_prefix
)
1579 rb_delete_host(&nh
->host_rb
, host_prefix
);
1581 if (RB_EMPTY(host_rb_tree_entry
, &nh
->host_rb
)) {
1582 /* uninstall from kernel */
1583 zl3vni_nh_uninstall(zl3vni
, nh
);
1585 /* delete the nh entry */
1586 zl3vni_nh_del(zl3vni
, nh
);
1590 /* handle neigh update from kernel - the only thing of interest is to
1591 * readd stale entries.
1593 static int zl3vni_local_nh_add_update(struct zebra_l3vni
*zl3vni
,
1594 struct ipaddr
*ip
, uint16_t state
)
1597 struct zebra_neigh
*n
= NULL
;
1599 n
= zl3vni_nh_lookup(zl3vni
, ip
);
1603 /* all next hop neigh are remote and installed by frr.
1604 * If the kernel has aged this entry, re-install.
1606 if (state
& NUD_STALE
)
1607 zl3vni_nh_install(zl3vni
, n
);
1612 /* handle neigh delete from kernel */
1613 static int zl3vni_local_nh_del(struct zebra_l3vni
*zl3vni
, struct ipaddr
*ip
)
1615 struct zebra_neigh
*n
= NULL
;
1617 n
= zl3vni_nh_lookup(zl3vni
, ip
);
1621 /* all next hop neigh are remote and installed by frr.
1622 * If we get an age out notification for these neigh entries, we have to
1625 zl3vni_nh_install(zl3vni
, n
);
1631 * Hash function for L3 VNI.
1633 static unsigned int l3vni_hash_keymake(const void *p
)
1635 const struct zebra_l3vni
*zl3vni
= p
;
1637 return jhash_1word(zl3vni
->vni
, 0);
1641 * Compare 2 L3 VNI hash entries.
1643 static bool l3vni_hash_cmp(const void *p1
, const void *p2
)
1645 const struct zebra_l3vni
*zl3vni1
= p1
;
1646 const struct zebra_l3vni
*zl3vni2
= p2
;
1648 return (zl3vni1
->vni
== zl3vni2
->vni
);
1652 * Callback to allocate L3 VNI hash entry.
1654 static void *zl3vni_alloc(void *p
)
1656 struct zebra_l3vni
*zl3vni
= NULL
;
1657 const struct zebra_l3vni
*tmp_l3vni
= p
;
1659 zl3vni
= XCALLOC(MTYPE_ZL3VNI
, sizeof(struct zebra_l3vni
));
1660 zl3vni
->vni
= tmp_l3vni
->vni
;
1661 return ((void *)zl3vni
);
1665 * Look up L3 VNI hash entry.
1667 struct zebra_l3vni
*zl3vni_lookup(vni_t vni
)
1669 struct zebra_l3vni tmp_l3vni
;
1670 struct zebra_l3vni
*zl3vni
= NULL
;
1672 memset(&tmp_l3vni
, 0, sizeof(tmp_l3vni
));
1673 tmp_l3vni
.vni
= vni
;
1674 zl3vni
= hash_lookup(zrouter
.l3vni_table
, &tmp_l3vni
);
1680 * Add L3 VNI hash entry.
1682 static struct zebra_l3vni
*zl3vni_add(vni_t vni
, vrf_id_t vrf_id
)
1684 struct zebra_l3vni tmp_zl3vni
;
1685 struct zebra_l3vni
*zl3vni
= NULL
;
1687 memset(&tmp_zl3vni
, 0, sizeof(tmp_zl3vni
));
1688 tmp_zl3vni
.vni
= vni
;
1690 zl3vni
= hash_get(zrouter
.l3vni_table
, &tmp_zl3vni
, zl3vni_alloc
);
1692 zl3vni
->vrf_id
= vrf_id
;
1693 zl3vni
->svi_if
= NULL
;
1694 zl3vni
->vxlan_if
= NULL
;
1695 zl3vni
->l2vnis
= list_new();
1696 zl3vni
->l2vnis
->cmp
= zebra_evpn_list_cmp
;
1698 /* Create hash table for remote RMAC */
1699 zl3vni
->rmac_table
= zebra_mac_db_create("Zebra L3-VNI RMAC-Table");
1701 /* Create hash table for neighbors */
1702 zl3vni
->nh_table
= zebra_neigh_db_create("Zebra L3-VNI next-hop table");
1708 * Delete L3 VNI hash entry.
1710 static int zl3vni_del(struct zebra_l3vni
*zl3vni
)
1712 struct zebra_l3vni
*tmp_zl3vni
;
1714 /* free the list of l2vnis */
1715 list_delete(&zl3vni
->l2vnis
);
1716 zl3vni
->l2vnis
= NULL
;
1718 /* Free the rmac table */
1719 hash_free(zl3vni
->rmac_table
);
1720 zl3vni
->rmac_table
= NULL
;
1722 /* Free the nh table */
1723 hash_free(zl3vni
->nh_table
);
1724 zl3vni
->nh_table
= NULL
;
1726 /* Free the VNI hash entry and allocated memory. */
1727 tmp_zl3vni
= hash_release(zrouter
.l3vni_table
, zl3vni
);
1728 XFREE(MTYPE_ZL3VNI
, tmp_zl3vni
);
1733 static int zl3vni_map_to_vxlan_if_ns(struct ns
*ns
,
1737 struct zebra_ns
*zns
= ns
->info
;
1738 struct zebra_l3vni
*zl3vni
= (struct zebra_l3vni
*)_zl3vni
;
1739 struct route_node
*rn
= NULL
;
1740 struct interface
*ifp
= NULL
;
1741 struct zebra_vrf
*zvrf
;
1743 zvrf
= zebra_vrf_get_evpn();
1747 /* loop through all vxlan-interface */
1748 for (rn
= route_top(zns
->if_table
); rn
; rn
= route_next(rn
)) {
1750 struct zebra_if
*zif
= NULL
;
1751 struct zebra_l2info_vxlan
*vxl
= NULL
;
1753 ifp
= (struct interface
*)rn
->info
;
1758 if (!zif
|| zif
->zif_type
!= ZEBRA_IF_VXLAN
)
1761 vxl
= &zif
->l2info
.vxl
;
1762 if (vxl
->vni
!= zl3vni
->vni
)
1765 /* link of VXLAN interface should be in zebra_evpn_vrf */
1766 if (zvrf
->zns
->ns_id
!= vxl
->link_nsid
) {
1767 if (IS_ZEBRA_DEBUG_VXLAN
)
1769 "Intf %s(%u) VNI %u, link not in same "
1770 "namespace than BGP EVPN core instance ",
1771 ifp
->name
, ifp
->ifindex
, vxl
->vni
);
1776 zl3vni
->local_vtep_ip
= vxl
->vtep_ip
;
1777 *_pifp
= (void *)ifp
;
1778 return NS_WALK_STOP
;
1781 return NS_WALK_CONTINUE
;
1784 struct interface
*zl3vni_map_to_vxlan_if(struct zebra_l3vni
*zl3vni
)
1786 struct interface
**p_ifp
;
1787 struct interface
*ifp
= NULL
;
1791 ns_walk_func(zl3vni_map_to_vxlan_if_ns
,
1792 (void *)zl3vni
, (void **)p_ifp
);
1796 struct interface
*zl3vni_map_to_svi_if(struct zebra_l3vni
*zl3vni
)
1798 struct zebra_if
*zif
= NULL
; /* zebra_if for vxlan_if */
1799 struct zebra_l2info_vxlan
*vxl
= NULL
; /* l2 info for vxlan_if */
1804 if (!zl3vni
->vxlan_if
)
1807 zif
= zl3vni
->vxlan_if
->info
;
1811 vxl
= &zif
->l2info
.vxl
;
1813 return zvni_map_to_svi(vxl
->access_vlan
, zif
->brslave_info
.br_if
);
1816 struct interface
*zl3vni_map_to_mac_vlan_if(struct zebra_l3vni
*zl3vni
)
1818 struct zebra_if
*zif
= NULL
; /* zebra_if for vxlan_if */
1823 if (!zl3vni
->vxlan_if
)
1826 zif
= zl3vni
->vxlan_if
->info
;
1830 return zebra_evpn_map_to_macvlan(zif
->brslave_info
.br_if
,
1835 struct zebra_l3vni
*zl3vni_from_vrf(vrf_id_t vrf_id
)
1837 struct zebra_vrf
*zvrf
= NULL
;
1839 zvrf
= zebra_vrf_lookup_by_id(vrf_id
);
1843 return zl3vni_lookup(zvrf
->l3vni
);
1846 static int zl3vni_from_svi_ns(struct ns
*ns
, void *_in_param
, void **_p_zl3vni
)
1848 struct zebra_ns
*zns
= ns
->info
;
1849 struct zebra_l3vni
**p_zl3vni
= (struct zebra_l3vni
**)_p_zl3vni
;
1850 struct zebra_from_svi_param
*in_param
=
1851 (struct zebra_from_svi_param
*)_in_param
;
1852 struct route_node
*rn
= NULL
;
1853 struct interface
*tmp_if
= NULL
;
1854 struct zebra_if
*zif
= NULL
;
1855 struct zebra_l2info_vxlan
*vxl
= NULL
;
1857 assert(in_param
&& p_zl3vni
);
1859 /* loop through all vxlan-interface */
1860 for (rn
= route_top(zns
->if_table
); rn
; rn
= route_next(rn
)) {
1861 tmp_if
= (struct interface
*)rn
->info
;
1865 if (!zif
|| zif
->zif_type
!= ZEBRA_IF_VXLAN
)
1867 if (!if_is_operative(tmp_if
))
1869 vxl
= &zif
->l2info
.vxl
;
1871 if (zif
->brslave_info
.br_if
!= in_param
->br_if
)
1874 if (!in_param
->bridge_vlan_aware
1875 || vxl
->access_vlan
== in_param
->vid
) {
1876 *p_zl3vni
= zl3vni_lookup(vxl
->vni
);
1877 return NS_WALK_STOP
;
1881 return NS_WALK_CONTINUE
;
1885 * Map SVI and associated bridge to a VNI. This is invoked upon getting
1886 * neighbor notifications, to see if they are of interest.
1888 static struct zebra_l3vni
*zl3vni_from_svi(struct interface
*ifp
,
1889 struct interface
*br_if
)
1891 struct zebra_l3vni
*zl3vni
= NULL
;
1892 struct zebra_if
*zif
= NULL
;
1893 struct zebra_l2info_bridge
*br
= NULL
;
1894 struct zebra_from_svi_param in_param
= {};
1895 struct zebra_l3vni
**p_zl3vni
;
1900 /* Make sure the linked interface is a bridge. */
1901 if (!IS_ZEBRA_IF_BRIDGE(br_if
))
1903 in_param
.br_if
= br_if
;
1905 /* Determine if bridge is VLAN-aware or not */
1908 br
= &zif
->l2info
.br
;
1909 in_param
.bridge_vlan_aware
= br
->vlan_aware
;
1910 if (in_param
.bridge_vlan_aware
) {
1911 struct zebra_l2info_vlan
*vl
;
1913 if (!IS_ZEBRA_IF_VLAN(ifp
))
1918 vl
= &zif
->l2info
.vl
;
1919 in_param
.vid
= vl
->vid
;
1922 /* See if this interface (or interface plus VLAN Id) maps to a VxLAN */
1923 /* TODO: Optimize with a hash. */
1927 ns_walk_func(zl3vni_from_svi_ns
, (void *)&in_param
, (void **)p_zl3vni
);
1931 vni_t
vni_id_from_svi(struct interface
*ifp
, struct interface
*br_if
)
1934 struct zebra_evpn
*zevpn
= NULL
;
1935 struct zebra_l3vni
*zl3vni
= NULL
;
1937 /* Check if an L3VNI belongs to this SVI interface.
1938 * If not, check if an L2VNI belongs to this SVI interface.
1940 zl3vni
= zl3vni_from_svi(ifp
, br_if
);
1944 zevpn
= zebra_evpn_from_svi(ifp
, br_if
);
1952 static inline void zl3vni_get_vrr_rmac(struct zebra_l3vni
*zl3vni
,
1953 struct ethaddr
*rmac
)
1958 if (!is_l3vni_oper_up(zl3vni
))
1961 if (zl3vni
->mac_vlan_if
&& if_is_operative(zl3vni
->mac_vlan_if
))
1962 memcpy(rmac
->octet
, zl3vni
->mac_vlan_if
->hw_addr
, ETH_ALEN
);
1966 * Inform BGP about l3-vni.
1968 static int zl3vni_send_add_to_client(struct zebra_l3vni
*zl3vni
)
1970 struct stream
*s
= NULL
;
1971 struct zserv
*client
= NULL
;
1972 struct ethaddr svi_rmac
, vrr_rmac
= {.octet
= {0} };
1973 struct zebra_vrf
*zvrf
;
1974 bool is_anycast_mac
= true;
1976 client
= zserv_find_client(ZEBRA_ROUTE_BGP
, 0);
1977 /* BGP may not be running. */
1981 zvrf
= zebra_vrf_lookup_by_id(zl3vni
->vrf_id
);
1984 /* get the svi and vrr rmac values */
1985 memset(&svi_rmac
, 0, sizeof(svi_rmac
));
1986 zl3vni_get_svi_rmac(zl3vni
, &svi_rmac
);
1987 zl3vni_get_vrr_rmac(zl3vni
, &vrr_rmac
);
1989 /* In absence of vrr mac use svi mac as anycast MAC value */
1990 if (is_zero_mac(&vrr_rmac
)) {
1991 memcpy(&vrr_rmac
, &svi_rmac
, ETH_ALEN
);
1992 is_anycast_mac
= false;
1995 s
= stream_new(ZEBRA_MAX_PACKET_SIZ
);
1997 /* The message is used for both vni add and/or update like
1998 * vrr mac is added for l3vni SVI.
2000 zclient_create_header(s
, ZEBRA_L3VNI_ADD
, zl3vni_vrf_id(zl3vni
));
2001 stream_putl(s
, zl3vni
->vni
);
2002 stream_put(s
, &svi_rmac
, sizeof(struct ethaddr
));
2003 stream_put_in_addr(s
, &zl3vni
->local_vtep_ip
);
2004 stream_put(s
, &zl3vni
->filter
, sizeof(int));
2005 stream_putl(s
, zl3vni
->svi_if
->ifindex
);
2006 stream_put(s
, &vrr_rmac
, sizeof(struct ethaddr
));
2007 stream_putl(s
, is_anycast_mac
);
2009 /* Write packet size. */
2010 stream_putw_at(s
, 0, stream_get_endp(s
));
2012 if (IS_ZEBRA_DEBUG_VXLAN
)
2014 "Send L3_VNI_ADD %u VRF %s RMAC %pEA VRR %pEA local-ip %pI4 filter %s to %s",
2015 zl3vni
->vni
, vrf_id_to_name(zl3vni_vrf_id(zl3vni
)),
2016 &svi_rmac
, &vrr_rmac
, &zl3vni
->local_vtep_ip
,
2017 CHECK_FLAG(zl3vni
->filter
, PREFIX_ROUTES_ONLY
)
2018 ? "prefix-routes-only"
2020 zebra_route_string(client
->proto
));
2022 client
->l3vniadd_cnt
++;
2023 return zserv_send_message(client
, s
);
2027 * Inform BGP about local l3-VNI deletion.
2029 static int zl3vni_send_del_to_client(struct zebra_l3vni
*zl3vni
)
2031 struct stream
*s
= NULL
;
2032 struct zserv
*client
= NULL
;
2034 client
= zserv_find_client(ZEBRA_ROUTE_BGP
, 0);
2035 /* BGP may not be running. */
2039 s
= stream_new(ZEBRA_MAX_PACKET_SIZ
);
2041 zclient_create_header(s
, ZEBRA_L3VNI_DEL
, zl3vni_vrf_id(zl3vni
));
2042 stream_putl(s
, zl3vni
->vni
);
2044 /* Write packet size. */
2045 stream_putw_at(s
, 0, stream_get_endp(s
));
2047 if (IS_ZEBRA_DEBUG_VXLAN
)
2048 zlog_debug("Send L3_VNI_DEL %u VRF %s to %s", zl3vni
->vni
,
2049 vrf_id_to_name(zl3vni_vrf_id(zl3vni
)),
2050 zebra_route_string(client
->proto
));
2052 client
->l3vnidel_cnt
++;
2053 return zserv_send_message(client
, s
);
2056 static void zebra_vxlan_process_l3vni_oper_up(struct zebra_l3vni
*zl3vni
)
2061 /* send l3vni add to BGP */
2062 zl3vni_send_add_to_client(zl3vni
);
2065 static void zebra_vxlan_process_l3vni_oper_down(struct zebra_l3vni
*zl3vni
)
2070 /* send l3-vni del to BGP*/
2071 zl3vni_send_del_to_client(zl3vni
);
2074 static void zevpn_add_to_l3vni_list(struct hash_bucket
*bucket
, void *ctxt
)
2076 struct zebra_evpn
*zevpn
= (struct zebra_evpn
*)bucket
->data
;
2077 struct zebra_l3vni
*zl3vni
= (struct zebra_l3vni
*)ctxt
;
2079 if (zevpn
->vrf_id
== zl3vni_vrf_id(zl3vni
))
2080 listnode_add_sort(zl3vni
->l2vnis
, zevpn
);
2084 * Handle transition of vni from l2 to l3 and vice versa.
2085 * This function handles only the L2VNI add/delete part of
2086 * the above transition.
2087 * L3VNI add/delete is handled by the calling functions.
2089 static int zebra_vxlan_handle_vni_transition(struct zebra_vrf
*zvrf
, vni_t vni
,
2092 struct zebra_evpn
*zevpn
= NULL
;
2093 struct zebra_l3vni
*zl3vni
= NULL
;
2095 /* There is a possibility that VNI notification was already received
2096 * from kernel and we programmed it as L2-VNI
2097 * In such a case we need to delete this L2-VNI first, so
2098 * that it can be reprogrammed as L3-VNI in the system. It is also
2099 * possible that the vrf-vni mapping is removed from FRR while the vxlan
2100 * interface is still present in kernel. In this case to keep it
2101 * symmetric, we will delete the l3-vni and reprogram it as l2-vni
2104 /* Locate hash entry */
2105 zevpn
= zebra_evpn_lookup(vni
);
2109 if (IS_ZEBRA_DEBUG_VXLAN
)
2110 zlog_debug("Del L2-VNI %u - transition to L3-VNI", vni
);
2112 /* Delete EVPN from BGP. */
2113 zebra_evpn_send_del_to_client(zevpn
);
2115 zebra_evpn_neigh_del_all(zevpn
, 0, 0, DEL_ALL_NEIGH
);
2116 zebra_evpn_mac_del_all(zevpn
, 0, 0, DEL_ALL_MAC
);
2118 /* Free up all remote VTEPs, if any. */
2119 zebra_evpn_vtep_del_all(zevpn
, 1);
2121 zl3vni
= zl3vni_from_vrf(zevpn
->vrf_id
);
2123 listnode_delete(zl3vni
->l2vnis
, zevpn
);
2125 /* Delete the hash entry. */
2126 if (zebra_evpn_vxlan_del(zevpn
)) {
2127 flog_err(EC_ZEBRA_VNI_DEL_FAILED
,
2128 "Failed to del EVPN hash %p, VNI %u", zevpn
,
2133 struct zebra_ns
*zns
;
2134 struct route_node
*rn
;
2135 struct interface
*ifp
;
2136 struct zebra_if
*zif
;
2137 struct zebra_l2info_vxlan
*vxl
;
2138 struct interface
*vlan_if
;
2141 if (IS_ZEBRA_DEBUG_VXLAN
)
2142 zlog_debug("Adding L2-VNI %u - transition from L3-VNI",
2145 /* Find VxLAN interface for this VNI. */
2146 zns
= zebra_ns_lookup(NS_DEFAULT
);
2147 for (rn
= route_top(zns
->if_table
); rn
; rn
= route_next(rn
)) {
2148 ifp
= (struct interface
*)rn
->info
;
2152 if (!zif
|| zif
->zif_type
!= ZEBRA_IF_VXLAN
)
2155 vxl
= &zif
->l2info
.vxl
;
2156 if (vxl
->vni
== vni
) {
2163 if (IS_ZEBRA_DEBUG_VXLAN
)
2165 "Adding L2-VNI - Failed to find VxLAN interface for VNI %u",
2170 /* Create VNI hash entry for L2VNI */
2171 zevpn
= zebra_evpn_lookup(vni
);
2175 zevpn
= zebra_evpn_add(vni
);
2177 /* Find bridge interface for the VNI */
2178 vlan_if
= zvni_map_to_svi(vxl
->access_vlan
,
2179 zif
->brslave_info
.br_if
);
2181 zevpn
->vrf_id
= vlan_if
->vrf
->vrf_id
;
2182 zl3vni
= zl3vni_from_vrf(vlan_if
->vrf
->vrf_id
);
2184 listnode_add_sort_nodup(zl3vni
->l2vnis
, zevpn
);
2187 zevpn
->vxlan_if
= ifp
;
2188 zevpn
->local_vtep_ip
= vxl
->vtep_ip
;
2190 /* Inform BGP if the VNI is up and mapped to a bridge. */
2191 if (if_is_operative(ifp
) && zif
->brslave_info
.br_if
) {
2192 zebra_evpn_send_add_to_client(zevpn
);
2193 zebra_evpn_read_mac_neigh(zevpn
, ifp
);
2200 /* delete and uninstall rmac hash entry */
2201 static void zl3vni_del_rmac_hash_entry(struct hash_bucket
*bucket
, void *ctx
)
2203 struct zebra_mac
*zrmac
= NULL
;
2204 struct zebra_l3vni
*zl3vni
= NULL
;
2206 zrmac
= (struct zebra_mac
*)bucket
->data
;
2207 zl3vni
= (struct zebra_l3vni
*)ctx
;
2208 zl3vni_rmac_uninstall(zl3vni
, zrmac
);
2210 /* Send RMAC for FPM processing */
2211 hook_call(zebra_rmac_update
, zrmac
, zl3vni
, true, "RMAC deleted");
2213 zl3vni_rmac_del(zl3vni
, zrmac
);
2216 /* delete and uninstall nh hash entry */
2217 static void zl3vni_del_nh_hash_entry(struct hash_bucket
*bucket
, void *ctx
)
2219 struct zebra_neigh
*n
= NULL
;
2220 struct zebra_l3vni
*zl3vni
= NULL
;
2222 n
= (struct zebra_neigh
*)bucket
->data
;
2223 zl3vni
= (struct zebra_l3vni
*)ctx
;
2224 zl3vni_nh_uninstall(zl3vni
, n
);
2225 zl3vni_nh_del(zl3vni
, n
);
2228 /* re-add remote rmac if needed */
2229 static int zebra_vxlan_readd_remote_rmac(struct zebra_l3vni
*zl3vni
,
2230 struct ethaddr
*rmac
)
2232 struct zebra_mac
*zrmac
= NULL
;
2234 zrmac
= zl3vni_rmac_lookup(zl3vni
, rmac
);
2238 if (IS_ZEBRA_DEBUG_VXLAN
)
2239 zlog_debug("Del remote RMAC %pEA L3VNI %u - readd",
2242 zl3vni_rmac_install(zl3vni
, zrmac
);
2246 /* Public functions */
2248 int is_l3vni_for_prefix_routes_only(vni_t vni
)
2250 struct zebra_l3vni
*zl3vni
= NULL
;
2252 zl3vni
= zl3vni_lookup(vni
);
2256 return CHECK_FLAG(zl3vni
->filter
, PREFIX_ROUTES_ONLY
) ? 1 : 0;
2259 /* handle evpn route in vrf table */
2260 void zebra_vxlan_evpn_vrf_route_add(vrf_id_t vrf_id
, const struct ethaddr
*rmac
,
2261 const struct ipaddr
*vtep_ip
,
2262 const struct prefix
*host_prefix
)
2264 struct zebra_l3vni
*zl3vni
= NULL
;
2265 struct ipaddr ipv4_vtep
;
2267 zl3vni
= zl3vni_from_vrf(vrf_id
);
2268 if (!zl3vni
|| !is_l3vni_oper_up(zl3vni
))
2272 * add the next hop neighbor -
2273 * neigh to be installed is the ipv6 nexthop neigh
2275 zl3vni_remote_nh_add(zl3vni
, vtep_ip
, rmac
, host_prefix
);
2278 * if the remote vtep is a ipv4 mapped ipv6 address convert it to ipv4
2279 * address. Rmac is programmed against the ipv4 vtep because we only
2280 * support ipv4 tunnels in the h/w right now
2282 memset(&ipv4_vtep
, 0, sizeof(ipv4_vtep
));
2283 ipv4_vtep
.ipa_type
= IPADDR_V4
;
2284 if (vtep_ip
->ipa_type
== IPADDR_V6
)
2285 ipv4_mapped_ipv6_to_ipv4(&vtep_ip
->ipaddr_v6
,
2286 &(ipv4_vtep
.ipaddr_v4
));
2288 memcpy(&(ipv4_vtep
.ipaddr_v4
), &vtep_ip
->ipaddr_v4
,
2289 sizeof(struct in_addr
));
2292 * add the rmac - remote rmac to be installed is against the ipv4
2295 zl3vni_remote_rmac_add(zl3vni
, rmac
, &ipv4_vtep
);
2298 /* handle evpn vrf route delete */
2299 void zebra_vxlan_evpn_vrf_route_del(vrf_id_t vrf_id
,
2300 struct ipaddr
*vtep_ip
,
2301 struct prefix
*host_prefix
)
2303 struct zebra_l3vni
*zl3vni
= NULL
;
2304 struct zebra_neigh
*nh
= NULL
;
2305 struct zebra_mac
*zrmac
= NULL
;
2307 zl3vni
= zl3vni_from_vrf(vrf_id
);
2311 /* find the next hop entry and rmac entry */
2312 nh
= zl3vni_nh_lookup(zl3vni
, vtep_ip
);
2315 zrmac
= zl3vni_rmac_lookup(zl3vni
, &nh
->emac
);
2317 /* delete the next hop entry */
2318 zl3vni_remote_nh_del(zl3vni
, nh
, host_prefix
);
2320 /* delete the rmac entry */
2322 zl3vni_remote_rmac_del(zl3vni
, zrmac
, vtep_ip
);
2325 void zebra_vxlan_print_specific_rmac_l3vni(struct vty
*vty
, vni_t l3vni
,
2326 struct ethaddr
*rmac
, bool use_json
)
2328 struct zebra_l3vni
*zl3vni
= NULL
;
2329 struct zebra_mac
*zrmac
= NULL
;
2330 json_object
*json
= NULL
;
2332 if (!is_evpn_enabled()) {
2334 vty_out(vty
, "{}\n");
2339 json
= json_object_new_object();
2341 zl3vni
= zl3vni_lookup(l3vni
);
2344 vty_out(vty
, "{}\n");
2346 vty_out(vty
, "%% L3-VNI %u doesn't exist\n", l3vni
);
2350 zrmac
= zl3vni_rmac_lookup(zl3vni
, rmac
);
2353 vty_out(vty
, "{}\n");
2356 "%% Requested RMAC doesn't exist in L3-VNI %u\n",
2361 zl3vni_print_rmac(zrmac
, vty
, json
);
2364 vty_json(vty
, json
);
2367 void zebra_vxlan_print_rmacs_l3vni(struct vty
*vty
, vni_t l3vni
, bool use_json
)
2369 struct zebra_l3vni
*zl3vni
;
2371 struct rmac_walk_ctx wctx
;
2372 json_object
*json
= NULL
;
2374 if (!is_evpn_enabled())
2377 zl3vni
= zl3vni_lookup(l3vni
);
2380 vty_out(vty
, "{}\n");
2382 vty_out(vty
, "%% L3-VNI %u does not exist\n", l3vni
);
2385 num_rmacs
= hashcount(zl3vni
->rmac_table
);
2390 json
= json_object_new_object();
2392 memset(&wctx
, 0, sizeof(wctx
));
2396 vty_out(vty
, "Number of Remote RMACs known for this VNI: %u\n",
2398 vty_out(vty
, "%-17s %-21s\n", "MAC", "Remote VTEP");
2400 json_object_int_add(json
, "numRmacs", num_rmacs
);
2402 hash_iterate(zl3vni
->rmac_table
, zl3vni_print_rmac_hash
, &wctx
);
2405 vty_json(vty
, json
);
2408 void zebra_vxlan_print_rmacs_all_l3vni(struct vty
*vty
, bool use_json
)
2410 json_object
*json
= NULL
;
2413 if (!is_evpn_enabled()) {
2415 vty_out(vty
, "{}\n");
2420 json
= json_object_new_object();
2424 hash_iterate(zrouter
.l3vni_table
,
2425 (void (*)(struct hash_bucket
*,
2426 void *))zl3vni_print_rmac_hash_all_vni
,
2430 vty_json(vty
, json
);
2433 void zebra_vxlan_print_specific_nh_l3vni(struct vty
*vty
, vni_t l3vni
,
2434 struct ipaddr
*ip
, bool use_json
)
2436 struct zebra_l3vni
*zl3vni
= NULL
;
2437 struct zebra_neigh
*n
= NULL
;
2438 json_object
*json
= NULL
;
2440 if (!is_evpn_enabled()) {
2442 vty_out(vty
, "{}\n");
2447 json
= json_object_new_object();
2449 zl3vni
= zl3vni_lookup(l3vni
);
2452 vty_out(vty
, "{}\n");
2454 vty_out(vty
, "%% L3-VNI %u does not exist\n", l3vni
);
2458 n
= zl3vni_nh_lookup(zl3vni
, ip
);
2461 vty_out(vty
, "{}\n");
2464 "%% Requested next-hop not present for L3-VNI %u",
2469 zl3vni_print_nh(n
, vty
, json
);
2472 vty_json(vty
, json
);
2475 void zebra_vxlan_print_nh_l3vni(struct vty
*vty
, vni_t l3vni
, bool use_json
)
2478 struct nh_walk_ctx wctx
;
2479 json_object
*json
= NULL
;
2480 struct zebra_l3vni
*zl3vni
= NULL
;
2482 if (!is_evpn_enabled())
2485 zl3vni
= zl3vni_lookup(l3vni
);
2488 vty_out(vty
, "{}\n");
2490 vty_out(vty
, "%% L3-VNI %u does not exist\n", l3vni
);
2494 num_nh
= hashcount(zl3vni
->nh_table
);
2499 json
= json_object_new_object();
2504 vty_out(vty
, "Number of NH Neighbors known for this VNI: %u\n",
2506 vty_out(vty
, "%-15s %-17s\n", "IP", "RMAC");
2508 json_object_int_add(json
, "numNextHops", num_nh
);
2510 hash_iterate(zl3vni
->nh_table
, zl3vni_print_nh_hash
, &wctx
);
2513 vty_json(vty
, json
);
2516 void zebra_vxlan_print_nh_all_l3vni(struct vty
*vty
, bool use_json
)
2518 json_object
*json
= NULL
;
2521 if (!is_evpn_enabled()) {
2523 vty_out(vty
, "{}\n");
2528 json
= json_object_new_object();
2532 hash_iterate(zrouter
.l3vni_table
,
2533 (void (*)(struct hash_bucket
*,
2534 void *))zl3vni_print_nh_hash_all_vni
,
2538 vty_json(vty
, json
);
2542 * Display L3 VNI information (VTY command handler).
2544 void zebra_vxlan_print_l3vni(struct vty
*vty
, vni_t vni
, bool use_json
)
2547 json_object
*json
= NULL
;
2548 struct zebra_l3vni
*zl3vni
= NULL
;
2550 if (!is_evpn_enabled()) {
2552 vty_out(vty
, "{}\n");
2556 zl3vni
= zl3vni_lookup(vni
);
2559 vty_out(vty
, "{}\n");
2561 vty_out(vty
, "%% VNI %u does not exist\n", vni
);
2566 json
= json_object_new_object();
2570 zl3vni_print(zl3vni
, (void *)args
);
2573 vty_json(vty
, json
);
2576 void zebra_vxlan_print_vrf_vni(struct vty
*vty
, struct zebra_vrf
*zvrf
,
2577 json_object
*json_vrfs
)
2579 char buf
[ETHER_ADDR_STRLEN
];
2580 struct zebra_l3vni
*zl3vni
= NULL
;
2582 zl3vni
= zl3vni_lookup(zvrf
->l3vni
);
2587 vty_out(vty
, "%-37s %-10u %-20s %-20s %-5s %-18s\n",
2588 zvrf_name(zvrf
), zl3vni
->vni
,
2589 zl3vni_vxlan_if_name(zl3vni
),
2590 zl3vni_svi_if_name(zl3vni
), zl3vni_state2str(zl3vni
),
2591 zl3vni_rmac2str(zl3vni
, buf
, sizeof(buf
)));
2593 json_object
*json_vrf
= NULL
;
2595 json_vrf
= json_object_new_object();
2596 json_object_string_add(json_vrf
, "vrf", zvrf_name(zvrf
));
2597 json_object_int_add(json_vrf
, "vni", zl3vni
->vni
);
2598 json_object_string_add(json_vrf
, "vxlanIntf",
2599 zl3vni_vxlan_if_name(zl3vni
));
2600 json_object_string_add(json_vrf
, "sviIntf",
2601 zl3vni_svi_if_name(zl3vni
));
2602 json_object_string_add(json_vrf
, "state",
2603 zl3vni_state2str(zl3vni
));
2604 json_object_string_add(
2605 json_vrf
, "routerMac",
2606 zl3vni_rmac2str(zl3vni
, buf
, sizeof(buf
)));
2607 json_object_array_add(json_vrfs
, json_vrf
);
2612 * Display Neighbors for a VNI (VTY command handler).
2614 void zebra_vxlan_print_neigh_vni(struct vty
*vty
, struct zebra_vrf
*zvrf
,
2615 vni_t vni
, bool use_json
)
2617 struct zebra_evpn
*zevpn
;
2619 struct neigh_walk_ctx wctx
;
2620 json_object
*json
= NULL
;
2622 if (!is_evpn_enabled())
2624 zevpn
= zebra_evpn_lookup(vni
);
2627 vty_out(vty
, "{}\n");
2629 vty_out(vty
, "%% VNI %u does not exist\n", vni
);
2632 num_neigh
= hashcount(zevpn
->neigh_table
);
2637 json
= json_object_new_object();
2639 /* Since we have IPv6 addresses to deal with which can vary widely in
2640 * size, we try to be a bit more elegant in display by first computing
2641 * the maximum width.
2643 memset(&wctx
, 0, sizeof(wctx
));
2646 wctx
.addr_width
= 15;
2648 hash_iterate(zevpn
->neigh_table
, zebra_evpn_find_neigh_addr_width
,
2653 "Number of ARPs (local and remote) known for this VNI: %u\n",
2655 zebra_evpn_print_neigh_hdr(vty
, &wctx
);
2657 json_object_int_add(json
, "numArpNd", num_neigh
);
2659 hash_iterate(zevpn
->neigh_table
, zebra_evpn_print_neigh_hash
, &wctx
);
2661 vty_json(vty
, json
);
2665 * Display neighbors across all VNIs (VTY command handler).
2667 void zebra_vxlan_print_neigh_all_vni(struct vty
*vty
, struct zebra_vrf
*zvrf
,
2668 bool print_dup
, bool use_json
)
2670 json_object
*json
= NULL
;
2673 if (!is_evpn_enabled())
2677 json
= json_object_new_object();
2681 args
[2] = (void *)(ptrdiff_t)print_dup
;
2683 hash_iterate(zvrf
->evpn_table
,
2684 (void (*)(struct hash_bucket
*,
2685 void *))zevpn_print_neigh_hash_all_evpn
,
2688 vty_json(vty
, json
);
2692 * Display neighbors across all VNIs in detail(VTY command handler).
2694 void zebra_vxlan_print_neigh_all_vni_detail(struct vty
*vty
,
2695 struct zebra_vrf
*zvrf
,
2696 bool print_dup
, bool use_json
)
2698 json_object
*json
= NULL
;
2701 if (!is_evpn_enabled())
2705 json
= json_object_new_object();
2709 args
[2] = (void *)(ptrdiff_t)print_dup
;
2711 hash_iterate(zvrf
->evpn_table
,
2712 (void (*)(struct hash_bucket
*,
2713 void *))zevpn_print_neigh_hash_all_evpn_detail
,
2716 vty_json(vty
, json
);
2720 * Display specific neighbor for a VNI, if present (VTY command handler).
2722 void zebra_vxlan_print_specific_neigh_vni(struct vty
*vty
,
2723 struct zebra_vrf
*zvrf
, vni_t vni
,
2724 struct ipaddr
*ip
, bool use_json
)
2726 struct zebra_evpn
*zevpn
;
2727 struct zebra_neigh
*n
;
2728 json_object
*json
= NULL
;
2730 if (!is_evpn_enabled())
2732 zevpn
= zebra_evpn_lookup(vni
);
2735 vty_out(vty
, "{}\n");
2737 vty_out(vty
, "%% VNI %u does not exist\n", vni
);
2740 n
= zebra_evpn_neigh_lookup(zevpn
, ip
);
2744 "%% Requested neighbor does not exist in VNI %u\n",
2749 json
= json_object_new_object();
2751 zebra_evpn_print_neigh(n
, vty
, json
);
2754 vty_json(vty
, json
);
2758 * Display neighbors for a VNI from specific VTEP (VTY command handler).
2759 * By definition, these are remote neighbors.
2761 void zebra_vxlan_print_neigh_vni_vtep(struct vty
*vty
, struct zebra_vrf
*zvrf
,
2762 vni_t vni
, struct in_addr vtep_ip
,
2765 struct zebra_evpn
*zevpn
;
2767 struct neigh_walk_ctx wctx
;
2768 json_object
*json
= NULL
;
2770 if (!is_evpn_enabled())
2772 zevpn
= zebra_evpn_lookup(vni
);
2775 vty_out(vty
, "{}\n");
2777 vty_out(vty
, "%% VNI %u does not exist\n", vni
);
2780 num_neigh
= hashcount(zevpn
->neigh_table
);
2785 json
= json_object_new_object();
2787 memset(&wctx
, 0, sizeof(wctx
));
2790 wctx
.addr_width
= 15;
2791 wctx
.flags
= SHOW_REMOTE_NEIGH_FROM_VTEP
;
2792 wctx
.r_vtep_ip
= vtep_ip
;
2794 hash_iterate(zevpn
->neigh_table
, zebra_evpn_find_neigh_addr_width
,
2796 hash_iterate(zevpn
->neigh_table
, zebra_evpn_print_neigh_hash
, &wctx
);
2799 vty_json(vty
, json
);
2803 * Display Duplicate detected Neighbors for a VNI
2804 * (VTY command handler).
2806 void zebra_vxlan_print_neigh_vni_dad(struct vty
*vty
,
2807 struct zebra_vrf
*zvrf
,
2811 struct zebra_evpn
*zevpn
;
2813 struct neigh_walk_ctx wctx
;
2814 json_object
*json
= NULL
;
2816 if (!is_evpn_enabled())
2819 zevpn
= zebra_evpn_lookup(vni
);
2821 vty_out(vty
, "%% VNI %u does not exist\n", vni
);
2825 num_neigh
= hashcount(zevpn
->neigh_table
);
2829 num_neigh
= num_dup_detected_neighs(zevpn
);
2834 json
= json_object_new_object();
2836 /* Since we have IPv6 addresses to deal with which can vary widely in
2837 * size, we try to be a bit more elegant in display by first computing
2838 * the maximum width.
2840 memset(&wctx
, 0, sizeof(wctx
));
2843 wctx
.addr_width
= 15;
2845 hash_iterate(zevpn
->neigh_table
, zebra_evpn_find_neigh_addr_width
,
2850 "Number of ARPs (local and remote) known for this VNI: %u\n",
2852 vty_out(vty
, "%*s %-6s %-8s %-17s %-30s\n",
2853 -wctx
.addr_width
, "IP", "Type",
2854 "State", "MAC", "Remote ES/VTEP");
2856 json_object_int_add(json
, "numArpNd", num_neigh
);
2858 hash_iterate(zevpn
->neigh_table
, zebra_evpn_print_dad_neigh_hash
,
2862 vty_json(vty
, json
);
2866 * Display MACs for a VNI (VTY command handler).
2868 void zebra_vxlan_print_macs_vni(struct vty
*vty
, struct zebra_vrf
*zvrf
,
2869 vni_t vni
, bool use_json
)
2871 struct zebra_evpn
*zevpn
;
2873 struct mac_walk_ctx wctx
;
2874 json_object
*json
= NULL
;
2875 json_object
*json_mac
= NULL
;
2877 if (!is_evpn_enabled())
2879 zevpn
= zebra_evpn_lookup(vni
);
2882 vty_out(vty
, "{}\n");
2884 vty_out(vty
, "%% VNI %u does not exist\n", vni
);
2887 num_macs
= num_valid_macs(zevpn
);
2892 json
= json_object_new_object();
2893 json_mac
= json_object_new_object();
2896 memset(&wctx
, 0, sizeof(wctx
));
2899 wctx
.json
= json_mac
;
2903 "Number of MACs (local and remote) known for this VNI: %u\n",
2906 "Flags: N=sync-neighs, I=local-inactive, P=peer-active, X=peer-proxy\n");
2907 vty_out(vty
, "%-17s %-6s %-5s %-30s %-5s %s\n", "MAC", "Type",
2908 "Flags", "Intf/Remote ES/VTEP", "VLAN", "Seq #'s");
2910 json_object_int_add(json
, "numMacs", num_macs
);
2912 hash_iterate(zevpn
->mac_table
, zebra_evpn_print_mac_hash
, &wctx
);
2915 json_object_object_add(json
, "macs", json_mac
);
2916 vty_json(vty
, json
);
2921 * Display MACs for all VNIs (VTY command handler).
2923 void zebra_vxlan_print_macs_all_vni(struct vty
*vty
, struct zebra_vrf
*zvrf
,
2924 bool print_dup
, bool use_json
)
2926 struct mac_walk_ctx wctx
;
2927 json_object
*json
= NULL
;
2929 if (!is_evpn_enabled()) {
2931 vty_out(vty
, "{}\n");
2935 json
= json_object_new_object();
2937 memset(&wctx
, 0, sizeof(wctx
));
2940 wctx
.print_dup
= print_dup
;
2941 hash_iterate(zvrf
->evpn_table
, zevpn_print_mac_hash_all_evpn
, &wctx
);
2944 vty_json(vty
, json
);
2948 * Display MACs in detail for all VNIs (VTY command handler).
2950 void zebra_vxlan_print_macs_all_vni_detail(struct vty
*vty
,
2951 struct zebra_vrf
*zvrf
,
2952 bool print_dup
, bool use_json
)
2954 struct mac_walk_ctx wctx
;
2955 json_object
*json
= NULL
;
2957 if (!is_evpn_enabled()) {
2959 vty_out(vty
, "{}\n");
2963 json
= json_object_new_object();
2965 memset(&wctx
, 0, sizeof(wctx
));
2968 wctx
.print_dup
= print_dup
;
2969 hash_iterate(zvrf
->evpn_table
, zevpn_print_mac_hash_all_evpn_detail
,
2973 vty_json(vty
, json
);
2977 * Display MACs for all VNIs (VTY command handler).
2979 void zebra_vxlan_print_macs_all_vni_vtep(struct vty
*vty
,
2980 struct zebra_vrf
*zvrf
,
2981 struct in_addr vtep_ip
, bool use_json
)
2983 struct mac_walk_ctx wctx
;
2984 json_object
*json
= NULL
;
2986 if (!is_evpn_enabled())
2990 json
= json_object_new_object();
2992 memset(&wctx
, 0, sizeof(wctx
));
2994 wctx
.flags
= SHOW_REMOTE_MAC_FROM_VTEP
;
2995 wctx
.r_vtep_ip
= vtep_ip
;
2997 hash_iterate(zvrf
->evpn_table
, zevpn_print_mac_hash_all_evpn
, &wctx
);
3000 vty_json(vty
, json
);
3004 * Display specific MAC for a VNI, if present (VTY command handler).
3006 void zebra_vxlan_print_specific_mac_vni(struct vty
*vty
, struct zebra_vrf
*zvrf
,
3007 vni_t vni
, struct ethaddr
*macaddr
,
3010 struct zebra_evpn
*zevpn
;
3011 struct zebra_mac
*mac
;
3012 json_object
*json
= NULL
;
3014 if (!is_evpn_enabled())
3017 zevpn
= zebra_evpn_lookup(vni
);
3020 vty_out(vty
, "{}\n");
3022 vty_out(vty
, "%% VNI %u does not exist\n", vni
);
3025 mac
= zebra_evpn_mac_lookup(zevpn
, macaddr
);
3028 vty_out(vty
, "{}\n");
3031 "%% Requested MAC does not exist in VNI %u\n",
3037 json
= json_object_new_object();
3039 zebra_evpn_print_mac(mac
, vty
, json
);
3041 vty_json(vty
, json
);
3044 /* Print Duplicate MACs per VNI */
3045 void zebra_vxlan_print_macs_vni_dad(struct vty
*vty
,
3046 struct zebra_vrf
*zvrf
,
3047 vni_t vni
, bool use_json
)
3049 struct zebra_evpn
*zevpn
;
3050 struct mac_walk_ctx wctx
;
3052 json_object
*json
= NULL
;
3053 json_object
*json_mac
= NULL
;
3055 if (!is_evpn_enabled())
3058 zevpn
= zebra_evpn_lookup(vni
);
3060 vty_out(vty
, "%% VNI %u does not exist\n", vni
);
3064 num_macs
= num_valid_macs(zevpn
);
3068 num_macs
= num_dup_detected_macs(zevpn
);
3073 json
= json_object_new_object();
3074 json_mac
= json_object_new_object();
3077 memset(&wctx
, 0, sizeof(wctx
));
3080 wctx
.json
= json_mac
;
3084 "Number of MACs (local and remote) known for this VNI: %u\n",
3086 vty_out(vty
, "%-17s %-6s %-5s %-30s %-5s\n", "MAC", "Type",
3087 "Flags", "Intf/Remote ES/VTEP", "VLAN");
3089 json_object_int_add(json
, "numMacs", num_macs
);
3091 hash_iterate(zevpn
->mac_table
, zebra_evpn_print_dad_mac_hash
, &wctx
);
3094 json_object_object_add(json
, "macs", json_mac
);
3095 vty_json(vty
, json
);
3100 int zebra_vxlan_clear_dup_detect_vni_mac(struct zebra_vrf
*zvrf
, vni_t vni
,
3101 struct ethaddr
*macaddr
, char *errmsg
,
3104 struct zebra_evpn
*zevpn
;
3105 struct zebra_mac
*mac
;
3106 struct listnode
*node
= NULL
;
3107 struct zebra_neigh
*nbr
= NULL
;
3109 if (!is_evpn_enabled())
3112 zevpn
= zebra_evpn_lookup(vni
);
3114 snprintfrr(errmsg
, errmsg_len
, "VNI %u does not exist", vni
);
3118 mac
= zebra_evpn_mac_lookup(zevpn
, macaddr
);
3120 snprintf(errmsg
, errmsg_len
,
3121 "Requested MAC does not exist in VNI %u\n", vni
);
3125 if (!CHECK_FLAG(mac
->flags
, ZEBRA_MAC_DUPLICATE
)) {
3126 snprintfrr(errmsg
, errmsg_len
,
3127 "Requested MAC is not duplicate detected\n");
3131 /* Remove all IPs as duplicate associcated with this MAC */
3132 for (ALL_LIST_ELEMENTS_RO(mac
->neigh_list
, node
, nbr
)) {
3133 /* For local neigh mark inactive so MACIP update is generated
3134 * to BGP. This is a scenario where MAC update received
3135 * and detected as duplicate which marked neigh as duplicate.
3136 * Later local neigh update did not get a chance to relay
3137 * to BGP. Similarly remote macip update, neigh needs to be
3138 * installed locally.
3140 if (zvrf
->dad_freeze
&&
3141 CHECK_FLAG(nbr
->flags
, ZEBRA_NEIGH_DUPLICATE
)) {
3142 if (CHECK_FLAG(nbr
->flags
, ZEBRA_NEIGH_LOCAL
))
3143 ZEBRA_NEIGH_SET_INACTIVE(nbr
);
3144 else if (CHECK_FLAG(nbr
->flags
, ZEBRA_NEIGH_REMOTE
))
3145 zebra_evpn_rem_neigh_install(
3146 zevpn
, nbr
, false /*was_static*/);
3149 UNSET_FLAG(nbr
->flags
, ZEBRA_NEIGH_DUPLICATE
);
3151 nbr
->detect_start_time
.tv_sec
= 0;
3152 nbr
->dad_dup_detect_time
= 0;
3155 UNSET_FLAG(mac
->flags
, ZEBRA_MAC_DUPLICATE
);
3157 mac
->detect_start_time
.tv_sec
= 0;
3158 mac
->detect_start_time
.tv_usec
= 0;
3159 mac
->dad_dup_detect_time
= 0;
3160 THREAD_OFF(mac
->dad_mac_auto_recovery_timer
);
3162 /* warn-only action return */
3163 if (!zvrf
->dad_freeze
)
3166 /* Local: Notify Peer VTEPs, Remote: Install the entry */
3167 if (CHECK_FLAG(mac
->flags
, ZEBRA_MAC_LOCAL
)) {
3169 if (zebra_evpn_mac_send_add_to_client(zevpn
->vni
, &mac
->macaddr
,
3170 mac
->flags
, mac
->loc_seq
,
3174 /* Process all neighbors associated with this MAC. */
3175 zebra_evpn_process_neigh_on_local_mac_change(zevpn
, mac
, 0,
3178 } else if (CHECK_FLAG(mac
->flags
, ZEBRA_MAC_REMOTE
)) {
3179 zebra_evpn_process_neigh_on_remote_mac_add(zevpn
, mac
);
3181 /* Install the entry. */
3182 zebra_evpn_rem_mac_install(zevpn
, mac
, false /* was_static */);
3188 int zebra_vxlan_clear_dup_detect_vni_ip(struct zebra_vrf
*zvrf
, vni_t vni
,
3189 struct ipaddr
*ip
, char *errmsg
,
3192 struct zebra_evpn
*zevpn
;
3193 struct zebra_neigh
*nbr
;
3194 struct zebra_mac
*mac
;
3195 char buf
[INET6_ADDRSTRLEN
];
3196 char buf2
[ETHER_ADDR_STRLEN
];
3198 if (!is_evpn_enabled())
3201 zevpn
= zebra_evpn_lookup(vni
);
3203 snprintfrr(errmsg
, errmsg_len
, "VNI %u does not exist\n", vni
);
3207 nbr
= zebra_evpn_neigh_lookup(zevpn
, ip
);
3209 snprintfrr(errmsg
, errmsg_len
,
3210 "Requested host IP does not exist in VNI %u\n", vni
);
3214 ipaddr2str(&nbr
->ip
, buf
, sizeof(buf
));
3216 if (!CHECK_FLAG(nbr
->flags
, ZEBRA_NEIGH_DUPLICATE
)) {
3217 snprintfrr(errmsg
, errmsg_len
,
3218 "Requested host IP %s is not duplicate detected\n",
3223 mac
= zebra_evpn_mac_lookup(zevpn
, &nbr
->emac
);
3225 if (CHECK_FLAG(mac
->flags
, ZEBRA_MAC_DUPLICATE
)) {
3228 "Requested IP's associated MAC %s is still in duplicate state\n",
3229 prefix_mac2str(&nbr
->emac
, buf2
, sizeof(buf2
)));
3233 if (IS_ZEBRA_DEBUG_VXLAN
)
3234 zlog_debug("%s: clear neigh %s in dup state, flags 0x%x seq %u",
3235 __func__
, buf
, nbr
->flags
, nbr
->loc_seq
);
3237 UNSET_FLAG(nbr
->flags
, ZEBRA_NEIGH_DUPLICATE
);
3239 nbr
->detect_start_time
.tv_sec
= 0;
3240 nbr
->detect_start_time
.tv_usec
= 0;
3241 nbr
->dad_dup_detect_time
= 0;
3242 THREAD_OFF(nbr
->dad_ip_auto_recovery_timer
);
3244 if (!!CHECK_FLAG(nbr
->flags
, ZEBRA_NEIGH_LOCAL
)) {
3245 zebra_evpn_neigh_send_add_to_client(zevpn
->vni
, ip
, &nbr
->emac
,
3246 nbr
->mac
, nbr
->flags
,
3248 } else if (!!CHECK_FLAG(nbr
->flags
, ZEBRA_NEIGH_REMOTE
)) {
3249 zebra_evpn_rem_neigh_install(zevpn
, nbr
, false /*was_static*/);
3255 static void zevpn_clear_dup_mac_hash(struct hash_bucket
*bucket
, void *ctxt
)
3257 struct mac_walk_ctx
*wctx
= ctxt
;
3258 struct zebra_mac
*mac
;
3259 struct zebra_evpn
*zevpn
;
3260 struct listnode
*node
= NULL
;
3261 struct zebra_neigh
*nbr
= NULL
;
3263 mac
= (struct zebra_mac
*)bucket
->data
;
3267 zevpn
= wctx
->zevpn
;
3269 if (!CHECK_FLAG(mac
->flags
, ZEBRA_MAC_DUPLICATE
))
3272 UNSET_FLAG(mac
->flags
, ZEBRA_MAC_DUPLICATE
);
3274 mac
->detect_start_time
.tv_sec
= 0;
3275 mac
->detect_start_time
.tv_usec
= 0;
3276 mac
->dad_dup_detect_time
= 0;
3277 THREAD_OFF(mac
->dad_mac_auto_recovery_timer
);
3279 /* Remove all IPs as duplicate associcated with this MAC */
3280 for (ALL_LIST_ELEMENTS_RO(mac
->neigh_list
, node
, nbr
)) {
3281 if (CHECK_FLAG(nbr
->flags
, ZEBRA_NEIGH_LOCAL
)
3283 ZEBRA_NEIGH_SET_INACTIVE(nbr
);
3285 UNSET_FLAG(nbr
->flags
, ZEBRA_NEIGH_DUPLICATE
);
3287 nbr
->detect_start_time
.tv_sec
= 0;
3288 nbr
->dad_dup_detect_time
= 0;
3291 /* Local: Notify Peer VTEPs, Remote: Install the entry */
3292 if (CHECK_FLAG(mac
->flags
, ZEBRA_MAC_LOCAL
)) {
3294 if (zebra_evpn_mac_send_add_to_client(zevpn
->vni
, &mac
->macaddr
,
3295 mac
->flags
, mac
->loc_seq
,
3299 /* Process all neighbors associated with this MAC. */
3300 zebra_evpn_process_neigh_on_local_mac_change(zevpn
, mac
, 0,
3303 } else if (CHECK_FLAG(mac
->flags
, ZEBRA_MAC_REMOTE
)) {
3304 zebra_evpn_process_neigh_on_remote_mac_add(zevpn
, mac
);
3306 /* Install the entry. */
3307 zebra_evpn_rem_mac_install(zevpn
, mac
, false /* was_static */);
3311 static void zevpn_clear_dup_detect_hash_vni_all(struct hash_bucket
*bucket
,
3314 struct zebra_evpn
*zevpn
;
3315 struct zebra_vrf
*zvrf
;
3316 struct mac_walk_ctx m_wctx
;
3317 struct neigh_walk_ctx n_wctx
;
3319 zevpn
= (struct zebra_evpn
*)bucket
->data
;
3323 zvrf
= (struct zebra_vrf
*)args
[0];
3325 if (hashcount(zevpn
->neigh_table
)) {
3326 memset(&n_wctx
, 0, sizeof(n_wctx
));
3327 n_wctx
.zevpn
= zevpn
;
3329 hash_iterate(zevpn
->neigh_table
,
3330 zebra_evpn_clear_dup_neigh_hash
, &n_wctx
);
3333 if (num_valid_macs(zevpn
)) {
3334 memset(&m_wctx
, 0, sizeof(m_wctx
));
3335 m_wctx
.zevpn
= zevpn
;
3337 hash_iterate(zevpn
->mac_table
, zevpn_clear_dup_mac_hash
, &m_wctx
);
3342 int zebra_vxlan_clear_dup_detect_vni_all(struct zebra_vrf
*zvrf
)
3346 if (!is_evpn_enabled())
3351 hash_iterate(zvrf
->evpn_table
,
3352 (void (*)(struct hash_bucket
*, void *))
3353 zevpn_clear_dup_detect_hash_vni_all
, args
);
3358 int zebra_vxlan_clear_dup_detect_vni(struct zebra_vrf
*zvrf
, vni_t vni
)
3360 struct zebra_evpn
*zevpn
;
3361 struct mac_walk_ctx m_wctx
;
3362 struct neigh_walk_ctx n_wctx
;
3364 if (!is_evpn_enabled())
3367 zevpn
= zebra_evpn_lookup(vni
);
3369 zlog_warn("VNI %u does not exist", vni
);
3373 if (hashcount(zevpn
->neigh_table
)) {
3374 memset(&n_wctx
, 0, sizeof(n_wctx
));
3375 n_wctx
.zevpn
= zevpn
;
3377 hash_iterate(zevpn
->neigh_table
,
3378 zebra_evpn_clear_dup_neigh_hash
, &n_wctx
);
3381 if (num_valid_macs(zevpn
)) {
3382 memset(&m_wctx
, 0, sizeof(m_wctx
));
3383 m_wctx
.zevpn
= zevpn
;
3385 hash_iterate(zevpn
->mac_table
, zevpn_clear_dup_mac_hash
, &m_wctx
);
3392 * Display MACs for a VNI from specific VTEP (VTY command handler).
3394 void zebra_vxlan_print_macs_vni_vtep(struct vty
*vty
, struct zebra_vrf
*zvrf
,
3395 vni_t vni
, struct in_addr vtep_ip
,
3398 struct zebra_evpn
*zevpn
;
3400 struct mac_walk_ctx wctx
;
3401 json_object
*json
= NULL
;
3402 json_object
*json_mac
= NULL
;
3404 if (!is_evpn_enabled())
3406 zevpn
= zebra_evpn_lookup(vni
);
3409 vty_out(vty
, "{}\n");
3411 vty_out(vty
, "%% VNI %u does not exist\n", vni
);
3414 num_macs
= num_valid_macs(zevpn
);
3419 json
= json_object_new_object();
3420 json_mac
= json_object_new_object();
3423 memset(&wctx
, 0, sizeof(wctx
));
3426 wctx
.flags
= SHOW_REMOTE_MAC_FROM_VTEP
;
3427 wctx
.r_vtep_ip
= vtep_ip
;
3428 wctx
.json
= json_mac
;
3429 hash_iterate(zevpn
->mac_table
, zebra_evpn_print_mac_hash
, &wctx
);
3432 json_object_int_add(json
, "numMacs", wctx
.count
);
3434 json_object_object_add(json
, "macs", json_mac
);
3435 vty_json(vty
, json
);
3441 * Display VNI information (VTY command handler).
3443 * use_json flag indicates that output should be in JSON format.
3444 * json_array is non NULL when JSON output needs to be aggregated (by the
3445 * caller) and then printed, otherwise, JSON evpn vni info is printed
3448 void zebra_vxlan_print_vni(struct vty
*vty
, struct zebra_vrf
*zvrf
, vni_t vni
,
3449 bool use_json
, json_object
*json_array
)
3451 json_object
*json
= NULL
;
3453 struct zebra_l3vni
*zl3vni
= NULL
;
3454 struct zebra_evpn
*zevpn
= NULL
;
3456 if (!is_evpn_enabled())
3460 json
= json_object_new_object();
3465 zl3vni
= zl3vni_lookup(vni
);
3467 zl3vni_print(zl3vni
, (void *)args
);
3469 zevpn
= zebra_evpn_lookup(vni
);
3471 zebra_evpn_print(zevpn
, (void *)args
);
3473 vty_out(vty
, "%% VNI %u does not exist\n", vni
);
3478 * Each "json" object contains info about 1 VNI.
3479 * When "json_array" is non-null, we aggreggate the json output
3480 * into json_array and print it as a JSON array.
3483 json_object_array_add(json_array
, json
);
3485 vty_json(vty
, json
);
3489 /* Display all global details for EVPN */
3490 void zebra_vxlan_print_evpn(struct vty
*vty
, bool uj
)
3495 json_object
*json
= NULL
;
3496 struct zebra_vrf
*zvrf
= NULL
;
3498 if (!is_evpn_enabled())
3501 zvrf
= zebra_vrf_get_evpn();
3503 num_l3vnis
= hashcount(zrouter
.l3vni_table
);
3504 num_l2vnis
= hashcount(zvrf
->evpn_table
);
3505 num_vnis
= num_l2vnis
+ num_l3vnis
;
3508 json
= json_object_new_object();
3509 json_object_string_add(json
, "advertiseGatewayMacip",
3510 zvrf
->advertise_gw_macip
? "Yes" : "No");
3511 json_object_int_add(json
, "numVnis", num_vnis
);
3512 json_object_int_add(json
, "numL2Vnis", num_l2vnis
);
3513 json_object_int_add(json
, "numL3Vnis", num_l3vnis
);
3514 if (zebra_evpn_do_dup_addr_detect(zvrf
))
3515 json_object_boolean_true_add(json
,
3516 "isDuplicateAddrDetection");
3518 json_object_boolean_false_add(json
,
3519 "isDuplicateAddrDetection");
3520 json_object_int_add(json
, "maxMoves", zvrf
->dad_max_moves
);
3521 json_object_int_add(json
, "detectionTime", zvrf
->dad_time
);
3522 json_object_int_add(json
, "detectionFreezeTime",
3523 zvrf
->dad_freeze_time
);
3524 zebra_evpn_mh_json(json
);
3526 vty_out(vty
, "L2 VNIs: %u\n", num_l2vnis
);
3527 vty_out(vty
, "L3 VNIs: %u\n", num_l3vnis
);
3528 vty_out(vty
, "Advertise gateway mac-ip: %s\n",
3529 zvrf
->advertise_gw_macip
? "Yes" : "No");
3530 vty_out(vty
, "Advertise svi mac-ip: %s\n",
3531 zvrf
->advertise_svi_macip
? "Yes" : "No");
3532 vty_out(vty
, "Advertise svi mac: %s\n",
3533 zebra_evpn_mh_do_adv_svi_mac() ? "Yes" : "No");
3534 vty_out(vty
, "Duplicate address detection: %s\n",
3535 zebra_evpn_do_dup_addr_detect(zvrf
) ? "Enable"
3537 vty_out(vty
, " Detection max-moves %u, time %d\n",
3538 zvrf
->dad_max_moves
, zvrf
->dad_time
);
3539 if (zvrf
->dad_freeze
) {
3540 if (zvrf
->dad_freeze_time
)
3541 vty_out(vty
, " Detection freeze %u\n",
3542 zvrf
->dad_freeze_time
);
3544 vty_out(vty
, " Detection freeze %s\n",
3547 zebra_evpn_mh_print(vty
);
3551 vty_json(vty
, json
);
3555 * Display VNI hash table (VTY command handler).
3557 void zebra_vxlan_print_vnis(struct vty
*vty
, struct zebra_vrf
*zvrf
,
3560 json_object
*json
= NULL
;
3563 if (!is_evpn_enabled())
3567 json
= json_object_new_object();
3569 vty_out(vty
, "%-10s %-4s %-21s %-8s %-8s %-15s %-37s\n", "VNI",
3570 "Type", "VxLAN IF", "# MACs", "# ARPs",
3571 "# Remote VTEPs", "Tenant VRF");
3576 /* Display all L2-VNIs */
3579 (void (*)(struct hash_bucket
*, void *))zebra_evpn_print_hash
,
3582 /* Display all L3-VNIs */
3583 hash_iterate(zrouter
.l3vni_table
,
3584 (void (*)(struct hash_bucket
*, void *))zl3vni_print_hash
,
3588 vty_json(vty
, json
);
3591 void zebra_vxlan_dup_addr_detection(ZAPI_HANDLER_ARGS
)
3595 uint32_t max_moves
= 0;
3596 uint32_t freeze_time
= 0;
3597 bool dup_addr_detect
= false;
3598 bool freeze
= false;
3599 bool old_addr_detect
;
3602 STREAM_GETL(s
, dup_addr_detect
);
3603 STREAM_GETL(s
, time
);
3604 STREAM_GETL(s
, max_moves
);
3605 STREAM_GETL(s
, freeze
);
3606 STREAM_GETL(s
, freeze_time
);
3608 old_addr_detect
= zebra_evpn_do_dup_addr_detect(zvrf
);
3609 zvrf
->dup_addr_detect
= dup_addr_detect
;
3610 dup_addr_detect
= zebra_evpn_do_dup_addr_detect(zvrf
);
3612 /* DAD previous state was enabled, and new state is disable,
3613 * clear all duplicate detected addresses.
3615 if (old_addr_detect
&& !dup_addr_detect
)
3616 zebra_vxlan_clear_dup_detect_vni_all(zvrf
);
3618 zvrf
->dad_time
= time
;
3619 zvrf
->dad_max_moves
= max_moves
;
3620 zvrf
->dad_freeze
= freeze
;
3621 zvrf
->dad_freeze_time
= freeze_time
;
3623 if (IS_ZEBRA_DEBUG_VXLAN
)
3625 "VRF %s duplicate detect %s max_moves %u timeout %u freeze %s freeze_time %u",
3626 vrf_id_to_name(zvrf
->vrf
->vrf_id
),
3627 dup_addr_detect
? "enable" : "disable",
3628 zvrf
->dad_max_moves
, zvrf
->dad_time
,
3629 zvrf
->dad_freeze
? "enable" : "disable",
3630 zvrf
->dad_freeze_time
);
3637 * Display VNI hash table in detail(VTY command handler).
3639 void zebra_vxlan_print_vnis_detail(struct vty
*vty
, struct zebra_vrf
*zvrf
,
3642 json_object
*json_array
= NULL
;
3643 struct zebra_ns
*zns
= NULL
;
3644 struct zebra_evpn_show zes
;
3646 if (!is_evpn_enabled())
3649 zns
= zebra_ns_lookup(NS_DEFAULT
);
3654 json_array
= json_object_new_array();
3657 zes
.json
= json_array
;
3659 zes
.use_json
= use_json
;
3661 /* Display all L2-VNIs */
3662 hash_iterate(zvrf
->evpn_table
,
3663 (void (*)(struct hash_bucket
*,
3664 void *))zebra_evpn_print_hash_detail
,
3667 /* Display all L3-VNIs */
3668 hash_iterate(zrouter
.l3vni_table
,
3669 (void (*)(struct hash_bucket
*,
3670 void *))zl3vni_print_hash_detail
,
3674 vty_json(vty
, json_array
);
3678 * Handle neighbor delete notification from the kernel (on a VLAN device
3679 * / L3 interface). This may result in either the neighbor getting deleted
3680 * from our database or being re-added to the kernel (if it is a valid
3683 int zebra_vxlan_handle_kernel_neigh_del(struct interface
*ifp
,
3684 struct interface
*link_if
,
3687 struct zebra_evpn
*zevpn
= NULL
;
3688 struct zebra_l3vni
*zl3vni
= NULL
;
3690 /* check if this is a remote neigh entry corresponding to remote
3693 zl3vni
= zl3vni_from_svi(ifp
, link_if
);
3695 return zl3vni_local_nh_del(zl3vni
, ip
);
3697 /* We are only interested in neighbors on an SVI that resides on top
3698 * of a VxLAN bridge.
3700 zevpn
= zebra_evpn_from_svi(ifp
, link_if
);
3702 if (IS_ZEBRA_DEBUG_VXLAN
)
3704 "%s: Del neighbor %pIA EVPN is not present for interface %s",
3705 __func__
, ip
, ifp
->name
);
3709 if (!zevpn
->vxlan_if
) {
3711 "VNI %u hash %p doesn't have intf upon local neighbor DEL",
3716 if (IS_ZEBRA_DEBUG_VXLAN
)
3717 zlog_debug("Del neighbor %pIA intf %s(%u) -> L2-VNI %u",
3718 ip
, ifp
->name
, ifp
->ifindex
, zevpn
->vni
);
3720 return zebra_evpn_neigh_del_ip(zevpn
, ip
);
3724 * Handle neighbor add or update notification from the kernel (on a VLAN
3725 * device / L3 interface). This is typically for a local neighbor but can
3726 * also be for a remote neighbor (e.g., ageout notification). It could
3727 * also be a "move" scenario.
3729 int zebra_vxlan_handle_kernel_neigh_update(struct interface
*ifp
,
3730 struct interface
*link_if
,
3732 struct ethaddr
*macaddr
,
3736 bool local_inactive
, bool dp_static
)
3738 struct zebra_evpn
*zevpn
= NULL
;
3739 struct zebra_l3vni
*zl3vni
= NULL
;
3741 /* check if this is a remote neigh entry corresponding to remote
3744 zl3vni
= zl3vni_from_svi(ifp
, link_if
);
3746 return zl3vni_local_nh_add_update(zl3vni
, ip
, state
);
3748 /* We are only interested in neighbors on an SVI that resides on top
3749 * of a VxLAN bridge.
3751 zevpn
= zebra_evpn_from_svi(ifp
, link_if
);
3755 if (IS_ZEBRA_DEBUG_VXLAN
|| IS_ZEBRA_DEBUG_EVPN_MH_NEIGH
)
3757 "Add/Update neighbor %pIA MAC %pEA intf %s(%u) state 0x%x %s%s%s%s-> L2-VNI %u",
3758 ip
, macaddr
, ifp
->name
,
3759 ifp
->ifindex
, state
, is_ext
? "ext-learned " : "",
3760 is_router
? "router " : "",
3761 local_inactive
? "local_inactive " : "",
3762 dp_static
? "peer_sync " : "", zevpn
->vni
);
3764 /* Is this about a local neighbor or a remote one? */
3766 return zebra_evpn_local_neigh_update(zevpn
, ifp
, ip
, macaddr
,
3767 is_router
, local_inactive
,
3770 return zebra_evpn_remote_neigh_update(zevpn
, ifp
, ip
, macaddr
, state
);
3774 zebra_vxlan_remote_macip_helper(bool add
, struct stream
*s
, vni_t
*vni
,
3775 struct ethaddr
*macaddr
, uint16_t *ipa_len
,
3776 struct ipaddr
*ip
, struct in_addr
*vtep_ip
,
3777 uint8_t *flags
, uint32_t *seq
, esi_t
*esi
)
3782 * Obtain each remote MACIP and process.
3783 * Message contains VNI, followed by MAC followed by IP (if any)
3784 * followed by remote VTEP IP.
3786 memset(ip
, 0, sizeof(*ip
));
3787 STREAM_GETL(s
, *vni
);
3788 STREAM_GET(macaddr
->octet
, s
, ETH_ALEN
);
3789 STREAM_GETW(s
, *ipa_len
);
3792 if (*ipa_len
== IPV4_MAX_BYTELEN
)
3793 ip
->ipa_type
= IPADDR_V4
;
3794 else if (*ipa_len
== IPV6_MAX_BYTELEN
)
3795 ip
->ipa_type
= IPADDR_V6
;
3797 if (IS_ZEBRA_DEBUG_VXLAN
)
3799 "ipa_len *must* be %d or %d bytes in length not %d",
3800 IPV4_MAX_BYTELEN
, IPV6_MAX_BYTELEN
,
3802 goto stream_failure
;
3805 STREAM_GET(&ip
->ip
.addr
, s
, *ipa_len
);
3807 l
+= 4 + ETH_ALEN
+ 4 + *ipa_len
;
3808 STREAM_GET(&vtep_ip
->s_addr
, s
, IPV4_MAX_BYTELEN
);
3809 l
+= IPV4_MAX_BYTELEN
;
3812 STREAM_GETC(s
, *flags
);
3813 STREAM_GETL(s
, *seq
);
3815 STREAM_GET(esi
, s
, sizeof(esi_t
));
3826 * Handle message from client to delete a remote MACIP for a VNI.
3828 void zebra_vxlan_remote_macip_del(ZAPI_HANDLER_ARGS
)
3832 struct ethaddr macaddr
;
3834 struct in_addr vtep_ip
;
3835 uint16_t l
= 0, ipa_len
;
3836 char buf1
[INET6_ADDRSTRLEN
];
3840 while (l
< hdr
->length
) {
3841 int res_length
= zebra_vxlan_remote_macip_helper(
3842 false, s
, &vni
, &macaddr
, &ipa_len
, &ip
, &vtep_ip
, NULL
,
3845 if (res_length
== -1)
3846 goto stream_failure
;
3849 if (IS_ZEBRA_DEBUG_VXLAN
)
3851 "Recv MACIP DEL VNI %u MAC %pEA%s%s Remote VTEP %pI4 from %s",
3853 ipa_len
? " IP " : "",
3855 ipaddr2str(&ip
, buf1
, sizeof(buf1
)) : "",
3856 &vtep_ip
, zebra_route_string(client
->proto
));
3858 /* Enqueue to workqueue for processing */
3859 zebra_rib_queue_evpn_rem_macip_del(vni
, &macaddr
, &ip
, vtep_ip
);
3867 * Handle message from client to add a remote MACIP for a VNI. This
3868 * could be just the add of a MAC address or the add of a neighbor
3871 void zebra_vxlan_remote_macip_add(ZAPI_HANDLER_ARGS
)
3875 struct ethaddr macaddr
;
3877 struct in_addr vtep_ip
;
3878 uint16_t l
= 0, ipa_len
;
3881 char buf1
[INET6_ADDRSTRLEN
];
3883 char esi_buf
[ESI_STR_LEN
];
3885 if (!EVPN_ENABLED(zvrf
)) {
3886 zlog_debug("EVPN not enabled, ignoring remote MACIP ADD");
3892 while (l
< hdr
->length
) {
3894 int res_length
= zebra_vxlan_remote_macip_helper(
3895 true, s
, &vni
, &macaddr
, &ipa_len
, &ip
, &vtep_ip
,
3896 &flags
, &seq
, &esi
);
3898 if (res_length
== -1)
3899 goto stream_failure
;
3902 if (IS_ZEBRA_DEBUG_VXLAN
) {
3903 if (memcmp(&esi
, zero_esi
, sizeof(esi_t
)))
3904 esi_to_str(&esi
, esi_buf
, sizeof(esi_buf
));
3906 strlcpy(esi_buf
, "-", ESI_STR_LEN
);
3908 "Recv %sMACIP ADD VNI %u MAC %pEA%s%s flags 0x%x seq %u VTEP %pI4 ESI %s from %s",
3909 (flags
& ZEBRA_MACIP_TYPE_SYNC_PATH
) ?
3912 ipa_len
? " IP " : "",
3914 ipaddr2str(&ip
, buf1
, sizeof(buf1
)) : "",
3915 flags
, seq
, &vtep_ip
, esi_buf
,
3916 zebra_route_string(client
->proto
));
3919 /* Enqueue to workqueue for processing */
3920 zebra_rib_queue_evpn_rem_macip_add(vni
, &macaddr
, &ip
, flags
,
3921 seq
, vtep_ip
, &esi
);
3929 * Handle remote vtep delete by kernel; re-add the vtep if we have it
3931 int zebra_vxlan_check_readd_vtep(struct interface
*ifp
,
3932 struct in_addr vtep_ip
)
3934 struct zebra_if
*zif
;
3935 struct zebra_vrf
*zvrf
= NULL
;
3936 struct zebra_l2info_vxlan
*vxl
;
3938 struct zebra_evpn
*zevpn
= NULL
;
3939 struct zebra_vtep
*zvtep
= NULL
;
3943 vxl
= &zif
->l2info
.vxl
;
3946 /* If EVPN is not enabled, nothing to do. */
3947 if (!is_evpn_enabled())
3950 /* Locate VRF corresponding to interface. */
3951 zvrf
= ifp
->vrf
->info
;
3955 /* Locate hash entry; it is expected to exist. */
3956 zevpn
= zebra_evpn_lookup(vni
);
3960 /* If the remote vtep entry doesn't exists nothing to do */
3961 zvtep
= zebra_evpn_vtep_find(zevpn
, &vtep_ip
);
3965 if (IS_ZEBRA_DEBUG_VXLAN
)
3967 "Del MAC for remote VTEP %pI4 intf %s(%u) VNI %u - readd",
3968 &vtep_ip
, ifp
->name
, ifp
->ifindex
, vni
);
3970 zebra_evpn_vtep_install(zevpn
, zvtep
);
3975 * Handle notification of MAC add/update over VxLAN. If the kernel is notifying
3976 * us, this must involve a multihoming scenario. Treat this as implicit delete
3977 * of any prior local MAC.
3979 static int zebra_vxlan_check_del_local_mac(struct interface
*ifp
,
3980 struct interface
*br_if
,
3981 struct ethaddr
*macaddr
,
3984 struct zebra_if
*zif
;
3985 struct zebra_l2info_vxlan
*vxl
;
3987 struct zebra_evpn
*zevpn
;
3988 struct zebra_mac
*mac
;
3992 vxl
= &zif
->l2info
.vxl
;
3995 /* Check if EVPN is enabled. */
3996 if (!is_evpn_enabled())
3999 /* Locate hash entry; it is expected to exist. */
4000 zevpn
= zebra_evpn_lookup(vni
);
4004 /* If entry doesn't exist, nothing to do. */
4005 mac
= zebra_evpn_mac_lookup(zevpn
, macaddr
);
4009 /* Is it a local entry? */
4010 if (!CHECK_FLAG(mac
->flags
, ZEBRA_MAC_LOCAL
))
4013 if (IS_ZEBRA_DEBUG_VXLAN
)
4015 "Add/update remote MAC %pEA intf %s(%u) VNI %u flags 0x%x - del local",
4016 macaddr
, ifp
->name
, ifp
->ifindex
, vni
, mac
->flags
);
4018 /* Remove MAC from BGP. */
4019 zebra_evpn_mac_send_del_to_client(zevpn
->vni
, macaddr
, mac
->flags
,
4023 * If there are no neigh associated with the mac delete the mac
4024 * else mark it as AUTO for forward reference
4026 if (!listcount(mac
->neigh_list
)) {
4027 zebra_evpn_mac_del(zevpn
, mac
);
4029 zebra_evpn_mac_clear_fwd_info(mac
);
4030 UNSET_FLAG(mac
->flags
, ZEBRA_MAC_ALL_LOCAL_FLAGS
);
4031 UNSET_FLAG(mac
->flags
, ZEBRA_MAC_STICKY
);
4032 SET_FLAG(mac
->flags
, ZEBRA_MAC_AUTO
);
4038 /* MAC notification from the dataplane with a network dest port -
4039 * 1. This can be a local MAC on a down ES (if fast-failover is not possible
4040 * 2. Or it can be a remote MAC
4042 int zebra_vxlan_dp_network_mac_add(struct interface
*ifp
,
4043 struct interface
*br_if
,
4044 struct ethaddr
*macaddr
, vlanid_t vid
,
4045 uint32_t nhg_id
, bool sticky
, bool dp_static
)
4047 struct zebra_evpn_es
*es
;
4048 struct interface
*acc_ifp
;
4050 /* If netlink message is with vid, it will have no nexthop.
4054 if (IS_ZEBRA_DEBUG_VXLAN
|| IS_ZEBRA_DEBUG_EVPN_MH_MAC
)
4055 zlog_debug("dpAdd MAC %pEA VID %u - ignore as no nhid",
4060 /* Get vxlan's vid for netlink message has no it. */
4061 vid
= ((struct zebra_if
*)ifp
->info
)->l2info
.vxl
.access_vlan
;
4063 /* if remote mac delete the local entry */
4064 if (!nhg_id
|| !zebra_evpn_nhg_is_local_es(nhg_id
, &es
)
4065 || !zebra_evpn_es_local_mac_via_network_port(es
)) {
4066 if (IS_ZEBRA_DEBUG_VXLAN
|| IS_ZEBRA_DEBUG_EVPN_MH_MAC
)
4067 zlog_debug("dpAdd remote MAC %pEA VID %u", macaddr
,
4069 return zebra_vxlan_check_del_local_mac(ifp
, br_if
, macaddr
,
4073 /* If local MAC on a down local ES translate the network-mac-add
4074 * to a local-active-mac-add
4076 if (IS_ZEBRA_DEBUG_VXLAN
|| IS_ZEBRA_DEBUG_EVPN_MH_MAC
)
4077 zlog_debug("dpAdd local-nw-MAC %pEA VID %u", macaddr
, vid
);
4078 acc_ifp
= es
->zif
->ifp
;
4079 return zebra_vxlan_local_mac_add_update(
4080 acc_ifp
, br_if
, macaddr
, vid
, sticky
,
4081 false /* local_inactive */, dp_static
);
4085 * Handle network MAC delete by kernel -
4086 * 1. readd the remote MAC if we have it
4087 * 2. local MAC with does ES may also need to be re-installed
4089 int zebra_vxlan_dp_network_mac_del(struct interface
*ifp
,
4090 struct interface
*br_if
,
4091 struct ethaddr
*macaddr
, vlanid_t vid
)
4093 struct zebra_if
*zif
= NULL
;
4094 struct zebra_l2info_vxlan
*vxl
= NULL
;
4096 struct zebra_evpn
*zevpn
= NULL
;
4097 struct zebra_l3vni
*zl3vni
= NULL
;
4098 struct zebra_mac
*mac
= NULL
;
4102 vxl
= &zif
->l2info
.vxl
;
4105 /* Check if EVPN is enabled. */
4106 if (!is_evpn_enabled())
4109 /* check if this is a remote RMAC and readd simillar to remote macs */
4110 zl3vni
= zl3vni_lookup(vni
);
4112 return zebra_vxlan_readd_remote_rmac(zl3vni
, macaddr
);
4114 /* Locate hash entry; it is expected to exist. */
4115 zevpn
= zebra_evpn_lookup(vni
);
4119 /* If entry doesn't exist, nothing to do. */
4120 mac
= zebra_evpn_mac_lookup(zevpn
, macaddr
);
4124 if (CHECK_FLAG(mac
->flags
, ZEBRA_MAC_REMOTE
)) {
4125 /* If remote entry simply re-install */
4126 if (IS_ZEBRA_DEBUG_VXLAN
|| IS_ZEBRA_DEBUG_EVPN_MH_MAC
)
4128 "dpDel remote MAC %pEA intf %s(%u) VNI %u - readd",
4129 macaddr
, ifp
->name
, ifp
->ifindex
, vni
);
4130 zebra_evpn_rem_mac_install(zevpn
, mac
, false /* was_static */);
4131 } else if (CHECK_FLAG(mac
->flags
, ZEBRA_MAC_LOCAL
) && mac
->es
4132 && zebra_evpn_es_local_mac_via_network_port(mac
->es
)) {
4133 /* If local entry via nw-port call local-del which will
4134 * re-install entry in the dataplane is needed
4136 if (IS_ZEBRA_DEBUG_VXLAN
|| IS_ZEBRA_DEBUG_EVPN_MH_MAC
)
4137 zlog_debug("dpDel local-nw-MAC %pEA VNI %u", macaddr
,
4140 zebra_evpn_del_local_mac(zevpn
, mac
, false);
4147 * Handle local MAC delete (on a port or VLAN corresponding to this VNI).
4149 int zebra_vxlan_local_mac_del(struct interface
*ifp
, struct interface
*br_if
,
4150 struct ethaddr
*macaddr
, vlanid_t vid
)
4152 struct zebra_evpn
*zevpn
;
4153 struct zebra_mac
*mac
;
4155 /* We are interested in MACs only on ports or (port, VLAN) that
4158 zevpn
= zebra_evpn_map_vlan(ifp
, br_if
, vid
);
4161 if (!zevpn
->vxlan_if
) {
4163 "VNI %u hash %p doesn't have intf upon local MAC DEL",
4168 /* If entry doesn't exist, nothing to do. */
4169 mac
= zebra_evpn_mac_lookup(zevpn
, macaddr
);
4173 /* Is it a local entry? */
4174 if (!CHECK_FLAG(mac
->flags
, ZEBRA_MAC_LOCAL
))
4177 return zebra_evpn_del_local_mac(zevpn
, mac
, false);
4181 * Handle local MAC add (on a port or VLAN corresponding to this VNI).
4183 int zebra_vxlan_local_mac_add_update(struct interface
*ifp
,
4184 struct interface
*br_if
,
4185 struct ethaddr
*macaddr
, vlanid_t vid
,
4186 bool sticky
, bool local_inactive
,
4189 struct zebra_evpn
*zevpn
;
4190 struct zebra_vrf
*zvrf
;
4194 /* We are interested in MACs only on ports or (port, VLAN) that
4197 zevpn
= zebra_evpn_map_vlan(ifp
, br_if
, vid
);
4199 if (IS_ZEBRA_DEBUG_VXLAN
)
4201 " Add/Update %sMAC %pEA intf %s(%u) VID %u, could not find EVPN",
4202 sticky
? "sticky " : "", macaddr
,
4203 ifp
->name
, ifp
->ifindex
, vid
);
4207 if (!zevpn
->vxlan_if
) {
4208 if (IS_ZEBRA_DEBUG_VXLAN
)
4210 " VNI %u hash %p doesn't have intf upon local MAC ADD",
4215 zvrf
= zebra_vrf_get_evpn();
4216 return zebra_evpn_add_update_local_mac(zvrf
, zevpn
, ifp
, macaddr
, vid
,
4217 sticky
, local_inactive
,
4222 * Handle message from client to delete a remote VTEP for an EVPN.
4224 void zebra_vxlan_remote_vtep_del_zapi(ZAPI_HANDLER_ARGS
)
4227 unsigned short l
= 0;
4229 struct in_addr vtep_ip
;
4231 if (!is_evpn_enabled()) {
4233 "%s: EVPN is not enabled yet we have received a VTEP DEL msg",
4238 if (!EVPN_ENABLED(zvrf
)) {
4239 zlog_debug("Recv VTEP DEL zapi for non-EVPN VRF %u",
4246 while (l
< hdr
->length
) {
4247 int flood_control
__attribute__((unused
));
4249 /* Obtain each remote VTEP and process. */
4250 STREAM_GETL(s
, vni
);
4252 STREAM_GET(&vtep_ip
.s_addr
, s
, IPV4_MAX_BYTELEN
);
4253 l
+= IPV4_MAX_BYTELEN
;
4255 /* Flood control is intentionally ignored right now */
4256 STREAM_GETL(s
, flood_control
);
4259 if (IS_ZEBRA_DEBUG_VXLAN
)
4260 zlog_debug("Recv VTEP DEL %pI4 VNI %u from %s",
4262 zebra_route_string(client
->proto
));
4264 /* Enqueue for processing */
4265 zebra_rib_queue_evpn_rem_vtep_del(zvrf_id(zvrf
), vni
, vtep_ip
);
4273 * Handle message from client to delete a remote VTEP for an EVPN.
4275 void zebra_vxlan_remote_vtep_del(vrf_id_t vrf_id
, vni_t vni
,
4276 struct in_addr vtep_ip
)
4278 struct zebra_evpn
*zevpn
;
4279 struct zebra_vtep
*zvtep
;
4280 struct interface
*ifp
;
4281 struct zebra_if
*zif
;
4282 struct zebra_vrf
*zvrf
;
4284 if (!is_evpn_enabled()) {
4285 zlog_debug("%s: Can't process vtep del: EVPN is not enabled",
4290 zvrf
= zebra_vrf_lookup_by_id(vrf_id
);
4294 if (!EVPN_ENABLED(zvrf
)) {
4295 zlog_debug("Can't process VTEP DEL for non-EVPN VRF %u",
4300 /* Locate VNI hash entry - expected to exist. */
4301 zevpn
= zebra_evpn_lookup(vni
);
4303 if (IS_ZEBRA_DEBUG_VXLAN
)
4305 "Failed to locate VNI hash for remote VTEP DEL, VNI %u",
4310 ifp
= zevpn
->vxlan_if
;
4313 "VNI %u hash %p doesn't have intf upon remote VTEP DEL",
4319 /* If down or not mapped to a bridge, we're done. */
4320 if (!if_is_operative(ifp
) || !zif
->brslave_info
.br_if
)
4323 /* If the remote VTEP does not exist, there's nothing more to
4325 * Otherwise, uninstall any remote MACs pointing to this VTEP
4326 * and then, the VTEP entry itself and remove it.
4328 zvtep
= zebra_evpn_vtep_find(zevpn
, &vtep_ip
);
4332 zebra_evpn_vtep_uninstall(zevpn
, &vtep_ip
);
4333 zebra_evpn_vtep_del(zevpn
, zvtep
);
4337 * Handle message from client to add a remote VTEP for an EVPN.
4339 void zebra_vxlan_remote_vtep_add(vrf_id_t vrf_id
, vni_t vni
,
4340 struct in_addr vtep_ip
, int flood_control
)
4342 struct zebra_evpn
*zevpn
;
4343 struct interface
*ifp
;
4344 struct zebra_if
*zif
;
4345 struct zebra_vtep
*zvtep
;
4346 struct zebra_vrf
*zvrf
;
4348 if (!is_evpn_enabled()) {
4349 zlog_debug("%s: EVPN not enabled: can't process a VTEP ADD",
4354 zvrf
= zebra_vrf_lookup_by_id(vrf_id
);
4358 if (!EVPN_ENABLED(zvrf
)) {
4359 zlog_debug("Can't process VTEP ADD for non-EVPN VRF %u",
4364 /* Locate VNI hash entry - expected to exist. */
4365 zevpn
= zebra_evpn_lookup(vni
);
4368 EC_ZEBRA_VTEP_ADD_FAILED
,
4369 "Failed to locate EVPN hash upon remote VTEP ADD, VNI %u",
4374 ifp
= zevpn
->vxlan_if
;
4377 EC_ZEBRA_VTEP_ADD_FAILED
,
4378 "VNI %u hash %p doesn't have intf upon remote VTEP ADD",
4385 /* If down or not mapped to a bridge, we're done. */
4386 if (!if_is_operative(ifp
) || !zif
->brslave_info
.br_if
)
4389 zvtep
= zebra_evpn_vtep_find(zevpn
, &vtep_ip
);
4391 /* If the remote VTEP already exists check if
4392 * the flood mode has changed
4394 if (zvtep
->flood_control
!= flood_control
) {
4395 if (zvtep
->flood_control
== VXLAN_FLOOD_DISABLED
)
4396 /* old mode was head-end-replication but
4397 * is no longer; get rid of the HER fdb
4398 * entry installed before
4400 zebra_evpn_vtep_uninstall(zevpn
, &vtep_ip
);
4401 zvtep
->flood_control
= flood_control
;
4402 zebra_evpn_vtep_install(zevpn
, zvtep
);
4405 zvtep
= zebra_evpn_vtep_add(zevpn
, &vtep_ip
, flood_control
);
4407 zebra_evpn_vtep_install(zevpn
, zvtep
);
4409 flog_err(EC_ZEBRA_VTEP_ADD_FAILED
,
4410 "Failed to add remote VTEP, VNI %u zevpn %p",
4416 * Handle message from client to add a remote VTEP for an EVPN.
4418 void zebra_vxlan_remote_vtep_add_zapi(ZAPI_HANDLER_ARGS
)
4421 unsigned short l
= 0;
4423 struct in_addr vtep_ip
;
4426 if (!is_evpn_enabled()) {
4428 "%s: EVPN not enabled yet we received a VTEP ADD zapi msg",
4433 if (!EVPN_ENABLED(zvrf
)) {
4434 zlog_debug("Recv VTEP ADD zapi for non-EVPN VRF %u",
4441 while (l
< hdr
->length
) {
4442 /* Obtain each remote VTEP and process. */
4443 STREAM_GETL(s
, vni
);
4445 STREAM_GET(&vtep_ip
.s_addr
, s
, IPV4_MAX_BYTELEN
);
4446 STREAM_GETL(s
, flood_control
);
4447 l
+= IPV4_MAX_BYTELEN
+ 4;
4449 if (IS_ZEBRA_DEBUG_VXLAN
)
4450 zlog_debug("Recv VTEP ADD %pI4 VNI %u flood %d from %s",
4451 &vtep_ip
, vni
, flood_control
,
4452 zebra_route_string(client
->proto
));
4454 /* Enqueue for processing */
4455 zebra_rib_queue_evpn_rem_vtep_add(zvrf_id(zvrf
), vni
, vtep_ip
,
4464 * Add/Del gateway macip to evpn
4466 * 1. SVI interface on a vlan aware bridge
4467 * 2. SVI interface on a vlan unaware bridge
4468 * 3. vrr interface (MACVLAN) associated to a SVI
4469 * We advertise macip routes for an interface if it is associated to VxLan vlan
4471 int zebra_vxlan_add_del_gw_macip(struct interface
*ifp
, const struct prefix
*p
,
4475 struct ethaddr macaddr
;
4476 struct zebra_evpn
*zevpn
= NULL
;
4478 memset(&ip
, 0, sizeof(ip
));
4479 memset(&macaddr
, 0, sizeof(macaddr
));
4481 /* Check if EVPN is enabled. */
4482 if (!is_evpn_enabled())
4485 if (IS_ZEBRA_IF_MACVLAN(ifp
)) {
4486 struct interface
*svi_if
=
4487 NULL
; /* SVI corresponding to the MACVLAN */
4488 struct zebra_if
*ifp_zif
=
4489 NULL
; /* Zebra daemon specific info for MACVLAN */
4490 struct zebra_if
*svi_if_zif
=
4491 NULL
; /* Zebra daemon specific info for SVI*/
4493 ifp_zif
= ifp
->info
;
4498 * for a MACVLAN interface the link represents the svi_if
4500 svi_if
= if_lookup_by_index_per_ns(zebra_ns_lookup(NS_DEFAULT
),
4501 ifp_zif
->link_ifindex
);
4503 zlog_debug("MACVLAN %s(%u) without link information",
4504 ifp
->name
, ifp
->ifindex
);
4508 if (IS_ZEBRA_IF_VLAN(svi_if
)) {
4510 * If it is a vlan aware bridge then the link gives the
4511 * bridge information
4513 struct interface
*svi_if_link
= NULL
;
4515 svi_if_zif
= svi_if
->info
;
4517 svi_if_link
= if_lookup_by_index_per_ns(
4518 zebra_ns_lookup(NS_DEFAULT
),
4519 svi_if_zif
->link_ifindex
);
4520 zevpn
= zebra_evpn_from_svi(svi_if
,
4523 } else if (IS_ZEBRA_IF_BRIDGE(svi_if
)) {
4525 * If it is a vlan unaware bridge then svi is the bridge
4528 zevpn
= zebra_evpn_from_svi(svi_if
, svi_if
);
4530 } else if (IS_ZEBRA_IF_VLAN(ifp
)) {
4531 struct zebra_if
*svi_if_zif
=
4532 NULL
; /* Zebra daemon specific info for SVI */
4533 struct interface
*svi_if_link
=
4534 NULL
; /* link info for the SVI = bridge info */
4536 svi_if_zif
= ifp
->info
;
4538 svi_if_link
= if_lookup_by_index_per_ns(
4539 zebra_ns_lookup(NS_DEFAULT
),
4540 svi_if_zif
->link_ifindex
);
4542 zevpn
= zebra_evpn_from_svi(ifp
, svi_if_link
);
4544 } else if (IS_ZEBRA_IF_BRIDGE(ifp
)) {
4545 zevpn
= zebra_evpn_from_svi(ifp
, ifp
);
4551 if (!zevpn
->vxlan_if
) {
4552 zlog_debug("VNI %u hash %p doesn't have intf upon MACVLAN up",
4557 /* VRR IP is advertised only if gw-macip-adv-enabled */
4558 if (IS_ZEBRA_IF_MACVLAN(ifp
)) {
4559 if (!advertise_gw_macip_enabled(zevpn
))
4562 /* SVI IP is advertised if gw or svi macip-adv-enabled */
4563 if (!advertise_svi_macip_enabled(zevpn
)
4564 && !advertise_gw_macip_enabled(zevpn
))
4568 memcpy(&macaddr
.octet
, ifp
->hw_addr
, ETH_ALEN
);
4570 if (p
->family
== AF_INET
) {
4571 ip
.ipa_type
= IPADDR_V4
;
4572 memcpy(&(ip
.ipaddr_v4
), &(p
->u
.prefix4
),
4573 sizeof(struct in_addr
));
4574 } else if (p
->family
== AF_INET6
) {
4575 ip
.ipa_type
= IPADDR_V6
;
4576 memcpy(&(ip
.ipaddr_v6
), &(p
->u
.prefix6
),
4577 sizeof(struct in6_addr
));
4582 zebra_evpn_gw_macip_add(ifp
, zevpn
, &macaddr
, &ip
);
4584 zebra_evpn_gw_macip_del(ifp
, zevpn
, &ip
);
4590 * Handle SVI interface going down.
4591 * SVI can be associated to either L3-VNI or L2-VNI.
4592 * For L2-VNI: At this point, this is a NOP since
4593 * the kernel deletes the neighbor entries on this SVI (if any).
4594 * We only need to update the vrf corresponding to zevpn.
4595 * For L3-VNI: L3-VNI is operationally down, update mac-ip routes and delete
4598 int zebra_vxlan_svi_down(struct interface
*ifp
, struct interface
*link_if
)
4600 struct zebra_l3vni
*zl3vni
= NULL
;
4602 zl3vni
= zl3vni_from_svi(ifp
, link_if
);
4605 /* process l3-vni down */
4606 zebra_vxlan_process_l3vni_oper_down(zl3vni
);
4608 /* remove association with svi-if */
4609 zl3vni
->svi_if
= NULL
;
4611 struct zebra_evpn
*zevpn
= NULL
;
4613 /* Unlink the SVI from the access VLAN */
4614 zebra_evpn_acc_bd_svi_set(ifp
->info
, link_if
->info
, false);
4616 /* since we dont have svi corresponding to zevpn, we associate it
4617 * to default vrf. Note: the corresponding neigh entries on the
4618 * SVI would have already been deleted */
4619 zevpn
= zebra_evpn_from_svi(ifp
, link_if
);
4622 /* remove from l3-vni list */
4623 zl3vni
= zl3vni_from_vrf(zevpn
->vrf_id
);
4625 listnode_delete(zl3vni
->l2vnis
, zevpn
);
4627 zevpn
->svi_if
= NULL
;
4628 zevpn
->vrf_id
= VRF_DEFAULT
;
4630 /* update the tenant vrf in BGP */
4631 if (if_is_operative(zevpn
->vxlan_if
))
4632 zebra_evpn_send_add_to_client(zevpn
);
4639 * Handle SVI interface coming up.
4640 * SVI can be associated to L3-VNI (l3vni vxlan interface) or L2-VNI (l2-vni
4642 * For L2-VNI: we need to install any remote neighbors entried (used for
4644 * For L3-VNI: SVI will be used to get the rmac to be used with L3-VNI
4646 int zebra_vxlan_svi_up(struct interface
*ifp
, struct interface
*link_if
)
4648 struct zebra_evpn
*zevpn
= NULL
;
4649 struct zebra_l3vni
*zl3vni
= NULL
;
4651 zl3vni
= zl3vni_from_svi(ifp
, link_if
);
4654 /* associate with svi */
4655 zl3vni
->svi_if
= ifp
;
4657 /* process oper-up */
4658 if (is_l3vni_oper_up(zl3vni
))
4659 zebra_vxlan_process_l3vni_oper_up(zl3vni
);
4662 /* process SVI up for l2-vni */
4663 struct neigh_walk_ctx n_wctx
;
4665 zevpn
= zebra_evpn_from_svi(ifp
, link_if
);
4669 if (!zevpn
->vxlan_if
) {
4671 "VNI %u hash %p doesn't have intf upon SVI up",
4676 if (IS_ZEBRA_DEBUG_VXLAN
)
4678 "SVI %s(%u) VNI %u VRF %s is UP, installing neighbors",
4679 ifp
->name
, ifp
->ifindex
, zevpn
->vni
,
4682 /* update the vrf information for l2-vni and inform bgp */
4683 zevpn
->svi_if
= ifp
;
4684 zevpn
->vrf_id
= ifp
->vrf
->vrf_id
;
4686 zl3vni
= zl3vni_from_vrf(zevpn
->vrf_id
);
4688 listnode_add_sort_nodup(zl3vni
->l2vnis
, zevpn
);
4690 if (if_is_operative(zevpn
->vxlan_if
))
4691 zebra_evpn_send_add_to_client(zevpn
);
4693 /* Install any remote neighbors for this VNI. */
4694 memset(&n_wctx
, 0, sizeof(n_wctx
));
4695 n_wctx
.zevpn
= zevpn
;
4696 hash_iterate(zevpn
->neigh_table
, zebra_evpn_install_neigh_hash
,
4699 /* Link the SVI from the access VLAN */
4700 zebra_evpn_acc_bd_svi_set(ifp
->info
, link_if
->info
, true);
4702 /* Update MACIP routes created by advertise-svi-ip */
4703 if (advertise_svi_macip_enabled(zevpn
)) {
4704 zebra_evpn_del_macip_for_intf(ifp
, zevpn
);
4705 zebra_evpn_add_macip_for_intf(ifp
, zevpn
);
4713 * Handle MAC-VLAN interface going down.
4714 * L3VNI: When MAC-VLAN interface goes down,
4715 * find its associated SVI and update type2/type-5 routes
4718 void zebra_vxlan_macvlan_down(struct interface
*ifp
)
4720 struct zebra_l3vni
*zl3vni
= NULL
;
4721 struct zebra_if
*zif
, *link_zif
;
4722 struct interface
*link_ifp
, *link_if
;
4726 link_ifp
= zif
->link
;
4728 if (IS_ZEBRA_DEBUG_VXLAN
)
4730 "macvlan parent link is not found. Parent index %d ifp %s",
4732 ifindex2ifname(zif
->link_ifindex
,
4736 link_zif
= link_ifp
->info
;
4739 link_if
= if_lookup_by_index_per_ns(zebra_ns_lookup(NS_DEFAULT
),
4740 link_zif
->link_ifindex
);
4742 zl3vni
= zl3vni_from_svi(link_ifp
, link_if
);
4744 zl3vni
->mac_vlan_if
= NULL
;
4745 if (is_l3vni_oper_up(zl3vni
))
4746 zebra_vxlan_process_l3vni_oper_up(zl3vni
);
4751 * Handle MAC-VLAN interface going up.
4752 * L3VNI: When MAC-VLAN interface comes up,
4753 * find its associated SVI and update type-2 routes
4754 * with MAC-VLAN's MAC as RMAC and for type-5 routes
4755 * use SVI's MAC as RMAC.
4757 void zebra_vxlan_macvlan_up(struct interface
*ifp
)
4759 struct zebra_l3vni
*zl3vni
= NULL
;
4760 struct zebra_if
*zif
, *link_zif
;
4761 struct interface
*link_ifp
, *link_if
;
4765 link_ifp
= zif
->link
;
4766 link_zif
= link_ifp
->info
;
4769 link_if
= if_lookup_by_index_per_ns(zebra_ns_lookup(NS_DEFAULT
),
4770 link_zif
->link_ifindex
);
4771 zl3vni
= zl3vni_from_svi(link_ifp
, link_if
);
4773 /* associate with macvlan (VRR) interface */
4774 zl3vni
->mac_vlan_if
= ifp
;
4776 /* process oper-up */
4777 if (is_l3vni_oper_up(zl3vni
))
4778 zebra_vxlan_process_l3vni_oper_up(zl3vni
);
4783 * Handle VxLAN interface down
4785 int zebra_vxlan_if_down(struct interface
*ifp
)
4788 struct zebra_if
*zif
= NULL
;
4789 struct zebra_l2info_vxlan
*vxl
= NULL
;
4790 struct zebra_l3vni
*zl3vni
= NULL
;
4791 struct zebra_evpn
*zevpn
;
4793 /* Check if EVPN is enabled. */
4794 if (!is_evpn_enabled())
4799 vxl
= &zif
->l2info
.vxl
;
4802 zl3vni
= zl3vni_lookup(vni
);
4804 /* process-if-down for l3-vni */
4805 if (IS_ZEBRA_DEBUG_VXLAN
)
4806 zlog_debug("Intf %s(%u) L3-VNI %u is DOWN", ifp
->name
,
4809 zebra_vxlan_process_l3vni_oper_down(zl3vni
);
4811 /* process if-down for l2-vni */
4812 if (IS_ZEBRA_DEBUG_VXLAN
)
4813 zlog_debug("Intf %s(%u) L2-VNI %u is DOWN", ifp
->name
,
4816 /* Locate hash entry; it is expected to exist. */
4817 zevpn
= zebra_evpn_lookup(vni
);
4820 "Failed to locate VNI hash at DOWN, IF %s(%u) VNI %u",
4821 ifp
->name
, ifp
->ifindex
, vni
);
4825 assert(zevpn
->vxlan_if
== ifp
);
4827 /* remove from l3-vni list */
4828 zl3vni
= zl3vni_from_vrf(zevpn
->vrf_id
);
4830 listnode_delete(zl3vni
->l2vnis
, zevpn
);
4832 /* Delete this VNI from BGP. */
4833 zebra_evpn_send_del_to_client(zevpn
);
4835 /* Free up all neighbors and MACs, if any. */
4836 zebra_evpn_neigh_del_all(zevpn
, 1, 0, DEL_ALL_NEIGH
);
4837 zebra_evpn_mac_del_all(zevpn
, 1, 0, DEL_ALL_MAC
);
4839 /* Free up all remote VTEPs, if any. */
4840 zebra_evpn_vtep_del_all(zevpn
, 1);
4846 * Handle VxLAN interface up - update BGP if required.
4848 int zebra_vxlan_if_up(struct interface
*ifp
)
4851 struct zebra_if
*zif
= NULL
;
4852 struct zebra_l2info_vxlan
*vxl
= NULL
;
4853 struct zebra_evpn
*zevpn
= NULL
;
4854 struct zebra_l3vni
*zl3vni
= NULL
;
4856 /* Check if EVPN is enabled. */
4857 if (!is_evpn_enabled())
4862 vxl
= &zif
->l2info
.vxl
;
4865 zl3vni
= zl3vni_lookup(vni
);
4867 /* we need to associate with SVI, if any, we can associate with
4868 * svi-if only after association with vxlan-intf is complete
4870 zl3vni
->svi_if
= zl3vni_map_to_svi_if(zl3vni
);
4871 zl3vni
->mac_vlan_if
= zl3vni_map_to_mac_vlan_if(zl3vni
);
4873 if (IS_ZEBRA_DEBUG_VXLAN
)
4874 zlog_debug("Intf %s(%u) L3-VNI %u is UP svi_if %s mac_vlan_if %s"
4875 , ifp
->name
, ifp
->ifindex
, vni
,
4876 zl3vni
->svi_if
? zl3vni
->svi_if
->name
: "NIL",
4877 zl3vni
->mac_vlan_if
?
4878 zl3vni
->mac_vlan_if
->name
: "NIL");
4880 if (is_l3vni_oper_up(zl3vni
))
4881 zebra_vxlan_process_l3vni_oper_up(zl3vni
);
4883 /* Handle L2-VNI add */
4884 struct interface
*vlan_if
= NULL
;
4886 if (IS_ZEBRA_DEBUG_VXLAN
)
4887 zlog_debug("Intf %s(%u) L2-VNI %u is UP", ifp
->name
,
4890 /* Locate hash entry; it is expected to exist. */
4891 zevpn
= zebra_evpn_lookup(vni
);
4894 "Failed to locate EVPN hash at UP, IF %s(%u) VNI %u",
4895 ifp
->name
, ifp
->ifindex
, vni
);
4899 assert(zevpn
->vxlan_if
== ifp
);
4900 vlan_if
= zvni_map_to_svi(vxl
->access_vlan
,
4901 zif
->brslave_info
.br_if
);
4903 zevpn
->svi_if
= vlan_if
;
4904 zevpn
->vrf_id
= vlan_if
->vrf
->vrf_id
;
4905 zl3vni
= zl3vni_from_vrf(vlan_if
->vrf
->vrf_id
);
4907 listnode_add_sort_nodup(zl3vni
->l2vnis
, zevpn
);
4910 /* If part of a bridge, inform BGP about this VNI. */
4911 /* Also, read and populate local MACs and neighbors. */
4912 if (zif
->brslave_info
.br_if
) {
4913 zebra_evpn_send_add_to_client(zevpn
);
4914 zebra_evpn_read_mac_neigh(zevpn
, ifp
);
4922 * Handle VxLAN interface delete. Locate and remove entry in hash table
4923 * and update BGP, if required.
4925 int zebra_vxlan_if_del(struct interface
*ifp
)
4928 struct zebra_if
*zif
= NULL
;
4929 struct zebra_l2info_vxlan
*vxl
= NULL
;
4930 struct zebra_evpn
*zevpn
= NULL
;
4931 struct zebra_l3vni
*zl3vni
= NULL
;
4933 /* Check if EVPN is enabled. */
4934 if (!is_evpn_enabled())
4939 vxl
= &zif
->l2info
.vxl
;
4942 zl3vni
= zl3vni_lookup(vni
);
4945 if (IS_ZEBRA_DEBUG_VXLAN
)
4946 zlog_debug("Del L3-VNI %u intf %s(%u)", vni
, ifp
->name
,
4949 /* process oper-down for l3-vni */
4950 zebra_vxlan_process_l3vni_oper_down(zl3vni
);
4952 /* remove the association with vxlan_if */
4953 memset(&zl3vni
->local_vtep_ip
, 0, sizeof(struct in_addr
));
4954 zl3vni
->vxlan_if
= NULL
;
4957 /* process if-del for l2-vni*/
4958 if (IS_ZEBRA_DEBUG_VXLAN
)
4959 zlog_debug("Del L2-VNI %u intf %s(%u)", vni
, ifp
->name
,
4962 /* Locate hash entry; it is expected to exist. */
4963 zevpn
= zebra_evpn_lookup(vni
);
4966 "Failed to locate VNI hash at del, IF %s(%u) VNI %u",
4967 ifp
->name
, ifp
->ifindex
, vni
);
4971 /* remove from l3-vni list */
4972 zl3vni
= zl3vni_from_vrf(zevpn
->vrf_id
);
4974 listnode_delete(zl3vni
->l2vnis
, zevpn
);
4975 /* Delete VNI from BGP. */
4976 zebra_evpn_send_del_to_client(zevpn
);
4978 /* Free up all neighbors and MAC, if any. */
4979 zebra_evpn_neigh_del_all(zevpn
, 0, 0, DEL_ALL_NEIGH
);
4980 zebra_evpn_mac_del_all(zevpn
, 0, 0, DEL_ALL_MAC
);
4982 /* Free up all remote VTEPs, if any. */
4983 zebra_evpn_vtep_del_all(zevpn
, 0);
4985 /* Delete the hash entry. */
4986 if (zebra_evpn_vxlan_del(zevpn
)) {
4987 flog_err(EC_ZEBRA_VNI_DEL_FAILED
,
4988 "Failed to del EVPN hash %p, IF %s(%u) VNI %u",
4989 zevpn
, ifp
->name
, ifp
->ifindex
, zevpn
->vni
);
4997 * Handle VxLAN interface update - change to tunnel IP, master or VLAN.
4999 int zebra_vxlan_if_update(struct interface
*ifp
, uint16_t chgflags
)
5002 struct zebra_if
*zif
= NULL
;
5003 struct zebra_l2info_vxlan
*vxl
= NULL
;
5004 struct zebra_evpn
*zevpn
= NULL
;
5005 struct zebra_l3vni
*zl3vni
= NULL
;
5006 struct interface
*vlan_if
= NULL
;
5008 /* Check if EVPN is enabled. */
5009 if (!is_evpn_enabled())
5014 vxl
= &zif
->l2info
.vxl
;
5017 zl3vni
= zl3vni_lookup(vni
);
5020 if (IS_ZEBRA_DEBUG_VXLAN
)
5022 "Update L3-VNI %u intf %s(%u) VLAN %u local IP %pI4 master %u chg 0x%x",
5023 vni
, ifp
->name
, ifp
->ifindex
, vxl
->access_vlan
,
5025 zif
->brslave_info
.bridge_ifindex
, chgflags
);
5027 /* Removed from bridge? Cleanup and return */
5028 if ((chgflags
& ZEBRA_VXLIF_MASTER_CHANGE
)
5029 && (zif
->brslave_info
.bridge_ifindex
== IFINDEX_INTERNAL
)) {
5030 zebra_vxlan_process_l3vni_oper_down(zl3vni
);
5034 if ((chgflags
& ZEBRA_VXLIF_MASTER_MAC_CHANGE
)
5035 && if_is_operative(ifp
) && is_l3vni_oper_up(zl3vni
)) {
5036 zebra_vxlan_process_l3vni_oper_down(zl3vni
);
5037 zebra_vxlan_process_l3vni_oper_up(zl3vni
);
5041 /* access-vlan change - process oper down, associate with new
5042 * svi_if and then process oper up again
5044 if (chgflags
& ZEBRA_VXLIF_VLAN_CHANGE
) {
5045 if (if_is_operative(ifp
)) {
5046 zebra_vxlan_process_l3vni_oper_down(zl3vni
);
5047 zl3vni
->svi_if
= NULL
;
5048 zl3vni
->svi_if
= zl3vni_map_to_svi_if(zl3vni
);
5049 zl3vni
->mac_vlan_if
=
5050 zl3vni_map_to_mac_vlan_if(zl3vni
);
5051 zl3vni
->local_vtep_ip
= vxl
->vtep_ip
;
5052 if (is_l3vni_oper_up(zl3vni
))
5053 zebra_vxlan_process_l3vni_oper_up(
5059 * local-ip change - process oper down, associate with new
5060 * local-ip and then process oper up again
5062 if (chgflags
& ZEBRA_VXLIF_LOCAL_IP_CHANGE
) {
5063 if (if_is_operative(ifp
)) {
5064 zebra_vxlan_process_l3vni_oper_down(zl3vni
);
5065 zl3vni
->local_vtep_ip
= vxl
->vtep_ip
;
5066 if (is_l3vni_oper_up(zl3vni
))
5067 zebra_vxlan_process_l3vni_oper_up(
5072 /* Update local tunnel IP. */
5073 zl3vni
->local_vtep_ip
= vxl
->vtep_ip
;
5075 /* if we have a valid new master, process l3-vni oper up */
5076 if (chgflags
& ZEBRA_VXLIF_MASTER_CHANGE
) {
5077 if (if_is_operative(ifp
) && is_l3vni_oper_up(zl3vni
))
5078 zebra_vxlan_process_l3vni_oper_up(zl3vni
);
5082 /* Update VNI hash. */
5083 zevpn
= zebra_evpn_lookup(vni
);
5086 "Failed to find EVPN hash on update, IF %s(%u) VNI %u",
5087 ifp
->name
, ifp
->ifindex
, vni
);
5091 if (IS_ZEBRA_DEBUG_VXLAN
)
5093 "Update L2-VNI %u intf %s(%u) VLAN %u local IP %pI4 master %u chg 0x%x",
5094 vni
, ifp
->name
, ifp
->ifindex
, vxl
->access_vlan
,
5096 zif
->brslave_info
.bridge_ifindex
, chgflags
);
5098 /* Removed from bridge? Cleanup and return */
5099 if ((chgflags
& ZEBRA_VXLIF_MASTER_CHANGE
)
5100 && (zif
->brslave_info
.bridge_ifindex
== IFINDEX_INTERNAL
)) {
5101 /* Delete from client, remove all remote VTEPs */
5102 /* Also, free up all MACs and neighbors. */
5103 zevpn
->svi_if
= NULL
;
5104 zebra_evpn_send_del_to_client(zevpn
);
5105 zebra_evpn_neigh_del_all(zevpn
, 1, 0, DEL_ALL_NEIGH
);
5106 zebra_evpn_mac_del_all(zevpn
, 1, 0, DEL_ALL_MAC
);
5107 zebra_evpn_vtep_del_all(zevpn
, 1);
5111 /* Handle other changes. */
5112 if (chgflags
& ZEBRA_VXLIF_VLAN_CHANGE
) {
5113 /* Remove all existing local neigh and MACs for this VNI
5114 * (including from BGP)
5116 zebra_evpn_neigh_del_all(zevpn
, 0, 1, DEL_LOCAL_MAC
);
5117 zebra_evpn_mac_del_all(zevpn
, 0, 1, DEL_LOCAL_MAC
);
5120 if (zevpn
->local_vtep_ip
.s_addr
!= vxl
->vtep_ip
.s_addr
||
5121 zevpn
->mcast_grp
.s_addr
!= vxl
->mcast_grp
.s_addr
) {
5122 zebra_vxlan_sg_deref(zevpn
->local_vtep_ip
,
5124 zebra_vxlan_sg_ref(vxl
->vtep_ip
, vxl
->mcast_grp
);
5125 zevpn
->local_vtep_ip
= vxl
->vtep_ip
;
5126 zevpn
->mcast_grp
= vxl
->mcast_grp
;
5127 /* on local vtep-ip check if ES orig-ip
5128 * needs to be updated
5130 zebra_evpn_es_set_base_evpn(zevpn
);
5132 zevpn_vxlan_if_set(zevpn
, ifp
, true /* set */);
5133 vlan_if
= zvni_map_to_svi(vxl
->access_vlan
,
5134 zif
->brslave_info
.br_if
);
5136 zevpn
->svi_if
= vlan_if
;
5137 zevpn
->vrf_id
= vlan_if
->vrf
->vrf_id
;
5138 zl3vni
= zl3vni_from_vrf(vlan_if
->vrf
->vrf_id
);
5140 listnode_add_sort_nodup(zl3vni
->l2vnis
, zevpn
);
5143 /* Take further actions needed.
5144 * Note that if we are here, there is a change of interest.
5146 /* If down or not mapped to a bridge, we're done. */
5147 if (!if_is_operative(ifp
) || !zif
->brslave_info
.br_if
)
5150 /* Inform BGP, if there is a change of interest. */
5152 (ZEBRA_VXLIF_MASTER_CHANGE
| ZEBRA_VXLIF_LOCAL_IP_CHANGE
|
5153 ZEBRA_VXLIF_MCAST_GRP_CHANGE
| ZEBRA_VXLIF_VLAN_CHANGE
))
5154 zebra_evpn_send_add_to_client(zevpn
);
5156 /* If there is a valid new master or a VLAN mapping change,
5157 * read and populate local MACs and neighbors.
5158 * Also, reinstall any remote MACs and neighbors
5159 * for this VNI (based on new VLAN).
5161 if (chgflags
& ZEBRA_VXLIF_MASTER_CHANGE
)
5162 zebra_evpn_read_mac_neigh(zevpn
, ifp
);
5163 else if (chgflags
& ZEBRA_VXLIF_VLAN_CHANGE
) {
5164 struct mac_walk_ctx m_wctx
;
5165 struct neigh_walk_ctx n_wctx
;
5167 zebra_evpn_read_mac_neigh(zevpn
, ifp
);
5169 memset(&m_wctx
, 0, sizeof(m_wctx
));
5170 m_wctx
.zevpn
= zevpn
;
5171 hash_iterate(zevpn
->mac_table
,
5172 zebra_evpn_install_mac_hash
, &m_wctx
);
5174 memset(&n_wctx
, 0, sizeof(n_wctx
));
5175 n_wctx
.zevpn
= zevpn
;
5176 hash_iterate(zevpn
->neigh_table
,
5177 zebra_evpn_install_neigh_hash
, &n_wctx
);
5185 * Handle VxLAN interface add.
5187 int zebra_vxlan_if_add(struct interface
*ifp
)
5190 struct zebra_if
*zif
= NULL
;
5191 struct zebra_l2info_vxlan
*vxl
= NULL
;
5192 struct zebra_evpn
*zevpn
= NULL
;
5193 struct zebra_l3vni
*zl3vni
= NULL
;
5195 /* Check if EVPN is enabled. */
5196 if (!is_evpn_enabled())
5201 vxl
= &zif
->l2info
.vxl
;
5204 zl3vni
= zl3vni_lookup(vni
);
5207 /* process if-add for l3-vni*/
5208 if (IS_ZEBRA_DEBUG_VXLAN
)
5210 "Add L3-VNI %u intf %s(%u) VLAN %u local IP %pI4 master %u",
5211 vni
, ifp
->name
, ifp
->ifindex
, vxl
->access_vlan
,
5213 zif
->brslave_info
.bridge_ifindex
);
5215 /* associate with vxlan_if */
5216 zl3vni
->local_vtep_ip
= vxl
->vtep_ip
;
5217 zl3vni
->vxlan_if
= ifp
;
5219 /* Associate with SVI, if any. We can associate with svi-if only
5220 * after association with vxlan_if is complete */
5221 zl3vni
->svi_if
= zl3vni_map_to_svi_if(zl3vni
);
5223 zl3vni
->mac_vlan_if
= zl3vni_map_to_mac_vlan_if(zl3vni
);
5225 if (is_l3vni_oper_up(zl3vni
))
5226 zebra_vxlan_process_l3vni_oper_up(zl3vni
);
5229 /* process if-add for l2-vni */
5230 struct interface
*vlan_if
= NULL
;
5232 /* Create or update EVPN hash. */
5233 zevpn
= zebra_evpn_lookup(vni
);
5235 zevpn
= zebra_evpn_add(vni
);
5237 if (zevpn
->local_vtep_ip
.s_addr
!= vxl
->vtep_ip
.s_addr
||
5238 zevpn
->mcast_grp
.s_addr
!= vxl
->mcast_grp
.s_addr
) {
5239 zebra_vxlan_sg_deref(zevpn
->local_vtep_ip
,
5241 zebra_vxlan_sg_ref(vxl
->vtep_ip
, vxl
->mcast_grp
);
5242 zevpn
->local_vtep_ip
= vxl
->vtep_ip
;
5243 zevpn
->mcast_grp
= vxl
->mcast_grp
;
5244 /* on local vtep-ip check if ES orig-ip
5245 * needs to be updated
5247 zebra_evpn_es_set_base_evpn(zevpn
);
5249 zevpn_vxlan_if_set(zevpn
, ifp
, true /* set */);
5250 vlan_if
= zvni_map_to_svi(vxl
->access_vlan
,
5251 zif
->brslave_info
.br_if
);
5253 zevpn
->svi_if
= vlan_if
;
5254 zevpn
->vrf_id
= vlan_if
->vrf
->vrf_id
;
5255 zl3vni
= zl3vni_from_vrf(vlan_if
->vrf
->vrf_id
);
5257 listnode_add_sort_nodup(zl3vni
->l2vnis
, zevpn
);
5260 if (IS_ZEBRA_DEBUG_VXLAN
)
5262 "Add L2-VNI %u VRF %s intf %s(%u) VLAN %u local IP %pI4 mcast_grp %pI4 master %u",
5264 vlan_if
? vlan_if
->vrf
->name
: VRF_DEFAULT_NAME
,
5265 ifp
->name
, ifp
->ifindex
, vxl
->access_vlan
,
5266 &vxl
->vtep_ip
, &vxl
->mcast_grp
,
5267 zif
->brslave_info
.bridge_ifindex
);
5269 /* If down or not mapped to a bridge, we're done. */
5270 if (!if_is_operative(ifp
) || !zif
->brslave_info
.br_if
)
5274 zebra_evpn_send_add_to_client(zevpn
);
5276 /* Read and populate local MACs and neighbors */
5277 zebra_evpn_read_mac_neigh(zevpn
, ifp
);
5283 int zebra_vxlan_process_vrf_vni_cmd(struct zebra_vrf
*zvrf
, vni_t vni
,
5284 char *err
, int err_str_sz
, int filter
,
5287 struct zebra_l3vni
*zl3vni
= NULL
;
5288 struct zebra_vrf
*zvrf_evpn
= NULL
;
5290 zvrf_evpn
= zebra_vrf_get_evpn();
5292 if (IS_ZEBRA_DEBUG_VXLAN
)
5293 zlog_debug("vrf %s vni %u %s", zvrf_name(zvrf
), vni
,
5294 add
? "ADD" : "DEL");
5297 /* check if the vni is already present under zvrf */
5299 snprintf(err
, err_str_sz
,
5300 "VNI is already configured under the vrf");
5304 /* check if this VNI is already present in the system */
5305 zl3vni
= zl3vni_lookup(vni
);
5307 snprintf(err
, err_str_sz
,
5308 "VNI is already configured as L3-VNI");
5312 /* Remove L2VNI if present */
5313 zebra_vxlan_handle_vni_transition(zvrf
, vni
, add
);
5315 /* add the L3-VNI to the global table */
5316 zl3vni
= zl3vni_add(vni
, zvrf_id(zvrf
));
5318 /* associate the vrf with vni */
5321 /* set the filter in l3vni to denote if we are using l3vni only
5325 SET_FLAG(zl3vni
->filter
, PREFIX_ROUTES_ONLY
);
5327 /* associate with vxlan-intf;
5328 * we need to associate with the vxlan-intf first
5330 zl3vni
->vxlan_if
= zl3vni_map_to_vxlan_if(zl3vni
);
5332 /* associate with corresponding SVI interface, we can associate
5333 * with svi-if only after vxlan interface association is
5336 zl3vni
->svi_if
= zl3vni_map_to_svi_if(zl3vni
);
5338 zl3vni
->mac_vlan_if
= zl3vni_map_to_mac_vlan_if(zl3vni
);
5340 if (IS_ZEBRA_DEBUG_VXLAN
)
5342 "%s: l3vni %u svi_if %s mac_vlan_if %s",
5344 zl3vni
->svi_if
? zl3vni
->svi_if
->name
: "NIL",
5345 zl3vni
->mac_vlan_if
? zl3vni
->mac_vlan_if
->name
5348 /* formulate l2vni list */
5349 hash_iterate(zvrf_evpn
->evpn_table
, zevpn_add_to_l3vni_list
,
5352 if (is_l3vni_oper_up(zl3vni
))
5353 zebra_vxlan_process_l3vni_oper_up(zl3vni
);
5356 zl3vni
= zl3vni_lookup(vni
);
5358 snprintf(err
, err_str_sz
, "VNI doesn't exist");
5362 if (zvrf
->l3vni
!= vni
) {
5363 snprintf(err
, err_str_sz
,
5364 "VNI %d doesn't exist in VRF: %s",
5365 vni
, zvrf
->vrf
->name
);
5369 if (filter
&& !CHECK_FLAG(zl3vni
->filter
, PREFIX_ROUTES_ONLY
)) {
5370 snprintf(err
, ERR_STR_SZ
,
5371 "prefix-routes-only is not set for the vni");
5375 zebra_vxlan_process_l3vni_oper_down(zl3vni
);
5377 /* delete and uninstall all rmacs */
5378 hash_iterate(zl3vni
->rmac_table
, zl3vni_del_rmac_hash_entry
,
5381 /* delete and uninstall all next-hops */
5382 hash_iterate(zl3vni
->nh_table
, zl3vni_del_nh_hash_entry
,
5388 /* Add L2VNI for this VNI */
5389 zebra_vxlan_handle_vni_transition(zvrf
, vni
, add
);
5394 int zebra_vxlan_vrf_enable(struct zebra_vrf
*zvrf
)
5396 struct zebra_l3vni
*zl3vni
= NULL
;
5399 zl3vni
= zl3vni_lookup(zvrf
->l3vni
);
5403 zl3vni
->vrf_id
= zvrf_id(zvrf
);
5404 if (is_l3vni_oper_up(zl3vni
))
5405 zebra_vxlan_process_l3vni_oper_up(zl3vni
);
5409 int zebra_vxlan_vrf_disable(struct zebra_vrf
*zvrf
)
5411 struct zebra_l3vni
*zl3vni
= NULL
;
5414 zl3vni
= zl3vni_lookup(zvrf
->l3vni
);
5418 zebra_vxlan_process_l3vni_oper_down(zl3vni
);
5420 /* delete and uninstall all rmacs */
5421 hash_iterate(zl3vni
->rmac_table
, zl3vni_del_rmac_hash_entry
, zl3vni
);
5422 /* delete and uninstall all next-hops */
5423 hash_iterate(zl3vni
->nh_table
, zl3vni_del_nh_hash_entry
, zl3vni
);
5425 zl3vni
->vrf_id
= VRF_UNKNOWN
;
5430 int zebra_vxlan_vrf_delete(struct zebra_vrf
*zvrf
)
5432 struct zebra_l3vni
*zl3vni
= NULL
;
5436 zl3vni
= zl3vni_lookup(zvrf
->l3vni
);
5442 zebra_vxlan_handle_vni_transition(zvrf
, vni
, 0);
5448 * Handle message from client to specify the flooding mechanism for
5449 * BUM packets. The default is to do head-end (ingress) replication
5450 * and the other supported option is to disable it. This applies to
5451 * all BUM traffic and disabling it applies to both the transmit and
5452 * receive direction.
5454 void zebra_vxlan_flood_control(ZAPI_HANDLER_ARGS
)
5457 enum vxlan_flood_control flood_ctrl
;
5459 if (!EVPN_ENABLED(zvrf
)) {
5460 zlog_err("EVPN flood control for non-EVPN VRF %u",
5466 STREAM_GETC(s
, flood_ctrl
);
5468 if (IS_ZEBRA_DEBUG_VXLAN
)
5469 zlog_debug("EVPN flood control %u, currently %u",
5470 flood_ctrl
, zvrf
->vxlan_flood_ctrl
);
5472 if (zvrf
->vxlan_flood_ctrl
== flood_ctrl
)
5475 zvrf
->vxlan_flood_ctrl
= flood_ctrl
;
5477 /* Install or uninstall flood entries corresponding to
5480 hash_iterate(zvrf
->evpn_table
, zebra_evpn_handle_flooding_remote_vteps
,
5488 * Handle message from client to enable/disable advertisement of svi macip
5491 void zebra_vxlan_advertise_svi_macip(ZAPI_HANDLER_ARGS
)
5496 struct zebra_evpn
*zevpn
= NULL
;
5497 struct interface
*ifp
= NULL
;
5499 if (!EVPN_ENABLED(zvrf
)) {
5500 zlog_debug("EVPN SVI-MACIP Adv for non-EVPN VRF %u",
5506 STREAM_GETC(s
, advertise
);
5507 STREAM_GETL(s
, vni
);
5510 if (IS_ZEBRA_DEBUG_VXLAN
)
5511 zlog_debug("EVPN SVI-MACIP Adv %s, currently %s",
5512 advertise
? "enabled" : "disabled",
5513 advertise_svi_macip_enabled(NULL
)
5517 if (zvrf
->advertise_svi_macip
== advertise
)
5522 zvrf
->advertise_svi_macip
= advertise
;
5523 hash_iterate(zvrf
->evpn_table
,
5524 zebra_evpn_gw_macip_add_for_evpn_hash
,
5527 hash_iterate(zvrf
->evpn_table
,
5528 zebra_evpn_svi_macip_del_for_evpn_hash
,
5530 zvrf
->advertise_svi_macip
= advertise
;
5534 struct zebra_if
*zif
= NULL
;
5535 struct zebra_l2info_vxlan zl2_info
;
5536 struct interface
*vlan_if
= NULL
;
5538 zevpn
= zebra_evpn_lookup(vni
);
5542 if (IS_ZEBRA_DEBUG_VXLAN
)
5544 "EVPN SVI macip Adv %s on VNI %d , currently %s",
5545 advertise
? "enabled" : "disabled", vni
,
5546 advertise_svi_macip_enabled(zevpn
)
5550 if (zevpn
->advertise_svi_macip
== advertise
)
5553 /* Store flag even though SVI is not present.
5554 * Once SVI comes up triggers self MAC-IP route add.
5556 zevpn
->advertise_svi_macip
= advertise
;
5558 ifp
= zevpn
->vxlan_if
;
5564 /* If down or not mapped to a bridge, we're done. */
5565 if (!if_is_operative(ifp
) || !zif
->brslave_info
.br_if
)
5568 zl2_info
= zif
->l2info
.vxl
;
5569 vlan_if
= zvni_map_to_svi(zl2_info
.access_vlan
,
5570 zif
->brslave_info
.br_if
);
5575 /* Add primary SVI MAC-IP */
5576 zebra_evpn_add_macip_for_intf(vlan_if
, zevpn
);
5578 /* Del primary SVI MAC-IP */
5579 zebra_evpn_del_macip_for_intf(vlan_if
, zevpn
);
5588 * Handle message from client to enable/disable advertisement of g/w macip
5591 void zebra_vxlan_advertise_subnet(ZAPI_HANDLER_ARGS
)
5596 struct zebra_evpn
*zevpn
= NULL
;
5597 struct interface
*ifp
= NULL
;
5598 struct zebra_if
*zif
= NULL
;
5599 struct zebra_l2info_vxlan zl2_info
;
5600 struct interface
*vlan_if
= NULL
;
5602 if (!EVPN_ENABLED(zvrf
)) {
5603 zlog_debug("EVPN GW-MACIP Adv for non-EVPN VRF %u",
5609 STREAM_GETC(s
, advertise
);
5610 STREAM_GET(&vni
, s
, 3);
5612 zevpn
= zebra_evpn_lookup(vni
);
5616 if (zevpn
->advertise_subnet
== advertise
)
5619 if (IS_ZEBRA_DEBUG_VXLAN
)
5620 zlog_debug("EVPN subnet Adv %s on VNI %d , currently %s",
5621 advertise
? "enabled" : "disabled", vni
,
5622 zevpn
->advertise_subnet
? "enabled" : "disabled");
5625 zevpn
->advertise_subnet
= advertise
;
5627 ifp
= zevpn
->vxlan_if
;
5633 /* If down or not mapped to a bridge, we're done. */
5634 if (!if_is_operative(ifp
) || !zif
->brslave_info
.br_if
)
5637 zl2_info
= zif
->l2info
.vxl
;
5640 zvni_map_to_svi(zl2_info
.access_vlan
, zif
->brslave_info
.br_if
);
5644 if (zevpn
->advertise_subnet
)
5645 zebra_evpn_advertise_subnet(zevpn
, vlan_if
, 1);
5647 zebra_evpn_advertise_subnet(zevpn
, vlan_if
, 0);
5654 * Handle message from client to enable/disable advertisement of g/w macip
5657 void zebra_vxlan_advertise_gw_macip(ZAPI_HANDLER_ARGS
)
5662 struct zebra_evpn
*zevpn
= NULL
;
5663 struct interface
*ifp
= NULL
;
5665 if (!EVPN_ENABLED(zvrf
)) {
5666 zlog_debug("EVPN GW-MACIP Adv for non-EVPN VRF %u",
5672 STREAM_GETC(s
, advertise
);
5673 STREAM_GETL(s
, vni
);
5676 if (IS_ZEBRA_DEBUG_VXLAN
)
5677 zlog_debug("EVPN gateway macip Adv %s, currently %s",
5678 advertise
? "enabled" : "disabled",
5679 advertise_gw_macip_enabled(NULL
)
5683 if (zvrf
->advertise_gw_macip
== advertise
)
5686 zvrf
->advertise_gw_macip
= advertise
;
5688 if (advertise_gw_macip_enabled(zevpn
))
5689 hash_iterate(zvrf
->evpn_table
,
5690 zebra_evpn_gw_macip_add_for_evpn_hash
,
5693 hash_iterate(zvrf
->evpn_table
,
5694 zebra_evpn_gw_macip_del_for_evpn_hash
,
5698 struct zebra_if
*zif
= NULL
;
5699 struct zebra_l2info_vxlan zl2_info
;
5700 struct interface
*vlan_if
= NULL
;
5701 struct interface
*vrr_if
= NULL
;
5703 zevpn
= zebra_evpn_lookup(vni
);
5707 if (IS_ZEBRA_DEBUG_VXLAN
)
5709 "EVPN gateway macip Adv %s on VNI %d , currently %s",
5710 advertise
? "enabled" : "disabled", vni
,
5711 advertise_gw_macip_enabled(zevpn
) ? "enabled"
5714 if (zevpn
->advertise_gw_macip
== advertise
)
5717 zevpn
->advertise_gw_macip
= advertise
;
5719 ifp
= zevpn
->vxlan_if
;
5725 /* If down or not mapped to a bridge, we're done. */
5726 if (!if_is_operative(ifp
) || !zif
->brslave_info
.br_if
)
5729 zl2_info
= zif
->l2info
.vxl
;
5731 vlan_if
= zvni_map_to_svi(zl2_info
.access_vlan
,
5732 zif
->brslave_info
.br_if
);
5736 if (advertise_gw_macip_enabled(zevpn
)) {
5737 /* Add primary SVI MAC-IP */
5738 zebra_evpn_add_macip_for_intf(vlan_if
, zevpn
);
5740 /* Add VRR MAC-IP - if any*/
5741 vrr_if
= zebra_get_vrr_intf_for_svi(vlan_if
);
5743 zebra_evpn_add_macip_for_intf(vrr_if
, zevpn
);
5745 /* Del primary MAC-IP */
5746 zebra_evpn_del_macip_for_intf(vlan_if
, zevpn
);
5748 /* Del VRR MAC-IP - if any*/
5749 vrr_if
= zebra_get_vrr_intf_for_svi(vlan_if
);
5751 zebra_evpn_del_macip_for_intf(vrr_if
, zevpn
);
5759 static int macfdb_read_ns(struct ns
*ns
,
5760 void *_in_param
__attribute__((unused
)),
5761 void **out_param
__attribute__((unused
)))
5763 struct zebra_ns
*zns
= ns
->info
;
5766 return NS_WALK_CONTINUE
;
5769 static int neigh_read_ns(struct ns
*ns
,
5770 void *_in_param
__attribute__((unused
)),
5771 void **out_param
__attribute__((unused
)))
5773 struct zebra_ns
*zns
= ns
->info
;
5776 return NS_WALK_CONTINUE
;
5780 * Handle message from client to learn (or stop learning) about VNIs and MACs.
5781 * When enabled, the VNI hash table will be built and MAC FDB table read;
5782 * when disabled, the entries should be deleted and remote VTEPs and MACs
5783 * uninstalled from the kernel.
5784 * This also informs the setting for BUM handling at the time this change
5785 * occurs; it is relevant only when specifying "learn".
5787 void zebra_vxlan_advertise_all_vni(ZAPI_HANDLER_ARGS
)
5789 struct stream
*s
= NULL
;
5791 enum vxlan_flood_control flood_ctrl
;
5793 /* Mismatch between EVPN VRF and current VRF (should be prevented by
5795 if (is_evpn_enabled() && !EVPN_ENABLED(zvrf
))
5799 STREAM_GETC(s
, advertise
);
5800 STREAM_GETC(s
, flood_ctrl
);
5802 if (IS_ZEBRA_DEBUG_VXLAN
)
5803 zlog_debug("EVPN VRF %s(%u) VNI Adv %s, currently %s, flood control %u",
5804 zvrf_name(zvrf
), zvrf_id(zvrf
),
5805 advertise
? "enabled" : "disabled",
5806 is_evpn_enabled() ? "enabled" : "disabled",
5809 if (zvrf
->advertise_all_vni
== advertise
)
5812 zvrf
->advertise_all_vni
= advertise
;
5813 if (EVPN_ENABLED(zvrf
)) {
5814 zrouter
.evpn_vrf
= zvrf
;
5816 /* Note BUM handling */
5817 zvrf
->vxlan_flood_ctrl
= flood_ctrl
;
5819 /* Replay all ESs */
5820 zebra_evpn_es_send_all_to_client(true /* add */);
5822 /* Build EVPN hash table and inform BGP. */
5823 zevpn_build_hash_table();
5825 /* Add all SVI (L3 GW) MACs to BGP*/
5826 hash_iterate(zvrf
->evpn_table
,
5827 zebra_evpn_gw_macip_add_for_evpn_hash
, NULL
);
5829 /* Read the MAC FDB */
5830 ns_walk_func(macfdb_read_ns
, NULL
, NULL
);
5832 /* Read neighbors */
5833 ns_walk_func(neigh_read_ns
, NULL
, NULL
);
5835 /* Cleanup VTEPs for all EVPNs - uninstall from
5836 * kernel and free entries.
5838 hash_iterate(zvrf
->evpn_table
, zebra_evpn_vxlan_cleanup_all
,
5841 /* Delete all ESs in BGP */
5842 zebra_evpn_es_send_all_to_client(false /* add */);
5844 /* cleanup all l3vnis */
5845 hash_iterate(zrouter
.l3vni_table
, zl3vni_cleanup_all
, NULL
);
5847 /* Mark as "no EVPN VRF" */
5848 zrouter
.evpn_vrf
= NULL
;
5856 * Allocate EVPN hash table for this VRF and do other initialization.
5857 * NOTE: Currently supported only for default VRF.
5859 void zebra_vxlan_init_tables(struct zebra_vrf
*zvrf
)
5866 snprintf(buffer
, sizeof(buffer
), "Zebra VRF EVPN Table: %s",
5868 zvrf
->evpn_table
= hash_create_size(8, zebra_evpn_hash_keymake
,
5869 zebra_evpn_hash_cmp
, buffer
);
5871 snprintf(buffer
, sizeof(buffer
), "Zebra VxLAN SG Table: %s",
5873 zvrf
->vxlan_sg_table
= hash_create_size(8, zebra_vxlan_sg_hash_key_make
,
5874 zebra_vxlan_sg_hash_eq
, buffer
);
5877 /* Cleanup EVPN info, but don't free the table. */
5878 void zebra_vxlan_cleanup_tables(struct zebra_vrf
*zvrf
)
5880 struct zebra_vrf
*evpn_zvrf
= zebra_vrf_get_evpn();
5882 hash_iterate(zvrf
->evpn_table
, zebra_evpn_vxlan_cleanup_all
, zvrf
);
5883 zebra_vxlan_cleanup_sg_table(zvrf
);
5885 if (zvrf
== evpn_zvrf
)
5886 zebra_evpn_es_cleanup();
5889 /* Close all EVPN handling */
5890 void zebra_vxlan_close_tables(struct zebra_vrf
*zvrf
)
5894 hash_iterate(zvrf
->evpn_table
, zebra_evpn_vxlan_cleanup_all
, zvrf
);
5895 hash_free(zvrf
->evpn_table
);
5896 if (zvrf
->vxlan_sg_table
) {
5897 zebra_vxlan_cleanup_sg_table(zvrf
);
5898 hash_free(zvrf
->vxlan_sg_table
);
5899 zvrf
->vxlan_sg_table
= NULL
;
5903 /* init the l3vni table */
5904 void zebra_vxlan_init(void)
5906 zrouter
.l3vni_table
= hash_create(l3vni_hash_keymake
, l3vni_hash_cmp
,
5907 "Zebra VRF L3 VNI table");
5908 zrouter
.evpn_vrf
= NULL
;
5909 zebra_evpn_mh_init();
5912 /* free l3vni table */
5913 void zebra_vxlan_disable(void)
5915 hash_free(zrouter
.l3vni_table
);
5916 zebra_evpn_mh_terminate();
5919 /* get the l3vni svi ifindex */
5920 ifindex_t
get_l3vni_svi_ifindex(vrf_id_t vrf_id
)
5922 struct zebra_l3vni
*zl3vni
= NULL
;
5924 zl3vni
= zl3vni_from_vrf(vrf_id
);
5925 if (!zl3vni
|| !is_l3vni_oper_up(zl3vni
))
5928 return zl3vni
->svi_if
->ifindex
;
5931 /************************** vxlan SG cache management ************************/
5932 /* Inform PIM about the mcast group */
5933 static int zebra_vxlan_sg_send(struct zebra_vrf
*zvrf
,
5934 struct prefix_sg
*sg
,
5935 char *sg_str
, uint16_t cmd
)
5937 struct zserv
*client
= NULL
;
5938 struct stream
*s
= NULL
;
5940 client
= zserv_find_client(ZEBRA_ROUTE_PIM
, 0);
5944 if (!CHECK_FLAG(zvrf
->flags
, ZEBRA_PIM_SEND_VXLAN_SG
))
5947 s
= stream_new(ZEBRA_MAX_PACKET_SIZ
);
5949 zclient_create_header(s
, cmd
, VRF_DEFAULT
);
5950 stream_putl(s
, IPV4_MAX_BYTELEN
);
5951 stream_put(s
, &sg
->src
.s_addr
, IPV4_MAX_BYTELEN
);
5952 stream_put(s
, &sg
->grp
.s_addr
, IPV4_MAX_BYTELEN
);
5954 /* Write packet size. */
5955 stream_putw_at(s
, 0, stream_get_endp(s
));
5957 if (IS_ZEBRA_DEBUG_VXLAN
)
5960 (cmd
== ZEBRA_VXLAN_SG_ADD
) ? "add" : "del", sg_str
,
5961 zebra_route_string(client
->proto
));
5963 if (cmd
== ZEBRA_VXLAN_SG_ADD
)
5964 client
->vxlan_sg_add_cnt
++;
5966 client
->vxlan_sg_del_cnt
++;
5968 return zserv_send_message(client
, s
);
5971 static unsigned int zebra_vxlan_sg_hash_key_make(const void *p
)
5973 const struct zebra_vxlan_sg
*vxlan_sg
= p
;
5975 return (jhash_2words(vxlan_sg
->sg
.src
.s_addr
,
5976 vxlan_sg
->sg
.grp
.s_addr
, 0));
5979 static bool zebra_vxlan_sg_hash_eq(const void *p1
, const void *p2
)
5981 const struct zebra_vxlan_sg
*sg1
= p1
;
5982 const struct zebra_vxlan_sg
*sg2
= p2
;
5984 return ((sg1
->sg
.src
.s_addr
== sg2
->sg
.src
.s_addr
)
5985 && (sg1
->sg
.grp
.s_addr
== sg2
->sg
.grp
.s_addr
));
5988 static struct zebra_vxlan_sg
*zebra_vxlan_sg_new(struct zebra_vrf
*zvrf
,
5989 struct prefix_sg
*sg
)
5991 struct zebra_vxlan_sg
*vxlan_sg
;
5993 vxlan_sg
= XCALLOC(MTYPE_ZVXLAN_SG
, sizeof(*vxlan_sg
));
5995 vxlan_sg
->zvrf
= zvrf
;
5997 prefix_sg2str(sg
, vxlan_sg
->sg_str
);
5999 vxlan_sg
= hash_get(zvrf
->vxlan_sg_table
, vxlan_sg
, hash_alloc_intern
);
6001 if (IS_ZEBRA_DEBUG_VXLAN
)
6002 zlog_debug("vxlan SG %s created", vxlan_sg
->sg_str
);
6007 static struct zebra_vxlan_sg
*zebra_vxlan_sg_find(struct zebra_vrf
*zvrf
,
6008 struct prefix_sg
*sg
)
6010 struct zebra_vxlan_sg lookup
;
6013 return hash_lookup(zvrf
->vxlan_sg_table
, &lookup
);
6016 static struct zebra_vxlan_sg
*zebra_vxlan_sg_add(struct zebra_vrf
*zvrf
,
6017 struct prefix_sg
*sg
)
6019 struct zebra_vxlan_sg
*vxlan_sg
;
6020 struct zebra_vxlan_sg
*parent
= NULL
;
6023 vxlan_sg
= zebra_vxlan_sg_find(zvrf
, sg
);
6027 /* create a *G entry for every BUM group implicitly -
6028 * 1. The SG entry is used by pimd to setup the vxlan-origination-mroute
6029 * 2. the XG entry is used by pimd to setup the
6030 * vxlan-termination-mroute
6032 if (sg
->src
.s_addr
!= INADDR_ANY
) {
6033 memset(&sip
, 0, sizeof(sip
));
6034 parent
= zebra_vxlan_sg_do_ref(zvrf
, sip
, sg
->grp
);
6039 vxlan_sg
= zebra_vxlan_sg_new(zvrf
, sg
);
6041 zebra_vxlan_sg_send(zvrf
, sg
, vxlan_sg
->sg_str
,
6042 ZEBRA_VXLAN_SG_ADD
);
6047 static void zebra_vxlan_sg_del(struct zebra_vxlan_sg
*vxlan_sg
)
6050 struct zebra_vrf
*zvrf
;
6052 zvrf
= vrf_info_lookup(VRF_DEFAULT
);
6056 /* On SG entry deletion remove the reference to its parent XG
6059 if (vxlan_sg
->sg
.src
.s_addr
!= INADDR_ANY
) {
6060 memset(&sip
, 0, sizeof(sip
));
6061 zebra_vxlan_sg_do_deref(zvrf
, sip
, vxlan_sg
->sg
.grp
);
6064 zebra_vxlan_sg_send(zvrf
, &vxlan_sg
->sg
,
6065 vxlan_sg
->sg_str
, ZEBRA_VXLAN_SG_DEL
);
6067 hash_release(vxlan_sg
->zvrf
->vxlan_sg_table
, vxlan_sg
);
6069 if (IS_ZEBRA_DEBUG_VXLAN
)
6070 zlog_debug("VXLAN SG %s deleted", vxlan_sg
->sg_str
);
6072 XFREE(MTYPE_ZVXLAN_SG
, vxlan_sg
);
6075 static void zebra_vxlan_sg_do_deref(struct zebra_vrf
*zvrf
,
6076 struct in_addr sip
, struct in_addr mcast_grp
)
6078 struct zebra_vxlan_sg
*vxlan_sg
;
6079 struct prefix_sg sg
;
6081 sg
.family
= AF_INET
;
6082 sg
.prefixlen
= IPV4_MAX_BYTELEN
;
6085 vxlan_sg
= zebra_vxlan_sg_find(zvrf
, &sg
);
6089 if (vxlan_sg
->ref_cnt
)
6090 --vxlan_sg
->ref_cnt
;
6092 if (!vxlan_sg
->ref_cnt
)
6093 zebra_vxlan_sg_del(vxlan_sg
);
6096 static struct zebra_vxlan_sg
*zebra_vxlan_sg_do_ref(struct zebra_vrf
*zvrf
,
6098 struct in_addr mcast_grp
)
6100 struct zebra_vxlan_sg
*vxlan_sg
;
6101 struct prefix_sg sg
;
6103 sg
.family
= AF_INET
;
6104 sg
.prefixlen
= IPV4_MAX_BYTELEN
;
6107 vxlan_sg
= zebra_vxlan_sg_add(zvrf
, &sg
);
6109 ++vxlan_sg
->ref_cnt
;
6114 static void zebra_vxlan_sg_deref(struct in_addr local_vtep_ip
,
6115 struct in_addr mcast_grp
)
6117 struct zebra_vrf
*zvrf
;
6119 if (local_vtep_ip
.s_addr
== INADDR_ANY
6120 || mcast_grp
.s_addr
== INADDR_ANY
)
6123 zvrf
= vrf_info_lookup(VRF_DEFAULT
);
6127 zebra_vxlan_sg_do_deref(zvrf
, local_vtep_ip
, mcast_grp
);
6130 static void zebra_vxlan_sg_ref(struct in_addr local_vtep_ip
,
6131 struct in_addr mcast_grp
)
6133 struct zebra_vrf
*zvrf
;
6135 if (local_vtep_ip
.s_addr
== INADDR_ANY
6136 || mcast_grp
.s_addr
== INADDR_ANY
)
6139 zvrf
= vrf_info_lookup(VRF_DEFAULT
);
6142 zebra_vxlan_sg_do_ref(zvrf
, local_vtep_ip
, mcast_grp
);
6145 static void zebra_vxlan_xg_pre_cleanup(struct hash_bucket
*bucket
, void *arg
)
6147 struct zebra_vxlan_sg
*vxlan_sg
= (struct zebra_vxlan_sg
*)bucket
->data
;
6149 /* increment the ref count against (*,G) to prevent them from being
6152 if (vxlan_sg
->sg
.src
.s_addr
== INADDR_ANY
)
6153 ++vxlan_sg
->ref_cnt
;
6156 static void zebra_vxlan_xg_post_cleanup(struct hash_bucket
*bucket
, void *arg
)
6158 struct zebra_vxlan_sg
*vxlan_sg
= (struct zebra_vxlan_sg
*)bucket
->data
;
6160 /* decrement the dummy ref count against (*,G) to delete them */
6161 if (vxlan_sg
->sg
.src
.s_addr
== INADDR_ANY
) {
6162 if (vxlan_sg
->ref_cnt
)
6163 --vxlan_sg
->ref_cnt
;
6164 if (!vxlan_sg
->ref_cnt
)
6165 zebra_vxlan_sg_del(vxlan_sg
);
6169 static void zebra_vxlan_sg_cleanup(struct hash_bucket
*bucket
, void *arg
)
6171 struct zebra_vxlan_sg
*vxlan_sg
= (struct zebra_vxlan_sg
*)bucket
->data
;
6173 zebra_vxlan_sg_del(vxlan_sg
);
6176 static void zebra_vxlan_cleanup_sg_table(struct zebra_vrf
*zvrf
)
6178 /* increment the ref count against (*,G) to prevent them from being
6181 hash_iterate(zvrf
->vxlan_sg_table
, zebra_vxlan_xg_pre_cleanup
, NULL
);
6183 hash_iterate(zvrf
->vxlan_sg_table
, zebra_vxlan_sg_cleanup
, NULL
);
6185 /* decrement the dummy ref count against the XG entries */
6186 hash_iterate(zvrf
->vxlan_sg_table
, zebra_vxlan_xg_post_cleanup
, NULL
);
6189 static void zebra_vxlan_sg_replay_send(struct hash_bucket
*bucket
, void *arg
)
6191 struct zebra_vxlan_sg
*vxlan_sg
= (struct zebra_vxlan_sg
*)bucket
->data
;
6193 zebra_vxlan_sg_send(vxlan_sg
->zvrf
, &vxlan_sg
->sg
,
6194 vxlan_sg
->sg_str
, ZEBRA_VXLAN_SG_ADD
);
6197 /* Handle message from client to replay vxlan SG entries */
6198 void zebra_vxlan_sg_replay(ZAPI_HANDLER_ARGS
)
6200 if (IS_ZEBRA_DEBUG_VXLAN
)
6201 zlog_debug("VxLAN SG updates to PIM, start");
6203 SET_FLAG(zvrf
->flags
, ZEBRA_PIM_SEND_VXLAN_SG
);
6205 if (!EVPN_ENABLED(zvrf
)) {
6206 if (IS_ZEBRA_DEBUG_VXLAN
)
6207 zlog_debug("VxLAN SG replay request on unexpected vrf %d",
6212 hash_iterate(zvrf
->vxlan_sg_table
, zebra_vxlan_sg_replay_send
, NULL
);
6216 /* Cleanup EVPN configuration of a specific VRF */
6217 static void zebra_evpn_vrf_cfg_cleanup(struct zebra_vrf
*zvrf
)
6219 struct zebra_l3vni
*zl3vni
= NULL
;
6221 zvrf
->advertise_all_vni
= 0;
6222 zvrf
->advertise_gw_macip
= 0;
6223 zvrf
->advertise_svi_macip
= 0;
6224 zvrf
->vxlan_flood_ctrl
= VXLAN_FLOOD_HEAD_END_REPL
;
6226 hash_iterate(zvrf
->evpn_table
, zebra_evpn_cfg_cleanup
, NULL
);
6229 zl3vni
= zl3vni_lookup(zvrf
->l3vni
);
6231 /* delete and uninstall all rmacs */
6232 hash_iterate(zl3vni
->rmac_table
, zl3vni_del_rmac_hash_entry
,
6234 /* delete and uninstall all next-hops */
6235 hash_iterate(zl3vni
->nh_table
, zl3vni_del_nh_hash_entry
,
6240 /* Cleanup BGP EVPN configuration upon client disconnect */
6241 static int zebra_evpn_bgp_cfg_clean_up(struct zserv
*client
)
6244 struct zebra_vrf
*zvrf
;
6246 RB_FOREACH (vrf
, vrf_id_head
, &vrfs_by_id
) {
6249 zebra_evpn_vrf_cfg_cleanup(zvrf
);
6255 static int zebra_evpn_pim_cfg_clean_up(struct zserv
*client
)
6257 struct zebra_vrf
*zvrf
= zebra_vrf_get_evpn();
6259 if (CHECK_FLAG(zvrf
->flags
, ZEBRA_PIM_SEND_VXLAN_SG
)) {
6260 if (IS_ZEBRA_DEBUG_VXLAN
)
6261 zlog_debug("VxLAN SG updates to PIM, stop");
6262 UNSET_FLAG(zvrf
->flags
, ZEBRA_PIM_SEND_VXLAN_SG
);
6268 static int zebra_evpn_cfg_clean_up(struct zserv
*client
)
6270 if (client
->proto
== ZEBRA_ROUTE_BGP
)
6271 return zebra_evpn_bgp_cfg_clean_up(client
);
6273 if (client
->proto
== ZEBRA_ROUTE_PIM
)
6274 return zebra_evpn_pim_cfg_clean_up(client
);
6280 * Handle results for vxlan dataplane operations.
6282 extern void zebra_vxlan_handle_result(struct zebra_dplane_ctx
*ctx
)
6287 /* Cleanup BGP EVPN configuration upon client disconnect */
6288 extern void zebra_evpn_init(void)
6290 hook_register(zserv_client_close
, zebra_evpn_cfg_clean_up
);