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_l2_bridge_if.h"
48 #include "zebra/zebra_ns.h"
49 #include "zebra/zebra_vrf.h"
50 #include "zebra/zebra_vxlan.h"
51 #include "zebra/zebra_vxlan_private.h"
52 #include "zebra/zebra_evpn.h"
53 #include "zebra/zebra_evpn_mac.h"
54 #include "zebra/zebra_evpn_neigh.h"
55 #include "zebra/zebra_evpn_mh.h"
56 #include "zebra/zebra_evpn_vxlan.h"
57 #include "zebra/zebra_router.h"
59 DEFINE_MTYPE_STATIC(ZEBRA
, ZEVPN
, "VNI hash");
60 DEFINE_MTYPE_STATIC(ZEBRA
, ZEVPN_VTEP
, "VNI remote VTEP");
63 #define VXLAN_FLOOD_STR_NO_INFO "-"
64 #define VXLAN_FLOOD_STR_DEFAULT VXLAN_FLOOD_STR_NO_INFO
65 static const struct message zvtep_flood_str
[] = {
66 {VXLAN_FLOOD_DISABLED
, VXLAN_FLOOD_STR_NO_INFO
},
67 {VXLAN_FLOOD_PIM_SM
, "PIM-SM"},
68 {VXLAN_FLOOD_HEAD_END_REPL
, "HER"},
72 int advertise_gw_macip_enabled(struct zebra_evpn
*zevpn
)
74 struct zebra_vrf
*zvrf
;
76 zvrf
= zebra_vrf_get_evpn();
77 if (zvrf
->advertise_gw_macip
)
80 if (zevpn
&& zevpn
->advertise_gw_macip
)
86 int advertise_svi_macip_enabled(struct zebra_evpn
*zevpn
)
88 struct zebra_vrf
*zvrf
;
90 zvrf
= zebra_vrf_get_evpn();
91 if (zvrf
->advertise_svi_macip
)
94 if (zevpn
&& zevpn
->advertise_svi_macip
)
101 * Print a specific EVPN entry.
103 void zebra_evpn_print(struct zebra_evpn
*zevpn
, void **ctxt
)
106 struct vty
*vty
= NULL
;
107 struct zebra_vtep
*zvtep
= NULL
;
108 uint32_t num_macs
= 0;
109 uint32_t num_neigh
= 0;
110 uint32_t num_vteps
= 0;
111 json_object
*json
= NULL
;
112 json_object
*json_vtep_list
= NULL
;
113 json_object
*json_vtep
= NULL
;
119 vty_out(vty
, "VNI: %u\n", zevpn
->vni
);
120 vty_out(vty
, " Type: %s\n", "L2");
121 vty_out(vty
, " Vlan: %u\n", zevpn
->vid
);
122 vty_out(vty
, " Bridge: %s\n",
123 zevpn
->bridge_if
? zevpn
->bridge_if
->name
: "-");
124 vty_out(vty
, " Tenant VRF: %s\n", vrf_id_to_name(zevpn
->vrf_id
));
126 json_object_int_add(json
, "vni", zevpn
->vni
);
127 json_object_string_add(json
, "type", "L2");
128 #if CONFDATE > 20240210
129 CPP_NOTICE("Drop `vrf` from JSON output")
131 json_object_string_add(json
, "vrf",
132 vrf_id_to_name(zevpn
->vrf_id
));
133 json_object_string_add(json
, "tenantVrf",
134 vrf_id_to_name(zevpn
->vrf_id
));
137 if (!zevpn
->vxlan_if
) { // unexpected
139 vty_out(vty
, " VxLAN interface: unknown\n");
141 json_object_string_add(json
, "vxlanInterface",
145 num_macs
= num_valid_macs(zevpn
);
146 num_neigh
= hashcount(zevpn
->neigh_table
);
148 vty_out(vty
, " VxLAN interface: %s\n", zevpn
->vxlan_if
->name
);
149 vty_out(vty
, " VxLAN ifIndex: %u\n", zevpn
->vxlan_if
->ifindex
);
150 vty_out(vty
, " SVI interface: %s\n",
151 (zevpn
->svi_if
? zevpn
->svi_if
->name
: ""));
152 vty_out(vty
, " SVI ifIndex: %u\n",
153 (zevpn
->svi_if
? zevpn
->svi_if
->ifindex
: 0));
154 vty_out(vty
, " Local VTEP IP: %pI4\n",
155 &zevpn
->local_vtep_ip
);
156 vty_out(vty
, " Mcast group: %pI4\n",
159 json_object_string_add(json
, "vxlanInterface",
160 zevpn
->vxlan_if
->name
);
161 #if CONFDATE > 20240210
162 CPP_NOTICE("Drop `ifindex` from JSON output")
164 json_object_int_add(json
, "ifindex", zevpn
->vxlan_if
->ifindex
);
165 json_object_int_add(json
, "vxlanIfindex",
166 zevpn
->vxlan_if
->ifindex
);
168 json_object_string_add(json
, "sviInterface",
169 zevpn
->svi_if
->name
);
170 json_object_int_add(json
, "sviIfindex",
171 zevpn
->svi_if
->ifindex
);
173 json_object_string_addf(json
, "vtepIp", "%pI4",
174 &zevpn
->local_vtep_ip
);
175 json_object_string_addf(json
, "mcastGroup", "%pI4",
177 json_object_string_add(json
, "advertiseGatewayMacip",
178 zevpn
->advertise_gw_macip
? "Yes"
180 json_object_string_add(json
, "advertiseSviMacip",
181 zevpn
->advertise_svi_macip
? "Yes"
183 json_object_int_add(json
, "numMacs", num_macs
);
184 json_object_int_add(json
, "numArpNd", num_neigh
);
188 vty_out(vty
, " No remote VTEPs known for this VNI\n");
190 json_object_int_add(json
, "numRemoteVteps", num_vteps
);
193 vty_out(vty
, " Remote VTEPs for this VNI:\n");
195 json_vtep_list
= json_object_new_array();
196 for (zvtep
= zevpn
->vteps
; zvtep
; zvtep
= zvtep
->next
) {
197 const char *flood_str
= lookup_msg(
198 zvtep_flood_str
, zvtep
->flood_control
,
199 VXLAN_FLOOD_STR_DEFAULT
);
202 vty_out(vty
, " %pI4 flood: %s\n",
206 json_vtep
= json_object_new_object();
207 json_object_string_addf(json_vtep
, "ip", "%pI4",
209 json_object_string_add(json_vtep
, "flood",
211 json_object_array_add(json_vtep_list
,
217 json_object_int_add(json
, "numRemoteVteps", num_vteps
);
218 json_object_object_add(json
, "remoteVteps",
224 " Number of MACs (local and remote) known for this VNI: %u\n",
227 " Number of ARPs (IPv4 and IPv6, local and remote) "
228 "known for this VNI: %u\n",
230 vty_out(vty
, " Advertise-gw-macip: %s\n",
231 zevpn
->advertise_gw_macip
? "Yes" : "No");
232 vty_out(vty
, " Advertise-svi-macip: %s\n",
233 zevpn
->advertise_svi_macip
? "Yes" : "No");
238 * Print an EVPN hash entry - called for display of all VNIs.
240 void zebra_evpn_print_hash(struct hash_bucket
*bucket
, void *ctxt
[])
243 struct zebra_evpn
*zevpn
;
244 struct zebra_vtep
*zvtep
;
245 uint32_t num_vteps
= 0;
246 uint32_t num_macs
= 0;
247 uint32_t num_neigh
= 0;
248 json_object
*json
= NULL
;
249 json_object
*json_evpn
= NULL
;
250 json_object
*json_ip_str
= NULL
;
251 json_object
*json_vtep_list
= NULL
;
252 char buf
[PREFIX_STRLEN
];
257 zevpn
= (struct zebra_evpn
*)bucket
->data
;
259 zvtep
= zevpn
->vteps
;
265 num_macs
= num_valid_macs(zevpn
);
266 num_neigh
= hashcount(zevpn
->neigh_table
);
268 vty_out(vty
, "%-10u %-4s %-21s %-8u %-8u %-15u %-37s\n",
270 zevpn
->vxlan_if
? zevpn
->vxlan_if
->name
: "unknown",
271 num_macs
, num_neigh
, num_vteps
,
272 vrf_id_to_name(zevpn
->vrf_id
));
274 char vni_str
[VNI_STR_LEN
];
275 snprintf(vni_str
, VNI_STR_LEN
, "%u", zevpn
->vni
);
276 json_evpn
= json_object_new_object();
277 json_object_int_add(json_evpn
, "vni", zevpn
->vni
);
278 json_object_string_add(json_evpn
, "type", "L2");
279 json_object_string_add(json_evpn
, "vxlanIf",
280 zevpn
->vxlan_if
? zevpn
->vxlan_if
->name
282 json_object_int_add(json_evpn
, "numMacs", num_macs
);
283 json_object_int_add(json_evpn
, "numArpNd", num_neigh
);
284 json_object_int_add(json_evpn
, "numRemoteVteps", num_vteps
);
285 json_object_string_add(json_evpn
, "tenantVrf",
286 vrf_id_to_name(zevpn
->vrf_id
));
288 json_vtep_list
= json_object_new_array();
289 for (zvtep
= zevpn
->vteps
; zvtep
; zvtep
= zvtep
->next
) {
290 json_ip_str
= json_object_new_string(
291 inet_ntop(AF_INET
, &zvtep
->vtep_ip
, buf
,
293 json_object_array_add(json_vtep_list
,
296 json_object_object_add(json_evpn
, "remoteVteps",
299 json_object_object_add(json
, vni_str
, json_evpn
);
304 * Print an EVPN hash entry in detail - called for display of all EVPNs.
306 void zebra_evpn_print_hash_detail(struct hash_bucket
*bucket
, void *data
)
309 struct zebra_evpn
*zevpn
;
310 json_object
*json_array
= NULL
;
311 bool use_json
= false;
312 struct zebra_evpn_show
*zes
= data
;
315 json_array
= zes
->json
;
316 use_json
= zes
->use_json
;
318 zevpn
= (struct zebra_evpn
*)bucket
->data
;
320 zebra_vxlan_print_vni(vty
, zes
->zvrf
, zevpn
->vni
, use_json
, json_array
);
326 int zebra_evpn_del_macip_for_intf(struct interface
*ifp
,
327 struct zebra_evpn
*zevpn
)
329 struct listnode
*cnode
= NULL
, *cnnode
= NULL
;
330 struct connected
*c
= NULL
;
331 struct ethaddr macaddr
;
333 memcpy(&macaddr
.octet
, ifp
->hw_addr
, ETH_ALEN
);
335 for (ALL_LIST_ELEMENTS(ifp
->connected
, cnode
, cnnode
, c
)) {
338 memset(&ip
, 0, sizeof(struct ipaddr
));
339 if (!CHECK_FLAG(c
->conf
, ZEBRA_IFC_REAL
))
342 if (c
->address
->family
== AF_INET
) {
343 ip
.ipa_type
= IPADDR_V4
;
344 memcpy(&(ip
.ipaddr_v4
), &(c
->address
->u
.prefix4
),
345 sizeof(struct in_addr
));
346 } else if (c
->address
->family
== AF_INET6
) {
347 ip
.ipa_type
= IPADDR_V6
;
348 memcpy(&(ip
.ipaddr_v6
), &(c
->address
->u
.prefix6
),
349 sizeof(struct in6_addr
));
354 zebra_evpn_gw_macip_del(ifp
, zevpn
, &ip
);
360 int zebra_evpn_add_macip_for_intf(struct interface
*ifp
,
361 struct zebra_evpn
*zevpn
)
363 struct listnode
*cnode
= NULL
, *cnnode
= NULL
;
364 struct connected
*c
= NULL
;
365 struct ethaddr macaddr
;
367 memcpy(&macaddr
.octet
, ifp
->hw_addr
, ETH_ALEN
);
369 for (ALL_LIST_ELEMENTS(ifp
->connected
, cnode
, cnnode
, c
)) {
372 if (!CHECK_FLAG(c
->conf
, ZEBRA_IFC_REAL
))
375 memset(&ip
, 0, sizeof(struct ipaddr
));
376 if (c
->address
->family
== AF_INET
) {
377 ip
.ipa_type
= IPADDR_V4
;
378 memcpy(&(ip
.ipaddr_v4
), &(c
->address
->u
.prefix4
),
379 sizeof(struct in_addr
));
380 } else if (c
->address
->family
== AF_INET6
) {
381 ip
.ipa_type
= IPADDR_V6
;
382 memcpy(&(ip
.ipaddr_v6
), &(c
->address
->u
.prefix6
),
383 sizeof(struct in6_addr
));
388 zebra_evpn_gw_macip_add(ifp
, zevpn
, &macaddr
, &ip
);
393 static int ip_prefix_send_to_client(vrf_id_t vrf_id
, struct prefix
*p
,
396 struct zserv
*client
= NULL
;
397 struct stream
*s
= NULL
;
399 client
= zserv_find_client(ZEBRA_ROUTE_BGP
, 0);
400 /* BGP may not be running. */
404 s
= stream_new(ZEBRA_MAX_PACKET_SIZ
);
406 zclient_create_header(s
, cmd
, vrf_id
);
407 stream_put(s
, p
, sizeof(struct prefix
));
409 /* Write packet size. */
410 stream_putw_at(s
, 0, stream_get_endp(s
));
412 if (IS_ZEBRA_DEBUG_VXLAN
)
413 zlog_debug("Send ip prefix %pFX %s on vrf %s", p
,
414 (cmd
== ZEBRA_IP_PREFIX_ROUTE_ADD
) ? "ADD" : "DEL",
415 vrf_id_to_name(vrf_id
));
417 if (cmd
== ZEBRA_IP_PREFIX_ROUTE_ADD
)
418 client
->prefixadd_cnt
++;
420 client
->prefixdel_cnt
++;
422 return zserv_send_message(client
, s
);
425 int zebra_evpn_advertise_subnet(struct zebra_evpn
*zevpn
, struct interface
*ifp
,
428 struct listnode
*cnode
= NULL
, *cnnode
= NULL
;
429 struct connected
*c
= NULL
;
430 struct ethaddr macaddr
;
432 memcpy(&macaddr
.octet
, ifp
->hw_addr
, ETH_ALEN
);
434 for (ALL_LIST_ELEMENTS(ifp
->connected
, cnode
, cnnode
, c
)) {
437 memcpy(&p
, c
->address
, sizeof(struct prefix
));
439 /* skip link local address */
440 if (IN6_IS_ADDR_LINKLOCAL(&p
.u
.prefix6
))
445 ip_prefix_send_to_client(ifp
->vrf
->vrf_id
, &p
,
446 ZEBRA_IP_PREFIX_ROUTE_ADD
);
448 ip_prefix_send_to_client(ifp
->vrf
->vrf_id
, &p
,
449 ZEBRA_IP_PREFIX_ROUTE_DEL
);
455 * zebra_evpn_gw_macip_add_to_client
457 int zebra_evpn_gw_macip_add(struct interface
*ifp
, struct zebra_evpn
*zevpn
,
458 struct ethaddr
*macaddr
, struct ipaddr
*ip
)
460 struct zebra_mac
*mac
= NULL
;
461 struct zebra_if
*zif
= NULL
;
462 struct zebra_vxlan_vni
*vni
;
464 zif
= zevpn
->vxlan_if
->info
;
468 vni
= zebra_vxlan_if_vni_find(zif
, zevpn
->vni
);
470 zebra_evpn_mac_gw_macip_add(ifp
, zevpn
, ip
, &mac
, macaddr
,
471 vni
->access_vlan
, true);
473 return zebra_evpn_neigh_gw_macip_add(ifp
, zevpn
, ip
, mac
);
477 * zebra_evpn_gw_macip_del_from_client
479 int zebra_evpn_gw_macip_del(struct interface
*ifp
, struct zebra_evpn
*zevpn
,
482 struct zebra_neigh
*n
= NULL
;
483 struct zebra_mac
*mac
= NULL
;
485 /* If the neigh entry is not present nothing to do*/
486 n
= zebra_evpn_neigh_lookup(zevpn
, ip
);
490 /* mac entry should be present */
491 mac
= zebra_evpn_mac_lookup(zevpn
, &n
->emac
);
493 if (IS_ZEBRA_DEBUG_VXLAN
)
494 zlog_debug("MAC %pEA doesn't exist for neigh %pIA on VNI %u",
495 &n
->emac
, ip
, zevpn
->vni
);
499 /* If the entry is not local nothing to do*/
500 if (!CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_LOCAL
))
503 /* only need to delete the entry from bgp if we sent it before */
504 if (IS_ZEBRA_DEBUG_VXLAN
)
506 "%u:SVI %s(%u) VNI %u, sending GW MAC %pEA IP %pIA del to BGP",
507 ifp
->vrf
->vrf_id
, ifp
->name
, ifp
->ifindex
, zevpn
->vni
,
510 /* Remove neighbor from BGP. */
511 zebra_evpn_neigh_send_del_to_client(zevpn
->vni
, &n
->ip
, &n
->emac
,
512 n
->flags
, ZEBRA_NEIGH_ACTIVE
,
515 /* Delete this neighbor entry. */
516 zebra_evpn_neigh_del(zevpn
, n
);
518 /* see if the mac needs to be deleted as well*/
520 zebra_evpn_deref_ip2mac(zevpn
, mac
);
525 void zebra_evpn_gw_macip_del_for_evpn_hash(struct hash_bucket
*bucket
,
528 struct zebra_evpn
*zevpn
= NULL
;
529 struct zebra_if
*zif
= NULL
;
530 struct zebra_vxlan_vni
*vni
= NULL
;
531 struct interface
*vlan_if
= NULL
;
532 struct interface
*vrr_if
= NULL
;
533 struct interface
*ifp
;
535 /* Add primary SVI MAC*/
536 zevpn
= (struct zebra_evpn
*)bucket
->data
;
538 /* Global (Zvrf) advertise-default-gw is disabled,
539 * but zevpn advertise-default-gw is enabled
541 if (zevpn
->advertise_gw_macip
) {
542 if (IS_ZEBRA_DEBUG_VXLAN
)
543 zlog_debug("VNI: %u GW-MACIP enabled, retain gw-macip",
548 ifp
= zevpn
->vxlan_if
;
553 /* If down or not mapped to a bridge, we're done. */
554 if (!if_is_operative(ifp
) || !zif
->brslave_info
.br_if
)
557 vni
= zebra_vxlan_if_vni_find(zif
, zevpn
->vni
);
561 vlan_if
= zvni_map_to_svi(vni
->access_vlan
, zif
->brslave_info
.br_if
);
565 /* Del primary MAC-IP */
566 zebra_evpn_del_macip_for_intf(vlan_if
, zevpn
);
568 /* Del VRR MAC-IP - if any*/
569 vrr_if
= zebra_get_vrr_intf_for_svi(vlan_if
);
571 zebra_evpn_del_macip_for_intf(vrr_if
, zevpn
);
576 void zebra_evpn_gw_macip_add_for_evpn_hash(struct hash_bucket
*bucket
,
579 struct zebra_evpn
*zevpn
= NULL
;
580 struct zebra_if
*zif
= NULL
;
581 struct interface
*vlan_if
= NULL
;
582 struct interface
*vrr_if
= NULL
;
583 struct interface
*ifp
= NULL
;
584 struct zebra_vxlan_vni
*vni
= NULL
;
586 zevpn
= (struct zebra_evpn
*)bucket
->data
;
588 ifp
= zevpn
->vxlan_if
;
593 /* If down or not mapped to a bridge, we're done. */
594 if (!if_is_operative(ifp
) || !zif
->brslave_info
.br_if
)
596 vni
= zebra_vxlan_if_vni_find(zif
, zevpn
->vni
);
600 vlan_if
= zvni_map_to_svi(vni
->access_vlan
, zif
->brslave_info
.br_if
);
604 /* Add primary SVI MAC-IP */
605 if (advertise_svi_macip_enabled(zevpn
)
606 || advertise_gw_macip_enabled(zevpn
))
607 zebra_evpn_add_macip_for_intf(vlan_if
, zevpn
);
609 if (advertise_gw_macip_enabled(zevpn
)) {
610 /* Add VRR MAC-IP - if any*/
611 vrr_if
= zebra_get_vrr_intf_for_svi(vlan_if
);
613 zebra_evpn_add_macip_for_intf(vrr_if
, zevpn
);
619 void zebra_evpn_svi_macip_del_for_evpn_hash(struct hash_bucket
*bucket
,
622 struct zebra_evpn
*zevpn
= NULL
;
623 struct zebra_if
*zif
= NULL
;
624 struct interface
*vlan_if
= NULL
;
625 struct zebra_vxlan_vni
*vni
= NULL
;
626 struct interface
*ifp
;
628 /* Add primary SVI MAC*/
629 zevpn
= (struct zebra_evpn
*)bucket
->data
;
633 /* Global(vrf) advertise-svi-ip disabled, but zevpn advertise-svi-ip
636 if (zevpn
->advertise_svi_macip
) {
637 if (IS_ZEBRA_DEBUG_VXLAN
)
638 zlog_debug("VNI: %u SVI-MACIP enabled, retain svi-macip",
643 ifp
= zevpn
->vxlan_if
;
648 /* If down or not mapped to a bridge, we're done. */
649 if (!if_is_operative(ifp
) || !zif
->brslave_info
.br_if
)
652 vni
= zebra_vxlan_if_vni_find(zif
, zevpn
->vni
);
656 vlan_if
= zvni_map_to_svi(vni
->access_vlan
, zif
->brslave_info
.br_if
);
660 /* Del primary MAC-IP */
661 zebra_evpn_del_macip_for_intf(vlan_if
, zevpn
);
666 static int zebra_evpn_map_vlan_ns(struct ns
*ns
,
671 struct zebra_ns
*zns
= ns
->info
;
672 struct route_node
*rn
;
673 struct interface
*br_if
;
674 struct zebra_evpn
**p_zevpn
= (struct zebra_evpn
**)_p_zevpn
;
675 struct zebra_evpn
*zevpn
;
676 struct interface
*tmp_if
= NULL
;
677 struct zebra_if
*zif
;
678 struct zebra_from_svi_param
*in_param
=
679 (struct zebra_from_svi_param
*)_in_param
;
682 uint8_t bridge_vlan_aware
;
684 assert(p_zevpn
&& in_param
);
686 br_if
= in_param
->br_if
;
691 bridge_vlan_aware
= in_param
->bridge_vlan_aware
;
693 if (bridge_vlan_aware
) {
694 vni_id
= zebra_l2_bridge_if_vni_find(zif
, vid
);
699 * See if this interface (or interface plus VLAN Id) maps to a
702 /* TODO: Optimize with a hash. */
703 for (rn
= route_top(zns
->if_table
); rn
; rn
= route_next(rn
)) {
704 tmp_if
= (struct interface
*)rn
->info
;
708 if (!zif
|| zif
->zif_type
!= ZEBRA_IF_VXLAN
)
710 if (!if_is_operative(tmp_if
))
713 if (zif
->brslave_info
.br_if
!= br_if
)
717 zebra_vxlan_if_access_vlan_vni_find(zif
, br_if
);
726 return NS_WALK_CONTINUE
;
728 zevpn
= zebra_evpn_lookup(vni_id
);
734 * Map port or (port, VLAN) to an EVPN. This is invoked upon getting MAC
735 * notifications, to see if they are of interest.
737 struct zebra_evpn
*zebra_evpn_map_vlan(struct interface
*ifp
,
738 struct interface
*br_if
, vlanid_t vid
)
740 struct zebra_if
*zif
;
741 struct zebra_evpn
**p_zevpn
;
742 struct zebra_evpn
*zevpn
= NULL
;
743 struct zebra_from_svi_param in_param
;
745 /* Determine if bridge is VLAN-aware or not */
748 in_param
.bridge_vlan_aware
= IS_ZEBRA_IF_BRIDGE_VLAN_AWARE(zif
);
750 in_param
.br_if
= br_if
;
754 ns_walk_func(zebra_evpn_map_vlan_ns
,
760 static int zebra_evpn_from_svi_ns(struct ns
*ns
,
764 struct zebra_ns
*zns
= ns
->info
;
765 struct route_node
*rn
;
766 struct interface
*br_if
;
767 struct zebra_evpn
**p_zevpn
= (struct zebra_evpn
**)_p_zevpn
;
768 struct zebra_evpn
*zevpn
;
769 struct interface
*tmp_if
= NULL
;
770 struct zebra_if
*zif
;
771 struct zebra_if
*br_zif
;
772 struct zebra_l2_bridge_vlan
*bvlan
;
773 struct zebra_from_svi_param
*in_param
=
774 (struct zebra_from_svi_param
*)_in_param
;
778 uint8_t bridge_vlan_aware
;
783 br_if
= in_param
->br_if
;
786 bridge_vlan_aware
= in_param
->bridge_vlan_aware
;
788 br_zif
= br_if
->info
;
791 if (bridge_vlan_aware
) {
792 bvlan
= zebra_l2_bridge_if_vlan_find(br_zif
, vid
);
793 if (bvlan
&& bvlan
->access_bd
&& bvlan
->access_bd
->vni
) {
795 vni_id
= bvlan
->access_bd
->vni
;
798 /* TODO: Optimize with a hash. */
799 for (rn
= route_top(zns
->if_table
); rn
; rn
= route_next(rn
)) {
800 tmp_if
= (struct interface
*)rn
->info
;
804 if (!zif
|| zif
->zif_type
!= ZEBRA_IF_VXLAN
)
806 if (!if_is_operative(tmp_if
))
809 if (zif
->brslave_info
.br_if
!= br_if
)
813 zebra_vxlan_if_access_vlan_vni_find(zif
, br_if
);
822 return NS_WALK_CONTINUE
;
824 zevpn
= zebra_evpn_lookup(vni_id
);
831 * Map SVI and associated bridge to an EVPN. This is invoked upon getting
832 * neighbor notifications, to see if they are of interest.
834 struct zebra_evpn
*zebra_evpn_from_svi(struct interface
*ifp
,
835 struct interface
*br_if
)
837 struct zebra_evpn
*zevpn
= NULL
;
838 struct zebra_evpn
**p_zevpn
;
839 struct zebra_if
*zif
;
840 struct zebra_from_svi_param in_param
;
845 /* Make sure the linked interface is a bridge. */
846 if (!IS_ZEBRA_IF_BRIDGE(br_if
))
849 /* Determine if bridge is VLAN-aware or not */
852 in_param
.bridge_vlan_aware
= IS_ZEBRA_IF_BRIDGE_VLAN_AWARE(zif
);
855 if (in_param
.bridge_vlan_aware
) {
856 struct zebra_l2info_vlan
*vl
;
858 if (!IS_ZEBRA_IF_VLAN(ifp
))
863 vl
= &zif
->l2info
.vl
;
864 in_param
.vid
= vl
->vid
;
867 in_param
.br_if
= br_if
;
870 /* See if this interface (or interface plus VLAN Id) maps to a VxLAN */
871 ns_walk_func(zebra_evpn_from_svi_ns
, (void *)&in_param
,
876 static int zvni_map_to_macvlan_ns(struct ns
*ns
,
880 struct zebra_ns
*zns
= ns
->info
;
881 struct zebra_from_svi_param
*in_param
=
882 (struct zebra_from_svi_param
*)_in_param
;
883 struct interface
**p_ifp
= (struct interface
**)_p_ifp
;
884 struct route_node
*rn
;
885 struct interface
*tmp_if
= NULL
;
886 struct zebra_if
*zif
;
888 assert(in_param
&& p_ifp
);
890 /* Identify corresponding VLAN interface. */
891 for (rn
= route_top(zns
->if_table
); rn
; rn
= route_next(rn
)) {
892 tmp_if
= (struct interface
*)rn
->info
;
893 /* Check oper status of the SVI. */
894 if (!tmp_if
|| !if_is_operative(tmp_if
))
898 if (!zif
|| zif
->zif_type
!= ZEBRA_IF_MACVLAN
)
901 if (zif
->link
== in_param
->svi_if
) {
907 return NS_WALK_CONTINUE
;
910 /* Map to MAC-VLAN interface corresponding to specified SVI interface.
912 struct interface
*zebra_evpn_map_to_macvlan(struct interface
*br_if
,
913 struct interface
*svi_if
)
915 struct interface
*tmp_if
= NULL
;
916 struct zebra_if
*zif
;
917 struct interface
**p_ifp
;
918 struct zebra_from_svi_param in_param
;
920 /* Defensive check, caller expected to invoke only with valid bridge. */
925 zlog_debug("svi_if is not passed.");
929 /* Determine if bridge is VLAN-aware or not */
934 in_param
.br_if
= br_if
;
936 in_param
.svi_if
= svi_if
;
939 /* Identify corresponding VLAN interface. */
940 ns_walk_func(zvni_map_to_macvlan_ns
,
947 * Install MAC hash entry - called upon access VLAN change.
949 void zebra_evpn_install_mac_hash(struct hash_bucket
*bucket
, void *ctxt
)
951 struct zebra_mac
*mac
;
952 struct mac_walk_ctx
*wctx
= ctxt
;
954 mac
= (struct zebra_mac
*)bucket
->data
;
956 if (CHECK_FLAG(mac
->flags
, ZEBRA_MAC_REMOTE
))
957 zebra_evpn_rem_mac_install(wctx
->zevpn
, mac
, false);
961 * Read and populate local MACs and neighbors corresponding to this EVPN.
963 void zebra_evpn_read_mac_neigh(struct zebra_evpn
*zevpn
, struct interface
*ifp
)
965 struct zebra_ns
*zns
;
966 struct zebra_vrf
*zvrf
;
967 struct zebra_if
*zif
;
968 struct interface
*vlan_if
;
969 struct zebra_vxlan_vni
*vni
;
970 struct interface
*vrr_if
;
973 vni
= zebra_vxlan_if_vni_find(zif
, zevpn
->vni
);
974 zvrf
= zebra_vrf_lookup_by_id(zevpn
->vrf_id
);
975 if (!zvrf
|| !zvrf
->zns
)
979 if (IS_ZEBRA_DEBUG_VXLAN
)
981 "Reading MAC FDB and Neighbors for intf %s(%u) VNI %u master %u",
982 ifp
->name
, ifp
->ifindex
, zevpn
->vni
,
983 zif
->brslave_info
.bridge_ifindex
);
985 macfdb_read_for_bridge(zns
, ifp
, zif
->brslave_info
.br_if
,
987 /* We need to specifically read and retrieve the entry for BUM handling
988 * via multicast, if any.
990 macfdb_read_mcast_entry_for_vni(zns
, ifp
, zevpn
->vni
);
991 vlan_if
= zvni_map_to_svi(vni
->access_vlan
, zif
->brslave_info
.br_if
);
994 zebra_evpn_acc_bd_svi_mac_add(vlan_if
);
997 if (advertise_svi_macip_enabled(zevpn
)
998 || advertise_gw_macip_enabled(zevpn
))
999 zebra_evpn_add_macip_for_intf(vlan_if
, zevpn
);
1001 /* Add VRR MAC-IP - if any*/
1002 if (advertise_gw_macip_enabled(zevpn
)) {
1003 vrr_if
= zebra_get_vrr_intf_for_svi(vlan_if
);
1005 zebra_evpn_add_macip_for_intf(vrr_if
, zevpn
);
1008 neigh_read_for_vlan(zns
, vlan_if
);
1013 * Hash function for EVPN.
1015 unsigned int zebra_evpn_hash_keymake(const void *p
)
1017 const struct zebra_evpn
*zevpn
= p
;
1019 return (jhash_1word(zevpn
->vni
, 0));
1023 * Compare 2 evpn hash entries.
1025 bool zebra_evpn_hash_cmp(const void *p1
, const void *p2
)
1027 const struct zebra_evpn
*zevpn1
= p1
;
1028 const struct zebra_evpn
*zevpn2
= p2
;
1030 return (zevpn1
->vni
== zevpn2
->vni
);
1033 int zebra_evpn_list_cmp(void *p1
, void *p2
)
1035 const struct zebra_evpn
*zevpn1
= p1
;
1036 const struct zebra_evpn
*zevpn2
= p2
;
1038 if (zevpn1
->vni
== zevpn2
->vni
)
1040 return (zevpn1
->vni
< zevpn2
->vni
) ? -1 : 1;
1044 * Callback to allocate VNI hash entry.
1046 void *zebra_evpn_alloc(void *p
)
1048 const struct zebra_evpn
*tmp_vni
= p
;
1049 struct zebra_evpn
*zevpn
;
1051 zevpn
= XCALLOC(MTYPE_ZEVPN
, sizeof(struct zebra_evpn
));
1052 zevpn
->vni
= tmp_vni
->vni
;
1053 return ((void *)zevpn
);
1057 * Look up EVPN hash entry.
1059 struct zebra_evpn
*zebra_evpn_lookup(vni_t vni
)
1061 struct zebra_vrf
*zvrf
;
1062 struct zebra_evpn tmp_vni
;
1063 struct zebra_evpn
*zevpn
= NULL
;
1065 zvrf
= zebra_vrf_get_evpn();
1066 memset(&tmp_vni
, 0, sizeof(tmp_vni
));
1068 zevpn
= hash_lookup(zvrf
->evpn_table
, &tmp_vni
);
1074 * Add EVPN hash entry.
1076 struct zebra_evpn
*zebra_evpn_add(vni_t vni
)
1079 struct zebra_vrf
*zvrf
;
1080 struct zebra_evpn tmp_zevpn
;
1081 struct zebra_evpn
*zevpn
= NULL
;
1083 zvrf
= zebra_vrf_get_evpn();
1084 memset(&tmp_zevpn
, 0, sizeof(tmp_zevpn
));
1085 tmp_zevpn
.vni
= vni
;
1086 zevpn
= hash_get(zvrf
->evpn_table
, &tmp_zevpn
, zebra_evpn_alloc
);
1088 zebra_evpn_es_evi_init(zevpn
);
1090 snprintf(buffer
, sizeof(buffer
), "Zebra EVPN MAC Table vni: %u", vni
);
1091 /* Create hash table for MAC */
1092 zevpn
->mac_table
= zebra_mac_db_create(buffer
);
1094 snprintf(buffer
, sizeof(buffer
), "Zebra EVPN Neighbor Table vni: %u",
1096 /* Create hash table for neighbors */
1097 zevpn
->neigh_table
= zebra_neigh_db_create(buffer
);
1103 * Delete EVPN hash entry.
1105 int zebra_evpn_del(struct zebra_evpn
*zevpn
)
1107 struct zebra_vrf
*zvrf
;
1108 struct zebra_evpn
*tmp_zevpn
;
1110 zvrf
= zebra_vrf_get_evpn();
1112 zevpn
->svi_if
= NULL
;
1114 /* Free the neighbor hash table. */
1115 hash_free(zevpn
->neigh_table
);
1116 zevpn
->neigh_table
= NULL
;
1118 /* Free the MAC hash table. */
1119 hash_free(zevpn
->mac_table
);
1120 zevpn
->mac_table
= NULL
;
1122 /* Remove references to the zevpn in the MH databases */
1123 if (zevpn
->vxlan_if
)
1124 zebra_evpn_vxl_evpn_set(zevpn
->vxlan_if
->info
, zevpn
, false);
1125 zebra_evpn_es_evi_cleanup(zevpn
);
1127 /* Free the EVPN hash entry and allocated memory. */
1128 tmp_zevpn
= hash_release(zvrf
->evpn_table
, zevpn
);
1129 XFREE(MTYPE_ZEVPN
, tmp_zevpn
);
1135 * Inform BGP about local EVPN addition.
1137 int zebra_evpn_send_add_to_client(struct zebra_evpn
*zevpn
)
1139 struct zserv
*client
;
1141 ifindex_t svi_index
;
1144 client
= zserv_find_client(ZEBRA_ROUTE_BGP
, 0);
1145 /* BGP may not be running. */
1149 svi_index
= zevpn
->svi_if
? zevpn
->svi_if
->ifindex
: 0;
1151 s
= stream_new(ZEBRA_MAX_PACKET_SIZ
);
1153 zclient_create_header(s
, ZEBRA_VNI_ADD
, zebra_vrf_get_evpn_id());
1154 stream_putl(s
, zevpn
->vni
);
1155 stream_put_in_addr(s
, &zevpn
->local_vtep_ip
);
1156 stream_put(s
, &zevpn
->vrf_id
, sizeof(vrf_id_t
)); /* tenant vrf */
1157 stream_put_in_addr(s
, &zevpn
->mcast_grp
);
1158 stream_put(s
, &svi_index
, sizeof(ifindex_t
));
1160 /* Write packet size. */
1161 stream_putw_at(s
, 0, stream_get_endp(s
));
1163 if (IS_ZEBRA_DEBUG_VXLAN
)
1165 "Send EVPN_ADD %u %pI4 tenant vrf %s(%u) SVI index %u to %s",
1166 zevpn
->vni
, &zevpn
->local_vtep_ip
,
1167 vrf_id_to_name(zevpn
->vrf_id
), zevpn
->vrf_id
,
1168 (zevpn
->svi_if
? zevpn
->svi_if
->ifindex
: 0),
1169 zebra_route_string(client
->proto
));
1171 client
->vniadd_cnt
++;
1172 rc
= zserv_send_message(client
, s
);
1174 if (!(zevpn
->flags
& ZEVPN_READY_FOR_BGP
)) {
1175 zevpn
->flags
|= ZEVPN_READY_FOR_BGP
;
1176 /* once the EVPN is sent the ES-EVIs can also be replayed
1179 zebra_evpn_update_all_es(zevpn
);
1185 * Inform BGP about local EVPN deletion.
1187 int zebra_evpn_send_del_to_client(struct zebra_evpn
*zevpn
)
1189 struct zserv
*client
;
1192 client
= zserv_find_client(ZEBRA_ROUTE_BGP
, 0);
1193 /* BGP may not be running. */
1197 if (zevpn
->flags
& ZEVPN_READY_FOR_BGP
) {
1198 zevpn
->flags
&= ~ZEVPN_READY_FOR_BGP
;
1199 /* the ES-EVIs must be removed from BGP before the EVPN is */
1200 zebra_evpn_update_all_es(zevpn
);
1203 s
= stream_new(ZEBRA_MAX_PACKET_SIZ
);
1206 zclient_create_header(s
, ZEBRA_VNI_DEL
, zebra_vrf_get_evpn_id());
1207 stream_putl(s
, zevpn
->vni
);
1209 /* Write packet size. */
1210 stream_putw_at(s
, 0, stream_get_endp(s
));
1212 if (IS_ZEBRA_DEBUG_VXLAN
)
1213 zlog_debug("Send EVPN_DEL %u to %s", zevpn
->vni
,
1214 zebra_route_string(client
->proto
));
1216 client
->vnidel_cnt
++;
1217 return zserv_send_message(client
, s
);
1221 * See if remote VTEP matches with prefix.
1223 static int zebra_evpn_vtep_match(struct in_addr
*vtep_ip
,
1224 struct zebra_vtep
*zvtep
)
1226 return (IPV4_ADDR_SAME(vtep_ip
, &zvtep
->vtep_ip
));
1230 * Locate remote VTEP in EVPN hash table.
1232 struct zebra_vtep
*zebra_evpn_vtep_find(struct zebra_evpn
*zevpn
,
1233 struct in_addr
*vtep_ip
)
1235 struct zebra_vtep
*zvtep
;
1240 for (zvtep
= zevpn
->vteps
; zvtep
; zvtep
= zvtep
->next
) {
1241 if (zebra_evpn_vtep_match(vtep_ip
, zvtep
))
1249 * Add remote VTEP to EVPN hash table.
1251 struct zebra_vtep
*zebra_evpn_vtep_add(struct zebra_evpn
*zevpn
,
1252 struct in_addr
*vtep_ip
,
1256 struct zebra_vtep
*zvtep
;
1258 zvtep
= XCALLOC(MTYPE_ZEVPN_VTEP
, sizeof(struct zebra_vtep
));
1260 zvtep
->vtep_ip
= *vtep_ip
;
1261 zvtep
->flood_control
= flood_control
;
1264 zevpn
->vteps
->prev
= zvtep
;
1265 zvtep
->next
= zevpn
->vteps
;
1266 zevpn
->vteps
= zvtep
;
1272 * Remove remote VTEP from EVPN hash table.
1274 int zebra_evpn_vtep_del(struct zebra_evpn
*zevpn
, struct zebra_vtep
*zvtep
)
1277 zvtep
->next
->prev
= zvtep
->prev
;
1279 zvtep
->prev
->next
= zvtep
->next
;
1281 zevpn
->vteps
= zvtep
->next
;
1283 zvtep
->prev
= zvtep
->next
= NULL
;
1284 XFREE(MTYPE_ZEVPN_VTEP
, zvtep
);
1290 * Delete all remote VTEPs for this EVPN (upon VNI delete). Also
1291 * uninstall from kernel if asked to.
1293 int zebra_evpn_vtep_del_all(struct zebra_evpn
*zevpn
, int uninstall
)
1295 struct zebra_vtep
*zvtep
, *zvtep_next
;
1300 for (zvtep
= zevpn
->vteps
; zvtep
; zvtep
= zvtep_next
) {
1301 zvtep_next
= zvtep
->next
;
1303 zebra_evpn_vtep_uninstall(zevpn
, &zvtep
->vtep_ip
);
1304 zebra_evpn_vtep_del(zevpn
, zvtep
);
1311 * Install remote VTEP into the kernel if the remote VTEP has asked
1312 * for head-end-replication.
1314 int zebra_evpn_vtep_install(struct zebra_evpn
*zevpn
, struct zebra_vtep
*zvtep
)
1316 if (is_vxlan_flooding_head_end() &&
1317 (zvtep
->flood_control
== VXLAN_FLOOD_HEAD_END_REPL
)) {
1318 if (ZEBRA_DPLANE_REQUEST_FAILURE
==
1319 dplane_vtep_add(zevpn
->vxlan_if
,
1320 &zvtep
->vtep_ip
, zevpn
->vni
))
1328 * Uninstall remote VTEP from the kernel.
1330 int zebra_evpn_vtep_uninstall(struct zebra_evpn
*zevpn
, struct in_addr
*vtep_ip
)
1332 if (!zevpn
->vxlan_if
) {
1333 zlog_debug("VNI %u hash %p couldn't be uninstalled - no intf",
1338 if (ZEBRA_DPLANE_REQUEST_FAILURE
==
1339 dplane_vtep_delete(zevpn
->vxlan_if
, vtep_ip
, zevpn
->vni
))
1346 * Install or uninstall flood entries in the kernel corresponding to
1347 * remote VTEPs. This is invoked upon change to BUM handling.
1349 void zebra_evpn_handle_flooding_remote_vteps(struct hash_bucket
*bucket
,
1352 struct zebra_evpn
*zevpn
;
1353 struct zebra_vtep
*zvtep
;
1355 zevpn
= (struct zebra_evpn
*)bucket
->data
;
1359 for (zvtep
= zevpn
->vteps
; zvtep
; zvtep
= zvtep
->next
) {
1360 if (is_vxlan_flooding_head_end())
1361 zebra_evpn_vtep_install(zevpn
, zvtep
);
1363 zebra_evpn_vtep_uninstall(zevpn
, &zvtep
->vtep_ip
);
1368 * Cleanup EVPN/VTEP and update kernel
1370 void zebra_evpn_cleanup_all(struct hash_bucket
*bucket
, void *arg
)
1372 struct zebra_evpn
*zevpn
= NULL
;
1374 zevpn
= (struct zebra_evpn
*)bucket
->data
;
1376 /* Free up all neighbors and MACs, if any. */
1377 zebra_evpn_neigh_del_all(zevpn
, 1, 0, DEL_ALL_NEIGH
);
1378 zebra_evpn_mac_del_all(zevpn
, 1, 0, DEL_ALL_MAC
);
1380 /* Free up all remote VTEPs, if any. */
1381 zebra_evpn_vtep_del_all(zevpn
, 1);
1383 /* Delete the hash entry. */
1384 zebra_evpn_del(zevpn
);
1387 static void zebra_evpn_process_sync_macip_add(struct zebra_evpn
*zevpn
,
1388 const struct ethaddr
*macaddr
,
1390 const struct ipaddr
*ipaddr
,
1391 uint8_t flags
, uint32_t seq
,
1394 char ipbuf
[INET6_ADDRSTRLEN
];
1397 struct zebra_neigh
*n
= NULL
;
1398 struct zebra_mac
*mac
= NULL
;
1400 sticky
= !!CHECK_FLAG(flags
, ZEBRA_MACIP_TYPE_STICKY
);
1401 remote_gw
= !!CHECK_FLAG(flags
, ZEBRA_MACIP_TYPE_GW
);
1402 /* if sticky or remote-gw ignore updates from the peer */
1403 if (sticky
|| remote_gw
) {
1404 if (IS_ZEBRA_DEBUG_VXLAN
|| IS_ZEBRA_DEBUG_EVPN_MH_NEIGH
1405 || IS_ZEBRA_DEBUG_EVPN_MH_MAC
)
1407 "Ignore sync-macip vni %u mac %pEA%s%s%s%s",
1410 ipa_len
? " IP " : "",
1411 ipa_len
? ipaddr2str(ipaddr
, ipbuf
,
1414 sticky
? " sticky" : "",
1415 remote_gw
? " remote_gw" : "");
1421 (void)zebra_evpn_proc_sync_mac_update(zevpn
, macaddr
, ipa_len
,
1422 ipaddr
, flags
, seq
, esi
);
1425 mac
= zebra_evpn_mac_lookup(zevpn
, macaddr
);
1427 mac
= zebra_evpn_proc_sync_mac_update(zevpn
, macaddr
,
1434 n
= zebra_evpn_neigh_lookup(zevpn
, ipaddr
);
1436 && !zebra_evpn_neigh_is_bgp_seq_ok(zevpn
, n
, macaddr
, seq
,
1440 zebra_evpn_proc_sync_neigh_update(zevpn
, n
, ipa_len
, ipaddr
,
1441 flags
, seq
, esi
, mac
);
1445 /************************** remote mac-ip handling **************************/
1446 /* Process a remote MACIP add from BGP. */
1447 void zebra_evpn_rem_macip_add(vni_t vni
, const struct ethaddr
*macaddr
,
1448 uint16_t ipa_len
, const struct ipaddr
*ipaddr
,
1449 uint8_t flags
, uint32_t seq
,
1450 struct in_addr vtep_ip
, const esi_t
*esi
)
1452 struct zebra_evpn
*zevpn
;
1453 struct zebra_vtep
*zvtep
;
1454 struct zebra_mac
*mac
= NULL
;
1455 struct interface
*ifp
= NULL
;
1456 struct zebra_if
*zif
= NULL
;
1457 struct zebra_vrf
*zvrf
;
1459 /* Locate EVPN hash entry - expected to exist. */
1460 zevpn
= zebra_evpn_lookup(vni
);
1462 if (IS_ZEBRA_DEBUG_VXLAN
)
1463 zlog_debug("Unknown VNI %u upon remote MACIP ADD", vni
);
1467 ifp
= zevpn
->vxlan_if
;
1470 if (!ifp
|| !if_is_operative(ifp
) || !zif
|| !zif
->brslave_info
.br_if
) {
1471 if (IS_ZEBRA_DEBUG_VXLAN
)
1473 "Ignoring remote MACIP ADD VNI %u, invalid interface state or info",
1478 /* Type-2 routes from another PE can be interpreted as remote or
1479 * SYNC based on the destination ES -
1480 * SYNC - if ES is local
1481 * REMOTE - if ES is not local
1483 if (flags
& ZEBRA_MACIP_TYPE_SYNC_PATH
) {
1484 struct zebra_evpn_es
*es
;
1486 es
= zebra_evpn_es_find(esi
);
1487 if (es
&& (es
->flags
& ZEBRA_EVPNES_READY_FOR_BGP
)) {
1488 zebra_evpn_process_sync_macip_add(zevpn
, macaddr
,
1492 if (IS_ZEBRA_DEBUG_EVPN_MH_ES
) {
1493 char esi_str
[ESI_STR_LEN
];
1495 esi_to_str(esi
, esi_str
, sizeof(esi_str
));
1497 "Ignore sync-macip add; ES %s is not ready",
1505 /* The remote VTEP specified should normally exist, but it is
1506 * possible that when peering comes up, peer may advertise MACIP
1507 * routes before advertising type-3 routes.
1509 if (vtep_ip
.s_addr
) {
1510 zvtep
= zebra_evpn_vtep_find(zevpn
, &vtep_ip
);
1512 zvtep
= zebra_evpn_vtep_add(zevpn
, &vtep_ip
,
1513 VXLAN_FLOOD_DISABLED
);
1516 EC_ZEBRA_VTEP_ADD_FAILED
,
1517 "Failed to add remote VTEP, VNI %u zevpn %p upon remote MACIP ADD",
1522 zebra_evpn_vtep_install(zevpn
, zvtep
);
1526 zvrf
= zebra_vrf_get_evpn();
1532 zebra_evpn_mac_remote_macip_add(zevpn
, zvrf
, macaddr
, vtep_ip
,
1536 * Add auto MAC if it doesn't exist.
1538 mac
= zebra_evpn_mac_lookup(zevpn
, macaddr
);
1540 mac
= zebra_evpn_mac_add_auto(zevpn
, macaddr
);
1542 if (IS_ZEBRA_DEBUG_VXLAN
)
1544 "Neigh %pIA: MAC %pEA not found, Auto MAC created",
1548 zebra_evpn_neigh_remote_macip_add(zevpn
, zvrf
, ipaddr
, mac
,
1549 vtep_ip
, flags
, seq
);
1553 /* Process a remote MACIP delete from BGP. */
1554 void zebra_evpn_rem_macip_del(vni_t vni
, const struct ethaddr
*macaddr
,
1555 uint16_t ipa_len
, const struct ipaddr
*ipaddr
,
1556 struct in_addr vtep_ip
)
1558 struct zebra_evpn
*zevpn
;
1559 struct zebra_mac
*mac
= NULL
;
1560 struct zebra_neigh
*n
= NULL
;
1561 struct interface
*ifp
= NULL
;
1562 struct zebra_if
*zif
= NULL
;
1563 struct zebra_ns
*zns
;
1564 struct zebra_vxlan_vni
*vnip
;
1565 struct zebra_vrf
*zvrf
;
1566 char buf1
[INET6_ADDRSTRLEN
];
1568 /* Locate EVPN hash entry - expected to exist. */
1569 zevpn
= zebra_evpn_lookup(vni
);
1571 if (IS_ZEBRA_DEBUG_VXLAN
)
1572 zlog_debug("Unknown VNI %u upon remote MACIP DEL", vni
);
1576 ifp
= zevpn
->vxlan_if
;
1579 if (!ifp
|| !if_is_operative(ifp
) || !zif
|| !zif
->brslave_info
.br_if
) {
1580 if (IS_ZEBRA_DEBUG_VXLAN
)
1582 "Ignoring remote MACIP DEL VNI %u, invalid interface state or info",
1586 zns
= zebra_ns_lookup(NS_DEFAULT
);
1587 vnip
= zebra_vxlan_if_vni_find(zif
, vni
);
1589 if (IS_ZEBRA_DEBUG_VXLAN
)
1591 "VNI %u not in interface upon remote MACIP DEL",
1596 mac
= zebra_evpn_mac_lookup(zevpn
, macaddr
);
1598 n
= zebra_evpn_neigh_lookup(zevpn
, ipaddr
);
1602 "Failed to locate MAC %pEA for Neigh %pIA VNI %u upon remote MACIP DEL",
1603 macaddr
, ipaddr
, vni
);
1607 /* If the remote mac or neighbor doesn't exist there is nothing
1608 * more to do. Otherwise, uninstall the entry and then remove it.
1611 if (IS_ZEBRA_DEBUG_VXLAN
)
1613 "Failed to locate MAC %pEA & Neigh %pIA VNI %u upon remote MACIP DEL",
1614 macaddr
, ipaddr
, vni
);
1618 zvrf
= zevpn
->vxlan_if
->vrf
->info
;
1620 /* Ignore the delete if this mac is a gateway mac-ip */
1621 if (CHECK_FLAG(mac
->flags
, ZEBRA_MAC_LOCAL
)
1622 && CHECK_FLAG(mac
->flags
, ZEBRA_MAC_DEF_GW
)) {
1624 "Ignore remote MACIP DEL VNI %u MAC %pEA%s%s as MAC is already configured as gateway MAC",
1626 ipa_len
? " IP " : "",
1627 ipa_len
? ipaddr2str(ipaddr
, buf1
, sizeof(buf1
)) : "");
1631 /* Uninstall remote neighbor or MAC. */
1633 zebra_evpn_neigh_remote_uninstall(zevpn
, zvrf
, n
, mac
, ipaddr
);
1635 /* DAD: when MAC is freeze state as remote learn event,
1636 * remote mac-ip delete event is received will result in freeze
1637 * entry removal, first fetch kernel for the same entry present
1638 * as LOCAL and reachable, avoid deleting this entry instead
1639 * use kerenel local entry to update during unfreeze time.
1641 if (zvrf
->dad_freeze
1642 && CHECK_FLAG(mac
->flags
, ZEBRA_MAC_DUPLICATE
)
1643 && CHECK_FLAG(mac
->flags
, ZEBRA_MAC_REMOTE
)) {
1644 if (IS_ZEBRA_DEBUG_VXLAN
)
1646 "%s: MAC %pEA (flags 0x%x) is remote and duplicate, read kernel for local entry",
1647 __func__
, macaddr
, mac
->flags
);
1648 macfdb_read_specific_mac(zns
, zif
->brslave_info
.br_if
,
1649 macaddr
, vnip
->access_vlan
);
1652 if (CHECK_FLAG(mac
->flags
, ZEBRA_MAC_LOCAL
)) {
1654 zebra_evpn_sync_mac_del(mac
);
1655 } else if (CHECK_FLAG(mac
->flags
, ZEBRA_NEIGH_REMOTE
)) {
1656 zebra_evpn_rem_mac_del(zevpn
, mac
);
1661 /************************** EVPN BGP config management ************************/
1662 void zebra_evpn_cfg_cleanup(struct hash_bucket
*bucket
, void *ctxt
)
1664 struct zebra_evpn
*zevpn
= NULL
;
1666 zevpn
= (struct zebra_evpn
*)bucket
->data
;
1667 zevpn
->advertise_gw_macip
= 0;
1668 zevpn
->advertise_svi_macip
= 0;
1669 zevpn
->advertise_subnet
= 0;
1671 zebra_evpn_neigh_del_all(zevpn
, 1, 0,
1672 DEL_REMOTE_NEIGH
| DEL_REMOTE_NEIGH_FROM_VTEP
);
1673 zebra_evpn_mac_del_all(zevpn
, 1, 0,
1674 DEL_REMOTE_MAC
| DEL_REMOTE_MAC_FROM_VTEP
);
1675 zebra_evpn_vtep_del_all(zevpn
, 1);