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
36 #include <linux/neighbour.h>
39 #include "zebra/zebra_router.h"
40 #include "zebra/debug.h"
41 #include "zebra/interface.h"
42 #include "zebra/rib.h"
44 #include "zebra/rt_netlink.h"
45 #include "zebra/zebra_errors.h"
46 #include "zebra/zebra_l2.h"
47 #include "zebra/zebra_ns.h"
48 #include "zebra/zebra_vrf.h"
49 #include "zebra/zebra_vxlan.h"
50 #include "zebra/zebra_evpn.h"
51 #include "zebra/zebra_evpn_mac.h"
52 #include "zebra/zebra_evpn_neigh.h"
53 #include "zebra/zebra_vxlan_private.h"
54 #include "zebra/zebra_evpn_mh.h"
55 #include "zebra/zebra_evpn_vxlan.h"
56 #include "zebra/zebra_router.h"
58 DEFINE_MTYPE_STATIC(ZEBRA
, ZEVPN
, "VNI hash");
59 DEFINE_MTYPE_STATIC(ZEBRA
, ZEVPN_VTEP
, "VNI remote VTEP");
62 #define VXLAN_FLOOD_STR_NO_INFO "-"
63 #define VXLAN_FLOOD_STR_DEFAULT VXLAN_FLOOD_STR_NO_INFO
64 static const struct message zvtep_flood_str
[] = {
65 {VXLAN_FLOOD_DISABLED
, VXLAN_FLOOD_STR_NO_INFO
},
66 {VXLAN_FLOOD_PIM_SM
, "PIM-SM"},
67 {VXLAN_FLOOD_HEAD_END_REPL
, "HER"},
71 int advertise_gw_macip_enabled(struct zebra_evpn
*zevpn
)
73 struct zebra_vrf
*zvrf
;
75 zvrf
= zebra_vrf_get_evpn();
76 if (zvrf
&& zvrf
->advertise_gw_macip
)
79 if (zevpn
&& zevpn
->advertise_gw_macip
)
85 int advertise_svi_macip_enabled(struct zebra_evpn
*zevpn
)
87 struct zebra_vrf
*zvrf
;
89 zvrf
= zebra_vrf_get_evpn();
90 if (zvrf
&& zvrf
->advertise_svi_macip
)
93 if (zevpn
&& zevpn
->advertise_svi_macip
)
100 * Print a specific EVPN entry.
102 void zebra_evpn_print(struct zebra_evpn
*zevpn
, void **ctxt
)
105 struct zebra_vtep
*zvtep
;
108 json_object
*json
= NULL
;
109 json_object
*json_vtep_list
= NULL
;
110 json_object
*json_ip_str
= NULL
;
111 char buf
[PREFIX_STRLEN
];
117 vty_out(vty
, "VNI: %u\n", zevpn
->vni
);
118 vty_out(vty
, " Type: %s\n", "L2");
119 vty_out(vty
, " Tenant VRF: %s\n", vrf_id_to_name(zevpn
->vrf_id
));
121 json_object_int_add(json
, "vni", zevpn
->vni
);
122 json_object_string_add(json
, "type", "L2");
123 json_object_string_add(json
, "vrf",
124 vrf_id_to_name(zevpn
->vrf_id
));
127 if (!zevpn
->vxlan_if
) { // unexpected
129 vty_out(vty
, " VxLAN interface: unknown\n");
132 num_macs
= num_valid_macs(zevpn
);
133 num_neigh
= hashcount(zevpn
->neigh_table
);
135 vty_out(vty
, " VxLAN interface: %s\n", zevpn
->vxlan_if
->name
);
136 vty_out(vty
, " VxLAN ifIndex: %u\n", zevpn
->vxlan_if
->ifindex
);
137 vty_out(vty
, " SVI interface: %s\n",
138 (zevpn
->svi_if
? zevpn
->svi_if
->name
: ""));
139 vty_out(vty
, " SVI ifIndex: %u\n",
140 (zevpn
->svi_if
? zevpn
->svi_if
->ifindex
: 0));
141 vty_out(vty
, " Local VTEP IP: %pI4\n",
142 &zevpn
->local_vtep_ip
);
143 vty_out(vty
, " Mcast group: %pI4\n",
146 json_object_string_add(json
, "vxlanInterface",
147 zevpn
->vxlan_if
->name
);
148 json_object_int_add(json
, "ifindex", zevpn
->vxlan_if
->ifindex
);
150 json_object_string_add(json
, "sviInterface",
151 zevpn
->svi_if
->name
);
152 json_object_int_add(json
, "sviIfindex",
153 zevpn
->svi_if
->ifindex
);
155 json_object_string_add(json
, "vtepIp",
156 inet_ntop(AF_INET
, &zevpn
->local_vtep_ip
,
158 json_object_string_add(json
, "mcastGroup",
159 inet_ntop(AF_INET
, &zevpn
->mcast_grp
,
161 json_object_string_add(json
, "advertiseGatewayMacip",
162 zevpn
->advertise_gw_macip
? "Yes" : "No");
163 json_object_string_add(json
, "advertiseSviMacip",
164 zevpn
->advertise_svi_macip
? "Yes"
166 json_object_int_add(json
, "numMacs", num_macs
);
167 json_object_int_add(json
, "numArpNd", num_neigh
);
171 vty_out(vty
, " No remote VTEPs known for this VNI\n");
174 vty_out(vty
, " Remote VTEPs for this VNI:\n");
176 json_vtep_list
= json_object_new_array();
177 for (zvtep
= zevpn
->vteps
; zvtep
; zvtep
= zvtep
->next
) {
178 const char *flood_str
= lookup_msg(zvtep_flood_str
,
179 zvtep
->flood_control
,
180 VXLAN_FLOOD_STR_DEFAULT
);
183 vty_out(vty
, " %pI4 flood: %s\n",
187 json_ip_str
= json_object_new_string(
189 &zvtep
->vtep_ip
, buf
,
191 json_object_array_add(json_vtep_list
,
196 json_object_object_add(json
, "numRemoteVteps",
201 " Number of MACs (local and remote) known for this VNI: %u\n",
204 " Number of ARPs (IPv4 and IPv6, local and remote) "
205 "known for this VNI: %u\n",
207 vty_out(vty
, " Advertise-gw-macip: %s\n",
208 zevpn
->advertise_gw_macip
? "Yes" : "No");
209 vty_out(vty
, " Advertise-svi-macip: %s\n",
210 zevpn
->advertise_svi_macip
? "Yes" : "No");
215 * Print an EVPN hash entry - called for display of all VNIs.
217 void zebra_evpn_print_hash(struct hash_bucket
*bucket
, void *ctxt
[])
220 struct zebra_evpn
*zevpn
;
221 struct zebra_vtep
*zvtep
;
222 uint32_t num_vteps
= 0;
223 uint32_t num_macs
= 0;
224 uint32_t num_neigh
= 0;
225 json_object
*json
= NULL
;
226 json_object
*json_evpn
= NULL
;
227 json_object
*json_ip_str
= NULL
;
228 json_object
*json_vtep_list
= NULL
;
229 char buf
[PREFIX_STRLEN
];
234 zevpn
= (struct zebra_evpn
*)bucket
->data
;
236 zvtep
= zevpn
->vteps
;
242 num_macs
= num_valid_macs(zevpn
);
243 num_neigh
= hashcount(zevpn
->neigh_table
);
245 vty_out(vty
, "%-10u %-4s %-21s %-8u %-8u %-15u %-37s\n",
247 zevpn
->vxlan_if
? zevpn
->vxlan_if
->name
: "unknown",
248 num_macs
, num_neigh
, num_vteps
,
249 vrf_id_to_name(zevpn
->vrf_id
));
251 char vni_str
[VNI_STR_LEN
];
252 snprintf(vni_str
, VNI_STR_LEN
, "%u", zevpn
->vni
);
253 json_evpn
= json_object_new_object();
254 json_object_int_add(json_evpn
, "vni", zevpn
->vni
);
255 json_object_string_add(json_evpn
, "type", "L2");
256 json_object_string_add(json_evpn
, "vxlanIf",
257 zevpn
->vxlan_if
? zevpn
->vxlan_if
->name
259 json_object_int_add(json_evpn
, "numMacs", num_macs
);
260 json_object_int_add(json_evpn
, "numArpNd", num_neigh
);
261 json_object_int_add(json_evpn
, "numRemoteVteps", num_vteps
);
262 json_object_string_add(json_evpn
, "tenantVrf",
263 vrf_id_to_name(zevpn
->vrf_id
));
265 json_vtep_list
= json_object_new_array();
266 for (zvtep
= zevpn
->vteps
; zvtep
; zvtep
= zvtep
->next
) {
267 json_ip_str
= json_object_new_string(
268 inet_ntop(AF_INET
, &zvtep
->vtep_ip
, buf
,
270 json_object_array_add(json_vtep_list
,
273 json_object_object_add(json_evpn
, "remoteVteps",
276 json_object_object_add(json
, vni_str
, json_evpn
);
281 * Print an EVPN hash entry in detail - called for display of all EVPNs.
283 void zebra_evpn_print_hash_detail(struct hash_bucket
*bucket
, void *data
)
286 struct zebra_evpn
*zevpn
;
287 json_object
*json_array
= NULL
;
288 bool use_json
= false;
289 struct zebra_evpn_show
*zes
= data
;
292 json_array
= zes
->json
;
293 use_json
= zes
->use_json
;
295 zevpn
= (struct zebra_evpn
*)bucket
->data
;
297 zebra_vxlan_print_vni(vty
, zes
->zvrf
, zevpn
->vni
, use_json
, json_array
);
303 int zebra_evpn_del_macip_for_intf(struct interface
*ifp
,
304 struct zebra_evpn
*zevpn
)
306 struct listnode
*cnode
= NULL
, *cnnode
= NULL
;
307 struct connected
*c
= NULL
;
308 struct ethaddr macaddr
;
310 memcpy(&macaddr
.octet
, ifp
->hw_addr
, ETH_ALEN
);
312 for (ALL_LIST_ELEMENTS(ifp
->connected
, cnode
, cnnode
, c
)) {
315 memset(&ip
, 0, sizeof(struct ipaddr
));
316 if (!CHECK_FLAG(c
->conf
, ZEBRA_IFC_REAL
))
319 if (c
->address
->family
== AF_INET
) {
320 ip
.ipa_type
= IPADDR_V4
;
321 memcpy(&(ip
.ipaddr_v4
), &(c
->address
->u
.prefix4
),
322 sizeof(struct in_addr
));
323 } else if (c
->address
->family
== AF_INET6
) {
324 ip
.ipa_type
= IPADDR_V6
;
325 memcpy(&(ip
.ipaddr_v6
), &(c
->address
->u
.prefix6
),
326 sizeof(struct in6_addr
));
331 zebra_evpn_gw_macip_del(ifp
, zevpn
, &ip
);
337 int zebra_evpn_add_macip_for_intf(struct interface
*ifp
,
338 struct zebra_evpn
*zevpn
)
340 struct listnode
*cnode
= NULL
, *cnnode
= NULL
;
341 struct connected
*c
= NULL
;
342 struct ethaddr macaddr
;
344 memcpy(&macaddr
.octet
, ifp
->hw_addr
, ETH_ALEN
);
346 for (ALL_LIST_ELEMENTS(ifp
->connected
, cnode
, cnnode
, c
)) {
349 memset(&ip
, 0, sizeof(struct ipaddr
));
350 if (!CHECK_FLAG(c
->conf
, ZEBRA_IFC_REAL
))
353 if (c
->address
->family
== AF_INET
) {
354 ip
.ipa_type
= IPADDR_V4
;
355 memcpy(&(ip
.ipaddr_v4
), &(c
->address
->u
.prefix4
),
356 sizeof(struct in_addr
));
357 } else if (c
->address
->family
== AF_INET6
) {
358 ip
.ipa_type
= IPADDR_V6
;
359 memcpy(&(ip
.ipaddr_v6
), &(c
->address
->u
.prefix6
),
360 sizeof(struct in6_addr
));
365 zebra_evpn_gw_macip_add(ifp
, zevpn
, &macaddr
, &ip
);
370 static int ip_prefix_send_to_client(vrf_id_t vrf_id
, struct prefix
*p
,
373 struct zserv
*client
= NULL
;
374 struct stream
*s
= NULL
;
376 client
= zserv_find_client(ZEBRA_ROUTE_BGP
, 0);
377 /* BGP may not be running. */
381 s
= stream_new(ZEBRA_MAX_PACKET_SIZ
);
383 zclient_create_header(s
, cmd
, vrf_id
);
384 stream_put(s
, p
, sizeof(struct prefix
));
386 /* Write packet size. */
387 stream_putw_at(s
, 0, stream_get_endp(s
));
389 if (IS_ZEBRA_DEBUG_VXLAN
)
390 zlog_debug("Send ip prefix %pFX %s on vrf %s", p
,
391 (cmd
== ZEBRA_IP_PREFIX_ROUTE_ADD
) ? "ADD" : "DEL",
392 vrf_id_to_name(vrf_id
));
394 if (cmd
== ZEBRA_IP_PREFIX_ROUTE_ADD
)
395 client
->prefixadd_cnt
++;
397 client
->prefixdel_cnt
++;
399 return zserv_send_message(client
, s
);
402 int zebra_evpn_advertise_subnet(struct zebra_evpn
*zevpn
, struct interface
*ifp
,
405 struct listnode
*cnode
= NULL
, *cnnode
= NULL
;
406 struct connected
*c
= NULL
;
407 struct ethaddr macaddr
;
409 memcpy(&macaddr
.octet
, ifp
->hw_addr
, ETH_ALEN
);
411 for (ALL_LIST_ELEMENTS(ifp
->connected
, cnode
, cnnode
, c
)) {
414 memcpy(&p
, c
->address
, sizeof(struct prefix
));
416 /* skip link local address */
417 if (IN6_IS_ADDR_LINKLOCAL(&p
.u
.prefix6
))
422 ip_prefix_send_to_client(ifp
->vrf_id
, &p
,
423 ZEBRA_IP_PREFIX_ROUTE_ADD
);
425 ip_prefix_send_to_client(ifp
->vrf_id
, &p
,
426 ZEBRA_IP_PREFIX_ROUTE_DEL
);
432 * zebra_evpn_gw_macip_add_to_client
434 int zebra_evpn_gw_macip_add(struct interface
*ifp
, struct zebra_evpn
*zevpn
,
435 struct ethaddr
*macaddr
, struct ipaddr
*ip
)
437 struct zebra_mac
*mac
= NULL
;
438 struct zebra_if
*zif
= NULL
;
439 struct zebra_l2info_vxlan
*vxl
= NULL
;
441 zif
= zevpn
->vxlan_if
->info
;
445 vxl
= &zif
->l2info
.vxl
;
447 if (zebra_evpn_mac_gw_macip_add(ifp
, zevpn
, ip
, &mac
, macaddr
,
448 vxl
->access_vlan
, true)
452 return zebra_evpn_neigh_gw_macip_add(ifp
, zevpn
, ip
, mac
);
456 * zebra_evpn_gw_macip_del_from_client
458 int zebra_evpn_gw_macip_del(struct interface
*ifp
, struct zebra_evpn
*zevpn
,
461 zebra_neigh_t
*n
= NULL
;
462 struct zebra_mac
*mac
= NULL
;
464 /* If the neigh entry is not present nothing to do*/
465 n
= zebra_evpn_neigh_lookup(zevpn
, ip
);
469 /* mac entry should be present */
470 mac
= zebra_evpn_mac_lookup(zevpn
, &n
->emac
);
472 if (IS_ZEBRA_DEBUG_VXLAN
)
473 zlog_debug("MAC %pEA doesn't exist for neigh %pIA on VNI %u",
474 &n
->emac
, ip
, zevpn
->vni
);
478 /* If the entry is not local nothing to do*/
479 if (!CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_LOCAL
))
482 /* only need to delete the entry from bgp if we sent it before */
483 if (IS_ZEBRA_DEBUG_VXLAN
)
485 "%u:SVI %s(%u) VNI %u, sending GW MAC %pEA IP %pIA del to BGP",
486 ifp
->vrf_id
, ifp
->name
, ifp
->ifindex
, zevpn
->vni
,
489 /* Remove neighbor from BGP. */
490 zebra_evpn_neigh_send_del_to_client(zevpn
->vni
, &n
->ip
, &n
->emac
,
491 n
->flags
, ZEBRA_NEIGH_ACTIVE
,
494 /* Delete this neighbor entry. */
495 zebra_evpn_neigh_del(zevpn
, n
);
497 /* see if the mac needs to be deleted as well*/
499 zebra_evpn_deref_ip2mac(zevpn
, mac
);
504 void zebra_evpn_gw_macip_del_for_evpn_hash(struct hash_bucket
*bucket
,
507 struct zebra_evpn
*zevpn
= NULL
;
508 struct zebra_if
*zif
= NULL
;
509 struct zebra_l2info_vxlan zl2_info
;
510 struct interface
*vlan_if
= NULL
;
511 struct interface
*vrr_if
= NULL
;
512 struct interface
*ifp
;
514 /* Add primary SVI MAC*/
515 zevpn
= (struct zebra_evpn
*)bucket
->data
;
517 /* Global (Zvrf) advertise-default-gw is disabled,
518 * but zevpn advertise-default-gw is enabled
520 if (zevpn
->advertise_gw_macip
) {
521 if (IS_ZEBRA_DEBUG_VXLAN
)
522 zlog_debug("VNI: %u GW-MACIP enabled, retain gw-macip",
527 ifp
= zevpn
->vxlan_if
;
532 /* If down or not mapped to a bridge, we're done. */
533 if (!if_is_operative(ifp
) || !zif
->brslave_info
.br_if
)
536 zl2_info
= zif
->l2info
.vxl
;
539 zvni_map_to_svi(zl2_info
.access_vlan
, zif
->brslave_info
.br_if
);
543 /* Del primary MAC-IP */
544 zebra_evpn_del_macip_for_intf(vlan_if
, zevpn
);
546 /* Del VRR MAC-IP - if any*/
547 vrr_if
= zebra_get_vrr_intf_for_svi(vlan_if
);
549 zebra_evpn_del_macip_for_intf(vrr_if
, zevpn
);
554 void zebra_evpn_gw_macip_add_for_evpn_hash(struct hash_bucket
*bucket
,
557 struct zebra_evpn
*zevpn
= NULL
;
558 struct zebra_if
*zif
= NULL
;
559 struct zebra_l2info_vxlan zl2_info
;
560 struct interface
*vlan_if
= NULL
;
561 struct interface
*vrr_if
= NULL
;
562 struct interface
*ifp
= NULL
;
564 zevpn
= (struct zebra_evpn
*)bucket
->data
;
566 ifp
= zevpn
->vxlan_if
;
571 /* If down or not mapped to a bridge, we're done. */
572 if (!if_is_operative(ifp
) || !zif
->brslave_info
.br_if
)
574 zl2_info
= zif
->l2info
.vxl
;
577 zvni_map_to_svi(zl2_info
.access_vlan
, zif
->brslave_info
.br_if
);
581 /* Add primary SVI MAC-IP */
582 if (advertise_svi_macip_enabled(zevpn
)
583 || advertise_gw_macip_enabled(zevpn
))
584 zebra_evpn_add_macip_for_intf(vlan_if
, zevpn
);
586 if (advertise_gw_macip_enabled(zevpn
)) {
587 /* Add VRR MAC-IP - if any*/
588 vrr_if
= zebra_get_vrr_intf_for_svi(vlan_if
);
590 zebra_evpn_add_macip_for_intf(vrr_if
, zevpn
);
596 void zebra_evpn_svi_macip_del_for_evpn_hash(struct hash_bucket
*bucket
,
599 struct zebra_evpn
*zevpn
= NULL
;
600 struct zebra_if
*zif
= NULL
;
601 struct zebra_l2info_vxlan zl2_info
;
602 struct interface
*vlan_if
= NULL
;
603 struct interface
*ifp
;
605 /* Add primary SVI MAC*/
606 zevpn
= (struct zebra_evpn
*)bucket
->data
;
610 /* Global(vrf) advertise-svi-ip disabled, but zevpn advertise-svi-ip
613 if (zevpn
->advertise_svi_macip
) {
614 if (IS_ZEBRA_DEBUG_VXLAN
)
615 zlog_debug("VNI: %u SVI-MACIP enabled, retain svi-macip",
620 ifp
= zevpn
->vxlan_if
;
625 /* If down or not mapped to a bridge, we're done. */
626 if (!if_is_operative(ifp
) || !zif
->brslave_info
.br_if
)
629 zl2_info
= zif
->l2info
.vxl
;
632 zvni_map_to_svi(zl2_info
.access_vlan
, zif
->brslave_info
.br_if
);
636 /* Del primary MAC-IP */
637 zebra_evpn_del_macip_for_intf(vlan_if
, zevpn
);
642 static int zebra_evpn_map_vlan_ns(struct ns
*ns
,
646 struct zebra_ns
*zns
= ns
->info
;
647 struct route_node
*rn
;
648 struct interface
*br_if
;
649 struct zebra_evpn
**p_zevpn
= (struct zebra_evpn
**)_p_zevpn
;
650 struct zebra_evpn
*zevpn
;
651 struct interface
*tmp_if
= NULL
;
652 struct zebra_if
*zif
;
653 struct zebra_l2info_vxlan
*vxl
= NULL
;
654 struct zebra_from_svi_param
*in_param
=
655 (struct zebra_from_svi_param
*)_in_param
;
660 br_if
= in_param
->br_if
;
665 /* See if this interface (or interface plus VLAN Id) maps to a VxLAN */
666 /* TODO: Optimize with a hash. */
667 for (rn
= route_top(zns
->if_table
); rn
; rn
= route_next(rn
)) {
668 tmp_if
= (struct interface
*)rn
->info
;
672 if (!zif
|| zif
->zif_type
!= ZEBRA_IF_VXLAN
)
674 if (!if_is_operative(tmp_if
))
676 vxl
= &zif
->l2info
.vxl
;
678 if (zif
->brslave_info
.br_if
!= br_if
)
681 if (!in_param
->bridge_vlan_aware
682 || vxl
->access_vlan
== in_param
->vid
) {
688 return NS_WALK_CONTINUE
;
690 zevpn
= zebra_evpn_lookup(vxl
->vni
);
697 * Map port or (port, VLAN) to an EVPN. This is invoked upon getting MAC
698 * notifications, to see if they are of interest.
700 struct zebra_evpn
*zebra_evpn_map_vlan(struct interface
*ifp
,
701 struct interface
*br_if
, vlanid_t vid
)
703 struct zebra_if
*zif
;
704 struct zebra_l2info_bridge
*br
;
705 struct zebra_evpn
**p_zevpn
;
706 struct zebra_evpn
*zevpn
= NULL
;
707 struct zebra_from_svi_param in_param
;
709 /* Determine if bridge is VLAN-aware or not */
712 br
= &zif
->l2info
.br
;
713 in_param
.bridge_vlan_aware
= br
->vlan_aware
;
715 in_param
.br_if
= br_if
;
719 ns_walk_func(zebra_evpn_map_vlan_ns
,
725 static int zebra_evpn_from_svi_ns(struct ns
*ns
,
729 struct zebra_ns
*zns
= ns
->info
;
730 struct route_node
*rn
;
731 struct interface
*br_if
;
732 struct zebra_evpn
**p_zevpn
= (struct zebra_evpn
**)_p_zevpn
;
733 struct zebra_evpn
*zevpn
;
734 struct interface
*tmp_if
= NULL
;
735 struct zebra_if
*zif
;
736 struct zebra_l2info_vxlan
*vxl
= NULL
;
737 struct zebra_from_svi_param
*in_param
=
738 (struct zebra_from_svi_param
*)_in_param
;
743 br_if
= in_param
->br_if
;
747 /* TODO: Optimize with a hash. */
748 for (rn
= route_top(zns
->if_table
); rn
; rn
= route_next(rn
)) {
749 tmp_if
= (struct interface
*)rn
->info
;
753 if (!zif
|| zif
->zif_type
!= ZEBRA_IF_VXLAN
)
755 if (!if_is_operative(tmp_if
))
757 vxl
= &zif
->l2info
.vxl
;
759 if (zif
->brslave_info
.br_if
!= br_if
)
762 if (!in_param
->bridge_vlan_aware
763 || vxl
->access_vlan
== in_param
->vid
) {
770 return NS_WALK_CONTINUE
;
772 zevpn
= zebra_evpn_lookup(vxl
->vni
);
779 * Map SVI and associated bridge to an EVPN. This is invoked upon getting
780 * neighbor notifications, to see if they are of interest.
782 struct zebra_evpn
*zebra_evpn_from_svi(struct interface
*ifp
,
783 struct interface
*br_if
)
785 struct zebra_l2info_bridge
*br
;
786 struct zebra_evpn
*zevpn
= NULL
;
787 struct zebra_evpn
**p_zevpn
;
788 struct zebra_if
*zif
;
789 struct zebra_from_svi_param in_param
;
794 /* Make sure the linked interface is a bridge. */
795 if (!IS_ZEBRA_IF_BRIDGE(br_if
))
798 /* Determine if bridge is VLAN-aware or not */
801 br
= &zif
->l2info
.br
;
802 in_param
.bridge_vlan_aware
= br
->vlan_aware
;
805 if (in_param
.bridge_vlan_aware
) {
806 struct zebra_l2info_vlan
*vl
;
808 if (!IS_ZEBRA_IF_VLAN(ifp
))
813 vl
= &zif
->l2info
.vl
;
814 in_param
.vid
= vl
->vid
;
817 in_param
.br_if
= br_if
;
820 /* See if this interface (or interface plus VLAN Id) maps to a VxLAN */
821 ns_walk_func(zebra_evpn_from_svi_ns
, (void *)&in_param
,
826 static int zvni_map_to_macvlan_ns(struct ns
*ns
,
830 struct zebra_ns
*zns
= ns
->info
;
831 struct zebra_from_svi_param
*in_param
=
832 (struct zebra_from_svi_param
*)_in_param
;
833 struct interface
**p_ifp
= (struct interface
**)_p_ifp
;
834 struct route_node
*rn
;
835 struct interface
*tmp_if
= NULL
;
836 struct zebra_if
*zif
;
841 /* Identify corresponding VLAN interface. */
842 for (rn
= route_top(zns
->if_table
); rn
; rn
= route_next(rn
)) {
843 tmp_if
= (struct interface
*)rn
->info
;
844 /* Check oper status of the SVI. */
845 if (!tmp_if
|| !if_is_operative(tmp_if
))
849 if (!zif
|| zif
->zif_type
!= ZEBRA_IF_MACVLAN
)
852 if (zif
->link
== in_param
->svi_if
) {
859 return NS_WALK_CONTINUE
;
862 /* Map to MAC-VLAN interface corresponding to specified SVI interface.
864 struct interface
*zebra_evpn_map_to_macvlan(struct interface
*br_if
,
865 struct interface
*svi_if
)
867 struct interface
*tmp_if
= NULL
;
868 struct zebra_if
*zif
;
869 struct interface
**p_ifp
;
870 struct zebra_from_svi_param in_param
;
872 /* Defensive check, caller expected to invoke only with valid bridge. */
877 zlog_debug("svi_if is not passed.");
881 /* Determine if bridge is VLAN-aware or not */
886 in_param
.br_if
= br_if
;
888 in_param
.svi_if
= svi_if
;
891 /* Identify corresponding VLAN interface. */
892 ns_walk_func(zvni_map_to_macvlan_ns
,
899 * Install MAC hash entry - called upon access VLAN change.
901 void zebra_evpn_install_mac_hash(struct hash_bucket
*bucket
, void *ctxt
)
903 struct zebra_mac
*mac
;
904 struct mac_walk_ctx
*wctx
= ctxt
;
906 mac
= (struct zebra_mac
*)bucket
->data
;
908 if (CHECK_FLAG(mac
->flags
, ZEBRA_MAC_REMOTE
))
909 zebra_evpn_rem_mac_install(wctx
->zevpn
, mac
, false);
913 * Read and populate local MACs and neighbors corresponding to this EVPN.
915 void zebra_evpn_read_mac_neigh(struct zebra_evpn
*zevpn
, struct interface
*ifp
)
917 struct zebra_ns
*zns
;
918 struct zebra_vrf
*zvrf
;
919 struct zebra_if
*zif
;
920 struct interface
*vlan_if
;
921 struct zebra_l2info_vxlan
*vxl
;
922 struct interface
*vrr_if
;
925 vxl
= &zif
->l2info
.vxl
;
926 zvrf
= zebra_vrf_lookup_by_id(zevpn
->vrf_id
);
927 if (!zvrf
|| !zvrf
->zns
)
931 if (IS_ZEBRA_DEBUG_VXLAN
)
933 "Reading MAC FDB and Neighbors for intf %s(%u) VNI %u master %u",
934 ifp
->name
, ifp
->ifindex
, zevpn
->vni
,
935 zif
->brslave_info
.bridge_ifindex
);
937 macfdb_read_for_bridge(zns
, ifp
, zif
->brslave_info
.br_if
);
938 vlan_if
= zvni_map_to_svi(vxl
->access_vlan
, zif
->brslave_info
.br_if
);
941 zebra_evpn_acc_bd_svi_mac_add(vlan_if
);
944 if (advertise_svi_macip_enabled(zevpn
)
945 || advertise_gw_macip_enabled(zevpn
))
946 zebra_evpn_add_macip_for_intf(vlan_if
, zevpn
);
948 /* Add VRR MAC-IP - if any*/
949 if (advertise_gw_macip_enabled(zevpn
)) {
950 vrr_if
= zebra_get_vrr_intf_for_svi(vlan_if
);
952 zebra_evpn_add_macip_for_intf(vrr_if
, zevpn
);
955 neigh_read_for_vlan(zns
, vlan_if
);
960 * Hash function for EVPN.
962 unsigned int zebra_evpn_hash_keymake(const void *p
)
964 const struct zebra_evpn
*zevpn
= p
;
966 return (jhash_1word(zevpn
->vni
, 0));
970 * Compare 2 evpn hash entries.
972 bool zebra_evpn_hash_cmp(const void *p1
, const void *p2
)
974 const struct zebra_evpn
*zevpn1
= p1
;
975 const struct zebra_evpn
*zevpn2
= p2
;
977 return (zevpn1
->vni
== zevpn2
->vni
);
980 int zebra_evpn_list_cmp(void *p1
, void *p2
)
982 const struct zebra_evpn
*zevpn1
= p1
;
983 const struct zebra_evpn
*zevpn2
= p2
;
985 if (zevpn1
->vni
== zevpn2
->vni
)
987 return (zevpn1
->vni
< zevpn2
->vni
) ? -1 : 1;
991 * Callback to allocate VNI hash entry.
993 void *zebra_evpn_alloc(void *p
)
995 const struct zebra_evpn
*tmp_vni
= p
;
996 struct zebra_evpn
*zevpn
;
998 zevpn
= XCALLOC(MTYPE_ZEVPN
, sizeof(struct zebra_evpn
));
999 zevpn
->vni
= tmp_vni
->vni
;
1000 return ((void *)zevpn
);
1004 * Look up EVPN hash entry.
1006 struct zebra_evpn
*zebra_evpn_lookup(vni_t vni
)
1008 struct zebra_vrf
*zvrf
;
1009 struct zebra_evpn tmp_vni
;
1010 struct zebra_evpn
*zevpn
= NULL
;
1012 zvrf
= zebra_vrf_get_evpn();
1014 memset(&tmp_vni
, 0, sizeof(struct zebra_evpn
));
1016 zevpn
= hash_lookup(zvrf
->evpn_table
, &tmp_vni
);
1022 * Add EVPN hash entry.
1024 struct zebra_evpn
*zebra_evpn_add(vni_t vni
)
1027 struct zebra_vrf
*zvrf
;
1028 struct zebra_evpn tmp_zevpn
;
1029 struct zebra_evpn
*zevpn
= NULL
;
1031 zvrf
= zebra_vrf_get_evpn();
1033 memset(&tmp_zevpn
, 0, sizeof(struct zebra_evpn
));
1034 tmp_zevpn
.vni
= vni
;
1035 zevpn
= hash_get(zvrf
->evpn_table
, &tmp_zevpn
, zebra_evpn_alloc
);
1038 zebra_evpn_es_evi_init(zevpn
);
1040 snprintf(buffer
, sizeof(buffer
), "Zebra EVPN MAC Table vni: %u", vni
);
1041 /* Create hash table for MAC */
1042 zevpn
->mac_table
= zebra_mac_db_create(buffer
);
1044 snprintf(buffer
, sizeof(buffer
), "Zebra EVPN Neighbor Table vni: %u",
1046 /* Create hash table for neighbors */
1047 zevpn
->neigh_table
= zebra_neigh_db_create(buffer
);
1053 * Delete EVPN hash entry.
1055 int zebra_evpn_del(struct zebra_evpn
*zevpn
)
1057 struct zebra_vrf
*zvrf
;
1058 struct zebra_evpn
*tmp_zevpn
;
1060 zvrf
= zebra_vrf_get_evpn();
1063 zevpn
->svi_if
= NULL
;
1065 /* Free the neighbor hash table. */
1066 hash_free(zevpn
->neigh_table
);
1067 zevpn
->neigh_table
= NULL
;
1069 /* Free the MAC hash table. */
1070 hash_free(zevpn
->mac_table
);
1071 zevpn
->mac_table
= NULL
;
1073 /* Remove references to the zevpn in the MH databases */
1074 if (zevpn
->vxlan_if
)
1075 zebra_evpn_vxl_evpn_set(zevpn
->vxlan_if
->info
, zevpn
, false);
1076 zebra_evpn_es_evi_cleanup(zevpn
);
1078 /* Free the EVPN hash entry and allocated memory. */
1079 tmp_zevpn
= hash_release(zvrf
->evpn_table
, zevpn
);
1080 XFREE(MTYPE_ZEVPN
, tmp_zevpn
);
1086 * Inform BGP about local EVPN addition.
1088 int zebra_evpn_send_add_to_client(struct zebra_evpn
*zevpn
)
1090 struct zserv
*client
;
1092 ifindex_t svi_index
;
1095 client
= zserv_find_client(ZEBRA_ROUTE_BGP
, 0);
1096 /* BGP may not be running. */
1100 svi_index
= zevpn
->svi_if
? zevpn
->svi_if
->ifindex
: 0;
1102 s
= stream_new(ZEBRA_MAX_PACKET_SIZ
);
1104 zclient_create_header(s
, ZEBRA_VNI_ADD
, zebra_vrf_get_evpn_id());
1105 stream_putl(s
, zevpn
->vni
);
1106 stream_put_in_addr(s
, &zevpn
->local_vtep_ip
);
1107 stream_put(s
, &zevpn
->vrf_id
, sizeof(vrf_id_t
)); /* tenant vrf */
1108 stream_put_in_addr(s
, &zevpn
->mcast_grp
);
1109 stream_put(s
, &svi_index
, sizeof(ifindex_t
));
1111 /* Write packet size. */
1112 stream_putw_at(s
, 0, stream_get_endp(s
));
1114 if (IS_ZEBRA_DEBUG_VXLAN
)
1116 "Send EVPN_ADD %u %pI4 tenant vrf %s(%u) SVI index %u to %s",
1117 zevpn
->vni
, &zevpn
->local_vtep_ip
,
1118 vrf_id_to_name(zevpn
->vrf_id
), zevpn
->vrf_id
,
1119 (zevpn
->svi_if
? zevpn
->svi_if
->ifindex
: 0),
1120 zebra_route_string(client
->proto
));
1122 client
->vniadd_cnt
++;
1123 rc
= zserv_send_message(client
, s
);
1125 if (!(zevpn
->flags
& ZEVPN_READY_FOR_BGP
)) {
1126 zevpn
->flags
|= ZEVPN_READY_FOR_BGP
;
1127 /* once the EVPN is sent the ES-EVIs can also be replayed
1130 zebra_evpn_update_all_es(zevpn
);
1136 * Inform BGP about local EVPN deletion.
1138 int zebra_evpn_send_del_to_client(struct zebra_evpn
*zevpn
)
1140 struct zserv
*client
;
1143 client
= zserv_find_client(ZEBRA_ROUTE_BGP
, 0);
1144 /* BGP may not be running. */
1148 if (zevpn
->flags
& ZEVPN_READY_FOR_BGP
) {
1149 zevpn
->flags
&= ~ZEVPN_READY_FOR_BGP
;
1150 /* the ES-EVIs must be removed from BGP before the EVPN is */
1151 zebra_evpn_update_all_es(zevpn
);
1154 s
= stream_new(ZEBRA_MAX_PACKET_SIZ
);
1157 zclient_create_header(s
, ZEBRA_VNI_DEL
, zebra_vrf_get_evpn_id());
1158 stream_putl(s
, zevpn
->vni
);
1160 /* Write packet size. */
1161 stream_putw_at(s
, 0, stream_get_endp(s
));
1163 if (IS_ZEBRA_DEBUG_VXLAN
)
1164 zlog_debug("Send EVPN_DEL %u to %s", zevpn
->vni
,
1165 zebra_route_string(client
->proto
));
1167 client
->vnidel_cnt
++;
1168 return zserv_send_message(client
, s
);
1172 * See if remote VTEP matches with prefix.
1174 static int zebra_evpn_vtep_match(struct in_addr
*vtep_ip
,
1175 struct zebra_vtep
*zvtep
)
1177 return (IPV4_ADDR_SAME(vtep_ip
, &zvtep
->vtep_ip
));
1181 * Locate remote VTEP in EVPN hash table.
1183 struct zebra_vtep
*zebra_evpn_vtep_find(struct zebra_evpn
*zevpn
,
1184 struct in_addr
*vtep_ip
)
1186 struct zebra_vtep
*zvtep
;
1191 for (zvtep
= zevpn
->vteps
; zvtep
; zvtep
= zvtep
->next
) {
1192 if (zebra_evpn_vtep_match(vtep_ip
, zvtep
))
1200 * Add remote VTEP to EVPN hash table.
1202 struct zebra_vtep
*zebra_evpn_vtep_add(struct zebra_evpn
*zevpn
,
1203 struct in_addr
*vtep_ip
,
1207 struct zebra_vtep
*zvtep
;
1209 zvtep
= XCALLOC(MTYPE_ZEVPN_VTEP
, sizeof(struct zebra_vtep
));
1211 zvtep
->vtep_ip
= *vtep_ip
;
1212 zvtep
->flood_control
= flood_control
;
1215 zevpn
->vteps
->prev
= zvtep
;
1216 zvtep
->next
= zevpn
->vteps
;
1217 zevpn
->vteps
= zvtep
;
1223 * Remove remote VTEP from EVPN hash table.
1225 int zebra_evpn_vtep_del(struct zebra_evpn
*zevpn
, struct zebra_vtep
*zvtep
)
1228 zvtep
->next
->prev
= zvtep
->prev
;
1230 zvtep
->prev
->next
= zvtep
->next
;
1232 zevpn
->vteps
= zvtep
->next
;
1234 zvtep
->prev
= zvtep
->next
= NULL
;
1235 XFREE(MTYPE_ZEVPN_VTEP
, zvtep
);
1241 * Delete all remote VTEPs for this EVPN (upon VNI delete). Also
1242 * uninstall from kernel if asked to.
1244 int zebra_evpn_vtep_del_all(struct zebra_evpn
*zevpn
, int uninstall
)
1246 struct zebra_vtep
*zvtep
, *zvtep_next
;
1251 for (zvtep
= zevpn
->vteps
; zvtep
; zvtep
= zvtep_next
) {
1252 zvtep_next
= zvtep
->next
;
1254 zebra_evpn_vtep_uninstall(zevpn
, &zvtep
->vtep_ip
);
1255 zebra_evpn_vtep_del(zevpn
, zvtep
);
1262 * Install remote VTEP into the kernel if the remote VTEP has asked
1263 * for head-end-replication.
1265 int zebra_evpn_vtep_install(struct zebra_evpn
*zevpn
, struct zebra_vtep
*zvtep
)
1267 if (is_vxlan_flooding_head_end() &&
1268 (zvtep
->flood_control
== VXLAN_FLOOD_HEAD_END_REPL
)) {
1269 if (ZEBRA_DPLANE_REQUEST_FAILURE
==
1270 dplane_vtep_add(zevpn
->vxlan_if
,
1271 &zvtep
->vtep_ip
, zevpn
->vni
))
1279 * Uninstall remote VTEP from the kernel.
1281 int zebra_evpn_vtep_uninstall(struct zebra_evpn
*zevpn
, struct in_addr
*vtep_ip
)
1283 if (!zevpn
->vxlan_if
) {
1284 zlog_debug("VNI %u hash %p couldn't be uninstalled - no intf",
1289 if (ZEBRA_DPLANE_REQUEST_FAILURE
==
1290 dplane_vtep_delete(zevpn
->vxlan_if
, vtep_ip
, zevpn
->vni
))
1297 * Install or uninstall flood entries in the kernel corresponding to
1298 * remote VTEPs. This is invoked upon change to BUM handling.
1300 void zebra_evpn_handle_flooding_remote_vteps(struct hash_bucket
*bucket
,
1303 struct zebra_evpn
*zevpn
;
1304 struct zebra_vtep
*zvtep
;
1306 zevpn
= (struct zebra_evpn
*)bucket
->data
;
1310 for (zvtep
= zevpn
->vteps
; zvtep
; zvtep
= zvtep
->next
) {
1311 if (is_vxlan_flooding_head_end())
1312 zebra_evpn_vtep_install(zevpn
, zvtep
);
1314 zebra_evpn_vtep_uninstall(zevpn
, &zvtep
->vtep_ip
);
1319 * Cleanup EVPN/VTEP and update kernel
1321 void zebra_evpn_cleanup_all(struct hash_bucket
*bucket
, void *arg
)
1323 struct zebra_evpn
*zevpn
= NULL
;
1325 zevpn
= (struct zebra_evpn
*)bucket
->data
;
1327 /* Free up all neighbors and MACs, if any. */
1328 zebra_evpn_neigh_del_all(zevpn
, 1, 0, DEL_ALL_NEIGH
);
1329 zebra_evpn_mac_del_all(zevpn
, 1, 0, DEL_ALL_MAC
);
1331 /* Free up all remote VTEPs, if any. */
1332 zebra_evpn_vtep_del_all(zevpn
, 1);
1334 /* Delete the hash entry. */
1335 zebra_evpn_del(zevpn
);
1338 static void zebra_evpn_process_sync_macip_add(struct zebra_evpn
*zevpn
,
1339 const struct ethaddr
*macaddr
,
1341 const struct ipaddr
*ipaddr
,
1342 uint8_t flags
, uint32_t seq
,
1345 struct sync_mac_ip_ctx ctx
;
1346 char ipbuf
[INET6_ADDRSTRLEN
];
1349 zebra_neigh_t
*n
= NULL
;
1351 sticky
= !!CHECK_FLAG(flags
, ZEBRA_MACIP_TYPE_STICKY
);
1352 remote_gw
= !!CHECK_FLAG(flags
, ZEBRA_MACIP_TYPE_GW
);
1353 /* if sticky or remote-gw ignore updates from the peer */
1354 if (sticky
|| remote_gw
) {
1355 if (IS_ZEBRA_DEBUG_VXLAN
|| IS_ZEBRA_DEBUG_EVPN_MH_NEIGH
1356 || IS_ZEBRA_DEBUG_EVPN_MH_MAC
)
1358 "Ignore sync-macip vni %u mac %pEA%s%s%s%s",
1361 ipa_len
? " IP " : "",
1362 ipa_len
? ipaddr2str(ipaddr
, ipbuf
,
1365 sticky
? " sticky" : "",
1366 remote_gw
? " remote_gw" : "");
1371 n
= zebra_evpn_neigh_lookup(zevpn
, ipaddr
);
1373 && !zebra_evpn_neigh_is_bgp_seq_ok(zevpn
, n
, macaddr
, seq
,
1378 memset(&ctx
, 0, sizeof(ctx
));
1379 ctx
.mac
= zebra_evpn_proc_sync_mac_update(
1380 zevpn
, macaddr
, ipa_len
, ipaddr
, flags
, seq
, esi
, &ctx
);
1381 if (ctx
.ignore_macip
|| !ctx
.mac
|| !ipa_len
)
1384 zebra_evpn_proc_sync_neigh_update(zevpn
, n
, ipa_len
, ipaddr
, flags
, seq
,
1388 /************************** remote mac-ip handling **************************/
1389 /* Process a remote MACIP add from BGP. */
1390 void zebra_evpn_rem_macip_add(vni_t vni
, const struct ethaddr
*macaddr
,
1391 uint16_t ipa_len
, const struct ipaddr
*ipaddr
,
1392 uint8_t flags
, uint32_t seq
,
1393 struct in_addr vtep_ip
, const esi_t
*esi
)
1395 struct zebra_evpn
*zevpn
;
1396 struct zebra_vtep
*zvtep
;
1397 struct zebra_mac
*mac
= NULL
;
1398 struct interface
*ifp
= NULL
;
1399 struct zebra_if
*zif
= NULL
;
1400 struct zebra_vrf
*zvrf
;
1402 /* Locate EVPN hash entry - expected to exist. */
1403 zevpn
= zebra_evpn_lookup(vni
);
1405 if (IS_ZEBRA_DEBUG_VXLAN
)
1406 zlog_debug("Unknown VNI %u upon remote MACIP ADD", vni
);
1410 ifp
= zevpn
->vxlan_if
;
1413 if (!ifp
|| !if_is_operative(ifp
) || !zif
|| !zif
->brslave_info
.br_if
) {
1415 "Ignoring remote MACIP ADD VNI %u, invalid interface state or info",
1420 /* Type-2 routes from another PE can be interpreted as remote or
1421 * SYNC based on the destination ES -
1422 * SYNC - if ES is local
1423 * REMOTE - if ES is not local
1425 if (flags
& ZEBRA_MACIP_TYPE_SYNC_PATH
) {
1426 zebra_evpn_process_sync_macip_add(zevpn
, macaddr
, ipa_len
,
1427 ipaddr
, flags
, seq
, esi
);
1431 /* The remote VTEP specified should normally exist, but it is
1432 * possible that when peering comes up, peer may advertise MACIP
1433 * routes before advertising type-3 routes.
1435 if (vtep_ip
.s_addr
) {
1436 zvtep
= zebra_evpn_vtep_find(zevpn
, &vtep_ip
);
1438 zvtep
= zebra_evpn_vtep_add(zevpn
, &vtep_ip
,
1439 VXLAN_FLOOD_DISABLED
);
1442 EC_ZEBRA_VTEP_ADD_FAILED
,
1443 "Failed to add remote VTEP, VNI %u zevpn %p upon remote MACIP ADD",
1448 zebra_evpn_vtep_install(zevpn
, zvtep
);
1452 zvrf
= zebra_vrf_get_evpn();
1457 if (zebra_evpn_mac_remote_macip_add(zevpn
, zvrf
, macaddr
, ipa_len
,
1458 ipaddr
, &mac
, vtep_ip
, flags
, seq
,
1463 zebra_evpn_neigh_remote_macip_add(zevpn
, zvrf
, ipaddr
, mac
, vtep_ip
,
1467 /* Process a remote MACIP delete from BGP. */
1468 void zebra_evpn_rem_macip_del(vni_t vni
, const struct ethaddr
*macaddr
,
1469 uint16_t ipa_len
, const struct ipaddr
*ipaddr
,
1470 struct in_addr vtep_ip
)
1472 struct zebra_evpn
*zevpn
;
1473 struct zebra_mac
*mac
= NULL
;
1474 zebra_neigh_t
*n
= NULL
;
1475 struct interface
*ifp
= NULL
;
1476 struct zebra_if
*zif
= NULL
;
1477 struct zebra_ns
*zns
;
1478 struct zebra_l2info_vxlan
*vxl
;
1479 struct zebra_vrf
*zvrf
;
1480 char buf1
[INET6_ADDRSTRLEN
];
1482 /* Locate EVPN hash entry - expected to exist. */
1483 zevpn
= zebra_evpn_lookup(vni
);
1485 if (IS_ZEBRA_DEBUG_VXLAN
)
1486 zlog_debug("Unknown VNI %u upon remote MACIP DEL", vni
);
1490 ifp
= zevpn
->vxlan_if
;
1493 if (!ifp
|| !if_is_operative(ifp
) || !zif
|| !zif
->brslave_info
.br_if
) {
1494 if (IS_ZEBRA_DEBUG_VXLAN
)
1496 "Ignoring remote MACIP DEL VNI %u, invalid interface state or info",
1500 zns
= zebra_ns_lookup(NS_DEFAULT
);
1501 vxl
= &zif
->l2info
.vxl
;
1503 mac
= zebra_evpn_mac_lookup(zevpn
, macaddr
);
1505 n
= zebra_evpn_neigh_lookup(zevpn
, ipaddr
);
1509 "Failed to locate MAC %pEA for neigh %pIA VNI %u upon remote MACIP DEL",
1510 macaddr
, ipaddr
, vni
);
1514 /* If the remote mac or neighbor doesn't exist there is nothing
1515 * more to do. Otherwise, uninstall the entry and then remove it.
1520 zvrf
= vrf_info_lookup(zevpn
->vxlan_if
->vrf_id
);
1522 /* Ignore the delete if this mac is a gateway mac-ip */
1523 if (CHECK_FLAG(mac
->flags
, ZEBRA_MAC_LOCAL
)
1524 && CHECK_FLAG(mac
->flags
, ZEBRA_MAC_DEF_GW
)) {
1526 "Ignore remote MACIP DEL VNI %u MAC %pEA%s%s as MAC is already configured as gateway MAC",
1528 ipa_len
? " IP " : "",
1529 ipa_len
? ipaddr2str(ipaddr
, buf1
, sizeof(buf1
)) : "");
1533 /* Uninstall remote neighbor or MAC. */
1535 zebra_evpn_neigh_remote_uninstall(zevpn
, zvrf
, n
, mac
, ipaddr
);
1537 /* DAD: when MAC is freeze state as remote learn event,
1538 * remote mac-ip delete event is received will result in freeze
1539 * entry removal, first fetch kernel for the same entry present
1540 * as LOCAL and reachable, avoid deleting this entry instead
1541 * use kerenel local entry to update during unfreeze time.
1543 if (zvrf
->dad_freeze
1544 && CHECK_FLAG(mac
->flags
, ZEBRA_MAC_DUPLICATE
)
1545 && CHECK_FLAG(mac
->flags
, ZEBRA_MAC_REMOTE
)) {
1546 if (IS_ZEBRA_DEBUG_VXLAN
)
1548 "%s: MAC %pEA (flags 0x%x) is remote and duplicate, read kernel for local entry",
1549 __func__
, macaddr
, mac
->flags
);
1550 macfdb_read_specific_mac(zns
, zif
->brslave_info
.br_if
,
1551 macaddr
, vxl
->access_vlan
);
1554 if (CHECK_FLAG(mac
->flags
, ZEBRA_MAC_LOCAL
)) {
1556 zebra_evpn_sync_mac_del(mac
);
1557 } else if (CHECK_FLAG(mac
->flags
, ZEBRA_NEIGH_REMOTE
)) {
1558 zebra_evpn_rem_mac_del(zevpn
, mac
);
1563 /************************** EVPN BGP config management ************************/
1564 void zebra_evpn_cfg_cleanup(struct hash_bucket
*bucket
, void *ctxt
)
1566 struct zebra_evpn
*zevpn
= NULL
;
1568 zevpn
= (struct zebra_evpn
*)bucket
->data
;
1569 zevpn
->advertise_gw_macip
= 0;
1570 zevpn
->advertise_svi_macip
= 0;
1571 zevpn
->advertise_subnet
= 0;
1573 zebra_evpn_neigh_del_all(zevpn
, 1, 0,
1574 DEL_REMOTE_NEIGH
| DEL_REMOTE_NEIGH_FROM_VTEP
);
1575 zebra_evpn_mac_del_all(zevpn
, 1, 0,
1576 DEL_REMOTE_MAC
| DEL_REMOTE_MAC_FROM_VTEP
);
1577 zebra_evpn_vtep_del_all(zevpn
, 1);