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_l2_bridge_if.h"
32 #include "zebra/zebra_ns.h"
33 #include "zebra/zebra_vrf.h"
34 #include "zebra/zebra_vxlan.h"
35 #include "zebra/zebra_vxlan_private.h"
36 #include "zebra/zebra_evpn.h"
37 #include "zebra/zebra_evpn_mac.h"
38 #include "zebra/zebra_evpn_neigh.h"
39 #include "zebra/zebra_evpn_mh.h"
40 #include "zebra/zebra_evpn_vxlan.h"
41 #include "zebra/zebra_router.h"
43 DEFINE_MTYPE_STATIC(ZEBRA
, ZEVPN
, "VNI hash");
44 DEFINE_MTYPE_STATIC(ZEBRA
, ZEVPN_VTEP
, "VNI remote VTEP");
47 #define VXLAN_FLOOD_STR_NO_INFO "-"
48 #define VXLAN_FLOOD_STR_DEFAULT VXLAN_FLOOD_STR_NO_INFO
49 static const struct message zvtep_flood_str
[] = {
50 {VXLAN_FLOOD_DISABLED
, VXLAN_FLOOD_STR_NO_INFO
},
51 {VXLAN_FLOOD_PIM_SM
, "PIM-SM"},
52 {VXLAN_FLOOD_HEAD_END_REPL
, "HER"},
56 int advertise_gw_macip_enabled(struct zebra_evpn
*zevpn
)
58 struct zebra_vrf
*zvrf
;
60 zvrf
= zebra_vrf_get_evpn();
61 if (zvrf
->advertise_gw_macip
)
64 if (zevpn
&& zevpn
->advertise_gw_macip
)
70 int advertise_svi_macip_enabled(struct zebra_evpn
*zevpn
)
72 struct zebra_vrf
*zvrf
;
74 zvrf
= zebra_vrf_get_evpn();
75 if (zvrf
->advertise_svi_macip
)
78 if (zevpn
&& zevpn
->advertise_svi_macip
)
85 * Print a specific EVPN entry.
87 void zebra_evpn_print(struct zebra_evpn
*zevpn
, void **ctxt
)
90 struct vty
*vty
= NULL
;
91 struct zebra_vtep
*zvtep
= NULL
;
92 uint32_t num_macs
= 0;
93 uint32_t num_neigh
= 0;
94 uint32_t num_vteps
= 0;
95 json_object
*json
= NULL
;
96 json_object
*json_vtep_list
= NULL
;
97 json_object
*json_vtep
= NULL
;
103 vty_out(vty
, "VNI: %u\n", zevpn
->vni
);
104 vty_out(vty
, " Type: %s\n", "L2");
105 vty_out(vty
, " Vlan: %u\n", zevpn
->vid
);
106 vty_out(vty
, " Bridge: %s\n",
107 zevpn
->bridge_if
? zevpn
->bridge_if
->name
: "-");
108 vty_out(vty
, " Tenant VRF: %s\n", vrf_id_to_name(zevpn
->vrf_id
));
110 json_object_int_add(json
, "vni", zevpn
->vni
);
111 json_object_string_add(json
, "type", "L2");
112 #if CONFDATE > 20240210
113 CPP_NOTICE("Drop `vrf` from JSON output")
115 json_object_string_add(json
, "vrf",
116 vrf_id_to_name(zevpn
->vrf_id
));
117 json_object_string_add(json
, "tenantVrf",
118 vrf_id_to_name(zevpn
->vrf_id
));
121 if (!zevpn
->vxlan_if
) { // unexpected
123 vty_out(vty
, " VxLAN interface: unknown\n");
125 json_object_string_add(json
, "vxlanInterface",
129 num_macs
= num_valid_macs(zevpn
);
130 num_neigh
= hashcount(zevpn
->neigh_table
);
132 vty_out(vty
, " VxLAN interface: %s\n", zevpn
->vxlan_if
->name
);
133 vty_out(vty
, " VxLAN ifIndex: %u\n", zevpn
->vxlan_if
->ifindex
);
134 vty_out(vty
, " SVI interface: %s\n",
135 (zevpn
->svi_if
? zevpn
->svi_if
->name
: ""));
136 vty_out(vty
, " SVI ifIndex: %u\n",
137 (zevpn
->svi_if
? zevpn
->svi_if
->ifindex
: 0));
138 vty_out(vty
, " Local VTEP IP: %pI4\n",
139 &zevpn
->local_vtep_ip
);
140 vty_out(vty
, " Mcast group: %pI4\n",
143 json_object_string_add(json
, "vxlanInterface",
144 zevpn
->vxlan_if
->name
);
145 #if CONFDATE > 20240210
146 CPP_NOTICE("Drop `ifindex` from JSON output")
148 json_object_int_add(json
, "ifindex", zevpn
->vxlan_if
->ifindex
);
149 json_object_int_add(json
, "vxlanIfindex",
150 zevpn
->vxlan_if
->ifindex
);
152 json_object_string_add(json
, "sviInterface",
153 zevpn
->svi_if
->name
);
154 json_object_int_add(json
, "sviIfindex",
155 zevpn
->svi_if
->ifindex
);
157 json_object_string_addf(json
, "vtepIp", "%pI4",
158 &zevpn
->local_vtep_ip
);
159 json_object_string_addf(json
, "mcastGroup", "%pI4",
161 json_object_string_add(json
, "advertiseGatewayMacip",
162 zevpn
->advertise_gw_macip
? "Yes"
164 json_object_string_add(json
, "advertiseSviMacip",
165 zevpn
->advertise_svi_macip
? "Yes"
167 json_object_int_add(json
, "numMacs", num_macs
);
168 json_object_int_add(json
, "numArpNd", num_neigh
);
172 vty_out(vty
, " No remote VTEPs known for this VNI\n");
174 json_object_int_add(json
, "numRemoteVteps", num_vteps
);
177 vty_out(vty
, " Remote VTEPs for this VNI:\n");
179 json_vtep_list
= json_object_new_array();
180 for (zvtep
= zevpn
->vteps
; zvtep
; zvtep
= zvtep
->next
) {
181 const char *flood_str
= lookup_msg(
182 zvtep_flood_str
, zvtep
->flood_control
,
183 VXLAN_FLOOD_STR_DEFAULT
);
186 vty_out(vty
, " %pI4 flood: %s\n",
190 json_vtep
= json_object_new_object();
191 json_object_string_addf(json_vtep
, "ip", "%pI4",
193 json_object_string_add(json_vtep
, "flood",
195 json_object_array_add(json_vtep_list
,
201 json_object_int_add(json
, "numRemoteVteps", num_vteps
);
202 json_object_object_add(json
, "remoteVteps",
208 " Number of MACs (local and remote) known for this VNI: %u\n",
211 " Number of ARPs (IPv4 and IPv6, local and remote) "
212 "known for this VNI: %u\n",
214 vty_out(vty
, " Advertise-gw-macip: %s\n",
215 zevpn
->advertise_gw_macip
? "Yes" : "No");
216 vty_out(vty
, " Advertise-svi-macip: %s\n",
217 zevpn
->advertise_svi_macip
? "Yes" : "No");
222 * Print an EVPN hash entry - called for display of all VNIs.
224 void zebra_evpn_print_hash(struct hash_bucket
*bucket
, void *ctxt
[])
227 struct zebra_evpn
*zevpn
;
228 struct zebra_vtep
*zvtep
;
229 uint32_t num_vteps
= 0;
230 uint32_t num_macs
= 0;
231 uint32_t num_neigh
= 0;
232 json_object
*json
= NULL
;
233 json_object
*json_evpn
= NULL
;
234 json_object
*json_ip_str
= NULL
;
235 json_object
*json_vtep_list
= NULL
;
236 char buf
[PREFIX_STRLEN
];
241 zevpn
= (struct zebra_evpn
*)bucket
->data
;
243 zvtep
= zevpn
->vteps
;
249 num_macs
= num_valid_macs(zevpn
);
250 num_neigh
= hashcount(zevpn
->neigh_table
);
252 vty_out(vty
, "%-10u %-4s %-21s %-8u %-8u %-15u %-37s\n",
254 zevpn
->vxlan_if
? zevpn
->vxlan_if
->name
: "unknown",
255 num_macs
, num_neigh
, num_vteps
,
256 vrf_id_to_name(zevpn
->vrf_id
));
258 char vni_str
[VNI_STR_LEN
];
259 snprintf(vni_str
, VNI_STR_LEN
, "%u", zevpn
->vni
);
260 json_evpn
= json_object_new_object();
261 json_object_int_add(json_evpn
, "vni", zevpn
->vni
);
262 json_object_string_add(json_evpn
, "type", "L2");
263 json_object_string_add(json_evpn
, "vxlanIf",
264 zevpn
->vxlan_if
? zevpn
->vxlan_if
->name
266 json_object_int_add(json_evpn
, "numMacs", num_macs
);
267 json_object_int_add(json_evpn
, "numArpNd", num_neigh
);
268 json_object_int_add(json_evpn
, "numRemoteVteps", num_vteps
);
269 json_object_string_add(json_evpn
, "tenantVrf",
270 vrf_id_to_name(zevpn
->vrf_id
));
272 json_vtep_list
= json_object_new_array();
273 for (zvtep
= zevpn
->vteps
; zvtep
; zvtep
= zvtep
->next
) {
274 json_ip_str
= json_object_new_string(
275 inet_ntop(AF_INET
, &zvtep
->vtep_ip
, buf
,
277 json_object_array_add(json_vtep_list
,
280 json_object_object_add(json_evpn
, "remoteVteps",
283 json_object_object_add(json
, vni_str
, json_evpn
);
288 * Print an EVPN hash entry in detail - called for display of all EVPNs.
290 void zebra_evpn_print_hash_detail(struct hash_bucket
*bucket
, void *data
)
293 struct zebra_evpn
*zevpn
;
294 json_object
*json_array
= NULL
;
295 bool use_json
= false;
296 struct zebra_evpn_show
*zes
= data
;
299 json_array
= zes
->json
;
300 use_json
= zes
->use_json
;
302 zevpn
= (struct zebra_evpn
*)bucket
->data
;
304 zebra_vxlan_print_vni(vty
, zes
->zvrf
, zevpn
->vni
, use_json
, json_array
);
310 int zebra_evpn_del_macip_for_intf(struct interface
*ifp
,
311 struct zebra_evpn
*zevpn
)
313 struct listnode
*cnode
= NULL
, *cnnode
= NULL
;
314 struct connected
*c
= NULL
;
315 struct ethaddr macaddr
;
317 memcpy(&macaddr
.octet
, ifp
->hw_addr
, ETH_ALEN
);
319 for (ALL_LIST_ELEMENTS(ifp
->connected
, cnode
, cnnode
, c
)) {
322 memset(&ip
, 0, sizeof(struct ipaddr
));
323 if (!CHECK_FLAG(c
->conf
, ZEBRA_IFC_REAL
))
326 if (c
->address
->family
== AF_INET
) {
327 ip
.ipa_type
= IPADDR_V4
;
328 memcpy(&(ip
.ipaddr_v4
), &(c
->address
->u
.prefix4
),
329 sizeof(struct in_addr
));
330 } else if (c
->address
->family
== AF_INET6
) {
331 ip
.ipa_type
= IPADDR_V6
;
332 memcpy(&(ip
.ipaddr_v6
), &(c
->address
->u
.prefix6
),
333 sizeof(struct in6_addr
));
338 zebra_evpn_gw_macip_del(ifp
, zevpn
, &ip
);
344 int zebra_evpn_add_macip_for_intf(struct interface
*ifp
,
345 struct zebra_evpn
*zevpn
)
347 struct listnode
*cnode
= NULL
, *cnnode
= NULL
;
348 struct connected
*c
= NULL
;
349 struct ethaddr macaddr
;
351 memcpy(&macaddr
.octet
, ifp
->hw_addr
, ETH_ALEN
);
353 for (ALL_LIST_ELEMENTS(ifp
->connected
, cnode
, cnnode
, c
)) {
356 if (!CHECK_FLAG(c
->conf
, ZEBRA_IFC_REAL
))
359 memset(&ip
, 0, sizeof(struct ipaddr
));
360 if (c
->address
->family
== AF_INET
) {
361 ip
.ipa_type
= IPADDR_V4
;
362 memcpy(&(ip
.ipaddr_v4
), &(c
->address
->u
.prefix4
),
363 sizeof(struct in_addr
));
364 } else if (c
->address
->family
== AF_INET6
) {
365 ip
.ipa_type
= IPADDR_V6
;
366 memcpy(&(ip
.ipaddr_v6
), &(c
->address
->u
.prefix6
),
367 sizeof(struct in6_addr
));
372 zebra_evpn_gw_macip_add(ifp
, zevpn
, &macaddr
, &ip
);
377 static int ip_prefix_send_to_client(vrf_id_t vrf_id
, struct prefix
*p
,
380 struct zserv
*client
= NULL
;
381 struct stream
*s
= NULL
;
383 client
= zserv_find_client(ZEBRA_ROUTE_BGP
, 0);
384 /* BGP may not be running. */
388 s
= stream_new(ZEBRA_MAX_PACKET_SIZ
);
390 zclient_create_header(s
, cmd
, vrf_id
);
391 stream_put(s
, p
, sizeof(struct prefix
));
393 /* Write packet size. */
394 stream_putw_at(s
, 0, stream_get_endp(s
));
396 if (IS_ZEBRA_DEBUG_VXLAN
)
397 zlog_debug("Send ip prefix %pFX %s on vrf %s", p
,
398 (cmd
== ZEBRA_IP_PREFIX_ROUTE_ADD
) ? "ADD" : "DEL",
399 vrf_id_to_name(vrf_id
));
401 if (cmd
== ZEBRA_IP_PREFIX_ROUTE_ADD
)
402 client
->prefixadd_cnt
++;
404 client
->prefixdel_cnt
++;
406 return zserv_send_message(client
, s
);
409 int zebra_evpn_advertise_subnet(struct zebra_evpn
*zevpn
, struct interface
*ifp
,
412 struct listnode
*cnode
= NULL
, *cnnode
= NULL
;
413 struct connected
*c
= NULL
;
414 struct ethaddr macaddr
;
416 memcpy(&macaddr
.octet
, ifp
->hw_addr
, ETH_ALEN
);
418 for (ALL_LIST_ELEMENTS(ifp
->connected
, cnode
, cnnode
, c
)) {
421 memcpy(&p
, c
->address
, sizeof(struct prefix
));
423 /* skip link local address */
424 if (IN6_IS_ADDR_LINKLOCAL(&p
.u
.prefix6
))
429 ip_prefix_send_to_client(ifp
->vrf
->vrf_id
, &p
,
430 ZEBRA_IP_PREFIX_ROUTE_ADD
);
432 ip_prefix_send_to_client(ifp
->vrf
->vrf_id
, &p
,
433 ZEBRA_IP_PREFIX_ROUTE_DEL
);
439 * zebra_evpn_gw_macip_add_to_client
441 int zebra_evpn_gw_macip_add(struct interface
*ifp
, struct zebra_evpn
*zevpn
,
442 struct ethaddr
*macaddr
, struct ipaddr
*ip
)
444 struct zebra_mac
*mac
= NULL
;
445 struct zebra_if
*zif
= NULL
;
446 struct zebra_vxlan_vni
*vni
;
448 zif
= zevpn
->vxlan_if
->info
;
452 vni
= zebra_vxlan_if_vni_find(zif
, zevpn
->vni
);
454 zebra_evpn_mac_gw_macip_add(ifp
, zevpn
, ip
, &mac
, macaddr
,
455 vni
->access_vlan
, true);
457 return zebra_evpn_neigh_gw_macip_add(ifp
, zevpn
, ip
, mac
);
461 * zebra_evpn_gw_macip_del_from_client
463 int zebra_evpn_gw_macip_del(struct interface
*ifp
, struct zebra_evpn
*zevpn
,
466 struct zebra_neigh
*n
= NULL
;
467 struct zebra_mac
*mac
= NULL
;
469 /* If the neigh entry is not present nothing to do*/
470 n
= zebra_evpn_neigh_lookup(zevpn
, ip
);
474 /* mac entry should be present */
475 mac
= zebra_evpn_mac_lookup(zevpn
, &n
->emac
);
477 if (IS_ZEBRA_DEBUG_VXLAN
)
478 zlog_debug("MAC %pEA doesn't exist for neigh %pIA on VNI %u",
479 &n
->emac
, ip
, zevpn
->vni
);
483 /* If the entry is not local nothing to do*/
484 if (!CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_LOCAL
))
487 /* only need to delete the entry from bgp if we sent it before */
488 if (IS_ZEBRA_DEBUG_VXLAN
)
490 "%u:SVI %s(%u) VNI %u, sending GW MAC %pEA IP %pIA del to BGP",
491 ifp
->vrf
->vrf_id
, ifp
->name
, ifp
->ifindex
, zevpn
->vni
,
494 /* Remove neighbor from BGP. */
495 zebra_evpn_neigh_send_del_to_client(zevpn
->vni
, &n
->ip
, &n
->emac
,
496 n
->flags
, ZEBRA_NEIGH_ACTIVE
,
499 /* Delete this neighbor entry. */
500 zebra_evpn_neigh_del(zevpn
, n
);
502 /* see if the mac needs to be deleted as well*/
504 zebra_evpn_deref_ip2mac(zevpn
, mac
);
509 void zebra_evpn_gw_macip_del_for_evpn_hash(struct hash_bucket
*bucket
,
512 struct zebra_evpn
*zevpn
= NULL
;
513 struct zebra_if
*zif
= NULL
;
514 struct zebra_vxlan_vni
*vni
= NULL
;
515 struct interface
*vlan_if
= NULL
;
516 struct interface
*vrr_if
= NULL
;
517 struct interface
*ifp
;
519 /* Add primary SVI MAC*/
520 zevpn
= (struct zebra_evpn
*)bucket
->data
;
522 /* Global (Zvrf) advertise-default-gw is disabled,
523 * but zevpn advertise-default-gw is enabled
525 if (zevpn
->advertise_gw_macip
) {
526 if (IS_ZEBRA_DEBUG_VXLAN
)
527 zlog_debug("VNI: %u GW-MACIP enabled, retain gw-macip",
532 ifp
= zevpn
->vxlan_if
;
537 /* If down or not mapped to a bridge, we're done. */
538 if (!if_is_operative(ifp
) || !zif
->brslave_info
.br_if
)
541 vni
= zebra_vxlan_if_vni_find(zif
, zevpn
->vni
);
545 vlan_if
= zvni_map_to_svi(vni
->access_vlan
, zif
->brslave_info
.br_if
);
549 /* Del primary MAC-IP */
550 zebra_evpn_del_macip_for_intf(vlan_if
, zevpn
);
552 /* Del VRR MAC-IP - if any*/
553 vrr_if
= zebra_get_vrr_intf_for_svi(vlan_if
);
555 zebra_evpn_del_macip_for_intf(vrr_if
, zevpn
);
560 void zebra_evpn_gw_macip_add_for_evpn_hash(struct hash_bucket
*bucket
,
563 struct zebra_evpn
*zevpn
= NULL
;
564 struct zebra_if
*zif
= NULL
;
565 struct interface
*vlan_if
= NULL
;
566 struct interface
*vrr_if
= NULL
;
567 struct interface
*ifp
= NULL
;
568 struct zebra_vxlan_vni
*vni
= NULL
;
570 zevpn
= (struct zebra_evpn
*)bucket
->data
;
572 ifp
= zevpn
->vxlan_if
;
577 /* If down or not mapped to a bridge, we're done. */
578 if (!if_is_operative(ifp
) || !zif
->brslave_info
.br_if
)
580 vni
= zebra_vxlan_if_vni_find(zif
, zevpn
->vni
);
584 vlan_if
= zvni_map_to_svi(vni
->access_vlan
, zif
->brslave_info
.br_if
);
588 /* Add primary SVI MAC-IP */
589 if (advertise_svi_macip_enabled(zevpn
)
590 || advertise_gw_macip_enabled(zevpn
))
591 zebra_evpn_add_macip_for_intf(vlan_if
, zevpn
);
593 if (advertise_gw_macip_enabled(zevpn
)) {
594 /* Add VRR MAC-IP - if any*/
595 vrr_if
= zebra_get_vrr_intf_for_svi(vlan_if
);
597 zebra_evpn_add_macip_for_intf(vrr_if
, zevpn
);
603 void zebra_evpn_svi_macip_del_for_evpn_hash(struct hash_bucket
*bucket
,
606 struct zebra_evpn
*zevpn
= NULL
;
607 struct zebra_if
*zif
= NULL
;
608 struct interface
*vlan_if
= NULL
;
609 struct zebra_vxlan_vni
*vni
= NULL
;
610 struct interface
*ifp
;
612 /* Add primary SVI MAC*/
613 zevpn
= (struct zebra_evpn
*)bucket
->data
;
617 /* Global(vrf) advertise-svi-ip disabled, but zevpn advertise-svi-ip
620 if (zevpn
->advertise_svi_macip
) {
621 if (IS_ZEBRA_DEBUG_VXLAN
)
622 zlog_debug("VNI: %u SVI-MACIP enabled, retain svi-macip",
627 ifp
= zevpn
->vxlan_if
;
632 /* If down or not mapped to a bridge, we're done. */
633 if (!if_is_operative(ifp
) || !zif
->brslave_info
.br_if
)
636 vni
= zebra_vxlan_if_vni_find(zif
, zevpn
->vni
);
640 vlan_if
= zvni_map_to_svi(vni
->access_vlan
, zif
->brslave_info
.br_if
);
644 /* Del primary MAC-IP */
645 zebra_evpn_del_macip_for_intf(vlan_if
, zevpn
);
650 static int zebra_evpn_map_vlan_ns(struct ns
*ns
,
655 struct zebra_ns
*zns
= ns
->info
;
656 struct route_node
*rn
;
657 struct interface
*br_if
;
658 struct zebra_evpn
**p_zevpn
= (struct zebra_evpn
**)_p_zevpn
;
659 struct zebra_evpn
*zevpn
;
660 struct interface
*tmp_if
= NULL
;
661 struct zebra_if
*zif
;
662 struct zebra_from_svi_param
*in_param
=
663 (struct zebra_from_svi_param
*)_in_param
;
666 uint8_t bridge_vlan_aware
;
668 assert(p_zevpn
&& in_param
);
670 br_if
= in_param
->br_if
;
675 bridge_vlan_aware
= in_param
->bridge_vlan_aware
;
677 if (bridge_vlan_aware
) {
678 vni_id
= zebra_l2_bridge_if_vni_find(zif
, vid
);
683 * See if this interface (or interface plus VLAN Id) maps to a
686 /* TODO: Optimize with a hash. */
687 for (rn
= route_top(zns
->if_table
); rn
; rn
= route_next(rn
)) {
688 tmp_if
= (struct interface
*)rn
->info
;
692 if (!zif
|| zif
->zif_type
!= ZEBRA_IF_VXLAN
)
694 if (!if_is_operative(tmp_if
))
697 if (zif
->brslave_info
.br_if
!= br_if
)
701 zebra_vxlan_if_access_vlan_vni_find(zif
, br_if
);
710 return NS_WALK_CONTINUE
;
712 zevpn
= zebra_evpn_lookup(vni_id
);
718 * Map port or (port, VLAN) to an EVPN. This is invoked upon getting MAC
719 * notifications, to see if they are of interest.
721 struct zebra_evpn
*zebra_evpn_map_vlan(struct interface
*ifp
,
722 struct interface
*br_if
, vlanid_t vid
)
724 struct zebra_if
*zif
;
725 struct zebra_evpn
**p_zevpn
;
726 struct zebra_evpn
*zevpn
= NULL
;
727 struct zebra_from_svi_param in_param
;
729 /* Determine if bridge is VLAN-aware or not */
732 in_param
.bridge_vlan_aware
= IS_ZEBRA_IF_BRIDGE_VLAN_AWARE(zif
);
734 in_param
.br_if
= br_if
;
738 ns_walk_func(zebra_evpn_map_vlan_ns
,
744 static int zebra_evpn_from_svi_ns(struct ns
*ns
,
748 struct zebra_ns
*zns
= ns
->info
;
749 struct route_node
*rn
;
750 struct interface
*br_if
;
751 struct zebra_evpn
**p_zevpn
= (struct zebra_evpn
**)_p_zevpn
;
752 struct zebra_evpn
*zevpn
;
753 struct interface
*tmp_if
= NULL
;
754 struct zebra_if
*zif
;
755 struct zebra_if
*br_zif
;
756 struct zebra_l2_bridge_vlan
*bvlan
;
757 struct zebra_from_svi_param
*in_param
=
758 (struct zebra_from_svi_param
*)_in_param
;
762 uint8_t bridge_vlan_aware
;
767 br_if
= in_param
->br_if
;
770 bridge_vlan_aware
= in_param
->bridge_vlan_aware
;
772 br_zif
= br_if
->info
;
775 if (bridge_vlan_aware
) {
776 bvlan
= zebra_l2_bridge_if_vlan_find(br_zif
, vid
);
777 if (bvlan
&& bvlan
->access_bd
&& bvlan
->access_bd
->vni
) {
779 vni_id
= bvlan
->access_bd
->vni
;
782 /* TODO: Optimize with a hash. */
783 for (rn
= route_top(zns
->if_table
); rn
; rn
= route_next(rn
)) {
784 tmp_if
= (struct interface
*)rn
->info
;
788 if (!zif
|| zif
->zif_type
!= ZEBRA_IF_VXLAN
)
790 if (!if_is_operative(tmp_if
))
793 if (zif
->brslave_info
.br_if
!= br_if
)
797 zebra_vxlan_if_access_vlan_vni_find(zif
, br_if
);
806 return NS_WALK_CONTINUE
;
808 zevpn
= zebra_evpn_lookup(vni_id
);
815 * Map SVI and associated bridge to an EVPN. This is invoked upon getting
816 * neighbor notifications, to see if they are of interest.
818 struct zebra_evpn
*zebra_evpn_from_svi(struct interface
*ifp
,
819 struct interface
*br_if
)
821 struct zebra_evpn
*zevpn
= NULL
;
822 struct zebra_evpn
**p_zevpn
;
823 struct zebra_if
*zif
;
824 struct zebra_from_svi_param in_param
;
829 /* Make sure the linked interface is a bridge. */
830 if (!IS_ZEBRA_IF_BRIDGE(br_if
))
833 /* Determine if bridge is VLAN-aware or not */
836 in_param
.bridge_vlan_aware
= IS_ZEBRA_IF_BRIDGE_VLAN_AWARE(zif
);
839 if (in_param
.bridge_vlan_aware
) {
840 struct zebra_l2info_vlan
*vl
;
842 if (!IS_ZEBRA_IF_VLAN(ifp
))
847 vl
= &zif
->l2info
.vl
;
848 in_param
.vid
= vl
->vid
;
851 in_param
.br_if
= br_if
;
854 /* See if this interface (or interface plus VLAN Id) maps to a VxLAN */
855 ns_walk_func(zebra_evpn_from_svi_ns
, (void *)&in_param
,
860 static int zvni_map_to_macvlan_ns(struct ns
*ns
,
864 struct zebra_ns
*zns
= ns
->info
;
865 struct zebra_from_svi_param
*in_param
=
866 (struct zebra_from_svi_param
*)_in_param
;
867 struct interface
**p_ifp
= (struct interface
**)_p_ifp
;
868 struct route_node
*rn
;
869 struct interface
*tmp_if
= NULL
;
870 struct zebra_if
*zif
;
872 assert(in_param
&& p_ifp
);
874 /* Identify corresponding VLAN interface. */
875 for (rn
= route_top(zns
->if_table
); rn
; rn
= route_next(rn
)) {
876 tmp_if
= (struct interface
*)rn
->info
;
877 /* Check oper status of the SVI. */
878 if (!tmp_if
|| !if_is_operative(tmp_if
))
882 if (!zif
|| zif
->zif_type
!= ZEBRA_IF_MACVLAN
)
885 if (zif
->link
== in_param
->svi_if
) {
891 return NS_WALK_CONTINUE
;
894 /* Map to MAC-VLAN interface corresponding to specified SVI interface.
896 struct interface
*zebra_evpn_map_to_macvlan(struct interface
*br_if
,
897 struct interface
*svi_if
)
899 struct interface
*tmp_if
= NULL
;
900 struct zebra_if
*zif
;
901 struct interface
**p_ifp
;
902 struct zebra_from_svi_param in_param
;
904 /* Defensive check, caller expected to invoke only with valid bridge. */
909 zlog_debug("svi_if is not passed.");
913 /* Determine if bridge is VLAN-aware or not */
918 in_param
.br_if
= br_if
;
920 in_param
.svi_if
= svi_if
;
923 /* Identify corresponding VLAN interface. */
924 ns_walk_func(zvni_map_to_macvlan_ns
,
931 * Uninstall MAC hash entry - called upon access VLAN change.
933 static void zebra_evpn_uninstall_mac_hash(struct hash_bucket
*bucket
,
936 struct zebra_mac
*mac
;
937 struct mac_walk_ctx
*wctx
= ctxt
;
939 mac
= (struct zebra_mac
*)bucket
->data
;
941 if (CHECK_FLAG(mac
->flags
, ZEBRA_MAC_REMOTE
))
942 zebra_evpn_rem_mac_uninstall(wctx
->zevpn
, mac
, false);
946 * Install MAC hash entry - called upon access VLAN change.
948 static void zebra_evpn_install_mac_hash(struct hash_bucket
*bucket
, void *ctxt
)
950 struct zebra_mac
*mac
;
951 struct mac_walk_ctx
*wctx
= ctxt
;
953 mac
= (struct zebra_mac
*)bucket
->data
;
955 if (CHECK_FLAG(mac
->flags
, ZEBRA_MAC_REMOTE
))
956 zebra_evpn_rem_mac_install(wctx
->zevpn
, mac
, false);
960 * Uninstall remote MAC entries for this EVPN.
962 void zebra_evpn_rem_mac_uninstall_all(struct zebra_evpn
*zevpn
)
964 struct mac_walk_ctx wctx
;
966 if (!zevpn
->mac_table
)
969 memset(&wctx
, 0, sizeof(struct mac_walk_ctx
));
973 wctx
.flags
= ZEBRA_MAC_REMOTE
;
975 hash_iterate(zevpn
->mac_table
, zebra_evpn_uninstall_mac_hash
, &wctx
);
979 * Install remote MAC entries for this EVPN.
981 void zebra_evpn_rem_mac_install_all(struct zebra_evpn
*zevpn
)
983 struct mac_walk_ctx wctx
;
985 if (!zevpn
->mac_table
)
988 memset(&wctx
, 0, sizeof(struct mac_walk_ctx
));
992 wctx
.flags
= ZEBRA_MAC_REMOTE
;
994 hash_iterate(zevpn
->mac_table
, zebra_evpn_install_mac_hash
, &wctx
);
998 * Read and populate local MACs and neighbors corresponding to this EVPN.
1000 void zebra_evpn_read_mac_neigh(struct zebra_evpn
*zevpn
, struct interface
*ifp
)
1002 struct zebra_ns
*zns
;
1003 struct zebra_vrf
*zvrf
;
1004 struct zebra_if
*zif
;
1005 struct interface
*vlan_if
;
1006 struct zebra_vxlan_vni
*vni
;
1007 struct interface
*vrr_if
;
1010 vni
= zebra_vxlan_if_vni_find(zif
, zevpn
->vni
);
1011 zvrf
= zebra_vrf_lookup_by_id(zevpn
->vrf_id
);
1012 if (!zvrf
|| !zvrf
->zns
)
1016 if (IS_ZEBRA_DEBUG_VXLAN
)
1018 "Reading MAC FDB and Neighbors for intf %s(%u) VNI %u master %u",
1019 ifp
->name
, ifp
->ifindex
, zevpn
->vni
,
1020 zif
->brslave_info
.bridge_ifindex
);
1022 macfdb_read_for_bridge(zns
, ifp
, zif
->brslave_info
.br_if
,
1024 /* We need to specifically read and retrieve the entry for BUM handling
1025 * via multicast, if any.
1027 macfdb_read_mcast_entry_for_vni(zns
, ifp
, zevpn
->vni
);
1028 vlan_if
= zvni_map_to_svi(vni
->access_vlan
, zif
->brslave_info
.br_if
);
1031 zebra_evpn_acc_bd_svi_mac_add(vlan_if
);
1033 /* Add SVI MAC-IP */
1034 if (advertise_svi_macip_enabled(zevpn
)
1035 || advertise_gw_macip_enabled(zevpn
))
1036 zebra_evpn_add_macip_for_intf(vlan_if
, zevpn
);
1038 /* Add VRR MAC-IP - if any*/
1039 if (advertise_gw_macip_enabled(zevpn
)) {
1040 vrr_if
= zebra_get_vrr_intf_for_svi(vlan_if
);
1042 zebra_evpn_add_macip_for_intf(vrr_if
, zevpn
);
1045 neigh_read_for_vlan(zns
, vlan_if
);
1050 * Hash function for EVPN.
1052 unsigned int zebra_evpn_hash_keymake(const void *p
)
1054 const struct zebra_evpn
*zevpn
= p
;
1056 return (jhash_1word(zevpn
->vni
, 0));
1060 * Compare 2 evpn hash entries.
1062 bool zebra_evpn_hash_cmp(const void *p1
, const void *p2
)
1064 const struct zebra_evpn
*zevpn1
= p1
;
1065 const struct zebra_evpn
*zevpn2
= p2
;
1067 return (zevpn1
->vni
== zevpn2
->vni
);
1070 int zebra_evpn_list_cmp(void *p1
, void *p2
)
1072 const struct zebra_evpn
*zevpn1
= p1
;
1073 const struct zebra_evpn
*zevpn2
= p2
;
1075 if (zevpn1
->vni
== zevpn2
->vni
)
1077 return (zevpn1
->vni
< zevpn2
->vni
) ? -1 : 1;
1081 * Callback to allocate VNI hash entry.
1083 void *zebra_evpn_alloc(void *p
)
1085 const struct zebra_evpn
*tmp_vni
= p
;
1086 struct zebra_evpn
*zevpn
;
1088 zevpn
= XCALLOC(MTYPE_ZEVPN
, sizeof(struct zebra_evpn
));
1089 zevpn
->vni
= tmp_vni
->vni
;
1090 return ((void *)zevpn
);
1094 * Look up EVPN hash entry.
1096 struct zebra_evpn
*zebra_evpn_lookup(vni_t vni
)
1098 struct zebra_vrf
*zvrf
;
1099 struct zebra_evpn tmp_vni
;
1100 struct zebra_evpn
*zevpn
= NULL
;
1102 zvrf
= zebra_vrf_get_evpn();
1103 memset(&tmp_vni
, 0, sizeof(tmp_vni
));
1105 zevpn
= hash_lookup(zvrf
->evpn_table
, &tmp_vni
);
1111 * Add EVPN hash entry.
1113 struct zebra_evpn
*zebra_evpn_add(vni_t vni
)
1116 struct zebra_vrf
*zvrf
;
1117 struct zebra_evpn tmp_zevpn
;
1118 struct zebra_evpn
*zevpn
= NULL
;
1120 zvrf
= zebra_vrf_get_evpn();
1121 memset(&tmp_zevpn
, 0, sizeof(tmp_zevpn
));
1122 tmp_zevpn
.vni
= vni
;
1123 zevpn
= hash_get(zvrf
->evpn_table
, &tmp_zevpn
, zebra_evpn_alloc
);
1125 zebra_evpn_es_evi_init(zevpn
);
1127 snprintf(buffer
, sizeof(buffer
), "Zebra EVPN MAC Table vni: %u", vni
);
1128 /* Create hash table for MAC */
1129 zevpn
->mac_table
= zebra_mac_db_create(buffer
);
1131 snprintf(buffer
, sizeof(buffer
), "Zebra EVPN Neighbor Table vni: %u",
1133 /* Create hash table for neighbors */
1134 zevpn
->neigh_table
= zebra_neigh_db_create(buffer
);
1140 * Delete EVPN hash entry.
1142 int zebra_evpn_del(struct zebra_evpn
*zevpn
)
1144 struct zebra_vrf
*zvrf
;
1145 struct zebra_evpn
*tmp_zevpn
;
1147 zvrf
= zebra_vrf_get_evpn();
1149 zevpn
->svi_if
= NULL
;
1151 /* Free the neighbor hash table. */
1152 hash_free(zevpn
->neigh_table
);
1153 zevpn
->neigh_table
= NULL
;
1155 /* Free the MAC hash table. */
1156 hash_free(zevpn
->mac_table
);
1157 zevpn
->mac_table
= NULL
;
1159 /* Remove references to the zevpn in the MH databases */
1160 if (zevpn
->vxlan_if
)
1161 zebra_evpn_vxl_evpn_set(zevpn
->vxlan_if
->info
, zevpn
, false);
1162 zebra_evpn_es_evi_cleanup(zevpn
);
1164 /* Free the EVPN hash entry and allocated memory. */
1165 tmp_zevpn
= hash_release(zvrf
->evpn_table
, zevpn
);
1166 XFREE(MTYPE_ZEVPN
, tmp_zevpn
);
1172 * Inform BGP about local EVPN addition.
1174 int zebra_evpn_send_add_to_client(struct zebra_evpn
*zevpn
)
1176 struct zserv
*client
;
1178 ifindex_t svi_index
;
1181 client
= zserv_find_client(ZEBRA_ROUTE_BGP
, 0);
1182 /* BGP may not be running. */
1186 svi_index
= zevpn
->svi_if
? zevpn
->svi_if
->ifindex
: 0;
1188 s
= stream_new(ZEBRA_MAX_PACKET_SIZ
);
1190 zclient_create_header(s
, ZEBRA_VNI_ADD
, zebra_vrf_get_evpn_id());
1191 stream_putl(s
, zevpn
->vni
);
1192 stream_put_in_addr(s
, &zevpn
->local_vtep_ip
);
1193 stream_put(s
, &zevpn
->vrf_id
, sizeof(vrf_id_t
)); /* tenant vrf */
1194 stream_put_in_addr(s
, &zevpn
->mcast_grp
);
1195 stream_put(s
, &svi_index
, sizeof(ifindex_t
));
1197 /* Write packet size. */
1198 stream_putw_at(s
, 0, stream_get_endp(s
));
1200 if (IS_ZEBRA_DEBUG_VXLAN
)
1202 "Send EVPN_ADD %u %pI4 tenant vrf %s(%u) SVI index %u to %s",
1203 zevpn
->vni
, &zevpn
->local_vtep_ip
,
1204 vrf_id_to_name(zevpn
->vrf_id
), zevpn
->vrf_id
,
1205 (zevpn
->svi_if
? zevpn
->svi_if
->ifindex
: 0),
1206 zebra_route_string(client
->proto
));
1208 client
->vniadd_cnt
++;
1209 rc
= zserv_send_message(client
, s
);
1211 if (!(zevpn
->flags
& ZEVPN_READY_FOR_BGP
)) {
1212 zevpn
->flags
|= ZEVPN_READY_FOR_BGP
;
1213 /* once the EVPN is sent the ES-EVIs can also be replayed
1216 zebra_evpn_update_all_es(zevpn
);
1222 * Inform BGP about local EVPN deletion.
1224 int zebra_evpn_send_del_to_client(struct zebra_evpn
*zevpn
)
1226 struct zserv
*client
;
1229 client
= zserv_find_client(ZEBRA_ROUTE_BGP
, 0);
1230 /* BGP may not be running. */
1234 if (zevpn
->flags
& ZEVPN_READY_FOR_BGP
) {
1235 zevpn
->flags
&= ~ZEVPN_READY_FOR_BGP
;
1236 /* the ES-EVIs must be removed from BGP before the EVPN is */
1237 zebra_evpn_update_all_es(zevpn
);
1240 s
= stream_new(ZEBRA_MAX_PACKET_SIZ
);
1243 zclient_create_header(s
, ZEBRA_VNI_DEL
, zebra_vrf_get_evpn_id());
1244 stream_putl(s
, zevpn
->vni
);
1246 /* Write packet size. */
1247 stream_putw_at(s
, 0, stream_get_endp(s
));
1249 if (IS_ZEBRA_DEBUG_VXLAN
)
1250 zlog_debug("Send EVPN_DEL %u to %s", zevpn
->vni
,
1251 zebra_route_string(client
->proto
));
1253 client
->vnidel_cnt
++;
1254 return zserv_send_message(client
, s
);
1258 * See if remote VTEP matches with prefix.
1260 static int zebra_evpn_vtep_match(struct in_addr
*vtep_ip
,
1261 struct zebra_vtep
*zvtep
)
1263 return (IPV4_ADDR_SAME(vtep_ip
, &zvtep
->vtep_ip
));
1267 * Locate remote VTEP in EVPN hash table.
1269 struct zebra_vtep
*zebra_evpn_vtep_find(struct zebra_evpn
*zevpn
,
1270 struct in_addr
*vtep_ip
)
1272 struct zebra_vtep
*zvtep
;
1277 for (zvtep
= zevpn
->vteps
; zvtep
; zvtep
= zvtep
->next
) {
1278 if (zebra_evpn_vtep_match(vtep_ip
, zvtep
))
1286 * Add remote VTEP to EVPN hash table.
1288 struct zebra_vtep
*zebra_evpn_vtep_add(struct zebra_evpn
*zevpn
,
1289 struct in_addr
*vtep_ip
,
1293 struct zebra_vtep
*zvtep
;
1295 zvtep
= XCALLOC(MTYPE_ZEVPN_VTEP
, sizeof(struct zebra_vtep
));
1297 zvtep
->vtep_ip
= *vtep_ip
;
1298 zvtep
->flood_control
= flood_control
;
1301 zevpn
->vteps
->prev
= zvtep
;
1302 zvtep
->next
= zevpn
->vteps
;
1303 zevpn
->vteps
= zvtep
;
1309 * Remove remote VTEP from EVPN hash table.
1311 int zebra_evpn_vtep_del(struct zebra_evpn
*zevpn
, struct zebra_vtep
*zvtep
)
1314 zvtep
->next
->prev
= zvtep
->prev
;
1316 zvtep
->prev
->next
= zvtep
->next
;
1318 zevpn
->vteps
= zvtep
->next
;
1320 zvtep
->prev
= zvtep
->next
= NULL
;
1321 XFREE(MTYPE_ZEVPN_VTEP
, zvtep
);
1327 * Delete all remote VTEPs for this EVPN (upon VNI delete). Also
1328 * uninstall from kernel if asked to.
1330 int zebra_evpn_vtep_del_all(struct zebra_evpn
*zevpn
, int uninstall
)
1332 struct zebra_vtep
*zvtep
, *zvtep_next
;
1337 for (zvtep
= zevpn
->vteps
; zvtep
; zvtep
= zvtep_next
) {
1338 zvtep_next
= zvtep
->next
;
1340 zebra_evpn_vtep_uninstall(zevpn
, &zvtep
->vtep_ip
);
1341 zebra_evpn_vtep_del(zevpn
, zvtep
);
1348 * Install remote VTEP into the kernel if the remote VTEP has asked
1349 * for head-end-replication.
1351 int zebra_evpn_vtep_install(struct zebra_evpn
*zevpn
, struct zebra_vtep
*zvtep
)
1353 if (is_vxlan_flooding_head_end() &&
1354 (zvtep
->flood_control
== VXLAN_FLOOD_HEAD_END_REPL
)) {
1355 if (ZEBRA_DPLANE_REQUEST_FAILURE
==
1356 dplane_vtep_add(zevpn
->vxlan_if
,
1357 &zvtep
->vtep_ip
, zevpn
->vni
))
1365 * Uninstall remote VTEP from the kernel.
1367 int zebra_evpn_vtep_uninstall(struct zebra_evpn
*zevpn
, struct in_addr
*vtep_ip
)
1369 if (!zevpn
->vxlan_if
) {
1370 zlog_debug("VNI %u hash %p couldn't be uninstalled - no intf",
1375 if (ZEBRA_DPLANE_REQUEST_FAILURE
==
1376 dplane_vtep_delete(zevpn
->vxlan_if
, vtep_ip
, zevpn
->vni
))
1383 * Install or uninstall flood entries in the kernel corresponding to
1384 * remote VTEPs. This is invoked upon change to BUM handling.
1386 void zebra_evpn_handle_flooding_remote_vteps(struct hash_bucket
*bucket
,
1389 struct zebra_evpn
*zevpn
;
1390 struct zebra_vtep
*zvtep
;
1392 zevpn
= (struct zebra_evpn
*)bucket
->data
;
1396 for (zvtep
= zevpn
->vteps
; zvtep
; zvtep
= zvtep
->next
) {
1397 if (is_vxlan_flooding_head_end())
1398 zebra_evpn_vtep_install(zevpn
, zvtep
);
1400 zebra_evpn_vtep_uninstall(zevpn
, &zvtep
->vtep_ip
);
1405 * Cleanup EVPN/VTEP and update kernel
1407 void zebra_evpn_cleanup_all(struct hash_bucket
*bucket
, void *arg
)
1409 struct zebra_evpn
*zevpn
= NULL
;
1411 zevpn
= (struct zebra_evpn
*)bucket
->data
;
1413 /* Free up all neighbors and MACs, if any. */
1414 zebra_evpn_neigh_del_all(zevpn
, 1, 0, DEL_ALL_NEIGH
);
1415 zebra_evpn_mac_del_all(zevpn
, 1, 0, DEL_ALL_MAC
);
1417 /* Free up all remote VTEPs, if any. */
1418 zebra_evpn_vtep_del_all(zevpn
, 1);
1420 /* Delete the hash entry. */
1421 zebra_evpn_del(zevpn
);
1424 static void zebra_evpn_process_sync_macip_add(struct zebra_evpn
*zevpn
,
1425 const struct ethaddr
*macaddr
,
1427 const struct ipaddr
*ipaddr
,
1428 uint8_t flags
, uint32_t seq
,
1431 char ipbuf
[INET6_ADDRSTRLEN
];
1434 struct zebra_neigh
*n
= NULL
;
1435 struct zebra_mac
*mac
= NULL
;
1437 sticky
= !!CHECK_FLAG(flags
, ZEBRA_MACIP_TYPE_STICKY
);
1438 remote_gw
= !!CHECK_FLAG(flags
, ZEBRA_MACIP_TYPE_GW
);
1439 /* if sticky or remote-gw ignore updates from the peer */
1440 if (sticky
|| remote_gw
) {
1441 if (IS_ZEBRA_DEBUG_VXLAN
|| IS_ZEBRA_DEBUG_EVPN_MH_NEIGH
1442 || IS_ZEBRA_DEBUG_EVPN_MH_MAC
)
1444 "Ignore sync-macip vni %u mac %pEA%s%s%s%s",
1447 ipa_len
? " IP " : "",
1448 ipa_len
? ipaddr2str(ipaddr
, ipbuf
,
1451 sticky
? " sticky" : "",
1452 remote_gw
? " remote_gw" : "");
1458 (void)zebra_evpn_proc_sync_mac_update(zevpn
, macaddr
, ipa_len
,
1459 ipaddr
, flags
, seq
, esi
);
1462 mac
= zebra_evpn_mac_lookup(zevpn
, macaddr
);
1464 mac
= zebra_evpn_proc_sync_mac_update(zevpn
, macaddr
,
1471 n
= zebra_evpn_neigh_lookup(zevpn
, ipaddr
);
1473 && !zebra_evpn_neigh_is_bgp_seq_ok(zevpn
, n
, macaddr
, seq
,
1477 zebra_evpn_proc_sync_neigh_update(zevpn
, n
, ipa_len
, ipaddr
,
1478 flags
, seq
, esi
, mac
);
1482 /************************** remote mac-ip handling **************************/
1483 /* Process a remote MACIP add from BGP. */
1484 void zebra_evpn_rem_macip_add(vni_t vni
, const struct ethaddr
*macaddr
,
1485 uint16_t ipa_len
, const struct ipaddr
*ipaddr
,
1486 uint8_t flags
, uint32_t seq
,
1487 struct in_addr vtep_ip
, const esi_t
*esi
)
1489 struct zebra_evpn
*zevpn
;
1490 struct zebra_vtep
*zvtep
;
1491 struct zebra_mac
*mac
= NULL
;
1492 struct interface
*ifp
= NULL
;
1493 struct zebra_if
*zif
= NULL
;
1494 struct zebra_vrf
*zvrf
;
1496 /* Locate EVPN hash entry - expected to exist. */
1497 zevpn
= zebra_evpn_lookup(vni
);
1499 if (IS_ZEBRA_DEBUG_VXLAN
)
1500 zlog_debug("Unknown VNI %u upon remote MACIP ADD", vni
);
1504 ifp
= zevpn
->vxlan_if
;
1507 if (!ifp
|| !if_is_operative(ifp
) || !zif
|| !zif
->brslave_info
.br_if
) {
1508 if (IS_ZEBRA_DEBUG_VXLAN
)
1510 "Ignoring remote MACIP ADD VNI %u, invalid interface state or info",
1515 /* Type-2 routes from another PE can be interpreted as remote or
1516 * SYNC based on the destination ES -
1517 * SYNC - if ES is local
1518 * REMOTE - if ES is not local
1520 if (flags
& ZEBRA_MACIP_TYPE_SYNC_PATH
) {
1521 struct zebra_evpn_es
*es
;
1523 es
= zebra_evpn_es_find(esi
);
1524 if (es
&& (es
->flags
& ZEBRA_EVPNES_READY_FOR_BGP
)) {
1525 zebra_evpn_process_sync_macip_add(zevpn
, macaddr
,
1529 if (IS_ZEBRA_DEBUG_EVPN_MH_ES
) {
1530 char esi_str
[ESI_STR_LEN
];
1532 esi_to_str(esi
, esi_str
, sizeof(esi_str
));
1534 "Ignore sync-macip add; ES %s is not ready",
1542 /* The remote VTEP specified should normally exist, but it is
1543 * possible that when peering comes up, peer may advertise MACIP
1544 * routes before advertising type-3 routes.
1546 if (vtep_ip
.s_addr
) {
1547 zvtep
= zebra_evpn_vtep_find(zevpn
, &vtep_ip
);
1549 zvtep
= zebra_evpn_vtep_add(zevpn
, &vtep_ip
,
1550 VXLAN_FLOOD_DISABLED
);
1553 EC_ZEBRA_VTEP_ADD_FAILED
,
1554 "Failed to add remote VTEP, VNI %u zevpn %p upon remote MACIP ADD",
1559 zebra_evpn_vtep_install(zevpn
, zvtep
);
1563 zvrf
= zebra_vrf_get_evpn();
1569 zebra_evpn_mac_remote_macip_add(zevpn
, zvrf
, macaddr
, vtep_ip
,
1573 * Add auto MAC if it doesn't exist.
1575 mac
= zebra_evpn_mac_lookup(zevpn
, macaddr
);
1577 mac
= zebra_evpn_mac_add_auto(zevpn
, macaddr
);
1579 if (IS_ZEBRA_DEBUG_VXLAN
)
1581 "Neigh %pIA: MAC %pEA not found, Auto MAC created",
1585 zebra_evpn_neigh_remote_macip_add(zevpn
, zvrf
, ipaddr
, mac
,
1586 vtep_ip
, flags
, seq
);
1590 /* Process a remote MACIP delete from BGP. */
1591 void zebra_evpn_rem_macip_del(vni_t vni
, const struct ethaddr
*macaddr
,
1592 uint16_t ipa_len
, const struct ipaddr
*ipaddr
,
1593 struct in_addr vtep_ip
)
1595 struct zebra_evpn
*zevpn
;
1596 struct zebra_mac
*mac
= NULL
;
1597 struct zebra_neigh
*n
= NULL
;
1598 struct interface
*ifp
= NULL
;
1599 struct zebra_if
*zif
= NULL
;
1600 struct zebra_ns
*zns
;
1601 struct zebra_vxlan_vni
*vnip
;
1602 struct zebra_vrf
*zvrf
;
1603 char buf1
[INET6_ADDRSTRLEN
];
1605 /* Locate EVPN hash entry - expected to exist. */
1606 zevpn
= zebra_evpn_lookup(vni
);
1608 if (IS_ZEBRA_DEBUG_VXLAN
)
1609 zlog_debug("Unknown VNI %u upon remote MACIP DEL", vni
);
1613 ifp
= zevpn
->vxlan_if
;
1616 if (!ifp
|| !if_is_operative(ifp
) || !zif
|| !zif
->brslave_info
.br_if
) {
1617 if (IS_ZEBRA_DEBUG_VXLAN
)
1619 "Ignoring remote MACIP DEL VNI %u, invalid interface state or info",
1623 zns
= zebra_ns_lookup(NS_DEFAULT
);
1624 vnip
= zebra_vxlan_if_vni_find(zif
, vni
);
1626 if (IS_ZEBRA_DEBUG_VXLAN
)
1628 "VNI %u not in interface upon remote MACIP DEL",
1633 mac
= zebra_evpn_mac_lookup(zevpn
, macaddr
);
1635 n
= zebra_evpn_neigh_lookup(zevpn
, ipaddr
);
1639 "Failed to locate MAC %pEA for Neigh %pIA VNI %u upon remote MACIP DEL",
1640 macaddr
, ipaddr
, vni
);
1644 /* If the remote mac or neighbor doesn't exist there is nothing
1645 * more to do. Otherwise, uninstall the entry and then remove it.
1648 if (IS_ZEBRA_DEBUG_VXLAN
)
1650 "Failed to locate MAC %pEA & Neigh %pIA VNI %u upon remote MACIP DEL",
1651 macaddr
, ipaddr
, vni
);
1655 zvrf
= zevpn
->vxlan_if
->vrf
->info
;
1657 /* Ignore the delete if this mac is a gateway mac-ip */
1658 if (CHECK_FLAG(mac
->flags
, ZEBRA_MAC_LOCAL
)
1659 && CHECK_FLAG(mac
->flags
, ZEBRA_MAC_DEF_GW
)) {
1661 "Ignore remote MACIP DEL VNI %u MAC %pEA%s%s as MAC is already configured as gateway MAC",
1663 ipa_len
? " IP " : "",
1664 ipa_len
? ipaddr2str(ipaddr
, buf1
, sizeof(buf1
)) : "");
1668 /* Uninstall remote neighbor or MAC. */
1670 zebra_evpn_neigh_remote_uninstall(zevpn
, zvrf
, n
, mac
, ipaddr
);
1672 /* DAD: when MAC is freeze state as remote learn event,
1673 * remote mac-ip delete event is received will result in freeze
1674 * entry removal, first fetch kernel for the same entry present
1675 * as LOCAL and reachable, avoid deleting this entry instead
1676 * use kerenel local entry to update during unfreeze time.
1678 if (zvrf
->dad_freeze
1679 && CHECK_FLAG(mac
->flags
, ZEBRA_MAC_DUPLICATE
)
1680 && CHECK_FLAG(mac
->flags
, ZEBRA_MAC_REMOTE
)) {
1681 if (IS_ZEBRA_DEBUG_VXLAN
)
1683 "%s: MAC %pEA (flags 0x%x) is remote and duplicate, read kernel for local entry",
1684 __func__
, macaddr
, mac
->flags
);
1685 macfdb_read_specific_mac(zns
, zif
->brslave_info
.br_if
,
1686 macaddr
, vnip
->access_vlan
);
1689 if (CHECK_FLAG(mac
->flags
, ZEBRA_MAC_LOCAL
)) {
1691 zebra_evpn_sync_mac_del(mac
);
1692 } else if (CHECK_FLAG(mac
->flags
, ZEBRA_NEIGH_REMOTE
)) {
1693 zebra_evpn_rem_mac_del(zevpn
, mac
);
1698 /************************** EVPN BGP config management ************************/
1699 void zebra_evpn_cfg_cleanup(struct hash_bucket
*bucket
, void *ctxt
)
1701 struct zebra_evpn
*zevpn
= NULL
;
1703 zevpn
= (struct zebra_evpn
*)bucket
->data
;
1704 zevpn
->advertise_gw_macip
= 0;
1705 zevpn
->advertise_svi_macip
= 0;
1706 zevpn
->advertise_subnet
= 0;
1708 zebra_evpn_neigh_del_all(zevpn
, 1, 0,
1709 DEL_REMOTE_NEIGH
| DEL_REMOTE_NEIGH_FROM_VTEP
);
1710 zebra_evpn_mac_del_all(zevpn
, 1, 0,
1711 DEL_REMOTE_MAC
| DEL_REMOTE_MAC_FROM_VTEP
);
1712 zebra_evpn_vtep_del_all(zevpn
, 1);