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
**p_ifp
,
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 *p_ifp
= 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 *p_ifp
= 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();
628 vty
= (struct vty
*)ctxt
;
629 prefix_mac2str(&mac
->macaddr
, buf1
, sizeof(buf1
));
631 uptime
= monotime(NULL
);
632 uptime
-= mac
->uptime
;
634 frrtime_to_interval(uptime
, up_str
, sizeof(up_str
));
637 json_object
*json_mac
= json_object_new_object();
639 if (CHECK_FLAG(mac
->flags
, ZEBRA_MAC_LOCAL
)) {
640 struct interface
*ifp
;
643 zebra_evpn_mac_get_access_info(mac
, &ifp
, &vid
);
644 json_object_string_add(json_mac
, "type", "local");
646 json_object_string_add(json_mac
, "intf",
648 json_object_int_add(json_mac
, "ifindex",
652 json_object_int_add(json_mac
, "vlan", vid
);
653 } else if (CHECK_FLAG(mac
->flags
, ZEBRA_MAC_REMOTE
)) {
654 json_object_string_add(json_mac
, "type", "remote");
655 json_object_string_addf(json_mac
, "remoteVtep", "%pI4",
656 &mac
->fwd_info
.r_vtep_ip
);
657 } else if (CHECK_FLAG(mac
->flags
, ZEBRA_MAC_AUTO
))
658 json_object_string_add(json_mac
, "type", "auto");
660 if (CHECK_FLAG(mac
->flags
, ZEBRA_MAC_STICKY
))
661 json_object_boolean_true_add(json_mac
, "stickyMac");
663 if (CHECK_FLAG(mac
->flags
, ZEBRA_MAC_SVI
))
664 json_object_boolean_true_add(json_mac
, "sviMac");
666 if (CHECK_FLAG(mac
->flags
, ZEBRA_MAC_DEF_GW
))
667 json_object_boolean_true_add(json_mac
,
670 if (CHECK_FLAG(mac
->flags
, ZEBRA_MAC_REMOTE_DEF_GW
))
671 json_object_boolean_true_add(json_mac
,
674 json_object_string_add(json_mac
, "uptime", up_str
);
675 json_object_int_add(json_mac
, "localSequence", mac
->loc_seq
);
676 json_object_int_add(json_mac
, "remoteSequence", mac
->rem_seq
);
678 json_object_int_add(json_mac
, "detectionCount", mac
->dad_count
);
679 if (CHECK_FLAG(mac
->flags
, ZEBRA_MAC_DUPLICATE
))
680 json_object_boolean_true_add(json_mac
, "isDuplicate");
682 json_object_boolean_false_add(json_mac
, "isDuplicate");
684 json_object_int_add(json_mac
, "syncNeighCount",
685 mac
->sync_neigh_cnt
);
686 if (CHECK_FLAG(mac
->flags
, ZEBRA_MAC_LOCAL_INACTIVE
))
687 json_object_boolean_true_add(json_mac
, "localInactive");
688 if (CHECK_FLAG(mac
->flags
, ZEBRA_MAC_ES_PEER_PROXY
))
689 json_object_boolean_true_add(json_mac
, "peerProxy");
690 if (CHECK_FLAG(mac
->flags
, ZEBRA_MAC_ES_PEER_ACTIVE
))
691 json_object_boolean_true_add(json_mac
, "peerActive");
693 json_object_string_add(
694 json_mac
, "peerActiveHold",
695 thread_timer_to_hhmmss(thread_buf
,
699 json_object_string_add(json_mac
, "esi",
701 /* print all the associated neigh */
702 if (!listcount(mac
->neigh_list
))
703 json_object_string_add(json_mac
, "neighbors", "none");
705 json_object
*json_active_nbrs
= json_object_new_array();
706 json_object
*json_inactive_nbrs
=
707 json_object_new_array();
708 json_object
*json_nbrs
= json_object_new_object();
710 for (ALL_LIST_ELEMENTS_RO(mac
->neigh_list
, node
, n
)) {
711 if (IS_ZEBRA_NEIGH_ACTIVE(n
))
712 json_object_array_add(
714 json_object_new_string(
719 json_object_array_add(
721 json_object_new_string(
727 json_object_object_add(json_nbrs
, "active",
729 json_object_object_add(json_nbrs
, "inactive",
731 json_object_object_add(json_mac
, "neighbors",
735 json_object_object_add(json
, buf1
, json_mac
);
737 vty_out(vty
, "MAC: %s\n", buf1
);
739 if (CHECK_FLAG(mac
->flags
, ZEBRA_MAC_LOCAL
)) {
740 struct interface
*ifp
;
743 zebra_evpn_mac_get_access_info(mac
, &ifp
, &vid
);
746 vty_out(vty
, " ESI: %s\n", mac
->es
->esi_str
);
749 vty_out(vty
, " Intf: %s(%u)", ifp
->name
,
752 vty_out(vty
, " Intf: -");
753 vty_out(vty
, " VLAN: %u", vid
);
754 } else if (CHECK_FLAG(mac
->flags
, ZEBRA_MAC_REMOTE
)) {
756 vty_out(vty
, " Remote ES: %s",
759 vty_out(vty
, " Remote VTEP: %pI4",
760 &mac
->fwd_info
.r_vtep_ip
);
761 } else if (CHECK_FLAG(mac
->flags
, ZEBRA_MAC_AUTO
)) {
762 vty_out(vty
, " Auto Mac ");
765 if (CHECK_FLAG(mac
->flags
, ZEBRA_MAC_STICKY
))
766 vty_out(vty
, " Sticky Mac ");
768 if (CHECK_FLAG(mac
->flags
, ZEBRA_MAC_SVI
))
769 vty_out(vty
, " SVI-Mac ");
771 if (CHECK_FLAG(mac
->flags
, ZEBRA_MAC_DEF_GW
))
772 vty_out(vty
, " Default-gateway Mac ");
774 if (CHECK_FLAG(mac
->flags
, ZEBRA_MAC_REMOTE_DEF_GW
))
775 vty_out(vty
, " Remote-gateway Mac ");
778 vty_out(vty
, " Sync-info: neigh#: %u", mac
->sync_neigh_cnt
);
779 if (CHECK_FLAG(mac
->flags
, ZEBRA_MAC_LOCAL_INACTIVE
))
780 vty_out(vty
, " local-inactive");
781 if (CHECK_FLAG(mac
->flags
, ZEBRA_MAC_ES_PEER_PROXY
))
782 vty_out(vty
, " peer-proxy");
783 if (CHECK_FLAG(mac
->flags
, ZEBRA_MAC_ES_PEER_ACTIVE
))
784 vty_out(vty
, " peer-active");
786 vty_out(vty
, " (ht: %s)",
787 thread_timer_to_hhmmss(thread_buf
,
791 vty_out(vty
, " Local Seq: %u Remote Seq: %u\n", mac
->loc_seq
,
793 vty_out(vty
, " Uptime: %s\n", up_str
);
795 if (CHECK_FLAG(mac
->flags
, ZEBRA_MAC_DUPLICATE
)) {
796 vty_out(vty
, " Duplicate, detected at %s",
797 time_to_string(mac
->dad_dup_detect_time
,
799 } else if (mac
->dad_count
) {
800 monotime_since(&mac
->detect_start_time
,
802 if (detect_start_time
.tv_sec
<= zvrf
->dad_time
) {
803 time_to_string(mac
->detect_start_time
.tv_sec
,
806 " Duplicate detection started at %s, detection count %u\n",
807 timebuf
, mac
->dad_count
);
811 /* print all the associated neigh */
812 vty_out(vty
, " Neighbors:\n");
813 if (!listcount(mac
->neigh_list
))
814 vty_out(vty
, " No Neighbors\n");
816 for (ALL_LIST_ELEMENTS_RO(mac
->neigh_list
, node
, n
)) {
817 vty_out(vty
, " %s %s\n",
818 ipaddr2str(&n
->ip
, buf2
, sizeof(buf2
)),
819 (IS_ZEBRA_NEIGH_ACTIVE(n
)
829 static char *zebra_evpn_print_mac_flags(struct zebra_mac
*mac
, char *flags_buf
,
832 snprintf(flags_buf
, flags_buf_sz
, "%s%s%s%s",
833 mac
->sync_neigh_cnt
? "N" : "",
834 (mac
->flags
& ZEBRA_MAC_ES_PEER_ACTIVE
) ? "P" : "",
835 (mac
->flags
& ZEBRA_MAC_ES_PEER_PROXY
) ? "X" : "",
836 (mac
->flags
& ZEBRA_MAC_LOCAL_INACTIVE
) ? "I" : "");
842 * Print MAC hash entry - called for display of all MACs.
844 void zebra_evpn_print_mac_hash(struct hash_bucket
*bucket
, void *ctxt
)
847 json_object
*json_mac_hdr
= NULL
, *json_mac
= NULL
;
848 struct zebra_mac
*mac
;
849 char buf1
[ETHER_ADDR_STRLEN
];
850 char addr_buf
[PREFIX_STRLEN
];
851 struct mac_walk_ctx
*wctx
= ctxt
;
855 json_mac_hdr
= wctx
->json
;
856 mac
= (struct zebra_mac
*)bucket
->data
;
858 prefix_mac2str(&mac
->macaddr
, buf1
, sizeof(buf1
));
861 json_mac
= json_object_new_object();
863 if (CHECK_FLAG(mac
->flags
, ZEBRA_MAC_LOCAL
)) {
864 struct interface
*ifp
;
867 if (wctx
->flags
& SHOW_REMOTE_MAC_FROM_VTEP
)
870 zebra_evpn_mac_get_access_info(mac
, &ifp
, &vid
);
871 if (json_mac_hdr
== NULL
) {
872 vty_out(vty
, "%-17s %-6s %-5s %-30s", buf1
, "local",
873 zebra_evpn_print_mac_flags(mac
, flags_buf
,
875 ifp
? ifp
->name
: "-");
877 json_object_string_add(json_mac
, "type", "local");
879 json_object_string_add(json_mac
, "intf",
883 if (json_mac_hdr
== NULL
)
884 vty_out(vty
, " %-5u", vid
);
886 json_object_int_add(json_mac
, "vlan", vid
);
887 } else /* No vid? fill out the space */
888 if (json_mac_hdr
== NULL
)
889 vty_out(vty
, " %-5s", "");
890 if (json_mac_hdr
== NULL
) {
891 vty_out(vty
, " %u/%u", mac
->loc_seq
, mac
->rem_seq
);
894 json_object_int_add(json_mac
, "localSequence",
896 json_object_int_add(json_mac
, "remoteSequence",
898 json_object_int_add(json_mac
, "detectionCount",
900 if (CHECK_FLAG(mac
->flags
, ZEBRA_MAC_DUPLICATE
))
901 json_object_boolean_true_add(json_mac
,
904 json_object_boolean_false_add(json_mac
,
906 json_object_object_add(json_mac_hdr
, buf1
, json_mac
);
911 } else if (CHECK_FLAG(mac
->flags
, ZEBRA_MAC_REMOTE
)) {
913 if ((wctx
->flags
& SHOW_REMOTE_MAC_FROM_VTEP
)
914 && !IPV4_ADDR_SAME(&mac
->fwd_info
.r_vtep_ip
,
918 if (json_mac_hdr
== NULL
) {
919 if ((wctx
->flags
& SHOW_REMOTE_MAC_FROM_VTEP
)
920 && (wctx
->count
== 0)) {
921 vty_out(vty
, "\nVNI %u\n\n", wctx
->zevpn
->vni
);
922 vty_out(vty
, "%-17s %-6s %-5s%-30s %-5s %s\n",
923 "MAC", "Type", "Flags",
924 "Intf/Remote ES/VTEP", "VLAN",
928 inet_ntop(AF_INET
, &mac
->fwd_info
.r_vtep_ip
,
929 addr_buf
, sizeof(addr_buf
));
931 vty_out(vty
, "%-17s %-6s %-5s %-30s %-5s %u/%u\n", buf1
,
933 zebra_evpn_print_mac_flags(mac
, flags_buf
,
935 mac
->es
? mac
->es
->esi_str
: addr_buf
,
936 "", mac
->loc_seq
, mac
->rem_seq
);
938 json_object_string_add(json_mac
, "type", "remote");
939 json_object_string_addf(json_mac
, "remoteVtep", "%pI4",
940 &mac
->fwd_info
.r_vtep_ip
);
941 json_object_object_add(json_mac_hdr
, buf1
, json_mac
);
942 json_object_int_add(json_mac
, "localSequence",
944 json_object_int_add(json_mac
, "remoteSequence",
946 json_object_int_add(json_mac
, "detectionCount",
948 if (CHECK_FLAG(mac
->flags
, ZEBRA_MAC_DUPLICATE
))
949 json_object_boolean_true_add(json_mac
,
952 json_object_boolean_false_add(json_mac
,
961 * Print MAC hash entry in detail - called for display of all MACs.
963 void zebra_evpn_print_mac_hash_detail(struct hash_bucket
*bucket
, void *ctxt
)
966 json_object
*json_mac_hdr
= NULL
;
967 struct zebra_mac
*mac
;
968 struct mac_walk_ctx
*wctx
= ctxt
;
969 char buf1
[ETHER_ADDR_STRLEN
];
972 json_mac_hdr
= wctx
->json
;
973 mac
= (struct zebra_mac
*)bucket
->data
;
978 prefix_mac2str(&mac
->macaddr
, buf1
, sizeof(buf1
));
980 zebra_evpn_print_mac(mac
, vty
, json_mac_hdr
);
984 * Inform BGP about local MACIP.
986 int zebra_evpn_macip_send_msg_to_client(vni_t vni
,
987 const struct ethaddr
*macaddr
,
988 const struct ipaddr
*ip
, uint8_t flags
,
989 uint32_t seq
, int state
,
990 struct zebra_evpn_es
*es
, uint16_t cmd
)
993 struct zserv
*client
= NULL
;
994 struct stream
*s
= NULL
;
995 esi_t
*esi
= es
? &es
->esi
: zero_esi
;
997 client
= zserv_find_client(ZEBRA_ROUTE_BGP
, 0);
998 /* BGP may not be running. */
1002 s
= stream_new(ZEBRA_MAX_PACKET_SIZ
);
1004 zclient_create_header(s
, cmd
, zebra_vrf_get_evpn_id());
1005 stream_putl(s
, vni
);
1006 stream_put(s
, macaddr
->octet
, ETH_ALEN
);
1009 if (IS_IPADDR_V4(ip
))
1010 ipa_len
= IPV4_MAX_BYTELEN
;
1011 else if (IS_IPADDR_V6(ip
))
1012 ipa_len
= IPV6_MAX_BYTELEN
;
1014 stream_putl(s
, ipa_len
); /* IP address length */
1016 stream_put(s
, &ip
->ip
.addr
, ipa_len
); /* IP address */
1018 stream_putl(s
, 0); /* Just MAC. */
1020 if (cmd
== ZEBRA_MACIP_ADD
) {
1021 stream_putc(s
, flags
); /* sticky mac/gateway mac */
1022 stream_putl(s
, seq
); /* sequence number */
1023 stream_put(s
, esi
, sizeof(esi_t
));
1025 stream_putl(s
, state
); /* state - active/inactive */
1029 /* Write packet size. */
1030 stream_putw_at(s
, 0, stream_get_endp(s
));
1032 if (IS_ZEBRA_DEBUG_VXLAN
) {
1033 char flag_buf
[MACIP_BUF_SIZE
];
1036 "Send MACIP %s f %s MAC %pEA IP %pIA seq %u L2-VNI %u ESI %s to %s",
1037 (cmd
== ZEBRA_MACIP_ADD
) ? "Add" : "Del",
1038 zclient_evpn_dump_macip_flags(flags
, flag_buf
,
1040 macaddr
, ip
, seq
, vni
,
1041 es
? es
->esi_str
: "-",
1042 zebra_route_string(client
->proto
));
1045 if (cmd
== ZEBRA_MACIP_ADD
)
1046 client
->macipadd_cnt
++;
1048 client
->macipdel_cnt
++;
1050 return zserv_send_message(client
, s
);
1053 static unsigned int mac_hash_keymake(const void *p
)
1055 const struct zebra_mac
*pmac
= p
;
1056 const void *pnt
= (void *)pmac
->macaddr
.octet
;
1058 return jhash(pnt
, ETH_ALEN
, 0xa5a5a55a);
1062 * Compare two MAC addresses.
1064 static bool mac_cmp(const void *p1
, const void *p2
)
1066 const struct zebra_mac
*pmac1
= p1
;
1067 const struct zebra_mac
*pmac2
= p2
;
1069 if (pmac1
== NULL
&& pmac2
== NULL
)
1072 if (pmac1
== NULL
|| pmac2
== NULL
)
1075 return (memcmp(pmac1
->macaddr
.octet
, pmac2
->macaddr
.octet
, ETH_ALEN
)
1080 * Callback to allocate MAC hash entry.
1082 static void *zebra_evpn_mac_alloc(void *p
)
1084 const struct zebra_mac
*tmp_mac
= p
;
1085 struct zebra_mac
*mac
;
1087 mac
= XCALLOC(MTYPE_MAC
, sizeof(struct zebra_mac
));
1090 return ((void *)mac
);
1096 struct zebra_mac
*zebra_evpn_mac_add(struct zebra_evpn
*zevpn
,
1097 const struct ethaddr
*macaddr
)
1099 struct zebra_mac tmp_mac
;
1100 struct zebra_mac
*mac
= NULL
;
1102 memset(&tmp_mac
, 0, sizeof(tmp_mac
));
1103 memcpy(&tmp_mac
.macaddr
, macaddr
, ETH_ALEN
);
1104 mac
= hash_get(zevpn
->mac_table
, &tmp_mac
, zebra_evpn_mac_alloc
);
1107 mac
->dad_mac_auto_recovery_timer
= NULL
;
1109 mac
->neigh_list
= list_new();
1110 mac
->neigh_list
->cmp
= neigh_list_cmp
;
1112 mac
->uptime
= monotime(NULL
);
1113 if (IS_ZEBRA_DEBUG_VXLAN
|| IS_ZEBRA_DEBUG_EVPN_MH_MAC
) {
1114 char mac_buf
[MAC_BUF_SIZE
];
1116 zlog_debug("%s: MAC %pEA flags %s", __func__
,
1118 zebra_evpn_zebra_mac_flag_dump(mac
, mac_buf
,
1127 int zebra_evpn_mac_del(struct zebra_evpn
*zevpn
, struct zebra_mac
*mac
)
1129 struct zebra_mac
*tmp_mac
;
1131 if (IS_ZEBRA_DEBUG_VXLAN
|| IS_ZEBRA_DEBUG_EVPN_MH_MAC
) {
1132 char mac_buf
[MAC_BUF_SIZE
];
1134 zlog_debug("%s: MAC %pEA flags %s", __func__
,
1136 zebra_evpn_zebra_mac_flag_dump(mac
, mac_buf
,
1140 /* force de-ref any ES entry linked to the MAC */
1141 zebra_evpn_es_mac_deref_entry(mac
);
1143 /* remove links to the destination access port */
1144 zebra_evpn_mac_clear_fwd_info(mac
);
1146 /* Cancel proxy hold timer */
1147 zebra_evpn_mac_stop_hold_timer(mac
);
1149 /* Cancel auto recovery */
1150 THREAD_OFF(mac
->dad_mac_auto_recovery_timer
);
1152 /* If the MAC is freed before the neigh we will end up
1153 * with a stale pointer against the neigh.
1154 * The situation can arise when a MAC is in remote state
1155 * and its associated neigh is local state.
1156 * zebra_evpn_cfg_cleanup() cleans up remote neighs and MACs.
1157 * Instead of deleting remote MAC, if its neigh list is non-empty
1158 * (associated to local neighs), mark the MAC as AUTO.
1160 if (!list_isempty(mac
->neigh_list
)) {
1161 if (IS_ZEBRA_DEBUG_VXLAN
)
1163 "MAC %pEA (flags 0x%x vni %u) has non-empty neigh list "
1164 "count %u, mark MAC as AUTO",
1165 &mac
->macaddr
, mac
->flags
, zevpn
->vni
,
1166 listcount(mac
->neigh_list
));
1168 SET_FLAG(mac
->flags
, ZEBRA_MAC_AUTO
);
1172 list_delete(&mac
->neigh_list
);
1174 /* Free the VNI hash entry and allocated memory. */
1175 tmp_mac
= hash_release(zevpn
->mac_table
, mac
);
1176 XFREE(MTYPE_MAC
, tmp_mac
);
1181 static bool zebra_evpn_check_mac_del_from_db(struct mac_walk_ctx
*wctx
,
1182 struct zebra_mac
*mac
)
1184 if ((wctx
->flags
& DEL_LOCAL_MAC
) && (mac
->flags
& ZEBRA_MAC_LOCAL
))
1186 else if ((wctx
->flags
& DEL_REMOTE_MAC
)
1187 && (mac
->flags
& ZEBRA_MAC_REMOTE
))
1189 else if ((wctx
->flags
& DEL_REMOTE_MAC_FROM_VTEP
)
1190 && (mac
->flags
& ZEBRA_MAC_REMOTE
)
1191 && IPV4_ADDR_SAME(&mac
->fwd_info
.r_vtep_ip
, &wctx
->r_vtep_ip
))
1193 else if ((wctx
->flags
& DEL_LOCAL_MAC
) && (mac
->flags
& ZEBRA_MAC_AUTO
)
1194 && !listcount(mac
->neigh_list
)) {
1195 if (IS_ZEBRA_DEBUG_VXLAN
) {
1196 char mac_buf
[MAC_BUF_SIZE
];
1199 "%s: Del MAC %pEA flags %s", __func__
,
1201 zebra_evpn_zebra_mac_flag_dump(
1202 mac
, mac_buf
, sizeof(mac_buf
)));
1204 wctx
->uninstall
= 0;
1213 * Free MAC hash entry (callback)
1215 static void zebra_evpn_mac_del_hash_entry(struct hash_bucket
*bucket
, void *arg
)
1217 struct mac_walk_ctx
*wctx
= arg
;
1218 struct zebra_mac
*mac
= bucket
->data
;
1220 if (zebra_evpn_check_mac_del_from_db(wctx
, mac
)) {
1221 if (wctx
->upd_client
&& (mac
->flags
& ZEBRA_MAC_LOCAL
)) {
1222 zebra_evpn_mac_send_del_to_client(wctx
->zevpn
->vni
,
1226 if (wctx
->uninstall
) {
1227 if (zebra_evpn_mac_is_static(mac
))
1228 zebra_evpn_sync_mac_dp_install(
1229 mac
, false /* set_inactive */,
1230 true /* force_clear_static */,
1233 if (mac
->flags
& ZEBRA_MAC_REMOTE
)
1234 zebra_evpn_rem_mac_uninstall(wctx
->zevpn
, mac
,
1238 zebra_evpn_mac_del(wctx
->zevpn
, mac
);
1245 * Delete all MAC entries for this EVPN.
1247 void zebra_evpn_mac_del_all(struct zebra_evpn
*zevpn
, int uninstall
,
1248 int upd_client
, uint32_t flags
)
1250 struct mac_walk_ctx wctx
;
1252 if (!zevpn
->mac_table
)
1255 memset(&wctx
, 0, sizeof(wctx
));
1257 wctx
.uninstall
= uninstall
;
1258 wctx
.upd_client
= upd_client
;
1261 hash_iterate(zevpn
->mac_table
, zebra_evpn_mac_del_hash_entry
, &wctx
);
1265 * Look up MAC hash entry.
1267 struct zebra_mac
*zebra_evpn_mac_lookup(struct zebra_evpn
*zevpn
,
1268 const struct ethaddr
*mac
)
1270 struct zebra_mac tmp
;
1271 struct zebra_mac
*pmac
;
1273 memset(&tmp
, 0, sizeof(tmp
));
1274 memcpy(&tmp
.macaddr
, mac
, ETH_ALEN
);
1275 pmac
= hash_lookup(zevpn
->mac_table
, &tmp
);
1281 * Inform BGP about local MAC addition.
1283 int zebra_evpn_mac_send_add_to_client(vni_t vni
, const struct ethaddr
*macaddr
,
1284 uint32_t mac_flags
, uint32_t seq
,
1285 struct zebra_evpn_es
*es
)
1289 if (CHECK_FLAG(mac_flags
, ZEBRA_MAC_LOCAL_INACTIVE
)) {
1290 /* host reachability has not been verified locally */
1292 /* if no ES peer is claiming reachability we can't advertise the
1295 if (!CHECK_FLAG(mac_flags
, ZEBRA_MAC_ES_PEER_ACTIVE
))
1298 /* ES peers are claiming reachability; we will
1299 * advertise the entry but with a proxy flag
1301 SET_FLAG(flags
, ZEBRA_MACIP_TYPE_PROXY_ADVERT
);
1304 if (CHECK_FLAG(mac_flags
, ZEBRA_MAC_STICKY
))
1305 SET_FLAG(flags
, ZEBRA_MACIP_TYPE_STICKY
);
1306 if (CHECK_FLAG(mac_flags
, ZEBRA_MAC_DEF_GW
))
1307 SET_FLAG(flags
, ZEBRA_MACIP_TYPE_GW
);
1309 return zebra_evpn_macip_send_msg_to_client(vni
, macaddr
, NULL
, flags
,
1310 seq
, ZEBRA_NEIGH_ACTIVE
, es
,
1315 * Inform BGP about local MAC deletion.
1317 int zebra_evpn_mac_send_del_to_client(vni_t vni
, const struct ethaddr
*macaddr
,
1318 uint32_t flags
, bool force
)
1321 if (CHECK_FLAG(flags
, ZEBRA_MAC_LOCAL_INACTIVE
)
1322 && !CHECK_FLAG(flags
, ZEBRA_MAC_ES_PEER_ACTIVE
))
1323 /* the host was not advertised - nothing to delete */
1327 return zebra_evpn_macip_send_msg_to_client(
1328 vni
, macaddr
, NULL
, 0 /* flags */, 0 /* seq */,
1329 ZEBRA_NEIGH_ACTIVE
, NULL
, ZEBRA_MACIP_DEL
);
1333 * wrapper to create a MAC hash table
1335 struct hash
*zebra_mac_db_create(const char *desc
)
1337 return hash_create_size(8, mac_hash_keymake
, mac_cmp
, desc
);
1340 /* program sync mac flags in the dataplane */
1341 int zebra_evpn_sync_mac_dp_install(struct zebra_mac
*mac
, bool set_inactive
,
1342 bool force_clear_static
, const char *caller
)
1344 struct interface
*ifp
;
1347 struct zebra_evpn
*zevpn
= mac
->zevpn
;
1349 struct zebra_if
*zif
;
1350 struct interface
*br_ifp
;
1352 /* If the ES-EVI doesn't exist defer install. When the ES-EVI is
1353 * created we will attempt to install the mac entry again
1356 struct zebra_evpn_es_evi
*es_evi
;
1358 es_evi
= zebra_evpn_es_evi_find(mac
->es
, mac
->zevpn
);
1360 if (IS_ZEBRA_DEBUG_EVPN_MH_MAC
)
1362 "%s: dp-install sync-mac vni %u mac %pEA es %s 0x%x %sskipped, no es-evi",
1363 caller
, zevpn
->vni
, &mac
->macaddr
,
1364 mac
->es
? mac
->es
->esi_str
: "-",
1366 set_inactive
? "inactive " : "");
1371 /* get the access vlan from the vxlan_device */
1372 zebra_evpn_mac_get_access_info(mac
, &ifp
, &vid
);
1375 if (IS_ZEBRA_DEBUG_EVPN_MH_MAC
) {
1376 char mac_buf
[MAC_BUF_SIZE
];
1379 "%s: dp-install sync-mac vni %u mac %pEA es %s %s%sskipped, no access-port",
1380 caller
, zevpn
->vni
, &mac
->macaddr
,
1381 mac
->es
? mac
->es
->esi_str
: "-",
1382 zebra_evpn_zebra_mac_flag_dump(mac
, mac_buf
,
1384 set_inactive
? "inactive " : "");
1390 br_ifp
= zif
->brslave_info
.br_if
;
1392 if (IS_ZEBRA_DEBUG_EVPN_MH_MAC
) {
1393 char mac_buf
[MAC_BUF_SIZE
];
1396 "%s: dp-install sync-mac vni %u mac %pEA es %s %s%sskipped, no br",
1397 caller
, zevpn
->vni
, &mac
->macaddr
,
1398 mac
->es
? mac
->es
->esi_str
: "-",
1399 zebra_evpn_zebra_mac_flag_dump(mac
, mac_buf
,
1401 set_inactive
? "inactive " : "");
1406 sticky
= !!CHECK_FLAG(mac
->flags
, ZEBRA_MAC_STICKY
);
1407 if (force_clear_static
)
1410 set_static
= zebra_evpn_mac_is_static(mac
);
1412 /* We can install a local mac that has been synced from the peer
1413 * over the VxLAN-overlay/network-port if fast failover is not
1414 * supported and if the local ES is oper-down.
1416 if (mac
->es
&& zebra_evpn_es_local_mac_via_network_port(mac
->es
)) {
1417 if (IS_ZEBRA_DEBUG_EVPN_MH_MAC
) {
1418 char mac_buf
[MAC_BUF_SIZE
];
1421 "dp-%s sync-nw-mac vni %u mac %pEA es %s %s%s",
1422 set_static
? "install" : "uninstall",
1423 zevpn
->vni
, &mac
->macaddr
,
1424 mac
->es
? mac
->es
->esi_str
: "-",
1425 zebra_evpn_zebra_mac_flag_dump(mac
, mac_buf
,
1427 set_inactive
? "inactive " : "");
1430 /* XXX - old_static needs to be computed more
1433 zebra_evpn_rem_mac_install(zevpn
, mac
,
1434 true /* old_static */);
1436 zebra_evpn_rem_mac_uninstall(zevpn
, mac
,
1442 if (IS_ZEBRA_DEBUG_EVPN_MH_MAC
) {
1443 char mac_buf
[MAC_BUF_SIZE
];
1445 zlog_debug("dp-install sync-mac vni %u mac %pEA es %s %s%s%s",
1446 zevpn
->vni
, &mac
->macaddr
,
1447 mac
->es
? mac
->es
->esi_str
: "-",
1448 zebra_evpn_zebra_mac_flag_dump(mac
, mac_buf
,
1450 set_static
? "static " : "",
1451 set_inactive
? "inactive " : "");
1454 dplane_local_mac_add(ifp
, br_ifp
, vid
, &mac
->macaddr
, sticky
,
1455 set_static
, set_inactive
);
1459 void zebra_evpn_mac_send_add_del_to_client(struct zebra_mac
*mac
,
1464 zebra_evpn_mac_send_add_to_client(mac
->zevpn
->vni
,
1465 &mac
->macaddr
, mac
->flags
,
1466 mac
->loc_seq
, mac
->es
);
1467 else if (old_bgp_ready
)
1468 zebra_evpn_mac_send_del_to_client(mac
->zevpn
->vni
,
1469 &mac
->macaddr
, mac
->flags
,
1473 /* MAC hold timer is used to age out peer-active flag.
1475 * During this wait time we expect the dataplane component or an
1476 * external neighmgr daemon to probe existing hosts to independently
1477 * establish their presence on the ES.
1479 static void zebra_evpn_mac_hold_exp_cb(struct thread
*t
)
1481 struct zebra_mac
*mac
;
1487 mac
= THREAD_ARG(t
);
1488 /* the purpose of the hold timer is to age out the peer-active
1491 if (!CHECK_FLAG(mac
->flags
, ZEBRA_MAC_ES_PEER_ACTIVE
))
1494 old_bgp_ready
= zebra_evpn_mac_is_ready_for_bgp(mac
->flags
);
1495 old_static
= zebra_evpn_mac_is_static(mac
);
1496 UNSET_FLAG(mac
->flags
, ZEBRA_MAC_ES_PEER_ACTIVE
);
1497 new_bgp_ready
= zebra_evpn_mac_is_ready_for_bgp(mac
->flags
);
1498 new_static
= zebra_evpn_mac_is_static(mac
);
1500 if (IS_ZEBRA_DEBUG_EVPN_MH_MAC
) {
1501 char mac_buf
[MAC_BUF_SIZE
];
1504 "sync-mac vni %u mac %pEA es %s %shold expired",
1505 mac
->zevpn
->vni
, &mac
->macaddr
,
1506 mac
->es
? mac
->es
->esi_str
: "-",
1507 zebra_evpn_zebra_mac_flag_dump(mac
, mac_buf
,
1511 /* re-program the local mac in the dataplane if the mac is no
1514 if (old_static
!= new_static
)
1515 zebra_evpn_sync_mac_dp_install(mac
, false /* set_inactive */,
1516 false /* force_clear_static */,
1519 /* inform bgp if needed */
1520 if (old_bgp_ready
!= new_bgp_ready
)
1521 zebra_evpn_mac_send_add_del_to_client(mac
, old_bgp_ready
,
1525 static inline void zebra_evpn_mac_start_hold_timer(struct zebra_mac
*mac
)
1527 if (mac
->hold_timer
)
1530 if (IS_ZEBRA_DEBUG_EVPN_MH_MAC
) {
1531 char mac_buf
[MAC_BUF_SIZE
];
1534 "sync-mac vni %u mac %pEA es %s %shold started",
1535 mac
->zevpn
->vni
, &mac
->macaddr
,
1536 mac
->es
? mac
->es
->esi_str
: "-",
1537 zebra_evpn_zebra_mac_flag_dump(mac
, mac_buf
,
1540 thread_add_timer(zrouter
.master
, zebra_evpn_mac_hold_exp_cb
, mac
,
1541 zmh_info
->mac_hold_time
, &mac
->hold_timer
);
1544 void zebra_evpn_mac_stop_hold_timer(struct zebra_mac
*mac
)
1546 if (!mac
->hold_timer
)
1549 if (IS_ZEBRA_DEBUG_EVPN_MH_MAC
) {
1550 char mac_buf
[MAC_BUF_SIZE
];
1553 "sync-mac vni %u mac %pEA es %s %shold stopped",
1554 mac
->zevpn
->vni
, &mac
->macaddr
,
1555 mac
->es
? mac
->es
->esi_str
: "-",
1556 zebra_evpn_zebra_mac_flag_dump(mac
, mac_buf
,
1560 THREAD_OFF(mac
->hold_timer
);
1563 void zebra_evpn_sync_mac_del(struct zebra_mac
*mac
)
1568 if (IS_ZEBRA_DEBUG_EVPN_MH_MAC
) {
1569 char mac_buf
[MAC_BUF_SIZE
];
1572 "sync-mac del vni %u mac %pEA es %s seq %d f %s",
1573 mac
->zevpn
->vni
, &mac
->macaddr
,
1574 mac
->es
? mac
->es
->esi_str
: "-", mac
->loc_seq
,
1575 zebra_evpn_zebra_mac_flag_dump(mac
, mac_buf
,
1579 old_static
= zebra_evpn_mac_is_static(mac
);
1580 UNSET_FLAG(mac
->flags
, ZEBRA_MAC_ES_PEER_PROXY
);
1581 if (CHECK_FLAG(mac
->flags
, ZEBRA_MAC_ES_PEER_ACTIVE
))
1582 zebra_evpn_mac_start_hold_timer(mac
);
1583 new_static
= zebra_evpn_mac_is_static(mac
);
1585 if (old_static
!= new_static
)
1586 /* program the local mac in the kernel */
1587 zebra_evpn_sync_mac_dp_install(mac
, false /* set_inactive */,
1588 false /* force_clear_static */,
1592 static inline bool zebra_evpn_mac_is_bgp_seq_ok(struct zebra_evpn
*zevpn
,
1593 struct zebra_mac
*mac
,
1594 uint32_t seq
, uint16_t ipa_len
,
1595 const struct ipaddr
*ipaddr
,
1598 char ipbuf
[INET6_ADDRSTRLEN
];
1602 if (CHECK_FLAG(mac
->flags
, ZEBRA_MAC_LOCAL
)) {
1603 tmp_seq
= mac
->loc_seq
;
1606 tmp_seq
= mac
->rem_seq
;
1610 if (seq
< tmp_seq
) {
1611 /* if the mac was never advertised to bgp we must accept
1612 * whatever sequence number bgp sends
1613 * XXX - check with Vivek
1615 if (CHECK_FLAG(mac
->flags
, ZEBRA_MAC_LOCAL
)
1616 && !zebra_evpn_mac_is_ready_for_bgp(mac
->flags
)) {
1617 if (IS_ZEBRA_DEBUG_EVPN_MH_MAC
1618 || IS_ZEBRA_DEBUG_VXLAN
) {
1619 char mac_buf
[MAC_BUF_SIZE
];
1622 "%s-macip accept vni %u %s-mac %pEA%s%s lower seq %u f %s",
1623 sync
? "sync" : "rem", zevpn
->vni
,
1626 ipa_len
? " IP " : "",
1627 ipa_len
? ipaddr2str(ipaddr
, ipbuf
,
1631 zebra_evpn_zebra_mac_flag_dump(
1632 mac
, mac_buf
, sizeof(mac_buf
)));
1638 if (IS_ZEBRA_DEBUG_EVPN_MH_MAC
|| IS_ZEBRA_DEBUG_VXLAN
) {
1639 char mac_buf
[MAC_BUF_SIZE
];
1642 "%s-macip ignore vni %u %s-mac %pEA%s%s as existing has higher seq %u f %s",
1643 sync
? "sync" : "rem", zevpn
->vni
, n_type
,
1645 ipa_len
? " IP " : "",
1646 ipa_len
? ipaddr2str(ipaddr
, ipbuf
,
1650 zebra_evpn_zebra_mac_flag_dump(
1651 mac
, mac_buf
, sizeof(mac_buf
)));
1659 struct zebra_mac
*zebra_evpn_proc_sync_mac_update(
1660 struct zebra_evpn
*zevpn
, const struct ethaddr
*macaddr
,
1661 uint16_t ipa_len
, const struct ipaddr
*ipaddr
, uint8_t flags
,
1662 uint32_t seq
, const esi_t
*esi
, struct sync_mac_ip_ctx
*ctx
)
1664 struct zebra_mac
*mac
;
1665 bool inform_bgp
= false;
1666 bool inform_dataplane
= false;
1667 bool seq_change
= false;
1668 bool es_change
= false;
1670 char ipbuf
[INET6_ADDRSTRLEN
];
1671 bool old_local
= false;
1675 mac
= zebra_evpn_mac_lookup(zevpn
, macaddr
);
1677 /* if it is a new local path we need to inform both
1678 * the control protocol and the data-plane
1681 inform_dataplane
= true;
1682 ctx
->mac_created
= true;
1683 ctx
->mac_inactive
= true;
1685 /* create the MAC and associate it with the dest ES */
1686 mac
= zebra_evpn_mac_add(zevpn
, macaddr
);
1687 zebra_evpn_es_mac_ref(mac
, esi
);
1689 /* local mac activated by an ES peer */
1690 SET_FLAG(mac
->flags
, ZEBRA_MAC_LOCAL
);
1691 /* if mac-only route setup peer flags */
1693 if (CHECK_FLAG(flags
, ZEBRA_MACIP_TYPE_PROXY_ADVERT
))
1694 SET_FLAG(mac
->flags
, ZEBRA_MAC_ES_PEER_PROXY
);
1696 SET_FLAG(mac
->flags
, ZEBRA_MAC_ES_PEER_ACTIVE
);
1698 SET_FLAG(mac
->flags
, ZEBRA_MAC_LOCAL_INACTIVE
);
1699 old_bgp_ready
= false;
1700 new_bgp_ready
= zebra_evpn_mac_is_ready_for_bgp(mac
->flags
);
1709 mac
->uptime
= monotime(NULL
);
1711 old_flags
= mac
->flags
;
1712 sticky
= !!CHECK_FLAG(old_flags
, ZEBRA_MAC_STICKY
);
1713 remote_gw
= !!CHECK_FLAG(old_flags
, ZEBRA_MAC_REMOTE_DEF_GW
);
1714 if (sticky
|| remote_gw
) {
1715 if (IS_ZEBRA_DEBUG_EVPN_MH_NEIGH
)
1717 "Ignore sync-macip vni %u mac %pEA%s%s%s%s",
1718 zevpn
->vni
, macaddr
,
1719 ipa_len
? " IP " : "",
1720 ipa_len
? ipaddr2str(ipaddr
, ipbuf
,
1723 sticky
? " sticky" : "",
1724 remote_gw
? " remote_gw" : "");
1725 ctx
->ignore_macip
= true;
1728 if (!zebra_evpn_mac_is_bgp_seq_ok(zevpn
, mac
, seq
, ipa_len
,
1730 ctx
->ignore_macip
= true;
1734 old_local
= !!CHECK_FLAG(old_flags
, ZEBRA_MAC_LOCAL
);
1735 old_static
= zebra_evpn_mac_is_static(mac
);
1737 /* re-build the mac flags */
1739 SET_FLAG(new_flags
, ZEBRA_MAC_LOCAL
);
1740 /* retain old local activity flag */
1741 if (old_flags
& ZEBRA_MAC_LOCAL
) {
1742 new_flags
|= (old_flags
& ZEBRA_MAC_LOCAL_INACTIVE
);
1744 new_flags
|= ZEBRA_MAC_LOCAL_INACTIVE
;
1745 ctx
->mac_inactive
= true;
1748 /* if mac-ip route do NOT update the peer flags
1749 * i.e. retain only flags as is
1751 new_flags
|= (old_flags
& ZEBRA_MAC_ALL_PEER_FLAGS
);
1753 /* if mac-only route update peer flags */
1754 if (CHECK_FLAG(flags
, ZEBRA_MACIP_TYPE_PROXY_ADVERT
)) {
1755 SET_FLAG(new_flags
, ZEBRA_MAC_ES_PEER_PROXY
);
1756 /* if the mac was peer-active previously we
1757 * need to keep the flag and start the
1758 * holdtimer on it. the peer-active flag is
1759 * cleared on holdtimer expiry.
1761 if (CHECK_FLAG(old_flags
,
1762 ZEBRA_MAC_ES_PEER_ACTIVE
)) {
1764 ZEBRA_MAC_ES_PEER_ACTIVE
);
1765 zebra_evpn_mac_start_hold_timer(mac
);
1768 SET_FLAG(new_flags
, ZEBRA_MAC_ES_PEER_ACTIVE
);
1769 /* stop hold timer if a peer has verified
1772 zebra_evpn_mac_stop_hold_timer(mac
);
1776 zebra_evpn_mac_clear_fwd_info(mac
);
1777 mac
->flags
= new_flags
;
1779 if (IS_ZEBRA_DEBUG_EVPN_MH_MAC
&& (old_flags
!= new_flags
)) {
1780 char mac_buf
[MAC_BUF_SIZE
], omac_buf
[MAC_BUF_SIZE
];
1781 struct zebra_mac omac
;
1783 omac
.flags
= old_flags
;
1785 "sync-mac vni %u mac %pEA old_f %snew_f %s",
1786 zevpn
->vni
, macaddr
,
1787 zebra_evpn_zebra_mac_flag_dump(
1788 &omac
, omac_buf
, sizeof(omac_buf
)),
1789 zebra_evpn_zebra_mac_flag_dump(
1790 mac
, mac_buf
, sizeof(mac_buf
)));
1794 es_change
= zebra_evpn_es_mac_ref(mac
, esi
);
1795 /* if mac dest change - inform both sides */
1798 inform_dataplane
= true;
1799 ctx
->mac_inactive
= true;
1802 /* if peer-flag is being set notify dataplane that the
1803 * entry must not be expired because of local inactivity
1805 new_static
= zebra_evpn_mac_is_static(mac
);
1806 if (old_static
!= new_static
)
1807 inform_dataplane
= true;
1809 old_bgp_ready
= zebra_evpn_mac_is_ready_for_bgp(old_flags
);
1810 new_bgp_ready
= zebra_evpn_mac_is_ready_for_bgp(mac
->flags
);
1811 if (old_bgp_ready
!= new_bgp_ready
)
1816 /* update sequence number; if that results in a new local sequence
1819 tmp_seq
= MAX(mac
->loc_seq
, seq
);
1820 if (tmp_seq
!= mac
->loc_seq
) {
1821 mac
->loc_seq
= tmp_seq
;
1826 if (IS_ZEBRA_DEBUG_EVPN_MH_MAC
) {
1827 char mac_buf
[MAC_BUF_SIZE
];
1829 zlog_debug("sync-mac %s vni %u mac %pEA es %s seq %d f %s%s%s",
1830 ctx
->mac_created
? "created" : "updated",
1831 zevpn
->vni
, macaddr
,
1832 mac
->es
? mac
->es
->esi_str
: "-", mac
->loc_seq
,
1833 zebra_evpn_zebra_mac_flag_dump(mac
, mac_buf
,
1835 inform_bgp
? "inform_bgp" : "",
1836 inform_dataplane
? " inform_dp" : "");
1840 zebra_evpn_mac_send_add_del_to_client(mac
, old_bgp_ready
,
1843 /* neighs using the mac may need to be re-sent to
1844 * bgp with updated info
1846 if (seq_change
|| es_change
|| !old_local
)
1847 zebra_evpn_process_neigh_on_local_mac_change(
1848 zevpn
, mac
, seq_change
, es_change
);
1850 if (inform_dataplane
) {
1852 /* if the mac is being created as a part of MAC-IP
1853 * route wait for the neigh to be updated or
1854 * created before programming the mac
1856 ctx
->mac_dp_update_deferred
= true;
1858 /* program the local mac in the kernel. when the ES
1859 * change we need to force the dataplane to reset
1860 * the activity as we are yet to establish activity
1863 zebra_evpn_sync_mac_dp_install(
1864 mac
, ctx
->mac_inactive
,
1865 false /* force_clear_static */, __func__
);
1871 /* update local forwarding info. return true if a dest-ES change
1874 static bool zebra_evpn_local_mac_update_fwd_info(struct zebra_mac
*mac
,
1875 struct interface
*ifp
,
1878 struct zebra_if
*zif
= ifp
->info
;
1880 ns_id_t local_ns_id
= NS_DEFAULT
;
1881 struct zebra_vrf
*zvrf
;
1882 struct zebra_evpn_es
*es
;
1884 zvrf
= ifp
->vrf
->info
;
1885 if (zvrf
&& zvrf
->zns
)
1886 local_ns_id
= zvrf
->zns
->ns_id
;
1888 zebra_evpn_mac_clear_fwd_info(mac
);
1890 es
= zif
->es_info
.es
;
1891 if (es
&& (es
->flags
& ZEBRA_EVPNES_BYPASS
))
1893 es_change
= zebra_evpn_es_mac_ref_entry(mac
, es
);
1896 /* if es is set fwd_info is not-relevant/taped-out */
1897 mac
->fwd_info
.local
.ifindex
= ifp
->ifindex
;
1898 mac
->fwd_info
.local
.ns_id
= local_ns_id
;
1899 mac
->fwd_info
.local
.vid
= vid
;
1900 zebra_evpn_mac_ifp_link(mac
, ifp
);
1906 /* Notify Local MACs to the clienti, skips GW MAC */
1907 static void zebra_evpn_send_mac_hash_entry_to_client(struct hash_bucket
*bucket
,
1910 struct mac_walk_ctx
*wctx
= arg
;
1911 struct zebra_mac
*zmac
= bucket
->data
;
1913 if (CHECK_FLAG(zmac
->flags
, ZEBRA_MAC_DEF_GW
))
1916 if (CHECK_FLAG(zmac
->flags
, ZEBRA_MAC_LOCAL
))
1917 zebra_evpn_mac_send_add_to_client(wctx
->zevpn
->vni
,
1918 &zmac
->macaddr
, zmac
->flags
,
1919 zmac
->loc_seq
, zmac
->es
);
1922 /* Iterator to Notify Local MACs of a EVPN */
1923 void zebra_evpn_send_mac_list_to_client(struct zebra_evpn
*zevpn
)
1925 struct mac_walk_ctx wctx
;
1927 if (!zevpn
->mac_table
)
1930 memset(&wctx
, 0, sizeof(wctx
));
1933 hash_iterate(zevpn
->mac_table
, zebra_evpn_send_mac_hash_entry_to_client
,
1937 void zebra_evpn_rem_mac_del(struct zebra_evpn
*zevpn
, struct zebra_mac
*mac
)
1939 zebra_evpn_process_neigh_on_remote_mac_del(zevpn
, mac
);
1940 /* the remote sequence number in the auto mac entry
1941 * needs to be reset to 0 as the mac entry may have
1942 * been removed on all VTEPs (including
1943 * the originating one)
1947 /* If all remote neighbors referencing a remote MAC
1948 * go away, we need to uninstall the MAC.
1950 if (remote_neigh_count(mac
) == 0) {
1951 zebra_evpn_rem_mac_uninstall(zevpn
, mac
, false /*force*/);
1952 zebra_evpn_es_mac_deref_entry(mac
);
1953 UNSET_FLAG(mac
->flags
, ZEBRA_MAC_REMOTE
);
1956 if (list_isempty(mac
->neigh_list
))
1957 zebra_evpn_mac_del(zevpn
, mac
);
1959 SET_FLAG(mac
->flags
, ZEBRA_MAC_AUTO
);
1962 /* Print Duplicate MAC */
1963 void zebra_evpn_print_dad_mac_hash(struct hash_bucket
*bucket
, void *ctxt
)
1965 struct zebra_mac
*mac
;
1967 mac
= (struct zebra_mac
*)bucket
->data
;
1971 if (CHECK_FLAG(mac
->flags
, ZEBRA_MAC_DUPLICATE
))
1972 zebra_evpn_print_mac_hash(bucket
, ctxt
);
1975 /* Print Duplicate MAC in detail */
1976 void zebra_evpn_print_dad_mac_hash_detail(struct hash_bucket
*bucket
,
1979 struct zebra_mac
*mac
;
1981 mac
= (struct zebra_mac
*)bucket
->data
;
1985 if (CHECK_FLAG(mac
->flags
, ZEBRA_MAC_DUPLICATE
))
1986 zebra_evpn_print_mac_hash_detail(bucket
, ctxt
);
1989 int zebra_evpn_mac_remote_macip_add(
1990 struct zebra_evpn
*zevpn
, struct zebra_vrf
*zvrf
,
1991 const struct ethaddr
*macaddr
, uint16_t ipa_len
,
1992 const struct ipaddr
*ipaddr
, struct zebra_mac
**macp
,
1993 struct in_addr vtep_ip
, uint8_t flags
, uint32_t seq
, const esi_t
*esi
)
1995 char buf1
[INET6_ADDRSTRLEN
];
1999 bool do_dad
= false;
2000 bool is_dup_detect
= false;
2002 bool old_static
= false;
2003 struct zebra_mac
*mac
;
2004 bool old_es_present
;
2005 bool new_es_present
;
2007 sticky
= !!CHECK_FLAG(flags
, ZEBRA_MACIP_TYPE_STICKY
);
2008 remote_gw
= !!CHECK_FLAG(flags
, ZEBRA_MACIP_TYPE_GW
);
2010 mac
= zebra_evpn_mac_lookup(zevpn
, macaddr
);
2012 /* Ignore if the mac is already present as a gateway mac */
2013 if (mac
&& CHECK_FLAG(mac
->flags
, ZEBRA_MAC_DEF_GW
)
2014 && CHECK_FLAG(flags
, ZEBRA_MACIP_TYPE_GW
)) {
2015 if (IS_ZEBRA_DEBUG_VXLAN
)
2017 "Ignore remote MACIP ADD VNI %u MAC %pEA%s%s as MAC is already configured as gateway MAC",
2018 zevpn
->vni
, macaddr
,
2019 ipa_len
? " IP " : "",
2020 ipa_len
? ipaddr2str(ipaddr
, buf1
, sizeof(buf1
))
2025 old_esi
= (mac
&& mac
->es
) ? &mac
->es
->esi
: zero_esi
;
2027 /* check if the remote MAC is unknown or has a change.
2028 * If so, that needs to be updated first. Note that client could
2029 * install MAC and MACIP separately or just install the latter.
2031 if (!mac
|| !CHECK_FLAG(mac
->flags
, ZEBRA_MAC_REMOTE
)
2032 || sticky
!= !!CHECK_FLAG(mac
->flags
, ZEBRA_MAC_STICKY
)
2033 || remote_gw
!= !!CHECK_FLAG(mac
->flags
, ZEBRA_MAC_REMOTE_DEF_GW
)
2034 || !IPV4_ADDR_SAME(&mac
->fwd_info
.r_vtep_ip
, &vtep_ip
)
2035 || memcmp(old_esi
, esi
, sizeof(esi_t
)) || seq
!= mac
->rem_seq
)
2040 mac
= zebra_evpn_mac_add(zevpn
, macaddr
);
2041 zebra_evpn_es_mac_ref(mac
, esi
);
2043 /* Is this MAC created for a MACIP? */
2045 SET_FLAG(mac
->flags
, ZEBRA_MAC_AUTO
);
2047 /* When host moves but changes its (MAC,IP)
2048 * binding, BGP may install a MACIP entry that
2049 * corresponds to "older" location of the host
2050 * in transient situations (because {IP1,M1}
2051 * is a different route from {IP1,M2}). Check
2052 * the sequence number and ignore this update
2055 if (!zebra_evpn_mac_is_bgp_seq_ok(
2056 zevpn
, mac
, seq
, ipa_len
, ipaddr
, false))
2059 old_es_present
= !!mac
->es
;
2060 zebra_evpn_es_mac_ref(mac
, esi
);
2061 new_es_present
= !!mac
->es
;
2062 /* XXX - dataplane is curently not able to handle a MAC
2063 * replace if the destination changes from L2-NHG to
2064 * single VTEP and vice-versa. So delete the old entry
2067 if (old_es_present
!= new_es_present
)
2068 zebra_evpn_rem_mac_uninstall(zevpn
, mac
, false);
2071 /* Check MAC's curent state is local (this is the case
2072 * where MAC has moved from L->R) and check previous
2073 * detection started via local learning.
2074 * RFC-7432: A PE/VTEP that detects a MAC mobility
2075 * event via local learning starts an M-second timer.
2077 * VTEP-IP or seq. change alone is not considered
2078 * for dup. detection.
2080 * MAC is already marked duplicate set dad, then
2081 * is_dup_detect will be set to not install the entry.
2083 if ((!CHECK_FLAG(mac
->flags
, ZEBRA_MAC_REMOTE
)
2085 || CHECK_FLAG(mac
->flags
, ZEBRA_MAC_DUPLICATE
))
2088 /* Remove local MAC from BGP. */
2089 if (CHECK_FLAG(mac
->flags
, ZEBRA_MAC_LOCAL
)) {
2090 /* force drop the sync flags */
2091 old_static
= zebra_evpn_mac_is_static(mac
);
2092 if (IS_ZEBRA_DEBUG_EVPN_MH_MAC
) {
2093 char mac_buf
[MAC_BUF_SIZE
];
2096 "sync-mac->remote vni %u mac %pEA es %s seq %d f %s",
2097 zevpn
->vni
, macaddr
,
2098 mac
->es
? mac
->es
->esi_str
: "-",
2100 zebra_evpn_zebra_mac_flag_dump(
2101 mac
, mac_buf
, sizeof(mac_buf
)));
2104 zebra_evpn_mac_clear_sync_info(mac
);
2105 zebra_evpn_mac_send_del_to_client(zevpn
->vni
, macaddr
,
2110 /* Set "auto" and "remote" forwarding info. */
2111 zebra_evpn_mac_clear_fwd_info(mac
);
2112 UNSET_FLAG(mac
->flags
, ZEBRA_MAC_ALL_LOCAL_FLAGS
);
2113 SET_FLAG(mac
->flags
, ZEBRA_MAC_REMOTE
);
2114 mac
->fwd_info
.r_vtep_ip
= vtep_ip
;
2117 SET_FLAG(mac
->flags
, ZEBRA_MAC_STICKY
);
2119 UNSET_FLAG(mac
->flags
, ZEBRA_MAC_STICKY
);
2122 SET_FLAG(mac
->flags
, ZEBRA_MAC_REMOTE_DEF_GW
);
2124 UNSET_FLAG(mac
->flags
, ZEBRA_MAC_REMOTE_DEF_GW
);
2126 zebra_evpn_dup_addr_detect_for_mac(
2127 zvrf
, mac
, mac
->fwd_info
.r_vtep_ip
, do_dad
,
2128 &is_dup_detect
, false);
2130 if (!is_dup_detect
) {
2131 zebra_evpn_process_neigh_on_remote_mac_add(zevpn
, mac
);
2132 /* Install the entry. */
2133 zebra_evpn_rem_mac_install(zevpn
, mac
, old_static
);
2137 /* Update seq number. */
2140 /* If there is no IP, return after clearing AUTO flag of MAC. */
2142 UNSET_FLAG(mac
->flags
, ZEBRA_MAC_AUTO
);
2149 int zebra_evpn_add_update_local_mac(struct zebra_vrf
*zvrf
,
2150 struct zebra_evpn
*zevpn
,
2151 struct interface
*ifp
,
2152 const struct ethaddr
*macaddr
, vlanid_t vid
,
2153 bool sticky
, bool local_inactive
,
2154 bool dp_static
, struct zebra_mac
*mac
)
2156 bool mac_sticky
= false;
2157 bool inform_client
= false;
2158 bool upd_neigh
= false;
2159 bool is_dup_detect
= false;
2160 struct in_addr vtep_ip
= {.s_addr
= 0};
2161 bool es_change
= false;
2163 /* assume inactive if not present or if not local */
2164 bool old_local_inactive
= true;
2165 bool old_bgp_ready
= false;
2166 bool inform_dataplane
= false;
2167 bool new_static
= false;
2170 /* Check if we need to create or update or it is a NO-OP. */
2172 mac
= zebra_evpn_mac_lookup(zevpn
, macaddr
);
2174 if (IS_ZEBRA_DEBUG_VXLAN
|| IS_ZEBRA_DEBUG_EVPN_MH_MAC
)
2176 "ADD %sMAC %pEA intf %s(%u) VID %u -> VNI %u%s",
2177 sticky
? "sticky " : "", macaddr
,
2178 ifp
->name
, ifp
->ifindex
, vid
, zevpn
->vni
,
2179 local_inactive
? " local-inactive" : "");
2181 mac
= zebra_evpn_mac_add(zevpn
, macaddr
);
2182 SET_FLAG(mac
->flags
, ZEBRA_MAC_LOCAL
);
2183 es_change
= zebra_evpn_local_mac_update_fwd_info(mac
, ifp
, vid
);
2185 SET_FLAG(mac
->flags
, ZEBRA_MAC_STICKY
);
2186 inform_client
= true;
2188 if (IS_ZEBRA_DEBUG_VXLAN
|| IS_ZEBRA_DEBUG_EVPN_MH_MAC
) {
2189 char mac_buf
[MAC_BUF_SIZE
];
2192 "UPD %sMAC %pEA intf %s(%u) VID %u -> VNI %u %scurFlags %s",
2193 sticky
? "sticky " : "", macaddr
,
2194 ifp
->name
, ifp
->ifindex
, vid
, zevpn
->vni
,
2195 local_inactive
? "local-inactive " : "",
2196 zebra_evpn_zebra_mac_flag_dump(
2197 mac
, mac_buf
, sizeof(mac_buf
)));
2200 if (CHECK_FLAG(mac
->flags
, ZEBRA_MAC_LOCAL
)) {
2201 struct interface
*old_ifp
;
2205 zebra_evpn_mac_get_access_info(mac
, &old_ifp
, &old_vid
);
2207 zebra_evpn_mac_is_ready_for_bgp(mac
->flags
);
2208 old_local_inactive
=
2209 !!(mac
->flags
& ZEBRA_MAC_LOCAL_INACTIVE
);
2210 old_static
= zebra_evpn_mac_is_static(mac
);
2211 if (CHECK_FLAG(mac
->flags
, ZEBRA_MAC_STICKY
))
2213 es_change
= zebra_evpn_local_mac_update_fwd_info(
2217 * Update any changes and if changes are relevant to
2220 if (mac_sticky
== sticky
&& old_ifp
== ifp
2222 && old_local_inactive
== local_inactive
2223 && dp_static
== old_static
&& !es_change
) {
2224 if (IS_ZEBRA_DEBUG_VXLAN
)
2226 " Add/Update %sMAC %pEA intf %s(%u) VID %u -> VNI %u%s, "
2227 "entry exists and has not changed ",
2228 sticky
? "sticky " : "",
2230 ifp
->ifindex
, vid
, zevpn
->vni
,
2236 if (mac_sticky
!= sticky
) {
2238 SET_FLAG(mac
->flags
, ZEBRA_MAC_STICKY
);
2240 UNSET_FLAG(mac
->flags
,
2242 inform_client
= true;
2245 /* If an es_change is detected we need to advertise
2246 * the route with a sequence that is one
2247 * greater. This is need to indicate a mac-move
2251 /* update the sequence number only if the entry
2254 if (!local_inactive
)
2255 mac
->loc_seq
= mac
->loc_seq
+ 1;
2256 /* force drop the peer/sync info as it is
2257 * simply no longer relevant
2259 if (CHECK_FLAG(mac
->flags
,
2260 ZEBRA_MAC_ALL_PEER_FLAGS
)) {
2261 zebra_evpn_mac_clear_sync_info(mac
);
2263 zebra_evpn_mac_is_static(mac
);
2264 /* if we clear peer-flags we
2265 * also need to notify the dataplane
2266 * to drop the static flag
2268 if (old_static
!= new_static
)
2269 inform_dataplane
= true;
2272 } else if (CHECK_FLAG(mac
->flags
, ZEBRA_MAC_REMOTE
)
2273 || CHECK_FLAG(mac
->flags
, ZEBRA_MAC_AUTO
)) {
2274 bool do_dad
= false;
2277 * MAC has either moved or was "internally" created due
2278 * to a neighbor learn and is now actually learnt. If
2279 * it was learnt as a remote sticky MAC, this is an
2282 if (CHECK_FLAG(mac
->flags
, ZEBRA_MAC_STICKY
)) {
2284 EC_ZEBRA_STICKY_MAC_ALREADY_LEARNT
,
2285 "MAC %pEA already learnt as remote sticky MAC behind VTEP %pI4 VNI %u",
2287 &mac
->fwd_info
.r_vtep_ip
,
2292 /* If an actual move, compute MAC's seq number */
2293 if (CHECK_FLAG(mac
->flags
, ZEBRA_MAC_REMOTE
)) {
2295 MAX(mac
->rem_seq
+ 1, mac
->loc_seq
);
2296 vtep_ip
= mac
->fwd_info
.r_vtep_ip
;
2297 /* Trigger DAD for remote MAC */
2301 UNSET_FLAG(mac
->flags
, ZEBRA_MAC_REMOTE
);
2302 UNSET_FLAG(mac
->flags
, ZEBRA_MAC_AUTO
);
2303 SET_FLAG(mac
->flags
, ZEBRA_MAC_LOCAL
);
2304 es_change
= zebra_evpn_local_mac_update_fwd_info(
2307 SET_FLAG(mac
->flags
, ZEBRA_MAC_STICKY
);
2309 UNSET_FLAG(mac
->flags
, ZEBRA_MAC_STICKY
);
2311 * We have to inform BGP of this MAC as well as process
2314 inform_client
= true;
2317 zebra_evpn_dup_addr_detect_for_mac(
2318 zvrf
, mac
, vtep_ip
, do_dad
, &is_dup_detect
,
2320 if (is_dup_detect
) {
2321 inform_client
= false;
2328 /* if the dataplane thinks the entry is sync but it is
2329 * not sync in zebra (or vice-versa) we need to re-install
2332 new_static
= zebra_evpn_mac_is_static(mac
);
2333 if (dp_static
!= new_static
)
2334 inform_dataplane
= true;
2337 SET_FLAG(mac
->flags
, ZEBRA_MAC_LOCAL_INACTIVE
);
2339 UNSET_FLAG(mac
->flags
, ZEBRA_MAC_LOCAL_INACTIVE
);
2341 new_bgp_ready
= zebra_evpn_mac_is_ready_for_bgp(mac
->flags
);
2342 /* if local-activity has changed we need update bgp
2343 * even if bgp already knows about the mac
2345 if ((old_local_inactive
!= local_inactive
)
2346 || (new_bgp_ready
!= old_bgp_ready
)) {
2347 if (IS_ZEBRA_DEBUG_EVPN_MH_MAC
) {
2348 char mac_buf
[MAC_BUF_SIZE
];
2351 "local mac vni %u mac %pEA es %s seq %d f %s%s",
2352 zevpn
->vni
, macaddr
,
2353 mac
->es
? mac
->es
->esi_str
: "", mac
->loc_seq
,
2354 zebra_evpn_zebra_mac_flag_dump(mac
, mac_buf
,
2356 local_inactive
? "local-inactive" : "");
2360 inform_client
= true;
2364 inform_client
= true;
2368 /* Inform dataplane if required. */
2369 if (inform_dataplane
)
2370 zebra_evpn_sync_mac_dp_install(mac
, false /* set_inactive */,
2371 false /* force_clear_static */,
2374 /* Inform BGP if required. */
2376 zebra_evpn_mac_send_add_del_to_client(mac
, old_bgp_ready
,
2379 /* Process all neighbors associated with this MAC, if required. */
2381 zebra_evpn_process_neigh_on_local_mac_change(zevpn
, mac
, 0,
2387 int zebra_evpn_del_local_mac(struct zebra_evpn
*zevpn
, struct zebra_mac
*mac
,
2393 if (IS_ZEBRA_DEBUG_VXLAN
)
2394 zlog_debug("DEL MAC %pEA VNI %u seq %u flags 0x%x nbr count %u",
2395 &mac
->macaddr
, zevpn
->vni
, mac
->loc_seq
, mac
->flags
,
2396 listcount(mac
->neigh_list
));
2398 old_bgp_ready
= zebra_evpn_mac_is_ready_for_bgp(mac
->flags
);
2399 if (!clear_static
&& zebra_evpn_mac_is_static(mac
)) {
2400 /* this is a synced entry and can only be removed when the
2401 * es-peers stop advertising it.
2403 zebra_evpn_mac_clear_fwd_info(mac
);
2405 if (IS_ZEBRA_DEBUG_EVPN_MH_MAC
) {
2406 char mac_buf
[MAC_BUF_SIZE
];
2409 "re-add sync-mac vni %u mac %pEA es %s seq %d f %s",
2410 zevpn
->vni
, &mac
->macaddr
,
2411 mac
->es
? mac
->es
->esi_str
: "-", mac
->loc_seq
,
2412 zebra_evpn_zebra_mac_flag_dump(
2413 mac
, mac_buf
, sizeof(mac_buf
)));
2416 /* inform-bgp about change in local-activity if any */
2417 if (!CHECK_FLAG(mac
->flags
, ZEBRA_MAC_LOCAL_INACTIVE
)) {
2418 SET_FLAG(mac
->flags
, ZEBRA_MAC_LOCAL_INACTIVE
);
2420 zebra_evpn_mac_is_ready_for_bgp(mac
->flags
);
2421 zebra_evpn_mac_send_add_del_to_client(
2422 mac
, old_bgp_ready
, new_bgp_ready
);
2425 /* re-install the inactive entry in the kernel */
2426 zebra_evpn_sync_mac_dp_install(mac
, true /* set_inactive */,
2427 false /* force_clear_static */,
2433 /* flush the peer info */
2434 zebra_evpn_mac_clear_sync_info(mac
);
2436 /* Update all the neigh entries associated with this mac */
2437 zebra_evpn_process_neigh_on_local_mac_del(zevpn
, mac
);
2439 /* Remove MAC from BGP. */
2440 zebra_evpn_mac_send_del_to_client(zevpn
->vni
, &mac
->macaddr
, mac
->flags
,
2443 zebra_evpn_es_mac_deref_entry(mac
);
2445 /* remove links to the destination access port */
2446 zebra_evpn_mac_clear_fwd_info(mac
);
2449 * If there are no neigh associated with the mac delete the mac
2450 * else mark it as AUTO for forward reference
2452 if (!listcount(mac
->neigh_list
)) {
2453 zebra_evpn_mac_del(zevpn
, mac
);
2455 UNSET_FLAG(mac
->flags
, ZEBRA_MAC_ALL_LOCAL_FLAGS
);
2456 UNSET_FLAG(mac
->flags
, ZEBRA_MAC_STICKY
);
2457 SET_FLAG(mac
->flags
, ZEBRA_MAC_AUTO
);
2463 void zebra_evpn_mac_gw_macip_add(struct interface
*ifp
,
2464 struct zebra_evpn
*zevpn
,
2465 const struct ipaddr
*ip
,
2466 struct zebra_mac
**macp
,
2467 const struct ethaddr
*macaddr
,
2468 vlanid_t vlan_id
, bool def_gw
)
2470 struct zebra_mac
*mac
;
2471 ns_id_t local_ns_id
= NS_DEFAULT
;
2472 struct zebra_vrf
*zvrf
;
2474 zvrf
= ifp
->vrf
->info
;
2475 if (zvrf
&& zvrf
->zns
)
2476 local_ns_id
= zvrf
->zns
->ns_id
;
2479 mac
= zebra_evpn_mac_lookup(zevpn
, macaddr
);
2481 mac
= zebra_evpn_mac_add(zevpn
, macaddr
);
2486 /* Set "local" forwarding info. */
2487 zebra_evpn_mac_clear_fwd_info(mac
);
2488 SET_FLAG(mac
->flags
, ZEBRA_MAC_LOCAL
);
2489 SET_FLAG(mac
->flags
, ZEBRA_MAC_AUTO
);
2491 SET_FLAG(mac
->flags
, ZEBRA_MAC_DEF_GW
);
2493 SET_FLAG(mac
->flags
, ZEBRA_MAC_SVI
);
2494 mac
->fwd_info
.local
.ifindex
= ifp
->ifindex
;
2495 mac
->fwd_info
.local
.ns_id
= local_ns_id
;
2496 mac
->fwd_info
.local
.vid
= vlan_id
;
2499 void zebra_evpn_mac_svi_del(struct interface
*ifp
, struct zebra_evpn
*zevpn
)
2501 struct zebra_mac
*mac
;
2502 struct ethaddr macaddr
;
2505 if (!zebra_evpn_mh_do_adv_svi_mac())
2508 memcpy(&macaddr
.octet
, ifp
->hw_addr
, ETH_ALEN
);
2509 mac
= zebra_evpn_mac_lookup(zevpn
, &macaddr
);
2510 if (mac
&& CHECK_FLAG(mac
->flags
, ZEBRA_MAC_SVI
)) {
2511 if (IS_ZEBRA_DEBUG_EVPN_MH_ES
)
2512 zlog_debug("SVI %s mac free", ifp
->name
);
2514 old_bgp_ready
= zebra_evpn_mac_is_ready_for_bgp(mac
->flags
);
2515 UNSET_FLAG(mac
->flags
, ZEBRA_MAC_SVI
);
2516 zebra_evpn_mac_send_add_del_to_client(mac
, old_bgp_ready
,
2518 zebra_evpn_deref_ip2mac(mac
->zevpn
, mac
);
2522 void zebra_evpn_mac_svi_add(struct interface
*ifp
, struct zebra_evpn
*zevpn
)
2524 struct zebra_mac
*mac
= NULL
;
2525 struct ethaddr macaddr
;
2526 struct zebra_if
*zif
= ifp
->info
;
2530 if (!zebra_evpn_mh_do_adv_svi_mac()
2531 || !zebra_evpn_send_to_client_ok(zevpn
))
2534 memcpy(&macaddr
.octet
, ifp
->hw_addr
, ETH_ALEN
);
2537 mac
= zebra_evpn_mac_lookup(zevpn
, &macaddr
);
2538 if (mac
&& CHECK_FLAG(mac
->flags
, ZEBRA_MAC_SVI
))
2541 /* add/update mac */
2542 if (IS_ZEBRA_DEBUG_EVPN_MH_ES
)
2543 zlog_debug("SVI %s mac add", zif
->ifp
->name
);
2545 old_bgp_ready
= (mac
&& zebra_evpn_mac_is_ready_for_bgp(mac
->flags
))
2549 zebra_evpn_mac_gw_macip_add(ifp
, zevpn
, NULL
, &mac
, &macaddr
, 0, false);
2551 new_bgp_ready
= zebra_evpn_mac_is_ready_for_bgp(mac
->flags
);
2552 zebra_evpn_mac_send_add_del_to_client(mac
, old_bgp_ready
,