2 * Zebra EVPN Neighbor 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"
33 #include "zebra/zserv.h"
34 #include "zebra/debug.h"
35 #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_neigh.h"
42 #include "zebra/zebra_evpn_mac.h"
44 DEFINE_MTYPE_STATIC(ZEBRA
, NEIGH
, "EVI Neighbor");
47 * Make hash key for neighbors.
49 static unsigned int neigh_hash_keymake(const void *p
)
51 const zebra_neigh_t
*n
= p
;
52 const struct ipaddr
*ip
= &n
->ip
;
55 return jhash_1word(ip
->ipaddr_v4
.s_addr
, 0);
57 return jhash2(ip
->ipaddr_v6
.s6_addr32
,
58 array_size(ip
->ipaddr_v6
.s6_addr32
), 0);
62 * Compare two neighbor hash structures.
64 static bool neigh_cmp(const void *p1
, const void *p2
)
66 const zebra_neigh_t
*n1
= p1
;
67 const zebra_neigh_t
*n2
= p2
;
69 if (n1
== NULL
&& n2
== NULL
)
72 if (n1
== NULL
|| n2
== NULL
)
75 return (memcmp(&n1
->ip
, &n2
->ip
, sizeof(struct ipaddr
)) == 0);
78 int neigh_list_cmp(void *p1
, void *p2
)
80 const zebra_neigh_t
*n1
= p1
;
81 const zebra_neigh_t
*n2
= p2
;
83 return memcmp(&n1
->ip
, &n2
->ip
, sizeof(struct ipaddr
));
86 struct hash
*zebra_neigh_db_create(const char *desc
)
88 return hash_create_size(8, neigh_hash_keymake
, neigh_cmp
, desc
);
91 uint32_t num_dup_detected_neighs(zebra_evpn_t
*zevpn
)
94 uint32_t num_neighs
= 0;
96 struct hash_bucket
*hb
;
99 hash
= zevpn
->neigh_table
;
102 for (i
= 0; i
< hash
->size
; i
++) {
103 for (hb
= hash
->index
[i
]; hb
; hb
= hb
->next
) {
104 nbr
= (zebra_neigh_t
*)hb
->data
;
105 if (CHECK_FLAG(nbr
->flags
, ZEBRA_NEIGH_DUPLICATE
))
114 * Helper function to determine maximum width of neighbor IP address for
115 * display - just because we're dealing with IPv6 addresses that can
118 void zebra_evpn_find_neigh_addr_width(struct hash_bucket
*bucket
, void *ctxt
)
121 char buf
[INET6_ADDRSTRLEN
];
122 struct neigh_walk_ctx
*wctx
= ctxt
;
125 n
= (zebra_neigh_t
*)bucket
->data
;
127 ipaddr2str(&n
->ip
, buf
, sizeof(buf
));
129 if (width
> wctx
->addr_width
)
130 wctx
->addr_width
= width
;
134 * Count of remote neighbors referencing this MAC.
136 int remote_neigh_count(zebra_mac_t
*zmac
)
138 zebra_neigh_t
*n
= NULL
;
139 struct listnode
*node
= NULL
;
142 for (ALL_LIST_ELEMENTS_RO(zmac
->neigh_list
, node
, n
)) {
143 if (CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_REMOTE
))
151 * Install remote neighbor into the kernel.
153 int zebra_evpn_rem_neigh_install(zebra_evpn_t
*zevpn
, zebra_neigh_t
*n
,
156 struct interface
*vlan_if
;
160 if (!(n
->flags
& ZEBRA_NEIGH_REMOTE
))
163 vlan_if
= zevpn_map_to_svi(zevpn
);
167 flags
= DPLANE_NTF_EXT_LEARNED
;
168 if (n
->flags
& ZEBRA_NEIGH_ROUTER_FLAG
)
169 flags
|= DPLANE_NTF_ROUTER
;
170 ZEBRA_NEIGH_SET_ACTIVE(n
);
172 dplane_rem_neigh_add(vlan_if
, &n
->ip
, &n
->emac
, flags
, was_static
);
178 * Install neighbor hash entry - called upon access VLAN change.
180 void zebra_evpn_install_neigh_hash(struct hash_bucket
*bucket
, void *ctxt
)
183 struct neigh_walk_ctx
*wctx
= ctxt
;
185 n
= (zebra_neigh_t
*)bucket
->data
;
187 if (CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_REMOTE
))
188 zebra_evpn_rem_neigh_install(wctx
->zevpn
, n
,
189 false /*was_static*/);
193 * Callback to allocate neighbor hash entry.
195 static void *zebra_evpn_neigh_alloc(void *p
)
197 const zebra_neigh_t
*tmp_n
= p
;
200 n
= XCALLOC(MTYPE_NEIGH
, sizeof(zebra_neigh_t
));
206 static void zebra_evpn_local_neigh_ref_mac(zebra_neigh_t
*n
,
207 struct ethaddr
*macaddr
,
209 bool send_mac_update
)
214 memcpy(&n
->emac
, macaddr
, ETH_ALEN
);
217 /* Link to new MAC */
221 listnode_add_sort(mac
->neigh_list
, n
);
222 if (n
->flags
& ZEBRA_NEIGH_ALL_PEER_FLAGS
) {
223 old_static
= zebra_evpn_mac_is_static(mac
);
224 ++mac
->sync_neigh_cnt
;
225 new_static
= zebra_evpn_mac_is_static(mac
);
226 if (IS_ZEBRA_DEBUG_EVPN_MH_NEIGH
)
228 "sync-neigh ref mac vni %u ip %pIA mac %pEA ref %d",
229 n
->zevpn
->vni
, &n
->ip
, &n
->emac
,
230 mac
->sync_neigh_cnt
);
231 if ((old_static
!= new_static
) && send_mac_update
)
232 /* program the local mac in the kernel */
233 zebra_evpn_sync_mac_dp_install(
234 mac
, false /*set_inactive*/,
235 false /*force_clear_static*/, __func__
);
239 /* sync-path that is active on an ES peer */
240 static void zebra_evpn_sync_neigh_dp_install(zebra_neigh_t
*n
,
242 bool force_clear_static
,
245 struct zebra_ns
*zns
;
246 struct interface
*ifp
;
250 zns
= zebra_ns_lookup(NS_DEFAULT
);
251 ifp
= if_lookup_by_index_per_ns(zns
, n
->ifindex
);
253 if (IS_ZEBRA_DEBUG_EVPN_MH_NEIGH
)
255 "%s: dp-install sync-neigh vni %u ip %pIA mac %pEA if %d f 0x%x skipped",
256 caller
, n
->zevpn
->vni
, &n
->ip
, &n
->emac
,
257 n
->ifindex
, n
->flags
);
261 if (force_clear_static
)
264 set_static
= zebra_evpn_neigh_is_static(n
);
266 set_router
= !!CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_ROUTER_FLAG
);
268 /* XXX - this will change post integration with the new kernel */
269 if (CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_LOCAL_INACTIVE
))
272 if (IS_ZEBRA_DEBUG_EVPN_MH_NEIGH
)
274 "%s: dp-install sync-neigh vni %u ip %pIA mac %pEA if %s(%d) f 0x%x%s%s%s",
275 caller
, n
->zevpn
->vni
, &n
->ip
, &n
->emac
,
276 ifp
->name
, n
->ifindex
, n
->flags
,
277 set_router
? " router" : "",
278 set_static
? " static" : "",
279 set_inactive
? " inactive" : "");
280 dplane_local_neigh_add(ifp
, &n
->ip
, &n
->emac
, set_router
, set_static
,
285 * Inform BGP about local neighbor addition.
287 int zebra_evpn_neigh_send_add_to_client(vni_t vni
, struct ipaddr
*ip
,
288 struct ethaddr
*macaddr
,
289 zebra_mac_t
*zmac
, uint32_t neigh_flags
,
294 if (CHECK_FLAG(neigh_flags
, ZEBRA_NEIGH_LOCAL_INACTIVE
)) {
295 /* host reachability has not been verified locally */
297 /* if no ES peer is claiming reachability we can't advertise
300 if (!CHECK_FLAG(neigh_flags
, ZEBRA_NEIGH_ES_PEER_ACTIVE
))
303 /* ES peers are claiming reachability; we will
304 * advertise the entry but with a proxy flag
306 SET_FLAG(flags
, ZEBRA_MACIP_TYPE_PROXY_ADVERT
);
309 if (CHECK_FLAG(neigh_flags
, ZEBRA_NEIGH_DEF_GW
))
310 SET_FLAG(flags
, ZEBRA_MACIP_TYPE_GW
);
311 /* Set router flag (R-bit) based on local neigh entry add */
312 if (CHECK_FLAG(neigh_flags
, ZEBRA_NEIGH_ROUTER_FLAG
))
313 SET_FLAG(flags
, ZEBRA_MACIP_TYPE_ROUTER_FLAG
);
314 if (CHECK_FLAG(neigh_flags
, ZEBRA_NEIGH_SVI_IP
))
315 SET_FLAG(flags
, ZEBRA_MACIP_TYPE_SVI_IP
);
317 return zebra_evpn_macip_send_msg_to_client(vni
, macaddr
, ip
, flags
, seq
,
318 ZEBRA_NEIGH_ACTIVE
, zmac
->es
,
323 * Inform BGP about local neighbor deletion.
325 int zebra_evpn_neigh_send_del_to_client(vni_t vni
, struct ipaddr
*ip
,
326 struct ethaddr
*macaddr
, uint32_t flags
,
327 int state
, bool force
)
330 if (CHECK_FLAG(flags
, ZEBRA_NEIGH_LOCAL_INACTIVE
)
331 && !CHECK_FLAG(flags
, ZEBRA_NEIGH_ES_PEER_ACTIVE
))
332 /* the neigh was not advertised - nothing to delete */
336 return zebra_evpn_macip_send_msg_to_client(
337 vni
, macaddr
, ip
, flags
, 0, state
, NULL
, ZEBRA_MACIP_DEL
);
340 static void zebra_evpn_neigh_send_add_del_to_client(zebra_neigh_t
*n
,
345 zebra_evpn_neigh_send_add_to_client(n
->zevpn
->vni
, &n
->ip
,
346 &n
->emac
, n
->mac
, n
->flags
,
348 else if (old_bgp_ready
)
349 zebra_evpn_neigh_send_del_to_client(n
->zevpn
->vni
, &n
->ip
,
351 n
->state
, true /*force*/);
354 /* if the static flag associated with the neigh changes we need
355 * to update the sync-neigh references against the MAC
356 * and inform the dataplane about the static flag changes.
358 void zebra_evpn_sync_neigh_static_chg(zebra_neigh_t
*n
, bool old_n_static
,
359 bool new_n_static
, bool defer_n_dp
,
360 bool defer_mac_dp
, const char *caller
)
362 zebra_mac_t
*mac
= n
->mac
;
366 if (old_n_static
== new_n_static
)
369 /* update the neigh sync references in the dataplane. if
370 * the neigh is in the middle of updates the caller can
371 * request for a defer
374 zebra_evpn_sync_neigh_dp_install(n
, false /* set_inactive */,
375 false /* force_clear_static */,
381 /* update the mac sync ref cnt */
382 old_mac_static
= zebra_evpn_mac_is_static(mac
);
384 ++mac
->sync_neigh_cnt
;
385 } else if (old_n_static
) {
386 if (mac
->sync_neigh_cnt
)
387 --mac
->sync_neigh_cnt
;
389 new_mac_static
= zebra_evpn_mac_is_static(mac
);
391 /* update the mac sync references in the dataplane */
392 if ((old_mac_static
!= new_mac_static
) && !defer_mac_dp
)
393 zebra_evpn_sync_mac_dp_install(mac
, false /* set_inactive */,
394 false /* force_clear_static */,
397 if (IS_ZEBRA_DEBUG_EVPN_MH_NEIGH
)
399 "sync-neigh ref-chg vni %u ip %pIA mac %pEA f 0x%x %d%s%s%s%s by %s",
400 n
->zevpn
->vni
, &n
->ip
, &n
->emac
, n
->flags
,
402 old_n_static
? " old_n_static" : "",
403 new_n_static
? " new_n_static" : "",
404 old_mac_static
? " old_mac_static" : "",
405 new_mac_static
? " new_mac_static" : "", caller
);
408 /* Neigh hold timer is used to age out peer-active flag.
410 * During this wait time we expect the dataplane component or an
411 * external neighmgr daemon to probe existing hosts to independently
412 * establish their presence on the ES.
414 static int zebra_evpn_neigh_hold_exp_cb(struct thread
*t
)
423 /* the purpose of the hold timer is to age out the peer-active
426 if (!CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_ES_PEER_ACTIVE
))
429 old_bgp_ready
= zebra_evpn_neigh_is_ready_for_bgp(n
);
430 old_n_static
= zebra_evpn_neigh_is_static(n
);
431 UNSET_FLAG(n
->flags
, ZEBRA_NEIGH_ES_PEER_ACTIVE
);
432 new_bgp_ready
= zebra_evpn_neigh_is_ready_for_bgp(n
);
433 new_n_static
= zebra_evpn_neigh_is_static(n
);
435 if (IS_ZEBRA_DEBUG_EVPN_MH_NEIGH
)
436 zlog_debug("sync-neigh vni %u ip %pIA mac %pEA 0x%x hold expired",
437 n
->zevpn
->vni
, &n
->ip
, &n
->emac
, n
->flags
);
439 /* re-program the local neigh in the dataplane if the neigh is no
442 if (old_n_static
!= new_n_static
)
443 zebra_evpn_sync_neigh_static_chg(
444 n
, old_n_static
, new_n_static
, false /*defer_n_dp*/,
445 false /*defer_mac_dp*/, __func__
);
447 /* inform bgp if needed */
448 if (old_bgp_ready
!= new_bgp_ready
)
449 zebra_evpn_neigh_send_add_del_to_client(n
, old_bgp_ready
,
455 static inline void zebra_evpn_neigh_start_hold_timer(zebra_neigh_t
*n
)
460 if (IS_ZEBRA_DEBUG_EVPN_MH_NEIGH
)
461 zlog_debug("sync-neigh vni %u ip %pIA mac %pEA 0x%x hold start",
462 n
->zevpn
->vni
, &n
->ip
, &n
->emac
, n
->flags
);
463 thread_add_timer(zrouter
.master
, zebra_evpn_neigh_hold_exp_cb
, n
,
464 zmh_info
->neigh_hold_time
, &n
->hold_timer
);
467 static void zebra_evpn_local_neigh_deref_mac(zebra_neigh_t
*n
,
468 bool send_mac_update
)
470 zebra_mac_t
*mac
= n
->mac
;
471 zebra_evpn_t
*zevpn
= n
->zevpn
;
479 if ((n
->flags
& ZEBRA_NEIGH_ALL_PEER_FLAGS
) && mac
->sync_neigh_cnt
) {
480 old_static
= zebra_evpn_mac_is_static(mac
);
481 --mac
->sync_neigh_cnt
;
482 new_static
= zebra_evpn_mac_is_static(mac
);
483 if (IS_ZEBRA_DEBUG_EVPN_MH_NEIGH
)
485 "sync-neigh deref mac vni %u ip %pIA mac %pEA ref %d",
486 n
->zevpn
->vni
, &n
->ip
, &n
->emac
,
487 mac
->sync_neigh_cnt
);
488 if ((old_static
!= new_static
) && send_mac_update
)
489 /* program the local mac in the kernel */
490 zebra_evpn_sync_mac_dp_install(
491 mac
, false /* set_inactive */,
492 false /* force_clear_static */, __func__
);
495 listnode_delete(mac
->neigh_list
, n
);
496 zebra_evpn_deref_ip2mac(zevpn
, mac
);
499 bool zebra_evpn_neigh_is_bgp_seq_ok(zebra_evpn_t
*zevpn
, zebra_neigh_t
*n
,
500 struct ethaddr
*macaddr
, uint32_t seq
,
506 if (CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_LOCAL
)) {
507 tmp_seq
= n
->loc_seq
;
510 tmp_seq
= n
->rem_seq
;
515 /* if the neigh was never advertised to bgp we must accept
516 * whatever sequence number bgp sends
517 * XXX - check with Vivek
519 if (CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_LOCAL
)
520 && !zebra_evpn_neigh_is_ready_for_bgp(n
)) {
521 if (IS_ZEBRA_DEBUG_EVPN_MH_NEIGH
522 || IS_ZEBRA_DEBUG_VXLAN
)
524 "%s-macip accept vni %u %s mac %pEA IP %pIA lower seq %u f 0x%x",
525 sync
? "sync" : "remote", zevpn
->vni
,
526 n_type
, macaddr
, &n
->ip
,
531 if (IS_ZEBRA_DEBUG_EVPN_MH_NEIGH
|| IS_ZEBRA_DEBUG_VXLAN
)
533 "%s-macip ignore vni %u %s mac %pEA IP %pIA as existing has higher seq %u f 0x%x",
534 sync
? "sync" : "remote", zevpn
->vni
, n_type
,
535 macaddr
, &n
->ip
, tmp_seq
, n
->flags
);
543 * Add neighbor entry.
545 static zebra_neigh_t
*zebra_evpn_neigh_add(zebra_evpn_t
*zevpn
,
548 zebra_mac_t
*zmac
, uint32_t n_flags
)
551 zebra_neigh_t
*n
= NULL
;
553 memset(&tmp_n
, 0, sizeof(zebra_neigh_t
));
554 memcpy(&tmp_n
.ip
, ip
, sizeof(struct ipaddr
));
555 n
= hash_get(zevpn
->neigh_table
, &tmp_n
, zebra_evpn_neigh_alloc
);
558 n
->state
= ZEBRA_NEIGH_INACTIVE
;
560 n
->dad_ip_auto_recovery_timer
= NULL
;
562 n
->uptime
= monotime(NULL
);
565 zmac
= zebra_evpn_mac_lookup(zevpn
, mac
);
566 zebra_evpn_local_neigh_ref_mac(n
, mac
, zmac
,
567 false /* send_mac_update */);
573 * Delete neighbor entry.
575 int zebra_evpn_neigh_del(zebra_evpn_t
*zevpn
, zebra_neigh_t
*n
)
577 zebra_neigh_t
*tmp_n
;
580 listnode_delete(n
->mac
->neigh_list
, n
);
582 /* Cancel auto recovery */
583 THREAD_OFF(n
->dad_ip_auto_recovery_timer
);
585 /* Cancel proxy hold timer */
586 zebra_evpn_neigh_stop_hold_timer(n
);
588 /* Free the VNI hash entry and allocated memory. */
589 tmp_n
= hash_release(zevpn
->neigh_table
, n
);
590 XFREE(MTYPE_NEIGH
, tmp_n
);
595 void zebra_evpn_sync_neigh_del(zebra_neigh_t
*n
)
600 if (IS_ZEBRA_DEBUG_EVPN_MH_NEIGH
)
601 zlog_debug("sync-neigh del vni %u ip %pIA mac %pEA f 0x%x",
602 n
->zevpn
->vni
, &n
->ip
, &n
->emac
, n
->flags
);
604 old_n_static
= zebra_evpn_neigh_is_static(n
);
605 UNSET_FLAG(n
->flags
, ZEBRA_NEIGH_ES_PEER_PROXY
);
606 if (CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_ES_PEER_ACTIVE
))
607 zebra_evpn_neigh_start_hold_timer(n
);
608 new_n_static
= zebra_evpn_neigh_is_static(n
);
610 if (old_n_static
!= new_n_static
)
611 zebra_evpn_sync_neigh_static_chg(
612 n
, old_n_static
, new_n_static
, false /*defer-dp*/,
613 false /*defer_mac_dp*/, __func__
);
617 zebra_evpn_proc_sync_neigh_update(zebra_evpn_t
*zevpn
, zebra_neigh_t
*n
,
618 uint16_t ipa_len
, struct ipaddr
*ipaddr
,
619 uint8_t flags
, uint32_t seq
, esi_t
*esi
,
620 struct sync_mac_ip_ctx
*ctx
)
622 struct interface
*ifp
= NULL
;
624 zebra_mac_t
*mac
= ctx
->mac
;
626 bool old_router
= false;
627 bool old_bgp_ready
= false;
629 bool inform_dataplane
= false;
630 bool inform_bgp
= false;
633 bool set_dp_inactive
= false;
635 ifindex_t ifindex
= 0;
638 ifp
= zevpn_map_to_svi(zevpn
);
640 ifindex
= ifp
->ifindex
;
642 is_router
= !!CHECK_FLAG(flags
, ZEBRA_MACIP_TYPE_ROUTER_FLAG
);
643 old_mac_static
= zebra_evpn_mac_is_static(mac
);
646 uint32_t n_flags
= 0;
648 /* New neighbor - create */
649 SET_FLAG(n_flags
, ZEBRA_NEIGH_LOCAL
);
650 if (CHECK_FLAG(flags
, ZEBRA_MACIP_TYPE_PROXY_ADVERT
))
651 SET_FLAG(n_flags
, ZEBRA_NEIGH_ES_PEER_PROXY
);
653 SET_FLAG(n_flags
, ZEBRA_NEIGH_ES_PEER_ACTIVE
);
654 SET_FLAG(n_flags
, ZEBRA_NEIGH_LOCAL_INACTIVE
);
656 n
= zebra_evpn_neigh_add(zevpn
, ipaddr
, &mac
->macaddr
, mac
,
658 n
->ifindex
= ifindex
;
659 ZEBRA_NEIGH_SET_ACTIVE(n
);
662 inform_dataplane
= true;
664 set_dp_inactive
= true;
667 uint32_t old_flags
= n
->flags
;
672 old_n_static
= zebra_evpn_neigh_is_static(n
);
673 old_bgp_ready
= zebra_evpn_neigh_is_ready_for_bgp(n
);
674 old_router
= !!CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_ROUTER_FLAG
);
676 mac_change
= !!memcmp(&n
->emac
, &mac
->macaddr
, ETH_ALEN
);
678 /* deref and clear old info */
681 zebra_evpn_neigh_send_del_to_client(
682 zevpn
->vni
, &n
->ip
, &n
->emac
, n
->flags
,
683 n
->state
, false /*force*/);
684 old_bgp_ready
= false;
686 zebra_evpn_local_neigh_deref_mac(n
,
687 false /*send_mac_update*/);
689 /* clear old fwd info */
691 n
->r_vtep_ip
.s_addr
= 0;
693 /* setup new flags */
695 SET_FLAG(n
->flags
, ZEBRA_NEIGH_LOCAL
);
696 /* retain activity flag if the neigh was
699 if (old_flags
& ZEBRA_NEIGH_LOCAL
) {
700 n
->flags
|= (old_flags
& ZEBRA_NEIGH_LOCAL_INACTIVE
);
702 inform_dataplane
= true;
703 set_dp_inactive
= true;
704 n
->flags
|= ZEBRA_NEIGH_LOCAL_INACTIVE
;
707 if (CHECK_FLAG(flags
, ZEBRA_MACIP_TYPE_PROXY_ADVERT
))
708 SET_FLAG(n
->flags
, ZEBRA_NEIGH_ES_PEER_PROXY
);
710 SET_FLAG(n
->flags
, ZEBRA_NEIGH_ES_PEER_ACTIVE
);
712 if (CHECK_FLAG(flags
, ZEBRA_MACIP_TYPE_PROXY_ADVERT
)) {
713 SET_FLAG(n
->flags
, ZEBRA_NEIGH_ES_PEER_PROXY
);
714 /* if the neigh was peer-active previously we
715 * need to keep the flag and start the
716 * holdtimer on it. the peer-active flag is
717 * cleared on holdtimer expiry.
719 if (CHECK_FLAG(old_flags
, ZEBRA_NEIGH_ES_PEER_ACTIVE
)) {
720 SET_FLAG(n
->flags
, ZEBRA_NEIGH_ES_PEER_ACTIVE
);
721 zebra_evpn_neigh_start_hold_timer(n
);
724 SET_FLAG(n
->flags
, ZEBRA_NEIGH_ES_PEER_ACTIVE
);
725 /* stop hold timer if a peer has verified
728 zebra_evpn_neigh_stop_hold_timer(n
);
730 ZEBRA_NEIGH_SET_ACTIVE(n
);
732 if (IS_ZEBRA_DEBUG_EVPN_MH_NEIGH
&& (old_flags
!= n
->flags
))
734 "sync-neigh vni %u ip %pIA mac %pEA old_f 0x%x new_f 0x%x",
735 n
->zevpn
->vni
, &n
->ip
, &n
->emac
,
736 old_flags
, n
->flags
);
738 new_n_static
= zebra_evpn_neigh_is_static(n
);
740 set_dp_inactive
= true;
741 n
->flags
|= ZEBRA_NEIGH_LOCAL_INACTIVE
;
742 inform_dataplane
= true;
743 zebra_evpn_local_neigh_ref_mac(
744 n
, &mac
->macaddr
, mac
,
745 false /*send_mac_update*/);
746 } else if (old_n_static
!= new_n_static
) {
747 inform_dataplane
= true;
748 /* if static flags have changed without a mac change
749 * we need to create the correct sync-refs against
752 zebra_evpn_sync_neigh_static_chg(
753 n
, old_n_static
, new_n_static
,
754 true /*defer_dp*/, true /*defer_mac_dp*/,
758 /* Update the forwarding info. */
759 if (n
->ifindex
!= ifindex
) {
760 n
->ifindex
= ifindex
;
761 inform_dataplane
= true;
764 n
->uptime
= monotime(NULL
);
767 /* update the neigh seq. we don't bother with the mac seq as
768 * sync_mac_update already took care of that
770 tmp_seq
= MAX(n
->loc_seq
, seq
);
771 if (tmp_seq
!= n
->loc_seq
) {
772 n
->loc_seq
= tmp_seq
;
776 /* Mark Router flag (R-bit) */
778 SET_FLAG(n
->flags
, ZEBRA_NEIGH_ROUTER_FLAG
);
780 UNSET_FLAG(n
->flags
, ZEBRA_NEIGH_ROUTER_FLAG
);
782 if (old_router
!= is_router
)
783 inform_dataplane
= true;
785 new_bgp_ready
= zebra_evpn_neigh_is_ready_for_bgp(n
);
786 if (old_bgp_ready
!= new_bgp_ready
)
789 new_mac_static
= zebra_evpn_mac_is_static(mac
);
790 if ((old_mac_static
!= new_mac_static
) || ctx
->mac_dp_update_deferred
)
791 zebra_evpn_sync_mac_dp_install(mac
, ctx
->mac_inactive
,
792 false /* force_clear_static */,
795 if (IS_ZEBRA_DEBUG_EVPN_MH_NEIGH
)
797 "sync-neigh %s vni %u ip %pIA mac %pEA if %s(%d) seq %d f 0x%x%s%s",
798 created
? "created" : "updated", n
->zevpn
->vni
,
800 ifp
? ifp
->name
: "", ifindex
, n
->loc_seq
, n
->flags
,
801 inform_bgp
? " inform_bgp" : "",
802 inform_dataplane
? " inform_dp" : "");
804 if (inform_dataplane
)
805 zebra_evpn_sync_neigh_dp_install(n
, set_dp_inactive
,
806 false /* force_clear_static */,
810 zebra_evpn_neigh_send_add_del_to_client(n
, old_bgp_ready
,
817 * Uninstall remote neighbor from the kernel.
819 static int zebra_evpn_neigh_uninstall(zebra_evpn_t
*zevpn
, zebra_neigh_t
*n
)
821 struct interface
*vlan_if
;
823 if (!(n
->flags
& ZEBRA_NEIGH_REMOTE
))
826 vlan_if
= zevpn_map_to_svi(zevpn
);
830 ZEBRA_NEIGH_SET_INACTIVE(n
);
833 dplane_rem_neigh_delete(vlan_if
, &n
->ip
);
839 * Free neighbor hash entry (callback)
841 static void zebra_evpn_neigh_del_hash_entry(struct hash_bucket
*bucket
,
844 struct neigh_walk_ctx
*wctx
= arg
;
845 zebra_neigh_t
*n
= bucket
->data
;
847 if (((wctx
->flags
& DEL_LOCAL_NEIGH
) && (n
->flags
& ZEBRA_NEIGH_LOCAL
))
848 || ((wctx
->flags
& DEL_REMOTE_NEIGH
)
849 && (n
->flags
& ZEBRA_NEIGH_REMOTE
))
850 || ((wctx
->flags
& DEL_REMOTE_NEIGH_FROM_VTEP
)
851 && (n
->flags
& ZEBRA_NEIGH_REMOTE
)
852 && IPV4_ADDR_SAME(&n
->r_vtep_ip
, &wctx
->r_vtep_ip
))) {
853 if (wctx
->upd_client
&& (n
->flags
& ZEBRA_NEIGH_LOCAL
))
854 zebra_evpn_neigh_send_del_to_client(
855 wctx
->zevpn
->vni
, &n
->ip
, &n
->emac
, n
->flags
,
856 n
->state
, false /*force*/);
858 if (wctx
->uninstall
) {
859 if (zebra_evpn_neigh_is_static(n
))
860 zebra_evpn_sync_neigh_dp_install(
861 n
, false /* set_inactive */,
862 true /* force_clear_static */,
864 if ((n
->flags
& ZEBRA_NEIGH_REMOTE
))
865 zebra_evpn_neigh_uninstall(wctx
->zevpn
, n
);
868 zebra_evpn_neigh_del(wctx
->zevpn
, n
);
875 * Delete all neighbor entries for this EVPN.
877 void zebra_evpn_neigh_del_all(zebra_evpn_t
*zevpn
, int uninstall
,
878 int upd_client
, uint32_t flags
)
880 struct neigh_walk_ctx wctx
;
882 if (!zevpn
->neigh_table
)
885 memset(&wctx
, 0, sizeof(struct neigh_walk_ctx
));
887 wctx
.uninstall
= uninstall
;
888 wctx
.upd_client
= upd_client
;
891 hash_iterate(zevpn
->neigh_table
, zebra_evpn_neigh_del_hash_entry
,
896 * Look up neighbor hash entry.
898 zebra_neigh_t
*zebra_evpn_neigh_lookup(zebra_evpn_t
*zevpn
, struct ipaddr
*ip
)
903 memset(&tmp
, 0, sizeof(tmp
));
904 memcpy(&tmp
.ip
, ip
, sizeof(struct ipaddr
));
905 n
= hash_lookup(zevpn
->neigh_table
, &tmp
);
911 * Process all neighbors associated with a MAC upon the MAC being learnt
912 * locally or undergoing any other change (such as sequence number).
914 void zebra_evpn_process_neigh_on_local_mac_change(zebra_evpn_t
*zevpn
,
919 zebra_neigh_t
*n
= NULL
;
920 struct listnode
*node
= NULL
;
921 struct zebra_vrf
*zvrf
= NULL
;
923 zvrf
= vrf_info_lookup(zevpn
->vxlan_if
->vrf_id
);
925 if (IS_ZEBRA_DEBUG_VXLAN
)
926 zlog_debug("Processing neighbors on local MAC %pEA %s, VNI %u",
927 &zmac
->macaddr
, seq_change
? "CHANGE" : "ADD",
930 /* Walk all neighbors and mark any inactive local neighbors as
931 * active and/or update sequence number upon a move, and inform BGP.
932 * The action for remote neighbors is TBD.
933 * NOTE: We can't simply uninstall remote neighbors as the kernel may
934 * accidentally end up deleting a just-learnt local neighbor.
936 for (ALL_LIST_ELEMENTS_RO(zmac
->neigh_list
, node
, n
)) {
937 if (CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_LOCAL
)) {
938 if (IS_ZEBRA_NEIGH_INACTIVE(n
) || seq_change
940 ZEBRA_NEIGH_SET_ACTIVE(n
);
941 n
->loc_seq
= zmac
->loc_seq
;
942 if (!(zebra_evpn_do_dup_addr_detect(zvrf
)
944 && !!CHECK_FLAG(n
->flags
,
945 ZEBRA_NEIGH_DUPLICATE
)))
946 zebra_evpn_neigh_send_add_to_client(
947 zevpn
->vni
, &n
->ip
, &n
->emac
,
948 n
->mac
, n
->flags
, n
->loc_seq
);
955 * Process all neighbors associated with a local MAC upon the MAC being
958 void zebra_evpn_process_neigh_on_local_mac_del(zebra_evpn_t
*zevpn
,
961 zebra_neigh_t
*n
= NULL
;
962 struct listnode
*node
= NULL
;
964 if (IS_ZEBRA_DEBUG_VXLAN
)
965 zlog_debug("Processing neighbors on local MAC %pEA DEL, VNI %u",
966 &zmac
->macaddr
, zevpn
->vni
);
968 /* Walk all local neighbors and mark as inactive and inform
970 * TBD: There is currently no handling for remote neighbors. We
971 * don't expect them to exist, if they do, do we install the MAC
972 * as a remote MAC and the neighbor as remote?
974 for (ALL_LIST_ELEMENTS_RO(zmac
->neigh_list
, node
, n
)) {
975 if (CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_LOCAL
)) {
976 if (IS_ZEBRA_NEIGH_ACTIVE(n
)) {
977 ZEBRA_NEIGH_SET_INACTIVE(n
);
979 zebra_evpn_neigh_send_del_to_client(
980 zevpn
->vni
, &n
->ip
, &n
->emac
, n
->flags
,
981 ZEBRA_NEIGH_ACTIVE
, false /*force*/);
988 * Process all neighbors associated with a MAC upon the MAC being remotely
991 void zebra_evpn_process_neigh_on_remote_mac_add(zebra_evpn_t
*zevpn
,
994 zebra_neigh_t
*n
= NULL
;
995 struct listnode
*node
= NULL
;
997 if (IS_ZEBRA_DEBUG_VXLAN
)
998 zlog_debug("Processing neighbors on remote MAC %pEA ADD, VNI %u",
999 &zmac
->macaddr
, zevpn
->vni
);
1001 /* Walk all local neighbors and mark as inactive and inform
1004 for (ALL_LIST_ELEMENTS_RO(zmac
->neigh_list
, node
, n
)) {
1005 if (CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_LOCAL
)) {
1006 if (IS_ZEBRA_NEIGH_ACTIVE(n
)) {
1007 ZEBRA_NEIGH_SET_INACTIVE(n
);
1009 zebra_evpn_neigh_send_del_to_client(
1010 zevpn
->vni
, &n
->ip
, &n
->emac
, n
->flags
,
1011 ZEBRA_NEIGH_ACTIVE
, false /* force */);
1018 * Process all neighbors associated with a remote MAC upon the MAC being
1021 void zebra_evpn_process_neigh_on_remote_mac_del(zebra_evpn_t
*zevpn
,
1024 /* NOTE: Currently a NO-OP. */
1027 static inline void zebra_evpn_local_neigh_update_log(
1028 const char *pfx
, zebra_neigh_t
*n
, bool is_router
, bool local_inactive
,
1029 bool old_bgp_ready
, bool new_bgp_ready
, bool inform_dataplane
,
1030 bool inform_bgp
, const char *sfx
)
1032 if (!IS_ZEBRA_DEBUG_EVPN_MH_NEIGH
)
1035 zlog_debug("%s neigh vni %u ip %pIA mac %pEA f 0x%x%s%s%s%s%s%s %s", pfx
,
1036 n
->zevpn
->vni
, &n
->ip
, &n
->emac
, n
->flags
,
1037 is_router
? " router" : "",
1038 local_inactive
? " local-inactive" : "",
1039 old_bgp_ready
? " old_bgp_ready" : "",
1040 new_bgp_ready
? " new_bgp_ready" : "",
1041 inform_dataplane
? " inform_dp" : "",
1042 inform_bgp
? " inform_bgp" : "", sfx
);
1045 /* As part Duplicate Address Detection (DAD) for IP mobility
1046 * MAC binding changes, ensure to inherit duplicate flag
1049 static int zebra_evpn_ip_inherit_dad_from_mac(struct zebra_vrf
*zvrf
,
1050 zebra_mac_t
*old_zmac
,
1051 zebra_mac_t
*new_zmac
,
1054 bool is_old_mac_dup
= false;
1055 bool is_new_mac_dup
= false;
1057 if (!zebra_evpn_do_dup_addr_detect(zvrf
))
1059 /* Check old or new MAC is detected as duplicate
1060 * mark this neigh as duplicate
1064 CHECK_FLAG(old_zmac
->flags
, ZEBRA_MAC_DUPLICATE
);
1067 CHECK_FLAG(new_zmac
->flags
, ZEBRA_MAC_DUPLICATE
);
1068 /* Old and/or new MAC can be in duplicate state,
1069 * based on that IP/Neigh Inherits the flag.
1070 * If New MAC is marked duplicate, inherit to the IP.
1071 * If old MAC is duplicate but new MAC is not, clear
1072 * duplicate flag for IP and reset detection params
1073 * and let IP DAD retrigger.
1075 if (is_new_mac_dup
&& !CHECK_FLAG(nbr
->flags
, ZEBRA_NEIGH_DUPLICATE
)) {
1076 SET_FLAG(nbr
->flags
, ZEBRA_NEIGH_DUPLICATE
);
1077 /* Capture Duplicate detection time */
1078 nbr
->dad_dup_detect_time
= monotime(NULL
);
1079 /* Mark neigh inactive */
1080 ZEBRA_NEIGH_SET_INACTIVE(nbr
);
1083 } else if (is_old_mac_dup
&& !is_new_mac_dup
) {
1084 UNSET_FLAG(nbr
->flags
, ZEBRA_NEIGH_DUPLICATE
);
1086 nbr
->detect_start_time
.tv_sec
= 0;
1087 nbr
->detect_start_time
.tv_usec
= 0;
1092 static int zebra_evpn_dad_ip_auto_recovery_exp(struct thread
*t
)
1094 struct zebra_vrf
*zvrf
= NULL
;
1095 zebra_neigh_t
*nbr
= NULL
;
1096 zebra_evpn_t
*zevpn
= NULL
;
1098 nbr
= THREAD_ARG(t
);
1100 /* since this is asynchronous we need sanity checks*/
1101 zvrf
= vrf_info_lookup(nbr
->zevpn
->vrf_id
);
1105 zevpn
= zebra_evpn_lookup(nbr
->zevpn
->vni
);
1109 nbr
= zebra_evpn_neigh_lookup(zevpn
, &nbr
->ip
);
1113 if (IS_ZEBRA_DEBUG_VXLAN
)
1115 "%s: duplicate addr MAC %pEA IP %pIA flags 0x%x learn count %u vni %u auto recovery expired",
1116 __func__
, &nbr
->emac
, &nbr
->ip
, nbr
->flags
,
1117 nbr
->dad_count
, zevpn
->vni
);
1119 UNSET_FLAG(nbr
->flags
, ZEBRA_NEIGH_DUPLICATE
);
1121 nbr
->detect_start_time
.tv_sec
= 0;
1122 nbr
->detect_start_time
.tv_usec
= 0;
1123 nbr
->dad_dup_detect_time
= 0;
1124 nbr
->dad_ip_auto_recovery_timer
= NULL
;
1125 ZEBRA_NEIGH_SET_ACTIVE(nbr
);
1128 if (CHECK_FLAG(nbr
->flags
, ZEBRA_NEIGH_LOCAL
)) {
1129 zebra_evpn_neigh_send_add_to_client(zevpn
->vni
, &nbr
->ip
,
1130 &nbr
->emac
, nbr
->mac
,
1131 nbr
->flags
, nbr
->loc_seq
);
1132 } else if (!!CHECK_FLAG(nbr
->flags
, ZEBRA_NEIGH_REMOTE
)) {
1133 zebra_evpn_rem_neigh_install(zevpn
, nbr
, false /*was_static*/);
1140 zebra_evpn_dup_addr_detect_for_neigh(struct zebra_vrf
*zvrf
, zebra_neigh_t
*nbr
,
1141 struct in_addr vtep_ip
, bool do_dad
,
1142 bool *is_dup_detect
, bool is_local
)
1145 struct timeval elapsed
= {0, 0};
1146 bool reset_params
= false;
1148 if (!zebra_evpn_do_dup_addr_detect(zvrf
))
1151 /* IP is detected as duplicate or inherit dup
1152 * state, hold on to install as remote entry
1153 * only if freeze is enabled.
1155 if (CHECK_FLAG(nbr
->flags
, ZEBRA_NEIGH_DUPLICATE
)) {
1156 if (IS_ZEBRA_DEBUG_VXLAN
)
1158 "%s: duplicate addr MAC %pEA IP %pIA flags 0x%x skip installing, learn count %u recover time %u",
1159 __func__
, &nbr
->emac
, &nbr
->ip
,
1160 nbr
->flags
, nbr
->dad_count
,
1161 zvrf
->dad_freeze_time
);
1163 if (zvrf
->dad_freeze
)
1164 *is_dup_detect
= true;
1166 /* warn-only action, neigh will be installed.
1167 * freeze action, it wil not be installed.
1175 /* Check if detection time (M-secs) expired.
1176 * Reset learn count and detection start time.
1177 * During remote mac add, count should already be 1
1178 * via local learning.
1180 monotime_since(&nbr
->detect_start_time
, &elapsed
);
1181 reset_params
= (elapsed
.tv_sec
> zvrf
->dad_time
);
1183 if (is_local
&& !reset_params
) {
1184 /* RFC-7432: A PE/VTEP that detects a MAC mobility
1185 * event via LOCAL learning starts an M-second timer.
1187 * NOTE: This is the START of the probe with count is
1188 * 0 during LOCAL learn event.
1190 reset_params
= !nbr
->dad_count
;
1194 if (IS_ZEBRA_DEBUG_VXLAN
)
1196 "%s: duplicate addr MAC %pEA IP %pIA flags 0x%x detection time passed, reset learn count %u",
1197 __func__
, &nbr
->emac
, &nbr
->ip
,
1198 nbr
->flags
, nbr
->dad_count
);
1199 /* Reset learn count but do not start detection
1200 * during REMOTE learn event.
1203 /* Start dup. addr detection (DAD) start time,
1204 * ONLY during LOCAL learn.
1207 monotime(&nbr
->detect_start_time
);
1209 } else if (!is_local
) {
1210 /* For REMOTE IP/Neigh, increment detection count
1211 * ONLY while in probe window, once window passed,
1212 * next local learn event should trigger DAD.
1217 /* For LOCAL IP/Neigh learn event, once count is reset above via either
1218 * initial/start detection time or passed the probe time, the count
1219 * needs to be incremented.
1224 if (nbr
->dad_count
>= zvrf
->dad_max_moves
) {
1226 EC_ZEBRA_DUP_IP_DETECTED
,
1227 "VNI %u: MAC %pEA IP %pIA detected as duplicate during %s VTEP %pI4",
1228 nbr
->zevpn
->vni
, &nbr
->emac
, &nbr
->ip
,
1229 is_local
? "local update, last" : "remote update, from",
1232 SET_FLAG(nbr
->flags
, ZEBRA_NEIGH_DUPLICATE
);
1234 /* Capture Duplicate detection time */
1235 nbr
->dad_dup_detect_time
= monotime(NULL
);
1237 /* Start auto recovery timer for this IP */
1238 THREAD_OFF(nbr
->dad_ip_auto_recovery_timer
);
1239 if (zvrf
->dad_freeze
&& zvrf
->dad_freeze_time
) {
1240 if (IS_ZEBRA_DEBUG_VXLAN
)
1242 "%s: duplicate addr MAC %pEA IP %pIA flags 0x%x auto recovery time %u start",
1243 __func__
, &nbr
->emac
, &nbr
->ip
,
1244 nbr
->flags
, zvrf
->dad_freeze_time
);
1246 thread_add_timer(zrouter
.master
,
1247 zebra_evpn_dad_ip_auto_recovery_exp
,
1248 nbr
, zvrf
->dad_freeze_time
,
1249 &nbr
->dad_ip_auto_recovery_timer
);
1251 if (zvrf
->dad_freeze
)
1252 *is_dup_detect
= true;
1256 int zebra_evpn_local_neigh_update(zebra_evpn_t
*zevpn
, struct interface
*ifp
,
1257 struct ipaddr
*ip
, struct ethaddr
*macaddr
,
1258 bool is_router
, bool local_inactive
,
1261 struct zebra_vrf
*zvrf
;
1262 zebra_neigh_t
*n
= NULL
;
1263 zebra_mac_t
*zmac
= NULL
, *old_zmac
= NULL
;
1264 uint32_t old_mac_seq
= 0, mac_new_seq
= 0;
1265 bool upd_mac_seq
= false;
1266 bool neigh_mac_change
= false;
1267 bool neigh_on_hold
= false;
1268 bool neigh_was_remote
= false;
1269 bool do_dad
= false;
1270 struct in_addr vtep_ip
= {.s_addr
= 0};
1271 bool inform_dataplane
= false;
1272 bool created
= false;
1273 bool new_static
= false;
1274 bool old_bgp_ready
= false;
1277 /* Check if the MAC exists. */
1278 zmac
= zebra_evpn_mac_lookup(zevpn
, macaddr
);
1280 /* create a dummy MAC if the MAC is not already present */
1281 if (IS_ZEBRA_DEBUG_VXLAN
)
1282 zlog_debug("AUTO MAC %pEA created for neigh %pIA on VNI %u",
1283 macaddr
, ip
, zevpn
->vni
);
1285 zmac
= zebra_evpn_mac_add(zevpn
, macaddr
);
1287 zlog_debug("Failed to add MAC %pEA VNI %u", macaddr
,
1292 zebra_evpn_mac_clear_fwd_info(zmac
);
1293 memset(&zmac
->flags
, 0, sizeof(uint32_t));
1294 SET_FLAG(zmac
->flags
, ZEBRA_MAC_AUTO
);
1296 if (CHECK_FLAG(zmac
->flags
, ZEBRA_MAC_REMOTE
)) {
1298 * We don't change the MAC to local upon a neighbor
1299 * learn event, we wait for the explicit local MAC
1300 * learn. However, we have to compute its sequence
1301 * number in preparation for when it actually turns
1308 zvrf
= vrf_info_lookup(zevpn
->vxlan_if
->vrf_id
);
1310 if (IS_ZEBRA_DEBUG_VXLAN
)
1311 zlog_debug(" Unable to find vrf for: %d",
1312 zevpn
->vxlan_if
->vrf_id
);
1316 /* Check if the neighbor exists. */
1317 n
= zebra_evpn_neigh_lookup(zevpn
, ip
);
1319 /* New neighbor - create */
1320 n
= zebra_evpn_neigh_add(zevpn
, ip
, macaddr
, zmac
, 0);
1323 EC_ZEBRA_MAC_ADD_FAILED
,
1324 "Failed to add neighbor %pIA MAC %pEA intf %s(%u) -> VNI %u",
1325 ip
, macaddr
, ifp
->name
, ifp
->ifindex
,
1329 /* Set "local" forwarding info. */
1330 SET_FLAG(n
->flags
, ZEBRA_NEIGH_LOCAL
);
1331 n
->ifindex
= ifp
->ifindex
;
1334 if (CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_LOCAL
)) {
1337 bool old_local_inactive
;
1339 old_local_inactive
= !!CHECK_FLAG(
1340 n
->flags
, ZEBRA_NEIGH_LOCAL_INACTIVE
);
1342 old_bgp_ready
= zebra_evpn_neigh_is_ready_for_bgp(n
);
1344 /* Note any changes and see if of interest to BGP. */
1345 mac_different
= !!memcmp(&n
->emac
, macaddr
, ETH_ALEN
);
1347 !!CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_ROUTER_FLAG
);
1348 new_static
= zebra_evpn_neigh_is_static(n
);
1349 if (!mac_different
&& is_router
== cur_is_router
1350 && old_local_inactive
== local_inactive
1351 && dp_static
!= new_static
) {
1352 if (IS_ZEBRA_DEBUG_VXLAN
)
1354 " Ignoring entry mac is the same and is_router == cur_is_router");
1355 n
->ifindex
= ifp
->ifindex
;
1360 if (!mac_different
) {
1361 /* XXX - cleanup this code duplication */
1362 bool is_neigh_freezed
= false;
1364 /* Only the router flag has changed. */
1367 ZEBRA_NEIGH_ROUTER_FLAG
);
1369 UNSET_FLAG(n
->flags
,
1370 ZEBRA_NEIGH_ROUTER_FLAG
);
1374 ZEBRA_NEIGH_LOCAL_INACTIVE
);
1376 UNSET_FLAG(n
->flags
,
1377 ZEBRA_NEIGH_LOCAL_INACTIVE
);
1379 zebra_evpn_neigh_is_ready_for_bgp(n
);
1381 if (dp_static
!= new_static
)
1382 inform_dataplane
= true;
1384 /* Neigh is in freeze state and freeze action
1385 * is enabled, do not send update to client.
1388 (zebra_evpn_do_dup_addr_detect(zvrf
)
1390 && CHECK_FLAG(n
->flags
,
1391 ZEBRA_NEIGH_DUPLICATE
));
1393 zebra_evpn_local_neigh_update_log(
1394 "local", n
, is_router
, local_inactive
,
1395 old_bgp_ready
, new_bgp_ready
, false,
1396 false, "flag-update");
1398 if (inform_dataplane
)
1399 zebra_evpn_sync_neigh_dp_install(
1400 n
, false /* set_inactive */,
1401 false /* force_clear_static */,
1404 /* if the neigh can no longer be advertised
1405 * remove it from bgp
1407 if (!is_neigh_freezed
) {
1408 zebra_evpn_neigh_send_add_del_to_client(
1412 if (IS_ZEBRA_DEBUG_VXLAN
1413 && IS_ZEBRA_NEIGH_ACTIVE(n
))
1415 " Neighbor active and frozen");
1420 /* The MAC has changed, need to issue a delete
1421 * first as this means a different MACIP route.
1422 * Also, need to do some unlinking/relinking.
1423 * We also need to update the MAC's sequence number
1424 * in different situations.
1426 if (old_bgp_ready
) {
1427 zebra_evpn_neigh_send_del_to_client(
1428 zevpn
->vni
, &n
->ip
, &n
->emac
, n
->flags
,
1429 n
->state
, false /*force*/);
1430 old_bgp_ready
= false;
1433 old_mac_seq
= CHECK_FLAG(old_zmac
->flags
,
1436 : old_zmac
->loc_seq
;
1437 neigh_mac_change
= upd_mac_seq
= true;
1438 zebra_evpn_local_neigh_deref_mac(
1439 n
, true /* send_mac_update */);
1442 /* if mac changes abandon peer flags and tell
1443 * dataplane to clear the static flag
1445 if (zebra_evpn_neigh_clear_sync_info(n
))
1446 inform_dataplane
= true;
1447 /* Update the forwarding info. */
1448 n
->ifindex
= ifp
->ifindex
;
1450 /* Link to new MAC */
1451 zebra_evpn_local_neigh_ref_mac(
1452 n
, macaddr
, zmac
, true /* send_mac_update */);
1453 } else if (CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_REMOTE
)) {
1455 * Neighbor has moved from remote to local. Its
1456 * MAC could have also changed as part of the move.
1458 if (memcmp(n
->emac
.octet
, macaddr
->octet
, ETH_ALEN
)
1463 CHECK_FLAG(old_zmac
->flags
,
1466 : old_zmac
->loc_seq
;
1467 neigh_mac_change
= upd_mac_seq
= true;
1468 zebra_evpn_local_neigh_deref_mac(
1469 n
, true /* send_update */);
1472 /* Link to new MAC */
1473 zebra_evpn_local_neigh_ref_mac(
1474 n
, macaddr
, zmac
, true /*send_update*/);
1476 /* Based on Mobility event Scenario-B from the
1477 * draft, neigh's previous state was remote treat this
1480 neigh_was_remote
= true;
1481 vtep_ip
= n
->r_vtep_ip
;
1482 /* Mark appropriately */
1483 UNSET_FLAG(n
->flags
, ZEBRA_NEIGH_REMOTE
);
1484 n
->r_vtep_ip
.s_addr
= INADDR_ANY
;
1485 SET_FLAG(n
->flags
, ZEBRA_NEIGH_LOCAL
);
1486 n
->ifindex
= ifp
->ifindex
;
1490 /* If MAC was previously remote, or the neighbor had a different
1491 * MAC earlier, recompute the sequence number.
1494 uint32_t seq1
, seq2
;
1496 seq1
= CHECK_FLAG(zmac
->flags
, ZEBRA_MAC_REMOTE
)
1499 seq2
= neigh_mac_change
? old_mac_seq
+ 1 : 0;
1500 mac_new_seq
= zmac
->loc_seq
< MAX(seq1
, seq2
) ? MAX(seq1
, seq2
)
1505 SET_FLAG(n
->flags
, ZEBRA_NEIGH_LOCAL_INACTIVE
);
1507 UNSET_FLAG(n
->flags
, ZEBRA_NEIGH_LOCAL_INACTIVE
);
1509 /* Mark Router flag (R-bit) */
1511 SET_FLAG(n
->flags
, ZEBRA_NEIGH_ROUTER_FLAG
);
1513 UNSET_FLAG(n
->flags
, ZEBRA_NEIGH_ROUTER_FLAG
);
1515 /* if zebra and dataplane don't agree this is a sync entry
1516 * re-install in the dataplane */
1517 new_static
= zebra_evpn_neigh_is_static(n
);
1518 if (dp_static
!= new_static
)
1519 inform_dataplane
= true;
1521 /* Check old and/or new MAC detected as duplicate mark
1522 * the neigh as duplicate
1524 if (zebra_evpn_ip_inherit_dad_from_mac(zvrf
, old_zmac
, zmac
, n
)) {
1526 EC_ZEBRA_DUP_IP_INHERIT_DETECTED
,
1527 "VNI %u: MAC %pEA IP %pIA detected as duplicate during local update, inherit duplicate from MAC",
1528 zevpn
->vni
, macaddr
, &n
->ip
);
1531 /* For IP Duplicate Address Detection (DAD) is trigger,
1532 * when the event is extended mobility based on scenario-B
1533 * from the draft, IP/Neigh's MAC binding changed and
1534 * neigh's previous state was remote.
1536 if (neigh_mac_change
&& neigh_was_remote
)
1539 zebra_evpn_dup_addr_detect_for_neigh(zvrf
, n
, vtep_ip
, do_dad
,
1540 &neigh_on_hold
, true);
1542 if (inform_dataplane
)
1543 zebra_evpn_sync_neigh_dp_install(n
, false /* set_inactive */,
1544 false /* force_clear_static */,
1547 /* Before we program this in BGP, we need to check if MAC is locally
1548 * learnt. If not, force neighbor to be inactive and reset its seq.
1550 if (!CHECK_FLAG(zmac
->flags
, ZEBRA_MAC_LOCAL
)) {
1551 zebra_evpn_local_neigh_update_log(
1552 "local", n
, is_router
, local_inactive
, false, false,
1553 inform_dataplane
, false, "auto-mac");
1554 ZEBRA_NEIGH_SET_INACTIVE(n
);
1556 zmac
->loc_seq
= mac_new_seq
;
1560 zebra_evpn_local_neigh_update_log("local", n
, is_router
, local_inactive
,
1561 false, false, inform_dataplane
, true,
1562 created
? "created" : "updated");
1564 /* If the MAC's sequence number has changed, inform the MAC and all
1565 * neighbors associated with the MAC to BGP, else just inform this
1568 if (upd_mac_seq
&& zmac
->loc_seq
!= mac_new_seq
) {
1569 if (IS_ZEBRA_DEBUG_VXLAN
)
1571 "Seq changed for MAC %pEA VNI %u - old %u new %u",
1572 macaddr
, zevpn
->vni
,
1573 zmac
->loc_seq
, mac_new_seq
);
1574 zmac
->loc_seq
= mac_new_seq
;
1575 if (zebra_evpn_mac_send_add_to_client(zevpn
->vni
, macaddr
,
1577 zmac
->loc_seq
, zmac
->es
))
1579 zebra_evpn_process_neigh_on_local_mac_change(zevpn
, zmac
, 1,
1584 n
->loc_seq
= zmac
->loc_seq
;
1586 if (!neigh_on_hold
) {
1587 ZEBRA_NEIGH_SET_ACTIVE(n
);
1588 new_bgp_ready
= zebra_evpn_neigh_is_ready_for_bgp(n
);
1589 zebra_evpn_neigh_send_add_del_to_client(n
, old_bgp_ready
,
1592 if (IS_ZEBRA_DEBUG_VXLAN
)
1593 zlog_debug(" Neighbor on hold not sending");
1598 int zebra_evpn_remote_neigh_update(zebra_evpn_t
*zevpn
, struct interface
*ifp
,
1599 struct ipaddr
*ip
, struct ethaddr
*macaddr
,
1602 zebra_neigh_t
*n
= NULL
;
1603 zebra_mac_t
*zmac
= NULL
;
1605 /* If the neighbor is unknown, there is no further action. */
1606 n
= zebra_evpn_neigh_lookup(zevpn
, ip
);
1610 /* If a remote entry, see if it needs to be refreshed */
1611 if (CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_REMOTE
)) {
1613 if (state
& NUD_STALE
)
1614 zebra_evpn_rem_neigh_install(zevpn
, n
,
1615 false /*was_static*/);
1618 /* We got a "remote" neighbor notification for an entry
1619 * we think is local. This can happen in a multihoming
1620 * scenario - but only if the MAC is already "remote".
1621 * Just mark our entry as "remote".
1623 zmac
= zebra_evpn_mac_lookup(zevpn
, macaddr
);
1624 if (!zmac
|| !CHECK_FLAG(zmac
->flags
, ZEBRA_MAC_REMOTE
)) {
1626 "Ignore remote neigh %pIA (MAC %pEA) on L2-VNI %u - MAC unknown or local",
1627 &n
->ip
, macaddr
, zevpn
->vni
);
1631 UNSET_FLAG(n
->flags
, ZEBRA_NEIGH_ALL_LOCAL_FLAGS
);
1632 SET_FLAG(n
->flags
, ZEBRA_NEIGH_REMOTE
);
1633 ZEBRA_NEIGH_SET_ACTIVE(n
);
1634 n
->r_vtep_ip
= zmac
->fwd_info
.r_vtep_ip
;
1640 /* Notify Neighbor entries to the Client, skips the GW entry */
1642 zebra_evpn_send_neigh_hash_entry_to_client(struct hash_bucket
*bucket
,
1645 struct mac_walk_ctx
*wctx
= arg
;
1646 zebra_neigh_t
*zn
= bucket
->data
;
1647 zebra_mac_t
*zmac
= NULL
;
1649 if (CHECK_FLAG(zn
->flags
, ZEBRA_NEIGH_DEF_GW
))
1652 if (CHECK_FLAG(zn
->flags
, ZEBRA_NEIGH_LOCAL
)
1653 && IS_ZEBRA_NEIGH_ACTIVE(zn
)) {
1654 zmac
= zebra_evpn_mac_lookup(wctx
->zevpn
, &zn
->emac
);
1658 zebra_evpn_neigh_send_add_to_client(wctx
->zevpn
->vni
, &zn
->ip
,
1660 zn
->flags
, zn
->loc_seq
);
1664 /* Iterator of a specific EVPN */
1665 void zebra_evpn_send_neigh_to_client(zebra_evpn_t
*zevpn
)
1667 struct neigh_walk_ctx wctx
;
1669 memset(&wctx
, 0, sizeof(struct neigh_walk_ctx
));
1672 hash_iterate(zevpn
->neigh_table
,
1673 zebra_evpn_send_neigh_hash_entry_to_client
, &wctx
);
1676 void zebra_evpn_clear_dup_neigh_hash(struct hash_bucket
*bucket
, void *ctxt
)
1678 struct neigh_walk_ctx
*wctx
= ctxt
;
1680 zebra_evpn_t
*zevpn
;
1681 char buf
[INET6_ADDRSTRLEN
];
1683 nbr
= (zebra_neigh_t
*)bucket
->data
;
1687 zevpn
= wctx
->zevpn
;
1689 if (!CHECK_FLAG(nbr
->flags
, ZEBRA_NEIGH_DUPLICATE
))
1692 if (IS_ZEBRA_DEBUG_VXLAN
) {
1693 ipaddr2str(&nbr
->ip
, buf
, sizeof(buf
));
1694 zlog_debug("%s: clear neigh %s dup state, flags 0x%x seq %u",
1695 __func__
, buf
, nbr
->flags
, nbr
->loc_seq
);
1698 UNSET_FLAG(nbr
->flags
, ZEBRA_NEIGH_DUPLICATE
);
1700 nbr
->detect_start_time
.tv_sec
= 0;
1701 nbr
->detect_start_time
.tv_usec
= 0;
1702 nbr
->dad_dup_detect_time
= 0;
1703 THREAD_OFF(nbr
->dad_ip_auto_recovery_timer
);
1705 if (CHECK_FLAG(nbr
->flags
, ZEBRA_NEIGH_LOCAL
)) {
1706 zebra_evpn_neigh_send_add_to_client(zevpn
->vni
, &nbr
->ip
,
1707 &nbr
->emac
, nbr
->mac
,
1708 nbr
->flags
, nbr
->loc_seq
);
1709 } else if (CHECK_FLAG(nbr
->flags
, ZEBRA_NEIGH_REMOTE
)) {
1710 zebra_evpn_rem_neigh_install(zevpn
, nbr
, false /*was_static*/);
1715 * Print a specific neighbor entry.
1717 void zebra_evpn_print_neigh(zebra_neigh_t
*n
, void *ctxt
, json_object
*json
)
1720 char buf1
[ETHER_ADDR_STRLEN
];
1721 char buf2
[INET6_ADDRSTRLEN
];
1722 char addr_buf
[PREFIX_STRLEN
];
1723 const char *type_str
;
1724 const char *state_str
;
1725 bool flags_present
= false;
1726 struct zebra_vrf
*zvrf
= NULL
;
1727 struct timeval detect_start_time
= {0, 0};
1728 char timebuf
[MONOTIME_STRLEN
];
1729 char thread_buf
[THREAD_TIMER_STRLEN
];
1731 char up_str
[MONOTIME_STRLEN
];
1733 zvrf
= zebra_vrf_get_evpn();
1737 uptime
= monotime(NULL
);
1738 uptime
-= n
->uptime
;
1740 frrtime_to_interval(uptime
, up_str
, sizeof(up_str
));
1742 ipaddr2str(&n
->ip
, buf2
, sizeof(buf2
));
1743 prefix_mac2str(&n
->emac
, buf1
, sizeof(buf1
));
1744 type_str
= CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_LOCAL
) ? "local" : "remote";
1745 state_str
= IS_ZEBRA_NEIGH_ACTIVE(n
) ? "active" : "inactive";
1746 vty
= (struct vty
*)ctxt
;
1748 bool sync_info
= false;
1750 vty_out(vty
, "IP: %s\n",
1751 ipaddr2str(&n
->ip
, buf2
, sizeof(buf2
)));
1752 vty_out(vty
, " Type: %s\n", type_str
);
1753 vty_out(vty
, " State: %s\n", state_str
);
1754 vty_out(vty
, " Uptime: %s\n", up_str
);
1755 vty_out(vty
, " MAC: %s\n",
1756 prefix_mac2str(&n
->emac
, buf1
, sizeof(buf1
)));
1757 vty_out(vty
, " Sync-info:");
1758 if (CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_LOCAL_INACTIVE
)) {
1759 vty_out(vty
, " local-inactive");
1762 if (CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_ES_PEER_PROXY
)) {
1763 vty_out(vty
, " peer-proxy");
1766 if (CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_ES_PEER_ACTIVE
)) {
1767 vty_out(vty
, " peer-active");
1770 if (n
->hold_timer
) {
1771 vty_out(vty
, " (ht: %s)",
1772 thread_timer_to_hhmmss(thread_buf
,
1781 json_object_string_add(json
, "uptime", up_str
);
1782 json_object_string_add(json
, "ip", buf2
);
1783 json_object_string_add(json
, "type", type_str
);
1784 json_object_string_add(json
, "state", state_str
);
1785 json_object_string_add(json
, "mac", buf1
);
1786 if (CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_LOCAL_INACTIVE
))
1787 json_object_boolean_true_add(json
, "localInactive");
1788 if (CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_ES_PEER_PROXY
))
1789 json_object_boolean_true_add(json
, "peerProxy");
1790 if (CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_ES_PEER_ACTIVE
))
1791 json_object_boolean_true_add(json
, "peerActive");
1793 json_object_string_add(
1794 json
, "peerActiveHold",
1795 thread_timer_to_hhmmss(thread_buf
,
1799 if (CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_REMOTE
)) {
1802 json_object_string_add(json
, "remoteEs",
1803 n
->mac
->es
->esi_str
);
1805 vty_out(vty
, " Remote ES: %s\n",
1806 n
->mac
->es
->esi_str
);
1809 json_object_string_add(
1811 inet_ntop(AF_INET
, &n
->r_vtep_ip
,
1812 addr_buf
, sizeof(addr_buf
)));
1814 vty_out(vty
, " Remote VTEP: %pI4\n",
1818 if (CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_DEF_GW
)) {
1820 vty_out(vty
, " Flags: Default-gateway");
1821 flags_present
= true;
1823 json_object_boolean_true_add(json
, "defaultGateway");
1825 if (CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_ROUTER_FLAG
)) {
1828 flags_present
? " ,Router" : " Flags: Router");
1829 flags_present
= true;
1835 vty_out(vty
, " Local Seq: %u Remote Seq: %u\n", n
->loc_seq
,
1838 if (CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_DUPLICATE
)) {
1839 vty_out(vty
, " Duplicate, detected at %s",
1840 time_to_string(n
->dad_dup_detect_time
,
1842 } else if (n
->dad_count
) {
1843 monotime_since(&n
->detect_start_time
,
1844 &detect_start_time
);
1845 if (detect_start_time
.tv_sec
<= zvrf
->dad_time
) {
1846 time_to_string(n
->detect_start_time
.tv_sec
,
1849 " Duplicate detection started at %s, detection count %u\n",
1850 timebuf
, n
->dad_count
);
1854 json_object_int_add(json
, "localSequence", n
->loc_seq
);
1855 json_object_int_add(json
, "remoteSequence", n
->rem_seq
);
1856 json_object_int_add(json
, "detectionCount", n
->dad_count
);
1857 if (CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_DUPLICATE
))
1858 json_object_boolean_true_add(json
, "isDuplicate");
1860 json_object_boolean_false_add(json
, "isDuplicate");
1864 void zebra_evpn_print_neigh_hdr(struct vty
*vty
, struct neigh_walk_ctx
*wctx
)
1866 vty_out(vty
, "Flags: I=local-inactive, P=peer-active, X=peer-proxy\n");
1867 vty_out(vty
, "%*s %-6s %-5s %-8s %-17s %-30s %s\n", -wctx
->addr_width
,
1868 "Neighbor", "Type", "Flags", "State", "MAC", "Remote ES/VTEP",
1872 static char *zebra_evpn_print_neigh_flags(zebra_neigh_t
*n
, char *flags_buf
,
1873 uint32_t flags_buf_sz
)
1875 snprintf(flags_buf
, flags_buf_sz
, "%s%s%s",
1876 (n
->flags
& ZEBRA_NEIGH_ES_PEER_ACTIVE
) ?
1878 (n
->flags
& ZEBRA_NEIGH_ES_PEER_PROXY
) ?
1880 (n
->flags
& ZEBRA_NEIGH_LOCAL_INACTIVE
) ?
1887 * Print neighbor hash entry - called for display of all neighbors.
1889 void zebra_evpn_print_neigh_hash(struct hash_bucket
*bucket
, void *ctxt
)
1892 json_object
*json_evpn
= NULL
, *json_row
= NULL
;
1894 char buf1
[ETHER_ADDR_STRLEN
];
1895 char buf2
[INET6_ADDRSTRLEN
];
1896 char addr_buf
[PREFIX_STRLEN
];
1897 struct neigh_walk_ctx
*wctx
= ctxt
;
1898 const char *state_str
;
1902 json_evpn
= wctx
->json
;
1903 n
= (zebra_neigh_t
*)bucket
->data
;
1906 json_row
= json_object_new_object();
1908 prefix_mac2str(&n
->emac
, buf1
, sizeof(buf1
));
1909 ipaddr2str(&n
->ip
, buf2
, sizeof(buf2
));
1910 state_str
= IS_ZEBRA_NEIGH_ACTIVE(n
) ? "active" : "inactive";
1911 if (CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_LOCAL
)) {
1912 if (wctx
->flags
& SHOW_REMOTE_NEIGH_FROM_VTEP
)
1915 if (json_evpn
== NULL
) {
1916 vty_out(vty
, "%*s %-6s %-5s %-8s %-17s %-30s %u/%u\n",
1917 -wctx
->addr_width
, buf2
, "local",
1918 zebra_evpn_print_neigh_flags(n
, flags_buf
,
1919 sizeof(flags_buf
)), state_str
, buf1
,
1920 "", n
->loc_seq
, n
->rem_seq
);
1922 json_object_string_add(json_row
, "type", "local");
1923 json_object_string_add(json_row
, "state", state_str
);
1924 json_object_string_add(json_row
, "mac", buf1
);
1925 if (CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_DEF_GW
))
1926 json_object_boolean_true_add(json_row
,
1928 json_object_int_add(json_row
, "localSequence",
1930 json_object_int_add(json_row
, "remoteSequence",
1932 json_object_int_add(json_row
, "detectionCount",
1934 if (CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_DUPLICATE
))
1935 json_object_boolean_true_add(json_row
,
1938 json_object_boolean_false_add(json_row
,
1942 } else if (CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_REMOTE
)) {
1943 if ((wctx
->flags
& SHOW_REMOTE_NEIGH_FROM_VTEP
)
1944 && !IPV4_ADDR_SAME(&n
->r_vtep_ip
, &wctx
->r_vtep_ip
))
1947 if (json_evpn
== NULL
) {
1948 if ((wctx
->flags
& SHOW_REMOTE_NEIGH_FROM_VTEP
)
1949 && (wctx
->count
== 0))
1950 zebra_evpn_print_neigh_hdr(vty
, wctx
);
1952 if (n
->mac
->es
== NULL
)
1953 inet_ntop(AF_INET
, &n
->r_vtep_ip
,
1954 addr_buf
, sizeof(addr_buf
));
1956 vty_out(vty
, "%*s %-6s %-5s %-8s %-17s %-30s %u/%u\n",
1957 -wctx
->addr_width
, buf2
, "remote",
1958 zebra_evpn_print_neigh_flags(n
, flags_buf
,
1959 sizeof(flags_buf
)), state_str
, buf1
,
1960 n
->mac
->es
? n
->mac
->es
->esi_str
: addr_buf
,
1961 n
->loc_seq
, n
->rem_seq
);
1963 json_object_string_add(json_row
, "type", "remote");
1964 json_object_string_add(json_row
, "state", state_str
);
1965 json_object_string_add(json_row
, "mac", buf1
);
1967 json_object_string_add(json_row
, "remoteEs",
1968 n
->mac
->es
->esi_str
);
1970 json_object_string_add(
1971 json_row
, "remoteVtep",
1972 inet_ntop(AF_INET
, &n
->r_vtep_ip
,
1973 addr_buf
, sizeof(addr_buf
)));
1974 if (CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_DEF_GW
))
1975 json_object_boolean_true_add(json_row
,
1977 json_object_int_add(json_row
, "localSequence",
1979 json_object_int_add(json_row
, "remoteSequence",
1981 json_object_int_add(json_row
, "detectionCount",
1983 if (CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_DUPLICATE
))
1984 json_object_boolean_true_add(json_row
,
1987 json_object_boolean_false_add(json_row
,
1994 json_object_object_add(json_evpn
, buf2
, json_row
);
1998 * Print neighbor hash entry in detail - called for display of all neighbors.
2000 void zebra_evpn_print_neigh_hash_detail(struct hash_bucket
*bucket
, void *ctxt
)
2003 json_object
*json_evpn
= NULL
, *json_row
= NULL
;
2005 char buf
[INET6_ADDRSTRLEN
];
2006 struct neigh_walk_ctx
*wctx
= ctxt
;
2009 json_evpn
= wctx
->json
;
2010 n
= (zebra_neigh_t
*)bucket
->data
;
2014 ipaddr2str(&n
->ip
, buf
, sizeof(buf
));
2016 json_row
= json_object_new_object();
2018 zebra_evpn_print_neigh(n
, vty
, json_row
);
2021 json_object_object_add(json_evpn
, buf
, json_row
);
2024 void zebra_evpn_print_dad_neigh_hash(struct hash_bucket
*bucket
, void *ctxt
)
2028 nbr
= (zebra_neigh_t
*)bucket
->data
;
2032 if (CHECK_FLAG(nbr
->flags
, ZEBRA_NEIGH_DUPLICATE
))
2033 zebra_evpn_print_neigh_hash(bucket
, ctxt
);
2036 void zebra_evpn_print_dad_neigh_hash_detail(struct hash_bucket
*bucket
,
2041 nbr
= (zebra_neigh_t
*)bucket
->data
;
2045 if (CHECK_FLAG(nbr
->flags
, ZEBRA_NEIGH_DUPLICATE
))
2046 zebra_evpn_print_neigh_hash_detail(bucket
, ctxt
);
2049 void process_neigh_remote_macip_add(zebra_evpn_t
*zevpn
, struct zebra_vrf
*zvrf
,
2050 struct ipaddr
*ipaddr
, zebra_mac_t
*mac
,
2051 struct in_addr vtep_ip
, uint8_t flags
,
2055 int update_neigh
= 0;
2056 zebra_mac_t
*old_mac
= NULL
;
2057 bool old_static
= false;
2058 bool do_dad
= false;
2059 bool is_dup_detect
= false;
2063 is_router
= !!CHECK_FLAG(flags
, ZEBRA_MACIP_TYPE_ROUTER_FLAG
);
2065 /* Check if the remote neighbor itself is unknown or has a
2066 * change. If so, create or update and then install the entry.
2068 n
= zebra_evpn_neigh_lookup(zevpn
, ipaddr
);
2069 if (!n
|| !CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_REMOTE
)
2070 || is_router
!= !!CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_ROUTER_FLAG
)
2071 || (memcmp(&n
->emac
, &mac
->macaddr
, sizeof(struct ethaddr
)) != 0)
2072 || !IPV4_ADDR_SAME(&n
->r_vtep_ip
, &vtep_ip
) || seq
!= n
->rem_seq
)
2077 n
= zebra_evpn_neigh_add(zevpn
, ipaddr
, &mac
->macaddr
,
2081 "Failed to add Neigh %pIA MAC %pEA VNI %u Remote VTEP %pI4",
2082 ipaddr
, &mac
->macaddr
, zevpn
->vni
,
2088 /* When host moves but changes its (MAC,IP)
2089 * binding, BGP may install a MACIP entry that
2090 * corresponds to "older" location of the host
2091 * in transient situations (because {IP1,M1}
2092 * is a different route from {IP1,M2}). Check
2093 * the sequence number and ignore this update
2097 if (!zebra_evpn_neigh_is_bgp_seq_ok(
2098 zevpn
, n
, &mac
->macaddr
, seq
, false))
2100 if (CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_LOCAL
)) {
2101 old_static
= zebra_evpn_neigh_is_static(n
);
2102 if (IS_ZEBRA_DEBUG_EVPN_MH_NEIGH
)
2104 "sync->remote neigh vni %u ip %pIA mac %pEA seq %d f0x%x",
2105 n
->zevpn
->vni
, &n
->ip
, &n
->emac
,
2107 zebra_evpn_neigh_clear_sync_info(n
);
2108 if (IS_ZEBRA_NEIGH_ACTIVE(n
))
2109 zebra_evpn_neigh_send_del_to_client(
2110 zevpn
->vni
, &n
->ip
, &n
->emac
,
2114 if (memcmp(&n
->emac
, &mac
->macaddr
,
2115 sizeof(struct ethaddr
))
2117 /* update neigh list for macs */
2119 zebra_evpn_mac_lookup(zevpn
, &n
->emac
);
2121 listnode_delete(old_mac
->neigh_list
, n
);
2123 zebra_evpn_deref_ip2mac(zevpn
, old_mac
);
2126 listnode_add_sort(mac
->neigh_list
, n
);
2127 memcpy(&n
->emac
, &mac
->macaddr
, ETH_ALEN
);
2129 /* Check Neigh's curent state is local
2130 * (this is the case where neigh/host has moved
2131 * from L->R) and check previous detction
2132 * started via local learning.
2134 * RFC-7432: A PE/VTEP that detects a MAC
2135 * mobilit event via local learning starts
2136 * an M-second timer.
2137 * VTEP-IP or seq. change along is not
2138 * considered for dup. detection.
2140 * Mobilty event scenario-B IP-MAC binding
2143 if ((!CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_REMOTE
))
2149 /* Set "remote" forwarding info. */
2150 UNSET_FLAG(n
->flags
, ZEBRA_NEIGH_ALL_LOCAL_FLAGS
);
2151 n
->r_vtep_ip
= vtep_ip
;
2152 SET_FLAG(n
->flags
, ZEBRA_NEIGH_REMOTE
);
2154 /* Set router flag (R-bit) to this Neighbor entry */
2155 if (CHECK_FLAG(flags
, ZEBRA_MACIP_TYPE_ROUTER_FLAG
))
2156 SET_FLAG(n
->flags
, ZEBRA_NEIGH_ROUTER_FLAG
);
2158 UNSET_FLAG(n
->flags
, ZEBRA_NEIGH_ROUTER_FLAG
);
2160 /* Check old or new MAC detected as duplicate,
2161 * inherit duplicate flag to this neigh.
2163 if (zebra_evpn_ip_inherit_dad_from_mac(zvrf
, old_mac
, mac
, n
)) {
2165 EC_ZEBRA_DUP_IP_INHERIT_DETECTED
,
2166 "VNI %u: MAC %pEA IP %pIA detected as duplicate during remote update, inherit duplicate from MAC",
2167 zevpn
->vni
, &mac
->macaddr
, &n
->ip
);
2170 /* Check duplicate address detection for IP */
2171 zebra_evpn_dup_addr_detect_for_neigh(
2172 zvrf
, n
, n
->r_vtep_ip
, do_dad
, &is_dup_detect
, false);
2173 /* Install the entry. */
2175 zebra_evpn_rem_neigh_install(zevpn
, n
, old_static
);
2178 /* Update seq number. */
2182 int zebra_evpn_neigh_gw_macip_add(struct interface
*ifp
, zebra_evpn_t
*zevpn
,
2183 struct ipaddr
*ip
, zebra_mac_t
*mac
)
2189 n
= zebra_evpn_neigh_lookup(zevpn
, ip
);
2191 n
= zebra_evpn_neigh_add(zevpn
, ip
, &mac
->macaddr
, mac
, 0);
2194 EC_ZEBRA_MAC_ADD_FAILED
,
2195 "Failed to add neighbor %pIA MAC %pEA intf %s(%u) -> VNI %u",
2197 ifp
->name
, ifp
->ifindex
, zevpn
->vni
);
2202 /* Set "local" forwarding info. */
2203 SET_FLAG(n
->flags
, ZEBRA_NEIGH_LOCAL
);
2204 ZEBRA_NEIGH_SET_ACTIVE(n
);
2205 memcpy(&n
->emac
, &mac
->macaddr
, ETH_ALEN
);
2206 n
->ifindex
= ifp
->ifindex
;
2208 /* Only advertise in BGP if the knob is enabled */
2209 if (advertise_gw_macip_enabled(zevpn
)) {
2211 SET_FLAG(mac
->flags
, ZEBRA_MAC_DEF_GW
);
2212 SET_FLAG(n
->flags
, ZEBRA_NEIGH_DEF_GW
);
2213 /* Set Router flag (R-bit) */
2214 if (ip
->ipa_type
== IPADDR_V6
)
2215 SET_FLAG(n
->flags
, ZEBRA_NEIGH_ROUTER_FLAG
);
2217 if (IS_ZEBRA_DEBUG_VXLAN
)
2219 "SVI %s(%u) L2-VNI %u, sending GW MAC %pEA IP %pIA add to BGP with flags 0x%x",
2220 ifp
->name
, ifp
->ifindex
, zevpn
->vni
,
2221 &mac
->macaddr
, ip
, n
->flags
);
2223 zebra_evpn_neigh_send_add_to_client(
2224 zevpn
->vni
, ip
, &n
->emac
, n
->mac
, n
->flags
, n
->loc_seq
);
2225 } else if (advertise_svi_macip_enabled(zevpn
)) {
2227 SET_FLAG(n
->flags
, ZEBRA_NEIGH_SVI_IP
);
2228 if (IS_ZEBRA_DEBUG_VXLAN
)
2230 "SVI %s(%u) L2-VNI %u, sending SVI MAC %pEA IP %pIA add to BGP with flags 0x%x",
2231 ifp
->name
, ifp
->ifindex
, zevpn
->vni
,
2232 &mac
->macaddr
, ip
, n
->flags
);
2234 zebra_evpn_neigh_send_add_to_client(
2235 zevpn
->vni
, ip
, &n
->emac
, n
->mac
, n
->flags
, n
->loc_seq
);
2241 void zebra_evpn_neigh_remote_uninstall(zebra_evpn_t
*zevpn
,
2242 struct zebra_vrf
*zvrf
, zebra_neigh_t
*n
,
2243 zebra_mac_t
*mac
, struct ipaddr
*ipaddr
)
2245 if (zvrf
->dad_freeze
&& CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_DUPLICATE
)
2246 && CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_REMOTE
)
2247 && (memcmp(n
->emac
.octet
, mac
->macaddr
.octet
, ETH_ALEN
) == 0)) {
2248 struct interface
*vlan_if
;
2250 vlan_if
= zevpn_map_to_svi(zevpn
);
2251 if (IS_ZEBRA_DEBUG_VXLAN
)
2253 "%s: IP %pIA (flags 0x%x intf %s) is remote and duplicate, read kernel for local entry",
2254 __func__
, ipaddr
, n
->flags
,
2255 vlan_if
? vlan_if
->name
: "Unknown");
2257 neigh_read_specific_ip(ipaddr
, vlan_if
);
2260 /* When the MAC changes for an IP, it is possible the
2261 * client may update the new MAC before trying to delete the
2262 * "old" neighbor (as these are two different MACIP routes).
2263 * Do the delete only if the MAC matches.
2265 if (!memcmp(n
->emac
.octet
, mac
->macaddr
.octet
, ETH_ALEN
)) {
2266 if (CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_LOCAL
)) {
2267 zebra_evpn_sync_neigh_del(n
);
2268 } else if (CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_REMOTE
)) {
2269 zebra_evpn_neigh_uninstall(zevpn
, n
);
2270 zebra_evpn_neigh_del(zevpn
, n
);
2271 zebra_evpn_deref_ip2mac(zevpn
, mac
);
2276 int zebra_evpn_neigh_del_ip(zebra_evpn_t
*zevpn
, struct ipaddr
*ip
)
2282 struct zebra_vrf
*zvrf
;
2284 /* If entry doesn't exist, nothing to do. */
2285 n
= zebra_evpn_neigh_lookup(zevpn
, ip
);
2289 zmac
= zebra_evpn_mac_lookup(zevpn
, &n
->emac
);
2291 if (IS_ZEBRA_DEBUG_VXLAN
)
2293 "Trying to del a neigh %pIA without a mac %pEA on VNI %u",
2300 /* If it is a remote entry, the kernel has aged this out or someone has
2301 * deleted it, it needs to be re-installed as Quagga is the owner.
2303 if (CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_REMOTE
)) {
2304 zebra_evpn_rem_neigh_install(zevpn
, n
, false /*was_static*/);
2308 /* if this is a sync entry it cannot be dropped re-install it in
2311 old_bgp_ready
= zebra_evpn_neigh_is_ready_for_bgp(n
);
2312 if (zebra_evpn_neigh_is_static(n
)) {
2313 if (IS_ZEBRA_DEBUG_EVPN_MH_NEIGH
)
2314 zlog_debug("re-add sync neigh vni %u ip %pIA mac %pEA 0x%x",
2315 n
->zevpn
->vni
, &n
->ip
, &n
->emac
,
2318 if (!CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_LOCAL_INACTIVE
))
2319 SET_FLAG(n
->flags
, ZEBRA_NEIGH_LOCAL_INACTIVE
);
2320 /* inform-bgp about change in local-activity if any */
2321 new_bgp_ready
= zebra_evpn_neigh_is_ready_for_bgp(n
);
2322 zebra_evpn_neigh_send_add_del_to_client(n
, old_bgp_ready
,
2325 /* re-install the entry in the kernel */
2326 zebra_evpn_sync_neigh_dp_install(n
, false /* set_inactive */,
2327 false /* force_clear_static */,
2333 zvrf
= vrf_info_lookup(zevpn
->vxlan_if
->vrf_id
);
2335 zlog_debug("%s: VNI %u vrf lookup failed.", __func__
,
2340 /* In case of feeze action, if local neigh is in duplicate state,
2341 * Mark the Neigh as inactive before sending delete request to BGPd,
2342 * If BGPd has remote entry, it will re-install
2344 if (zvrf
->dad_freeze
&& CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_DUPLICATE
))
2345 ZEBRA_NEIGH_SET_INACTIVE(n
);
2347 /* Remove neighbor from BGP. */
2348 zebra_evpn_neigh_send_del_to_client(zevpn
->vni
, &n
->ip
, &n
->emac
,
2352 /* Delete this neighbor entry. */
2353 zebra_evpn_neigh_del(zevpn
, n
);
2355 /* see if the AUTO mac needs to be deleted */
2356 if (CHECK_FLAG(zmac
->flags
, ZEBRA_MAC_AUTO
)
2357 && !zebra_evpn_mac_in_use(zmac
))
2358 zebra_evpn_mac_del(zevpn
, zmac
);