1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Zebra EVPN for VxLAN code
4 * Copyright (C) 2016, 2017 Cumulus Networks, Inc.
20 #include <linux/neighbour.h>
23 #include "zebra/zebra_router.h"
24 #include "zebra/debug.h"
25 #include "zebra/interface.h"
26 #include "zebra/rib.h"
28 #include "zebra/rt_netlink.h"
29 #include "zebra/zebra_errors.h"
30 #include "zebra/zebra_l2.h"
31 #include "zebra/zebra_ns.h"
32 #include "zebra/zebra_vrf.h"
33 #include "zebra/zebra_vxlan.h"
34 #include "zebra/zebra_evpn.h"
35 #include "zebra/zebra_evpn_mac.h"
36 #include "zebra/zebra_evpn_neigh.h"
37 #include "zebra/zebra_vxlan_private.h"
38 #include "zebra/zebra_evpn_mh.h"
39 #include "zebra/zebra_evpn_vxlan.h"
40 #include "zebra/zebra_router.h"
42 DEFINE_MTYPE_STATIC(ZEBRA
, ZEVPN
, "VNI hash");
43 DEFINE_MTYPE_STATIC(ZEBRA
, ZEVPN_VTEP
, "VNI remote VTEP");
46 #define VXLAN_FLOOD_STR_NO_INFO "-"
47 #define VXLAN_FLOOD_STR_DEFAULT VXLAN_FLOOD_STR_NO_INFO
48 static const struct message zvtep_flood_str
[] = {
49 {VXLAN_FLOOD_DISABLED
, VXLAN_FLOOD_STR_NO_INFO
},
50 {VXLAN_FLOOD_PIM_SM
, "PIM-SM"},
51 {VXLAN_FLOOD_HEAD_END_REPL
, "HER"},
55 int advertise_gw_macip_enabled(struct zebra_evpn
*zevpn
)
57 struct zebra_vrf
*zvrf
;
59 zvrf
= zebra_vrf_get_evpn();
60 if (zvrf
->advertise_gw_macip
)
63 if (zevpn
&& zevpn
->advertise_gw_macip
)
69 int advertise_svi_macip_enabled(struct zebra_evpn
*zevpn
)
71 struct zebra_vrf
*zvrf
;
73 zvrf
= zebra_vrf_get_evpn();
74 if (zvrf
->advertise_svi_macip
)
77 if (zevpn
&& zevpn
->advertise_svi_macip
)
84 * Print a specific EVPN entry.
86 void zebra_evpn_print(struct zebra_evpn
*zevpn
, void **ctxt
)
89 struct vty
*vty
= NULL
;
90 struct zebra_vtep
*zvtep
= NULL
;
91 uint32_t num_macs
= 0;
92 uint32_t num_neigh
= 0;
93 uint32_t num_vteps
= 0;
94 json_object
*json
= NULL
;
95 json_object
*json_vtep_list
= NULL
;
96 json_object
*json_vtep
= NULL
;
102 vty_out(vty
, "VNI: %u\n", zevpn
->vni
);
103 vty_out(vty
, " Type: %s\n", "L2");
104 vty_out(vty
, " Tenant VRF: %s\n", vrf_id_to_name(zevpn
->vrf_id
));
106 json_object_int_add(json
, "vni", zevpn
->vni
);
107 json_object_string_add(json
, "type", "L2");
108 #if CONFDATE > 20240210
109 CPP_NOTICE("Drop `vrf` from JSON output")
111 json_object_string_add(json
, "vrf",
112 vrf_id_to_name(zevpn
->vrf_id
));
113 json_object_string_add(json
, "tenantVrf",
114 vrf_id_to_name(zevpn
->vrf_id
));
117 if (!zevpn
->vxlan_if
) { // unexpected
119 vty_out(vty
, " VxLAN interface: unknown\n");
121 json_object_string_add(json
, "vxlanInterface",
125 num_macs
= num_valid_macs(zevpn
);
126 num_neigh
= hashcount(zevpn
->neigh_table
);
128 vty_out(vty
, " VxLAN interface: %s\n", zevpn
->vxlan_if
->name
);
129 vty_out(vty
, " VxLAN ifIndex: %u\n", zevpn
->vxlan_if
->ifindex
);
130 vty_out(vty
, " SVI interface: %s\n",
131 (zevpn
->svi_if
? zevpn
->svi_if
->name
: ""));
132 vty_out(vty
, " SVI ifIndex: %u\n",
133 (zevpn
->svi_if
? zevpn
->svi_if
->ifindex
: 0));
134 vty_out(vty
, " Local VTEP IP: %pI4\n",
135 &zevpn
->local_vtep_ip
);
136 vty_out(vty
, " Mcast group: %pI4\n",
139 json_object_string_add(json
, "vxlanInterface",
140 zevpn
->vxlan_if
->name
);
141 #if CONFDATE > 20240210
142 CPP_NOTICE("Drop `ifindex` from JSON output")
144 json_object_int_add(json
, "ifindex", zevpn
->vxlan_if
->ifindex
);
145 json_object_int_add(json
, "vxlanIfindex",
146 zevpn
->vxlan_if
->ifindex
);
148 json_object_string_add(json
, "sviInterface",
149 zevpn
->svi_if
->name
);
150 json_object_int_add(json
, "sviIfindex",
151 zevpn
->svi_if
->ifindex
);
153 json_object_string_addf(json
, "vtepIp", "%pI4",
154 &zevpn
->local_vtep_ip
);
155 json_object_string_addf(json
, "mcastGroup", "%pI4",
157 json_object_string_add(json
, "advertiseGatewayMacip",
158 zevpn
->advertise_gw_macip
? "Yes"
160 json_object_string_add(json
, "advertiseSviMacip",
161 zevpn
->advertise_svi_macip
? "Yes"
163 json_object_int_add(json
, "numMacs", num_macs
);
164 json_object_int_add(json
, "numArpNd", num_neigh
);
168 vty_out(vty
, " No remote VTEPs known for this VNI\n");
170 json_object_int_add(json
, "numRemoteVteps", num_vteps
);
173 vty_out(vty
, " Remote VTEPs for this VNI:\n");
175 json_vtep_list
= json_object_new_array();
176 for (zvtep
= zevpn
->vteps
; zvtep
; zvtep
= zvtep
->next
) {
177 const char *flood_str
= lookup_msg(
178 zvtep_flood_str
, zvtep
->flood_control
,
179 VXLAN_FLOOD_STR_DEFAULT
);
182 vty_out(vty
, " %pI4 flood: %s\n",
186 json_vtep
= json_object_new_object();
187 json_object_string_addf(json_vtep
, "ip", "%pI4",
189 json_object_string_add(json_vtep
, "flood",
191 json_object_array_add(json_vtep_list
,
197 json_object_int_add(json
, "numRemoteVteps", num_vteps
);
198 json_object_object_add(json
, "remoteVteps",
204 " Number of MACs (local and remote) known for this VNI: %u\n",
207 " Number of ARPs (IPv4 and IPv6, local and remote) "
208 "known for this VNI: %u\n",
210 vty_out(vty
, " Advertise-gw-macip: %s\n",
211 zevpn
->advertise_gw_macip
? "Yes" : "No");
212 vty_out(vty
, " Advertise-svi-macip: %s\n",
213 zevpn
->advertise_svi_macip
? "Yes" : "No");
218 * Print an EVPN hash entry - called for display of all VNIs.
220 void zebra_evpn_print_hash(struct hash_bucket
*bucket
, void *ctxt
[])
223 struct zebra_evpn
*zevpn
;
224 struct zebra_vtep
*zvtep
;
225 uint32_t num_vteps
= 0;
226 uint32_t num_macs
= 0;
227 uint32_t num_neigh
= 0;
228 json_object
*json
= NULL
;
229 json_object
*json_evpn
= NULL
;
230 json_object
*json_ip_str
= NULL
;
231 json_object
*json_vtep_list
= NULL
;
232 char buf
[PREFIX_STRLEN
];
237 zevpn
= (struct zebra_evpn
*)bucket
->data
;
239 zvtep
= zevpn
->vteps
;
245 num_macs
= num_valid_macs(zevpn
);
246 num_neigh
= hashcount(zevpn
->neigh_table
);
248 vty_out(vty
, "%-10u %-4s %-21s %-8u %-8u %-15u %-37s\n",
250 zevpn
->vxlan_if
? zevpn
->vxlan_if
->name
: "unknown",
251 num_macs
, num_neigh
, num_vteps
,
252 vrf_id_to_name(zevpn
->vrf_id
));
254 char vni_str
[VNI_STR_LEN
];
255 snprintf(vni_str
, VNI_STR_LEN
, "%u", zevpn
->vni
);
256 json_evpn
= json_object_new_object();
257 json_object_int_add(json_evpn
, "vni", zevpn
->vni
);
258 json_object_string_add(json_evpn
, "type", "L2");
259 json_object_string_add(json_evpn
, "vxlanIf",
260 zevpn
->vxlan_if
? zevpn
->vxlan_if
->name
262 json_object_int_add(json_evpn
, "numMacs", num_macs
);
263 json_object_int_add(json_evpn
, "numArpNd", num_neigh
);
264 json_object_int_add(json_evpn
, "numRemoteVteps", num_vteps
);
265 json_object_string_add(json_evpn
, "tenantVrf",
266 vrf_id_to_name(zevpn
->vrf_id
));
268 json_vtep_list
= json_object_new_array();
269 for (zvtep
= zevpn
->vteps
; zvtep
; zvtep
= zvtep
->next
) {
270 json_ip_str
= json_object_new_string(
271 inet_ntop(AF_INET
, &zvtep
->vtep_ip
, buf
,
273 json_object_array_add(json_vtep_list
,
276 json_object_object_add(json_evpn
, "remoteVteps",
279 json_object_object_add(json
, vni_str
, json_evpn
);
284 * Print an EVPN hash entry in detail - called for display of all EVPNs.
286 void zebra_evpn_print_hash_detail(struct hash_bucket
*bucket
, void *data
)
289 struct zebra_evpn
*zevpn
;
290 json_object
*json_array
= NULL
;
291 bool use_json
= false;
292 struct zebra_evpn_show
*zes
= data
;
295 json_array
= zes
->json
;
296 use_json
= zes
->use_json
;
298 zevpn
= (struct zebra_evpn
*)bucket
->data
;
300 zebra_vxlan_print_vni(vty
, zes
->zvrf
, zevpn
->vni
, use_json
, json_array
);
306 int zebra_evpn_del_macip_for_intf(struct interface
*ifp
,
307 struct zebra_evpn
*zevpn
)
309 struct listnode
*cnode
= NULL
, *cnnode
= NULL
;
310 struct connected
*c
= NULL
;
311 struct ethaddr macaddr
;
313 memcpy(&macaddr
.octet
, ifp
->hw_addr
, ETH_ALEN
);
315 for (ALL_LIST_ELEMENTS(ifp
->connected
, cnode
, cnnode
, c
)) {
318 memset(&ip
, 0, sizeof(struct ipaddr
));
319 if (!CHECK_FLAG(c
->conf
, ZEBRA_IFC_REAL
))
322 if (c
->address
->family
== AF_INET
) {
323 ip
.ipa_type
= IPADDR_V4
;
324 memcpy(&(ip
.ipaddr_v4
), &(c
->address
->u
.prefix4
),
325 sizeof(struct in_addr
));
326 } else if (c
->address
->family
== AF_INET6
) {
327 ip
.ipa_type
= IPADDR_V6
;
328 memcpy(&(ip
.ipaddr_v6
), &(c
->address
->u
.prefix6
),
329 sizeof(struct in6_addr
));
334 zebra_evpn_gw_macip_del(ifp
, zevpn
, &ip
);
340 int zebra_evpn_add_macip_for_intf(struct interface
*ifp
,
341 struct zebra_evpn
*zevpn
)
343 struct listnode
*cnode
= NULL
, *cnnode
= NULL
;
344 struct connected
*c
= NULL
;
345 struct ethaddr macaddr
;
347 memcpy(&macaddr
.octet
, ifp
->hw_addr
, ETH_ALEN
);
349 for (ALL_LIST_ELEMENTS(ifp
->connected
, cnode
, cnnode
, c
)) {
352 if (!CHECK_FLAG(c
->conf
, ZEBRA_IFC_REAL
))
355 memset(&ip
, 0, sizeof(struct ipaddr
));
356 if (c
->address
->family
== AF_INET
) {
357 ip
.ipa_type
= IPADDR_V4
;
358 memcpy(&(ip
.ipaddr_v4
), &(c
->address
->u
.prefix4
),
359 sizeof(struct in_addr
));
360 } else if (c
->address
->family
== AF_INET6
) {
361 ip
.ipa_type
= IPADDR_V6
;
362 memcpy(&(ip
.ipaddr_v6
), &(c
->address
->u
.prefix6
),
363 sizeof(struct in6_addr
));
368 zebra_evpn_gw_macip_add(ifp
, zevpn
, &macaddr
, &ip
);
373 static int ip_prefix_send_to_client(vrf_id_t vrf_id
, struct prefix
*p
,
376 struct zserv
*client
= NULL
;
377 struct stream
*s
= NULL
;
379 client
= zserv_find_client(ZEBRA_ROUTE_BGP
, 0);
380 /* BGP may not be running. */
384 s
= stream_new(ZEBRA_MAX_PACKET_SIZ
);
386 zclient_create_header(s
, cmd
, vrf_id
);
387 stream_put(s
, p
, sizeof(struct prefix
));
389 /* Write packet size. */
390 stream_putw_at(s
, 0, stream_get_endp(s
));
392 if (IS_ZEBRA_DEBUG_VXLAN
)
393 zlog_debug("Send ip prefix %pFX %s on vrf %s", p
,
394 (cmd
== ZEBRA_IP_PREFIX_ROUTE_ADD
) ? "ADD" : "DEL",
395 vrf_id_to_name(vrf_id
));
397 if (cmd
== ZEBRA_IP_PREFIX_ROUTE_ADD
)
398 client
->prefixadd_cnt
++;
400 client
->prefixdel_cnt
++;
402 return zserv_send_message(client
, s
);
405 int zebra_evpn_advertise_subnet(struct zebra_evpn
*zevpn
, struct interface
*ifp
,
408 struct listnode
*cnode
= NULL
, *cnnode
= NULL
;
409 struct connected
*c
= NULL
;
410 struct ethaddr macaddr
;
412 memcpy(&macaddr
.octet
, ifp
->hw_addr
, ETH_ALEN
);
414 for (ALL_LIST_ELEMENTS(ifp
->connected
, cnode
, cnnode
, c
)) {
417 memcpy(&p
, c
->address
, sizeof(struct prefix
));
419 /* skip link local address */
420 if (IN6_IS_ADDR_LINKLOCAL(&p
.u
.prefix6
))
425 ip_prefix_send_to_client(ifp
->vrf
->vrf_id
, &p
,
426 ZEBRA_IP_PREFIX_ROUTE_ADD
);
428 ip_prefix_send_to_client(ifp
->vrf
->vrf_id
, &p
,
429 ZEBRA_IP_PREFIX_ROUTE_DEL
);
435 * zebra_evpn_gw_macip_add_to_client
437 int zebra_evpn_gw_macip_add(struct interface
*ifp
, struct zebra_evpn
*zevpn
,
438 struct ethaddr
*macaddr
, struct ipaddr
*ip
)
440 struct zebra_mac
*mac
= NULL
;
441 struct zebra_if
*zif
= NULL
;
442 struct zebra_l2info_vxlan
*vxl
= NULL
;
444 zif
= zevpn
->vxlan_if
->info
;
448 vxl
= &zif
->l2info
.vxl
;
450 zebra_evpn_mac_gw_macip_add(ifp
, zevpn
, ip
, &mac
, macaddr
,
451 vxl
->access_vlan
, true);
453 return zebra_evpn_neigh_gw_macip_add(ifp
, zevpn
, ip
, mac
);
457 * zebra_evpn_gw_macip_del_from_client
459 int zebra_evpn_gw_macip_del(struct interface
*ifp
, struct zebra_evpn
*zevpn
,
462 struct zebra_neigh
*n
= NULL
;
463 struct zebra_mac
*mac
= NULL
;
465 /* If the neigh entry is not present nothing to do*/
466 n
= zebra_evpn_neigh_lookup(zevpn
, ip
);
470 /* mac entry should be present */
471 mac
= zebra_evpn_mac_lookup(zevpn
, &n
->emac
);
473 if (IS_ZEBRA_DEBUG_VXLAN
)
474 zlog_debug("MAC %pEA doesn't exist for neigh %pIA on VNI %u",
475 &n
->emac
, ip
, zevpn
->vni
);
479 /* If the entry is not local nothing to do*/
480 if (!CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_LOCAL
))
483 /* only need to delete the entry from bgp if we sent it before */
484 if (IS_ZEBRA_DEBUG_VXLAN
)
486 "%u:SVI %s(%u) VNI %u, sending GW MAC %pEA IP %pIA del to BGP",
487 ifp
->vrf
->vrf_id
, ifp
->name
, ifp
->ifindex
, zevpn
->vni
,
490 /* Remove neighbor from BGP. */
491 zebra_evpn_neigh_send_del_to_client(zevpn
->vni
, &n
->ip
, &n
->emac
,
492 n
->flags
, ZEBRA_NEIGH_ACTIVE
,
495 /* Delete this neighbor entry. */
496 zebra_evpn_neigh_del(zevpn
, n
);
498 /* see if the mac needs to be deleted as well*/
500 zebra_evpn_deref_ip2mac(zevpn
, mac
);
505 void zebra_evpn_gw_macip_del_for_evpn_hash(struct hash_bucket
*bucket
,
508 struct zebra_evpn
*zevpn
= NULL
;
509 struct zebra_if
*zif
= NULL
;
510 struct zebra_l2info_vxlan zl2_info
;
511 struct interface
*vlan_if
= NULL
;
512 struct interface
*vrr_if
= NULL
;
513 struct interface
*ifp
;
515 /* Add primary SVI MAC*/
516 zevpn
= (struct zebra_evpn
*)bucket
->data
;
518 /* Global (Zvrf) advertise-default-gw is disabled,
519 * but zevpn advertise-default-gw is enabled
521 if (zevpn
->advertise_gw_macip
) {
522 if (IS_ZEBRA_DEBUG_VXLAN
)
523 zlog_debug("VNI: %u GW-MACIP enabled, retain gw-macip",
528 ifp
= zevpn
->vxlan_if
;
533 /* If down or not mapped to a bridge, we're done. */
534 if (!if_is_operative(ifp
) || !zif
->brslave_info
.br_if
)
537 zl2_info
= zif
->l2info
.vxl
;
540 zvni_map_to_svi(zl2_info
.access_vlan
, zif
->brslave_info
.br_if
);
544 /* Del primary MAC-IP */
545 zebra_evpn_del_macip_for_intf(vlan_if
, zevpn
);
547 /* Del VRR MAC-IP - if any*/
548 vrr_if
= zebra_get_vrr_intf_for_svi(vlan_if
);
550 zebra_evpn_del_macip_for_intf(vrr_if
, zevpn
);
555 void zebra_evpn_gw_macip_add_for_evpn_hash(struct hash_bucket
*bucket
,
558 struct zebra_evpn
*zevpn
= NULL
;
559 struct zebra_if
*zif
= NULL
;
560 struct zebra_l2info_vxlan zl2_info
;
561 struct interface
*vlan_if
= NULL
;
562 struct interface
*vrr_if
= NULL
;
563 struct interface
*ifp
= NULL
;
565 zevpn
= (struct zebra_evpn
*)bucket
->data
;
567 ifp
= zevpn
->vxlan_if
;
572 /* If down or not mapped to a bridge, we're done. */
573 if (!if_is_operative(ifp
) || !zif
->brslave_info
.br_if
)
575 zl2_info
= zif
->l2info
.vxl
;
578 zvni_map_to_svi(zl2_info
.access_vlan
, zif
->brslave_info
.br_if
);
582 /* Add primary SVI MAC-IP */
583 if (advertise_svi_macip_enabled(zevpn
)
584 || advertise_gw_macip_enabled(zevpn
))
585 zebra_evpn_add_macip_for_intf(vlan_if
, zevpn
);
587 if (advertise_gw_macip_enabled(zevpn
)) {
588 /* Add VRR MAC-IP - if any*/
589 vrr_if
= zebra_get_vrr_intf_for_svi(vlan_if
);
591 zebra_evpn_add_macip_for_intf(vrr_if
, zevpn
);
597 void zebra_evpn_svi_macip_del_for_evpn_hash(struct hash_bucket
*bucket
,
600 struct zebra_evpn
*zevpn
= NULL
;
601 struct zebra_if
*zif
= NULL
;
602 struct zebra_l2info_vxlan zl2_info
;
603 struct interface
*vlan_if
= NULL
;
604 struct interface
*ifp
;
606 /* Add primary SVI MAC*/
607 zevpn
= (struct zebra_evpn
*)bucket
->data
;
611 /* Global(vrf) advertise-svi-ip disabled, but zevpn advertise-svi-ip
614 if (zevpn
->advertise_svi_macip
) {
615 if (IS_ZEBRA_DEBUG_VXLAN
)
616 zlog_debug("VNI: %u SVI-MACIP enabled, retain svi-macip",
621 ifp
= zevpn
->vxlan_if
;
626 /* If down or not mapped to a bridge, we're done. */
627 if (!if_is_operative(ifp
) || !zif
->brslave_info
.br_if
)
630 zl2_info
= zif
->l2info
.vxl
;
633 zvni_map_to_svi(zl2_info
.access_vlan
, zif
->brslave_info
.br_if
);
637 /* Del primary MAC-IP */
638 zebra_evpn_del_macip_for_intf(vlan_if
, zevpn
);
643 static int zebra_evpn_map_vlan_ns(struct ns
*ns
,
647 struct zebra_ns
*zns
= ns
->info
;
648 struct route_node
*rn
;
649 struct interface
*br_if
;
650 struct zebra_evpn
**p_zevpn
= (struct zebra_evpn
**)_p_zevpn
;
651 struct zebra_evpn
*zevpn
;
652 struct interface
*tmp_if
= NULL
;
653 struct zebra_if
*zif
;
654 struct zebra_l2info_vxlan
*vxl
= NULL
;
655 struct zebra_from_svi_param
*in_param
=
656 (struct zebra_from_svi_param
*)_in_param
;
658 assert(p_zevpn
&& 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
) {
683 zevpn
= zebra_evpn_lookup(vxl
->vni
);
689 return NS_WALK_CONTINUE
;
693 * Map port or (port, VLAN) to an EVPN. This is invoked upon getting MAC
694 * notifications, to see if they are of interest.
696 struct zebra_evpn
*zebra_evpn_map_vlan(struct interface
*ifp
,
697 struct interface
*br_if
, vlanid_t vid
)
699 struct zebra_if
*zif
;
700 struct zebra_l2info_bridge
*br
;
701 struct zebra_evpn
**p_zevpn
;
702 struct zebra_evpn
*zevpn
= NULL
;
703 struct zebra_from_svi_param in_param
;
705 /* Determine if bridge is VLAN-aware or not */
708 br
= &zif
->l2info
.br
;
709 in_param
.bridge_vlan_aware
= br
->vlan_aware
;
711 in_param
.br_if
= br_if
;
715 ns_walk_func(zebra_evpn_map_vlan_ns
,
721 static int zebra_evpn_from_svi_ns(struct ns
*ns
,
725 struct zebra_ns
*zns
= ns
->info
;
726 struct route_node
*rn
;
727 struct interface
*br_if
;
728 struct zebra_evpn
**p_zevpn
= (struct zebra_evpn
**)_p_zevpn
;
729 struct zebra_evpn
*zevpn
;
730 struct interface
*tmp_if
= NULL
;
731 struct zebra_if
*zif
;
732 struct zebra_l2info_vxlan
*vxl
= NULL
;
733 struct zebra_from_svi_param
*in_param
=
734 (struct zebra_from_svi_param
*)_in_param
;
739 br_if
= in_param
->br_if
;
743 /* TODO: Optimize with a hash. */
744 for (rn
= route_top(zns
->if_table
); rn
; rn
= route_next(rn
)) {
745 tmp_if
= (struct interface
*)rn
->info
;
749 if (!zif
|| zif
->zif_type
!= ZEBRA_IF_VXLAN
)
751 if (!if_is_operative(tmp_if
))
753 vxl
= &zif
->l2info
.vxl
;
755 if (zif
->brslave_info
.br_if
!= br_if
)
758 if (!in_param
->bridge_vlan_aware
759 || vxl
->access_vlan
== in_param
->vid
) {
766 return NS_WALK_CONTINUE
;
768 zevpn
= zebra_evpn_lookup(vxl
->vni
);
775 * Map SVI and associated bridge to an EVPN. This is invoked upon getting
776 * neighbor notifications, to see if they are of interest.
778 struct zebra_evpn
*zebra_evpn_from_svi(struct interface
*ifp
,
779 struct interface
*br_if
)
781 struct zebra_l2info_bridge
*br
;
782 struct zebra_evpn
*zevpn
= NULL
;
783 struct zebra_evpn
**p_zevpn
;
784 struct zebra_if
*zif
;
785 struct zebra_from_svi_param in_param
;
790 /* Make sure the linked interface is a bridge. */
791 if (!IS_ZEBRA_IF_BRIDGE(br_if
))
794 /* Determine if bridge is VLAN-aware or not */
797 br
= &zif
->l2info
.br
;
798 in_param
.bridge_vlan_aware
= br
->vlan_aware
;
801 if (in_param
.bridge_vlan_aware
) {
802 struct zebra_l2info_vlan
*vl
;
804 if (!IS_ZEBRA_IF_VLAN(ifp
))
809 vl
= &zif
->l2info
.vl
;
810 in_param
.vid
= vl
->vid
;
813 in_param
.br_if
= br_if
;
816 /* See if this interface (or interface plus VLAN Id) maps to a VxLAN */
817 ns_walk_func(zebra_evpn_from_svi_ns
, (void *)&in_param
,
822 static int zvni_map_to_macvlan_ns(struct ns
*ns
,
826 struct zebra_ns
*zns
= ns
->info
;
827 struct zebra_from_svi_param
*in_param
=
828 (struct zebra_from_svi_param
*)_in_param
;
829 struct interface
**p_ifp
= (struct interface
**)_p_ifp
;
830 struct route_node
*rn
;
831 struct interface
*tmp_if
= NULL
;
832 struct zebra_if
*zif
;
834 assert(in_param
&& p_ifp
);
836 /* Identify corresponding VLAN interface. */
837 for (rn
= route_top(zns
->if_table
); rn
; rn
= route_next(rn
)) {
838 tmp_if
= (struct interface
*)rn
->info
;
839 /* Check oper status of the SVI. */
840 if (!tmp_if
|| !if_is_operative(tmp_if
))
844 if (!zif
|| zif
->zif_type
!= ZEBRA_IF_MACVLAN
)
847 if (zif
->link
== in_param
->svi_if
) {
853 return NS_WALK_CONTINUE
;
856 /* Map to MAC-VLAN interface corresponding to specified SVI interface.
858 struct interface
*zebra_evpn_map_to_macvlan(struct interface
*br_if
,
859 struct interface
*svi_if
)
861 struct interface
*tmp_if
= NULL
;
862 struct zebra_if
*zif
;
863 struct interface
**p_ifp
;
864 struct zebra_from_svi_param in_param
;
866 /* Defensive check, caller expected to invoke only with valid bridge. */
871 zlog_debug("svi_if is not passed.");
875 /* Determine if bridge is VLAN-aware or not */
880 in_param
.br_if
= br_if
;
882 in_param
.svi_if
= svi_if
;
885 /* Identify corresponding VLAN interface. */
886 ns_walk_func(zvni_map_to_macvlan_ns
,
893 * Install MAC hash entry - called upon access VLAN change.
895 void zebra_evpn_install_mac_hash(struct hash_bucket
*bucket
, void *ctxt
)
897 struct zebra_mac
*mac
;
898 struct mac_walk_ctx
*wctx
= ctxt
;
900 mac
= (struct zebra_mac
*)bucket
->data
;
902 if (CHECK_FLAG(mac
->flags
, ZEBRA_MAC_REMOTE
))
903 zebra_evpn_rem_mac_install(wctx
->zevpn
, mac
, false);
907 * Read and populate local MACs and neighbors corresponding to this EVPN.
909 void zebra_evpn_read_mac_neigh(struct zebra_evpn
*zevpn
, struct interface
*ifp
)
911 struct zebra_ns
*zns
;
912 struct zebra_vrf
*zvrf
;
913 struct zebra_if
*zif
;
914 struct interface
*vlan_if
;
915 struct zebra_l2info_vxlan
*vxl
;
916 struct interface
*vrr_if
;
919 vxl
= &zif
->l2info
.vxl
;
920 zvrf
= zebra_vrf_lookup_by_id(zevpn
->vrf_id
);
921 if (!zvrf
|| !zvrf
->zns
)
925 if (IS_ZEBRA_DEBUG_VXLAN
)
927 "Reading MAC FDB and Neighbors for intf %s(%u) VNI %u master %u",
928 ifp
->name
, ifp
->ifindex
, zevpn
->vni
,
929 zif
->brslave_info
.bridge_ifindex
);
931 macfdb_read_for_bridge(zns
, ifp
, zif
->brslave_info
.br_if
);
932 vlan_if
= zvni_map_to_svi(vxl
->access_vlan
, zif
->brslave_info
.br_if
);
935 zebra_evpn_acc_bd_svi_mac_add(vlan_if
);
938 if (advertise_svi_macip_enabled(zevpn
)
939 || advertise_gw_macip_enabled(zevpn
))
940 zebra_evpn_add_macip_for_intf(vlan_if
, zevpn
);
942 /* Add VRR MAC-IP - if any*/
943 if (advertise_gw_macip_enabled(zevpn
)) {
944 vrr_if
= zebra_get_vrr_intf_for_svi(vlan_if
);
946 zebra_evpn_add_macip_for_intf(vrr_if
, zevpn
);
949 neigh_read_for_vlan(zns
, vlan_if
);
954 * Hash function for EVPN.
956 unsigned int zebra_evpn_hash_keymake(const void *p
)
958 const struct zebra_evpn
*zevpn
= p
;
960 return (jhash_1word(zevpn
->vni
, 0));
964 * Compare 2 evpn hash entries.
966 bool zebra_evpn_hash_cmp(const void *p1
, const void *p2
)
968 const struct zebra_evpn
*zevpn1
= p1
;
969 const struct zebra_evpn
*zevpn2
= p2
;
971 return (zevpn1
->vni
== zevpn2
->vni
);
974 int zebra_evpn_list_cmp(void *p1
, void *p2
)
976 const struct zebra_evpn
*zevpn1
= p1
;
977 const struct zebra_evpn
*zevpn2
= p2
;
979 if (zevpn1
->vni
== zevpn2
->vni
)
981 return (zevpn1
->vni
< zevpn2
->vni
) ? -1 : 1;
985 * Callback to allocate VNI hash entry.
987 void *zebra_evpn_alloc(void *p
)
989 const struct zebra_evpn
*tmp_vni
= p
;
990 struct zebra_evpn
*zevpn
;
992 zevpn
= XCALLOC(MTYPE_ZEVPN
, sizeof(struct zebra_evpn
));
993 zevpn
->vni
= tmp_vni
->vni
;
994 return ((void *)zevpn
);
998 * Look up EVPN hash entry.
1000 struct zebra_evpn
*zebra_evpn_lookup(vni_t vni
)
1002 struct zebra_vrf
*zvrf
;
1003 struct zebra_evpn tmp_vni
;
1004 struct zebra_evpn
*zevpn
= NULL
;
1006 zvrf
= zebra_vrf_get_evpn();
1007 memset(&tmp_vni
, 0, sizeof(tmp_vni
));
1009 zevpn
= hash_lookup(zvrf
->evpn_table
, &tmp_vni
);
1015 * Add EVPN hash entry.
1017 struct zebra_evpn
*zebra_evpn_add(vni_t vni
)
1020 struct zebra_vrf
*zvrf
;
1021 struct zebra_evpn tmp_zevpn
;
1022 struct zebra_evpn
*zevpn
= NULL
;
1024 zvrf
= zebra_vrf_get_evpn();
1025 memset(&tmp_zevpn
, 0, sizeof(tmp_zevpn
));
1026 tmp_zevpn
.vni
= vni
;
1027 zevpn
= hash_get(zvrf
->evpn_table
, &tmp_zevpn
, zebra_evpn_alloc
);
1029 zebra_evpn_es_evi_init(zevpn
);
1031 snprintf(buffer
, sizeof(buffer
), "Zebra EVPN MAC Table vni: %u", vni
);
1032 /* Create hash table for MAC */
1033 zevpn
->mac_table
= zebra_mac_db_create(buffer
);
1035 snprintf(buffer
, sizeof(buffer
), "Zebra EVPN Neighbor Table vni: %u",
1037 /* Create hash table for neighbors */
1038 zevpn
->neigh_table
= zebra_neigh_db_create(buffer
);
1044 * Delete EVPN hash entry.
1046 int zebra_evpn_del(struct zebra_evpn
*zevpn
)
1048 struct zebra_vrf
*zvrf
;
1049 struct zebra_evpn
*tmp_zevpn
;
1051 zvrf
= zebra_vrf_get_evpn();
1053 zevpn
->svi_if
= NULL
;
1055 /* Free the neighbor hash table. */
1056 hash_free(zevpn
->neigh_table
);
1057 zevpn
->neigh_table
= NULL
;
1059 /* Free the MAC hash table. */
1060 hash_free(zevpn
->mac_table
);
1061 zevpn
->mac_table
= NULL
;
1063 /* Remove references to the zevpn in the MH databases */
1064 if (zevpn
->vxlan_if
)
1065 zebra_evpn_vxl_evpn_set(zevpn
->vxlan_if
->info
, zevpn
, false);
1066 zebra_evpn_es_evi_cleanup(zevpn
);
1068 /* Free the EVPN hash entry and allocated memory. */
1069 tmp_zevpn
= hash_release(zvrf
->evpn_table
, zevpn
);
1070 XFREE(MTYPE_ZEVPN
, tmp_zevpn
);
1076 * Inform BGP about local EVPN addition.
1078 int zebra_evpn_send_add_to_client(struct zebra_evpn
*zevpn
)
1080 struct zserv
*client
;
1082 ifindex_t svi_index
;
1085 client
= zserv_find_client(ZEBRA_ROUTE_BGP
, 0);
1086 /* BGP may not be running. */
1090 svi_index
= zevpn
->svi_if
? zevpn
->svi_if
->ifindex
: 0;
1092 s
= stream_new(ZEBRA_MAX_PACKET_SIZ
);
1094 zclient_create_header(s
, ZEBRA_VNI_ADD
, zebra_vrf_get_evpn_id());
1095 stream_putl(s
, zevpn
->vni
);
1096 stream_put_in_addr(s
, &zevpn
->local_vtep_ip
);
1097 stream_put(s
, &zevpn
->vrf_id
, sizeof(vrf_id_t
)); /* tenant vrf */
1098 stream_put_in_addr(s
, &zevpn
->mcast_grp
);
1099 stream_put(s
, &svi_index
, sizeof(ifindex_t
));
1101 /* Write packet size. */
1102 stream_putw_at(s
, 0, stream_get_endp(s
));
1104 if (IS_ZEBRA_DEBUG_VXLAN
)
1106 "Send EVPN_ADD %u %pI4 tenant vrf %s(%u) SVI index %u to %s",
1107 zevpn
->vni
, &zevpn
->local_vtep_ip
,
1108 vrf_id_to_name(zevpn
->vrf_id
), zevpn
->vrf_id
,
1109 (zevpn
->svi_if
? zevpn
->svi_if
->ifindex
: 0),
1110 zebra_route_string(client
->proto
));
1112 client
->vniadd_cnt
++;
1113 rc
= zserv_send_message(client
, s
);
1115 if (!(zevpn
->flags
& ZEVPN_READY_FOR_BGP
)) {
1116 zevpn
->flags
|= ZEVPN_READY_FOR_BGP
;
1117 /* once the EVPN is sent the ES-EVIs can also be replayed
1120 zebra_evpn_update_all_es(zevpn
);
1126 * Inform BGP about local EVPN deletion.
1128 int zebra_evpn_send_del_to_client(struct zebra_evpn
*zevpn
)
1130 struct zserv
*client
;
1133 client
= zserv_find_client(ZEBRA_ROUTE_BGP
, 0);
1134 /* BGP may not be running. */
1138 if (zevpn
->flags
& ZEVPN_READY_FOR_BGP
) {
1139 zevpn
->flags
&= ~ZEVPN_READY_FOR_BGP
;
1140 /* the ES-EVIs must be removed from BGP before the EVPN is */
1141 zebra_evpn_update_all_es(zevpn
);
1144 s
= stream_new(ZEBRA_MAX_PACKET_SIZ
);
1147 zclient_create_header(s
, ZEBRA_VNI_DEL
, zebra_vrf_get_evpn_id());
1148 stream_putl(s
, zevpn
->vni
);
1150 /* Write packet size. */
1151 stream_putw_at(s
, 0, stream_get_endp(s
));
1153 if (IS_ZEBRA_DEBUG_VXLAN
)
1154 zlog_debug("Send EVPN_DEL %u to %s", zevpn
->vni
,
1155 zebra_route_string(client
->proto
));
1157 client
->vnidel_cnt
++;
1158 return zserv_send_message(client
, s
);
1162 * See if remote VTEP matches with prefix.
1164 static int zebra_evpn_vtep_match(struct in_addr
*vtep_ip
,
1165 struct zebra_vtep
*zvtep
)
1167 return (IPV4_ADDR_SAME(vtep_ip
, &zvtep
->vtep_ip
));
1171 * Locate remote VTEP in EVPN hash table.
1173 struct zebra_vtep
*zebra_evpn_vtep_find(struct zebra_evpn
*zevpn
,
1174 struct in_addr
*vtep_ip
)
1176 struct zebra_vtep
*zvtep
;
1181 for (zvtep
= zevpn
->vteps
; zvtep
; zvtep
= zvtep
->next
) {
1182 if (zebra_evpn_vtep_match(vtep_ip
, zvtep
))
1190 * Add remote VTEP to EVPN hash table.
1192 struct zebra_vtep
*zebra_evpn_vtep_add(struct zebra_evpn
*zevpn
,
1193 struct in_addr
*vtep_ip
,
1197 struct zebra_vtep
*zvtep
;
1199 zvtep
= XCALLOC(MTYPE_ZEVPN_VTEP
, sizeof(struct zebra_vtep
));
1201 zvtep
->vtep_ip
= *vtep_ip
;
1202 zvtep
->flood_control
= flood_control
;
1205 zevpn
->vteps
->prev
= zvtep
;
1206 zvtep
->next
= zevpn
->vteps
;
1207 zevpn
->vteps
= zvtep
;
1213 * Remove remote VTEP from EVPN hash table.
1215 int zebra_evpn_vtep_del(struct zebra_evpn
*zevpn
, struct zebra_vtep
*zvtep
)
1218 zvtep
->next
->prev
= zvtep
->prev
;
1220 zvtep
->prev
->next
= zvtep
->next
;
1222 zevpn
->vteps
= zvtep
->next
;
1224 zvtep
->prev
= zvtep
->next
= NULL
;
1225 XFREE(MTYPE_ZEVPN_VTEP
, zvtep
);
1231 * Delete all remote VTEPs for this EVPN (upon VNI delete). Also
1232 * uninstall from kernel if asked to.
1234 int zebra_evpn_vtep_del_all(struct zebra_evpn
*zevpn
, int uninstall
)
1236 struct zebra_vtep
*zvtep
, *zvtep_next
;
1241 for (zvtep
= zevpn
->vteps
; zvtep
; zvtep
= zvtep_next
) {
1242 zvtep_next
= zvtep
->next
;
1244 zebra_evpn_vtep_uninstall(zevpn
, &zvtep
->vtep_ip
);
1245 zebra_evpn_vtep_del(zevpn
, zvtep
);
1252 * Install remote VTEP into the kernel if the remote VTEP has asked
1253 * for head-end-replication.
1255 int zebra_evpn_vtep_install(struct zebra_evpn
*zevpn
, struct zebra_vtep
*zvtep
)
1257 if (is_vxlan_flooding_head_end() &&
1258 (zvtep
->flood_control
== VXLAN_FLOOD_HEAD_END_REPL
)) {
1259 if (ZEBRA_DPLANE_REQUEST_FAILURE
==
1260 dplane_vtep_add(zevpn
->vxlan_if
,
1261 &zvtep
->vtep_ip
, zevpn
->vni
))
1269 * Uninstall remote VTEP from the kernel.
1271 int zebra_evpn_vtep_uninstall(struct zebra_evpn
*zevpn
, struct in_addr
*vtep_ip
)
1273 if (!zevpn
->vxlan_if
) {
1274 zlog_debug("VNI %u hash %p couldn't be uninstalled - no intf",
1279 if (ZEBRA_DPLANE_REQUEST_FAILURE
==
1280 dplane_vtep_delete(zevpn
->vxlan_if
, vtep_ip
, zevpn
->vni
))
1287 * Install or uninstall flood entries in the kernel corresponding to
1288 * remote VTEPs. This is invoked upon change to BUM handling.
1290 void zebra_evpn_handle_flooding_remote_vteps(struct hash_bucket
*bucket
,
1293 struct zebra_evpn
*zevpn
;
1294 struct zebra_vtep
*zvtep
;
1296 zevpn
= (struct zebra_evpn
*)bucket
->data
;
1300 for (zvtep
= zevpn
->vteps
; zvtep
; zvtep
= zvtep
->next
) {
1301 if (is_vxlan_flooding_head_end())
1302 zebra_evpn_vtep_install(zevpn
, zvtep
);
1304 zebra_evpn_vtep_uninstall(zevpn
, &zvtep
->vtep_ip
);
1309 * Cleanup EVPN/VTEP and update kernel
1311 void zebra_evpn_cleanup_all(struct hash_bucket
*bucket
, void *arg
)
1313 struct zebra_evpn
*zevpn
= NULL
;
1315 zevpn
= (struct zebra_evpn
*)bucket
->data
;
1317 /* Free up all neighbors and MACs, if any. */
1318 zebra_evpn_neigh_del_all(zevpn
, 1, 0, DEL_ALL_NEIGH
);
1319 zebra_evpn_mac_del_all(zevpn
, 1, 0, DEL_ALL_MAC
);
1321 /* Free up all remote VTEPs, if any. */
1322 zebra_evpn_vtep_del_all(zevpn
, 1);
1324 /* Delete the hash entry. */
1325 zebra_evpn_del(zevpn
);
1328 static void zebra_evpn_process_sync_macip_add(struct zebra_evpn
*zevpn
,
1329 const struct ethaddr
*macaddr
,
1331 const struct ipaddr
*ipaddr
,
1332 uint8_t flags
, uint32_t seq
,
1335 char ipbuf
[INET6_ADDRSTRLEN
];
1338 struct zebra_neigh
*n
= NULL
;
1339 struct zebra_mac
*mac
= NULL
;
1341 sticky
= !!CHECK_FLAG(flags
, ZEBRA_MACIP_TYPE_STICKY
);
1342 remote_gw
= !!CHECK_FLAG(flags
, ZEBRA_MACIP_TYPE_GW
);
1343 /* if sticky or remote-gw ignore updates from the peer */
1344 if (sticky
|| remote_gw
) {
1345 if (IS_ZEBRA_DEBUG_VXLAN
|| IS_ZEBRA_DEBUG_EVPN_MH_NEIGH
1346 || IS_ZEBRA_DEBUG_EVPN_MH_MAC
)
1348 "Ignore sync-macip vni %u mac %pEA%s%s%s%s",
1351 ipa_len
? " IP " : "",
1352 ipa_len
? ipaddr2str(ipaddr
, ipbuf
,
1355 sticky
? " sticky" : "",
1356 remote_gw
? " remote_gw" : "");
1362 (void)zebra_evpn_proc_sync_mac_update(zevpn
, macaddr
, ipa_len
,
1363 ipaddr
, flags
, seq
, esi
);
1366 mac
= zebra_evpn_mac_lookup(zevpn
, macaddr
);
1368 mac
= zebra_evpn_proc_sync_mac_update(zevpn
, macaddr
,
1375 n
= zebra_evpn_neigh_lookup(zevpn
, ipaddr
);
1377 && !zebra_evpn_neigh_is_bgp_seq_ok(zevpn
, n
, macaddr
, seq
,
1381 zebra_evpn_proc_sync_neigh_update(zevpn
, n
, ipa_len
, ipaddr
,
1382 flags
, seq
, esi
, mac
);
1386 /************************** remote mac-ip handling **************************/
1387 /* Process a remote MACIP add from BGP. */
1388 void zebra_evpn_rem_macip_add(vni_t vni
, const struct ethaddr
*macaddr
,
1389 uint16_t ipa_len
, const struct ipaddr
*ipaddr
,
1390 uint8_t flags
, uint32_t seq
,
1391 struct in_addr vtep_ip
, const esi_t
*esi
)
1393 struct zebra_evpn
*zevpn
;
1394 struct zebra_vtep
*zvtep
;
1395 struct zebra_mac
*mac
= NULL
;
1396 struct interface
*ifp
= NULL
;
1397 struct zebra_if
*zif
= NULL
;
1398 struct zebra_vrf
*zvrf
;
1400 /* Locate EVPN hash entry - expected to exist. */
1401 zevpn
= zebra_evpn_lookup(vni
);
1403 if (IS_ZEBRA_DEBUG_VXLAN
)
1404 zlog_debug("Unknown VNI %u upon remote MACIP ADD", vni
);
1408 ifp
= zevpn
->vxlan_if
;
1411 if (!ifp
|| !if_is_operative(ifp
) || !zif
|| !zif
->brslave_info
.br_if
) {
1412 if (IS_ZEBRA_DEBUG_VXLAN
)
1414 "Ignoring remote MACIP ADD VNI %u, invalid interface state or info",
1419 /* Type-2 routes from another PE can be interpreted as remote or
1420 * SYNC based on the destination ES -
1421 * SYNC - if ES is local
1422 * REMOTE - if ES is not local
1424 if (flags
& ZEBRA_MACIP_TYPE_SYNC_PATH
) {
1425 struct zebra_evpn_es
*es
;
1427 es
= zebra_evpn_es_find(esi
);
1428 if (es
&& (es
->flags
& ZEBRA_EVPNES_READY_FOR_BGP
)) {
1429 zebra_evpn_process_sync_macip_add(zevpn
, macaddr
,
1433 if (IS_ZEBRA_DEBUG_EVPN_MH_ES
) {
1434 char esi_str
[ESI_STR_LEN
];
1436 esi_to_str(esi
, esi_str
, sizeof(esi_str
));
1438 "Ignore sync-macip add; ES %s is not ready",
1446 /* The remote VTEP specified should normally exist, but it is
1447 * possible that when peering comes up, peer may advertise MACIP
1448 * routes before advertising type-3 routes.
1450 if (vtep_ip
.s_addr
) {
1451 zvtep
= zebra_evpn_vtep_find(zevpn
, &vtep_ip
);
1453 zvtep
= zebra_evpn_vtep_add(zevpn
, &vtep_ip
,
1454 VXLAN_FLOOD_DISABLED
);
1457 EC_ZEBRA_VTEP_ADD_FAILED
,
1458 "Failed to add remote VTEP, VNI %u zevpn %p upon remote MACIP ADD",
1463 zebra_evpn_vtep_install(zevpn
, zvtep
);
1467 zvrf
= zebra_vrf_get_evpn();
1473 zebra_evpn_mac_remote_macip_add(zevpn
, zvrf
, macaddr
, vtep_ip
,
1477 * Add auto MAC if it doesn't exist.
1479 mac
= zebra_evpn_mac_lookup(zevpn
, macaddr
);
1481 mac
= zebra_evpn_mac_add_auto(zevpn
, macaddr
);
1483 if (IS_ZEBRA_DEBUG_VXLAN
)
1485 "Neigh %pIA: MAC %pEA not found, Auto MAC created",
1489 zebra_evpn_neigh_remote_macip_add(zevpn
, zvrf
, ipaddr
, mac
,
1490 vtep_ip
, flags
, seq
);
1494 /* Process a remote MACIP delete from BGP. */
1495 void zebra_evpn_rem_macip_del(vni_t vni
, const struct ethaddr
*macaddr
,
1496 uint16_t ipa_len
, const struct ipaddr
*ipaddr
,
1497 struct in_addr vtep_ip
)
1499 struct zebra_evpn
*zevpn
;
1500 struct zebra_mac
*mac
= NULL
;
1501 struct zebra_neigh
*n
= NULL
;
1502 struct interface
*ifp
= NULL
;
1503 struct zebra_if
*zif
= NULL
;
1504 struct zebra_ns
*zns
;
1505 struct zebra_l2info_vxlan
*vxl
;
1506 struct zebra_vrf
*zvrf
;
1507 char buf1
[INET6_ADDRSTRLEN
];
1509 /* Locate EVPN hash entry - expected to exist. */
1510 zevpn
= zebra_evpn_lookup(vni
);
1512 if (IS_ZEBRA_DEBUG_VXLAN
)
1513 zlog_debug("Unknown VNI %u upon remote MACIP DEL", vni
);
1517 ifp
= zevpn
->vxlan_if
;
1520 if (!ifp
|| !if_is_operative(ifp
) || !zif
|| !zif
->brslave_info
.br_if
) {
1521 if (IS_ZEBRA_DEBUG_VXLAN
)
1523 "Ignoring remote MACIP DEL VNI %u, invalid interface state or info",
1527 zns
= zebra_ns_lookup(NS_DEFAULT
);
1528 vxl
= &zif
->l2info
.vxl
;
1530 mac
= zebra_evpn_mac_lookup(zevpn
, macaddr
);
1532 n
= zebra_evpn_neigh_lookup(zevpn
, ipaddr
);
1536 "Failed to locate MAC %pEA for Neigh %pIA VNI %u upon remote MACIP DEL",
1537 macaddr
, ipaddr
, vni
);
1541 /* If the remote mac or neighbor doesn't exist there is nothing
1542 * more to do. Otherwise, uninstall the entry and then remove it.
1545 if (IS_ZEBRA_DEBUG_VXLAN
)
1547 "Failed to locate MAC %pEA & Neigh %pIA VNI %u upon remote MACIP DEL",
1548 macaddr
, ipaddr
, vni
);
1552 zvrf
= zevpn
->vxlan_if
->vrf
->info
;
1554 /* Ignore the delete if this mac is a gateway mac-ip */
1555 if (CHECK_FLAG(mac
->flags
, ZEBRA_MAC_LOCAL
)
1556 && CHECK_FLAG(mac
->flags
, ZEBRA_MAC_DEF_GW
)) {
1558 "Ignore remote MACIP DEL VNI %u MAC %pEA%s%s as MAC is already configured as gateway MAC",
1560 ipa_len
? " IP " : "",
1561 ipa_len
? ipaddr2str(ipaddr
, buf1
, sizeof(buf1
)) : "");
1565 /* Uninstall remote neighbor or MAC. */
1567 zebra_evpn_neigh_remote_uninstall(zevpn
, zvrf
, n
, mac
, ipaddr
);
1569 /* DAD: when MAC is freeze state as remote learn event,
1570 * remote mac-ip delete event is received will result in freeze
1571 * entry removal, first fetch kernel for the same entry present
1572 * as LOCAL and reachable, avoid deleting this entry instead
1573 * use kerenel local entry to update during unfreeze time.
1575 if (zvrf
->dad_freeze
1576 && CHECK_FLAG(mac
->flags
, ZEBRA_MAC_DUPLICATE
)
1577 && CHECK_FLAG(mac
->flags
, ZEBRA_MAC_REMOTE
)) {
1578 if (IS_ZEBRA_DEBUG_VXLAN
)
1580 "%s: MAC %pEA (flags 0x%x) is remote and duplicate, read kernel for local entry",
1581 __func__
, macaddr
, mac
->flags
);
1582 macfdb_read_specific_mac(zns
, zif
->brslave_info
.br_if
,
1583 macaddr
, vxl
->access_vlan
);
1586 if (CHECK_FLAG(mac
->flags
, ZEBRA_MAC_LOCAL
)) {
1588 zebra_evpn_sync_mac_del(mac
);
1589 } else if (CHECK_FLAG(mac
->flags
, ZEBRA_NEIGH_REMOTE
)) {
1590 zebra_evpn_rem_mac_del(zevpn
, mac
);
1595 /************************** EVPN BGP config management ************************/
1596 void zebra_evpn_cfg_cleanup(struct hash_bucket
*bucket
, void *ctxt
)
1598 struct zebra_evpn
*zevpn
= NULL
;
1600 zevpn
= (struct zebra_evpn
*)bucket
->data
;
1601 zevpn
->advertise_gw_macip
= 0;
1602 zevpn
->advertise_svi_macip
= 0;
1603 zevpn
->advertise_subnet
= 0;
1605 zebra_evpn_neigh_del_all(zevpn
, 1, 0,
1606 DEL_REMOTE_NEIGH
| DEL_REMOTE_NEIGH_FROM_VTEP
);
1607 zebra_evpn_mac_del_all(zevpn
, 1, 0,
1608 DEL_REMOTE_MAC
| DEL_REMOTE_MAC_FROM_VTEP
);
1609 zebra_evpn_vtep_del_all(zevpn
, 1);