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_vxlan.h"
40 #include "zebra/zebra_vxlan_if.h"
41 #include "zebra/zebra_evpn.h"
42 #include "zebra/zebra_evpn_mh.h"
43 #include "zebra/zebra_evpn_neigh.h"
44 #include "zebra/zebra_evpn_mac.h"
46 DEFINE_MTYPE_STATIC(ZEBRA
, NEIGH
, "EVI Neighbor");
49 * Make hash key for neighbors.
51 static unsigned int neigh_hash_keymake(const void *p
)
53 const struct zebra_neigh
*n
= p
;
54 const struct ipaddr
*ip
= &n
->ip
;
57 return jhash_1word(ip
->ipaddr_v4
.s_addr
, 0);
59 return jhash2(ip
->ipaddr_v6
.s6_addr32
,
60 array_size(ip
->ipaddr_v6
.s6_addr32
), 0);
64 * Compare two neighbor hash structures.
66 static bool neigh_cmp(const void *p1
, const void *p2
)
68 const struct zebra_neigh
*n1
= p1
;
69 const struct zebra_neigh
*n2
= p2
;
71 if (n1
== NULL
&& n2
== NULL
)
74 if (n1
== NULL
|| n2
== NULL
)
77 return ipaddr_cmp(&n1
->ip
, &n2
->ip
) == 0;
80 int neigh_list_cmp(void *p1
, void *p2
)
82 const struct zebra_neigh
*n1
= p1
;
83 const struct zebra_neigh
*n2
= p2
;
85 return ipaddr_cmp(&n1
->ip
, &n2
->ip
);
88 struct hash
*zebra_neigh_db_create(const char *desc
)
90 return hash_create_size(8, neigh_hash_keymake
, neigh_cmp
, desc
);
93 uint32_t num_dup_detected_neighs(struct zebra_evpn
*zevpn
)
96 uint32_t num_neighs
= 0;
98 struct hash_bucket
*hb
;
99 struct zebra_neigh
*nbr
;
101 hash
= zevpn
->neigh_table
;
104 for (i
= 0; i
< hash
->size
; i
++) {
105 for (hb
= hash
->index
[i
]; hb
; hb
= hb
->next
) {
106 nbr
= (struct zebra_neigh
*)hb
->data
;
107 if (CHECK_FLAG(nbr
->flags
, ZEBRA_NEIGH_DUPLICATE
))
116 * Helper function to determine maximum width of neighbor IP address for
117 * display - just because we're dealing with IPv6 addresses that can
120 void zebra_evpn_find_neigh_addr_width(struct hash_bucket
*bucket
, void *ctxt
)
122 struct zebra_neigh
*n
;
123 char buf
[INET6_ADDRSTRLEN
];
124 struct neigh_walk_ctx
*wctx
= ctxt
;
127 n
= (struct zebra_neigh
*)bucket
->data
;
129 ipaddr2str(&n
->ip
, buf
, sizeof(buf
));
131 if (width
> wctx
->addr_width
)
132 wctx
->addr_width
= width
;
136 * Count of remote neighbors referencing this MAC.
138 int remote_neigh_count(struct zebra_mac
*zmac
)
140 struct zebra_neigh
*n
= NULL
;
141 struct listnode
*node
= NULL
;
144 for (ALL_LIST_ELEMENTS_RO(zmac
->neigh_list
, node
, n
)) {
145 if (CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_REMOTE
))
153 * Install remote neighbor into the kernel.
155 int zebra_evpn_rem_neigh_install(struct zebra_evpn
*zevpn
,
156 struct zebra_neigh
*n
, bool was_static
)
158 struct interface
*vlan_if
;
162 if (!(n
->flags
& ZEBRA_NEIGH_REMOTE
))
165 vlan_if
= zevpn_map_to_svi(zevpn
);
169 flags
= DPLANE_NTF_EXT_LEARNED
;
170 if (n
->flags
& ZEBRA_NEIGH_ROUTER_FLAG
)
171 flags
|= DPLANE_NTF_ROUTER
;
172 ZEBRA_NEIGH_SET_ACTIVE(n
);
174 dplane_rem_neigh_add(vlan_if
, &n
->ip
, &n
->emac
, flags
, was_static
);
180 * Install neighbor hash entry - called upon access VLAN change.
182 void zebra_evpn_install_neigh_hash(struct hash_bucket
*bucket
, void *ctxt
)
184 struct zebra_neigh
*n
;
185 struct neigh_walk_ctx
*wctx
= ctxt
;
187 n
= (struct zebra_neigh
*)bucket
->data
;
189 if (CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_REMOTE
))
190 zebra_evpn_rem_neigh_install(wctx
->zevpn
, n
,
191 false /*was_static*/);
195 * Callback to allocate neighbor hash entry.
197 static void *zebra_evpn_neigh_alloc(void *p
)
199 const struct zebra_neigh
*tmp_n
= p
;
200 struct zebra_neigh
*n
;
202 n
= XCALLOC(MTYPE_NEIGH
, sizeof(struct zebra_neigh
));
208 static void zebra_evpn_local_neigh_ref_mac(struct zebra_neigh
*n
,
209 const struct ethaddr
*macaddr
,
210 struct zebra_mac
*mac
,
211 bool send_mac_update
)
216 memcpy(&n
->emac
, macaddr
, ETH_ALEN
);
219 /* Link to new MAC */
223 listnode_add_sort(mac
->neigh_list
, n
);
224 if (n
->flags
& ZEBRA_NEIGH_ALL_PEER_FLAGS
) {
225 old_static
= zebra_evpn_mac_is_static(mac
);
226 ++mac
->sync_neigh_cnt
;
227 new_static
= zebra_evpn_mac_is_static(mac
);
228 if (IS_ZEBRA_DEBUG_EVPN_MH_NEIGH
)
230 "sync-neigh ref mac vni %u ip %pIA mac %pEA ref %d",
231 n
->zevpn
->vni
, &n
->ip
, &n
->emac
,
232 mac
->sync_neigh_cnt
);
233 if ((old_static
!= new_static
) && send_mac_update
)
234 /* program the local mac in the kernel */
235 zebra_evpn_sync_mac_dp_install(
236 mac
, false /*set_inactive*/,
237 false /*force_clear_static*/, __func__
);
241 /* sync-path that is active on an ES peer */
242 static void zebra_evpn_sync_neigh_dp_install(struct zebra_neigh
*n
,
244 bool force_clear_static
,
247 struct zebra_ns
*zns
;
248 struct interface
*ifp
;
252 zns
= zebra_ns_lookup(NS_DEFAULT
);
253 ifp
= if_lookup_by_index_per_ns(zns
, n
->ifindex
);
255 if (IS_ZEBRA_DEBUG_EVPN_MH_NEIGH
)
257 "%s: dp-install sync-neigh vni %u ip %pIA mac %pEA if %d f 0x%x skipped",
258 caller
, n
->zevpn
->vni
, &n
->ip
, &n
->emac
,
259 n
->ifindex
, n
->flags
);
263 if (force_clear_static
)
266 set_static
= zebra_evpn_neigh_is_static(n
);
268 set_router
= !!CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_ROUTER_FLAG
);
270 /* XXX - this will change post integration with the new kernel */
271 if (CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_LOCAL_INACTIVE
))
274 if (IS_ZEBRA_DEBUG_EVPN_MH_NEIGH
)
276 "%s: dp-install sync-neigh vni %u ip %pIA mac %pEA if %s(%d) f 0x%x%s%s%s",
277 caller
, n
->zevpn
->vni
, &n
->ip
, &n
->emac
,
278 ifp
->name
, n
->ifindex
, n
->flags
,
279 set_router
? " router" : "",
280 set_static
? " static" : "",
281 set_inactive
? " inactive" : "");
282 dplane_local_neigh_add(ifp
, &n
->ip
, &n
->emac
, set_router
, set_static
,
287 * Inform BGP about local neighbor addition.
289 int zebra_evpn_neigh_send_add_to_client(vni_t vni
, const struct ipaddr
*ip
,
290 const struct ethaddr
*macaddr
,
291 struct zebra_mac
*zmac
,
292 uint32_t neigh_flags
, uint32_t seq
)
296 if (CHECK_FLAG(neigh_flags
, ZEBRA_NEIGH_LOCAL_INACTIVE
)) {
297 /* host reachability has not been verified locally */
299 /* if no ES peer is claiming reachability we can't advertise
302 if (!CHECK_FLAG(neigh_flags
, ZEBRA_NEIGH_ES_PEER_ACTIVE
))
305 /* ES peers are claiming reachability; we will
306 * advertise the entry but with a proxy flag
308 SET_FLAG(flags
, ZEBRA_MACIP_TYPE_PROXY_ADVERT
);
311 if (CHECK_FLAG(neigh_flags
, ZEBRA_NEIGH_DEF_GW
))
312 SET_FLAG(flags
, ZEBRA_MACIP_TYPE_GW
);
313 /* Set router flag (R-bit) based on local neigh entry add */
314 if (CHECK_FLAG(neigh_flags
, ZEBRA_NEIGH_ROUTER_FLAG
))
315 SET_FLAG(flags
, ZEBRA_MACIP_TYPE_ROUTER_FLAG
);
316 if (CHECK_FLAG(neigh_flags
, ZEBRA_NEIGH_SVI_IP
))
317 SET_FLAG(flags
, ZEBRA_MACIP_TYPE_SVI_IP
);
319 return zebra_evpn_macip_send_msg_to_client(vni
, macaddr
, ip
, flags
, seq
,
320 ZEBRA_NEIGH_ACTIVE
, zmac
->es
,
325 * Inform BGP about local neighbor deletion.
327 int zebra_evpn_neigh_send_del_to_client(vni_t vni
, struct ipaddr
*ip
,
328 struct ethaddr
*macaddr
, uint32_t flags
,
329 int state
, bool force
)
332 if (CHECK_FLAG(flags
, ZEBRA_NEIGH_LOCAL_INACTIVE
)
333 && !CHECK_FLAG(flags
, ZEBRA_NEIGH_ES_PEER_ACTIVE
))
334 /* the neigh was not advertised - nothing to delete */
338 return zebra_evpn_macip_send_msg_to_client(
339 vni
, macaddr
, ip
, flags
, 0, state
, NULL
, ZEBRA_MACIP_DEL
);
342 static void zebra_evpn_neigh_send_add_del_to_client(struct zebra_neigh
*n
,
347 zebra_evpn_neigh_send_add_to_client(n
->zevpn
->vni
, &n
->ip
,
348 &n
->emac
, n
->mac
, n
->flags
,
350 else if (old_bgp_ready
)
351 zebra_evpn_neigh_send_del_to_client(n
->zevpn
->vni
, &n
->ip
,
353 n
->state
, true /*force*/);
356 /* if the static flag associated with the neigh changes we need
357 * to update the sync-neigh references against the MAC
358 * and inform the dataplane about the static flag changes.
360 void zebra_evpn_sync_neigh_static_chg(struct zebra_neigh
*n
, bool old_n_static
,
361 bool new_n_static
, bool defer_n_dp
,
362 bool defer_mac_dp
, const char *caller
)
364 struct zebra_mac
*mac
= n
->mac
;
368 if (old_n_static
== new_n_static
)
371 /* update the neigh sync references in the dataplane. if
372 * the neigh is in the middle of updates the caller can
373 * request for a defer
376 zebra_evpn_sync_neigh_dp_install(n
, false /* set_inactive */,
377 false /* force_clear_static */,
383 /* update the mac sync ref cnt */
384 old_mac_static
= zebra_evpn_mac_is_static(mac
);
386 ++mac
->sync_neigh_cnt
;
387 } else if (old_n_static
) {
388 if (mac
->sync_neigh_cnt
)
389 --mac
->sync_neigh_cnt
;
391 new_mac_static
= zebra_evpn_mac_is_static(mac
);
393 /* update the mac sync references in the dataplane */
394 if ((old_mac_static
!= new_mac_static
) && !defer_mac_dp
)
395 zebra_evpn_sync_mac_dp_install(mac
, false /* set_inactive */,
396 false /* force_clear_static */,
399 if (IS_ZEBRA_DEBUG_EVPN_MH_NEIGH
)
401 "sync-neigh ref-chg vni %u ip %pIA mac %pEA f 0x%x %d%s%s%s%s by %s",
402 n
->zevpn
->vni
, &n
->ip
, &n
->emac
, n
->flags
,
404 old_n_static
? " old_n_static" : "",
405 new_n_static
? " new_n_static" : "",
406 old_mac_static
? " old_mac_static" : "",
407 new_mac_static
? " new_mac_static" : "", caller
);
410 /* Neigh hold timer is used to age out peer-active flag.
412 * During this wait time we expect the dataplane component or an
413 * external neighmgr daemon to probe existing hosts to independently
414 * establish their presence on the ES.
416 static void zebra_evpn_neigh_hold_exp_cb(struct thread
*t
)
418 struct zebra_neigh
*n
;
425 /* the purpose of the hold timer is to age out the peer-active
428 if (!CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_ES_PEER_ACTIVE
))
431 old_bgp_ready
= zebra_evpn_neigh_is_ready_for_bgp(n
);
432 old_n_static
= zebra_evpn_neigh_is_static(n
);
433 UNSET_FLAG(n
->flags
, ZEBRA_NEIGH_ES_PEER_ACTIVE
);
434 new_bgp_ready
= zebra_evpn_neigh_is_ready_for_bgp(n
);
435 new_n_static
= zebra_evpn_neigh_is_static(n
);
437 if (IS_ZEBRA_DEBUG_EVPN_MH_NEIGH
)
438 zlog_debug("sync-neigh vni %u ip %pIA mac %pEA 0x%x hold expired",
439 n
->zevpn
->vni
, &n
->ip
, &n
->emac
, n
->flags
);
441 /* re-program the local neigh in the dataplane if the neigh is no
444 if (old_n_static
!= new_n_static
)
445 zebra_evpn_sync_neigh_static_chg(
446 n
, old_n_static
, new_n_static
, false /*defer_n_dp*/,
447 false /*defer_mac_dp*/, __func__
);
449 /* inform bgp if needed */
450 if (old_bgp_ready
!= new_bgp_ready
)
451 zebra_evpn_neigh_send_add_del_to_client(n
, old_bgp_ready
,
455 static inline void zebra_evpn_neigh_start_hold_timer(struct zebra_neigh
*n
)
460 if (IS_ZEBRA_DEBUG_EVPN_MH_NEIGH
)
461 zlog_debug("sync-neigh vni %u ip %pIA mac %pEA 0x%x hold start",
462 n
->zevpn
->vni
, &n
->ip
, &n
->emac
, n
->flags
);
463 thread_add_timer(zrouter
.master
, zebra_evpn_neigh_hold_exp_cb
, n
,
464 zmh_info
->neigh_hold_time
, &n
->hold_timer
);
467 static void zebra_evpn_local_neigh_deref_mac(struct zebra_neigh
*n
,
468 bool send_mac_update
)
470 struct zebra_mac
*mac
= n
->mac
;
471 struct zebra_evpn
*zevpn
= n
->zevpn
;
479 if ((n
->flags
& ZEBRA_NEIGH_ALL_PEER_FLAGS
) && mac
->sync_neigh_cnt
) {
480 old_static
= zebra_evpn_mac_is_static(mac
);
481 --mac
->sync_neigh_cnt
;
482 new_static
= zebra_evpn_mac_is_static(mac
);
483 if (IS_ZEBRA_DEBUG_EVPN_MH_NEIGH
)
485 "sync-neigh deref mac vni %u ip %pIA mac %pEA ref %d",
486 n
->zevpn
->vni
, &n
->ip
, &n
->emac
,
487 mac
->sync_neigh_cnt
);
488 if ((old_static
!= new_static
) && send_mac_update
)
489 /* program the local mac in the kernel */
490 zebra_evpn_sync_mac_dp_install(
491 mac
, false /* set_inactive */,
492 false /* force_clear_static */, __func__
);
495 listnode_delete(mac
->neigh_list
, n
);
496 zebra_evpn_deref_ip2mac(zevpn
, mac
);
499 bool zebra_evpn_neigh_is_bgp_seq_ok(struct zebra_evpn
*zevpn
,
500 struct zebra_neigh
*n
,
501 const struct ethaddr
*macaddr
, uint32_t seq
,
506 bool is_local
= false;
508 if (CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_LOCAL
)) {
509 tmp_seq
= n
->loc_seq
;
513 tmp_seq
= n
->rem_seq
;
518 if (is_local
&& !zebra_evpn_neigh_is_ready_for_bgp(n
)) {
519 if (IS_ZEBRA_DEBUG_EVPN_MH_NEIGH
||
520 IS_ZEBRA_DEBUG_VXLAN
)
522 "%s-macip not ready vni %u %s mac %pEA IP %pIA lower seq %u f 0x%x",
523 sync
? "sync" : "remote", zevpn
->vni
,
524 n_type
, macaddr
, &n
->ip
, tmp_seq
,
529 /* if the neigh was never advertised to bgp we must accept
530 * whatever sequence number bgp sends
532 if (!is_local
&& zebra_vxlan_get_accept_bgp_seq()) {
533 if (IS_ZEBRA_DEBUG_EVPN_MH_NEIGH
534 || IS_ZEBRA_DEBUG_VXLAN
)
536 "%s-macip accept vni %u %s mac %pEA IP %pIA lower seq %u f 0x%x",
537 sync
? "sync" : "remote", zevpn
->vni
,
538 n_type
, macaddr
, &n
->ip
,
543 if (IS_ZEBRA_DEBUG_EVPN_MH_NEIGH
|| IS_ZEBRA_DEBUG_VXLAN
)
545 "%s-macip ignore vni %u %s mac %pEA IP %pIA as existing has higher seq %u f 0x%x",
546 sync
? "sync" : "remote", zevpn
->vni
, n_type
,
547 macaddr
, &n
->ip
, tmp_seq
, n
->flags
);
555 * Add neighbor entry.
557 static struct zebra_neigh
*zebra_evpn_neigh_add(struct zebra_evpn
*zevpn
,
558 const struct ipaddr
*ip
,
559 const struct ethaddr
*mac
,
560 struct zebra_mac
*zmac
,
563 struct zebra_neigh tmp_n
;
564 struct zebra_neigh
*n
= NULL
;
566 memset(&tmp_n
, 0, sizeof(tmp_n
));
567 memcpy(&tmp_n
.ip
, ip
, sizeof(struct ipaddr
));
568 n
= hash_get(zevpn
->neigh_table
, &tmp_n
, zebra_evpn_neigh_alloc
);
570 n
->state
= ZEBRA_NEIGH_INACTIVE
;
572 n
->dad_ip_auto_recovery_timer
= NULL
;
574 n
->uptime
= monotime(NULL
);
577 zmac
= zebra_evpn_mac_lookup(zevpn
, mac
);
578 zebra_evpn_local_neigh_ref_mac(n
, mac
, zmac
,
579 false /* send_mac_update */);
585 * Delete neighbor entry.
587 int zebra_evpn_neigh_del(struct zebra_evpn
*zevpn
, struct zebra_neigh
*n
)
589 struct zebra_neigh
*tmp_n
;
592 listnode_delete(n
->mac
->neigh_list
, n
);
594 /* Cancel auto recovery */
595 THREAD_OFF(n
->dad_ip_auto_recovery_timer
);
597 /* Cancel proxy hold timer */
598 zebra_evpn_neigh_stop_hold_timer(n
);
600 /* Free the VNI hash entry and allocated memory. */
601 tmp_n
= hash_release(zevpn
->neigh_table
, n
);
602 XFREE(MTYPE_NEIGH
, tmp_n
);
607 void zebra_evpn_sync_neigh_del(struct zebra_neigh
*n
)
612 if (IS_ZEBRA_DEBUG_EVPN_MH_NEIGH
)
613 zlog_debug("sync-neigh del vni %u ip %pIA mac %pEA f 0x%x",
614 n
->zevpn
->vni
, &n
->ip
, &n
->emac
, n
->flags
);
616 old_n_static
= zebra_evpn_neigh_is_static(n
);
617 UNSET_FLAG(n
->flags
, ZEBRA_NEIGH_ES_PEER_PROXY
);
618 if (CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_ES_PEER_ACTIVE
))
619 zebra_evpn_neigh_start_hold_timer(n
);
620 new_n_static
= zebra_evpn_neigh_is_static(n
);
622 if (old_n_static
!= new_n_static
)
623 zebra_evpn_sync_neigh_static_chg(
624 n
, old_n_static
, new_n_static
, false /*defer-dp*/,
625 false /*defer_mac_dp*/, __func__
);
628 struct zebra_neigh
*zebra_evpn_proc_sync_neigh_update(
629 struct zebra_evpn
*zevpn
, struct zebra_neigh
*n
, uint16_t ipa_len
,
630 const struct ipaddr
*ipaddr
, uint8_t flags
, uint32_t seq
,
631 const esi_t
*esi
, struct zebra_mac
*mac
)
633 struct interface
*ifp
= NULL
;
636 bool old_router
= false;
637 bool old_bgp_ready
= false;
639 bool inform_dataplane
= false;
640 bool inform_bgp
= false;
643 bool set_dp_inactive
= false;
645 ifindex_t ifindex
= 0;
648 ifp
= zevpn_map_to_svi(zevpn
);
650 ifindex
= ifp
->ifindex
;
652 is_router
= !!CHECK_FLAG(flags
, ZEBRA_MACIP_TYPE_ROUTER_FLAG
);
653 old_mac_static
= zebra_evpn_mac_is_static(mac
);
656 uint32_t n_flags
= 0;
658 /* New neighbor - create */
659 SET_FLAG(n_flags
, ZEBRA_NEIGH_LOCAL
);
660 if (CHECK_FLAG(flags
, ZEBRA_MACIP_TYPE_PROXY_ADVERT
))
661 SET_FLAG(n_flags
, ZEBRA_NEIGH_ES_PEER_PROXY
);
663 SET_FLAG(n_flags
, ZEBRA_NEIGH_ES_PEER_ACTIVE
);
664 SET_FLAG(n_flags
, ZEBRA_NEIGH_LOCAL_INACTIVE
);
666 n
= zebra_evpn_neigh_add(zevpn
, ipaddr
, &mac
->macaddr
, mac
,
668 n
->ifindex
= ifindex
;
669 ZEBRA_NEIGH_SET_ACTIVE(n
);
672 inform_dataplane
= true;
674 set_dp_inactive
= true;
677 uint32_t old_flags
= n
->flags
;
682 old_n_static
= zebra_evpn_neigh_is_static(n
);
683 old_bgp_ready
= zebra_evpn_neigh_is_ready_for_bgp(n
);
684 old_router
= !!CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_ROUTER_FLAG
);
686 mac_change
= !!memcmp(&n
->emac
, &mac
->macaddr
, ETH_ALEN
);
688 /* deref and clear old info */
691 zebra_evpn_neigh_send_del_to_client(
692 zevpn
->vni
, &n
->ip
, &n
->emac
, n
->flags
,
693 n
->state
, false /*force*/);
694 old_bgp_ready
= false;
696 zebra_evpn_local_neigh_deref_mac(n
,
697 false /*send_mac_update*/);
699 /* clear old fwd info */
701 n
->r_vtep_ip
.s_addr
= 0;
703 /* setup new flags */
705 SET_FLAG(n
->flags
, ZEBRA_NEIGH_LOCAL
);
706 /* retain activity flag if the neigh was
709 if (old_flags
& ZEBRA_NEIGH_LOCAL
) {
710 n
->flags
|= (old_flags
& ZEBRA_NEIGH_LOCAL_INACTIVE
);
712 inform_dataplane
= true;
713 set_dp_inactive
= true;
714 n
->flags
|= ZEBRA_NEIGH_LOCAL_INACTIVE
;
717 if (CHECK_FLAG(flags
, ZEBRA_MACIP_TYPE_PROXY_ADVERT
)) {
718 SET_FLAG(n
->flags
, ZEBRA_NEIGH_ES_PEER_PROXY
);
719 /* if the neigh was peer-active previously we
720 * need to keep the flag and start the
721 * holdtimer on it. the peer-active flag is
722 * cleared on holdtimer expiry.
724 if (CHECK_FLAG(old_flags
, ZEBRA_NEIGH_ES_PEER_ACTIVE
)) {
725 SET_FLAG(n
->flags
, ZEBRA_NEIGH_ES_PEER_ACTIVE
);
726 zebra_evpn_neigh_start_hold_timer(n
);
729 SET_FLAG(n
->flags
, ZEBRA_NEIGH_ES_PEER_ACTIVE
);
730 /* stop hold timer if a peer has verified
733 zebra_evpn_neigh_stop_hold_timer(n
);
735 ZEBRA_NEIGH_SET_ACTIVE(n
);
737 if (IS_ZEBRA_DEBUG_EVPN_MH_NEIGH
&& (old_flags
!= n
->flags
))
739 "sync-neigh vni %u ip %pIA mac %pEA old_f 0x%x new_f 0x%x",
740 n
->zevpn
->vni
, &n
->ip
, &n
->emac
,
741 old_flags
, n
->flags
);
743 new_n_static
= zebra_evpn_neigh_is_static(n
);
745 set_dp_inactive
= true;
746 n
->flags
|= ZEBRA_NEIGH_LOCAL_INACTIVE
;
747 inform_dataplane
= true;
748 zebra_evpn_local_neigh_ref_mac(
749 n
, &mac
->macaddr
, mac
,
750 false /*send_mac_update*/);
751 } else if (old_n_static
!= new_n_static
) {
752 inform_dataplane
= true;
753 /* if static flags have changed without a mac change
754 * we need to create the correct sync-refs against
757 zebra_evpn_sync_neigh_static_chg(
758 n
, old_n_static
, new_n_static
,
759 true /*defer_dp*/, true /*defer_mac_dp*/,
763 /* Update the forwarding info. */
764 if (n
->ifindex
!= ifindex
) {
765 n
->ifindex
= ifindex
;
766 inform_dataplane
= true;
769 n
->uptime
= monotime(NULL
);
772 /* update the neigh seq. we don't bother with the mac seq as
773 * sync_mac_update already took care of that
775 tmp_seq
= MAX(n
->loc_seq
, seq
);
776 if (tmp_seq
!= n
->loc_seq
) {
777 n
->loc_seq
= tmp_seq
;
781 /* Mark Router flag (R-bit) */
783 SET_FLAG(n
->flags
, ZEBRA_NEIGH_ROUTER_FLAG
);
785 UNSET_FLAG(n
->flags
, ZEBRA_NEIGH_ROUTER_FLAG
);
787 if (old_router
!= is_router
)
788 inform_dataplane
= true;
790 new_bgp_ready
= zebra_evpn_neigh_is_ready_for_bgp(n
);
791 if (old_bgp_ready
!= new_bgp_ready
)
794 new_mac_static
= zebra_evpn_mac_is_static(mac
);
795 if (old_mac_static
!= new_mac_static
)
796 zebra_evpn_sync_mac_dp_install(mac
, false /* set_inactive */,
797 false /* force_clear_static */,
800 if (IS_ZEBRA_DEBUG_EVPN_MH_NEIGH
)
802 "sync-neigh %s vni %u ip %pIA mac %pEA if %s(%d) seq %d f 0x%x%s%s",
803 created
? "created" : "updated", n
->zevpn
->vni
,
805 ifp
? ifp
->name
: "", ifindex
, n
->loc_seq
, n
->flags
,
806 inform_bgp
? " inform_bgp" : "",
807 inform_dataplane
? " inform_dp" : "");
809 if (inform_dataplane
)
810 zebra_evpn_sync_neigh_dp_install(n
, set_dp_inactive
,
811 false /* force_clear_static */,
815 zebra_evpn_neigh_send_add_del_to_client(n
, old_bgp_ready
,
822 * Uninstall remote neighbor from the kernel.
824 static int zebra_evpn_neigh_uninstall(struct zebra_evpn
*zevpn
,
825 struct zebra_neigh
*n
)
827 struct interface
*vlan_if
;
829 if (!(n
->flags
& ZEBRA_NEIGH_REMOTE
))
832 vlan_if
= zevpn_map_to_svi(zevpn
);
836 ZEBRA_NEIGH_SET_INACTIVE(n
);
839 dplane_rem_neigh_delete(vlan_if
, &n
->ip
);
845 * Free neighbor hash entry (callback)
847 static void zebra_evpn_neigh_del_hash_entry(struct hash_bucket
*bucket
,
850 struct neigh_walk_ctx
*wctx
= arg
;
851 struct zebra_neigh
*n
= bucket
->data
;
853 if (((wctx
->flags
& DEL_LOCAL_NEIGH
) && (n
->flags
& ZEBRA_NEIGH_LOCAL
))
854 || ((wctx
->flags
& DEL_REMOTE_NEIGH
)
855 && (n
->flags
& ZEBRA_NEIGH_REMOTE
))
856 || ((wctx
->flags
& DEL_REMOTE_NEIGH_FROM_VTEP
)
857 && (n
->flags
& ZEBRA_NEIGH_REMOTE
)
858 && IPV4_ADDR_SAME(&n
->r_vtep_ip
, &wctx
->r_vtep_ip
))) {
859 if (wctx
->upd_client
&& (n
->flags
& ZEBRA_NEIGH_LOCAL
))
860 zebra_evpn_neigh_send_del_to_client(
861 wctx
->zevpn
->vni
, &n
->ip
, &n
->emac
, n
->flags
,
862 n
->state
, false /*force*/);
864 if (wctx
->uninstall
) {
865 if (zebra_evpn_neigh_is_static(n
))
866 zebra_evpn_sync_neigh_dp_install(
867 n
, false /* set_inactive */,
868 true /* force_clear_static */,
870 if ((n
->flags
& ZEBRA_NEIGH_REMOTE
))
871 zebra_evpn_neigh_uninstall(wctx
->zevpn
, n
);
874 zebra_evpn_neigh_del(wctx
->zevpn
, n
);
881 * Delete all neighbor entries for this EVPN.
883 void zebra_evpn_neigh_del_all(struct zebra_evpn
*zevpn
, int uninstall
,
884 int upd_client
, uint32_t flags
)
886 struct neigh_walk_ctx wctx
;
888 if (!zevpn
->neigh_table
)
891 memset(&wctx
, 0, sizeof(wctx
));
893 wctx
.uninstall
= uninstall
;
894 wctx
.upd_client
= upd_client
;
897 hash_iterate(zevpn
->neigh_table
, zebra_evpn_neigh_del_hash_entry
,
902 * Look up neighbor hash entry.
904 struct zebra_neigh
*zebra_evpn_neigh_lookup(struct zebra_evpn
*zevpn
,
905 const struct ipaddr
*ip
)
907 struct zebra_neigh tmp
;
908 struct zebra_neigh
*n
;
910 memset(&tmp
, 0, sizeof(tmp
));
911 memcpy(&tmp
.ip
, ip
, sizeof(struct ipaddr
));
912 n
= hash_lookup(zevpn
->neigh_table
, &tmp
);
918 * Process all neighbors associated with a MAC upon the MAC being learnt
919 * locally or undergoing any other change (such as sequence number).
921 void zebra_evpn_process_neigh_on_local_mac_change(struct zebra_evpn
*zevpn
,
922 struct zebra_mac
*zmac
,
926 struct zebra_neigh
*n
= NULL
;
927 struct listnode
*node
= NULL
;
928 struct zebra_vrf
*zvrf
= NULL
;
930 zvrf
= zevpn
->vxlan_if
->vrf
->info
;
932 if (IS_ZEBRA_DEBUG_VXLAN
)
933 zlog_debug("Processing neighbors on local MAC %pEA %s, VNI %u",
934 &zmac
->macaddr
, seq_change
? "CHANGE" : "ADD",
937 /* Walk all neighbors and mark any inactive local neighbors as
938 * active and/or update sequence number upon a move, and inform BGP.
939 * The action for remote neighbors is TBD.
940 * NOTE: We can't simply uninstall remote neighbors as the kernel may
941 * accidentally end up deleting a just-learnt local neighbor.
943 for (ALL_LIST_ELEMENTS_RO(zmac
->neigh_list
, node
, n
)) {
944 if (CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_LOCAL
)) {
945 if (IS_ZEBRA_NEIGH_INACTIVE(n
) || seq_change
947 ZEBRA_NEIGH_SET_ACTIVE(n
);
948 n
->loc_seq
= zmac
->loc_seq
;
949 if (!(zebra_evpn_do_dup_addr_detect(zvrf
)
951 && !!CHECK_FLAG(n
->flags
,
952 ZEBRA_NEIGH_DUPLICATE
)))
953 zebra_evpn_neigh_send_add_to_client(
954 zevpn
->vni
, &n
->ip
, &n
->emac
,
955 n
->mac
, n
->flags
, n
->loc_seq
);
962 * Process all neighbors associated with a local MAC upon the MAC being
965 void zebra_evpn_process_neigh_on_local_mac_del(struct zebra_evpn
*zevpn
,
966 struct zebra_mac
*zmac
)
968 struct zebra_neigh
*n
= NULL
;
969 struct listnode
*node
= NULL
;
971 if (IS_ZEBRA_DEBUG_VXLAN
)
972 zlog_debug("Processing neighbors on local MAC %pEA DEL, VNI %u",
973 &zmac
->macaddr
, zevpn
->vni
);
975 /* Walk all local neighbors and mark as inactive and inform
977 * TBD: There is currently no handling for remote neighbors. We
978 * don't expect them to exist, if they do, do we install the MAC
979 * as a remote MAC and the neighbor as remote?
981 for (ALL_LIST_ELEMENTS_RO(zmac
->neigh_list
, node
, n
)) {
982 if (CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_LOCAL
)) {
983 if (IS_ZEBRA_NEIGH_ACTIVE(n
)) {
984 ZEBRA_NEIGH_SET_INACTIVE(n
);
986 zebra_evpn_neigh_send_del_to_client(
987 zevpn
->vni
, &n
->ip
, &n
->emac
, n
->flags
,
988 ZEBRA_NEIGH_ACTIVE
, false /*force*/);
995 * Process all neighbors associated with a MAC upon the MAC being remotely
998 void zebra_evpn_process_neigh_on_remote_mac_add(struct zebra_evpn
*zevpn
,
999 struct zebra_mac
*zmac
)
1001 struct zebra_neigh
*n
= NULL
;
1002 struct listnode
*node
= NULL
;
1004 if (IS_ZEBRA_DEBUG_VXLAN
)
1005 zlog_debug("Processing neighbors on remote MAC %pEA ADD, VNI %u",
1006 &zmac
->macaddr
, zevpn
->vni
);
1008 /* Walk all local neighbors and mark as inactive and inform
1011 for (ALL_LIST_ELEMENTS_RO(zmac
->neigh_list
, node
, n
)) {
1012 if (CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_LOCAL
)) {
1013 if (IS_ZEBRA_NEIGH_ACTIVE(n
)) {
1014 ZEBRA_NEIGH_SET_INACTIVE(n
);
1016 zebra_evpn_neigh_send_del_to_client(
1017 zevpn
->vni
, &n
->ip
, &n
->emac
, n
->flags
,
1018 ZEBRA_NEIGH_ACTIVE
, false /* force */);
1025 * Process all neighbors associated with a remote MAC upon the MAC being
1028 void zebra_evpn_process_neigh_on_remote_mac_del(struct zebra_evpn
*zevpn
,
1029 struct zebra_mac
*zmac
)
1031 /* NOTE: Currently a NO-OP. */
1034 static inline void zebra_evpn_local_neigh_update_log(
1035 const char *pfx
, struct zebra_neigh
*n
, bool is_router
,
1036 bool local_inactive
, bool old_bgp_ready
, bool new_bgp_ready
,
1037 bool inform_dataplane
, bool inform_bgp
, const char *sfx
)
1039 if (!IS_ZEBRA_DEBUG_EVPN_MH_NEIGH
)
1042 zlog_debug("%s neigh vni %u ip %pIA mac %pEA f 0x%x%s%s%s%s%s%s %s", pfx
,
1043 n
->zevpn
->vni
, &n
->ip
, &n
->emac
, n
->flags
,
1044 is_router
? " router" : "",
1045 local_inactive
? " local-inactive" : "",
1046 old_bgp_ready
? " old_bgp_ready" : "",
1047 new_bgp_ready
? " new_bgp_ready" : "",
1048 inform_dataplane
? " inform_dp" : "",
1049 inform_bgp
? " inform_bgp" : "", sfx
);
1052 /* As part Duplicate Address Detection (DAD) for IP mobility
1053 * MAC binding changes, ensure to inherit duplicate flag
1056 static int zebra_evpn_ip_inherit_dad_from_mac(struct zebra_vrf
*zvrf
,
1057 struct zebra_mac
*old_zmac
,
1058 struct zebra_mac
*new_zmac
,
1059 struct zebra_neigh
*nbr
)
1061 bool is_old_mac_dup
= false;
1062 bool is_new_mac_dup
= false;
1064 if (!zebra_evpn_do_dup_addr_detect(zvrf
))
1066 /* Check old or new MAC is detected as duplicate
1067 * mark this neigh as duplicate
1071 CHECK_FLAG(old_zmac
->flags
, ZEBRA_MAC_DUPLICATE
);
1074 CHECK_FLAG(new_zmac
->flags
, ZEBRA_MAC_DUPLICATE
);
1075 /* Old and/or new MAC can be in duplicate state,
1076 * based on that IP/Neigh Inherits the flag.
1077 * If New MAC is marked duplicate, inherit to the IP.
1078 * If old MAC is duplicate but new MAC is not, clear
1079 * duplicate flag for IP and reset detection params
1080 * and let IP DAD retrigger.
1082 if (is_new_mac_dup
&& !CHECK_FLAG(nbr
->flags
, ZEBRA_NEIGH_DUPLICATE
)) {
1083 SET_FLAG(nbr
->flags
, ZEBRA_NEIGH_DUPLICATE
);
1084 /* Capture Duplicate detection time */
1085 nbr
->dad_dup_detect_time
= monotime(NULL
);
1086 /* Mark neigh inactive */
1087 ZEBRA_NEIGH_SET_INACTIVE(nbr
);
1090 } else if (is_old_mac_dup
&& !is_new_mac_dup
) {
1091 UNSET_FLAG(nbr
->flags
, ZEBRA_NEIGH_DUPLICATE
);
1093 nbr
->detect_start_time
.tv_sec
= 0;
1094 nbr
->detect_start_time
.tv_usec
= 0;
1099 static void zebra_evpn_dad_ip_auto_recovery_exp(struct thread
*t
)
1101 struct zebra_vrf
*zvrf
= NULL
;
1102 struct zebra_neigh
*nbr
= NULL
;
1103 struct zebra_evpn
*zevpn
= NULL
;
1105 nbr
= THREAD_ARG(t
);
1107 /* since this is asynchronous we need sanity checks*/
1108 zvrf
= vrf_info_lookup(nbr
->zevpn
->vrf_id
);
1112 zevpn
= zebra_evpn_lookup(nbr
->zevpn
->vni
);
1116 nbr
= zebra_evpn_neigh_lookup(zevpn
, &nbr
->ip
);
1120 if (IS_ZEBRA_DEBUG_VXLAN
)
1122 "%s: duplicate addr MAC %pEA IP %pIA flags 0x%x learn count %u vni %u auto recovery expired",
1123 __func__
, &nbr
->emac
, &nbr
->ip
, nbr
->flags
,
1124 nbr
->dad_count
, zevpn
->vni
);
1126 UNSET_FLAG(nbr
->flags
, ZEBRA_NEIGH_DUPLICATE
);
1128 nbr
->detect_start_time
.tv_sec
= 0;
1129 nbr
->detect_start_time
.tv_usec
= 0;
1130 nbr
->dad_dup_detect_time
= 0;
1131 nbr
->dad_ip_auto_recovery_timer
= NULL
;
1132 ZEBRA_NEIGH_SET_ACTIVE(nbr
);
1135 if (CHECK_FLAG(nbr
->flags
, ZEBRA_NEIGH_LOCAL
)) {
1136 zebra_evpn_neigh_send_add_to_client(zevpn
->vni
, &nbr
->ip
,
1137 &nbr
->emac
, nbr
->mac
,
1138 nbr
->flags
, nbr
->loc_seq
);
1139 } else if (!!CHECK_FLAG(nbr
->flags
, ZEBRA_NEIGH_REMOTE
)) {
1140 zebra_evpn_rem_neigh_install(zevpn
, nbr
, false /*was_static*/);
1144 static void zebra_evpn_dup_addr_detect_for_neigh(
1145 struct zebra_vrf
*zvrf
, struct zebra_neigh
*nbr
, struct in_addr vtep_ip
,
1146 bool do_dad
, bool *is_dup_detect
, bool is_local
)
1149 struct timeval elapsed
= {0, 0};
1150 bool reset_params
= false;
1152 if (!zebra_evpn_do_dup_addr_detect(zvrf
))
1155 /* IP is detected as duplicate or inherit dup
1156 * state, hold on to install as remote entry
1157 * only if freeze is enabled.
1159 if (CHECK_FLAG(nbr
->flags
, ZEBRA_NEIGH_DUPLICATE
)) {
1160 if (IS_ZEBRA_DEBUG_VXLAN
)
1162 "%s: duplicate addr MAC %pEA IP %pIA flags 0x%x skip installing, learn count %u recover time %u",
1163 __func__
, &nbr
->emac
, &nbr
->ip
,
1164 nbr
->flags
, nbr
->dad_count
,
1165 zvrf
->dad_freeze_time
);
1167 if (zvrf
->dad_freeze
)
1168 *is_dup_detect
= true;
1170 /* warn-only action, neigh will be installed.
1171 * freeze action, it wil not be installed.
1179 /* Check if detection time (M-secs) expired.
1180 * Reset learn count and detection start time.
1181 * During remote mac add, count should already be 1
1182 * via local learning.
1184 monotime_since(&nbr
->detect_start_time
, &elapsed
);
1185 reset_params
= (elapsed
.tv_sec
> zvrf
->dad_time
);
1187 if (is_local
&& !reset_params
) {
1188 /* RFC-7432: A PE/VTEP that detects a MAC mobility
1189 * event via LOCAL learning starts an M-second timer.
1191 * NOTE: This is the START of the probe with count is
1192 * 0 during LOCAL learn event.
1194 reset_params
= !nbr
->dad_count
;
1198 if (IS_ZEBRA_DEBUG_VXLAN
)
1200 "%s: duplicate addr MAC %pEA IP %pIA flags 0x%x detection time passed, reset learn count %u",
1201 __func__
, &nbr
->emac
, &nbr
->ip
,
1202 nbr
->flags
, nbr
->dad_count
);
1203 /* Reset learn count but do not start detection
1204 * during REMOTE learn event.
1207 /* Start dup. addr detection (DAD) start time,
1208 * ONLY during LOCAL learn.
1211 monotime(&nbr
->detect_start_time
);
1213 } else if (!is_local
) {
1214 /* For REMOTE IP/Neigh, increment detection count
1215 * ONLY while in probe window, once window passed,
1216 * next local learn event should trigger DAD.
1221 /* For LOCAL IP/Neigh learn event, once count is reset above via either
1222 * initial/start detection time or passed the probe time, the count
1223 * needs to be incremented.
1228 if (nbr
->dad_count
>= zvrf
->dad_max_moves
) {
1230 EC_ZEBRA_DUP_IP_DETECTED
,
1231 "VNI %u: MAC %pEA IP %pIA detected as duplicate during %s VTEP %pI4",
1232 nbr
->zevpn
->vni
, &nbr
->emac
, &nbr
->ip
,
1233 is_local
? "local update, last" : "remote update, from",
1236 SET_FLAG(nbr
->flags
, ZEBRA_NEIGH_DUPLICATE
);
1238 /* Capture Duplicate detection time */
1239 nbr
->dad_dup_detect_time
= monotime(NULL
);
1241 /* Start auto recovery timer for this IP */
1242 THREAD_OFF(nbr
->dad_ip_auto_recovery_timer
);
1243 if (zvrf
->dad_freeze
&& zvrf
->dad_freeze_time
) {
1244 if (IS_ZEBRA_DEBUG_VXLAN
)
1246 "%s: duplicate addr MAC %pEA IP %pIA flags 0x%x auto recovery time %u start",
1247 __func__
, &nbr
->emac
, &nbr
->ip
,
1248 nbr
->flags
, zvrf
->dad_freeze_time
);
1250 thread_add_timer(zrouter
.master
,
1251 zebra_evpn_dad_ip_auto_recovery_exp
,
1252 nbr
, zvrf
->dad_freeze_time
,
1253 &nbr
->dad_ip_auto_recovery_timer
);
1255 if (zvrf
->dad_freeze
)
1256 *is_dup_detect
= true;
1260 int zebra_evpn_local_neigh_update(struct zebra_evpn
*zevpn
,
1261 struct interface
*ifp
,
1262 const struct ipaddr
*ip
,
1263 const struct ethaddr
*macaddr
, bool is_router
,
1264 bool local_inactive
, bool dp_static
)
1266 struct zebra_vrf
*zvrf
;
1267 struct zebra_neigh
*n
= NULL
;
1268 struct zebra_mac
*zmac
= NULL
, *old_zmac
= NULL
;
1269 uint32_t old_mac_seq
= 0, mac_new_seq
= 0;
1270 bool upd_mac_seq
= false;
1271 bool neigh_mac_change
= false;
1272 bool neigh_on_hold
= false;
1273 bool neigh_was_remote
= false;
1274 bool do_dad
= false;
1275 struct in_addr vtep_ip
= {.s_addr
= 0};
1276 bool inform_dataplane
= false;
1277 bool created
= false;
1278 bool new_static
= false;
1279 bool old_bgp_ready
= false;
1282 /* Check if the MAC exists. */
1283 zmac
= zebra_evpn_mac_lookup(zevpn
, macaddr
);
1285 /* create a dummy MAC if the MAC is not already present */
1286 if (IS_ZEBRA_DEBUG_VXLAN
)
1287 zlog_debug("AUTO MAC %pEA created for neigh %pIA on VNI %u",
1288 macaddr
, ip
, zevpn
->vni
);
1290 zmac
= zebra_evpn_mac_add_auto(zevpn
, macaddr
);
1292 zlog_debug("Failed to add MAC %pEA VNI %u", macaddr
,
1297 if (CHECK_FLAG(zmac
->flags
, ZEBRA_MAC_REMOTE
)) {
1299 * We don't change the MAC to local upon a neighbor
1300 * learn event, we wait for the explicit local MAC
1301 * learn. However, we have to compute its sequence
1302 * number in preparation for when it actually turns
1309 zvrf
= zevpn
->vxlan_if
->vrf
->info
;
1311 if (IS_ZEBRA_DEBUG_VXLAN
)
1312 zlog_debug(" Unable to find vrf for: %d",
1313 zevpn
->vxlan_if
->vrf
->vrf_id
);
1317 /* Check if the neighbor exists. */
1318 n
= zebra_evpn_neigh_lookup(zevpn
, ip
);
1320 /* New neighbor - create */
1321 n
= zebra_evpn_neigh_add(zevpn
, ip
, macaddr
, zmac
, 0);
1323 /* Set "local" forwarding info. */
1324 SET_FLAG(n
->flags
, ZEBRA_NEIGH_LOCAL
);
1325 n
->ifindex
= ifp
->ifindex
;
1328 if (CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_LOCAL
)) {
1331 bool old_local_inactive
;
1333 old_local_inactive
= !!CHECK_FLAG(
1334 n
->flags
, ZEBRA_NEIGH_LOCAL_INACTIVE
);
1336 old_bgp_ready
= zebra_evpn_neigh_is_ready_for_bgp(n
);
1338 /* Note any changes and see if of interest to BGP. */
1339 mac_different
= !!memcmp(&n
->emac
, macaddr
, ETH_ALEN
);
1341 !!CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_ROUTER_FLAG
);
1342 new_static
= zebra_evpn_neigh_is_static(n
);
1343 if (!mac_different
&& is_router
== cur_is_router
1344 && old_local_inactive
== local_inactive
1345 && dp_static
!= new_static
) {
1346 if (IS_ZEBRA_DEBUG_VXLAN
)
1348 " Ignoring entry mac is the same and is_router == cur_is_router");
1349 n
->ifindex
= ifp
->ifindex
;
1354 if (!mac_different
) {
1355 /* XXX - cleanup this code duplication */
1356 bool is_neigh_freezed
= false;
1358 /* Only the router flag has changed. */
1361 ZEBRA_NEIGH_ROUTER_FLAG
);
1363 UNSET_FLAG(n
->flags
,
1364 ZEBRA_NEIGH_ROUTER_FLAG
);
1368 ZEBRA_NEIGH_LOCAL_INACTIVE
);
1370 UNSET_FLAG(n
->flags
,
1371 ZEBRA_NEIGH_LOCAL_INACTIVE
);
1373 zebra_evpn_neigh_is_ready_for_bgp(n
);
1375 if (dp_static
!= new_static
)
1376 inform_dataplane
= true;
1378 /* Neigh is in freeze state and freeze action
1379 * is enabled, do not send update to client.
1382 (zebra_evpn_do_dup_addr_detect(zvrf
)
1384 && CHECK_FLAG(n
->flags
,
1385 ZEBRA_NEIGH_DUPLICATE
));
1387 zebra_evpn_local_neigh_update_log(
1388 "local", n
, is_router
, local_inactive
,
1389 old_bgp_ready
, new_bgp_ready
, false,
1390 false, "flag-update");
1392 if (inform_dataplane
)
1393 zebra_evpn_sync_neigh_dp_install(
1394 n
, false /* set_inactive */,
1395 false /* force_clear_static */,
1398 /* if the neigh can no longer be advertised
1399 * remove it from bgp
1401 if (!is_neigh_freezed
) {
1402 zebra_evpn_neigh_send_add_del_to_client(
1406 if (IS_ZEBRA_DEBUG_VXLAN
1407 && IS_ZEBRA_NEIGH_ACTIVE(n
))
1409 " Neighbor active and frozen");
1414 /* The MAC has changed, need to issue a delete
1415 * first as this means a different MACIP route.
1416 * Also, need to do some unlinking/relinking.
1417 * We also need to update the MAC's sequence number
1418 * in different situations.
1420 if (old_bgp_ready
) {
1421 zebra_evpn_neigh_send_del_to_client(
1422 zevpn
->vni
, &n
->ip
, &n
->emac
, n
->flags
,
1423 n
->state
, false /*force*/);
1424 old_bgp_ready
= false;
1427 old_mac_seq
= CHECK_FLAG(old_zmac
->flags
,
1430 : old_zmac
->loc_seq
;
1431 neigh_mac_change
= upd_mac_seq
= true;
1432 zebra_evpn_local_neigh_deref_mac(
1433 n
, true /* send_mac_update */);
1436 /* if mac changes abandon peer flags and tell
1437 * dataplane to clear the static flag
1439 if (zebra_evpn_neigh_clear_sync_info(n
))
1440 inform_dataplane
= true;
1441 /* Update the forwarding info. */
1442 n
->ifindex
= ifp
->ifindex
;
1444 /* Link to new MAC */
1445 zebra_evpn_local_neigh_ref_mac(
1446 n
, macaddr
, zmac
, true /* send_mac_update */);
1447 } else if (CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_REMOTE
)) {
1449 * Neighbor has moved from remote to local. Its
1450 * MAC could have also changed as part of the move.
1452 if (memcmp(n
->emac
.octet
, macaddr
->octet
, ETH_ALEN
)
1457 CHECK_FLAG(old_zmac
->flags
,
1460 : old_zmac
->loc_seq
;
1461 neigh_mac_change
= upd_mac_seq
= true;
1462 zebra_evpn_local_neigh_deref_mac(
1463 n
, true /* send_update */);
1466 /* Link to new MAC */
1467 zebra_evpn_local_neigh_ref_mac(
1468 n
, macaddr
, zmac
, true /*send_update*/);
1470 /* Based on Mobility event Scenario-B from the
1471 * draft, neigh's previous state was remote treat this
1474 neigh_was_remote
= true;
1475 vtep_ip
= n
->r_vtep_ip
;
1476 /* Mark appropriately */
1477 UNSET_FLAG(n
->flags
, ZEBRA_NEIGH_REMOTE
);
1478 n
->r_vtep_ip
.s_addr
= INADDR_ANY
;
1479 SET_FLAG(n
->flags
, ZEBRA_NEIGH_LOCAL
);
1480 n
->ifindex
= ifp
->ifindex
;
1484 /* If MAC was previously remote, or the neighbor had a different
1485 * MAC earlier, recompute the sequence number.
1488 uint32_t seq1
, seq2
;
1490 seq1
= CHECK_FLAG(zmac
->flags
, ZEBRA_MAC_REMOTE
)
1493 seq2
= neigh_mac_change
? old_mac_seq
+ 1 : 0;
1494 mac_new_seq
= zmac
->loc_seq
< MAX(seq1
, seq2
) ? MAX(seq1
, seq2
)
1499 SET_FLAG(n
->flags
, ZEBRA_NEIGH_LOCAL_INACTIVE
);
1501 UNSET_FLAG(n
->flags
, ZEBRA_NEIGH_LOCAL_INACTIVE
);
1503 /* Mark Router flag (R-bit) */
1505 SET_FLAG(n
->flags
, ZEBRA_NEIGH_ROUTER_FLAG
);
1507 UNSET_FLAG(n
->flags
, ZEBRA_NEIGH_ROUTER_FLAG
);
1509 /* if zebra and dataplane don't agree this is a sync entry
1510 * re-install in the dataplane */
1511 new_static
= zebra_evpn_neigh_is_static(n
);
1512 if (dp_static
!= new_static
)
1513 inform_dataplane
= true;
1515 /* Check old and/or new MAC detected as duplicate mark
1516 * the neigh as duplicate
1518 if (zebra_evpn_ip_inherit_dad_from_mac(zvrf
, old_zmac
, zmac
, n
)) {
1520 EC_ZEBRA_DUP_IP_INHERIT_DETECTED
,
1521 "VNI %u: MAC %pEA IP %pIA detected as duplicate during local update, inherit duplicate from MAC",
1522 zevpn
->vni
, macaddr
, &n
->ip
);
1525 /* For IP Duplicate Address Detection (DAD) is trigger,
1526 * when the event is extended mobility based on scenario-B
1527 * from the draft, IP/Neigh's MAC binding changed and
1528 * neigh's previous state was remote.
1530 if (neigh_mac_change
&& neigh_was_remote
)
1533 zebra_evpn_dup_addr_detect_for_neigh(zvrf
, n
, vtep_ip
, do_dad
,
1534 &neigh_on_hold
, true);
1536 if (inform_dataplane
)
1537 zebra_evpn_sync_neigh_dp_install(n
, false /* set_inactive */,
1538 false /* force_clear_static */,
1541 /* Before we program this in BGP, we need to check if MAC is locally
1542 * learnt. If not, force neighbor to be inactive and reset its seq.
1544 if (!CHECK_FLAG(zmac
->flags
, ZEBRA_MAC_LOCAL
)) {
1545 zebra_evpn_local_neigh_update_log(
1546 "local", n
, is_router
, local_inactive
, false, false,
1547 inform_dataplane
, false, "auto-mac");
1548 ZEBRA_NEIGH_SET_INACTIVE(n
);
1550 zmac
->loc_seq
= mac_new_seq
;
1554 zebra_evpn_local_neigh_update_log("local", n
, is_router
, local_inactive
,
1555 false, false, inform_dataplane
, true,
1556 created
? "created" : "updated");
1558 /* If the MAC's sequence number has changed, inform the MAC and all
1559 * neighbors associated with the MAC to BGP, else just inform this
1562 if (upd_mac_seq
&& zmac
->loc_seq
!= mac_new_seq
) {
1563 if (IS_ZEBRA_DEBUG_VXLAN
)
1565 "Seq changed for MAC %pEA VNI %u - old %u new %u",
1566 macaddr
, zevpn
->vni
,
1567 zmac
->loc_seq
, mac_new_seq
);
1568 zmac
->loc_seq
= mac_new_seq
;
1569 if (zebra_evpn_mac_send_add_to_client(zevpn
->vni
, macaddr
,
1571 zmac
->loc_seq
, zmac
->es
))
1573 zebra_evpn_process_neigh_on_local_mac_change(zevpn
, zmac
, 1,
1578 n
->loc_seq
= zmac
->loc_seq
;
1580 if (!neigh_on_hold
) {
1581 ZEBRA_NEIGH_SET_ACTIVE(n
);
1582 new_bgp_ready
= zebra_evpn_neigh_is_ready_for_bgp(n
);
1583 zebra_evpn_neigh_send_add_del_to_client(n
, old_bgp_ready
,
1586 if (IS_ZEBRA_DEBUG_VXLAN
)
1587 zlog_debug(" Neighbor on hold not sending");
1592 int zebra_evpn_remote_neigh_update(struct zebra_evpn
*zevpn
,
1593 struct interface
*ifp
,
1594 const struct ipaddr
*ip
,
1595 const struct ethaddr
*macaddr
,
1598 struct zebra_neigh
*n
= NULL
;
1599 struct zebra_mac
*zmac
= NULL
;
1601 /* If the neighbor is unknown, there is no further action. */
1602 n
= zebra_evpn_neigh_lookup(zevpn
, ip
);
1606 /* If a remote entry, see if it needs to be refreshed */
1607 if (CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_REMOTE
)) {
1609 if (state
& NUD_STALE
)
1610 zebra_evpn_rem_neigh_install(zevpn
, n
,
1611 false /*was_static*/);
1614 /* We got a "remote" neighbor notification for an entry
1615 * we think is local. This can happen in a multihoming
1616 * scenario - but only if the MAC is already "remote".
1617 * Just mark our entry as "remote".
1619 zmac
= zebra_evpn_mac_lookup(zevpn
, macaddr
);
1620 if (!zmac
|| !CHECK_FLAG(zmac
->flags
, ZEBRA_MAC_REMOTE
)) {
1622 "Ignore remote neigh %pIA (MAC %pEA) on L2-VNI %u - MAC unknown or local",
1623 &n
->ip
, macaddr
, zevpn
->vni
);
1627 UNSET_FLAG(n
->flags
, ZEBRA_NEIGH_ALL_LOCAL_FLAGS
);
1628 SET_FLAG(n
->flags
, ZEBRA_NEIGH_REMOTE
);
1629 ZEBRA_NEIGH_SET_ACTIVE(n
);
1630 n
->r_vtep_ip
= zmac
->fwd_info
.r_vtep_ip
;
1636 /* Notify Neighbor entries to the Client, skips the GW entry */
1638 zebra_evpn_send_neigh_hash_entry_to_client(struct hash_bucket
*bucket
,
1641 struct mac_walk_ctx
*wctx
= arg
;
1642 struct zebra_neigh
*zn
= bucket
->data
;
1643 struct zebra_mac
*zmac
= NULL
;
1645 if (CHECK_FLAG(zn
->flags
, ZEBRA_NEIGH_DEF_GW
))
1648 if (CHECK_FLAG(zn
->flags
, ZEBRA_NEIGH_LOCAL
)
1649 && IS_ZEBRA_NEIGH_ACTIVE(zn
)) {
1650 zmac
= zebra_evpn_mac_lookup(wctx
->zevpn
, &zn
->emac
);
1654 zebra_evpn_neigh_send_add_to_client(wctx
->zevpn
->vni
, &zn
->ip
,
1656 zn
->flags
, zn
->loc_seq
);
1660 /* Iterator of a specific EVPN */
1661 void zebra_evpn_send_neigh_to_client(struct zebra_evpn
*zevpn
)
1663 struct neigh_walk_ctx wctx
;
1665 memset(&wctx
, 0, sizeof(wctx
));
1668 hash_iterate(zevpn
->neigh_table
,
1669 zebra_evpn_send_neigh_hash_entry_to_client
, &wctx
);
1672 void zebra_evpn_clear_dup_neigh_hash(struct hash_bucket
*bucket
, void *ctxt
)
1674 struct neigh_walk_ctx
*wctx
= ctxt
;
1675 struct zebra_neigh
*nbr
;
1676 struct zebra_evpn
*zevpn
;
1677 char buf
[INET6_ADDRSTRLEN
];
1679 nbr
= (struct zebra_neigh
*)bucket
->data
;
1683 zevpn
= wctx
->zevpn
;
1685 if (!CHECK_FLAG(nbr
->flags
, ZEBRA_NEIGH_DUPLICATE
))
1688 if (IS_ZEBRA_DEBUG_VXLAN
) {
1689 ipaddr2str(&nbr
->ip
, buf
, sizeof(buf
));
1690 zlog_debug("%s: clear neigh %s dup state, flags 0x%x seq %u",
1691 __func__
, buf
, nbr
->flags
, nbr
->loc_seq
);
1694 UNSET_FLAG(nbr
->flags
, ZEBRA_NEIGH_DUPLICATE
);
1696 nbr
->detect_start_time
.tv_sec
= 0;
1697 nbr
->detect_start_time
.tv_usec
= 0;
1698 nbr
->dad_dup_detect_time
= 0;
1699 THREAD_OFF(nbr
->dad_ip_auto_recovery_timer
);
1701 if (CHECK_FLAG(nbr
->flags
, ZEBRA_NEIGH_LOCAL
)) {
1702 zebra_evpn_neigh_send_add_to_client(zevpn
->vni
, &nbr
->ip
,
1703 &nbr
->emac
, nbr
->mac
,
1704 nbr
->flags
, nbr
->loc_seq
);
1705 } else if (CHECK_FLAG(nbr
->flags
, ZEBRA_NEIGH_REMOTE
)) {
1706 zebra_evpn_rem_neigh_install(zevpn
, nbr
, false /*was_static*/);
1711 * Print a specific neighbor entry.
1713 void zebra_evpn_print_neigh(struct zebra_neigh
*n
, void *ctxt
,
1717 char buf1
[ETHER_ADDR_STRLEN
];
1718 char buf2
[INET6_ADDRSTRLEN
];
1719 const char *type_str
;
1720 const char *state_str
;
1721 bool flags_present
= false;
1722 struct zebra_vrf
*zvrf
= NULL
;
1723 struct timeval detect_start_time
= {0, 0};
1724 char timebuf
[MONOTIME_STRLEN
];
1725 char thread_buf
[THREAD_TIMER_STRLEN
];
1727 char up_str
[MONOTIME_STRLEN
];
1729 zvrf
= zebra_vrf_get_evpn();
1730 uptime
= monotime(NULL
);
1731 uptime
-= n
->uptime
;
1733 frrtime_to_interval(uptime
, up_str
, sizeof(up_str
));
1735 ipaddr2str(&n
->ip
, buf2
, sizeof(buf2
));
1736 prefix_mac2str(&n
->emac
, buf1
, sizeof(buf1
));
1737 type_str
= CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_LOCAL
) ? "local" : "remote";
1738 state_str
= IS_ZEBRA_NEIGH_ACTIVE(n
) ? "active" : "inactive";
1739 vty
= (struct vty
*)ctxt
;
1741 bool sync_info
= false;
1743 vty_out(vty
, "IP: %s\n",
1744 ipaddr2str(&n
->ip
, buf2
, sizeof(buf2
)));
1745 vty_out(vty
, " Type: %s\n", type_str
);
1746 vty_out(vty
, " State: %s\n", state_str
);
1747 vty_out(vty
, " Uptime: %s\n", up_str
);
1748 vty_out(vty
, " MAC: %s\n",
1749 prefix_mac2str(&n
->emac
, buf1
, sizeof(buf1
)));
1750 vty_out(vty
, " Sync-info:");
1751 if (CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_LOCAL_INACTIVE
)) {
1752 vty_out(vty
, " local-inactive");
1755 if (CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_ES_PEER_PROXY
)) {
1756 vty_out(vty
, " peer-proxy");
1759 if (CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_ES_PEER_ACTIVE
)) {
1760 vty_out(vty
, " peer-active");
1763 if (n
->hold_timer
) {
1764 vty_out(vty
, " (ht: %s)",
1765 thread_timer_to_hhmmss(thread_buf
,
1774 json_object_string_add(json
, "uptime", up_str
);
1775 json_object_string_add(json
, "ip", buf2
);
1776 json_object_string_add(json
, "type", type_str
);
1777 json_object_string_add(json
, "state", state_str
);
1778 json_object_string_add(json
, "mac", buf1
);
1779 if (CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_LOCAL_INACTIVE
))
1780 json_object_boolean_true_add(json
, "localInactive");
1781 if (CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_ES_PEER_PROXY
))
1782 json_object_boolean_true_add(json
, "peerProxy");
1783 if (CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_ES_PEER_ACTIVE
))
1784 json_object_boolean_true_add(json
, "peerActive");
1786 json_object_string_add(
1787 json
, "peerActiveHold",
1788 thread_timer_to_hhmmss(thread_buf
,
1792 if (CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_REMOTE
)) {
1795 json_object_string_add(json
, "remoteEs",
1796 n
->mac
->es
->esi_str
);
1798 vty_out(vty
, " Remote ES: %s\n",
1799 n
->mac
->es
->esi_str
);
1802 json_object_string_addf(json
, "remoteVtep",
1803 "%pI4", &n
->r_vtep_ip
);
1805 vty_out(vty
, " Remote VTEP: %pI4\n",
1809 if (CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_DEF_GW
)) {
1811 vty_out(vty
, " Flags: Default-gateway");
1812 flags_present
= true;
1814 json_object_boolean_true_add(json
, "defaultGateway");
1816 if (CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_ROUTER_FLAG
)) {
1819 flags_present
? " ,Router" : " Flags: Router");
1820 flags_present
= true;
1826 vty_out(vty
, " Local Seq: %u Remote Seq: %u\n", n
->loc_seq
,
1829 if (CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_DUPLICATE
)) {
1830 vty_out(vty
, " Duplicate, detected at %s",
1831 time_to_string(n
->dad_dup_detect_time
,
1833 } else if (n
->dad_count
) {
1834 monotime_since(&n
->detect_start_time
,
1835 &detect_start_time
);
1836 if (detect_start_time
.tv_sec
<= zvrf
->dad_time
) {
1837 time_to_string(n
->detect_start_time
.tv_sec
,
1840 " Duplicate detection started at %s, detection count %u\n",
1841 timebuf
, n
->dad_count
);
1845 json_object_int_add(json
, "localSequence", n
->loc_seq
);
1846 json_object_int_add(json
, "remoteSequence", n
->rem_seq
);
1847 json_object_int_add(json
, "detectionCount", n
->dad_count
);
1848 if (CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_DUPLICATE
))
1849 json_object_boolean_true_add(json
, "isDuplicate");
1851 json_object_boolean_false_add(json
, "isDuplicate");
1855 void zebra_evpn_print_neigh_hdr(struct vty
*vty
, struct neigh_walk_ctx
*wctx
)
1857 vty_out(vty
, "Flags: I=local-inactive, P=peer-active, X=peer-proxy\n");
1858 vty_out(vty
, "%*s %-6s %-5s %-8s %-17s %-30s %s\n", -wctx
->addr_width
,
1859 "Neighbor", "Type", "Flags", "State", "MAC", "Remote ES/VTEP",
1863 static char *zebra_evpn_print_neigh_flags(struct zebra_neigh
*n
,
1865 uint32_t flags_buf_sz
)
1867 snprintf(flags_buf
, flags_buf_sz
, "%s%s%s",
1868 (n
->flags
& ZEBRA_NEIGH_ES_PEER_ACTIVE
) ?
1870 (n
->flags
& ZEBRA_NEIGH_ES_PEER_PROXY
) ?
1872 (n
->flags
& ZEBRA_NEIGH_LOCAL_INACTIVE
) ?
1879 * Print neighbor hash entry - called for display of all neighbors.
1881 void zebra_evpn_print_neigh_hash(struct hash_bucket
*bucket
, void *ctxt
)
1884 json_object
*json_evpn
= NULL
, *json_row
= NULL
;
1885 struct zebra_neigh
*n
;
1886 char buf1
[ETHER_ADDR_STRLEN
];
1887 char buf2
[INET6_ADDRSTRLEN
];
1888 char addr_buf
[PREFIX_STRLEN
];
1889 struct neigh_walk_ctx
*wctx
= ctxt
;
1890 const char *state_str
;
1894 json_evpn
= wctx
->json
;
1895 n
= (struct zebra_neigh
*)bucket
->data
;
1898 json_row
= json_object_new_object();
1900 prefix_mac2str(&n
->emac
, buf1
, sizeof(buf1
));
1901 ipaddr2str(&n
->ip
, buf2
, sizeof(buf2
));
1902 state_str
= IS_ZEBRA_NEIGH_ACTIVE(n
) ? "active" : "inactive";
1903 if (CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_LOCAL
)) {
1904 if (wctx
->flags
& SHOW_REMOTE_NEIGH_FROM_VTEP
)
1907 if (json_evpn
== NULL
) {
1908 vty_out(vty
, "%*s %-6s %-5s %-8s %-17s %-30s %u/%u\n",
1909 -wctx
->addr_width
, buf2
, "local",
1910 zebra_evpn_print_neigh_flags(n
, flags_buf
,
1911 sizeof(flags_buf
)), state_str
, buf1
,
1912 "", n
->loc_seq
, n
->rem_seq
);
1914 json_object_string_add(json_row
, "type", "local");
1915 json_object_string_add(json_row
, "state", state_str
);
1916 json_object_string_add(json_row
, "mac", buf1
);
1917 if (CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_DEF_GW
))
1918 json_object_boolean_true_add(json_row
,
1920 json_object_int_add(json_row
, "localSequence",
1922 json_object_int_add(json_row
, "remoteSequence",
1924 json_object_int_add(json_row
, "detectionCount",
1926 if (CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_DUPLICATE
))
1927 json_object_boolean_true_add(json_row
,
1930 json_object_boolean_false_add(json_row
,
1934 } else if (CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_REMOTE
)) {
1935 if ((wctx
->flags
& SHOW_REMOTE_NEIGH_FROM_VTEP
)
1936 && !IPV4_ADDR_SAME(&n
->r_vtep_ip
, &wctx
->r_vtep_ip
))
1939 if (json_evpn
== NULL
) {
1940 if ((wctx
->flags
& SHOW_REMOTE_NEIGH_FROM_VTEP
)
1941 && (wctx
->count
== 0))
1942 zebra_evpn_print_neigh_hdr(vty
, wctx
);
1944 if (n
->mac
->es
== NULL
)
1945 inet_ntop(AF_INET
, &n
->r_vtep_ip
,
1946 addr_buf
, sizeof(addr_buf
));
1948 vty_out(vty
, "%*s %-6s %-5s %-8s %-17s %-30s %u/%u\n",
1949 -wctx
->addr_width
, buf2
, "remote",
1950 zebra_evpn_print_neigh_flags(n
, flags_buf
,
1951 sizeof(flags_buf
)), state_str
, buf1
,
1952 n
->mac
->es
? n
->mac
->es
->esi_str
: addr_buf
,
1953 n
->loc_seq
, n
->rem_seq
);
1955 json_object_string_add(json_row
, "type", "remote");
1956 json_object_string_add(json_row
, "state", state_str
);
1957 json_object_string_add(json_row
, "mac", buf1
);
1959 json_object_string_add(json_row
, "remoteEs",
1960 n
->mac
->es
->esi_str
);
1962 json_object_string_addf(json_row
, "remoteVtep",
1963 "%pI4", &n
->r_vtep_ip
);
1964 if (CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_DEF_GW
))
1965 json_object_boolean_true_add(json_row
,
1967 json_object_int_add(json_row
, "localSequence",
1969 json_object_int_add(json_row
, "remoteSequence",
1971 json_object_int_add(json_row
, "detectionCount",
1973 if (CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_DUPLICATE
))
1974 json_object_boolean_true_add(json_row
,
1977 json_object_boolean_false_add(json_row
,
1984 json_object_object_add(json_evpn
, buf2
, json_row
);
1988 * Print neighbor hash entry in detail - called for display of all neighbors.
1990 void zebra_evpn_print_neigh_hash_detail(struct hash_bucket
*bucket
, void *ctxt
)
1993 json_object
*json_evpn
= NULL
, *json_row
= NULL
;
1994 struct zebra_neigh
*n
;
1995 char buf
[INET6_ADDRSTRLEN
];
1996 struct neigh_walk_ctx
*wctx
= ctxt
;
1999 json_evpn
= wctx
->json
;
2000 n
= (struct zebra_neigh
*)bucket
->data
;
2004 ipaddr2str(&n
->ip
, buf
, sizeof(buf
));
2006 json_row
= json_object_new_object();
2008 zebra_evpn_print_neigh(n
, vty
, json_row
);
2011 json_object_object_add(json_evpn
, buf
, json_row
);
2014 void zebra_evpn_print_dad_neigh_hash(struct hash_bucket
*bucket
, void *ctxt
)
2016 struct zebra_neigh
*nbr
;
2018 nbr
= (struct zebra_neigh
*)bucket
->data
;
2022 if (CHECK_FLAG(nbr
->flags
, ZEBRA_NEIGH_DUPLICATE
))
2023 zebra_evpn_print_neigh_hash(bucket
, ctxt
);
2026 void zebra_evpn_print_dad_neigh_hash_detail(struct hash_bucket
*bucket
,
2029 struct zebra_neigh
*nbr
;
2031 nbr
= (struct zebra_neigh
*)bucket
->data
;
2035 if (CHECK_FLAG(nbr
->flags
, ZEBRA_NEIGH_DUPLICATE
))
2036 zebra_evpn_print_neigh_hash_detail(bucket
, ctxt
);
2039 void zebra_evpn_neigh_remote_macip_add(struct zebra_evpn
*zevpn
,
2040 struct zebra_vrf
*zvrf
,
2041 const struct ipaddr
*ipaddr
,
2042 struct zebra_mac
*mac
,
2043 struct in_addr vtep_ip
, uint8_t flags
,
2046 struct zebra_neigh
*n
;
2047 int update_neigh
= 0;
2048 struct zebra_mac
*old_mac
= NULL
;
2049 bool old_static
= false;
2050 bool do_dad
= false;
2051 bool is_dup_detect
= false;
2055 is_router
= !!CHECK_FLAG(flags
, ZEBRA_MACIP_TYPE_ROUTER_FLAG
);
2057 /* Check if the remote neighbor itself is unknown or has a
2058 * change. If so, create or update and then install the entry.
2060 n
= zebra_evpn_neigh_lookup(zevpn
, ipaddr
);
2061 if (!n
|| !CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_REMOTE
)
2062 || is_router
!= !!CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_ROUTER_FLAG
)
2063 || (memcmp(&n
->emac
, &mac
->macaddr
, sizeof(struct ethaddr
)) != 0)
2064 || !IPV4_ADDR_SAME(&n
->r_vtep_ip
, &vtep_ip
) || seq
!= n
->rem_seq
)
2069 n
= zebra_evpn_neigh_add(zevpn
, ipaddr
, &mac
->macaddr
,
2072 /* When host moves but changes its (MAC,IP)
2073 * binding, BGP may install a MACIP entry that
2074 * corresponds to "older" location of the host
2075 * in transient situations (because {IP1,M1}
2076 * is a different route from {IP1,M2}). Check
2077 * the sequence number and ignore this update
2081 if (!zebra_evpn_neigh_is_bgp_seq_ok(
2082 zevpn
, n
, &mac
->macaddr
, seq
, false))
2084 if (CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_LOCAL
)) {
2085 old_static
= zebra_evpn_neigh_is_static(n
);
2086 if (IS_ZEBRA_DEBUG_EVPN_MH_NEIGH
)
2088 "sync->remote neigh vni %u ip %pIA mac %pEA seq %d f0x%x",
2089 n
->zevpn
->vni
, &n
->ip
, &n
->emac
,
2091 if (IS_ZEBRA_NEIGH_ACTIVE(n
))
2092 zebra_evpn_neigh_send_del_to_client(
2093 zevpn
->vni
, &n
->ip
, &n
->emac
,
2096 zebra_evpn_neigh_clear_sync_info(n
);
2098 if (memcmp(&n
->emac
, &mac
->macaddr
,
2099 sizeof(struct ethaddr
))
2101 /* update neigh list for macs */
2103 zebra_evpn_mac_lookup(zevpn
, &n
->emac
);
2105 listnode_delete(old_mac
->neigh_list
, n
);
2107 zebra_evpn_deref_ip2mac(zevpn
, old_mac
);
2110 listnode_add_sort(mac
->neigh_list
, n
);
2111 memcpy(&n
->emac
, &mac
->macaddr
, ETH_ALEN
);
2113 /* Check Neigh's curent state is local
2114 * (this is the case where neigh/host has moved
2115 * from L->R) and check previous detction
2116 * started via local learning.
2118 * RFC-7432: A PE/VTEP that detects a MAC
2119 * mobilit event via local learning starts
2120 * an M-second timer.
2121 * VTEP-IP or seq. change along is not
2122 * considered for dup. detection.
2124 * Mobilty event scenario-B IP-MAC binding
2127 if ((!CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_REMOTE
))
2133 /* Set "remote" forwarding info. */
2134 UNSET_FLAG(n
->flags
, ZEBRA_NEIGH_ALL_LOCAL_FLAGS
);
2135 n
->r_vtep_ip
= vtep_ip
;
2136 SET_FLAG(n
->flags
, ZEBRA_NEIGH_REMOTE
);
2138 /* Set router flag (R-bit) to this Neighbor entry */
2139 if (CHECK_FLAG(flags
, ZEBRA_MACIP_TYPE_ROUTER_FLAG
))
2140 SET_FLAG(n
->flags
, ZEBRA_NEIGH_ROUTER_FLAG
);
2142 UNSET_FLAG(n
->flags
, ZEBRA_NEIGH_ROUTER_FLAG
);
2144 /* Check old or new MAC detected as duplicate,
2145 * inherit duplicate flag to this neigh.
2147 if (zebra_evpn_ip_inherit_dad_from_mac(zvrf
, old_mac
, mac
, n
)) {
2149 EC_ZEBRA_DUP_IP_INHERIT_DETECTED
,
2150 "VNI %u: MAC %pEA IP %pIA detected as duplicate during remote update, inherit duplicate from MAC",
2151 zevpn
->vni
, &mac
->macaddr
, &n
->ip
);
2154 /* Check duplicate address detection for IP */
2155 zebra_evpn_dup_addr_detect_for_neigh(
2156 zvrf
, n
, n
->r_vtep_ip
, do_dad
, &is_dup_detect
, false);
2157 /* Install the entry. */
2159 zebra_evpn_rem_neigh_install(zevpn
, n
, old_static
);
2162 /* Update seq number. */
2166 int zebra_evpn_neigh_gw_macip_add(struct interface
*ifp
,
2167 struct zebra_evpn
*zevpn
, struct ipaddr
*ip
,
2168 struct zebra_mac
*mac
)
2170 struct zebra_neigh
*n
;
2174 n
= zebra_evpn_neigh_lookup(zevpn
, ip
);
2176 n
= zebra_evpn_neigh_add(zevpn
, ip
, &mac
->macaddr
, mac
, 0);
2178 /* Set "local" forwarding info. */
2179 SET_FLAG(n
->flags
, ZEBRA_NEIGH_LOCAL
);
2180 ZEBRA_NEIGH_SET_ACTIVE(n
);
2181 memcpy(&n
->emac
, &mac
->macaddr
, ETH_ALEN
);
2182 n
->ifindex
= ifp
->ifindex
;
2184 /* Only advertise in BGP if the knob is enabled */
2185 if (advertise_gw_macip_enabled(zevpn
)) {
2187 SET_FLAG(n
->flags
, ZEBRA_NEIGH_DEF_GW
);
2188 /* Set Router flag (R-bit) */
2189 if (ip
->ipa_type
== IPADDR_V6
)
2190 SET_FLAG(n
->flags
, ZEBRA_NEIGH_ROUTER_FLAG
);
2192 if (IS_ZEBRA_DEBUG_VXLAN
)
2194 "SVI %s(%u) L2-VNI %u, sending GW MAC %pEA IP %pIA add to BGP with flags 0x%x",
2195 ifp
->name
, ifp
->ifindex
, zevpn
->vni
,
2196 &mac
->macaddr
, ip
, n
->flags
);
2198 zebra_evpn_neigh_send_add_to_client(
2199 zevpn
->vni
, ip
, &n
->emac
, n
->mac
, n
->flags
, n
->loc_seq
);
2200 } else if (advertise_svi_macip_enabled(zevpn
)) {
2202 SET_FLAG(n
->flags
, ZEBRA_NEIGH_SVI_IP
);
2203 if (IS_ZEBRA_DEBUG_VXLAN
)
2205 "SVI %s(%u) L2-VNI %u, sending SVI MAC %pEA IP %pIA add to BGP with flags 0x%x",
2206 ifp
->name
, ifp
->ifindex
, zevpn
->vni
,
2207 &mac
->macaddr
, ip
, n
->flags
);
2209 zebra_evpn_neigh_send_add_to_client(
2210 zevpn
->vni
, ip
, &n
->emac
, n
->mac
, n
->flags
, n
->loc_seq
);
2216 void zebra_evpn_neigh_remote_uninstall(struct zebra_evpn
*zevpn
,
2217 struct zebra_vrf
*zvrf
,
2218 struct zebra_neigh
*n
,
2219 struct zebra_mac
*mac
,
2220 const struct ipaddr
*ipaddr
)
2222 if (zvrf
->dad_freeze
&& CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_DUPLICATE
)
2223 && CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_REMOTE
)
2224 && (memcmp(n
->emac
.octet
, mac
->macaddr
.octet
, ETH_ALEN
) == 0)) {
2225 struct interface
*vlan_if
;
2227 vlan_if
= zevpn_map_to_svi(zevpn
);
2228 if (IS_ZEBRA_DEBUG_VXLAN
)
2230 "%s: IP %pIA (flags 0x%x intf %s) is remote and duplicate, read kernel for local entry",
2231 __func__
, ipaddr
, n
->flags
,
2232 vlan_if
? vlan_if
->name
: "Unknown");
2234 neigh_read_specific_ip(ipaddr
, vlan_if
);
2237 /* When the MAC changes for an IP, it is possible the
2238 * client may update the new MAC before trying to delete the
2239 * "old" neighbor (as these are two different MACIP routes).
2240 * Do the delete only if the MAC matches.
2242 if (!memcmp(n
->emac
.octet
, mac
->macaddr
.octet
, ETH_ALEN
)) {
2243 if (CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_LOCAL
)) {
2244 zebra_evpn_sync_neigh_del(n
);
2245 } else if (CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_REMOTE
)) {
2246 zebra_evpn_neigh_uninstall(zevpn
, n
);
2247 zebra_evpn_neigh_del(zevpn
, n
);
2248 zebra_evpn_deref_ip2mac(zevpn
, mac
);
2251 if (IS_ZEBRA_DEBUG_VXLAN
)
2253 "%s: IP %pIA MAC %pEA (flags 0x%x) found doesn't match MAC %pEA, ignoring Neigh DEL",
2254 __func__
, ipaddr
, &n
->emac
, n
->flags
,
2259 int zebra_evpn_neigh_del_ip(struct zebra_evpn
*zevpn
, const struct ipaddr
*ip
)
2261 struct zebra_neigh
*n
;
2262 struct zebra_mac
*zmac
;
2265 struct zebra_vrf
*zvrf
;
2267 /* If entry doesn't exist, nothing to do. */
2268 n
= zebra_evpn_neigh_lookup(zevpn
, ip
);
2272 zmac
= zebra_evpn_mac_lookup(zevpn
, &n
->emac
);
2274 if (IS_ZEBRA_DEBUG_VXLAN
)
2276 "Trying to del a neigh %pIA without a mac %pEA on VNI %u",
2283 /* If it is a remote entry, the kernel has aged this out or someone has
2284 * deleted it, it needs to be re-installed as FRR is the owner.
2286 if (CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_REMOTE
)) {
2287 zebra_evpn_rem_neigh_install(zevpn
, n
, false /*was_static*/);
2291 /* if this is a sync entry it cannot be dropped re-install it in
2294 old_bgp_ready
= zebra_evpn_neigh_is_ready_for_bgp(n
);
2295 if (zebra_evpn_neigh_is_static(n
)) {
2296 if (IS_ZEBRA_DEBUG_EVPN_MH_NEIGH
)
2297 zlog_debug("re-add sync neigh vni %u ip %pIA mac %pEA 0x%x",
2298 n
->zevpn
->vni
, &n
->ip
, &n
->emac
,
2301 if (!CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_LOCAL_INACTIVE
))
2302 SET_FLAG(n
->flags
, ZEBRA_NEIGH_LOCAL_INACTIVE
);
2303 /* inform-bgp about change in local-activity if any */
2304 new_bgp_ready
= zebra_evpn_neigh_is_ready_for_bgp(n
);
2305 zebra_evpn_neigh_send_add_del_to_client(n
, old_bgp_ready
,
2308 /* re-install the entry in the kernel */
2309 zebra_evpn_sync_neigh_dp_install(n
, false /* set_inactive */,
2310 false /* force_clear_static */,
2316 zvrf
= zevpn
->vxlan_if
->vrf
->info
;
2318 zlog_debug("%s: VNI %u vrf lookup failed.", __func__
,
2323 /* In case of feeze action, if local neigh is in duplicate state,
2324 * Mark the Neigh as inactive before sending delete request to BGPd,
2325 * If BGPd has remote entry, it will re-install
2327 if (zvrf
->dad_freeze
&& CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_DUPLICATE
))
2328 ZEBRA_NEIGH_SET_INACTIVE(n
);
2330 /* Remove neighbor from BGP. */
2331 zebra_evpn_neigh_send_del_to_client(zevpn
->vni
, &n
->ip
, &n
->emac
,
2335 /* Delete this neighbor entry. */
2336 zebra_evpn_neigh_del(zevpn
, n
);
2338 /* see if the AUTO mac needs to be deleted */
2339 if (CHECK_FLAG(zmac
->flags
, ZEBRA_MAC_AUTO
)
2340 && !zebra_evpn_mac_in_use(zmac
))
2341 zebra_evpn_mac_del(zevpn
, zmac
);