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_memory.h"
38 #include "zebra/zebra_errors.h"
39 #include "zebra/zebra_vrf.h"
40 #include "zebra/zebra_evpn.h"
41 #include "zebra/zebra_evpn_mh.h"
42 #include "zebra/zebra_evpn_neigh.h"
43 #include "zebra/zebra_evpn_mac.h"
45 DEFINE_MTYPE_STATIC(ZEBRA
, NEIGH
, "EVI Neighbor");
48 * Make hash key for neighbors.
50 static unsigned int neigh_hash_keymake(const void *p
)
52 const zebra_neigh_t
*n
= p
;
53 const struct ipaddr
*ip
= &n
->ip
;
56 return jhash_1word(ip
->ipaddr_v4
.s_addr
, 0);
58 return jhash2(ip
->ipaddr_v6
.s6_addr32
,
59 array_size(ip
->ipaddr_v6
.s6_addr32
), 0);
63 * Compare two neighbor hash structures.
65 static bool neigh_cmp(const void *p1
, const void *p2
)
67 const zebra_neigh_t
*n1
= p1
;
68 const zebra_neigh_t
*n2
= p2
;
70 if (n1
== NULL
&& n2
== NULL
)
73 if (n1
== NULL
|| n2
== NULL
)
76 return (memcmp(&n1
->ip
, &n2
->ip
, sizeof(struct ipaddr
)) == 0);
79 int neigh_list_cmp(void *p1
, void *p2
)
81 const zebra_neigh_t
*n1
= p1
;
82 const zebra_neigh_t
*n2
= p2
;
84 return memcmp(&n1
->ip
, &n2
->ip
, sizeof(struct ipaddr
));
87 struct hash
*zebra_neigh_db_create(const char *desc
)
89 return hash_create(neigh_hash_keymake
, neigh_cmp
, desc
);
92 uint32_t num_dup_detected_neighs(zebra_evpn_t
*zevpn
)
95 uint32_t num_neighs
= 0;
97 struct hash_bucket
*hb
;
100 hash
= zevpn
->neigh_table
;
103 for (i
= 0; i
< hash
->size
; i
++) {
104 for (hb
= hash
->index
[i
]; hb
; hb
= hb
->next
) {
105 nbr
= (zebra_neigh_t
*)hb
->data
;
106 if (CHECK_FLAG(nbr
->flags
, ZEBRA_NEIGH_DUPLICATE
))
115 * Helper function to determine maximum width of neighbor IP address for
116 * display - just because we're dealing with IPv6 addresses that can
119 void zebra_evpn_find_neigh_addr_width(struct hash_bucket
*bucket
, void *ctxt
)
122 char buf
[INET6_ADDRSTRLEN
];
123 struct neigh_walk_ctx
*wctx
= ctxt
;
126 n
= (zebra_neigh_t
*)bucket
->data
;
128 ipaddr2str(&n
->ip
, buf
, sizeof(buf
));
130 if (width
> wctx
->addr_width
)
131 wctx
->addr_width
= width
;
135 * Count of remote neighbors referencing this MAC.
137 int remote_neigh_count(zebra_mac_t
*zmac
)
139 zebra_neigh_t
*n
= NULL
;
140 struct listnode
*node
= NULL
;
143 for (ALL_LIST_ELEMENTS_RO(zmac
->neigh_list
, node
, n
)) {
144 if (CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_REMOTE
))
152 * Install remote neighbor into the kernel.
154 int zebra_evpn_rem_neigh_install(zebra_evpn_t
*zevpn
, zebra_neigh_t
*n
,
157 struct interface
*vlan_if
;
161 if (!(n
->flags
& ZEBRA_NEIGH_REMOTE
))
164 vlan_if
= zevpn_map_to_svi(zevpn
);
168 flags
= DPLANE_NTF_EXT_LEARNED
;
169 if (n
->flags
& ZEBRA_NEIGH_ROUTER_FLAG
)
170 flags
|= DPLANE_NTF_ROUTER
;
171 ZEBRA_NEIGH_SET_ACTIVE(n
);
173 dplane_rem_neigh_add(vlan_if
, &n
->ip
, &n
->emac
, flags
, was_static
);
179 * Install neighbor hash entry - called upon access VLAN change.
181 void zebra_evpn_install_neigh_hash(struct hash_bucket
*bucket
, void *ctxt
)
184 struct neigh_walk_ctx
*wctx
= ctxt
;
186 n
= (zebra_neigh_t
*)bucket
->data
;
188 if (CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_REMOTE
))
189 zebra_evpn_rem_neigh_install(wctx
->zevpn
, n
,
190 false /*was_static*/);
194 * Callback to allocate neighbor hash entry.
196 static void *zebra_evpn_neigh_alloc(void *p
)
198 const zebra_neigh_t
*tmp_n
= p
;
201 n
= XCALLOC(MTYPE_NEIGH
, sizeof(zebra_neigh_t
));
207 static void zebra_evpn_local_neigh_ref_mac(zebra_neigh_t
*n
,
208 struct ethaddr
*macaddr
,
210 bool send_mac_update
)
212 char macbuf
[ETHER_ADDR_STRLEN
];
213 char ipbuf
[INET6_ADDRSTRLEN
];
217 memcpy(&n
->emac
, macaddr
, ETH_ALEN
);
220 /* Link to new MAC */
224 listnode_add_sort(mac
->neigh_list
, n
);
225 if (n
->flags
& ZEBRA_NEIGH_ALL_PEER_FLAGS
) {
226 old_static
= zebra_evpn_mac_is_static(mac
);
227 ++mac
->sync_neigh_cnt
;
228 new_static
= zebra_evpn_mac_is_static(mac
);
229 if (IS_ZEBRA_DEBUG_EVPN_MH_NEIGH
)
231 "sync-neigh ref mac vni %u ip %s mac %s ref %d",
233 ipaddr2str(&n
->ip
, ipbuf
, sizeof(ipbuf
)),
234 prefix_mac2str(&n
->emac
, macbuf
,
236 mac
->sync_neigh_cnt
);
237 if ((old_static
!= new_static
) && send_mac_update
)
238 /* program the local mac in the kernel */
239 zebra_evpn_sync_mac_dp_install(
240 mac
, false /*set_inactive*/,
241 false /*force_clear_static*/, __func__
);
245 /* sync-path that is active on an ES peer */
246 static void zebra_evpn_sync_neigh_dp_install(zebra_neigh_t
*n
,
248 bool force_clear_static
,
251 char macbuf
[ETHER_ADDR_STRLEN
];
252 char ipbuf
[INET6_ADDRSTRLEN
];
253 struct zebra_ns
*zns
;
254 struct interface
*ifp
;
258 zns
= zebra_ns_lookup(NS_DEFAULT
);
259 ifp
= if_lookup_by_index_per_ns(zns
, n
->ifindex
);
261 if (IS_ZEBRA_DEBUG_EVPN_MH_NEIGH
)
263 "%s: dp-install sync-neigh vni %u ip %s mac %s if %d f 0x%x skipped",
264 caller
, n
->zevpn
->vni
,
265 ipaddr2str(&n
->ip
, ipbuf
, sizeof(ipbuf
)),
266 prefix_mac2str(&n
->emac
, macbuf
,
268 n
->ifindex
, n
->flags
);
272 if (force_clear_static
)
275 set_static
= zebra_evpn_neigh_is_static(n
);
277 set_router
= !!CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_ROUTER_FLAG
);
279 /* XXX - this will change post integration with the new kernel */
280 if (CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_LOCAL_INACTIVE
))
283 if (IS_ZEBRA_DEBUG_EVPN_MH_NEIGH
)
285 "%s: dp-install sync-neigh vni %u ip %s mac %s if %s(%d) f 0x%x%s%s%s",
286 caller
, n
->zevpn
->vni
,
287 ipaddr2str(&n
->ip
, ipbuf
, sizeof(ipbuf
)),
288 prefix_mac2str(&n
->emac
, macbuf
, sizeof(macbuf
)),
289 ifp
->name
, n
->ifindex
, n
->flags
,
290 set_router
? " router" : "",
291 set_static
? " static" : "",
292 set_inactive
? " inactive" : "");
293 dplane_local_neigh_add(ifp
, &n
->ip
, &n
->emac
, set_router
, set_static
,
298 * Inform BGP about local neighbor addition.
300 int zebra_evpn_neigh_send_add_to_client(vni_t vni
, struct ipaddr
*ip
,
301 struct ethaddr
*macaddr
,
302 zebra_mac_t
*zmac
, uint32_t neigh_flags
,
307 if (CHECK_FLAG(neigh_flags
, ZEBRA_NEIGH_LOCAL_INACTIVE
)) {
308 /* host reachability has not been verified locally */
310 /* if no ES peer is claiming reachability we can't advertise
313 if (!CHECK_FLAG(neigh_flags
, ZEBRA_NEIGH_ES_PEER_ACTIVE
))
316 /* ES peers are claiming reachability; we will
317 * advertise the entry but with a proxy flag
319 SET_FLAG(flags
, ZEBRA_MACIP_TYPE_PROXY_ADVERT
);
322 if (CHECK_FLAG(neigh_flags
, ZEBRA_NEIGH_DEF_GW
))
323 SET_FLAG(flags
, ZEBRA_MACIP_TYPE_GW
);
324 /* Set router flag (R-bit) based on local neigh entry add */
325 if (CHECK_FLAG(neigh_flags
, ZEBRA_NEIGH_ROUTER_FLAG
))
326 SET_FLAG(flags
, ZEBRA_MACIP_TYPE_ROUTER_FLAG
);
327 if (CHECK_FLAG(neigh_flags
, ZEBRA_NEIGH_SVI_IP
))
328 SET_FLAG(flags
, ZEBRA_MACIP_TYPE_SVI_IP
);
330 return zebra_evpn_macip_send_msg_to_client(
331 vni
, macaddr
, ip
, flags
, seq
, ZEBRA_NEIGH_ACTIVE
,
332 zmac
? zmac
->es
: NULL
, ZEBRA_MACIP_ADD
);
336 * Inform BGP about local neighbor deletion.
338 int zebra_evpn_neigh_send_del_to_client(vni_t vni
, struct ipaddr
*ip
,
339 struct ethaddr
*macaddr
, uint32_t flags
,
340 int state
, bool force
)
343 if (CHECK_FLAG(flags
, ZEBRA_NEIGH_LOCAL_INACTIVE
)
344 && !CHECK_FLAG(flags
, ZEBRA_NEIGH_ES_PEER_ACTIVE
))
345 /* the neigh was not advertised - nothing to delete */
349 return zebra_evpn_macip_send_msg_to_client(
350 vni
, macaddr
, ip
, flags
, 0, state
, NULL
, ZEBRA_MACIP_DEL
);
353 static void zebra_evpn_neigh_send_add_del_to_client(zebra_neigh_t
*n
,
358 zebra_evpn_neigh_send_add_to_client(n
->zevpn
->vni
, &n
->ip
,
359 &n
->emac
, n
->mac
, n
->flags
,
361 else if (old_bgp_ready
)
362 zebra_evpn_neigh_send_del_to_client(n
->zevpn
->vni
, &n
->ip
,
364 n
->state
, true /*force*/);
367 /* if the static flag associated with the neigh changes we need
368 * to update the sync-neigh references against the MAC
369 * and inform the dataplane about the static flag changes.
371 void zebra_evpn_sync_neigh_static_chg(zebra_neigh_t
*n
, bool old_n_static
,
372 bool new_n_static
, bool defer_n_dp
,
373 bool defer_mac_dp
, const char *caller
)
375 zebra_mac_t
*mac
= n
->mac
;
378 char macbuf
[ETHER_ADDR_STRLEN
];
379 char ipbuf
[INET6_ADDRSTRLEN
];
381 if (old_n_static
== new_n_static
)
384 /* update the neigh sync references in the dataplane. if
385 * the neigh is in the middle of updates the caller can
386 * request for a defer
389 zebra_evpn_sync_neigh_dp_install(n
, false /* set_inactive */,
390 false /* force_clear_static */,
396 /* update the mac sync ref cnt */
397 old_mac_static
= zebra_evpn_mac_is_static(mac
);
399 ++mac
->sync_neigh_cnt
;
400 } else if (old_n_static
) {
401 if (mac
->sync_neigh_cnt
)
402 --mac
->sync_neigh_cnt
;
404 new_mac_static
= zebra_evpn_mac_is_static(mac
);
406 /* update the mac sync references in the dataplane */
407 if ((old_mac_static
!= new_mac_static
) && !defer_mac_dp
)
408 zebra_evpn_sync_mac_dp_install(mac
, false /* set_inactive */,
409 false /* force_clear_static */,
412 if (IS_ZEBRA_DEBUG_EVPN_MH_NEIGH
)
414 "sync-neigh ref-chg vni %u ip %s mac %s f 0x%x %d%s%s%s%s by %s",
415 n
->zevpn
->vni
, ipaddr2str(&n
->ip
, ipbuf
, sizeof(ipbuf
)),
416 prefix_mac2str(&n
->emac
, macbuf
, sizeof(macbuf
)),
417 n
->flags
, mac
->sync_neigh_cnt
,
418 old_n_static
? " old_n_static" : "",
419 new_n_static
? " new_n_static" : "",
420 old_mac_static
? " old_mac_static" : "",
421 new_mac_static
? " new_mac_static" : "", caller
);
424 /* Neigh hold timer is used to age out peer-active flag.
426 * During this wait time we expect the dataplane component or an
427 * external neighmgr daemon to probe existing hosts to independently
428 * establish their presence on the ES.
430 static int zebra_evpn_neigh_hold_exp_cb(struct thread
*t
)
437 char macbuf
[ETHER_ADDR_STRLEN
];
438 char ipbuf
[INET6_ADDRSTRLEN
];
441 /* the purpose of the hold timer is to age out the peer-active
444 if (!CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_ES_PEER_ACTIVE
))
447 old_bgp_ready
= zebra_evpn_neigh_is_ready_for_bgp(n
);
448 old_n_static
= zebra_evpn_neigh_is_static(n
);
449 UNSET_FLAG(n
->flags
, ZEBRA_NEIGH_ES_PEER_ACTIVE
);
450 new_bgp_ready
= zebra_evpn_neigh_is_ready_for_bgp(n
);
451 new_n_static
= zebra_evpn_neigh_is_static(n
);
453 if (IS_ZEBRA_DEBUG_EVPN_MH_NEIGH
)
454 zlog_debug("sync-neigh vni %u ip %s mac %s 0x%x hold expired",
456 ipaddr2str(&n
->ip
, ipbuf
, sizeof(ipbuf
)),
457 prefix_mac2str(&n
->emac
, macbuf
, sizeof(macbuf
)),
460 /* re-program the local neigh in the dataplane if the neigh is no
463 if (old_n_static
!= new_n_static
)
464 zebra_evpn_sync_neigh_static_chg(
465 n
, old_n_static
, new_n_static
, false /*defer_n_dp*/,
466 false /*defer_mac_dp*/, __func__
);
468 /* inform bgp if needed */
469 if (old_bgp_ready
!= new_bgp_ready
)
470 zebra_evpn_neigh_send_add_del_to_client(n
, old_bgp_ready
,
476 static inline void zebra_evpn_neigh_start_hold_timer(zebra_neigh_t
*n
)
478 char macbuf
[ETHER_ADDR_STRLEN
];
479 char ipbuf
[INET6_ADDRSTRLEN
];
484 if (IS_ZEBRA_DEBUG_EVPN_MH_NEIGH
)
485 zlog_debug("sync-neigh vni %u ip %s mac %s 0x%x hold start",
487 ipaddr2str(&n
->ip
, ipbuf
, sizeof(ipbuf
)),
488 prefix_mac2str(&n
->emac
, macbuf
, sizeof(macbuf
)),
490 thread_add_timer(zrouter
.master
, zebra_evpn_neigh_hold_exp_cb
, n
,
491 zmh_info
->neigh_hold_time
, &n
->hold_timer
);
494 static void zebra_evpn_local_neigh_deref_mac(zebra_neigh_t
*n
,
495 bool send_mac_update
)
497 zebra_mac_t
*mac
= n
->mac
;
498 zebra_evpn_t
*zevpn
= n
->zevpn
;
499 char macbuf
[ETHER_ADDR_STRLEN
];
500 char ipbuf
[INET6_ADDRSTRLEN
];
508 if ((n
->flags
& ZEBRA_NEIGH_ALL_PEER_FLAGS
) && mac
->sync_neigh_cnt
) {
509 old_static
= zebra_evpn_mac_is_static(mac
);
510 --mac
->sync_neigh_cnt
;
511 new_static
= zebra_evpn_mac_is_static(mac
);
512 if (IS_ZEBRA_DEBUG_EVPN_MH_NEIGH
)
514 "sync-neigh deref mac vni %u ip %s mac %s ref %d",
516 ipaddr2str(&n
->ip
, ipbuf
, sizeof(ipbuf
)),
517 prefix_mac2str(&n
->emac
, macbuf
,
519 mac
->sync_neigh_cnt
);
520 if ((old_static
!= new_static
) && send_mac_update
)
521 /* program the local mac in the kernel */
522 zebra_evpn_sync_mac_dp_install(
523 mac
, false /* set_inactive */,
524 false /* force_clear_static */, __func__
);
527 listnode_delete(mac
->neigh_list
, n
);
528 zebra_evpn_deref_ip2mac(zevpn
, mac
);
531 bool zebra_evpn_neigh_is_bgp_seq_ok(zebra_evpn_t
*zevpn
, zebra_neigh_t
*n
,
532 struct ethaddr
*macaddr
, uint32_t seq
)
534 char macbuf
[ETHER_ADDR_STRLEN
];
535 char ipbuf
[INET6_ADDRSTRLEN
];
538 if (CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_LOCAL
))
539 tmp_seq
= n
->loc_seq
;
541 tmp_seq
= n
->rem_seq
;
544 /* if the neigh was never advertised to bgp we must accept
545 * whatever sequence number bgp sends
546 * XXX - check with Vivek
548 if (CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_LOCAL
)
549 && !zebra_evpn_neigh_is_ready_for_bgp(n
)) {
550 if (IS_ZEBRA_DEBUG_EVPN_MH_NEIGH
)
552 "sync-macip accept vni %u mac %s IP %s lower seq %u f 0x%x",
554 prefix_mac2str(macaddr
, macbuf
,
556 ipaddr2str(&n
->ip
, ipbuf
,
562 if (IS_ZEBRA_DEBUG_EVPN_MH_NEIGH
)
564 "sync-macip ignore vni %u mac %s IP %s as existing has higher seq %u f 0x%x",
566 prefix_mac2str(macaddr
, macbuf
, sizeof(macbuf
)),
567 ipaddr2str(&n
->ip
, ipbuf
, sizeof(ipbuf
)),
576 * Add neighbor entry.
578 static zebra_neigh_t
*zebra_evpn_neigh_add(zebra_evpn_t
*zevpn
,
581 zebra_mac_t
*zmac
, uint32_t n_flags
)
584 zebra_neigh_t
*n
= NULL
;
586 memset(&tmp_n
, 0, sizeof(zebra_neigh_t
));
587 memcpy(&tmp_n
.ip
, ip
, sizeof(struct ipaddr
));
588 n
= hash_get(zevpn
->neigh_table
, &tmp_n
, zebra_evpn_neigh_alloc
);
591 n
->state
= ZEBRA_NEIGH_INACTIVE
;
593 n
->dad_ip_auto_recovery_timer
= NULL
;
597 zmac
= zebra_evpn_mac_lookup(zevpn
, mac
);
598 zebra_evpn_local_neigh_ref_mac(n
, mac
, zmac
,
599 false /* send_mac_update */);
605 * Delete neighbor entry.
607 int zebra_evpn_neigh_del(zebra_evpn_t
*zevpn
, zebra_neigh_t
*n
)
609 zebra_neigh_t
*tmp_n
;
612 listnode_delete(n
->mac
->neigh_list
, n
);
614 /* Cancel auto recovery */
615 THREAD_OFF(n
->dad_ip_auto_recovery_timer
);
617 /* Free the VNI hash entry and allocated memory. */
618 tmp_n
= hash_release(zevpn
->neigh_table
, n
);
619 XFREE(MTYPE_NEIGH
, tmp_n
);
624 void zebra_evpn_sync_neigh_del(zebra_neigh_t
*n
)
628 char macbuf
[ETHER_ADDR_STRLEN
];
629 char ipbuf
[INET6_ADDRSTRLEN
];
631 if (IS_ZEBRA_DEBUG_EVPN_MH_NEIGH
)
632 zlog_debug("sync-neigh del vni %u ip %s mac %s f 0x%x",
634 ipaddr2str(&n
->ip
, ipbuf
, sizeof(ipbuf
)),
635 prefix_mac2str(&n
->emac
, macbuf
, sizeof(macbuf
)),
638 old_n_static
= zebra_evpn_neigh_is_static(n
);
639 UNSET_FLAG(n
->flags
, ZEBRA_NEIGH_ES_PEER_PROXY
);
640 if (CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_ES_PEER_ACTIVE
))
641 zebra_evpn_neigh_start_hold_timer(n
);
642 new_n_static
= zebra_evpn_neigh_is_static(n
);
644 if (old_n_static
!= new_n_static
)
645 zebra_evpn_sync_neigh_static_chg(
646 n
, old_n_static
, new_n_static
, false /*defer-dp*/,
647 false /*defer_mac_dp*/, __func__
);
651 zebra_evpn_proc_sync_neigh_update(zebra_evpn_t
*zevpn
, zebra_neigh_t
*n
,
652 uint16_t ipa_len
, struct ipaddr
*ipaddr
,
653 uint8_t flags
, uint32_t seq
, esi_t
*esi
,
654 struct sync_mac_ip_ctx
*ctx
)
656 struct interface
*ifp
= NULL
;
658 zebra_mac_t
*mac
= ctx
->mac
;
660 bool old_router
= false;
661 bool old_bgp_ready
= false;
663 bool inform_dataplane
= false;
664 bool inform_bgp
= false;
667 bool set_dp_inactive
= false;
668 char macbuf
[ETHER_ADDR_STRLEN
];
669 char ipbuf
[INET6_ADDRSTRLEN
];
671 ifindex_t ifindex
= 0;
674 ifp
= zevpn_map_to_svi(zevpn
);
676 ifindex
= ifp
->ifindex
;
678 is_router
= !!CHECK_FLAG(flags
, ZEBRA_MACIP_TYPE_ROUTER_FLAG
);
679 old_mac_static
= zebra_evpn_mac_is_static(mac
);
682 uint32_t n_flags
= 0;
684 /* New neighbor - create */
685 SET_FLAG(n_flags
, ZEBRA_NEIGH_LOCAL
);
686 if (CHECK_FLAG(flags
, ZEBRA_MACIP_TYPE_PROXY_ADVERT
))
687 SET_FLAG(n_flags
, ZEBRA_NEIGH_ES_PEER_PROXY
);
689 SET_FLAG(n_flags
, ZEBRA_NEIGH_ES_PEER_ACTIVE
);
690 SET_FLAG(n_flags
, ZEBRA_NEIGH_LOCAL_INACTIVE
);
692 n
= zebra_evpn_neigh_add(zevpn
, ipaddr
, &mac
->macaddr
, mac
,
694 n
->ifindex
= ifindex
;
695 ZEBRA_NEIGH_SET_ACTIVE(n
);
698 inform_dataplane
= true;
700 set_dp_inactive
= true;
703 uint32_t old_flags
= n
->flags
;
708 old_n_static
= zebra_evpn_neigh_is_static(n
);
709 old_bgp_ready
= zebra_evpn_neigh_is_ready_for_bgp(n
);
710 old_router
= !!CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_ROUTER_FLAG
);
712 mac_change
= !!memcmp(&n
->emac
, &mac
->macaddr
, ETH_ALEN
);
714 /* deref and clear old info */
717 zebra_evpn_neigh_send_del_to_client(
718 zevpn
->vni
, &n
->ip
, &n
->emac
, n
->flags
,
719 n
->state
, false /*force*/);
720 old_bgp_ready
= false;
723 zebra_evpn_local_neigh_deref_mac(
724 n
, false /*send_mac_update*/);
726 /* clear old fwd info */
728 n
->r_vtep_ip
.s_addr
= 0;
730 /* setup new flags */
732 SET_FLAG(n
->flags
, ZEBRA_NEIGH_LOCAL
);
733 /* retain activity flag if the neigh was
736 if (old_flags
& ZEBRA_NEIGH_LOCAL
) {
737 n
->flags
|= (old_flags
& ZEBRA_NEIGH_LOCAL_INACTIVE
);
739 inform_dataplane
= true;
740 set_dp_inactive
= true;
741 n
->flags
|= ZEBRA_NEIGH_LOCAL_INACTIVE
;
744 if (CHECK_FLAG(flags
, ZEBRA_MACIP_TYPE_PROXY_ADVERT
))
745 SET_FLAG(n
->flags
, ZEBRA_NEIGH_ES_PEER_PROXY
);
747 SET_FLAG(n
->flags
, ZEBRA_NEIGH_ES_PEER_ACTIVE
);
749 if (CHECK_FLAG(flags
, ZEBRA_MACIP_TYPE_PROXY_ADVERT
)) {
750 SET_FLAG(n
->flags
, ZEBRA_NEIGH_ES_PEER_PROXY
);
751 /* if the neigh was peer-active previously we
752 * need to keep the flag and start the
753 * holdtimer on it. the peer-active flag is
754 * cleared on holdtimer expiry.
756 if (CHECK_FLAG(old_flags
, ZEBRA_NEIGH_ES_PEER_ACTIVE
)) {
757 SET_FLAG(n
->flags
, ZEBRA_NEIGH_ES_PEER_ACTIVE
);
758 zebra_evpn_neigh_start_hold_timer(n
);
761 SET_FLAG(n
->flags
, ZEBRA_NEIGH_ES_PEER_ACTIVE
);
762 /* stop hold timer if a peer has verified
765 zebra_evpn_neigh_stop_hold_timer(n
);
767 ZEBRA_NEIGH_SET_ACTIVE(n
);
769 if (IS_ZEBRA_DEBUG_EVPN_MH_NEIGH
&& (old_flags
!= n
->flags
))
771 "sync-neigh vni %u ip %s mac %s old_f 0x%x new_f 0x%x",
773 ipaddr2str(&n
->ip
, ipbuf
, sizeof(ipbuf
)),
774 prefix_mac2str(&n
->emac
, macbuf
,
776 old_flags
, n
->flags
);
778 new_n_static
= zebra_evpn_neigh_is_static(n
);
780 set_dp_inactive
= true;
781 n
->flags
|= ZEBRA_NEIGH_LOCAL_INACTIVE
;
782 inform_dataplane
= true;
783 zebra_evpn_local_neigh_ref_mac(
784 n
, &mac
->macaddr
, mac
,
785 false /*send_mac_update*/);
786 } else if (old_n_static
!= new_n_static
) {
787 inform_dataplane
= true;
788 /* if static flags have changed without a mac change
789 * we need to create the correct sync-refs against
792 zebra_evpn_sync_neigh_static_chg(
793 n
, old_n_static
, new_n_static
,
794 true /*defer_dp*/, true /*defer_mac_dp*/,
798 /* Update the forwarding info. */
799 if (n
->ifindex
!= ifindex
) {
800 n
->ifindex
= ifindex
;
801 inform_dataplane
= true;
805 /* update the neigh seq. we don't bother with the mac seq as
806 * sync_mac_update already took care of that
808 tmp_seq
= MAX(n
->loc_seq
, seq
);
809 if (tmp_seq
!= n
->loc_seq
) {
810 n
->loc_seq
= tmp_seq
;
814 /* Mark Router flag (R-bit) */
816 SET_FLAG(n
->flags
, ZEBRA_NEIGH_ROUTER_FLAG
);
818 UNSET_FLAG(n
->flags
, ZEBRA_NEIGH_ROUTER_FLAG
);
820 if (old_router
!= is_router
)
821 inform_dataplane
= true;
823 new_bgp_ready
= zebra_evpn_neigh_is_ready_for_bgp(n
);
824 if (old_bgp_ready
!= new_bgp_ready
)
827 new_mac_static
= zebra_evpn_mac_is_static(mac
);
828 if ((old_mac_static
!= new_mac_static
) || ctx
->mac_dp_update_deferred
)
829 zebra_evpn_sync_mac_dp_install(mac
, ctx
->mac_inactive
,
830 false /* force_clear_static */,
833 if (IS_ZEBRA_DEBUG_EVPN_MH_NEIGH
)
835 "sync-neigh %s vni %u ip %s mac %s if %s(%d) seq %d f 0x%x%s%s",
836 created
? "created" : "updated", n
->zevpn
->vni
,
837 ipaddr2str(&n
->ip
, ipbuf
, sizeof(ipbuf
)),
838 prefix_mac2str(&n
->emac
, macbuf
, sizeof(macbuf
)),
839 ifp
? ifp
->name
: "", ifindex
, n
->loc_seq
, n
->flags
,
840 inform_bgp
? " inform_bgp" : "",
841 inform_dataplane
? " inform_dp" : "");
843 if (inform_dataplane
)
844 zebra_evpn_sync_neigh_dp_install(n
, set_dp_inactive
,
845 false /* force_clear_static */,
849 zebra_evpn_neigh_send_add_del_to_client(n
, old_bgp_ready
,
856 * Uninstall remote neighbor from the kernel.
858 static int zebra_evpn_neigh_uninstall(zebra_evpn_t
*zevpn
, zebra_neigh_t
*n
)
860 struct interface
*vlan_if
;
862 if (!(n
->flags
& ZEBRA_NEIGH_REMOTE
))
865 vlan_if
= zevpn_map_to_svi(zevpn
);
869 ZEBRA_NEIGH_SET_INACTIVE(n
);
872 dplane_rem_neigh_delete(vlan_if
, &n
->ip
);
878 * Free neighbor hash entry (callback)
880 static void zebra_evpn_neigh_del_hash_entry(struct hash_bucket
*bucket
,
883 struct neigh_walk_ctx
*wctx
= arg
;
884 zebra_neigh_t
*n
= bucket
->data
;
886 if (((wctx
->flags
& DEL_LOCAL_NEIGH
) && (n
->flags
& ZEBRA_NEIGH_LOCAL
))
887 || ((wctx
->flags
& DEL_REMOTE_NEIGH
)
888 && (n
->flags
& ZEBRA_NEIGH_REMOTE
))
889 || ((wctx
->flags
& DEL_REMOTE_NEIGH_FROM_VTEP
)
890 && (n
->flags
& ZEBRA_NEIGH_REMOTE
)
891 && IPV4_ADDR_SAME(&n
->r_vtep_ip
, &wctx
->r_vtep_ip
))) {
892 if (wctx
->upd_client
&& (n
->flags
& ZEBRA_NEIGH_LOCAL
))
893 zebra_evpn_neigh_send_del_to_client(
894 wctx
->zevpn
->vni
, &n
->ip
, &n
->emac
, n
->flags
,
895 n
->state
, false /*force*/);
897 if (wctx
->uninstall
) {
898 if (zebra_evpn_neigh_is_static(n
))
899 zebra_evpn_sync_neigh_dp_install(
900 n
, false /* set_inactive */,
901 true /* force_clear_static */,
903 if ((n
->flags
& ZEBRA_NEIGH_REMOTE
))
904 zebra_evpn_neigh_uninstall(wctx
->zevpn
, n
);
907 zebra_evpn_neigh_del(wctx
->zevpn
, n
);
914 * Delete all neighbor entries for this EVPN.
916 void zebra_evpn_neigh_del_all(zebra_evpn_t
*zevpn
, int uninstall
,
917 int upd_client
, uint32_t flags
)
919 struct neigh_walk_ctx wctx
;
921 if (!zevpn
->neigh_table
)
924 memset(&wctx
, 0, sizeof(struct neigh_walk_ctx
));
926 wctx
.uninstall
= uninstall
;
927 wctx
.upd_client
= upd_client
;
930 hash_iterate(zevpn
->neigh_table
, zebra_evpn_neigh_del_hash_entry
,
935 * Look up neighbor hash entry.
937 zebra_neigh_t
*zebra_evpn_neigh_lookup(zebra_evpn_t
*zevpn
, struct ipaddr
*ip
)
942 memset(&tmp
, 0, sizeof(tmp
));
943 memcpy(&tmp
.ip
, ip
, sizeof(struct ipaddr
));
944 n
= hash_lookup(zevpn
->neigh_table
, &tmp
);
950 * Process all neighbors associated with a MAC upon the MAC being learnt
951 * locally or undergoing any other change (such as sequence number).
953 void zebra_evpn_process_neigh_on_local_mac_change(zebra_evpn_t
*zevpn
,
958 zebra_neigh_t
*n
= NULL
;
959 struct listnode
*node
= NULL
;
960 struct zebra_vrf
*zvrf
= NULL
;
961 char buf
[ETHER_ADDR_STRLEN
];
963 zvrf
= vrf_info_lookup(zevpn
->vxlan_if
->vrf_id
);
965 if (IS_ZEBRA_DEBUG_VXLAN
)
966 zlog_debug("Processing neighbors on local MAC %s %s, VNI %u",
967 prefix_mac2str(&zmac
->macaddr
, buf
, sizeof(buf
)),
968 seq_change
? "CHANGE" : "ADD", zevpn
->vni
);
970 /* Walk all neighbors and mark any inactive local neighbors as
971 * active and/or update sequence number upon a move, and inform BGP.
972 * The action for remote neighbors is TBD.
973 * NOTE: We can't simply uninstall remote neighbors as the kernel may
974 * accidentally end up deleting a just-learnt local neighbor.
976 for (ALL_LIST_ELEMENTS_RO(zmac
->neigh_list
, node
, n
)) {
977 if (CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_LOCAL
)) {
978 if (IS_ZEBRA_NEIGH_INACTIVE(n
) || seq_change
980 ZEBRA_NEIGH_SET_ACTIVE(n
);
981 n
->loc_seq
= zmac
->loc_seq
;
982 if (!(zvrf
->dup_addr_detect
&& zvrf
->dad_freeze
983 && !!CHECK_FLAG(n
->flags
,
984 ZEBRA_NEIGH_DUPLICATE
)))
985 zebra_evpn_neigh_send_add_to_client(
986 zevpn
->vni
, &n
->ip
, &n
->emac
,
987 n
->mac
, n
->flags
, n
->loc_seq
);
994 * Process all neighbors associated with a local MAC upon the MAC being
997 void zebra_evpn_process_neigh_on_local_mac_del(zebra_evpn_t
*zevpn
,
1000 zebra_neigh_t
*n
= NULL
;
1001 struct listnode
*node
= NULL
;
1002 char buf
[ETHER_ADDR_STRLEN
];
1004 if (IS_ZEBRA_DEBUG_VXLAN
)
1005 zlog_debug("Processing neighbors on local MAC %s DEL, VNI %u",
1006 prefix_mac2str(&zmac
->macaddr
, buf
, sizeof(buf
)),
1009 /* Walk all local neighbors and mark as inactive and inform
1011 * TBD: There is currently no handling for remote neighbors. We
1012 * don't expect them to exist, if they do, do we install the MAC
1013 * as a remote MAC and the neighbor as remote?
1015 for (ALL_LIST_ELEMENTS_RO(zmac
->neigh_list
, node
, n
)) {
1016 if (CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_LOCAL
)) {
1017 if (IS_ZEBRA_NEIGH_ACTIVE(n
)) {
1018 ZEBRA_NEIGH_SET_INACTIVE(n
);
1020 zebra_evpn_neigh_send_del_to_client(
1021 zevpn
->vni
, &n
->ip
, &n
->emac
, n
->flags
,
1022 ZEBRA_NEIGH_ACTIVE
, false /*force*/);
1029 * Process all neighbors associated with a MAC upon the MAC being remotely
1032 void zebra_evpn_process_neigh_on_remote_mac_add(zebra_evpn_t
*zevpn
,
1035 zebra_neigh_t
*n
= NULL
;
1036 struct listnode
*node
= NULL
;
1037 char buf
[ETHER_ADDR_STRLEN
];
1039 if (IS_ZEBRA_DEBUG_VXLAN
)
1040 zlog_debug("Processing neighbors on remote MAC %s ADD, VNI %u",
1041 prefix_mac2str(&zmac
->macaddr
, buf
, sizeof(buf
)),
1044 /* Walk all local neighbors and mark as inactive and inform
1047 for (ALL_LIST_ELEMENTS_RO(zmac
->neigh_list
, node
, n
)) {
1048 if (CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_LOCAL
)) {
1049 if (IS_ZEBRA_NEIGH_ACTIVE(n
)) {
1050 ZEBRA_NEIGH_SET_INACTIVE(n
);
1052 zebra_evpn_neigh_send_del_to_client(
1053 zevpn
->vni
, &n
->ip
, &n
->emac
, n
->flags
,
1054 ZEBRA_NEIGH_ACTIVE
, false /* force */);
1061 * Process all neighbors associated with a remote MAC upon the MAC being
1064 void zebra_evpn_process_neigh_on_remote_mac_del(zebra_evpn_t
*zevpn
,
1067 /* NOTE: Currently a NO-OP. */
1070 static inline void zebra_evpn_local_neigh_update_log(
1071 const char *pfx
, zebra_neigh_t
*n
, bool is_router
, bool local_inactive
,
1072 bool old_bgp_ready
, bool new_bgp_ready
, bool inform_dataplane
,
1073 bool inform_bgp
, const char *sfx
)
1075 char macbuf
[ETHER_ADDR_STRLEN
];
1076 char ipbuf
[INET6_ADDRSTRLEN
];
1078 if (!IS_ZEBRA_DEBUG_EVPN_MH_NEIGH
)
1081 zlog_debug("%s neigh vni %u ip %s mac %s f 0x%x%s%s%s%s%s%s %s", pfx
,
1082 n
->zevpn
->vni
, ipaddr2str(&n
->ip
, ipbuf
, sizeof(ipbuf
)),
1083 prefix_mac2str(&n
->emac
, macbuf
, sizeof(macbuf
)), n
->flags
,
1084 is_router
? " router" : "",
1085 local_inactive
? " local-inactive" : "",
1086 old_bgp_ready
? " old_bgp_ready" : "",
1087 new_bgp_ready
? " new_bgp_ready" : "",
1088 inform_dataplane
? " inform_dp" : "",
1089 inform_bgp
? " inform_bgp" : "", sfx
);
1092 /* As part Duplicate Address Detection (DAD) for IP mobility
1093 * MAC binding changes, ensure to inherit duplicate flag
1096 static int zebra_evpn_ip_inherit_dad_from_mac(struct zebra_vrf
*zvrf
,
1097 zebra_mac_t
*old_zmac
,
1098 zebra_mac_t
*new_zmac
,
1101 bool is_old_mac_dup
= false;
1102 bool is_new_mac_dup
= false;
1104 if (!zvrf
->dup_addr_detect
)
1106 /* Check old or new MAC is detected as duplicate
1107 * mark this neigh as duplicate
1111 CHECK_FLAG(old_zmac
->flags
, ZEBRA_MAC_DUPLICATE
);
1114 CHECK_FLAG(new_zmac
->flags
, ZEBRA_MAC_DUPLICATE
);
1115 /* Old and/or new MAC can be in duplicate state,
1116 * based on that IP/Neigh Inherits the flag.
1117 * If New MAC is marked duplicate, inherit to the IP.
1118 * If old MAC is duplicate but new MAC is not, clear
1119 * duplicate flag for IP and reset detection params
1120 * and let IP DAD retrigger.
1122 if (is_new_mac_dup
&& !CHECK_FLAG(nbr
->flags
, ZEBRA_NEIGH_DUPLICATE
)) {
1123 SET_FLAG(nbr
->flags
, ZEBRA_NEIGH_DUPLICATE
);
1124 /* Capture Duplicate detection time */
1125 nbr
->dad_dup_detect_time
= monotime(NULL
);
1126 /* Mark neigh inactive */
1127 ZEBRA_NEIGH_SET_INACTIVE(nbr
);
1130 } else if (is_old_mac_dup
&& !is_new_mac_dup
) {
1131 UNSET_FLAG(nbr
->flags
, ZEBRA_NEIGH_DUPLICATE
);
1133 nbr
->detect_start_time
.tv_sec
= 0;
1134 nbr
->detect_start_time
.tv_usec
= 0;
1139 static int zebra_evpn_dad_ip_auto_recovery_exp(struct thread
*t
)
1141 struct zebra_vrf
*zvrf
= NULL
;
1142 zebra_neigh_t
*nbr
= NULL
;
1143 zebra_evpn_t
*zevpn
= NULL
;
1144 char buf1
[INET6_ADDRSTRLEN
];
1145 char buf2
[ETHER_ADDR_STRLEN
];
1147 nbr
= THREAD_ARG(t
);
1149 /* since this is asynchronous we need sanity checks*/
1150 zvrf
= vrf_info_lookup(nbr
->zevpn
->vrf_id
);
1154 zevpn
= zebra_evpn_lookup(nbr
->zevpn
->vni
);
1158 nbr
= zebra_evpn_neigh_lookup(zevpn
, &nbr
->ip
);
1162 if (IS_ZEBRA_DEBUG_VXLAN
)
1164 "%s: duplicate addr MAC %s IP %s flags 0x%x learn count %u vni %u auto recovery expired",
1166 prefix_mac2str(&nbr
->emac
, buf2
, sizeof(buf2
)),
1167 ipaddr2str(&nbr
->ip
, buf1
, sizeof(buf1
)), nbr
->flags
,
1168 nbr
->dad_count
, zevpn
->vni
);
1170 UNSET_FLAG(nbr
->flags
, ZEBRA_NEIGH_DUPLICATE
);
1172 nbr
->detect_start_time
.tv_sec
= 0;
1173 nbr
->detect_start_time
.tv_usec
= 0;
1174 nbr
->dad_dup_detect_time
= 0;
1175 nbr
->dad_ip_auto_recovery_timer
= NULL
;
1176 ZEBRA_NEIGH_SET_ACTIVE(nbr
);
1179 if (CHECK_FLAG(nbr
->flags
, ZEBRA_NEIGH_LOCAL
)) {
1180 zebra_evpn_neigh_send_add_to_client(zevpn
->vni
, &nbr
->ip
,
1181 &nbr
->emac
, nbr
->mac
,
1182 nbr
->flags
, nbr
->loc_seq
);
1183 } else if (!!CHECK_FLAG(nbr
->flags
, ZEBRA_NEIGH_REMOTE
)) {
1184 zebra_evpn_rem_neigh_install(zevpn
, nbr
, false /*was_static*/);
1191 zebra_evpn_dup_addr_detect_for_neigh(struct zebra_vrf
*zvrf
, zebra_neigh_t
*nbr
,
1192 struct in_addr vtep_ip
, bool do_dad
,
1193 bool *is_dup_detect
, bool is_local
)
1196 struct timeval elapsed
= {0, 0};
1197 char buf
[ETHER_ADDR_STRLEN
];
1198 char buf1
[INET6_ADDRSTRLEN
];
1199 bool reset_params
= false;
1201 if (!zvrf
->dup_addr_detect
)
1204 /* IP is detected as duplicate or inherit dup
1205 * state, hold on to install as remote entry
1206 * only if freeze is enabled.
1208 if (CHECK_FLAG(nbr
->flags
, ZEBRA_NEIGH_DUPLICATE
)) {
1209 if (IS_ZEBRA_DEBUG_VXLAN
)
1211 "%s: duplicate addr MAC %s IP %s flags 0x%x skip installing, learn count %u recover time %u",
1213 prefix_mac2str(&nbr
->emac
, buf
, sizeof(buf
)),
1214 ipaddr2str(&nbr
->ip
, buf1
, sizeof(buf1
)),
1215 nbr
->flags
, nbr
->dad_count
,
1216 zvrf
->dad_freeze_time
);
1218 if (zvrf
->dad_freeze
)
1219 *is_dup_detect
= true;
1221 /* warn-only action, neigh will be installed.
1222 * freeze action, it wil not be installed.
1230 /* Check if detection time (M-secs) expired.
1231 * Reset learn count and detection start time.
1232 * During remote mac add, count should already be 1
1233 * via local learning.
1235 monotime_since(&nbr
->detect_start_time
, &elapsed
);
1236 reset_params
= (elapsed
.tv_sec
> zvrf
->dad_time
);
1238 if (is_local
&& !reset_params
) {
1239 /* RFC-7432: A PE/VTEP that detects a MAC mobility
1240 * event via LOCAL learning starts an M-second timer.
1242 * NOTE: This is the START of the probe with count is
1243 * 0 during LOCAL learn event.
1245 reset_params
= !nbr
->dad_count
;
1249 if (IS_ZEBRA_DEBUG_VXLAN
)
1251 "%s: duplicate addr MAC %s IP %s flags 0x%x detection time passed, reset learn count %u",
1253 prefix_mac2str(&nbr
->emac
, buf
, sizeof(buf
)),
1254 ipaddr2str(&nbr
->ip
, buf1
, sizeof(buf1
)),
1255 nbr
->flags
, nbr
->dad_count
);
1256 /* Reset learn count but do not start detection
1257 * during REMOTE learn event.
1260 /* Start dup. addr detection (DAD) start time,
1261 * ONLY during LOCAL learn.
1264 monotime(&nbr
->detect_start_time
);
1266 } else if (!is_local
) {
1267 /* For REMOTE IP/Neigh, increment detection count
1268 * ONLY while in probe window, once window passed,
1269 * next local learn event should trigger DAD.
1274 /* For LOCAL IP/Neigh learn event, once count is reset above via either
1275 * initial/start detection time or passed the probe time, the count
1276 * needs to be incremented.
1281 if (nbr
->dad_count
>= zvrf
->dad_max_moves
) {
1283 EC_ZEBRA_DUP_IP_DETECTED
,
1284 "VNI %u: MAC %s IP %s detected as duplicate during %s VTEP %s",
1286 prefix_mac2str(&nbr
->emac
, buf
, sizeof(buf
)),
1287 ipaddr2str(&nbr
->ip
, buf1
, sizeof(buf1
)),
1288 is_local
? "local update, last" : "remote update, from",
1289 inet_ntoa(vtep_ip
));
1291 SET_FLAG(nbr
->flags
, ZEBRA_NEIGH_DUPLICATE
);
1293 /* Capture Duplicate detection time */
1294 nbr
->dad_dup_detect_time
= monotime(NULL
);
1296 /* Start auto recovery timer for this IP */
1297 THREAD_OFF(nbr
->dad_ip_auto_recovery_timer
);
1298 if (zvrf
->dad_freeze
&& zvrf
->dad_freeze_time
) {
1299 if (IS_ZEBRA_DEBUG_VXLAN
)
1301 "%s: duplicate addr MAC %s IP %s flags 0x%x auto recovery time %u start",
1303 prefix_mac2str(&nbr
->emac
, buf
,
1305 ipaddr2str(&nbr
->ip
, buf1
,
1307 nbr
->flags
, zvrf
->dad_freeze_time
);
1309 thread_add_timer(zrouter
.master
,
1310 zebra_evpn_dad_ip_auto_recovery_exp
,
1311 nbr
, zvrf
->dad_freeze_time
,
1312 &nbr
->dad_ip_auto_recovery_timer
);
1314 if (zvrf
->dad_freeze
)
1315 *is_dup_detect
= true;
1319 int zebra_evpn_local_neigh_update(zebra_evpn_t
*zevpn
, struct interface
*ifp
,
1320 struct ipaddr
*ip
, struct ethaddr
*macaddr
,
1321 bool is_router
, bool local_inactive
,
1324 char buf
[ETHER_ADDR_STRLEN
];
1325 char buf2
[INET6_ADDRSTRLEN
];
1326 struct zebra_vrf
*zvrf
;
1327 zebra_neigh_t
*n
= NULL
;
1328 zebra_mac_t
*zmac
= NULL
, *old_zmac
= NULL
;
1329 uint32_t old_mac_seq
= 0, mac_new_seq
= 0;
1330 bool upd_mac_seq
= false;
1331 bool neigh_mac_change
= false;
1332 bool neigh_on_hold
= false;
1333 bool neigh_was_remote
= false;
1334 bool do_dad
= false;
1335 struct in_addr vtep_ip
= {.s_addr
= 0};
1336 bool inform_dataplane
= false;
1337 bool created
= false;
1338 bool new_static
= false;
1339 bool old_bgp_ready
= false;
1342 /* Check if the MAC exists. */
1343 zmac
= zebra_evpn_mac_lookup(zevpn
, macaddr
);
1345 /* create a dummy MAC if the MAC is not already present */
1346 if (IS_ZEBRA_DEBUG_VXLAN
)
1347 zlog_debug("AUTO MAC %s created for neigh %s on VNI %u",
1348 prefix_mac2str(macaddr
, buf
, sizeof(buf
)),
1349 ipaddr2str(ip
, buf2
, sizeof(buf2
)),
1352 zmac
= zebra_evpn_mac_add(zevpn
, macaddr
);
1354 zlog_debug("Failed to add MAC %s VNI %u",
1355 prefix_mac2str(macaddr
, buf
, sizeof(buf
)),
1360 memset(&zmac
->fwd_info
, 0, sizeof(zmac
->fwd_info
));
1361 memset(&zmac
->flags
, 0, sizeof(uint32_t));
1362 SET_FLAG(zmac
->flags
, ZEBRA_MAC_AUTO
);
1364 if (CHECK_FLAG(zmac
->flags
, ZEBRA_MAC_REMOTE
)) {
1366 * We don't change the MAC to local upon a neighbor
1367 * learn event, we wait for the explicit local MAC
1368 * learn. However, we have to compute its sequence
1369 * number in preparation for when it actually turns
1376 zvrf
= vrf_info_lookup(zevpn
->vxlan_if
->vrf_id
);
1378 if (IS_ZEBRA_DEBUG_VXLAN
)
1379 zlog_debug(" Unable to find vrf for: %d",
1380 zevpn
->vxlan_if
->vrf_id
);
1384 /* Check if the neighbor exists. */
1385 n
= zebra_evpn_neigh_lookup(zevpn
, ip
);
1387 /* New neighbor - create */
1388 n
= zebra_evpn_neigh_add(zevpn
, ip
, macaddr
, zmac
, 0);
1391 EC_ZEBRA_MAC_ADD_FAILED
,
1392 "Failed to add neighbor %s MAC %s intf %s(%u) -> VNI %u",
1393 ipaddr2str(ip
, buf2
, sizeof(buf2
)),
1394 prefix_mac2str(macaddr
, buf
, sizeof(buf
)),
1395 ifp
->name
, ifp
->ifindex
, zevpn
->vni
);
1398 /* Set "local" forwarding info. */
1399 SET_FLAG(n
->flags
, ZEBRA_NEIGH_LOCAL
);
1400 n
->ifindex
= ifp
->ifindex
;
1403 if (CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_LOCAL
)) {
1406 bool old_local_inactive
;
1408 old_local_inactive
= !!CHECK_FLAG(
1409 n
->flags
, ZEBRA_NEIGH_LOCAL_INACTIVE
);
1411 old_bgp_ready
= zebra_evpn_neigh_is_ready_for_bgp(n
);
1413 /* Note any changes and see if of interest to BGP. */
1414 mac_different
= !!memcmp(&n
->emac
, macaddr
, ETH_ALEN
);
1416 !!CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_ROUTER_FLAG
);
1417 new_static
= zebra_evpn_neigh_is_static(n
);
1418 if (!mac_different
&& is_router
== cur_is_router
1419 && old_local_inactive
== local_inactive
1420 && dp_static
!= new_static
) {
1421 if (IS_ZEBRA_DEBUG_VXLAN
)
1423 " Ignoring entry mac is the same and is_router == cur_is_router");
1424 n
->ifindex
= ifp
->ifindex
;
1429 if (!mac_different
) {
1430 /* XXX - cleanup this code duplication */
1431 bool is_neigh_freezed
= false;
1433 /* Only the router flag has changed. */
1436 ZEBRA_NEIGH_ROUTER_FLAG
);
1438 UNSET_FLAG(n
->flags
,
1439 ZEBRA_NEIGH_ROUTER_FLAG
);
1443 ZEBRA_NEIGH_LOCAL_INACTIVE
);
1445 UNSET_FLAG(n
->flags
,
1446 ZEBRA_NEIGH_LOCAL_INACTIVE
);
1448 zebra_evpn_neigh_is_ready_for_bgp(n
);
1450 /* Neigh is in freeze state and freeze action
1451 * is enabled, do not send update to client.
1454 (zvrf
->dup_addr_detect
1456 && CHECK_FLAG(n
->flags
,
1457 ZEBRA_NEIGH_DUPLICATE
));
1459 zebra_evpn_local_neigh_update_log(
1460 "local", n
, is_router
, local_inactive
,
1461 old_bgp_ready
, new_bgp_ready
, false,
1462 false, "flag-update");
1464 /* if the neigh can no longer be advertised
1465 * remove it from bgp
1467 if (!is_neigh_freezed
) {
1468 zebra_evpn_neigh_send_add_del_to_client(
1472 if (IS_ZEBRA_DEBUG_VXLAN
1473 && IS_ZEBRA_NEIGH_ACTIVE(n
))
1475 " Neighbor active and frozen");
1480 /* The MAC has changed, need to issue a delete
1481 * first as this means a different MACIP route.
1482 * Also, need to do some unlinking/relinking.
1483 * We also need to update the MAC's sequence number
1484 * in different situations.
1486 if (old_bgp_ready
) {
1487 zebra_evpn_neigh_send_del_to_client(
1488 zevpn
->vni
, &n
->ip
, &n
->emac
, n
->flags
,
1489 n
->state
, false /*force*/);
1490 old_bgp_ready
= false;
1493 old_mac_seq
= CHECK_FLAG(old_zmac
->flags
,
1496 : old_zmac
->loc_seq
;
1497 neigh_mac_change
= upd_mac_seq
= true;
1498 zebra_evpn_local_neigh_deref_mac(
1499 n
, true /* send_mac_update */);
1502 /* if mac changes abandon peer flags and tell
1503 * dataplane to clear the static flag
1505 if (zebra_evpn_neigh_clear_sync_info(n
))
1506 inform_dataplane
= true;
1507 /* Update the forwarding info. */
1508 n
->ifindex
= ifp
->ifindex
;
1510 /* Link to new MAC */
1511 zebra_evpn_local_neigh_ref_mac(
1512 n
, macaddr
, zmac
, true /* send_mac_update */);
1513 } else if (CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_REMOTE
)) {
1515 * Neighbor has moved from remote to local. Its
1516 * MAC could have also changed as part of the move.
1518 if (memcmp(n
->emac
.octet
, macaddr
->octet
, ETH_ALEN
)
1523 CHECK_FLAG(old_zmac
->flags
,
1526 : old_zmac
->loc_seq
;
1527 neigh_mac_change
= upd_mac_seq
= true;
1528 zebra_evpn_local_neigh_deref_mac(
1529 n
, true /* send_update */);
1532 /* Link to new MAC */
1533 zebra_evpn_local_neigh_ref_mac(
1534 n
, macaddr
, zmac
, true /*send_update*/);
1536 /* Based on Mobility event Scenario-B from the
1537 * draft, neigh's previous state was remote treat this
1540 neigh_was_remote
= true;
1541 vtep_ip
= n
->r_vtep_ip
;
1542 /* Mark appropriately */
1543 UNSET_FLAG(n
->flags
, ZEBRA_NEIGH_REMOTE
);
1544 n
->r_vtep_ip
.s_addr
= INADDR_ANY
;
1545 SET_FLAG(n
->flags
, ZEBRA_NEIGH_LOCAL
);
1546 n
->ifindex
= ifp
->ifindex
;
1550 /* If MAC was previously remote, or the neighbor had a different
1551 * MAC earlier, recompute the sequence number.
1554 uint32_t seq1
, seq2
;
1556 seq1
= CHECK_FLAG(zmac
->flags
, ZEBRA_MAC_REMOTE
)
1559 seq2
= neigh_mac_change
? old_mac_seq
+ 1 : 0;
1560 mac_new_seq
= zmac
->loc_seq
< MAX(seq1
, seq2
) ? MAX(seq1
, seq2
)
1565 SET_FLAG(n
->flags
, ZEBRA_NEIGH_LOCAL_INACTIVE
);
1567 UNSET_FLAG(n
->flags
, ZEBRA_NEIGH_LOCAL_INACTIVE
);
1569 /* Mark Router flag (R-bit) */
1571 SET_FLAG(n
->flags
, ZEBRA_NEIGH_ROUTER_FLAG
);
1573 UNSET_FLAG(n
->flags
, ZEBRA_NEIGH_ROUTER_FLAG
);
1575 /* if the dataplane thinks that this is a sync entry but
1576 * zebra doesn't we need to re-concile the diff
1577 * by re-installing the dataplane entry
1580 new_static
= zebra_evpn_neigh_is_static(n
);
1582 inform_dataplane
= true;
1585 /* Check old and/or new MAC detected as duplicate mark
1586 * the neigh as duplicate
1588 if (zebra_evpn_ip_inherit_dad_from_mac(zvrf
, old_zmac
, zmac
, n
)) {
1590 EC_ZEBRA_DUP_IP_INHERIT_DETECTED
,
1591 "VNI %u: MAC %s IP %s detected as duplicate during local update, inherit duplicate from MAC",
1592 zevpn
->vni
, prefix_mac2str(macaddr
, buf
, sizeof(buf
)),
1593 ipaddr2str(&n
->ip
, buf2
, sizeof(buf2
)));
1596 /* For IP Duplicate Address Detection (DAD) is trigger,
1597 * when the event is extended mobility based on scenario-B
1598 * from the draft, IP/Neigh's MAC binding changed and
1599 * neigh's previous state was remote.
1601 if (neigh_mac_change
&& neigh_was_remote
)
1604 zebra_evpn_dup_addr_detect_for_neigh(zvrf
, n
, vtep_ip
, do_dad
,
1605 &neigh_on_hold
, true);
1607 if (inform_dataplane
)
1608 zebra_evpn_sync_neigh_dp_install(n
, false /* set_inactive */,
1609 false /* force_clear_static */,
1612 /* Before we program this in BGP, we need to check if MAC is locally
1613 * learnt. If not, force neighbor to be inactive and reset its seq.
1615 if (!CHECK_FLAG(zmac
->flags
, ZEBRA_MAC_LOCAL
)) {
1616 zebra_evpn_local_neigh_update_log(
1617 "local", n
, is_router
, local_inactive
, false, false,
1618 inform_dataplane
, false, "auto-mac");
1619 ZEBRA_NEIGH_SET_INACTIVE(n
);
1621 zmac
->loc_seq
= mac_new_seq
;
1625 zebra_evpn_local_neigh_update_log("local", n
, is_router
, local_inactive
,
1626 false, false, inform_dataplane
, true,
1627 created
? "created" : "updated");
1629 /* If the MAC's sequence number has changed, inform the MAC and all
1630 * neighbors associated with the MAC to BGP, else just inform this
1633 if (upd_mac_seq
&& zmac
->loc_seq
!= mac_new_seq
) {
1634 if (IS_ZEBRA_DEBUG_VXLAN
)
1636 "Seq changed for MAC %s VNI %u - old %u new %u",
1637 prefix_mac2str(macaddr
, buf
, sizeof(buf
)),
1638 zevpn
->vni
, zmac
->loc_seq
, mac_new_seq
);
1639 zmac
->loc_seq
= mac_new_seq
;
1640 if (zebra_evpn_mac_send_add_to_client(zevpn
->vni
, macaddr
,
1642 zmac
->loc_seq
, zmac
->es
))
1644 zebra_evpn_process_neigh_on_local_mac_change(zevpn
, zmac
, 1,
1649 n
->loc_seq
= zmac
->loc_seq
;
1651 if (!neigh_on_hold
) {
1652 ZEBRA_NEIGH_SET_ACTIVE(n
);
1653 new_bgp_ready
= zebra_evpn_neigh_is_ready_for_bgp(n
);
1654 zebra_evpn_neigh_send_add_del_to_client(n
, old_bgp_ready
,
1657 if (IS_ZEBRA_DEBUG_VXLAN
)
1658 zlog_debug(" Neighbor on hold not sending");
1663 int zebra_evpn_remote_neigh_update(zebra_evpn_t
*zevpn
, struct interface
*ifp
,
1664 struct ipaddr
*ip
, struct ethaddr
*macaddr
,
1667 char buf
[ETHER_ADDR_STRLEN
];
1668 char buf2
[INET6_ADDRSTRLEN
];
1669 zebra_neigh_t
*n
= NULL
;
1670 zebra_mac_t
*zmac
= NULL
;
1672 /* If the neighbor is unknown, there is no further action. */
1673 n
= zebra_evpn_neigh_lookup(zevpn
, ip
);
1677 /* If a remote entry, see if it needs to be refreshed */
1678 if (CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_REMOTE
)) {
1680 if (state
& NUD_STALE
)
1681 zebra_evpn_rem_neigh_install(zevpn
, n
,
1682 false /*was_static*/);
1685 /* We got a "remote" neighbor notification for an entry
1686 * we think is local. This can happen in a multihoming
1687 * scenario - but only if the MAC is already "remote".
1688 * Just mark our entry as "remote".
1690 zmac
= zebra_evpn_mac_lookup(zevpn
, macaddr
);
1691 if (!zmac
|| !CHECK_FLAG(zmac
->flags
, ZEBRA_MAC_REMOTE
)) {
1693 "Ignore remote neigh %s (MAC %s) on L2-VNI %u - MAC unknown or local",
1694 ipaddr2str(&n
->ip
, buf2
, sizeof(buf2
)),
1695 prefix_mac2str(macaddr
, buf
, sizeof(buf
)),
1700 UNSET_FLAG(n
->flags
, ZEBRA_NEIGH_ALL_LOCAL_FLAGS
);
1701 SET_FLAG(n
->flags
, ZEBRA_NEIGH_REMOTE
);
1702 ZEBRA_NEIGH_SET_ACTIVE(n
);
1703 n
->r_vtep_ip
= zmac
->fwd_info
.r_vtep_ip
;
1709 /* Notify Neighbor entries to the Client, skips the GW entry */
1711 zebra_evpn_send_neigh_hash_entry_to_client(struct hash_bucket
*bucket
,
1714 struct mac_walk_ctx
*wctx
= arg
;
1715 zebra_neigh_t
*zn
= bucket
->data
;
1716 zebra_mac_t
*zmac
= NULL
;
1718 if (CHECK_FLAG(zn
->flags
, ZEBRA_NEIGH_DEF_GW
))
1721 if (CHECK_FLAG(zn
->flags
, ZEBRA_NEIGH_LOCAL
)
1722 && IS_ZEBRA_NEIGH_ACTIVE(zn
)) {
1723 zmac
= zebra_evpn_mac_lookup(wctx
->zevpn
, &zn
->emac
);
1727 zebra_evpn_neigh_send_add_to_client(wctx
->zevpn
->vni
, &zn
->ip
,
1729 zn
->flags
, zn
->loc_seq
);
1733 /* Iterator of a specific EVPN */
1734 void zebra_evpn_send_neigh_to_client(zebra_evpn_t
*zevpn
)
1736 struct neigh_walk_ctx wctx
;
1738 memset(&wctx
, 0, sizeof(struct neigh_walk_ctx
));
1741 hash_iterate(zevpn
->neigh_table
,
1742 zebra_evpn_send_neigh_hash_entry_to_client
, &wctx
);
1745 void zebra_evpn_clear_dup_neigh_hash(struct hash_bucket
*bucket
, void *ctxt
)
1747 struct neigh_walk_ctx
*wctx
= ctxt
;
1749 zebra_evpn_t
*zevpn
;
1750 char buf
[INET6_ADDRSTRLEN
];
1752 nbr
= (zebra_neigh_t
*)bucket
->data
;
1756 zevpn
= wctx
->zevpn
;
1758 if (!CHECK_FLAG(nbr
->flags
, ZEBRA_NEIGH_DUPLICATE
))
1761 if (IS_ZEBRA_DEBUG_VXLAN
) {
1762 ipaddr2str(&nbr
->ip
, buf
, sizeof(buf
));
1763 zlog_debug("%s: clear neigh %s dup state, flags 0x%x seq %u",
1764 __func__
, buf
, nbr
->flags
, nbr
->loc_seq
);
1767 UNSET_FLAG(nbr
->flags
, ZEBRA_NEIGH_DUPLICATE
);
1769 nbr
->detect_start_time
.tv_sec
= 0;
1770 nbr
->detect_start_time
.tv_usec
= 0;
1771 nbr
->dad_dup_detect_time
= 0;
1772 THREAD_OFF(nbr
->dad_ip_auto_recovery_timer
);
1774 if (CHECK_FLAG(nbr
->flags
, ZEBRA_NEIGH_LOCAL
)) {
1775 zebra_evpn_neigh_send_add_to_client(zevpn
->vni
, &nbr
->ip
,
1776 &nbr
->emac
, nbr
->mac
,
1777 nbr
->flags
, nbr
->loc_seq
);
1778 } else if (CHECK_FLAG(nbr
->flags
, ZEBRA_NEIGH_REMOTE
)) {
1779 zebra_evpn_rem_neigh_install(zevpn
, nbr
, false /*was_static*/);
1784 * Print a specific neighbor entry.
1786 void zebra_evpn_print_neigh(zebra_neigh_t
*n
, void *ctxt
, json_object
*json
)
1789 char buf1
[ETHER_ADDR_STRLEN
];
1790 char buf2
[INET6_ADDRSTRLEN
];
1791 const char *type_str
;
1792 const char *state_str
;
1793 bool flags_present
= false;
1794 struct zebra_vrf
*zvrf
= NULL
;
1795 struct timeval detect_start_time
= {0, 0};
1796 char timebuf
[MONOTIME_STRLEN
];
1797 char thread_buf
[THREAD_TIMER_STRLEN
];
1799 zvrf
= zebra_vrf_get_evpn();
1803 ipaddr2str(&n
->ip
, buf2
, sizeof(buf2
));
1804 prefix_mac2str(&n
->emac
, buf1
, sizeof(buf1
));
1805 type_str
= CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_LOCAL
) ? "local" : "remote";
1806 state_str
= IS_ZEBRA_NEIGH_ACTIVE(n
) ? "active" : "inactive";
1807 vty
= (struct vty
*)ctxt
;
1809 bool sync_info
= false;
1811 vty_out(vty
, "IP: %s\n",
1812 ipaddr2str(&n
->ip
, buf2
, sizeof(buf2
)));
1813 vty_out(vty
, " Type: %s\n", type_str
);
1814 vty_out(vty
, " State: %s\n", state_str
);
1815 vty_out(vty
, " MAC: %s\n",
1816 prefix_mac2str(&n
->emac
, buf1
, sizeof(buf1
)));
1817 vty_out(vty
, " Sync-info:");
1818 if (CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_LOCAL_INACTIVE
)) {
1819 vty_out(vty
, " local-inactive");
1822 if (CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_ES_PEER_PROXY
)) {
1823 vty_out(vty
, " peer-proxy");
1826 if (CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_ES_PEER_ACTIVE
)) {
1827 vty_out(vty
, " peer-active");
1830 if (n
->hold_timer
) {
1831 vty_out(vty
, " (ht: %s)",
1832 thread_timer_to_hhmmss(thread_buf
,
1841 json_object_string_add(json
, "ip", buf2
);
1842 json_object_string_add(json
, "type", type_str
);
1843 json_object_string_add(json
, "state", state_str
);
1844 json_object_string_add(json
, "mac", buf1
);
1845 if (CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_LOCAL_INACTIVE
))
1846 json_object_boolean_true_add(json
, "localInactive");
1847 if (CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_ES_PEER_PROXY
))
1848 json_object_boolean_true_add(json
, "peerProxy");
1849 if (CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_ES_PEER_ACTIVE
))
1850 json_object_boolean_true_add(json
, "peerActive");
1852 json_object_string_add(
1853 json
, "peerActiveHold",
1854 thread_timer_to_hhmmss(thread_buf
,
1858 if (CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_REMOTE
)) {
1861 json_object_string_add(json
, "remoteEs",
1862 n
->mac
->es
->esi_str
);
1864 vty_out(vty
, " Remote ES: %s\n",
1865 n
->mac
->es
->esi_str
);
1868 json_object_string_add(json
, "remoteVtep",
1869 inet_ntoa(n
->r_vtep_ip
));
1871 vty_out(vty
, " Remote VTEP: %s\n",
1872 inet_ntoa(n
->r_vtep_ip
));
1875 if (CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_DEF_GW
)) {
1877 vty_out(vty
, " Flags: Default-gateway");
1878 flags_present
= true;
1880 json_object_boolean_true_add(json
, "defaultGateway");
1882 if (CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_ROUTER_FLAG
)) {
1885 flags_present
? " ,Router" : " Flags: Router");
1886 flags_present
= true;
1892 vty_out(vty
, " Local Seq: %u Remote Seq: %u\n", n
->loc_seq
,
1895 if (CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_DUPLICATE
)) {
1896 vty_out(vty
, " Duplicate, detected at %s",
1897 time_to_string(n
->dad_dup_detect_time
,
1899 } else if (n
->dad_count
) {
1900 monotime_since(&n
->detect_start_time
,
1901 &detect_start_time
);
1902 if (detect_start_time
.tv_sec
<= zvrf
->dad_time
) {
1903 time_to_string(n
->detect_start_time
.tv_sec
,
1906 " Duplicate detection started at %s, detection count %u\n",
1907 timebuf
, n
->dad_count
);
1911 json_object_int_add(json
, "localSequence", n
->loc_seq
);
1912 json_object_int_add(json
, "remoteSequence", n
->rem_seq
);
1913 json_object_int_add(json
, "detectionCount", n
->dad_count
);
1914 if (CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_DUPLICATE
))
1915 json_object_boolean_true_add(json
, "isDuplicate");
1917 json_object_boolean_false_add(json
, "isDuplicate");
1921 void zebra_evpn_print_neigh_hdr(struct vty
*vty
, struct neigh_walk_ctx
*wctx
)
1923 vty_out(vty
, "Flags: I=local-inactive, P=peer-active, X=peer-proxy\n");
1924 vty_out(vty
, "%*s %-6s %-5s %-8s %-17s %-30s %s\n", -wctx
->addr_width
,
1925 "Neighbor", "Type", "Flags", "State", "MAC", "Remote ES/VTEP",
1929 static char *zebra_evpn_print_neigh_flags(zebra_neigh_t
*n
, char *flags_buf
,
1930 uint32_t flags_buf_sz
)
1932 snprintf(flags_buf
, flags_buf_sz
, "%s%s%s",
1933 (n
->flags
& ZEBRA_NEIGH_ES_PEER_ACTIVE
) ?
1935 (n
->flags
& ZEBRA_NEIGH_ES_PEER_PROXY
) ?
1937 (n
->flags
& ZEBRA_NEIGH_LOCAL_INACTIVE
) ?
1944 * Print neighbor hash entry - called for display of all neighbors.
1946 void zebra_evpn_print_neigh_hash(struct hash_bucket
*bucket
, void *ctxt
)
1949 json_object
*json_evpn
= NULL
, *json_row
= NULL
;
1951 char buf1
[ETHER_ADDR_STRLEN
];
1952 char buf2
[INET6_ADDRSTRLEN
];
1953 struct neigh_walk_ctx
*wctx
= ctxt
;
1954 const char *state_str
;
1958 json_evpn
= wctx
->json
;
1959 n
= (zebra_neigh_t
*)bucket
->data
;
1962 json_row
= json_object_new_object();
1964 prefix_mac2str(&n
->emac
, buf1
, sizeof(buf1
));
1965 ipaddr2str(&n
->ip
, buf2
, sizeof(buf2
));
1966 state_str
= IS_ZEBRA_NEIGH_ACTIVE(n
) ? "active" : "inactive";
1967 if (CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_LOCAL
)) {
1968 if (wctx
->flags
& SHOW_REMOTE_NEIGH_FROM_VTEP
)
1971 if (json_evpn
== NULL
) {
1972 vty_out(vty
, "%*s %-6s %-5s %-8s %-17s %-30s %u/%u\n",
1973 -wctx
->addr_width
, buf2
, "local",
1974 zebra_evpn_print_neigh_flags(n
, flags_buf
,
1975 sizeof(flags_buf
)), state_str
, buf1
,
1976 "", n
->loc_seq
, n
->rem_seq
);
1978 json_object_string_add(json_row
, "type", "local");
1979 json_object_string_add(json_row
, "state", state_str
);
1980 json_object_string_add(json_row
, "mac", buf1
);
1981 if (CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_DEF_GW
))
1982 json_object_boolean_true_add(json_row
,
1984 json_object_int_add(json_row
, "localSequence",
1986 json_object_int_add(json_row
, "remoteSequence",
1988 json_object_int_add(json_row
, "detectionCount",
1990 if (CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_DUPLICATE
))
1991 json_object_boolean_true_add(json_row
,
1994 json_object_boolean_false_add(json_row
,
1998 } else if (CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_REMOTE
)) {
1999 if ((wctx
->flags
& SHOW_REMOTE_NEIGH_FROM_VTEP
)
2000 && !IPV4_ADDR_SAME(&n
->r_vtep_ip
, &wctx
->r_vtep_ip
))
2003 if (json_evpn
== NULL
) {
2004 if ((wctx
->flags
& SHOW_REMOTE_NEIGH_FROM_VTEP
)
2005 && (wctx
->count
== 0))
2006 zebra_evpn_print_neigh_hdr(vty
, wctx
);
2007 vty_out(vty
, "%*s %-6s %-5s %-8s %-17s %-30s %u/%u\n",
2008 -wctx
->addr_width
, buf2
, "remote",
2009 zebra_evpn_print_neigh_flags(n
, flags_buf
,
2010 sizeof(flags_buf
)), state_str
, buf1
,
2011 n
->mac
->es
? n
->mac
->es
->esi_str
2012 : inet_ntoa(n
->r_vtep_ip
),
2013 n
->loc_seq
, n
->rem_seq
);
2015 json_object_string_add(json_row
, "type", "remote");
2016 json_object_string_add(json_row
, "state", state_str
);
2017 json_object_string_add(json_row
, "mac", buf1
);
2019 json_object_string_add(json_row
, "remoteEs",
2020 n
->mac
->es
->esi_str
);
2022 json_object_string_add(json_row
, "remoteVtep",
2023 inet_ntoa(n
->r_vtep_ip
));
2024 if (CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_DEF_GW
))
2025 json_object_boolean_true_add(json_row
,
2027 json_object_int_add(json_row
, "localSequence",
2029 json_object_int_add(json_row
, "remoteSequence",
2031 json_object_int_add(json_row
, "detectionCount",
2033 if (CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_DUPLICATE
))
2034 json_object_boolean_true_add(json_row
,
2037 json_object_boolean_false_add(json_row
,
2044 json_object_object_add(json_evpn
, buf2
, json_row
);
2048 * Print neighbor hash entry in detail - called for display of all neighbors.
2050 void zebra_evpn_print_neigh_hash_detail(struct hash_bucket
*bucket
, void *ctxt
)
2053 json_object
*json_evpn
= NULL
, *json_row
= NULL
;
2055 char buf
[INET6_ADDRSTRLEN
];
2056 struct neigh_walk_ctx
*wctx
= ctxt
;
2059 json_evpn
= wctx
->json
;
2060 n
= (zebra_neigh_t
*)bucket
->data
;
2064 ipaddr2str(&n
->ip
, buf
, sizeof(buf
));
2066 json_row
= json_object_new_object();
2068 zebra_evpn_print_neigh(n
, vty
, json_row
);
2071 json_object_object_add(json_evpn
, buf
, json_row
);
2074 void zebra_evpn_print_dad_neigh_hash(struct hash_bucket
*bucket
, void *ctxt
)
2078 nbr
= (zebra_neigh_t
*)bucket
->data
;
2082 if (CHECK_FLAG(nbr
->flags
, ZEBRA_NEIGH_DUPLICATE
))
2083 zebra_evpn_print_neigh_hash(bucket
, ctxt
);
2086 void zebra_evpn_print_dad_neigh_hash_detail(struct hash_bucket
*bucket
,
2091 nbr
= (zebra_neigh_t
*)bucket
->data
;
2095 if (CHECK_FLAG(nbr
->flags
, ZEBRA_NEIGH_DUPLICATE
))
2096 zebra_evpn_print_neigh_hash_detail(bucket
, ctxt
);
2099 void process_neigh_remote_macip_add(zebra_evpn_t
*zevpn
, struct zebra_vrf
*zvrf
,
2100 struct ipaddr
*ipaddr
, zebra_mac_t
*mac
,
2101 struct in_addr vtep_ip
, uint8_t flags
,
2105 int update_neigh
= 0;
2107 char buf
[ETHER_ADDR_STRLEN
];
2108 char buf1
[INET6_ADDRSTRLEN
];
2109 zebra_mac_t
*old_mac
= NULL
;
2110 bool old_static
= false;
2111 bool do_dad
= false;
2112 bool is_dup_detect
= false;
2116 is_router
= !!CHECK_FLAG(flags
, ZEBRA_MACIP_TYPE_ROUTER_FLAG
);
2118 /* Check if the remote neighbor itself is unknown or has a
2119 * change. If so, create or update and then install the entry.
2121 n
= zebra_evpn_neigh_lookup(zevpn
, ipaddr
);
2122 if (!n
|| !CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_REMOTE
)
2123 || is_router
!= !!CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_ROUTER_FLAG
)
2124 || (memcmp(&n
->emac
, &mac
->macaddr
, sizeof(struct ethaddr
)) != 0)
2125 || !IPV4_ADDR_SAME(&n
->r_vtep_ip
, &vtep_ip
) || seq
!= n
->rem_seq
)
2130 n
= zebra_evpn_neigh_add(zevpn
, ipaddr
, &mac
->macaddr
,
2134 "Failed to add Neigh %s MAC %s VNI %u Remote VTEP %s",
2135 ipaddr2str(ipaddr
, buf1
, sizeof(buf1
)),
2136 prefix_mac2str(&mac
->macaddr
, buf
,
2138 zevpn
->vni
, inet_ntoa(vtep_ip
));
2145 /* When host moves but changes its (MAC,IP)
2146 * binding, BGP may install a MACIP entry that
2147 * corresponds to "older" location of the host
2148 * in transient situations (because {IP1,M1}
2149 * is a different route from {IP1,M2}). Check
2150 * the sequence number and ignore this update
2153 if (CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_LOCAL
)) {
2154 tmp_seq
= n
->loc_seq
;
2157 tmp_seq
= n
->rem_seq
;
2160 if (seq
< tmp_seq
) {
2161 if (IS_ZEBRA_DEBUG_VXLAN
)
2163 "Ignore remote MACIP ADD VNI %u MAC %s%s%s as existing %s Neigh has higher seq %u",
2165 prefix_mac2str(&mac
->macaddr
,
2169 ipaddr2str(ipaddr
, buf1
,
2174 if (CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_LOCAL
)) {
2175 old_static
= zebra_evpn_neigh_is_static(n
);
2176 if (IS_ZEBRA_DEBUG_EVPN_MH_NEIGH
)
2178 "sync->remote neigh vni %u ip %s mac %s seq %d f0x%x",
2180 ipaddr2str(&n
->ip
, buf1
,
2182 prefix_mac2str(&n
->emac
, buf
,
2185 zebra_evpn_neigh_clear_sync_info(n
);
2186 if (IS_ZEBRA_NEIGH_ACTIVE(n
))
2187 zebra_evpn_mac_send_del_to_client(
2188 zevpn
->vni
, &mac
->macaddr
,
2189 mac
->flags
, false /*force*/);
2191 if (memcmp(&n
->emac
, &mac
->macaddr
,
2192 sizeof(struct ethaddr
))
2194 /* update neigh list for macs */
2196 zebra_evpn_mac_lookup(zevpn
, &n
->emac
);
2198 listnode_delete(old_mac
->neigh_list
, n
);
2200 zebra_evpn_deref_ip2mac(zevpn
, old_mac
);
2203 listnode_add_sort(mac
->neigh_list
, n
);
2204 memcpy(&n
->emac
, &mac
->macaddr
, ETH_ALEN
);
2206 /* Check Neigh's curent state is local
2207 * (this is the case where neigh/host has moved
2208 * from L->R) and check previous detction
2209 * started via local learning.
2211 * RFC-7432: A PE/VTEP that detects a MAC
2212 * mobilit event via local learning starts
2213 * an M-second timer.
2214 * VTEP-IP or seq. change along is not
2215 * considered for dup. detection.
2217 * Mobilty event scenario-B IP-MAC binding
2220 if ((!CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_REMOTE
))
2226 /* Set "remote" forwarding info. */
2227 UNSET_FLAG(n
->flags
, ZEBRA_NEIGH_ALL_LOCAL_FLAGS
);
2228 n
->r_vtep_ip
= vtep_ip
;
2229 SET_FLAG(n
->flags
, ZEBRA_NEIGH_REMOTE
);
2231 /* Set router flag (R-bit) to this Neighbor entry */
2232 if (CHECK_FLAG(flags
, ZEBRA_MACIP_TYPE_ROUTER_FLAG
))
2233 SET_FLAG(n
->flags
, ZEBRA_NEIGH_ROUTER_FLAG
);
2235 UNSET_FLAG(n
->flags
, ZEBRA_NEIGH_ROUTER_FLAG
);
2237 /* Check old or new MAC detected as duplicate,
2238 * inherit duplicate flag to this neigh.
2240 if (zebra_evpn_ip_inherit_dad_from_mac(zvrf
, old_mac
, mac
, n
)) {
2242 EC_ZEBRA_DUP_IP_INHERIT_DETECTED
,
2243 "VNI %u: MAC %s IP %s detected as duplicate during remote update, inherit duplicate from MAC",
2245 prefix_mac2str(&mac
->macaddr
, buf
, sizeof(buf
)),
2246 ipaddr2str(&n
->ip
, buf1
, sizeof(buf1
)));
2249 /* Check duplicate address detection for IP */
2250 zebra_evpn_dup_addr_detect_for_neigh(
2251 zvrf
, n
, n
->r_vtep_ip
, do_dad
, &is_dup_detect
, false);
2252 /* Install the entry. */
2254 zebra_evpn_rem_neigh_install(zevpn
, n
, old_static
);
2257 /* Update seq number. */
2261 int zebra_evpn_neigh_gw_macip_add(struct interface
*ifp
, zebra_evpn_t
*zevpn
,
2262 struct ipaddr
*ip
, zebra_mac_t
*mac
)
2265 char buf
[ETHER_ADDR_STRLEN
];
2266 char buf2
[INET6_ADDRSTRLEN
];
2270 n
= zebra_evpn_neigh_lookup(zevpn
, ip
);
2272 n
= zebra_evpn_neigh_add(zevpn
, ip
, &mac
->macaddr
, mac
, 0);
2275 EC_ZEBRA_MAC_ADD_FAILED
,
2276 "Failed to add neighbor %s MAC %s intf %s(%u) -> VNI %u",
2277 ipaddr2str(ip
, buf2
, sizeof(buf2
)),
2278 prefix_mac2str(&mac
->macaddr
, buf
, sizeof(buf
)),
2279 ifp
->name
, ifp
->ifindex
, zevpn
->vni
);
2284 /* Set "local" forwarding info. */
2285 SET_FLAG(n
->flags
, ZEBRA_NEIGH_LOCAL
);
2286 ZEBRA_NEIGH_SET_ACTIVE(n
);
2287 memcpy(&n
->emac
, &mac
->macaddr
, ETH_ALEN
);
2288 n
->ifindex
= ifp
->ifindex
;
2290 /* Only advertise in BGP if the knob is enabled */
2291 if (advertise_gw_macip_enabled(zevpn
)) {
2293 SET_FLAG(mac
->flags
, ZEBRA_MAC_DEF_GW
);
2294 SET_FLAG(n
->flags
, ZEBRA_NEIGH_DEF_GW
);
2295 /* Set Router flag (R-bit) */
2296 if (ip
->ipa_type
== IPADDR_V6
)
2297 SET_FLAG(n
->flags
, ZEBRA_NEIGH_ROUTER_FLAG
);
2299 if (IS_ZEBRA_DEBUG_VXLAN
)
2301 "SVI %s(%u) L2-VNI %u, sending GW MAC %s IP %s add to BGP with flags 0x%x",
2302 ifp
->name
, ifp
->ifindex
, zevpn
->vni
,
2303 prefix_mac2str(&mac
->macaddr
, buf
, sizeof(buf
)),
2304 ipaddr2str(ip
, buf2
, sizeof(buf2
)), n
->flags
);
2306 zebra_evpn_neigh_send_add_to_client(
2307 zevpn
->vni
, ip
, &n
->emac
, n
->mac
, n
->flags
, n
->loc_seq
);
2308 } else if (advertise_svi_macip_enabled(zevpn
)) {
2310 SET_FLAG(n
->flags
, ZEBRA_NEIGH_SVI_IP
);
2311 if (IS_ZEBRA_DEBUG_VXLAN
)
2313 "SVI %s(%u) L2-VNI %u, sending SVI MAC %s IP %s add to BGP with flags 0x%x",
2314 ifp
->name
, ifp
->ifindex
, zevpn
->vni
,
2315 prefix_mac2str(&mac
->macaddr
, buf
, sizeof(buf
)),
2316 ipaddr2str(ip
, buf2
, sizeof(buf2
)), n
->flags
);
2318 zebra_evpn_neigh_send_add_to_client(
2319 zevpn
->vni
, ip
, &n
->emac
, n
->mac
, n
->flags
, n
->loc_seq
);
2325 void zebra_evpn_neigh_remote_uninstall(zebra_evpn_t
*zevpn
,
2326 struct zebra_vrf
*zvrf
, zebra_neigh_t
*n
,
2327 zebra_mac_t
*mac
, struct ipaddr
*ipaddr
)
2329 char buf1
[INET6_ADDRSTRLEN
];
2331 if (zvrf
->dad_freeze
&& CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_DUPLICATE
)
2332 && CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_REMOTE
)
2333 && (memcmp(n
->emac
.octet
, mac
->macaddr
.octet
, ETH_ALEN
) == 0)) {
2334 struct interface
*vlan_if
;
2336 vlan_if
= zevpn_map_to_svi(zevpn
);
2337 if (IS_ZEBRA_DEBUG_VXLAN
)
2339 "%s: IP %s (flags 0x%x intf %s) is remote and duplicate, read kernel for local entry",
2341 ipaddr2str(ipaddr
, buf1
, sizeof(buf1
)),
2342 n
->flags
, vlan_if
? vlan_if
->name
: "Unknown");
2344 neigh_read_specific_ip(ipaddr
, vlan_if
);
2347 /* When the MAC changes for an IP, it is possible the
2348 * client may update the new MAC before trying to delete the
2349 * "old" neighbor (as these are two different MACIP routes).
2350 * Do the delete only if the MAC matches.
2352 if (!memcmp(n
->emac
.octet
, mac
->macaddr
.octet
, ETH_ALEN
)) {
2353 if (CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_LOCAL
)) {
2354 zebra_evpn_sync_neigh_del(n
);
2355 } else if (CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_REMOTE
)) {
2356 zebra_evpn_neigh_uninstall(zevpn
, n
);
2357 zebra_evpn_neigh_del(zevpn
, n
);
2358 zebra_evpn_deref_ip2mac(zevpn
, mac
);
2363 int zebra_evpn_neigh_del_ip(zebra_evpn_t
*zevpn
, struct ipaddr
*ip
)
2369 char buf
[INET6_ADDRSTRLEN
];
2370 char buf2
[ETHER_ADDR_STRLEN
];
2371 struct zebra_vrf
*zvrf
;
2373 /* If entry doesn't exist, nothing to do. */
2374 n
= zebra_evpn_neigh_lookup(zevpn
, ip
);
2378 zmac
= zebra_evpn_mac_lookup(zevpn
, &n
->emac
);
2380 if (IS_ZEBRA_DEBUG_VXLAN
)
2382 "Trying to del a neigh %s without a mac %s on VNI %u",
2383 ipaddr2str(ip
, buf
, sizeof(buf
)),
2384 prefix_mac2str(&n
->emac
, buf2
, sizeof(buf2
)),
2390 /* If it is a remote entry, the kernel has aged this out or someone has
2391 * deleted it, it needs to be re-installed as Quagga is the owner.
2393 if (CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_REMOTE
)) {
2394 zebra_evpn_rem_neigh_install(zevpn
, n
, false /*was_static*/);
2398 /* if this is a sync entry it cannot be dropped re-install it in
2401 old_bgp_ready
= zebra_evpn_neigh_is_ready_for_bgp(n
);
2402 if (zebra_evpn_neigh_is_static(n
)) {
2403 if (IS_ZEBRA_DEBUG_EVPN_MH_NEIGH
)
2404 zlog_debug("re-add sync neigh vni %u ip %s mac %s 0x%x",
2406 ipaddr2str(&n
->ip
, buf
, sizeof(buf
)),
2407 prefix_mac2str(&n
->emac
, buf2
, sizeof(buf2
)),
2410 if (!CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_LOCAL_INACTIVE
))
2411 SET_FLAG(n
->flags
, ZEBRA_NEIGH_LOCAL_INACTIVE
);
2412 /* inform-bgp about change in local-activity if any */
2413 new_bgp_ready
= zebra_evpn_neigh_is_ready_for_bgp(n
);
2414 zebra_evpn_neigh_send_add_del_to_client(n
, old_bgp_ready
,
2417 /* re-install the entry in the kernel */
2418 zebra_evpn_sync_neigh_dp_install(n
, false /* set_inactive */,
2419 false /* force_clear_static */,
2425 zvrf
= vrf_info_lookup(zevpn
->vxlan_if
->vrf_id
);
2427 zlog_debug("%s: VNI %u vrf lookup failed.", __func__
,
2432 /* In case of feeze action, if local neigh is in duplicate state,
2433 * Mark the Neigh as inactive before sending delete request to BGPd,
2434 * If BGPd has remote entry, it will re-install
2436 if (zvrf
->dad_freeze
&& CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_DUPLICATE
))
2437 ZEBRA_NEIGH_SET_INACTIVE(n
);
2439 /* Remove neighbor from BGP. */
2440 zebra_evpn_neigh_send_del_to_client(zevpn
->vni
, &n
->ip
, &n
->emac
,
2444 /* Delete this neighbor entry. */
2445 zebra_evpn_neigh_del(zevpn
, n
);
2447 /* see if the AUTO mac needs to be deleted */
2448 if (CHECK_FLAG(zmac
->flags
, ZEBRA_MAC_AUTO
)
2449 && !listcount(zmac
->neigh_list
))
2450 zebra_evpn_mac_del(zevpn
, zmac
);