]> git.proxmox.com Git - mirror_frr.git/blob - zebra/zebra_evpn_neigh.c
Merge pull request #8639 from idryzhov/isis-new-bfd-lib
[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 zebra_neigh_t *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 zebra_neigh_t *n1 = p1;
67 const zebra_neigh_t *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 (memcmp(&n1->ip, &n2->ip, sizeof(struct ipaddr)) == 0);
76 }
77
78 int neigh_list_cmp(void *p1, void *p2)
79 {
80 const zebra_neigh_t *n1 = p1;
81 const zebra_neigh_t *n2 = p2;
82
83 return memcmp(&n1->ip, &n2->ip, sizeof(struct ipaddr));
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(zebra_evpn_t *zevpn)
92 {
93 unsigned int i;
94 uint32_t num_neighs = 0;
95 struct hash *hash;
96 struct hash_bucket *hb;
97 zebra_neigh_t *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 = (zebra_neigh_t *)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 zebra_neigh_t *n;
121 char buf[INET6_ADDRSTRLEN];
122 struct neigh_walk_ctx *wctx = ctxt;
123 int width;
124
125 n = (zebra_neigh_t *)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(zebra_mac_t *zmac)
137 {
138 zebra_neigh_t *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(zebra_evpn_t *zevpn, zebra_neigh_t *n,
154 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 zebra_neigh_t *n;
183 struct neigh_walk_ctx *wctx = ctxt;
184
185 n = (zebra_neigh_t *)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 zebra_neigh_t *tmp_n = p;
198 zebra_neigh_t *n;
199
200 n = XCALLOC(MTYPE_NEIGH, sizeof(zebra_neigh_t));
201 *n = *tmp_n;
202
203 return ((void *)n);
204 }
205
206 static void zebra_evpn_local_neigh_ref_mac(zebra_neigh_t *n,
207 struct ethaddr *macaddr,
208 zebra_mac_t *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(zebra_neigh_t *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, struct ipaddr *ip,
288 struct ethaddr *macaddr,
289 zebra_mac_t *zmac, uint32_t neigh_flags,
290 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(zebra_neigh_t *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(zebra_neigh_t *n, bool old_n_static,
359 bool new_n_static, bool defer_n_dp,
360 bool defer_mac_dp, const char *caller)
361 {
362 zebra_mac_t *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 int zebra_evpn_neigh_hold_exp_cb(struct thread *t)
415 {
416 zebra_neigh_t *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 0;
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 return 0;
453 }
454
455 static inline void zebra_evpn_neigh_start_hold_timer(zebra_neigh_t *n)
456 {
457 if (n->hold_timer)
458 return;
459
460 if (IS_ZEBRA_DEBUG_EVPN_MH_NEIGH)
461 zlog_debug("sync-neigh vni %u ip %pIA mac %pEA 0x%x hold start",
462 n->zevpn->vni, &n->ip, &n->emac, n->flags);
463 thread_add_timer(zrouter.master, zebra_evpn_neigh_hold_exp_cb, n,
464 zmh_info->neigh_hold_time, &n->hold_timer);
465 }
466
467 static void zebra_evpn_local_neigh_deref_mac(zebra_neigh_t *n,
468 bool send_mac_update)
469 {
470 zebra_mac_t *mac = n->mac;
471 zebra_evpn_t *zevpn = n->zevpn;
472 bool old_static;
473 bool new_static;
474
475 n->mac = NULL;
476 if (!mac)
477 return;
478
479 if ((n->flags & ZEBRA_NEIGH_ALL_PEER_FLAGS) && mac->sync_neigh_cnt) {
480 old_static = zebra_evpn_mac_is_static(mac);
481 --mac->sync_neigh_cnt;
482 new_static = zebra_evpn_mac_is_static(mac);
483 if (IS_ZEBRA_DEBUG_EVPN_MH_NEIGH)
484 zlog_debug(
485 "sync-neigh deref mac vni %u ip %pIA mac %pEA ref %d",
486 n->zevpn->vni, &n->ip, &n->emac,
487 mac->sync_neigh_cnt);
488 if ((old_static != new_static) && send_mac_update)
489 /* program the local mac in the kernel */
490 zebra_evpn_sync_mac_dp_install(
491 mac, false /* set_inactive */,
492 false /* force_clear_static */, __func__);
493 }
494
495 listnode_delete(mac->neigh_list, n);
496 zebra_evpn_deref_ip2mac(zevpn, mac);
497 }
498
499 bool zebra_evpn_neigh_is_bgp_seq_ok(zebra_evpn_t *zevpn, zebra_neigh_t *n,
500 struct ethaddr *macaddr, uint32_t seq,
501 bool sync)
502 {
503 uint32_t tmp_seq;
504 const char *n_type;
505
506 if (CHECK_FLAG(n->flags, ZEBRA_NEIGH_LOCAL)) {
507 tmp_seq = n->loc_seq;
508 n_type = "local";
509 } else {
510 tmp_seq = n->rem_seq;
511 n_type = "remote";
512 }
513
514 if (seq < tmp_seq) {
515 /* if the neigh was never advertised to bgp we must accept
516 * whatever sequence number bgp sends
517 * XXX - check with Vivek
518 */
519 if (CHECK_FLAG(n->flags, ZEBRA_NEIGH_LOCAL)
520 && !zebra_evpn_neigh_is_ready_for_bgp(n)) {
521 if (IS_ZEBRA_DEBUG_EVPN_MH_NEIGH
522 || IS_ZEBRA_DEBUG_VXLAN)
523 zlog_debug(
524 "%s-macip accept vni %u %s mac %pEA IP %pIA lower seq %u f 0x%x",
525 sync ? "sync" : "remote", zevpn->vni,
526 n_type, macaddr, &n->ip,
527 tmp_seq, n->flags);
528 return true;
529 }
530
531 if (IS_ZEBRA_DEBUG_EVPN_MH_NEIGH || IS_ZEBRA_DEBUG_VXLAN)
532 zlog_debug(
533 "%s-macip ignore vni %u %s mac %pEA IP %pIA as existing has higher seq %u f 0x%x",
534 sync ? "sync" : "remote", zevpn->vni, n_type,
535 macaddr, &n->ip, tmp_seq, n->flags);
536 return false;
537 }
538
539 return true;
540 }
541
542 /*
543 * Add neighbor entry.
544 */
545 static zebra_neigh_t *zebra_evpn_neigh_add(zebra_evpn_t *zevpn,
546 struct ipaddr *ip,
547 struct ethaddr *mac,
548 zebra_mac_t *zmac, uint32_t n_flags)
549 {
550 zebra_neigh_t tmp_n;
551 zebra_neigh_t *n = NULL;
552
553 memset(&tmp_n, 0, sizeof(zebra_neigh_t));
554 memcpy(&tmp_n.ip, ip, sizeof(struct ipaddr));
555 n = hash_get(zevpn->neigh_table, &tmp_n, zebra_evpn_neigh_alloc);
556 assert(n);
557
558 n->state = ZEBRA_NEIGH_INACTIVE;
559 n->zevpn = zevpn;
560 n->dad_ip_auto_recovery_timer = NULL;
561 n->flags = n_flags;
562 n->uptime = monotime(NULL);
563
564 if (!zmac)
565 zmac = zebra_evpn_mac_lookup(zevpn, mac);
566 zebra_evpn_local_neigh_ref_mac(n, mac, zmac,
567 false /* send_mac_update */);
568
569 return n;
570 }
571
572 /*
573 * Delete neighbor entry.
574 */
575 int zebra_evpn_neigh_del(zebra_evpn_t *zevpn, zebra_neigh_t *n)
576 {
577 zebra_neigh_t *tmp_n;
578
579 if (n->mac)
580 listnode_delete(n->mac->neigh_list, n);
581
582 /* Cancel auto recovery */
583 THREAD_OFF(n->dad_ip_auto_recovery_timer);
584
585 /* Cancel proxy hold timer */
586 zebra_evpn_neigh_stop_hold_timer(n);
587
588 /* Free the VNI hash entry and allocated memory. */
589 tmp_n = hash_release(zevpn->neigh_table, n);
590 XFREE(MTYPE_NEIGH, tmp_n);
591
592 return 0;
593 }
594
595 void zebra_evpn_sync_neigh_del(zebra_neigh_t *n)
596 {
597 bool old_n_static;
598 bool new_n_static;
599
600 if (IS_ZEBRA_DEBUG_EVPN_MH_NEIGH)
601 zlog_debug("sync-neigh del vni %u ip %pIA mac %pEA f 0x%x",
602 n->zevpn->vni, &n->ip, &n->emac, n->flags);
603
604 old_n_static = zebra_evpn_neigh_is_static(n);
605 UNSET_FLAG(n->flags, ZEBRA_NEIGH_ES_PEER_PROXY);
606 if (CHECK_FLAG(n->flags, ZEBRA_NEIGH_ES_PEER_ACTIVE))
607 zebra_evpn_neigh_start_hold_timer(n);
608 new_n_static = zebra_evpn_neigh_is_static(n);
609
610 if (old_n_static != new_n_static)
611 zebra_evpn_sync_neigh_static_chg(
612 n, old_n_static, new_n_static, false /*defer-dp*/,
613 false /*defer_mac_dp*/, __func__);
614 }
615
616 zebra_neigh_t *
617 zebra_evpn_proc_sync_neigh_update(zebra_evpn_t *zevpn, zebra_neigh_t *n,
618 uint16_t ipa_len, struct ipaddr *ipaddr,
619 uint8_t flags, uint32_t seq, esi_t *esi,
620 struct sync_mac_ip_ctx *ctx)
621 {
622 struct interface *ifp = NULL;
623 bool is_router;
624 zebra_mac_t *mac = ctx->mac;
625 uint32_t tmp_seq;
626 bool old_router = false;
627 bool old_bgp_ready = false;
628 bool new_bgp_ready;
629 bool inform_dataplane = false;
630 bool inform_bgp = false;
631 bool old_mac_static;
632 bool new_mac_static;
633 bool set_dp_inactive = false;
634 bool created;
635 ifindex_t ifindex = 0;
636
637 /* locate l3-svi */
638 ifp = zevpn_map_to_svi(zevpn);
639 if (ifp)
640 ifindex = ifp->ifindex;
641
642 is_router = !!CHECK_FLAG(flags, ZEBRA_MACIP_TYPE_ROUTER_FLAG);
643 old_mac_static = zebra_evpn_mac_is_static(mac);
644
645 if (!n) {
646 uint32_t n_flags = 0;
647
648 /* New neighbor - create */
649 SET_FLAG(n_flags, ZEBRA_NEIGH_LOCAL);
650 if (CHECK_FLAG(flags, ZEBRA_MACIP_TYPE_PROXY_ADVERT))
651 SET_FLAG(n_flags, ZEBRA_NEIGH_ES_PEER_PROXY);
652 else
653 SET_FLAG(n_flags, ZEBRA_NEIGH_ES_PEER_ACTIVE);
654 SET_FLAG(n_flags, ZEBRA_NEIGH_LOCAL_INACTIVE);
655
656 n = zebra_evpn_neigh_add(zevpn, ipaddr, &mac->macaddr, mac,
657 n_flags);
658 n->ifindex = ifindex;
659 ZEBRA_NEIGH_SET_ACTIVE(n);
660
661 created = true;
662 inform_dataplane = true;
663 inform_bgp = true;
664 set_dp_inactive = true;
665 } else {
666 bool mac_change;
667 uint32_t old_flags = n->flags;
668 bool old_n_static;
669 bool new_n_static;
670
671 created = false;
672 old_n_static = zebra_evpn_neigh_is_static(n);
673 old_bgp_ready = zebra_evpn_neigh_is_ready_for_bgp(n);
674 old_router = !!CHECK_FLAG(n->flags, ZEBRA_NEIGH_ROUTER_FLAG);
675
676 mac_change = !!memcmp(&n->emac, &mac->macaddr, ETH_ALEN);
677
678 /* deref and clear old info */
679 if (mac_change) {
680 if (old_bgp_ready) {
681 zebra_evpn_neigh_send_del_to_client(
682 zevpn->vni, &n->ip, &n->emac, n->flags,
683 n->state, false /*force*/);
684 old_bgp_ready = false;
685 }
686 zebra_evpn_local_neigh_deref_mac(n,
687 false /*send_mac_update*/);
688 }
689 /* clear old fwd info */
690 n->rem_seq = 0;
691 n->r_vtep_ip.s_addr = 0;
692
693 /* setup new flags */
694 n->flags = 0;
695 SET_FLAG(n->flags, ZEBRA_NEIGH_LOCAL);
696 /* retain activity flag if the neigh was
697 * previously local
698 */
699 if (old_flags & ZEBRA_NEIGH_LOCAL) {
700 n->flags |= (old_flags & ZEBRA_NEIGH_LOCAL_INACTIVE);
701 } else {
702 inform_dataplane = true;
703 set_dp_inactive = true;
704 n->flags |= ZEBRA_NEIGH_LOCAL_INACTIVE;
705 }
706
707 if (CHECK_FLAG(flags, ZEBRA_MACIP_TYPE_PROXY_ADVERT))
708 SET_FLAG(n->flags, ZEBRA_NEIGH_ES_PEER_PROXY);
709 else
710 SET_FLAG(n->flags, ZEBRA_NEIGH_ES_PEER_ACTIVE);
711
712 if (CHECK_FLAG(flags, ZEBRA_MACIP_TYPE_PROXY_ADVERT)) {
713 SET_FLAG(n->flags, ZEBRA_NEIGH_ES_PEER_PROXY);
714 /* if the neigh was peer-active previously we
715 * need to keep the flag and start the
716 * holdtimer on it. the peer-active flag is
717 * cleared on holdtimer expiry.
718 */
719 if (CHECK_FLAG(old_flags, ZEBRA_NEIGH_ES_PEER_ACTIVE)) {
720 SET_FLAG(n->flags, ZEBRA_NEIGH_ES_PEER_ACTIVE);
721 zebra_evpn_neigh_start_hold_timer(n);
722 }
723 } else {
724 SET_FLAG(n->flags, ZEBRA_NEIGH_ES_PEER_ACTIVE);
725 /* stop hold timer if a peer has verified
726 * reachability
727 */
728 zebra_evpn_neigh_stop_hold_timer(n);
729 }
730 ZEBRA_NEIGH_SET_ACTIVE(n);
731
732 if (IS_ZEBRA_DEBUG_EVPN_MH_NEIGH && (old_flags != n->flags))
733 zlog_debug(
734 "sync-neigh vni %u ip %pIA mac %pEA old_f 0x%x new_f 0x%x",
735 n->zevpn->vni, &n->ip, &n->emac,
736 old_flags, n->flags);
737
738 new_n_static = zebra_evpn_neigh_is_static(n);
739 if (mac_change) {
740 set_dp_inactive = true;
741 n->flags |= ZEBRA_NEIGH_LOCAL_INACTIVE;
742 inform_dataplane = true;
743 zebra_evpn_local_neigh_ref_mac(
744 n, &mac->macaddr, mac,
745 false /*send_mac_update*/);
746 } else if (old_n_static != new_n_static) {
747 inform_dataplane = true;
748 /* if static flags have changed without a mac change
749 * we need to create the correct sync-refs against
750 * the existing mac
751 */
752 zebra_evpn_sync_neigh_static_chg(
753 n, old_n_static, new_n_static,
754 true /*defer_dp*/, true /*defer_mac_dp*/,
755 __func__);
756 }
757
758 /* Update the forwarding info. */
759 if (n->ifindex != ifindex) {
760 n->ifindex = ifindex;
761 inform_dataplane = true;
762 }
763
764 n->uptime = monotime(NULL);
765 }
766
767 /* update the neigh seq. we don't bother with the mac seq as
768 * sync_mac_update already took care of that
769 */
770 tmp_seq = MAX(n->loc_seq, seq);
771 if (tmp_seq != n->loc_seq) {
772 n->loc_seq = tmp_seq;
773 inform_bgp = true;
774 }
775
776 /* Mark Router flag (R-bit) */
777 if (is_router)
778 SET_FLAG(n->flags, ZEBRA_NEIGH_ROUTER_FLAG);
779 else
780 UNSET_FLAG(n->flags, ZEBRA_NEIGH_ROUTER_FLAG);
781
782 if (old_router != is_router)
783 inform_dataplane = true;
784
785 new_bgp_ready = zebra_evpn_neigh_is_ready_for_bgp(n);
786 if (old_bgp_ready != new_bgp_ready)
787 inform_bgp = true;
788
789 new_mac_static = zebra_evpn_mac_is_static(mac);
790 if ((old_mac_static != new_mac_static) || ctx->mac_dp_update_deferred)
791 zebra_evpn_sync_mac_dp_install(mac, ctx->mac_inactive,
792 false /* force_clear_static */,
793 __func__);
794
795 if (IS_ZEBRA_DEBUG_EVPN_MH_NEIGH)
796 zlog_debug(
797 "sync-neigh %s vni %u ip %pIA mac %pEA if %s(%d) seq %d f 0x%x%s%s",
798 created ? "created" : "updated", n->zevpn->vni,
799 &n->ip, &n->emac,
800 ifp ? ifp->name : "", ifindex, n->loc_seq, n->flags,
801 inform_bgp ? " inform_bgp" : "",
802 inform_dataplane ? " inform_dp" : "");
803
804 if (inform_dataplane)
805 zebra_evpn_sync_neigh_dp_install(n, set_dp_inactive,
806 false /* force_clear_static */,
807 __func__);
808
809 if (inform_bgp)
810 zebra_evpn_neigh_send_add_del_to_client(n, old_bgp_ready,
811 new_bgp_ready);
812
813 return n;
814 }
815
816 /*
817 * Uninstall remote neighbor from the kernel.
818 */
819 static int zebra_evpn_neigh_uninstall(zebra_evpn_t *zevpn, zebra_neigh_t *n)
820 {
821 struct interface *vlan_if;
822
823 if (!(n->flags & ZEBRA_NEIGH_REMOTE))
824 return 0;
825
826 vlan_if = zevpn_map_to_svi(zevpn);
827 if (!vlan_if)
828 return -1;
829
830 ZEBRA_NEIGH_SET_INACTIVE(n);
831 n->loc_seq = 0;
832
833 dplane_rem_neigh_delete(vlan_if, &n->ip);
834
835 return 0;
836 }
837
838 /*
839 * Free neighbor hash entry (callback)
840 */
841 static void zebra_evpn_neigh_del_hash_entry(struct hash_bucket *bucket,
842 void *arg)
843 {
844 struct neigh_walk_ctx *wctx = arg;
845 zebra_neigh_t *n = bucket->data;
846
847 if (((wctx->flags & DEL_LOCAL_NEIGH) && (n->flags & ZEBRA_NEIGH_LOCAL))
848 || ((wctx->flags & DEL_REMOTE_NEIGH)
849 && (n->flags & ZEBRA_NEIGH_REMOTE))
850 || ((wctx->flags & DEL_REMOTE_NEIGH_FROM_VTEP)
851 && (n->flags & ZEBRA_NEIGH_REMOTE)
852 && IPV4_ADDR_SAME(&n->r_vtep_ip, &wctx->r_vtep_ip))) {
853 if (wctx->upd_client && (n->flags & ZEBRA_NEIGH_LOCAL))
854 zebra_evpn_neigh_send_del_to_client(
855 wctx->zevpn->vni, &n->ip, &n->emac, n->flags,
856 n->state, false /*force*/);
857
858 if (wctx->uninstall) {
859 if (zebra_evpn_neigh_is_static(n))
860 zebra_evpn_sync_neigh_dp_install(
861 n, false /* set_inactive */,
862 true /* force_clear_static */,
863 __func__);
864 if ((n->flags & ZEBRA_NEIGH_REMOTE))
865 zebra_evpn_neigh_uninstall(wctx->zevpn, n);
866 }
867
868 zebra_evpn_neigh_del(wctx->zevpn, n);
869 }
870
871 return;
872 }
873
874 /*
875 * Delete all neighbor entries for this EVPN.
876 */
877 void zebra_evpn_neigh_del_all(zebra_evpn_t *zevpn, int uninstall,
878 int upd_client, uint32_t flags)
879 {
880 struct neigh_walk_ctx wctx;
881
882 if (!zevpn->neigh_table)
883 return;
884
885 memset(&wctx, 0, sizeof(struct neigh_walk_ctx));
886 wctx.zevpn = zevpn;
887 wctx.uninstall = uninstall;
888 wctx.upd_client = upd_client;
889 wctx.flags = flags;
890
891 hash_iterate(zevpn->neigh_table, zebra_evpn_neigh_del_hash_entry,
892 &wctx);
893 }
894
895 /*
896 * Look up neighbor hash entry.
897 */
898 zebra_neigh_t *zebra_evpn_neigh_lookup(zebra_evpn_t *zevpn, struct ipaddr *ip)
899 {
900 zebra_neigh_t tmp;
901 zebra_neigh_t *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(zebra_evpn_t *zevpn,
915 zebra_mac_t *zmac,
916 bool seq_change,
917 bool es_change)
918 {
919 zebra_neigh_t *n = NULL;
920 struct listnode *node = NULL;
921 struct zebra_vrf *zvrf = NULL;
922
923 zvrf = vrf_info_lookup(zevpn->vxlan_if->vrf_id);
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(zebra_evpn_t *zevpn,
959 zebra_mac_t *zmac)
960 {
961 zebra_neigh_t *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(zebra_evpn_t *zevpn,
992 zebra_mac_t *zmac)
993 {
994 zebra_neigh_t *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(zebra_evpn_t *zevpn,
1022 zebra_mac_t *zmac)
1023 {
1024 /* NOTE: Currently a NO-OP. */
1025 }
1026
1027 static inline void zebra_evpn_local_neigh_update_log(
1028 const char *pfx, zebra_neigh_t *n, bool is_router, bool local_inactive,
1029 bool old_bgp_ready, bool new_bgp_ready, bool inform_dataplane,
1030 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 zebra_mac_t *old_zmac,
1051 zebra_mac_t *new_zmac,
1052 zebra_neigh_t *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 int zebra_evpn_dad_ip_auto_recovery_exp(struct thread *t)
1093 {
1094 struct zebra_vrf *zvrf = NULL;
1095 zebra_neigh_t *nbr = NULL;
1096 zebra_evpn_t *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 0;
1104
1105 zevpn = zebra_evpn_lookup(nbr->zevpn->vni);
1106 if (!zevpn)
1107 return 0;
1108
1109 nbr = zebra_evpn_neigh_lookup(zevpn, &nbr->ip);
1110 if (!nbr)
1111 return 0;
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 return 0;
1137 }
1138
1139 static void
1140 zebra_evpn_dup_addr_detect_for_neigh(struct zebra_vrf *zvrf, zebra_neigh_t *nbr,
1141 struct in_addr vtep_ip, bool do_dad,
1142 bool *is_dup_detect, bool is_local)
1143 {
1144
1145 struct timeval elapsed = {0, 0};
1146 bool reset_params = false;
1147
1148 if (!zebra_evpn_do_dup_addr_detect(zvrf))
1149 return;
1150
1151 /* IP is detected as duplicate or inherit dup
1152 * state, hold on to install as remote entry
1153 * only if freeze is enabled.
1154 */
1155 if (CHECK_FLAG(nbr->flags, ZEBRA_NEIGH_DUPLICATE)) {
1156 if (IS_ZEBRA_DEBUG_VXLAN)
1157 zlog_debug(
1158 "%s: duplicate addr MAC %pEA IP %pIA flags 0x%x skip installing, learn count %u recover time %u",
1159 __func__, &nbr->emac, &nbr->ip,
1160 nbr->flags, nbr->dad_count,
1161 zvrf->dad_freeze_time);
1162
1163 if (zvrf->dad_freeze)
1164 *is_dup_detect = true;
1165
1166 /* warn-only action, neigh will be installed.
1167 * freeze action, it wil not be installed.
1168 */
1169 return;
1170 }
1171
1172 if (!do_dad)
1173 return;
1174
1175 /* Check if detection time (M-secs) expired.
1176 * Reset learn count and detection start time.
1177 * During remote mac add, count should already be 1
1178 * via local learning.
1179 */
1180 monotime_since(&nbr->detect_start_time, &elapsed);
1181 reset_params = (elapsed.tv_sec > zvrf->dad_time);
1182
1183 if (is_local && !reset_params) {
1184 /* RFC-7432: A PE/VTEP that detects a MAC mobility
1185 * event via LOCAL learning starts an M-second timer.
1186 *
1187 * NOTE: This is the START of the probe with count is
1188 * 0 during LOCAL learn event.
1189 */
1190 reset_params = !nbr->dad_count;
1191 }
1192
1193 if (reset_params) {
1194 if (IS_ZEBRA_DEBUG_VXLAN)
1195 zlog_debug(
1196 "%s: duplicate addr MAC %pEA IP %pIA flags 0x%x detection time passed, reset learn count %u",
1197 __func__, &nbr->emac, &nbr->ip,
1198 nbr->flags, nbr->dad_count);
1199 /* Reset learn count but do not start detection
1200 * during REMOTE learn event.
1201 */
1202 nbr->dad_count = 0;
1203 /* Start dup. addr detection (DAD) start time,
1204 * ONLY during LOCAL learn.
1205 */
1206 if (is_local)
1207 monotime(&nbr->detect_start_time);
1208
1209 } else if (!is_local) {
1210 /* For REMOTE IP/Neigh, increment detection count
1211 * ONLY while in probe window, once window passed,
1212 * next local learn event should trigger DAD.
1213 */
1214 nbr->dad_count++;
1215 }
1216
1217 /* For LOCAL IP/Neigh learn event, once count is reset above via either
1218 * initial/start detection time or passed the probe time, the count
1219 * needs to be incremented.
1220 */
1221 if (is_local)
1222 nbr->dad_count++;
1223
1224 if (nbr->dad_count >= zvrf->dad_max_moves) {
1225 flog_warn(
1226 EC_ZEBRA_DUP_IP_DETECTED,
1227 "VNI %u: MAC %pEA IP %pIA detected as duplicate during %s VTEP %pI4",
1228 nbr->zevpn->vni, &nbr->emac, &nbr->ip,
1229 is_local ? "local update, last" : "remote update, from",
1230 &vtep_ip);
1231
1232 SET_FLAG(nbr->flags, ZEBRA_NEIGH_DUPLICATE);
1233
1234 /* Capture Duplicate detection time */
1235 nbr->dad_dup_detect_time = monotime(NULL);
1236
1237 /* Start auto recovery timer for this IP */
1238 THREAD_OFF(nbr->dad_ip_auto_recovery_timer);
1239 if (zvrf->dad_freeze && zvrf->dad_freeze_time) {
1240 if (IS_ZEBRA_DEBUG_VXLAN)
1241 zlog_debug(
1242 "%s: duplicate addr MAC %pEA IP %pIA flags 0x%x auto recovery time %u start",
1243 __func__, &nbr->emac, &nbr->ip,
1244 nbr->flags, zvrf->dad_freeze_time);
1245
1246 thread_add_timer(zrouter.master,
1247 zebra_evpn_dad_ip_auto_recovery_exp,
1248 nbr, zvrf->dad_freeze_time,
1249 &nbr->dad_ip_auto_recovery_timer);
1250 }
1251 if (zvrf->dad_freeze)
1252 *is_dup_detect = true;
1253 }
1254 }
1255
1256 int zebra_evpn_local_neigh_update(zebra_evpn_t *zevpn, struct interface *ifp,
1257 struct ipaddr *ip, struct ethaddr *macaddr,
1258 bool is_router, bool local_inactive,
1259 bool dp_static)
1260 {
1261 struct zebra_vrf *zvrf;
1262 zebra_neigh_t *n = NULL;
1263 zebra_mac_t *zmac = NULL, *old_zmac = NULL;
1264 uint32_t old_mac_seq = 0, mac_new_seq = 0;
1265 bool upd_mac_seq = false;
1266 bool neigh_mac_change = false;
1267 bool neigh_on_hold = false;
1268 bool neigh_was_remote = false;
1269 bool do_dad = false;
1270 struct in_addr vtep_ip = {.s_addr = 0};
1271 bool inform_dataplane = false;
1272 bool created = false;
1273 bool new_static = false;
1274 bool old_bgp_ready = false;
1275 bool new_bgp_ready;
1276
1277 /* Check if the MAC exists. */
1278 zmac = zebra_evpn_mac_lookup(zevpn, macaddr);
1279 if (!zmac) {
1280 /* create a dummy MAC if the MAC is not already present */
1281 if (IS_ZEBRA_DEBUG_VXLAN)
1282 zlog_debug("AUTO MAC %pEA created for neigh %pIA on VNI %u",
1283 macaddr, ip, zevpn->vni);
1284
1285 zmac = zebra_evpn_mac_add(zevpn, macaddr);
1286 if (!zmac) {
1287 zlog_debug("Failed to add MAC %pEA VNI %u", macaddr,
1288 zevpn->vni);
1289 return -1;
1290 }
1291
1292 zebra_evpn_mac_clear_fwd_info(zmac);
1293 memset(&zmac->flags, 0, sizeof(uint32_t));
1294 SET_FLAG(zmac->flags, ZEBRA_MAC_AUTO);
1295 } else {
1296 if (CHECK_FLAG(zmac->flags, ZEBRA_MAC_REMOTE)) {
1297 /*
1298 * We don't change the MAC to local upon a neighbor
1299 * learn event, we wait for the explicit local MAC
1300 * learn. However, we have to compute its sequence
1301 * number in preparation for when it actually turns
1302 * local.
1303 */
1304 upd_mac_seq = true;
1305 }
1306 }
1307
1308 zvrf = vrf_info_lookup(zevpn->vxlan_if->vrf_id);
1309 if (!zvrf) {
1310 if (IS_ZEBRA_DEBUG_VXLAN)
1311 zlog_debug(" Unable to find vrf for: %d",
1312 zevpn->vxlan_if->vrf_id);
1313 return -1;
1314 }
1315
1316 /* Check if the neighbor exists. */
1317 n = zebra_evpn_neigh_lookup(zevpn, ip);
1318 if (!n) {
1319 /* New neighbor - create */
1320 n = zebra_evpn_neigh_add(zevpn, ip, macaddr, zmac, 0);
1321 if (!n) {
1322 flog_err(
1323 EC_ZEBRA_MAC_ADD_FAILED,
1324 "Failed to add neighbor %pIA MAC %pEA intf %s(%u) -> VNI %u",
1325 ip, macaddr, ifp->name, ifp->ifindex,
1326 zevpn->vni);
1327 return -1;
1328 }
1329 /* Set "local" forwarding info. */
1330 SET_FLAG(n->flags, ZEBRA_NEIGH_LOCAL);
1331 n->ifindex = ifp->ifindex;
1332 created = true;
1333 } else {
1334 if (CHECK_FLAG(n->flags, ZEBRA_NEIGH_LOCAL)) {
1335 bool mac_different;
1336 bool cur_is_router;
1337 bool old_local_inactive;
1338
1339 old_local_inactive = !!CHECK_FLAG(
1340 n->flags, ZEBRA_NEIGH_LOCAL_INACTIVE);
1341
1342 old_bgp_ready = zebra_evpn_neigh_is_ready_for_bgp(n);
1343
1344 /* Note any changes and see if of interest to BGP. */
1345 mac_different = !!memcmp(&n->emac, macaddr, ETH_ALEN);
1346 cur_is_router =
1347 !!CHECK_FLAG(n->flags, ZEBRA_NEIGH_ROUTER_FLAG);
1348 new_static = zebra_evpn_neigh_is_static(n);
1349 if (!mac_different && is_router == cur_is_router
1350 && old_local_inactive == local_inactive
1351 && dp_static != new_static) {
1352 if (IS_ZEBRA_DEBUG_VXLAN)
1353 zlog_debug(
1354 " Ignoring entry mac is the same and is_router == cur_is_router");
1355 n->ifindex = ifp->ifindex;
1356 return 0;
1357 }
1358
1359 old_zmac = n->mac;
1360 if (!mac_different) {
1361 /* XXX - cleanup this code duplication */
1362 bool is_neigh_freezed = false;
1363
1364 /* Only the router flag has changed. */
1365 if (is_router)
1366 SET_FLAG(n->flags,
1367 ZEBRA_NEIGH_ROUTER_FLAG);
1368 else
1369 UNSET_FLAG(n->flags,
1370 ZEBRA_NEIGH_ROUTER_FLAG);
1371
1372 if (local_inactive)
1373 SET_FLAG(n->flags,
1374 ZEBRA_NEIGH_LOCAL_INACTIVE);
1375 else
1376 UNSET_FLAG(n->flags,
1377 ZEBRA_NEIGH_LOCAL_INACTIVE);
1378 new_bgp_ready =
1379 zebra_evpn_neigh_is_ready_for_bgp(n);
1380
1381 if (dp_static != new_static)
1382 inform_dataplane = true;
1383
1384 /* Neigh is in freeze state and freeze action
1385 * is enabled, do not send update to client.
1386 */
1387 is_neigh_freezed =
1388 (zebra_evpn_do_dup_addr_detect(zvrf)
1389 && zvrf->dad_freeze
1390 && CHECK_FLAG(n->flags,
1391 ZEBRA_NEIGH_DUPLICATE));
1392
1393 zebra_evpn_local_neigh_update_log(
1394 "local", n, is_router, local_inactive,
1395 old_bgp_ready, new_bgp_ready, false,
1396 false, "flag-update");
1397
1398 if (inform_dataplane)
1399 zebra_evpn_sync_neigh_dp_install(
1400 n, false /* set_inactive */,
1401 false /* force_clear_static */,
1402 __func__);
1403
1404 /* if the neigh can no longer be advertised
1405 * remove it from bgp
1406 */
1407 if (!is_neigh_freezed) {
1408 zebra_evpn_neigh_send_add_del_to_client(
1409 n, old_bgp_ready,
1410 new_bgp_ready);
1411 } else {
1412 if (IS_ZEBRA_DEBUG_VXLAN
1413 && IS_ZEBRA_NEIGH_ACTIVE(n))
1414 zlog_debug(
1415 " Neighbor active and frozen");
1416 }
1417 return 0;
1418 }
1419
1420 /* The MAC has changed, need to issue a delete
1421 * first as this means a different MACIP route.
1422 * Also, need to do some unlinking/relinking.
1423 * We also need to update the MAC's sequence number
1424 * in different situations.
1425 */
1426 if (old_bgp_ready) {
1427 zebra_evpn_neigh_send_del_to_client(
1428 zevpn->vni, &n->ip, &n->emac, n->flags,
1429 n->state, false /*force*/);
1430 old_bgp_ready = false;
1431 }
1432 if (old_zmac) {
1433 old_mac_seq = CHECK_FLAG(old_zmac->flags,
1434 ZEBRA_MAC_REMOTE)
1435 ? old_zmac->rem_seq
1436 : old_zmac->loc_seq;
1437 neigh_mac_change = upd_mac_seq = true;
1438 zebra_evpn_local_neigh_deref_mac(
1439 n, true /* send_mac_update */);
1440 }
1441
1442 /* if mac changes abandon peer flags and tell
1443 * dataplane to clear the static flag
1444 */
1445 if (zebra_evpn_neigh_clear_sync_info(n))
1446 inform_dataplane = true;
1447 /* Update the forwarding info. */
1448 n->ifindex = ifp->ifindex;
1449
1450 /* Link to new MAC */
1451 zebra_evpn_local_neigh_ref_mac(
1452 n, macaddr, zmac, true /* send_mac_update */);
1453 } else if (CHECK_FLAG(n->flags, ZEBRA_NEIGH_REMOTE)) {
1454 /*
1455 * Neighbor has moved from remote to local. Its
1456 * MAC could have also changed as part of the move.
1457 */
1458 if (memcmp(n->emac.octet, macaddr->octet, ETH_ALEN)
1459 != 0) {
1460 old_zmac = n->mac;
1461 if (old_zmac) {
1462 old_mac_seq =
1463 CHECK_FLAG(old_zmac->flags,
1464 ZEBRA_MAC_REMOTE)
1465 ? old_zmac->rem_seq
1466 : old_zmac->loc_seq;
1467 neigh_mac_change = upd_mac_seq = true;
1468 zebra_evpn_local_neigh_deref_mac(
1469 n, true /* send_update */);
1470 }
1471
1472 /* Link to new MAC */
1473 zebra_evpn_local_neigh_ref_mac(
1474 n, macaddr, zmac, true /*send_update*/);
1475 }
1476 /* Based on Mobility event Scenario-B from the
1477 * draft, neigh's previous state was remote treat this
1478 * event for DAD.
1479 */
1480 neigh_was_remote = true;
1481 vtep_ip = n->r_vtep_ip;
1482 /* Mark appropriately */
1483 UNSET_FLAG(n->flags, ZEBRA_NEIGH_REMOTE);
1484 n->r_vtep_ip.s_addr = INADDR_ANY;
1485 SET_FLAG(n->flags, ZEBRA_NEIGH_LOCAL);
1486 n->ifindex = ifp->ifindex;
1487 }
1488 }
1489
1490 /* If MAC was previously remote, or the neighbor had a different
1491 * MAC earlier, recompute the sequence number.
1492 */
1493 if (upd_mac_seq) {
1494 uint32_t seq1, seq2;
1495
1496 seq1 = CHECK_FLAG(zmac->flags, ZEBRA_MAC_REMOTE)
1497 ? zmac->rem_seq + 1
1498 : zmac->loc_seq;
1499 seq2 = neigh_mac_change ? old_mac_seq + 1 : 0;
1500 mac_new_seq = zmac->loc_seq < MAX(seq1, seq2) ? MAX(seq1, seq2)
1501 : zmac->loc_seq;
1502 }
1503
1504 if (local_inactive)
1505 SET_FLAG(n->flags, ZEBRA_NEIGH_LOCAL_INACTIVE);
1506 else
1507 UNSET_FLAG(n->flags, ZEBRA_NEIGH_LOCAL_INACTIVE);
1508
1509 /* Mark Router flag (R-bit) */
1510 if (is_router)
1511 SET_FLAG(n->flags, ZEBRA_NEIGH_ROUTER_FLAG);
1512 else
1513 UNSET_FLAG(n->flags, ZEBRA_NEIGH_ROUTER_FLAG);
1514
1515 /* if zebra and dataplane don't agree this is a sync entry
1516 * re-install in the dataplane */
1517 new_static = zebra_evpn_neigh_is_static(n);
1518 if (dp_static != new_static)
1519 inform_dataplane = true;
1520
1521 /* Check old and/or new MAC detected as duplicate mark
1522 * the neigh as duplicate
1523 */
1524 if (zebra_evpn_ip_inherit_dad_from_mac(zvrf, old_zmac, zmac, n)) {
1525 flog_warn(
1526 EC_ZEBRA_DUP_IP_INHERIT_DETECTED,
1527 "VNI %u: MAC %pEA IP %pIA detected as duplicate during local update, inherit duplicate from MAC",
1528 zevpn->vni, macaddr, &n->ip);
1529 }
1530
1531 /* For IP Duplicate Address Detection (DAD) is trigger,
1532 * when the event is extended mobility based on scenario-B
1533 * from the draft, IP/Neigh's MAC binding changed and
1534 * neigh's previous state was remote.
1535 */
1536 if (neigh_mac_change && neigh_was_remote)
1537 do_dad = true;
1538
1539 zebra_evpn_dup_addr_detect_for_neigh(zvrf, n, vtep_ip, do_dad,
1540 &neigh_on_hold, true);
1541
1542 if (inform_dataplane)
1543 zebra_evpn_sync_neigh_dp_install(n, false /* set_inactive */,
1544 false /* force_clear_static */,
1545 __func__);
1546
1547 /* Before we program this in BGP, we need to check if MAC is locally
1548 * learnt. If not, force neighbor to be inactive and reset its seq.
1549 */
1550 if (!CHECK_FLAG(zmac->flags, ZEBRA_MAC_LOCAL)) {
1551 zebra_evpn_local_neigh_update_log(
1552 "local", n, is_router, local_inactive, false, false,
1553 inform_dataplane, false, "auto-mac");
1554 ZEBRA_NEIGH_SET_INACTIVE(n);
1555 n->loc_seq = 0;
1556 zmac->loc_seq = mac_new_seq;
1557 return 0;
1558 }
1559
1560 zebra_evpn_local_neigh_update_log("local", n, is_router, local_inactive,
1561 false, false, inform_dataplane, true,
1562 created ? "created" : "updated");
1563
1564 /* If the MAC's sequence number has changed, inform the MAC and all
1565 * neighbors associated with the MAC to BGP, else just inform this
1566 * neighbor.
1567 */
1568 if (upd_mac_seq && zmac->loc_seq != mac_new_seq) {
1569 if (IS_ZEBRA_DEBUG_VXLAN)
1570 zlog_debug(
1571 "Seq changed for MAC %pEA VNI %u - old %u new %u",
1572 macaddr, zevpn->vni,
1573 zmac->loc_seq, mac_new_seq);
1574 zmac->loc_seq = mac_new_seq;
1575 if (zebra_evpn_mac_send_add_to_client(zevpn->vni, macaddr,
1576 zmac->flags,
1577 zmac->loc_seq, zmac->es))
1578 return -1;
1579 zebra_evpn_process_neigh_on_local_mac_change(zevpn, zmac, 1,
1580 0 /*es_change*/);
1581 return 0;
1582 }
1583
1584 n->loc_seq = zmac->loc_seq;
1585
1586 if (!neigh_on_hold) {
1587 ZEBRA_NEIGH_SET_ACTIVE(n);
1588 new_bgp_ready = zebra_evpn_neigh_is_ready_for_bgp(n);
1589 zebra_evpn_neigh_send_add_del_to_client(n, old_bgp_ready,
1590 new_bgp_ready);
1591 } else {
1592 if (IS_ZEBRA_DEBUG_VXLAN)
1593 zlog_debug(" Neighbor on hold not sending");
1594 }
1595 return 0;
1596 }
1597
1598 int zebra_evpn_remote_neigh_update(zebra_evpn_t *zevpn, struct interface *ifp,
1599 struct ipaddr *ip, struct ethaddr *macaddr,
1600 uint16_t state)
1601 {
1602 zebra_neigh_t *n = NULL;
1603 zebra_mac_t *zmac = NULL;
1604
1605 /* If the neighbor is unknown, there is no further action. */
1606 n = zebra_evpn_neigh_lookup(zevpn, ip);
1607 if (!n)
1608 return 0;
1609
1610 /* If a remote entry, see if it needs to be refreshed */
1611 if (CHECK_FLAG(n->flags, ZEBRA_NEIGH_REMOTE)) {
1612 #ifdef GNU_LINUX
1613 if (state & NUD_STALE)
1614 zebra_evpn_rem_neigh_install(zevpn, n,
1615 false /*was_static*/);
1616 #endif
1617 } else {
1618 /* We got a "remote" neighbor notification for an entry
1619 * we think is local. This can happen in a multihoming
1620 * scenario - but only if the MAC is already "remote".
1621 * Just mark our entry as "remote".
1622 */
1623 zmac = zebra_evpn_mac_lookup(zevpn, macaddr);
1624 if (!zmac || !CHECK_FLAG(zmac->flags, ZEBRA_MAC_REMOTE)) {
1625 zlog_debug(
1626 "Ignore remote neigh %pIA (MAC %pEA) on L2-VNI %u - MAC unknown or local",
1627 &n->ip, macaddr, zevpn->vni);
1628 return -1;
1629 }
1630
1631 UNSET_FLAG(n->flags, ZEBRA_NEIGH_ALL_LOCAL_FLAGS);
1632 SET_FLAG(n->flags, ZEBRA_NEIGH_REMOTE);
1633 ZEBRA_NEIGH_SET_ACTIVE(n);
1634 n->r_vtep_ip = zmac->fwd_info.r_vtep_ip;
1635 }
1636
1637 return 0;
1638 }
1639
1640 /* Notify Neighbor entries to the Client, skips the GW entry */
1641 static void
1642 zebra_evpn_send_neigh_hash_entry_to_client(struct hash_bucket *bucket,
1643 void *arg)
1644 {
1645 struct mac_walk_ctx *wctx = arg;
1646 zebra_neigh_t *zn = bucket->data;
1647 zebra_mac_t *zmac = NULL;
1648
1649 if (CHECK_FLAG(zn->flags, ZEBRA_NEIGH_DEF_GW))
1650 return;
1651
1652 if (CHECK_FLAG(zn->flags, ZEBRA_NEIGH_LOCAL)
1653 && IS_ZEBRA_NEIGH_ACTIVE(zn)) {
1654 zmac = zebra_evpn_mac_lookup(wctx->zevpn, &zn->emac);
1655 if (!zmac)
1656 return;
1657
1658 zebra_evpn_neigh_send_add_to_client(wctx->zevpn->vni, &zn->ip,
1659 &zn->emac, zn->mac,
1660 zn->flags, zn->loc_seq);
1661 }
1662 }
1663
1664 /* Iterator of a specific EVPN */
1665 void zebra_evpn_send_neigh_to_client(zebra_evpn_t *zevpn)
1666 {
1667 struct neigh_walk_ctx wctx;
1668
1669 memset(&wctx, 0, sizeof(struct neigh_walk_ctx));
1670 wctx.zevpn = zevpn;
1671
1672 hash_iterate(zevpn->neigh_table,
1673 zebra_evpn_send_neigh_hash_entry_to_client, &wctx);
1674 }
1675
1676 void zebra_evpn_clear_dup_neigh_hash(struct hash_bucket *bucket, void *ctxt)
1677 {
1678 struct neigh_walk_ctx *wctx = ctxt;
1679 zebra_neigh_t *nbr;
1680 zebra_evpn_t *zevpn;
1681 char buf[INET6_ADDRSTRLEN];
1682
1683 nbr = (zebra_neigh_t *)bucket->data;
1684 if (!nbr)
1685 return;
1686
1687 zevpn = wctx->zevpn;
1688
1689 if (!CHECK_FLAG(nbr->flags, ZEBRA_NEIGH_DUPLICATE))
1690 return;
1691
1692 if (IS_ZEBRA_DEBUG_VXLAN) {
1693 ipaddr2str(&nbr->ip, buf, sizeof(buf));
1694 zlog_debug("%s: clear neigh %s dup state, flags 0x%x seq %u",
1695 __func__, buf, nbr->flags, nbr->loc_seq);
1696 }
1697
1698 UNSET_FLAG(nbr->flags, ZEBRA_NEIGH_DUPLICATE);
1699 nbr->dad_count = 0;
1700 nbr->detect_start_time.tv_sec = 0;
1701 nbr->detect_start_time.tv_usec = 0;
1702 nbr->dad_dup_detect_time = 0;
1703 THREAD_OFF(nbr->dad_ip_auto_recovery_timer);
1704
1705 if (CHECK_FLAG(nbr->flags, ZEBRA_NEIGH_LOCAL)) {
1706 zebra_evpn_neigh_send_add_to_client(zevpn->vni, &nbr->ip,
1707 &nbr->emac, nbr->mac,
1708 nbr->flags, nbr->loc_seq);
1709 } else if (CHECK_FLAG(nbr->flags, ZEBRA_NEIGH_REMOTE)) {
1710 zebra_evpn_rem_neigh_install(zevpn, nbr, false /*was_static*/);
1711 }
1712 }
1713
1714 /*
1715 * Print a specific neighbor entry.
1716 */
1717 void zebra_evpn_print_neigh(zebra_neigh_t *n, void *ctxt, json_object *json)
1718 {
1719 struct vty *vty;
1720 char buf1[ETHER_ADDR_STRLEN];
1721 char buf2[INET6_ADDRSTRLEN];
1722 char addr_buf[PREFIX_STRLEN];
1723 const char *type_str;
1724 const char *state_str;
1725 bool flags_present = false;
1726 struct zebra_vrf *zvrf = NULL;
1727 struct timeval detect_start_time = {0, 0};
1728 char timebuf[MONOTIME_STRLEN];
1729 char thread_buf[THREAD_TIMER_STRLEN];
1730 time_t uptime;
1731 char up_str[MONOTIME_STRLEN];
1732
1733 zvrf = zebra_vrf_get_evpn();
1734 if (!zvrf)
1735 return;
1736
1737 uptime = monotime(NULL);
1738 uptime -= n->uptime;
1739
1740 frrtime_to_interval(uptime, up_str, sizeof(up_str));
1741
1742 ipaddr2str(&n->ip, buf2, sizeof(buf2));
1743 prefix_mac2str(&n->emac, buf1, sizeof(buf1));
1744 type_str = CHECK_FLAG(n->flags, ZEBRA_NEIGH_LOCAL) ? "local" : "remote";
1745 state_str = IS_ZEBRA_NEIGH_ACTIVE(n) ? "active" : "inactive";
1746 vty = (struct vty *)ctxt;
1747 if (json == NULL) {
1748 bool sync_info = false;
1749
1750 vty_out(vty, "IP: %s\n",
1751 ipaddr2str(&n->ip, buf2, sizeof(buf2)));
1752 vty_out(vty, " Type: %s\n", type_str);
1753 vty_out(vty, " State: %s\n", state_str);
1754 vty_out(vty, " Uptime: %s\n", up_str);
1755 vty_out(vty, " MAC: %s\n",
1756 prefix_mac2str(&n->emac, buf1, sizeof(buf1)));
1757 vty_out(vty, " Sync-info:");
1758 if (CHECK_FLAG(n->flags, ZEBRA_NEIGH_LOCAL_INACTIVE)) {
1759 vty_out(vty, " local-inactive");
1760 sync_info = true;
1761 }
1762 if (CHECK_FLAG(n->flags, ZEBRA_NEIGH_ES_PEER_PROXY)) {
1763 vty_out(vty, " peer-proxy");
1764 sync_info = true;
1765 }
1766 if (CHECK_FLAG(n->flags, ZEBRA_NEIGH_ES_PEER_ACTIVE)) {
1767 vty_out(vty, " peer-active");
1768 sync_info = true;
1769 }
1770 if (n->hold_timer) {
1771 vty_out(vty, " (ht: %s)",
1772 thread_timer_to_hhmmss(thread_buf,
1773 sizeof(thread_buf),
1774 n->hold_timer));
1775 sync_info = true;
1776 }
1777 if (!sync_info)
1778 vty_out(vty, " -");
1779 vty_out(vty, "\n");
1780 } else {
1781 json_object_string_add(json, "uptime", up_str);
1782 json_object_string_add(json, "ip", buf2);
1783 json_object_string_add(json, "type", type_str);
1784 json_object_string_add(json, "state", state_str);
1785 json_object_string_add(json, "mac", buf1);
1786 if (CHECK_FLAG(n->flags, ZEBRA_NEIGH_LOCAL_INACTIVE))
1787 json_object_boolean_true_add(json, "localInactive");
1788 if (CHECK_FLAG(n->flags, ZEBRA_NEIGH_ES_PEER_PROXY))
1789 json_object_boolean_true_add(json, "peerProxy");
1790 if (CHECK_FLAG(n->flags, ZEBRA_NEIGH_ES_PEER_ACTIVE))
1791 json_object_boolean_true_add(json, "peerActive");
1792 if (n->hold_timer)
1793 json_object_string_add(
1794 json, "peerActiveHold",
1795 thread_timer_to_hhmmss(thread_buf,
1796 sizeof(thread_buf),
1797 n->hold_timer));
1798 }
1799 if (CHECK_FLAG(n->flags, ZEBRA_NEIGH_REMOTE)) {
1800 if (n->mac->es) {
1801 if (json)
1802 json_object_string_add(json, "remoteEs",
1803 n->mac->es->esi_str);
1804 else
1805 vty_out(vty, " Remote ES: %s\n",
1806 n->mac->es->esi_str);
1807 } else {
1808 if (json)
1809 json_object_string_add(
1810 json, "remoteVtep",
1811 inet_ntop(AF_INET, &n->r_vtep_ip,
1812 addr_buf, sizeof(addr_buf)));
1813 else
1814 vty_out(vty, " Remote VTEP: %pI4\n",
1815 &n->r_vtep_ip);
1816 }
1817 }
1818 if (CHECK_FLAG(n->flags, ZEBRA_NEIGH_DEF_GW)) {
1819 if (!json) {
1820 vty_out(vty, " Flags: Default-gateway");
1821 flags_present = true;
1822 } else
1823 json_object_boolean_true_add(json, "defaultGateway");
1824 }
1825 if (CHECK_FLAG(n->flags, ZEBRA_NEIGH_ROUTER_FLAG)) {
1826 if (!json) {
1827 vty_out(vty,
1828 flags_present ? " ,Router" : " Flags: Router");
1829 flags_present = true;
1830 }
1831 }
1832 if (json == NULL) {
1833 if (flags_present)
1834 vty_out(vty, "\n");
1835 vty_out(vty, " Local Seq: %u Remote Seq: %u\n", n->loc_seq,
1836 n->rem_seq);
1837
1838 if (CHECK_FLAG(n->flags, ZEBRA_NEIGH_DUPLICATE)) {
1839 vty_out(vty, " Duplicate, detected at %s",
1840 time_to_string(n->dad_dup_detect_time,
1841 timebuf));
1842 } else if (n->dad_count) {
1843 monotime_since(&n->detect_start_time,
1844 &detect_start_time);
1845 if (detect_start_time.tv_sec <= zvrf->dad_time) {
1846 time_to_string(n->detect_start_time.tv_sec,
1847 timebuf);
1848 vty_out(vty,
1849 " Duplicate detection started at %s, detection count %u\n",
1850 timebuf, n->dad_count);
1851 }
1852 }
1853 } else {
1854 json_object_int_add(json, "localSequence", n->loc_seq);
1855 json_object_int_add(json, "remoteSequence", n->rem_seq);
1856 json_object_int_add(json, "detectionCount", n->dad_count);
1857 if (CHECK_FLAG(n->flags, ZEBRA_NEIGH_DUPLICATE))
1858 json_object_boolean_true_add(json, "isDuplicate");
1859 else
1860 json_object_boolean_false_add(json, "isDuplicate");
1861 }
1862 }
1863
1864 void zebra_evpn_print_neigh_hdr(struct vty *vty, struct neigh_walk_ctx *wctx)
1865 {
1866 vty_out(vty, "Flags: I=local-inactive, P=peer-active, X=peer-proxy\n");
1867 vty_out(vty, "%*s %-6s %-5s %-8s %-17s %-30s %s\n", -wctx->addr_width,
1868 "Neighbor", "Type", "Flags", "State", "MAC", "Remote ES/VTEP",
1869 "Seq #'s");
1870 }
1871
1872 static char *zebra_evpn_print_neigh_flags(zebra_neigh_t *n, char *flags_buf,
1873 uint32_t flags_buf_sz)
1874 {
1875 snprintf(flags_buf, flags_buf_sz, "%s%s%s",
1876 (n->flags & ZEBRA_NEIGH_ES_PEER_ACTIVE) ?
1877 "P" : "",
1878 (n->flags & ZEBRA_NEIGH_ES_PEER_PROXY) ?
1879 "X" : "",
1880 (n->flags & ZEBRA_NEIGH_LOCAL_INACTIVE) ?
1881 "I" : "");
1882
1883 return flags_buf;
1884 }
1885
1886 /*
1887 * Print neighbor hash entry - called for display of all neighbors.
1888 */
1889 void zebra_evpn_print_neigh_hash(struct hash_bucket *bucket, void *ctxt)
1890 {
1891 struct vty *vty;
1892 json_object *json_evpn = NULL, *json_row = NULL;
1893 zebra_neigh_t *n;
1894 char buf1[ETHER_ADDR_STRLEN];
1895 char buf2[INET6_ADDRSTRLEN];
1896 char addr_buf[PREFIX_STRLEN];
1897 struct neigh_walk_ctx *wctx = ctxt;
1898 const char *state_str;
1899 char flags_buf[6];
1900
1901 vty = wctx->vty;
1902 json_evpn = wctx->json;
1903 n = (zebra_neigh_t *)bucket->data;
1904
1905 if (json_evpn)
1906 json_row = json_object_new_object();
1907
1908 prefix_mac2str(&n->emac, buf1, sizeof(buf1));
1909 ipaddr2str(&n->ip, buf2, sizeof(buf2));
1910 state_str = IS_ZEBRA_NEIGH_ACTIVE(n) ? "active" : "inactive";
1911 if (CHECK_FLAG(n->flags, ZEBRA_NEIGH_LOCAL)) {
1912 if (wctx->flags & SHOW_REMOTE_NEIGH_FROM_VTEP)
1913 return;
1914
1915 if (json_evpn == NULL) {
1916 vty_out(vty, "%*s %-6s %-5s %-8s %-17s %-30s %u/%u\n",
1917 -wctx->addr_width, buf2, "local",
1918 zebra_evpn_print_neigh_flags(n, flags_buf,
1919 sizeof(flags_buf)), state_str, buf1,
1920 "", n->loc_seq, n->rem_seq);
1921 } else {
1922 json_object_string_add(json_row, "type", "local");
1923 json_object_string_add(json_row, "state", state_str);
1924 json_object_string_add(json_row, "mac", buf1);
1925 if (CHECK_FLAG(n->flags, ZEBRA_NEIGH_DEF_GW))
1926 json_object_boolean_true_add(json_row,
1927 "defaultGateway");
1928 json_object_int_add(json_row, "localSequence",
1929 n->loc_seq);
1930 json_object_int_add(json_row, "remoteSequence",
1931 n->rem_seq);
1932 json_object_int_add(json_row, "detectionCount",
1933 n->dad_count);
1934 if (CHECK_FLAG(n->flags, ZEBRA_NEIGH_DUPLICATE))
1935 json_object_boolean_true_add(json_row,
1936 "isDuplicate");
1937 else
1938 json_object_boolean_false_add(json_row,
1939 "isDuplicate");
1940 }
1941 wctx->count++;
1942 } else if (CHECK_FLAG(n->flags, ZEBRA_NEIGH_REMOTE)) {
1943 if ((wctx->flags & SHOW_REMOTE_NEIGH_FROM_VTEP)
1944 && !IPV4_ADDR_SAME(&n->r_vtep_ip, &wctx->r_vtep_ip))
1945 return;
1946
1947 if (json_evpn == NULL) {
1948 if ((wctx->flags & SHOW_REMOTE_NEIGH_FROM_VTEP)
1949 && (wctx->count == 0))
1950 zebra_evpn_print_neigh_hdr(vty, wctx);
1951
1952 if (n->mac->es == NULL)
1953 inet_ntop(AF_INET, &n->r_vtep_ip,
1954 addr_buf, sizeof(addr_buf));
1955
1956 vty_out(vty, "%*s %-6s %-5s %-8s %-17s %-30s %u/%u\n",
1957 -wctx->addr_width, buf2, "remote",
1958 zebra_evpn_print_neigh_flags(n, flags_buf,
1959 sizeof(flags_buf)), state_str, buf1,
1960 n->mac->es ? n->mac->es->esi_str : addr_buf,
1961 n->loc_seq, n->rem_seq);
1962 } else {
1963 json_object_string_add(json_row, "type", "remote");
1964 json_object_string_add(json_row, "state", state_str);
1965 json_object_string_add(json_row, "mac", buf1);
1966 if (n->mac->es)
1967 json_object_string_add(json_row, "remoteEs",
1968 n->mac->es->esi_str);
1969 else
1970 json_object_string_add(
1971 json_row, "remoteVtep",
1972 inet_ntop(AF_INET, &n->r_vtep_ip,
1973 addr_buf, sizeof(addr_buf)));
1974 if (CHECK_FLAG(n->flags, ZEBRA_NEIGH_DEF_GW))
1975 json_object_boolean_true_add(json_row,
1976 "defaultGateway");
1977 json_object_int_add(json_row, "localSequence",
1978 n->loc_seq);
1979 json_object_int_add(json_row, "remoteSequence",
1980 n->rem_seq);
1981 json_object_int_add(json_row, "detectionCount",
1982 n->dad_count);
1983 if (CHECK_FLAG(n->flags, ZEBRA_NEIGH_DUPLICATE))
1984 json_object_boolean_true_add(json_row,
1985 "isDuplicate");
1986 else
1987 json_object_boolean_false_add(json_row,
1988 "isDuplicate");
1989 }
1990 wctx->count++;
1991 }
1992
1993 if (json_evpn)
1994 json_object_object_add(json_evpn, buf2, json_row);
1995 }
1996
1997 /*
1998 * Print neighbor hash entry in detail - called for display of all neighbors.
1999 */
2000 void zebra_evpn_print_neigh_hash_detail(struct hash_bucket *bucket, void *ctxt)
2001 {
2002 struct vty *vty;
2003 json_object *json_evpn = NULL, *json_row = NULL;
2004 zebra_neigh_t *n;
2005 char buf[INET6_ADDRSTRLEN];
2006 struct neigh_walk_ctx *wctx = ctxt;
2007
2008 vty = wctx->vty;
2009 json_evpn = wctx->json;
2010 n = (zebra_neigh_t *)bucket->data;
2011 if (!n)
2012 return;
2013
2014 ipaddr2str(&n->ip, buf, sizeof(buf));
2015 if (json_evpn)
2016 json_row = json_object_new_object();
2017
2018 zebra_evpn_print_neigh(n, vty, json_row);
2019
2020 if (json_evpn)
2021 json_object_object_add(json_evpn, buf, json_row);
2022 }
2023
2024 void zebra_evpn_print_dad_neigh_hash(struct hash_bucket *bucket, void *ctxt)
2025 {
2026 zebra_neigh_t *nbr;
2027
2028 nbr = (zebra_neigh_t *)bucket->data;
2029 if (!nbr)
2030 return;
2031
2032 if (CHECK_FLAG(nbr->flags, ZEBRA_NEIGH_DUPLICATE))
2033 zebra_evpn_print_neigh_hash(bucket, ctxt);
2034 }
2035
2036 void zebra_evpn_print_dad_neigh_hash_detail(struct hash_bucket *bucket,
2037 void *ctxt)
2038 {
2039 zebra_neigh_t *nbr;
2040
2041 nbr = (zebra_neigh_t *)bucket->data;
2042 if (!nbr)
2043 return;
2044
2045 if (CHECK_FLAG(nbr->flags, ZEBRA_NEIGH_DUPLICATE))
2046 zebra_evpn_print_neigh_hash_detail(bucket, ctxt);
2047 }
2048
2049 void process_neigh_remote_macip_add(zebra_evpn_t *zevpn, struct zebra_vrf *zvrf,
2050 struct ipaddr *ipaddr, zebra_mac_t *mac,
2051 struct in_addr vtep_ip, uint8_t flags,
2052 uint32_t seq)
2053 {
2054 zebra_neigh_t *n;
2055 int update_neigh = 0;
2056 zebra_mac_t *old_mac = NULL;
2057 bool old_static = false;
2058 bool do_dad = false;
2059 bool is_dup_detect = false;
2060 bool is_router;
2061
2062 assert(mac);
2063 is_router = !!CHECK_FLAG(flags, ZEBRA_MACIP_TYPE_ROUTER_FLAG);
2064
2065 /* Check if the remote neighbor itself is unknown or has a
2066 * change. If so, create or update and then install the entry.
2067 */
2068 n = zebra_evpn_neigh_lookup(zevpn, ipaddr);
2069 if (!n || !CHECK_FLAG(n->flags, ZEBRA_NEIGH_REMOTE)
2070 || is_router != !!CHECK_FLAG(n->flags, ZEBRA_NEIGH_ROUTER_FLAG)
2071 || (memcmp(&n->emac, &mac->macaddr, sizeof(struct ethaddr)) != 0)
2072 || !IPV4_ADDR_SAME(&n->r_vtep_ip, &vtep_ip) || seq != n->rem_seq)
2073 update_neigh = 1;
2074
2075 if (update_neigh) {
2076 if (!n) {
2077 n = zebra_evpn_neigh_add(zevpn, ipaddr, &mac->macaddr,
2078 mac, 0);
2079 if (!n) {
2080 zlog_warn(
2081 "Failed to add Neigh %pIA MAC %pEA VNI %u Remote VTEP %pI4",
2082 ipaddr, &mac->macaddr, zevpn->vni,
2083 &vtep_ip);
2084 return;
2085 }
2086
2087 } else {
2088 /* When host moves but changes its (MAC,IP)
2089 * binding, BGP may install a MACIP entry that
2090 * corresponds to "older" location of the host
2091 * in transient situations (because {IP1,M1}
2092 * is a different route from {IP1,M2}). Check
2093 * the sequence number and ignore this update
2094 * if appropriate.
2095 */
2096
2097 if (!zebra_evpn_neigh_is_bgp_seq_ok(
2098 zevpn, n, &mac->macaddr, seq, false))
2099 return;
2100 if (CHECK_FLAG(n->flags, ZEBRA_NEIGH_LOCAL)) {
2101 old_static = zebra_evpn_neigh_is_static(n);
2102 if (IS_ZEBRA_DEBUG_EVPN_MH_NEIGH)
2103 zlog_debug(
2104 "sync->remote neigh vni %u ip %pIA mac %pEA seq %d f0x%x",
2105 n->zevpn->vni, &n->ip, &n->emac,
2106 seq, n->flags);
2107 zebra_evpn_neigh_clear_sync_info(n);
2108 if (IS_ZEBRA_NEIGH_ACTIVE(n))
2109 zebra_evpn_neigh_send_del_to_client(
2110 zevpn->vni, &n->ip, &n->emac,
2111 n->flags, n->state,
2112 false /*force*/);
2113 }
2114 if (memcmp(&n->emac, &mac->macaddr,
2115 sizeof(struct ethaddr))
2116 != 0) {
2117 /* update neigh list for macs */
2118 old_mac =
2119 zebra_evpn_mac_lookup(zevpn, &n->emac);
2120 if (old_mac) {
2121 listnode_delete(old_mac->neigh_list, n);
2122 n->mac = NULL;
2123 zebra_evpn_deref_ip2mac(zevpn, old_mac);
2124 }
2125 n->mac = mac;
2126 listnode_add_sort(mac->neigh_list, n);
2127 memcpy(&n->emac, &mac->macaddr, ETH_ALEN);
2128
2129 /* Check Neigh's curent state is local
2130 * (this is the case where neigh/host has moved
2131 * from L->R) and check previous detction
2132 * started via local learning.
2133 *
2134 * RFC-7432: A PE/VTEP that detects a MAC
2135 * mobilit event via local learning starts
2136 * an M-second timer.
2137 * VTEP-IP or seq. change along is not
2138 * considered for dup. detection.
2139 *
2140 * Mobilty event scenario-B IP-MAC binding
2141 * changed.
2142 */
2143 if ((!CHECK_FLAG(n->flags, ZEBRA_NEIGH_REMOTE))
2144 && n->dad_count)
2145 do_dad = true;
2146 }
2147 }
2148
2149 /* Set "remote" forwarding info. */
2150 UNSET_FLAG(n->flags, ZEBRA_NEIGH_ALL_LOCAL_FLAGS);
2151 n->r_vtep_ip = vtep_ip;
2152 SET_FLAG(n->flags, ZEBRA_NEIGH_REMOTE);
2153
2154 /* Set router flag (R-bit) to this Neighbor entry */
2155 if (CHECK_FLAG(flags, ZEBRA_MACIP_TYPE_ROUTER_FLAG))
2156 SET_FLAG(n->flags, ZEBRA_NEIGH_ROUTER_FLAG);
2157 else
2158 UNSET_FLAG(n->flags, ZEBRA_NEIGH_ROUTER_FLAG);
2159
2160 /* Check old or new MAC detected as duplicate,
2161 * inherit duplicate flag to this neigh.
2162 */
2163 if (zebra_evpn_ip_inherit_dad_from_mac(zvrf, old_mac, mac, n)) {
2164 flog_warn(
2165 EC_ZEBRA_DUP_IP_INHERIT_DETECTED,
2166 "VNI %u: MAC %pEA IP %pIA detected as duplicate during remote update, inherit duplicate from MAC",
2167 zevpn->vni, &mac->macaddr, &n->ip);
2168 }
2169
2170 /* Check duplicate address detection for IP */
2171 zebra_evpn_dup_addr_detect_for_neigh(
2172 zvrf, n, n->r_vtep_ip, do_dad, &is_dup_detect, false);
2173 /* Install the entry. */
2174 if (!is_dup_detect)
2175 zebra_evpn_rem_neigh_install(zevpn, n, old_static);
2176 }
2177
2178 /* Update seq number. */
2179 n->rem_seq = seq;
2180 }
2181
2182 int zebra_evpn_neigh_gw_macip_add(struct interface *ifp, zebra_evpn_t *zevpn,
2183 struct ipaddr *ip, zebra_mac_t *mac)
2184 {
2185 zebra_neigh_t *n;
2186
2187 assert(mac);
2188
2189 n = zebra_evpn_neigh_lookup(zevpn, ip);
2190 if (!n) {
2191 n = zebra_evpn_neigh_add(zevpn, ip, &mac->macaddr, mac, 0);
2192 if (!n) {
2193 flog_err(
2194 EC_ZEBRA_MAC_ADD_FAILED,
2195 "Failed to add neighbor %pIA MAC %pEA intf %s(%u) -> VNI %u",
2196 ip, &mac->macaddr,
2197 ifp->name, ifp->ifindex, zevpn->vni);
2198 return -1;
2199 }
2200 }
2201
2202 /* Set "local" forwarding info. */
2203 SET_FLAG(n->flags, ZEBRA_NEIGH_LOCAL);
2204 ZEBRA_NEIGH_SET_ACTIVE(n);
2205 memcpy(&n->emac, &mac->macaddr, ETH_ALEN);
2206 n->ifindex = ifp->ifindex;
2207
2208 /* Only advertise in BGP if the knob is enabled */
2209 if (advertise_gw_macip_enabled(zevpn)) {
2210
2211 SET_FLAG(mac->flags, ZEBRA_MAC_DEF_GW);
2212 SET_FLAG(n->flags, ZEBRA_NEIGH_DEF_GW);
2213 /* Set Router flag (R-bit) */
2214 if (ip->ipa_type == IPADDR_V6)
2215 SET_FLAG(n->flags, ZEBRA_NEIGH_ROUTER_FLAG);
2216
2217 if (IS_ZEBRA_DEBUG_VXLAN)
2218 zlog_debug(
2219 "SVI %s(%u) L2-VNI %u, sending GW MAC %pEA IP %pIA add to BGP with flags 0x%x",
2220 ifp->name, ifp->ifindex, zevpn->vni,
2221 &mac->macaddr, ip, n->flags);
2222
2223 zebra_evpn_neigh_send_add_to_client(
2224 zevpn->vni, ip, &n->emac, n->mac, n->flags, n->loc_seq);
2225 } else if (advertise_svi_macip_enabled(zevpn)) {
2226
2227 SET_FLAG(n->flags, ZEBRA_NEIGH_SVI_IP);
2228 if (IS_ZEBRA_DEBUG_VXLAN)
2229 zlog_debug(
2230 "SVI %s(%u) L2-VNI %u, sending SVI MAC %pEA IP %pIA add to BGP with flags 0x%x",
2231 ifp->name, ifp->ifindex, zevpn->vni,
2232 &mac->macaddr, ip, n->flags);
2233
2234 zebra_evpn_neigh_send_add_to_client(
2235 zevpn->vni, ip, &n->emac, n->mac, n->flags, n->loc_seq);
2236 }
2237
2238 return 0;
2239 }
2240
2241 void zebra_evpn_neigh_remote_uninstall(zebra_evpn_t *zevpn,
2242 struct zebra_vrf *zvrf, zebra_neigh_t *n,
2243 zebra_mac_t *mac, struct ipaddr *ipaddr)
2244 {
2245 if (zvrf->dad_freeze && CHECK_FLAG(n->flags, ZEBRA_NEIGH_DUPLICATE)
2246 && CHECK_FLAG(n->flags, ZEBRA_NEIGH_REMOTE)
2247 && (memcmp(n->emac.octet, mac->macaddr.octet, ETH_ALEN) == 0)) {
2248 struct interface *vlan_if;
2249
2250 vlan_if = zevpn_map_to_svi(zevpn);
2251 if (IS_ZEBRA_DEBUG_VXLAN)
2252 zlog_debug(
2253 "%s: IP %pIA (flags 0x%x intf %s) is remote and duplicate, read kernel for local entry",
2254 __func__, ipaddr, n->flags,
2255 vlan_if ? vlan_if->name : "Unknown");
2256 if (vlan_if)
2257 neigh_read_specific_ip(ipaddr, vlan_if);
2258 }
2259
2260 /* When the MAC changes for an IP, it is possible the
2261 * client may update the new MAC before trying to delete the
2262 * "old" neighbor (as these are two different MACIP routes).
2263 * Do the delete only if the MAC matches.
2264 */
2265 if (!memcmp(n->emac.octet, mac->macaddr.octet, ETH_ALEN)) {
2266 if (CHECK_FLAG(n->flags, ZEBRA_NEIGH_LOCAL)) {
2267 zebra_evpn_sync_neigh_del(n);
2268 } else if (CHECK_FLAG(n->flags, ZEBRA_NEIGH_REMOTE)) {
2269 zebra_evpn_neigh_uninstall(zevpn, n);
2270 zebra_evpn_neigh_del(zevpn, n);
2271 zebra_evpn_deref_ip2mac(zevpn, mac);
2272 }
2273 }
2274 }
2275
2276 int zebra_evpn_neigh_del_ip(zebra_evpn_t *zevpn, struct ipaddr *ip)
2277 {
2278 zebra_neigh_t *n;
2279 zebra_mac_t *zmac;
2280 bool old_bgp_ready;
2281 bool new_bgp_ready;
2282 struct zebra_vrf *zvrf;
2283
2284 /* If entry doesn't exist, nothing to do. */
2285 n = zebra_evpn_neigh_lookup(zevpn, ip);
2286 if (!n)
2287 return 0;
2288
2289 zmac = zebra_evpn_mac_lookup(zevpn, &n->emac);
2290 if (!zmac) {
2291 if (IS_ZEBRA_DEBUG_VXLAN)
2292 zlog_debug(
2293 "Trying to del a neigh %pIA without a mac %pEA on VNI %u",
2294 ip, &n->emac,
2295 zevpn->vni);
2296
2297 return 0;
2298 }
2299
2300 /* If it is a remote entry, the kernel has aged this out or someone has
2301 * deleted it, it needs to be re-installed as Quagga is the owner.
2302 */
2303 if (CHECK_FLAG(n->flags, ZEBRA_NEIGH_REMOTE)) {
2304 zebra_evpn_rem_neigh_install(zevpn, n, false /*was_static*/);
2305 return 0;
2306 }
2307
2308 /* if this is a sync entry it cannot be dropped re-install it in
2309 * the dataplane
2310 */
2311 old_bgp_ready = zebra_evpn_neigh_is_ready_for_bgp(n);
2312 if (zebra_evpn_neigh_is_static(n)) {
2313 if (IS_ZEBRA_DEBUG_EVPN_MH_NEIGH)
2314 zlog_debug("re-add sync neigh vni %u ip %pIA mac %pEA 0x%x",
2315 n->zevpn->vni, &n->ip, &n->emac,
2316 n->flags);
2317
2318 if (!CHECK_FLAG(n->flags, ZEBRA_NEIGH_LOCAL_INACTIVE))
2319 SET_FLAG(n->flags, ZEBRA_NEIGH_LOCAL_INACTIVE);
2320 /* inform-bgp about change in local-activity if any */
2321 new_bgp_ready = zebra_evpn_neigh_is_ready_for_bgp(n);
2322 zebra_evpn_neigh_send_add_del_to_client(n, old_bgp_ready,
2323 new_bgp_ready);
2324
2325 /* re-install the entry in the kernel */
2326 zebra_evpn_sync_neigh_dp_install(n, false /* set_inactive */,
2327 false /* force_clear_static */,
2328 __func__);
2329
2330 return 0;
2331 }
2332
2333 zvrf = vrf_info_lookup(zevpn->vxlan_if->vrf_id);
2334 if (!zvrf) {
2335 zlog_debug("%s: VNI %u vrf lookup failed.", __func__,
2336 zevpn->vni);
2337 return -1;
2338 }
2339
2340 /* In case of feeze action, if local neigh is in duplicate state,
2341 * Mark the Neigh as inactive before sending delete request to BGPd,
2342 * If BGPd has remote entry, it will re-install
2343 */
2344 if (zvrf->dad_freeze && CHECK_FLAG(n->flags, ZEBRA_NEIGH_DUPLICATE))
2345 ZEBRA_NEIGH_SET_INACTIVE(n);
2346
2347 /* Remove neighbor from BGP. */
2348 zebra_evpn_neigh_send_del_to_client(zevpn->vni, &n->ip, &n->emac,
2349 n->flags, n->state,
2350 false /* force */);
2351
2352 /* Delete this neighbor entry. */
2353 zebra_evpn_neigh_del(zevpn, n);
2354
2355 /* see if the AUTO mac needs to be deleted */
2356 if (CHECK_FLAG(zmac->flags, ZEBRA_MAC_AUTO)
2357 && !zebra_evpn_mac_in_use(zmac))
2358 zebra_evpn_mac_del(zevpn, zmac);
2359
2360 return 0;
2361 }