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
->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
->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 vty
*vty
= NULL
;
106 struct zebra_vtep
*zvtep
= NULL
;
107 uint32_t num_macs
= 0;
108 uint32_t num_neigh
= 0;
109 uint32_t num_vteps
= 0;
110 json_object
*json
= NULL
;
111 json_object
*json_vtep_list
= NULL
;
112 json_object
*json_vtep
= NULL
;
118 vty_out(vty
, "VNI: %u\n", zevpn
->vni
);
119 vty_out(vty
, " Type: %s\n", "L2");
120 vty_out(vty
, " Tenant VRF: %s\n", vrf_id_to_name(zevpn
->vrf_id
));
122 json_object_int_add(json
, "vni", zevpn
->vni
);
123 json_object_string_add(json
, "type", "L2");
124 #if CONFDATE > 20240210
125 CPP_NOTICE("Drop `vrf` from JSON output")
127 json_object_string_add(json
, "vrf",
128 vrf_id_to_name(zevpn
->vrf_id
));
129 json_object_string_add(json
, "tenantVrf",
130 vrf_id_to_name(zevpn
->vrf_id
));
133 if (!zevpn
->vxlan_if
) { // unexpected
135 vty_out(vty
, " VxLAN interface: unknown\n");
137 json_object_string_add(json
, "vxlanInterface",
141 num_macs
= num_valid_macs(zevpn
);
142 num_neigh
= hashcount(zevpn
->neigh_table
);
144 vty_out(vty
, " VxLAN interface: %s\n", zevpn
->vxlan_if
->name
);
145 vty_out(vty
, " VxLAN ifIndex: %u\n", zevpn
->vxlan_if
->ifindex
);
146 vty_out(vty
, " SVI interface: %s\n",
147 (zevpn
->svi_if
? zevpn
->svi_if
->name
: ""));
148 vty_out(vty
, " SVI ifIndex: %u\n",
149 (zevpn
->svi_if
? zevpn
->svi_if
->ifindex
: 0));
150 vty_out(vty
, " Local VTEP IP: %pI4\n",
151 &zevpn
->local_vtep_ip
);
152 vty_out(vty
, " Mcast group: %pI4\n",
155 json_object_string_add(json
, "vxlanInterface",
156 zevpn
->vxlan_if
->name
);
157 #if CONFDATE > 20240210
158 CPP_NOTICE("Drop `ifindex` from JSON output")
160 json_object_int_add(json
, "ifindex", zevpn
->vxlan_if
->ifindex
);
161 json_object_int_add(json
, "vxlanIfindex",
162 zevpn
->vxlan_if
->ifindex
);
164 json_object_string_add(json
, "sviInterface",
165 zevpn
->svi_if
->name
);
166 json_object_int_add(json
, "sviIfindex",
167 zevpn
->svi_if
->ifindex
);
169 json_object_string_addf(json
, "vtepIp", "%pI4",
170 &zevpn
->local_vtep_ip
);
171 json_object_string_addf(json
, "mcastGroup", "%pI4",
173 json_object_string_add(json
, "advertiseGatewayMacip",
174 zevpn
->advertise_gw_macip
? "Yes"
176 json_object_string_add(json
, "advertiseSviMacip",
177 zevpn
->advertise_svi_macip
? "Yes"
179 json_object_int_add(json
, "numMacs", num_macs
);
180 json_object_int_add(json
, "numArpNd", num_neigh
);
184 vty_out(vty
, " No remote VTEPs known for this VNI\n");
186 json_object_int_add(json
, "numRemoteVteps", num_vteps
);
189 vty_out(vty
, " Remote VTEPs for this VNI:\n");
191 json_vtep_list
= json_object_new_array();
192 for (zvtep
= zevpn
->vteps
; zvtep
; zvtep
= zvtep
->next
) {
193 const char *flood_str
= lookup_msg(
194 zvtep_flood_str
, zvtep
->flood_control
,
195 VXLAN_FLOOD_STR_DEFAULT
);
198 vty_out(vty
, " %pI4 flood: %s\n",
202 json_vtep
= json_object_new_object();
203 json_object_string_addf(json_vtep
, "ip", "%pI4",
205 json_object_string_add(json_vtep
, "flood",
207 json_object_array_add(json_vtep_list
,
213 json_object_int_add(json
, "numRemoteVteps", num_vteps
);
214 json_object_object_add(json
, "remoteVteps",
220 " Number of MACs (local and remote) known for this VNI: %u\n",
223 " Number of ARPs (IPv4 and IPv6, local and remote) "
224 "known for this VNI: %u\n",
226 vty_out(vty
, " Advertise-gw-macip: %s\n",
227 zevpn
->advertise_gw_macip
? "Yes" : "No");
228 vty_out(vty
, " Advertise-svi-macip: %s\n",
229 zevpn
->advertise_svi_macip
? "Yes" : "No");
234 * Print an EVPN hash entry - called for display of all VNIs.
236 void zebra_evpn_print_hash(struct hash_bucket
*bucket
, void *ctxt
[])
239 struct zebra_evpn
*zevpn
;
240 struct zebra_vtep
*zvtep
;
241 uint32_t num_vteps
= 0;
242 uint32_t num_macs
= 0;
243 uint32_t num_neigh
= 0;
244 json_object
*json
= NULL
;
245 json_object
*json_evpn
= NULL
;
246 json_object
*json_ip_str
= NULL
;
247 json_object
*json_vtep_list
= NULL
;
248 char buf
[PREFIX_STRLEN
];
253 zevpn
= (struct zebra_evpn
*)bucket
->data
;
255 zvtep
= zevpn
->vteps
;
261 num_macs
= num_valid_macs(zevpn
);
262 num_neigh
= hashcount(zevpn
->neigh_table
);
264 vty_out(vty
, "%-10u %-4s %-21s %-8u %-8u %-15u %-37s\n",
266 zevpn
->vxlan_if
? zevpn
->vxlan_if
->name
: "unknown",
267 num_macs
, num_neigh
, num_vteps
,
268 vrf_id_to_name(zevpn
->vrf_id
));
270 char vni_str
[VNI_STR_LEN
];
271 snprintf(vni_str
, VNI_STR_LEN
, "%u", zevpn
->vni
);
272 json_evpn
= json_object_new_object();
273 json_object_int_add(json_evpn
, "vni", zevpn
->vni
);
274 json_object_string_add(json_evpn
, "type", "L2");
275 json_object_string_add(json_evpn
, "vxlanIf",
276 zevpn
->vxlan_if
? zevpn
->vxlan_if
->name
278 json_object_int_add(json_evpn
, "numMacs", num_macs
);
279 json_object_int_add(json_evpn
, "numArpNd", num_neigh
);
280 json_object_int_add(json_evpn
, "numRemoteVteps", num_vteps
);
281 json_object_string_add(json_evpn
, "tenantVrf",
282 vrf_id_to_name(zevpn
->vrf_id
));
284 json_vtep_list
= json_object_new_array();
285 for (zvtep
= zevpn
->vteps
; zvtep
; zvtep
= zvtep
->next
) {
286 json_ip_str
= json_object_new_string(
287 inet_ntop(AF_INET
, &zvtep
->vtep_ip
, buf
,
289 json_object_array_add(json_vtep_list
,
292 json_object_object_add(json_evpn
, "remoteVteps",
295 json_object_object_add(json
, vni_str
, json_evpn
);
300 * Print an EVPN hash entry in detail - called for display of all EVPNs.
302 void zebra_evpn_print_hash_detail(struct hash_bucket
*bucket
, void *data
)
305 struct zebra_evpn
*zevpn
;
306 json_object
*json_array
= NULL
;
307 bool use_json
= false;
308 struct zebra_evpn_show
*zes
= data
;
311 json_array
= zes
->json
;
312 use_json
= zes
->use_json
;
314 zevpn
= (struct zebra_evpn
*)bucket
->data
;
316 zebra_vxlan_print_vni(vty
, zes
->zvrf
, zevpn
->vni
, use_json
, json_array
);
322 int zebra_evpn_del_macip_for_intf(struct interface
*ifp
,
323 struct zebra_evpn
*zevpn
)
325 struct listnode
*cnode
= NULL
, *cnnode
= NULL
;
326 struct connected
*c
= NULL
;
327 struct ethaddr macaddr
;
329 memcpy(&macaddr
.octet
, ifp
->hw_addr
, ETH_ALEN
);
331 for (ALL_LIST_ELEMENTS(ifp
->connected
, cnode
, cnnode
, c
)) {
334 memset(&ip
, 0, sizeof(struct ipaddr
));
335 if (!CHECK_FLAG(c
->conf
, ZEBRA_IFC_REAL
))
338 if (c
->address
->family
== AF_INET
) {
339 ip
.ipa_type
= IPADDR_V4
;
340 memcpy(&(ip
.ipaddr_v4
), &(c
->address
->u
.prefix4
),
341 sizeof(struct in_addr
));
342 } else if (c
->address
->family
== AF_INET6
) {
343 ip
.ipa_type
= IPADDR_V6
;
344 memcpy(&(ip
.ipaddr_v6
), &(c
->address
->u
.prefix6
),
345 sizeof(struct in6_addr
));
350 zebra_evpn_gw_macip_del(ifp
, zevpn
, &ip
);
356 int zebra_evpn_add_macip_for_intf(struct interface
*ifp
,
357 struct zebra_evpn
*zevpn
)
359 struct listnode
*cnode
= NULL
, *cnnode
= NULL
;
360 struct connected
*c
= NULL
;
361 struct ethaddr macaddr
;
363 memcpy(&macaddr
.octet
, ifp
->hw_addr
, ETH_ALEN
);
365 for (ALL_LIST_ELEMENTS(ifp
->connected
, cnode
, cnnode
, c
)) {
368 if (!CHECK_FLAG(c
->conf
, ZEBRA_IFC_REAL
))
371 memset(&ip
, 0, sizeof(struct ipaddr
));
372 if (c
->address
->family
== AF_INET
) {
373 ip
.ipa_type
= IPADDR_V4
;
374 memcpy(&(ip
.ipaddr_v4
), &(c
->address
->u
.prefix4
),
375 sizeof(struct in_addr
));
376 } else if (c
->address
->family
== AF_INET6
) {
377 ip
.ipa_type
= IPADDR_V6
;
378 memcpy(&(ip
.ipaddr_v6
), &(c
->address
->u
.prefix6
),
379 sizeof(struct in6_addr
));
384 zebra_evpn_gw_macip_add(ifp
, zevpn
, &macaddr
, &ip
);
389 static int ip_prefix_send_to_client(vrf_id_t vrf_id
, struct prefix
*p
,
392 struct zserv
*client
= NULL
;
393 struct stream
*s
= NULL
;
395 client
= zserv_find_client(ZEBRA_ROUTE_BGP
, 0);
396 /* BGP may not be running. */
400 s
= stream_new(ZEBRA_MAX_PACKET_SIZ
);
402 zclient_create_header(s
, cmd
, vrf_id
);
403 stream_put(s
, p
, sizeof(struct prefix
));
405 /* Write packet size. */
406 stream_putw_at(s
, 0, stream_get_endp(s
));
408 if (IS_ZEBRA_DEBUG_VXLAN
)
409 zlog_debug("Send ip prefix %pFX %s on vrf %s", p
,
410 (cmd
== ZEBRA_IP_PREFIX_ROUTE_ADD
) ? "ADD" : "DEL",
411 vrf_id_to_name(vrf_id
));
413 if (cmd
== ZEBRA_IP_PREFIX_ROUTE_ADD
)
414 client
->prefixadd_cnt
++;
416 client
->prefixdel_cnt
++;
418 return zserv_send_message(client
, s
);
421 int zebra_evpn_advertise_subnet(struct zebra_evpn
*zevpn
, struct interface
*ifp
,
424 struct listnode
*cnode
= NULL
, *cnnode
= NULL
;
425 struct connected
*c
= NULL
;
426 struct ethaddr macaddr
;
428 memcpy(&macaddr
.octet
, ifp
->hw_addr
, ETH_ALEN
);
430 for (ALL_LIST_ELEMENTS(ifp
->connected
, cnode
, cnnode
, c
)) {
433 memcpy(&p
, c
->address
, sizeof(struct prefix
));
435 /* skip link local address */
436 if (IN6_IS_ADDR_LINKLOCAL(&p
.u
.prefix6
))
441 ip_prefix_send_to_client(ifp
->vrf
->vrf_id
, &p
,
442 ZEBRA_IP_PREFIX_ROUTE_ADD
);
444 ip_prefix_send_to_client(ifp
->vrf
->vrf_id
, &p
,
445 ZEBRA_IP_PREFIX_ROUTE_DEL
);
451 * zebra_evpn_gw_macip_add_to_client
453 int zebra_evpn_gw_macip_add(struct interface
*ifp
, struct zebra_evpn
*zevpn
,
454 struct ethaddr
*macaddr
, struct ipaddr
*ip
)
456 struct zebra_mac
*mac
= NULL
;
457 struct zebra_if
*zif
= NULL
;
458 struct zebra_l2info_vxlan
*vxl
= NULL
;
460 zif
= zevpn
->vxlan_if
->info
;
464 vxl
= &zif
->l2info
.vxl
;
466 zebra_evpn_mac_gw_macip_add(ifp
, zevpn
, ip
, &mac
, macaddr
,
467 vxl
->access_vlan
, true);
469 return zebra_evpn_neigh_gw_macip_add(ifp
, zevpn
, ip
, mac
);
473 * zebra_evpn_gw_macip_del_from_client
475 int zebra_evpn_gw_macip_del(struct interface
*ifp
, struct zebra_evpn
*zevpn
,
478 struct zebra_neigh
*n
= NULL
;
479 struct zebra_mac
*mac
= NULL
;
481 /* If the neigh entry is not present nothing to do*/
482 n
= zebra_evpn_neigh_lookup(zevpn
, ip
);
486 /* mac entry should be present */
487 mac
= zebra_evpn_mac_lookup(zevpn
, &n
->emac
);
489 if (IS_ZEBRA_DEBUG_VXLAN
)
490 zlog_debug("MAC %pEA doesn't exist for neigh %pIA on VNI %u",
491 &n
->emac
, ip
, zevpn
->vni
);
495 /* If the entry is not local nothing to do*/
496 if (!CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_LOCAL
))
499 /* only need to delete the entry from bgp if we sent it before */
500 if (IS_ZEBRA_DEBUG_VXLAN
)
502 "%u:SVI %s(%u) VNI %u, sending GW MAC %pEA IP %pIA del to BGP",
503 ifp
->vrf
->vrf_id
, ifp
->name
, ifp
->ifindex
, zevpn
->vni
,
506 /* Remove neighbor from BGP. */
507 zebra_evpn_neigh_send_del_to_client(zevpn
->vni
, &n
->ip
, &n
->emac
,
508 n
->flags
, ZEBRA_NEIGH_ACTIVE
,
511 /* Delete this neighbor entry. */
512 zebra_evpn_neigh_del(zevpn
, n
);
514 /* see if the mac needs to be deleted as well*/
516 zebra_evpn_deref_ip2mac(zevpn
, mac
);
521 void zebra_evpn_gw_macip_del_for_evpn_hash(struct hash_bucket
*bucket
,
524 struct zebra_evpn
*zevpn
= NULL
;
525 struct zebra_if
*zif
= NULL
;
526 struct zebra_l2info_vxlan zl2_info
;
527 struct interface
*vlan_if
= NULL
;
528 struct interface
*vrr_if
= NULL
;
529 struct interface
*ifp
;
531 /* Add primary SVI MAC*/
532 zevpn
= (struct zebra_evpn
*)bucket
->data
;
534 /* Global (Zvrf) advertise-default-gw is disabled,
535 * but zevpn advertise-default-gw is enabled
537 if (zevpn
->advertise_gw_macip
) {
538 if (IS_ZEBRA_DEBUG_VXLAN
)
539 zlog_debug("VNI: %u GW-MACIP enabled, retain gw-macip",
544 ifp
= zevpn
->vxlan_if
;
549 /* If down or not mapped to a bridge, we're done. */
550 if (!if_is_operative(ifp
) || !zif
->brslave_info
.br_if
)
553 zl2_info
= zif
->l2info
.vxl
;
556 zvni_map_to_svi(zl2_info
.access_vlan
, zif
->brslave_info
.br_if
);
560 /* Del primary MAC-IP */
561 zebra_evpn_del_macip_for_intf(vlan_if
, zevpn
);
563 /* Del VRR MAC-IP - if any*/
564 vrr_if
= zebra_get_vrr_intf_for_svi(vlan_if
);
566 zebra_evpn_del_macip_for_intf(vrr_if
, zevpn
);
571 void zebra_evpn_gw_macip_add_for_evpn_hash(struct hash_bucket
*bucket
,
574 struct zebra_evpn
*zevpn
= NULL
;
575 struct zebra_if
*zif
= NULL
;
576 struct zebra_l2info_vxlan zl2_info
;
577 struct interface
*vlan_if
= NULL
;
578 struct interface
*vrr_if
= NULL
;
579 struct interface
*ifp
= NULL
;
581 zevpn
= (struct zebra_evpn
*)bucket
->data
;
583 ifp
= zevpn
->vxlan_if
;
588 /* If down or not mapped to a bridge, we're done. */
589 if (!if_is_operative(ifp
) || !zif
->brslave_info
.br_if
)
591 zl2_info
= zif
->l2info
.vxl
;
594 zvni_map_to_svi(zl2_info
.access_vlan
, zif
->brslave_info
.br_if
);
598 /* Add primary SVI MAC-IP */
599 if (advertise_svi_macip_enabled(zevpn
)
600 || advertise_gw_macip_enabled(zevpn
))
601 zebra_evpn_add_macip_for_intf(vlan_if
, zevpn
);
603 if (advertise_gw_macip_enabled(zevpn
)) {
604 /* Add VRR MAC-IP - if any*/
605 vrr_if
= zebra_get_vrr_intf_for_svi(vlan_if
);
607 zebra_evpn_add_macip_for_intf(vrr_if
, zevpn
);
613 void zebra_evpn_svi_macip_del_for_evpn_hash(struct hash_bucket
*bucket
,
616 struct zebra_evpn
*zevpn
= NULL
;
617 struct zebra_if
*zif
= NULL
;
618 struct zebra_l2info_vxlan zl2_info
;
619 struct interface
*vlan_if
= NULL
;
620 struct interface
*ifp
;
622 /* Add primary SVI MAC*/
623 zevpn
= (struct zebra_evpn
*)bucket
->data
;
627 /* Global(vrf) advertise-svi-ip disabled, but zevpn advertise-svi-ip
630 if (zevpn
->advertise_svi_macip
) {
631 if (IS_ZEBRA_DEBUG_VXLAN
)
632 zlog_debug("VNI: %u SVI-MACIP enabled, retain svi-macip",
637 ifp
= zevpn
->vxlan_if
;
642 /* If down or not mapped to a bridge, we're done. */
643 if (!if_is_operative(ifp
) || !zif
->brslave_info
.br_if
)
646 zl2_info
= zif
->l2info
.vxl
;
649 zvni_map_to_svi(zl2_info
.access_vlan
, zif
->brslave_info
.br_if
);
653 /* Del primary MAC-IP */
654 zebra_evpn_del_macip_for_intf(vlan_if
, zevpn
);
659 static int zebra_evpn_map_vlan_ns(struct ns
*ns
,
663 struct zebra_ns
*zns
= ns
->info
;
664 struct route_node
*rn
;
665 struct interface
*br_if
;
666 struct zebra_evpn
**p_zevpn
= (struct zebra_evpn
**)_p_zevpn
;
667 struct zebra_evpn
*zevpn
;
668 struct interface
*tmp_if
= NULL
;
669 struct zebra_if
*zif
;
670 struct zebra_l2info_vxlan
*vxl
= NULL
;
671 struct zebra_from_svi_param
*in_param
=
672 (struct zebra_from_svi_param
*)_in_param
;
674 assert(p_zevpn
&& in_param
);
676 br_if
= in_param
->br_if
;
681 /* See if this interface (or interface plus VLAN Id) maps to a VxLAN */
682 /* TODO: Optimize with a hash. */
683 for (rn
= route_top(zns
->if_table
); rn
; rn
= route_next(rn
)) {
684 tmp_if
= (struct interface
*)rn
->info
;
688 if (!zif
|| zif
->zif_type
!= ZEBRA_IF_VXLAN
)
690 if (!if_is_operative(tmp_if
))
692 vxl
= &zif
->l2info
.vxl
;
694 if (zif
->brslave_info
.br_if
!= br_if
)
697 if (!in_param
->bridge_vlan_aware
698 || vxl
->access_vlan
== in_param
->vid
) {
699 zevpn
= zebra_evpn_lookup(vxl
->vni
);
705 return NS_WALK_CONTINUE
;
709 * Map port or (port, VLAN) to an EVPN. This is invoked upon getting MAC
710 * notifications, to see if they are of interest.
712 struct zebra_evpn
*zebra_evpn_map_vlan(struct interface
*ifp
,
713 struct interface
*br_if
, vlanid_t vid
)
715 struct zebra_if
*zif
;
716 struct zebra_l2info_bridge
*br
;
717 struct zebra_evpn
**p_zevpn
;
718 struct zebra_evpn
*zevpn
= NULL
;
719 struct zebra_from_svi_param in_param
;
721 /* Determine if bridge is VLAN-aware or not */
724 br
= &zif
->l2info
.br
;
725 in_param
.bridge_vlan_aware
= br
->vlan_aware
;
727 in_param
.br_if
= br_if
;
731 ns_walk_func(zebra_evpn_map_vlan_ns
,
737 static int zebra_evpn_from_svi_ns(struct ns
*ns
,
741 struct zebra_ns
*zns
= ns
->info
;
742 struct route_node
*rn
;
743 struct interface
*br_if
;
744 struct zebra_evpn
**p_zevpn
= (struct zebra_evpn
**)_p_zevpn
;
745 struct zebra_evpn
*zevpn
;
746 struct interface
*tmp_if
= NULL
;
747 struct zebra_if
*zif
;
748 struct zebra_l2info_vxlan
*vxl
= NULL
;
749 struct zebra_from_svi_param
*in_param
=
750 (struct zebra_from_svi_param
*)_in_param
;
755 br_if
= in_param
->br_if
;
759 /* TODO: Optimize with a hash. */
760 for (rn
= route_top(zns
->if_table
); rn
; rn
= route_next(rn
)) {
761 tmp_if
= (struct interface
*)rn
->info
;
765 if (!zif
|| zif
->zif_type
!= ZEBRA_IF_VXLAN
)
767 if (!if_is_operative(tmp_if
))
769 vxl
= &zif
->l2info
.vxl
;
771 if (zif
->brslave_info
.br_if
!= br_if
)
774 if (!in_param
->bridge_vlan_aware
775 || vxl
->access_vlan
== in_param
->vid
) {
782 return NS_WALK_CONTINUE
;
784 zevpn
= zebra_evpn_lookup(vxl
->vni
);
791 * Map SVI and associated bridge to an EVPN. This is invoked upon getting
792 * neighbor notifications, to see if they are of interest.
794 struct zebra_evpn
*zebra_evpn_from_svi(struct interface
*ifp
,
795 struct interface
*br_if
)
797 struct zebra_l2info_bridge
*br
;
798 struct zebra_evpn
*zevpn
= NULL
;
799 struct zebra_evpn
**p_zevpn
;
800 struct zebra_if
*zif
;
801 struct zebra_from_svi_param in_param
;
806 /* Make sure the linked interface is a bridge. */
807 if (!IS_ZEBRA_IF_BRIDGE(br_if
))
810 /* Determine if bridge is VLAN-aware or not */
813 br
= &zif
->l2info
.br
;
814 in_param
.bridge_vlan_aware
= br
->vlan_aware
;
817 if (in_param
.bridge_vlan_aware
) {
818 struct zebra_l2info_vlan
*vl
;
820 if (!IS_ZEBRA_IF_VLAN(ifp
))
825 vl
= &zif
->l2info
.vl
;
826 in_param
.vid
= vl
->vid
;
829 in_param
.br_if
= br_if
;
832 /* See if this interface (or interface plus VLAN Id) maps to a VxLAN */
833 ns_walk_func(zebra_evpn_from_svi_ns
, (void *)&in_param
,
838 static int zvni_map_to_macvlan_ns(struct ns
*ns
,
842 struct zebra_ns
*zns
= ns
->info
;
843 struct zebra_from_svi_param
*in_param
=
844 (struct zebra_from_svi_param
*)_in_param
;
845 struct interface
**p_ifp
= (struct interface
**)_p_ifp
;
846 struct route_node
*rn
;
847 struct interface
*tmp_if
= NULL
;
848 struct zebra_if
*zif
;
850 assert(in_param
&& p_ifp
);
852 /* Identify corresponding VLAN interface. */
853 for (rn
= route_top(zns
->if_table
); rn
; rn
= route_next(rn
)) {
854 tmp_if
= (struct interface
*)rn
->info
;
855 /* Check oper status of the SVI. */
856 if (!tmp_if
|| !if_is_operative(tmp_if
))
860 if (!zif
|| zif
->zif_type
!= ZEBRA_IF_MACVLAN
)
863 if (zif
->link
== in_param
->svi_if
) {
869 return NS_WALK_CONTINUE
;
872 /* Map to MAC-VLAN interface corresponding to specified SVI interface.
874 struct interface
*zebra_evpn_map_to_macvlan(struct interface
*br_if
,
875 struct interface
*svi_if
)
877 struct interface
*tmp_if
= NULL
;
878 struct zebra_if
*zif
;
879 struct interface
**p_ifp
;
880 struct zebra_from_svi_param in_param
;
882 /* Defensive check, caller expected to invoke only with valid bridge. */
887 zlog_debug("svi_if is not passed.");
891 /* Determine if bridge is VLAN-aware or not */
896 in_param
.br_if
= br_if
;
898 in_param
.svi_if
= svi_if
;
901 /* Identify corresponding VLAN interface. */
902 ns_walk_func(zvni_map_to_macvlan_ns
,
909 * Install MAC hash entry - called upon access VLAN change.
911 void zebra_evpn_install_mac_hash(struct hash_bucket
*bucket
, void *ctxt
)
913 struct zebra_mac
*mac
;
914 struct mac_walk_ctx
*wctx
= ctxt
;
916 mac
= (struct zebra_mac
*)bucket
->data
;
918 if (CHECK_FLAG(mac
->flags
, ZEBRA_MAC_REMOTE
))
919 zebra_evpn_rem_mac_install(wctx
->zevpn
, mac
, false);
923 * Read and populate local MACs and neighbors corresponding to this EVPN.
925 void zebra_evpn_read_mac_neigh(struct zebra_evpn
*zevpn
, struct interface
*ifp
)
927 struct zebra_ns
*zns
;
928 struct zebra_vrf
*zvrf
;
929 struct zebra_if
*zif
;
930 struct interface
*vlan_if
;
931 struct zebra_l2info_vxlan
*vxl
;
932 struct interface
*vrr_if
;
935 vxl
= &zif
->l2info
.vxl
;
936 zvrf
= zebra_vrf_lookup_by_id(zevpn
->vrf_id
);
937 if (!zvrf
|| !zvrf
->zns
)
941 if (IS_ZEBRA_DEBUG_VXLAN
)
943 "Reading MAC FDB and Neighbors for intf %s(%u) VNI %u master %u",
944 ifp
->name
, ifp
->ifindex
, zevpn
->vni
,
945 zif
->brslave_info
.bridge_ifindex
);
947 macfdb_read_for_bridge(zns
, ifp
, zif
->brslave_info
.br_if
);
948 vlan_if
= zvni_map_to_svi(vxl
->access_vlan
, zif
->brslave_info
.br_if
);
951 zebra_evpn_acc_bd_svi_mac_add(vlan_if
);
954 if (advertise_svi_macip_enabled(zevpn
)
955 || advertise_gw_macip_enabled(zevpn
))
956 zebra_evpn_add_macip_for_intf(vlan_if
, zevpn
);
958 /* Add VRR MAC-IP - if any*/
959 if (advertise_gw_macip_enabled(zevpn
)) {
960 vrr_if
= zebra_get_vrr_intf_for_svi(vlan_if
);
962 zebra_evpn_add_macip_for_intf(vrr_if
, zevpn
);
965 neigh_read_for_vlan(zns
, vlan_if
);
970 * Hash function for EVPN.
972 unsigned int zebra_evpn_hash_keymake(const void *p
)
974 const struct zebra_evpn
*zevpn
= p
;
976 return (jhash_1word(zevpn
->vni
, 0));
980 * Compare 2 evpn hash entries.
982 bool zebra_evpn_hash_cmp(const void *p1
, const void *p2
)
984 const struct zebra_evpn
*zevpn1
= p1
;
985 const struct zebra_evpn
*zevpn2
= p2
;
987 return (zevpn1
->vni
== zevpn2
->vni
);
990 int zebra_evpn_list_cmp(void *p1
, void *p2
)
992 const struct zebra_evpn
*zevpn1
= p1
;
993 const struct zebra_evpn
*zevpn2
= p2
;
995 if (zevpn1
->vni
== zevpn2
->vni
)
997 return (zevpn1
->vni
< zevpn2
->vni
) ? -1 : 1;
1001 * Callback to allocate VNI hash entry.
1003 void *zebra_evpn_alloc(void *p
)
1005 const struct zebra_evpn
*tmp_vni
= p
;
1006 struct zebra_evpn
*zevpn
;
1008 zevpn
= XCALLOC(MTYPE_ZEVPN
, sizeof(struct zebra_evpn
));
1009 zevpn
->vni
= tmp_vni
->vni
;
1010 return ((void *)zevpn
);
1014 * Look up EVPN hash entry.
1016 struct zebra_evpn
*zebra_evpn_lookup(vni_t vni
)
1018 struct zebra_vrf
*zvrf
;
1019 struct zebra_evpn tmp_vni
;
1020 struct zebra_evpn
*zevpn
= NULL
;
1022 zvrf
= zebra_vrf_get_evpn();
1023 memset(&tmp_vni
, 0, sizeof(tmp_vni
));
1025 zevpn
= hash_lookup(zvrf
->evpn_table
, &tmp_vni
);
1031 * Add EVPN hash entry.
1033 struct zebra_evpn
*zebra_evpn_add(vni_t vni
)
1036 struct zebra_vrf
*zvrf
;
1037 struct zebra_evpn tmp_zevpn
;
1038 struct zebra_evpn
*zevpn
= NULL
;
1040 zvrf
= zebra_vrf_get_evpn();
1041 memset(&tmp_zevpn
, 0, sizeof(tmp_zevpn
));
1042 tmp_zevpn
.vni
= vni
;
1043 zevpn
= hash_get(zvrf
->evpn_table
, &tmp_zevpn
, zebra_evpn_alloc
);
1045 zebra_evpn_es_evi_init(zevpn
);
1047 snprintf(buffer
, sizeof(buffer
), "Zebra EVPN MAC Table vni: %u", vni
);
1048 /* Create hash table for MAC */
1049 zevpn
->mac_table
= zebra_mac_db_create(buffer
);
1051 snprintf(buffer
, sizeof(buffer
), "Zebra EVPN Neighbor Table vni: %u",
1053 /* Create hash table for neighbors */
1054 zevpn
->neigh_table
= zebra_neigh_db_create(buffer
);
1060 * Delete EVPN hash entry.
1062 int zebra_evpn_del(struct zebra_evpn
*zevpn
)
1064 struct zebra_vrf
*zvrf
;
1065 struct zebra_evpn
*tmp_zevpn
;
1067 zvrf
= zebra_vrf_get_evpn();
1069 zevpn
->svi_if
= NULL
;
1071 /* Free the neighbor hash table. */
1072 hash_free(zevpn
->neigh_table
);
1073 zevpn
->neigh_table
= NULL
;
1075 /* Free the MAC hash table. */
1076 hash_free(zevpn
->mac_table
);
1077 zevpn
->mac_table
= NULL
;
1079 /* Remove references to the zevpn in the MH databases */
1080 if (zevpn
->vxlan_if
)
1081 zebra_evpn_vxl_evpn_set(zevpn
->vxlan_if
->info
, zevpn
, false);
1082 zebra_evpn_es_evi_cleanup(zevpn
);
1084 /* Free the EVPN hash entry and allocated memory. */
1085 tmp_zevpn
= hash_release(zvrf
->evpn_table
, zevpn
);
1086 XFREE(MTYPE_ZEVPN
, tmp_zevpn
);
1092 * Inform BGP about local EVPN addition.
1094 int zebra_evpn_send_add_to_client(struct zebra_evpn
*zevpn
)
1096 struct zserv
*client
;
1098 ifindex_t svi_index
;
1101 client
= zserv_find_client(ZEBRA_ROUTE_BGP
, 0);
1102 /* BGP may not be running. */
1106 svi_index
= zevpn
->svi_if
? zevpn
->svi_if
->ifindex
: 0;
1108 s
= stream_new(ZEBRA_MAX_PACKET_SIZ
);
1110 zclient_create_header(s
, ZEBRA_VNI_ADD
, zebra_vrf_get_evpn_id());
1111 stream_putl(s
, zevpn
->vni
);
1112 stream_put_in_addr(s
, &zevpn
->local_vtep_ip
);
1113 stream_put(s
, &zevpn
->vrf_id
, sizeof(vrf_id_t
)); /* tenant vrf */
1114 stream_put_in_addr(s
, &zevpn
->mcast_grp
);
1115 stream_put(s
, &svi_index
, sizeof(ifindex_t
));
1117 /* Write packet size. */
1118 stream_putw_at(s
, 0, stream_get_endp(s
));
1120 if (IS_ZEBRA_DEBUG_VXLAN
)
1122 "Send EVPN_ADD %u %pI4 tenant vrf %s(%u) SVI index %u to %s",
1123 zevpn
->vni
, &zevpn
->local_vtep_ip
,
1124 vrf_id_to_name(zevpn
->vrf_id
), zevpn
->vrf_id
,
1125 (zevpn
->svi_if
? zevpn
->svi_if
->ifindex
: 0),
1126 zebra_route_string(client
->proto
));
1128 client
->vniadd_cnt
++;
1129 rc
= zserv_send_message(client
, s
);
1131 if (!(zevpn
->flags
& ZEVPN_READY_FOR_BGP
)) {
1132 zevpn
->flags
|= ZEVPN_READY_FOR_BGP
;
1133 /* once the EVPN is sent the ES-EVIs can also be replayed
1136 zebra_evpn_update_all_es(zevpn
);
1142 * Inform BGP about local EVPN deletion.
1144 int zebra_evpn_send_del_to_client(struct zebra_evpn
*zevpn
)
1146 struct zserv
*client
;
1149 client
= zserv_find_client(ZEBRA_ROUTE_BGP
, 0);
1150 /* BGP may not be running. */
1154 if (zevpn
->flags
& ZEVPN_READY_FOR_BGP
) {
1155 zevpn
->flags
&= ~ZEVPN_READY_FOR_BGP
;
1156 /* the ES-EVIs must be removed from BGP before the EVPN is */
1157 zebra_evpn_update_all_es(zevpn
);
1160 s
= stream_new(ZEBRA_MAX_PACKET_SIZ
);
1163 zclient_create_header(s
, ZEBRA_VNI_DEL
, zebra_vrf_get_evpn_id());
1164 stream_putl(s
, zevpn
->vni
);
1166 /* Write packet size. */
1167 stream_putw_at(s
, 0, stream_get_endp(s
));
1169 if (IS_ZEBRA_DEBUG_VXLAN
)
1170 zlog_debug("Send EVPN_DEL %u to %s", zevpn
->vni
,
1171 zebra_route_string(client
->proto
));
1173 client
->vnidel_cnt
++;
1174 return zserv_send_message(client
, s
);
1178 * See if remote VTEP matches with prefix.
1180 static int zebra_evpn_vtep_match(struct in_addr
*vtep_ip
,
1181 struct zebra_vtep
*zvtep
)
1183 return (IPV4_ADDR_SAME(vtep_ip
, &zvtep
->vtep_ip
));
1187 * Locate remote VTEP in EVPN hash table.
1189 struct zebra_vtep
*zebra_evpn_vtep_find(struct zebra_evpn
*zevpn
,
1190 struct in_addr
*vtep_ip
)
1192 struct zebra_vtep
*zvtep
;
1197 for (zvtep
= zevpn
->vteps
; zvtep
; zvtep
= zvtep
->next
) {
1198 if (zebra_evpn_vtep_match(vtep_ip
, zvtep
))
1206 * Add remote VTEP to EVPN hash table.
1208 struct zebra_vtep
*zebra_evpn_vtep_add(struct zebra_evpn
*zevpn
,
1209 struct in_addr
*vtep_ip
,
1213 struct zebra_vtep
*zvtep
;
1215 zvtep
= XCALLOC(MTYPE_ZEVPN_VTEP
, sizeof(struct zebra_vtep
));
1217 zvtep
->vtep_ip
= *vtep_ip
;
1218 zvtep
->flood_control
= flood_control
;
1221 zevpn
->vteps
->prev
= zvtep
;
1222 zvtep
->next
= zevpn
->vteps
;
1223 zevpn
->vteps
= zvtep
;
1229 * Remove remote VTEP from EVPN hash table.
1231 int zebra_evpn_vtep_del(struct zebra_evpn
*zevpn
, struct zebra_vtep
*zvtep
)
1234 zvtep
->next
->prev
= zvtep
->prev
;
1236 zvtep
->prev
->next
= zvtep
->next
;
1238 zevpn
->vteps
= zvtep
->next
;
1240 zvtep
->prev
= zvtep
->next
= NULL
;
1241 XFREE(MTYPE_ZEVPN_VTEP
, zvtep
);
1247 * Delete all remote VTEPs for this EVPN (upon VNI delete). Also
1248 * uninstall from kernel if asked to.
1250 int zebra_evpn_vtep_del_all(struct zebra_evpn
*zevpn
, int uninstall
)
1252 struct zebra_vtep
*zvtep
, *zvtep_next
;
1257 for (zvtep
= zevpn
->vteps
; zvtep
; zvtep
= zvtep_next
) {
1258 zvtep_next
= zvtep
->next
;
1260 zebra_evpn_vtep_uninstall(zevpn
, &zvtep
->vtep_ip
);
1261 zebra_evpn_vtep_del(zevpn
, zvtep
);
1268 * Install remote VTEP into the kernel if the remote VTEP has asked
1269 * for head-end-replication.
1271 int zebra_evpn_vtep_install(struct zebra_evpn
*zevpn
, struct zebra_vtep
*zvtep
)
1273 if (is_vxlan_flooding_head_end() &&
1274 (zvtep
->flood_control
== VXLAN_FLOOD_HEAD_END_REPL
)) {
1275 if (ZEBRA_DPLANE_REQUEST_FAILURE
==
1276 dplane_vtep_add(zevpn
->vxlan_if
,
1277 &zvtep
->vtep_ip
, zevpn
->vni
))
1285 * Uninstall remote VTEP from the kernel.
1287 int zebra_evpn_vtep_uninstall(struct zebra_evpn
*zevpn
, struct in_addr
*vtep_ip
)
1289 if (!zevpn
->vxlan_if
) {
1290 zlog_debug("VNI %u hash %p couldn't be uninstalled - no intf",
1295 if (ZEBRA_DPLANE_REQUEST_FAILURE
==
1296 dplane_vtep_delete(zevpn
->vxlan_if
, vtep_ip
, zevpn
->vni
))
1303 * Install or uninstall flood entries in the kernel corresponding to
1304 * remote VTEPs. This is invoked upon change to BUM handling.
1306 void zebra_evpn_handle_flooding_remote_vteps(struct hash_bucket
*bucket
,
1309 struct zebra_evpn
*zevpn
;
1310 struct zebra_vtep
*zvtep
;
1312 zevpn
= (struct zebra_evpn
*)bucket
->data
;
1316 for (zvtep
= zevpn
->vteps
; zvtep
; zvtep
= zvtep
->next
) {
1317 if (is_vxlan_flooding_head_end())
1318 zebra_evpn_vtep_install(zevpn
, zvtep
);
1320 zebra_evpn_vtep_uninstall(zevpn
, &zvtep
->vtep_ip
);
1325 * Cleanup EVPN/VTEP and update kernel
1327 void zebra_evpn_cleanup_all(struct hash_bucket
*bucket
, void *arg
)
1329 struct zebra_evpn
*zevpn
= NULL
;
1331 zevpn
= (struct zebra_evpn
*)bucket
->data
;
1333 /* Free up all neighbors and MACs, if any. */
1334 zebra_evpn_neigh_del_all(zevpn
, 1, 0, DEL_ALL_NEIGH
);
1335 zebra_evpn_mac_del_all(zevpn
, 1, 0, DEL_ALL_MAC
);
1337 /* Free up all remote VTEPs, if any. */
1338 zebra_evpn_vtep_del_all(zevpn
, 1);
1340 /* Delete the hash entry. */
1341 zebra_evpn_del(zevpn
);
1344 static void zebra_evpn_process_sync_macip_add(struct zebra_evpn
*zevpn
,
1345 const struct ethaddr
*macaddr
,
1347 const struct ipaddr
*ipaddr
,
1348 uint8_t flags
, uint32_t seq
,
1351 char ipbuf
[INET6_ADDRSTRLEN
];
1354 struct zebra_neigh
*n
= NULL
;
1355 struct zebra_mac
*mac
= NULL
;
1357 sticky
= !!CHECK_FLAG(flags
, ZEBRA_MACIP_TYPE_STICKY
);
1358 remote_gw
= !!CHECK_FLAG(flags
, ZEBRA_MACIP_TYPE_GW
);
1359 /* if sticky or remote-gw ignore updates from the peer */
1360 if (sticky
|| remote_gw
) {
1361 if (IS_ZEBRA_DEBUG_VXLAN
|| IS_ZEBRA_DEBUG_EVPN_MH_NEIGH
1362 || IS_ZEBRA_DEBUG_EVPN_MH_MAC
)
1364 "Ignore sync-macip vni %u mac %pEA%s%s%s%s",
1367 ipa_len
? " IP " : "",
1368 ipa_len
? ipaddr2str(ipaddr
, ipbuf
,
1371 sticky
? " sticky" : "",
1372 remote_gw
? " remote_gw" : "");
1378 (void)zebra_evpn_proc_sync_mac_update(zevpn
, macaddr
, ipa_len
,
1379 ipaddr
, flags
, seq
, esi
);
1382 mac
= zebra_evpn_mac_lookup(zevpn
, macaddr
);
1384 mac
= zebra_evpn_proc_sync_mac_update(zevpn
, macaddr
,
1391 n
= zebra_evpn_neigh_lookup(zevpn
, ipaddr
);
1393 && !zebra_evpn_neigh_is_bgp_seq_ok(zevpn
, n
, macaddr
, seq
,
1397 zebra_evpn_proc_sync_neigh_update(zevpn
, n
, ipa_len
, ipaddr
,
1398 flags
, seq
, esi
, mac
);
1402 /************************** remote mac-ip handling **************************/
1403 /* Process a remote MACIP add from BGP. */
1404 void zebra_evpn_rem_macip_add(vni_t vni
, const struct ethaddr
*macaddr
,
1405 uint16_t ipa_len
, const struct ipaddr
*ipaddr
,
1406 uint8_t flags
, uint32_t seq
,
1407 struct in_addr vtep_ip
, const esi_t
*esi
)
1409 struct zebra_evpn
*zevpn
;
1410 struct zebra_vtep
*zvtep
;
1411 struct zebra_mac
*mac
= NULL
;
1412 struct interface
*ifp
= NULL
;
1413 struct zebra_if
*zif
= NULL
;
1414 struct zebra_vrf
*zvrf
;
1416 /* Locate EVPN hash entry - expected to exist. */
1417 zevpn
= zebra_evpn_lookup(vni
);
1419 if (IS_ZEBRA_DEBUG_VXLAN
)
1420 zlog_debug("Unknown VNI %u upon remote MACIP ADD", vni
);
1424 ifp
= zevpn
->vxlan_if
;
1427 if (!ifp
|| !if_is_operative(ifp
) || !zif
|| !zif
->brslave_info
.br_if
) {
1428 if (IS_ZEBRA_DEBUG_VXLAN
)
1430 "Ignoring remote MACIP ADD VNI %u, invalid interface state or info",
1435 /* Type-2 routes from another PE can be interpreted as remote or
1436 * SYNC based on the destination ES -
1437 * SYNC - if ES is local
1438 * REMOTE - if ES is not local
1440 if (flags
& ZEBRA_MACIP_TYPE_SYNC_PATH
) {
1441 struct zebra_evpn_es
*es
;
1443 es
= zebra_evpn_es_find(esi
);
1444 if (es
&& (es
->flags
& ZEBRA_EVPNES_READY_FOR_BGP
)) {
1445 zebra_evpn_process_sync_macip_add(zevpn
, macaddr
,
1449 if (IS_ZEBRA_DEBUG_EVPN_MH_ES
) {
1450 char esi_str
[ESI_STR_LEN
];
1452 esi_to_str(esi
, esi_str
, sizeof(esi_str
));
1454 "Ignore sync-macip add; ES %s is not ready",
1462 /* The remote VTEP specified should normally exist, but it is
1463 * possible that when peering comes up, peer may advertise MACIP
1464 * routes before advertising type-3 routes.
1466 if (vtep_ip
.s_addr
) {
1467 zvtep
= zebra_evpn_vtep_find(zevpn
, &vtep_ip
);
1469 zvtep
= zebra_evpn_vtep_add(zevpn
, &vtep_ip
,
1470 VXLAN_FLOOD_DISABLED
);
1473 EC_ZEBRA_VTEP_ADD_FAILED
,
1474 "Failed to add remote VTEP, VNI %u zevpn %p upon remote MACIP ADD",
1479 zebra_evpn_vtep_install(zevpn
, zvtep
);
1483 zvrf
= zebra_vrf_get_evpn();
1489 zebra_evpn_mac_remote_macip_add(zevpn
, zvrf
, macaddr
, vtep_ip
,
1493 * Add auto MAC if it doesn't exist.
1495 mac
= zebra_evpn_mac_lookup(zevpn
, macaddr
);
1497 mac
= zebra_evpn_mac_add_auto(zevpn
, macaddr
);
1499 if (IS_ZEBRA_DEBUG_VXLAN
)
1501 "Neigh %pIA: MAC %pEA not found, Auto MAC created",
1505 zebra_evpn_neigh_remote_macip_add(zevpn
, zvrf
, ipaddr
, mac
,
1506 vtep_ip
, flags
, seq
);
1510 /* Process a remote MACIP delete from BGP. */
1511 void zebra_evpn_rem_macip_del(vni_t vni
, const struct ethaddr
*macaddr
,
1512 uint16_t ipa_len
, const struct ipaddr
*ipaddr
,
1513 struct in_addr vtep_ip
)
1515 struct zebra_evpn
*zevpn
;
1516 struct zebra_mac
*mac
= NULL
;
1517 struct zebra_neigh
*n
= NULL
;
1518 struct interface
*ifp
= NULL
;
1519 struct zebra_if
*zif
= NULL
;
1520 struct zebra_ns
*zns
;
1521 struct zebra_l2info_vxlan
*vxl
;
1522 struct zebra_vrf
*zvrf
;
1523 char buf1
[INET6_ADDRSTRLEN
];
1525 /* Locate EVPN hash entry - expected to exist. */
1526 zevpn
= zebra_evpn_lookup(vni
);
1528 if (IS_ZEBRA_DEBUG_VXLAN
)
1529 zlog_debug("Unknown VNI %u upon remote MACIP DEL", vni
);
1533 ifp
= zevpn
->vxlan_if
;
1536 if (!ifp
|| !if_is_operative(ifp
) || !zif
|| !zif
->brslave_info
.br_if
) {
1537 if (IS_ZEBRA_DEBUG_VXLAN
)
1539 "Ignoring remote MACIP DEL VNI %u, invalid interface state or info",
1543 zns
= zebra_ns_lookup(NS_DEFAULT
);
1544 vxl
= &zif
->l2info
.vxl
;
1546 mac
= zebra_evpn_mac_lookup(zevpn
, macaddr
);
1548 n
= zebra_evpn_neigh_lookup(zevpn
, ipaddr
);
1552 "Failed to locate MAC %pEA for Neigh %pIA VNI %u upon remote MACIP DEL",
1553 macaddr
, ipaddr
, vni
);
1557 /* If the remote mac or neighbor doesn't exist there is nothing
1558 * more to do. Otherwise, uninstall the entry and then remove it.
1561 if (IS_ZEBRA_DEBUG_VXLAN
)
1563 "Failed to locate MAC %pEA & Neigh %pIA VNI %u upon remote MACIP DEL",
1564 macaddr
, ipaddr
, vni
);
1568 zvrf
= zevpn
->vxlan_if
->vrf
->info
;
1570 /* Ignore the delete if this mac is a gateway mac-ip */
1571 if (CHECK_FLAG(mac
->flags
, ZEBRA_MAC_LOCAL
)
1572 && CHECK_FLAG(mac
->flags
, ZEBRA_MAC_DEF_GW
)) {
1574 "Ignore remote MACIP DEL VNI %u MAC %pEA%s%s as MAC is already configured as gateway MAC",
1576 ipa_len
? " IP " : "",
1577 ipa_len
? ipaddr2str(ipaddr
, buf1
, sizeof(buf1
)) : "");
1581 /* Uninstall remote neighbor or MAC. */
1583 zebra_evpn_neigh_remote_uninstall(zevpn
, zvrf
, n
, mac
, ipaddr
);
1585 /* DAD: when MAC is freeze state as remote learn event,
1586 * remote mac-ip delete event is received will result in freeze
1587 * entry removal, first fetch kernel for the same entry present
1588 * as LOCAL and reachable, avoid deleting this entry instead
1589 * use kerenel local entry to update during unfreeze time.
1591 if (zvrf
->dad_freeze
1592 && CHECK_FLAG(mac
->flags
, ZEBRA_MAC_DUPLICATE
)
1593 && CHECK_FLAG(mac
->flags
, ZEBRA_MAC_REMOTE
)) {
1594 if (IS_ZEBRA_DEBUG_VXLAN
)
1596 "%s: MAC %pEA (flags 0x%x) is remote and duplicate, read kernel for local entry",
1597 __func__
, macaddr
, mac
->flags
);
1598 macfdb_read_specific_mac(zns
, zif
->brslave_info
.br_if
,
1599 macaddr
, vxl
->access_vlan
);
1602 if (CHECK_FLAG(mac
->flags
, ZEBRA_MAC_LOCAL
)) {
1604 zebra_evpn_sync_mac_del(mac
);
1605 } else if (CHECK_FLAG(mac
->flags
, ZEBRA_NEIGH_REMOTE
)) {
1606 zebra_evpn_rem_mac_del(zevpn
, mac
);
1611 /************************** EVPN BGP config management ************************/
1612 void zebra_evpn_cfg_cleanup(struct hash_bucket
*bucket
, void *ctxt
)
1614 struct zebra_evpn
*zevpn
= NULL
;
1616 zevpn
= (struct zebra_evpn
*)bucket
->data
;
1617 zevpn
->advertise_gw_macip
= 0;
1618 zevpn
->advertise_svi_macip
= 0;
1619 zevpn
->advertise_subnet
= 0;
1621 zebra_evpn_neigh_del_all(zevpn
, 1, 0,
1622 DEL_REMOTE_NEIGH
| DEL_REMOTE_NEIGH_FROM_VTEP
);
1623 zebra_evpn_mac_del_all(zevpn
, 1, 0,
1624 DEL_REMOTE_MAC
| DEL_REMOTE_MAC_FROM_VTEP
);
1625 zebra_evpn_vtep_del_all(zevpn
, 1);