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
,
504 bool is_local
= false;
506 if (CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_LOCAL
)) {
507 tmp_seq
= n
->loc_seq
;
511 tmp_seq
= n
->rem_seq
;
516 if (is_local
&& !zebra_evpn_neigh_is_ready_for_bgp(n
)) {
517 if (IS_ZEBRA_DEBUG_EVPN_MH_NEIGH
||
518 IS_ZEBRA_DEBUG_VXLAN
)
520 "%s-macip not ready vni %u %s mac %pEA IP %pIA lower seq %u f 0x%x",
521 sync
? "sync" : "remote", zevpn
->vni
,
522 n_type
, macaddr
, &n
->ip
, tmp_seq
,
527 /* if the neigh was never advertised to bgp we must accept
528 * whatever sequence number bgp sends
530 if (!is_local
&& zebra_vxlan_get_accept_bgp_seq()) {
531 if (IS_ZEBRA_DEBUG_EVPN_MH_NEIGH
532 || IS_ZEBRA_DEBUG_VXLAN
)
534 "%s-macip accept vni %u %s mac %pEA IP %pIA lower seq %u f 0x%x",
535 sync
? "sync" : "remote", zevpn
->vni
,
536 n_type
, macaddr
, &n
->ip
,
541 if (IS_ZEBRA_DEBUG_EVPN_MH_NEIGH
|| IS_ZEBRA_DEBUG_VXLAN
)
543 "%s-macip ignore vni %u %s mac %pEA IP %pIA as existing has higher seq %u f 0x%x",
544 sync
? "sync" : "remote", zevpn
->vni
, n_type
,
545 macaddr
, &n
->ip
, tmp_seq
, n
->flags
);
553 * Add neighbor entry.
555 static struct zebra_neigh
*zebra_evpn_neigh_add(struct zebra_evpn
*zevpn
,
556 const struct ipaddr
*ip
,
557 const struct ethaddr
*mac
,
558 struct zebra_mac
*zmac
,
561 struct zebra_neigh tmp_n
;
562 struct zebra_neigh
*n
= NULL
;
564 memset(&tmp_n
, 0, sizeof(tmp_n
));
565 memcpy(&tmp_n
.ip
, ip
, sizeof(struct ipaddr
));
566 n
= hash_get(zevpn
->neigh_table
, &tmp_n
, zebra_evpn_neigh_alloc
);
568 n
->state
= ZEBRA_NEIGH_INACTIVE
;
570 n
->dad_ip_auto_recovery_timer
= NULL
;
572 n
->uptime
= monotime(NULL
);
575 zmac
= zebra_evpn_mac_lookup(zevpn
, mac
);
576 zebra_evpn_local_neigh_ref_mac(n
, mac
, zmac
,
577 false /* send_mac_update */);
583 * Delete neighbor entry.
585 int zebra_evpn_neigh_del(struct zebra_evpn
*zevpn
, struct zebra_neigh
*n
)
587 struct zebra_neigh
*tmp_n
;
590 listnode_delete(n
->mac
->neigh_list
, n
);
592 /* Cancel auto recovery */
593 THREAD_OFF(n
->dad_ip_auto_recovery_timer
);
595 /* Cancel proxy hold timer */
596 zebra_evpn_neigh_stop_hold_timer(n
);
598 /* Free the VNI hash entry and allocated memory. */
599 tmp_n
= hash_release(zevpn
->neigh_table
, n
);
600 XFREE(MTYPE_NEIGH
, tmp_n
);
605 void zebra_evpn_sync_neigh_del(struct zebra_neigh
*n
)
610 if (IS_ZEBRA_DEBUG_EVPN_MH_NEIGH
)
611 zlog_debug("sync-neigh del vni %u ip %pIA mac %pEA f 0x%x",
612 n
->zevpn
->vni
, &n
->ip
, &n
->emac
, n
->flags
);
614 old_n_static
= zebra_evpn_neigh_is_static(n
);
615 UNSET_FLAG(n
->flags
, ZEBRA_NEIGH_ES_PEER_PROXY
);
616 if (CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_ES_PEER_ACTIVE
))
617 zebra_evpn_neigh_start_hold_timer(n
);
618 new_n_static
= zebra_evpn_neigh_is_static(n
);
620 if (old_n_static
!= new_n_static
)
621 zebra_evpn_sync_neigh_static_chg(
622 n
, old_n_static
, new_n_static
, false /*defer-dp*/,
623 false /*defer_mac_dp*/, __func__
);
626 struct zebra_neigh
*zebra_evpn_proc_sync_neigh_update(
627 struct zebra_evpn
*zevpn
, struct zebra_neigh
*n
, uint16_t ipa_len
,
628 const struct ipaddr
*ipaddr
, uint8_t flags
, uint32_t seq
,
629 const esi_t
*esi
, struct zebra_mac
*mac
)
631 struct interface
*ifp
= NULL
;
634 bool old_router
= false;
635 bool old_bgp_ready
= false;
637 bool inform_dataplane
= false;
638 bool inform_bgp
= false;
641 bool set_dp_inactive
= false;
643 ifindex_t ifindex
= 0;
646 ifp
= zevpn_map_to_svi(zevpn
);
648 ifindex
= ifp
->ifindex
;
650 is_router
= !!CHECK_FLAG(flags
, ZEBRA_MACIP_TYPE_ROUTER_FLAG
);
651 old_mac_static
= zebra_evpn_mac_is_static(mac
);
654 uint32_t n_flags
= 0;
656 /* New neighbor - create */
657 SET_FLAG(n_flags
, ZEBRA_NEIGH_LOCAL
);
658 if (CHECK_FLAG(flags
, ZEBRA_MACIP_TYPE_PROXY_ADVERT
))
659 SET_FLAG(n_flags
, ZEBRA_NEIGH_ES_PEER_PROXY
);
661 SET_FLAG(n_flags
, ZEBRA_NEIGH_ES_PEER_ACTIVE
);
662 SET_FLAG(n_flags
, ZEBRA_NEIGH_LOCAL_INACTIVE
);
664 n
= zebra_evpn_neigh_add(zevpn
, ipaddr
, &mac
->macaddr
, mac
,
666 n
->ifindex
= ifindex
;
667 ZEBRA_NEIGH_SET_ACTIVE(n
);
670 inform_dataplane
= true;
672 set_dp_inactive
= true;
675 uint32_t old_flags
= n
->flags
;
680 old_n_static
= zebra_evpn_neigh_is_static(n
);
681 old_bgp_ready
= zebra_evpn_neigh_is_ready_for_bgp(n
);
682 old_router
= !!CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_ROUTER_FLAG
);
684 mac_change
= !!memcmp(&n
->emac
, &mac
->macaddr
, ETH_ALEN
);
686 /* deref and clear old info */
689 zebra_evpn_neigh_send_del_to_client(
690 zevpn
->vni
, &n
->ip
, &n
->emac
, n
->flags
,
691 n
->state
, false /*force*/);
692 old_bgp_ready
= false;
694 zebra_evpn_local_neigh_deref_mac(n
,
695 false /*send_mac_update*/);
697 /* clear old fwd info */
699 n
->r_vtep_ip
.s_addr
= 0;
701 /* setup new flags */
703 SET_FLAG(n
->flags
, ZEBRA_NEIGH_LOCAL
);
704 /* retain activity flag if the neigh was
707 if (old_flags
& ZEBRA_NEIGH_LOCAL
) {
708 n
->flags
|= (old_flags
& ZEBRA_NEIGH_LOCAL_INACTIVE
);
710 inform_dataplane
= true;
711 set_dp_inactive
= true;
712 n
->flags
|= ZEBRA_NEIGH_LOCAL_INACTIVE
;
715 if (CHECK_FLAG(flags
, ZEBRA_MACIP_TYPE_PROXY_ADVERT
)) {
716 SET_FLAG(n
->flags
, ZEBRA_NEIGH_ES_PEER_PROXY
);
717 /* if the neigh was peer-active previously we
718 * need to keep the flag and start the
719 * holdtimer on it. the peer-active flag is
720 * cleared on holdtimer expiry.
722 if (CHECK_FLAG(old_flags
, ZEBRA_NEIGH_ES_PEER_ACTIVE
)) {
723 SET_FLAG(n
->flags
, ZEBRA_NEIGH_ES_PEER_ACTIVE
);
724 zebra_evpn_neigh_start_hold_timer(n
);
727 SET_FLAG(n
->flags
, ZEBRA_NEIGH_ES_PEER_ACTIVE
);
728 /* stop hold timer if a peer has verified
731 zebra_evpn_neigh_stop_hold_timer(n
);
733 ZEBRA_NEIGH_SET_ACTIVE(n
);
735 if (IS_ZEBRA_DEBUG_EVPN_MH_NEIGH
&& (old_flags
!= n
->flags
))
737 "sync-neigh vni %u ip %pIA mac %pEA old_f 0x%x new_f 0x%x",
738 n
->zevpn
->vni
, &n
->ip
, &n
->emac
,
739 old_flags
, n
->flags
);
741 new_n_static
= zebra_evpn_neigh_is_static(n
);
743 set_dp_inactive
= true;
744 n
->flags
|= ZEBRA_NEIGH_LOCAL_INACTIVE
;
745 inform_dataplane
= true;
746 zebra_evpn_local_neigh_ref_mac(
747 n
, &mac
->macaddr
, mac
,
748 false /*send_mac_update*/);
749 } else if (old_n_static
!= new_n_static
) {
750 inform_dataplane
= true;
751 /* if static flags have changed without a mac change
752 * we need to create the correct sync-refs against
755 zebra_evpn_sync_neigh_static_chg(
756 n
, old_n_static
, new_n_static
,
757 true /*defer_dp*/, true /*defer_mac_dp*/,
761 /* Update the forwarding info. */
762 if (n
->ifindex
!= ifindex
) {
763 n
->ifindex
= ifindex
;
764 inform_dataplane
= true;
767 n
->uptime
= monotime(NULL
);
770 /* update the neigh seq. we don't bother with the mac seq as
771 * sync_mac_update already took care of that
773 tmp_seq
= MAX(n
->loc_seq
, seq
);
774 if (tmp_seq
!= n
->loc_seq
) {
775 n
->loc_seq
= tmp_seq
;
779 /* Mark Router flag (R-bit) */
781 SET_FLAG(n
->flags
, ZEBRA_NEIGH_ROUTER_FLAG
);
783 UNSET_FLAG(n
->flags
, ZEBRA_NEIGH_ROUTER_FLAG
);
785 if (old_router
!= is_router
)
786 inform_dataplane
= true;
788 new_bgp_ready
= zebra_evpn_neigh_is_ready_for_bgp(n
);
789 if (old_bgp_ready
!= new_bgp_ready
)
792 new_mac_static
= zebra_evpn_mac_is_static(mac
);
793 if (old_mac_static
!= new_mac_static
)
794 zebra_evpn_sync_mac_dp_install(mac
, false /* set_inactive */,
795 false /* force_clear_static */,
798 if (IS_ZEBRA_DEBUG_EVPN_MH_NEIGH
)
800 "sync-neigh %s vni %u ip %pIA mac %pEA if %s(%d) seq %d f 0x%x%s%s",
801 created
? "created" : "updated", n
->zevpn
->vni
,
803 ifp
? ifp
->name
: "", ifindex
, n
->loc_seq
, n
->flags
,
804 inform_bgp
? " inform_bgp" : "",
805 inform_dataplane
? " inform_dp" : "");
807 if (inform_dataplane
)
808 zebra_evpn_sync_neigh_dp_install(n
, set_dp_inactive
,
809 false /* force_clear_static */,
813 zebra_evpn_neigh_send_add_del_to_client(n
, old_bgp_ready
,
820 * Uninstall remote neighbor from the kernel.
822 static int zebra_evpn_neigh_uninstall(struct zebra_evpn
*zevpn
,
823 struct zebra_neigh
*n
)
825 struct interface
*vlan_if
;
827 if (!(n
->flags
& ZEBRA_NEIGH_REMOTE
))
830 vlan_if
= zevpn_map_to_svi(zevpn
);
834 ZEBRA_NEIGH_SET_INACTIVE(n
);
837 dplane_rem_neigh_delete(vlan_if
, &n
->ip
);
843 * Free neighbor hash entry (callback)
845 static void zebra_evpn_neigh_del_hash_entry(struct hash_bucket
*bucket
,
848 struct neigh_walk_ctx
*wctx
= arg
;
849 struct zebra_neigh
*n
= bucket
->data
;
851 if (((wctx
->flags
& DEL_LOCAL_NEIGH
) && (n
->flags
& ZEBRA_NEIGH_LOCAL
))
852 || ((wctx
->flags
& DEL_REMOTE_NEIGH
)
853 && (n
->flags
& ZEBRA_NEIGH_REMOTE
))
854 || ((wctx
->flags
& DEL_REMOTE_NEIGH_FROM_VTEP
)
855 && (n
->flags
& ZEBRA_NEIGH_REMOTE
)
856 && IPV4_ADDR_SAME(&n
->r_vtep_ip
, &wctx
->r_vtep_ip
))) {
857 if (wctx
->upd_client
&& (n
->flags
& ZEBRA_NEIGH_LOCAL
))
858 zebra_evpn_neigh_send_del_to_client(
859 wctx
->zevpn
->vni
, &n
->ip
, &n
->emac
, n
->flags
,
860 n
->state
, false /*force*/);
862 if (wctx
->uninstall
) {
863 if (zebra_evpn_neigh_is_static(n
))
864 zebra_evpn_sync_neigh_dp_install(
865 n
, false /* set_inactive */,
866 true /* force_clear_static */,
868 if ((n
->flags
& ZEBRA_NEIGH_REMOTE
))
869 zebra_evpn_neigh_uninstall(wctx
->zevpn
, n
);
872 zebra_evpn_neigh_del(wctx
->zevpn
, n
);
879 * Delete all neighbor entries for this EVPN.
881 void zebra_evpn_neigh_del_all(struct zebra_evpn
*zevpn
, int uninstall
,
882 int upd_client
, uint32_t flags
)
884 struct neigh_walk_ctx wctx
;
886 if (!zevpn
->neigh_table
)
889 memset(&wctx
, 0, sizeof(wctx
));
891 wctx
.uninstall
= uninstall
;
892 wctx
.upd_client
= upd_client
;
895 hash_iterate(zevpn
->neigh_table
, zebra_evpn_neigh_del_hash_entry
,
900 * Look up neighbor hash entry.
902 struct zebra_neigh
*zebra_evpn_neigh_lookup(struct zebra_evpn
*zevpn
,
903 const struct ipaddr
*ip
)
905 struct zebra_neigh tmp
;
906 struct zebra_neigh
*n
;
908 memset(&tmp
, 0, sizeof(tmp
));
909 memcpy(&tmp
.ip
, ip
, sizeof(struct ipaddr
));
910 n
= hash_lookup(zevpn
->neigh_table
, &tmp
);
916 * Process all neighbors associated with a MAC upon the MAC being learnt
917 * locally or undergoing any other change (such as sequence number).
919 void zebra_evpn_process_neigh_on_local_mac_change(struct zebra_evpn
*zevpn
,
920 struct zebra_mac
*zmac
,
924 struct zebra_neigh
*n
= NULL
;
925 struct listnode
*node
= NULL
;
926 struct zebra_vrf
*zvrf
= NULL
;
928 zvrf
= zevpn
->vxlan_if
->vrf
->info
;
930 if (IS_ZEBRA_DEBUG_VXLAN
)
931 zlog_debug("Processing neighbors on local MAC %pEA %s, VNI %u",
932 &zmac
->macaddr
, seq_change
? "CHANGE" : "ADD",
935 /* Walk all neighbors and mark any inactive local neighbors as
936 * active and/or update sequence number upon a move, and inform BGP.
937 * The action for remote neighbors is TBD.
938 * NOTE: We can't simply uninstall remote neighbors as the kernel may
939 * accidentally end up deleting a just-learnt local neighbor.
941 for (ALL_LIST_ELEMENTS_RO(zmac
->neigh_list
, node
, n
)) {
942 if (CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_LOCAL
)) {
943 if (IS_ZEBRA_NEIGH_INACTIVE(n
) || seq_change
945 ZEBRA_NEIGH_SET_ACTIVE(n
);
946 n
->loc_seq
= zmac
->loc_seq
;
947 if (!(zebra_evpn_do_dup_addr_detect(zvrf
)
949 && !!CHECK_FLAG(n
->flags
,
950 ZEBRA_NEIGH_DUPLICATE
)))
951 zebra_evpn_neigh_send_add_to_client(
952 zevpn
->vni
, &n
->ip
, &n
->emac
,
953 n
->mac
, n
->flags
, n
->loc_seq
);
960 * Process all neighbors associated with a local MAC upon the MAC being
963 void zebra_evpn_process_neigh_on_local_mac_del(struct zebra_evpn
*zevpn
,
964 struct zebra_mac
*zmac
)
966 struct zebra_neigh
*n
= NULL
;
967 struct listnode
*node
= NULL
;
969 if (IS_ZEBRA_DEBUG_VXLAN
)
970 zlog_debug("Processing neighbors on local MAC %pEA DEL, VNI %u",
971 &zmac
->macaddr
, zevpn
->vni
);
973 /* Walk all local neighbors and mark as inactive and inform
975 * TBD: There is currently no handling for remote neighbors. We
976 * don't expect them to exist, if they do, do we install the MAC
977 * as a remote MAC and the neighbor as remote?
979 for (ALL_LIST_ELEMENTS_RO(zmac
->neigh_list
, node
, n
)) {
980 if (CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_LOCAL
)) {
981 if (IS_ZEBRA_NEIGH_ACTIVE(n
)) {
982 ZEBRA_NEIGH_SET_INACTIVE(n
);
984 zebra_evpn_neigh_send_del_to_client(
985 zevpn
->vni
, &n
->ip
, &n
->emac
, n
->flags
,
986 ZEBRA_NEIGH_ACTIVE
, false /*force*/);
993 * Process all neighbors associated with a MAC upon the MAC being remotely
996 void zebra_evpn_process_neigh_on_remote_mac_add(struct zebra_evpn
*zevpn
,
997 struct zebra_mac
*zmac
)
999 struct zebra_neigh
*n
= NULL
;
1000 struct listnode
*node
= NULL
;
1002 if (IS_ZEBRA_DEBUG_VXLAN
)
1003 zlog_debug("Processing neighbors on remote MAC %pEA ADD, VNI %u",
1004 &zmac
->macaddr
, zevpn
->vni
);
1006 /* Walk all local neighbors and mark as inactive and inform
1009 for (ALL_LIST_ELEMENTS_RO(zmac
->neigh_list
, node
, n
)) {
1010 if (CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_LOCAL
)) {
1011 if (IS_ZEBRA_NEIGH_ACTIVE(n
)) {
1012 ZEBRA_NEIGH_SET_INACTIVE(n
);
1014 zebra_evpn_neigh_send_del_to_client(
1015 zevpn
->vni
, &n
->ip
, &n
->emac
, n
->flags
,
1016 ZEBRA_NEIGH_ACTIVE
, false /* force */);
1023 * Process all neighbors associated with a remote MAC upon the MAC being
1026 void zebra_evpn_process_neigh_on_remote_mac_del(struct zebra_evpn
*zevpn
,
1027 struct zebra_mac
*zmac
)
1029 /* NOTE: Currently a NO-OP. */
1032 static inline void zebra_evpn_local_neigh_update_log(
1033 const char *pfx
, struct zebra_neigh
*n
, bool is_router
,
1034 bool local_inactive
, bool old_bgp_ready
, bool new_bgp_ready
,
1035 bool inform_dataplane
, bool inform_bgp
, const char *sfx
)
1037 if (!IS_ZEBRA_DEBUG_EVPN_MH_NEIGH
)
1040 zlog_debug("%s neigh vni %u ip %pIA mac %pEA f 0x%x%s%s%s%s%s%s %s", pfx
,
1041 n
->zevpn
->vni
, &n
->ip
, &n
->emac
, n
->flags
,
1042 is_router
? " router" : "",
1043 local_inactive
? " local-inactive" : "",
1044 old_bgp_ready
? " old_bgp_ready" : "",
1045 new_bgp_ready
? " new_bgp_ready" : "",
1046 inform_dataplane
? " inform_dp" : "",
1047 inform_bgp
? " inform_bgp" : "", sfx
);
1050 /* As part Duplicate Address Detection (DAD) for IP mobility
1051 * MAC binding changes, ensure to inherit duplicate flag
1054 static int zebra_evpn_ip_inherit_dad_from_mac(struct zebra_vrf
*zvrf
,
1055 struct zebra_mac
*old_zmac
,
1056 struct zebra_mac
*new_zmac
,
1057 struct zebra_neigh
*nbr
)
1059 bool is_old_mac_dup
= false;
1060 bool is_new_mac_dup
= false;
1062 if (!zebra_evpn_do_dup_addr_detect(zvrf
))
1064 /* Check old or new MAC is detected as duplicate
1065 * mark this neigh as duplicate
1069 CHECK_FLAG(old_zmac
->flags
, ZEBRA_MAC_DUPLICATE
);
1072 CHECK_FLAG(new_zmac
->flags
, ZEBRA_MAC_DUPLICATE
);
1073 /* Old and/or new MAC can be in duplicate state,
1074 * based on that IP/Neigh Inherits the flag.
1075 * If New MAC is marked duplicate, inherit to the IP.
1076 * If old MAC is duplicate but new MAC is not, clear
1077 * duplicate flag for IP and reset detection params
1078 * and let IP DAD retrigger.
1080 if (is_new_mac_dup
&& !CHECK_FLAG(nbr
->flags
, ZEBRA_NEIGH_DUPLICATE
)) {
1081 SET_FLAG(nbr
->flags
, ZEBRA_NEIGH_DUPLICATE
);
1082 /* Capture Duplicate detection time */
1083 nbr
->dad_dup_detect_time
= monotime(NULL
);
1084 /* Mark neigh inactive */
1085 ZEBRA_NEIGH_SET_INACTIVE(nbr
);
1088 } else if (is_old_mac_dup
&& !is_new_mac_dup
) {
1089 UNSET_FLAG(nbr
->flags
, ZEBRA_NEIGH_DUPLICATE
);
1091 nbr
->detect_start_time
.tv_sec
= 0;
1092 nbr
->detect_start_time
.tv_usec
= 0;
1097 static void zebra_evpn_dad_ip_auto_recovery_exp(struct thread
*t
)
1099 struct zebra_vrf
*zvrf
= NULL
;
1100 struct zebra_neigh
*nbr
= NULL
;
1101 struct zebra_evpn
*zevpn
= NULL
;
1103 nbr
= THREAD_ARG(t
);
1105 /* since this is asynchronous we need sanity checks*/
1106 zvrf
= vrf_info_lookup(nbr
->zevpn
->vrf_id
);
1110 zevpn
= zebra_evpn_lookup(nbr
->zevpn
->vni
);
1114 nbr
= zebra_evpn_neigh_lookup(zevpn
, &nbr
->ip
);
1118 if (IS_ZEBRA_DEBUG_VXLAN
)
1120 "%s: duplicate addr MAC %pEA IP %pIA flags 0x%x learn count %u vni %u auto recovery expired",
1121 __func__
, &nbr
->emac
, &nbr
->ip
, nbr
->flags
,
1122 nbr
->dad_count
, zevpn
->vni
);
1124 UNSET_FLAG(nbr
->flags
, ZEBRA_NEIGH_DUPLICATE
);
1126 nbr
->detect_start_time
.tv_sec
= 0;
1127 nbr
->detect_start_time
.tv_usec
= 0;
1128 nbr
->dad_dup_detect_time
= 0;
1129 nbr
->dad_ip_auto_recovery_timer
= NULL
;
1130 ZEBRA_NEIGH_SET_ACTIVE(nbr
);
1133 if (CHECK_FLAG(nbr
->flags
, ZEBRA_NEIGH_LOCAL
)) {
1134 zebra_evpn_neigh_send_add_to_client(zevpn
->vni
, &nbr
->ip
,
1135 &nbr
->emac
, nbr
->mac
,
1136 nbr
->flags
, nbr
->loc_seq
);
1137 } else if (!!CHECK_FLAG(nbr
->flags
, ZEBRA_NEIGH_REMOTE
)) {
1138 zebra_evpn_rem_neigh_install(zevpn
, nbr
, false /*was_static*/);
1142 static void zebra_evpn_dup_addr_detect_for_neigh(
1143 struct zebra_vrf
*zvrf
, struct zebra_neigh
*nbr
, struct in_addr vtep_ip
,
1144 bool do_dad
, bool *is_dup_detect
, bool is_local
)
1147 struct timeval elapsed
= {0, 0};
1148 bool reset_params
= false;
1150 if (!zebra_evpn_do_dup_addr_detect(zvrf
))
1153 /* IP is detected as duplicate or inherit dup
1154 * state, hold on to install as remote entry
1155 * only if freeze is enabled.
1157 if (CHECK_FLAG(nbr
->flags
, ZEBRA_NEIGH_DUPLICATE
)) {
1158 if (IS_ZEBRA_DEBUG_VXLAN
)
1160 "%s: duplicate addr MAC %pEA IP %pIA flags 0x%x skip installing, learn count %u recover time %u",
1161 __func__
, &nbr
->emac
, &nbr
->ip
,
1162 nbr
->flags
, nbr
->dad_count
,
1163 zvrf
->dad_freeze_time
);
1165 if (zvrf
->dad_freeze
)
1166 *is_dup_detect
= true;
1168 /* warn-only action, neigh will be installed.
1169 * freeze action, it wil not be installed.
1177 /* Check if detection time (M-secs) expired.
1178 * Reset learn count and detection start time.
1179 * During remote mac add, count should already be 1
1180 * via local learning.
1182 monotime_since(&nbr
->detect_start_time
, &elapsed
);
1183 reset_params
= (elapsed
.tv_sec
> zvrf
->dad_time
);
1185 if (is_local
&& !reset_params
) {
1186 /* RFC-7432: A PE/VTEP that detects a MAC mobility
1187 * event via LOCAL learning starts an M-second timer.
1189 * NOTE: This is the START of the probe with count is
1190 * 0 during LOCAL learn event.
1192 reset_params
= !nbr
->dad_count
;
1196 if (IS_ZEBRA_DEBUG_VXLAN
)
1198 "%s: duplicate addr MAC %pEA IP %pIA flags 0x%x detection time passed, reset learn count %u",
1199 __func__
, &nbr
->emac
, &nbr
->ip
,
1200 nbr
->flags
, nbr
->dad_count
);
1201 /* Reset learn count but do not start detection
1202 * during REMOTE learn event.
1205 /* Start dup. addr detection (DAD) start time,
1206 * ONLY during LOCAL learn.
1209 monotime(&nbr
->detect_start_time
);
1211 } else if (!is_local
) {
1212 /* For REMOTE IP/Neigh, increment detection count
1213 * ONLY while in probe window, once window passed,
1214 * next local learn event should trigger DAD.
1219 /* For LOCAL IP/Neigh learn event, once count is reset above via either
1220 * initial/start detection time or passed the probe time, the count
1221 * needs to be incremented.
1226 if (nbr
->dad_count
>= zvrf
->dad_max_moves
) {
1228 EC_ZEBRA_DUP_IP_DETECTED
,
1229 "VNI %u: MAC %pEA IP %pIA detected as duplicate during %s VTEP %pI4",
1230 nbr
->zevpn
->vni
, &nbr
->emac
, &nbr
->ip
,
1231 is_local
? "local update, last" : "remote update, from",
1234 SET_FLAG(nbr
->flags
, ZEBRA_NEIGH_DUPLICATE
);
1236 /* Capture Duplicate detection time */
1237 nbr
->dad_dup_detect_time
= monotime(NULL
);
1239 /* Start auto recovery timer for this IP */
1240 THREAD_OFF(nbr
->dad_ip_auto_recovery_timer
);
1241 if (zvrf
->dad_freeze
&& zvrf
->dad_freeze_time
) {
1242 if (IS_ZEBRA_DEBUG_VXLAN
)
1244 "%s: duplicate addr MAC %pEA IP %pIA flags 0x%x auto recovery time %u start",
1245 __func__
, &nbr
->emac
, &nbr
->ip
,
1246 nbr
->flags
, zvrf
->dad_freeze_time
);
1248 thread_add_timer(zrouter
.master
,
1249 zebra_evpn_dad_ip_auto_recovery_exp
,
1250 nbr
, zvrf
->dad_freeze_time
,
1251 &nbr
->dad_ip_auto_recovery_timer
);
1253 if (zvrf
->dad_freeze
)
1254 *is_dup_detect
= true;
1258 int zebra_evpn_local_neigh_update(struct zebra_evpn
*zevpn
,
1259 struct interface
*ifp
,
1260 const struct ipaddr
*ip
,
1261 const struct ethaddr
*macaddr
, bool is_router
,
1262 bool local_inactive
, bool dp_static
)
1264 struct zebra_vrf
*zvrf
;
1265 struct zebra_neigh
*n
= NULL
;
1266 struct zebra_mac
*zmac
= NULL
, *old_zmac
= NULL
;
1267 uint32_t old_mac_seq
= 0, mac_new_seq
= 0;
1268 bool upd_mac_seq
= false;
1269 bool neigh_mac_change
= false;
1270 bool neigh_on_hold
= false;
1271 bool neigh_was_remote
= false;
1272 bool do_dad
= false;
1273 struct in_addr vtep_ip
= {.s_addr
= 0};
1274 bool inform_dataplane
= false;
1275 bool created
= false;
1276 bool new_static
= false;
1277 bool old_bgp_ready
= false;
1280 /* Check if the MAC exists. */
1281 zmac
= zebra_evpn_mac_lookup(zevpn
, macaddr
);
1283 /* create a dummy MAC if the MAC is not already present */
1284 if (IS_ZEBRA_DEBUG_VXLAN
)
1285 zlog_debug("AUTO MAC %pEA created for neigh %pIA on VNI %u",
1286 macaddr
, ip
, zevpn
->vni
);
1288 zmac
= zebra_evpn_mac_add_auto(zevpn
, macaddr
);
1290 zlog_debug("Failed to add MAC %pEA VNI %u", macaddr
,
1295 if (CHECK_FLAG(zmac
->flags
, ZEBRA_MAC_REMOTE
)) {
1297 * We don't change the MAC to local upon a neighbor
1298 * learn event, we wait for the explicit local MAC
1299 * learn. However, we have to compute its sequence
1300 * number in preparation for when it actually turns
1307 zvrf
= zevpn
->vxlan_if
->vrf
->info
;
1309 if (IS_ZEBRA_DEBUG_VXLAN
)
1310 zlog_debug(" Unable to find vrf for: %d",
1311 zevpn
->vxlan_if
->vrf
->vrf_id
);
1315 /* Check if the neighbor exists. */
1316 n
= zebra_evpn_neigh_lookup(zevpn
, ip
);
1318 /* New neighbor - create */
1319 n
= zebra_evpn_neigh_add(zevpn
, ip
, macaddr
, zmac
, 0);
1321 /* Set "local" forwarding info. */
1322 SET_FLAG(n
->flags
, ZEBRA_NEIGH_LOCAL
);
1323 n
->ifindex
= ifp
->ifindex
;
1326 if (CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_LOCAL
)) {
1329 bool old_local_inactive
;
1331 old_local_inactive
= !!CHECK_FLAG(
1332 n
->flags
, ZEBRA_NEIGH_LOCAL_INACTIVE
);
1334 old_bgp_ready
= zebra_evpn_neigh_is_ready_for_bgp(n
);
1336 /* Note any changes and see if of interest to BGP. */
1337 mac_different
= !!memcmp(&n
->emac
, macaddr
, ETH_ALEN
);
1339 !!CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_ROUTER_FLAG
);
1340 new_static
= zebra_evpn_neigh_is_static(n
);
1341 if (!mac_different
&& is_router
== cur_is_router
1342 && old_local_inactive
== local_inactive
1343 && dp_static
!= new_static
) {
1344 if (IS_ZEBRA_DEBUG_VXLAN
)
1346 " Ignoring entry mac is the same and is_router == cur_is_router");
1347 n
->ifindex
= ifp
->ifindex
;
1352 if (!mac_different
) {
1353 /* XXX - cleanup this code duplication */
1354 bool is_neigh_freezed
= false;
1356 /* Only the router flag has changed. */
1359 ZEBRA_NEIGH_ROUTER_FLAG
);
1361 UNSET_FLAG(n
->flags
,
1362 ZEBRA_NEIGH_ROUTER_FLAG
);
1366 ZEBRA_NEIGH_LOCAL_INACTIVE
);
1368 UNSET_FLAG(n
->flags
,
1369 ZEBRA_NEIGH_LOCAL_INACTIVE
);
1371 zebra_evpn_neigh_is_ready_for_bgp(n
);
1373 if (dp_static
!= new_static
)
1374 inform_dataplane
= true;
1376 /* Neigh is in freeze state and freeze action
1377 * is enabled, do not send update to client.
1380 (zebra_evpn_do_dup_addr_detect(zvrf
)
1382 && CHECK_FLAG(n
->flags
,
1383 ZEBRA_NEIGH_DUPLICATE
));
1385 zebra_evpn_local_neigh_update_log(
1386 "local", n
, is_router
, local_inactive
,
1387 old_bgp_ready
, new_bgp_ready
, false,
1388 false, "flag-update");
1390 if (inform_dataplane
)
1391 zebra_evpn_sync_neigh_dp_install(
1392 n
, false /* set_inactive */,
1393 false /* force_clear_static */,
1396 /* if the neigh can no longer be advertised
1397 * remove it from bgp
1399 if (!is_neigh_freezed
) {
1400 zebra_evpn_neigh_send_add_del_to_client(
1404 if (IS_ZEBRA_DEBUG_VXLAN
1405 && IS_ZEBRA_NEIGH_ACTIVE(n
))
1407 " Neighbor active and frozen");
1412 /* The MAC has changed, need to issue a delete
1413 * first as this means a different MACIP route.
1414 * Also, need to do some unlinking/relinking.
1415 * We also need to update the MAC's sequence number
1416 * in different situations.
1418 if (old_bgp_ready
) {
1419 zebra_evpn_neigh_send_del_to_client(
1420 zevpn
->vni
, &n
->ip
, &n
->emac
, n
->flags
,
1421 n
->state
, false /*force*/);
1422 old_bgp_ready
= false;
1425 old_mac_seq
= CHECK_FLAG(old_zmac
->flags
,
1428 : old_zmac
->loc_seq
;
1429 neigh_mac_change
= upd_mac_seq
= true;
1430 zebra_evpn_local_neigh_deref_mac(
1431 n
, true /* send_mac_update */);
1434 /* if mac changes abandon peer flags and tell
1435 * dataplane to clear the static flag
1437 if (zebra_evpn_neigh_clear_sync_info(n
))
1438 inform_dataplane
= true;
1439 /* Update the forwarding info. */
1440 n
->ifindex
= ifp
->ifindex
;
1442 /* Link to new MAC */
1443 zebra_evpn_local_neigh_ref_mac(
1444 n
, macaddr
, zmac
, true /* send_mac_update */);
1445 } else if (CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_REMOTE
)) {
1447 * Neighbor has moved from remote to local. Its
1448 * MAC could have also changed as part of the move.
1450 if (memcmp(n
->emac
.octet
, macaddr
->octet
, ETH_ALEN
)
1455 CHECK_FLAG(old_zmac
->flags
,
1458 : old_zmac
->loc_seq
;
1459 neigh_mac_change
= upd_mac_seq
= true;
1460 zebra_evpn_local_neigh_deref_mac(
1461 n
, true /* send_update */);
1464 /* Link to new MAC */
1465 zebra_evpn_local_neigh_ref_mac(
1466 n
, macaddr
, zmac
, true /*send_update*/);
1468 /* Based on Mobility event Scenario-B from the
1469 * draft, neigh's previous state was remote treat this
1472 neigh_was_remote
= true;
1473 vtep_ip
= n
->r_vtep_ip
;
1474 /* Mark appropriately */
1475 UNSET_FLAG(n
->flags
, ZEBRA_NEIGH_REMOTE
);
1476 n
->r_vtep_ip
.s_addr
= INADDR_ANY
;
1477 SET_FLAG(n
->flags
, ZEBRA_NEIGH_LOCAL
);
1478 n
->ifindex
= ifp
->ifindex
;
1482 /* If MAC was previously remote, or the neighbor had a different
1483 * MAC earlier, recompute the sequence number.
1486 uint32_t seq1
, seq2
;
1488 seq1
= CHECK_FLAG(zmac
->flags
, ZEBRA_MAC_REMOTE
)
1491 seq2
= neigh_mac_change
? old_mac_seq
+ 1 : 0;
1492 mac_new_seq
= zmac
->loc_seq
< MAX(seq1
, seq2
) ? MAX(seq1
, seq2
)
1497 SET_FLAG(n
->flags
, ZEBRA_NEIGH_LOCAL_INACTIVE
);
1499 UNSET_FLAG(n
->flags
, ZEBRA_NEIGH_LOCAL_INACTIVE
);
1501 /* Mark Router flag (R-bit) */
1503 SET_FLAG(n
->flags
, ZEBRA_NEIGH_ROUTER_FLAG
);
1505 UNSET_FLAG(n
->flags
, ZEBRA_NEIGH_ROUTER_FLAG
);
1507 /* if zebra and dataplane don't agree this is a sync entry
1508 * re-install in the dataplane */
1509 new_static
= zebra_evpn_neigh_is_static(n
);
1510 if (dp_static
!= new_static
)
1511 inform_dataplane
= true;
1513 /* Check old and/or new MAC detected as duplicate mark
1514 * the neigh as duplicate
1516 if (zebra_evpn_ip_inherit_dad_from_mac(zvrf
, old_zmac
, zmac
, n
)) {
1518 EC_ZEBRA_DUP_IP_INHERIT_DETECTED
,
1519 "VNI %u: MAC %pEA IP %pIA detected as duplicate during local update, inherit duplicate from MAC",
1520 zevpn
->vni
, macaddr
, &n
->ip
);
1523 /* For IP Duplicate Address Detection (DAD) is trigger,
1524 * when the event is extended mobility based on scenario-B
1525 * from the draft, IP/Neigh's MAC binding changed and
1526 * neigh's previous state was remote.
1528 if (neigh_mac_change
&& neigh_was_remote
)
1531 zebra_evpn_dup_addr_detect_for_neigh(zvrf
, n
, vtep_ip
, do_dad
,
1532 &neigh_on_hold
, true);
1534 if (inform_dataplane
)
1535 zebra_evpn_sync_neigh_dp_install(n
, false /* set_inactive */,
1536 false /* force_clear_static */,
1539 /* Before we program this in BGP, we need to check if MAC is locally
1540 * learnt. If not, force neighbor to be inactive and reset its seq.
1542 if (!CHECK_FLAG(zmac
->flags
, ZEBRA_MAC_LOCAL
)) {
1543 zebra_evpn_local_neigh_update_log(
1544 "local", n
, is_router
, local_inactive
, false, false,
1545 inform_dataplane
, false, "auto-mac");
1546 ZEBRA_NEIGH_SET_INACTIVE(n
);
1548 zmac
->loc_seq
= mac_new_seq
;
1552 zebra_evpn_local_neigh_update_log("local", n
, is_router
, local_inactive
,
1553 false, false, inform_dataplane
, true,
1554 created
? "created" : "updated");
1556 /* If the MAC's sequence number has changed, inform the MAC and all
1557 * neighbors associated with the MAC to BGP, else just inform this
1560 if (upd_mac_seq
&& zmac
->loc_seq
!= mac_new_seq
) {
1561 if (IS_ZEBRA_DEBUG_VXLAN
)
1563 "Seq changed for MAC %pEA VNI %u - old %u new %u",
1564 macaddr
, zevpn
->vni
,
1565 zmac
->loc_seq
, mac_new_seq
);
1566 zmac
->loc_seq
= mac_new_seq
;
1567 if (zebra_evpn_mac_send_add_to_client(zevpn
->vni
, macaddr
,
1569 zmac
->loc_seq
, zmac
->es
))
1571 zebra_evpn_process_neigh_on_local_mac_change(zevpn
, zmac
, 1,
1576 n
->loc_seq
= zmac
->loc_seq
;
1578 if (!neigh_on_hold
) {
1579 ZEBRA_NEIGH_SET_ACTIVE(n
);
1580 new_bgp_ready
= zebra_evpn_neigh_is_ready_for_bgp(n
);
1581 zebra_evpn_neigh_send_add_del_to_client(n
, old_bgp_ready
,
1584 if (IS_ZEBRA_DEBUG_VXLAN
)
1585 zlog_debug(" Neighbor on hold not sending");
1590 int zebra_evpn_remote_neigh_update(struct zebra_evpn
*zevpn
,
1591 struct interface
*ifp
,
1592 const struct ipaddr
*ip
,
1593 const struct ethaddr
*macaddr
,
1596 struct zebra_neigh
*n
= NULL
;
1597 struct zebra_mac
*zmac
= NULL
;
1599 /* If the neighbor is unknown, there is no further action. */
1600 n
= zebra_evpn_neigh_lookup(zevpn
, ip
);
1604 /* If a remote entry, see if it needs to be refreshed */
1605 if (CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_REMOTE
)) {
1607 if (state
& NUD_STALE
)
1608 zebra_evpn_rem_neigh_install(zevpn
, n
,
1609 false /*was_static*/);
1612 /* We got a "remote" neighbor notification for an entry
1613 * we think is local. This can happen in a multihoming
1614 * scenario - but only if the MAC is already "remote".
1615 * Just mark our entry as "remote".
1617 zmac
= zebra_evpn_mac_lookup(zevpn
, macaddr
);
1618 if (!zmac
|| !CHECK_FLAG(zmac
->flags
, ZEBRA_MAC_REMOTE
)) {
1620 "Ignore remote neigh %pIA (MAC %pEA) on L2-VNI %u - MAC unknown or local",
1621 &n
->ip
, macaddr
, zevpn
->vni
);
1625 UNSET_FLAG(n
->flags
, ZEBRA_NEIGH_ALL_LOCAL_FLAGS
);
1626 SET_FLAG(n
->flags
, ZEBRA_NEIGH_REMOTE
);
1627 ZEBRA_NEIGH_SET_ACTIVE(n
);
1628 n
->r_vtep_ip
= zmac
->fwd_info
.r_vtep_ip
;
1634 /* Notify Neighbor entries to the Client, skips the GW entry */
1636 zebra_evpn_send_neigh_hash_entry_to_client(struct hash_bucket
*bucket
,
1639 struct mac_walk_ctx
*wctx
= arg
;
1640 struct zebra_neigh
*zn
= bucket
->data
;
1641 struct zebra_mac
*zmac
= NULL
;
1643 if (CHECK_FLAG(zn
->flags
, ZEBRA_NEIGH_DEF_GW
))
1646 if (CHECK_FLAG(zn
->flags
, ZEBRA_NEIGH_LOCAL
)
1647 && IS_ZEBRA_NEIGH_ACTIVE(zn
)) {
1648 zmac
= zebra_evpn_mac_lookup(wctx
->zevpn
, &zn
->emac
);
1652 zebra_evpn_neigh_send_add_to_client(wctx
->zevpn
->vni
, &zn
->ip
,
1654 zn
->flags
, zn
->loc_seq
);
1658 /* Iterator of a specific EVPN */
1659 void zebra_evpn_send_neigh_to_client(struct zebra_evpn
*zevpn
)
1661 struct neigh_walk_ctx wctx
;
1663 memset(&wctx
, 0, sizeof(wctx
));
1666 hash_iterate(zevpn
->neigh_table
,
1667 zebra_evpn_send_neigh_hash_entry_to_client
, &wctx
);
1670 void zebra_evpn_clear_dup_neigh_hash(struct hash_bucket
*bucket
, void *ctxt
)
1672 struct neigh_walk_ctx
*wctx
= ctxt
;
1673 struct zebra_neigh
*nbr
;
1674 struct zebra_evpn
*zevpn
;
1675 char buf
[INET6_ADDRSTRLEN
];
1677 nbr
= (struct zebra_neigh
*)bucket
->data
;
1681 zevpn
= wctx
->zevpn
;
1683 if (!CHECK_FLAG(nbr
->flags
, ZEBRA_NEIGH_DUPLICATE
))
1686 if (IS_ZEBRA_DEBUG_VXLAN
) {
1687 ipaddr2str(&nbr
->ip
, buf
, sizeof(buf
));
1688 zlog_debug("%s: clear neigh %s dup state, flags 0x%x seq %u",
1689 __func__
, buf
, nbr
->flags
, nbr
->loc_seq
);
1692 UNSET_FLAG(nbr
->flags
, ZEBRA_NEIGH_DUPLICATE
);
1694 nbr
->detect_start_time
.tv_sec
= 0;
1695 nbr
->detect_start_time
.tv_usec
= 0;
1696 nbr
->dad_dup_detect_time
= 0;
1697 THREAD_OFF(nbr
->dad_ip_auto_recovery_timer
);
1699 if (CHECK_FLAG(nbr
->flags
, ZEBRA_NEIGH_LOCAL
)) {
1700 zebra_evpn_neigh_send_add_to_client(zevpn
->vni
, &nbr
->ip
,
1701 &nbr
->emac
, nbr
->mac
,
1702 nbr
->flags
, nbr
->loc_seq
);
1703 } else if (CHECK_FLAG(nbr
->flags
, ZEBRA_NEIGH_REMOTE
)) {
1704 zebra_evpn_rem_neigh_install(zevpn
, nbr
, false /*was_static*/);
1709 * Print a specific neighbor entry.
1711 void zebra_evpn_print_neigh(struct zebra_neigh
*n
, void *ctxt
,
1715 char buf1
[ETHER_ADDR_STRLEN
];
1716 char buf2
[INET6_ADDRSTRLEN
];
1717 const char *type_str
;
1718 const char *state_str
;
1719 bool flags_present
= false;
1720 struct zebra_vrf
*zvrf
= NULL
;
1721 struct timeval detect_start_time
= {0, 0};
1722 char timebuf
[MONOTIME_STRLEN
];
1723 char thread_buf
[THREAD_TIMER_STRLEN
];
1725 char up_str
[MONOTIME_STRLEN
];
1727 zvrf
= zebra_vrf_get_evpn();
1728 uptime
= monotime(NULL
);
1729 uptime
-= n
->uptime
;
1731 frrtime_to_interval(uptime
, up_str
, sizeof(up_str
));
1733 ipaddr2str(&n
->ip
, buf2
, sizeof(buf2
));
1734 prefix_mac2str(&n
->emac
, buf1
, sizeof(buf1
));
1735 type_str
= CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_LOCAL
) ? "local" : "remote";
1736 state_str
= IS_ZEBRA_NEIGH_ACTIVE(n
) ? "active" : "inactive";
1737 vty
= (struct vty
*)ctxt
;
1739 bool sync_info
= false;
1741 vty_out(vty
, "IP: %s\n",
1742 ipaddr2str(&n
->ip
, buf2
, sizeof(buf2
)));
1743 vty_out(vty
, " Type: %s\n", type_str
);
1744 vty_out(vty
, " State: %s\n", state_str
);
1745 vty_out(vty
, " Uptime: %s\n", up_str
);
1746 vty_out(vty
, " MAC: %s\n",
1747 prefix_mac2str(&n
->emac
, buf1
, sizeof(buf1
)));
1748 vty_out(vty
, " Sync-info:");
1749 if (CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_LOCAL_INACTIVE
)) {
1750 vty_out(vty
, " local-inactive");
1753 if (CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_ES_PEER_PROXY
)) {
1754 vty_out(vty
, " peer-proxy");
1757 if (CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_ES_PEER_ACTIVE
)) {
1758 vty_out(vty
, " peer-active");
1761 if (n
->hold_timer
) {
1762 vty_out(vty
, " (ht: %s)",
1763 thread_timer_to_hhmmss(thread_buf
,
1772 json_object_string_add(json
, "uptime", up_str
);
1773 json_object_string_add(json
, "ip", buf2
);
1774 json_object_string_add(json
, "type", type_str
);
1775 json_object_string_add(json
, "state", state_str
);
1776 json_object_string_add(json
, "mac", buf1
);
1777 if (CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_LOCAL_INACTIVE
))
1778 json_object_boolean_true_add(json
, "localInactive");
1779 if (CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_ES_PEER_PROXY
))
1780 json_object_boolean_true_add(json
, "peerProxy");
1781 if (CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_ES_PEER_ACTIVE
))
1782 json_object_boolean_true_add(json
, "peerActive");
1784 json_object_string_add(
1785 json
, "peerActiveHold",
1786 thread_timer_to_hhmmss(thread_buf
,
1790 if (CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_REMOTE
)) {
1793 json_object_string_add(json
, "remoteEs",
1794 n
->mac
->es
->esi_str
);
1796 vty_out(vty
, " Remote ES: %s\n",
1797 n
->mac
->es
->esi_str
);
1800 json_object_string_addf(json
, "remoteVtep",
1801 "%pI4", &n
->r_vtep_ip
);
1803 vty_out(vty
, " Remote VTEP: %pI4\n",
1807 if (CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_DEF_GW
)) {
1809 vty_out(vty
, " Flags: Default-gateway");
1810 flags_present
= true;
1812 json_object_boolean_true_add(json
, "defaultGateway");
1814 if (CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_ROUTER_FLAG
)) {
1817 flags_present
? " ,Router" : " Flags: Router");
1818 flags_present
= true;
1824 vty_out(vty
, " Local Seq: %u Remote Seq: %u\n", n
->loc_seq
,
1827 if (CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_DUPLICATE
)) {
1828 vty_out(vty
, " Duplicate, detected at %s",
1829 time_to_string(n
->dad_dup_detect_time
,
1831 } else if (n
->dad_count
) {
1832 monotime_since(&n
->detect_start_time
,
1833 &detect_start_time
);
1834 if (detect_start_time
.tv_sec
<= zvrf
->dad_time
) {
1835 time_to_string(n
->detect_start_time
.tv_sec
,
1838 " Duplicate detection started at %s, detection count %u\n",
1839 timebuf
, n
->dad_count
);
1843 json_object_int_add(json
, "localSequence", n
->loc_seq
);
1844 json_object_int_add(json
, "remoteSequence", n
->rem_seq
);
1845 json_object_int_add(json
, "detectionCount", n
->dad_count
);
1846 if (CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_DUPLICATE
))
1847 json_object_boolean_true_add(json
, "isDuplicate");
1849 json_object_boolean_false_add(json
, "isDuplicate");
1853 void zebra_evpn_print_neigh_hdr(struct vty
*vty
, struct neigh_walk_ctx
*wctx
)
1855 vty_out(vty
, "Flags: I=local-inactive, P=peer-active, X=peer-proxy\n");
1856 vty_out(vty
, "%*s %-6s %-5s %-8s %-17s %-30s %s\n", -wctx
->addr_width
,
1857 "Neighbor", "Type", "Flags", "State", "MAC", "Remote ES/VTEP",
1861 static char *zebra_evpn_print_neigh_flags(struct zebra_neigh
*n
,
1863 uint32_t flags_buf_sz
)
1865 snprintf(flags_buf
, flags_buf_sz
, "%s%s%s",
1866 (n
->flags
& ZEBRA_NEIGH_ES_PEER_ACTIVE
) ?
1868 (n
->flags
& ZEBRA_NEIGH_ES_PEER_PROXY
) ?
1870 (n
->flags
& ZEBRA_NEIGH_LOCAL_INACTIVE
) ?
1877 * Print neighbor hash entry - called for display of all neighbors.
1879 void zebra_evpn_print_neigh_hash(struct hash_bucket
*bucket
, void *ctxt
)
1882 json_object
*json_evpn
= NULL
, *json_row
= NULL
;
1883 struct zebra_neigh
*n
;
1884 char buf1
[ETHER_ADDR_STRLEN
];
1885 char buf2
[INET6_ADDRSTRLEN
];
1886 char addr_buf
[PREFIX_STRLEN
];
1887 struct neigh_walk_ctx
*wctx
= ctxt
;
1888 const char *state_str
;
1892 json_evpn
= wctx
->json
;
1893 n
= (struct zebra_neigh
*)bucket
->data
;
1896 json_row
= json_object_new_object();
1898 prefix_mac2str(&n
->emac
, buf1
, sizeof(buf1
));
1899 ipaddr2str(&n
->ip
, buf2
, sizeof(buf2
));
1900 state_str
= IS_ZEBRA_NEIGH_ACTIVE(n
) ? "active" : "inactive";
1901 if (CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_LOCAL
)) {
1902 if (wctx
->flags
& SHOW_REMOTE_NEIGH_FROM_VTEP
)
1905 if (json_evpn
== NULL
) {
1906 vty_out(vty
, "%*s %-6s %-5s %-8s %-17s %-30s %u/%u\n",
1907 -wctx
->addr_width
, buf2
, "local",
1908 zebra_evpn_print_neigh_flags(n
, flags_buf
,
1909 sizeof(flags_buf
)), state_str
, buf1
,
1910 "", n
->loc_seq
, n
->rem_seq
);
1912 json_object_string_add(json_row
, "type", "local");
1913 json_object_string_add(json_row
, "state", state_str
);
1914 json_object_string_add(json_row
, "mac", buf1
);
1915 if (CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_DEF_GW
))
1916 json_object_boolean_true_add(json_row
,
1918 json_object_int_add(json_row
, "localSequence",
1920 json_object_int_add(json_row
, "remoteSequence",
1922 json_object_int_add(json_row
, "detectionCount",
1924 if (CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_DUPLICATE
))
1925 json_object_boolean_true_add(json_row
,
1928 json_object_boolean_false_add(json_row
,
1932 } else if (CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_REMOTE
)) {
1933 if ((wctx
->flags
& SHOW_REMOTE_NEIGH_FROM_VTEP
)
1934 && !IPV4_ADDR_SAME(&n
->r_vtep_ip
, &wctx
->r_vtep_ip
))
1937 if (json_evpn
== NULL
) {
1938 if ((wctx
->flags
& SHOW_REMOTE_NEIGH_FROM_VTEP
)
1939 && (wctx
->count
== 0))
1940 zebra_evpn_print_neigh_hdr(vty
, wctx
);
1942 if (n
->mac
->es
== NULL
)
1943 inet_ntop(AF_INET
, &n
->r_vtep_ip
,
1944 addr_buf
, sizeof(addr_buf
));
1946 vty_out(vty
, "%*s %-6s %-5s %-8s %-17s %-30s %u/%u\n",
1947 -wctx
->addr_width
, buf2
, "remote",
1948 zebra_evpn_print_neigh_flags(n
, flags_buf
,
1949 sizeof(flags_buf
)), state_str
, buf1
,
1950 n
->mac
->es
? n
->mac
->es
->esi_str
: addr_buf
,
1951 n
->loc_seq
, n
->rem_seq
);
1953 json_object_string_add(json_row
, "type", "remote");
1954 json_object_string_add(json_row
, "state", state_str
);
1955 json_object_string_add(json_row
, "mac", buf1
);
1957 json_object_string_add(json_row
, "remoteEs",
1958 n
->mac
->es
->esi_str
);
1960 json_object_string_addf(json_row
, "remoteVtep",
1961 "%pI4", &n
->r_vtep_ip
);
1962 if (CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_DEF_GW
))
1963 json_object_boolean_true_add(json_row
,
1965 json_object_int_add(json_row
, "localSequence",
1967 json_object_int_add(json_row
, "remoteSequence",
1969 json_object_int_add(json_row
, "detectionCount",
1971 if (CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_DUPLICATE
))
1972 json_object_boolean_true_add(json_row
,
1975 json_object_boolean_false_add(json_row
,
1982 json_object_object_add(json_evpn
, buf2
, json_row
);
1986 * Print neighbor hash entry in detail - called for display of all neighbors.
1988 void zebra_evpn_print_neigh_hash_detail(struct hash_bucket
*bucket
, void *ctxt
)
1991 json_object
*json_evpn
= NULL
, *json_row
= NULL
;
1992 struct zebra_neigh
*n
;
1993 char buf
[INET6_ADDRSTRLEN
];
1994 struct neigh_walk_ctx
*wctx
= ctxt
;
1997 json_evpn
= wctx
->json
;
1998 n
= (struct zebra_neigh
*)bucket
->data
;
2002 ipaddr2str(&n
->ip
, buf
, sizeof(buf
));
2004 json_row
= json_object_new_object();
2006 zebra_evpn_print_neigh(n
, vty
, json_row
);
2009 json_object_object_add(json_evpn
, buf
, json_row
);
2012 void zebra_evpn_print_dad_neigh_hash(struct hash_bucket
*bucket
, void *ctxt
)
2014 struct zebra_neigh
*nbr
;
2016 nbr
= (struct zebra_neigh
*)bucket
->data
;
2020 if (CHECK_FLAG(nbr
->flags
, ZEBRA_NEIGH_DUPLICATE
))
2021 zebra_evpn_print_neigh_hash(bucket
, ctxt
);
2024 void zebra_evpn_print_dad_neigh_hash_detail(struct hash_bucket
*bucket
,
2027 struct zebra_neigh
*nbr
;
2029 nbr
= (struct zebra_neigh
*)bucket
->data
;
2033 if (CHECK_FLAG(nbr
->flags
, ZEBRA_NEIGH_DUPLICATE
))
2034 zebra_evpn_print_neigh_hash_detail(bucket
, ctxt
);
2037 void zebra_evpn_neigh_remote_macip_add(struct zebra_evpn
*zevpn
,
2038 struct zebra_vrf
*zvrf
,
2039 const struct ipaddr
*ipaddr
,
2040 struct zebra_mac
*mac
,
2041 struct in_addr vtep_ip
, uint8_t flags
,
2044 struct zebra_neigh
*n
;
2045 int update_neigh
= 0;
2046 struct zebra_mac
*old_mac
= NULL
;
2047 bool old_static
= false;
2048 bool do_dad
= false;
2049 bool is_dup_detect
= false;
2053 is_router
= !!CHECK_FLAG(flags
, ZEBRA_MACIP_TYPE_ROUTER_FLAG
);
2055 /* Check if the remote neighbor itself is unknown or has a
2056 * change. If so, create or update and then install the entry.
2058 n
= zebra_evpn_neigh_lookup(zevpn
, ipaddr
);
2059 if (!n
|| !CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_REMOTE
)
2060 || is_router
!= !!CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_ROUTER_FLAG
)
2061 || (memcmp(&n
->emac
, &mac
->macaddr
, sizeof(struct ethaddr
)) != 0)
2062 || !IPV4_ADDR_SAME(&n
->r_vtep_ip
, &vtep_ip
) || seq
!= n
->rem_seq
)
2067 n
= zebra_evpn_neigh_add(zevpn
, ipaddr
, &mac
->macaddr
,
2070 /* When host moves but changes its (MAC,IP)
2071 * binding, BGP may install a MACIP entry that
2072 * corresponds to "older" location of the host
2073 * in transient situations (because {IP1,M1}
2074 * is a different route from {IP1,M2}). Check
2075 * the sequence number and ignore this update
2079 if (!zebra_evpn_neigh_is_bgp_seq_ok(
2080 zevpn
, n
, &mac
->macaddr
, seq
, false))
2082 if (CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_LOCAL
)) {
2083 old_static
= zebra_evpn_neigh_is_static(n
);
2084 if (IS_ZEBRA_DEBUG_EVPN_MH_NEIGH
)
2086 "sync->remote neigh vni %u ip %pIA mac %pEA seq %d f0x%x",
2087 n
->zevpn
->vni
, &n
->ip
, &n
->emac
,
2089 if (IS_ZEBRA_NEIGH_ACTIVE(n
))
2090 zebra_evpn_neigh_send_del_to_client(
2091 zevpn
->vni
, &n
->ip
, &n
->emac
,
2094 zebra_evpn_neigh_clear_sync_info(n
);
2096 if (memcmp(&n
->emac
, &mac
->macaddr
,
2097 sizeof(struct ethaddr
))
2099 /* update neigh list for macs */
2101 zebra_evpn_mac_lookup(zevpn
, &n
->emac
);
2103 listnode_delete(old_mac
->neigh_list
, n
);
2105 zebra_evpn_deref_ip2mac(zevpn
, old_mac
);
2108 listnode_add_sort(mac
->neigh_list
, n
);
2109 memcpy(&n
->emac
, &mac
->macaddr
, ETH_ALEN
);
2111 /* Check Neigh's curent state is local
2112 * (this is the case where neigh/host has moved
2113 * from L->R) and check previous detction
2114 * started via local learning.
2116 * RFC-7432: A PE/VTEP that detects a MAC
2117 * mobilit event via local learning starts
2118 * an M-second timer.
2119 * VTEP-IP or seq. change along is not
2120 * considered for dup. detection.
2122 * Mobilty event scenario-B IP-MAC binding
2125 if ((!CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_REMOTE
))
2131 /* Set "remote" forwarding info. */
2132 UNSET_FLAG(n
->flags
, ZEBRA_NEIGH_ALL_LOCAL_FLAGS
);
2133 n
->r_vtep_ip
= vtep_ip
;
2134 SET_FLAG(n
->flags
, ZEBRA_NEIGH_REMOTE
);
2136 /* Set router flag (R-bit) to this Neighbor entry */
2137 if (CHECK_FLAG(flags
, ZEBRA_MACIP_TYPE_ROUTER_FLAG
))
2138 SET_FLAG(n
->flags
, ZEBRA_NEIGH_ROUTER_FLAG
);
2140 UNSET_FLAG(n
->flags
, ZEBRA_NEIGH_ROUTER_FLAG
);
2142 /* Check old or new MAC detected as duplicate,
2143 * inherit duplicate flag to this neigh.
2145 if (zebra_evpn_ip_inherit_dad_from_mac(zvrf
, old_mac
, mac
, n
)) {
2147 EC_ZEBRA_DUP_IP_INHERIT_DETECTED
,
2148 "VNI %u: MAC %pEA IP %pIA detected as duplicate during remote update, inherit duplicate from MAC",
2149 zevpn
->vni
, &mac
->macaddr
, &n
->ip
);
2152 /* Check duplicate address detection for IP */
2153 zebra_evpn_dup_addr_detect_for_neigh(
2154 zvrf
, n
, n
->r_vtep_ip
, do_dad
, &is_dup_detect
, false);
2155 /* Install the entry. */
2157 zebra_evpn_rem_neigh_install(zevpn
, n
, old_static
);
2160 /* Update seq number. */
2164 int zebra_evpn_neigh_gw_macip_add(struct interface
*ifp
,
2165 struct zebra_evpn
*zevpn
, struct ipaddr
*ip
,
2166 struct zebra_mac
*mac
)
2168 struct zebra_neigh
*n
;
2172 n
= zebra_evpn_neigh_lookup(zevpn
, ip
);
2174 n
= zebra_evpn_neigh_add(zevpn
, ip
, &mac
->macaddr
, mac
, 0);
2176 /* Set "local" forwarding info. */
2177 SET_FLAG(n
->flags
, ZEBRA_NEIGH_LOCAL
);
2178 ZEBRA_NEIGH_SET_ACTIVE(n
);
2179 memcpy(&n
->emac
, &mac
->macaddr
, ETH_ALEN
);
2180 n
->ifindex
= ifp
->ifindex
;
2182 /* Only advertise in BGP if the knob is enabled */
2183 if (advertise_gw_macip_enabled(zevpn
)) {
2185 SET_FLAG(n
->flags
, ZEBRA_NEIGH_DEF_GW
);
2186 /* Set Router flag (R-bit) */
2187 if (ip
->ipa_type
== IPADDR_V6
)
2188 SET_FLAG(n
->flags
, ZEBRA_NEIGH_ROUTER_FLAG
);
2190 if (IS_ZEBRA_DEBUG_VXLAN
)
2192 "SVI %s(%u) L2-VNI %u, sending GW MAC %pEA IP %pIA add to BGP with flags 0x%x",
2193 ifp
->name
, ifp
->ifindex
, zevpn
->vni
,
2194 &mac
->macaddr
, ip
, n
->flags
);
2196 zebra_evpn_neigh_send_add_to_client(
2197 zevpn
->vni
, ip
, &n
->emac
, n
->mac
, n
->flags
, n
->loc_seq
);
2198 } else if (advertise_svi_macip_enabled(zevpn
)) {
2200 SET_FLAG(n
->flags
, ZEBRA_NEIGH_SVI_IP
);
2201 if (IS_ZEBRA_DEBUG_VXLAN
)
2203 "SVI %s(%u) L2-VNI %u, sending SVI MAC %pEA IP %pIA add to BGP with flags 0x%x",
2204 ifp
->name
, ifp
->ifindex
, zevpn
->vni
,
2205 &mac
->macaddr
, ip
, n
->flags
);
2207 zebra_evpn_neigh_send_add_to_client(
2208 zevpn
->vni
, ip
, &n
->emac
, n
->mac
, n
->flags
, n
->loc_seq
);
2214 void zebra_evpn_neigh_remote_uninstall(struct zebra_evpn
*zevpn
,
2215 struct zebra_vrf
*zvrf
,
2216 struct zebra_neigh
*n
,
2217 struct zebra_mac
*mac
,
2218 const struct ipaddr
*ipaddr
)
2220 if (zvrf
->dad_freeze
&& CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_DUPLICATE
)
2221 && CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_REMOTE
)
2222 && (memcmp(n
->emac
.octet
, mac
->macaddr
.octet
, ETH_ALEN
) == 0)) {
2223 struct interface
*vlan_if
;
2225 vlan_if
= zevpn_map_to_svi(zevpn
);
2226 if (IS_ZEBRA_DEBUG_VXLAN
)
2228 "%s: IP %pIA (flags 0x%x intf %s) is remote and duplicate, read kernel for local entry",
2229 __func__
, ipaddr
, n
->flags
,
2230 vlan_if
? vlan_if
->name
: "Unknown");
2232 neigh_read_specific_ip(ipaddr
, vlan_if
);
2235 /* When the MAC changes for an IP, it is possible the
2236 * client may update the new MAC before trying to delete the
2237 * "old" neighbor (as these are two different MACIP routes).
2238 * Do the delete only if the MAC matches.
2240 if (!memcmp(n
->emac
.octet
, mac
->macaddr
.octet
, ETH_ALEN
)) {
2241 if (CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_LOCAL
)) {
2242 zebra_evpn_sync_neigh_del(n
);
2243 } else if (CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_REMOTE
)) {
2244 zebra_evpn_neigh_uninstall(zevpn
, n
);
2245 zebra_evpn_neigh_del(zevpn
, n
);
2246 zebra_evpn_deref_ip2mac(zevpn
, mac
);
2249 if (IS_ZEBRA_DEBUG_VXLAN
)
2251 "%s: IP %pIA MAC %pEA (flags 0x%x) found doesn't match MAC %pEA, ignoring Neigh DEL",
2252 __func__
, ipaddr
, &n
->emac
, n
->flags
,
2257 int zebra_evpn_neigh_del_ip(struct zebra_evpn
*zevpn
, const struct ipaddr
*ip
)
2259 struct zebra_neigh
*n
;
2260 struct zebra_mac
*zmac
;
2263 struct zebra_vrf
*zvrf
;
2265 /* If entry doesn't exist, nothing to do. */
2266 n
= zebra_evpn_neigh_lookup(zevpn
, ip
);
2270 zmac
= zebra_evpn_mac_lookup(zevpn
, &n
->emac
);
2272 if (IS_ZEBRA_DEBUG_VXLAN
)
2274 "Trying to del a neigh %pIA without a mac %pEA on VNI %u",
2281 /* If it is a remote entry, the kernel has aged this out or someone has
2282 * deleted it, it needs to be re-installed as FRR is the owner.
2284 if (CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_REMOTE
)) {
2285 zebra_evpn_rem_neigh_install(zevpn
, n
, false /*was_static*/);
2289 /* if this is a sync entry it cannot be dropped re-install it in
2292 old_bgp_ready
= zebra_evpn_neigh_is_ready_for_bgp(n
);
2293 if (zebra_evpn_neigh_is_static(n
)) {
2294 if (IS_ZEBRA_DEBUG_EVPN_MH_NEIGH
)
2295 zlog_debug("re-add sync neigh vni %u ip %pIA mac %pEA 0x%x",
2296 n
->zevpn
->vni
, &n
->ip
, &n
->emac
,
2299 if (!CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_LOCAL_INACTIVE
))
2300 SET_FLAG(n
->flags
, ZEBRA_NEIGH_LOCAL_INACTIVE
);
2301 /* inform-bgp about change in local-activity if any */
2302 new_bgp_ready
= zebra_evpn_neigh_is_ready_for_bgp(n
);
2303 zebra_evpn_neigh_send_add_del_to_client(n
, old_bgp_ready
,
2306 /* re-install the entry in the kernel */
2307 zebra_evpn_sync_neigh_dp_install(n
, false /* set_inactive */,
2308 false /* force_clear_static */,
2314 zvrf
= zevpn
->vxlan_if
->vrf
->info
;
2316 zlog_debug("%s: VNI %u vrf lookup failed.", __func__
,
2321 /* In case of feeze action, if local neigh is in duplicate state,
2322 * Mark the Neigh as inactive before sending delete request to BGPd,
2323 * If BGPd has remote entry, it will re-install
2325 if (zvrf
->dad_freeze
&& CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_DUPLICATE
))
2326 ZEBRA_NEIGH_SET_INACTIVE(n
);
2328 /* Remove neighbor from BGP. */
2329 zebra_evpn_neigh_send_del_to_client(zevpn
->vni
, &n
->ip
, &n
->emac
,
2333 /* Delete this neighbor entry. */
2334 zebra_evpn_neigh_del(zevpn
, n
);
2336 /* see if the AUTO mac needs to be deleted */
2337 if (CHECK_FLAG(zmac
->flags
, ZEBRA_MAC_AUTO
)
2338 && !zebra_evpn_mac_in_use(zmac
))
2339 zebra_evpn_mac_del(zevpn
, zmac
);