]> git.proxmox.com Git - mirror_frr.git/blob - zebra/zebra_nhg.c
Merge pull request #5224 from manuhalo/fix_frr_reload_paths
[mirror_frr.git] / zebra / zebra_nhg.c
1 /* Zebra Nexthop Group Code.
2 * Copyright (C) 2019 Cumulus Networks, Inc.
3 * Donald Sharp
4 * Stephen Worley
5 *
6 * This file is part of FRR.
7 *
8 * FRR is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the
10 * Free Software Foundation; either version 2, or (at your option) any
11 * later version.
12 *
13 * FRR is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with FRR; see the file COPYING. If not, write to the Free
20 * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
21 * 02111-1307, USA.
22 */
23 #include <zebra.h>
24
25 #include "lib/nexthop.h"
26 #include "lib/nexthop_group_private.h"
27 #include "lib/routemap.h"
28 #include "lib/mpls.h"
29 #include "lib/jhash.h"
30 #include "lib/debug.h"
31
32 #include "zebra/connected.h"
33 #include "zebra/debug.h"
34 #include "zebra/zebra_router.h"
35 #include "zebra/zebra_nhg_private.h"
36 #include "zebra/zebra_rnh.h"
37 #include "zebra/zebra_routemap.h"
38 #include "zebra/zebra_memory.h"
39 #include "zebra/zserv.h"
40 #include "zebra/rt.h"
41 #include "zebra_errors.h"
42 #include "zebra_dplane.h"
43 #include "zebra/interface.h"
44
45 DEFINE_MTYPE_STATIC(ZEBRA, NHG, "Nexthop Group Entry");
46 DEFINE_MTYPE_STATIC(ZEBRA, NHG_CONNECTED, "Nexthop Group Connected");
47 DEFINE_MTYPE_STATIC(ZEBRA, NHG_CTX, "Nexthop Group Context");
48
49 /* id counter to keep in sync with kernel */
50 uint32_t id_counter;
51
52 static struct nhg_hash_entry *depends_find(struct nexthop *nh, afi_t afi);
53 static void depends_add(struct nhg_connected_tree_head *head,
54 struct nhg_hash_entry *depend);
55 static struct nhg_hash_entry *
56 depends_find_add(struct nhg_connected_tree_head *head, struct nexthop *nh,
57 afi_t afi);
58 static struct nhg_hash_entry *
59 depends_find_id_add(struct nhg_connected_tree_head *head, uint32_t id);
60 static void depends_decrement_free(struct nhg_connected_tree_head *head);
61
62
63 static void nhg_connected_free(struct nhg_connected *dep)
64 {
65 XFREE(MTYPE_NHG_CONNECTED, dep);
66 }
67
68 static struct nhg_connected *nhg_connected_new(struct nhg_hash_entry *nhe)
69 {
70 struct nhg_connected *new = NULL;
71
72 new = XCALLOC(MTYPE_NHG_CONNECTED, sizeof(struct nhg_connected));
73 new->nhe = nhe;
74
75 return new;
76 }
77
78 void nhg_connected_tree_free(struct nhg_connected_tree_head *head)
79 {
80 struct nhg_connected *rb_node_dep = NULL;
81
82 if (!nhg_connected_tree_is_empty(head)) {
83 frr_each_safe(nhg_connected_tree, head, rb_node_dep) {
84 nhg_connected_tree_del(head, rb_node_dep);
85 nhg_connected_free(rb_node_dep);
86 }
87 }
88 }
89
90 bool nhg_connected_tree_is_empty(const struct nhg_connected_tree_head *head)
91 {
92 return nhg_connected_tree_count(head) ? false : true;
93 }
94
95 struct nhg_connected *
96 nhg_connected_tree_root(struct nhg_connected_tree_head *head)
97 {
98 return nhg_connected_tree_first(head);
99 }
100
101 void nhg_connected_tree_del_nhe(struct nhg_connected_tree_head *head,
102 struct nhg_hash_entry *depend)
103 {
104 struct nhg_connected lookup = {};
105 struct nhg_connected *remove = NULL;
106
107 lookup.nhe = depend;
108
109 /* Lookup to find the element, then remove it */
110 remove = nhg_connected_tree_find(head, &lookup);
111 remove = nhg_connected_tree_del(head, remove);
112
113 if (remove)
114 nhg_connected_free(remove);
115 }
116
117 void nhg_connected_tree_add_nhe(struct nhg_connected_tree_head *head,
118 struct nhg_hash_entry *depend)
119 {
120 struct nhg_connected *new = NULL;
121
122 new = nhg_connected_new(depend);
123
124 if (new)
125 nhg_connected_tree_add(head, new);
126 }
127
128 static void
129 nhg_connected_tree_decrement_ref(struct nhg_connected_tree_head *head)
130 {
131 struct nhg_connected *rb_node_dep = NULL;
132
133 frr_each_safe(nhg_connected_tree, head, rb_node_dep) {
134 zebra_nhg_decrement_ref(rb_node_dep->nhe);
135 }
136 }
137
138 static void
139 nhg_connected_tree_increment_ref(struct nhg_connected_tree_head *head)
140 {
141 struct nhg_connected *rb_node_dep = NULL;
142
143 frr_each(nhg_connected_tree, head, rb_node_dep) {
144 zebra_nhg_increment_ref(rb_node_dep->nhe);
145 }
146 }
147
148 struct nhg_hash_entry *zebra_nhg_resolve(struct nhg_hash_entry *nhe)
149 {
150 if (CHECK_FLAG(nhe->flags, NEXTHOP_GROUP_RECURSIVE)
151 && !zebra_nhg_depends_is_empty(nhe)) {
152 nhe = nhg_connected_tree_root(&nhe->nhg_depends)->nhe;
153 return zebra_nhg_resolve(nhe);
154 }
155
156 return nhe;
157 }
158
159 unsigned int zebra_nhg_depends_count(const struct nhg_hash_entry *nhe)
160 {
161 return nhg_connected_tree_count(&nhe->nhg_depends);
162 }
163
164 bool zebra_nhg_depends_is_empty(const struct nhg_hash_entry *nhe)
165 {
166 return nhg_connected_tree_is_empty(&nhe->nhg_depends);
167 }
168
169 static void zebra_nhg_depends_del(struct nhg_hash_entry *from,
170 struct nhg_hash_entry *depend)
171 {
172 nhg_connected_tree_del_nhe(&from->nhg_depends, depend);
173 }
174
175 static void zebra_nhg_depends_init(struct nhg_hash_entry *nhe)
176 {
177 nhg_connected_tree_init(&nhe->nhg_depends);
178 }
179
180 unsigned int zebra_nhg_dependents_count(const struct nhg_hash_entry *nhe)
181 {
182 return nhg_connected_tree_count(&nhe->nhg_dependents);
183 }
184
185
186 bool zebra_nhg_dependents_is_empty(const struct nhg_hash_entry *nhe)
187 {
188 return nhg_connected_tree_is_empty(&nhe->nhg_dependents);
189 }
190
191 static void zebra_nhg_dependents_del(struct nhg_hash_entry *from,
192 struct nhg_hash_entry *dependent)
193 {
194 nhg_connected_tree_del_nhe(&from->nhg_dependents, dependent);
195 }
196
197 static void zebra_nhg_dependents_add(struct nhg_hash_entry *to,
198 struct nhg_hash_entry *dependent)
199 {
200 nhg_connected_tree_add_nhe(&to->nhg_dependents, dependent);
201 }
202
203 static void zebra_nhg_dependents_init(struct nhg_hash_entry *nhe)
204 {
205 nhg_connected_tree_init(&nhe->nhg_dependents);
206 }
207
208 /* Release this nhe from anything depending on it */
209 static void zebra_nhg_dependents_release(struct nhg_hash_entry *nhe)
210 {
211 struct nhg_connected *rb_node_dep = NULL;
212
213 frr_each_safe(nhg_connected_tree, &nhe->nhg_dependents, rb_node_dep) {
214 zebra_nhg_depends_del(rb_node_dep->nhe, nhe);
215 /* recheck validity of the dependent */
216 zebra_nhg_check_valid(rb_node_dep->nhe);
217 }
218 }
219
220 /* Release this nhe from anything that it depends on */
221 static void zebra_nhg_depends_release(struct nhg_hash_entry *nhe)
222 {
223 if (!zebra_nhg_depends_is_empty(nhe)) {
224 struct nhg_connected *rb_node_dep = NULL;
225
226 frr_each_safe(nhg_connected_tree, &nhe->nhg_depends,
227 rb_node_dep) {
228 zebra_nhg_dependents_del(rb_node_dep->nhe, nhe);
229 }
230 }
231 }
232
233
234 struct nhg_hash_entry *zebra_nhg_lookup_id(uint32_t id)
235 {
236 struct nhg_hash_entry lookup = {};
237
238 lookup.id = id;
239 return hash_lookup(zrouter.nhgs_id, &lookup);
240 }
241
242 static int zebra_nhg_insert_id(struct nhg_hash_entry *nhe)
243 {
244 if (hash_lookup(zrouter.nhgs_id, nhe)) {
245 flog_err(
246 EC_ZEBRA_NHG_TABLE_INSERT_FAILED,
247 "Failed inserting NHG id=%u into the ID hash table, entry already exists",
248 nhe->id);
249 return -1;
250 }
251
252 hash_get(zrouter.nhgs_id, nhe, hash_alloc_intern);
253
254 return 0;
255 }
256
257 static void zebra_nhg_set_if(struct nhg_hash_entry *nhe, struct interface *ifp)
258 {
259 nhe->ifp = ifp;
260 if_nhg_dependents_add(ifp, nhe);
261 }
262
263 static void
264 zebra_nhg_connect_depends(struct nhg_hash_entry *nhe,
265 struct nhg_connected_tree_head nhg_depends)
266 {
267 struct nhg_connected *rb_node_dep = NULL;
268
269 /* This has been allocated higher above in the stack. Could probably
270 * re-allocate and free the old stuff but just using the same memory
271 * for now. Otherwise, their might be a time trade-off for repeated
272 * alloc/frees as startup.
273 */
274 nhe->nhg_depends = nhg_depends;
275
276 /* Attach backpointer to anything that it depends on */
277 zebra_nhg_dependents_init(nhe);
278 if (!zebra_nhg_depends_is_empty(nhe)) {
279 frr_each(nhg_connected_tree, &nhe->nhg_depends, rb_node_dep) {
280 zebra_nhg_dependents_add(rb_node_dep->nhe, nhe);
281 }
282 }
283
284 /* Add the ifp now if its not a group or recursive and has ifindex */
285 if (zebra_nhg_depends_is_empty(nhe) && nhe->nhg->nexthop
286 && nhe->nhg->nexthop->ifindex) {
287 struct interface *ifp = NULL;
288
289 ifp = if_lookup_by_index(nhe->nhg->nexthop->ifindex,
290 nhe->vrf_id);
291 if (ifp)
292 zebra_nhg_set_if(nhe, ifp);
293 else
294 flog_err(
295 EC_ZEBRA_IF_LOOKUP_FAILED,
296 "Zebra failed to lookup an interface with ifindex=%d in vrf=%u for NHE id=%u",
297 nhe->nhg->nexthop->ifindex, nhe->vrf_id,
298 nhe->id);
299 }
300 }
301
302 static struct nhg_hash_entry *zebra_nhg_copy(struct nhg_hash_entry *copy,
303 uint32_t id)
304 {
305 struct nhg_hash_entry *nhe;
306
307 nhe = XCALLOC(MTYPE_NHG, sizeof(struct nhg_hash_entry));
308
309 nhe->id = id;
310
311 nhe->nhg = nexthop_group_new();
312 nexthop_group_copy(nhe->nhg, copy->nhg);
313
314 nhe->vrf_id = copy->vrf_id;
315 nhe->afi = copy->afi;
316 nhe->type = copy->type ? copy->type : ZEBRA_ROUTE_NHG;
317 nhe->refcnt = 0;
318 nhe->dplane_ref = zebra_router_get_next_sequence();
319
320 return nhe;
321 }
322
323 /* Allocation via hash handler */
324 static void *zebra_nhg_hash_alloc(void *arg)
325 {
326 struct nhg_hash_entry *nhe = NULL;
327 struct nhg_hash_entry *copy = arg;
328
329 nhe = zebra_nhg_copy(copy, copy->id);
330
331 /* Mark duplicate nexthops in a group at creation time. */
332 nexthop_group_mark_duplicates(nhe->nhg);
333
334 zebra_nhg_connect_depends(nhe, copy->nhg_depends);
335 zebra_nhg_insert_id(nhe);
336
337 return nhe;
338 }
339
340 uint32_t zebra_nhg_hash_key(const void *arg)
341 {
342 const struct nhg_hash_entry *nhe = arg;
343
344 uint32_t key = 0x5a351234;
345
346 key = jhash_3words(nhe->vrf_id, nhe->afi, nexthop_group_hash(nhe->nhg),
347 key);
348
349 return key;
350 }
351
352 uint32_t zebra_nhg_id_key(const void *arg)
353 {
354 const struct nhg_hash_entry *nhe = arg;
355
356 return nhe->id;
357 }
358
359 bool zebra_nhg_hash_equal(const void *arg1, const void *arg2)
360 {
361 const struct nhg_hash_entry *nhe1 = arg1;
362 const struct nhg_hash_entry *nhe2 = arg2;
363 struct nexthop *nexthop1;
364 struct nexthop *nexthop2;
365
366 /* No matter what if they equal IDs, assume equal */
367 if (nhe1->id && nhe2->id && (nhe1->id == nhe2->id))
368 return true;
369
370 if (nhe1->vrf_id != nhe2->vrf_id)
371 return false;
372
373 if (nhe1->afi != nhe2->afi)
374 return false;
375
376 /* Nexthops should be sorted */
377 for (nexthop1 = nhe1->nhg->nexthop, nexthop2 = nhe2->nhg->nexthop;
378 nexthop1 || nexthop2;
379 nexthop1 = nexthop1->next, nexthop2 = nexthop2->next) {
380 if (nexthop1 && !nexthop2)
381 return false;
382
383 if (!nexthop1 && nexthop2)
384 return false;
385
386 /*
387 * We have to check the active flag of each individual one,
388 * not just the overall active_num. This solves the special case
389 * issue of a route with a nexthop group with one nexthop
390 * resolving to itself and thus marking it inactive. If we
391 * have two different routes each wanting to mark a different
392 * nexthop inactive, they need to hash to two different groups.
393 *
394 * If we just hashed on num_active, they would hash the same
395 * which is incorrect.
396 *
397 * ex)
398 * 1.1.1.0/24
399 * -> 1.1.1.1 dummy1 (inactive)
400 * -> 1.1.2.1 dummy2
401 *
402 * 1.1.2.0/24
403 * -> 1.1.1.1 dummy1
404 * -> 1.1.2.1 dummy2 (inactive)
405 *
406 * Without checking each individual one, they would hash to
407 * the same group and both have 1.1.1.1 dummy1 marked inactive.
408 *
409 */
410 if (CHECK_FLAG(nexthop1->flags, NEXTHOP_FLAG_ACTIVE)
411 != CHECK_FLAG(nexthop2->flags, NEXTHOP_FLAG_ACTIVE))
412 return false;
413
414 if (!nexthop_same(nexthop1, nexthop2))
415 return false;
416 }
417
418 return true;
419 }
420
421 bool zebra_nhg_hash_id_equal(const void *arg1, const void *arg2)
422 {
423 const struct nhg_hash_entry *nhe1 = arg1;
424 const struct nhg_hash_entry *nhe2 = arg2;
425
426 return nhe1->id == nhe2->id;
427 }
428
429 static int zebra_nhg_process_grp(struct nexthop_group *nhg,
430 struct nhg_connected_tree_head *depends,
431 struct nh_grp *grp, uint8_t count)
432 {
433 nhg_connected_tree_init(depends);
434
435 for (int i = 0; i < count; i++) {
436 struct nhg_hash_entry *depend = NULL;
437 /* We do not care about nexthop_grp.weight at
438 * this time. But we should figure out
439 * how to adapt this to our code in
440 * the future.
441 */
442 depend = depends_find_id_add(depends, grp[i].id);
443
444 if (!depend) {
445 flog_err(
446 EC_ZEBRA_NHG_SYNC,
447 "Received Nexthop Group from the kernel with a dependent Nexthop ID (%u) which we do not have in our table",
448 grp[i].id);
449 return -1;
450 }
451
452 /*
453 * If this is a nexthop with its own group
454 * dependencies, add them as well. Not sure its
455 * even possible to have a group within a group
456 * in the kernel.
457 */
458
459 copy_nexthops(&nhg->nexthop, depend->nhg->nexthop, NULL);
460 }
461
462 return 0;
463 }
464
465 static void handle_recursive_depend(struct nhg_connected_tree_head *nhg_depends,
466 struct nexthop *nh, afi_t afi)
467 {
468 struct nhg_hash_entry *depend = NULL;
469 struct nexthop_group resolved_ng = {};
470
471 _nexthop_group_add_sorted(&resolved_ng, nh);
472
473 depend = zebra_nhg_rib_find(0, &resolved_ng, afi);
474 depends_add(nhg_depends, depend);
475 }
476
477 static bool zebra_nhg_find(struct nhg_hash_entry **nhe, uint32_t id,
478 struct nexthop_group *nhg,
479 struct nhg_connected_tree_head *nhg_depends,
480 vrf_id_t vrf_id, afi_t afi, int type)
481 {
482 struct nhg_hash_entry lookup = {};
483
484 uint32_t old_id_counter = id_counter;
485
486 bool created = false;
487 bool recursive = false;
488
489 /*
490 * If it has an id at this point, we must have gotten it from the kernel
491 */
492 lookup.id = id ? id : ++id_counter;
493
494 lookup.type = type ? type : ZEBRA_ROUTE_NHG;
495 lookup.nhg = nhg;
496
497 if (lookup.nhg->nexthop->next) {
498 /* Groups can have all vrfs and AF's in them */
499 lookup.afi = AFI_UNSPEC;
500 lookup.vrf_id = 0;
501 } else {
502 switch (lookup.nhg->nexthop->type) {
503 case (NEXTHOP_TYPE_IFINDEX):
504 case (NEXTHOP_TYPE_BLACKHOLE):
505 /*
506 * This switch case handles setting the afi different
507 * for ipv4/v6 routes. Ifindex/blackhole nexthop
508 * objects cannot be ambiguous, they must be Address
509 * Family specific. If we get here, we will either use
510 * the AF of the route, or the one we got passed from
511 * here from the kernel.
512 */
513 lookup.afi = afi;
514 break;
515 case (NEXTHOP_TYPE_IPV4_IFINDEX):
516 case (NEXTHOP_TYPE_IPV4):
517 lookup.afi = AFI_IP;
518 break;
519 case (NEXTHOP_TYPE_IPV6_IFINDEX):
520 case (NEXTHOP_TYPE_IPV6):
521 lookup.afi = AFI_IP6;
522 break;
523 }
524
525 lookup.vrf_id = vrf_id;
526 }
527
528 if (id)
529 (*nhe) = zebra_nhg_lookup_id(id);
530 else
531 (*nhe) = hash_lookup(zrouter.nhgs, &lookup);
532
533 /* If it found an nhe in our tables, this new ID is unused */
534 if (*nhe)
535 id_counter = old_id_counter;
536
537 if (!(*nhe)) {
538 /* Only hash/lookup the depends if the first lookup
539 * fails to find something. This should hopefully save a
540 * lot of cycles for larger ecmp sizes.
541 */
542 if (nhg_depends)
543 /* If you don't want to hash on each nexthop in the
544 * nexthop group struct you can pass the depends
545 * directly. Kernel-side we do this since it just looks
546 * them up via IDs.
547 */
548 lookup.nhg_depends = *nhg_depends;
549 else {
550 if (nhg->nexthop->next) {
551 zebra_nhg_depends_init(&lookup);
552
553 /* If its a group, create a dependency tree */
554 struct nexthop *nh = NULL;
555
556 for (nh = nhg->nexthop; nh; nh = nh->next)
557 depends_find_add(&lookup.nhg_depends,
558 nh, afi);
559 } else if (CHECK_FLAG(nhg->nexthop->flags,
560 NEXTHOP_FLAG_RECURSIVE)) {
561 zebra_nhg_depends_init(&lookup);
562 handle_recursive_depend(&lookup.nhg_depends,
563 nhg->nexthop->resolved,
564 afi);
565 recursive = true;
566 }
567 }
568
569 (*nhe) = hash_get(zrouter.nhgs, &lookup, zebra_nhg_hash_alloc);
570 created = true;
571
572 if (recursive)
573 SET_FLAG((*nhe)->flags, NEXTHOP_GROUP_RECURSIVE);
574 }
575 return created;
576 }
577
578 /* Find/create a single nexthop */
579 static struct nhg_hash_entry *
580 zebra_nhg_find_nexthop(uint32_t id, struct nexthop *nh, afi_t afi, int type)
581 {
582 struct nhg_hash_entry *nhe = NULL;
583 struct nexthop_group nhg = {};
584
585 _nexthop_group_add_sorted(&nhg, nh);
586
587 zebra_nhg_find(&nhe, id, &nhg, NULL, nh->vrf_id, afi, 0);
588
589 return nhe;
590 }
591
592 static uint32_t nhg_ctx_get_id(const struct nhg_ctx *ctx)
593 {
594 return ctx->id;
595 }
596
597 static void nhg_ctx_set_status(struct nhg_ctx *ctx, enum nhg_ctx_status status)
598 {
599 ctx->status = status;
600 }
601
602 static enum nhg_ctx_status nhg_ctx_get_status(const struct nhg_ctx *ctx)
603 {
604 return ctx->status;
605 }
606
607 static void nhg_ctx_set_op(struct nhg_ctx *ctx, enum nhg_ctx_op_e op)
608 {
609 ctx->op = op;
610 }
611
612 static enum nhg_ctx_op_e nhg_ctx_get_op(const struct nhg_ctx *ctx)
613 {
614 return ctx->op;
615 }
616
617 static vrf_id_t nhg_ctx_get_vrf_id(const struct nhg_ctx *ctx)
618 {
619 return ctx->vrf_id;
620 }
621
622 static int nhg_ctx_get_type(const struct nhg_ctx *ctx)
623 {
624 return ctx->type;
625 }
626
627 static int nhg_ctx_get_afi(const struct nhg_ctx *ctx)
628 {
629 return ctx->afi;
630 }
631
632 static struct nexthop *nhg_ctx_get_nh(struct nhg_ctx *ctx)
633 {
634 return &ctx->u.nh;
635 }
636
637 static uint8_t nhg_ctx_get_count(const struct nhg_ctx *ctx)
638 {
639 return ctx->count;
640 }
641
642 static struct nh_grp *nhg_ctx_get_grp(struct nhg_ctx *ctx)
643 {
644 return ctx->u.grp;
645 }
646
647 static struct nhg_ctx *nhg_ctx_new()
648 {
649 struct nhg_ctx *new = NULL;
650
651 new = XCALLOC(MTYPE_NHG_CTX, sizeof(struct nhg_ctx));
652
653 return new;
654 }
655
656 static void nhg_ctx_free(struct nhg_ctx **ctx)
657 {
658 struct nexthop *nh;
659
660 if (ctx == NULL)
661 return;
662
663 assert((*ctx) != NULL);
664
665 if (nhg_ctx_get_count(*ctx))
666 goto done;
667
668 nh = nhg_ctx_get_nh(*ctx);
669
670 nexthop_del_labels(nh);
671
672 done:
673 XFREE(MTYPE_NHG_CTX, *ctx);
674 *ctx = NULL;
675 }
676
677 static struct nhg_ctx *nhg_ctx_init(uint32_t id, struct nexthop *nh,
678 struct nh_grp *grp, vrf_id_t vrf_id,
679 afi_t afi, int type, uint8_t count)
680 {
681 struct nhg_ctx *ctx = NULL;
682
683 ctx = nhg_ctx_new();
684
685 ctx->id = id;
686 ctx->vrf_id = vrf_id;
687 ctx->afi = afi;
688 ctx->type = type;
689 ctx->count = count;
690
691 if (count)
692 /* Copy over the array */
693 memcpy(&ctx->u.grp, grp, count * sizeof(struct nh_grp));
694 else if (nh)
695 ctx->u.nh = *nh;
696
697 return ctx;
698 }
699
700 static bool zebra_nhg_contains_unhashable(struct nhg_hash_entry *nhe)
701 {
702 struct nhg_connected *rb_node_dep = NULL;
703
704 frr_each(nhg_connected_tree, &nhe->nhg_depends, rb_node_dep) {
705 if (CHECK_FLAG(rb_node_dep->nhe->flags,
706 NEXTHOP_GROUP_UNHASHABLE))
707 return true;
708 }
709
710 return false;
711 }
712
713 static void zebra_nhg_set_unhashable(struct nhg_hash_entry *nhe)
714 {
715 SET_FLAG(nhe->flags, NEXTHOP_GROUP_UNHASHABLE);
716 SET_FLAG(nhe->flags, NEXTHOP_GROUP_INSTALLED);
717
718 flog_warn(
719 EC_ZEBRA_DUPLICATE_NHG_MESSAGE,
720 "Nexthop Group with ID (%d) is a duplicate, therefore unhashable, ignoring",
721 nhe->id);
722 }
723
724 static void zebra_nhg_set_valid(struct nhg_hash_entry *nhe)
725 {
726 struct nhg_connected *rb_node_dep;
727
728 SET_FLAG(nhe->flags, NEXTHOP_GROUP_VALID);
729
730 frr_each(nhg_connected_tree, &nhe->nhg_dependents, rb_node_dep)
731 zebra_nhg_set_valid(rb_node_dep->nhe);
732 }
733
734 static void zebra_nhg_set_invalid(struct nhg_hash_entry *nhe)
735 {
736 struct nhg_connected *rb_node_dep;
737
738 UNSET_FLAG(nhe->flags, NEXTHOP_GROUP_VALID);
739
740 /* Update validity of nexthops depending on it */
741 frr_each(nhg_connected_tree, &nhe->nhg_dependents, rb_node_dep)
742 zebra_nhg_check_valid(rb_node_dep->nhe);
743 }
744
745 void zebra_nhg_check_valid(struct nhg_hash_entry *nhe)
746 {
747 struct nhg_connected *rb_node_dep = NULL;
748 bool valid = false;
749
750 /* If anthing else in the group is valid, the group is valid */
751 frr_each(nhg_connected_tree, &nhe->nhg_depends, rb_node_dep) {
752 if (CHECK_FLAG(rb_node_dep->nhe->flags, NEXTHOP_GROUP_VALID)) {
753 valid = true;
754 goto done;
755 }
756 }
757
758 done:
759 if (valid)
760 zebra_nhg_set_valid(nhe);
761 else
762 zebra_nhg_set_invalid(nhe);
763 }
764
765
766 static void zebra_nhg_release(struct nhg_hash_entry *nhe)
767 {
768 /* Remove it from any lists it may be on */
769 zebra_nhg_depends_release(nhe);
770 zebra_nhg_dependents_release(nhe);
771 if (nhe->ifp)
772 if_nhg_dependents_del(nhe->ifp, nhe);
773
774 /*
775 * If its unhashable, we didn't store it here and have to be
776 * sure we don't clear one thats actually being used.
777 */
778 if (!CHECK_FLAG(nhe->flags, NEXTHOP_GROUP_UNHASHABLE))
779 hash_release(zrouter.nhgs, nhe);
780
781 hash_release(zrouter.nhgs_id, nhe);
782 }
783
784 static void zebra_nhg_handle_uninstall(struct nhg_hash_entry *nhe)
785 {
786 zebra_nhg_release(nhe);
787 zebra_nhg_free(nhe);
788 }
789
790 static void zebra_nhg_handle_install(struct nhg_hash_entry *nhe)
791 {
792 /* Update validity of groups depending on it */
793 struct nhg_connected *rb_node_dep;
794
795 frr_each_safe(nhg_connected_tree, &nhe->nhg_dependents, rb_node_dep)
796 zebra_nhg_set_valid(rb_node_dep->nhe);
797 }
798
799 /*
800 * The kernel/other program has changed the state of a nexthop object we are
801 * using.
802 */
803 static void zebra_nhg_handle_kernel_state_change(struct nhg_hash_entry *nhe,
804 bool is_delete)
805 {
806 if (nhe->refcnt) {
807 flog_err(
808 EC_ZEBRA_NHG_SYNC,
809 "Kernel %s a nexthop group with ID (%u) that we are still using for a route, sending it back down",
810 (is_delete ? "deleted" : "updated"), nhe->id);
811
812 UNSET_FLAG(nhe->flags, NEXTHOP_GROUP_INSTALLED);
813 zebra_nhg_install_kernel(nhe);
814 } else
815 zebra_nhg_handle_uninstall(nhe);
816 }
817
818 static int nhg_ctx_process_new(struct nhg_ctx *ctx)
819 {
820 struct nexthop_group *nhg = NULL;
821 struct nhg_connected_tree_head nhg_depends = {};
822 struct nhg_hash_entry *lookup = NULL;
823 struct nhg_hash_entry *nhe = NULL;
824
825 uint32_t id = nhg_ctx_get_id(ctx);
826 uint8_t count = nhg_ctx_get_count(ctx);
827 vrf_id_t vrf_id = nhg_ctx_get_vrf_id(ctx);
828 int type = nhg_ctx_get_type(ctx);
829 afi_t afi = nhg_ctx_get_afi(ctx);
830
831 lookup = zebra_nhg_lookup_id(id);
832
833 if (lookup) {
834 /* This is already present in our table, hence an update
835 * that we did not initate.
836 */
837 zebra_nhg_handle_kernel_state_change(lookup, false);
838 return 0;
839 }
840
841 if (nhg_ctx_get_count(ctx)) {
842 nhg = nexthop_group_new();
843 if (zebra_nhg_process_grp(nhg, &nhg_depends,
844 nhg_ctx_get_grp(ctx), count)) {
845 depends_decrement_free(&nhg_depends);
846 nexthop_group_delete(&nhg);
847 return -ENOENT;
848 }
849
850 if (!zebra_nhg_find(&nhe, id, nhg, &nhg_depends, vrf_id, type,
851 afi))
852 depends_decrement_free(&nhg_depends);
853
854 /* These got copied over in zebra_nhg_alloc() */
855 nexthop_group_delete(&nhg);
856 } else
857 nhe = zebra_nhg_find_nexthop(id, nhg_ctx_get_nh(ctx), afi,
858 type);
859
860 if (nhe) {
861 if (id != nhe->id) {
862 struct nhg_hash_entry *kernel_nhe = NULL;
863
864 /* Duplicate but with different ID from
865 * the kernel
866 */
867
868 /* The kernel allows duplicate nexthops
869 * as long as they have different IDs.
870 * We are ignoring those to prevent
871 * syncing problems with the kernel
872 * changes.
873 *
874 * We maintain them *ONLY* in the ID hash table to
875 * track them and set the flag to indicated
876 * their attributes are unhashable.
877 */
878
879 kernel_nhe = zebra_nhg_copy(nhe, id);
880 zebra_nhg_insert_id(kernel_nhe);
881 zebra_nhg_set_unhashable(kernel_nhe);
882 } else if (zebra_nhg_contains_unhashable(nhe)) {
883 /* The group we got contains an unhashable/duplicated
884 * depend, so lets mark this group as unhashable as well
885 * and release it from the non-ID hash.
886 */
887 hash_release(zrouter.nhgs, nhe);
888 zebra_nhg_set_unhashable(nhe);
889 } else {
890 /* It actually created a new nhe */
891 SET_FLAG(nhe->flags, NEXTHOP_GROUP_VALID);
892 SET_FLAG(nhe->flags, NEXTHOP_GROUP_INSTALLED);
893 }
894 } else {
895 flog_err(
896 EC_ZEBRA_TABLE_LOOKUP_FAILED,
897 "Zebra failed to find or create a nexthop hash entry for ID (%u)",
898 id);
899 return -1;
900 }
901
902 return 0;
903 }
904
905 static int nhg_ctx_process_del(struct nhg_ctx *ctx)
906 {
907 struct nhg_hash_entry *nhe = NULL;
908 uint32_t id = nhg_ctx_get_id(ctx);
909
910 nhe = zebra_nhg_lookup_id(id);
911
912 if (!nhe) {
913 flog_warn(
914 EC_ZEBRA_BAD_NHG_MESSAGE,
915 "Kernel delete message received for nexthop group ID (%u) that we do not have in our ID table",
916 id);
917 return -1;
918 }
919
920 zebra_nhg_handle_kernel_state_change(nhe, true);
921
922 return 0;
923 }
924
925 static void nhg_ctx_fini(struct nhg_ctx **ctx)
926 {
927 /*
928 * Just freeing for now, maybe do something more in the future
929 * based on flag.
930 */
931
932 nhg_ctx_free(ctx);
933 }
934
935 static int queue_add(struct nhg_ctx *ctx)
936 {
937 /* If its queued or already processed do nothing */
938 if (nhg_ctx_get_status(ctx) == NHG_CTX_QUEUED)
939 return 0;
940
941 if (rib_queue_nhg_add(ctx)) {
942 nhg_ctx_set_status(ctx, NHG_CTX_FAILURE);
943 return -1;
944 }
945
946 nhg_ctx_set_status(ctx, NHG_CTX_QUEUED);
947
948 return 0;
949 }
950
951 int nhg_ctx_process(struct nhg_ctx *ctx)
952 {
953 int ret = 0;
954
955 switch (nhg_ctx_get_op(ctx)) {
956 case NHG_CTX_OP_NEW:
957 ret = nhg_ctx_process_new(ctx);
958 if (nhg_ctx_get_count(ctx) && ret == -ENOENT
959 && nhg_ctx_get_status(ctx) != NHG_CTX_REQUEUED) {
960 /**
961 * We have entered a situation where we are
962 * processing a group from the kernel
963 * that has a contained nexthop which
964 * we have not yet processed.
965 *
966 * Re-enqueue this ctx to be handled exactly one
967 * more time (indicated by the flag).
968 *
969 * By the time we get back to it, we
970 * should have processed its depends.
971 */
972 nhg_ctx_set_status(ctx, NHG_CTX_NONE);
973 if (queue_add(ctx) == 0) {
974 nhg_ctx_set_status(ctx, NHG_CTX_REQUEUED);
975 return 0;
976 }
977 }
978 break;
979 case NHG_CTX_OP_DEL:
980 ret = nhg_ctx_process_del(ctx);
981 case NHG_CTX_OP_NONE:
982 break;
983 }
984
985 nhg_ctx_set_status(ctx, (ret ? NHG_CTX_FAILURE : NHG_CTX_SUCCESS));
986
987 nhg_ctx_fini(&ctx);
988
989 return ret;
990 }
991
992 /* Kernel-side, you either get a single new nexthop or a array of ID's */
993 int zebra_nhg_kernel_find(uint32_t id, struct nexthop *nh, struct nh_grp *grp,
994 uint8_t count, vrf_id_t vrf_id, afi_t afi, int type,
995 int startup)
996 {
997 struct nhg_ctx *ctx = NULL;
998
999 if (id > id_counter)
1000 /* Increase our counter so we don't try to create
1001 * an ID that already exists
1002 */
1003 id_counter = id;
1004
1005 ctx = nhg_ctx_init(id, nh, grp, vrf_id, afi, type, count);
1006 nhg_ctx_set_op(ctx, NHG_CTX_OP_NEW);
1007
1008 /* Under statup conditions, we need to handle them immediately
1009 * like we do for routes. Otherwise, we are going to get a route
1010 * with a nhe_id that we have not handled.
1011 */
1012 if (startup)
1013 return nhg_ctx_process(ctx);
1014
1015 if (queue_add(ctx)) {
1016 nhg_ctx_fini(&ctx);
1017 return -1;
1018 }
1019
1020 return 0;
1021 }
1022
1023 /* Kernel-side, received delete message */
1024 int zebra_nhg_kernel_del(uint32_t id)
1025 {
1026 struct nhg_ctx *ctx = NULL;
1027
1028 ctx = nhg_ctx_init(id, NULL, NULL, 0, 0, 0, 0);
1029
1030 nhg_ctx_set_op(ctx, NHG_CTX_OP_DEL);
1031
1032 if (queue_add(ctx)) {
1033 nhg_ctx_fini(&ctx);
1034 return -1;
1035 }
1036
1037 return 0;
1038 }
1039
1040 /* Some dependency helper functions */
1041 static struct nhg_hash_entry *depends_find(struct nexthop *nh, afi_t afi)
1042 {
1043 struct nexthop *lookup = NULL;
1044 struct nhg_hash_entry *nhe = NULL;
1045
1046 if (!nh)
1047 goto done;
1048
1049 copy_nexthops(&lookup, nh, NULL);
1050
1051 /* Clear it, in case its a group */
1052 nexthops_free(lookup->next);
1053 nexthops_free(lookup->prev);
1054 lookup->next = NULL;
1055 lookup->prev = NULL;
1056
1057 nhe = zebra_nhg_find_nexthop(0, lookup, afi, 0);
1058
1059 nexthops_free(lookup);
1060
1061 done:
1062 return nhe;
1063 }
1064
1065 static void depends_add(struct nhg_connected_tree_head *head,
1066 struct nhg_hash_entry *depend)
1067 {
1068 nhg_connected_tree_add_nhe(head, depend);
1069 zebra_nhg_increment_ref(depend);
1070 }
1071
1072 static struct nhg_hash_entry *
1073 depends_find_add(struct nhg_connected_tree_head *head, struct nexthop *nh,
1074 afi_t afi)
1075 {
1076 struct nhg_hash_entry *depend = NULL;
1077
1078 depend = depends_find(nh, afi);
1079
1080 if (depend)
1081 depends_add(head, depend);
1082
1083 return depend;
1084 }
1085
1086 static struct nhg_hash_entry *
1087 depends_find_id_add(struct nhg_connected_tree_head *head, uint32_t id)
1088 {
1089 struct nhg_hash_entry *depend = NULL;
1090
1091 depend = zebra_nhg_lookup_id(id);
1092
1093 if (depend)
1094 depends_add(head, depend);
1095
1096 return depend;
1097 }
1098
1099 static void depends_decrement_free(struct nhg_connected_tree_head *head)
1100 {
1101 nhg_connected_tree_decrement_ref(head);
1102 nhg_connected_tree_free(head);
1103 }
1104
1105 /* Rib-side, you get a nexthop group struct */
1106 struct nhg_hash_entry *
1107 zebra_nhg_rib_find(uint32_t id, struct nexthop_group *nhg, afi_t rt_afi)
1108 {
1109 struct nhg_hash_entry *nhe = NULL;
1110
1111 if (!(nhg && nhg->nexthop)) {
1112 flog_err(EC_ZEBRA_TABLE_LOOKUP_FAILED,
1113 "No nexthop passed to %s", __func__);
1114 return NULL;
1115 }
1116
1117 zebra_nhg_find(&nhe, id, nhg, NULL, nhg->nexthop->vrf_id, rt_afi, 0);
1118
1119 return nhe;
1120 }
1121
1122 static void zebra_nhg_free_members(struct nhg_hash_entry *nhe)
1123 {
1124 nexthop_group_delete(&nhe->nhg);
1125 /* Decrement to remove connection ref */
1126 nhg_connected_tree_decrement_ref(&nhe->nhg_depends);
1127 nhg_connected_tree_free(&nhe->nhg_depends);
1128 nhg_connected_tree_free(&nhe->nhg_dependents);
1129 }
1130
1131 void zebra_nhg_free(void *arg)
1132 {
1133 struct nhg_hash_entry *nhe = NULL;
1134
1135 nhe = (struct nhg_hash_entry *)arg;
1136
1137 if (nhe->refcnt)
1138 zlog_debug("nhe_id=%u hash refcnt=%d", nhe->id, nhe->refcnt);
1139
1140 zebra_nhg_free_members(nhe);
1141
1142 XFREE(MTYPE_NHG, nhe);
1143 }
1144
1145 void zebra_nhg_decrement_ref(struct nhg_hash_entry *nhe)
1146 {
1147 nhe->refcnt--;
1148
1149 if (!zebra_nhg_depends_is_empty(nhe))
1150 nhg_connected_tree_decrement_ref(&nhe->nhg_depends);
1151
1152 if (ZEBRA_NHG_CREATED(nhe) && nhe->refcnt <= 0)
1153 zebra_nhg_uninstall_kernel(nhe);
1154 }
1155
1156 void zebra_nhg_increment_ref(struct nhg_hash_entry *nhe)
1157 {
1158 nhe->refcnt++;
1159
1160 if (!zebra_nhg_depends_is_empty(nhe))
1161 nhg_connected_tree_increment_ref(&nhe->nhg_depends);
1162 }
1163
1164 static void nexthop_set_resolved(afi_t afi, const struct nexthop *newhop,
1165 struct nexthop *nexthop)
1166 {
1167 struct nexthop *resolved_hop;
1168 uint8_t num_labels = 0;
1169 mpls_label_t labels[MPLS_MAX_LABELS];
1170 enum lsp_types_t label_type = ZEBRA_LSP_NONE;
1171 int i = 0;
1172
1173 resolved_hop = nexthop_new();
1174 SET_FLAG(resolved_hop->flags, NEXTHOP_FLAG_ACTIVE);
1175
1176 resolved_hop->vrf_id = nexthop->vrf_id;
1177 switch (newhop->type) {
1178 case NEXTHOP_TYPE_IPV4:
1179 case NEXTHOP_TYPE_IPV4_IFINDEX:
1180 /* If the resolving route specifies a gateway, use it */
1181 resolved_hop->type = newhop->type;
1182 resolved_hop->gate.ipv4 = newhop->gate.ipv4;
1183
1184 if (newhop->ifindex) {
1185 resolved_hop->type = NEXTHOP_TYPE_IPV4_IFINDEX;
1186 resolved_hop->ifindex = newhop->ifindex;
1187 }
1188 break;
1189 case NEXTHOP_TYPE_IPV6:
1190 case NEXTHOP_TYPE_IPV6_IFINDEX:
1191 resolved_hop->type = newhop->type;
1192 resolved_hop->gate.ipv6 = newhop->gate.ipv6;
1193
1194 if (newhop->ifindex) {
1195 resolved_hop->type = NEXTHOP_TYPE_IPV6_IFINDEX;
1196 resolved_hop->ifindex = newhop->ifindex;
1197 }
1198 break;
1199 case NEXTHOP_TYPE_IFINDEX:
1200 /* If the resolving route is an interface route,
1201 * it means the gateway we are looking up is connected
1202 * to that interface. (The actual network is _not_ onlink).
1203 * Therefore, the resolved route should have the original
1204 * gateway as nexthop as it is directly connected.
1205 *
1206 * On Linux, we have to set the onlink netlink flag because
1207 * otherwise, the kernel won't accept the route.
1208 */
1209 resolved_hop->flags |= NEXTHOP_FLAG_ONLINK;
1210 if (afi == AFI_IP) {
1211 resolved_hop->type = NEXTHOP_TYPE_IPV4_IFINDEX;
1212 resolved_hop->gate.ipv4 = nexthop->gate.ipv4;
1213 } else if (afi == AFI_IP6) {
1214 resolved_hop->type = NEXTHOP_TYPE_IPV6_IFINDEX;
1215 resolved_hop->gate.ipv6 = nexthop->gate.ipv6;
1216 }
1217 resolved_hop->ifindex = newhop->ifindex;
1218 break;
1219 case NEXTHOP_TYPE_BLACKHOLE:
1220 resolved_hop->type = NEXTHOP_TYPE_BLACKHOLE;
1221 resolved_hop->bh_type = newhop->bh_type;
1222 break;
1223 }
1224
1225 if (newhop->flags & NEXTHOP_FLAG_ONLINK)
1226 resolved_hop->flags |= NEXTHOP_FLAG_ONLINK;
1227
1228 /* Copy labels of the resolved route and the parent resolving to it */
1229 if (newhop->nh_label) {
1230 for (i = 0; i < newhop->nh_label->num_labels; i++)
1231 labels[num_labels++] = newhop->nh_label->label[i];
1232 label_type = newhop->nh_label_type;
1233 }
1234
1235 if (nexthop->nh_label) {
1236 for (i = 0; i < nexthop->nh_label->num_labels; i++)
1237 labels[num_labels++] = nexthop->nh_label->label[i];
1238
1239 /* If the parent has labels, use its type */
1240 label_type = nexthop->nh_label_type;
1241 }
1242
1243 if (num_labels)
1244 nexthop_add_labels(resolved_hop, label_type, num_labels,
1245 labels);
1246
1247 resolved_hop->rparent = nexthop;
1248 _nexthop_add(&nexthop->resolved, resolved_hop);
1249 }
1250
1251 /* Checks if nexthop we are trying to resolve to is valid */
1252 static bool nexthop_valid_resolve(const struct nexthop *nexthop,
1253 const struct nexthop *resolved)
1254 {
1255 /* Can't resolve to a recursive nexthop */
1256 if (CHECK_FLAG(resolved->flags, NEXTHOP_FLAG_RECURSIVE))
1257 return false;
1258
1259 switch (nexthop->type) {
1260 case NEXTHOP_TYPE_IPV4_IFINDEX:
1261 case NEXTHOP_TYPE_IPV6_IFINDEX:
1262 /* If the nexthop we are resolving to does not match the
1263 * ifindex for the nexthop the route wanted, its not valid.
1264 */
1265 if (nexthop->ifindex != resolved->ifindex)
1266 return false;
1267 break;
1268 case NEXTHOP_TYPE_IPV4:
1269 case NEXTHOP_TYPE_IPV6:
1270 case NEXTHOP_TYPE_IFINDEX:
1271 case NEXTHOP_TYPE_BLACKHOLE:
1272 break;
1273 }
1274
1275 return true;
1276 }
1277
1278 /*
1279 * Given a nexthop we need to properly recursively resolve
1280 * the route. As such, do a table lookup to find and match
1281 * if at all possible. Set the nexthop->ifindex and resolved_id
1282 * as appropriate
1283 */
1284 static int nexthop_active(afi_t afi, struct route_entry *re,
1285 struct nexthop *nexthop, struct route_node *top)
1286 {
1287 struct prefix p;
1288 struct route_table *table;
1289 struct route_node *rn;
1290 struct route_entry *match = NULL;
1291 int resolved;
1292 struct nexthop *newhop;
1293 struct interface *ifp;
1294 rib_dest_t *dest;
1295 struct zebra_vrf *zvrf;
1296
1297 if ((nexthop->type == NEXTHOP_TYPE_IPV4)
1298 || nexthop->type == NEXTHOP_TYPE_IPV6)
1299 nexthop->ifindex = 0;
1300
1301
1302 UNSET_FLAG(nexthop->flags, NEXTHOP_FLAG_RECURSIVE);
1303 nexthops_free(nexthop->resolved);
1304 nexthop->resolved = NULL;
1305 re->nexthop_mtu = 0;
1306
1307 /*
1308 * If the kernel has sent us a NEW route, then
1309 * by golly gee whiz it's a good route.
1310 *
1311 * If its an already INSTALLED route we have already handled, then the
1312 * kernel route's nexthop might have became unreachable
1313 * and we have to handle that.
1314 */
1315 if (!CHECK_FLAG(re->status, ROUTE_ENTRY_INSTALLED)
1316 && (re->type == ZEBRA_ROUTE_KERNEL
1317 || re->type == ZEBRA_ROUTE_SYSTEM))
1318 return 1;
1319
1320 /*
1321 * Check to see if we should trust the passed in information
1322 * for UNNUMBERED interfaces as that we won't find the GW
1323 * address in the routing table.
1324 * This check should suffice to handle IPv4 or IPv6 routes
1325 * sourced from EVPN routes which are installed with the
1326 * next hop as the remote VTEP IP.
1327 */
1328 if (CHECK_FLAG(nexthop->flags, NEXTHOP_FLAG_ONLINK)) {
1329 ifp = if_lookup_by_index(nexthop->ifindex, nexthop->vrf_id);
1330 if (!ifp) {
1331 if (IS_ZEBRA_DEBUG_RIB_DETAILED)
1332 zlog_debug(
1333 "\t%s: Onlink and interface: %u[%u] does not exist",
1334 __PRETTY_FUNCTION__, nexthop->ifindex,
1335 nexthop->vrf_id);
1336 return 0;
1337 }
1338 if (connected_is_unnumbered(ifp)) {
1339 if (if_is_operative(ifp))
1340 return 1;
1341
1342 if (IS_ZEBRA_DEBUG_RIB_DETAILED)
1343 zlog_debug(
1344 "\t%s: Onlink and interface %s is not operative",
1345 __PRETTY_FUNCTION__, ifp->name);
1346 return 0;
1347 }
1348 if (!if_is_operative(ifp)) {
1349 if (IS_ZEBRA_DEBUG_RIB_DETAILED)
1350 zlog_debug(
1351 "\t%s: Interface %s is not unnumbered",
1352 __PRETTY_FUNCTION__, ifp->name);
1353 return 0;
1354 }
1355 }
1356
1357 /* Make lookup prefix. */
1358 memset(&p, 0, sizeof(struct prefix));
1359 switch (afi) {
1360 case AFI_IP:
1361 p.family = AF_INET;
1362 p.prefixlen = IPV4_MAX_PREFIXLEN;
1363 p.u.prefix4 = nexthop->gate.ipv4;
1364 break;
1365 case AFI_IP6:
1366 p.family = AF_INET6;
1367 p.prefixlen = IPV6_MAX_PREFIXLEN;
1368 p.u.prefix6 = nexthop->gate.ipv6;
1369 break;
1370 default:
1371 assert(afi != AFI_IP && afi != AFI_IP6);
1372 break;
1373 }
1374 /* Lookup table. */
1375 table = zebra_vrf_table(afi, SAFI_UNICAST, nexthop->vrf_id);
1376 /* get zvrf */
1377 zvrf = zebra_vrf_lookup_by_id(nexthop->vrf_id);
1378 if (!table || !zvrf) {
1379 if (IS_ZEBRA_DEBUG_RIB_DETAILED)
1380 zlog_debug("\t%s: Table not found",
1381 __PRETTY_FUNCTION__);
1382 return 0;
1383 }
1384
1385 rn = route_node_match(table, (struct prefix *)&p);
1386 while (rn) {
1387 route_unlock_node(rn);
1388
1389 /* Lookup should halt if we've matched against ourselves ('top',
1390 * if specified) - i.e., we cannot have a nexthop NH1 is
1391 * resolved by a route NH1. The exception is if the route is a
1392 * host route.
1393 */
1394 if (top && rn == top)
1395 if (((afi == AFI_IP) && (rn->p.prefixlen != 32))
1396 || ((afi == AFI_IP6) && (rn->p.prefixlen != 128))) {
1397 if (IS_ZEBRA_DEBUG_RIB_DETAILED)
1398 zlog_debug(
1399 "\t%s: Matched against ourself and prefix length is not max bit length",
1400 __PRETTY_FUNCTION__);
1401 return 0;
1402 }
1403
1404 /* Pick up selected route. */
1405 /* However, do not resolve over default route unless explicitly
1406 * allowed.
1407 */
1408 if (is_default_prefix(&rn->p)
1409 && !rnh_resolve_via_default(zvrf, p.family)) {
1410 if (IS_ZEBRA_DEBUG_RIB_DETAILED)
1411 zlog_debug(
1412 "\t:%s: Resolved against default route",
1413 __PRETTY_FUNCTION__);
1414 return 0;
1415 }
1416
1417 dest = rib_dest_from_rnode(rn);
1418 if (dest && dest->selected_fib
1419 && !CHECK_FLAG(dest->selected_fib->status,
1420 ROUTE_ENTRY_REMOVED)
1421 && dest->selected_fib->type != ZEBRA_ROUTE_TABLE)
1422 match = dest->selected_fib;
1423
1424 /* If there is no selected route or matched route is EGP, go up
1425 * tree.
1426 */
1427 if (!match) {
1428 do {
1429 rn = rn->parent;
1430 } while (rn && rn->info == NULL);
1431 if (rn)
1432 route_lock_node(rn);
1433
1434 continue;
1435 }
1436
1437 if (match->type == ZEBRA_ROUTE_CONNECT) {
1438 /* Directly point connected route. */
1439 newhop = match->ng->nexthop;
1440 if (newhop) {
1441 if (nexthop->type == NEXTHOP_TYPE_IPV4
1442 || nexthop->type == NEXTHOP_TYPE_IPV6)
1443 nexthop->ifindex = newhop->ifindex;
1444 }
1445 return 1;
1446 } else if (CHECK_FLAG(re->flags, ZEBRA_FLAG_ALLOW_RECURSION)) {
1447 resolved = 0;
1448 for (ALL_NEXTHOPS_PTR(match->ng, newhop)) {
1449 if (!CHECK_FLAG(match->status,
1450 ROUTE_ENTRY_INSTALLED))
1451 continue;
1452 if (!nexthop_valid_resolve(nexthop, newhop))
1453 continue;
1454
1455 SET_FLAG(nexthop->flags,
1456 NEXTHOP_FLAG_RECURSIVE);
1457 nexthop_set_resolved(afi, newhop, nexthop);
1458 resolved = 1;
1459 }
1460 if (resolved)
1461 re->nexthop_mtu = match->mtu;
1462
1463 if (!resolved && IS_ZEBRA_DEBUG_RIB_DETAILED)
1464 zlog_debug("\t%s: Recursion failed to find",
1465 __PRETTY_FUNCTION__);
1466 return resolved;
1467 } else if (re->type == ZEBRA_ROUTE_STATIC) {
1468 resolved = 0;
1469 for (ALL_NEXTHOPS_PTR(match->ng, newhop)) {
1470 if (!CHECK_FLAG(match->status,
1471 ROUTE_ENTRY_INSTALLED))
1472 continue;
1473 if (!nexthop_valid_resolve(nexthop, newhop))
1474 continue;
1475
1476 SET_FLAG(nexthop->flags,
1477 NEXTHOP_FLAG_RECURSIVE);
1478 nexthop_set_resolved(afi, newhop, nexthop);
1479 resolved = 1;
1480 }
1481 if (resolved)
1482 re->nexthop_mtu = match->mtu;
1483
1484 if (!resolved && IS_ZEBRA_DEBUG_RIB_DETAILED)
1485 zlog_debug(
1486 "\t%s: Static route unable to resolve",
1487 __PRETTY_FUNCTION__);
1488 return resolved;
1489 } else {
1490 if (IS_ZEBRA_DEBUG_RIB_DETAILED) {
1491 zlog_debug(
1492 "\t%s: Route Type %s has not turned on recursion",
1493 __PRETTY_FUNCTION__,
1494 zebra_route_string(re->type));
1495 if (re->type == ZEBRA_ROUTE_BGP
1496 && !CHECK_FLAG(re->flags, ZEBRA_FLAG_IBGP))
1497 zlog_debug(
1498 "\tEBGP: see \"disable-ebgp-connected-route-check\" or \"disable-connected-check\"");
1499 }
1500 return 0;
1501 }
1502 }
1503 if (IS_ZEBRA_DEBUG_RIB_DETAILED)
1504 zlog_debug("\t%s: Nexthop did not lookup in table",
1505 __PRETTY_FUNCTION__);
1506 return 0;
1507 }
1508
1509 /* This function verifies reachability of one given nexthop, which can be
1510 * numbered or unnumbered, IPv4 or IPv6. The result is unconditionally stored
1511 * in nexthop->flags field. The nexthop->ifindex will be updated
1512 * appropriately as well. An existing route map can turn
1513 * (otherwise active) nexthop into inactive, but not vice versa.
1514 *
1515 * If it finds a nexthop recursivedly, set the resolved_id
1516 * to match that nexthop's nhg_hash_entry ID;
1517 *
1518 * The return value is the final value of 'ACTIVE' flag.
1519 */
1520 static unsigned nexthop_active_check(struct route_node *rn,
1521 struct route_entry *re,
1522 struct nexthop *nexthop)
1523 {
1524 struct interface *ifp;
1525 route_map_result_t ret = RMAP_PERMITMATCH;
1526 int family;
1527 char buf[SRCDEST2STR_BUFFER];
1528 const struct prefix *p, *src_p;
1529 struct zebra_vrf *zvrf;
1530
1531 srcdest_rnode_prefixes(rn, &p, &src_p);
1532
1533 if (rn->p.family == AF_INET)
1534 family = AFI_IP;
1535 else if (rn->p.family == AF_INET6)
1536 family = AFI_IP6;
1537 else
1538 family = 0;
1539 switch (nexthop->type) {
1540 case NEXTHOP_TYPE_IFINDEX:
1541 ifp = if_lookup_by_index(nexthop->ifindex, nexthop->vrf_id);
1542 if (ifp && if_is_operative(ifp))
1543 SET_FLAG(nexthop->flags, NEXTHOP_FLAG_ACTIVE);
1544 else
1545 UNSET_FLAG(nexthop->flags, NEXTHOP_FLAG_ACTIVE);
1546 break;
1547 case NEXTHOP_TYPE_IPV4:
1548 case NEXTHOP_TYPE_IPV4_IFINDEX:
1549 family = AFI_IP;
1550 if (nexthop_active(AFI_IP, re, nexthop, rn))
1551 SET_FLAG(nexthop->flags, NEXTHOP_FLAG_ACTIVE);
1552 else
1553 UNSET_FLAG(nexthop->flags, NEXTHOP_FLAG_ACTIVE);
1554 break;
1555 case NEXTHOP_TYPE_IPV6:
1556 family = AFI_IP6;
1557 if (nexthop_active(AFI_IP6, re, nexthop, rn))
1558 SET_FLAG(nexthop->flags, NEXTHOP_FLAG_ACTIVE);
1559 else
1560 UNSET_FLAG(nexthop->flags, NEXTHOP_FLAG_ACTIVE);
1561 break;
1562 case NEXTHOP_TYPE_IPV6_IFINDEX:
1563 /* RFC 5549, v4 prefix with v6 NH */
1564 if (rn->p.family != AF_INET)
1565 family = AFI_IP6;
1566 if (IN6_IS_ADDR_LINKLOCAL(&nexthop->gate.ipv6)) {
1567 ifp = if_lookup_by_index(nexthop->ifindex,
1568 nexthop->vrf_id);
1569 if (ifp && if_is_operative(ifp))
1570 SET_FLAG(nexthop->flags, NEXTHOP_FLAG_ACTIVE);
1571 else
1572 UNSET_FLAG(nexthop->flags, NEXTHOP_FLAG_ACTIVE);
1573 } else {
1574 if (nexthop_active(AFI_IP6, re, nexthop, rn))
1575 SET_FLAG(nexthop->flags, NEXTHOP_FLAG_ACTIVE);
1576 else
1577 UNSET_FLAG(nexthop->flags, NEXTHOP_FLAG_ACTIVE);
1578 }
1579 break;
1580 case NEXTHOP_TYPE_BLACKHOLE:
1581 SET_FLAG(nexthop->flags, NEXTHOP_FLAG_ACTIVE);
1582 break;
1583 default:
1584 break;
1585 }
1586 if (!CHECK_FLAG(nexthop->flags, NEXTHOP_FLAG_ACTIVE)) {
1587 if (IS_ZEBRA_DEBUG_RIB_DETAILED)
1588 zlog_debug("\t%s: Unable to find a active nexthop",
1589 __PRETTY_FUNCTION__);
1590 return 0;
1591 }
1592
1593 /* XXX: What exactly do those checks do? Do we support
1594 * e.g. IPv4 routes with IPv6 nexthops or vice versa?
1595 */
1596 if (RIB_SYSTEM_ROUTE(re) || (family == AFI_IP && p->family != AF_INET)
1597 || (family == AFI_IP6 && p->family != AF_INET6))
1598 return CHECK_FLAG(nexthop->flags, NEXTHOP_FLAG_ACTIVE);
1599
1600 /* The original code didn't determine the family correctly
1601 * e.g. for NEXTHOP_TYPE_IFINDEX. Retrieve the correct afi
1602 * from the rib_table_info in those cases.
1603 * Possibly it may be better to use only the rib_table_info
1604 * in every case.
1605 */
1606 if (!family) {
1607 rib_table_info_t *info;
1608
1609 info = srcdest_rnode_table_info(rn);
1610 family = info->afi;
1611 }
1612
1613 memset(&nexthop->rmap_src.ipv6, 0, sizeof(union g_addr));
1614
1615 zvrf = zebra_vrf_lookup_by_id(nexthop->vrf_id);
1616 if (!zvrf) {
1617 if (IS_ZEBRA_DEBUG_RIB_DETAILED)
1618 zlog_debug("\t%s: zvrf is NULL", __PRETTY_FUNCTION__);
1619 return CHECK_FLAG(nexthop->flags, NEXTHOP_FLAG_ACTIVE);
1620 }
1621
1622 /* It'll get set if required inside */
1623 ret = zebra_route_map_check(family, re->type, re->instance, p, nexthop,
1624 zvrf, re->tag);
1625 if (ret == RMAP_DENYMATCH) {
1626 if (IS_ZEBRA_DEBUG_RIB) {
1627 srcdest_rnode2str(rn, buf, sizeof(buf));
1628 zlog_debug(
1629 "%u:%s: Filtering out with NH out %s due to route map",
1630 re->vrf_id, buf,
1631 ifindex2ifname(nexthop->ifindex,
1632 nexthop->vrf_id));
1633 }
1634 UNSET_FLAG(nexthop->flags, NEXTHOP_FLAG_ACTIVE);
1635 }
1636 return CHECK_FLAG(nexthop->flags, NEXTHOP_FLAG_ACTIVE);
1637 }
1638
1639 /*
1640 * Iterate over all nexthops of the given RIB entry and refresh their
1641 * ACTIVE flag. If any nexthop is found to toggle the ACTIVE flag,
1642 * the whole re structure is flagged with ROUTE_ENTRY_CHANGED.
1643 *
1644 * Return value is the new number of active nexthops.
1645 */
1646 int nexthop_active_update(struct route_node *rn, struct route_entry *re)
1647 {
1648 struct nexthop_group new_grp = {};
1649 struct nexthop *nexthop;
1650 union g_addr prev_src;
1651 unsigned int prev_active, new_active;
1652 ifindex_t prev_index;
1653 uint8_t curr_active = 0;
1654
1655 afi_t rt_afi = family2afi(rn->p.family);
1656
1657 UNSET_FLAG(re->status, ROUTE_ENTRY_CHANGED);
1658
1659 /* Copy over the nexthops in current state */
1660 nexthop_group_copy(&new_grp, re->ng);
1661
1662 for (nexthop = new_grp.nexthop; nexthop; nexthop = nexthop->next) {
1663
1664 /* No protocol daemon provides src and so we're skipping
1665 * tracking it */
1666 prev_src = nexthop->rmap_src;
1667 prev_active = CHECK_FLAG(nexthop->flags, NEXTHOP_FLAG_ACTIVE);
1668 prev_index = nexthop->ifindex;
1669 /*
1670 * We need to respect the multipath_num here
1671 * as that what we should be able to install from
1672 * a multipath perpsective should not be a data plane
1673 * decision point.
1674 */
1675 new_active =
1676 nexthop_active_check(rn, re, nexthop);
1677
1678 if (new_active
1679 && nexthop_group_active_nexthop_num(&new_grp)
1680 >= zrouter.multipath_num) {
1681 UNSET_FLAG(nexthop->flags, NEXTHOP_FLAG_ACTIVE);
1682 new_active = 0;
1683 }
1684
1685 if (new_active)
1686 curr_active++;
1687
1688 /* Don't allow src setting on IPv6 addr for now */
1689 if (prev_active != new_active || prev_index != nexthop->ifindex
1690 || ((nexthop->type >= NEXTHOP_TYPE_IFINDEX
1691 && nexthop->type < NEXTHOP_TYPE_IPV6)
1692 && prev_src.ipv4.s_addr
1693 != nexthop->rmap_src.ipv4.s_addr)
1694 || ((nexthop->type >= NEXTHOP_TYPE_IPV6
1695 && nexthop->type < NEXTHOP_TYPE_BLACKHOLE)
1696 && !(IPV6_ADDR_SAME(&prev_src.ipv6,
1697 &nexthop->rmap_src.ipv6)))
1698 || CHECK_FLAG(re->status, ROUTE_ENTRY_LABELS_CHANGED))
1699 SET_FLAG(re->status, ROUTE_ENTRY_CHANGED);
1700 }
1701
1702 if (CHECK_FLAG(re->status, ROUTE_ENTRY_CHANGED)) {
1703 struct nhg_hash_entry *new_nhe = NULL;
1704
1705 new_nhe = zebra_nhg_rib_find(0, &new_grp, rt_afi);
1706
1707 zebra_nhg_re_update_ref(re, new_nhe);
1708 }
1709
1710 if (curr_active) {
1711 struct nhg_hash_entry *nhe = NULL;
1712
1713 nhe = zebra_nhg_lookup_id(re->nhe_id);
1714
1715 if (nhe)
1716 SET_FLAG(nhe->flags, NEXTHOP_GROUP_VALID);
1717 else
1718 flog_err(
1719 EC_ZEBRA_TABLE_LOOKUP_FAILED,
1720 "Active update on NHE id=%u that we do not have in our tables",
1721 re->nhe_id);
1722 }
1723
1724 /*
1725 * Do not need these nexthops anymore since they
1726 * were either copied over into an nhe or not
1727 * used at all.
1728 */
1729 nexthops_free(new_grp.nexthop);
1730 return curr_active;
1731 }
1732
1733 static void zebra_nhg_re_attach_ref(struct route_entry *re,
1734 struct nhg_hash_entry *new)
1735 {
1736 re->ng = new->nhg;
1737 re->nhe_id = new->id;
1738
1739 zebra_nhg_increment_ref(new);
1740 }
1741
1742 int zebra_nhg_re_update_ref(struct route_entry *re, struct nhg_hash_entry *new)
1743 {
1744 struct nhg_hash_entry *old = NULL;
1745 int ret = 0;
1746
1747 if (new == NULL) {
1748 re->ng = NULL;
1749 goto done;
1750 }
1751
1752 if (re->nhe_id != new->id) {
1753 old = zebra_nhg_lookup_id(re->nhe_id);
1754
1755 zebra_nhg_re_attach_ref(re, new);
1756
1757 if (old)
1758 zebra_nhg_decrement_ref(old);
1759 } else if (!re->ng)
1760 /* This is the first time it's being attached */
1761 zebra_nhg_re_attach_ref(re, new);
1762
1763 done:
1764 return ret;
1765 }
1766
1767 /* Convert a nhe into a group array */
1768 uint8_t zebra_nhg_nhe2grp(struct nh_grp *grp, struct nhg_hash_entry *nhe,
1769 int max_num)
1770 {
1771 struct nhg_connected *rb_node_dep = NULL;
1772 struct nhg_hash_entry *depend = NULL;
1773 uint8_t i = 0;
1774
1775 frr_each(nhg_connected_tree, &nhe->nhg_depends, rb_node_dep) {
1776 bool duplicate = false;
1777
1778 depend = rb_node_dep->nhe;
1779
1780 /*
1781 * If its recursive, use its resolved nhe in the group
1782 */
1783 if (CHECK_FLAG(depend->flags, NEXTHOP_GROUP_RECURSIVE)) {
1784 depend = zebra_nhg_resolve(depend);
1785 if (!depend) {
1786 flog_err(
1787 EC_ZEBRA_NHG_FIB_UPDATE,
1788 "Failed to recursively resolve Nexthop Hash Entry in the group id=%u",
1789 nhe->id);
1790 continue;
1791 }
1792 }
1793
1794 /* Check for duplicate IDs, kernel doesn't like that */
1795 for (int j = 0; j < i; j++) {
1796 if (depend->id == grp[j].id)
1797 duplicate = true;
1798 }
1799
1800 if (!duplicate) {
1801 grp[i].id = depend->id;
1802 /* We aren't using weights for anything right now */
1803 grp[i].weight = 0;
1804 i++;
1805 }
1806
1807 if (i >= max_num)
1808 goto done;
1809 }
1810
1811 done:
1812 return i;
1813 }
1814
1815 void zebra_nhg_install_kernel(struct nhg_hash_entry *nhe)
1816 {
1817 struct nhg_connected *rb_node_dep = NULL;
1818
1819 /* Resolve it first */
1820 nhe = zebra_nhg_resolve(nhe);
1821
1822 /* Make sure all depends are installed/queued */
1823 frr_each(nhg_connected_tree, &nhe->nhg_depends, rb_node_dep) {
1824 zebra_nhg_install_kernel(rb_node_dep->nhe);
1825 }
1826
1827 if (!CHECK_FLAG(nhe->flags, NEXTHOP_GROUP_INSTALLED)
1828 && !CHECK_FLAG(nhe->flags, NEXTHOP_GROUP_QUEUED)) {
1829 /* Change its type to us since we are installing it */
1830 nhe->type = ZEBRA_ROUTE_NHG;
1831
1832 int ret = dplane_nexthop_add(nhe);
1833
1834 switch (ret) {
1835 case ZEBRA_DPLANE_REQUEST_QUEUED:
1836 SET_FLAG(nhe->flags, NEXTHOP_GROUP_QUEUED);
1837 break;
1838 case ZEBRA_DPLANE_REQUEST_FAILURE:
1839 flog_err(
1840 EC_ZEBRA_DP_INSTALL_FAIL,
1841 "Failed to install Nexthop ID (%u) into the kernel",
1842 nhe->id);
1843 break;
1844 case ZEBRA_DPLANE_REQUEST_SUCCESS:
1845 SET_FLAG(nhe->flags, NEXTHOP_GROUP_INSTALLED);
1846 zebra_nhg_handle_install(nhe);
1847 break;
1848 }
1849 }
1850 }
1851
1852 void zebra_nhg_uninstall_kernel(struct nhg_hash_entry *nhe)
1853 {
1854 if (CHECK_FLAG(nhe->flags, NEXTHOP_GROUP_INSTALLED)) {
1855 int ret = dplane_nexthop_delete(nhe);
1856
1857 switch (ret) {
1858 case ZEBRA_DPLANE_REQUEST_QUEUED:
1859 SET_FLAG(nhe->flags, NEXTHOP_GROUP_QUEUED);
1860 break;
1861 case ZEBRA_DPLANE_REQUEST_FAILURE:
1862 flog_err(
1863 EC_ZEBRA_DP_DELETE_FAIL,
1864 "Failed to uninstall Nexthop ID (%u) from the kernel",
1865 nhe->id);
1866 break;
1867 case ZEBRA_DPLANE_REQUEST_SUCCESS:
1868 UNSET_FLAG(nhe->flags, NEXTHOP_GROUP_INSTALLED);
1869 break;
1870 }
1871 }
1872
1873 zebra_nhg_handle_uninstall(nhe);
1874 }
1875
1876 void zebra_nhg_dplane_result(struct zebra_dplane_ctx *ctx)
1877 {
1878 enum dplane_op_e op;
1879 enum zebra_dplane_result status;
1880 uint32_t id = 0;
1881 struct nhg_hash_entry *nhe = NULL;
1882
1883 op = dplane_ctx_get_op(ctx);
1884 status = dplane_ctx_get_status(ctx);
1885
1886 id = dplane_ctx_get_nhe_id(ctx);
1887
1888 if (IS_ZEBRA_DEBUG_DPLANE_DETAIL)
1889 zlog_debug(
1890 "Nexthop dplane ctx %p, op %s, nexthop ID (%u), result %s",
1891 ctx, dplane_op2str(op), id, dplane_res2str(status));
1892
1893 switch (op) {
1894 case DPLANE_OP_NH_DELETE:
1895 if (status != ZEBRA_DPLANE_REQUEST_SUCCESS)
1896 flog_err(
1897 EC_ZEBRA_DP_DELETE_FAIL,
1898 "Failed to uninstall Nexthop ID (%u) from the kernel",
1899 id);
1900 /* We already free'd the data, nothing to do */
1901 break;
1902 case DPLANE_OP_NH_INSTALL:
1903 case DPLANE_OP_NH_UPDATE:
1904 nhe = zebra_nhg_lookup_id(id);
1905
1906 if (!nhe) {
1907 flog_err(
1908 EC_ZEBRA_NHG_SYNC,
1909 "%s operation preformed on Nexthop ID (%u) in the kernel, that we no longer have in our table",
1910 dplane_op2str(op), id);
1911 break;
1912 }
1913
1914 UNSET_FLAG(nhe->flags, NEXTHOP_GROUP_QUEUED);
1915 if (status == ZEBRA_DPLANE_REQUEST_SUCCESS) {
1916 SET_FLAG(nhe->flags, NEXTHOP_GROUP_VALID);
1917 SET_FLAG(nhe->flags, NEXTHOP_GROUP_INSTALLED);
1918 zebra_nhg_handle_install(nhe);
1919 } else
1920 flog_err(
1921 EC_ZEBRA_DP_INSTALL_FAIL,
1922 "Failed to install Nexthop ID (%u) into the kernel",
1923 nhe->id);
1924 break;
1925 case DPLANE_OP_ROUTE_INSTALL:
1926 case DPLANE_OP_ROUTE_UPDATE:
1927 case DPLANE_OP_ROUTE_DELETE:
1928 case DPLANE_OP_ROUTE_NOTIFY:
1929 case DPLANE_OP_LSP_INSTALL:
1930 case DPLANE_OP_LSP_UPDATE:
1931 case DPLANE_OP_LSP_DELETE:
1932 case DPLANE_OP_LSP_NOTIFY:
1933 case DPLANE_OP_PW_INSTALL:
1934 case DPLANE_OP_PW_UNINSTALL:
1935 case DPLANE_OP_SYS_ROUTE_ADD:
1936 case DPLANE_OP_SYS_ROUTE_DELETE:
1937 case DPLANE_OP_ADDR_INSTALL:
1938 case DPLANE_OP_ADDR_UNINSTALL:
1939 case DPLANE_OP_MAC_INSTALL:
1940 case DPLANE_OP_MAC_DELETE:
1941 case DPLANE_OP_NEIGH_INSTALL:
1942 case DPLANE_OP_NEIGH_UPDATE:
1943 case DPLANE_OP_NEIGH_DELETE:
1944 case DPLANE_OP_VTEP_ADD:
1945 case DPLANE_OP_VTEP_DELETE:
1946 case DPLANE_OP_NONE:
1947 break;
1948 }
1949
1950 dplane_ctx_fini(&ctx);
1951 }
1952
1953 static void zebra_nhg_sweep_entry(struct hash_bucket *bucket, void *arg)
1954 {
1955 struct nhg_hash_entry *nhe = NULL;
1956
1957 nhe = (struct nhg_hash_entry *)bucket->data;
1958
1959 /* If its being ref'd, just let it be uninstalled via a route removal */
1960 if (ZEBRA_NHG_CREATED(nhe) && nhe->refcnt <= 0)
1961 zebra_nhg_uninstall_kernel(nhe);
1962 }
1963
1964 void zebra_nhg_sweep_table(struct hash *hash)
1965 {
1966 hash_iterate(hash, zebra_nhg_sweep_entry, NULL);
1967 }