1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Zebra EVPN Neighbor code
4 * Copyright (C) 2016, 2017 Cumulus Networks, Inc.
10 #include "interface.h"
17 #include "zebra/zserv.h"
18 #include "zebra/debug.h"
19 #include "zebra/zebra_router.h"
21 #include "zebra/zebra_errors.h"
22 #include "zebra/zebra_vrf.h"
23 #include "zebra/zebra_vxlan.h"
24 #include "zebra/zebra_vxlan_if.h"
25 #include "zebra/zebra_evpn.h"
26 #include "zebra/zebra_evpn_mh.h"
27 #include "zebra/zebra_evpn_neigh.h"
28 #include "zebra/zebra_evpn_mac.h"
30 DEFINE_MTYPE_STATIC(ZEBRA
, NEIGH
, "EVI Neighbor");
33 * Make hash key for neighbors.
35 static unsigned int neigh_hash_keymake(const void *p
)
37 const struct zebra_neigh
*n
= p
;
38 const struct ipaddr
*ip
= &n
->ip
;
41 return jhash_1word(ip
->ipaddr_v4
.s_addr
, 0);
43 return jhash2(ip
->ipaddr_v6
.s6_addr32
,
44 array_size(ip
->ipaddr_v6
.s6_addr32
), 0);
48 * Compare two neighbor hash structures.
50 static bool neigh_cmp(const void *p1
, const void *p2
)
52 const struct zebra_neigh
*n1
= p1
;
53 const struct zebra_neigh
*n2
= p2
;
55 if (n1
== NULL
&& n2
== NULL
)
58 if (n1
== NULL
|| n2
== NULL
)
61 return ipaddr_cmp(&n1
->ip
, &n2
->ip
) == 0;
64 int neigh_list_cmp(void *p1
, void *p2
)
66 const struct zebra_neigh
*n1
= p1
;
67 const struct zebra_neigh
*n2
= p2
;
69 return ipaddr_cmp(&n1
->ip
, &n2
->ip
);
72 struct hash
*zebra_neigh_db_create(const char *desc
)
74 return hash_create_size(8, neigh_hash_keymake
, neigh_cmp
, desc
);
77 uint32_t num_dup_detected_neighs(struct zebra_evpn
*zevpn
)
80 uint32_t num_neighs
= 0;
82 struct hash_bucket
*hb
;
83 struct zebra_neigh
*nbr
;
85 hash
= zevpn
->neigh_table
;
88 for (i
= 0; i
< hash
->size
; i
++) {
89 for (hb
= hash
->index
[i
]; hb
; hb
= hb
->next
) {
90 nbr
= (struct zebra_neigh
*)hb
->data
;
91 if (CHECK_FLAG(nbr
->flags
, ZEBRA_NEIGH_DUPLICATE
))
100 * Helper function to determine maximum width of neighbor IP address for
101 * display - just because we're dealing with IPv6 addresses that can
104 void zebra_evpn_find_neigh_addr_width(struct hash_bucket
*bucket
, void *ctxt
)
106 struct zebra_neigh
*n
;
107 char buf
[INET6_ADDRSTRLEN
];
108 struct neigh_walk_ctx
*wctx
= ctxt
;
111 n
= (struct zebra_neigh
*)bucket
->data
;
113 ipaddr2str(&n
->ip
, buf
, sizeof(buf
));
115 if (width
> wctx
->addr_width
)
116 wctx
->addr_width
= width
;
120 * Count of remote neighbors referencing this MAC.
122 int remote_neigh_count(struct zebra_mac
*zmac
)
124 struct zebra_neigh
*n
= NULL
;
125 struct listnode
*node
= NULL
;
128 for (ALL_LIST_ELEMENTS_RO(zmac
->neigh_list
, node
, n
)) {
129 if (CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_REMOTE
))
137 * Install remote neighbor into the kernel.
139 int zebra_evpn_rem_neigh_install(struct zebra_evpn
*zevpn
,
140 struct zebra_neigh
*n
, bool was_static
)
142 struct interface
*vlan_if
;
146 if (!(n
->flags
& ZEBRA_NEIGH_REMOTE
))
149 vlan_if
= zevpn_map_to_svi(zevpn
);
153 flags
= DPLANE_NTF_EXT_LEARNED
;
154 if (n
->flags
& ZEBRA_NEIGH_ROUTER_FLAG
)
155 flags
|= DPLANE_NTF_ROUTER
;
156 ZEBRA_NEIGH_SET_ACTIVE(n
);
158 dplane_rem_neigh_add(vlan_if
, &n
->ip
, &n
->emac
, flags
, was_static
);
164 * Install neighbor hash entry - called upon access VLAN change.
166 void zebra_evpn_install_neigh_hash(struct hash_bucket
*bucket
, void *ctxt
)
168 struct zebra_neigh
*n
;
169 struct neigh_walk_ctx
*wctx
= ctxt
;
171 n
= (struct zebra_neigh
*)bucket
->data
;
173 if (CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_REMOTE
))
174 zebra_evpn_rem_neigh_install(wctx
->zevpn
, n
,
175 false /*was_static*/);
179 * Callback to allocate neighbor hash entry.
181 static void *zebra_evpn_neigh_alloc(void *p
)
183 const struct zebra_neigh
*tmp_n
= p
;
184 struct zebra_neigh
*n
;
186 n
= XCALLOC(MTYPE_NEIGH
, sizeof(struct zebra_neigh
));
192 static void zebra_evpn_local_neigh_ref_mac(struct zebra_neigh
*n
,
193 const struct ethaddr
*macaddr
,
194 struct zebra_mac
*mac
,
195 bool send_mac_update
)
200 memcpy(&n
->emac
, macaddr
, ETH_ALEN
);
203 /* Link to new MAC */
207 listnode_add_sort(mac
->neigh_list
, n
);
208 if (n
->flags
& ZEBRA_NEIGH_ALL_PEER_FLAGS
) {
209 old_static
= zebra_evpn_mac_is_static(mac
);
210 ++mac
->sync_neigh_cnt
;
211 new_static
= zebra_evpn_mac_is_static(mac
);
212 if (IS_ZEBRA_DEBUG_EVPN_MH_NEIGH
)
214 "sync-neigh ref mac vni %u ip %pIA mac %pEA ref %d",
215 n
->zevpn
->vni
, &n
->ip
, &n
->emac
,
216 mac
->sync_neigh_cnt
);
217 if ((old_static
!= new_static
) && send_mac_update
)
218 /* program the local mac in the kernel */
219 zebra_evpn_sync_mac_dp_install(
220 mac
, false /*set_inactive*/,
221 false /*force_clear_static*/, __func__
);
225 /* sync-path that is active on an ES peer */
226 static void zebra_evpn_sync_neigh_dp_install(struct zebra_neigh
*n
,
228 bool force_clear_static
,
231 struct zebra_ns
*zns
;
232 struct interface
*ifp
;
236 zns
= zebra_ns_lookup(NS_DEFAULT
);
237 ifp
= if_lookup_by_index_per_ns(zns
, n
->ifindex
);
239 if (IS_ZEBRA_DEBUG_EVPN_MH_NEIGH
)
241 "%s: dp-install sync-neigh vni %u ip %pIA mac %pEA if %d f 0x%x skipped",
242 caller
, n
->zevpn
->vni
, &n
->ip
, &n
->emac
,
243 n
->ifindex
, n
->flags
);
247 if (force_clear_static
)
250 set_static
= zebra_evpn_neigh_is_static(n
);
252 set_router
= !!CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_ROUTER_FLAG
);
254 /* XXX - this will change post integration with the new kernel */
255 if (CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_LOCAL_INACTIVE
))
258 if (IS_ZEBRA_DEBUG_EVPN_MH_NEIGH
)
260 "%s: dp-install sync-neigh vni %u ip %pIA mac %pEA if %s(%d) f 0x%x%s%s%s",
261 caller
, n
->zevpn
->vni
, &n
->ip
, &n
->emac
,
262 ifp
->name
, n
->ifindex
, n
->flags
,
263 set_router
? " router" : "",
264 set_static
? " static" : "",
265 set_inactive
? " inactive" : "");
266 dplane_local_neigh_add(ifp
, &n
->ip
, &n
->emac
, set_router
, set_static
,
271 * Inform BGP about local neighbor addition.
273 int zebra_evpn_neigh_send_add_to_client(vni_t vni
, const struct ipaddr
*ip
,
274 const struct ethaddr
*macaddr
,
275 struct zebra_mac
*zmac
,
276 uint32_t neigh_flags
, uint32_t seq
)
280 if (CHECK_FLAG(neigh_flags
, ZEBRA_NEIGH_LOCAL_INACTIVE
)) {
281 /* host reachability has not been verified locally */
283 /* if no ES peer is claiming reachability we can't advertise
286 if (!CHECK_FLAG(neigh_flags
, ZEBRA_NEIGH_ES_PEER_ACTIVE
))
289 /* ES peers are claiming reachability; we will
290 * advertise the entry but with a proxy flag
292 SET_FLAG(flags
, ZEBRA_MACIP_TYPE_PROXY_ADVERT
);
295 if (CHECK_FLAG(neigh_flags
, ZEBRA_NEIGH_DEF_GW
))
296 SET_FLAG(flags
, ZEBRA_MACIP_TYPE_GW
);
297 /* Set router flag (R-bit) based on local neigh entry add */
298 if (CHECK_FLAG(neigh_flags
, ZEBRA_NEIGH_ROUTER_FLAG
))
299 SET_FLAG(flags
, ZEBRA_MACIP_TYPE_ROUTER_FLAG
);
300 if (CHECK_FLAG(neigh_flags
, ZEBRA_NEIGH_SVI_IP
))
301 SET_FLAG(flags
, ZEBRA_MACIP_TYPE_SVI_IP
);
303 return zebra_evpn_macip_send_msg_to_client(vni
, macaddr
, ip
, flags
, seq
,
304 ZEBRA_NEIGH_ACTIVE
, zmac
->es
,
309 * Inform BGP about local neighbor deletion.
311 int zebra_evpn_neigh_send_del_to_client(vni_t vni
, struct ipaddr
*ip
,
312 struct ethaddr
*macaddr
, uint32_t flags
,
313 int state
, bool force
)
316 if (CHECK_FLAG(flags
, ZEBRA_NEIGH_LOCAL_INACTIVE
)
317 && !CHECK_FLAG(flags
, ZEBRA_NEIGH_ES_PEER_ACTIVE
))
318 /* the neigh was not advertised - nothing to delete */
322 return zebra_evpn_macip_send_msg_to_client(
323 vni
, macaddr
, ip
, flags
, 0, state
, NULL
, ZEBRA_MACIP_DEL
);
326 static void zebra_evpn_neigh_send_add_del_to_client(struct zebra_neigh
*n
,
331 zebra_evpn_neigh_send_add_to_client(n
->zevpn
->vni
, &n
->ip
,
332 &n
->emac
, n
->mac
, n
->flags
,
334 else if (old_bgp_ready
)
335 zebra_evpn_neigh_send_del_to_client(n
->zevpn
->vni
, &n
->ip
,
337 n
->state
, true /*force*/);
340 /* if the static flag associated with the neigh changes we need
341 * to update the sync-neigh references against the MAC
342 * and inform the dataplane about the static flag changes.
344 void zebra_evpn_sync_neigh_static_chg(struct zebra_neigh
*n
, bool old_n_static
,
345 bool new_n_static
, bool defer_n_dp
,
346 bool defer_mac_dp
, const char *caller
)
348 struct zebra_mac
*mac
= n
->mac
;
352 if (old_n_static
== new_n_static
)
355 /* update the neigh sync references in the dataplane. if
356 * the neigh is in the middle of updates the caller can
357 * request for a defer
360 zebra_evpn_sync_neigh_dp_install(n
, false /* set_inactive */,
361 false /* force_clear_static */,
367 /* update the mac sync ref cnt */
368 old_mac_static
= zebra_evpn_mac_is_static(mac
);
370 ++mac
->sync_neigh_cnt
;
371 } else if (old_n_static
) {
372 if (mac
->sync_neigh_cnt
)
373 --mac
->sync_neigh_cnt
;
375 new_mac_static
= zebra_evpn_mac_is_static(mac
);
377 /* update the mac sync references in the dataplane */
378 if ((old_mac_static
!= new_mac_static
) && !defer_mac_dp
)
379 zebra_evpn_sync_mac_dp_install(mac
, false /* set_inactive */,
380 false /* force_clear_static */,
383 if (IS_ZEBRA_DEBUG_EVPN_MH_NEIGH
)
385 "sync-neigh ref-chg vni %u ip %pIA mac %pEA f 0x%x %d%s%s%s%s by %s",
386 n
->zevpn
->vni
, &n
->ip
, &n
->emac
, n
->flags
,
388 old_n_static
? " old_n_static" : "",
389 new_n_static
? " new_n_static" : "",
390 old_mac_static
? " old_mac_static" : "",
391 new_mac_static
? " new_mac_static" : "", caller
);
394 /* Neigh hold timer is used to age out peer-active flag.
396 * During this wait time we expect the dataplane component or an
397 * external neighmgr daemon to probe existing hosts to independently
398 * establish their presence on the ES.
400 static void zebra_evpn_neigh_hold_exp_cb(struct thread
*t
)
402 struct zebra_neigh
*n
;
409 /* the purpose of the hold timer is to age out the peer-active
412 if (!CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_ES_PEER_ACTIVE
))
415 old_bgp_ready
= zebra_evpn_neigh_is_ready_for_bgp(n
);
416 old_n_static
= zebra_evpn_neigh_is_static(n
);
417 UNSET_FLAG(n
->flags
, ZEBRA_NEIGH_ES_PEER_ACTIVE
);
418 new_bgp_ready
= zebra_evpn_neigh_is_ready_for_bgp(n
);
419 new_n_static
= zebra_evpn_neigh_is_static(n
);
421 if (IS_ZEBRA_DEBUG_EVPN_MH_NEIGH
)
422 zlog_debug("sync-neigh vni %u ip %pIA mac %pEA 0x%x hold expired",
423 n
->zevpn
->vni
, &n
->ip
, &n
->emac
, n
->flags
);
425 /* re-program the local neigh in the dataplane if the neigh is no
428 if (old_n_static
!= new_n_static
)
429 zebra_evpn_sync_neigh_static_chg(
430 n
, old_n_static
, new_n_static
, false /*defer_n_dp*/,
431 false /*defer_mac_dp*/, __func__
);
433 /* inform bgp if needed */
434 if (old_bgp_ready
!= new_bgp_ready
)
435 zebra_evpn_neigh_send_add_del_to_client(n
, old_bgp_ready
,
439 static inline void zebra_evpn_neigh_start_hold_timer(struct zebra_neigh
*n
)
444 if (IS_ZEBRA_DEBUG_EVPN_MH_NEIGH
)
445 zlog_debug("sync-neigh vni %u ip %pIA mac %pEA 0x%x hold start",
446 n
->zevpn
->vni
, &n
->ip
, &n
->emac
, n
->flags
);
447 thread_add_timer(zrouter
.master
, zebra_evpn_neigh_hold_exp_cb
, n
,
448 zmh_info
->neigh_hold_time
, &n
->hold_timer
);
451 static void zebra_evpn_local_neigh_deref_mac(struct zebra_neigh
*n
,
452 bool send_mac_update
)
454 struct zebra_mac
*mac
= n
->mac
;
455 struct zebra_evpn
*zevpn
= n
->zevpn
;
463 if ((n
->flags
& ZEBRA_NEIGH_ALL_PEER_FLAGS
) && mac
->sync_neigh_cnt
) {
464 old_static
= zebra_evpn_mac_is_static(mac
);
465 --mac
->sync_neigh_cnt
;
466 new_static
= zebra_evpn_mac_is_static(mac
);
467 if (IS_ZEBRA_DEBUG_EVPN_MH_NEIGH
)
469 "sync-neigh deref mac vni %u ip %pIA mac %pEA ref %d",
470 n
->zevpn
->vni
, &n
->ip
, &n
->emac
,
471 mac
->sync_neigh_cnt
);
472 if ((old_static
!= new_static
) && send_mac_update
)
473 /* program the local mac in the kernel */
474 zebra_evpn_sync_mac_dp_install(
475 mac
, false /* set_inactive */,
476 false /* force_clear_static */, __func__
);
479 listnode_delete(mac
->neigh_list
, n
);
480 zebra_evpn_deref_ip2mac(zevpn
, mac
);
483 bool zebra_evpn_neigh_is_bgp_seq_ok(struct zebra_evpn
*zevpn
,
484 struct zebra_neigh
*n
,
485 const struct ethaddr
*macaddr
, uint32_t seq
,
490 bool is_local
= false;
492 if (CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_LOCAL
)) {
493 tmp_seq
= n
->loc_seq
;
497 tmp_seq
= n
->rem_seq
;
502 if (is_local
&& !zebra_evpn_neigh_is_ready_for_bgp(n
)) {
503 if (IS_ZEBRA_DEBUG_EVPN_MH_NEIGH
||
504 IS_ZEBRA_DEBUG_VXLAN
)
506 "%s-macip not ready vni %u %s mac %pEA IP %pIA lower seq %u f 0x%x",
507 sync
? "sync" : "remote", zevpn
->vni
,
508 n_type
, macaddr
, &n
->ip
, tmp_seq
,
513 /* if the neigh was never advertised to bgp we must accept
514 * whatever sequence number bgp sends
516 if (!is_local
&& zebra_vxlan_get_accept_bgp_seq()) {
517 if (IS_ZEBRA_DEBUG_EVPN_MH_NEIGH
518 || IS_ZEBRA_DEBUG_VXLAN
)
520 "%s-macip accept 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
,
527 if (IS_ZEBRA_DEBUG_EVPN_MH_NEIGH
|| IS_ZEBRA_DEBUG_VXLAN
)
529 "%s-macip ignore vni %u %s mac %pEA IP %pIA as existing has higher seq %u f 0x%x",
530 sync
? "sync" : "remote", zevpn
->vni
, n_type
,
531 macaddr
, &n
->ip
, tmp_seq
, n
->flags
);
539 * Add neighbor entry.
541 static struct zebra_neigh
*zebra_evpn_neigh_add(struct zebra_evpn
*zevpn
,
542 const struct ipaddr
*ip
,
543 const struct ethaddr
*mac
,
544 struct zebra_mac
*zmac
,
547 struct zebra_neigh tmp_n
;
548 struct zebra_neigh
*n
= NULL
;
550 memset(&tmp_n
, 0, sizeof(tmp_n
));
551 memcpy(&tmp_n
.ip
, ip
, sizeof(struct ipaddr
));
552 n
= hash_get(zevpn
->neigh_table
, &tmp_n
, zebra_evpn_neigh_alloc
);
554 n
->state
= ZEBRA_NEIGH_INACTIVE
;
556 n
->dad_ip_auto_recovery_timer
= NULL
;
558 n
->uptime
= monotime(NULL
);
561 zmac
= zebra_evpn_mac_lookup(zevpn
, mac
);
562 zebra_evpn_local_neigh_ref_mac(n
, mac
, zmac
,
563 false /* send_mac_update */);
569 * Delete neighbor entry.
571 int zebra_evpn_neigh_del(struct zebra_evpn
*zevpn
, struct zebra_neigh
*n
)
573 struct zebra_neigh
*tmp_n
;
576 listnode_delete(n
->mac
->neigh_list
, n
);
578 /* Cancel auto recovery */
579 THREAD_OFF(n
->dad_ip_auto_recovery_timer
);
581 /* Cancel proxy hold timer */
582 zebra_evpn_neigh_stop_hold_timer(n
);
584 /* Free the VNI hash entry and allocated memory. */
585 tmp_n
= hash_release(zevpn
->neigh_table
, n
);
586 XFREE(MTYPE_NEIGH
, tmp_n
);
591 void zebra_evpn_sync_neigh_del(struct zebra_neigh
*n
)
596 if (IS_ZEBRA_DEBUG_EVPN_MH_NEIGH
)
597 zlog_debug("sync-neigh del vni %u ip %pIA mac %pEA f 0x%x",
598 n
->zevpn
->vni
, &n
->ip
, &n
->emac
, n
->flags
);
600 old_n_static
= zebra_evpn_neigh_is_static(n
);
601 UNSET_FLAG(n
->flags
, ZEBRA_NEIGH_ES_PEER_PROXY
);
602 if (CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_ES_PEER_ACTIVE
))
603 zebra_evpn_neigh_start_hold_timer(n
);
604 new_n_static
= zebra_evpn_neigh_is_static(n
);
606 if (old_n_static
!= new_n_static
)
607 zebra_evpn_sync_neigh_static_chg(
608 n
, old_n_static
, new_n_static
, false /*defer-dp*/,
609 false /*defer_mac_dp*/, __func__
);
612 struct zebra_neigh
*zebra_evpn_proc_sync_neigh_update(
613 struct zebra_evpn
*zevpn
, struct zebra_neigh
*n
, uint16_t ipa_len
,
614 const struct ipaddr
*ipaddr
, uint8_t flags
, uint32_t seq
,
615 const esi_t
*esi
, struct zebra_mac
*mac
)
617 struct interface
*ifp
= NULL
;
620 bool old_router
= false;
621 bool old_bgp_ready
= false;
623 bool inform_dataplane
= false;
624 bool inform_bgp
= false;
627 bool set_dp_inactive
= false;
629 ifindex_t ifindex
= 0;
632 ifp
= zevpn_map_to_svi(zevpn
);
634 ifindex
= ifp
->ifindex
;
636 is_router
= !!CHECK_FLAG(flags
, ZEBRA_MACIP_TYPE_ROUTER_FLAG
);
637 old_mac_static
= zebra_evpn_mac_is_static(mac
);
640 uint32_t n_flags
= 0;
642 /* New neighbor - create */
643 SET_FLAG(n_flags
, ZEBRA_NEIGH_LOCAL
);
644 if (CHECK_FLAG(flags
, ZEBRA_MACIP_TYPE_PROXY_ADVERT
))
645 SET_FLAG(n_flags
, ZEBRA_NEIGH_ES_PEER_PROXY
);
647 SET_FLAG(n_flags
, ZEBRA_NEIGH_ES_PEER_ACTIVE
);
648 SET_FLAG(n_flags
, ZEBRA_NEIGH_LOCAL_INACTIVE
);
650 n
= zebra_evpn_neigh_add(zevpn
, ipaddr
, &mac
->macaddr
, mac
,
652 n
->ifindex
= ifindex
;
653 ZEBRA_NEIGH_SET_ACTIVE(n
);
656 inform_dataplane
= true;
658 set_dp_inactive
= true;
661 uint32_t old_flags
= n
->flags
;
666 old_n_static
= zebra_evpn_neigh_is_static(n
);
667 old_bgp_ready
= zebra_evpn_neigh_is_ready_for_bgp(n
);
668 old_router
= !!CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_ROUTER_FLAG
);
670 mac_change
= !!memcmp(&n
->emac
, &mac
->macaddr
, ETH_ALEN
);
672 /* deref and clear old info */
675 zebra_evpn_neigh_send_del_to_client(
676 zevpn
->vni
, &n
->ip
, &n
->emac
, n
->flags
,
677 n
->state
, false /*force*/);
678 old_bgp_ready
= false;
680 zebra_evpn_local_neigh_deref_mac(n
,
681 false /*send_mac_update*/);
683 /* clear old fwd info */
685 n
->r_vtep_ip
.s_addr
= 0;
687 /* setup new flags */
689 SET_FLAG(n
->flags
, ZEBRA_NEIGH_LOCAL
);
690 /* retain activity flag if the neigh was
693 if (old_flags
& ZEBRA_NEIGH_LOCAL
) {
694 n
->flags
|= (old_flags
& ZEBRA_NEIGH_LOCAL_INACTIVE
);
696 inform_dataplane
= true;
697 set_dp_inactive
= true;
698 n
->flags
|= ZEBRA_NEIGH_LOCAL_INACTIVE
;
701 if (CHECK_FLAG(flags
, ZEBRA_MACIP_TYPE_PROXY_ADVERT
)) {
702 SET_FLAG(n
->flags
, ZEBRA_NEIGH_ES_PEER_PROXY
);
703 /* if the neigh was peer-active previously we
704 * need to keep the flag and start the
705 * holdtimer on it. the peer-active flag is
706 * cleared on holdtimer expiry.
708 if (CHECK_FLAG(old_flags
, ZEBRA_NEIGH_ES_PEER_ACTIVE
)) {
709 SET_FLAG(n
->flags
, ZEBRA_NEIGH_ES_PEER_ACTIVE
);
710 zebra_evpn_neigh_start_hold_timer(n
);
713 SET_FLAG(n
->flags
, ZEBRA_NEIGH_ES_PEER_ACTIVE
);
714 /* stop hold timer if a peer has verified
717 zebra_evpn_neigh_stop_hold_timer(n
);
719 ZEBRA_NEIGH_SET_ACTIVE(n
);
721 if (IS_ZEBRA_DEBUG_EVPN_MH_NEIGH
&& (old_flags
!= n
->flags
))
723 "sync-neigh vni %u ip %pIA mac %pEA old_f 0x%x new_f 0x%x",
724 n
->zevpn
->vni
, &n
->ip
, &n
->emac
,
725 old_flags
, n
->flags
);
727 new_n_static
= zebra_evpn_neigh_is_static(n
);
729 set_dp_inactive
= true;
730 n
->flags
|= ZEBRA_NEIGH_LOCAL_INACTIVE
;
731 inform_dataplane
= true;
732 zebra_evpn_local_neigh_ref_mac(
733 n
, &mac
->macaddr
, mac
,
734 false /*send_mac_update*/);
735 } else if (old_n_static
!= new_n_static
) {
736 inform_dataplane
= true;
737 /* if static flags have changed without a mac change
738 * we need to create the correct sync-refs against
741 zebra_evpn_sync_neigh_static_chg(
742 n
, old_n_static
, new_n_static
,
743 true /*defer_dp*/, true /*defer_mac_dp*/,
747 /* Update the forwarding info. */
748 if (n
->ifindex
!= ifindex
) {
749 n
->ifindex
= ifindex
;
750 inform_dataplane
= true;
753 n
->uptime
= monotime(NULL
);
756 /* update the neigh seq. we don't bother with the mac seq as
757 * sync_mac_update already took care of that
759 tmp_seq
= MAX(n
->loc_seq
, seq
);
760 if (tmp_seq
!= n
->loc_seq
) {
761 n
->loc_seq
= tmp_seq
;
765 /* Mark Router flag (R-bit) */
767 SET_FLAG(n
->flags
, ZEBRA_NEIGH_ROUTER_FLAG
);
769 UNSET_FLAG(n
->flags
, ZEBRA_NEIGH_ROUTER_FLAG
);
771 if (old_router
!= is_router
)
772 inform_dataplane
= true;
774 new_bgp_ready
= zebra_evpn_neigh_is_ready_for_bgp(n
);
775 if (old_bgp_ready
!= new_bgp_ready
)
778 new_mac_static
= zebra_evpn_mac_is_static(mac
);
779 if (old_mac_static
!= new_mac_static
)
780 zebra_evpn_sync_mac_dp_install(mac
, false /* set_inactive */,
781 false /* force_clear_static */,
784 if (IS_ZEBRA_DEBUG_EVPN_MH_NEIGH
)
786 "sync-neigh %s vni %u ip %pIA mac %pEA if %s(%d) seq %d f 0x%x%s%s",
787 created
? "created" : "updated", n
->zevpn
->vni
,
789 ifp
? ifp
->name
: "", ifindex
, n
->loc_seq
, n
->flags
,
790 inform_bgp
? " inform_bgp" : "",
791 inform_dataplane
? " inform_dp" : "");
793 if (inform_dataplane
)
794 zebra_evpn_sync_neigh_dp_install(n
, set_dp_inactive
,
795 false /* force_clear_static */,
799 zebra_evpn_neigh_send_add_del_to_client(n
, old_bgp_ready
,
806 * Uninstall remote neighbor from the kernel.
808 static int zebra_evpn_neigh_uninstall(struct zebra_evpn
*zevpn
,
809 struct zebra_neigh
*n
)
811 struct interface
*vlan_if
;
813 if (!(n
->flags
& ZEBRA_NEIGH_REMOTE
))
816 vlan_if
= zevpn_map_to_svi(zevpn
);
820 ZEBRA_NEIGH_SET_INACTIVE(n
);
823 dplane_rem_neigh_delete(vlan_if
, &n
->ip
);
829 * Free neighbor hash entry (callback)
831 static void zebra_evpn_neigh_del_hash_entry(struct hash_bucket
*bucket
,
834 struct neigh_walk_ctx
*wctx
= arg
;
835 struct zebra_neigh
*n
= bucket
->data
;
837 if (((wctx
->flags
& DEL_LOCAL_NEIGH
) && (n
->flags
& ZEBRA_NEIGH_LOCAL
))
838 || ((wctx
->flags
& DEL_REMOTE_NEIGH
)
839 && (n
->flags
& ZEBRA_NEIGH_REMOTE
))
840 || ((wctx
->flags
& DEL_REMOTE_NEIGH_FROM_VTEP
)
841 && (n
->flags
& ZEBRA_NEIGH_REMOTE
)
842 && IPV4_ADDR_SAME(&n
->r_vtep_ip
, &wctx
->r_vtep_ip
))) {
843 if (wctx
->upd_client
&& (n
->flags
& ZEBRA_NEIGH_LOCAL
))
844 zebra_evpn_neigh_send_del_to_client(
845 wctx
->zevpn
->vni
, &n
->ip
, &n
->emac
, n
->flags
,
846 n
->state
, false /*force*/);
848 if (wctx
->uninstall
) {
849 if (zebra_evpn_neigh_is_static(n
))
850 zebra_evpn_sync_neigh_dp_install(
851 n
, false /* set_inactive */,
852 true /* force_clear_static */,
854 if ((n
->flags
& ZEBRA_NEIGH_REMOTE
))
855 zebra_evpn_neigh_uninstall(wctx
->zevpn
, n
);
858 zebra_evpn_neigh_del(wctx
->zevpn
, n
);
865 * Delete all neighbor entries for this EVPN.
867 void zebra_evpn_neigh_del_all(struct zebra_evpn
*zevpn
, int uninstall
,
868 int upd_client
, uint32_t flags
)
870 struct neigh_walk_ctx wctx
;
872 if (!zevpn
->neigh_table
)
875 memset(&wctx
, 0, sizeof(wctx
));
877 wctx
.uninstall
= uninstall
;
878 wctx
.upd_client
= upd_client
;
881 hash_iterate(zevpn
->neigh_table
, zebra_evpn_neigh_del_hash_entry
,
886 * Look up neighbor hash entry.
888 struct zebra_neigh
*zebra_evpn_neigh_lookup(struct zebra_evpn
*zevpn
,
889 const struct ipaddr
*ip
)
891 struct zebra_neigh tmp
;
892 struct zebra_neigh
*n
;
894 memset(&tmp
, 0, sizeof(tmp
));
895 memcpy(&tmp
.ip
, ip
, sizeof(struct ipaddr
));
896 n
= hash_lookup(zevpn
->neigh_table
, &tmp
);
902 * Process all neighbors associated with a MAC upon the MAC being learnt
903 * locally or undergoing any other change (such as sequence number).
905 void zebra_evpn_process_neigh_on_local_mac_change(struct zebra_evpn
*zevpn
,
906 struct zebra_mac
*zmac
,
910 struct zebra_neigh
*n
= NULL
;
911 struct listnode
*node
= NULL
;
912 struct zebra_vrf
*zvrf
= NULL
;
914 zvrf
= zevpn
->vxlan_if
->vrf
->info
;
916 if (IS_ZEBRA_DEBUG_VXLAN
)
917 zlog_debug("Processing neighbors on local MAC %pEA %s, VNI %u",
918 &zmac
->macaddr
, seq_change
? "CHANGE" : "ADD",
921 /* Walk all neighbors and mark any inactive local neighbors as
922 * active and/or update sequence number upon a move, and inform BGP.
923 * The action for remote neighbors is TBD.
924 * NOTE: We can't simply uninstall remote neighbors as the kernel may
925 * accidentally end up deleting a just-learnt local neighbor.
927 for (ALL_LIST_ELEMENTS_RO(zmac
->neigh_list
, node
, n
)) {
928 if (CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_LOCAL
)) {
929 if (IS_ZEBRA_NEIGH_INACTIVE(n
) || seq_change
931 ZEBRA_NEIGH_SET_ACTIVE(n
);
932 n
->loc_seq
= zmac
->loc_seq
;
933 if (!(zebra_evpn_do_dup_addr_detect(zvrf
)
935 && !!CHECK_FLAG(n
->flags
,
936 ZEBRA_NEIGH_DUPLICATE
)))
937 zebra_evpn_neigh_send_add_to_client(
938 zevpn
->vni
, &n
->ip
, &n
->emac
,
939 n
->mac
, n
->flags
, n
->loc_seq
);
946 * Process all neighbors associated with a local MAC upon the MAC being
949 void zebra_evpn_process_neigh_on_local_mac_del(struct zebra_evpn
*zevpn
,
950 struct zebra_mac
*zmac
)
952 struct zebra_neigh
*n
= NULL
;
953 struct listnode
*node
= NULL
;
955 if (IS_ZEBRA_DEBUG_VXLAN
)
956 zlog_debug("Processing neighbors on local MAC %pEA DEL, VNI %u",
957 &zmac
->macaddr
, zevpn
->vni
);
959 /* Walk all local neighbors and mark as inactive and inform
961 * TBD: There is currently no handling for remote neighbors. We
962 * don't expect them to exist, if they do, do we install the MAC
963 * as a remote MAC and the neighbor as remote?
965 for (ALL_LIST_ELEMENTS_RO(zmac
->neigh_list
, node
, n
)) {
966 if (CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_LOCAL
)) {
967 if (IS_ZEBRA_NEIGH_ACTIVE(n
)) {
968 ZEBRA_NEIGH_SET_INACTIVE(n
);
970 zebra_evpn_neigh_send_del_to_client(
971 zevpn
->vni
, &n
->ip
, &n
->emac
, n
->flags
,
972 ZEBRA_NEIGH_ACTIVE
, false /*force*/);
979 * Process all neighbors associated with a MAC upon the MAC being remotely
982 void zebra_evpn_process_neigh_on_remote_mac_add(struct zebra_evpn
*zevpn
,
983 struct zebra_mac
*zmac
)
985 struct zebra_neigh
*n
= NULL
;
986 struct listnode
*node
= NULL
;
988 if (IS_ZEBRA_DEBUG_VXLAN
)
989 zlog_debug("Processing neighbors on remote MAC %pEA ADD, VNI %u",
990 &zmac
->macaddr
, zevpn
->vni
);
992 /* Walk all local neighbors and mark as inactive and inform
995 for (ALL_LIST_ELEMENTS_RO(zmac
->neigh_list
, node
, n
)) {
996 if (CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_LOCAL
)) {
997 if (IS_ZEBRA_NEIGH_ACTIVE(n
)) {
998 ZEBRA_NEIGH_SET_INACTIVE(n
);
1000 zebra_evpn_neigh_send_del_to_client(
1001 zevpn
->vni
, &n
->ip
, &n
->emac
, n
->flags
,
1002 ZEBRA_NEIGH_ACTIVE
, false /* force */);
1009 * Process all neighbors associated with a remote MAC upon the MAC being
1012 void zebra_evpn_process_neigh_on_remote_mac_del(struct zebra_evpn
*zevpn
,
1013 struct zebra_mac
*zmac
)
1015 /* NOTE: Currently a NO-OP. */
1018 static inline void zebra_evpn_local_neigh_update_log(
1019 const char *pfx
, struct zebra_neigh
*n
, bool is_router
,
1020 bool local_inactive
, bool old_bgp_ready
, bool new_bgp_ready
,
1021 bool inform_dataplane
, bool inform_bgp
, const char *sfx
)
1023 if (!IS_ZEBRA_DEBUG_EVPN_MH_NEIGH
)
1026 zlog_debug("%s neigh vni %u ip %pIA mac %pEA f 0x%x%s%s%s%s%s%s %s", pfx
,
1027 n
->zevpn
->vni
, &n
->ip
, &n
->emac
, n
->flags
,
1028 is_router
? " router" : "",
1029 local_inactive
? " local-inactive" : "",
1030 old_bgp_ready
? " old_bgp_ready" : "",
1031 new_bgp_ready
? " new_bgp_ready" : "",
1032 inform_dataplane
? " inform_dp" : "",
1033 inform_bgp
? " inform_bgp" : "", sfx
);
1036 /* As part Duplicate Address Detection (DAD) for IP mobility
1037 * MAC binding changes, ensure to inherit duplicate flag
1040 static int zebra_evpn_ip_inherit_dad_from_mac(struct zebra_vrf
*zvrf
,
1041 struct zebra_mac
*old_zmac
,
1042 struct zebra_mac
*new_zmac
,
1043 struct zebra_neigh
*nbr
)
1045 bool is_old_mac_dup
= false;
1046 bool is_new_mac_dup
= false;
1048 if (!zebra_evpn_do_dup_addr_detect(zvrf
))
1050 /* Check old or new MAC is detected as duplicate
1051 * mark this neigh as duplicate
1055 CHECK_FLAG(old_zmac
->flags
, ZEBRA_MAC_DUPLICATE
);
1058 CHECK_FLAG(new_zmac
->flags
, ZEBRA_MAC_DUPLICATE
);
1059 /* Old and/or new MAC can be in duplicate state,
1060 * based on that IP/Neigh Inherits the flag.
1061 * If New MAC is marked duplicate, inherit to the IP.
1062 * If old MAC is duplicate but new MAC is not, clear
1063 * duplicate flag for IP and reset detection params
1064 * and let IP DAD retrigger.
1066 if (is_new_mac_dup
&& !CHECK_FLAG(nbr
->flags
, ZEBRA_NEIGH_DUPLICATE
)) {
1067 SET_FLAG(nbr
->flags
, ZEBRA_NEIGH_DUPLICATE
);
1068 /* Capture Duplicate detection time */
1069 nbr
->dad_dup_detect_time
= monotime(NULL
);
1070 /* Mark neigh inactive */
1071 ZEBRA_NEIGH_SET_INACTIVE(nbr
);
1074 } else if (is_old_mac_dup
&& !is_new_mac_dup
) {
1075 UNSET_FLAG(nbr
->flags
, ZEBRA_NEIGH_DUPLICATE
);
1077 nbr
->detect_start_time
.tv_sec
= 0;
1078 nbr
->detect_start_time
.tv_usec
= 0;
1083 static void zebra_evpn_dad_ip_auto_recovery_exp(struct thread
*t
)
1085 struct zebra_vrf
*zvrf
= NULL
;
1086 struct zebra_neigh
*nbr
= NULL
;
1087 struct zebra_evpn
*zevpn
= NULL
;
1089 nbr
= THREAD_ARG(t
);
1091 /* since this is asynchronous we need sanity checks*/
1092 zvrf
= vrf_info_lookup(nbr
->zevpn
->vrf_id
);
1096 zevpn
= zebra_evpn_lookup(nbr
->zevpn
->vni
);
1100 nbr
= zebra_evpn_neigh_lookup(zevpn
, &nbr
->ip
);
1104 if (IS_ZEBRA_DEBUG_VXLAN
)
1106 "%s: duplicate addr MAC %pEA IP %pIA flags 0x%x learn count %u vni %u auto recovery expired",
1107 __func__
, &nbr
->emac
, &nbr
->ip
, nbr
->flags
,
1108 nbr
->dad_count
, zevpn
->vni
);
1110 UNSET_FLAG(nbr
->flags
, ZEBRA_NEIGH_DUPLICATE
);
1112 nbr
->detect_start_time
.tv_sec
= 0;
1113 nbr
->detect_start_time
.tv_usec
= 0;
1114 nbr
->dad_dup_detect_time
= 0;
1115 nbr
->dad_ip_auto_recovery_timer
= NULL
;
1116 ZEBRA_NEIGH_SET_ACTIVE(nbr
);
1119 if (CHECK_FLAG(nbr
->flags
, ZEBRA_NEIGH_LOCAL
)) {
1120 zebra_evpn_neigh_send_add_to_client(zevpn
->vni
, &nbr
->ip
,
1121 &nbr
->emac
, nbr
->mac
,
1122 nbr
->flags
, nbr
->loc_seq
);
1123 } else if (!!CHECK_FLAG(nbr
->flags
, ZEBRA_NEIGH_REMOTE
)) {
1124 zebra_evpn_rem_neigh_install(zevpn
, nbr
, false /*was_static*/);
1128 static void zebra_evpn_dup_addr_detect_for_neigh(
1129 struct zebra_vrf
*zvrf
, struct zebra_neigh
*nbr
, struct in_addr vtep_ip
,
1130 bool do_dad
, bool *is_dup_detect
, bool is_local
)
1133 struct timeval elapsed
= {0, 0};
1134 bool reset_params
= false;
1136 if (!zebra_evpn_do_dup_addr_detect(zvrf
))
1139 /* IP is detected as duplicate or inherit dup
1140 * state, hold on to install as remote entry
1141 * only if freeze is enabled.
1143 if (CHECK_FLAG(nbr
->flags
, ZEBRA_NEIGH_DUPLICATE
)) {
1144 if (IS_ZEBRA_DEBUG_VXLAN
)
1146 "%s: duplicate addr MAC %pEA IP %pIA flags 0x%x skip installing, learn count %u recover time %u",
1147 __func__
, &nbr
->emac
, &nbr
->ip
,
1148 nbr
->flags
, nbr
->dad_count
,
1149 zvrf
->dad_freeze_time
);
1151 if (zvrf
->dad_freeze
)
1152 *is_dup_detect
= true;
1154 /* warn-only action, neigh will be installed.
1155 * freeze action, it wil not be installed.
1163 /* Check if detection time (M-secs) expired.
1164 * Reset learn count and detection start time.
1165 * During remote mac add, count should already be 1
1166 * via local learning.
1168 monotime_since(&nbr
->detect_start_time
, &elapsed
);
1169 reset_params
= (elapsed
.tv_sec
> zvrf
->dad_time
);
1171 if (is_local
&& !reset_params
) {
1172 /* RFC-7432: A PE/VTEP that detects a MAC mobility
1173 * event via LOCAL learning starts an M-second timer.
1175 * NOTE: This is the START of the probe with count is
1176 * 0 during LOCAL learn event.
1178 reset_params
= !nbr
->dad_count
;
1182 if (IS_ZEBRA_DEBUG_VXLAN
)
1184 "%s: duplicate addr MAC %pEA IP %pIA flags 0x%x detection time passed, reset learn count %u",
1185 __func__
, &nbr
->emac
, &nbr
->ip
,
1186 nbr
->flags
, nbr
->dad_count
);
1187 /* Reset learn count but do not start detection
1188 * during REMOTE learn event.
1191 /* Start dup. addr detection (DAD) start time,
1192 * ONLY during LOCAL learn.
1195 monotime(&nbr
->detect_start_time
);
1197 } else if (!is_local
) {
1198 /* For REMOTE IP/Neigh, increment detection count
1199 * ONLY while in probe window, once window passed,
1200 * next local learn event should trigger DAD.
1205 /* For LOCAL IP/Neigh learn event, once count is reset above via either
1206 * initial/start detection time or passed the probe time, the count
1207 * needs to be incremented.
1212 if (nbr
->dad_count
>= zvrf
->dad_max_moves
) {
1214 EC_ZEBRA_DUP_IP_DETECTED
,
1215 "VNI %u: MAC %pEA IP %pIA detected as duplicate during %s VTEP %pI4",
1216 nbr
->zevpn
->vni
, &nbr
->emac
, &nbr
->ip
,
1217 is_local
? "local update, last" : "remote update, from",
1220 SET_FLAG(nbr
->flags
, ZEBRA_NEIGH_DUPLICATE
);
1222 /* Capture Duplicate detection time */
1223 nbr
->dad_dup_detect_time
= monotime(NULL
);
1225 /* Start auto recovery timer for this IP */
1226 THREAD_OFF(nbr
->dad_ip_auto_recovery_timer
);
1227 if (zvrf
->dad_freeze
&& zvrf
->dad_freeze_time
) {
1228 if (IS_ZEBRA_DEBUG_VXLAN
)
1230 "%s: duplicate addr MAC %pEA IP %pIA flags 0x%x auto recovery time %u start",
1231 __func__
, &nbr
->emac
, &nbr
->ip
,
1232 nbr
->flags
, zvrf
->dad_freeze_time
);
1234 thread_add_timer(zrouter
.master
,
1235 zebra_evpn_dad_ip_auto_recovery_exp
,
1236 nbr
, zvrf
->dad_freeze_time
,
1237 &nbr
->dad_ip_auto_recovery_timer
);
1239 if (zvrf
->dad_freeze
)
1240 *is_dup_detect
= true;
1244 int zebra_evpn_local_neigh_update(struct zebra_evpn
*zevpn
,
1245 struct interface
*ifp
,
1246 const struct ipaddr
*ip
,
1247 const struct ethaddr
*macaddr
, bool is_router
,
1248 bool local_inactive
, bool dp_static
)
1250 struct zebra_vrf
*zvrf
;
1251 struct zebra_neigh
*n
= NULL
;
1252 struct zebra_mac
*zmac
= NULL
, *old_zmac
= NULL
;
1253 uint32_t old_mac_seq
= 0, mac_new_seq
= 0;
1254 bool upd_mac_seq
= false;
1255 bool neigh_mac_change
= false;
1256 bool neigh_on_hold
= false;
1257 bool neigh_was_remote
= false;
1258 bool do_dad
= false;
1259 struct in_addr vtep_ip
= {.s_addr
= 0};
1260 bool inform_dataplane
= false;
1261 bool created
= false;
1262 bool new_static
= false;
1263 bool old_bgp_ready
= false;
1266 /* Check if the MAC exists. */
1267 zmac
= zebra_evpn_mac_lookup(zevpn
, macaddr
);
1269 /* create a dummy MAC if the MAC is not already present */
1270 if (IS_ZEBRA_DEBUG_VXLAN
)
1271 zlog_debug("AUTO MAC %pEA created for neigh %pIA on VNI %u",
1272 macaddr
, ip
, zevpn
->vni
);
1274 zmac
= zebra_evpn_mac_add_auto(zevpn
, macaddr
);
1276 zlog_debug("Failed to add MAC %pEA VNI %u", macaddr
,
1281 if (CHECK_FLAG(zmac
->flags
, ZEBRA_MAC_REMOTE
)) {
1283 * We don't change the MAC to local upon a neighbor
1284 * learn event, we wait for the explicit local MAC
1285 * learn. However, we have to compute its sequence
1286 * number in preparation for when it actually turns
1293 zvrf
= zevpn
->vxlan_if
->vrf
->info
;
1295 if (IS_ZEBRA_DEBUG_VXLAN
)
1296 zlog_debug(" Unable to find vrf for: %d",
1297 zevpn
->vxlan_if
->vrf
->vrf_id
);
1301 /* Check if the neighbor exists. */
1302 n
= zebra_evpn_neigh_lookup(zevpn
, ip
);
1304 /* New neighbor - create */
1305 n
= zebra_evpn_neigh_add(zevpn
, ip
, macaddr
, zmac
, 0);
1307 /* Set "local" forwarding info. */
1308 SET_FLAG(n
->flags
, ZEBRA_NEIGH_LOCAL
);
1309 n
->ifindex
= ifp
->ifindex
;
1312 if (CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_LOCAL
)) {
1315 bool old_local_inactive
;
1317 old_local_inactive
= !!CHECK_FLAG(
1318 n
->flags
, ZEBRA_NEIGH_LOCAL_INACTIVE
);
1320 old_bgp_ready
= zebra_evpn_neigh_is_ready_for_bgp(n
);
1322 /* Note any changes and see if of interest to BGP. */
1323 mac_different
= !!memcmp(&n
->emac
, macaddr
, ETH_ALEN
);
1325 !!CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_ROUTER_FLAG
);
1326 new_static
= zebra_evpn_neigh_is_static(n
);
1327 if (!mac_different
&& is_router
== cur_is_router
1328 && old_local_inactive
== local_inactive
1329 && dp_static
!= new_static
) {
1330 if (IS_ZEBRA_DEBUG_VXLAN
)
1332 " Ignoring entry mac is the same and is_router == cur_is_router");
1333 n
->ifindex
= ifp
->ifindex
;
1338 if (!mac_different
) {
1339 /* XXX - cleanup this code duplication */
1340 bool is_neigh_freezed
= false;
1342 /* Only the router flag has changed. */
1345 ZEBRA_NEIGH_ROUTER_FLAG
);
1347 UNSET_FLAG(n
->flags
,
1348 ZEBRA_NEIGH_ROUTER_FLAG
);
1352 ZEBRA_NEIGH_LOCAL_INACTIVE
);
1354 UNSET_FLAG(n
->flags
,
1355 ZEBRA_NEIGH_LOCAL_INACTIVE
);
1357 zebra_evpn_neigh_is_ready_for_bgp(n
);
1359 if (dp_static
!= new_static
)
1360 inform_dataplane
= true;
1362 /* Neigh is in freeze state and freeze action
1363 * is enabled, do not send update to client.
1366 (zebra_evpn_do_dup_addr_detect(zvrf
)
1368 && CHECK_FLAG(n
->flags
,
1369 ZEBRA_NEIGH_DUPLICATE
));
1371 zebra_evpn_local_neigh_update_log(
1372 "local", n
, is_router
, local_inactive
,
1373 old_bgp_ready
, new_bgp_ready
, false,
1374 false, "flag-update");
1376 if (inform_dataplane
)
1377 zebra_evpn_sync_neigh_dp_install(
1378 n
, false /* set_inactive */,
1379 false /* force_clear_static */,
1382 /* if the neigh can no longer be advertised
1383 * remove it from bgp
1385 if (!is_neigh_freezed
) {
1386 zebra_evpn_neigh_send_add_del_to_client(
1390 if (IS_ZEBRA_DEBUG_VXLAN
1391 && IS_ZEBRA_NEIGH_ACTIVE(n
))
1393 " Neighbor active and frozen");
1398 /* The MAC has changed, need to issue a delete
1399 * first as this means a different MACIP route.
1400 * Also, need to do some unlinking/relinking.
1401 * We also need to update the MAC's sequence number
1402 * in different situations.
1404 if (old_bgp_ready
) {
1405 zebra_evpn_neigh_send_del_to_client(
1406 zevpn
->vni
, &n
->ip
, &n
->emac
, n
->flags
,
1407 n
->state
, false /*force*/);
1408 old_bgp_ready
= false;
1411 old_mac_seq
= CHECK_FLAG(old_zmac
->flags
,
1414 : old_zmac
->loc_seq
;
1415 neigh_mac_change
= upd_mac_seq
= true;
1416 zebra_evpn_local_neigh_deref_mac(
1417 n
, true /* send_mac_update */);
1420 /* if mac changes abandon peer flags and tell
1421 * dataplane to clear the static flag
1423 if (zebra_evpn_neigh_clear_sync_info(n
))
1424 inform_dataplane
= true;
1425 /* Update the forwarding info. */
1426 n
->ifindex
= ifp
->ifindex
;
1428 /* Link to new MAC */
1429 zebra_evpn_local_neigh_ref_mac(
1430 n
, macaddr
, zmac
, true /* send_mac_update */);
1431 } else if (CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_REMOTE
)) {
1433 * Neighbor has moved from remote to local. Its
1434 * MAC could have also changed as part of the move.
1436 if (memcmp(n
->emac
.octet
, macaddr
->octet
, ETH_ALEN
)
1441 CHECK_FLAG(old_zmac
->flags
,
1444 : old_zmac
->loc_seq
;
1445 neigh_mac_change
= upd_mac_seq
= true;
1446 zebra_evpn_local_neigh_deref_mac(
1447 n
, true /* send_update */);
1450 /* Link to new MAC */
1451 zebra_evpn_local_neigh_ref_mac(
1452 n
, macaddr
, zmac
, true /*send_update*/);
1454 /* Based on Mobility event Scenario-B from the
1455 * draft, neigh's previous state was remote treat this
1458 neigh_was_remote
= true;
1459 vtep_ip
= n
->r_vtep_ip
;
1460 /* Mark appropriately */
1461 UNSET_FLAG(n
->flags
, ZEBRA_NEIGH_REMOTE
);
1462 n
->r_vtep_ip
.s_addr
= INADDR_ANY
;
1463 SET_FLAG(n
->flags
, ZEBRA_NEIGH_LOCAL
);
1464 n
->ifindex
= ifp
->ifindex
;
1468 /* If MAC was previously remote, or the neighbor had a different
1469 * MAC earlier, recompute the sequence number.
1472 uint32_t seq1
, seq2
;
1474 seq1
= CHECK_FLAG(zmac
->flags
, ZEBRA_MAC_REMOTE
)
1477 seq2
= neigh_mac_change
? old_mac_seq
+ 1 : 0;
1478 mac_new_seq
= zmac
->loc_seq
< MAX(seq1
, seq2
) ? MAX(seq1
, seq2
)
1483 SET_FLAG(n
->flags
, ZEBRA_NEIGH_LOCAL_INACTIVE
);
1485 UNSET_FLAG(n
->flags
, ZEBRA_NEIGH_LOCAL_INACTIVE
);
1487 /* Mark Router flag (R-bit) */
1489 SET_FLAG(n
->flags
, ZEBRA_NEIGH_ROUTER_FLAG
);
1491 UNSET_FLAG(n
->flags
, ZEBRA_NEIGH_ROUTER_FLAG
);
1493 /* if zebra and dataplane don't agree this is a sync entry
1494 * re-install in the dataplane */
1495 new_static
= zebra_evpn_neigh_is_static(n
);
1496 if (dp_static
!= new_static
)
1497 inform_dataplane
= true;
1499 /* Check old and/or new MAC detected as duplicate mark
1500 * the neigh as duplicate
1502 if (zebra_evpn_ip_inherit_dad_from_mac(zvrf
, old_zmac
, zmac
, n
)) {
1504 EC_ZEBRA_DUP_IP_INHERIT_DETECTED
,
1505 "VNI %u: MAC %pEA IP %pIA detected as duplicate during local update, inherit duplicate from MAC",
1506 zevpn
->vni
, macaddr
, &n
->ip
);
1509 /* For IP Duplicate Address Detection (DAD) is trigger,
1510 * when the event is extended mobility based on scenario-B
1511 * from the draft, IP/Neigh's MAC binding changed and
1512 * neigh's previous state was remote.
1514 if (neigh_mac_change
&& neigh_was_remote
)
1517 zebra_evpn_dup_addr_detect_for_neigh(zvrf
, n
, vtep_ip
, do_dad
,
1518 &neigh_on_hold
, true);
1520 if (inform_dataplane
)
1521 zebra_evpn_sync_neigh_dp_install(n
, false /* set_inactive */,
1522 false /* force_clear_static */,
1525 /* Before we program this in BGP, we need to check if MAC is locally
1526 * learnt. If not, force neighbor to be inactive and reset its seq.
1528 if (!CHECK_FLAG(zmac
->flags
, ZEBRA_MAC_LOCAL
)) {
1529 zebra_evpn_local_neigh_update_log(
1530 "local", n
, is_router
, local_inactive
, false, false,
1531 inform_dataplane
, false, "auto-mac");
1532 ZEBRA_NEIGH_SET_INACTIVE(n
);
1534 zmac
->loc_seq
= mac_new_seq
;
1538 zebra_evpn_local_neigh_update_log("local", n
, is_router
, local_inactive
,
1539 false, false, inform_dataplane
, true,
1540 created
? "created" : "updated");
1542 /* If the MAC's sequence number has changed, inform the MAC and all
1543 * neighbors associated with the MAC to BGP, else just inform this
1546 if (upd_mac_seq
&& zmac
->loc_seq
!= mac_new_seq
) {
1547 if (IS_ZEBRA_DEBUG_VXLAN
)
1549 "Seq changed for MAC %pEA VNI %u - old %u new %u",
1550 macaddr
, zevpn
->vni
,
1551 zmac
->loc_seq
, mac_new_seq
);
1552 zmac
->loc_seq
= mac_new_seq
;
1553 if (zebra_evpn_mac_send_add_to_client(zevpn
->vni
, macaddr
,
1555 zmac
->loc_seq
, zmac
->es
))
1557 zebra_evpn_process_neigh_on_local_mac_change(zevpn
, zmac
, 1,
1562 n
->loc_seq
= zmac
->loc_seq
;
1564 if (!neigh_on_hold
) {
1565 ZEBRA_NEIGH_SET_ACTIVE(n
);
1566 new_bgp_ready
= zebra_evpn_neigh_is_ready_for_bgp(n
);
1567 zebra_evpn_neigh_send_add_del_to_client(n
, old_bgp_ready
,
1570 if (IS_ZEBRA_DEBUG_VXLAN
)
1571 zlog_debug(" Neighbor on hold not sending");
1576 int zebra_evpn_remote_neigh_update(struct zebra_evpn
*zevpn
,
1577 struct interface
*ifp
,
1578 const struct ipaddr
*ip
,
1579 const struct ethaddr
*macaddr
,
1582 struct zebra_neigh
*n
= NULL
;
1583 struct zebra_mac
*zmac
= NULL
;
1585 /* If the neighbor is unknown, there is no further action. */
1586 n
= zebra_evpn_neigh_lookup(zevpn
, ip
);
1590 /* If a remote entry, see if it needs to be refreshed */
1591 if (CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_REMOTE
)) {
1593 if (state
& NUD_STALE
)
1594 zebra_evpn_rem_neigh_install(zevpn
, n
,
1595 false /*was_static*/);
1598 /* We got a "remote" neighbor notification for an entry
1599 * we think is local. This can happen in a multihoming
1600 * scenario - but only if the MAC is already "remote".
1601 * Just mark our entry as "remote".
1603 zmac
= zebra_evpn_mac_lookup(zevpn
, macaddr
);
1604 if (!zmac
|| !CHECK_FLAG(zmac
->flags
, ZEBRA_MAC_REMOTE
)) {
1606 "Ignore remote neigh %pIA (MAC %pEA) on L2-VNI %u - MAC unknown or local",
1607 &n
->ip
, macaddr
, zevpn
->vni
);
1611 UNSET_FLAG(n
->flags
, ZEBRA_NEIGH_ALL_LOCAL_FLAGS
);
1612 SET_FLAG(n
->flags
, ZEBRA_NEIGH_REMOTE
);
1613 ZEBRA_NEIGH_SET_ACTIVE(n
);
1614 n
->r_vtep_ip
= zmac
->fwd_info
.r_vtep_ip
;
1620 /* Notify Neighbor entries to the Client, skips the GW entry */
1622 zebra_evpn_send_neigh_hash_entry_to_client(struct hash_bucket
*bucket
,
1625 struct mac_walk_ctx
*wctx
= arg
;
1626 struct zebra_neigh
*zn
= bucket
->data
;
1627 struct zebra_mac
*zmac
= NULL
;
1629 if (CHECK_FLAG(zn
->flags
, ZEBRA_NEIGH_DEF_GW
))
1632 if (CHECK_FLAG(zn
->flags
, ZEBRA_NEIGH_LOCAL
)
1633 && IS_ZEBRA_NEIGH_ACTIVE(zn
)) {
1634 zmac
= zebra_evpn_mac_lookup(wctx
->zevpn
, &zn
->emac
);
1638 zebra_evpn_neigh_send_add_to_client(wctx
->zevpn
->vni
, &zn
->ip
,
1640 zn
->flags
, zn
->loc_seq
);
1644 /* Iterator of a specific EVPN */
1645 void zebra_evpn_send_neigh_to_client(struct zebra_evpn
*zevpn
)
1647 struct neigh_walk_ctx wctx
;
1649 memset(&wctx
, 0, sizeof(wctx
));
1652 hash_iterate(zevpn
->neigh_table
,
1653 zebra_evpn_send_neigh_hash_entry_to_client
, &wctx
);
1656 void zebra_evpn_clear_dup_neigh_hash(struct hash_bucket
*bucket
, void *ctxt
)
1658 struct neigh_walk_ctx
*wctx
= ctxt
;
1659 struct zebra_neigh
*nbr
;
1660 struct zebra_evpn
*zevpn
;
1661 char buf
[INET6_ADDRSTRLEN
];
1663 nbr
= (struct zebra_neigh
*)bucket
->data
;
1667 zevpn
= wctx
->zevpn
;
1669 if (!CHECK_FLAG(nbr
->flags
, ZEBRA_NEIGH_DUPLICATE
))
1672 if (IS_ZEBRA_DEBUG_VXLAN
) {
1673 ipaddr2str(&nbr
->ip
, buf
, sizeof(buf
));
1674 zlog_debug("%s: clear neigh %s dup state, flags 0x%x seq %u",
1675 __func__
, buf
, nbr
->flags
, nbr
->loc_seq
);
1678 UNSET_FLAG(nbr
->flags
, ZEBRA_NEIGH_DUPLICATE
);
1680 nbr
->detect_start_time
.tv_sec
= 0;
1681 nbr
->detect_start_time
.tv_usec
= 0;
1682 nbr
->dad_dup_detect_time
= 0;
1683 THREAD_OFF(nbr
->dad_ip_auto_recovery_timer
);
1685 if (CHECK_FLAG(nbr
->flags
, ZEBRA_NEIGH_LOCAL
)) {
1686 zebra_evpn_neigh_send_add_to_client(zevpn
->vni
, &nbr
->ip
,
1687 &nbr
->emac
, nbr
->mac
,
1688 nbr
->flags
, nbr
->loc_seq
);
1689 } else if (CHECK_FLAG(nbr
->flags
, ZEBRA_NEIGH_REMOTE
)) {
1690 zebra_evpn_rem_neigh_install(zevpn
, nbr
, false /*was_static*/);
1695 * Print a specific neighbor entry.
1697 void zebra_evpn_print_neigh(struct zebra_neigh
*n
, void *ctxt
,
1701 char buf1
[ETHER_ADDR_STRLEN
];
1702 char buf2
[INET6_ADDRSTRLEN
];
1703 const char *type_str
;
1704 const char *state_str
;
1705 bool flags_present
= false;
1706 struct zebra_vrf
*zvrf
= NULL
;
1707 struct timeval detect_start_time
= {0, 0};
1708 char timebuf
[MONOTIME_STRLEN
];
1709 char thread_buf
[THREAD_TIMER_STRLEN
];
1711 char up_str
[MONOTIME_STRLEN
];
1713 zvrf
= zebra_vrf_get_evpn();
1714 uptime
= monotime(NULL
);
1715 uptime
-= n
->uptime
;
1717 frrtime_to_interval(uptime
, up_str
, sizeof(up_str
));
1719 ipaddr2str(&n
->ip
, buf2
, sizeof(buf2
));
1720 prefix_mac2str(&n
->emac
, buf1
, sizeof(buf1
));
1721 type_str
= CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_LOCAL
) ? "local" : "remote";
1722 state_str
= IS_ZEBRA_NEIGH_ACTIVE(n
) ? "active" : "inactive";
1723 vty
= (struct vty
*)ctxt
;
1725 bool sync_info
= false;
1727 vty_out(vty
, "IP: %s\n",
1728 ipaddr2str(&n
->ip
, buf2
, sizeof(buf2
)));
1729 vty_out(vty
, " Type: %s\n", type_str
);
1730 vty_out(vty
, " State: %s\n", state_str
);
1731 vty_out(vty
, " Uptime: %s\n", up_str
);
1732 vty_out(vty
, " MAC: %s\n",
1733 prefix_mac2str(&n
->emac
, buf1
, sizeof(buf1
)));
1734 vty_out(vty
, " Sync-info:");
1735 if (CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_LOCAL_INACTIVE
)) {
1736 vty_out(vty
, " local-inactive");
1739 if (CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_ES_PEER_PROXY
)) {
1740 vty_out(vty
, " peer-proxy");
1743 if (CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_ES_PEER_ACTIVE
)) {
1744 vty_out(vty
, " peer-active");
1747 if (n
->hold_timer
) {
1748 vty_out(vty
, " (ht: %s)",
1749 thread_timer_to_hhmmss(thread_buf
,
1758 json_object_string_add(json
, "uptime", up_str
);
1759 json_object_string_add(json
, "ip", buf2
);
1760 json_object_string_add(json
, "type", type_str
);
1761 json_object_string_add(json
, "state", state_str
);
1762 json_object_string_add(json
, "mac", buf1
);
1763 if (CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_LOCAL_INACTIVE
))
1764 json_object_boolean_true_add(json
, "localInactive");
1765 if (CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_ES_PEER_PROXY
))
1766 json_object_boolean_true_add(json
, "peerProxy");
1767 if (CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_ES_PEER_ACTIVE
))
1768 json_object_boolean_true_add(json
, "peerActive");
1770 json_object_string_add(
1771 json
, "peerActiveHold",
1772 thread_timer_to_hhmmss(thread_buf
,
1776 if (CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_REMOTE
)) {
1779 json_object_string_add(json
, "remoteEs",
1780 n
->mac
->es
->esi_str
);
1782 vty_out(vty
, " Remote ES: %s\n",
1783 n
->mac
->es
->esi_str
);
1786 json_object_string_addf(json
, "remoteVtep",
1787 "%pI4", &n
->r_vtep_ip
);
1789 vty_out(vty
, " Remote VTEP: %pI4\n",
1793 if (CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_DEF_GW
)) {
1795 vty_out(vty
, " Flags: Default-gateway");
1796 flags_present
= true;
1798 json_object_boolean_true_add(json
, "defaultGateway");
1800 if (CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_ROUTER_FLAG
)) {
1803 flags_present
? " ,Router" : " Flags: Router");
1804 flags_present
= true;
1810 vty_out(vty
, " Local Seq: %u Remote Seq: %u\n", n
->loc_seq
,
1813 if (CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_DUPLICATE
)) {
1814 vty_out(vty
, " Duplicate, detected at %s",
1815 time_to_string(n
->dad_dup_detect_time
,
1817 } else if (n
->dad_count
) {
1818 monotime_since(&n
->detect_start_time
,
1819 &detect_start_time
);
1820 if (detect_start_time
.tv_sec
<= zvrf
->dad_time
) {
1821 time_to_string(n
->detect_start_time
.tv_sec
,
1824 " Duplicate detection started at %s, detection count %u\n",
1825 timebuf
, n
->dad_count
);
1829 json_object_int_add(json
, "localSequence", n
->loc_seq
);
1830 json_object_int_add(json
, "remoteSequence", n
->rem_seq
);
1831 json_object_int_add(json
, "detectionCount", n
->dad_count
);
1832 if (CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_DUPLICATE
))
1833 json_object_boolean_true_add(json
, "isDuplicate");
1835 json_object_boolean_false_add(json
, "isDuplicate");
1839 void zebra_evpn_print_neigh_hdr(struct vty
*vty
, struct neigh_walk_ctx
*wctx
)
1841 vty_out(vty
, "Flags: I=local-inactive, P=peer-active, X=peer-proxy\n");
1842 vty_out(vty
, "%*s %-6s %-5s %-8s %-17s %-30s %s\n", -wctx
->addr_width
,
1843 "Neighbor", "Type", "Flags", "State", "MAC", "Remote ES/VTEP",
1847 static char *zebra_evpn_print_neigh_flags(struct zebra_neigh
*n
,
1849 uint32_t flags_buf_sz
)
1851 snprintf(flags_buf
, flags_buf_sz
, "%s%s%s",
1852 (n
->flags
& ZEBRA_NEIGH_ES_PEER_ACTIVE
) ?
1854 (n
->flags
& ZEBRA_NEIGH_ES_PEER_PROXY
) ?
1856 (n
->flags
& ZEBRA_NEIGH_LOCAL_INACTIVE
) ?
1863 * Print neighbor hash entry - called for display of all neighbors.
1865 void zebra_evpn_print_neigh_hash(struct hash_bucket
*bucket
, void *ctxt
)
1868 json_object
*json_evpn
= NULL
, *json_row
= NULL
;
1869 struct zebra_neigh
*n
;
1870 char buf1
[ETHER_ADDR_STRLEN
];
1871 char buf2
[INET6_ADDRSTRLEN
];
1872 char addr_buf
[PREFIX_STRLEN
];
1873 struct neigh_walk_ctx
*wctx
= ctxt
;
1874 const char *state_str
;
1878 json_evpn
= wctx
->json
;
1879 n
= (struct zebra_neigh
*)bucket
->data
;
1882 json_row
= json_object_new_object();
1884 prefix_mac2str(&n
->emac
, buf1
, sizeof(buf1
));
1885 ipaddr2str(&n
->ip
, buf2
, sizeof(buf2
));
1886 state_str
= IS_ZEBRA_NEIGH_ACTIVE(n
) ? "active" : "inactive";
1887 if (CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_LOCAL
)) {
1888 if (wctx
->flags
& SHOW_REMOTE_NEIGH_FROM_VTEP
)
1891 if (json_evpn
== NULL
) {
1892 vty_out(vty
, "%*s %-6s %-5s %-8s %-17s %-30s %u/%u\n",
1893 -wctx
->addr_width
, buf2
, "local",
1894 zebra_evpn_print_neigh_flags(n
, flags_buf
,
1895 sizeof(flags_buf
)), state_str
, buf1
,
1896 "", n
->loc_seq
, n
->rem_seq
);
1898 json_object_string_add(json_row
, "type", "local");
1899 json_object_string_add(json_row
, "state", state_str
);
1900 json_object_string_add(json_row
, "mac", buf1
);
1901 if (CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_DEF_GW
))
1902 json_object_boolean_true_add(json_row
,
1904 json_object_int_add(json_row
, "localSequence",
1906 json_object_int_add(json_row
, "remoteSequence",
1908 json_object_int_add(json_row
, "detectionCount",
1910 if (CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_DUPLICATE
))
1911 json_object_boolean_true_add(json_row
,
1914 json_object_boolean_false_add(json_row
,
1918 } else if (CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_REMOTE
)) {
1919 if ((wctx
->flags
& SHOW_REMOTE_NEIGH_FROM_VTEP
)
1920 && !IPV4_ADDR_SAME(&n
->r_vtep_ip
, &wctx
->r_vtep_ip
))
1923 if (json_evpn
== NULL
) {
1924 if ((wctx
->flags
& SHOW_REMOTE_NEIGH_FROM_VTEP
)
1925 && (wctx
->count
== 0))
1926 zebra_evpn_print_neigh_hdr(vty
, wctx
);
1928 if (n
->mac
->es
== NULL
)
1929 inet_ntop(AF_INET
, &n
->r_vtep_ip
,
1930 addr_buf
, sizeof(addr_buf
));
1932 vty_out(vty
, "%*s %-6s %-5s %-8s %-17s %-30s %u/%u\n",
1933 -wctx
->addr_width
, buf2
, "remote",
1934 zebra_evpn_print_neigh_flags(n
, flags_buf
,
1935 sizeof(flags_buf
)), state_str
, buf1
,
1936 n
->mac
->es
? n
->mac
->es
->esi_str
: addr_buf
,
1937 n
->loc_seq
, n
->rem_seq
);
1939 json_object_string_add(json_row
, "type", "remote");
1940 json_object_string_add(json_row
, "state", state_str
);
1941 json_object_string_add(json_row
, "mac", buf1
);
1943 json_object_string_add(json_row
, "remoteEs",
1944 n
->mac
->es
->esi_str
);
1946 json_object_string_addf(json_row
, "remoteVtep",
1947 "%pI4", &n
->r_vtep_ip
);
1948 if (CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_DEF_GW
))
1949 json_object_boolean_true_add(json_row
,
1951 json_object_int_add(json_row
, "localSequence",
1953 json_object_int_add(json_row
, "remoteSequence",
1955 json_object_int_add(json_row
, "detectionCount",
1957 if (CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_DUPLICATE
))
1958 json_object_boolean_true_add(json_row
,
1961 json_object_boolean_false_add(json_row
,
1968 json_object_object_add(json_evpn
, buf2
, json_row
);
1972 * Print neighbor hash entry in detail - called for display of all neighbors.
1974 void zebra_evpn_print_neigh_hash_detail(struct hash_bucket
*bucket
, void *ctxt
)
1977 json_object
*json_evpn
= NULL
, *json_row
= NULL
;
1978 struct zebra_neigh
*n
;
1979 char buf
[INET6_ADDRSTRLEN
];
1980 struct neigh_walk_ctx
*wctx
= ctxt
;
1983 json_evpn
= wctx
->json
;
1984 n
= (struct zebra_neigh
*)bucket
->data
;
1988 ipaddr2str(&n
->ip
, buf
, sizeof(buf
));
1990 json_row
= json_object_new_object();
1992 zebra_evpn_print_neigh(n
, vty
, json_row
);
1995 json_object_object_add(json_evpn
, buf
, json_row
);
1998 void zebra_evpn_print_dad_neigh_hash(struct hash_bucket
*bucket
, void *ctxt
)
2000 struct zebra_neigh
*nbr
;
2002 nbr
= (struct zebra_neigh
*)bucket
->data
;
2006 if (CHECK_FLAG(nbr
->flags
, ZEBRA_NEIGH_DUPLICATE
))
2007 zebra_evpn_print_neigh_hash(bucket
, ctxt
);
2010 void zebra_evpn_print_dad_neigh_hash_detail(struct hash_bucket
*bucket
,
2013 struct zebra_neigh
*nbr
;
2015 nbr
= (struct zebra_neigh
*)bucket
->data
;
2019 if (CHECK_FLAG(nbr
->flags
, ZEBRA_NEIGH_DUPLICATE
))
2020 zebra_evpn_print_neigh_hash_detail(bucket
, ctxt
);
2023 void zebra_evpn_neigh_remote_macip_add(struct zebra_evpn
*zevpn
,
2024 struct zebra_vrf
*zvrf
,
2025 const struct ipaddr
*ipaddr
,
2026 struct zebra_mac
*mac
,
2027 struct in_addr vtep_ip
, uint8_t flags
,
2030 struct zebra_neigh
*n
;
2031 int update_neigh
= 0;
2032 struct zebra_mac
*old_mac
= NULL
;
2033 bool old_static
= false;
2034 bool do_dad
= false;
2035 bool is_dup_detect
= false;
2039 is_router
= !!CHECK_FLAG(flags
, ZEBRA_MACIP_TYPE_ROUTER_FLAG
);
2041 /* Check if the remote neighbor itself is unknown or has a
2042 * change. If so, create or update and then install the entry.
2044 n
= zebra_evpn_neigh_lookup(zevpn
, ipaddr
);
2045 if (!n
|| !CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_REMOTE
)
2046 || is_router
!= !!CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_ROUTER_FLAG
)
2047 || (memcmp(&n
->emac
, &mac
->macaddr
, sizeof(struct ethaddr
)) != 0)
2048 || !IPV4_ADDR_SAME(&n
->r_vtep_ip
, &vtep_ip
) || seq
!= n
->rem_seq
)
2053 n
= zebra_evpn_neigh_add(zevpn
, ipaddr
, &mac
->macaddr
,
2056 /* When host moves but changes its (MAC,IP)
2057 * binding, BGP may install a MACIP entry that
2058 * corresponds to "older" location of the host
2059 * in transient situations (because {IP1,M1}
2060 * is a different route from {IP1,M2}). Check
2061 * the sequence number and ignore this update
2065 if (!zebra_evpn_neigh_is_bgp_seq_ok(
2066 zevpn
, n
, &mac
->macaddr
, seq
, false))
2068 if (CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_LOCAL
)) {
2069 old_static
= zebra_evpn_neigh_is_static(n
);
2070 if (IS_ZEBRA_DEBUG_EVPN_MH_NEIGH
)
2072 "sync->remote neigh vni %u ip %pIA mac %pEA seq %d f0x%x",
2073 n
->zevpn
->vni
, &n
->ip
, &n
->emac
,
2075 if (IS_ZEBRA_NEIGH_ACTIVE(n
))
2076 zebra_evpn_neigh_send_del_to_client(
2077 zevpn
->vni
, &n
->ip
, &n
->emac
,
2080 zebra_evpn_neigh_clear_sync_info(n
);
2082 if (memcmp(&n
->emac
, &mac
->macaddr
,
2083 sizeof(struct ethaddr
))
2085 /* update neigh list for macs */
2087 zebra_evpn_mac_lookup(zevpn
, &n
->emac
);
2089 listnode_delete(old_mac
->neigh_list
, n
);
2091 zebra_evpn_deref_ip2mac(zevpn
, old_mac
);
2094 listnode_add_sort(mac
->neigh_list
, n
);
2095 memcpy(&n
->emac
, &mac
->macaddr
, ETH_ALEN
);
2097 /* Check Neigh's curent state is local
2098 * (this is the case where neigh/host has moved
2099 * from L->R) and check previous detction
2100 * started via local learning.
2102 * RFC-7432: A PE/VTEP that detects a MAC
2103 * mobilit event via local learning starts
2104 * an M-second timer.
2105 * VTEP-IP or seq. change along is not
2106 * considered for dup. detection.
2108 * Mobilty event scenario-B IP-MAC binding
2111 if ((!CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_REMOTE
))
2117 /* Set "remote" forwarding info. */
2118 UNSET_FLAG(n
->flags
, ZEBRA_NEIGH_ALL_LOCAL_FLAGS
);
2119 n
->r_vtep_ip
= vtep_ip
;
2120 SET_FLAG(n
->flags
, ZEBRA_NEIGH_REMOTE
);
2122 /* Set router flag (R-bit) to this Neighbor entry */
2123 if (CHECK_FLAG(flags
, ZEBRA_MACIP_TYPE_ROUTER_FLAG
))
2124 SET_FLAG(n
->flags
, ZEBRA_NEIGH_ROUTER_FLAG
);
2126 UNSET_FLAG(n
->flags
, ZEBRA_NEIGH_ROUTER_FLAG
);
2128 /* Check old or new MAC detected as duplicate,
2129 * inherit duplicate flag to this neigh.
2131 if (zebra_evpn_ip_inherit_dad_from_mac(zvrf
, old_mac
, mac
, n
)) {
2133 EC_ZEBRA_DUP_IP_INHERIT_DETECTED
,
2134 "VNI %u: MAC %pEA IP %pIA detected as duplicate during remote update, inherit duplicate from MAC",
2135 zevpn
->vni
, &mac
->macaddr
, &n
->ip
);
2138 /* Check duplicate address detection for IP */
2139 zebra_evpn_dup_addr_detect_for_neigh(
2140 zvrf
, n
, n
->r_vtep_ip
, do_dad
, &is_dup_detect
, false);
2141 /* Install the entry. */
2143 zebra_evpn_rem_neigh_install(zevpn
, n
, old_static
);
2146 /* Update seq number. */
2150 int zebra_evpn_neigh_gw_macip_add(struct interface
*ifp
,
2151 struct zebra_evpn
*zevpn
, struct ipaddr
*ip
,
2152 struct zebra_mac
*mac
)
2154 struct zebra_neigh
*n
;
2158 n
= zebra_evpn_neigh_lookup(zevpn
, ip
);
2160 n
= zebra_evpn_neigh_add(zevpn
, ip
, &mac
->macaddr
, mac
, 0);
2162 /* Set "local" forwarding info. */
2163 SET_FLAG(n
->flags
, ZEBRA_NEIGH_LOCAL
);
2164 ZEBRA_NEIGH_SET_ACTIVE(n
);
2165 memcpy(&n
->emac
, &mac
->macaddr
, ETH_ALEN
);
2166 n
->ifindex
= ifp
->ifindex
;
2168 /* Only advertise in BGP if the knob is enabled */
2169 if (advertise_gw_macip_enabled(zevpn
)) {
2171 SET_FLAG(n
->flags
, ZEBRA_NEIGH_DEF_GW
);
2172 /* Set Router flag (R-bit) */
2173 if (ip
->ipa_type
== IPADDR_V6
)
2174 SET_FLAG(n
->flags
, ZEBRA_NEIGH_ROUTER_FLAG
);
2176 if (IS_ZEBRA_DEBUG_VXLAN
)
2178 "SVI %s(%u) L2-VNI %u, sending GW MAC %pEA IP %pIA add to BGP with flags 0x%x",
2179 ifp
->name
, ifp
->ifindex
, zevpn
->vni
,
2180 &mac
->macaddr
, ip
, n
->flags
);
2182 zebra_evpn_neigh_send_add_to_client(
2183 zevpn
->vni
, ip
, &n
->emac
, n
->mac
, n
->flags
, n
->loc_seq
);
2184 } else if (advertise_svi_macip_enabled(zevpn
)) {
2186 SET_FLAG(n
->flags
, ZEBRA_NEIGH_SVI_IP
);
2187 if (IS_ZEBRA_DEBUG_VXLAN
)
2189 "SVI %s(%u) L2-VNI %u, sending SVI MAC %pEA IP %pIA add to BGP with flags 0x%x",
2190 ifp
->name
, ifp
->ifindex
, zevpn
->vni
,
2191 &mac
->macaddr
, ip
, n
->flags
);
2193 zebra_evpn_neigh_send_add_to_client(
2194 zevpn
->vni
, ip
, &n
->emac
, n
->mac
, n
->flags
, n
->loc_seq
);
2200 void zebra_evpn_neigh_remote_uninstall(struct zebra_evpn
*zevpn
,
2201 struct zebra_vrf
*zvrf
,
2202 struct zebra_neigh
*n
,
2203 struct zebra_mac
*mac
,
2204 const struct ipaddr
*ipaddr
)
2206 if (zvrf
->dad_freeze
&& CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_DUPLICATE
)
2207 && CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_REMOTE
)
2208 && (memcmp(n
->emac
.octet
, mac
->macaddr
.octet
, ETH_ALEN
) == 0)) {
2209 struct interface
*vlan_if
;
2211 vlan_if
= zevpn_map_to_svi(zevpn
);
2212 if (IS_ZEBRA_DEBUG_VXLAN
)
2214 "%s: IP %pIA (flags 0x%x intf %s) is remote and duplicate, read kernel for local entry",
2215 __func__
, ipaddr
, n
->flags
,
2216 vlan_if
? vlan_if
->name
: "Unknown");
2218 neigh_read_specific_ip(ipaddr
, vlan_if
);
2221 /* When the MAC changes for an IP, it is possible the
2222 * client may update the new MAC before trying to delete the
2223 * "old" neighbor (as these are two different MACIP routes).
2224 * Do the delete only if the MAC matches.
2226 if (!memcmp(n
->emac
.octet
, mac
->macaddr
.octet
, ETH_ALEN
)) {
2227 if (CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_LOCAL
)) {
2228 zebra_evpn_sync_neigh_del(n
);
2229 } else if (CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_REMOTE
)) {
2230 zebra_evpn_neigh_uninstall(zevpn
, n
);
2231 zebra_evpn_neigh_del(zevpn
, n
);
2232 zebra_evpn_deref_ip2mac(zevpn
, mac
);
2235 if (IS_ZEBRA_DEBUG_VXLAN
)
2237 "%s: IP %pIA MAC %pEA (flags 0x%x) found doesn't match MAC %pEA, ignoring Neigh DEL",
2238 __func__
, ipaddr
, &n
->emac
, n
->flags
,
2243 int zebra_evpn_neigh_del_ip(struct zebra_evpn
*zevpn
, const struct ipaddr
*ip
)
2245 struct zebra_neigh
*n
;
2246 struct zebra_mac
*zmac
;
2249 struct zebra_vrf
*zvrf
;
2251 /* If entry doesn't exist, nothing to do. */
2252 n
= zebra_evpn_neigh_lookup(zevpn
, ip
);
2256 zmac
= zebra_evpn_mac_lookup(zevpn
, &n
->emac
);
2258 if (IS_ZEBRA_DEBUG_VXLAN
)
2260 "Trying to del a neigh %pIA without a mac %pEA on VNI %u",
2267 /* If it is a remote entry, the kernel has aged this out or someone has
2268 * deleted it, it needs to be re-installed as FRR is the owner.
2270 if (CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_REMOTE
)) {
2271 zebra_evpn_rem_neigh_install(zevpn
, n
, false /*was_static*/);
2275 /* if this is a sync entry it cannot be dropped re-install it in
2278 old_bgp_ready
= zebra_evpn_neigh_is_ready_for_bgp(n
);
2279 if (zebra_evpn_neigh_is_static(n
)) {
2280 if (IS_ZEBRA_DEBUG_EVPN_MH_NEIGH
)
2281 zlog_debug("re-add sync neigh vni %u ip %pIA mac %pEA 0x%x",
2282 n
->zevpn
->vni
, &n
->ip
, &n
->emac
,
2285 if (!CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_LOCAL_INACTIVE
))
2286 SET_FLAG(n
->flags
, ZEBRA_NEIGH_LOCAL_INACTIVE
);
2287 /* inform-bgp about change in local-activity if any */
2288 new_bgp_ready
= zebra_evpn_neigh_is_ready_for_bgp(n
);
2289 zebra_evpn_neigh_send_add_del_to_client(n
, old_bgp_ready
,
2292 /* re-install the entry in the kernel */
2293 zebra_evpn_sync_neigh_dp_install(n
, false /* set_inactive */,
2294 false /* force_clear_static */,
2300 zvrf
= zevpn
->vxlan_if
->vrf
->info
;
2302 zlog_debug("%s: VNI %u vrf lookup failed.", __func__
,
2307 /* In case of feeze action, if local neigh is in duplicate state,
2308 * Mark the Neigh as inactive before sending delete request to BGPd,
2309 * If BGPd has remote entry, it will re-install
2311 if (zvrf
->dad_freeze
&& CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_DUPLICATE
))
2312 ZEBRA_NEIGH_SET_INACTIVE(n
);
2314 /* Remove neighbor from BGP. */
2315 zebra_evpn_neigh_send_del_to_client(zevpn
->vni
, &n
->ip
, &n
->emac
,
2319 /* Delete this neighbor entry. */
2320 zebra_evpn_neigh_del(zevpn
, n
);
2322 /* see if the AUTO mac needs to be deleted */
2323 if (CHECK_FLAG(zmac
->flags
, ZEBRA_MAC_AUTO
)
2324 && !zebra_evpn_mac_in_use(zmac
))
2325 zebra_evpn_mac_del(zevpn
, zmac
);