]> git.proxmox.com Git - mirror_frr.git/blob - zebra/zebra_evpn_neigh.c
Merge pull request #11177 from opensourcerouting/fix/memset_memcpy
[mirror_frr.git] / zebra / zebra_evpn_neigh.c
1 /*
2 * Zebra EVPN Neighbor code
3 * Copyright (C) 2016, 2017 Cumulus Networks, Inc.
4 *
5 * This file is part of FRR.
6 *
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
10 * later version.
11 *
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.
16 *
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
20 * 02111-1307, USA.
21 */
22
23 #include <zebra.h>
24
25 #include "hash.h"
26 #include "interface.h"
27 #include "jhash.h"
28 #include "memory.h"
29 #include "prefix.h"
30 #include "vlan.h"
31 #include "json.h"
32
33 #include "zebra/zserv.h"
34 #include "zebra/debug.h"
35 #include "zebra/zebra_router.h"
36 #include "zebra/rt.h"
37 #include "zebra/zebra_errors.h"
38 #include "zebra/zebra_vrf.h"
39 #include "zebra/zebra_evpn.h"
40 #include "zebra/zebra_evpn_mh.h"
41 #include "zebra/zebra_evpn_neigh.h"
42 #include "zebra/zebra_evpn_mac.h"
43
44 DEFINE_MTYPE_STATIC(ZEBRA, NEIGH, "EVI Neighbor");
45
46 /*
47 * Make hash key for neighbors.
48 */
49 static unsigned int neigh_hash_keymake(const void *p)
50 {
51 const struct zebra_neigh *n = p;
52 const struct ipaddr *ip = &n->ip;
53
54 if (IS_IPADDR_V4(ip))
55 return jhash_1word(ip->ipaddr_v4.s_addr, 0);
56
57 return jhash2(ip->ipaddr_v6.s6_addr32,
58 array_size(ip->ipaddr_v6.s6_addr32), 0);
59 }
60
61 /*
62 * Compare two neighbor hash structures.
63 */
64 static bool neigh_cmp(const void *p1, const void *p2)
65 {
66 const struct zebra_neigh *n1 = p1;
67 const struct zebra_neigh *n2 = p2;
68
69 if (n1 == NULL && n2 == NULL)
70 return true;
71
72 if (n1 == NULL || n2 == NULL)
73 return false;
74
75 return ipaddr_cmp(&n1->ip, &n2->ip) == 0;
76 }
77
78 int neigh_list_cmp(void *p1, void *p2)
79 {
80 const struct zebra_neigh *n1 = p1;
81 const struct zebra_neigh *n2 = p2;
82
83 return ipaddr_cmp(&n1->ip, &n2->ip);
84 }
85
86 struct hash *zebra_neigh_db_create(const char *desc)
87 {
88 return hash_create_size(8, neigh_hash_keymake, neigh_cmp, desc);
89 }
90
91 uint32_t num_dup_detected_neighs(struct zebra_evpn *zevpn)
92 {
93 unsigned int i;
94 uint32_t num_neighs = 0;
95 struct hash *hash;
96 struct hash_bucket *hb;
97 struct zebra_neigh *nbr;
98
99 hash = zevpn->neigh_table;
100 if (!hash)
101 return num_neighs;
102 for (i = 0; i < hash->size; i++) {
103 for (hb = hash->index[i]; hb; hb = hb->next) {
104 nbr = (struct zebra_neigh *)hb->data;
105 if (CHECK_FLAG(nbr->flags, ZEBRA_NEIGH_DUPLICATE))
106 num_neighs++;
107 }
108 }
109
110 return num_neighs;
111 }
112
113 /*
114 * Helper function to determine maximum width of neighbor IP address for
115 * display - just because we're dealing with IPv6 addresses that can
116 * widely vary.
117 */
118 void zebra_evpn_find_neigh_addr_width(struct hash_bucket *bucket, void *ctxt)
119 {
120 struct zebra_neigh *n;
121 char buf[INET6_ADDRSTRLEN];
122 struct neigh_walk_ctx *wctx = ctxt;
123 int width;
124
125 n = (struct zebra_neigh *)bucket->data;
126
127 ipaddr2str(&n->ip, buf, sizeof(buf));
128 width = strlen(buf);
129 if (width > wctx->addr_width)
130 wctx->addr_width = width;
131 }
132
133 /*
134 * Count of remote neighbors referencing this MAC.
135 */
136 int remote_neigh_count(struct zebra_mac *zmac)
137 {
138 struct zebra_neigh *n = NULL;
139 struct listnode *node = NULL;
140 int count = 0;
141
142 for (ALL_LIST_ELEMENTS_RO(zmac->neigh_list, node, n)) {
143 if (CHECK_FLAG(n->flags, ZEBRA_NEIGH_REMOTE))
144 count++;
145 }
146
147 return count;
148 }
149
150 /*
151 * Install remote neighbor into the kernel.
152 */
153 int zebra_evpn_rem_neigh_install(struct zebra_evpn *zevpn,
154 struct zebra_neigh *n, bool was_static)
155 {
156 struct interface *vlan_if;
157 int flags;
158 int ret = 0;
159
160 if (!(n->flags & ZEBRA_NEIGH_REMOTE))
161 return 0;
162
163 vlan_if = zevpn_map_to_svi(zevpn);
164 if (!vlan_if)
165 return -1;
166
167 flags = DPLANE_NTF_EXT_LEARNED;
168 if (n->flags & ZEBRA_NEIGH_ROUTER_FLAG)
169 flags |= DPLANE_NTF_ROUTER;
170 ZEBRA_NEIGH_SET_ACTIVE(n);
171
172 dplane_rem_neigh_add(vlan_if, &n->ip, &n->emac, flags, was_static);
173
174 return ret;
175 }
176
177 /*
178 * Install neighbor hash entry - called upon access VLAN change.
179 */
180 void zebra_evpn_install_neigh_hash(struct hash_bucket *bucket, void *ctxt)
181 {
182 struct zebra_neigh *n;
183 struct neigh_walk_ctx *wctx = ctxt;
184
185 n = (struct zebra_neigh *)bucket->data;
186
187 if (CHECK_FLAG(n->flags, ZEBRA_NEIGH_REMOTE))
188 zebra_evpn_rem_neigh_install(wctx->zevpn, n,
189 false /*was_static*/);
190 }
191
192 /*
193 * Callback to allocate neighbor hash entry.
194 */
195 static void *zebra_evpn_neigh_alloc(void *p)
196 {
197 const struct zebra_neigh *tmp_n = p;
198 struct zebra_neigh *n;
199
200 n = XCALLOC(MTYPE_NEIGH, sizeof(struct zebra_neigh));
201 *n = *tmp_n;
202
203 return ((void *)n);
204 }
205
206 static void zebra_evpn_local_neigh_ref_mac(struct zebra_neigh *n,
207 const struct ethaddr *macaddr,
208 struct zebra_mac *mac,
209 bool send_mac_update)
210 {
211 bool old_static;
212 bool new_static;
213
214 memcpy(&n->emac, macaddr, ETH_ALEN);
215 n->mac = mac;
216
217 /* Link to new MAC */
218 if (!mac)
219 return;
220
221 listnode_add_sort(mac->neigh_list, n);
222 if (n->flags & ZEBRA_NEIGH_ALL_PEER_FLAGS) {
223 old_static = zebra_evpn_mac_is_static(mac);
224 ++mac->sync_neigh_cnt;
225 new_static = zebra_evpn_mac_is_static(mac);
226 if (IS_ZEBRA_DEBUG_EVPN_MH_NEIGH)
227 zlog_debug(
228 "sync-neigh ref mac vni %u ip %pIA mac %pEA ref %d",
229 n->zevpn->vni, &n->ip, &n->emac,
230 mac->sync_neigh_cnt);
231 if ((old_static != new_static) && send_mac_update)
232 /* program the local mac in the kernel */
233 zebra_evpn_sync_mac_dp_install(
234 mac, false /*set_inactive*/,
235 false /*force_clear_static*/, __func__);
236 }
237 }
238
239 /* sync-path that is active on an ES peer */
240 static void zebra_evpn_sync_neigh_dp_install(struct zebra_neigh *n,
241 bool set_inactive,
242 bool force_clear_static,
243 const char *caller)
244 {
245 struct zebra_ns *zns;
246 struct interface *ifp;
247 bool set_static;
248 bool set_router;
249
250 zns = zebra_ns_lookup(NS_DEFAULT);
251 ifp = if_lookup_by_index_per_ns(zns, n->ifindex);
252 if (!ifp) {
253 if (IS_ZEBRA_DEBUG_EVPN_MH_NEIGH)
254 zlog_debug(
255 "%s: dp-install sync-neigh vni %u ip %pIA mac %pEA if %d f 0x%x skipped",
256 caller, n->zevpn->vni, &n->ip, &n->emac,
257 n->ifindex, n->flags);
258 return;
259 }
260
261 if (force_clear_static)
262 set_static = false;
263 else
264 set_static = zebra_evpn_neigh_is_static(n);
265
266 set_router = !!CHECK_FLAG(n->flags, ZEBRA_NEIGH_ROUTER_FLAG);
267
268 /* XXX - this will change post integration with the new kernel */
269 if (CHECK_FLAG(n->flags, ZEBRA_NEIGH_LOCAL_INACTIVE))
270 set_inactive = true;
271
272 if (IS_ZEBRA_DEBUG_EVPN_MH_NEIGH)
273 zlog_debug(
274 "%s: dp-install sync-neigh vni %u ip %pIA mac %pEA if %s(%d) f 0x%x%s%s%s",
275 caller, n->zevpn->vni, &n->ip, &n->emac,
276 ifp->name, n->ifindex, n->flags,
277 set_router ? " router" : "",
278 set_static ? " static" : "",
279 set_inactive ? " inactive" : "");
280 dplane_local_neigh_add(ifp, &n->ip, &n->emac, set_router, set_static,
281 set_inactive);
282 }
283
284 /*
285 * Inform BGP about local neighbor addition.
286 */
287 int zebra_evpn_neigh_send_add_to_client(vni_t vni, const struct ipaddr *ip,
288 const struct ethaddr *macaddr,
289 struct zebra_mac *zmac,
290 uint32_t neigh_flags, uint32_t seq)
291 {
292 uint8_t flags = 0;
293
294 if (CHECK_FLAG(neigh_flags, ZEBRA_NEIGH_LOCAL_INACTIVE)) {
295 /* host reachability has not been verified locally */
296
297 /* if no ES peer is claiming reachability we can't advertise
298 * the entry
299 */
300 if (!CHECK_FLAG(neigh_flags, ZEBRA_NEIGH_ES_PEER_ACTIVE))
301 return 0;
302
303 /* ES peers are claiming reachability; we will
304 * advertise the entry but with a proxy flag
305 */
306 SET_FLAG(flags, ZEBRA_MACIP_TYPE_PROXY_ADVERT);
307 }
308
309 if (CHECK_FLAG(neigh_flags, ZEBRA_NEIGH_DEF_GW))
310 SET_FLAG(flags, ZEBRA_MACIP_TYPE_GW);
311 /* Set router flag (R-bit) based on local neigh entry add */
312 if (CHECK_FLAG(neigh_flags, ZEBRA_NEIGH_ROUTER_FLAG))
313 SET_FLAG(flags, ZEBRA_MACIP_TYPE_ROUTER_FLAG);
314 if (CHECK_FLAG(neigh_flags, ZEBRA_NEIGH_SVI_IP))
315 SET_FLAG(flags, ZEBRA_MACIP_TYPE_SVI_IP);
316
317 return zebra_evpn_macip_send_msg_to_client(vni, macaddr, ip, flags, seq,
318 ZEBRA_NEIGH_ACTIVE, zmac->es,
319 ZEBRA_MACIP_ADD);
320 }
321
322 /*
323 * Inform BGP about local neighbor deletion.
324 */
325 int zebra_evpn_neigh_send_del_to_client(vni_t vni, struct ipaddr *ip,
326 struct ethaddr *macaddr, uint32_t flags,
327 int state, bool force)
328 {
329 if (!force) {
330 if (CHECK_FLAG(flags, ZEBRA_NEIGH_LOCAL_INACTIVE)
331 && !CHECK_FLAG(flags, ZEBRA_NEIGH_ES_PEER_ACTIVE))
332 /* the neigh was not advertised - nothing to delete */
333 return 0;
334 }
335
336 return zebra_evpn_macip_send_msg_to_client(
337 vni, macaddr, ip, flags, 0, state, NULL, ZEBRA_MACIP_DEL);
338 }
339
340 static void zebra_evpn_neigh_send_add_del_to_client(struct zebra_neigh *n,
341 bool old_bgp_ready,
342 bool new_bgp_ready)
343 {
344 if (new_bgp_ready)
345 zebra_evpn_neigh_send_add_to_client(n->zevpn->vni, &n->ip,
346 &n->emac, n->mac, n->flags,
347 n->loc_seq);
348 else if (old_bgp_ready)
349 zebra_evpn_neigh_send_del_to_client(n->zevpn->vni, &n->ip,
350 &n->emac, n->flags,
351 n->state, true /*force*/);
352 }
353
354 /* if the static flag associated with the neigh changes we need
355 * to update the sync-neigh references against the MAC
356 * and inform the dataplane about the static flag changes.
357 */
358 void zebra_evpn_sync_neigh_static_chg(struct zebra_neigh *n, bool old_n_static,
359 bool new_n_static, bool defer_n_dp,
360 bool defer_mac_dp, const char *caller)
361 {
362 struct zebra_mac *mac = n->mac;
363 bool old_mac_static;
364 bool new_mac_static;
365
366 if (old_n_static == new_n_static)
367 return;
368
369 /* update the neigh sync references in the dataplane. if
370 * the neigh is in the middle of updates the caller can
371 * request for a defer
372 */
373 if (!defer_n_dp)
374 zebra_evpn_sync_neigh_dp_install(n, false /* set_inactive */,
375 false /* force_clear_static */,
376 __func__);
377
378 if (!mac)
379 return;
380
381 /* update the mac sync ref cnt */
382 old_mac_static = zebra_evpn_mac_is_static(mac);
383 if (new_n_static) {
384 ++mac->sync_neigh_cnt;
385 } else if (old_n_static) {
386 if (mac->sync_neigh_cnt)
387 --mac->sync_neigh_cnt;
388 }
389 new_mac_static = zebra_evpn_mac_is_static(mac);
390
391 /* update the mac sync references in the dataplane */
392 if ((old_mac_static != new_mac_static) && !defer_mac_dp)
393 zebra_evpn_sync_mac_dp_install(mac, false /* set_inactive */,
394 false /* force_clear_static */,
395 __func__);
396
397 if (IS_ZEBRA_DEBUG_EVPN_MH_NEIGH)
398 zlog_debug(
399 "sync-neigh ref-chg vni %u ip %pIA mac %pEA f 0x%x %d%s%s%s%s by %s",
400 n->zevpn->vni, &n->ip, &n->emac, n->flags,
401 mac->sync_neigh_cnt,
402 old_n_static ? " old_n_static" : "",
403 new_n_static ? " new_n_static" : "",
404 old_mac_static ? " old_mac_static" : "",
405 new_mac_static ? " new_mac_static" : "", caller);
406 }
407
408 /* Neigh hold timer is used to age out peer-active flag.
409 *
410 * During this wait time we expect the dataplane component or an
411 * external neighmgr daemon to probe existing hosts to independently
412 * establish their presence on the ES.
413 */
414 static void zebra_evpn_neigh_hold_exp_cb(struct thread *t)
415 {
416 struct zebra_neigh *n;
417 bool old_bgp_ready;
418 bool new_bgp_ready;
419 bool old_n_static;
420 bool new_n_static;
421
422 n = THREAD_ARG(t);
423 /* the purpose of the hold timer is to age out the peer-active
424 * flag
425 */
426 if (!CHECK_FLAG(n->flags, ZEBRA_NEIGH_ES_PEER_ACTIVE))
427 return;
428
429 old_bgp_ready = zebra_evpn_neigh_is_ready_for_bgp(n);
430 old_n_static = zebra_evpn_neigh_is_static(n);
431 UNSET_FLAG(n->flags, ZEBRA_NEIGH_ES_PEER_ACTIVE);
432 new_bgp_ready = zebra_evpn_neigh_is_ready_for_bgp(n);
433 new_n_static = zebra_evpn_neigh_is_static(n);
434
435 if (IS_ZEBRA_DEBUG_EVPN_MH_NEIGH)
436 zlog_debug("sync-neigh vni %u ip %pIA mac %pEA 0x%x hold expired",
437 n->zevpn->vni, &n->ip, &n->emac, n->flags);
438
439 /* re-program the local neigh in the dataplane if the neigh is no
440 * longer static
441 */
442 if (old_n_static != new_n_static)
443 zebra_evpn_sync_neigh_static_chg(
444 n, old_n_static, new_n_static, false /*defer_n_dp*/,
445 false /*defer_mac_dp*/, __func__);
446
447 /* inform bgp if needed */
448 if (old_bgp_ready != new_bgp_ready)
449 zebra_evpn_neigh_send_add_del_to_client(n, old_bgp_ready,
450 new_bgp_ready);
451 }
452
453 static inline void zebra_evpn_neigh_start_hold_timer(struct zebra_neigh *n)
454 {
455 if (n->hold_timer)
456 return;
457
458 if (IS_ZEBRA_DEBUG_EVPN_MH_NEIGH)
459 zlog_debug("sync-neigh vni %u ip %pIA mac %pEA 0x%x hold start",
460 n->zevpn->vni, &n->ip, &n->emac, n->flags);
461 thread_add_timer(zrouter.master, zebra_evpn_neigh_hold_exp_cb, n,
462 zmh_info->neigh_hold_time, &n->hold_timer);
463 }
464
465 static void zebra_evpn_local_neigh_deref_mac(struct zebra_neigh *n,
466 bool send_mac_update)
467 {
468 struct zebra_mac *mac = n->mac;
469 struct zebra_evpn *zevpn = n->zevpn;
470 bool old_static;
471 bool new_static;
472
473 n->mac = NULL;
474 if (!mac)
475 return;
476
477 if ((n->flags & ZEBRA_NEIGH_ALL_PEER_FLAGS) && mac->sync_neigh_cnt) {
478 old_static = zebra_evpn_mac_is_static(mac);
479 --mac->sync_neigh_cnt;
480 new_static = zebra_evpn_mac_is_static(mac);
481 if (IS_ZEBRA_DEBUG_EVPN_MH_NEIGH)
482 zlog_debug(
483 "sync-neigh deref mac vni %u ip %pIA mac %pEA ref %d",
484 n->zevpn->vni, &n->ip, &n->emac,
485 mac->sync_neigh_cnt);
486 if ((old_static != new_static) && send_mac_update)
487 /* program the local mac in the kernel */
488 zebra_evpn_sync_mac_dp_install(
489 mac, false /* set_inactive */,
490 false /* force_clear_static */, __func__);
491 }
492
493 listnode_delete(mac->neigh_list, n);
494 zebra_evpn_deref_ip2mac(zevpn, mac);
495 }
496
497 bool zebra_evpn_neigh_is_bgp_seq_ok(struct zebra_evpn *zevpn,
498 struct zebra_neigh *n,
499 const struct ethaddr *macaddr, uint32_t seq,
500 bool sync)
501 {
502 uint32_t tmp_seq;
503 const char *n_type;
504
505 if (CHECK_FLAG(n->flags, ZEBRA_NEIGH_LOCAL)) {
506 tmp_seq = n->loc_seq;
507 n_type = "local";
508 } else {
509 tmp_seq = n->rem_seq;
510 n_type = "remote";
511 }
512
513 if (seq < tmp_seq) {
514 /* if the neigh was never advertised to bgp we must accept
515 * whatever sequence number bgp sends
516 * XXX - check with Vivek
517 */
518 if (CHECK_FLAG(n->flags, ZEBRA_NEIGH_LOCAL)
519 && !zebra_evpn_neigh_is_ready_for_bgp(n)) {
520 if (IS_ZEBRA_DEBUG_EVPN_MH_NEIGH
521 || IS_ZEBRA_DEBUG_VXLAN)
522 zlog_debug(
523 "%s-macip accept vni %u %s mac %pEA IP %pIA lower seq %u f 0x%x",
524 sync ? "sync" : "remote", zevpn->vni,
525 n_type, macaddr, &n->ip,
526 tmp_seq, n->flags);
527 return true;
528 }
529
530 if (IS_ZEBRA_DEBUG_EVPN_MH_NEIGH || IS_ZEBRA_DEBUG_VXLAN)
531 zlog_debug(
532 "%s-macip ignore vni %u %s mac %pEA IP %pIA as existing has higher seq %u f 0x%x",
533 sync ? "sync" : "remote", zevpn->vni, n_type,
534 macaddr, &n->ip, tmp_seq, n->flags);
535 return false;
536 }
537
538 return true;
539 }
540
541 /*
542 * Add neighbor entry.
543 */
544 static struct zebra_neigh *zebra_evpn_neigh_add(struct zebra_evpn *zevpn,
545 const struct ipaddr *ip,
546 const struct ethaddr *mac,
547 struct zebra_mac *zmac,
548 uint32_t n_flags)
549 {
550 struct zebra_neigh tmp_n;
551 struct zebra_neigh *n = NULL;
552
553 memset(&tmp_n, 0, sizeof(tmp_n));
554 memcpy(&tmp_n.ip, ip, sizeof(struct ipaddr));
555 n = hash_get(zevpn->neigh_table, &tmp_n, zebra_evpn_neigh_alloc);
556
557 n->state = ZEBRA_NEIGH_INACTIVE;
558 n->zevpn = zevpn;
559 n->dad_ip_auto_recovery_timer = NULL;
560 n->flags = n_flags;
561 n->uptime = monotime(NULL);
562
563 if (!zmac)
564 zmac = zebra_evpn_mac_lookup(zevpn, mac);
565 zebra_evpn_local_neigh_ref_mac(n, mac, zmac,
566 false /* send_mac_update */);
567
568 return n;
569 }
570
571 /*
572 * Delete neighbor entry.
573 */
574 int zebra_evpn_neigh_del(struct zebra_evpn *zevpn, struct zebra_neigh *n)
575 {
576 struct zebra_neigh *tmp_n;
577
578 if (n->mac)
579 listnode_delete(n->mac->neigh_list, n);
580
581 /* Cancel auto recovery */
582 THREAD_OFF(n->dad_ip_auto_recovery_timer);
583
584 /* Cancel proxy hold timer */
585 zebra_evpn_neigh_stop_hold_timer(n);
586
587 /* Free the VNI hash entry and allocated memory. */
588 tmp_n = hash_release(zevpn->neigh_table, n);
589 XFREE(MTYPE_NEIGH, tmp_n);
590
591 return 0;
592 }
593
594 void zebra_evpn_sync_neigh_del(struct zebra_neigh *n)
595 {
596 bool old_n_static;
597 bool new_n_static;
598
599 if (IS_ZEBRA_DEBUG_EVPN_MH_NEIGH)
600 zlog_debug("sync-neigh del vni %u ip %pIA mac %pEA f 0x%x",
601 n->zevpn->vni, &n->ip, &n->emac, n->flags);
602
603 old_n_static = zebra_evpn_neigh_is_static(n);
604 UNSET_FLAG(n->flags, ZEBRA_NEIGH_ES_PEER_PROXY);
605 if (CHECK_FLAG(n->flags, ZEBRA_NEIGH_ES_PEER_ACTIVE))
606 zebra_evpn_neigh_start_hold_timer(n);
607 new_n_static = zebra_evpn_neigh_is_static(n);
608
609 if (old_n_static != new_n_static)
610 zebra_evpn_sync_neigh_static_chg(
611 n, old_n_static, new_n_static, false /*defer-dp*/,
612 false /*defer_mac_dp*/, __func__);
613 }
614
615 struct zebra_neigh *zebra_evpn_proc_sync_neigh_update(
616 struct zebra_evpn *zevpn, struct zebra_neigh *n, uint16_t ipa_len,
617 const struct ipaddr *ipaddr, uint8_t flags, uint32_t seq,
618 const esi_t *esi, struct sync_mac_ip_ctx *ctx)
619 {
620 struct interface *ifp = NULL;
621 bool is_router;
622 struct zebra_mac *mac = ctx->mac;
623 uint32_t tmp_seq;
624 bool old_router = false;
625 bool old_bgp_ready = false;
626 bool new_bgp_ready;
627 bool inform_dataplane = false;
628 bool inform_bgp = false;
629 bool old_mac_static;
630 bool new_mac_static;
631 bool set_dp_inactive = false;
632 bool created;
633 ifindex_t ifindex = 0;
634
635 /* locate l3-svi */
636 ifp = zevpn_map_to_svi(zevpn);
637 if (ifp)
638 ifindex = ifp->ifindex;
639
640 is_router = !!CHECK_FLAG(flags, ZEBRA_MACIP_TYPE_ROUTER_FLAG);
641 old_mac_static = zebra_evpn_mac_is_static(mac);
642
643 if (!n) {
644 uint32_t n_flags = 0;
645
646 /* New neighbor - create */
647 SET_FLAG(n_flags, ZEBRA_NEIGH_LOCAL);
648 if (CHECK_FLAG(flags, ZEBRA_MACIP_TYPE_PROXY_ADVERT))
649 SET_FLAG(n_flags, ZEBRA_NEIGH_ES_PEER_PROXY);
650 else
651 SET_FLAG(n_flags, ZEBRA_NEIGH_ES_PEER_ACTIVE);
652 SET_FLAG(n_flags, ZEBRA_NEIGH_LOCAL_INACTIVE);
653
654 n = zebra_evpn_neigh_add(zevpn, ipaddr, &mac->macaddr, mac,
655 n_flags);
656 n->ifindex = ifindex;
657 ZEBRA_NEIGH_SET_ACTIVE(n);
658
659 created = true;
660 inform_dataplane = true;
661 inform_bgp = true;
662 set_dp_inactive = true;
663 } else {
664 bool mac_change;
665 uint32_t old_flags = n->flags;
666 bool old_n_static;
667 bool new_n_static;
668
669 created = false;
670 old_n_static = zebra_evpn_neigh_is_static(n);
671 old_bgp_ready = zebra_evpn_neigh_is_ready_for_bgp(n);
672 old_router = !!CHECK_FLAG(n->flags, ZEBRA_NEIGH_ROUTER_FLAG);
673
674 mac_change = !!memcmp(&n->emac, &mac->macaddr, ETH_ALEN);
675
676 /* deref and clear old info */
677 if (mac_change) {
678 if (old_bgp_ready) {
679 zebra_evpn_neigh_send_del_to_client(
680 zevpn->vni, &n->ip, &n->emac, n->flags,
681 n->state, false /*force*/);
682 old_bgp_ready = false;
683 }
684 zebra_evpn_local_neigh_deref_mac(n,
685 false /*send_mac_update*/);
686 }
687 /* clear old fwd info */
688 n->rem_seq = 0;
689 n->r_vtep_ip.s_addr = 0;
690
691 /* setup new flags */
692 n->flags = 0;
693 SET_FLAG(n->flags, ZEBRA_NEIGH_LOCAL);
694 /* retain activity flag if the neigh was
695 * previously local
696 */
697 if (old_flags & ZEBRA_NEIGH_LOCAL) {
698 n->flags |= (old_flags & ZEBRA_NEIGH_LOCAL_INACTIVE);
699 } else {
700 inform_dataplane = true;
701 set_dp_inactive = true;
702 n->flags |= ZEBRA_NEIGH_LOCAL_INACTIVE;
703 }
704
705 if (CHECK_FLAG(flags, ZEBRA_MACIP_TYPE_PROXY_ADVERT))
706 SET_FLAG(n->flags, ZEBRA_NEIGH_ES_PEER_PROXY);
707 else
708 SET_FLAG(n->flags, ZEBRA_NEIGH_ES_PEER_ACTIVE);
709
710 if (CHECK_FLAG(flags, ZEBRA_MACIP_TYPE_PROXY_ADVERT)) {
711 SET_FLAG(n->flags, ZEBRA_NEIGH_ES_PEER_PROXY);
712 /* if the neigh was peer-active previously we
713 * need to keep the flag and start the
714 * holdtimer on it. the peer-active flag is
715 * cleared on holdtimer expiry.
716 */
717 if (CHECK_FLAG(old_flags, ZEBRA_NEIGH_ES_PEER_ACTIVE)) {
718 SET_FLAG(n->flags, ZEBRA_NEIGH_ES_PEER_ACTIVE);
719 zebra_evpn_neigh_start_hold_timer(n);
720 }
721 } else {
722 SET_FLAG(n->flags, ZEBRA_NEIGH_ES_PEER_ACTIVE);
723 /* stop hold timer if a peer has verified
724 * reachability
725 */
726 zebra_evpn_neigh_stop_hold_timer(n);
727 }
728 ZEBRA_NEIGH_SET_ACTIVE(n);
729
730 if (IS_ZEBRA_DEBUG_EVPN_MH_NEIGH && (old_flags != n->flags))
731 zlog_debug(
732 "sync-neigh vni %u ip %pIA mac %pEA old_f 0x%x new_f 0x%x",
733 n->zevpn->vni, &n->ip, &n->emac,
734 old_flags, n->flags);
735
736 new_n_static = zebra_evpn_neigh_is_static(n);
737 if (mac_change) {
738 set_dp_inactive = true;
739 n->flags |= ZEBRA_NEIGH_LOCAL_INACTIVE;
740 inform_dataplane = true;
741 zebra_evpn_local_neigh_ref_mac(
742 n, &mac->macaddr, mac,
743 false /*send_mac_update*/);
744 } else if (old_n_static != new_n_static) {
745 inform_dataplane = true;
746 /* if static flags have changed without a mac change
747 * we need to create the correct sync-refs against
748 * the existing mac
749 */
750 zebra_evpn_sync_neigh_static_chg(
751 n, old_n_static, new_n_static,
752 true /*defer_dp*/, true /*defer_mac_dp*/,
753 __func__);
754 }
755
756 /* Update the forwarding info. */
757 if (n->ifindex != ifindex) {
758 n->ifindex = ifindex;
759 inform_dataplane = true;
760 }
761
762 n->uptime = monotime(NULL);
763 }
764
765 /* update the neigh seq. we don't bother with the mac seq as
766 * sync_mac_update already took care of that
767 */
768 tmp_seq = MAX(n->loc_seq, seq);
769 if (tmp_seq != n->loc_seq) {
770 n->loc_seq = tmp_seq;
771 inform_bgp = true;
772 }
773
774 /* Mark Router flag (R-bit) */
775 if (is_router)
776 SET_FLAG(n->flags, ZEBRA_NEIGH_ROUTER_FLAG);
777 else
778 UNSET_FLAG(n->flags, ZEBRA_NEIGH_ROUTER_FLAG);
779
780 if (old_router != is_router)
781 inform_dataplane = true;
782
783 new_bgp_ready = zebra_evpn_neigh_is_ready_for_bgp(n);
784 if (old_bgp_ready != new_bgp_ready)
785 inform_bgp = true;
786
787 new_mac_static = zebra_evpn_mac_is_static(mac);
788 if ((old_mac_static != new_mac_static) || ctx->mac_dp_update_deferred)
789 zebra_evpn_sync_mac_dp_install(mac, ctx->mac_inactive,
790 false /* force_clear_static */,
791 __func__);
792
793 if (IS_ZEBRA_DEBUG_EVPN_MH_NEIGH)
794 zlog_debug(
795 "sync-neigh %s vni %u ip %pIA mac %pEA if %s(%d) seq %d f 0x%x%s%s",
796 created ? "created" : "updated", n->zevpn->vni,
797 &n->ip, &n->emac,
798 ifp ? ifp->name : "", ifindex, n->loc_seq, n->flags,
799 inform_bgp ? " inform_bgp" : "",
800 inform_dataplane ? " inform_dp" : "");
801
802 if (inform_dataplane)
803 zebra_evpn_sync_neigh_dp_install(n, set_dp_inactive,
804 false /* force_clear_static */,
805 __func__);
806
807 if (inform_bgp)
808 zebra_evpn_neigh_send_add_del_to_client(n, old_bgp_ready,
809 new_bgp_ready);
810
811 return n;
812 }
813
814 /*
815 * Uninstall remote neighbor from the kernel.
816 */
817 static int zebra_evpn_neigh_uninstall(struct zebra_evpn *zevpn,
818 struct zebra_neigh *n)
819 {
820 struct interface *vlan_if;
821
822 if (!(n->flags & ZEBRA_NEIGH_REMOTE))
823 return 0;
824
825 vlan_if = zevpn_map_to_svi(zevpn);
826 if (!vlan_if)
827 return -1;
828
829 ZEBRA_NEIGH_SET_INACTIVE(n);
830 n->loc_seq = 0;
831
832 dplane_rem_neigh_delete(vlan_if, &n->ip);
833
834 return 0;
835 }
836
837 /*
838 * Free neighbor hash entry (callback)
839 */
840 static void zebra_evpn_neigh_del_hash_entry(struct hash_bucket *bucket,
841 void *arg)
842 {
843 struct neigh_walk_ctx *wctx = arg;
844 struct zebra_neigh *n = bucket->data;
845
846 if (((wctx->flags & DEL_LOCAL_NEIGH) && (n->flags & ZEBRA_NEIGH_LOCAL))
847 || ((wctx->flags & DEL_REMOTE_NEIGH)
848 && (n->flags & ZEBRA_NEIGH_REMOTE))
849 || ((wctx->flags & DEL_REMOTE_NEIGH_FROM_VTEP)
850 && (n->flags & ZEBRA_NEIGH_REMOTE)
851 && IPV4_ADDR_SAME(&n->r_vtep_ip, &wctx->r_vtep_ip))) {
852 if (wctx->upd_client && (n->flags & ZEBRA_NEIGH_LOCAL))
853 zebra_evpn_neigh_send_del_to_client(
854 wctx->zevpn->vni, &n->ip, &n->emac, n->flags,
855 n->state, false /*force*/);
856
857 if (wctx->uninstall) {
858 if (zebra_evpn_neigh_is_static(n))
859 zebra_evpn_sync_neigh_dp_install(
860 n, false /* set_inactive */,
861 true /* force_clear_static */,
862 __func__);
863 if ((n->flags & ZEBRA_NEIGH_REMOTE))
864 zebra_evpn_neigh_uninstall(wctx->zevpn, n);
865 }
866
867 zebra_evpn_neigh_del(wctx->zevpn, n);
868 }
869
870 return;
871 }
872
873 /*
874 * Delete all neighbor entries for this EVPN.
875 */
876 void zebra_evpn_neigh_del_all(struct zebra_evpn *zevpn, int uninstall,
877 int upd_client, uint32_t flags)
878 {
879 struct neigh_walk_ctx wctx;
880
881 if (!zevpn->neigh_table)
882 return;
883
884 memset(&wctx, 0, sizeof(wctx));
885 wctx.zevpn = zevpn;
886 wctx.uninstall = uninstall;
887 wctx.upd_client = upd_client;
888 wctx.flags = flags;
889
890 hash_iterate(zevpn->neigh_table, zebra_evpn_neigh_del_hash_entry,
891 &wctx);
892 }
893
894 /*
895 * Look up neighbor hash entry.
896 */
897 struct zebra_neigh *zebra_evpn_neigh_lookup(struct zebra_evpn *zevpn,
898 const struct ipaddr *ip)
899 {
900 struct zebra_neigh tmp;
901 struct zebra_neigh *n;
902
903 memset(&tmp, 0, sizeof(tmp));
904 memcpy(&tmp.ip, ip, sizeof(struct ipaddr));
905 n = hash_lookup(zevpn->neigh_table, &tmp);
906
907 return n;
908 }
909
910 /*
911 * Process all neighbors associated with a MAC upon the MAC being learnt
912 * locally or undergoing any other change (such as sequence number).
913 */
914 void zebra_evpn_process_neigh_on_local_mac_change(struct zebra_evpn *zevpn,
915 struct zebra_mac *zmac,
916 bool seq_change,
917 bool es_change)
918 {
919 struct zebra_neigh *n = NULL;
920 struct listnode *node = NULL;
921 struct zebra_vrf *zvrf = NULL;
922
923 zvrf = zevpn->vxlan_if->vrf->info;
924
925 if (IS_ZEBRA_DEBUG_VXLAN)
926 zlog_debug("Processing neighbors on local MAC %pEA %s, VNI %u",
927 &zmac->macaddr, seq_change ? "CHANGE" : "ADD",
928 zevpn->vni);
929
930 /* Walk all neighbors and mark any inactive local neighbors as
931 * active and/or update sequence number upon a move, and inform BGP.
932 * The action for remote neighbors is TBD.
933 * NOTE: We can't simply uninstall remote neighbors as the kernel may
934 * accidentally end up deleting a just-learnt local neighbor.
935 */
936 for (ALL_LIST_ELEMENTS_RO(zmac->neigh_list, node, n)) {
937 if (CHECK_FLAG(n->flags, ZEBRA_NEIGH_LOCAL)) {
938 if (IS_ZEBRA_NEIGH_INACTIVE(n) || seq_change
939 || es_change) {
940 ZEBRA_NEIGH_SET_ACTIVE(n);
941 n->loc_seq = zmac->loc_seq;
942 if (!(zebra_evpn_do_dup_addr_detect(zvrf)
943 && zvrf->dad_freeze
944 && !!CHECK_FLAG(n->flags,
945 ZEBRA_NEIGH_DUPLICATE)))
946 zebra_evpn_neigh_send_add_to_client(
947 zevpn->vni, &n->ip, &n->emac,
948 n->mac, n->flags, n->loc_seq);
949 }
950 }
951 }
952 }
953
954 /*
955 * Process all neighbors associated with a local MAC upon the MAC being
956 * deleted.
957 */
958 void zebra_evpn_process_neigh_on_local_mac_del(struct zebra_evpn *zevpn,
959 struct zebra_mac *zmac)
960 {
961 struct zebra_neigh *n = NULL;
962 struct listnode *node = NULL;
963
964 if (IS_ZEBRA_DEBUG_VXLAN)
965 zlog_debug("Processing neighbors on local MAC %pEA DEL, VNI %u",
966 &zmac->macaddr, zevpn->vni);
967
968 /* Walk all local neighbors and mark as inactive and inform
969 * BGP, if needed.
970 * TBD: There is currently no handling for remote neighbors. We
971 * don't expect them to exist, if they do, do we install the MAC
972 * as a remote MAC and the neighbor as remote?
973 */
974 for (ALL_LIST_ELEMENTS_RO(zmac->neigh_list, node, n)) {
975 if (CHECK_FLAG(n->flags, ZEBRA_NEIGH_LOCAL)) {
976 if (IS_ZEBRA_NEIGH_ACTIVE(n)) {
977 ZEBRA_NEIGH_SET_INACTIVE(n);
978 n->loc_seq = 0;
979 zebra_evpn_neigh_send_del_to_client(
980 zevpn->vni, &n->ip, &n->emac, n->flags,
981 ZEBRA_NEIGH_ACTIVE, false /*force*/);
982 }
983 }
984 }
985 }
986
987 /*
988 * Process all neighbors associated with a MAC upon the MAC being remotely
989 * learnt.
990 */
991 void zebra_evpn_process_neigh_on_remote_mac_add(struct zebra_evpn *zevpn,
992 struct zebra_mac *zmac)
993 {
994 struct zebra_neigh *n = NULL;
995 struct listnode *node = NULL;
996
997 if (IS_ZEBRA_DEBUG_VXLAN)
998 zlog_debug("Processing neighbors on remote MAC %pEA ADD, VNI %u",
999 &zmac->macaddr, zevpn->vni);
1000
1001 /* Walk all local neighbors and mark as inactive and inform
1002 * BGP, if needed.
1003 */
1004 for (ALL_LIST_ELEMENTS_RO(zmac->neigh_list, node, n)) {
1005 if (CHECK_FLAG(n->flags, ZEBRA_NEIGH_LOCAL)) {
1006 if (IS_ZEBRA_NEIGH_ACTIVE(n)) {
1007 ZEBRA_NEIGH_SET_INACTIVE(n);
1008 n->loc_seq = 0;
1009 zebra_evpn_neigh_send_del_to_client(
1010 zevpn->vni, &n->ip, &n->emac, n->flags,
1011 ZEBRA_NEIGH_ACTIVE, false /* force */);
1012 }
1013 }
1014 }
1015 }
1016
1017 /*
1018 * Process all neighbors associated with a remote MAC upon the MAC being
1019 * deleted.
1020 */
1021 void zebra_evpn_process_neigh_on_remote_mac_del(struct zebra_evpn *zevpn,
1022 struct zebra_mac *zmac)
1023 {
1024 /* NOTE: Currently a NO-OP. */
1025 }
1026
1027 static inline void zebra_evpn_local_neigh_update_log(
1028 const char *pfx, struct zebra_neigh *n, bool is_router,
1029 bool local_inactive, bool old_bgp_ready, bool new_bgp_ready,
1030 bool inform_dataplane, bool inform_bgp, const char *sfx)
1031 {
1032 if (!IS_ZEBRA_DEBUG_EVPN_MH_NEIGH)
1033 return;
1034
1035 zlog_debug("%s neigh vni %u ip %pIA mac %pEA f 0x%x%s%s%s%s%s%s %s", pfx,
1036 n->zevpn->vni, &n->ip, &n->emac, n->flags,
1037 is_router ? " router" : "",
1038 local_inactive ? " local-inactive" : "",
1039 old_bgp_ready ? " old_bgp_ready" : "",
1040 new_bgp_ready ? " new_bgp_ready" : "",
1041 inform_dataplane ? " inform_dp" : "",
1042 inform_bgp ? " inform_bgp" : "", sfx);
1043 }
1044
1045 /* As part Duplicate Address Detection (DAD) for IP mobility
1046 * MAC binding changes, ensure to inherit duplicate flag
1047 * from MAC.
1048 */
1049 static int zebra_evpn_ip_inherit_dad_from_mac(struct zebra_vrf *zvrf,
1050 struct zebra_mac *old_zmac,
1051 struct zebra_mac *new_zmac,
1052 struct zebra_neigh *nbr)
1053 {
1054 bool is_old_mac_dup = false;
1055 bool is_new_mac_dup = false;
1056
1057 if (!zebra_evpn_do_dup_addr_detect(zvrf))
1058 return 0;
1059 /* Check old or new MAC is detected as duplicate
1060 * mark this neigh as duplicate
1061 */
1062 if (old_zmac)
1063 is_old_mac_dup =
1064 CHECK_FLAG(old_zmac->flags, ZEBRA_MAC_DUPLICATE);
1065 if (new_zmac)
1066 is_new_mac_dup =
1067 CHECK_FLAG(new_zmac->flags, ZEBRA_MAC_DUPLICATE);
1068 /* Old and/or new MAC can be in duplicate state,
1069 * based on that IP/Neigh Inherits the flag.
1070 * If New MAC is marked duplicate, inherit to the IP.
1071 * If old MAC is duplicate but new MAC is not, clear
1072 * duplicate flag for IP and reset detection params
1073 * and let IP DAD retrigger.
1074 */
1075 if (is_new_mac_dup && !CHECK_FLAG(nbr->flags, ZEBRA_NEIGH_DUPLICATE)) {
1076 SET_FLAG(nbr->flags, ZEBRA_NEIGH_DUPLICATE);
1077 /* Capture Duplicate detection time */
1078 nbr->dad_dup_detect_time = monotime(NULL);
1079 /* Mark neigh inactive */
1080 ZEBRA_NEIGH_SET_INACTIVE(nbr);
1081
1082 return 1;
1083 } else if (is_old_mac_dup && !is_new_mac_dup) {
1084 UNSET_FLAG(nbr->flags, ZEBRA_NEIGH_DUPLICATE);
1085 nbr->dad_count = 0;
1086 nbr->detect_start_time.tv_sec = 0;
1087 nbr->detect_start_time.tv_usec = 0;
1088 }
1089 return 0;
1090 }
1091
1092 static void zebra_evpn_dad_ip_auto_recovery_exp(struct thread *t)
1093 {
1094 struct zebra_vrf *zvrf = NULL;
1095 struct zebra_neigh *nbr = NULL;
1096 struct zebra_evpn *zevpn = NULL;
1097
1098 nbr = THREAD_ARG(t);
1099
1100 /* since this is asynchronous we need sanity checks*/
1101 zvrf = vrf_info_lookup(nbr->zevpn->vrf_id);
1102 if (!zvrf)
1103 return;
1104
1105 zevpn = zebra_evpn_lookup(nbr->zevpn->vni);
1106 if (!zevpn)
1107 return;
1108
1109 nbr = zebra_evpn_neigh_lookup(zevpn, &nbr->ip);
1110 if (!nbr)
1111 return;
1112
1113 if (IS_ZEBRA_DEBUG_VXLAN)
1114 zlog_debug(
1115 "%s: duplicate addr MAC %pEA IP %pIA flags 0x%x learn count %u vni %u auto recovery expired",
1116 __func__, &nbr->emac, &nbr->ip, nbr->flags,
1117 nbr->dad_count, zevpn->vni);
1118
1119 UNSET_FLAG(nbr->flags, ZEBRA_NEIGH_DUPLICATE);
1120 nbr->dad_count = 0;
1121 nbr->detect_start_time.tv_sec = 0;
1122 nbr->detect_start_time.tv_usec = 0;
1123 nbr->dad_dup_detect_time = 0;
1124 nbr->dad_ip_auto_recovery_timer = NULL;
1125 ZEBRA_NEIGH_SET_ACTIVE(nbr);
1126
1127 /* Send to BGP */
1128 if (CHECK_FLAG(nbr->flags, ZEBRA_NEIGH_LOCAL)) {
1129 zebra_evpn_neigh_send_add_to_client(zevpn->vni, &nbr->ip,
1130 &nbr->emac, nbr->mac,
1131 nbr->flags, nbr->loc_seq);
1132 } else if (!!CHECK_FLAG(nbr->flags, ZEBRA_NEIGH_REMOTE)) {
1133 zebra_evpn_rem_neigh_install(zevpn, nbr, false /*was_static*/);
1134 }
1135 }
1136
1137 static void zebra_evpn_dup_addr_detect_for_neigh(
1138 struct zebra_vrf *zvrf, struct zebra_neigh *nbr, struct in_addr vtep_ip,
1139 bool do_dad, bool *is_dup_detect, bool is_local)
1140 {
1141
1142 struct timeval elapsed = {0, 0};
1143 bool reset_params = false;
1144
1145 if (!zebra_evpn_do_dup_addr_detect(zvrf))
1146 return;
1147
1148 /* IP is detected as duplicate or inherit dup
1149 * state, hold on to install as remote entry
1150 * only if freeze is enabled.
1151 */
1152 if (CHECK_FLAG(nbr->flags, ZEBRA_NEIGH_DUPLICATE)) {
1153 if (IS_ZEBRA_DEBUG_VXLAN)
1154 zlog_debug(
1155 "%s: duplicate addr MAC %pEA IP %pIA flags 0x%x skip installing, learn count %u recover time %u",
1156 __func__, &nbr->emac, &nbr->ip,
1157 nbr->flags, nbr->dad_count,
1158 zvrf->dad_freeze_time);
1159
1160 if (zvrf->dad_freeze)
1161 *is_dup_detect = true;
1162
1163 /* warn-only action, neigh will be installed.
1164 * freeze action, it wil not be installed.
1165 */
1166 return;
1167 }
1168
1169 if (!do_dad)
1170 return;
1171
1172 /* Check if detection time (M-secs) expired.
1173 * Reset learn count and detection start time.
1174 * During remote mac add, count should already be 1
1175 * via local learning.
1176 */
1177 monotime_since(&nbr->detect_start_time, &elapsed);
1178 reset_params = (elapsed.tv_sec > zvrf->dad_time);
1179
1180 if (is_local && !reset_params) {
1181 /* RFC-7432: A PE/VTEP that detects a MAC mobility
1182 * event via LOCAL learning starts an M-second timer.
1183 *
1184 * NOTE: This is the START of the probe with count is
1185 * 0 during LOCAL learn event.
1186 */
1187 reset_params = !nbr->dad_count;
1188 }
1189
1190 if (reset_params) {
1191 if (IS_ZEBRA_DEBUG_VXLAN)
1192 zlog_debug(
1193 "%s: duplicate addr MAC %pEA IP %pIA flags 0x%x detection time passed, reset learn count %u",
1194 __func__, &nbr->emac, &nbr->ip,
1195 nbr->flags, nbr->dad_count);
1196 /* Reset learn count but do not start detection
1197 * during REMOTE learn event.
1198 */
1199 nbr->dad_count = 0;
1200 /* Start dup. addr detection (DAD) start time,
1201 * ONLY during LOCAL learn.
1202 */
1203 if (is_local)
1204 monotime(&nbr->detect_start_time);
1205
1206 } else if (!is_local) {
1207 /* For REMOTE IP/Neigh, increment detection count
1208 * ONLY while in probe window, once window passed,
1209 * next local learn event should trigger DAD.
1210 */
1211 nbr->dad_count++;
1212 }
1213
1214 /* For LOCAL IP/Neigh learn event, once count is reset above via either
1215 * initial/start detection time or passed the probe time, the count
1216 * needs to be incremented.
1217 */
1218 if (is_local)
1219 nbr->dad_count++;
1220
1221 if (nbr->dad_count >= zvrf->dad_max_moves) {
1222 flog_warn(
1223 EC_ZEBRA_DUP_IP_DETECTED,
1224 "VNI %u: MAC %pEA IP %pIA detected as duplicate during %s VTEP %pI4",
1225 nbr->zevpn->vni, &nbr->emac, &nbr->ip,
1226 is_local ? "local update, last" : "remote update, from",
1227 &vtep_ip);
1228
1229 SET_FLAG(nbr->flags, ZEBRA_NEIGH_DUPLICATE);
1230
1231 /* Capture Duplicate detection time */
1232 nbr->dad_dup_detect_time = monotime(NULL);
1233
1234 /* Start auto recovery timer for this IP */
1235 THREAD_OFF(nbr->dad_ip_auto_recovery_timer);
1236 if (zvrf->dad_freeze && zvrf->dad_freeze_time) {
1237 if (IS_ZEBRA_DEBUG_VXLAN)
1238 zlog_debug(
1239 "%s: duplicate addr MAC %pEA IP %pIA flags 0x%x auto recovery time %u start",
1240 __func__, &nbr->emac, &nbr->ip,
1241 nbr->flags, zvrf->dad_freeze_time);
1242
1243 thread_add_timer(zrouter.master,
1244 zebra_evpn_dad_ip_auto_recovery_exp,
1245 nbr, zvrf->dad_freeze_time,
1246 &nbr->dad_ip_auto_recovery_timer);
1247 }
1248 if (zvrf->dad_freeze)
1249 *is_dup_detect = true;
1250 }
1251 }
1252
1253 int zebra_evpn_local_neigh_update(struct zebra_evpn *zevpn,
1254 struct interface *ifp,
1255 const struct ipaddr *ip,
1256 const struct ethaddr *macaddr, bool is_router,
1257 bool local_inactive, bool dp_static)
1258 {
1259 struct zebra_vrf *zvrf;
1260 struct zebra_neigh *n = NULL;
1261 struct zebra_mac *zmac = NULL, *old_zmac = NULL;
1262 uint32_t old_mac_seq = 0, mac_new_seq = 0;
1263 bool upd_mac_seq = false;
1264 bool neigh_mac_change = false;
1265 bool neigh_on_hold = false;
1266 bool neigh_was_remote = false;
1267 bool do_dad = false;
1268 struct in_addr vtep_ip = {.s_addr = 0};
1269 bool inform_dataplane = false;
1270 bool created = false;
1271 bool new_static = false;
1272 bool old_bgp_ready = false;
1273 bool new_bgp_ready;
1274
1275 /* Check if the MAC exists. */
1276 zmac = zebra_evpn_mac_lookup(zevpn, macaddr);
1277 if (!zmac) {
1278 /* create a dummy MAC if the MAC is not already present */
1279 if (IS_ZEBRA_DEBUG_VXLAN)
1280 zlog_debug("AUTO MAC %pEA created for neigh %pIA on VNI %u",
1281 macaddr, ip, zevpn->vni);
1282
1283 zmac = zebra_evpn_mac_add(zevpn, macaddr);
1284 zebra_evpn_mac_clear_fwd_info(zmac);
1285 memset(&zmac->flags, 0, sizeof(uint32_t));
1286 SET_FLAG(zmac->flags, ZEBRA_MAC_AUTO);
1287 } else {
1288 if (CHECK_FLAG(zmac->flags, ZEBRA_MAC_REMOTE)) {
1289 /*
1290 * We don't change the MAC to local upon a neighbor
1291 * learn event, we wait for the explicit local MAC
1292 * learn. However, we have to compute its sequence
1293 * number in preparation for when it actually turns
1294 * local.
1295 */
1296 upd_mac_seq = true;
1297 }
1298 }
1299
1300 zvrf = zevpn->vxlan_if->vrf->info;
1301 if (!zvrf) {
1302 if (IS_ZEBRA_DEBUG_VXLAN)
1303 zlog_debug(" Unable to find vrf for: %d",
1304 zevpn->vxlan_if->vrf->vrf_id);
1305 return -1;
1306 }
1307
1308 /* Check if the neighbor exists. */
1309 n = zebra_evpn_neigh_lookup(zevpn, ip);
1310 if (!n) {
1311 /* New neighbor - create */
1312 n = zebra_evpn_neigh_add(zevpn, ip, macaddr, zmac, 0);
1313
1314 /* Set "local" forwarding info. */
1315 SET_FLAG(n->flags, ZEBRA_NEIGH_LOCAL);
1316 n->ifindex = ifp->ifindex;
1317 created = true;
1318 } else {
1319 if (CHECK_FLAG(n->flags, ZEBRA_NEIGH_LOCAL)) {
1320 bool mac_different;
1321 bool cur_is_router;
1322 bool old_local_inactive;
1323
1324 old_local_inactive = !!CHECK_FLAG(
1325 n->flags, ZEBRA_NEIGH_LOCAL_INACTIVE);
1326
1327 old_bgp_ready = zebra_evpn_neigh_is_ready_for_bgp(n);
1328
1329 /* Note any changes and see if of interest to BGP. */
1330 mac_different = !!memcmp(&n->emac, macaddr, ETH_ALEN);
1331 cur_is_router =
1332 !!CHECK_FLAG(n->flags, ZEBRA_NEIGH_ROUTER_FLAG);
1333 new_static = zebra_evpn_neigh_is_static(n);
1334 if (!mac_different && is_router == cur_is_router
1335 && old_local_inactive == local_inactive
1336 && dp_static != new_static) {
1337 if (IS_ZEBRA_DEBUG_VXLAN)
1338 zlog_debug(
1339 " Ignoring entry mac is the same and is_router == cur_is_router");
1340 n->ifindex = ifp->ifindex;
1341 return 0;
1342 }
1343
1344 old_zmac = n->mac;
1345 if (!mac_different) {
1346 /* XXX - cleanup this code duplication */
1347 bool is_neigh_freezed = false;
1348
1349 /* Only the router flag has changed. */
1350 if (is_router)
1351 SET_FLAG(n->flags,
1352 ZEBRA_NEIGH_ROUTER_FLAG);
1353 else
1354 UNSET_FLAG(n->flags,
1355 ZEBRA_NEIGH_ROUTER_FLAG);
1356
1357 if (local_inactive)
1358 SET_FLAG(n->flags,
1359 ZEBRA_NEIGH_LOCAL_INACTIVE);
1360 else
1361 UNSET_FLAG(n->flags,
1362 ZEBRA_NEIGH_LOCAL_INACTIVE);
1363 new_bgp_ready =
1364 zebra_evpn_neigh_is_ready_for_bgp(n);
1365
1366 if (dp_static != new_static)
1367 inform_dataplane = true;
1368
1369 /* Neigh is in freeze state and freeze action
1370 * is enabled, do not send update to client.
1371 */
1372 is_neigh_freezed =
1373 (zebra_evpn_do_dup_addr_detect(zvrf)
1374 && zvrf->dad_freeze
1375 && CHECK_FLAG(n->flags,
1376 ZEBRA_NEIGH_DUPLICATE));
1377
1378 zebra_evpn_local_neigh_update_log(
1379 "local", n, is_router, local_inactive,
1380 old_bgp_ready, new_bgp_ready, false,
1381 false, "flag-update");
1382
1383 if (inform_dataplane)
1384 zebra_evpn_sync_neigh_dp_install(
1385 n, false /* set_inactive */,
1386 false /* force_clear_static */,
1387 __func__);
1388
1389 /* if the neigh can no longer be advertised
1390 * remove it from bgp
1391 */
1392 if (!is_neigh_freezed) {
1393 zebra_evpn_neigh_send_add_del_to_client(
1394 n, old_bgp_ready,
1395 new_bgp_ready);
1396 } else {
1397 if (IS_ZEBRA_DEBUG_VXLAN
1398 && IS_ZEBRA_NEIGH_ACTIVE(n))
1399 zlog_debug(
1400 " Neighbor active and frozen");
1401 }
1402 return 0;
1403 }
1404
1405 /* The MAC has changed, need to issue a delete
1406 * first as this means a different MACIP route.
1407 * Also, need to do some unlinking/relinking.
1408 * We also need to update the MAC's sequence number
1409 * in different situations.
1410 */
1411 if (old_bgp_ready) {
1412 zebra_evpn_neigh_send_del_to_client(
1413 zevpn->vni, &n->ip, &n->emac, n->flags,
1414 n->state, false /*force*/);
1415 old_bgp_ready = false;
1416 }
1417 if (old_zmac) {
1418 old_mac_seq = CHECK_FLAG(old_zmac->flags,
1419 ZEBRA_MAC_REMOTE)
1420 ? old_zmac->rem_seq
1421 : old_zmac->loc_seq;
1422 neigh_mac_change = upd_mac_seq = true;
1423 zebra_evpn_local_neigh_deref_mac(
1424 n, true /* send_mac_update */);
1425 }
1426
1427 /* if mac changes abandon peer flags and tell
1428 * dataplane to clear the static flag
1429 */
1430 if (zebra_evpn_neigh_clear_sync_info(n))
1431 inform_dataplane = true;
1432 /* Update the forwarding info. */
1433 n->ifindex = ifp->ifindex;
1434
1435 /* Link to new MAC */
1436 zebra_evpn_local_neigh_ref_mac(
1437 n, macaddr, zmac, true /* send_mac_update */);
1438 } else if (CHECK_FLAG(n->flags, ZEBRA_NEIGH_REMOTE)) {
1439 /*
1440 * Neighbor has moved from remote to local. Its
1441 * MAC could have also changed as part of the move.
1442 */
1443 if (memcmp(n->emac.octet, macaddr->octet, ETH_ALEN)
1444 != 0) {
1445 old_zmac = n->mac;
1446 if (old_zmac) {
1447 old_mac_seq =
1448 CHECK_FLAG(old_zmac->flags,
1449 ZEBRA_MAC_REMOTE)
1450 ? old_zmac->rem_seq
1451 : old_zmac->loc_seq;
1452 neigh_mac_change = upd_mac_seq = true;
1453 zebra_evpn_local_neigh_deref_mac(
1454 n, true /* send_update */);
1455 }
1456
1457 /* Link to new MAC */
1458 zebra_evpn_local_neigh_ref_mac(
1459 n, macaddr, zmac, true /*send_update*/);
1460 }
1461 /* Based on Mobility event Scenario-B from the
1462 * draft, neigh's previous state was remote treat this
1463 * event for DAD.
1464 */
1465 neigh_was_remote = true;
1466 vtep_ip = n->r_vtep_ip;
1467 /* Mark appropriately */
1468 UNSET_FLAG(n->flags, ZEBRA_NEIGH_REMOTE);
1469 n->r_vtep_ip.s_addr = INADDR_ANY;
1470 SET_FLAG(n->flags, ZEBRA_NEIGH_LOCAL);
1471 n->ifindex = ifp->ifindex;
1472 }
1473 }
1474
1475 /* If MAC was previously remote, or the neighbor had a different
1476 * MAC earlier, recompute the sequence number.
1477 */
1478 if (upd_mac_seq) {
1479 uint32_t seq1, seq2;
1480
1481 seq1 = CHECK_FLAG(zmac->flags, ZEBRA_MAC_REMOTE)
1482 ? zmac->rem_seq + 1
1483 : zmac->loc_seq;
1484 seq2 = neigh_mac_change ? old_mac_seq + 1 : 0;
1485 mac_new_seq = zmac->loc_seq < MAX(seq1, seq2) ? MAX(seq1, seq2)
1486 : zmac->loc_seq;
1487 }
1488
1489 if (local_inactive)
1490 SET_FLAG(n->flags, ZEBRA_NEIGH_LOCAL_INACTIVE);
1491 else
1492 UNSET_FLAG(n->flags, ZEBRA_NEIGH_LOCAL_INACTIVE);
1493
1494 /* Mark Router flag (R-bit) */
1495 if (is_router)
1496 SET_FLAG(n->flags, ZEBRA_NEIGH_ROUTER_FLAG);
1497 else
1498 UNSET_FLAG(n->flags, ZEBRA_NEIGH_ROUTER_FLAG);
1499
1500 /* if zebra and dataplane don't agree this is a sync entry
1501 * re-install in the dataplane */
1502 new_static = zebra_evpn_neigh_is_static(n);
1503 if (dp_static != new_static)
1504 inform_dataplane = true;
1505
1506 /* Check old and/or new MAC detected as duplicate mark
1507 * the neigh as duplicate
1508 */
1509 if (zebra_evpn_ip_inherit_dad_from_mac(zvrf, old_zmac, zmac, n)) {
1510 flog_warn(
1511 EC_ZEBRA_DUP_IP_INHERIT_DETECTED,
1512 "VNI %u: MAC %pEA IP %pIA detected as duplicate during local update, inherit duplicate from MAC",
1513 zevpn->vni, macaddr, &n->ip);
1514 }
1515
1516 /* For IP Duplicate Address Detection (DAD) is trigger,
1517 * when the event is extended mobility based on scenario-B
1518 * from the draft, IP/Neigh's MAC binding changed and
1519 * neigh's previous state was remote.
1520 */
1521 if (neigh_mac_change && neigh_was_remote)
1522 do_dad = true;
1523
1524 zebra_evpn_dup_addr_detect_for_neigh(zvrf, n, vtep_ip, do_dad,
1525 &neigh_on_hold, true);
1526
1527 if (inform_dataplane)
1528 zebra_evpn_sync_neigh_dp_install(n, false /* set_inactive */,
1529 false /* force_clear_static */,
1530 __func__);
1531
1532 /* Before we program this in BGP, we need to check if MAC is locally
1533 * learnt. If not, force neighbor to be inactive and reset its seq.
1534 */
1535 if (!CHECK_FLAG(zmac->flags, ZEBRA_MAC_LOCAL)) {
1536 zebra_evpn_local_neigh_update_log(
1537 "local", n, is_router, local_inactive, false, false,
1538 inform_dataplane, false, "auto-mac");
1539 ZEBRA_NEIGH_SET_INACTIVE(n);
1540 n->loc_seq = 0;
1541 zmac->loc_seq = mac_new_seq;
1542 return 0;
1543 }
1544
1545 zebra_evpn_local_neigh_update_log("local", n, is_router, local_inactive,
1546 false, false, inform_dataplane, true,
1547 created ? "created" : "updated");
1548
1549 /* If the MAC's sequence number has changed, inform the MAC and all
1550 * neighbors associated with the MAC to BGP, else just inform this
1551 * neighbor.
1552 */
1553 if (upd_mac_seq && zmac->loc_seq != mac_new_seq) {
1554 if (IS_ZEBRA_DEBUG_VXLAN)
1555 zlog_debug(
1556 "Seq changed for MAC %pEA VNI %u - old %u new %u",
1557 macaddr, zevpn->vni,
1558 zmac->loc_seq, mac_new_seq);
1559 zmac->loc_seq = mac_new_seq;
1560 if (zebra_evpn_mac_send_add_to_client(zevpn->vni, macaddr,
1561 zmac->flags,
1562 zmac->loc_seq, zmac->es))
1563 return -1;
1564 zebra_evpn_process_neigh_on_local_mac_change(zevpn, zmac, 1,
1565 0 /*es_change*/);
1566 return 0;
1567 }
1568
1569 n->loc_seq = zmac->loc_seq;
1570
1571 if (!neigh_on_hold) {
1572 ZEBRA_NEIGH_SET_ACTIVE(n);
1573 new_bgp_ready = zebra_evpn_neigh_is_ready_for_bgp(n);
1574 zebra_evpn_neigh_send_add_del_to_client(n, old_bgp_ready,
1575 new_bgp_ready);
1576 } else {
1577 if (IS_ZEBRA_DEBUG_VXLAN)
1578 zlog_debug(" Neighbor on hold not sending");
1579 }
1580 return 0;
1581 }
1582
1583 int zebra_evpn_remote_neigh_update(struct zebra_evpn *zevpn,
1584 struct interface *ifp,
1585 const struct ipaddr *ip,
1586 const struct ethaddr *macaddr,
1587 uint16_t state)
1588 {
1589 struct zebra_neigh *n = NULL;
1590 struct zebra_mac *zmac = NULL;
1591
1592 /* If the neighbor is unknown, there is no further action. */
1593 n = zebra_evpn_neigh_lookup(zevpn, ip);
1594 if (!n)
1595 return 0;
1596
1597 /* If a remote entry, see if it needs to be refreshed */
1598 if (CHECK_FLAG(n->flags, ZEBRA_NEIGH_REMOTE)) {
1599 #ifdef GNU_LINUX
1600 if (state & NUD_STALE)
1601 zebra_evpn_rem_neigh_install(zevpn, n,
1602 false /*was_static*/);
1603 #endif
1604 } else {
1605 /* We got a "remote" neighbor notification for an entry
1606 * we think is local. This can happen in a multihoming
1607 * scenario - but only if the MAC is already "remote".
1608 * Just mark our entry as "remote".
1609 */
1610 zmac = zebra_evpn_mac_lookup(zevpn, macaddr);
1611 if (!zmac || !CHECK_FLAG(zmac->flags, ZEBRA_MAC_REMOTE)) {
1612 zlog_debug(
1613 "Ignore remote neigh %pIA (MAC %pEA) on L2-VNI %u - MAC unknown or local",
1614 &n->ip, macaddr, zevpn->vni);
1615 return -1;
1616 }
1617
1618 UNSET_FLAG(n->flags, ZEBRA_NEIGH_ALL_LOCAL_FLAGS);
1619 SET_FLAG(n->flags, ZEBRA_NEIGH_REMOTE);
1620 ZEBRA_NEIGH_SET_ACTIVE(n);
1621 n->r_vtep_ip = zmac->fwd_info.r_vtep_ip;
1622 }
1623
1624 return 0;
1625 }
1626
1627 /* Notify Neighbor entries to the Client, skips the GW entry */
1628 static void
1629 zebra_evpn_send_neigh_hash_entry_to_client(struct hash_bucket *bucket,
1630 void *arg)
1631 {
1632 struct mac_walk_ctx *wctx = arg;
1633 struct zebra_neigh *zn = bucket->data;
1634 struct zebra_mac *zmac = NULL;
1635
1636 if (CHECK_FLAG(zn->flags, ZEBRA_NEIGH_DEF_GW))
1637 return;
1638
1639 if (CHECK_FLAG(zn->flags, ZEBRA_NEIGH_LOCAL)
1640 && IS_ZEBRA_NEIGH_ACTIVE(zn)) {
1641 zmac = zebra_evpn_mac_lookup(wctx->zevpn, &zn->emac);
1642 if (!zmac)
1643 return;
1644
1645 zebra_evpn_neigh_send_add_to_client(wctx->zevpn->vni, &zn->ip,
1646 &zn->emac, zn->mac,
1647 zn->flags, zn->loc_seq);
1648 }
1649 }
1650
1651 /* Iterator of a specific EVPN */
1652 void zebra_evpn_send_neigh_to_client(struct zebra_evpn *zevpn)
1653 {
1654 struct neigh_walk_ctx wctx;
1655
1656 memset(&wctx, 0, sizeof(wctx));
1657 wctx.zevpn = zevpn;
1658
1659 hash_iterate(zevpn->neigh_table,
1660 zebra_evpn_send_neigh_hash_entry_to_client, &wctx);
1661 }
1662
1663 void zebra_evpn_clear_dup_neigh_hash(struct hash_bucket *bucket, void *ctxt)
1664 {
1665 struct neigh_walk_ctx *wctx = ctxt;
1666 struct zebra_neigh *nbr;
1667 struct zebra_evpn *zevpn;
1668 char buf[INET6_ADDRSTRLEN];
1669
1670 nbr = (struct zebra_neigh *)bucket->data;
1671 if (!nbr)
1672 return;
1673
1674 zevpn = wctx->zevpn;
1675
1676 if (!CHECK_FLAG(nbr->flags, ZEBRA_NEIGH_DUPLICATE))
1677 return;
1678
1679 if (IS_ZEBRA_DEBUG_VXLAN) {
1680 ipaddr2str(&nbr->ip, buf, sizeof(buf));
1681 zlog_debug("%s: clear neigh %s dup state, flags 0x%x seq %u",
1682 __func__, buf, nbr->flags, nbr->loc_seq);
1683 }
1684
1685 UNSET_FLAG(nbr->flags, ZEBRA_NEIGH_DUPLICATE);
1686 nbr->dad_count = 0;
1687 nbr->detect_start_time.tv_sec = 0;
1688 nbr->detect_start_time.tv_usec = 0;
1689 nbr->dad_dup_detect_time = 0;
1690 THREAD_OFF(nbr->dad_ip_auto_recovery_timer);
1691
1692 if (CHECK_FLAG(nbr->flags, ZEBRA_NEIGH_LOCAL)) {
1693 zebra_evpn_neigh_send_add_to_client(zevpn->vni, &nbr->ip,
1694 &nbr->emac, nbr->mac,
1695 nbr->flags, nbr->loc_seq);
1696 } else if (CHECK_FLAG(nbr->flags, ZEBRA_NEIGH_REMOTE)) {
1697 zebra_evpn_rem_neigh_install(zevpn, nbr, false /*was_static*/);
1698 }
1699 }
1700
1701 /*
1702 * Print a specific neighbor entry.
1703 */
1704 void zebra_evpn_print_neigh(struct zebra_neigh *n, void *ctxt,
1705 json_object *json)
1706 {
1707 struct vty *vty;
1708 char buf1[ETHER_ADDR_STRLEN];
1709 char buf2[INET6_ADDRSTRLEN];
1710 const char *type_str;
1711 const char *state_str;
1712 bool flags_present = false;
1713 struct zebra_vrf *zvrf = NULL;
1714 struct timeval detect_start_time = {0, 0};
1715 char timebuf[MONOTIME_STRLEN];
1716 char thread_buf[THREAD_TIMER_STRLEN];
1717 time_t uptime;
1718 char up_str[MONOTIME_STRLEN];
1719
1720 zvrf = zebra_vrf_get_evpn();
1721 if (!zvrf)
1722 return;
1723
1724 uptime = monotime(NULL);
1725 uptime -= n->uptime;
1726
1727 frrtime_to_interval(uptime, up_str, sizeof(up_str));
1728
1729 ipaddr2str(&n->ip, buf2, sizeof(buf2));
1730 prefix_mac2str(&n->emac, buf1, sizeof(buf1));
1731 type_str = CHECK_FLAG(n->flags, ZEBRA_NEIGH_LOCAL) ? "local" : "remote";
1732 state_str = IS_ZEBRA_NEIGH_ACTIVE(n) ? "active" : "inactive";
1733 vty = (struct vty *)ctxt;
1734 if (json == NULL) {
1735 bool sync_info = false;
1736
1737 vty_out(vty, "IP: %s\n",
1738 ipaddr2str(&n->ip, buf2, sizeof(buf2)));
1739 vty_out(vty, " Type: %s\n", type_str);
1740 vty_out(vty, " State: %s\n", state_str);
1741 vty_out(vty, " Uptime: %s\n", up_str);
1742 vty_out(vty, " MAC: %s\n",
1743 prefix_mac2str(&n->emac, buf1, sizeof(buf1)));
1744 vty_out(vty, " Sync-info:");
1745 if (CHECK_FLAG(n->flags, ZEBRA_NEIGH_LOCAL_INACTIVE)) {
1746 vty_out(vty, " local-inactive");
1747 sync_info = true;
1748 }
1749 if (CHECK_FLAG(n->flags, ZEBRA_NEIGH_ES_PEER_PROXY)) {
1750 vty_out(vty, " peer-proxy");
1751 sync_info = true;
1752 }
1753 if (CHECK_FLAG(n->flags, ZEBRA_NEIGH_ES_PEER_ACTIVE)) {
1754 vty_out(vty, " peer-active");
1755 sync_info = true;
1756 }
1757 if (n->hold_timer) {
1758 vty_out(vty, " (ht: %s)",
1759 thread_timer_to_hhmmss(thread_buf,
1760 sizeof(thread_buf),
1761 n->hold_timer));
1762 sync_info = true;
1763 }
1764 if (!sync_info)
1765 vty_out(vty, " -");
1766 vty_out(vty, "\n");
1767 } else {
1768 json_object_string_add(json, "uptime", up_str);
1769 json_object_string_add(json, "ip", buf2);
1770 json_object_string_add(json, "type", type_str);
1771 json_object_string_add(json, "state", state_str);
1772 json_object_string_add(json, "mac", buf1);
1773 if (CHECK_FLAG(n->flags, ZEBRA_NEIGH_LOCAL_INACTIVE))
1774 json_object_boolean_true_add(json, "localInactive");
1775 if (CHECK_FLAG(n->flags, ZEBRA_NEIGH_ES_PEER_PROXY))
1776 json_object_boolean_true_add(json, "peerProxy");
1777 if (CHECK_FLAG(n->flags, ZEBRA_NEIGH_ES_PEER_ACTIVE))
1778 json_object_boolean_true_add(json, "peerActive");
1779 if (n->hold_timer)
1780 json_object_string_add(
1781 json, "peerActiveHold",
1782 thread_timer_to_hhmmss(thread_buf,
1783 sizeof(thread_buf),
1784 n->hold_timer));
1785 }
1786 if (CHECK_FLAG(n->flags, ZEBRA_NEIGH_REMOTE)) {
1787 if (n->mac->es) {
1788 if (json)
1789 json_object_string_add(json, "remoteEs",
1790 n->mac->es->esi_str);
1791 else
1792 vty_out(vty, " Remote ES: %s\n",
1793 n->mac->es->esi_str);
1794 } else {
1795 if (json)
1796 json_object_string_addf(json, "remoteVtep",
1797 "%pI4", &n->r_vtep_ip);
1798 else
1799 vty_out(vty, " Remote VTEP: %pI4\n",
1800 &n->r_vtep_ip);
1801 }
1802 }
1803 if (CHECK_FLAG(n->flags, ZEBRA_NEIGH_DEF_GW)) {
1804 if (!json) {
1805 vty_out(vty, " Flags: Default-gateway");
1806 flags_present = true;
1807 } else
1808 json_object_boolean_true_add(json, "defaultGateway");
1809 }
1810 if (CHECK_FLAG(n->flags, ZEBRA_NEIGH_ROUTER_FLAG)) {
1811 if (!json) {
1812 vty_out(vty,
1813 flags_present ? " ,Router" : " Flags: Router");
1814 flags_present = true;
1815 }
1816 }
1817 if (json == NULL) {
1818 if (flags_present)
1819 vty_out(vty, "\n");
1820 vty_out(vty, " Local Seq: %u Remote Seq: %u\n", n->loc_seq,
1821 n->rem_seq);
1822
1823 if (CHECK_FLAG(n->flags, ZEBRA_NEIGH_DUPLICATE)) {
1824 vty_out(vty, " Duplicate, detected at %s",
1825 time_to_string(n->dad_dup_detect_time,
1826 timebuf));
1827 } else if (n->dad_count) {
1828 monotime_since(&n->detect_start_time,
1829 &detect_start_time);
1830 if (detect_start_time.tv_sec <= zvrf->dad_time) {
1831 time_to_string(n->detect_start_time.tv_sec,
1832 timebuf);
1833 vty_out(vty,
1834 " Duplicate detection started at %s, detection count %u\n",
1835 timebuf, n->dad_count);
1836 }
1837 }
1838 } else {
1839 json_object_int_add(json, "localSequence", n->loc_seq);
1840 json_object_int_add(json, "remoteSequence", n->rem_seq);
1841 json_object_int_add(json, "detectionCount", n->dad_count);
1842 if (CHECK_FLAG(n->flags, ZEBRA_NEIGH_DUPLICATE))
1843 json_object_boolean_true_add(json, "isDuplicate");
1844 else
1845 json_object_boolean_false_add(json, "isDuplicate");
1846 }
1847 }
1848
1849 void zebra_evpn_print_neigh_hdr(struct vty *vty, struct neigh_walk_ctx *wctx)
1850 {
1851 vty_out(vty, "Flags: I=local-inactive, P=peer-active, X=peer-proxy\n");
1852 vty_out(vty, "%*s %-6s %-5s %-8s %-17s %-30s %s\n", -wctx->addr_width,
1853 "Neighbor", "Type", "Flags", "State", "MAC", "Remote ES/VTEP",
1854 "Seq #'s");
1855 }
1856
1857 static char *zebra_evpn_print_neigh_flags(struct zebra_neigh *n,
1858 char *flags_buf,
1859 uint32_t flags_buf_sz)
1860 {
1861 snprintf(flags_buf, flags_buf_sz, "%s%s%s",
1862 (n->flags & ZEBRA_NEIGH_ES_PEER_ACTIVE) ?
1863 "P" : "",
1864 (n->flags & ZEBRA_NEIGH_ES_PEER_PROXY) ?
1865 "X" : "",
1866 (n->flags & ZEBRA_NEIGH_LOCAL_INACTIVE) ?
1867 "I" : "");
1868
1869 return flags_buf;
1870 }
1871
1872 /*
1873 * Print neighbor hash entry - called for display of all neighbors.
1874 */
1875 void zebra_evpn_print_neigh_hash(struct hash_bucket *bucket, void *ctxt)
1876 {
1877 struct vty *vty;
1878 json_object *json_evpn = NULL, *json_row = NULL;
1879 struct zebra_neigh *n;
1880 char buf1[ETHER_ADDR_STRLEN];
1881 char buf2[INET6_ADDRSTRLEN];
1882 char addr_buf[PREFIX_STRLEN];
1883 struct neigh_walk_ctx *wctx = ctxt;
1884 const char *state_str;
1885 char flags_buf[6];
1886
1887 vty = wctx->vty;
1888 json_evpn = wctx->json;
1889 n = (struct zebra_neigh *)bucket->data;
1890
1891 if (json_evpn)
1892 json_row = json_object_new_object();
1893
1894 prefix_mac2str(&n->emac, buf1, sizeof(buf1));
1895 ipaddr2str(&n->ip, buf2, sizeof(buf2));
1896 state_str = IS_ZEBRA_NEIGH_ACTIVE(n) ? "active" : "inactive";
1897 if (CHECK_FLAG(n->flags, ZEBRA_NEIGH_LOCAL)) {
1898 if (wctx->flags & SHOW_REMOTE_NEIGH_FROM_VTEP)
1899 return;
1900
1901 if (json_evpn == NULL) {
1902 vty_out(vty, "%*s %-6s %-5s %-8s %-17s %-30s %u/%u\n",
1903 -wctx->addr_width, buf2, "local",
1904 zebra_evpn_print_neigh_flags(n, flags_buf,
1905 sizeof(flags_buf)), state_str, buf1,
1906 "", n->loc_seq, n->rem_seq);
1907 } else {
1908 json_object_string_add(json_row, "type", "local");
1909 json_object_string_add(json_row, "state", state_str);
1910 json_object_string_add(json_row, "mac", buf1);
1911 if (CHECK_FLAG(n->flags, ZEBRA_NEIGH_DEF_GW))
1912 json_object_boolean_true_add(json_row,
1913 "defaultGateway");
1914 json_object_int_add(json_row, "localSequence",
1915 n->loc_seq);
1916 json_object_int_add(json_row, "remoteSequence",
1917 n->rem_seq);
1918 json_object_int_add(json_row, "detectionCount",
1919 n->dad_count);
1920 if (CHECK_FLAG(n->flags, ZEBRA_NEIGH_DUPLICATE))
1921 json_object_boolean_true_add(json_row,
1922 "isDuplicate");
1923 else
1924 json_object_boolean_false_add(json_row,
1925 "isDuplicate");
1926 }
1927 wctx->count++;
1928 } else if (CHECK_FLAG(n->flags, ZEBRA_NEIGH_REMOTE)) {
1929 if ((wctx->flags & SHOW_REMOTE_NEIGH_FROM_VTEP)
1930 && !IPV4_ADDR_SAME(&n->r_vtep_ip, &wctx->r_vtep_ip))
1931 return;
1932
1933 if (json_evpn == NULL) {
1934 if ((wctx->flags & SHOW_REMOTE_NEIGH_FROM_VTEP)
1935 && (wctx->count == 0))
1936 zebra_evpn_print_neigh_hdr(vty, wctx);
1937
1938 if (n->mac->es == NULL)
1939 inet_ntop(AF_INET, &n->r_vtep_ip,
1940 addr_buf, sizeof(addr_buf));
1941
1942 vty_out(vty, "%*s %-6s %-5s %-8s %-17s %-30s %u/%u\n",
1943 -wctx->addr_width, buf2, "remote",
1944 zebra_evpn_print_neigh_flags(n, flags_buf,
1945 sizeof(flags_buf)), state_str, buf1,
1946 n->mac->es ? n->mac->es->esi_str : addr_buf,
1947 n->loc_seq, n->rem_seq);
1948 } else {
1949 json_object_string_add(json_row, "type", "remote");
1950 json_object_string_add(json_row, "state", state_str);
1951 json_object_string_add(json_row, "mac", buf1);
1952 if (n->mac->es)
1953 json_object_string_add(json_row, "remoteEs",
1954 n->mac->es->esi_str);
1955 else
1956 json_object_string_addf(json_row, "remoteVtep",
1957 "%pI4", &n->r_vtep_ip);
1958 if (CHECK_FLAG(n->flags, ZEBRA_NEIGH_DEF_GW))
1959 json_object_boolean_true_add(json_row,
1960 "defaultGateway");
1961 json_object_int_add(json_row, "localSequence",
1962 n->loc_seq);
1963 json_object_int_add(json_row, "remoteSequence",
1964 n->rem_seq);
1965 json_object_int_add(json_row, "detectionCount",
1966 n->dad_count);
1967 if (CHECK_FLAG(n->flags, ZEBRA_NEIGH_DUPLICATE))
1968 json_object_boolean_true_add(json_row,
1969 "isDuplicate");
1970 else
1971 json_object_boolean_false_add(json_row,
1972 "isDuplicate");
1973 }
1974 wctx->count++;
1975 }
1976
1977 if (json_evpn)
1978 json_object_object_add(json_evpn, buf2, json_row);
1979 }
1980
1981 /*
1982 * Print neighbor hash entry in detail - called for display of all neighbors.
1983 */
1984 void zebra_evpn_print_neigh_hash_detail(struct hash_bucket *bucket, void *ctxt)
1985 {
1986 struct vty *vty;
1987 json_object *json_evpn = NULL, *json_row = NULL;
1988 struct zebra_neigh *n;
1989 char buf[INET6_ADDRSTRLEN];
1990 struct neigh_walk_ctx *wctx = ctxt;
1991
1992 vty = wctx->vty;
1993 json_evpn = wctx->json;
1994 n = (struct zebra_neigh *)bucket->data;
1995 if (!n)
1996 return;
1997
1998 ipaddr2str(&n->ip, buf, sizeof(buf));
1999 if (json_evpn)
2000 json_row = json_object_new_object();
2001
2002 zebra_evpn_print_neigh(n, vty, json_row);
2003
2004 if (json_evpn)
2005 json_object_object_add(json_evpn, buf, json_row);
2006 }
2007
2008 void zebra_evpn_print_dad_neigh_hash(struct hash_bucket *bucket, void *ctxt)
2009 {
2010 struct zebra_neigh *nbr;
2011
2012 nbr = (struct zebra_neigh *)bucket->data;
2013 if (!nbr)
2014 return;
2015
2016 if (CHECK_FLAG(nbr->flags, ZEBRA_NEIGH_DUPLICATE))
2017 zebra_evpn_print_neigh_hash(bucket, ctxt);
2018 }
2019
2020 void zebra_evpn_print_dad_neigh_hash_detail(struct hash_bucket *bucket,
2021 void *ctxt)
2022 {
2023 struct zebra_neigh *nbr;
2024
2025 nbr = (struct zebra_neigh *)bucket->data;
2026 if (!nbr)
2027 return;
2028
2029 if (CHECK_FLAG(nbr->flags, ZEBRA_NEIGH_DUPLICATE))
2030 zebra_evpn_print_neigh_hash_detail(bucket, ctxt);
2031 }
2032
2033 void zebra_evpn_neigh_remote_macip_add(struct zebra_evpn *zevpn,
2034 struct zebra_vrf *zvrf,
2035 const struct ipaddr *ipaddr,
2036 struct zebra_mac *mac,
2037 struct in_addr vtep_ip, uint8_t flags,
2038 uint32_t seq)
2039 {
2040 struct zebra_neigh *n;
2041 int update_neigh = 0;
2042 struct zebra_mac *old_mac = NULL;
2043 bool old_static = false;
2044 bool do_dad = false;
2045 bool is_dup_detect = false;
2046 bool is_router;
2047
2048 assert(mac);
2049 is_router = !!CHECK_FLAG(flags, ZEBRA_MACIP_TYPE_ROUTER_FLAG);
2050
2051 /* Check if the remote neighbor itself is unknown or has a
2052 * change. If so, create or update and then install the entry.
2053 */
2054 n = zebra_evpn_neigh_lookup(zevpn, ipaddr);
2055 if (!n || !CHECK_FLAG(n->flags, ZEBRA_NEIGH_REMOTE)
2056 || is_router != !!CHECK_FLAG(n->flags, ZEBRA_NEIGH_ROUTER_FLAG)
2057 || (memcmp(&n->emac, &mac->macaddr, sizeof(struct ethaddr)) != 0)
2058 || !IPV4_ADDR_SAME(&n->r_vtep_ip, &vtep_ip) || seq != n->rem_seq)
2059 update_neigh = 1;
2060
2061 if (update_neigh) {
2062 if (!n) {
2063 n = zebra_evpn_neigh_add(zevpn, ipaddr, &mac->macaddr,
2064 mac, 0);
2065 } else {
2066 /* When host moves but changes its (MAC,IP)
2067 * binding, BGP may install a MACIP entry that
2068 * corresponds to "older" location of the host
2069 * in transient situations (because {IP1,M1}
2070 * is a different route from {IP1,M2}). Check
2071 * the sequence number and ignore this update
2072 * if appropriate.
2073 */
2074
2075 if (!zebra_evpn_neigh_is_bgp_seq_ok(
2076 zevpn, n, &mac->macaddr, seq, false))
2077 return;
2078 if (CHECK_FLAG(n->flags, ZEBRA_NEIGH_LOCAL)) {
2079 old_static = zebra_evpn_neigh_is_static(n);
2080 if (IS_ZEBRA_DEBUG_EVPN_MH_NEIGH)
2081 zlog_debug(
2082 "sync->remote neigh vni %u ip %pIA mac %pEA seq %d f0x%x",
2083 n->zevpn->vni, &n->ip, &n->emac,
2084 seq, n->flags);
2085 if (IS_ZEBRA_NEIGH_ACTIVE(n))
2086 zebra_evpn_neigh_send_del_to_client(
2087 zevpn->vni, &n->ip, &n->emac,
2088 n->flags, n->state,
2089 false /*force*/);
2090 zebra_evpn_neigh_clear_sync_info(n);
2091 }
2092 if (memcmp(&n->emac, &mac->macaddr,
2093 sizeof(struct ethaddr))
2094 != 0) {
2095 /* update neigh list for macs */
2096 old_mac =
2097 zebra_evpn_mac_lookup(zevpn, &n->emac);
2098 if (old_mac) {
2099 listnode_delete(old_mac->neigh_list, n);
2100 n->mac = NULL;
2101 zebra_evpn_deref_ip2mac(zevpn, old_mac);
2102 }
2103 n->mac = mac;
2104 listnode_add_sort(mac->neigh_list, n);
2105 memcpy(&n->emac, &mac->macaddr, ETH_ALEN);
2106
2107 /* Check Neigh's curent state is local
2108 * (this is the case where neigh/host has moved
2109 * from L->R) and check previous detction
2110 * started via local learning.
2111 *
2112 * RFC-7432: A PE/VTEP that detects a MAC
2113 * mobilit event via local learning starts
2114 * an M-second timer.
2115 * VTEP-IP or seq. change along is not
2116 * considered for dup. detection.
2117 *
2118 * Mobilty event scenario-B IP-MAC binding
2119 * changed.
2120 */
2121 if ((!CHECK_FLAG(n->flags, ZEBRA_NEIGH_REMOTE))
2122 && n->dad_count)
2123 do_dad = true;
2124 }
2125 }
2126
2127 /* Set "remote" forwarding info. */
2128 UNSET_FLAG(n->flags, ZEBRA_NEIGH_ALL_LOCAL_FLAGS);
2129 n->r_vtep_ip = vtep_ip;
2130 SET_FLAG(n->flags, ZEBRA_NEIGH_REMOTE);
2131
2132 /* Set router flag (R-bit) to this Neighbor entry */
2133 if (CHECK_FLAG(flags, ZEBRA_MACIP_TYPE_ROUTER_FLAG))
2134 SET_FLAG(n->flags, ZEBRA_NEIGH_ROUTER_FLAG);
2135 else
2136 UNSET_FLAG(n->flags, ZEBRA_NEIGH_ROUTER_FLAG);
2137
2138 /* Check old or new MAC detected as duplicate,
2139 * inherit duplicate flag to this neigh.
2140 */
2141 if (zebra_evpn_ip_inherit_dad_from_mac(zvrf, old_mac, mac, n)) {
2142 flog_warn(
2143 EC_ZEBRA_DUP_IP_INHERIT_DETECTED,
2144 "VNI %u: MAC %pEA IP %pIA detected as duplicate during remote update, inherit duplicate from MAC",
2145 zevpn->vni, &mac->macaddr, &n->ip);
2146 }
2147
2148 /* Check duplicate address detection for IP */
2149 zebra_evpn_dup_addr_detect_for_neigh(
2150 zvrf, n, n->r_vtep_ip, do_dad, &is_dup_detect, false);
2151 /* Install the entry. */
2152 if (!is_dup_detect)
2153 zebra_evpn_rem_neigh_install(zevpn, n, old_static);
2154 }
2155
2156 /* Update seq number. */
2157 n->rem_seq = seq;
2158 }
2159
2160 int zebra_evpn_neigh_gw_macip_add(struct interface *ifp,
2161 struct zebra_evpn *zevpn, struct ipaddr *ip,
2162 struct zebra_mac *mac)
2163 {
2164 struct zebra_neigh *n;
2165
2166 assert(mac);
2167
2168 n = zebra_evpn_neigh_lookup(zevpn, ip);
2169 if (!n)
2170 n = zebra_evpn_neigh_add(zevpn, ip, &mac->macaddr, mac, 0);
2171
2172 /* Set "local" forwarding info. */
2173 SET_FLAG(n->flags, ZEBRA_NEIGH_LOCAL);
2174 ZEBRA_NEIGH_SET_ACTIVE(n);
2175 memcpy(&n->emac, &mac->macaddr, ETH_ALEN);
2176 n->ifindex = ifp->ifindex;
2177
2178 /* Only advertise in BGP if the knob is enabled */
2179 if (advertise_gw_macip_enabled(zevpn)) {
2180
2181 SET_FLAG(n->flags, ZEBRA_NEIGH_DEF_GW);
2182 /* Set Router flag (R-bit) */
2183 if (ip->ipa_type == IPADDR_V6)
2184 SET_FLAG(n->flags, ZEBRA_NEIGH_ROUTER_FLAG);
2185
2186 if (IS_ZEBRA_DEBUG_VXLAN)
2187 zlog_debug(
2188 "SVI %s(%u) L2-VNI %u, sending GW MAC %pEA IP %pIA add to BGP with flags 0x%x",
2189 ifp->name, ifp->ifindex, zevpn->vni,
2190 &mac->macaddr, ip, n->flags);
2191
2192 zebra_evpn_neigh_send_add_to_client(
2193 zevpn->vni, ip, &n->emac, n->mac, n->flags, n->loc_seq);
2194 } else if (advertise_svi_macip_enabled(zevpn)) {
2195
2196 SET_FLAG(n->flags, ZEBRA_NEIGH_SVI_IP);
2197 if (IS_ZEBRA_DEBUG_VXLAN)
2198 zlog_debug(
2199 "SVI %s(%u) L2-VNI %u, sending SVI MAC %pEA IP %pIA add to BGP with flags 0x%x",
2200 ifp->name, ifp->ifindex, zevpn->vni,
2201 &mac->macaddr, ip, n->flags);
2202
2203 zebra_evpn_neigh_send_add_to_client(
2204 zevpn->vni, ip, &n->emac, n->mac, n->flags, n->loc_seq);
2205 }
2206
2207 return 0;
2208 }
2209
2210 void zebra_evpn_neigh_remote_uninstall(struct zebra_evpn *zevpn,
2211 struct zebra_vrf *zvrf,
2212 struct zebra_neigh *n,
2213 struct zebra_mac *mac,
2214 const struct ipaddr *ipaddr)
2215 {
2216 if (zvrf->dad_freeze && CHECK_FLAG(n->flags, ZEBRA_NEIGH_DUPLICATE)
2217 && CHECK_FLAG(n->flags, ZEBRA_NEIGH_REMOTE)
2218 && (memcmp(n->emac.octet, mac->macaddr.octet, ETH_ALEN) == 0)) {
2219 struct interface *vlan_if;
2220
2221 vlan_if = zevpn_map_to_svi(zevpn);
2222 if (IS_ZEBRA_DEBUG_VXLAN)
2223 zlog_debug(
2224 "%s: IP %pIA (flags 0x%x intf %s) is remote and duplicate, read kernel for local entry",
2225 __func__, ipaddr, n->flags,
2226 vlan_if ? vlan_if->name : "Unknown");
2227 if (vlan_if)
2228 neigh_read_specific_ip(ipaddr, vlan_if);
2229 }
2230
2231 /* When the MAC changes for an IP, it is possible the
2232 * client may update the new MAC before trying to delete the
2233 * "old" neighbor (as these are two different MACIP routes).
2234 * Do the delete only if the MAC matches.
2235 */
2236 if (!memcmp(n->emac.octet, mac->macaddr.octet, ETH_ALEN)) {
2237 if (CHECK_FLAG(n->flags, ZEBRA_NEIGH_LOCAL)) {
2238 zebra_evpn_sync_neigh_del(n);
2239 } else if (CHECK_FLAG(n->flags, ZEBRA_NEIGH_REMOTE)) {
2240 zebra_evpn_neigh_uninstall(zevpn, n);
2241 zebra_evpn_neigh_del(zevpn, n);
2242 zebra_evpn_deref_ip2mac(zevpn, mac);
2243 }
2244 }
2245 }
2246
2247 int zebra_evpn_neigh_del_ip(struct zebra_evpn *zevpn, const struct ipaddr *ip)
2248 {
2249 struct zebra_neigh *n;
2250 struct zebra_mac *zmac;
2251 bool old_bgp_ready;
2252 bool new_bgp_ready;
2253 struct zebra_vrf *zvrf;
2254
2255 /* If entry doesn't exist, nothing to do. */
2256 n = zebra_evpn_neigh_lookup(zevpn, ip);
2257 if (!n)
2258 return 0;
2259
2260 zmac = zebra_evpn_mac_lookup(zevpn, &n->emac);
2261 if (!zmac) {
2262 if (IS_ZEBRA_DEBUG_VXLAN)
2263 zlog_debug(
2264 "Trying to del a neigh %pIA without a mac %pEA on VNI %u",
2265 ip, &n->emac,
2266 zevpn->vni);
2267
2268 return 0;
2269 }
2270
2271 /* If it is a remote entry, the kernel has aged this out or someone has
2272 * deleted it, it needs to be re-installed as FRR is the owner.
2273 */
2274 if (CHECK_FLAG(n->flags, ZEBRA_NEIGH_REMOTE)) {
2275 zebra_evpn_rem_neigh_install(zevpn, n, false /*was_static*/);
2276 return 0;
2277 }
2278
2279 /* if this is a sync entry it cannot be dropped re-install it in
2280 * the dataplane
2281 */
2282 old_bgp_ready = zebra_evpn_neigh_is_ready_for_bgp(n);
2283 if (zebra_evpn_neigh_is_static(n)) {
2284 if (IS_ZEBRA_DEBUG_EVPN_MH_NEIGH)
2285 zlog_debug("re-add sync neigh vni %u ip %pIA mac %pEA 0x%x",
2286 n->zevpn->vni, &n->ip, &n->emac,
2287 n->flags);
2288
2289 if (!CHECK_FLAG(n->flags, ZEBRA_NEIGH_LOCAL_INACTIVE))
2290 SET_FLAG(n->flags, ZEBRA_NEIGH_LOCAL_INACTIVE);
2291 /* inform-bgp about change in local-activity if any */
2292 new_bgp_ready = zebra_evpn_neigh_is_ready_for_bgp(n);
2293 zebra_evpn_neigh_send_add_del_to_client(n, old_bgp_ready,
2294 new_bgp_ready);
2295
2296 /* re-install the entry in the kernel */
2297 zebra_evpn_sync_neigh_dp_install(n, false /* set_inactive */,
2298 false /* force_clear_static */,
2299 __func__);
2300
2301 return 0;
2302 }
2303
2304 zvrf = zevpn->vxlan_if->vrf->info;
2305 if (!zvrf) {
2306 zlog_debug("%s: VNI %u vrf lookup failed.", __func__,
2307 zevpn->vni);
2308 return -1;
2309 }
2310
2311 /* In case of feeze action, if local neigh is in duplicate state,
2312 * Mark the Neigh as inactive before sending delete request to BGPd,
2313 * If BGPd has remote entry, it will re-install
2314 */
2315 if (zvrf->dad_freeze && CHECK_FLAG(n->flags, ZEBRA_NEIGH_DUPLICATE))
2316 ZEBRA_NEIGH_SET_INACTIVE(n);
2317
2318 /* Remove neighbor from BGP. */
2319 zebra_evpn_neigh_send_del_to_client(zevpn->vni, &n->ip, &n->emac,
2320 n->flags, n->state,
2321 false /* force */);
2322
2323 /* Delete this neighbor entry. */
2324 zebra_evpn_neigh_del(zevpn, n);
2325
2326 /* see if the AUTO mac needs to be deleted */
2327 if (CHECK_FLAG(zmac->flags, ZEBRA_MAC_AUTO)
2328 && !zebra_evpn_mac_in_use(zmac))
2329 zebra_evpn_mac_del(zevpn, zmac);
2330
2331 return 0;
2332 }