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_addf(json
, "vtepIp", "%pI4",
156 &zevpn
->local_vtep_ip
);
157 json_object_string_addf(json
, "mcastGroup", "%pI4",
159 json_object_string_add(json
, "advertiseGatewayMacip",
160 zevpn
->advertise_gw_macip
? "Yes" : "No");
161 json_object_string_add(json
, "advertiseSviMacip",
162 zevpn
->advertise_svi_macip
? "Yes"
164 json_object_int_add(json
, "numMacs", num_macs
);
165 json_object_int_add(json
, "numArpNd", num_neigh
);
169 vty_out(vty
, " No remote VTEPs known for this VNI\n");
172 vty_out(vty
, " Remote VTEPs for this VNI:\n");
174 json_vtep_list
= json_object_new_array();
175 for (zvtep
= zevpn
->vteps
; zvtep
; zvtep
= zvtep
->next
) {
176 const char *flood_str
= lookup_msg(zvtep_flood_str
,
177 zvtep
->flood_control
,
178 VXLAN_FLOOD_STR_DEFAULT
);
181 vty_out(vty
, " %pI4 flood: %s\n",
185 json_ip_str
= json_object_new_string(
187 &zvtep
->vtep_ip
, buf
,
189 json_object_array_add(json_vtep_list
,
194 json_object_object_add(json
, "numRemoteVteps",
199 " Number of MACs (local and remote) known for this VNI: %u\n",
202 " Number of ARPs (IPv4 and IPv6, local and remote) "
203 "known for this VNI: %u\n",
205 vty_out(vty
, " Advertise-gw-macip: %s\n",
206 zevpn
->advertise_gw_macip
? "Yes" : "No");
207 vty_out(vty
, " Advertise-svi-macip: %s\n",
208 zevpn
->advertise_svi_macip
? "Yes" : "No");
213 * Print an EVPN hash entry - called for display of all VNIs.
215 void zebra_evpn_print_hash(struct hash_bucket
*bucket
, void *ctxt
[])
218 struct zebra_evpn
*zevpn
;
219 struct zebra_vtep
*zvtep
;
220 uint32_t num_vteps
= 0;
221 uint32_t num_macs
= 0;
222 uint32_t num_neigh
= 0;
223 json_object
*json
= NULL
;
224 json_object
*json_evpn
= NULL
;
225 json_object
*json_ip_str
= NULL
;
226 json_object
*json_vtep_list
= NULL
;
227 char buf
[PREFIX_STRLEN
];
232 zevpn
= (struct zebra_evpn
*)bucket
->data
;
234 zvtep
= zevpn
->vteps
;
240 num_macs
= num_valid_macs(zevpn
);
241 num_neigh
= hashcount(zevpn
->neigh_table
);
243 vty_out(vty
, "%-10u %-4s %-21s %-8u %-8u %-15u %-37s\n",
245 zevpn
->vxlan_if
? zevpn
->vxlan_if
->name
: "unknown",
246 num_macs
, num_neigh
, num_vteps
,
247 vrf_id_to_name(zevpn
->vrf_id
));
249 char vni_str
[VNI_STR_LEN
];
250 snprintf(vni_str
, VNI_STR_LEN
, "%u", zevpn
->vni
);
251 json_evpn
= json_object_new_object();
252 json_object_int_add(json_evpn
, "vni", zevpn
->vni
);
253 json_object_string_add(json_evpn
, "type", "L2");
254 json_object_string_add(json_evpn
, "vxlanIf",
255 zevpn
->vxlan_if
? zevpn
->vxlan_if
->name
257 json_object_int_add(json_evpn
, "numMacs", num_macs
);
258 json_object_int_add(json_evpn
, "numArpNd", num_neigh
);
259 json_object_int_add(json_evpn
, "numRemoteVteps", num_vteps
);
260 json_object_string_add(json_evpn
, "tenantVrf",
261 vrf_id_to_name(zevpn
->vrf_id
));
263 json_vtep_list
= json_object_new_array();
264 for (zvtep
= zevpn
->vteps
; zvtep
; zvtep
= zvtep
->next
) {
265 json_ip_str
= json_object_new_string(
266 inet_ntop(AF_INET
, &zvtep
->vtep_ip
, buf
,
268 json_object_array_add(json_vtep_list
,
271 json_object_object_add(json_evpn
, "remoteVteps",
274 json_object_object_add(json
, vni_str
, json_evpn
);
279 * Print an EVPN hash entry in detail - called for display of all EVPNs.
281 void zebra_evpn_print_hash_detail(struct hash_bucket
*bucket
, void *data
)
284 struct zebra_evpn
*zevpn
;
285 json_object
*json_array
= NULL
;
286 bool use_json
= false;
287 struct zebra_evpn_show
*zes
= data
;
290 json_array
= zes
->json
;
291 use_json
= zes
->use_json
;
293 zevpn
= (struct zebra_evpn
*)bucket
->data
;
295 zebra_vxlan_print_vni(vty
, zes
->zvrf
, zevpn
->vni
, use_json
, json_array
);
301 int zebra_evpn_del_macip_for_intf(struct interface
*ifp
,
302 struct zebra_evpn
*zevpn
)
304 struct listnode
*cnode
= NULL
, *cnnode
= NULL
;
305 struct connected
*c
= NULL
;
306 struct ethaddr macaddr
;
308 memcpy(&macaddr
.octet
, ifp
->hw_addr
, ETH_ALEN
);
310 for (ALL_LIST_ELEMENTS(ifp
->connected
, cnode
, cnnode
, c
)) {
313 memset(&ip
, 0, sizeof(struct ipaddr
));
314 if (!CHECK_FLAG(c
->conf
, ZEBRA_IFC_REAL
))
317 if (c
->address
->family
== AF_INET
) {
318 ip
.ipa_type
= IPADDR_V4
;
319 memcpy(&(ip
.ipaddr_v4
), &(c
->address
->u
.prefix4
),
320 sizeof(struct in_addr
));
321 } else if (c
->address
->family
== AF_INET6
) {
322 ip
.ipa_type
= IPADDR_V6
;
323 memcpy(&(ip
.ipaddr_v6
), &(c
->address
->u
.prefix6
),
324 sizeof(struct in6_addr
));
329 zebra_evpn_gw_macip_del(ifp
, zevpn
, &ip
);
335 int zebra_evpn_add_macip_for_intf(struct interface
*ifp
,
336 struct zebra_evpn
*zevpn
)
338 struct listnode
*cnode
= NULL
, *cnnode
= NULL
;
339 struct connected
*c
= NULL
;
340 struct ethaddr macaddr
;
342 memcpy(&macaddr
.octet
, ifp
->hw_addr
, ETH_ALEN
);
344 for (ALL_LIST_ELEMENTS(ifp
->connected
, cnode
, cnnode
, c
)) {
347 if (!CHECK_FLAG(c
->conf
, ZEBRA_IFC_REAL
))
350 memset(&ip
, 0, sizeof(struct ipaddr
));
351 if (c
->address
->family
== AF_INET
) {
352 ip
.ipa_type
= IPADDR_V4
;
353 memcpy(&(ip
.ipaddr_v4
), &(c
->address
->u
.prefix4
),
354 sizeof(struct in_addr
));
355 } else if (c
->address
->family
== AF_INET6
) {
356 ip
.ipa_type
= IPADDR_V6
;
357 memcpy(&(ip
.ipaddr_v6
), &(c
->address
->u
.prefix6
),
358 sizeof(struct in6_addr
));
363 zebra_evpn_gw_macip_add(ifp
, zevpn
, &macaddr
, &ip
);
368 static int ip_prefix_send_to_client(vrf_id_t vrf_id
, struct prefix
*p
,
371 struct zserv
*client
= NULL
;
372 struct stream
*s
= NULL
;
374 client
= zserv_find_client(ZEBRA_ROUTE_BGP
, 0);
375 /* BGP may not be running. */
379 s
= stream_new(ZEBRA_MAX_PACKET_SIZ
);
381 zclient_create_header(s
, cmd
, vrf_id
);
382 stream_put(s
, p
, sizeof(struct prefix
));
384 /* Write packet size. */
385 stream_putw_at(s
, 0, stream_get_endp(s
));
387 if (IS_ZEBRA_DEBUG_VXLAN
)
388 zlog_debug("Send ip prefix %pFX %s on vrf %s", p
,
389 (cmd
== ZEBRA_IP_PREFIX_ROUTE_ADD
) ? "ADD" : "DEL",
390 vrf_id_to_name(vrf_id
));
392 if (cmd
== ZEBRA_IP_PREFIX_ROUTE_ADD
)
393 client
->prefixadd_cnt
++;
395 client
->prefixdel_cnt
++;
397 return zserv_send_message(client
, s
);
400 int zebra_evpn_advertise_subnet(struct zebra_evpn
*zevpn
, struct interface
*ifp
,
403 struct listnode
*cnode
= NULL
, *cnnode
= NULL
;
404 struct connected
*c
= NULL
;
405 struct ethaddr macaddr
;
407 memcpy(&macaddr
.octet
, ifp
->hw_addr
, ETH_ALEN
);
409 for (ALL_LIST_ELEMENTS(ifp
->connected
, cnode
, cnnode
, c
)) {
412 memcpy(&p
, c
->address
, sizeof(struct prefix
));
414 /* skip link local address */
415 if (IN6_IS_ADDR_LINKLOCAL(&p
.u
.prefix6
))
420 ip_prefix_send_to_client(ifp
->vrf
->vrf_id
, &p
,
421 ZEBRA_IP_PREFIX_ROUTE_ADD
);
423 ip_prefix_send_to_client(ifp
->vrf
->vrf_id
, &p
,
424 ZEBRA_IP_PREFIX_ROUTE_DEL
);
430 * zebra_evpn_gw_macip_add_to_client
432 int zebra_evpn_gw_macip_add(struct interface
*ifp
, struct zebra_evpn
*zevpn
,
433 struct ethaddr
*macaddr
, struct ipaddr
*ip
)
435 struct zebra_mac
*mac
= NULL
;
436 struct zebra_if
*zif
= NULL
;
437 struct zebra_l2info_vxlan
*vxl
= NULL
;
439 zif
= zevpn
->vxlan_if
->info
;
443 vxl
= &zif
->l2info
.vxl
;
445 zebra_evpn_mac_gw_macip_add(ifp
, zevpn
, ip
, &mac
, macaddr
,
446 vxl
->access_vlan
, true);
448 return zebra_evpn_neigh_gw_macip_add(ifp
, zevpn
, ip
, mac
);
452 * zebra_evpn_gw_macip_del_from_client
454 int zebra_evpn_gw_macip_del(struct interface
*ifp
, struct zebra_evpn
*zevpn
,
457 struct zebra_neigh
*n
= NULL
;
458 struct zebra_mac
*mac
= NULL
;
460 /* If the neigh entry is not present nothing to do*/
461 n
= zebra_evpn_neigh_lookup(zevpn
, ip
);
465 /* mac entry should be present */
466 mac
= zebra_evpn_mac_lookup(zevpn
, &n
->emac
);
468 if (IS_ZEBRA_DEBUG_VXLAN
)
469 zlog_debug("MAC %pEA doesn't exist for neigh %pIA on VNI %u",
470 &n
->emac
, ip
, zevpn
->vni
);
474 /* If the entry is not local nothing to do*/
475 if (!CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_LOCAL
))
478 /* only need to delete the entry from bgp if we sent it before */
479 if (IS_ZEBRA_DEBUG_VXLAN
)
481 "%u:SVI %s(%u) VNI %u, sending GW MAC %pEA IP %pIA del to BGP",
482 ifp
->vrf
->vrf_id
, ifp
->name
, ifp
->ifindex
, zevpn
->vni
,
485 /* Remove neighbor from BGP. */
486 zebra_evpn_neigh_send_del_to_client(zevpn
->vni
, &n
->ip
, &n
->emac
,
487 n
->flags
, ZEBRA_NEIGH_ACTIVE
,
490 /* Delete this neighbor entry. */
491 zebra_evpn_neigh_del(zevpn
, n
);
493 /* see if the mac needs to be deleted as well*/
495 zebra_evpn_deref_ip2mac(zevpn
, mac
);
500 void zebra_evpn_gw_macip_del_for_evpn_hash(struct hash_bucket
*bucket
,
503 struct zebra_evpn
*zevpn
= NULL
;
504 struct zebra_if
*zif
= NULL
;
505 struct zebra_l2info_vxlan zl2_info
;
506 struct interface
*vlan_if
= NULL
;
507 struct interface
*vrr_if
= NULL
;
508 struct interface
*ifp
;
510 /* Add primary SVI MAC*/
511 zevpn
= (struct zebra_evpn
*)bucket
->data
;
513 /* Global (Zvrf) advertise-default-gw is disabled,
514 * but zevpn advertise-default-gw is enabled
516 if (zevpn
->advertise_gw_macip
) {
517 if (IS_ZEBRA_DEBUG_VXLAN
)
518 zlog_debug("VNI: %u GW-MACIP enabled, retain gw-macip",
523 ifp
= zevpn
->vxlan_if
;
528 /* If down or not mapped to a bridge, we're done. */
529 if (!if_is_operative(ifp
) || !zif
->brslave_info
.br_if
)
532 zl2_info
= zif
->l2info
.vxl
;
535 zvni_map_to_svi(zl2_info
.access_vlan
, zif
->brslave_info
.br_if
);
539 /* Del primary MAC-IP */
540 zebra_evpn_del_macip_for_intf(vlan_if
, zevpn
);
542 /* Del VRR MAC-IP - if any*/
543 vrr_if
= zebra_get_vrr_intf_for_svi(vlan_if
);
545 zebra_evpn_del_macip_for_intf(vrr_if
, zevpn
);
550 void zebra_evpn_gw_macip_add_for_evpn_hash(struct hash_bucket
*bucket
,
553 struct zebra_evpn
*zevpn
= NULL
;
554 struct zebra_if
*zif
= NULL
;
555 struct zebra_l2info_vxlan zl2_info
;
556 struct interface
*vlan_if
= NULL
;
557 struct interface
*vrr_if
= NULL
;
558 struct interface
*ifp
= NULL
;
560 zevpn
= (struct zebra_evpn
*)bucket
->data
;
562 ifp
= zevpn
->vxlan_if
;
567 /* If down or not mapped to a bridge, we're done. */
568 if (!if_is_operative(ifp
) || !zif
->brslave_info
.br_if
)
570 zl2_info
= zif
->l2info
.vxl
;
573 zvni_map_to_svi(zl2_info
.access_vlan
, zif
->brslave_info
.br_if
);
577 /* Add primary SVI MAC-IP */
578 if (advertise_svi_macip_enabled(zevpn
)
579 || advertise_gw_macip_enabled(zevpn
))
580 zebra_evpn_add_macip_for_intf(vlan_if
, zevpn
);
582 if (advertise_gw_macip_enabled(zevpn
)) {
583 /* Add VRR MAC-IP - if any*/
584 vrr_if
= zebra_get_vrr_intf_for_svi(vlan_if
);
586 zebra_evpn_add_macip_for_intf(vrr_if
, zevpn
);
592 void zebra_evpn_svi_macip_del_for_evpn_hash(struct hash_bucket
*bucket
,
595 struct zebra_evpn
*zevpn
= NULL
;
596 struct zebra_if
*zif
= NULL
;
597 struct zebra_l2info_vxlan zl2_info
;
598 struct interface
*vlan_if
= NULL
;
599 struct interface
*ifp
;
601 /* Add primary SVI MAC*/
602 zevpn
= (struct zebra_evpn
*)bucket
->data
;
606 /* Global(vrf) advertise-svi-ip disabled, but zevpn advertise-svi-ip
609 if (zevpn
->advertise_svi_macip
) {
610 if (IS_ZEBRA_DEBUG_VXLAN
)
611 zlog_debug("VNI: %u SVI-MACIP enabled, retain svi-macip",
616 ifp
= zevpn
->vxlan_if
;
621 /* If down or not mapped to a bridge, we're done. */
622 if (!if_is_operative(ifp
) || !zif
->brslave_info
.br_if
)
625 zl2_info
= zif
->l2info
.vxl
;
628 zvni_map_to_svi(zl2_info
.access_vlan
, zif
->brslave_info
.br_if
);
632 /* Del primary MAC-IP */
633 zebra_evpn_del_macip_for_intf(vlan_if
, zevpn
);
638 static int zebra_evpn_map_vlan_ns(struct ns
*ns
,
642 struct zebra_ns
*zns
= ns
->info
;
643 struct route_node
*rn
;
644 struct interface
*br_if
;
645 struct zebra_evpn
**p_zevpn
= (struct zebra_evpn
**)_p_zevpn
;
646 struct zebra_evpn
*zevpn
;
647 struct interface
*tmp_if
= NULL
;
648 struct zebra_if
*zif
;
649 struct zebra_l2info_vxlan
*vxl
= NULL
;
650 struct zebra_from_svi_param
*in_param
=
651 (struct zebra_from_svi_param
*)_in_param
;
653 assert(p_zevpn
&& in_param
);
655 br_if
= in_param
->br_if
;
660 /* See if this interface (or interface plus VLAN Id) maps to a VxLAN */
661 /* TODO: Optimize with a hash. */
662 for (rn
= route_top(zns
->if_table
); rn
; rn
= route_next(rn
)) {
663 tmp_if
= (struct interface
*)rn
->info
;
667 if (!zif
|| zif
->zif_type
!= ZEBRA_IF_VXLAN
)
669 if (!if_is_operative(tmp_if
))
671 vxl
= &zif
->l2info
.vxl
;
673 if (zif
->brslave_info
.br_if
!= br_if
)
676 if (!in_param
->bridge_vlan_aware
677 || vxl
->access_vlan
== in_param
->vid
) {
678 zevpn
= zebra_evpn_lookup(vxl
->vni
);
684 return NS_WALK_CONTINUE
;
688 * Map port or (port, VLAN) to an EVPN. This is invoked upon getting MAC
689 * notifications, to see if they are of interest.
691 struct zebra_evpn
*zebra_evpn_map_vlan(struct interface
*ifp
,
692 struct interface
*br_if
, vlanid_t vid
)
694 struct zebra_if
*zif
;
695 struct zebra_l2info_bridge
*br
;
696 struct zebra_evpn
**p_zevpn
;
697 struct zebra_evpn
*zevpn
= NULL
;
698 struct zebra_from_svi_param in_param
;
700 /* Determine if bridge is VLAN-aware or not */
703 br
= &zif
->l2info
.br
;
704 in_param
.bridge_vlan_aware
= br
->vlan_aware
;
706 in_param
.br_if
= br_if
;
710 ns_walk_func(zebra_evpn_map_vlan_ns
,
716 static int zebra_evpn_from_svi_ns(struct ns
*ns
,
720 struct zebra_ns
*zns
= ns
->info
;
721 struct route_node
*rn
;
722 struct interface
*br_if
;
723 struct zebra_evpn
**p_zevpn
= (struct zebra_evpn
**)_p_zevpn
;
724 struct zebra_evpn
*zevpn
;
725 struct interface
*tmp_if
= NULL
;
726 struct zebra_if
*zif
;
727 struct zebra_l2info_vxlan
*vxl
= NULL
;
728 struct zebra_from_svi_param
*in_param
=
729 (struct zebra_from_svi_param
*)_in_param
;
734 br_if
= in_param
->br_if
;
738 /* TODO: Optimize with a hash. */
739 for (rn
= route_top(zns
->if_table
); rn
; rn
= route_next(rn
)) {
740 tmp_if
= (struct interface
*)rn
->info
;
744 if (!zif
|| zif
->zif_type
!= ZEBRA_IF_VXLAN
)
746 if (!if_is_operative(tmp_if
))
748 vxl
= &zif
->l2info
.vxl
;
750 if (zif
->brslave_info
.br_if
!= br_if
)
753 if (!in_param
->bridge_vlan_aware
754 || vxl
->access_vlan
== in_param
->vid
) {
761 return NS_WALK_CONTINUE
;
763 zevpn
= zebra_evpn_lookup(vxl
->vni
);
770 * Map SVI and associated bridge to an EVPN. This is invoked upon getting
771 * neighbor notifications, to see if they are of interest.
773 struct zebra_evpn
*zebra_evpn_from_svi(struct interface
*ifp
,
774 struct interface
*br_if
)
776 struct zebra_l2info_bridge
*br
;
777 struct zebra_evpn
*zevpn
= NULL
;
778 struct zebra_evpn
**p_zevpn
;
779 struct zebra_if
*zif
;
780 struct zebra_from_svi_param in_param
;
785 /* Make sure the linked interface is a bridge. */
786 if (!IS_ZEBRA_IF_BRIDGE(br_if
))
789 /* Determine if bridge is VLAN-aware or not */
792 br
= &zif
->l2info
.br
;
793 in_param
.bridge_vlan_aware
= br
->vlan_aware
;
796 if (in_param
.bridge_vlan_aware
) {
797 struct zebra_l2info_vlan
*vl
;
799 if (!IS_ZEBRA_IF_VLAN(ifp
))
804 vl
= &zif
->l2info
.vl
;
805 in_param
.vid
= vl
->vid
;
808 in_param
.br_if
= br_if
;
811 /* See if this interface (or interface plus VLAN Id) maps to a VxLAN */
812 ns_walk_func(zebra_evpn_from_svi_ns
, (void *)&in_param
,
817 static int zvni_map_to_macvlan_ns(struct ns
*ns
,
821 struct zebra_ns
*zns
= ns
->info
;
822 struct zebra_from_svi_param
*in_param
=
823 (struct zebra_from_svi_param
*)_in_param
;
824 struct interface
**p_ifp
= (struct interface
**)_p_ifp
;
825 struct route_node
*rn
;
826 struct interface
*tmp_if
= NULL
;
827 struct zebra_if
*zif
;
829 assert(in_param
&& p_ifp
);
831 /* Identify corresponding VLAN interface. */
832 for (rn
= route_top(zns
->if_table
); rn
; rn
= route_next(rn
)) {
833 tmp_if
= (struct interface
*)rn
->info
;
834 /* Check oper status of the SVI. */
835 if (!tmp_if
|| !if_is_operative(tmp_if
))
839 if (!zif
|| zif
->zif_type
!= ZEBRA_IF_MACVLAN
)
842 if (zif
->link
== in_param
->svi_if
) {
848 return NS_WALK_CONTINUE
;
851 /* Map to MAC-VLAN interface corresponding to specified SVI interface.
853 struct interface
*zebra_evpn_map_to_macvlan(struct interface
*br_if
,
854 struct interface
*svi_if
)
856 struct interface
*tmp_if
= NULL
;
857 struct zebra_if
*zif
;
858 struct interface
**p_ifp
;
859 struct zebra_from_svi_param in_param
;
861 /* Defensive check, caller expected to invoke only with valid bridge. */
866 zlog_debug("svi_if is not passed.");
870 /* Determine if bridge is VLAN-aware or not */
875 in_param
.br_if
= br_if
;
877 in_param
.svi_if
= svi_if
;
880 /* Identify corresponding VLAN interface. */
881 ns_walk_func(zvni_map_to_macvlan_ns
,
888 * Install MAC hash entry - called upon access VLAN change.
890 void zebra_evpn_install_mac_hash(struct hash_bucket
*bucket
, void *ctxt
)
892 struct zebra_mac
*mac
;
893 struct mac_walk_ctx
*wctx
= ctxt
;
895 mac
= (struct zebra_mac
*)bucket
->data
;
897 if (CHECK_FLAG(mac
->flags
, ZEBRA_MAC_REMOTE
))
898 zebra_evpn_rem_mac_install(wctx
->zevpn
, mac
, false);
902 * Read and populate local MACs and neighbors corresponding to this EVPN.
904 void zebra_evpn_read_mac_neigh(struct zebra_evpn
*zevpn
, struct interface
*ifp
)
906 struct zebra_ns
*zns
;
907 struct zebra_vrf
*zvrf
;
908 struct zebra_if
*zif
;
909 struct interface
*vlan_if
;
910 struct zebra_l2info_vxlan
*vxl
;
911 struct interface
*vrr_if
;
914 vxl
= &zif
->l2info
.vxl
;
915 zvrf
= zebra_vrf_lookup_by_id(zevpn
->vrf_id
);
916 if (!zvrf
|| !zvrf
->zns
)
920 if (IS_ZEBRA_DEBUG_VXLAN
)
922 "Reading MAC FDB and Neighbors for intf %s(%u) VNI %u master %u",
923 ifp
->name
, ifp
->ifindex
, zevpn
->vni
,
924 zif
->brslave_info
.bridge_ifindex
);
926 macfdb_read_for_bridge(zns
, ifp
, zif
->brslave_info
.br_if
);
927 vlan_if
= zvni_map_to_svi(vxl
->access_vlan
, zif
->brslave_info
.br_if
);
930 zebra_evpn_acc_bd_svi_mac_add(vlan_if
);
933 if (advertise_svi_macip_enabled(zevpn
)
934 || advertise_gw_macip_enabled(zevpn
))
935 zebra_evpn_add_macip_for_intf(vlan_if
, zevpn
);
937 /* Add VRR MAC-IP - if any*/
938 if (advertise_gw_macip_enabled(zevpn
)) {
939 vrr_if
= zebra_get_vrr_intf_for_svi(vlan_if
);
941 zebra_evpn_add_macip_for_intf(vrr_if
, zevpn
);
944 neigh_read_for_vlan(zns
, vlan_if
);
949 * Hash function for EVPN.
951 unsigned int zebra_evpn_hash_keymake(const void *p
)
953 const struct zebra_evpn
*zevpn
= p
;
955 return (jhash_1word(zevpn
->vni
, 0));
959 * Compare 2 evpn hash entries.
961 bool zebra_evpn_hash_cmp(const void *p1
, const void *p2
)
963 const struct zebra_evpn
*zevpn1
= p1
;
964 const struct zebra_evpn
*zevpn2
= p2
;
966 return (zevpn1
->vni
== zevpn2
->vni
);
969 int zebra_evpn_list_cmp(void *p1
, void *p2
)
971 const struct zebra_evpn
*zevpn1
= p1
;
972 const struct zebra_evpn
*zevpn2
= p2
;
974 if (zevpn1
->vni
== zevpn2
->vni
)
976 return (zevpn1
->vni
< zevpn2
->vni
) ? -1 : 1;
980 * Callback to allocate VNI hash entry.
982 void *zebra_evpn_alloc(void *p
)
984 const struct zebra_evpn
*tmp_vni
= p
;
985 struct zebra_evpn
*zevpn
;
987 zevpn
= XCALLOC(MTYPE_ZEVPN
, sizeof(struct zebra_evpn
));
988 zevpn
->vni
= tmp_vni
->vni
;
989 return ((void *)zevpn
);
993 * Look up EVPN hash entry.
995 struct zebra_evpn
*zebra_evpn_lookup(vni_t vni
)
997 struct zebra_vrf
*zvrf
;
998 struct zebra_evpn tmp_vni
;
999 struct zebra_evpn
*zevpn
= NULL
;
1001 zvrf
= zebra_vrf_get_evpn();
1003 memset(&tmp_vni
, 0, sizeof(struct zebra_evpn
));
1005 zevpn
= hash_lookup(zvrf
->evpn_table
, &tmp_vni
);
1011 * Add EVPN hash entry.
1013 struct zebra_evpn
*zebra_evpn_add(vni_t vni
)
1016 struct zebra_vrf
*zvrf
;
1017 struct zebra_evpn tmp_zevpn
;
1018 struct zebra_evpn
*zevpn
= NULL
;
1020 zvrf
= zebra_vrf_get_evpn();
1022 memset(&tmp_zevpn
, 0, sizeof(struct zebra_evpn
));
1023 tmp_zevpn
.vni
= vni
;
1024 zevpn
= hash_get(zvrf
->evpn_table
, &tmp_zevpn
, zebra_evpn_alloc
);
1027 zebra_evpn_es_evi_init(zevpn
);
1029 snprintf(buffer
, sizeof(buffer
), "Zebra EVPN MAC Table vni: %u", vni
);
1030 /* Create hash table for MAC */
1031 zevpn
->mac_table
= zebra_mac_db_create(buffer
);
1033 snprintf(buffer
, sizeof(buffer
), "Zebra EVPN Neighbor Table vni: %u",
1035 /* Create hash table for neighbors */
1036 zevpn
->neigh_table
= zebra_neigh_db_create(buffer
);
1042 * Delete EVPN hash entry.
1044 int zebra_evpn_del(struct zebra_evpn
*zevpn
)
1046 struct zebra_vrf
*zvrf
;
1047 struct zebra_evpn
*tmp_zevpn
;
1049 zvrf
= zebra_vrf_get_evpn();
1052 zevpn
->svi_if
= NULL
;
1054 /* Free the neighbor hash table. */
1055 hash_free(zevpn
->neigh_table
);
1056 zevpn
->neigh_table
= NULL
;
1058 /* Free the MAC hash table. */
1059 hash_free(zevpn
->mac_table
);
1060 zevpn
->mac_table
= NULL
;
1062 /* Remove references to the zevpn in the MH databases */
1063 if (zevpn
->vxlan_if
)
1064 zebra_evpn_vxl_evpn_set(zevpn
->vxlan_if
->info
, zevpn
, false);
1065 zebra_evpn_es_evi_cleanup(zevpn
);
1067 /* Free the EVPN hash entry and allocated memory. */
1068 tmp_zevpn
= hash_release(zvrf
->evpn_table
, zevpn
);
1069 XFREE(MTYPE_ZEVPN
, tmp_zevpn
);
1075 * Inform BGP about local EVPN addition.
1077 int zebra_evpn_send_add_to_client(struct zebra_evpn
*zevpn
)
1079 struct zserv
*client
;
1081 ifindex_t svi_index
;
1084 client
= zserv_find_client(ZEBRA_ROUTE_BGP
, 0);
1085 /* BGP may not be running. */
1089 svi_index
= zevpn
->svi_if
? zevpn
->svi_if
->ifindex
: 0;
1091 s
= stream_new(ZEBRA_MAX_PACKET_SIZ
);
1093 zclient_create_header(s
, ZEBRA_VNI_ADD
, zebra_vrf_get_evpn_id());
1094 stream_putl(s
, zevpn
->vni
);
1095 stream_put_in_addr(s
, &zevpn
->local_vtep_ip
);
1096 stream_put(s
, &zevpn
->vrf_id
, sizeof(vrf_id_t
)); /* tenant vrf */
1097 stream_put_in_addr(s
, &zevpn
->mcast_grp
);
1098 stream_put(s
, &svi_index
, sizeof(ifindex_t
));
1100 /* Write packet size. */
1101 stream_putw_at(s
, 0, stream_get_endp(s
));
1103 if (IS_ZEBRA_DEBUG_VXLAN
)
1105 "Send EVPN_ADD %u %pI4 tenant vrf %s(%u) SVI index %u to %s",
1106 zevpn
->vni
, &zevpn
->local_vtep_ip
,
1107 vrf_id_to_name(zevpn
->vrf_id
), zevpn
->vrf_id
,
1108 (zevpn
->svi_if
? zevpn
->svi_if
->ifindex
: 0),
1109 zebra_route_string(client
->proto
));
1111 client
->vniadd_cnt
++;
1112 rc
= zserv_send_message(client
, s
);
1114 if (!(zevpn
->flags
& ZEVPN_READY_FOR_BGP
)) {
1115 zevpn
->flags
|= ZEVPN_READY_FOR_BGP
;
1116 /* once the EVPN is sent the ES-EVIs can also be replayed
1119 zebra_evpn_update_all_es(zevpn
);
1125 * Inform BGP about local EVPN deletion.
1127 int zebra_evpn_send_del_to_client(struct zebra_evpn
*zevpn
)
1129 struct zserv
*client
;
1132 client
= zserv_find_client(ZEBRA_ROUTE_BGP
, 0);
1133 /* BGP may not be running. */
1137 if (zevpn
->flags
& ZEVPN_READY_FOR_BGP
) {
1138 zevpn
->flags
&= ~ZEVPN_READY_FOR_BGP
;
1139 /* the ES-EVIs must be removed from BGP before the EVPN is */
1140 zebra_evpn_update_all_es(zevpn
);
1143 s
= stream_new(ZEBRA_MAX_PACKET_SIZ
);
1146 zclient_create_header(s
, ZEBRA_VNI_DEL
, zebra_vrf_get_evpn_id());
1147 stream_putl(s
, zevpn
->vni
);
1149 /* Write packet size. */
1150 stream_putw_at(s
, 0, stream_get_endp(s
));
1152 if (IS_ZEBRA_DEBUG_VXLAN
)
1153 zlog_debug("Send EVPN_DEL %u to %s", zevpn
->vni
,
1154 zebra_route_string(client
->proto
));
1156 client
->vnidel_cnt
++;
1157 return zserv_send_message(client
, s
);
1161 * See if remote VTEP matches with prefix.
1163 static int zebra_evpn_vtep_match(struct in_addr
*vtep_ip
,
1164 struct zebra_vtep
*zvtep
)
1166 return (IPV4_ADDR_SAME(vtep_ip
, &zvtep
->vtep_ip
));
1170 * Locate remote VTEP in EVPN hash table.
1172 struct zebra_vtep
*zebra_evpn_vtep_find(struct zebra_evpn
*zevpn
,
1173 struct in_addr
*vtep_ip
)
1175 struct zebra_vtep
*zvtep
;
1180 for (zvtep
= zevpn
->vteps
; zvtep
; zvtep
= zvtep
->next
) {
1181 if (zebra_evpn_vtep_match(vtep_ip
, zvtep
))
1189 * Add remote VTEP to EVPN hash table.
1191 struct zebra_vtep
*zebra_evpn_vtep_add(struct zebra_evpn
*zevpn
,
1192 struct in_addr
*vtep_ip
,
1196 struct zebra_vtep
*zvtep
;
1198 zvtep
= XCALLOC(MTYPE_ZEVPN_VTEP
, sizeof(struct zebra_vtep
));
1200 zvtep
->vtep_ip
= *vtep_ip
;
1201 zvtep
->flood_control
= flood_control
;
1204 zevpn
->vteps
->prev
= zvtep
;
1205 zvtep
->next
= zevpn
->vteps
;
1206 zevpn
->vteps
= zvtep
;
1212 * Remove remote VTEP from EVPN hash table.
1214 int zebra_evpn_vtep_del(struct zebra_evpn
*zevpn
, struct zebra_vtep
*zvtep
)
1217 zvtep
->next
->prev
= zvtep
->prev
;
1219 zvtep
->prev
->next
= zvtep
->next
;
1221 zevpn
->vteps
= zvtep
->next
;
1223 zvtep
->prev
= zvtep
->next
= NULL
;
1224 XFREE(MTYPE_ZEVPN_VTEP
, zvtep
);
1230 * Delete all remote VTEPs for this EVPN (upon VNI delete). Also
1231 * uninstall from kernel if asked to.
1233 int zebra_evpn_vtep_del_all(struct zebra_evpn
*zevpn
, int uninstall
)
1235 struct zebra_vtep
*zvtep
, *zvtep_next
;
1240 for (zvtep
= zevpn
->vteps
; zvtep
; zvtep
= zvtep_next
) {
1241 zvtep_next
= zvtep
->next
;
1243 zebra_evpn_vtep_uninstall(zevpn
, &zvtep
->vtep_ip
);
1244 zebra_evpn_vtep_del(zevpn
, zvtep
);
1251 * Install remote VTEP into the kernel if the remote VTEP has asked
1252 * for head-end-replication.
1254 int zebra_evpn_vtep_install(struct zebra_evpn
*zevpn
, struct zebra_vtep
*zvtep
)
1256 if (is_vxlan_flooding_head_end() &&
1257 (zvtep
->flood_control
== VXLAN_FLOOD_HEAD_END_REPL
)) {
1258 if (ZEBRA_DPLANE_REQUEST_FAILURE
==
1259 dplane_vtep_add(zevpn
->vxlan_if
,
1260 &zvtep
->vtep_ip
, zevpn
->vni
))
1268 * Uninstall remote VTEP from the kernel.
1270 int zebra_evpn_vtep_uninstall(struct zebra_evpn
*zevpn
, struct in_addr
*vtep_ip
)
1272 if (!zevpn
->vxlan_if
) {
1273 zlog_debug("VNI %u hash %p couldn't be uninstalled - no intf",
1278 if (ZEBRA_DPLANE_REQUEST_FAILURE
==
1279 dplane_vtep_delete(zevpn
->vxlan_if
, vtep_ip
, zevpn
->vni
))
1286 * Install or uninstall flood entries in the kernel corresponding to
1287 * remote VTEPs. This is invoked upon change to BUM handling.
1289 void zebra_evpn_handle_flooding_remote_vteps(struct hash_bucket
*bucket
,
1292 struct zebra_evpn
*zevpn
;
1293 struct zebra_vtep
*zvtep
;
1295 zevpn
= (struct zebra_evpn
*)bucket
->data
;
1299 for (zvtep
= zevpn
->vteps
; zvtep
; zvtep
= zvtep
->next
) {
1300 if (is_vxlan_flooding_head_end())
1301 zebra_evpn_vtep_install(zevpn
, zvtep
);
1303 zebra_evpn_vtep_uninstall(zevpn
, &zvtep
->vtep_ip
);
1308 * Cleanup EVPN/VTEP and update kernel
1310 void zebra_evpn_cleanup_all(struct hash_bucket
*bucket
, void *arg
)
1312 struct zebra_evpn
*zevpn
= NULL
;
1314 zevpn
= (struct zebra_evpn
*)bucket
->data
;
1316 /* Free up all neighbors and MACs, if any. */
1317 zebra_evpn_neigh_del_all(zevpn
, 1, 0, DEL_ALL_NEIGH
);
1318 zebra_evpn_mac_del_all(zevpn
, 1, 0, DEL_ALL_MAC
);
1320 /* Free up all remote VTEPs, if any. */
1321 zebra_evpn_vtep_del_all(zevpn
, 1);
1323 /* Delete the hash entry. */
1324 zebra_evpn_del(zevpn
);
1327 static void zebra_evpn_process_sync_macip_add(struct zebra_evpn
*zevpn
,
1328 const struct ethaddr
*macaddr
,
1330 const struct ipaddr
*ipaddr
,
1331 uint8_t flags
, uint32_t seq
,
1334 struct sync_mac_ip_ctx ctx
;
1335 char ipbuf
[INET6_ADDRSTRLEN
];
1338 struct zebra_neigh
*n
= NULL
;
1340 sticky
= !!CHECK_FLAG(flags
, ZEBRA_MACIP_TYPE_STICKY
);
1341 remote_gw
= !!CHECK_FLAG(flags
, ZEBRA_MACIP_TYPE_GW
);
1342 /* if sticky or remote-gw ignore updates from the peer */
1343 if (sticky
|| remote_gw
) {
1344 if (IS_ZEBRA_DEBUG_VXLAN
|| IS_ZEBRA_DEBUG_EVPN_MH_NEIGH
1345 || IS_ZEBRA_DEBUG_EVPN_MH_MAC
)
1347 "Ignore sync-macip vni %u mac %pEA%s%s%s%s",
1350 ipa_len
? " IP " : "",
1351 ipa_len
? ipaddr2str(ipaddr
, ipbuf
,
1354 sticky
? " sticky" : "",
1355 remote_gw
? " remote_gw" : "");
1360 n
= zebra_evpn_neigh_lookup(zevpn
, ipaddr
);
1362 && !zebra_evpn_neigh_is_bgp_seq_ok(zevpn
, n
, macaddr
, seq
,
1367 memset(&ctx
, 0, sizeof(ctx
));
1368 ctx
.mac
= zebra_evpn_proc_sync_mac_update(
1369 zevpn
, macaddr
, ipa_len
, ipaddr
, flags
, seq
, esi
, &ctx
);
1370 if (ctx
.ignore_macip
|| !ctx
.mac
|| !ipa_len
)
1373 zebra_evpn_proc_sync_neigh_update(zevpn
, n
, ipa_len
, ipaddr
, flags
, seq
,
1377 /************************** remote mac-ip handling **************************/
1378 /* Process a remote MACIP add from BGP. */
1379 void zebra_evpn_rem_macip_add(vni_t vni
, const struct ethaddr
*macaddr
,
1380 uint16_t ipa_len
, const struct ipaddr
*ipaddr
,
1381 uint8_t flags
, uint32_t seq
,
1382 struct in_addr vtep_ip
, const esi_t
*esi
)
1384 struct zebra_evpn
*zevpn
;
1385 struct zebra_vtep
*zvtep
;
1386 struct zebra_mac
*mac
= NULL
;
1387 struct interface
*ifp
= NULL
;
1388 struct zebra_if
*zif
= NULL
;
1389 struct zebra_vrf
*zvrf
;
1391 /* Locate EVPN hash entry - expected to exist. */
1392 zevpn
= zebra_evpn_lookup(vni
);
1394 if (IS_ZEBRA_DEBUG_VXLAN
)
1395 zlog_debug("Unknown VNI %u upon remote MACIP ADD", vni
);
1399 ifp
= zevpn
->vxlan_if
;
1402 if (!ifp
|| !if_is_operative(ifp
) || !zif
|| !zif
->brslave_info
.br_if
) {
1404 "Ignoring remote MACIP ADD VNI %u, invalid interface state or info",
1409 /* Type-2 routes from another PE can be interpreted as remote or
1410 * SYNC based on the destination ES -
1411 * SYNC - if ES is local
1412 * REMOTE - if ES is not local
1414 if (flags
& ZEBRA_MACIP_TYPE_SYNC_PATH
) {
1415 struct zebra_evpn_es
*es
;
1417 es
= zebra_evpn_es_find(esi
);
1418 if (es
&& (es
->flags
& ZEBRA_EVPNES_READY_FOR_BGP
)) {
1419 zebra_evpn_process_sync_macip_add(zevpn
, macaddr
,
1423 if (IS_ZEBRA_DEBUG_EVPN_MH_ES
) {
1424 char esi_str
[ESI_STR_LEN
];
1426 esi_to_str(esi
, esi_str
, sizeof(esi_str
));
1428 "Ignore sync-macip add; ES %s is not ready",
1436 /* The remote VTEP specified should normally exist, but it is
1437 * possible that when peering comes up, peer may advertise MACIP
1438 * routes before advertising type-3 routes.
1440 if (vtep_ip
.s_addr
) {
1441 zvtep
= zebra_evpn_vtep_find(zevpn
, &vtep_ip
);
1443 zvtep
= zebra_evpn_vtep_add(zevpn
, &vtep_ip
,
1444 VXLAN_FLOOD_DISABLED
);
1447 EC_ZEBRA_VTEP_ADD_FAILED
,
1448 "Failed to add remote VTEP, VNI %u zevpn %p upon remote MACIP ADD",
1453 zebra_evpn_vtep_install(zevpn
, zvtep
);
1457 zvrf
= zebra_vrf_get_evpn();
1462 if (zebra_evpn_mac_remote_macip_add(zevpn
, zvrf
, macaddr
, ipa_len
,
1463 ipaddr
, &mac
, vtep_ip
, flags
, seq
,
1468 zebra_evpn_neigh_remote_macip_add(zevpn
, zvrf
, ipaddr
, mac
, vtep_ip
,
1472 /* Process a remote MACIP delete from BGP. */
1473 void zebra_evpn_rem_macip_del(vni_t vni
, const struct ethaddr
*macaddr
,
1474 uint16_t ipa_len
, const struct ipaddr
*ipaddr
,
1475 struct in_addr vtep_ip
)
1477 struct zebra_evpn
*zevpn
;
1478 struct zebra_mac
*mac
= NULL
;
1479 struct zebra_neigh
*n
= NULL
;
1480 struct interface
*ifp
= NULL
;
1481 struct zebra_if
*zif
= NULL
;
1482 struct zebra_ns
*zns
;
1483 struct zebra_l2info_vxlan
*vxl
;
1484 struct zebra_vrf
*zvrf
;
1485 char buf1
[INET6_ADDRSTRLEN
];
1487 /* Locate EVPN hash entry - expected to exist. */
1488 zevpn
= zebra_evpn_lookup(vni
);
1490 if (IS_ZEBRA_DEBUG_VXLAN
)
1491 zlog_debug("Unknown VNI %u upon remote MACIP DEL", vni
);
1495 ifp
= zevpn
->vxlan_if
;
1498 if (!ifp
|| !if_is_operative(ifp
) || !zif
|| !zif
->brslave_info
.br_if
) {
1499 if (IS_ZEBRA_DEBUG_VXLAN
)
1501 "Ignoring remote MACIP DEL VNI %u, invalid interface state or info",
1505 zns
= zebra_ns_lookup(NS_DEFAULT
);
1506 vxl
= &zif
->l2info
.vxl
;
1508 mac
= zebra_evpn_mac_lookup(zevpn
, macaddr
);
1510 n
= zebra_evpn_neigh_lookup(zevpn
, ipaddr
);
1514 "Failed to locate MAC %pEA for neigh %pIA VNI %u upon remote MACIP DEL",
1515 macaddr
, ipaddr
, vni
);
1519 /* If the remote mac or neighbor doesn't exist there is nothing
1520 * more to do. Otherwise, uninstall the entry and then remove it.
1525 zvrf
= zevpn
->vxlan_if
->vrf
->info
;
1527 /* Ignore the delete if this mac is a gateway mac-ip */
1528 if (CHECK_FLAG(mac
->flags
, ZEBRA_MAC_LOCAL
)
1529 && CHECK_FLAG(mac
->flags
, ZEBRA_MAC_DEF_GW
)) {
1531 "Ignore remote MACIP DEL VNI %u MAC %pEA%s%s as MAC is already configured as gateway MAC",
1533 ipa_len
? " IP " : "",
1534 ipa_len
? ipaddr2str(ipaddr
, buf1
, sizeof(buf1
)) : "");
1538 /* Uninstall remote neighbor or MAC. */
1540 zebra_evpn_neigh_remote_uninstall(zevpn
, zvrf
, n
, mac
, ipaddr
);
1542 /* DAD: when MAC is freeze state as remote learn event,
1543 * remote mac-ip delete event is received will result in freeze
1544 * entry removal, first fetch kernel for the same entry present
1545 * as LOCAL and reachable, avoid deleting this entry instead
1546 * use kerenel local entry to update during unfreeze time.
1548 if (zvrf
->dad_freeze
1549 && CHECK_FLAG(mac
->flags
, ZEBRA_MAC_DUPLICATE
)
1550 && CHECK_FLAG(mac
->flags
, ZEBRA_MAC_REMOTE
)) {
1551 if (IS_ZEBRA_DEBUG_VXLAN
)
1553 "%s: MAC %pEA (flags 0x%x) is remote and duplicate, read kernel for local entry",
1554 __func__
, macaddr
, mac
->flags
);
1555 macfdb_read_specific_mac(zns
, zif
->brslave_info
.br_if
,
1556 macaddr
, vxl
->access_vlan
);
1559 if (CHECK_FLAG(mac
->flags
, ZEBRA_MAC_LOCAL
)) {
1561 zebra_evpn_sync_mac_del(mac
);
1562 } else if (CHECK_FLAG(mac
->flags
, ZEBRA_NEIGH_REMOTE
)) {
1563 zebra_evpn_rem_mac_del(zevpn
, mac
);
1568 /************************** EVPN BGP config management ************************/
1569 void zebra_evpn_cfg_cleanup(struct hash_bucket
*bucket
, void *ctxt
)
1571 struct zebra_evpn
*zevpn
= NULL
;
1573 zevpn
= (struct zebra_evpn
*)bucket
->data
;
1574 zevpn
->advertise_gw_macip
= 0;
1575 zevpn
->advertise_svi_macip
= 0;
1576 zevpn
->advertise_subnet
= 0;
1578 zebra_evpn_neigh_del_all(zevpn
, 1, 0,
1579 DEL_REMOTE_NEIGH
| DEL_REMOTE_NEIGH_FROM_VTEP
);
1580 zebra_evpn_mac_del_all(zevpn
, 1, 0,
1581 DEL_REMOTE_MAC
| DEL_REMOTE_MAC_FROM_VTEP
);
1582 zebra_evpn_vtep_del_all(zevpn
, 1);