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