]> git.proxmox.com Git - mirror_frr.git/blob - zebra/zebra_evpn_neigh.c
Merge pull request #11202 from anlancs/fix/check_zebra_vrf_get_evpn
[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 uptime = monotime(NULL);
1722 uptime -= n->uptime;
1723
1724 frrtime_to_interval(uptime, up_str, sizeof(up_str));
1725
1726 ipaddr2str(&n->ip, buf2, sizeof(buf2));
1727 prefix_mac2str(&n->emac, buf1, sizeof(buf1));
1728 type_str = CHECK_FLAG(n->flags, ZEBRA_NEIGH_LOCAL) ? "local" : "remote";
1729 state_str = IS_ZEBRA_NEIGH_ACTIVE(n) ? "active" : "inactive";
1730 vty = (struct vty *)ctxt;
1731 if (json == NULL) {
1732 bool sync_info = false;
1733
1734 vty_out(vty, "IP: %s\n",
1735 ipaddr2str(&n->ip, buf2, sizeof(buf2)));
1736 vty_out(vty, " Type: %s\n", type_str);
1737 vty_out(vty, " State: %s\n", state_str);
1738 vty_out(vty, " Uptime: %s\n", up_str);
1739 vty_out(vty, " MAC: %s\n",
1740 prefix_mac2str(&n->emac, buf1, sizeof(buf1)));
1741 vty_out(vty, " Sync-info:");
1742 if (CHECK_FLAG(n->flags, ZEBRA_NEIGH_LOCAL_INACTIVE)) {
1743 vty_out(vty, " local-inactive");
1744 sync_info = true;
1745 }
1746 if (CHECK_FLAG(n->flags, ZEBRA_NEIGH_ES_PEER_PROXY)) {
1747 vty_out(vty, " peer-proxy");
1748 sync_info = true;
1749 }
1750 if (CHECK_FLAG(n->flags, ZEBRA_NEIGH_ES_PEER_ACTIVE)) {
1751 vty_out(vty, " peer-active");
1752 sync_info = true;
1753 }
1754 if (n->hold_timer) {
1755 vty_out(vty, " (ht: %s)",
1756 thread_timer_to_hhmmss(thread_buf,
1757 sizeof(thread_buf),
1758 n->hold_timer));
1759 sync_info = true;
1760 }
1761 if (!sync_info)
1762 vty_out(vty, " -");
1763 vty_out(vty, "\n");
1764 } else {
1765 json_object_string_add(json, "uptime", up_str);
1766 json_object_string_add(json, "ip", buf2);
1767 json_object_string_add(json, "type", type_str);
1768 json_object_string_add(json, "state", state_str);
1769 json_object_string_add(json, "mac", buf1);
1770 if (CHECK_FLAG(n->flags, ZEBRA_NEIGH_LOCAL_INACTIVE))
1771 json_object_boolean_true_add(json, "localInactive");
1772 if (CHECK_FLAG(n->flags, ZEBRA_NEIGH_ES_PEER_PROXY))
1773 json_object_boolean_true_add(json, "peerProxy");
1774 if (CHECK_FLAG(n->flags, ZEBRA_NEIGH_ES_PEER_ACTIVE))
1775 json_object_boolean_true_add(json, "peerActive");
1776 if (n->hold_timer)
1777 json_object_string_add(
1778 json, "peerActiveHold",
1779 thread_timer_to_hhmmss(thread_buf,
1780 sizeof(thread_buf),
1781 n->hold_timer));
1782 }
1783 if (CHECK_FLAG(n->flags, ZEBRA_NEIGH_REMOTE)) {
1784 if (n->mac->es) {
1785 if (json)
1786 json_object_string_add(json, "remoteEs",
1787 n->mac->es->esi_str);
1788 else
1789 vty_out(vty, " Remote ES: %s\n",
1790 n->mac->es->esi_str);
1791 } else {
1792 if (json)
1793 json_object_string_addf(json, "remoteVtep",
1794 "%pI4", &n->r_vtep_ip);
1795 else
1796 vty_out(vty, " Remote VTEP: %pI4\n",
1797 &n->r_vtep_ip);
1798 }
1799 }
1800 if (CHECK_FLAG(n->flags, ZEBRA_NEIGH_DEF_GW)) {
1801 if (!json) {
1802 vty_out(vty, " Flags: Default-gateway");
1803 flags_present = true;
1804 } else
1805 json_object_boolean_true_add(json, "defaultGateway");
1806 }
1807 if (CHECK_FLAG(n->flags, ZEBRA_NEIGH_ROUTER_FLAG)) {
1808 if (!json) {
1809 vty_out(vty,
1810 flags_present ? " ,Router" : " Flags: Router");
1811 flags_present = true;
1812 }
1813 }
1814 if (json == NULL) {
1815 if (flags_present)
1816 vty_out(vty, "\n");
1817 vty_out(vty, " Local Seq: %u Remote Seq: %u\n", n->loc_seq,
1818 n->rem_seq);
1819
1820 if (CHECK_FLAG(n->flags, ZEBRA_NEIGH_DUPLICATE)) {
1821 vty_out(vty, " Duplicate, detected at %s",
1822 time_to_string(n->dad_dup_detect_time,
1823 timebuf));
1824 } else if (n->dad_count) {
1825 monotime_since(&n->detect_start_time,
1826 &detect_start_time);
1827 if (detect_start_time.tv_sec <= zvrf->dad_time) {
1828 time_to_string(n->detect_start_time.tv_sec,
1829 timebuf);
1830 vty_out(vty,
1831 " Duplicate detection started at %s, detection count %u\n",
1832 timebuf, n->dad_count);
1833 }
1834 }
1835 } else {
1836 json_object_int_add(json, "localSequence", n->loc_seq);
1837 json_object_int_add(json, "remoteSequence", n->rem_seq);
1838 json_object_int_add(json, "detectionCount", n->dad_count);
1839 if (CHECK_FLAG(n->flags, ZEBRA_NEIGH_DUPLICATE))
1840 json_object_boolean_true_add(json, "isDuplicate");
1841 else
1842 json_object_boolean_false_add(json, "isDuplicate");
1843 }
1844 }
1845
1846 void zebra_evpn_print_neigh_hdr(struct vty *vty, struct neigh_walk_ctx *wctx)
1847 {
1848 vty_out(vty, "Flags: I=local-inactive, P=peer-active, X=peer-proxy\n");
1849 vty_out(vty, "%*s %-6s %-5s %-8s %-17s %-30s %s\n", -wctx->addr_width,
1850 "Neighbor", "Type", "Flags", "State", "MAC", "Remote ES/VTEP",
1851 "Seq #'s");
1852 }
1853
1854 static char *zebra_evpn_print_neigh_flags(struct zebra_neigh *n,
1855 char *flags_buf,
1856 uint32_t flags_buf_sz)
1857 {
1858 snprintf(flags_buf, flags_buf_sz, "%s%s%s",
1859 (n->flags & ZEBRA_NEIGH_ES_PEER_ACTIVE) ?
1860 "P" : "",
1861 (n->flags & ZEBRA_NEIGH_ES_PEER_PROXY) ?
1862 "X" : "",
1863 (n->flags & ZEBRA_NEIGH_LOCAL_INACTIVE) ?
1864 "I" : "");
1865
1866 return flags_buf;
1867 }
1868
1869 /*
1870 * Print neighbor hash entry - called for display of all neighbors.
1871 */
1872 void zebra_evpn_print_neigh_hash(struct hash_bucket *bucket, void *ctxt)
1873 {
1874 struct vty *vty;
1875 json_object *json_evpn = NULL, *json_row = NULL;
1876 struct zebra_neigh *n;
1877 char buf1[ETHER_ADDR_STRLEN];
1878 char buf2[INET6_ADDRSTRLEN];
1879 char addr_buf[PREFIX_STRLEN];
1880 struct neigh_walk_ctx *wctx = ctxt;
1881 const char *state_str;
1882 char flags_buf[6];
1883
1884 vty = wctx->vty;
1885 json_evpn = wctx->json;
1886 n = (struct zebra_neigh *)bucket->data;
1887
1888 if (json_evpn)
1889 json_row = json_object_new_object();
1890
1891 prefix_mac2str(&n->emac, buf1, sizeof(buf1));
1892 ipaddr2str(&n->ip, buf2, sizeof(buf2));
1893 state_str = IS_ZEBRA_NEIGH_ACTIVE(n) ? "active" : "inactive";
1894 if (CHECK_FLAG(n->flags, ZEBRA_NEIGH_LOCAL)) {
1895 if (wctx->flags & SHOW_REMOTE_NEIGH_FROM_VTEP)
1896 return;
1897
1898 if (json_evpn == NULL) {
1899 vty_out(vty, "%*s %-6s %-5s %-8s %-17s %-30s %u/%u\n",
1900 -wctx->addr_width, buf2, "local",
1901 zebra_evpn_print_neigh_flags(n, flags_buf,
1902 sizeof(flags_buf)), state_str, buf1,
1903 "", n->loc_seq, n->rem_seq);
1904 } else {
1905 json_object_string_add(json_row, "type", "local");
1906 json_object_string_add(json_row, "state", state_str);
1907 json_object_string_add(json_row, "mac", buf1);
1908 if (CHECK_FLAG(n->flags, ZEBRA_NEIGH_DEF_GW))
1909 json_object_boolean_true_add(json_row,
1910 "defaultGateway");
1911 json_object_int_add(json_row, "localSequence",
1912 n->loc_seq);
1913 json_object_int_add(json_row, "remoteSequence",
1914 n->rem_seq);
1915 json_object_int_add(json_row, "detectionCount",
1916 n->dad_count);
1917 if (CHECK_FLAG(n->flags, ZEBRA_NEIGH_DUPLICATE))
1918 json_object_boolean_true_add(json_row,
1919 "isDuplicate");
1920 else
1921 json_object_boolean_false_add(json_row,
1922 "isDuplicate");
1923 }
1924 wctx->count++;
1925 } else if (CHECK_FLAG(n->flags, ZEBRA_NEIGH_REMOTE)) {
1926 if ((wctx->flags & SHOW_REMOTE_NEIGH_FROM_VTEP)
1927 && !IPV4_ADDR_SAME(&n->r_vtep_ip, &wctx->r_vtep_ip))
1928 return;
1929
1930 if (json_evpn == NULL) {
1931 if ((wctx->flags & SHOW_REMOTE_NEIGH_FROM_VTEP)
1932 && (wctx->count == 0))
1933 zebra_evpn_print_neigh_hdr(vty, wctx);
1934
1935 if (n->mac->es == NULL)
1936 inet_ntop(AF_INET, &n->r_vtep_ip,
1937 addr_buf, sizeof(addr_buf));
1938
1939 vty_out(vty, "%*s %-6s %-5s %-8s %-17s %-30s %u/%u\n",
1940 -wctx->addr_width, buf2, "remote",
1941 zebra_evpn_print_neigh_flags(n, flags_buf,
1942 sizeof(flags_buf)), state_str, buf1,
1943 n->mac->es ? n->mac->es->esi_str : addr_buf,
1944 n->loc_seq, n->rem_seq);
1945 } else {
1946 json_object_string_add(json_row, "type", "remote");
1947 json_object_string_add(json_row, "state", state_str);
1948 json_object_string_add(json_row, "mac", buf1);
1949 if (n->mac->es)
1950 json_object_string_add(json_row, "remoteEs",
1951 n->mac->es->esi_str);
1952 else
1953 json_object_string_addf(json_row, "remoteVtep",
1954 "%pI4", &n->r_vtep_ip);
1955 if (CHECK_FLAG(n->flags, ZEBRA_NEIGH_DEF_GW))
1956 json_object_boolean_true_add(json_row,
1957 "defaultGateway");
1958 json_object_int_add(json_row, "localSequence",
1959 n->loc_seq);
1960 json_object_int_add(json_row, "remoteSequence",
1961 n->rem_seq);
1962 json_object_int_add(json_row, "detectionCount",
1963 n->dad_count);
1964 if (CHECK_FLAG(n->flags, ZEBRA_NEIGH_DUPLICATE))
1965 json_object_boolean_true_add(json_row,
1966 "isDuplicate");
1967 else
1968 json_object_boolean_false_add(json_row,
1969 "isDuplicate");
1970 }
1971 wctx->count++;
1972 }
1973
1974 if (json_evpn)
1975 json_object_object_add(json_evpn, buf2, json_row);
1976 }
1977
1978 /*
1979 * Print neighbor hash entry in detail - called for display of all neighbors.
1980 */
1981 void zebra_evpn_print_neigh_hash_detail(struct hash_bucket *bucket, void *ctxt)
1982 {
1983 struct vty *vty;
1984 json_object *json_evpn = NULL, *json_row = NULL;
1985 struct zebra_neigh *n;
1986 char buf[INET6_ADDRSTRLEN];
1987 struct neigh_walk_ctx *wctx = ctxt;
1988
1989 vty = wctx->vty;
1990 json_evpn = wctx->json;
1991 n = (struct zebra_neigh *)bucket->data;
1992 if (!n)
1993 return;
1994
1995 ipaddr2str(&n->ip, buf, sizeof(buf));
1996 if (json_evpn)
1997 json_row = json_object_new_object();
1998
1999 zebra_evpn_print_neigh(n, vty, json_row);
2000
2001 if (json_evpn)
2002 json_object_object_add(json_evpn, buf, json_row);
2003 }
2004
2005 void zebra_evpn_print_dad_neigh_hash(struct hash_bucket *bucket, void *ctxt)
2006 {
2007 struct zebra_neigh *nbr;
2008
2009 nbr = (struct zebra_neigh *)bucket->data;
2010 if (!nbr)
2011 return;
2012
2013 if (CHECK_FLAG(nbr->flags, ZEBRA_NEIGH_DUPLICATE))
2014 zebra_evpn_print_neigh_hash(bucket, ctxt);
2015 }
2016
2017 void zebra_evpn_print_dad_neigh_hash_detail(struct hash_bucket *bucket,
2018 void *ctxt)
2019 {
2020 struct zebra_neigh *nbr;
2021
2022 nbr = (struct zebra_neigh *)bucket->data;
2023 if (!nbr)
2024 return;
2025
2026 if (CHECK_FLAG(nbr->flags, ZEBRA_NEIGH_DUPLICATE))
2027 zebra_evpn_print_neigh_hash_detail(bucket, ctxt);
2028 }
2029
2030 void zebra_evpn_neigh_remote_macip_add(struct zebra_evpn *zevpn,
2031 struct zebra_vrf *zvrf,
2032 const struct ipaddr *ipaddr,
2033 struct zebra_mac *mac,
2034 struct in_addr vtep_ip, uint8_t flags,
2035 uint32_t seq)
2036 {
2037 struct zebra_neigh *n;
2038 int update_neigh = 0;
2039 struct zebra_mac *old_mac = NULL;
2040 bool old_static = false;
2041 bool do_dad = false;
2042 bool is_dup_detect = false;
2043 bool is_router;
2044
2045 assert(mac);
2046 is_router = !!CHECK_FLAG(flags, ZEBRA_MACIP_TYPE_ROUTER_FLAG);
2047
2048 /* Check if the remote neighbor itself is unknown or has a
2049 * change. If so, create or update and then install the entry.
2050 */
2051 n = zebra_evpn_neigh_lookup(zevpn, ipaddr);
2052 if (!n || !CHECK_FLAG(n->flags, ZEBRA_NEIGH_REMOTE)
2053 || is_router != !!CHECK_FLAG(n->flags, ZEBRA_NEIGH_ROUTER_FLAG)
2054 || (memcmp(&n->emac, &mac->macaddr, sizeof(struct ethaddr)) != 0)
2055 || !IPV4_ADDR_SAME(&n->r_vtep_ip, &vtep_ip) || seq != n->rem_seq)
2056 update_neigh = 1;
2057
2058 if (update_neigh) {
2059 if (!n) {
2060 n = zebra_evpn_neigh_add(zevpn, ipaddr, &mac->macaddr,
2061 mac, 0);
2062 } else {
2063 /* When host moves but changes its (MAC,IP)
2064 * binding, BGP may install a MACIP entry that
2065 * corresponds to "older" location of the host
2066 * in transient situations (because {IP1,M1}
2067 * is a different route from {IP1,M2}). Check
2068 * the sequence number and ignore this update
2069 * if appropriate.
2070 */
2071
2072 if (!zebra_evpn_neigh_is_bgp_seq_ok(
2073 zevpn, n, &mac->macaddr, seq, false))
2074 return;
2075 if (CHECK_FLAG(n->flags, ZEBRA_NEIGH_LOCAL)) {
2076 old_static = zebra_evpn_neigh_is_static(n);
2077 if (IS_ZEBRA_DEBUG_EVPN_MH_NEIGH)
2078 zlog_debug(
2079 "sync->remote neigh vni %u ip %pIA mac %pEA seq %d f0x%x",
2080 n->zevpn->vni, &n->ip, &n->emac,
2081 seq, n->flags);
2082 if (IS_ZEBRA_NEIGH_ACTIVE(n))
2083 zebra_evpn_neigh_send_del_to_client(
2084 zevpn->vni, &n->ip, &n->emac,
2085 n->flags, n->state,
2086 false /*force*/);
2087 zebra_evpn_neigh_clear_sync_info(n);
2088 }
2089 if (memcmp(&n->emac, &mac->macaddr,
2090 sizeof(struct ethaddr))
2091 != 0) {
2092 /* update neigh list for macs */
2093 old_mac =
2094 zebra_evpn_mac_lookup(zevpn, &n->emac);
2095 if (old_mac) {
2096 listnode_delete(old_mac->neigh_list, n);
2097 n->mac = NULL;
2098 zebra_evpn_deref_ip2mac(zevpn, old_mac);
2099 }
2100 n->mac = mac;
2101 listnode_add_sort(mac->neigh_list, n);
2102 memcpy(&n->emac, &mac->macaddr, ETH_ALEN);
2103
2104 /* Check Neigh's curent state is local
2105 * (this is the case where neigh/host has moved
2106 * from L->R) and check previous detction
2107 * started via local learning.
2108 *
2109 * RFC-7432: A PE/VTEP that detects a MAC
2110 * mobilit event via local learning starts
2111 * an M-second timer.
2112 * VTEP-IP or seq. change along is not
2113 * considered for dup. detection.
2114 *
2115 * Mobilty event scenario-B IP-MAC binding
2116 * changed.
2117 */
2118 if ((!CHECK_FLAG(n->flags, ZEBRA_NEIGH_REMOTE))
2119 && n->dad_count)
2120 do_dad = true;
2121 }
2122 }
2123
2124 /* Set "remote" forwarding info. */
2125 UNSET_FLAG(n->flags, ZEBRA_NEIGH_ALL_LOCAL_FLAGS);
2126 n->r_vtep_ip = vtep_ip;
2127 SET_FLAG(n->flags, ZEBRA_NEIGH_REMOTE);
2128
2129 /* Set router flag (R-bit) to this Neighbor entry */
2130 if (CHECK_FLAG(flags, ZEBRA_MACIP_TYPE_ROUTER_FLAG))
2131 SET_FLAG(n->flags, ZEBRA_NEIGH_ROUTER_FLAG);
2132 else
2133 UNSET_FLAG(n->flags, ZEBRA_NEIGH_ROUTER_FLAG);
2134
2135 /* Check old or new MAC detected as duplicate,
2136 * inherit duplicate flag to this neigh.
2137 */
2138 if (zebra_evpn_ip_inherit_dad_from_mac(zvrf, old_mac, mac, n)) {
2139 flog_warn(
2140 EC_ZEBRA_DUP_IP_INHERIT_DETECTED,
2141 "VNI %u: MAC %pEA IP %pIA detected as duplicate during remote update, inherit duplicate from MAC",
2142 zevpn->vni, &mac->macaddr, &n->ip);
2143 }
2144
2145 /* Check duplicate address detection for IP */
2146 zebra_evpn_dup_addr_detect_for_neigh(
2147 zvrf, n, n->r_vtep_ip, do_dad, &is_dup_detect, false);
2148 /* Install the entry. */
2149 if (!is_dup_detect)
2150 zebra_evpn_rem_neigh_install(zevpn, n, old_static);
2151 }
2152
2153 /* Update seq number. */
2154 n->rem_seq = seq;
2155 }
2156
2157 int zebra_evpn_neigh_gw_macip_add(struct interface *ifp,
2158 struct zebra_evpn *zevpn, struct ipaddr *ip,
2159 struct zebra_mac *mac)
2160 {
2161 struct zebra_neigh *n;
2162
2163 assert(mac);
2164
2165 n = zebra_evpn_neigh_lookup(zevpn, ip);
2166 if (!n)
2167 n = zebra_evpn_neigh_add(zevpn, ip, &mac->macaddr, mac, 0);
2168
2169 /* Set "local" forwarding info. */
2170 SET_FLAG(n->flags, ZEBRA_NEIGH_LOCAL);
2171 ZEBRA_NEIGH_SET_ACTIVE(n);
2172 memcpy(&n->emac, &mac->macaddr, ETH_ALEN);
2173 n->ifindex = ifp->ifindex;
2174
2175 /* Only advertise in BGP if the knob is enabled */
2176 if (advertise_gw_macip_enabled(zevpn)) {
2177
2178 SET_FLAG(n->flags, ZEBRA_NEIGH_DEF_GW);
2179 /* Set Router flag (R-bit) */
2180 if (ip->ipa_type == IPADDR_V6)
2181 SET_FLAG(n->flags, ZEBRA_NEIGH_ROUTER_FLAG);
2182
2183 if (IS_ZEBRA_DEBUG_VXLAN)
2184 zlog_debug(
2185 "SVI %s(%u) L2-VNI %u, sending GW MAC %pEA IP %pIA add to BGP with flags 0x%x",
2186 ifp->name, ifp->ifindex, zevpn->vni,
2187 &mac->macaddr, ip, n->flags);
2188
2189 zebra_evpn_neigh_send_add_to_client(
2190 zevpn->vni, ip, &n->emac, n->mac, n->flags, n->loc_seq);
2191 } else if (advertise_svi_macip_enabled(zevpn)) {
2192
2193 SET_FLAG(n->flags, ZEBRA_NEIGH_SVI_IP);
2194 if (IS_ZEBRA_DEBUG_VXLAN)
2195 zlog_debug(
2196 "SVI %s(%u) L2-VNI %u, sending SVI MAC %pEA IP %pIA add to BGP with flags 0x%x",
2197 ifp->name, ifp->ifindex, zevpn->vni,
2198 &mac->macaddr, ip, n->flags);
2199
2200 zebra_evpn_neigh_send_add_to_client(
2201 zevpn->vni, ip, &n->emac, n->mac, n->flags, n->loc_seq);
2202 }
2203
2204 return 0;
2205 }
2206
2207 void zebra_evpn_neigh_remote_uninstall(struct zebra_evpn *zevpn,
2208 struct zebra_vrf *zvrf,
2209 struct zebra_neigh *n,
2210 struct zebra_mac *mac,
2211 const struct ipaddr *ipaddr)
2212 {
2213 if (zvrf->dad_freeze && CHECK_FLAG(n->flags, ZEBRA_NEIGH_DUPLICATE)
2214 && CHECK_FLAG(n->flags, ZEBRA_NEIGH_REMOTE)
2215 && (memcmp(n->emac.octet, mac->macaddr.octet, ETH_ALEN) == 0)) {
2216 struct interface *vlan_if;
2217
2218 vlan_if = zevpn_map_to_svi(zevpn);
2219 if (IS_ZEBRA_DEBUG_VXLAN)
2220 zlog_debug(
2221 "%s: IP %pIA (flags 0x%x intf %s) is remote and duplicate, read kernel for local entry",
2222 __func__, ipaddr, n->flags,
2223 vlan_if ? vlan_if->name : "Unknown");
2224 if (vlan_if)
2225 neigh_read_specific_ip(ipaddr, vlan_if);
2226 }
2227
2228 /* When the MAC changes for an IP, it is possible the
2229 * client may update the new MAC before trying to delete the
2230 * "old" neighbor (as these are two different MACIP routes).
2231 * Do the delete only if the MAC matches.
2232 */
2233 if (!memcmp(n->emac.octet, mac->macaddr.octet, ETH_ALEN)) {
2234 if (CHECK_FLAG(n->flags, ZEBRA_NEIGH_LOCAL)) {
2235 zebra_evpn_sync_neigh_del(n);
2236 } else if (CHECK_FLAG(n->flags, ZEBRA_NEIGH_REMOTE)) {
2237 zebra_evpn_neigh_uninstall(zevpn, n);
2238 zebra_evpn_neigh_del(zevpn, n);
2239 zebra_evpn_deref_ip2mac(zevpn, mac);
2240 }
2241 }
2242 }
2243
2244 int zebra_evpn_neigh_del_ip(struct zebra_evpn *zevpn, const struct ipaddr *ip)
2245 {
2246 struct zebra_neigh *n;
2247 struct zebra_mac *zmac;
2248 bool old_bgp_ready;
2249 bool new_bgp_ready;
2250 struct zebra_vrf *zvrf;
2251
2252 /* If entry doesn't exist, nothing to do. */
2253 n = zebra_evpn_neigh_lookup(zevpn, ip);
2254 if (!n)
2255 return 0;
2256
2257 zmac = zebra_evpn_mac_lookup(zevpn, &n->emac);
2258 if (!zmac) {
2259 if (IS_ZEBRA_DEBUG_VXLAN)
2260 zlog_debug(
2261 "Trying to del a neigh %pIA without a mac %pEA on VNI %u",
2262 ip, &n->emac,
2263 zevpn->vni);
2264
2265 return 0;
2266 }
2267
2268 /* If it is a remote entry, the kernel has aged this out or someone has
2269 * deleted it, it needs to be re-installed as FRR is the owner.
2270 */
2271 if (CHECK_FLAG(n->flags, ZEBRA_NEIGH_REMOTE)) {
2272 zebra_evpn_rem_neigh_install(zevpn, n, false /*was_static*/);
2273 return 0;
2274 }
2275
2276 /* if this is a sync entry it cannot be dropped re-install it in
2277 * the dataplane
2278 */
2279 old_bgp_ready = zebra_evpn_neigh_is_ready_for_bgp(n);
2280 if (zebra_evpn_neigh_is_static(n)) {
2281 if (IS_ZEBRA_DEBUG_EVPN_MH_NEIGH)
2282 zlog_debug("re-add sync neigh vni %u ip %pIA mac %pEA 0x%x",
2283 n->zevpn->vni, &n->ip, &n->emac,
2284 n->flags);
2285
2286 if (!CHECK_FLAG(n->flags, ZEBRA_NEIGH_LOCAL_INACTIVE))
2287 SET_FLAG(n->flags, ZEBRA_NEIGH_LOCAL_INACTIVE);
2288 /* inform-bgp about change in local-activity if any */
2289 new_bgp_ready = zebra_evpn_neigh_is_ready_for_bgp(n);
2290 zebra_evpn_neigh_send_add_del_to_client(n, old_bgp_ready,
2291 new_bgp_ready);
2292
2293 /* re-install the entry in the kernel */
2294 zebra_evpn_sync_neigh_dp_install(n, false /* set_inactive */,
2295 false /* force_clear_static */,
2296 __func__);
2297
2298 return 0;
2299 }
2300
2301 zvrf = zevpn->vxlan_if->vrf->info;
2302 if (!zvrf) {
2303 zlog_debug("%s: VNI %u vrf lookup failed.", __func__,
2304 zevpn->vni);
2305 return -1;
2306 }
2307
2308 /* In case of feeze action, if local neigh is in duplicate state,
2309 * Mark the Neigh as inactive before sending delete request to BGPd,
2310 * If BGPd has remote entry, it will re-install
2311 */
2312 if (zvrf->dad_freeze && CHECK_FLAG(n->flags, ZEBRA_NEIGH_DUPLICATE))
2313 ZEBRA_NEIGH_SET_INACTIVE(n);
2314
2315 /* Remove neighbor from BGP. */
2316 zebra_evpn_neigh_send_del_to_client(zevpn->vni, &n->ip, &n->emac,
2317 n->flags, n->state,
2318 false /* force */);
2319
2320 /* Delete this neighbor entry. */
2321 zebra_evpn_neigh_del(zevpn, n);
2322
2323 /* see if the AUTO mac needs to be deleted */
2324 if (CHECK_FLAG(zmac->flags, ZEBRA_MAC_AUTO)
2325 && !zebra_evpn_mac_in_use(zmac))
2326 zebra_evpn_mac_del(zevpn, zmac);
2327
2328 return 0;
2329 }