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
26 #include "interface.h"
34 #include "zebra/zserv.h"
35 #include "zebra/debug.h"
36 #include "zebra/zebra_router.h"
37 #include "zebra/zebra_errors.h"
38 #include "zebra/zebra_vrf.h"
39 #include "zebra/zebra_evpn.h"
40 #include "zebra/zebra_evpn_mh.h"
41 #include "zebra/zebra_evpn_mac.h"
42 #include "zebra/zebra_evpn_neigh.h"
44 DEFINE_MTYPE_STATIC(ZEBRA
, MAC
, "EVPN MAC");
47 * Return number of valid MACs in an EVPN's MAC hash table - all
48 * remote MACs and non-internal (auto) local MACs count.
50 uint32_t num_valid_macs(struct zebra_evpn
*zevpn
)
53 uint32_t num_macs
= 0;
55 struct hash_bucket
*hb
;
56 struct zebra_mac
*mac
;
58 hash
= zevpn
->mac_table
;
61 for (i
= 0; i
< hash
->size
; i
++) {
62 for (hb
= hash
->index
[i
]; hb
; hb
= hb
->next
) {
63 mac
= (struct zebra_mac
*)hb
->data
;
64 if (CHECK_FLAG(mac
->flags
, ZEBRA_MAC_REMOTE
)
65 || CHECK_FLAG(mac
->flags
, ZEBRA_MAC_LOCAL
)
66 || !CHECK_FLAG(mac
->flags
, ZEBRA_MAC_AUTO
))
74 uint32_t num_dup_detected_macs(struct zebra_evpn
*zevpn
)
77 uint32_t num_macs
= 0;
79 struct hash_bucket
*hb
;
80 struct zebra_mac
*mac
;
82 hash
= zevpn
->mac_table
;
85 for (i
= 0; i
< hash
->size
; i
++) {
86 for (hb
= hash
->index
[i
]; hb
; hb
= hb
->next
) {
87 mac
= (struct zebra_mac
*)hb
->data
;
88 if (CHECK_FLAG(mac
->flags
, ZEBRA_MAC_DUPLICATE
))
96 /* Setup mac_list against the access port. This is done when a mac uses
97 * the ifp as destination for the first time
99 static void zebra_evpn_mac_ifp_new(struct zebra_if
*zif
)
101 if (IS_ZEBRA_DEBUG_EVPN_MH_MAC
)
102 zlog_debug("MAC list created for ifp %s (%u)", zif
->ifp
->name
,
105 zif
->mac_list
= list_new();
106 listset_app_node_mem(zif
->mac_list
);
109 /* Unlink local mac from a destination access port */
110 static void zebra_evpn_mac_ifp_unlink(struct zebra_mac
*zmac
)
112 struct zebra_if
*zif
;
113 struct interface
*ifp
= zmac
->ifp
;
118 if (IS_ZEBRA_DEBUG_EVPN_MH_MAC
)
119 zlog_debug("VNI %d MAC %pEA unlinked from ifp %s (%u)",
122 ifp
->name
, ifp
->ifindex
);
125 list_delete_node(zif
->mac_list
, &zmac
->ifp_listnode
);
129 /* Free up the mac_list if any as a part of the interface del/cleanup */
130 void zebra_evpn_mac_ifp_del(struct interface
*ifp
)
132 struct zebra_if
*zif
= ifp
->info
;
133 struct listnode
*node
;
134 struct zebra_mac
*zmac
;
137 if (IS_ZEBRA_DEBUG_EVPN_MH_MAC
)
138 zlog_debug("MAC list deleted for ifp %s (%u)",
139 zif
->ifp
->name
, zif
->ifp
->ifindex
);
141 for (ALL_LIST_ELEMENTS_RO(zif
->mac_list
, node
, zmac
)) {
142 zebra_evpn_mac_ifp_unlink(zmac
);
144 list_delete(&zif
->mac_list
);
148 /* Link local mac to destination access port. This is done only if the
149 * local mac is associated with a zero ESI i.e. single attach or lacp-bypass
152 static void zebra_evpn_mac_ifp_link(struct zebra_mac
*zmac
,
153 struct interface
*ifp
)
155 struct zebra_if
*zif
;
157 if (!CHECK_FLAG(zmac
->flags
, ZEBRA_MAC_LOCAL
))
160 /* already linked to the destination */
161 if (zmac
->ifp
== ifp
)
164 /* unlink the mac from any old destination */
166 zebra_evpn_mac_ifp_unlink(zmac
);
172 /* the interface mac_list is created on first mac link attempt */
174 zebra_evpn_mac_ifp_new(zif
);
176 if (IS_ZEBRA_DEBUG_EVPN_MH_MAC
)
177 zlog_debug("VNI %d MAC %pEA linked to ifp %s (%u)",
180 ifp
->name
, ifp
->ifindex
);
183 listnode_init(&zmac
->ifp_listnode
, zmac
);
184 listnode_add(zif
->mac_list
, &zmac
->ifp_listnode
);
187 /* If the mac is a local mac clear links to destination access port */
188 void zebra_evpn_mac_clear_fwd_info(struct zebra_mac
*zmac
)
190 zebra_evpn_mac_ifp_unlink(zmac
);
191 memset(&zmac
->fwd_info
, 0, sizeof(zmac
->fwd_info
));
195 * Install remote MAC into the forwarding plane.
197 int zebra_evpn_rem_mac_install(struct zebra_evpn
*zevpn
, struct zebra_mac
*mac
,
200 const struct zebra_if
*zif
, *br_zif
;
201 const struct zebra_l2info_vxlan
*vxl
;
203 enum zebra_dplane_result res
;
204 const struct interface
*br_ifp
;
207 struct in_addr vtep_ip
;
209 zif
= zevpn
->vxlan_if
->info
;
213 br_ifp
= zif
->brslave_info
.br_if
;
217 vxl
= &zif
->l2info
.vxl
;
219 sticky
= !!CHECK_FLAG(mac
->flags
,
220 (ZEBRA_MAC_STICKY
| ZEBRA_MAC_REMOTE_DEF_GW
));
222 /* If nexthop group for the FDB entry is inactive (not programmed in
223 * the dataplane) the MAC entry cannot be installed
226 if (!(mac
->es
->flags
& ZEBRA_EVPNES_NHG_ACTIVE
))
228 nhg_id
= mac
->es
->nhg_id
;
232 vtep_ip
= mac
->fwd_info
.r_vtep_ip
;
235 br_zif
= (const struct zebra_if
*)(br_ifp
->info
);
237 if (IS_ZEBRA_IF_BRIDGE_VLAN_AWARE(br_zif
))
238 vid
= vxl
->access_vlan
;
242 res
= dplane_rem_mac_add(zevpn
->vxlan_if
, br_ifp
, vid
, &mac
->macaddr
,
243 vtep_ip
, sticky
, nhg_id
, was_static
);
244 if (res
!= ZEBRA_DPLANE_REQUEST_FAILURE
)
251 * Uninstall remote MAC from the forwarding plane.
253 int zebra_evpn_rem_mac_uninstall(struct zebra_evpn
*zevpn
,
254 struct zebra_mac
*mac
, bool force
)
256 const struct zebra_if
*zif
, *br_zif
;
257 const struct zebra_l2info_vxlan
*vxl
;
258 struct in_addr vtep_ip
;
259 const struct interface
*ifp
, *br_ifp
;
261 enum zebra_dplane_result res
;
263 /* If the MAC was not installed there is no need to uninstall it */
264 if (!force
&& mac
->es
&& !(mac
->es
->flags
& ZEBRA_EVPNES_NHG_ACTIVE
))
267 if (!zevpn
->vxlan_if
) {
268 if (IS_ZEBRA_DEBUG_VXLAN
)
270 "VNI %u hash %p couldn't be uninstalled - no intf",
275 zif
= zevpn
->vxlan_if
->info
;
279 br_ifp
= zif
->brslave_info
.br_if
;
283 vxl
= &zif
->l2info
.vxl
;
285 br_zif
= (const struct zebra_if
*)br_ifp
->info
;
287 if (IS_ZEBRA_IF_BRIDGE_VLAN_AWARE(br_zif
))
288 vid
= vxl
->access_vlan
;
292 ifp
= zevpn
->vxlan_if
;
293 vtep_ip
= mac
->fwd_info
.r_vtep_ip
;
295 res
= dplane_rem_mac_del(ifp
, br_ifp
, vid
, &mac
->macaddr
, vtep_ip
);
296 if (res
!= ZEBRA_DPLANE_REQUEST_FAILURE
)
303 * Decrement neighbor refcount of MAC; uninstall and free it if
306 void zebra_evpn_deref_ip2mac(struct zebra_evpn
*zevpn
, struct zebra_mac
*mac
)
308 if (!CHECK_FLAG(mac
->flags
, ZEBRA_MAC_AUTO
))
311 /* If all remote neighbors referencing a remote MAC go away,
312 * we need to uninstall the MAC.
314 if (CHECK_FLAG(mac
->flags
, ZEBRA_MAC_REMOTE
)
315 && remote_neigh_count(mac
) == 0) {
316 zebra_evpn_rem_mac_uninstall(zevpn
, mac
, false /*force*/);
317 zebra_evpn_es_mac_deref_entry(mac
);
318 UNSET_FLAG(mac
->flags
, ZEBRA_MAC_REMOTE
);
321 /* If no references, delete the MAC. */
322 if (!zebra_evpn_mac_in_use(mac
))
323 zebra_evpn_mac_del(zevpn
, mac
);
326 static void zebra_evpn_mac_get_access_info(struct zebra_mac
*mac
,
327 struct interface
**ifpP
,
330 /* if the mac is associated with an ES we must get the access
334 struct zebra_if
*zif
;
336 /* get the access port from the es */
337 *ifpP
= mac
->es
->zif
? mac
->es
->zif
->ifp
: NULL
;
338 /* get the vlan from the EVPN */
339 if (mac
->zevpn
->vxlan_if
) {
340 zif
= mac
->zevpn
->vxlan_if
->info
;
341 *vid
= zif
->l2info
.vxl
.access_vlan
;
346 struct zebra_ns
*zns
;
348 *vid
= mac
->fwd_info
.local
.vid
;
349 zns
= zebra_ns_lookup(mac
->fwd_info
.local
.ns_id
);
350 *ifpP
= if_lookup_by_index_per_ns(zns
,
351 mac
->fwd_info
.local
.ifindex
);
355 #define MAC_BUF_SIZE 256
356 static char *zebra_evpn_zebra_mac_flag_dump(struct zebra_mac
*mac
, char *buf
,
359 if (mac
->flags
== 0) {
360 snprintfrr(buf
, len
, "None ");
365 buf
, len
, "%s%s%s%s%s%s%s%s%s%s%s%s",
366 CHECK_FLAG(mac
->flags
, ZEBRA_MAC_LOCAL
) ? "LOC " : "",
367 CHECK_FLAG(mac
->flags
, ZEBRA_MAC_REMOTE
) ? "REM " : "",
368 CHECK_FLAG(mac
->flags
, ZEBRA_MAC_AUTO
) ? "AUTO " : "",
369 CHECK_FLAG(mac
->flags
, ZEBRA_MAC_STICKY
) ? "STICKY " : "",
370 CHECK_FLAG(mac
->flags
, ZEBRA_MAC_REMOTE_RMAC
) ? "REM Router "
372 CHECK_FLAG(mac
->flags
, ZEBRA_MAC_DEF_GW
) ? "Default GW " : "",
373 CHECK_FLAG(mac
->flags
, ZEBRA_MAC_REMOTE_DEF_GW
) ? "REM DEF GW "
375 CHECK_FLAG(mac
->flags
, ZEBRA_MAC_DUPLICATE
) ? "DUP " : "",
376 CHECK_FLAG(mac
->flags
, ZEBRA_MAC_FPM_SENT
) ? "FPM " : "",
377 CHECK_FLAG(mac
->flags
, ZEBRA_MAC_ES_PEER_ACTIVE
) ? "LOC Active "
379 CHECK_FLAG(mac
->flags
, ZEBRA_MAC_ES_PEER_PROXY
) ? "PROXY " : "",
380 CHECK_FLAG(mac
->flags
, ZEBRA_MAC_LOCAL_INACTIVE
)
386 static void zebra_evpn_dad_mac_auto_recovery_exp(struct thread
*t
)
388 struct zebra_vrf
*zvrf
= NULL
;
389 struct zebra_mac
*mac
= NULL
;
390 struct zebra_evpn
*zevpn
= NULL
;
391 struct listnode
*node
= NULL
;
392 struct zebra_neigh
*nbr
= NULL
;
396 /* since this is asynchronous we need sanity checks*/
397 zvrf
= vrf_info_lookup(mac
->zevpn
->vrf_id
);
401 zevpn
= zebra_evpn_lookup(mac
->zevpn
->vni
);
405 mac
= zebra_evpn_mac_lookup(zevpn
, &mac
->macaddr
);
409 if (IS_ZEBRA_DEBUG_VXLAN
) {
410 char mac_buf
[MAC_BUF_SIZE
];
413 "%s: duplicate addr mac %pEA flags %slearn count %u host count %u auto recovery expired",
414 __func__
, &mac
->macaddr
,
415 zebra_evpn_zebra_mac_flag_dump(mac
, mac_buf
,
417 mac
->dad_count
, listcount(mac
->neigh_list
));
420 /* Remove all IPs as duplicate associcated with this MAC */
421 for (ALL_LIST_ELEMENTS_RO(mac
->neigh_list
, node
, nbr
)) {
422 if (CHECK_FLAG(nbr
->flags
, ZEBRA_NEIGH_DUPLICATE
)) {
423 if (CHECK_FLAG(nbr
->flags
, ZEBRA_NEIGH_LOCAL
))
424 ZEBRA_NEIGH_SET_INACTIVE(nbr
);
425 else if (CHECK_FLAG(nbr
->flags
, ZEBRA_NEIGH_REMOTE
))
426 zebra_evpn_rem_neigh_install(
427 zevpn
, nbr
, false /*was_static*/);
430 UNSET_FLAG(nbr
->flags
, ZEBRA_NEIGH_DUPLICATE
);
432 nbr
->detect_start_time
.tv_sec
= 0;
433 nbr
->dad_dup_detect_time
= 0;
436 UNSET_FLAG(mac
->flags
, ZEBRA_MAC_DUPLICATE
);
438 mac
->detect_start_time
.tv_sec
= 0;
439 mac
->detect_start_time
.tv_usec
= 0;
440 mac
->dad_dup_detect_time
= 0;
441 mac
->dad_mac_auto_recovery_timer
= NULL
;
443 if (CHECK_FLAG(mac
->flags
, ZEBRA_MAC_LOCAL
)) {
445 if (zebra_evpn_mac_send_add_to_client(zevpn
->vni
, &mac
->macaddr
,
446 mac
->flags
, mac
->loc_seq
,
450 /* Process all neighbors associated with this MAC. */
451 zebra_evpn_process_neigh_on_local_mac_change(zevpn
, mac
, 0,
454 } else if (CHECK_FLAG(mac
->flags
, ZEBRA_MAC_REMOTE
)) {
455 zebra_evpn_process_neigh_on_remote_mac_add(zevpn
, mac
);
457 /* Install the entry. */
458 zebra_evpn_rem_mac_install(zevpn
, mac
, false /* was_static */);
462 static void zebra_evpn_dup_addr_detect_for_mac(struct zebra_vrf
*zvrf
,
463 struct zebra_mac
*mac
,
464 struct in_addr vtep_ip
,
465 bool do_dad
, bool *is_dup_detect
,
468 struct zebra_neigh
*nbr
;
469 struct listnode
*node
= NULL
;
470 struct timeval elapsed
= {0, 0};
471 bool reset_params
= false;
473 if (!(zebra_evpn_do_dup_addr_detect(zvrf
) && do_dad
))
476 /* MAC is detected as duplicate,
477 * Local MAC event -> hold on advertising to BGP.
478 * Remote MAC event -> hold on installing it.
480 if (CHECK_FLAG(mac
->flags
, ZEBRA_MAC_DUPLICATE
)) {
481 if (IS_ZEBRA_DEBUG_VXLAN
) {
482 char mac_buf
[MAC_BUF_SIZE
];
485 "%s: duplicate addr MAC %pEA flags %sskip update to client, learn count %u recover time %u",
486 __func__
, &mac
->macaddr
,
487 zebra_evpn_zebra_mac_flag_dump(mac
, mac_buf
,
489 mac
->dad_count
, zvrf
->dad_freeze_time
);
491 /* For duplicate MAC do not update
492 * client but update neigh due to
495 if (zvrf
->dad_freeze
)
496 *is_dup_detect
= true;
501 /* Check if detection time (M-secs) expired.
502 * Reset learn count and detection start time.
504 monotime_since(&mac
->detect_start_time
, &elapsed
);
505 reset_params
= (elapsed
.tv_sec
> zvrf
->dad_time
);
506 if (is_local
&& !reset_params
) {
507 /* RFC-7432: A PE/VTEP that detects a MAC mobility
508 * event via LOCAL learning starts an M-second timer.
510 * NOTE: This is the START of the probe with count is
511 * 0 during LOCAL learn event.
512 * (mac->dad_count == 0 || elapsed.tv_sec >= zvrf->dad_time)
514 reset_params
= !mac
->dad_count
;
518 if (IS_ZEBRA_DEBUG_VXLAN
) {
519 char mac_buf
[MAC_BUF_SIZE
];
522 "%s: duplicate addr MAC %pEA flags %sdetection time passed, reset learn count %u",
523 __func__
, &mac
->macaddr
,
524 zebra_evpn_zebra_mac_flag_dump(mac
, mac_buf
,
530 /* Start dup. addr detection (DAD) start time,
531 * ONLY during LOCAL learn.
534 monotime(&mac
->detect_start_time
);
536 } else if (!is_local
) {
537 /* For REMOTE MAC, increment detection count
538 * ONLY while in probe window, once window passed,
539 * next local learn event should trigger DAD.
544 /* For LOCAL MAC learn event, once count is reset above via either
545 * initial/start detection time or passed the probe time, the count
546 * needs to be incremented.
551 if (mac
->dad_count
>= zvrf
->dad_max_moves
) {
552 flog_warn(EC_ZEBRA_DUP_MAC_DETECTED
,
553 "VNI %u: MAC %pEA detected as duplicate during %s VTEP %pI4",
554 mac
->zevpn
->vni
, &mac
->macaddr
,
555 is_local
? "local update, last" :
556 "remote update, from", &vtep_ip
);
558 SET_FLAG(mac
->flags
, ZEBRA_MAC_DUPLICATE
);
560 /* Capture Duplicate detection time */
561 mac
->dad_dup_detect_time
= monotime(NULL
);
563 /* Mark all IPs/Neighs as duplicate
564 * associcated with this MAC
566 for (ALL_LIST_ELEMENTS_RO(mac
->neigh_list
, node
, nbr
)) {
568 /* Ony Mark IPs which are Local */
569 if (!CHECK_FLAG(nbr
->flags
, ZEBRA_NEIGH_LOCAL
))
572 SET_FLAG(nbr
->flags
, ZEBRA_NEIGH_DUPLICATE
);
574 nbr
->dad_dup_detect_time
= monotime(NULL
);
576 flog_warn(EC_ZEBRA_DUP_IP_INHERIT_DETECTED
,
577 "VNI %u: MAC %pEA IP %pIA detected as duplicate during %s update, inherit duplicate from MAC",
578 mac
->zevpn
->vni
, &mac
->macaddr
, &nbr
->ip
,
579 is_local
? "local" : "remote");
582 /* Start auto recovery timer for this MAC */
583 THREAD_OFF(mac
->dad_mac_auto_recovery_timer
);
584 if (zvrf
->dad_freeze
&& zvrf
->dad_freeze_time
) {
585 if (IS_ZEBRA_DEBUG_VXLAN
) {
586 char mac_buf
[MAC_BUF_SIZE
];
589 "%s: duplicate addr MAC %pEA flags %sauto recovery time %u start",
590 __func__
, &mac
->macaddr
,
591 zebra_evpn_zebra_mac_flag_dump(
592 mac
, mac_buf
, sizeof(mac_buf
)),
593 zvrf
->dad_freeze_time
);
596 thread_add_timer(zrouter
.master
,
597 zebra_evpn_dad_mac_auto_recovery_exp
,
598 mac
, zvrf
->dad_freeze_time
,
599 &mac
->dad_mac_auto_recovery_timer
);
602 /* In case of local update, do not inform to client (BGPd),
603 * upd_neigh for neigh sequence change.
605 if (zvrf
->dad_freeze
)
606 *is_dup_detect
= true;
611 * Print a specific MAC entry.
613 void zebra_evpn_print_mac(struct zebra_mac
*mac
, void *ctxt
, json_object
*json
)
616 struct zebra_neigh
*n
= NULL
;
617 struct listnode
*node
= NULL
;
618 char buf1
[ETHER_ADDR_STRLEN
];
619 char buf2
[INET6_ADDRSTRLEN
];
620 struct zebra_vrf
*zvrf
;
621 struct timeval detect_start_time
= {0, 0};
622 char timebuf
[MONOTIME_STRLEN
];
623 char thread_buf
[THREAD_TIMER_STRLEN
];
625 char up_str
[MONOTIME_STRLEN
];
627 zvrf
= zebra_vrf_get_evpn();
631 vty
= (struct vty
*)ctxt
;
632 prefix_mac2str(&mac
->macaddr
, buf1
, sizeof(buf1
));
634 uptime
= monotime(NULL
);
635 uptime
-= mac
->uptime
;
637 frrtime_to_interval(uptime
, up_str
, sizeof(up_str
));
640 json_object
*json_mac
= json_object_new_object();
642 if (CHECK_FLAG(mac
->flags
, ZEBRA_MAC_LOCAL
)) {
643 struct interface
*ifp
;
646 zebra_evpn_mac_get_access_info(mac
, &ifp
, &vid
);
647 json_object_string_add(json_mac
, "type", "local");
649 json_object_string_add(json_mac
, "intf",
651 json_object_int_add(json_mac
, "ifindex",
655 json_object_int_add(json_mac
, "vlan", vid
);
656 } else if (CHECK_FLAG(mac
->flags
, ZEBRA_MAC_REMOTE
)) {
657 json_object_string_add(json_mac
, "type", "remote");
658 json_object_string_addf(json_mac
, "remoteVtep", "%pI4",
659 &mac
->fwd_info
.r_vtep_ip
);
660 } else if (CHECK_FLAG(mac
->flags
, ZEBRA_MAC_AUTO
))
661 json_object_string_add(json_mac
, "type", "auto");
663 if (CHECK_FLAG(mac
->flags
, ZEBRA_MAC_STICKY
))
664 json_object_boolean_true_add(json_mac
, "stickyMac");
666 if (CHECK_FLAG(mac
->flags
, ZEBRA_MAC_SVI
))
667 json_object_boolean_true_add(json_mac
, "sviMac");
669 if (CHECK_FLAG(mac
->flags
, ZEBRA_MAC_DEF_GW
))
670 json_object_boolean_true_add(json_mac
,
673 if (CHECK_FLAG(mac
->flags
, ZEBRA_MAC_REMOTE_DEF_GW
))
674 json_object_boolean_true_add(json_mac
,
677 json_object_string_add(json_mac
, "uptime", up_str
);
678 json_object_int_add(json_mac
, "localSequence", mac
->loc_seq
);
679 json_object_int_add(json_mac
, "remoteSequence", mac
->rem_seq
);
681 json_object_int_add(json_mac
, "detectionCount", mac
->dad_count
);
682 if (CHECK_FLAG(mac
->flags
, ZEBRA_MAC_DUPLICATE
))
683 json_object_boolean_true_add(json_mac
, "isDuplicate");
685 json_object_boolean_false_add(json_mac
, "isDuplicate");
687 json_object_int_add(json_mac
, "syncNeighCount",
688 mac
->sync_neigh_cnt
);
689 if (CHECK_FLAG(mac
->flags
, ZEBRA_MAC_LOCAL_INACTIVE
))
690 json_object_boolean_true_add(json_mac
, "localInactive");
691 if (CHECK_FLAG(mac
->flags
, ZEBRA_MAC_ES_PEER_PROXY
))
692 json_object_boolean_true_add(json_mac
, "peerProxy");
693 if (CHECK_FLAG(mac
->flags
, ZEBRA_MAC_ES_PEER_ACTIVE
))
694 json_object_boolean_true_add(json_mac
, "peerActive");
696 json_object_string_add(
697 json_mac
, "peerActiveHold",
698 thread_timer_to_hhmmss(thread_buf
,
702 json_object_string_add(json_mac
, "esi",
704 /* print all the associated neigh */
705 if (!listcount(mac
->neigh_list
))
706 json_object_string_add(json_mac
, "neighbors", "none");
708 json_object
*json_active_nbrs
= json_object_new_array();
709 json_object
*json_inactive_nbrs
=
710 json_object_new_array();
711 json_object
*json_nbrs
= json_object_new_object();
713 for (ALL_LIST_ELEMENTS_RO(mac
->neigh_list
, node
, n
)) {
714 if (IS_ZEBRA_NEIGH_ACTIVE(n
))
715 json_object_array_add(
717 json_object_new_string(
722 json_object_array_add(
724 json_object_new_string(
730 json_object_object_add(json_nbrs
, "active",
732 json_object_object_add(json_nbrs
, "inactive",
734 json_object_object_add(json_mac
, "neighbors",
738 json_object_object_add(json
, buf1
, json_mac
);
740 vty_out(vty
, "MAC: %s\n", buf1
);
742 if (CHECK_FLAG(mac
->flags
, ZEBRA_MAC_LOCAL
)) {
743 struct interface
*ifp
;
746 zebra_evpn_mac_get_access_info(mac
, &ifp
, &vid
);
749 vty_out(vty
, " ESI: %s\n", mac
->es
->esi_str
);
752 vty_out(vty
, " Intf: %s(%u)", ifp
->name
,
755 vty_out(vty
, " Intf: -");
756 vty_out(vty
, " VLAN: %u", vid
);
757 } else if (CHECK_FLAG(mac
->flags
, ZEBRA_MAC_REMOTE
)) {
759 vty_out(vty
, " Remote ES: %s",
762 vty_out(vty
, " Remote VTEP: %pI4",
763 &mac
->fwd_info
.r_vtep_ip
);
764 } else if (CHECK_FLAG(mac
->flags
, ZEBRA_MAC_AUTO
)) {
765 vty_out(vty
, " Auto Mac ");
768 if (CHECK_FLAG(mac
->flags
, ZEBRA_MAC_STICKY
))
769 vty_out(vty
, " Sticky Mac ");
771 if (CHECK_FLAG(mac
->flags
, ZEBRA_MAC_SVI
))
772 vty_out(vty
, " SVI-Mac ");
774 if (CHECK_FLAG(mac
->flags
, ZEBRA_MAC_DEF_GW
))
775 vty_out(vty
, " Default-gateway Mac ");
777 if (CHECK_FLAG(mac
->flags
, ZEBRA_MAC_REMOTE_DEF_GW
))
778 vty_out(vty
, " Remote-gateway Mac ");
781 vty_out(vty
, " Sync-info: neigh#: %u", mac
->sync_neigh_cnt
);
782 if (CHECK_FLAG(mac
->flags
, ZEBRA_MAC_LOCAL_INACTIVE
))
783 vty_out(vty
, " local-inactive");
784 if (CHECK_FLAG(mac
->flags
, ZEBRA_MAC_ES_PEER_PROXY
))
785 vty_out(vty
, " peer-proxy");
786 if (CHECK_FLAG(mac
->flags
, ZEBRA_MAC_ES_PEER_ACTIVE
))
787 vty_out(vty
, " peer-active");
789 vty_out(vty
, " (ht: %s)",
790 thread_timer_to_hhmmss(thread_buf
,
794 vty_out(vty
, " Local Seq: %u Remote Seq: %u\n", mac
->loc_seq
,
796 vty_out(vty
, " Uptime: %s\n", up_str
);
798 if (CHECK_FLAG(mac
->flags
, ZEBRA_MAC_DUPLICATE
)) {
799 vty_out(vty
, " Duplicate, detected at %s",
800 time_to_string(mac
->dad_dup_detect_time
,
802 } else if (mac
->dad_count
) {
803 monotime_since(&mac
->detect_start_time
,
805 if (detect_start_time
.tv_sec
<= zvrf
->dad_time
) {
806 time_to_string(mac
->detect_start_time
.tv_sec
,
809 " Duplicate detection started at %s, detection count %u\n",
810 timebuf
, mac
->dad_count
);
814 /* print all the associated neigh */
815 vty_out(vty
, " Neighbors:\n");
816 if (!listcount(mac
->neigh_list
))
817 vty_out(vty
, " No Neighbors\n");
819 for (ALL_LIST_ELEMENTS_RO(mac
->neigh_list
, node
, n
)) {
820 vty_out(vty
, " %s %s\n",
821 ipaddr2str(&n
->ip
, buf2
, sizeof(buf2
)),
822 (IS_ZEBRA_NEIGH_ACTIVE(n
)
832 static char *zebra_evpn_print_mac_flags(struct zebra_mac
*mac
, char *flags_buf
,
835 snprintf(flags_buf
, flags_buf_sz
, "%s%s%s%s",
836 mac
->sync_neigh_cnt
? "N" : "",
837 (mac
->flags
& ZEBRA_MAC_ES_PEER_ACTIVE
) ? "P" : "",
838 (mac
->flags
& ZEBRA_MAC_ES_PEER_PROXY
) ? "X" : "",
839 (mac
->flags
& ZEBRA_MAC_LOCAL_INACTIVE
) ? "I" : "");
845 * Print MAC hash entry - called for display of all MACs.
847 void zebra_evpn_print_mac_hash(struct hash_bucket
*bucket
, void *ctxt
)
850 json_object
*json_mac_hdr
= NULL
, *json_mac
= NULL
;
851 struct zebra_mac
*mac
;
852 char buf1
[ETHER_ADDR_STRLEN
];
853 char addr_buf
[PREFIX_STRLEN
];
854 struct mac_walk_ctx
*wctx
= ctxt
;
858 json_mac_hdr
= wctx
->json
;
859 mac
= (struct zebra_mac
*)bucket
->data
;
861 prefix_mac2str(&mac
->macaddr
, buf1
, sizeof(buf1
));
864 json_mac
= json_object_new_object();
866 if (CHECK_FLAG(mac
->flags
, ZEBRA_MAC_LOCAL
)) {
867 struct interface
*ifp
;
870 if (wctx
->flags
& SHOW_REMOTE_MAC_FROM_VTEP
)
873 zebra_evpn_mac_get_access_info(mac
, &ifp
, &vid
);
874 if (json_mac_hdr
== NULL
) {
875 vty_out(vty
, "%-17s %-6s %-5s %-30s", buf1
, "local",
876 zebra_evpn_print_mac_flags(mac
, flags_buf
,
878 ifp
? ifp
->name
: "-");
880 json_object_string_add(json_mac
, "type", "local");
882 json_object_string_add(json_mac
, "intf",
886 if (json_mac_hdr
== NULL
)
887 vty_out(vty
, " %-5u", vid
);
889 json_object_int_add(json_mac
, "vlan", vid
);
890 } else /* No vid? fill out the space */
891 if (json_mac_hdr
== NULL
)
892 vty_out(vty
, " %-5s", "");
893 if (json_mac_hdr
== NULL
) {
894 vty_out(vty
, " %u/%u", mac
->loc_seq
, mac
->rem_seq
);
897 json_object_int_add(json_mac
, "localSequence",
899 json_object_int_add(json_mac
, "remoteSequence",
901 json_object_int_add(json_mac
, "detectionCount",
903 if (CHECK_FLAG(mac
->flags
, ZEBRA_MAC_DUPLICATE
))
904 json_object_boolean_true_add(json_mac
,
907 json_object_boolean_false_add(json_mac
,
909 json_object_object_add(json_mac_hdr
, buf1
, json_mac
);
914 } else if (CHECK_FLAG(mac
->flags
, ZEBRA_MAC_REMOTE
)) {
916 if ((wctx
->flags
& SHOW_REMOTE_MAC_FROM_VTEP
)
917 && !IPV4_ADDR_SAME(&mac
->fwd_info
.r_vtep_ip
,
921 if (json_mac_hdr
== NULL
) {
922 if ((wctx
->flags
& SHOW_REMOTE_MAC_FROM_VTEP
)
923 && (wctx
->count
== 0)) {
924 vty_out(vty
, "\nVNI %u\n\n", wctx
->zevpn
->vni
);
925 vty_out(vty
, "%-17s %-6s %-5s%-30s %-5s %s\n",
926 "MAC", "Type", "Flags",
927 "Intf/Remote ES/VTEP", "VLAN",
931 inet_ntop(AF_INET
, &mac
->fwd_info
.r_vtep_ip
,
932 addr_buf
, sizeof(addr_buf
));
934 vty_out(vty
, "%-17s %-6s %-5s %-30s %-5s %u/%u\n", buf1
,
936 zebra_evpn_print_mac_flags(mac
, flags_buf
,
938 mac
->es
? mac
->es
->esi_str
: addr_buf
,
939 "", mac
->loc_seq
, mac
->rem_seq
);
941 json_object_string_add(json_mac
, "type", "remote");
942 json_object_string_addf(json_mac
, "remoteVtep", "%pI4",
943 &mac
->fwd_info
.r_vtep_ip
);
944 json_object_object_add(json_mac_hdr
, buf1
, json_mac
);
945 json_object_int_add(json_mac
, "localSequence",
947 json_object_int_add(json_mac
, "remoteSequence",
949 json_object_int_add(json_mac
, "detectionCount",
951 if (CHECK_FLAG(mac
->flags
, ZEBRA_MAC_DUPLICATE
))
952 json_object_boolean_true_add(json_mac
,
955 json_object_boolean_false_add(json_mac
,
964 * Print MAC hash entry in detail - called for display of all MACs.
966 void zebra_evpn_print_mac_hash_detail(struct hash_bucket
*bucket
, void *ctxt
)
969 json_object
*json_mac_hdr
= NULL
;
970 struct zebra_mac
*mac
;
971 struct mac_walk_ctx
*wctx
= ctxt
;
972 char buf1
[ETHER_ADDR_STRLEN
];
975 json_mac_hdr
= wctx
->json
;
976 mac
= (struct zebra_mac
*)bucket
->data
;
981 prefix_mac2str(&mac
->macaddr
, buf1
, sizeof(buf1
));
983 zebra_evpn_print_mac(mac
, vty
, json_mac_hdr
);
987 * Inform BGP about local MACIP.
989 int zebra_evpn_macip_send_msg_to_client(vni_t vni
,
990 const struct ethaddr
*macaddr
,
991 const struct ipaddr
*ip
, uint8_t flags
,
992 uint32_t seq
, int state
,
993 struct zebra_evpn_es
*es
, uint16_t cmd
)
996 struct zserv
*client
= NULL
;
997 struct stream
*s
= NULL
;
998 esi_t
*esi
= es
? &es
->esi
: zero_esi
;
1000 client
= zserv_find_client(ZEBRA_ROUTE_BGP
, 0);
1001 /* BGP may not be running. */
1005 s
= stream_new(ZEBRA_MAX_PACKET_SIZ
);
1007 zclient_create_header(s
, cmd
, zebra_vrf_get_evpn_id());
1008 stream_putl(s
, vni
);
1009 stream_put(s
, macaddr
->octet
, ETH_ALEN
);
1012 if (IS_IPADDR_V4(ip
))
1013 ipa_len
= IPV4_MAX_BYTELEN
;
1014 else if (IS_IPADDR_V6(ip
))
1015 ipa_len
= IPV6_MAX_BYTELEN
;
1017 stream_putl(s
, ipa_len
); /* IP address length */
1019 stream_put(s
, &ip
->ip
.addr
, ipa_len
); /* IP address */
1021 stream_putl(s
, 0); /* Just MAC. */
1023 if (cmd
== ZEBRA_MACIP_ADD
) {
1024 stream_putc(s
, flags
); /* sticky mac/gateway mac */
1025 stream_putl(s
, seq
); /* sequence number */
1026 stream_put(s
, esi
, sizeof(esi_t
));
1028 stream_putl(s
, state
); /* state - active/inactive */
1032 /* Write packet size. */
1033 stream_putw_at(s
, 0, stream_get_endp(s
));
1035 if (IS_ZEBRA_DEBUG_VXLAN
) {
1036 char flag_buf
[MACIP_BUF_SIZE
];
1039 "Send MACIP %s f %s MAC %pEA IP %pIA seq %u L2-VNI %u ESI %s to %s",
1040 (cmd
== ZEBRA_MACIP_ADD
) ? "Add" : "Del",
1041 zclient_evpn_dump_macip_flags(flags
, flag_buf
,
1043 macaddr
, ip
, seq
, vni
,
1044 es
? es
->esi_str
: "-",
1045 zebra_route_string(client
->proto
));
1048 if (cmd
== ZEBRA_MACIP_ADD
)
1049 client
->macipadd_cnt
++;
1051 client
->macipdel_cnt
++;
1053 return zserv_send_message(client
, s
);
1056 static unsigned int mac_hash_keymake(const void *p
)
1058 const struct zebra_mac
*pmac
= p
;
1059 const void *pnt
= (void *)pmac
->macaddr
.octet
;
1061 return jhash(pnt
, ETH_ALEN
, 0xa5a5a55a);
1065 * Compare two MAC addresses.
1067 static bool mac_cmp(const void *p1
, const void *p2
)
1069 const struct zebra_mac
*pmac1
= p1
;
1070 const struct zebra_mac
*pmac2
= p2
;
1072 if (pmac1
== NULL
&& pmac2
== NULL
)
1075 if (pmac1
== NULL
|| pmac2
== NULL
)
1078 return (memcmp(pmac1
->macaddr
.octet
, pmac2
->macaddr
.octet
, ETH_ALEN
)
1083 * Callback to allocate MAC hash entry.
1085 static void *zebra_evpn_mac_alloc(void *p
)
1087 const struct zebra_mac
*tmp_mac
= p
;
1088 struct zebra_mac
*mac
;
1090 mac
= XCALLOC(MTYPE_MAC
, sizeof(struct zebra_mac
));
1093 return ((void *)mac
);
1099 struct zebra_mac
*zebra_evpn_mac_add(struct zebra_evpn
*zevpn
,
1100 const struct ethaddr
*macaddr
)
1102 struct zebra_mac tmp_mac
;
1103 struct zebra_mac
*mac
= NULL
;
1105 memset(&tmp_mac
, 0, sizeof(struct zebra_mac
));
1106 memcpy(&tmp_mac
.macaddr
, macaddr
, ETH_ALEN
);
1107 mac
= hash_get(zevpn
->mac_table
, &tmp_mac
, zebra_evpn_mac_alloc
);
1111 mac
->dad_mac_auto_recovery_timer
= NULL
;
1113 mac
->neigh_list
= list_new();
1114 mac
->neigh_list
->cmp
= neigh_list_cmp
;
1116 mac
->uptime
= monotime(NULL
);
1117 if (IS_ZEBRA_DEBUG_VXLAN
|| IS_ZEBRA_DEBUG_EVPN_MH_MAC
) {
1118 char mac_buf
[MAC_BUF_SIZE
];
1120 zlog_debug("%s: MAC %pEA flags %s", __func__
,
1122 zebra_evpn_zebra_mac_flag_dump(mac
, mac_buf
,
1131 int zebra_evpn_mac_del(struct zebra_evpn
*zevpn
, struct zebra_mac
*mac
)
1133 struct zebra_mac
*tmp_mac
;
1135 if (IS_ZEBRA_DEBUG_VXLAN
|| IS_ZEBRA_DEBUG_EVPN_MH_MAC
) {
1136 char mac_buf
[MAC_BUF_SIZE
];
1138 zlog_debug("%s: MAC %pEA flags %s", __func__
,
1140 zebra_evpn_zebra_mac_flag_dump(mac
, mac_buf
,
1144 /* If the MAC is freed before the neigh we will end up
1145 * with a stale pointer against the neigh
1147 if (!list_isempty(mac
->neigh_list
))
1148 zlog_warn("%s: MAC %pEA flags 0x%x neigh list not empty %d",
1149 __func__
, &mac
->macaddr
, mac
->flags
,
1150 listcount(mac
->neigh_list
));
1152 /* force de-ref any ES entry linked to the MAC */
1153 zebra_evpn_es_mac_deref_entry(mac
);
1155 /* remove links to the destination access port */
1156 zebra_evpn_mac_clear_fwd_info(mac
);
1158 /* Cancel proxy hold timer */
1159 zebra_evpn_mac_stop_hold_timer(mac
);
1161 /* Cancel auto recovery */
1162 THREAD_OFF(mac
->dad_mac_auto_recovery_timer
);
1164 list_delete(&mac
->neigh_list
);
1166 /* Free the VNI hash entry and allocated memory. */
1167 tmp_mac
= hash_release(zevpn
->mac_table
, mac
);
1168 XFREE(MTYPE_MAC
, tmp_mac
);
1173 static bool zebra_evpn_check_mac_del_from_db(struct mac_walk_ctx
*wctx
,
1174 struct zebra_mac
*mac
)
1176 if ((wctx
->flags
& DEL_LOCAL_MAC
) && (mac
->flags
& ZEBRA_MAC_LOCAL
))
1178 else if ((wctx
->flags
& DEL_REMOTE_MAC
)
1179 && (mac
->flags
& ZEBRA_MAC_REMOTE
))
1181 else if ((wctx
->flags
& DEL_REMOTE_MAC_FROM_VTEP
)
1182 && (mac
->flags
& ZEBRA_MAC_REMOTE
)
1183 && IPV4_ADDR_SAME(&mac
->fwd_info
.r_vtep_ip
, &wctx
->r_vtep_ip
))
1185 else if ((wctx
->flags
& DEL_LOCAL_MAC
) && (mac
->flags
& ZEBRA_MAC_AUTO
)
1186 && !listcount(mac
->neigh_list
)) {
1187 if (IS_ZEBRA_DEBUG_VXLAN
) {
1188 char mac_buf
[MAC_BUF_SIZE
];
1191 "%s: Del MAC %pEA flags %s", __func__
,
1193 zebra_evpn_zebra_mac_flag_dump(
1194 mac
, mac_buf
, sizeof(mac_buf
)));
1196 wctx
->uninstall
= 0;
1205 * Free MAC hash entry (callback)
1207 static void zebra_evpn_mac_del_hash_entry(struct hash_bucket
*bucket
, void *arg
)
1209 struct mac_walk_ctx
*wctx
= arg
;
1210 struct zebra_mac
*mac
= bucket
->data
;
1212 if (zebra_evpn_check_mac_del_from_db(wctx
, mac
)) {
1213 if (wctx
->upd_client
&& (mac
->flags
& ZEBRA_MAC_LOCAL
)) {
1214 zebra_evpn_mac_send_del_to_client(wctx
->zevpn
->vni
,
1218 if (wctx
->uninstall
) {
1219 if (zebra_evpn_mac_is_static(mac
))
1220 zebra_evpn_sync_mac_dp_install(
1221 mac
, false /* set_inactive */,
1222 true /* force_clear_static */,
1225 if (mac
->flags
& ZEBRA_MAC_REMOTE
)
1226 zebra_evpn_rem_mac_uninstall(wctx
->zevpn
, mac
,
1230 zebra_evpn_mac_del(wctx
->zevpn
, mac
);
1237 * Delete all MAC entries for this EVPN.
1239 void zebra_evpn_mac_del_all(struct zebra_evpn
*zevpn
, int uninstall
,
1240 int upd_client
, uint32_t flags
)
1242 struct mac_walk_ctx wctx
;
1244 if (!zevpn
->mac_table
)
1247 memset(&wctx
, 0, sizeof(struct mac_walk_ctx
));
1249 wctx
.uninstall
= uninstall
;
1250 wctx
.upd_client
= upd_client
;
1253 hash_iterate(zevpn
->mac_table
, zebra_evpn_mac_del_hash_entry
, &wctx
);
1257 * Look up MAC hash entry.
1259 struct zebra_mac
*zebra_evpn_mac_lookup(struct zebra_evpn
*zevpn
,
1260 const struct ethaddr
*mac
)
1262 struct zebra_mac tmp
;
1263 struct zebra_mac
*pmac
;
1265 memset(&tmp
, 0, sizeof(tmp
));
1266 memcpy(&tmp
.macaddr
, mac
, ETH_ALEN
);
1267 pmac
= hash_lookup(zevpn
->mac_table
, &tmp
);
1273 * Inform BGP about local MAC addition.
1275 int zebra_evpn_mac_send_add_to_client(vni_t vni
, const struct ethaddr
*macaddr
,
1276 uint32_t mac_flags
, uint32_t seq
,
1277 struct zebra_evpn_es
*es
)
1281 if (CHECK_FLAG(mac_flags
, ZEBRA_MAC_LOCAL_INACTIVE
)) {
1282 /* host reachability has not been verified locally */
1284 /* if no ES peer is claiming reachability we can't advertise the
1287 if (!CHECK_FLAG(mac_flags
, ZEBRA_MAC_ES_PEER_ACTIVE
))
1290 /* ES peers are claiming reachability; we will
1291 * advertise the entry but with a proxy flag
1293 SET_FLAG(flags
, ZEBRA_MACIP_TYPE_PROXY_ADVERT
);
1296 if (CHECK_FLAG(mac_flags
, ZEBRA_MAC_STICKY
))
1297 SET_FLAG(flags
, ZEBRA_MACIP_TYPE_STICKY
);
1298 if (CHECK_FLAG(mac_flags
, ZEBRA_MAC_DEF_GW
))
1299 SET_FLAG(flags
, ZEBRA_MACIP_TYPE_GW
);
1301 return zebra_evpn_macip_send_msg_to_client(vni
, macaddr
, NULL
, flags
,
1302 seq
, ZEBRA_NEIGH_ACTIVE
, es
,
1307 * Inform BGP about local MAC deletion.
1309 int zebra_evpn_mac_send_del_to_client(vni_t vni
, const struct ethaddr
*macaddr
,
1310 uint32_t flags
, bool force
)
1313 if (CHECK_FLAG(flags
, ZEBRA_MAC_LOCAL_INACTIVE
)
1314 && !CHECK_FLAG(flags
, ZEBRA_MAC_ES_PEER_ACTIVE
))
1315 /* the host was not advertised - nothing to delete */
1319 return zebra_evpn_macip_send_msg_to_client(
1320 vni
, macaddr
, NULL
, 0 /* flags */, 0 /* seq */,
1321 ZEBRA_NEIGH_ACTIVE
, NULL
, ZEBRA_MACIP_DEL
);
1325 * wrapper to create a MAC hash table
1327 struct hash
*zebra_mac_db_create(const char *desc
)
1329 return hash_create_size(8, mac_hash_keymake
, mac_cmp
, desc
);
1332 /* program sync mac flags in the dataplane */
1333 int zebra_evpn_sync_mac_dp_install(struct zebra_mac
*mac
, bool set_inactive
,
1334 bool force_clear_static
, const char *caller
)
1336 struct interface
*ifp
;
1339 struct zebra_evpn
*zevpn
= mac
->zevpn
;
1341 struct zebra_if
*zif
;
1342 struct interface
*br_ifp
;
1344 /* If the ES-EVI doesn't exist defer install. When the ES-EVI is
1345 * created we will attempt to install the mac entry again
1348 struct zebra_evpn_es_evi
*es_evi
;
1350 es_evi
= zebra_evpn_es_evi_find(mac
->es
, mac
->zevpn
);
1352 if (IS_ZEBRA_DEBUG_EVPN_MH_MAC
)
1354 "%s: dp-install sync-mac vni %u mac %pEA es %s 0x%x %sskipped, no es-evi",
1355 caller
, zevpn
->vni
, &mac
->macaddr
,
1356 mac
->es
? mac
->es
->esi_str
: "-",
1358 set_inactive
? "inactive " : "");
1363 /* get the access vlan from the vxlan_device */
1364 zebra_evpn_mac_get_access_info(mac
, &ifp
, &vid
);
1367 if (IS_ZEBRA_DEBUG_EVPN_MH_MAC
) {
1368 char mac_buf
[MAC_BUF_SIZE
];
1371 "%s: dp-install sync-mac vni %u mac %pEA es %s %s%sskipped, no access-port",
1372 caller
, zevpn
->vni
, &mac
->macaddr
,
1373 mac
->es
? mac
->es
->esi_str
: "-",
1374 zebra_evpn_zebra_mac_flag_dump(mac
, mac_buf
,
1376 set_inactive
? "inactive " : "");
1382 br_ifp
= zif
->brslave_info
.br_if
;
1384 if (IS_ZEBRA_DEBUG_EVPN_MH_MAC
) {
1385 char mac_buf
[MAC_BUF_SIZE
];
1388 "%s: dp-install sync-mac vni %u mac %pEA es %s %s%sskipped, no br",
1389 caller
, zevpn
->vni
, &mac
->macaddr
,
1390 mac
->es
? mac
->es
->esi_str
: "-",
1391 zebra_evpn_zebra_mac_flag_dump(mac
, mac_buf
,
1393 set_inactive
? "inactive " : "");
1398 sticky
= !!CHECK_FLAG(mac
->flags
, ZEBRA_MAC_STICKY
);
1399 if (force_clear_static
)
1402 set_static
= zebra_evpn_mac_is_static(mac
);
1404 /* We can install a local mac that has been synced from the peer
1405 * over the VxLAN-overlay/network-port if fast failover is not
1406 * supported and if the local ES is oper-down.
1408 if (mac
->es
&& zebra_evpn_es_local_mac_via_network_port(mac
->es
)) {
1409 if (IS_ZEBRA_DEBUG_EVPN_MH_MAC
) {
1410 char mac_buf
[MAC_BUF_SIZE
];
1413 "dp-%s sync-nw-mac vni %u mac %pEA es %s %s%s",
1414 set_static
? "install" : "uninstall",
1415 zevpn
->vni
, &mac
->macaddr
,
1416 mac
->es
? mac
->es
->esi_str
: "-",
1417 zebra_evpn_zebra_mac_flag_dump(mac
, mac_buf
,
1419 set_inactive
? "inactive " : "");
1422 /* XXX - old_static needs to be computed more
1425 zebra_evpn_rem_mac_install(zevpn
, mac
,
1426 true /* old_static */);
1428 zebra_evpn_rem_mac_uninstall(zevpn
, mac
,
1434 if (IS_ZEBRA_DEBUG_EVPN_MH_MAC
) {
1435 char mac_buf
[MAC_BUF_SIZE
];
1437 zlog_debug("dp-install sync-mac vni %u mac %pEA es %s %s%s%s",
1438 zevpn
->vni
, &mac
->macaddr
,
1439 mac
->es
? mac
->es
->esi_str
: "-",
1440 zebra_evpn_zebra_mac_flag_dump(mac
, mac_buf
,
1442 set_static
? "static " : "",
1443 set_inactive
? "inactive " : "");
1446 dplane_local_mac_add(ifp
, br_ifp
, vid
, &mac
->macaddr
, sticky
,
1447 set_static
, set_inactive
);
1451 void zebra_evpn_mac_send_add_del_to_client(struct zebra_mac
*mac
,
1456 zebra_evpn_mac_send_add_to_client(mac
->zevpn
->vni
,
1457 &mac
->macaddr
, mac
->flags
,
1458 mac
->loc_seq
, mac
->es
);
1459 else if (old_bgp_ready
)
1460 zebra_evpn_mac_send_del_to_client(mac
->zevpn
->vni
,
1461 &mac
->macaddr
, mac
->flags
,
1465 /* MAC hold timer is used to age out peer-active flag.
1467 * During this wait time we expect the dataplane component or an
1468 * external neighmgr daemon to probe existing hosts to independently
1469 * establish their presence on the ES.
1471 static void zebra_evpn_mac_hold_exp_cb(struct thread
*t
)
1473 struct zebra_mac
*mac
;
1479 mac
= THREAD_ARG(t
);
1480 /* the purpose of the hold timer is to age out the peer-active
1483 if (!CHECK_FLAG(mac
->flags
, ZEBRA_MAC_ES_PEER_ACTIVE
))
1486 old_bgp_ready
= zebra_evpn_mac_is_ready_for_bgp(mac
->flags
);
1487 old_static
= zebra_evpn_mac_is_static(mac
);
1488 UNSET_FLAG(mac
->flags
, ZEBRA_MAC_ES_PEER_ACTIVE
);
1489 new_bgp_ready
= zebra_evpn_mac_is_ready_for_bgp(mac
->flags
);
1490 new_static
= zebra_evpn_mac_is_static(mac
);
1492 if (IS_ZEBRA_DEBUG_EVPN_MH_MAC
) {
1493 char mac_buf
[MAC_BUF_SIZE
];
1496 "sync-mac vni %u mac %pEA es %s %shold expired",
1497 mac
->zevpn
->vni
, &mac
->macaddr
,
1498 mac
->es
? mac
->es
->esi_str
: "-",
1499 zebra_evpn_zebra_mac_flag_dump(mac
, mac_buf
,
1503 /* re-program the local mac in the dataplane if the mac is no
1506 if (old_static
!= new_static
)
1507 zebra_evpn_sync_mac_dp_install(mac
, false /* set_inactive */,
1508 false /* force_clear_static */,
1511 /* inform bgp if needed */
1512 if (old_bgp_ready
!= new_bgp_ready
)
1513 zebra_evpn_mac_send_add_del_to_client(mac
, old_bgp_ready
,
1517 static inline void zebra_evpn_mac_start_hold_timer(struct zebra_mac
*mac
)
1519 if (mac
->hold_timer
)
1522 if (IS_ZEBRA_DEBUG_EVPN_MH_MAC
) {
1523 char mac_buf
[MAC_BUF_SIZE
];
1526 "sync-mac vni %u mac %pEA es %s %shold started",
1527 mac
->zevpn
->vni
, &mac
->macaddr
,
1528 mac
->es
? mac
->es
->esi_str
: "-",
1529 zebra_evpn_zebra_mac_flag_dump(mac
, mac_buf
,
1532 thread_add_timer(zrouter
.master
, zebra_evpn_mac_hold_exp_cb
, mac
,
1533 zmh_info
->mac_hold_time
, &mac
->hold_timer
);
1536 void zebra_evpn_mac_stop_hold_timer(struct zebra_mac
*mac
)
1538 if (!mac
->hold_timer
)
1541 if (IS_ZEBRA_DEBUG_EVPN_MH_MAC
) {
1542 char mac_buf
[MAC_BUF_SIZE
];
1545 "sync-mac vni %u mac %pEA es %s %shold stopped",
1546 mac
->zevpn
->vni
, &mac
->macaddr
,
1547 mac
->es
? mac
->es
->esi_str
: "-",
1548 zebra_evpn_zebra_mac_flag_dump(mac
, mac_buf
,
1552 THREAD_OFF(mac
->hold_timer
);
1555 void zebra_evpn_sync_mac_del(struct zebra_mac
*mac
)
1560 if (IS_ZEBRA_DEBUG_EVPN_MH_MAC
) {
1561 char mac_buf
[MAC_BUF_SIZE
];
1564 "sync-mac del vni %u mac %pEA es %s seq %d f %s",
1565 mac
->zevpn
->vni
, &mac
->macaddr
,
1566 mac
->es
? mac
->es
->esi_str
: "-", mac
->loc_seq
,
1567 zebra_evpn_zebra_mac_flag_dump(mac
, mac_buf
,
1571 old_static
= zebra_evpn_mac_is_static(mac
);
1572 UNSET_FLAG(mac
->flags
, ZEBRA_MAC_ES_PEER_PROXY
);
1573 if (CHECK_FLAG(mac
->flags
, ZEBRA_MAC_ES_PEER_ACTIVE
))
1574 zebra_evpn_mac_start_hold_timer(mac
);
1575 new_static
= zebra_evpn_mac_is_static(mac
);
1577 if (old_static
!= new_static
)
1578 /* program the local mac in the kernel */
1579 zebra_evpn_sync_mac_dp_install(mac
, false /* set_inactive */,
1580 false /* force_clear_static */,
1584 static inline bool zebra_evpn_mac_is_bgp_seq_ok(struct zebra_evpn
*zevpn
,
1585 struct zebra_mac
*mac
,
1586 uint32_t seq
, uint16_t ipa_len
,
1587 const struct ipaddr
*ipaddr
,
1590 char ipbuf
[INET6_ADDRSTRLEN
];
1594 if (CHECK_FLAG(mac
->flags
, ZEBRA_MAC_LOCAL
)) {
1595 tmp_seq
= mac
->loc_seq
;
1598 tmp_seq
= mac
->rem_seq
;
1602 if (seq
< tmp_seq
) {
1603 /* if the mac was never advertised to bgp we must accept
1604 * whatever sequence number bgp sends
1605 * XXX - check with Vivek
1607 if (CHECK_FLAG(mac
->flags
, ZEBRA_MAC_LOCAL
)
1608 && !zebra_evpn_mac_is_ready_for_bgp(mac
->flags
)) {
1609 if (IS_ZEBRA_DEBUG_EVPN_MH_MAC
1610 || IS_ZEBRA_DEBUG_VXLAN
) {
1611 char mac_buf
[MAC_BUF_SIZE
];
1614 "%s-macip accept vni %u %s-mac %pEA%s%s lower seq %u f %s",
1615 sync
? "sync" : "rem", zevpn
->vni
,
1618 ipa_len
? " IP " : "",
1619 ipa_len
? ipaddr2str(ipaddr
, ipbuf
,
1623 zebra_evpn_zebra_mac_flag_dump(
1624 mac
, mac_buf
, sizeof(mac_buf
)));
1630 if (IS_ZEBRA_DEBUG_EVPN_MH_MAC
|| IS_ZEBRA_DEBUG_VXLAN
) {
1631 char mac_buf
[MAC_BUF_SIZE
];
1634 "%s-macip ignore vni %u %s-mac %pEA%s%s as existing has higher seq %u f %s",
1635 sync
? "sync" : "rem", zevpn
->vni
, n_type
,
1637 ipa_len
? " IP " : "",
1638 ipa_len
? ipaddr2str(ipaddr
, ipbuf
,
1642 zebra_evpn_zebra_mac_flag_dump(
1643 mac
, mac_buf
, sizeof(mac_buf
)));
1651 struct zebra_mac
*zebra_evpn_proc_sync_mac_update(
1652 struct zebra_evpn
*zevpn
, const struct ethaddr
*macaddr
,
1653 uint16_t ipa_len
, const struct ipaddr
*ipaddr
, uint8_t flags
,
1654 uint32_t seq
, const esi_t
*esi
, struct sync_mac_ip_ctx
*ctx
)
1656 struct zebra_mac
*mac
;
1657 bool inform_bgp
= false;
1658 bool inform_dataplane
= false;
1659 bool seq_change
= false;
1660 bool es_change
= false;
1662 char ipbuf
[INET6_ADDRSTRLEN
];
1663 bool old_local
= false;
1667 mac
= zebra_evpn_mac_lookup(zevpn
, macaddr
);
1669 /* if it is a new local path we need to inform both
1670 * the control protocol and the data-plane
1673 inform_dataplane
= true;
1674 ctx
->mac_created
= true;
1675 ctx
->mac_inactive
= true;
1677 /* create the MAC and associate it with the dest ES */
1678 mac
= zebra_evpn_mac_add(zevpn
, macaddr
);
1679 zebra_evpn_es_mac_ref(mac
, esi
);
1681 /* local mac activated by an ES peer */
1682 SET_FLAG(mac
->flags
, ZEBRA_MAC_LOCAL
);
1683 /* if mac-only route setup peer flags */
1685 if (CHECK_FLAG(flags
, ZEBRA_MACIP_TYPE_PROXY_ADVERT
))
1686 SET_FLAG(mac
->flags
, ZEBRA_MAC_ES_PEER_PROXY
);
1688 SET_FLAG(mac
->flags
, ZEBRA_MAC_ES_PEER_ACTIVE
);
1690 SET_FLAG(mac
->flags
, ZEBRA_MAC_LOCAL_INACTIVE
);
1691 old_bgp_ready
= false;
1692 new_bgp_ready
= zebra_evpn_mac_is_ready_for_bgp(mac
->flags
);
1701 mac
->uptime
= monotime(NULL
);
1703 old_flags
= mac
->flags
;
1704 sticky
= !!CHECK_FLAG(old_flags
, ZEBRA_MAC_STICKY
);
1705 remote_gw
= !!CHECK_FLAG(old_flags
, ZEBRA_MAC_REMOTE_DEF_GW
);
1706 if (sticky
|| remote_gw
) {
1707 if (IS_ZEBRA_DEBUG_EVPN_MH_NEIGH
)
1709 "Ignore sync-macip vni %u mac %pEA%s%s%s%s",
1710 zevpn
->vni
, macaddr
,
1711 ipa_len
? " IP " : "",
1712 ipa_len
? ipaddr2str(ipaddr
, ipbuf
,
1715 sticky
? " sticky" : "",
1716 remote_gw
? " remote_gw" : "");
1717 ctx
->ignore_macip
= true;
1720 if (!zebra_evpn_mac_is_bgp_seq_ok(zevpn
, mac
, seq
, ipa_len
,
1722 ctx
->ignore_macip
= true;
1726 old_local
= !!CHECK_FLAG(old_flags
, ZEBRA_MAC_LOCAL
);
1727 old_static
= zebra_evpn_mac_is_static(mac
);
1729 /* re-build the mac flags */
1731 SET_FLAG(new_flags
, ZEBRA_MAC_LOCAL
);
1732 /* retain old local activity flag */
1733 if (old_flags
& ZEBRA_MAC_LOCAL
) {
1734 new_flags
|= (old_flags
& ZEBRA_MAC_LOCAL_INACTIVE
);
1736 new_flags
|= ZEBRA_MAC_LOCAL_INACTIVE
;
1737 ctx
->mac_inactive
= true;
1740 /* if mac-ip route do NOT update the peer flags
1741 * i.e. retain only flags as is
1743 new_flags
|= (old_flags
& ZEBRA_MAC_ALL_PEER_FLAGS
);
1745 /* if mac-only route update peer flags */
1746 if (CHECK_FLAG(flags
, ZEBRA_MACIP_TYPE_PROXY_ADVERT
)) {
1747 SET_FLAG(new_flags
, ZEBRA_MAC_ES_PEER_PROXY
);
1748 /* if the mac was peer-active previously we
1749 * need to keep the flag and start the
1750 * holdtimer on it. the peer-active flag is
1751 * cleared on holdtimer expiry.
1753 if (CHECK_FLAG(old_flags
,
1754 ZEBRA_MAC_ES_PEER_ACTIVE
)) {
1756 ZEBRA_MAC_ES_PEER_ACTIVE
);
1757 zebra_evpn_mac_start_hold_timer(mac
);
1760 SET_FLAG(new_flags
, ZEBRA_MAC_ES_PEER_ACTIVE
);
1761 /* stop hold timer if a peer has verified
1764 zebra_evpn_mac_stop_hold_timer(mac
);
1768 zebra_evpn_mac_clear_fwd_info(mac
);
1769 mac
->flags
= new_flags
;
1771 if (IS_ZEBRA_DEBUG_EVPN_MH_MAC
&& (old_flags
!= new_flags
)) {
1772 char mac_buf
[MAC_BUF_SIZE
], omac_buf
[MAC_BUF_SIZE
];
1773 struct zebra_mac omac
;
1775 omac
.flags
= old_flags
;
1777 "sync-mac vni %u mac %pEA old_f %snew_f %s",
1778 zevpn
->vni
, macaddr
,
1779 zebra_evpn_zebra_mac_flag_dump(
1780 &omac
, omac_buf
, sizeof(omac_buf
)),
1781 zebra_evpn_zebra_mac_flag_dump(
1782 mac
, mac_buf
, sizeof(mac_buf
)));
1786 es_change
= zebra_evpn_es_mac_ref(mac
, esi
);
1787 /* if mac dest change - inform both sides */
1790 inform_dataplane
= true;
1791 ctx
->mac_inactive
= true;
1794 /* if peer-flag is being set notify dataplane that the
1795 * entry must not be expired because of local inactivity
1797 new_static
= zebra_evpn_mac_is_static(mac
);
1798 if (old_static
!= new_static
)
1799 inform_dataplane
= true;
1801 old_bgp_ready
= zebra_evpn_mac_is_ready_for_bgp(old_flags
);
1802 new_bgp_ready
= zebra_evpn_mac_is_ready_for_bgp(mac
->flags
);
1803 if (old_bgp_ready
!= new_bgp_ready
)
1808 /* update sequence number; if that results in a new local sequence
1811 tmp_seq
= MAX(mac
->loc_seq
, seq
);
1812 if (tmp_seq
!= mac
->loc_seq
) {
1813 mac
->loc_seq
= tmp_seq
;
1818 if (IS_ZEBRA_DEBUG_EVPN_MH_MAC
) {
1819 char mac_buf
[MAC_BUF_SIZE
];
1821 zlog_debug("sync-mac %s vni %u mac %pEA es %s seq %d f %s%s%s",
1822 ctx
->mac_created
? "created" : "updated",
1823 zevpn
->vni
, macaddr
,
1824 mac
->es
? mac
->es
->esi_str
: "-", mac
->loc_seq
,
1825 zebra_evpn_zebra_mac_flag_dump(mac
, mac_buf
,
1827 inform_bgp
? "inform_bgp" : "",
1828 inform_dataplane
? " inform_dp" : "");
1832 zebra_evpn_mac_send_add_del_to_client(mac
, old_bgp_ready
,
1835 /* neighs using the mac may need to be re-sent to
1836 * bgp with updated info
1838 if (seq_change
|| es_change
|| !old_local
)
1839 zebra_evpn_process_neigh_on_local_mac_change(
1840 zevpn
, mac
, seq_change
, es_change
);
1842 if (inform_dataplane
) {
1844 /* if the mac is being created as a part of MAC-IP
1845 * route wait for the neigh to be updated or
1846 * created before programming the mac
1848 ctx
->mac_dp_update_deferred
= true;
1850 /* program the local mac in the kernel. when the ES
1851 * change we need to force the dataplane to reset
1852 * the activity as we are yet to establish activity
1855 zebra_evpn_sync_mac_dp_install(
1856 mac
, ctx
->mac_inactive
,
1857 false /* force_clear_static */, __func__
);
1863 /* update local fowarding info. return true if a dest-ES change
1866 static bool zebra_evpn_local_mac_update_fwd_info(struct zebra_mac
*mac
,
1867 struct interface
*ifp
,
1870 struct zebra_if
*zif
= ifp
->info
;
1872 ns_id_t local_ns_id
= NS_DEFAULT
;
1873 struct zebra_vrf
*zvrf
;
1874 struct zebra_evpn_es
*es
;
1876 zvrf
= ifp
->vrf
->info
;
1877 if (zvrf
&& zvrf
->zns
)
1878 local_ns_id
= zvrf
->zns
->ns_id
;
1880 zebra_evpn_mac_clear_fwd_info(mac
);
1882 es
= zif
->es_info
.es
;
1883 if (es
&& (es
->flags
& ZEBRA_EVPNES_BYPASS
))
1885 es_change
= zebra_evpn_es_mac_ref_entry(mac
, es
);
1888 /* if es is set fwd_info is not-relevant/taped-out */
1889 mac
->fwd_info
.local
.ifindex
= ifp
->ifindex
;
1890 mac
->fwd_info
.local
.ns_id
= local_ns_id
;
1891 mac
->fwd_info
.local
.vid
= vid
;
1892 zebra_evpn_mac_ifp_link(mac
, ifp
);
1898 /* Notify Local MACs to the clienti, skips GW MAC */
1899 static void zebra_evpn_send_mac_hash_entry_to_client(struct hash_bucket
*bucket
,
1902 struct mac_walk_ctx
*wctx
= arg
;
1903 struct zebra_mac
*zmac
= bucket
->data
;
1905 if (CHECK_FLAG(zmac
->flags
, ZEBRA_MAC_DEF_GW
))
1908 if (CHECK_FLAG(zmac
->flags
, ZEBRA_MAC_LOCAL
))
1909 zebra_evpn_mac_send_add_to_client(wctx
->zevpn
->vni
,
1910 &zmac
->macaddr
, zmac
->flags
,
1911 zmac
->loc_seq
, zmac
->es
);
1914 /* Iterator to Notify Local MACs of a EVPN */
1915 void zebra_evpn_send_mac_list_to_client(struct zebra_evpn
*zevpn
)
1917 struct mac_walk_ctx wctx
;
1919 if (!zevpn
->mac_table
)
1922 memset(&wctx
, 0, sizeof(struct mac_walk_ctx
));
1925 hash_iterate(zevpn
->mac_table
, zebra_evpn_send_mac_hash_entry_to_client
,
1929 void zebra_evpn_rem_mac_del(struct zebra_evpn
*zevpn
, struct zebra_mac
*mac
)
1931 zebra_evpn_process_neigh_on_remote_mac_del(zevpn
, mac
);
1932 /* the remote sequence number in the auto mac entry
1933 * needs to be reset to 0 as the mac entry may have
1934 * been removed on all VTEPs (including
1935 * the originating one)
1939 /* If all remote neighbors referencing a remote MAC
1940 * go away, we need to uninstall the MAC.
1942 if (remote_neigh_count(mac
) == 0) {
1943 zebra_evpn_rem_mac_uninstall(zevpn
, mac
, false /*force*/);
1944 zebra_evpn_es_mac_deref_entry(mac
);
1945 UNSET_FLAG(mac
->flags
, ZEBRA_MAC_REMOTE
);
1948 if (list_isempty(mac
->neigh_list
))
1949 zebra_evpn_mac_del(zevpn
, mac
);
1951 SET_FLAG(mac
->flags
, ZEBRA_MAC_AUTO
);
1954 /* Print Duplicate MAC */
1955 void zebra_evpn_print_dad_mac_hash(struct hash_bucket
*bucket
, void *ctxt
)
1957 struct zebra_mac
*mac
;
1959 mac
= (struct zebra_mac
*)bucket
->data
;
1963 if (CHECK_FLAG(mac
->flags
, ZEBRA_MAC_DUPLICATE
))
1964 zebra_evpn_print_mac_hash(bucket
, ctxt
);
1967 /* Print Duplicate MAC in detail */
1968 void zebra_evpn_print_dad_mac_hash_detail(struct hash_bucket
*bucket
,
1971 struct zebra_mac
*mac
;
1973 mac
= (struct zebra_mac
*)bucket
->data
;
1977 if (CHECK_FLAG(mac
->flags
, ZEBRA_MAC_DUPLICATE
))
1978 zebra_evpn_print_mac_hash_detail(bucket
, ctxt
);
1981 int zebra_evpn_mac_remote_macip_add(
1982 struct zebra_evpn
*zevpn
, struct zebra_vrf
*zvrf
,
1983 const struct ethaddr
*macaddr
, uint16_t ipa_len
,
1984 const struct ipaddr
*ipaddr
, struct zebra_mac
**macp
,
1985 struct in_addr vtep_ip
, uint8_t flags
, uint32_t seq
, const esi_t
*esi
)
1987 char buf1
[INET6_ADDRSTRLEN
];
1991 bool do_dad
= false;
1992 bool is_dup_detect
= false;
1994 bool old_static
= false;
1995 struct zebra_mac
*mac
;
1996 bool old_es_present
;
1997 bool new_es_present
;
1999 sticky
= !!CHECK_FLAG(flags
, ZEBRA_MACIP_TYPE_STICKY
);
2000 remote_gw
= !!CHECK_FLAG(flags
, ZEBRA_MACIP_TYPE_GW
);
2002 mac
= zebra_evpn_mac_lookup(zevpn
, macaddr
);
2004 /* Ignore if the mac is already present as a gateway mac */
2005 if (mac
&& CHECK_FLAG(mac
->flags
, ZEBRA_MAC_DEF_GW
)
2006 && CHECK_FLAG(flags
, ZEBRA_MACIP_TYPE_GW
)) {
2007 if (IS_ZEBRA_DEBUG_VXLAN
)
2009 "Ignore remote MACIP ADD VNI %u MAC %pEA%s%s as MAC is already configured as gateway MAC",
2010 zevpn
->vni
, macaddr
,
2011 ipa_len
? " IP " : "",
2012 ipa_len
? ipaddr2str(ipaddr
, buf1
, sizeof(buf1
))
2017 old_esi
= (mac
&& mac
->es
) ? &mac
->es
->esi
: zero_esi
;
2019 /* check if the remote MAC is unknown or has a change.
2020 * If so, that needs to be updated first. Note that client could
2021 * install MAC and MACIP separately or just install the latter.
2023 if (!mac
|| !CHECK_FLAG(mac
->flags
, ZEBRA_MAC_REMOTE
)
2024 || sticky
!= !!CHECK_FLAG(mac
->flags
, ZEBRA_MAC_STICKY
)
2025 || remote_gw
!= !!CHECK_FLAG(mac
->flags
, ZEBRA_MAC_REMOTE_DEF_GW
)
2026 || !IPV4_ADDR_SAME(&mac
->fwd_info
.r_vtep_ip
, &vtep_ip
)
2027 || memcmp(old_esi
, esi
, sizeof(esi_t
)) || seq
!= mac
->rem_seq
)
2032 mac
= zebra_evpn_mac_add(zevpn
, macaddr
);
2033 zebra_evpn_es_mac_ref(mac
, esi
);
2035 /* Is this MAC created for a MACIP? */
2037 SET_FLAG(mac
->flags
, ZEBRA_MAC_AUTO
);
2039 /* When host moves but changes its (MAC,IP)
2040 * binding, BGP may install a MACIP entry that
2041 * corresponds to "older" location of the host
2042 * in transient situations (because {IP1,M1}
2043 * is a different route from {IP1,M2}). Check
2044 * the sequence number and ignore this update
2047 if (!zebra_evpn_mac_is_bgp_seq_ok(
2048 zevpn
, mac
, seq
, ipa_len
, ipaddr
, false))
2051 old_es_present
= !!mac
->es
;
2052 zebra_evpn_es_mac_ref(mac
, esi
);
2053 new_es_present
= !!mac
->es
;
2054 /* XXX - dataplane is curently not able to handle a MAC
2055 * replace if the destination changes from L2-NHG to
2056 * single VTEP and vice-versa. So delete the old entry
2059 if (old_es_present
!= new_es_present
)
2060 zebra_evpn_rem_mac_uninstall(zevpn
, mac
, false);
2063 /* Check MAC's curent state is local (this is the case
2064 * where MAC has moved from L->R) and check previous
2065 * detection started via local learning.
2066 * RFC-7432: A PE/VTEP that detects a MAC mobility
2067 * event via local learning starts an M-second timer.
2069 * VTEP-IP or seq. change alone is not considered
2070 * for dup. detection.
2072 * MAC is already marked duplicate set dad, then
2073 * is_dup_detect will be set to not install the entry.
2075 if ((!CHECK_FLAG(mac
->flags
, ZEBRA_MAC_REMOTE
)
2077 || CHECK_FLAG(mac
->flags
, ZEBRA_MAC_DUPLICATE
))
2080 /* Remove local MAC from BGP. */
2081 if (CHECK_FLAG(mac
->flags
, ZEBRA_MAC_LOCAL
)) {
2082 /* force drop the sync flags */
2083 old_static
= zebra_evpn_mac_is_static(mac
);
2084 if (IS_ZEBRA_DEBUG_EVPN_MH_MAC
) {
2085 char mac_buf
[MAC_BUF_SIZE
];
2088 "sync-mac->remote vni %u mac %pEA es %s seq %d f %s",
2089 zevpn
->vni
, macaddr
,
2090 mac
->es
? mac
->es
->esi_str
: "-",
2092 zebra_evpn_zebra_mac_flag_dump(
2093 mac
, mac_buf
, sizeof(mac_buf
)));
2096 zebra_evpn_mac_clear_sync_info(mac
);
2097 zebra_evpn_mac_send_del_to_client(zevpn
->vni
, macaddr
,
2102 /* Set "auto" and "remote" forwarding info. */
2103 zebra_evpn_mac_clear_fwd_info(mac
);
2104 UNSET_FLAG(mac
->flags
, ZEBRA_MAC_ALL_LOCAL_FLAGS
);
2105 SET_FLAG(mac
->flags
, ZEBRA_MAC_REMOTE
);
2106 mac
->fwd_info
.r_vtep_ip
= vtep_ip
;
2109 SET_FLAG(mac
->flags
, ZEBRA_MAC_STICKY
);
2111 UNSET_FLAG(mac
->flags
, ZEBRA_MAC_STICKY
);
2114 SET_FLAG(mac
->flags
, ZEBRA_MAC_REMOTE_DEF_GW
);
2116 UNSET_FLAG(mac
->flags
, ZEBRA_MAC_REMOTE_DEF_GW
);
2118 zebra_evpn_dup_addr_detect_for_mac(
2119 zvrf
, mac
, mac
->fwd_info
.r_vtep_ip
, do_dad
,
2120 &is_dup_detect
, false);
2122 if (!is_dup_detect
) {
2123 zebra_evpn_process_neigh_on_remote_mac_add(zevpn
, mac
);
2124 /* Install the entry. */
2125 zebra_evpn_rem_mac_install(zevpn
, mac
, old_static
);
2129 /* Update seq number. */
2132 /* If there is no IP, return after clearing AUTO flag of MAC. */
2134 UNSET_FLAG(mac
->flags
, ZEBRA_MAC_AUTO
);
2141 int zebra_evpn_add_update_local_mac(struct zebra_vrf
*zvrf
,
2142 struct zebra_evpn
*zevpn
,
2143 struct interface
*ifp
,
2144 const struct ethaddr
*macaddr
, vlanid_t vid
,
2145 bool sticky
, bool local_inactive
,
2146 bool dp_static
, struct zebra_mac
*mac
)
2148 bool mac_sticky
= false;
2149 bool inform_client
= false;
2150 bool upd_neigh
= false;
2151 bool is_dup_detect
= false;
2152 struct in_addr vtep_ip
= {.s_addr
= 0};
2153 bool es_change
= false;
2155 /* assume inactive if not present or if not local */
2156 bool old_local_inactive
= true;
2157 bool old_bgp_ready
= false;
2158 bool inform_dataplane
= false;
2159 bool new_static
= false;
2162 /* Check if we need to create or update or it is a NO-OP. */
2164 mac
= zebra_evpn_mac_lookup(zevpn
, macaddr
);
2166 if (IS_ZEBRA_DEBUG_VXLAN
|| IS_ZEBRA_DEBUG_EVPN_MH_MAC
)
2168 "ADD %sMAC %pEA intf %s(%u) VID %u -> VNI %u%s",
2169 sticky
? "sticky " : "", macaddr
,
2170 ifp
->name
, ifp
->ifindex
, vid
, zevpn
->vni
,
2171 local_inactive
? " local-inactive" : "");
2173 mac
= zebra_evpn_mac_add(zevpn
, macaddr
);
2174 SET_FLAG(mac
->flags
, ZEBRA_MAC_LOCAL
);
2175 es_change
= zebra_evpn_local_mac_update_fwd_info(mac
, ifp
, vid
);
2177 SET_FLAG(mac
->flags
, ZEBRA_MAC_STICKY
);
2178 inform_client
= true;
2180 if (IS_ZEBRA_DEBUG_VXLAN
|| IS_ZEBRA_DEBUG_EVPN_MH_MAC
) {
2181 char mac_buf
[MAC_BUF_SIZE
];
2184 "UPD %sMAC %pEA intf %s(%u) VID %u -> VNI %u %scurFlags %s",
2185 sticky
? "sticky " : "", macaddr
,
2186 ifp
->name
, ifp
->ifindex
, vid
, zevpn
->vni
,
2187 local_inactive
? "local-inactive " : "",
2188 zebra_evpn_zebra_mac_flag_dump(
2189 mac
, mac_buf
, sizeof(mac_buf
)));
2192 if (CHECK_FLAG(mac
->flags
, ZEBRA_MAC_LOCAL
)) {
2193 struct interface
*old_ifp
;
2197 zebra_evpn_mac_get_access_info(mac
, &old_ifp
, &old_vid
);
2199 zebra_evpn_mac_is_ready_for_bgp(mac
->flags
);
2200 old_local_inactive
=
2201 !!(mac
->flags
& ZEBRA_MAC_LOCAL_INACTIVE
);
2202 old_static
= zebra_evpn_mac_is_static(mac
);
2203 if (CHECK_FLAG(mac
->flags
, ZEBRA_MAC_STICKY
))
2205 es_change
= zebra_evpn_local_mac_update_fwd_info(
2209 * Update any changes and if changes are relevant to
2212 if (mac_sticky
== sticky
&& old_ifp
== ifp
2214 && old_local_inactive
== local_inactive
2215 && dp_static
== old_static
&& !es_change
) {
2216 if (IS_ZEBRA_DEBUG_VXLAN
)
2218 " Add/Update %sMAC %pEA intf %s(%u) VID %u -> VNI %u%s, "
2219 "entry exists and has not changed ",
2220 sticky
? "sticky " : "",
2222 ifp
->ifindex
, vid
, zevpn
->vni
,
2228 if (mac_sticky
!= sticky
) {
2230 SET_FLAG(mac
->flags
, ZEBRA_MAC_STICKY
);
2232 UNSET_FLAG(mac
->flags
,
2234 inform_client
= true;
2237 /* If an es_change is detected we need to advertise
2238 * the route with a sequence that is one
2239 * greater. This is need to indicate a mac-move
2243 /* update the sequence number only if the entry
2246 if (!local_inactive
)
2247 mac
->loc_seq
= mac
->loc_seq
+ 1;
2248 /* force drop the peer/sync info as it is
2249 * simply no longer relevant
2251 if (CHECK_FLAG(mac
->flags
,
2252 ZEBRA_MAC_ALL_PEER_FLAGS
)) {
2253 zebra_evpn_mac_clear_sync_info(mac
);
2255 zebra_evpn_mac_is_static(mac
);
2256 /* if we clear peer-flags we
2257 * also need to notify the dataplane
2258 * to drop the static flag
2260 if (old_static
!= new_static
)
2261 inform_dataplane
= true;
2264 } else if (CHECK_FLAG(mac
->flags
, ZEBRA_MAC_REMOTE
)
2265 || CHECK_FLAG(mac
->flags
, ZEBRA_MAC_AUTO
)) {
2266 bool do_dad
= false;
2269 * MAC has either moved or was "internally" created due
2270 * to a neighbor learn and is now actually learnt. If
2271 * it was learnt as a remote sticky MAC, this is an
2274 if (CHECK_FLAG(mac
->flags
, ZEBRA_MAC_STICKY
)) {
2276 EC_ZEBRA_STICKY_MAC_ALREADY_LEARNT
,
2277 "MAC %pEA already learnt as remote sticky MAC behind VTEP %pI4 VNI %u",
2279 &mac
->fwd_info
.r_vtep_ip
,
2284 /* If an actual move, compute MAC's seq number */
2285 if (CHECK_FLAG(mac
->flags
, ZEBRA_MAC_REMOTE
)) {
2287 MAX(mac
->rem_seq
+ 1, mac
->loc_seq
);
2288 vtep_ip
= mac
->fwd_info
.r_vtep_ip
;
2289 /* Trigger DAD for remote MAC */
2293 UNSET_FLAG(mac
->flags
, ZEBRA_MAC_REMOTE
);
2294 UNSET_FLAG(mac
->flags
, ZEBRA_MAC_AUTO
);
2295 SET_FLAG(mac
->flags
, ZEBRA_MAC_LOCAL
);
2296 es_change
= zebra_evpn_local_mac_update_fwd_info(
2299 SET_FLAG(mac
->flags
, ZEBRA_MAC_STICKY
);
2301 UNSET_FLAG(mac
->flags
, ZEBRA_MAC_STICKY
);
2303 * We have to inform BGP of this MAC as well as process
2306 inform_client
= true;
2309 zebra_evpn_dup_addr_detect_for_mac(
2310 zvrf
, mac
, vtep_ip
, do_dad
, &is_dup_detect
,
2312 if (is_dup_detect
) {
2313 inform_client
= false;
2320 /* if the dataplane thinks the entry is sync but it is
2321 * not sync in zebra (or vice-versa) we need to re-install
2324 new_static
= zebra_evpn_mac_is_static(mac
);
2325 if (dp_static
!= new_static
)
2326 inform_dataplane
= true;
2329 SET_FLAG(mac
->flags
, ZEBRA_MAC_LOCAL_INACTIVE
);
2331 UNSET_FLAG(mac
->flags
, ZEBRA_MAC_LOCAL_INACTIVE
);
2333 new_bgp_ready
= zebra_evpn_mac_is_ready_for_bgp(mac
->flags
);
2334 /* if local-activity has changed we need update bgp
2335 * even if bgp already knows about the mac
2337 if ((old_local_inactive
!= local_inactive
)
2338 || (new_bgp_ready
!= old_bgp_ready
)) {
2339 if (IS_ZEBRA_DEBUG_EVPN_MH_MAC
) {
2340 char mac_buf
[MAC_BUF_SIZE
];
2343 "local mac vni %u mac %pEA es %s seq %d f %s%s",
2344 zevpn
->vni
, macaddr
,
2345 mac
->es
? mac
->es
->esi_str
: "", mac
->loc_seq
,
2346 zebra_evpn_zebra_mac_flag_dump(mac
, mac_buf
,
2348 local_inactive
? "local-inactive" : "");
2352 inform_client
= true;
2356 inform_client
= true;
2360 /* Inform dataplane if required. */
2361 if (inform_dataplane
)
2362 zebra_evpn_sync_mac_dp_install(mac
, false /* set_inactive */,
2363 false /* force_clear_static */,
2366 /* Inform BGP if required. */
2368 zebra_evpn_mac_send_add_del_to_client(mac
, old_bgp_ready
,
2371 /* Process all neighbors associated with this MAC, if required. */
2373 zebra_evpn_process_neigh_on_local_mac_change(zevpn
, mac
, 0,
2379 int zebra_evpn_del_local_mac(struct zebra_evpn
*zevpn
, struct zebra_mac
*mac
,
2385 if (IS_ZEBRA_DEBUG_VXLAN
)
2386 zlog_debug("DEL MAC %pEA VNI %u seq %u flags 0x%x nbr count %u",
2387 &mac
->macaddr
, zevpn
->vni
, mac
->loc_seq
, mac
->flags
,
2388 listcount(mac
->neigh_list
));
2390 old_bgp_ready
= zebra_evpn_mac_is_ready_for_bgp(mac
->flags
);
2391 if (!clear_static
&& zebra_evpn_mac_is_static(mac
)) {
2392 /* this is a synced entry and can only be removed when the
2393 * es-peers stop advertising it.
2395 zebra_evpn_mac_clear_fwd_info(mac
);
2397 if (IS_ZEBRA_DEBUG_EVPN_MH_MAC
) {
2398 char mac_buf
[MAC_BUF_SIZE
];
2401 "re-add sync-mac vni %u mac %pEA es %s seq %d f %s",
2402 zevpn
->vni
, &mac
->macaddr
,
2403 mac
->es
? mac
->es
->esi_str
: "-", mac
->loc_seq
,
2404 zebra_evpn_zebra_mac_flag_dump(
2405 mac
, mac_buf
, sizeof(mac_buf
)));
2408 /* inform-bgp about change in local-activity if any */
2409 if (!CHECK_FLAG(mac
->flags
, ZEBRA_MAC_LOCAL_INACTIVE
)) {
2410 SET_FLAG(mac
->flags
, ZEBRA_MAC_LOCAL_INACTIVE
);
2412 zebra_evpn_mac_is_ready_for_bgp(mac
->flags
);
2413 zebra_evpn_mac_send_add_del_to_client(
2414 mac
, old_bgp_ready
, new_bgp_ready
);
2417 /* re-install the inactive entry in the kernel */
2418 zebra_evpn_sync_mac_dp_install(mac
, true /* set_inactive */,
2419 false /* force_clear_static */,
2425 /* flush the peer info */
2426 zebra_evpn_mac_clear_sync_info(mac
);
2428 /* Update all the neigh entries associated with this mac */
2429 zebra_evpn_process_neigh_on_local_mac_del(zevpn
, mac
);
2431 /* Remove MAC from BGP. */
2432 zebra_evpn_mac_send_del_to_client(zevpn
->vni
, &mac
->macaddr
, mac
->flags
,
2435 zebra_evpn_es_mac_deref_entry(mac
);
2437 /* remove links to the destination access port */
2438 zebra_evpn_mac_clear_fwd_info(mac
);
2441 * If there are no neigh associated with the mac delete the mac
2442 * else mark it as AUTO for forward reference
2444 if (!listcount(mac
->neigh_list
)) {
2445 zebra_evpn_mac_del(zevpn
, mac
);
2447 UNSET_FLAG(mac
->flags
, ZEBRA_MAC_ALL_LOCAL_FLAGS
);
2448 UNSET_FLAG(mac
->flags
, ZEBRA_MAC_STICKY
);
2449 SET_FLAG(mac
->flags
, ZEBRA_MAC_AUTO
);
2455 int zebra_evpn_mac_gw_macip_add(struct interface
*ifp
, struct zebra_evpn
*zevpn
,
2456 const struct ipaddr
*ip
,
2457 struct zebra_mac
**macp
,
2458 const struct ethaddr
*macaddr
, vlanid_t vlan_id
,
2461 struct zebra_mac
*mac
;
2462 ns_id_t local_ns_id
= NS_DEFAULT
;
2463 struct zebra_vrf
*zvrf
;
2465 zvrf
= ifp
->vrf
->info
;
2466 if (zvrf
&& zvrf
->zns
)
2467 local_ns_id
= zvrf
->zns
->ns_id
;
2469 mac
= zebra_evpn_mac_lookup(zevpn
, macaddr
);
2471 mac
= zebra_evpn_mac_add(zevpn
, macaddr
);
2473 /* Set "local" forwarding info. */
2474 zebra_evpn_mac_clear_fwd_info(mac
);
2475 SET_FLAG(mac
->flags
, ZEBRA_MAC_LOCAL
);
2476 SET_FLAG(mac
->flags
, ZEBRA_MAC_AUTO
);
2478 SET_FLAG(mac
->flags
, ZEBRA_MAC_DEF_GW
);
2479 mac
->fwd_info
.local
.ifindex
= ifp
->ifindex
;
2480 mac
->fwd_info
.local
.ns_id
= local_ns_id
;
2481 mac
->fwd_info
.local
.vid
= vlan_id
;
2488 void zebra_evpn_mac_svi_del(struct interface
*ifp
, struct zebra_evpn
*zevpn
)
2490 struct zebra_mac
*mac
;
2491 struct ethaddr macaddr
;
2494 if (!zebra_evpn_mh_do_adv_svi_mac())
2497 memcpy(&macaddr
.octet
, ifp
->hw_addr
, ETH_ALEN
);
2498 mac
= zebra_evpn_mac_lookup(zevpn
, &macaddr
);
2499 if (mac
&& CHECK_FLAG(mac
->flags
, ZEBRA_MAC_SVI
)) {
2500 if (IS_ZEBRA_DEBUG_EVPN_MH_ES
)
2501 zlog_debug("SVI %s mac free", ifp
->name
);
2503 old_bgp_ready
= zebra_evpn_mac_is_ready_for_bgp(mac
->flags
);
2504 UNSET_FLAG(mac
->flags
, ZEBRA_MAC_SVI
);
2505 zebra_evpn_mac_send_add_del_to_client(mac
, old_bgp_ready
,
2507 zebra_evpn_deref_ip2mac(mac
->zevpn
, mac
);
2511 void zebra_evpn_mac_svi_add(struct interface
*ifp
, struct zebra_evpn
*zevpn
)
2513 struct zebra_mac
*mac
= NULL
;
2514 struct ethaddr macaddr
;
2515 struct zebra_if
*zif
= ifp
->info
;
2519 if (!zebra_evpn_mh_do_adv_svi_mac()
2520 || !zebra_evpn_send_to_client_ok(zevpn
))
2523 memcpy(&macaddr
.octet
, ifp
->hw_addr
, ETH_ALEN
);
2526 mac
= zebra_evpn_mac_lookup(zevpn
, &macaddr
);
2527 if (mac
&& CHECK_FLAG(mac
->flags
, ZEBRA_MAC_SVI
))
2530 /* add/update mac */
2531 if (IS_ZEBRA_DEBUG_EVPN_MH_ES
)
2532 zlog_debug("SVI %s mac add", zif
->ifp
->name
);
2534 old_bgp_ready
= (mac
&& zebra_evpn_mac_is_ready_for_bgp(mac
->flags
))
2539 zebra_evpn_mac_gw_macip_add(ifp
, zevpn
, NULL
, &mac
, &macaddr
, 0, false);
2541 SET_FLAG(mac
->flags
, ZEBRA_MAC_SVI
);
2543 new_bgp_ready
= zebra_evpn_mac_is_ready_for_bgp(mac
->flags
);
2544 zebra_evpn_mac_send_add_del_to_client(mac
, old_bgp_ready
,