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 struct zebra_neigh
*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 struct zebra_neigh
*n1
= p1
;
67 const struct zebra_neigh
*n2
= p2
;
69 if (n1
== NULL
&& n2
== NULL
)
72 if (n1
== NULL
|| n2
== NULL
)
75 return ipaddr_cmp(&n1
->ip
, &n2
->ip
) == 0;
78 int neigh_list_cmp(void *p1
, void *p2
)
80 const struct zebra_neigh
*n1
= p1
;
81 const struct zebra_neigh
*n2
= p2
;
83 return ipaddr_cmp(&n1
->ip
, &n2
->ip
);
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(struct zebra_evpn
*zevpn
)
94 uint32_t num_neighs
= 0;
96 struct hash_bucket
*hb
;
97 struct zebra_neigh
*nbr
;
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
= (struct zebra_neigh
*)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
)
120 struct zebra_neigh
*n
;
121 char buf
[INET6_ADDRSTRLEN
];
122 struct neigh_walk_ctx
*wctx
= ctxt
;
125 n
= (struct zebra_neigh
*)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(struct zebra_mac
*zmac
)
138 struct zebra_neigh
*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(struct zebra_evpn
*zevpn
,
154 struct zebra_neigh
*n
, bool was_static
)
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
)
182 struct zebra_neigh
*n
;
183 struct neigh_walk_ctx
*wctx
= ctxt
;
185 n
= (struct zebra_neigh
*)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 struct zebra_neigh
*tmp_n
= p
;
198 struct zebra_neigh
*n
;
200 n
= XCALLOC(MTYPE_NEIGH
, sizeof(struct zebra_neigh
));
206 static void zebra_evpn_local_neigh_ref_mac(struct zebra_neigh
*n
,
207 const struct ethaddr
*macaddr
,
208 struct zebra_mac
*mac
,
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(struct zebra_neigh
*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
, const struct ipaddr
*ip
,
288 const struct ethaddr
*macaddr
,
289 struct zebra_mac
*zmac
,
290 uint32_t neigh_flags
, uint32_t seq
)
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(struct zebra_neigh
*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(struct zebra_neigh
*n
, bool old_n_static
,
359 bool new_n_static
, bool defer_n_dp
,
360 bool defer_mac_dp
, const char *caller
)
362 struct zebra_mac
*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 void zebra_evpn_neigh_hold_exp_cb(struct thread
*t
)
416 struct zebra_neigh
*n
;
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
,
453 static inline void zebra_evpn_neigh_start_hold_timer(struct zebra_neigh
*n
)
458 if (IS_ZEBRA_DEBUG_EVPN_MH_NEIGH
)
459 zlog_debug("sync-neigh vni %u ip %pIA mac %pEA 0x%x hold start",
460 n
->zevpn
->vni
, &n
->ip
, &n
->emac
, n
->flags
);
461 thread_add_timer(zrouter
.master
, zebra_evpn_neigh_hold_exp_cb
, n
,
462 zmh_info
->neigh_hold_time
, &n
->hold_timer
);
465 static void zebra_evpn_local_neigh_deref_mac(struct zebra_neigh
*n
,
466 bool send_mac_update
)
468 struct zebra_mac
*mac
= n
->mac
;
469 struct zebra_evpn
*zevpn
= n
->zevpn
;
477 if ((n
->flags
& ZEBRA_NEIGH_ALL_PEER_FLAGS
) && mac
->sync_neigh_cnt
) {
478 old_static
= zebra_evpn_mac_is_static(mac
);
479 --mac
->sync_neigh_cnt
;
480 new_static
= zebra_evpn_mac_is_static(mac
);
481 if (IS_ZEBRA_DEBUG_EVPN_MH_NEIGH
)
483 "sync-neigh deref mac vni %u ip %pIA mac %pEA ref %d",
484 n
->zevpn
->vni
, &n
->ip
, &n
->emac
,
485 mac
->sync_neigh_cnt
);
486 if ((old_static
!= new_static
) && send_mac_update
)
487 /* program the local mac in the kernel */
488 zebra_evpn_sync_mac_dp_install(
489 mac
, false /* set_inactive */,
490 false /* force_clear_static */, __func__
);
493 listnode_delete(mac
->neigh_list
, n
);
494 zebra_evpn_deref_ip2mac(zevpn
, mac
);
497 bool zebra_evpn_neigh_is_bgp_seq_ok(struct zebra_evpn
*zevpn
,
498 struct zebra_neigh
*n
,
499 const struct ethaddr
*macaddr
, uint32_t seq
,
505 if (CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_LOCAL
)) {
506 tmp_seq
= n
->loc_seq
;
509 tmp_seq
= n
->rem_seq
;
514 /* if the neigh was never advertised to bgp we must accept
515 * whatever sequence number bgp sends
516 * XXX - check with Vivek
518 if (CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_LOCAL
)
519 && !zebra_evpn_neigh_is_ready_for_bgp(n
)) {
520 if (IS_ZEBRA_DEBUG_EVPN_MH_NEIGH
521 || IS_ZEBRA_DEBUG_VXLAN
)
523 "%s-macip accept vni %u %s mac %pEA IP %pIA lower seq %u f 0x%x",
524 sync
? "sync" : "remote", zevpn
->vni
,
525 n_type
, macaddr
, &n
->ip
,
530 if (IS_ZEBRA_DEBUG_EVPN_MH_NEIGH
|| IS_ZEBRA_DEBUG_VXLAN
)
532 "%s-macip ignore vni %u %s mac %pEA IP %pIA as existing has higher seq %u f 0x%x",
533 sync
? "sync" : "remote", zevpn
->vni
, n_type
,
534 macaddr
, &n
->ip
, tmp_seq
, n
->flags
);
542 * Add neighbor entry.
544 static struct zebra_neigh
*zebra_evpn_neigh_add(struct zebra_evpn
*zevpn
,
545 const struct ipaddr
*ip
,
546 const struct ethaddr
*mac
,
547 struct zebra_mac
*zmac
,
550 struct zebra_neigh tmp_n
;
551 struct zebra_neigh
*n
= NULL
;
553 memset(&tmp_n
, 0, sizeof(tmp_n
));
554 memcpy(&tmp_n
.ip
, ip
, sizeof(struct ipaddr
));
555 n
= hash_get(zevpn
->neigh_table
, &tmp_n
, zebra_evpn_neigh_alloc
);
557 n
->state
= ZEBRA_NEIGH_INACTIVE
;
559 n
->dad_ip_auto_recovery_timer
= NULL
;
561 n
->uptime
= monotime(NULL
);
564 zmac
= zebra_evpn_mac_lookup(zevpn
, mac
);
565 zebra_evpn_local_neigh_ref_mac(n
, mac
, zmac
,
566 false /* send_mac_update */);
572 * Delete neighbor entry.
574 int zebra_evpn_neigh_del(struct zebra_evpn
*zevpn
, struct zebra_neigh
*n
)
576 struct zebra_neigh
*tmp_n
;
579 listnode_delete(n
->mac
->neigh_list
, n
);
581 /* Cancel auto recovery */
582 THREAD_OFF(n
->dad_ip_auto_recovery_timer
);
584 /* Cancel proxy hold timer */
585 zebra_evpn_neigh_stop_hold_timer(n
);
587 /* Free the VNI hash entry and allocated memory. */
588 tmp_n
= hash_release(zevpn
->neigh_table
, n
);
589 XFREE(MTYPE_NEIGH
, tmp_n
);
594 void zebra_evpn_sync_neigh_del(struct zebra_neigh
*n
)
599 if (IS_ZEBRA_DEBUG_EVPN_MH_NEIGH
)
600 zlog_debug("sync-neigh del vni %u ip %pIA mac %pEA f 0x%x",
601 n
->zevpn
->vni
, &n
->ip
, &n
->emac
, n
->flags
);
603 old_n_static
= zebra_evpn_neigh_is_static(n
);
604 UNSET_FLAG(n
->flags
, ZEBRA_NEIGH_ES_PEER_PROXY
);
605 if (CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_ES_PEER_ACTIVE
))
606 zebra_evpn_neigh_start_hold_timer(n
);
607 new_n_static
= zebra_evpn_neigh_is_static(n
);
609 if (old_n_static
!= new_n_static
)
610 zebra_evpn_sync_neigh_static_chg(
611 n
, old_n_static
, new_n_static
, false /*defer-dp*/,
612 false /*defer_mac_dp*/, __func__
);
615 struct zebra_neigh
*zebra_evpn_proc_sync_neigh_update(
616 struct zebra_evpn
*zevpn
, struct zebra_neigh
*n
, uint16_t ipa_len
,
617 const struct ipaddr
*ipaddr
, uint8_t flags
, uint32_t seq
,
618 const esi_t
*esi
, struct sync_mac_ip_ctx
*ctx
)
620 struct interface
*ifp
= NULL
;
622 struct zebra_mac
*mac
= ctx
->mac
;
624 bool old_router
= false;
625 bool old_bgp_ready
= false;
627 bool inform_dataplane
= false;
628 bool inform_bgp
= false;
631 bool set_dp_inactive
= false;
633 ifindex_t ifindex
= 0;
636 ifp
= zevpn_map_to_svi(zevpn
);
638 ifindex
= ifp
->ifindex
;
640 is_router
= !!CHECK_FLAG(flags
, ZEBRA_MACIP_TYPE_ROUTER_FLAG
);
641 old_mac_static
= zebra_evpn_mac_is_static(mac
);
644 uint32_t n_flags
= 0;
646 /* New neighbor - create */
647 SET_FLAG(n_flags
, ZEBRA_NEIGH_LOCAL
);
648 if (CHECK_FLAG(flags
, ZEBRA_MACIP_TYPE_PROXY_ADVERT
))
649 SET_FLAG(n_flags
, ZEBRA_NEIGH_ES_PEER_PROXY
);
651 SET_FLAG(n_flags
, ZEBRA_NEIGH_ES_PEER_ACTIVE
);
652 SET_FLAG(n_flags
, ZEBRA_NEIGH_LOCAL_INACTIVE
);
654 n
= zebra_evpn_neigh_add(zevpn
, ipaddr
, &mac
->macaddr
, mac
,
656 n
->ifindex
= ifindex
;
657 ZEBRA_NEIGH_SET_ACTIVE(n
);
660 inform_dataplane
= true;
662 set_dp_inactive
= true;
665 uint32_t old_flags
= n
->flags
;
670 old_n_static
= zebra_evpn_neigh_is_static(n
);
671 old_bgp_ready
= zebra_evpn_neigh_is_ready_for_bgp(n
);
672 old_router
= !!CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_ROUTER_FLAG
);
674 mac_change
= !!memcmp(&n
->emac
, &mac
->macaddr
, ETH_ALEN
);
676 /* deref and clear old info */
679 zebra_evpn_neigh_send_del_to_client(
680 zevpn
->vni
, &n
->ip
, &n
->emac
, n
->flags
,
681 n
->state
, false /*force*/);
682 old_bgp_ready
= false;
684 zebra_evpn_local_neigh_deref_mac(n
,
685 false /*send_mac_update*/);
687 /* clear old fwd info */
689 n
->r_vtep_ip
.s_addr
= 0;
691 /* setup new flags */
693 SET_FLAG(n
->flags
, ZEBRA_NEIGH_LOCAL
);
694 /* retain activity flag if the neigh was
697 if (old_flags
& ZEBRA_NEIGH_LOCAL
) {
698 n
->flags
|= (old_flags
& ZEBRA_NEIGH_LOCAL_INACTIVE
);
700 inform_dataplane
= true;
701 set_dp_inactive
= true;
702 n
->flags
|= ZEBRA_NEIGH_LOCAL_INACTIVE
;
705 if (CHECK_FLAG(flags
, ZEBRA_MACIP_TYPE_PROXY_ADVERT
))
706 SET_FLAG(n
->flags
, ZEBRA_NEIGH_ES_PEER_PROXY
);
708 SET_FLAG(n
->flags
, ZEBRA_NEIGH_ES_PEER_ACTIVE
);
710 if (CHECK_FLAG(flags
, ZEBRA_MACIP_TYPE_PROXY_ADVERT
)) {
711 SET_FLAG(n
->flags
, ZEBRA_NEIGH_ES_PEER_PROXY
);
712 /* if the neigh was peer-active previously we
713 * need to keep the flag and start the
714 * holdtimer on it. the peer-active flag is
715 * cleared on holdtimer expiry.
717 if (CHECK_FLAG(old_flags
, ZEBRA_NEIGH_ES_PEER_ACTIVE
)) {
718 SET_FLAG(n
->flags
, ZEBRA_NEIGH_ES_PEER_ACTIVE
);
719 zebra_evpn_neigh_start_hold_timer(n
);
722 SET_FLAG(n
->flags
, ZEBRA_NEIGH_ES_PEER_ACTIVE
);
723 /* stop hold timer if a peer has verified
726 zebra_evpn_neigh_stop_hold_timer(n
);
728 ZEBRA_NEIGH_SET_ACTIVE(n
);
730 if (IS_ZEBRA_DEBUG_EVPN_MH_NEIGH
&& (old_flags
!= n
->flags
))
732 "sync-neigh vni %u ip %pIA mac %pEA old_f 0x%x new_f 0x%x",
733 n
->zevpn
->vni
, &n
->ip
, &n
->emac
,
734 old_flags
, n
->flags
);
736 new_n_static
= zebra_evpn_neigh_is_static(n
);
738 set_dp_inactive
= true;
739 n
->flags
|= ZEBRA_NEIGH_LOCAL_INACTIVE
;
740 inform_dataplane
= true;
741 zebra_evpn_local_neigh_ref_mac(
742 n
, &mac
->macaddr
, mac
,
743 false /*send_mac_update*/);
744 } else if (old_n_static
!= new_n_static
) {
745 inform_dataplane
= true;
746 /* if static flags have changed without a mac change
747 * we need to create the correct sync-refs against
750 zebra_evpn_sync_neigh_static_chg(
751 n
, old_n_static
, new_n_static
,
752 true /*defer_dp*/, true /*defer_mac_dp*/,
756 /* Update the forwarding info. */
757 if (n
->ifindex
!= ifindex
) {
758 n
->ifindex
= ifindex
;
759 inform_dataplane
= true;
762 n
->uptime
= monotime(NULL
);
765 /* update the neigh seq. we don't bother with the mac seq as
766 * sync_mac_update already took care of that
768 tmp_seq
= MAX(n
->loc_seq
, seq
);
769 if (tmp_seq
!= n
->loc_seq
) {
770 n
->loc_seq
= tmp_seq
;
774 /* Mark Router flag (R-bit) */
776 SET_FLAG(n
->flags
, ZEBRA_NEIGH_ROUTER_FLAG
);
778 UNSET_FLAG(n
->flags
, ZEBRA_NEIGH_ROUTER_FLAG
);
780 if (old_router
!= is_router
)
781 inform_dataplane
= true;
783 new_bgp_ready
= zebra_evpn_neigh_is_ready_for_bgp(n
);
784 if (old_bgp_ready
!= new_bgp_ready
)
787 new_mac_static
= zebra_evpn_mac_is_static(mac
);
788 if ((old_mac_static
!= new_mac_static
) || ctx
->mac_dp_update_deferred
)
789 zebra_evpn_sync_mac_dp_install(mac
, ctx
->mac_inactive
,
790 false /* force_clear_static */,
793 if (IS_ZEBRA_DEBUG_EVPN_MH_NEIGH
)
795 "sync-neigh %s vni %u ip %pIA mac %pEA if %s(%d) seq %d f 0x%x%s%s",
796 created
? "created" : "updated", n
->zevpn
->vni
,
798 ifp
? ifp
->name
: "", ifindex
, n
->loc_seq
, n
->flags
,
799 inform_bgp
? " inform_bgp" : "",
800 inform_dataplane
? " inform_dp" : "");
802 if (inform_dataplane
)
803 zebra_evpn_sync_neigh_dp_install(n
, set_dp_inactive
,
804 false /* force_clear_static */,
808 zebra_evpn_neigh_send_add_del_to_client(n
, old_bgp_ready
,
815 * Uninstall remote neighbor from the kernel.
817 static int zebra_evpn_neigh_uninstall(struct zebra_evpn
*zevpn
,
818 struct zebra_neigh
*n
)
820 struct interface
*vlan_if
;
822 if (!(n
->flags
& ZEBRA_NEIGH_REMOTE
))
825 vlan_if
= zevpn_map_to_svi(zevpn
);
829 ZEBRA_NEIGH_SET_INACTIVE(n
);
832 dplane_rem_neigh_delete(vlan_if
, &n
->ip
);
838 * Free neighbor hash entry (callback)
840 static void zebra_evpn_neigh_del_hash_entry(struct hash_bucket
*bucket
,
843 struct neigh_walk_ctx
*wctx
= arg
;
844 struct zebra_neigh
*n
= bucket
->data
;
846 if (((wctx
->flags
& DEL_LOCAL_NEIGH
) && (n
->flags
& ZEBRA_NEIGH_LOCAL
))
847 || ((wctx
->flags
& DEL_REMOTE_NEIGH
)
848 && (n
->flags
& ZEBRA_NEIGH_REMOTE
))
849 || ((wctx
->flags
& DEL_REMOTE_NEIGH_FROM_VTEP
)
850 && (n
->flags
& ZEBRA_NEIGH_REMOTE
)
851 && IPV4_ADDR_SAME(&n
->r_vtep_ip
, &wctx
->r_vtep_ip
))) {
852 if (wctx
->upd_client
&& (n
->flags
& ZEBRA_NEIGH_LOCAL
))
853 zebra_evpn_neigh_send_del_to_client(
854 wctx
->zevpn
->vni
, &n
->ip
, &n
->emac
, n
->flags
,
855 n
->state
, false /*force*/);
857 if (wctx
->uninstall
) {
858 if (zebra_evpn_neigh_is_static(n
))
859 zebra_evpn_sync_neigh_dp_install(
860 n
, false /* set_inactive */,
861 true /* force_clear_static */,
863 if ((n
->flags
& ZEBRA_NEIGH_REMOTE
))
864 zebra_evpn_neigh_uninstall(wctx
->zevpn
, n
);
867 zebra_evpn_neigh_del(wctx
->zevpn
, n
);
874 * Delete all neighbor entries for this EVPN.
876 void zebra_evpn_neigh_del_all(struct zebra_evpn
*zevpn
, int uninstall
,
877 int upd_client
, uint32_t flags
)
879 struct neigh_walk_ctx wctx
;
881 if (!zevpn
->neigh_table
)
884 memset(&wctx
, 0, sizeof(wctx
));
886 wctx
.uninstall
= uninstall
;
887 wctx
.upd_client
= upd_client
;
890 hash_iterate(zevpn
->neigh_table
, zebra_evpn_neigh_del_hash_entry
,
895 * Look up neighbor hash entry.
897 struct zebra_neigh
*zebra_evpn_neigh_lookup(struct zebra_evpn
*zevpn
,
898 const struct ipaddr
*ip
)
900 struct zebra_neigh tmp
;
901 struct zebra_neigh
*n
;
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(struct zebra_evpn
*zevpn
,
915 struct zebra_mac
*zmac
,
919 struct zebra_neigh
*n
= NULL
;
920 struct listnode
*node
= NULL
;
921 struct zebra_vrf
*zvrf
= NULL
;
923 zvrf
= zevpn
->vxlan_if
->vrf
->info
;
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(struct zebra_evpn
*zevpn
,
959 struct zebra_mac
*zmac
)
961 struct zebra_neigh
*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(struct zebra_evpn
*zevpn
,
992 struct zebra_mac
*zmac
)
994 struct zebra_neigh
*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(struct zebra_evpn
*zevpn
,
1022 struct zebra_mac
*zmac
)
1024 /* NOTE: Currently a NO-OP. */
1027 static inline void zebra_evpn_local_neigh_update_log(
1028 const char *pfx
, struct zebra_neigh
*n
, bool is_router
,
1029 bool local_inactive
, bool old_bgp_ready
, bool new_bgp_ready
,
1030 bool inform_dataplane
, 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 struct zebra_mac
*old_zmac
,
1051 struct zebra_mac
*new_zmac
,
1052 struct zebra_neigh
*nbr
)
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 void zebra_evpn_dad_ip_auto_recovery_exp(struct thread
*t
)
1094 struct zebra_vrf
*zvrf
= NULL
;
1095 struct zebra_neigh
*nbr
= NULL
;
1096 struct zebra_evpn
*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*/);
1137 static void zebra_evpn_dup_addr_detect_for_neigh(
1138 struct zebra_vrf
*zvrf
, struct zebra_neigh
*nbr
, struct in_addr vtep_ip
,
1139 bool do_dad
, bool *is_dup_detect
, bool is_local
)
1142 struct timeval elapsed
= {0, 0};
1143 bool reset_params
= false;
1145 if (!zebra_evpn_do_dup_addr_detect(zvrf
))
1148 /* IP is detected as duplicate or inherit dup
1149 * state, hold on to install as remote entry
1150 * only if freeze is enabled.
1152 if (CHECK_FLAG(nbr
->flags
, ZEBRA_NEIGH_DUPLICATE
)) {
1153 if (IS_ZEBRA_DEBUG_VXLAN
)
1155 "%s: duplicate addr MAC %pEA IP %pIA flags 0x%x skip installing, learn count %u recover time %u",
1156 __func__
, &nbr
->emac
, &nbr
->ip
,
1157 nbr
->flags
, nbr
->dad_count
,
1158 zvrf
->dad_freeze_time
);
1160 if (zvrf
->dad_freeze
)
1161 *is_dup_detect
= true;
1163 /* warn-only action, neigh will be installed.
1164 * freeze action, it wil not be installed.
1172 /* Check if detection time (M-secs) expired.
1173 * Reset learn count and detection start time.
1174 * During remote mac add, count should already be 1
1175 * via local learning.
1177 monotime_since(&nbr
->detect_start_time
, &elapsed
);
1178 reset_params
= (elapsed
.tv_sec
> zvrf
->dad_time
);
1180 if (is_local
&& !reset_params
) {
1181 /* RFC-7432: A PE/VTEP that detects a MAC mobility
1182 * event via LOCAL learning starts an M-second timer.
1184 * NOTE: This is the START of the probe with count is
1185 * 0 during LOCAL learn event.
1187 reset_params
= !nbr
->dad_count
;
1191 if (IS_ZEBRA_DEBUG_VXLAN
)
1193 "%s: duplicate addr MAC %pEA IP %pIA flags 0x%x detection time passed, reset learn count %u",
1194 __func__
, &nbr
->emac
, &nbr
->ip
,
1195 nbr
->flags
, nbr
->dad_count
);
1196 /* Reset learn count but do not start detection
1197 * during REMOTE learn event.
1200 /* Start dup. addr detection (DAD) start time,
1201 * ONLY during LOCAL learn.
1204 monotime(&nbr
->detect_start_time
);
1206 } else if (!is_local
) {
1207 /* For REMOTE IP/Neigh, increment detection count
1208 * ONLY while in probe window, once window passed,
1209 * next local learn event should trigger DAD.
1214 /* For LOCAL IP/Neigh learn event, once count is reset above via either
1215 * initial/start detection time or passed the probe time, the count
1216 * needs to be incremented.
1221 if (nbr
->dad_count
>= zvrf
->dad_max_moves
) {
1223 EC_ZEBRA_DUP_IP_DETECTED
,
1224 "VNI %u: MAC %pEA IP %pIA detected as duplicate during %s VTEP %pI4",
1225 nbr
->zevpn
->vni
, &nbr
->emac
, &nbr
->ip
,
1226 is_local
? "local update, last" : "remote update, from",
1229 SET_FLAG(nbr
->flags
, ZEBRA_NEIGH_DUPLICATE
);
1231 /* Capture Duplicate detection time */
1232 nbr
->dad_dup_detect_time
= monotime(NULL
);
1234 /* Start auto recovery timer for this IP */
1235 THREAD_OFF(nbr
->dad_ip_auto_recovery_timer
);
1236 if (zvrf
->dad_freeze
&& zvrf
->dad_freeze_time
) {
1237 if (IS_ZEBRA_DEBUG_VXLAN
)
1239 "%s: duplicate addr MAC %pEA IP %pIA flags 0x%x auto recovery time %u start",
1240 __func__
, &nbr
->emac
, &nbr
->ip
,
1241 nbr
->flags
, zvrf
->dad_freeze_time
);
1243 thread_add_timer(zrouter
.master
,
1244 zebra_evpn_dad_ip_auto_recovery_exp
,
1245 nbr
, zvrf
->dad_freeze_time
,
1246 &nbr
->dad_ip_auto_recovery_timer
);
1248 if (zvrf
->dad_freeze
)
1249 *is_dup_detect
= true;
1253 int zebra_evpn_local_neigh_update(struct zebra_evpn
*zevpn
,
1254 struct interface
*ifp
,
1255 const struct ipaddr
*ip
,
1256 const struct ethaddr
*macaddr
, bool is_router
,
1257 bool local_inactive
, bool dp_static
)
1259 struct zebra_vrf
*zvrf
;
1260 struct zebra_neigh
*n
= NULL
;
1261 struct zebra_mac
*zmac
= NULL
, *old_zmac
= NULL
;
1262 uint32_t old_mac_seq
= 0, mac_new_seq
= 0;
1263 bool upd_mac_seq
= false;
1264 bool neigh_mac_change
= false;
1265 bool neigh_on_hold
= false;
1266 bool neigh_was_remote
= false;
1267 bool do_dad
= false;
1268 struct in_addr vtep_ip
= {.s_addr
= 0};
1269 bool inform_dataplane
= false;
1270 bool created
= false;
1271 bool new_static
= false;
1272 bool old_bgp_ready
= false;
1275 /* Check if the MAC exists. */
1276 zmac
= zebra_evpn_mac_lookup(zevpn
, macaddr
);
1278 /* create a dummy MAC if the MAC is not already present */
1279 if (IS_ZEBRA_DEBUG_VXLAN
)
1280 zlog_debug("AUTO MAC %pEA created for neigh %pIA on VNI %u",
1281 macaddr
, ip
, zevpn
->vni
);
1283 zmac
= zebra_evpn_mac_add(zevpn
, macaddr
);
1284 zebra_evpn_mac_clear_fwd_info(zmac
);
1285 memset(&zmac
->flags
, 0, sizeof(uint32_t));
1286 SET_FLAG(zmac
->flags
, ZEBRA_MAC_AUTO
);
1288 if (CHECK_FLAG(zmac
->flags
, ZEBRA_MAC_REMOTE
)) {
1290 * We don't change the MAC to local upon a neighbor
1291 * learn event, we wait for the explicit local MAC
1292 * learn. However, we have to compute its sequence
1293 * number in preparation for when it actually turns
1300 zvrf
= zevpn
->vxlan_if
->vrf
->info
;
1302 if (IS_ZEBRA_DEBUG_VXLAN
)
1303 zlog_debug(" Unable to find vrf for: %d",
1304 zevpn
->vxlan_if
->vrf
->vrf_id
);
1308 /* Check if the neighbor exists. */
1309 n
= zebra_evpn_neigh_lookup(zevpn
, ip
);
1311 /* New neighbor - create */
1312 n
= zebra_evpn_neigh_add(zevpn
, ip
, macaddr
, zmac
, 0);
1314 /* Set "local" forwarding info. */
1315 SET_FLAG(n
->flags
, ZEBRA_NEIGH_LOCAL
);
1316 n
->ifindex
= ifp
->ifindex
;
1319 if (CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_LOCAL
)) {
1322 bool old_local_inactive
;
1324 old_local_inactive
= !!CHECK_FLAG(
1325 n
->flags
, ZEBRA_NEIGH_LOCAL_INACTIVE
);
1327 old_bgp_ready
= zebra_evpn_neigh_is_ready_for_bgp(n
);
1329 /* Note any changes and see if of interest to BGP. */
1330 mac_different
= !!memcmp(&n
->emac
, macaddr
, ETH_ALEN
);
1332 !!CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_ROUTER_FLAG
);
1333 new_static
= zebra_evpn_neigh_is_static(n
);
1334 if (!mac_different
&& is_router
== cur_is_router
1335 && old_local_inactive
== local_inactive
1336 && dp_static
!= new_static
) {
1337 if (IS_ZEBRA_DEBUG_VXLAN
)
1339 " Ignoring entry mac is the same and is_router == cur_is_router");
1340 n
->ifindex
= ifp
->ifindex
;
1345 if (!mac_different
) {
1346 /* XXX - cleanup this code duplication */
1347 bool is_neigh_freezed
= false;
1349 /* Only the router flag has changed. */
1352 ZEBRA_NEIGH_ROUTER_FLAG
);
1354 UNSET_FLAG(n
->flags
,
1355 ZEBRA_NEIGH_ROUTER_FLAG
);
1359 ZEBRA_NEIGH_LOCAL_INACTIVE
);
1361 UNSET_FLAG(n
->flags
,
1362 ZEBRA_NEIGH_LOCAL_INACTIVE
);
1364 zebra_evpn_neigh_is_ready_for_bgp(n
);
1366 if (dp_static
!= new_static
)
1367 inform_dataplane
= true;
1369 /* Neigh is in freeze state and freeze action
1370 * is enabled, do not send update to client.
1373 (zebra_evpn_do_dup_addr_detect(zvrf
)
1375 && CHECK_FLAG(n
->flags
,
1376 ZEBRA_NEIGH_DUPLICATE
));
1378 zebra_evpn_local_neigh_update_log(
1379 "local", n
, is_router
, local_inactive
,
1380 old_bgp_ready
, new_bgp_ready
, false,
1381 false, "flag-update");
1383 if (inform_dataplane
)
1384 zebra_evpn_sync_neigh_dp_install(
1385 n
, false /* set_inactive */,
1386 false /* force_clear_static */,
1389 /* if the neigh can no longer be advertised
1390 * remove it from bgp
1392 if (!is_neigh_freezed
) {
1393 zebra_evpn_neigh_send_add_del_to_client(
1397 if (IS_ZEBRA_DEBUG_VXLAN
1398 && IS_ZEBRA_NEIGH_ACTIVE(n
))
1400 " Neighbor active and frozen");
1405 /* The MAC has changed, need to issue a delete
1406 * first as this means a different MACIP route.
1407 * Also, need to do some unlinking/relinking.
1408 * We also need to update the MAC's sequence number
1409 * in different situations.
1411 if (old_bgp_ready
) {
1412 zebra_evpn_neigh_send_del_to_client(
1413 zevpn
->vni
, &n
->ip
, &n
->emac
, n
->flags
,
1414 n
->state
, false /*force*/);
1415 old_bgp_ready
= false;
1418 old_mac_seq
= CHECK_FLAG(old_zmac
->flags
,
1421 : old_zmac
->loc_seq
;
1422 neigh_mac_change
= upd_mac_seq
= true;
1423 zebra_evpn_local_neigh_deref_mac(
1424 n
, true /* send_mac_update */);
1427 /* if mac changes abandon peer flags and tell
1428 * dataplane to clear the static flag
1430 if (zebra_evpn_neigh_clear_sync_info(n
))
1431 inform_dataplane
= true;
1432 /* Update the forwarding info. */
1433 n
->ifindex
= ifp
->ifindex
;
1435 /* Link to new MAC */
1436 zebra_evpn_local_neigh_ref_mac(
1437 n
, macaddr
, zmac
, true /* send_mac_update */);
1438 } else if (CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_REMOTE
)) {
1440 * Neighbor has moved from remote to local. Its
1441 * MAC could have also changed as part of the move.
1443 if (memcmp(n
->emac
.octet
, macaddr
->octet
, ETH_ALEN
)
1448 CHECK_FLAG(old_zmac
->flags
,
1451 : old_zmac
->loc_seq
;
1452 neigh_mac_change
= upd_mac_seq
= true;
1453 zebra_evpn_local_neigh_deref_mac(
1454 n
, true /* send_update */);
1457 /* Link to new MAC */
1458 zebra_evpn_local_neigh_ref_mac(
1459 n
, macaddr
, zmac
, true /*send_update*/);
1461 /* Based on Mobility event Scenario-B from the
1462 * draft, neigh's previous state was remote treat this
1465 neigh_was_remote
= true;
1466 vtep_ip
= n
->r_vtep_ip
;
1467 /* Mark appropriately */
1468 UNSET_FLAG(n
->flags
, ZEBRA_NEIGH_REMOTE
);
1469 n
->r_vtep_ip
.s_addr
= INADDR_ANY
;
1470 SET_FLAG(n
->flags
, ZEBRA_NEIGH_LOCAL
);
1471 n
->ifindex
= ifp
->ifindex
;
1475 /* If MAC was previously remote, or the neighbor had a different
1476 * MAC earlier, recompute the sequence number.
1479 uint32_t seq1
, seq2
;
1481 seq1
= CHECK_FLAG(zmac
->flags
, ZEBRA_MAC_REMOTE
)
1484 seq2
= neigh_mac_change
? old_mac_seq
+ 1 : 0;
1485 mac_new_seq
= zmac
->loc_seq
< MAX(seq1
, seq2
) ? MAX(seq1
, seq2
)
1490 SET_FLAG(n
->flags
, ZEBRA_NEIGH_LOCAL_INACTIVE
);
1492 UNSET_FLAG(n
->flags
, ZEBRA_NEIGH_LOCAL_INACTIVE
);
1494 /* Mark Router flag (R-bit) */
1496 SET_FLAG(n
->flags
, ZEBRA_NEIGH_ROUTER_FLAG
);
1498 UNSET_FLAG(n
->flags
, ZEBRA_NEIGH_ROUTER_FLAG
);
1500 /* if zebra and dataplane don't agree this is a sync entry
1501 * re-install in the dataplane */
1502 new_static
= zebra_evpn_neigh_is_static(n
);
1503 if (dp_static
!= new_static
)
1504 inform_dataplane
= true;
1506 /* Check old and/or new MAC detected as duplicate mark
1507 * the neigh as duplicate
1509 if (zebra_evpn_ip_inherit_dad_from_mac(zvrf
, old_zmac
, zmac
, n
)) {
1511 EC_ZEBRA_DUP_IP_INHERIT_DETECTED
,
1512 "VNI %u: MAC %pEA IP %pIA detected as duplicate during local update, inherit duplicate from MAC",
1513 zevpn
->vni
, macaddr
, &n
->ip
);
1516 /* For IP Duplicate Address Detection (DAD) is trigger,
1517 * when the event is extended mobility based on scenario-B
1518 * from the draft, IP/Neigh's MAC binding changed and
1519 * neigh's previous state was remote.
1521 if (neigh_mac_change
&& neigh_was_remote
)
1524 zebra_evpn_dup_addr_detect_for_neigh(zvrf
, n
, vtep_ip
, do_dad
,
1525 &neigh_on_hold
, true);
1527 if (inform_dataplane
)
1528 zebra_evpn_sync_neigh_dp_install(n
, false /* set_inactive */,
1529 false /* force_clear_static */,
1532 /* Before we program this in BGP, we need to check if MAC is locally
1533 * learnt. If not, force neighbor to be inactive and reset its seq.
1535 if (!CHECK_FLAG(zmac
->flags
, ZEBRA_MAC_LOCAL
)) {
1536 zebra_evpn_local_neigh_update_log(
1537 "local", n
, is_router
, local_inactive
, false, false,
1538 inform_dataplane
, false, "auto-mac");
1539 ZEBRA_NEIGH_SET_INACTIVE(n
);
1541 zmac
->loc_seq
= mac_new_seq
;
1545 zebra_evpn_local_neigh_update_log("local", n
, is_router
, local_inactive
,
1546 false, false, inform_dataplane
, true,
1547 created
? "created" : "updated");
1549 /* If the MAC's sequence number has changed, inform the MAC and all
1550 * neighbors associated with the MAC to BGP, else just inform this
1553 if (upd_mac_seq
&& zmac
->loc_seq
!= mac_new_seq
) {
1554 if (IS_ZEBRA_DEBUG_VXLAN
)
1556 "Seq changed for MAC %pEA VNI %u - old %u new %u",
1557 macaddr
, zevpn
->vni
,
1558 zmac
->loc_seq
, mac_new_seq
);
1559 zmac
->loc_seq
= mac_new_seq
;
1560 if (zebra_evpn_mac_send_add_to_client(zevpn
->vni
, macaddr
,
1562 zmac
->loc_seq
, zmac
->es
))
1564 zebra_evpn_process_neigh_on_local_mac_change(zevpn
, zmac
, 1,
1569 n
->loc_seq
= zmac
->loc_seq
;
1571 if (!neigh_on_hold
) {
1572 ZEBRA_NEIGH_SET_ACTIVE(n
);
1573 new_bgp_ready
= zebra_evpn_neigh_is_ready_for_bgp(n
);
1574 zebra_evpn_neigh_send_add_del_to_client(n
, old_bgp_ready
,
1577 if (IS_ZEBRA_DEBUG_VXLAN
)
1578 zlog_debug(" Neighbor on hold not sending");
1583 int zebra_evpn_remote_neigh_update(struct zebra_evpn
*zevpn
,
1584 struct interface
*ifp
,
1585 const struct ipaddr
*ip
,
1586 const struct ethaddr
*macaddr
,
1589 struct zebra_neigh
*n
= NULL
;
1590 struct zebra_mac
*zmac
= NULL
;
1592 /* If the neighbor is unknown, there is no further action. */
1593 n
= zebra_evpn_neigh_lookup(zevpn
, ip
);
1597 /* If a remote entry, see if it needs to be refreshed */
1598 if (CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_REMOTE
)) {
1600 if (state
& NUD_STALE
)
1601 zebra_evpn_rem_neigh_install(zevpn
, n
,
1602 false /*was_static*/);
1605 /* We got a "remote" neighbor notification for an entry
1606 * we think is local. This can happen in a multihoming
1607 * scenario - but only if the MAC is already "remote".
1608 * Just mark our entry as "remote".
1610 zmac
= zebra_evpn_mac_lookup(zevpn
, macaddr
);
1611 if (!zmac
|| !CHECK_FLAG(zmac
->flags
, ZEBRA_MAC_REMOTE
)) {
1613 "Ignore remote neigh %pIA (MAC %pEA) on L2-VNI %u - MAC unknown or local",
1614 &n
->ip
, macaddr
, zevpn
->vni
);
1618 UNSET_FLAG(n
->flags
, ZEBRA_NEIGH_ALL_LOCAL_FLAGS
);
1619 SET_FLAG(n
->flags
, ZEBRA_NEIGH_REMOTE
);
1620 ZEBRA_NEIGH_SET_ACTIVE(n
);
1621 n
->r_vtep_ip
= zmac
->fwd_info
.r_vtep_ip
;
1627 /* Notify Neighbor entries to the Client, skips the GW entry */
1629 zebra_evpn_send_neigh_hash_entry_to_client(struct hash_bucket
*bucket
,
1632 struct mac_walk_ctx
*wctx
= arg
;
1633 struct zebra_neigh
*zn
= bucket
->data
;
1634 struct zebra_mac
*zmac
= NULL
;
1636 if (CHECK_FLAG(zn
->flags
, ZEBRA_NEIGH_DEF_GW
))
1639 if (CHECK_FLAG(zn
->flags
, ZEBRA_NEIGH_LOCAL
)
1640 && IS_ZEBRA_NEIGH_ACTIVE(zn
)) {
1641 zmac
= zebra_evpn_mac_lookup(wctx
->zevpn
, &zn
->emac
);
1645 zebra_evpn_neigh_send_add_to_client(wctx
->zevpn
->vni
, &zn
->ip
,
1647 zn
->flags
, zn
->loc_seq
);
1651 /* Iterator of a specific EVPN */
1652 void zebra_evpn_send_neigh_to_client(struct zebra_evpn
*zevpn
)
1654 struct neigh_walk_ctx wctx
;
1656 memset(&wctx
, 0, sizeof(wctx
));
1659 hash_iterate(zevpn
->neigh_table
,
1660 zebra_evpn_send_neigh_hash_entry_to_client
, &wctx
);
1663 void zebra_evpn_clear_dup_neigh_hash(struct hash_bucket
*bucket
, void *ctxt
)
1665 struct neigh_walk_ctx
*wctx
= ctxt
;
1666 struct zebra_neigh
*nbr
;
1667 struct zebra_evpn
*zevpn
;
1668 char buf
[INET6_ADDRSTRLEN
];
1670 nbr
= (struct zebra_neigh
*)bucket
->data
;
1674 zevpn
= wctx
->zevpn
;
1676 if (!CHECK_FLAG(nbr
->flags
, ZEBRA_NEIGH_DUPLICATE
))
1679 if (IS_ZEBRA_DEBUG_VXLAN
) {
1680 ipaddr2str(&nbr
->ip
, buf
, sizeof(buf
));
1681 zlog_debug("%s: clear neigh %s dup state, flags 0x%x seq %u",
1682 __func__
, buf
, nbr
->flags
, nbr
->loc_seq
);
1685 UNSET_FLAG(nbr
->flags
, ZEBRA_NEIGH_DUPLICATE
);
1687 nbr
->detect_start_time
.tv_sec
= 0;
1688 nbr
->detect_start_time
.tv_usec
= 0;
1689 nbr
->dad_dup_detect_time
= 0;
1690 THREAD_OFF(nbr
->dad_ip_auto_recovery_timer
);
1692 if (CHECK_FLAG(nbr
->flags
, ZEBRA_NEIGH_LOCAL
)) {
1693 zebra_evpn_neigh_send_add_to_client(zevpn
->vni
, &nbr
->ip
,
1694 &nbr
->emac
, nbr
->mac
,
1695 nbr
->flags
, nbr
->loc_seq
);
1696 } else if (CHECK_FLAG(nbr
->flags
, ZEBRA_NEIGH_REMOTE
)) {
1697 zebra_evpn_rem_neigh_install(zevpn
, nbr
, false /*was_static*/);
1702 * Print a specific neighbor entry.
1704 void zebra_evpn_print_neigh(struct zebra_neigh
*n
, void *ctxt
,
1708 char buf1
[ETHER_ADDR_STRLEN
];
1709 char buf2
[INET6_ADDRSTRLEN
];
1710 const char *type_str
;
1711 const char *state_str
;
1712 bool flags_present
= false;
1713 struct zebra_vrf
*zvrf
= NULL
;
1714 struct timeval detect_start_time
= {0, 0};
1715 char timebuf
[MONOTIME_STRLEN
];
1716 char thread_buf
[THREAD_TIMER_STRLEN
];
1718 char up_str
[MONOTIME_STRLEN
];
1720 zvrf
= zebra_vrf_get_evpn();
1721 uptime
= monotime(NULL
);
1722 uptime
-= n
->uptime
;
1724 frrtime_to_interval(uptime
, up_str
, sizeof(up_str
));
1726 ipaddr2str(&n
->ip
, buf2
, sizeof(buf2
));
1727 prefix_mac2str(&n
->emac
, buf1
, sizeof(buf1
));
1728 type_str
= CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_LOCAL
) ? "local" : "remote";
1729 state_str
= IS_ZEBRA_NEIGH_ACTIVE(n
) ? "active" : "inactive";
1730 vty
= (struct vty
*)ctxt
;
1732 bool sync_info
= false;
1734 vty_out(vty
, "IP: %s\n",
1735 ipaddr2str(&n
->ip
, buf2
, sizeof(buf2
)));
1736 vty_out(vty
, " Type: %s\n", type_str
);
1737 vty_out(vty
, " State: %s\n", state_str
);
1738 vty_out(vty
, " Uptime: %s\n", up_str
);
1739 vty_out(vty
, " MAC: %s\n",
1740 prefix_mac2str(&n
->emac
, buf1
, sizeof(buf1
)));
1741 vty_out(vty
, " Sync-info:");
1742 if (CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_LOCAL_INACTIVE
)) {
1743 vty_out(vty
, " local-inactive");
1746 if (CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_ES_PEER_PROXY
)) {
1747 vty_out(vty
, " peer-proxy");
1750 if (CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_ES_PEER_ACTIVE
)) {
1751 vty_out(vty
, " peer-active");
1754 if (n
->hold_timer
) {
1755 vty_out(vty
, " (ht: %s)",
1756 thread_timer_to_hhmmss(thread_buf
,
1765 json_object_string_add(json
, "uptime", up_str
);
1766 json_object_string_add(json
, "ip", buf2
);
1767 json_object_string_add(json
, "type", type_str
);
1768 json_object_string_add(json
, "state", state_str
);
1769 json_object_string_add(json
, "mac", buf1
);
1770 if (CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_LOCAL_INACTIVE
))
1771 json_object_boolean_true_add(json
, "localInactive");
1772 if (CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_ES_PEER_PROXY
))
1773 json_object_boolean_true_add(json
, "peerProxy");
1774 if (CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_ES_PEER_ACTIVE
))
1775 json_object_boolean_true_add(json
, "peerActive");
1777 json_object_string_add(
1778 json
, "peerActiveHold",
1779 thread_timer_to_hhmmss(thread_buf
,
1783 if (CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_REMOTE
)) {
1786 json_object_string_add(json
, "remoteEs",
1787 n
->mac
->es
->esi_str
);
1789 vty_out(vty
, " Remote ES: %s\n",
1790 n
->mac
->es
->esi_str
);
1793 json_object_string_addf(json
, "remoteVtep",
1794 "%pI4", &n
->r_vtep_ip
);
1796 vty_out(vty
, " Remote VTEP: %pI4\n",
1800 if (CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_DEF_GW
)) {
1802 vty_out(vty
, " Flags: Default-gateway");
1803 flags_present
= true;
1805 json_object_boolean_true_add(json
, "defaultGateway");
1807 if (CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_ROUTER_FLAG
)) {
1810 flags_present
? " ,Router" : " Flags: Router");
1811 flags_present
= true;
1817 vty_out(vty
, " Local Seq: %u Remote Seq: %u\n", n
->loc_seq
,
1820 if (CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_DUPLICATE
)) {
1821 vty_out(vty
, " Duplicate, detected at %s",
1822 time_to_string(n
->dad_dup_detect_time
,
1824 } else if (n
->dad_count
) {
1825 monotime_since(&n
->detect_start_time
,
1826 &detect_start_time
);
1827 if (detect_start_time
.tv_sec
<= zvrf
->dad_time
) {
1828 time_to_string(n
->detect_start_time
.tv_sec
,
1831 " Duplicate detection started at %s, detection count %u\n",
1832 timebuf
, n
->dad_count
);
1836 json_object_int_add(json
, "localSequence", n
->loc_seq
);
1837 json_object_int_add(json
, "remoteSequence", n
->rem_seq
);
1838 json_object_int_add(json
, "detectionCount", n
->dad_count
);
1839 if (CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_DUPLICATE
))
1840 json_object_boolean_true_add(json
, "isDuplicate");
1842 json_object_boolean_false_add(json
, "isDuplicate");
1846 void zebra_evpn_print_neigh_hdr(struct vty
*vty
, struct neigh_walk_ctx
*wctx
)
1848 vty_out(vty
, "Flags: I=local-inactive, P=peer-active, X=peer-proxy\n");
1849 vty_out(vty
, "%*s %-6s %-5s %-8s %-17s %-30s %s\n", -wctx
->addr_width
,
1850 "Neighbor", "Type", "Flags", "State", "MAC", "Remote ES/VTEP",
1854 static char *zebra_evpn_print_neigh_flags(struct zebra_neigh
*n
,
1856 uint32_t flags_buf_sz
)
1858 snprintf(flags_buf
, flags_buf_sz
, "%s%s%s",
1859 (n
->flags
& ZEBRA_NEIGH_ES_PEER_ACTIVE
) ?
1861 (n
->flags
& ZEBRA_NEIGH_ES_PEER_PROXY
) ?
1863 (n
->flags
& ZEBRA_NEIGH_LOCAL_INACTIVE
) ?
1870 * Print neighbor hash entry - called for display of all neighbors.
1872 void zebra_evpn_print_neigh_hash(struct hash_bucket
*bucket
, void *ctxt
)
1875 json_object
*json_evpn
= NULL
, *json_row
= NULL
;
1876 struct zebra_neigh
*n
;
1877 char buf1
[ETHER_ADDR_STRLEN
];
1878 char buf2
[INET6_ADDRSTRLEN
];
1879 char addr_buf
[PREFIX_STRLEN
];
1880 struct neigh_walk_ctx
*wctx
= ctxt
;
1881 const char *state_str
;
1885 json_evpn
= wctx
->json
;
1886 n
= (struct zebra_neigh
*)bucket
->data
;
1889 json_row
= json_object_new_object();
1891 prefix_mac2str(&n
->emac
, buf1
, sizeof(buf1
));
1892 ipaddr2str(&n
->ip
, buf2
, sizeof(buf2
));
1893 state_str
= IS_ZEBRA_NEIGH_ACTIVE(n
) ? "active" : "inactive";
1894 if (CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_LOCAL
)) {
1895 if (wctx
->flags
& SHOW_REMOTE_NEIGH_FROM_VTEP
)
1898 if (json_evpn
== NULL
) {
1899 vty_out(vty
, "%*s %-6s %-5s %-8s %-17s %-30s %u/%u\n",
1900 -wctx
->addr_width
, buf2
, "local",
1901 zebra_evpn_print_neigh_flags(n
, flags_buf
,
1902 sizeof(flags_buf
)), state_str
, buf1
,
1903 "", n
->loc_seq
, n
->rem_seq
);
1905 json_object_string_add(json_row
, "type", "local");
1906 json_object_string_add(json_row
, "state", state_str
);
1907 json_object_string_add(json_row
, "mac", buf1
);
1908 if (CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_DEF_GW
))
1909 json_object_boolean_true_add(json_row
,
1911 json_object_int_add(json_row
, "localSequence",
1913 json_object_int_add(json_row
, "remoteSequence",
1915 json_object_int_add(json_row
, "detectionCount",
1917 if (CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_DUPLICATE
))
1918 json_object_boolean_true_add(json_row
,
1921 json_object_boolean_false_add(json_row
,
1925 } else if (CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_REMOTE
)) {
1926 if ((wctx
->flags
& SHOW_REMOTE_NEIGH_FROM_VTEP
)
1927 && !IPV4_ADDR_SAME(&n
->r_vtep_ip
, &wctx
->r_vtep_ip
))
1930 if (json_evpn
== NULL
) {
1931 if ((wctx
->flags
& SHOW_REMOTE_NEIGH_FROM_VTEP
)
1932 && (wctx
->count
== 0))
1933 zebra_evpn_print_neigh_hdr(vty
, wctx
);
1935 if (n
->mac
->es
== NULL
)
1936 inet_ntop(AF_INET
, &n
->r_vtep_ip
,
1937 addr_buf
, sizeof(addr_buf
));
1939 vty_out(vty
, "%*s %-6s %-5s %-8s %-17s %-30s %u/%u\n",
1940 -wctx
->addr_width
, buf2
, "remote",
1941 zebra_evpn_print_neigh_flags(n
, flags_buf
,
1942 sizeof(flags_buf
)), state_str
, buf1
,
1943 n
->mac
->es
? n
->mac
->es
->esi_str
: addr_buf
,
1944 n
->loc_seq
, n
->rem_seq
);
1946 json_object_string_add(json_row
, "type", "remote");
1947 json_object_string_add(json_row
, "state", state_str
);
1948 json_object_string_add(json_row
, "mac", buf1
);
1950 json_object_string_add(json_row
, "remoteEs",
1951 n
->mac
->es
->esi_str
);
1953 json_object_string_addf(json_row
, "remoteVtep",
1954 "%pI4", &n
->r_vtep_ip
);
1955 if (CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_DEF_GW
))
1956 json_object_boolean_true_add(json_row
,
1958 json_object_int_add(json_row
, "localSequence",
1960 json_object_int_add(json_row
, "remoteSequence",
1962 json_object_int_add(json_row
, "detectionCount",
1964 if (CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_DUPLICATE
))
1965 json_object_boolean_true_add(json_row
,
1968 json_object_boolean_false_add(json_row
,
1975 json_object_object_add(json_evpn
, buf2
, json_row
);
1979 * Print neighbor hash entry in detail - called for display of all neighbors.
1981 void zebra_evpn_print_neigh_hash_detail(struct hash_bucket
*bucket
, void *ctxt
)
1984 json_object
*json_evpn
= NULL
, *json_row
= NULL
;
1985 struct zebra_neigh
*n
;
1986 char buf
[INET6_ADDRSTRLEN
];
1987 struct neigh_walk_ctx
*wctx
= ctxt
;
1990 json_evpn
= wctx
->json
;
1991 n
= (struct zebra_neigh
*)bucket
->data
;
1995 ipaddr2str(&n
->ip
, buf
, sizeof(buf
));
1997 json_row
= json_object_new_object();
1999 zebra_evpn_print_neigh(n
, vty
, json_row
);
2002 json_object_object_add(json_evpn
, buf
, json_row
);
2005 void zebra_evpn_print_dad_neigh_hash(struct hash_bucket
*bucket
, void *ctxt
)
2007 struct zebra_neigh
*nbr
;
2009 nbr
= (struct zebra_neigh
*)bucket
->data
;
2013 if (CHECK_FLAG(nbr
->flags
, ZEBRA_NEIGH_DUPLICATE
))
2014 zebra_evpn_print_neigh_hash(bucket
, ctxt
);
2017 void zebra_evpn_print_dad_neigh_hash_detail(struct hash_bucket
*bucket
,
2020 struct zebra_neigh
*nbr
;
2022 nbr
= (struct zebra_neigh
*)bucket
->data
;
2026 if (CHECK_FLAG(nbr
->flags
, ZEBRA_NEIGH_DUPLICATE
))
2027 zebra_evpn_print_neigh_hash_detail(bucket
, ctxt
);
2030 void zebra_evpn_neigh_remote_macip_add(struct zebra_evpn
*zevpn
,
2031 struct zebra_vrf
*zvrf
,
2032 const struct ipaddr
*ipaddr
,
2033 struct zebra_mac
*mac
,
2034 struct in_addr vtep_ip
, uint8_t flags
,
2037 struct zebra_neigh
*n
;
2038 int update_neigh
= 0;
2039 struct zebra_mac
*old_mac
= NULL
;
2040 bool old_static
= false;
2041 bool do_dad
= false;
2042 bool is_dup_detect
= false;
2046 is_router
= !!CHECK_FLAG(flags
, ZEBRA_MACIP_TYPE_ROUTER_FLAG
);
2048 /* Check if the remote neighbor itself is unknown or has a
2049 * change. If so, create or update and then install the entry.
2051 n
= zebra_evpn_neigh_lookup(zevpn
, ipaddr
);
2052 if (!n
|| !CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_REMOTE
)
2053 || is_router
!= !!CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_ROUTER_FLAG
)
2054 || (memcmp(&n
->emac
, &mac
->macaddr
, sizeof(struct ethaddr
)) != 0)
2055 || !IPV4_ADDR_SAME(&n
->r_vtep_ip
, &vtep_ip
) || seq
!= n
->rem_seq
)
2060 n
= zebra_evpn_neigh_add(zevpn
, ipaddr
, &mac
->macaddr
,
2063 /* When host moves but changes its (MAC,IP)
2064 * binding, BGP may install a MACIP entry that
2065 * corresponds to "older" location of the host
2066 * in transient situations (because {IP1,M1}
2067 * is a different route from {IP1,M2}). Check
2068 * the sequence number and ignore this update
2072 if (!zebra_evpn_neigh_is_bgp_seq_ok(
2073 zevpn
, n
, &mac
->macaddr
, seq
, false))
2075 if (CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_LOCAL
)) {
2076 old_static
= zebra_evpn_neigh_is_static(n
);
2077 if (IS_ZEBRA_DEBUG_EVPN_MH_NEIGH
)
2079 "sync->remote neigh vni %u ip %pIA mac %pEA seq %d f0x%x",
2080 n
->zevpn
->vni
, &n
->ip
, &n
->emac
,
2082 if (IS_ZEBRA_NEIGH_ACTIVE(n
))
2083 zebra_evpn_neigh_send_del_to_client(
2084 zevpn
->vni
, &n
->ip
, &n
->emac
,
2087 zebra_evpn_neigh_clear_sync_info(n
);
2089 if (memcmp(&n
->emac
, &mac
->macaddr
,
2090 sizeof(struct ethaddr
))
2092 /* update neigh list for macs */
2094 zebra_evpn_mac_lookup(zevpn
, &n
->emac
);
2096 listnode_delete(old_mac
->neigh_list
, n
);
2098 zebra_evpn_deref_ip2mac(zevpn
, old_mac
);
2101 listnode_add_sort(mac
->neigh_list
, n
);
2102 memcpy(&n
->emac
, &mac
->macaddr
, ETH_ALEN
);
2104 /* Check Neigh's curent state is local
2105 * (this is the case where neigh/host has moved
2106 * from L->R) and check previous detction
2107 * started via local learning.
2109 * RFC-7432: A PE/VTEP that detects a MAC
2110 * mobilit event via local learning starts
2111 * an M-second timer.
2112 * VTEP-IP or seq. change along is not
2113 * considered for dup. detection.
2115 * Mobilty event scenario-B IP-MAC binding
2118 if ((!CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_REMOTE
))
2124 /* Set "remote" forwarding info. */
2125 UNSET_FLAG(n
->flags
, ZEBRA_NEIGH_ALL_LOCAL_FLAGS
);
2126 n
->r_vtep_ip
= vtep_ip
;
2127 SET_FLAG(n
->flags
, ZEBRA_NEIGH_REMOTE
);
2129 /* Set router flag (R-bit) to this Neighbor entry */
2130 if (CHECK_FLAG(flags
, ZEBRA_MACIP_TYPE_ROUTER_FLAG
))
2131 SET_FLAG(n
->flags
, ZEBRA_NEIGH_ROUTER_FLAG
);
2133 UNSET_FLAG(n
->flags
, ZEBRA_NEIGH_ROUTER_FLAG
);
2135 /* Check old or new MAC detected as duplicate,
2136 * inherit duplicate flag to this neigh.
2138 if (zebra_evpn_ip_inherit_dad_from_mac(zvrf
, old_mac
, mac
, n
)) {
2140 EC_ZEBRA_DUP_IP_INHERIT_DETECTED
,
2141 "VNI %u: MAC %pEA IP %pIA detected as duplicate during remote update, inherit duplicate from MAC",
2142 zevpn
->vni
, &mac
->macaddr
, &n
->ip
);
2145 /* Check duplicate address detection for IP */
2146 zebra_evpn_dup_addr_detect_for_neigh(
2147 zvrf
, n
, n
->r_vtep_ip
, do_dad
, &is_dup_detect
, false);
2148 /* Install the entry. */
2150 zebra_evpn_rem_neigh_install(zevpn
, n
, old_static
);
2153 /* Update seq number. */
2157 int zebra_evpn_neigh_gw_macip_add(struct interface
*ifp
,
2158 struct zebra_evpn
*zevpn
, struct ipaddr
*ip
,
2159 struct zebra_mac
*mac
)
2161 struct zebra_neigh
*n
;
2165 n
= zebra_evpn_neigh_lookup(zevpn
, ip
);
2167 n
= zebra_evpn_neigh_add(zevpn
, ip
, &mac
->macaddr
, mac
, 0);
2169 /* Set "local" forwarding info. */
2170 SET_FLAG(n
->flags
, ZEBRA_NEIGH_LOCAL
);
2171 ZEBRA_NEIGH_SET_ACTIVE(n
);
2172 memcpy(&n
->emac
, &mac
->macaddr
, ETH_ALEN
);
2173 n
->ifindex
= ifp
->ifindex
;
2175 /* Only advertise in BGP if the knob is enabled */
2176 if (advertise_gw_macip_enabled(zevpn
)) {
2178 SET_FLAG(n
->flags
, ZEBRA_NEIGH_DEF_GW
);
2179 /* Set Router flag (R-bit) */
2180 if (ip
->ipa_type
== IPADDR_V6
)
2181 SET_FLAG(n
->flags
, ZEBRA_NEIGH_ROUTER_FLAG
);
2183 if (IS_ZEBRA_DEBUG_VXLAN
)
2185 "SVI %s(%u) L2-VNI %u, sending GW MAC %pEA IP %pIA add to BGP with flags 0x%x",
2186 ifp
->name
, ifp
->ifindex
, zevpn
->vni
,
2187 &mac
->macaddr
, ip
, n
->flags
);
2189 zebra_evpn_neigh_send_add_to_client(
2190 zevpn
->vni
, ip
, &n
->emac
, n
->mac
, n
->flags
, n
->loc_seq
);
2191 } else if (advertise_svi_macip_enabled(zevpn
)) {
2193 SET_FLAG(n
->flags
, ZEBRA_NEIGH_SVI_IP
);
2194 if (IS_ZEBRA_DEBUG_VXLAN
)
2196 "SVI %s(%u) L2-VNI %u, sending SVI MAC %pEA IP %pIA add to BGP with flags 0x%x",
2197 ifp
->name
, ifp
->ifindex
, zevpn
->vni
,
2198 &mac
->macaddr
, ip
, n
->flags
);
2200 zebra_evpn_neigh_send_add_to_client(
2201 zevpn
->vni
, ip
, &n
->emac
, n
->mac
, n
->flags
, n
->loc_seq
);
2207 void zebra_evpn_neigh_remote_uninstall(struct zebra_evpn
*zevpn
,
2208 struct zebra_vrf
*zvrf
,
2209 struct zebra_neigh
*n
,
2210 struct zebra_mac
*mac
,
2211 const struct ipaddr
*ipaddr
)
2213 if (zvrf
->dad_freeze
&& CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_DUPLICATE
)
2214 && CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_REMOTE
)
2215 && (memcmp(n
->emac
.octet
, mac
->macaddr
.octet
, ETH_ALEN
) == 0)) {
2216 struct interface
*vlan_if
;
2218 vlan_if
= zevpn_map_to_svi(zevpn
);
2219 if (IS_ZEBRA_DEBUG_VXLAN
)
2221 "%s: IP %pIA (flags 0x%x intf %s) is remote and duplicate, read kernel for local entry",
2222 __func__
, ipaddr
, n
->flags
,
2223 vlan_if
? vlan_if
->name
: "Unknown");
2225 neigh_read_specific_ip(ipaddr
, vlan_if
);
2228 /* When the MAC changes for an IP, it is possible the
2229 * client may update the new MAC before trying to delete the
2230 * "old" neighbor (as these are two different MACIP routes).
2231 * Do the delete only if the MAC matches.
2233 if (!memcmp(n
->emac
.octet
, mac
->macaddr
.octet
, ETH_ALEN
)) {
2234 if (CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_LOCAL
)) {
2235 zebra_evpn_sync_neigh_del(n
);
2236 } else if (CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_REMOTE
)) {
2237 zebra_evpn_neigh_uninstall(zevpn
, n
);
2238 zebra_evpn_neigh_del(zevpn
, n
);
2239 zebra_evpn_deref_ip2mac(zevpn
, mac
);
2244 int zebra_evpn_neigh_del_ip(struct zebra_evpn
*zevpn
, const struct ipaddr
*ip
)
2246 struct zebra_neigh
*n
;
2247 struct zebra_mac
*zmac
;
2250 struct zebra_vrf
*zvrf
;
2252 /* If entry doesn't exist, nothing to do. */
2253 n
= zebra_evpn_neigh_lookup(zevpn
, ip
);
2257 zmac
= zebra_evpn_mac_lookup(zevpn
, &n
->emac
);
2259 if (IS_ZEBRA_DEBUG_VXLAN
)
2261 "Trying to del a neigh %pIA without a mac %pEA on VNI %u",
2268 /* If it is a remote entry, the kernel has aged this out or someone has
2269 * deleted it, it needs to be re-installed as FRR is the owner.
2271 if (CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_REMOTE
)) {
2272 zebra_evpn_rem_neigh_install(zevpn
, n
, false /*was_static*/);
2276 /* if this is a sync entry it cannot be dropped re-install it in
2279 old_bgp_ready
= zebra_evpn_neigh_is_ready_for_bgp(n
);
2280 if (zebra_evpn_neigh_is_static(n
)) {
2281 if (IS_ZEBRA_DEBUG_EVPN_MH_NEIGH
)
2282 zlog_debug("re-add sync neigh vni %u ip %pIA mac %pEA 0x%x",
2283 n
->zevpn
->vni
, &n
->ip
, &n
->emac
,
2286 if (!CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_LOCAL_INACTIVE
))
2287 SET_FLAG(n
->flags
, ZEBRA_NEIGH_LOCAL_INACTIVE
);
2288 /* inform-bgp about change in local-activity if any */
2289 new_bgp_ready
= zebra_evpn_neigh_is_ready_for_bgp(n
);
2290 zebra_evpn_neigh_send_add_del_to_client(n
, old_bgp_ready
,
2293 /* re-install the entry in the kernel */
2294 zebra_evpn_sync_neigh_dp_install(n
, false /* set_inactive */,
2295 false /* force_clear_static */,
2301 zvrf
= zevpn
->vxlan_if
->vrf
->info
;
2303 zlog_debug("%s: VNI %u vrf lookup failed.", __func__
,
2308 /* In case of feeze action, if local neigh is in duplicate state,
2309 * Mark the Neigh as inactive before sending delete request to BGPd,
2310 * If BGPd has remote entry, it will re-install
2312 if (zvrf
->dad_freeze
&& CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_DUPLICATE
))
2313 ZEBRA_NEIGH_SET_INACTIVE(n
);
2315 /* Remove neighbor from BGP. */
2316 zebra_evpn_neigh_send_del_to_client(zevpn
->vni
, &n
->ip
, &n
->emac
,
2320 /* Delete this neighbor entry. */
2321 zebra_evpn_neigh_del(zevpn
, n
);
2323 /* see if the AUTO mac needs to be deleted */
2324 if (CHECK_FLAG(zmac
->flags
, ZEBRA_MAC_AUTO
)
2325 && !zebra_evpn_mac_in_use(zmac
))
2326 zebra_evpn_mac_del(zevpn
, zmac
);