1 /* Routing Information Base.
2 * Copyright (C) 1997, 98, 99, 2001 Kunihiro Ishiguro
4 * This file is part of GNU Zebra.
6 * GNU Zebra is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2, or (at your option) any
11 * GNU Zebra is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with this program; see the file COPYING; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
33 #include "sockunion.h"
34 #include "srcdest_table.h"
38 #include "workqueue.h"
39 #include "nexthop_group_private.h"
40 #include "frr_pthread.h"
42 #include "frrscript.h"
44 #include "zebra/zebra_router.h"
45 #include "zebra/connected.h"
46 #include "zebra/debug.h"
47 #include "zebra/interface.h"
48 #include "zebra/redistribute.h"
49 #include "zebra/rib.h"
51 #include "zebra/zapi_msg.h"
52 #include "zebra/zebra_errors.h"
53 #include "zebra/zebra_ns.h"
54 #include "zebra/zebra_rnh.h"
55 #include "zebra/zebra_routemap.h"
56 #include "zebra/zebra_vrf.h"
57 #include "zebra/zebra_vxlan.h"
58 #include "zebra/zapi_msg.h"
59 #include "zebra/zebra_dplane.h"
60 #include "zebra/zebra_evpn_mh.h"
61 #include "zebra/zebra_script.h"
63 DEFINE_MGROUP(ZEBRA
, "zebra");
65 DEFINE_MTYPE(ZEBRA
, RE
, "Route Entry");
66 DEFINE_MTYPE_STATIC(ZEBRA
, RIB_DEST
, "RIB destination");
67 DEFINE_MTYPE_STATIC(ZEBRA
, RIB_UPDATE_CTX
, "Rib update context object");
68 DEFINE_MTYPE_STATIC(ZEBRA
, WQ_WRAPPER
, "WQ wrapper");
71 * Event, list, and mutex for delivery of dataplane results
73 static pthread_mutex_t dplane_mutex
;
74 static struct thread
*t_dplane
;
75 static struct dplane_ctx_q rib_dplane_q
;
77 DEFINE_HOOK(rib_update
, (struct route_node
* rn
, const char *reason
),
80 /* Should we allow non FRR processes to delete our routes */
81 extern int allow_delete
;
83 /* Each route type's string and default distance value. */
88 } route_info
[ZEBRA_ROUTE_MAX
] = {
89 [ZEBRA_ROUTE_NHG
] = {ZEBRA_ROUTE_NHG
, 255 /* Unneeded for nhg's */, 0},
90 [ZEBRA_ROUTE_SYSTEM
] = {ZEBRA_ROUTE_SYSTEM
, 0, 7},
91 [ZEBRA_ROUTE_KERNEL
] = {ZEBRA_ROUTE_KERNEL
, 0, 3},
92 [ZEBRA_ROUTE_CONNECT
] = {ZEBRA_ROUTE_CONNECT
, 0, 2},
93 [ZEBRA_ROUTE_STATIC
] = {ZEBRA_ROUTE_STATIC
, 1, 4},
94 [ZEBRA_ROUTE_RIP
] = {ZEBRA_ROUTE_RIP
, 120, 5},
95 [ZEBRA_ROUTE_RIPNG
] = {ZEBRA_ROUTE_RIPNG
, 120, 5},
96 [ZEBRA_ROUTE_OSPF
] = {ZEBRA_ROUTE_OSPF
, 110, 5},
97 [ZEBRA_ROUTE_OSPF6
] = {ZEBRA_ROUTE_OSPF6
, 110, 5},
98 [ZEBRA_ROUTE_ISIS
] = {ZEBRA_ROUTE_ISIS
, 115, 5},
99 [ZEBRA_ROUTE_BGP
] = {ZEBRA_ROUTE_BGP
, 20 /* IBGP is 200. */, 6},
100 [ZEBRA_ROUTE_PIM
] = {ZEBRA_ROUTE_PIM
, 255, 7},
101 [ZEBRA_ROUTE_EIGRP
] = {ZEBRA_ROUTE_EIGRP
, 90, 5},
102 [ZEBRA_ROUTE_NHRP
] = {ZEBRA_ROUTE_NHRP
, 10, 5},
103 [ZEBRA_ROUTE_HSLS
] = {ZEBRA_ROUTE_HSLS
, 255, 7},
104 [ZEBRA_ROUTE_OLSR
] = {ZEBRA_ROUTE_OLSR
, 255, 7},
105 [ZEBRA_ROUTE_TABLE
] = {ZEBRA_ROUTE_TABLE
, 150, 4},
106 [ZEBRA_ROUTE_LDP
] = {ZEBRA_ROUTE_LDP
, 150, 7},
107 [ZEBRA_ROUTE_VNC
] = {ZEBRA_ROUTE_VNC
, 20, 6},
108 [ZEBRA_ROUTE_VNC_DIRECT
] = {ZEBRA_ROUTE_VNC_DIRECT
, 20, 6},
109 [ZEBRA_ROUTE_VNC_DIRECT_RH
] = {ZEBRA_ROUTE_VNC_DIRECT_RH
, 20, 6},
110 [ZEBRA_ROUTE_BGP_DIRECT
] = {ZEBRA_ROUTE_BGP_DIRECT
, 20, 6},
111 [ZEBRA_ROUTE_BGP_DIRECT_EXT
] = {ZEBRA_ROUTE_BGP_DIRECT_EXT
, 20, 6},
112 [ZEBRA_ROUTE_BABEL
] = {ZEBRA_ROUTE_BABEL
, 100, 5},
113 [ZEBRA_ROUTE_SHARP
] = {ZEBRA_ROUTE_SHARP
, 150, 7},
114 [ZEBRA_ROUTE_PBR
] = {ZEBRA_ROUTE_PBR
, 200, 7},
115 [ZEBRA_ROUTE_BFD
] = {ZEBRA_ROUTE_BFD
, 255, 7},
116 [ZEBRA_ROUTE_OPENFABRIC
] = {ZEBRA_ROUTE_OPENFABRIC
, 115, 5},
117 [ZEBRA_ROUTE_VRRP
] = {ZEBRA_ROUTE_VRRP
, 255, 7},
118 [ZEBRA_ROUTE_SRTE
] = {ZEBRA_ROUTE_SRTE
, 255, 7},
119 /* Any new route type added to zebra, should be mirrored here */
121 /* no entry/default: 150 */
124 /* EVPN/VXLAN subqueue is number 1 */
125 #define META_QUEUE_EVPN 1
127 /* Wrapper struct for nhg workqueue items; a 'ctx' is an incoming update
128 * from the OS, and an 'nhe' is a nhe update.
130 struct wq_nhg_wrapper
{
134 struct nhg_hash_entry
*nhe
;
138 #define WQ_NHG_WRAPPER_TYPE_CTX 0x01
139 #define WQ_NHG_WRAPPER_TYPE_NHG 0x02
141 /* Wrapper structs for evpn/vxlan workqueue items. */
142 struct wq_evpn_wrapper
{
154 struct ethaddr macaddr
;
155 struct prefix prefix
;
156 struct in_addr vtep_ip
;
159 #define WQ_EVPN_WRAPPER_TYPE_VRFROUTE 0x01
160 #define WQ_EVPN_WRAPPER_TYPE_REM_ES 0x02
161 #define WQ_EVPN_WRAPPER_TYPE_REM_MACIP 0x03
162 #define WQ_EVPN_WRAPPER_TYPE_REM_VTEP 0x04
164 /* %pRN is already a printer for route_nodes that just prints the prefix */
165 #ifdef _FRR_ATTRIBUTE_PRINTFRR
166 #pragma FRR printfrr_ext "%pZN" (struct route_node *)
169 printfrr_ext_autoreg_p("ZN", printfrr_zebra_node
);
170 static ssize_t
printfrr_zebra_node(struct fbuf
*buf
, struct printfrr_eargs
*ea
,
173 struct route_node
*rn
= (struct route_node
*)ptr
;
176 /* just the table number? */
177 if (ea
->fmt
[0] == 't') {
179 struct route_entry
*re
= NULL
;
184 return bputch(buf
, '!');
186 dest
= rib_dest_from_rnode(rn
);
188 re
= re_list_first(&dest
->routes
);
190 rv
+= bprintfrr(buf
, "%u", re
->table
);
192 rv
+= bputch(buf
, '?');
195 char cbuf
[PREFIX_STRLEN
* 2 + 6];
196 struct rib_table_info
*info
;
199 return bputs(buf
, "{(route_node *) NULL}");
201 srcdest_rnode2str(rn
, cbuf
, sizeof(cbuf
));
202 rv
+= bputs(buf
, cbuf
);
204 info
= srcdest_rnode_table_info(rn
);
205 if (info
->safi
== SAFI_MULTICAST
)
206 rv
+= bputs(buf
, " (MRIB)");
211 #define rnode_debug(node, vrf_id, msg, ...) \
212 zlog_debug("%s: (%u:%pZNt):%pZN: " msg, __func__, vrf_id, node, node, \
215 #define rnode_info(node, vrf_id, msg, ...) \
216 zlog_info("%s: (%u:%pZNt):%pZN: " msg, __func__, vrf_id, node, node, \
219 static char *_dump_re_status(const struct route_entry
*re
, char *buf
,
222 if (re
->status
== 0) {
223 snprintfrr(buf
, len
, "None ");
228 buf
, len
, "%s%s%s%s%s%s%s",
229 CHECK_FLAG(re
->status
, ROUTE_ENTRY_REMOVED
) ? "Removed " : "",
230 CHECK_FLAG(re
->status
, ROUTE_ENTRY_CHANGED
) ? "Changed " : "",
231 CHECK_FLAG(re
->status
, ROUTE_ENTRY_LABELS_CHANGED
)
234 CHECK_FLAG(re
->status
, ROUTE_ENTRY_QUEUED
) ? "Queued " : "",
235 CHECK_FLAG(re
->status
, ROUTE_ENTRY_INSTALLED
) ? "Installed "
237 CHECK_FLAG(re
->status
, ROUTE_ENTRY_FAILED
) ? "Failed " : "",
238 CHECK_FLAG(re
->status
, ROUTE_ENTRY_USE_FIB_NHG
) ? "Fib NHG "
243 uint8_t route_distance(int type
)
247 if ((unsigned)type
>= array_size(route_info
))
250 distance
= route_info
[type
].distance
;
255 int is_zebra_valid_kernel_table(uint32_t table_id
)
258 if ((table_id
== RT_TABLE_UNSPEC
) || (table_id
== RT_TABLE_LOCAL
)
259 || (table_id
== RT_TABLE_COMPAT
))
266 int is_zebra_main_routing_table(uint32_t table_id
)
268 if (table_id
== RT_TABLE_MAIN
)
273 int zebra_check_addr(const struct prefix
*p
)
275 if (p
->family
== AF_INET
) {
278 addr
= p
->u
.prefix4
.s_addr
;
281 if (IPV4_NET127(addr
) || IN_CLASSD(addr
)
282 || IPV4_LINKLOCAL(addr
))
285 if (p
->family
== AF_INET6
) {
286 if (IN6_IS_ADDR_LOOPBACK(&p
->u
.prefix6
))
288 if (IN6_IS_ADDR_LINKLOCAL(&p
->u
.prefix6
))
295 * copy_nexthop - copy a nexthop to the rib structure.
297 void route_entry_copy_nexthops(struct route_entry
*re
, struct nexthop
*nh
)
299 assert(!re
->nhe
->nhg
.nexthop
);
300 copy_nexthops(&re
->nhe
->nhg
.nexthop
, nh
, NULL
);
303 static void route_entry_attach_ref(struct route_entry
*re
,
304 struct nhg_hash_entry
*new)
307 re
->nhe_id
= new->id
;
308 re
->nhe_installed_id
= 0;
310 zebra_nhg_increment_ref(new);
313 /* Replace (if 'new_nhghe') or clear (if that's NULL) an re's nhe. */
314 int route_entry_update_nhe(struct route_entry
*re
,
315 struct nhg_hash_entry
*new_nhghe
)
318 struct nhg_hash_entry
*old_nhg
= NULL
;
320 if (new_nhghe
== NULL
) {
324 re
->nhe_installed_id
= 0;
329 if ((re
->nhe_id
!= 0) && re
->nhe
&& (re
->nhe
!= new_nhghe
)) {
330 /* Capture previous nhg, if any */
333 route_entry_attach_ref(re
, new_nhghe
);
335 /* This is the first time it's being attached */
336 route_entry_attach_ref(re
, new_nhghe
);
339 /* Detach / deref previous nhg */
341 zebra_nhg_decrement_ref(old_nhg
);
346 void rib_handle_nhg_replace(struct nhg_hash_entry
*old_entry
,
347 struct nhg_hash_entry
*new_entry
)
349 struct zebra_router_table
*zrt
;
350 struct route_node
*rn
;
351 struct route_entry
*re
, *next
;
353 if (IS_ZEBRA_DEBUG_RIB_DETAILED
|| IS_ZEBRA_DEBUG_NHG_DETAIL
)
354 zlog_debug("%s: replacing routes nhe (%u) OLD %p NEW %p",
355 __func__
, new_entry
->id
, new_entry
, old_entry
);
357 /* We have to do them ALL */
358 RB_FOREACH (zrt
, zebra_router_table_head
, &zrouter
.tables
) {
359 for (rn
= route_top(zrt
->table
); rn
;
360 rn
= srcdest_route_next(rn
)) {
361 RNODE_FOREACH_RE_SAFE (rn
, re
, next
) {
362 if (re
->nhe
&& re
->nhe
== old_entry
)
363 route_entry_update_nhe(re
, new_entry
);
369 struct route_entry
*rib_match(afi_t afi
, safi_t safi
, vrf_id_t vrf_id
,
370 const union g_addr
*addr
,
371 struct route_node
**rn_out
)
374 struct route_table
*table
;
375 struct route_node
*rn
;
376 struct route_entry
*match
= NULL
;
379 table
= zebra_vrf_table(afi
, safi
, vrf_id
);
383 memset(&p
, 0, sizeof(struct prefix
));
386 p
.u
.prefix4
= addr
->ipv4
;
387 p
.prefixlen
= IPV4_MAX_BITLEN
;
389 p
.u
.prefix6
= addr
->ipv6
;
390 p
.prefixlen
= IPV6_MAX_BITLEN
;
393 rn
= route_node_match(table
, &p
);
398 route_unlock_node(rn
);
400 dest
= rib_dest_from_rnode(rn
);
401 if (dest
&& dest
->selected_fib
402 && !CHECK_FLAG(dest
->selected_fib
->status
,
403 ROUTE_ENTRY_REMOVED
))
404 match
= dest
->selected_fib
;
406 /* If there is no selected route or matched route is EGP, go up
411 } while (rn
&& rn
->info
== NULL
);
415 if (match
->type
!= ZEBRA_ROUTE_CONNECT
) {
416 if (!CHECK_FLAG(match
->status
,
417 ROUTE_ENTRY_INSTALLED
))
429 struct route_entry
*rib_match_ipv4_multicast(vrf_id_t vrf_id
,
431 struct route_node
**rn_out
)
433 struct route_entry
*re
= NULL
, *mre
= NULL
, *ure
= NULL
;
434 struct route_node
*m_rn
= NULL
, *u_rn
= NULL
;
435 union g_addr gaddr
= {.ipv4
= addr
};
437 switch (zrouter
.ipv4_multicast_mode
) {
438 case MCAST_MRIB_ONLY
:
439 return rib_match(AFI_IP
, SAFI_MULTICAST
, vrf_id
, &gaddr
,
441 case MCAST_URIB_ONLY
:
442 return rib_match(AFI_IP
, SAFI_UNICAST
, vrf_id
, &gaddr
, rn_out
);
443 case MCAST_NO_CONFIG
:
444 case MCAST_MIX_MRIB_FIRST
:
445 re
= mre
= rib_match(AFI_IP
, SAFI_MULTICAST
, vrf_id
, &gaddr
,
448 re
= ure
= rib_match(AFI_IP
, SAFI_UNICAST
, vrf_id
,
451 case MCAST_MIX_DISTANCE
:
452 mre
= rib_match(AFI_IP
, SAFI_MULTICAST
, vrf_id
, &gaddr
, &m_rn
);
453 ure
= rib_match(AFI_IP
, SAFI_UNICAST
, vrf_id
, &gaddr
, &u_rn
);
455 re
= ure
->distance
< mre
->distance
? ure
: mre
;
461 case MCAST_MIX_PFXLEN
:
462 mre
= rib_match(AFI_IP
, SAFI_MULTICAST
, vrf_id
, &gaddr
, &m_rn
);
463 ure
= rib_match(AFI_IP
, SAFI_UNICAST
, vrf_id
, &gaddr
, &u_rn
);
465 re
= u_rn
->p
.prefixlen
> m_rn
->p
.prefixlen
? ure
: mre
;
474 *rn_out
= (re
== mre
) ? m_rn
: u_rn
;
476 if (IS_ZEBRA_DEBUG_RIB
) {
478 inet_ntop(AF_INET
, &addr
, buf
, BUFSIZ
);
480 zlog_debug("%s: %s: vrf: %s(%u) found %s, using %s", __func__
,
481 buf
, vrf_id_to_name(vrf_id
), vrf_id
,
482 mre
? (ure
? "MRIB+URIB" : "MRIB")
483 : ure
? "URIB" : "nothing",
484 re
== ure
? "URIB" : re
== mre
? "MRIB" : "none");
489 struct route_entry
*rib_lookup_ipv4(struct prefix_ipv4
*p
, vrf_id_t vrf_id
)
491 struct route_table
*table
;
492 struct route_node
*rn
;
493 struct route_entry
*match
= NULL
;
497 table
= zebra_vrf_table(AFI_IP
, SAFI_UNICAST
, vrf_id
);
501 rn
= route_node_lookup(table
, (struct prefix
*)p
);
503 /* No route for this prefix. */
508 route_unlock_node(rn
);
509 dest
= rib_dest_from_rnode(rn
);
511 if (dest
&& dest
->selected_fib
512 && !CHECK_FLAG(dest
->selected_fib
->status
, ROUTE_ENTRY_REMOVED
))
513 match
= dest
->selected_fib
;
518 if (match
->type
== ZEBRA_ROUTE_CONNECT
)
521 if (CHECK_FLAG(match
->status
, ROUTE_ENTRY_INSTALLED
))
528 * Is this RIB labeled-unicast? It must be of type BGP and all paths
529 * (nexthops) must have a label.
531 int zebra_rib_labeled_unicast(struct route_entry
*re
)
533 struct nexthop
*nexthop
= NULL
;
535 if (re
->type
!= ZEBRA_ROUTE_BGP
)
538 for (ALL_NEXTHOPS(re
->nhe
->nhg
, nexthop
))
539 if (!nexthop
->nh_label
|| !nexthop
->nh_label
->num_labels
)
545 /* Update flag indicates whether this is a "replace" or not. Currently, this
546 * is only used for IPv4.
548 void rib_install_kernel(struct route_node
*rn
, struct route_entry
*re
,
549 struct route_entry
*old
)
551 struct nexthop
*nexthop
;
552 struct rib_table_info
*info
= srcdest_rnode_table_info(rn
);
553 struct zebra_vrf
*zvrf
= vrf_info_lookup(re
->vrf_id
);
554 const struct prefix
*p
, *src_p
;
555 enum zebra_dplane_result ret
;
557 rib_dest_t
*dest
= rib_dest_from_rnode(rn
);
559 srcdest_rnode_prefixes(rn
, &p
, &src_p
);
561 if (info
->safi
!= SAFI_UNICAST
) {
562 for (ALL_NEXTHOPS(re
->nhe
->nhg
, nexthop
))
563 SET_FLAG(nexthop
->flags
, NEXTHOP_FLAG_FIB
);
569 * Install the resolved nexthop object first.
571 zebra_nhg_install_kernel(re
->nhe
);
574 * If this is a replace to a new RE let the originator of the RE
575 * know that they've lost
577 if (old
&& (old
!= re
) && (old
->type
!= re
->type
))
578 zsend_route_notify_owner(rn
, old
, ZAPI_ROUTE_BETTER_ADMIN_WON
,
579 info
->afi
, info
->safi
);
581 /* Update fib selection */
582 dest
->selected_fib
= re
;
585 * Make sure we update the FPM any time we send new information to
588 hook_call(rib_update
, rn
, "installing in kernel");
590 /* Send add or update */
592 ret
= dplane_route_update(rn
, re
, old
);
594 ret
= dplane_route_add(rn
, re
);
597 case ZEBRA_DPLANE_REQUEST_QUEUED
:
598 SET_FLAG(re
->status
, ROUTE_ENTRY_QUEUED
);
601 SET_FLAG(old
->status
, ROUTE_ENTRY_QUEUED
);
603 /* Free old FIB nexthop group */
604 UNSET_FLAG(old
->status
, ROUTE_ENTRY_USE_FIB_NHG
);
605 if (old
->fib_ng
.nexthop
) {
606 nexthops_free(old
->fib_ng
.nexthop
);
607 old
->fib_ng
.nexthop
= NULL
;
612 zvrf
->installs_queued
++;
614 case ZEBRA_DPLANE_REQUEST_FAILURE
:
616 flog_err(EC_ZEBRA_DP_INSTALL_FAIL
,
617 "%u:%u:%pRN: Failed to enqueue dataplane install",
618 re
->vrf_id
, re
->table
, rn
);
621 case ZEBRA_DPLANE_REQUEST_SUCCESS
:
630 /* Uninstall the route from kernel. */
631 void rib_uninstall_kernel(struct route_node
*rn
, struct route_entry
*re
)
633 struct nexthop
*nexthop
;
634 struct rib_table_info
*info
= srcdest_rnode_table_info(rn
);
635 struct zebra_vrf
*zvrf
= vrf_info_lookup(re
->vrf_id
);
637 if (info
->safi
!= SAFI_UNICAST
) {
638 UNSET_FLAG(re
->status
, ROUTE_ENTRY_INSTALLED
);
639 for (ALL_NEXTHOPS(re
->nhe
->nhg
, nexthop
))
640 UNSET_FLAG(nexthop
->flags
, NEXTHOP_FLAG_FIB
);
645 * Make sure we update the FPM any time we send new information to
648 hook_call(rib_update
, rn
, "uninstalling from kernel");
650 switch (dplane_route_delete(rn
, re
)) {
651 case ZEBRA_DPLANE_REQUEST_QUEUED
:
653 zvrf
->removals_queued
++;
655 case ZEBRA_DPLANE_REQUEST_FAILURE
:
656 flog_err(EC_ZEBRA_DP_INSTALL_FAIL
,
657 "%u:%pRN: Failed to enqueue dataplane uninstall",
660 case ZEBRA_DPLANE_REQUEST_SUCCESS
:
670 * rib_can_delete_dest
672 * Returns true if the given dest can be deleted from the table.
674 static int rib_can_delete_dest(rib_dest_t
*dest
)
676 if (re_list_first(&dest
->routes
)) {
681 * Unresolved rnh's are stored on the default route's list
683 * dest->rnode can also be the source prefix node in an
684 * ipv6 sourcedest table. Fortunately the prefix of a
685 * source prefix node can never be the default prefix.
687 if (is_default_prefix(&dest
->rnode
->p
))
691 * Don't delete the dest if we have to update the FPM about this
694 if (CHECK_FLAG(dest
->flags
, RIB_DEST_UPDATE_FPM
)
695 || CHECK_FLAG(dest
->flags
, RIB_DEST_SENT_TO_FPM
))
701 void zebra_rib_evaluate_rn_nexthops(struct route_node
*rn
, uint32_t seq
,
704 rib_dest_t
*dest
= rib_dest_from_rnode(rn
);
708 * We are storing the rnh's associated withb
709 * the tracked nexthop as a list of the rn's.
710 * Unresolved rnh's are placed at the top
711 * of the tree list.( 0.0.0.0/0 for v4 and 0::0/0 for v6 )
712 * As such for each rn we need to walk up the tree
713 * and see if any rnh's need to see if they
714 * would match a more specific route
717 if (IS_ZEBRA_DEBUG_NHT_DETAILED
)
719 "%s: %pRN Being examined for Nexthop Tracking Count: %zd",
721 dest
? rnh_list_count(&dest
->nht
) : 0);
723 if (rt_delete
&& (!dest
|| !rnh_list_count(&dest
->nht
))) {
724 if (IS_ZEBRA_DEBUG_NHT_DETAILED
)
725 zlog_debug("%pRN has no tracking NHTs. Bailing",
732 dest
= rib_dest_from_rnode(rn
);
736 * If we have any rnh's stored in the nht list
737 * then we know that this route node was used for
738 * nht resolution and as such we need to call the
739 * nexthop tracking evaluation code
741 frr_each_safe(rnh_list
, &dest
->nht
, rnh
) {
742 struct zebra_vrf
*zvrf
=
743 zebra_vrf_lookup_by_id(rnh
->vrf_id
);
744 struct prefix
*p
= &rnh
->node
->p
;
746 if (IS_ZEBRA_DEBUG_NHT_DETAILED
)
748 "%s(%u):%pRN has Nexthop(%pRN) depending on it, evaluating %u:%u",
749 zvrf_name(zvrf
), zvrf_id(zvrf
), rn
,
750 rnh
->node
, seq
, rnh
->seqno
);
753 * If we have evaluated this node on this pass
754 * already, due to following the tree up
755 * then we know that we can move onto the next
758 * Additionally we call zebra_evaluate_rnh
759 * when we gc the dest. In this case we know
760 * that there must be no other re's where
761 * we were originally as such we know that
762 * that sequence number is ok to respect.
764 if (rnh
->seqno
== seq
) {
765 if (IS_ZEBRA_DEBUG_NHT_DETAILED
)
767 " Node processed and moved already");
772 zebra_evaluate_rnh(zvrf
, family2afi(p
->family
), 0, p
,
778 dest
= rib_dest_from_rnode(rn
);
785 * Garbage collect the rib dest corresponding to the given route node
788 * Returns true if the dest was deleted, false otherwise.
790 int rib_gc_dest(struct route_node
*rn
)
794 dest
= rib_dest_from_rnode(rn
);
798 if (!rib_can_delete_dest(dest
))
801 if (IS_ZEBRA_DEBUG_RIB
) {
802 struct zebra_vrf
*zvrf
;
804 zvrf
= rib_dest_vrf(dest
);
805 rnode_debug(rn
, zvrf_id(zvrf
), "removing dest from table");
808 zebra_rib_evaluate_rn_nexthops(rn
, zebra_router_get_next_sequence(),
812 rnh_list_fini(&dest
->nht
);
813 XFREE(MTYPE_RIB_DEST
, dest
);
817 * Release the one reference that we keep on the route node.
819 route_unlock_node(rn
);
823 void zebra_rtable_node_cleanup(struct route_table
*table
,
824 struct route_node
*node
)
826 struct route_entry
*re
, *next
;
828 RNODE_FOREACH_RE_SAFE (node
, re
, next
) {
829 rib_unlink(node
, re
);
833 rib_dest_t
*dest
= node
->info
;
835 rnh_list_fini(&dest
->nht
);
836 XFREE(MTYPE_RIB_DEST
, node
->info
);
840 static void rib_process_add_fib(struct zebra_vrf
*zvrf
, struct route_node
*rn
,
841 struct route_entry
*new)
843 hook_call(rib_update
, rn
, "new route selected");
845 /* Update real nexthop. This may actually determine if nexthop is active
847 if (!nexthop_group_active_nexthop_num(&(new->nhe
->nhg
))) {
848 UNSET_FLAG(new->status
, ROUTE_ENTRY_CHANGED
);
852 if (IS_ZEBRA_DEBUG_RIB
)
853 zlog_debug("%s(%u:%u):%pRN: Adding route rn %p, re %p (%s)",
854 zvrf_name(zvrf
), zvrf_id(zvrf
), new->table
, rn
, rn
,
855 new, zebra_route_string(new->type
));
857 /* If labeled-unicast route, install transit LSP. */
858 if (zebra_rib_labeled_unicast(new))
859 zebra_mpls_lsp_install(zvrf
, rn
, new);
861 rib_install_kernel(rn
, new, NULL
);
863 UNSET_FLAG(new->status
, ROUTE_ENTRY_CHANGED
);
866 static void rib_process_del_fib(struct zebra_vrf
*zvrf
, struct route_node
*rn
,
867 struct route_entry
*old
)
869 hook_call(rib_update
, rn
, "removing existing route");
871 /* Uninstall from kernel. */
872 if (IS_ZEBRA_DEBUG_RIB
)
873 zlog_debug("%s(%u:%u):%pRN: Deleting route rn %p, re %p (%s)",
874 zvrf_name(zvrf
), zvrf_id(zvrf
), old
->table
, rn
, rn
,
875 old
, zebra_route_string(old
->type
));
877 /* If labeled-unicast route, uninstall transit LSP. */
878 if (zebra_rib_labeled_unicast(old
))
879 zebra_mpls_lsp_uninstall(zvrf
, rn
, old
);
881 rib_uninstall_kernel(rn
, old
);
883 /* Update nexthop for route, reset changed flag. */
884 /* Note: this code also handles the Linux case when an interface goes
885 * down, causing the kernel to delete routes without sending DELROUTE
888 if (RIB_KERNEL_ROUTE(old
))
889 SET_FLAG(old
->status
, ROUTE_ENTRY_REMOVED
);
891 UNSET_FLAG(old
->status
, ROUTE_ENTRY_CHANGED
);
894 static void rib_process_update_fib(struct zebra_vrf
*zvrf
,
895 struct route_node
*rn
,
896 struct route_entry
*old
,
897 struct route_entry
*new)
902 * We have to install or update if a new route has been selected or
903 * something has changed.
905 if (new != old
|| CHECK_FLAG(new->status
, ROUTE_ENTRY_CHANGED
)) {
906 hook_call(rib_update
, rn
, "updating existing route");
908 /* Update the nexthop; we could determine here that nexthop is
910 if (nexthop_group_active_nexthop_num(&(new->nhe
->nhg
)))
913 /* If nexthop is active, install the selected route, if
915 * the install succeeds, cleanup flags for prior route, if
920 if (IS_ZEBRA_DEBUG_RIB
) {
923 "%s(%u:%u):%pRN: Updating route rn %p, re %p (%s) old %p (%s)",
924 zvrf_name(zvrf
), zvrf_id(zvrf
),
925 new->table
, rn
, rn
, new,
926 zebra_route_string(new->type
),
928 zebra_route_string(old
->type
));
931 "%s(%u:%u):%pRN: Updating route rn %p, re %p (%s)",
932 zvrf_name(zvrf
), zvrf_id(zvrf
),
933 new->table
, rn
, rn
, new,
934 zebra_route_string(new->type
));
937 /* If labeled-unicast route, uninstall transit LSP. */
938 if (zebra_rib_labeled_unicast(old
))
939 zebra_mpls_lsp_uninstall(zvrf
, rn
, old
);
942 * Non-system route should be installed.
943 * If labeled-unicast route, install transit
946 if (zebra_rib_labeled_unicast(new))
947 zebra_mpls_lsp_install(zvrf
, rn
, new);
949 rib_install_kernel(rn
, new, old
);
953 * If nexthop for selected route is not active or install
955 * may need to uninstall and delete for redistribution.
958 if (IS_ZEBRA_DEBUG_RIB
) {
961 "%s(%u:%u):%pRN: Deleting route rn %p, re %p (%s) old %p (%s) - nexthop inactive",
962 zvrf_name(zvrf
), zvrf_id(zvrf
),
963 new->table
, rn
, rn
, new,
964 zebra_route_string(new->type
),
966 zebra_route_string(old
->type
));
969 "%s(%u:%u):%pRN: Deleting route rn %p, re %p (%s) - nexthop inactive",
970 zvrf_name(zvrf
), zvrf_id(zvrf
),
971 new->table
, rn
, rn
, new,
972 zebra_route_string(new->type
));
976 * When we have gotten to this point
977 * the new route entry has no nexthops
978 * that are usable and as such we need
979 * to remove the old route, but only
980 * if we were the one who installed
983 if (!RIB_SYSTEM_ROUTE(old
)) {
984 /* If labeled-unicast route, uninstall transit
986 if (zebra_rib_labeled_unicast(old
))
987 zebra_mpls_lsp_uninstall(zvrf
, rn
, old
);
989 rib_uninstall_kernel(rn
, old
);
994 * Same route selected; check if in the FIB and if not,
995 * re-install. This is housekeeping code to deal with
996 * race conditions in kernel with linux netlink reporting
997 * interface up before IPv4 or IPv6 protocol is ready
1000 if (!CHECK_FLAG(new->status
, ROUTE_ENTRY_INSTALLED
) ||
1001 RIB_SYSTEM_ROUTE(new))
1002 rib_install_kernel(rn
, new, NULL
);
1005 /* Update prior route. */
1007 UNSET_FLAG(old
->status
, ROUTE_ENTRY_CHANGED
);
1009 /* Clear changed flag. */
1010 UNSET_FLAG(new->status
, ROUTE_ENTRY_CHANGED
);
1013 /* Check if 'alternate' RIB entry is better than 'current'. */
1014 static struct route_entry
*rib_choose_best(struct route_entry
*current
,
1015 struct route_entry
*alternate
)
1017 if (current
== NULL
)
1020 /* filter route selection in following order:
1021 * - connected beats other types
1022 * - if both connected, loopback or vrf wins
1023 * - lower distance beats higher
1024 * - lower metric beats higher for equal distance
1025 * - last, hence oldest, route wins tie break.
1028 /* Connected routes. Check to see if either are a vrf
1029 * or loopback interface. If not, pick the last connected
1030 * route of the set of lowest metric connected routes.
1032 if (alternate
->type
== ZEBRA_ROUTE_CONNECT
) {
1033 if (current
->type
!= ZEBRA_ROUTE_CONNECT
)
1036 /* both are connected. are either loop or vrf? */
1037 struct nexthop
*nexthop
= NULL
;
1039 for (ALL_NEXTHOPS(alternate
->nhe
->nhg
, nexthop
)) {
1040 struct interface
*ifp
= if_lookup_by_index(
1041 nexthop
->ifindex
, alternate
->vrf_id
);
1043 if (ifp
&& if_is_loopback(ifp
))
1047 for (ALL_NEXTHOPS(current
->nhe
->nhg
, nexthop
)) {
1048 struct interface
*ifp
= if_lookup_by_index(
1049 nexthop
->ifindex
, current
->vrf_id
);
1051 if (ifp
&& if_is_loopback(ifp
))
1055 /* Neither are loop or vrf so pick best metric */
1056 if (alternate
->metric
<= current
->metric
)
1062 if (current
->type
== ZEBRA_ROUTE_CONNECT
)
1065 /* higher distance loses */
1066 if (alternate
->distance
< current
->distance
)
1068 if (current
->distance
< alternate
->distance
)
1071 /* metric tie-breaks equal distance */
1072 if (alternate
->metric
<= current
->metric
)
1078 /* Core function for processing routing information base. */
1079 static void rib_process(struct route_node
*rn
)
1081 struct route_entry
*re
;
1082 struct route_entry
*next
;
1083 struct route_entry
*old_selected
= NULL
;
1084 struct route_entry
*new_selected
= NULL
;
1085 struct route_entry
*old_fib
= NULL
;
1086 struct route_entry
*new_fib
= NULL
;
1087 struct route_entry
*best
= NULL
;
1089 struct zebra_vrf
*zvrf
= NULL
;
1092 vrf_id_t vrf_id
= VRF_UNKNOWN
;
1096 dest
= rib_dest_from_rnode(rn
);
1098 * We have an enqueued node with nothing to process here
1099 * let's just finish up and return;
1104 zvrf
= rib_dest_vrf(dest
);
1105 vrf_id
= zvrf_id(zvrf
);
1107 vrf
= vrf_lookup_by_id(vrf_id
);
1110 * we can have rn's that have a NULL info pointer
1111 * (dest). As such let's not let the deref happen
1112 * additionally we know RNODE_FOREACH_RE_SAFE
1113 * will not iterate so we are ok.
1115 if (IS_ZEBRA_DEBUG_RIB_DETAILED
) {
1116 struct route_entry
*re
= re_list_first(&dest
->routes
);
1118 zlog_debug("%s(%u:%u):%pRN: Processing rn %p",
1119 VRF_LOGNAME(vrf
), vrf_id
, re
->table
, rn
,
1123 old_fib
= dest
->selected_fib
;
1125 RNODE_FOREACH_RE_SAFE (rn
, re
, next
) {
1126 if (IS_ZEBRA_DEBUG_RIB_DETAILED
) {
1127 char flags_buf
[128];
1128 char status_buf
[128];
1131 "%s(%u:%u):%pRN: Examine re %p (%s) status: %sflags: %sdist %d metric %d",
1132 VRF_LOGNAME(vrf
), vrf_id
, re
->table
, rn
, re
,
1133 zebra_route_string(re
->type
),
1134 _dump_re_status(re
, status_buf
,
1135 sizeof(status_buf
)),
1136 zclient_dump_route_flags(re
->flags
, flags_buf
,
1138 re
->distance
, re
->metric
);
1141 /* Currently selected re. */
1142 if (CHECK_FLAG(re
->flags
, ZEBRA_FLAG_SELECTED
)) {
1143 assert(old_selected
== NULL
);
1147 /* Skip deleted entries from selection */
1148 if (CHECK_FLAG(re
->status
, ROUTE_ENTRY_REMOVED
))
1152 * If the route entry has changed, verify/resolve
1153 * the nexthops associated with the entry.
1155 * In any event if we have nexthops that are not active
1156 * then we cannot use this particular route entry so
1159 if (CHECK_FLAG(re
->status
, ROUTE_ENTRY_CHANGED
)) {
1160 if (!nexthop_active_update(rn
, re
)) {
1161 const struct prefix
*p
;
1162 struct rib_table_info
*info
;
1164 if (re
->type
== ZEBRA_ROUTE_TABLE
) {
1165 /* XXX: HERE BE DRAGONS!!!!!
1166 * In all honesty, I have not yet
1167 * figured out what this part does or
1168 * why the ROUTE_ENTRY_CHANGED test
1169 * above is correct or why we need to
1170 * delete a route here, and also not
1171 * whether this concerns both selected
1172 * and fib route, or only selected
1175 * This entry was denied by the 'ip
1177 * table' route-map, we need to delete
1179 if (re
!= old_selected
) {
1180 if (IS_ZEBRA_DEBUG_RIB
)
1182 "%s: %s(%u):%pRN: imported via import-table but denied by the ip protocol table route-map",
1189 SET_FLAG(re
->status
,
1190 ROUTE_ENTRY_REMOVED
);
1193 info
= srcdest_rnode_table_info(rn
);
1194 srcdest_rnode_prefixes(rn
, &p
, NULL
);
1195 zsend_route_notify_owner(
1196 rn
, re
, ZAPI_ROUTE_FAIL_INSTALL
,
1197 info
->afi
, info
->safi
);
1202 * If the re has not changed and the nhg we have is
1203 * not usable, then we cannot use this route entry
1204 * for consideration, as that the route will just
1205 * not install if it is selected.
1207 if (!nexthop_group_active_nexthop_num(&re
->nhe
->nhg
))
1211 /* Infinite distance. */
1212 if (re
->distance
== DISTANCE_INFINITY
&&
1213 re
->type
!= ZEBRA_ROUTE_KERNEL
) {
1214 UNSET_FLAG(re
->status
, ROUTE_ENTRY_CHANGED
);
1218 if (CHECK_FLAG(re
->flags
, ZEBRA_FLAG_FIB_OVERRIDE
)) {
1219 best
= rib_choose_best(new_fib
, re
);
1220 if (new_fib
&& best
!= new_fib
)
1221 UNSET_FLAG(new_fib
->status
,
1222 ROUTE_ENTRY_CHANGED
);
1225 best
= rib_choose_best(new_selected
, re
);
1226 if (new_selected
&& best
!= new_selected
)
1227 UNSET_FLAG(new_selected
->status
,
1228 ROUTE_ENTRY_CHANGED
);
1229 new_selected
= best
;
1232 UNSET_FLAG(re
->status
, ROUTE_ENTRY_CHANGED
);
1233 } /* RNODE_FOREACH_RE */
1235 /* If no FIB override route, use the selected route also for FIB */
1236 if (new_fib
== NULL
)
1237 new_fib
= new_selected
;
1239 /* After the cycle is finished, the following pointers will be set:
1240 * old_selected --- RE entry currently having SELECTED
1241 * new_selected --- RE entry that is newly SELECTED
1242 * old_fib --- RE entry currently in kernel FIB
1243 * new_fib --- RE entry that is newly to be in kernel FIB
1245 * new_selected will get SELECTED flag, and is going to be redistributed
1246 * the zclients. new_fib (which can be new_selected) will be installed
1250 if (IS_ZEBRA_DEBUG_RIB_DETAILED
) {
1251 struct route_entry
*entry
;
1253 entry
= old_selected
1258 : new_fib
? new_fib
: NULL
;
1261 "%s(%u:%u):%pRN: After processing: old_selected %p new_selected %p old_fib %p new_fib %p",
1262 VRF_LOGNAME(vrf
), vrf_id
, entry
? entry
->table
: 0, rn
,
1263 (void *)old_selected
, (void *)new_selected
,
1264 (void *)old_fib
, (void *)new_fib
);
1267 /* Buffer ROUTE_ENTRY_CHANGED here, because it will get cleared if
1268 * fib == selected */
1269 bool selected_changed
= new_selected
&& CHECK_FLAG(new_selected
->status
,
1270 ROUTE_ENTRY_CHANGED
);
1272 /* Update SELECTED entry */
1273 if (old_selected
!= new_selected
|| selected_changed
) {
1275 if (new_selected
&& new_selected
!= new_fib
)
1276 UNSET_FLAG(new_selected
->status
, ROUTE_ENTRY_CHANGED
);
1279 SET_FLAG(new_selected
->flags
, ZEBRA_FLAG_SELECTED
);
1283 * If we're removing the old entry, we should tell
1284 * redist subscribers about that *if* they aren't
1285 * going to see a redist for the new entry.
1287 if (!new_selected
|| CHECK_FLAG(old_selected
->status
,
1288 ROUTE_ENTRY_REMOVED
))
1289 redistribute_delete(rn
, old_selected
,
1292 if (old_selected
!= new_selected
)
1293 UNSET_FLAG(old_selected
->flags
,
1294 ZEBRA_FLAG_SELECTED
);
1298 /* Update fib according to selection results */
1299 if (new_fib
&& old_fib
)
1300 rib_process_update_fib(zvrf
, rn
, old_fib
, new_fib
);
1302 rib_process_add_fib(zvrf
, rn
, new_fib
);
1304 rib_process_del_fib(zvrf
, rn
, old_fib
);
1306 /* Remove all RE entries queued for removal */
1307 RNODE_FOREACH_RE_SAFE (rn
, re
, next
) {
1308 if (CHECK_FLAG(re
->status
, ROUTE_ENTRY_REMOVED
)) {
1309 if (IS_ZEBRA_DEBUG_RIB
) {
1310 rnode_debug(rn
, vrf_id
, "rn %p, removing re %p",
1311 (void *)rn
, (void *)re
);
1318 * Check if the dest can be deleted now.
1323 static void zebra_rib_evaluate_mpls(struct route_node
*rn
)
1325 rib_dest_t
*dest
= rib_dest_from_rnode(rn
);
1326 struct zebra_vrf
*zvrf
= vrf_info_lookup(VRF_DEFAULT
);
1331 if (CHECK_FLAG(dest
->flags
, RIB_DEST_UPDATE_LSPS
)) {
1332 if (IS_ZEBRA_DEBUG_MPLS
)
1334 "%s(%u): Scheduling all LSPs upon RIB completion",
1335 zvrf_name(zvrf
), zvrf_id(zvrf
));
1336 zebra_mpls_lsp_schedule(zvrf
);
1337 mpls_unmark_lsps_for_processing(rn
);
1342 * Utility to match route with dplane context data
1344 static bool rib_route_match_ctx(const struct route_entry
*re
,
1345 const struct zebra_dplane_ctx
*ctx
,
1348 bool result
= false;
1352 * In 'update' case, we test info about the 'previous' or
1355 if ((re
->type
== dplane_ctx_get_old_type(ctx
)) &&
1356 (re
->instance
== dplane_ctx_get_old_instance(ctx
))) {
1359 /* We use an extra test for statics, and another for
1362 if (re
->type
== ZEBRA_ROUTE_STATIC
&&
1363 (re
->distance
!= dplane_ctx_get_old_distance(ctx
) ||
1364 re
->tag
!= dplane_ctx_get_old_tag(ctx
))) {
1366 } else if (re
->type
== ZEBRA_ROUTE_KERNEL
&&
1368 dplane_ctx_get_old_metric(ctx
)) {
1375 * Ordinary, single-route case using primary context info
1377 if ((dplane_ctx_get_op(ctx
) != DPLANE_OP_ROUTE_DELETE
) &&
1378 CHECK_FLAG(re
->status
, ROUTE_ENTRY_REMOVED
)) {
1379 /* Skip route that's been deleted */
1383 if ((re
->type
== dplane_ctx_get_type(ctx
)) &&
1384 (re
->instance
== dplane_ctx_get_instance(ctx
))) {
1387 /* We use an extra test for statics, and another for
1390 if (re
->type
== ZEBRA_ROUTE_STATIC
&&
1391 (re
->distance
!= dplane_ctx_get_distance(ctx
) ||
1392 re
->tag
!= dplane_ctx_get_tag(ctx
))) {
1394 } else if (re
->type
== ZEBRA_ROUTE_KERNEL
&&
1395 re
->metric
!= dplane_ctx_get_metric(ctx
)) {
1397 } else if (re
->type
== ZEBRA_ROUTE_CONNECT
) {
1398 result
= nexthop_group_equal_no_recurse(
1399 &re
->nhe
->nhg
, dplane_ctx_get_ng(ctx
));
1409 static void zebra_rib_fixup_system(struct route_node
*rn
)
1411 struct route_entry
*re
;
1413 RNODE_FOREACH_RE(rn
, re
) {
1414 struct nexthop
*nhop
;
1416 if (!RIB_SYSTEM_ROUTE(re
))
1419 if (CHECK_FLAG(re
->status
, ROUTE_ENTRY_REMOVED
))
1422 SET_FLAG(re
->status
, ROUTE_ENTRY_INSTALLED
);
1423 UNSET_FLAG(re
->status
, ROUTE_ENTRY_QUEUED
);
1425 for (ALL_NEXTHOPS(re
->nhe
->nhg
, nhop
)) {
1426 if (CHECK_FLAG(nhop
->flags
, NEXTHOP_FLAG_RECURSIVE
))
1429 SET_FLAG(nhop
->flags
, NEXTHOP_FLAG_FIB
);
1434 /* Route comparison logic, with various special cases. */
1435 static bool rib_compare_routes(const struct route_entry
*re1
,
1436 const struct route_entry
*re2
)
1438 if (re1
->type
!= re2
->type
)
1441 if (re1
->instance
!= re2
->instance
)
1444 if (re1
->type
== ZEBRA_ROUTE_KERNEL
&& re1
->metric
!= re2
->metric
)
1447 if (CHECK_FLAG(re1
->flags
, ZEBRA_FLAG_RR_USE_DISTANCE
) &&
1448 re1
->distance
!= re2
->distance
)
1451 /* We support multiple connected routes: this supports multiple
1452 * v6 link-locals, and we also support multiple addresses in the same
1453 * subnet on a single interface.
1455 if (re1
->type
!= ZEBRA_ROUTE_CONNECT
)
1462 * Compare nexthop lists from a route and a dplane context; test whether
1463 * the list installed in the FIB matches the route's list.
1464 * Set 'changed_p' to 'true' if there were changes to the route's
1465 * installed nexthops.
1467 * Return 'false' if any ACTIVE route nexthops are not mentioned in the FIB
1470 static bool rib_update_nhg_from_ctx(struct nexthop_group
*re_nhg
,
1471 const struct nexthop_group
*ctx_nhg
,
1474 bool matched_p
= true;
1475 struct nexthop
*nexthop
, *ctx_nexthop
;
1477 /* Get the first `installed` one to check against.
1478 * If the dataplane doesn't set these to be what was actually installed,
1479 * it will just be whatever was in re->nhe->nhg?
1481 ctx_nexthop
= ctx_nhg
->nexthop
;
1483 if (CHECK_FLAG(ctx_nexthop
->flags
, NEXTHOP_FLAG_RECURSIVE
)
1484 || !CHECK_FLAG(ctx_nexthop
->flags
, NEXTHOP_FLAG_ACTIVE
))
1485 ctx_nexthop
= nexthop_next_active_resolved(ctx_nexthop
);
1487 for (ALL_NEXTHOPS_PTR(re_nhg
, nexthop
)) {
1489 if (CHECK_FLAG(nexthop
->flags
, NEXTHOP_FLAG_RECURSIVE
))
1492 if (!CHECK_FLAG(nexthop
->flags
, NEXTHOP_FLAG_ACTIVE
))
1495 /* Check for a FIB nexthop corresponding to the RIB nexthop */
1496 if (!nexthop_same(ctx_nexthop
, nexthop
)) {
1497 /* If the FIB doesn't know about the nexthop,
1498 * it's not installed
1500 if (IS_ZEBRA_DEBUG_RIB_DETAILED
||
1501 IS_ZEBRA_DEBUG_NHG_DETAIL
) {
1502 zlog_debug("%s: no ctx match for rib nh %pNHv %s",
1504 (CHECK_FLAG(nexthop
->flags
,
1510 if (CHECK_FLAG(nexthop
->flags
, NEXTHOP_FLAG_FIB
))
1513 UNSET_FLAG(nexthop
->flags
, NEXTHOP_FLAG_FIB
);
1515 /* Keep checking nexthops */
1519 if (CHECK_FLAG(ctx_nexthop
->flags
, NEXTHOP_FLAG_FIB
)) {
1520 if (!CHECK_FLAG(nexthop
->flags
, NEXTHOP_FLAG_FIB
)) {
1521 if (IS_ZEBRA_DEBUG_NHG_DETAIL
)
1522 zlog_debug("%s: rib nh %pNHv -> installed",
1528 SET_FLAG(nexthop
->flags
, NEXTHOP_FLAG_FIB
);
1530 if (CHECK_FLAG(nexthop
->flags
, NEXTHOP_FLAG_FIB
)) {
1531 if (IS_ZEBRA_DEBUG_NHG_DETAIL
)
1532 zlog_debug("%s: rib nh %pNHv -> uninstalled",
1538 UNSET_FLAG(nexthop
->flags
, NEXTHOP_FLAG_FIB
);
1541 ctx_nexthop
= nexthop_next_active_resolved(ctx_nexthop
);
1548 * Update a route from a dplane context. This consolidates common code
1549 * that can be used in processing of results from FIB updates, and in
1550 * async notification processing.
1551 * The return is 'true' if the installed nexthops changed; 'false' otherwise.
1553 static bool rib_update_re_from_ctx(struct route_entry
*re
,
1554 struct route_node
*rn
,
1555 struct zebra_dplane_ctx
*ctx
)
1557 struct nexthop
*nexthop
;
1559 const struct nexthop_group
*ctxnhg
;
1560 struct nexthop_group
*re_nhg
;
1561 bool is_selected
= false; /* Is 're' currently the selected re? */
1562 bool changed_p
= false; /* Change to nexthops? */
1566 vrf
= vrf_lookup_by_id(re
->vrf_id
);
1568 dest
= rib_dest_from_rnode(rn
);
1570 is_selected
= (re
== dest
->selected_fib
);
1572 if (IS_ZEBRA_DEBUG_RIB_DETAILED
)
1573 zlog_debug("update_from_ctx: %s(%u:%u):%pRN: %sSELECTED, re %p",
1574 VRF_LOGNAME(vrf
), re
->vrf_id
, re
->table
, rn
,
1575 (is_selected
? "" : "NOT "), re
);
1577 /* Update zebra's nexthop FIB flag for each nexthop that was installed.
1578 * If the installed set differs from the set requested by the rib/owner,
1579 * we use the fib-specific nexthop-group to record the actual FIB
1583 ctxnhg
= dplane_ctx_get_ng(ctx
);
1585 /* Check route's fib group and incoming notif group for equivalence.
1587 * Let's assume the nexthops are ordered here to save time.
1589 /* TODO -- this isn't testing or comparing the FIB flags; we should
1590 * do a more explicit loop, checking the incoming notification's flags.
1592 if (re
->fib_ng
.nexthop
&& ctxnhg
->nexthop
&&
1593 nexthop_group_equal(&re
->fib_ng
, ctxnhg
))
1596 /* If the new FIB set matches the existing FIB set, we're done. */
1598 if (IS_ZEBRA_DEBUG_RIB
)
1600 "%s(%u:%u):%pRN update_from_ctx(): existing fib nhg, no change",
1601 VRF_LOGNAME(vrf
), re
->vrf_id
, re
->table
, rn
);
1604 } else if (CHECK_FLAG(re
->status
, ROUTE_ENTRY_USE_FIB_NHG
)) {
1606 * Free stale fib list and move on to check the rib nhg.
1608 if (IS_ZEBRA_DEBUG_RIB
)
1610 "%s(%u:%u):%pRN update_from_ctx(): replacing fib nhg",
1611 VRF_LOGNAME(vrf
), re
->vrf_id
, re
->table
, rn
);
1612 nexthops_free(re
->fib_ng
.nexthop
);
1613 re
->fib_ng
.nexthop
= NULL
;
1615 UNSET_FLAG(re
->status
, ROUTE_ENTRY_USE_FIB_NHG
);
1617 /* Note that the installed nexthops have changed */
1620 if (IS_ZEBRA_DEBUG_RIB
)
1622 "%s(%u:%u):%pRN update_from_ctx(): no fib nhg",
1623 VRF_LOGNAME(vrf
), re
->vrf_id
, re
->table
, rn
);
1627 * Compare with the rib nexthop group. The comparison here is different:
1628 * the RIB group may be a superset of the list installed in the FIB. We
1629 * walk the RIB group, looking for the 'installable' candidate
1630 * nexthops, and then check those against the set
1631 * that is actually installed.
1633 * Assume nexthops are ordered here as well.
1636 /* If nothing is installed, we can skip some of the checking/comparison
1639 if (ctxnhg
->nexthop
== NULL
) {
1644 matched
= rib_update_nhg_from_ctx(&(re
->nhe
->nhg
), ctxnhg
, &changed_p
);
1646 /* If all nexthops were processed, we're done */
1648 if (IS_ZEBRA_DEBUG_RIB
)
1650 "%s(%u:%u):%pRN update_from_ctx(): rib nhg matched, changed '%s'",
1651 VRF_LOGNAME(vrf
), re
->vrf_id
, re
->table
, rn
,
1652 (changed_p
? "true" : "false"));
1658 /* FIB nexthop set differs from the RIB set:
1659 * create a fib-specific nexthop-group
1661 if (IS_ZEBRA_DEBUG_RIB
)
1663 "%s(%u:%u):%pRN update_from_ctx(): changed %s, adding new fib nhg%s",
1664 VRF_LOGNAME(vrf
), re
->vrf_id
, re
->table
, rn
,
1665 (changed_p
? "true" : "false"),
1666 ctxnhg
->nexthop
!= NULL
? "" : " (empty)");
1668 /* Set the flag about the dedicated fib list */
1669 SET_FLAG(re
->status
, ROUTE_ENTRY_USE_FIB_NHG
);
1670 if (ctxnhg
->nexthop
)
1671 copy_nexthops(&(re
->fib_ng
.nexthop
), ctxnhg
->nexthop
, NULL
);
1676 * Check the status of the route's backup nexthops, if any.
1677 * The logic for backups is somewhat different: if any backup is
1678 * installed, a new fib nhg will be attached to the route.
1680 re_nhg
= zebra_nhg_get_backup_nhg(re
->nhe
);
1682 goto done
; /* No backup nexthops */
1684 /* First check the route's 'fib' list of backups, if it's present
1685 * from some previous event.
1687 re_nhg
= &re
->fib_backup_ng
;
1688 ctxnhg
= dplane_ctx_get_backup_ng(ctx
);
1691 if (re_nhg
->nexthop
&& ctxnhg
&& nexthop_group_equal(re_nhg
, ctxnhg
))
1694 /* If the new FIB set matches an existing FIB set, we're done. */
1696 if (IS_ZEBRA_DEBUG_RIB
)
1698 "%s(%u):%pRN update_from_ctx(): existing fib backup nhg, no change",
1699 VRF_LOGNAME(vrf
), re
->vrf_id
, rn
);
1702 } else if (re
->fib_backup_ng
.nexthop
) {
1704 * Free stale fib backup list and move on to check
1705 * the route's backups.
1707 if (IS_ZEBRA_DEBUG_RIB
)
1709 "%s(%u):%pRN update_from_ctx(): replacing fib backup nhg",
1710 VRF_LOGNAME(vrf
), re
->vrf_id
, rn
);
1711 nexthops_free(re
->fib_backup_ng
.nexthop
);
1712 re
->fib_backup_ng
.nexthop
= NULL
;
1714 /* Note that the installed nexthops have changed */
1717 if (IS_ZEBRA_DEBUG_RIB
)
1719 "%s(%u):%pRN update_from_ctx(): no fib backup nhg",
1720 VRF_LOGNAME(vrf
), re
->vrf_id
, rn
);
1724 * If a FIB backup nexthop set exists, attach a copy
1725 * to the route if any backup is installed
1727 if (ctxnhg
&& ctxnhg
->nexthop
) {
1729 for (ALL_NEXTHOPS_PTR(ctxnhg
, nexthop
)) {
1730 if (CHECK_FLAG(nexthop
->flags
, NEXTHOP_FLAG_FIB
))
1734 /* If no installed backups, we're done */
1735 if (nexthop
== NULL
)
1738 if (IS_ZEBRA_DEBUG_RIB
)
1740 "%s(%u):%pRN update_from_ctx(): changed %s, adding new backup fib nhg",
1741 VRF_LOGNAME(vrf
), re
->vrf_id
, rn
,
1742 (changed_p
? "true" : "false"));
1744 copy_nexthops(&(re
->fib_backup_ng
.nexthop
), ctxnhg
->nexthop
,
1754 * Helper to locate a zebra route-node from a dplane context. This is used
1755 * when processing dplane results, e.g. Note well: the route-node is returned
1756 * with a ref held - route_unlock_node() must be called eventually.
1758 struct route_node
*rib_find_rn_from_ctx(const struct zebra_dplane_ctx
*ctx
)
1760 struct route_table
*table
= NULL
;
1761 struct route_node
*rn
= NULL
;
1762 const struct prefix
*dest_pfx
, *src_pfx
;
1764 /* Locate rn and re(s) from ctx */
1766 table
= zebra_vrf_lookup_table_with_table_id(
1767 dplane_ctx_get_afi(ctx
), dplane_ctx_get_safi(ctx
),
1768 dplane_ctx_get_vrf(ctx
), dplane_ctx_get_table(ctx
));
1769 if (table
== NULL
) {
1770 if (IS_ZEBRA_DEBUG_DPLANE
) {
1772 "Failed to find route for ctx: no table for afi %d, safi %d, vrf %s(%u)",
1773 dplane_ctx_get_afi(ctx
),
1774 dplane_ctx_get_safi(ctx
),
1775 vrf_id_to_name(dplane_ctx_get_vrf(ctx
)),
1776 dplane_ctx_get_vrf(ctx
));
1781 dest_pfx
= dplane_ctx_get_dest(ctx
);
1782 src_pfx
= dplane_ctx_get_src(ctx
);
1784 rn
= srcdest_rnode_get(table
, dest_pfx
,
1785 src_pfx
? (struct prefix_ipv6
*)src_pfx
: NULL
);
1794 * Route-update results processing after async dataplane update.
1796 static void rib_process_result(struct zebra_dplane_ctx
*ctx
)
1798 struct zebra_vrf
*zvrf
= NULL
;
1800 struct route_node
*rn
= NULL
;
1801 struct route_entry
*re
= NULL
, *old_re
= NULL
, *rib
;
1802 bool is_update
= false;
1803 enum dplane_op_e op
;
1804 enum zebra_dplane_result status
;
1807 bool fib_changed
= false;
1808 struct rib_table_info
*info
;
1809 bool rt_delete
= false;
1811 zvrf
= vrf_info_lookup(dplane_ctx_get_vrf(ctx
));
1812 vrf
= vrf_lookup_by_id(dplane_ctx_get_vrf(ctx
));
1814 /* Locate rn and re(s) from ctx */
1815 rn
= rib_find_rn_from_ctx(ctx
);
1817 if (IS_ZEBRA_DEBUG_DPLANE
) {
1819 "Failed to process dplane results: no route for %s(%u):%pRN",
1820 VRF_LOGNAME(vrf
), dplane_ctx_get_vrf(ctx
), rn
);
1825 dest
= rib_dest_from_rnode(rn
);
1826 info
= srcdest_rnode_table_info(rn
);
1828 op
= dplane_ctx_get_op(ctx
);
1829 status
= dplane_ctx_get_status(ctx
);
1831 if (IS_ZEBRA_DEBUG_DPLANE_DETAIL
)
1833 "%s(%u:%u):%pRN Processing dplane result ctx %p, op %s result %s",
1834 VRF_LOGNAME(vrf
), dplane_ctx_get_vrf(ctx
),
1835 dplane_ctx_get_table(ctx
), rn
, ctx
, dplane_op2str(op
),
1836 dplane_res2str(status
));
1839 * Update is a bit of a special case, where we may have both old and new
1840 * routes to post-process.
1842 is_update
= dplane_ctx_is_update(ctx
);
1845 * Take a pass through the routes, look for matches with the context
1848 RNODE_FOREACH_RE(rn
, rib
) {
1851 if (rib_route_match_ctx(rib
, ctx
, false))
1855 /* Check for old route match */
1856 if (is_update
&& (old_re
== NULL
)) {
1857 if (rib_route_match_ctx(rib
, ctx
, true /*is_update*/))
1861 /* Have we found the routes we need to work on? */
1862 if (re
&& ((!is_update
|| old_re
)))
1866 seq
= dplane_ctx_get_seq(ctx
);
1869 * Check sequence number(s) to detect stale results before continuing
1872 if (re
->dplane_sequence
!= seq
) {
1873 if (IS_ZEBRA_DEBUG_DPLANE_DETAIL
)
1875 "%s(%u):%pRN Stale dplane result for re %p",
1877 dplane_ctx_get_vrf(ctx
), rn
, re
);
1879 if (!zrouter
.asic_offloaded
||
1880 (CHECK_FLAG(re
->flags
, ZEBRA_FLAG_OFFLOADED
) ||
1881 CHECK_FLAG(re
->flags
, ZEBRA_FLAG_OFFLOAD_FAILED
)))
1882 UNSET_FLAG(re
->status
, ROUTE_ENTRY_QUEUED
);
1887 if (old_re
->dplane_sequence
!= dplane_ctx_get_old_seq(ctx
)) {
1888 if (IS_ZEBRA_DEBUG_DPLANE_DETAIL
)
1890 "%s(%u:%u):%pRN Stale dplane result for old_re %p",
1892 dplane_ctx_get_vrf(ctx
), old_re
->table
,
1895 UNSET_FLAG(old_re
->status
, ROUTE_ENTRY_QUEUED
);
1899 case DPLANE_OP_ROUTE_INSTALL
:
1900 case DPLANE_OP_ROUTE_UPDATE
:
1901 if (status
== ZEBRA_DPLANE_REQUEST_SUCCESS
) {
1903 UNSET_FLAG(re
->status
, ROUTE_ENTRY_FAILED
);
1904 SET_FLAG(re
->status
, ROUTE_ENTRY_INSTALLED
);
1907 * On an update operation from the same route type
1908 * context retrieval currently has no way to know
1909 * which was the old and which was the new.
1910 * So don't unset our flags that we just set.
1911 * We know redistribution is ok because the
1912 * old_re in this case is used for nothing
1913 * more than knowing whom to contact if necessary.
1915 if (old_re
&& old_re
!= re
) {
1916 UNSET_FLAG(old_re
->status
, ROUTE_ENTRY_FAILED
);
1917 UNSET_FLAG(old_re
->status
,
1918 ROUTE_ENTRY_INSTALLED
);
1921 /* Update zebra route based on the results in
1922 * the context struct.
1926 rib_update_re_from_ctx(re
, rn
, ctx
);
1929 if (IS_ZEBRA_DEBUG_DPLANE_DETAIL
)
1931 "%s(%u:%u):%pRN no fib change for re",
1933 dplane_ctx_get_vrf(ctx
),
1934 dplane_ctx_get_table(
1939 /* Redistribute if this is the selected re */
1940 if (dest
&& re
== dest
->selected_fib
)
1941 redistribute_update(rn
, re
, old_re
);
1945 * System routes are weird in that they
1946 * allow multiple to be installed that match
1947 * to the same prefix, so after we get the
1948 * result we need to clean them up so that
1949 * we can actually use them.
1951 if ((re
&& RIB_SYSTEM_ROUTE(re
)) ||
1952 (old_re
&& RIB_SYSTEM_ROUTE(old_re
)))
1953 zebra_rib_fixup_system(rn
);
1958 /* Notify route owner */
1959 if (zebra_router_notify_on_ack())
1960 zsend_route_notify_owner_ctx(ctx
, ZAPI_ROUTE_INSTALLED
);
1963 if (CHECK_FLAG(re
->flags
,
1964 ZEBRA_FLAG_OFFLOADED
))
1965 zsend_route_notify_owner_ctx(
1967 ZAPI_ROUTE_INSTALLED
);
1970 ZEBRA_FLAG_OFFLOAD_FAILED
))
1971 zsend_route_notify_owner_ctx(
1973 ZAPI_ROUTE_FAIL_INSTALL
);
1978 SET_FLAG(re
->status
, ROUTE_ENTRY_FAILED
);
1979 UNSET_FLAG(re
->status
, ROUTE_ENTRY_INSTALLED
);
1981 SET_FLAG(old_re
->status
, ROUTE_ENTRY_FAILED
);
1983 zsend_route_notify_owner(
1984 rn
, re
, ZAPI_ROUTE_FAIL_INSTALL
,
1985 info
->afi
, info
->safi
);
1987 zlog_warn("%s(%u:%u):%pRN: Route install failed",
1988 VRF_LOGNAME(vrf
), dplane_ctx_get_vrf(ctx
),
1989 dplane_ctx_get_table(ctx
), rn
);
1992 case DPLANE_OP_ROUTE_DELETE
:
1995 SET_FLAG(re
->status
, ROUTE_ENTRY_FAILED
);
1997 * In the delete case, the zebra core datastructs were
1998 * updated (or removed) at the time the delete was issued,
1999 * so we're just notifying the route owner.
2001 if (status
== ZEBRA_DPLANE_REQUEST_SUCCESS
) {
2003 UNSET_FLAG(re
->status
, ROUTE_ENTRY_INSTALLED
);
2004 UNSET_FLAG(re
->status
, ROUTE_ENTRY_FAILED
);
2006 zsend_route_notify_owner_ctx(ctx
, ZAPI_ROUTE_REMOVED
);
2012 SET_FLAG(re
->status
, ROUTE_ENTRY_FAILED
);
2013 zsend_route_notify_owner_ctx(ctx
,
2014 ZAPI_ROUTE_REMOVE_FAIL
);
2016 zlog_warn("%s(%u:%u):%pRN: Route Deletion failure",
2017 VRF_LOGNAME(vrf
), dplane_ctx_get_vrf(ctx
),
2018 dplane_ctx_get_table(ctx
), rn
);
2022 * System routes are weird in that they
2023 * allow multiple to be installed that match
2024 * to the same prefix, so after we get the
2025 * result we need to clean them up so that
2026 * we can actually use them.
2028 if ((re
&& RIB_SYSTEM_ROUTE(re
)) ||
2029 (old_re
&& RIB_SYSTEM_ROUTE(old_re
)))
2030 zebra_rib_fixup_system(rn
);
2036 zebra_rib_evaluate_rn_nexthops(rn
, seq
, rt_delete
);
2037 zebra_rib_evaluate_mpls(rn
);
2041 route_unlock_node(rn
);
2043 /* Return context to dataplane module */
2044 dplane_ctx_fini(&ctx
);
2048 * Count installed/FIB nexthops
2050 static int rib_count_installed_nh(struct route_entry
*re
)
2053 struct nexthop
*nexthop
;
2054 struct nexthop_group
*nhg
;
2056 nhg
= rib_get_fib_nhg(re
);
2058 for (ALL_NEXTHOPS_PTR(nhg
, nexthop
)) {
2059 /* The meaningful flag depends on where the installed
2062 if (nhg
== &(re
->fib_ng
)) {
2063 if (CHECK_FLAG(nexthop
->flags
, NEXTHOP_FLAG_FIB
))
2066 if (CHECK_FLAG(nexthop
->flags
, NEXTHOP_FLAG_ACTIVE
))
2071 nhg
= rib_get_fib_backup_nhg(re
);
2073 for (ALL_NEXTHOPS_PTR(nhg
, nexthop
)) {
2074 if (CHECK_FLAG(nexthop
->flags
, NEXTHOP_FLAG_FIB
))
2083 * Handle notification from async dataplane: the dataplane has detected
2084 * some change to a route, and notifies zebra so that the control plane
2085 * can reflect that change.
2087 static void rib_process_dplane_notify(struct zebra_dplane_ctx
*ctx
)
2089 struct route_node
*rn
= NULL
;
2090 struct route_entry
*re
= NULL
;
2092 struct nexthop
*nexthop
;
2094 bool fib_changed
= false;
2095 bool debug_p
= IS_ZEBRA_DEBUG_DPLANE
| IS_ZEBRA_DEBUG_RIB
;
2096 int start_count
, end_count
;
2098 vrf
= vrf_lookup_by_id(dplane_ctx_get_vrf(ctx
));
2100 /* Locate rn and re(s) from ctx */
2101 rn
= rib_find_rn_from_ctx(ctx
);
2105 "Failed to process dplane notification: no routes for %s(%u:%u):%pRN",
2106 VRF_LOGNAME(vrf
), dplane_ctx_get_vrf(ctx
),
2107 dplane_ctx_get_table(ctx
), rn
);
2112 dest
= rib_dest_from_rnode(rn
);
2115 zlog_debug("%s(%u:%u):%pRN Processing dplane notif ctx %p",
2116 VRF_LOGNAME(vrf
), dplane_ctx_get_vrf(ctx
),
2117 dplane_ctx_get_table(ctx
), rn
, ctx
);
2120 * Take a pass through the routes, look for matches with the context
2123 RNODE_FOREACH_RE(rn
, re
) {
2124 if (rib_route_match_ctx(re
, ctx
, false /*!update*/))
2128 /* No match? Nothing we can do */
2132 "%s(%u:%u):%pRN Unable to process dplane notification: no entry for type %s",
2133 VRF_LOGNAME(vrf
), dplane_ctx_get_vrf(ctx
),
2134 dplane_ctx_get_table(ctx
), rn
,
2135 zebra_route_string(dplane_ctx_get_type(ctx
)));
2140 /* Ensure we clear the QUEUED flag */
2141 if (!zrouter
.asic_offloaded
)
2142 UNSET_FLAG(re
->status
, ROUTE_ENTRY_QUEUED
);
2144 /* Is this a notification that ... matters? We mostly care about
2145 * the route that is currently selected for installation; we may also
2146 * get an un-install notification, and handle that too.
2148 if (re
!= dest
->selected_fib
) {
2150 * If we need to, clean up after a delete that was part of
2151 * an update operation.
2154 for (ALL_NEXTHOPS_PTR(dplane_ctx_get_ng(ctx
), nexthop
)) {
2155 if (CHECK_FLAG(nexthop
->flags
, NEXTHOP_FLAG_FIB
))
2159 /* If no nexthops or none installed, ensure that this re
2160 * gets its 'installed' flag cleared.
2162 if (end_count
== 0) {
2163 if (CHECK_FLAG(re
->status
, ROUTE_ENTRY_INSTALLED
))
2164 UNSET_FLAG(re
->status
, ROUTE_ENTRY_INSTALLED
);
2167 "%s(%u:%u):%pRN dplane notif, uninstalled type %s route",
2169 dplane_ctx_get_vrf(ctx
),
2170 dplane_ctx_get_table(ctx
), rn
,
2172 dplane_ctx_get_type(ctx
)));
2174 /* At least report on the event. */
2177 "%s(%u:%u):%pRN dplane notif, but type %s not selected_fib",
2179 dplane_ctx_get_vrf(ctx
),
2180 dplane_ctx_get_table(ctx
), rn
,
2182 dplane_ctx_get_type(ctx
)));
2187 /* We'll want to determine whether the installation status of the
2188 * route has changed: we'll check the status before processing,
2189 * and then again if there's been a change.
2193 if (CHECK_FLAG(re
->status
, ROUTE_ENTRY_INSTALLED
))
2194 start_count
= rib_count_installed_nh(re
);
2196 /* Update zebra's nexthop FIB flags based on the context struct's
2199 fib_changed
= rib_update_re_from_ctx(re
, rn
, ctx
);
2204 "%s(%u:%u):%pRN dplane notification: rib_update returns FALSE",
2205 VRF_LOGNAME(vrf
), dplane_ctx_get_vrf(ctx
),
2206 dplane_ctx_get_table(ctx
), rn
);
2210 * Perform follow-up work if the actual status of the prefix
2213 end_count
= rib_count_installed_nh(re
);
2215 /* Various fib transitions: changed nexthops; from installed to
2216 * not-installed; or not-installed to installed.
2218 if (start_count
> 0 && end_count
> 0) {
2221 "%s(%u:%u):%pRN applied nexthop changes from dplane notification",
2222 VRF_LOGNAME(vrf
), dplane_ctx_get_vrf(ctx
),
2223 dplane_ctx_get_table(ctx
), rn
);
2225 /* Changed nexthops - update kernel/others */
2226 dplane_route_notif_update(rn
, re
,
2227 DPLANE_OP_ROUTE_UPDATE
, ctx
);
2229 } else if (start_count
== 0 && end_count
> 0) {
2232 "%s(%u:%u):%pRN installed transition from dplane notification",
2233 VRF_LOGNAME(vrf
), dplane_ctx_get_vrf(ctx
),
2234 dplane_ctx_get_table(ctx
), rn
);
2236 /* We expect this to be the selected route, so we want
2237 * to tell others about this transition.
2239 SET_FLAG(re
->status
, ROUTE_ENTRY_INSTALLED
);
2241 /* Changed nexthops - update kernel/others */
2242 dplane_route_notif_update(rn
, re
, DPLANE_OP_ROUTE_UPDATE
, ctx
);
2244 /* Redistribute, lsp, and nht update */
2245 redistribute_update(rn
, re
, NULL
);
2247 } else if (start_count
> 0 && end_count
== 0) {
2250 "%s(%u:%u):%pRN un-installed transition from dplane notification",
2251 VRF_LOGNAME(vrf
), dplane_ctx_get_vrf(ctx
),
2252 dplane_ctx_get_table(ctx
), rn
);
2254 /* Transition from _something_ installed to _nothing_
2257 /* We expect this to be the selected route, so we want
2258 * to tell others about this transistion.
2260 UNSET_FLAG(re
->status
, ROUTE_ENTRY_INSTALLED
);
2262 /* Changed nexthops - update kernel/others */
2263 dplane_route_notif_update(rn
, re
, DPLANE_OP_ROUTE_DELETE
, ctx
);
2265 /* Redistribute, lsp, and nht update */
2266 redistribute_delete(rn
, re
, NULL
);
2269 /* Make any changes visible for lsp and nexthop-tracking processing */
2270 zebra_rib_evaluate_rn_nexthops(rn
, zebra_router_get_next_sequence(),
2273 zebra_rib_evaluate_mpls(rn
);
2277 route_unlock_node(rn
);
2279 /* Return context to dataplane module */
2280 dplane_ctx_fini(&ctx
);
2284 * Process a node from the EVPN/VXLAN subqueue.
2286 static void process_subq_evpn(struct listnode
*lnode
)
2288 struct wq_evpn_wrapper
*w
;
2290 /* In general, the list node points to a wrapper object
2291 * holding the info necessary to make some update.
2293 w
= listgetdata(lnode
);
2297 if (w
->type
== WQ_EVPN_WRAPPER_TYPE_VRFROUTE
) {
2299 zebra_vxlan_evpn_vrf_route_add(w
->vrf_id
, &w
->macaddr
,
2300 &w
->ip
, &w
->prefix
);
2302 zebra_vxlan_evpn_vrf_route_del(w
->vrf_id
, &w
->ip
,
2304 } else if (w
->type
== WQ_EVPN_WRAPPER_TYPE_REM_ES
) {
2306 zebra_evpn_remote_es_add(&w
->esi
, w
->ip
.ipaddr_v4
,
2307 w
->esr_rxed
, w
->df_alg
,
2310 zebra_evpn_remote_es_del(&w
->esi
, w
->ip
.ipaddr_v4
);
2311 } else if (w
->type
== WQ_EVPN_WRAPPER_TYPE_REM_MACIP
) {
2312 uint16_t ipa_len
= 0;
2314 if (w
->ip
.ipa_type
== IPADDR_V4
)
2315 ipa_len
= IPV4_MAX_BYTELEN
;
2316 else if (w
->ip
.ipa_type
== IPADDR_V6
)
2317 ipa_len
= IPV6_MAX_BYTELEN
;
2320 zebra_evpn_rem_macip_add(w
->vni
, &w
->macaddr
, ipa_len
,
2321 &w
->ip
, w
->flags
, w
->seq
,
2322 w
->vtep_ip
, &w
->esi
);
2324 zebra_evpn_rem_macip_del(w
->vni
, &w
->macaddr
, ipa_len
,
2325 &w
->ip
, w
->vtep_ip
);
2326 } else if (w
->type
== WQ_EVPN_WRAPPER_TYPE_REM_VTEP
) {
2328 zebra_vxlan_remote_vtep_add(w
->vrf_id
, w
->vni
,
2329 w
->vtep_ip
, w
->flags
);
2331 zebra_vxlan_remote_vtep_del(w
->vrf_id
, w
->vni
,
2336 XFREE(MTYPE_WQ_WRAPPER
, w
);
2340 * Process the nexthop-group workqueue subqueue
2342 static void process_subq_nhg(struct listnode
*lnode
)
2344 struct nhg_ctx
*ctx
;
2345 struct nhg_hash_entry
*nhe
, *newnhe
;
2346 struct wq_nhg_wrapper
*w
;
2347 uint8_t qindex
= route_info
[ZEBRA_ROUTE_NHG
].meta_q_map
;
2349 w
= listgetdata(lnode
);
2354 /* Two types of object - an update from the local kernel, or
2355 * an nhg update from a daemon.
2357 if (w
->type
== WQ_NHG_WRAPPER_TYPE_CTX
) {
2360 if (IS_ZEBRA_DEBUG_RIB_DETAILED
)
2362 "NHG Context id=%u dequeued from sub-queue %u",
2366 /* Process nexthop group updates coming 'up' from the OS */
2367 nhg_ctx_process(ctx
);
2369 } else if (w
->type
== WQ_NHG_WRAPPER_TYPE_NHG
) {
2372 if (IS_ZEBRA_DEBUG_RIB_DETAILED
)
2373 zlog_debug("NHG %u dequeued from sub-queue %u",
2376 /* Process incoming nhg update, probably from a proto daemon */
2377 newnhe
= zebra_nhg_proto_add(nhe
->id
, nhe
->type
,
2379 nhe
->zapi_session
, &nhe
->nhg
, 0);
2381 /* Report error to daemon via ZAPI */
2383 zsend_nhg_notify(nhe
->type
, nhe
->zapi_instance
,
2384 nhe
->zapi_session
, nhe
->id
,
2385 ZAPI_NHG_FAIL_INSTALL
);
2387 /* Free temp nhe - we own that memory. */
2388 zebra_nhg_free(nhe
);
2391 XFREE(MTYPE_WQ_WRAPPER
, w
);
2394 static void process_subq_route(struct listnode
*lnode
, uint8_t qindex
)
2396 struct route_node
*rnode
= NULL
;
2397 rib_dest_t
*dest
= NULL
;
2398 struct zebra_vrf
*zvrf
= NULL
;
2400 rnode
= listgetdata(lnode
);
2401 dest
= rib_dest_from_rnode(rnode
);
2404 zvrf
= rib_dest_vrf(dest
);
2408 if (IS_ZEBRA_DEBUG_RIB_DETAILED
) {
2409 struct route_entry
*re
= NULL
;
2412 * rib_process may have freed the dest
2413 * as part of the garbage collection. Let's
2414 * prevent stupidity from happening.
2416 dest
= rib_dest_from_rnode(rnode
);
2418 re
= re_list_first(&dest
->routes
);
2420 zlog_debug("%s(%u:%u):%pRN rn %p dequeued from sub-queue %u",
2421 zvrf_name(zvrf
), zvrf_id(zvrf
), re
? re
->table
: 0,
2422 rnode
, rnode
, qindex
);
2426 UNSET_FLAG(rib_dest_from_rnode(rnode
)->flags
,
2427 RIB_ROUTE_QUEUED(qindex
));
2429 route_unlock_node(rnode
);
2433 * Examine the specified subqueue; process one entry and return 1 if
2434 * there is a node, return 0 otherwise.
2436 static unsigned int process_subq(struct list
*subq
, uint8_t qindex
)
2438 struct listnode
*lnode
= listhead(subq
);
2443 if (qindex
== META_QUEUE_EVPN
)
2444 process_subq_evpn(lnode
);
2445 else if (qindex
== route_info
[ZEBRA_ROUTE_NHG
].meta_q_map
)
2446 process_subq_nhg(lnode
);
2448 process_subq_route(lnode
, qindex
);
2450 list_delete_node(subq
, lnode
);
2455 /* Dispatch the meta queue by picking and processing the next node from
2456 * a non-empty sub-queue with lowest priority. wq is equal to zebra->ribq and
2457 * data is pointed to the meta queue structure.
2459 static wq_item_status
meta_queue_process(struct work_queue
*dummy
, void *data
)
2461 struct meta_queue
*mq
= data
;
2463 uint32_t queue_len
, queue_limit
;
2465 /* Ensure there's room for more dataplane updates */
2466 queue_limit
= dplane_get_in_queue_limit();
2467 queue_len
= dplane_get_in_queue_len();
2468 if (queue_len
> queue_limit
) {
2469 if (IS_ZEBRA_DEBUG_RIB_DETAILED
)
2470 zlog_debug("rib queue: dplane queue len %u, limit %u, retrying",
2471 queue_len
, queue_limit
);
2473 /* Ensure that the meta-queue is actually enqueued */
2474 if (work_queue_empty(zrouter
.ribq
))
2475 work_queue_add(zrouter
.ribq
, zrouter
.mq
);
2477 return WQ_QUEUE_BLOCKED
;
2480 for (i
= 0; i
< MQ_SIZE
; i
++)
2481 if (process_subq(mq
->subq
[i
], i
)) {
2485 return mq
->size
? WQ_REQUEUE
: WQ_SUCCESS
;
2490 * Look into the RN and queue it into the highest priority queue
2491 * at this point in time for processing.
2493 * We will enqueue a route node only once per invocation.
2495 * There are two possibilities here that should be kept in mind.
2496 * If the original invocation has not been pulled off for processing
2497 * yet, A subsuquent invocation can have a route entry with a better
2498 * meta queue index value and we can have a situation where
2499 * we might have the same node enqueued 2 times. Not necessarily
2500 * an optimal situation but it should be ok.
2502 * The other possibility is that the original invocation has not
2503 * been pulled off for processing yet, A subsusquent invocation
2504 * doesn't have a route_entry with a better meta-queue and the
2505 * original metaqueue index value will win and we'll end up with
2506 * the route node enqueued once.
2508 static int rib_meta_queue_add(struct meta_queue
*mq
, void *data
)
2510 struct route_node
*rn
= NULL
;
2511 struct route_entry
*re
= NULL
, *curr_re
= NULL
;
2512 uint8_t qindex
= MQ_SIZE
, curr_qindex
= MQ_SIZE
;
2514 rn
= (struct route_node
*)data
;
2516 RNODE_FOREACH_RE (rn
, curr_re
) {
2517 curr_qindex
= route_info
[curr_re
->type
].meta_q_map
;
2519 if (curr_qindex
<= qindex
) {
2521 qindex
= curr_qindex
;
2528 /* Invariant: at this point we always have rn->info set. */
2529 if (CHECK_FLAG(rib_dest_from_rnode(rn
)->flags
,
2530 RIB_ROUTE_QUEUED(qindex
))) {
2531 if (IS_ZEBRA_DEBUG_RIB_DETAILED
)
2532 rnode_debug(rn
, re
->vrf_id
,
2533 "rn %p is already queued in sub-queue %u",
2534 (void *)rn
, qindex
);
2538 SET_FLAG(rib_dest_from_rnode(rn
)->flags
, RIB_ROUTE_QUEUED(qindex
));
2539 listnode_add(mq
->subq
[qindex
], rn
);
2540 route_lock_node(rn
);
2543 if (IS_ZEBRA_DEBUG_RIB_DETAILED
)
2544 rnode_debug(rn
, re
->vrf_id
, "queued rn %p into sub-queue %u",
2545 (void *)rn
, qindex
);
2550 static int rib_meta_queue_nhg_ctx_add(struct meta_queue
*mq
, void *data
)
2552 struct nhg_ctx
*ctx
= NULL
;
2553 uint8_t qindex
= route_info
[ZEBRA_ROUTE_NHG
].meta_q_map
;
2554 struct wq_nhg_wrapper
*w
;
2556 ctx
= (struct nhg_ctx
*)data
;
2561 w
= XCALLOC(MTYPE_WQ_WRAPPER
, sizeof(struct wq_nhg_wrapper
));
2563 w
->type
= WQ_NHG_WRAPPER_TYPE_CTX
;
2566 listnode_add(mq
->subq
[qindex
], w
);
2569 if (IS_ZEBRA_DEBUG_RIB_DETAILED
)
2570 zlog_debug("NHG Context id=%u queued into sub-queue %u",
2576 static int rib_meta_queue_nhg_add(struct meta_queue
*mq
, void *data
)
2578 struct nhg_hash_entry
*nhe
= NULL
;
2579 uint8_t qindex
= route_info
[ZEBRA_ROUTE_NHG
].meta_q_map
;
2580 struct wq_nhg_wrapper
*w
;
2582 nhe
= (struct nhg_hash_entry
*)data
;
2587 w
= XCALLOC(MTYPE_WQ_WRAPPER
, sizeof(struct wq_nhg_wrapper
));
2589 w
->type
= WQ_NHG_WRAPPER_TYPE_NHG
;
2592 listnode_add(mq
->subq
[qindex
], w
);
2595 if (IS_ZEBRA_DEBUG_RIB_DETAILED
)
2596 zlog_debug("NHG id=%u queued into sub-queue %u",
2602 static int rib_meta_queue_evpn_add(struct meta_queue
*mq
, void *data
)
2604 listnode_add(mq
->subq
[META_QUEUE_EVPN
], data
);
2610 static int mq_add_handler(void *data
,
2611 int (*mq_add_func
)(struct meta_queue
*mq
, void *data
))
2613 if (zrouter
.ribq
== NULL
) {
2614 flog_err(EC_ZEBRA_WQ_NONEXISTENT
,
2615 "%s: work_queue does not exist!", __func__
);
2620 * The RIB queue should normally be either empty or holding the only
2621 * work_queue_item element. In the latter case this element would
2622 * hold a pointer to the meta queue structure, which must be used to
2623 * actually queue the route nodes to process. So create the MQ
2624 * holder, if necessary, then push the work into it in any case.
2625 * This semantics was introduced after 0.99.9 release.
2627 if (work_queue_empty(zrouter
.ribq
))
2628 work_queue_add(zrouter
.ribq
, zrouter
.mq
);
2630 return mq_add_func(zrouter
.mq
, data
);
2633 /* Add route_node to work queue and schedule processing */
2634 int rib_queue_add(struct route_node
*rn
)
2638 /* Pointless to queue a route_node with no RIB entries to add or remove
2640 if (!rnode_to_ribs(rn
)) {
2641 zlog_debug("%s: called for route_node (%p, %u) with no ribs",
2642 __func__
, (void *)rn
, route_node_get_lock_count(rn
));
2643 zlog_backtrace(LOG_DEBUG
);
2647 return mq_add_handler(rn
, rib_meta_queue_add
);
2651 * Enqueue incoming nhg info from OS for processing
2653 int rib_queue_nhg_ctx_add(struct nhg_ctx
*ctx
)
2657 return mq_add_handler(ctx
, rib_meta_queue_nhg_ctx_add
);
2661 * Enqueue incoming nhg from proto daemon for processing
2663 int rib_queue_nhe_add(struct nhg_hash_entry
*nhe
)
2668 return mq_add_handler(nhe
, rib_meta_queue_nhg_add
);
2672 * Enqueue evpn route for processing
2674 int zebra_rib_queue_evpn_route_add(vrf_id_t vrf_id
, const struct ethaddr
*rmac
,
2675 const struct ipaddr
*vtep_ip
,
2676 const struct prefix
*host_prefix
)
2678 struct wq_evpn_wrapper
*w
;
2680 w
= XCALLOC(MTYPE_WQ_WRAPPER
, sizeof(struct wq_evpn_wrapper
));
2682 w
->type
= WQ_EVPN_WRAPPER_TYPE_VRFROUTE
;
2687 w
->prefix
= *host_prefix
;
2689 if (IS_ZEBRA_DEBUG_RIB_DETAILED
)
2690 zlog_debug("%s: (%u)%pIA, host prefix %pFX enqueued", __func__
,
2691 vrf_id
, vtep_ip
, host_prefix
);
2693 return mq_add_handler(w
, rib_meta_queue_evpn_add
);
2696 int zebra_rib_queue_evpn_route_del(vrf_id_t vrf_id
,
2697 const struct ipaddr
*vtep_ip
,
2698 const struct prefix
*host_prefix
)
2700 struct wq_evpn_wrapper
*w
;
2702 w
= XCALLOC(MTYPE_WQ_WRAPPER
, sizeof(struct wq_evpn_wrapper
));
2704 w
->type
= WQ_EVPN_WRAPPER_TYPE_VRFROUTE
;
2708 w
->prefix
= *host_prefix
;
2710 if (IS_ZEBRA_DEBUG_RIB_DETAILED
)
2711 zlog_debug("%s: (%u)%pIA, host prefix %pFX enqueued", __func__
,
2712 vrf_id
, vtep_ip
, host_prefix
);
2714 return mq_add_handler(w
, rib_meta_queue_evpn_add
);
2717 /* Enqueue EVPN remote ES for processing */
2718 int zebra_rib_queue_evpn_rem_es_add(const esi_t
*esi
,
2719 const struct in_addr
*vtep_ip
,
2720 bool esr_rxed
, uint8_t df_alg
,
2723 struct wq_evpn_wrapper
*w
;
2724 char buf
[ESI_STR_LEN
];
2726 w
= XCALLOC(MTYPE_WQ_WRAPPER
, sizeof(struct wq_evpn_wrapper
));
2728 w
->type
= WQ_EVPN_WRAPPER_TYPE_REM_ES
;
2731 w
->ip
.ipa_type
= IPADDR_V4
;
2732 w
->ip
.ipaddr_v4
= *vtep_ip
;
2733 w
->esr_rxed
= esr_rxed
;
2735 w
->df_pref
= df_pref
;
2737 if (IS_ZEBRA_DEBUG_RIB_DETAILED
)
2738 zlog_debug("%s: vtep %pI4, esi %s enqueued", __func__
, vtep_ip
,
2739 esi_to_str(esi
, buf
, sizeof(buf
)));
2741 return mq_add_handler(w
, rib_meta_queue_evpn_add
);
2744 int zebra_rib_queue_evpn_rem_es_del(const esi_t
*esi
,
2745 const struct in_addr
*vtep_ip
)
2747 struct wq_evpn_wrapper
*w
;
2748 char buf
[ESI_STR_LEN
];
2750 w
= XCALLOC(MTYPE_WQ_WRAPPER
, sizeof(struct wq_evpn_wrapper
));
2752 w
->type
= WQ_EVPN_WRAPPER_TYPE_REM_ES
;
2755 w
->ip
.ipa_type
= IPADDR_V4
;
2756 w
->ip
.ipaddr_v4
= *vtep_ip
;
2758 if (IS_ZEBRA_DEBUG_RIB_DETAILED
) {
2759 if (memcmp(esi
, zero_esi
, sizeof(esi_t
)) != 0)
2760 esi_to_str(esi
, buf
, sizeof(buf
));
2762 strlcpy(buf
, "-", sizeof(buf
));
2764 zlog_debug("%s: vtep %pI4, esi %s enqueued", __func__
, vtep_ip
,
2768 return mq_add_handler(w
, rib_meta_queue_evpn_add
);
2772 * Enqueue EVPN remote macip update for processing
2774 int zebra_rib_queue_evpn_rem_macip_add(vni_t vni
, const struct ethaddr
*macaddr
,
2775 const struct ipaddr
*ipaddr
,
2776 uint8_t flags
, uint32_t seq
,
2777 struct in_addr vtep_ip
, const esi_t
*esi
)
2779 struct wq_evpn_wrapper
*w
;
2780 char buf
[ESI_STR_LEN
];
2782 w
= XCALLOC(MTYPE_WQ_WRAPPER
, sizeof(struct wq_evpn_wrapper
));
2784 w
->type
= WQ_EVPN_WRAPPER_TYPE_REM_MACIP
;
2787 w
->macaddr
= *macaddr
;
2791 w
->vtep_ip
= vtep_ip
;
2794 if (IS_ZEBRA_DEBUG_RIB_DETAILED
) {
2795 if (memcmp(esi
, zero_esi
, sizeof(esi_t
)) != 0)
2796 esi_to_str(esi
, buf
, sizeof(buf
));
2798 strlcpy(buf
, "-", sizeof(buf
));
2800 zlog_debug("%s: mac %pEA, vtep %pI4, esi %s enqueued", __func__
,
2801 macaddr
, &vtep_ip
, buf
);
2804 return mq_add_handler(w
, rib_meta_queue_evpn_add
);
2807 int zebra_rib_queue_evpn_rem_macip_del(vni_t vni
, const struct ethaddr
*macaddr
,
2808 const struct ipaddr
*ip
,
2809 struct in_addr vtep_ip
)
2811 struct wq_evpn_wrapper
*w
;
2813 w
= XCALLOC(MTYPE_WQ_WRAPPER
, sizeof(struct wq_evpn_wrapper
));
2815 w
->type
= WQ_EVPN_WRAPPER_TYPE_REM_MACIP
;
2818 w
->macaddr
= *macaddr
;
2820 w
->vtep_ip
= vtep_ip
;
2822 if (IS_ZEBRA_DEBUG_RIB_DETAILED
)
2823 zlog_debug("%s: mac %pEA, vtep %pI4 enqueued", __func__
,
2826 return mq_add_handler(w
, rib_meta_queue_evpn_add
);
2830 * Enqueue remote VTEP address for processing
2832 int zebra_rib_queue_evpn_rem_vtep_add(vrf_id_t vrf_id
, vni_t vni
,
2833 struct in_addr vtep_ip
, int flood_control
)
2835 struct wq_evpn_wrapper
*w
;
2837 w
= XCALLOC(MTYPE_WQ_WRAPPER
, sizeof(struct wq_evpn_wrapper
));
2839 w
->type
= WQ_EVPN_WRAPPER_TYPE_REM_VTEP
;
2843 w
->vtep_ip
= vtep_ip
;
2844 w
->flags
= flood_control
;
2846 if (IS_ZEBRA_DEBUG_RIB_DETAILED
)
2847 zlog_debug("%s: vrf %u, vtep %pI4 enqueued", __func__
, vrf_id
,
2850 return mq_add_handler(w
, rib_meta_queue_evpn_add
);
2853 int zebra_rib_queue_evpn_rem_vtep_del(vrf_id_t vrf_id
, vni_t vni
,
2854 struct in_addr vtep_ip
)
2856 struct wq_evpn_wrapper
*w
;
2858 w
= XCALLOC(MTYPE_WQ_WRAPPER
, sizeof(struct wq_evpn_wrapper
));
2860 w
->type
= WQ_EVPN_WRAPPER_TYPE_REM_VTEP
;
2864 w
->vtep_ip
= vtep_ip
;
2866 if (IS_ZEBRA_DEBUG_RIB_DETAILED
)
2867 zlog_debug("%s: vrf %u, vtep %pI4 enqueued", __func__
, vrf_id
,
2870 return mq_add_handler(w
, rib_meta_queue_evpn_add
);
2873 /* Clean up the EVPN meta-queue list */
2874 static void evpn_meta_queue_free(struct list
*l
)
2876 struct listnode
*node
;
2877 struct wq_evpn_wrapper
*w
;
2879 /* Free the node wrapper object, and the struct it wraps */
2880 while ((node
= listhead(l
)) != NULL
) {
2884 XFREE(MTYPE_WQ_WRAPPER
, w
);
2886 list_delete_node(l
, node
);
2890 /* Clean up the nhg meta-queue list */
2891 static void nhg_meta_queue_free(struct list
*l
)
2893 struct wq_nhg_wrapper
*w
;
2894 struct listnode
*node
;
2896 /* Free the node wrapper object, and the struct it wraps */
2897 while ((node
= listhead(l
)) != NULL
) {
2901 if (w
->type
== WQ_NHG_WRAPPER_TYPE_CTX
)
2902 nhg_ctx_free(&w
->u
.ctx
);
2903 else if (w
->type
== WQ_NHG_WRAPPER_TYPE_NHG
)
2904 zebra_nhg_free(w
->u
.nhe
);
2906 XFREE(MTYPE_WQ_WRAPPER
, w
);
2908 list_delete_node(l
, node
);
2912 /* Create new meta queue.
2913 A destructor function doesn't seem to be necessary here.
2915 static struct meta_queue
*meta_queue_new(void)
2917 struct meta_queue
*new;
2920 new = XCALLOC(MTYPE_WORK_QUEUE
, sizeof(struct meta_queue
));
2922 for (i
= 0; i
< MQ_SIZE
; i
++) {
2923 new->subq
[i
] = list_new();
2924 assert(new->subq
[i
]);
2930 void meta_queue_free(struct meta_queue
*mq
)
2934 for (i
= 0; i
< MQ_SIZE
; i
++) {
2935 /* Some subqueues may need cleanup - nhgs for example */
2936 if (i
== route_info
[ZEBRA_ROUTE_NHG
].meta_q_map
)
2937 nhg_meta_queue_free(mq
->subq
[i
]);
2938 else if (i
== META_QUEUE_EVPN
)
2939 evpn_meta_queue_free(mq
->subq
[i
]);
2941 list_delete(&mq
->subq
[i
]);
2944 XFREE(MTYPE_WORK_QUEUE
, mq
);
2947 void rib_meta_queue_free_vrf(struct meta_queue
*mq
, struct zebra_vrf
*zvrf
)
2949 vrf_id_t vrf_id
= zvrf
->vrf
->vrf_id
;
2952 for (i
= 0; i
< MQ_SIZE
; i
++) {
2953 struct listnode
*lnode
, *nnode
;
2957 for (ALL_LIST_ELEMENTS(mq
->subq
[i
], lnode
, nnode
, data
)) {
2960 if (i
== META_QUEUE_EVPN
) {
2961 struct wq_evpn_wrapper
*w
= data
;
2963 if (w
->vrf_id
== vrf_id
) {
2964 XFREE(MTYPE_WQ_WRAPPER
, w
);
2968 route_info
[ZEBRA_ROUTE_NHG
].meta_q_map
) {
2969 struct wq_nhg_wrapper
*w
= data
;
2971 if (w
->type
== WQ_NHG_WRAPPER_TYPE_CTX
&&
2972 w
->u
.ctx
->vrf_id
== vrf_id
) {
2973 nhg_ctx_free(&w
->u
.ctx
);
2974 XFREE(MTYPE_WQ_WRAPPER
, w
);
2976 } else if (w
->type
== WQ_NHG_WRAPPER_TYPE_NHG
&&
2977 w
->u
.nhe
->vrf_id
== vrf_id
) {
2978 zebra_nhg_free(w
->u
.nhe
);
2979 XFREE(MTYPE_WQ_WRAPPER
, w
);
2983 struct route_node
*rnode
= data
;
2984 rib_dest_t
*dest
= rib_dest_from_rnode(rnode
);
2986 if (dest
&& rib_dest_vrf(dest
) == zvrf
) {
2987 route_unlock_node(rnode
);
2993 list_delete_node(mq
->subq
[i
], lnode
);
3000 /* initialise zebra rib work queue */
3001 static void rib_queue_init(void)
3003 if (!(zrouter
.ribq
= work_queue_new(zrouter
.master
,
3004 "route_node processing"))) {
3005 flog_err(EC_ZEBRA_WQ_NONEXISTENT
,
3006 "%s: could not initialise work queue!", __func__
);
3010 /* fill in the work queue spec */
3011 zrouter
.ribq
->spec
.workfunc
= &meta_queue_process
;
3012 zrouter
.ribq
->spec
.errorfunc
= NULL
;
3013 zrouter
.ribq
->spec
.completion_func
= NULL
;
3014 /* XXX: TODO: These should be runtime configurable via vty */
3015 zrouter
.ribq
->spec
.max_retries
= 3;
3016 zrouter
.ribq
->spec
.hold
= ZEBRA_RIB_PROCESS_HOLD_TIME
;
3017 zrouter
.ribq
->spec
.retry
= ZEBRA_RIB_PROCESS_RETRY_TIME
;
3019 if (!(zrouter
.mq
= meta_queue_new())) {
3020 flog_err(EC_ZEBRA_WQ_NONEXISTENT
,
3021 "%s: could not initialise meta queue!", __func__
);
3027 rib_dest_t
*zebra_rib_create_dest(struct route_node
*rn
)
3031 dest
= XCALLOC(MTYPE_RIB_DEST
, sizeof(rib_dest_t
));
3032 rnh_list_init(&dest
->nht
);
3033 re_list_init(&dest
->routes
);
3034 route_lock_node(rn
); /* rn route table reference */
3041 /* RIB updates are processed via a queue of pointers to route_nodes.
3043 * The queue length is bounded by the maximal size of the routing table,
3044 * as a route_node will not be requeued, if already queued.
3046 * REs are submitted via rib_addnode or rib_delnode which set minimal
3047 * state, or static_install_route (when an existing RE is updated)
3048 * and then submit route_node to queue for best-path selection later.
3049 * Order of add/delete state changes are preserved for any given RE.
3051 * Deleted REs are reaped during best-path selection.
3054 * |-> rib_link or unset ROUTE_ENTRY_REMOVE |->Update kernel with
3055 * |-------->| | best RE, if required
3057 * static_install->|->rib_addqueue...... -> rib_process
3059 * |-------->| |-> rib_unlink
3060 * |-> set ROUTE_ENTRY_REMOVE |
3061 * rib_delnode (RE freed)
3063 * The 'info' pointer of a route_node points to a rib_dest_t
3064 * ('dest'). Queueing state for a route_node is kept on the dest. The
3065 * dest is created on-demand by rib_link() and is kept around at least
3066 * as long as there are ribs hanging off it (@see rib_gc_dest()).
3068 * Refcounting (aka "locking" throughout the Zebra and FRR code):
3070 * - route_nodes: refcounted by:
3071 * - dest attached to route_node:
3072 * - managed by: rib_link/rib_gc_dest
3073 * - route_node processing queue
3074 * - managed by: rib_addqueue, rib_process.
3078 /* Add RE to head of the route node. */
3079 static void rib_link(struct route_node
*rn
, struct route_entry
*re
, int process
)
3083 const char *rmap_name
;
3087 dest
= rib_dest_from_rnode(rn
);
3089 if (IS_ZEBRA_DEBUG_RIB_DETAILED
)
3090 rnode_debug(rn
, re
->vrf_id
, "rn %p adding dest", rn
);
3092 dest
= zebra_rib_create_dest(rn
);
3095 re_list_add_head(&dest
->routes
, re
);
3097 afi
= (rn
->p
.family
== AF_INET
)
3099 : (rn
->p
.family
== AF_INET6
) ? AFI_IP6
: AFI_MAX
;
3100 if (is_zebra_import_table_enabled(afi
, re
->vrf_id
, re
->table
)) {
3101 struct zebra_vrf
*zvrf
= zebra_vrf_lookup_by_id(re
->vrf_id
);
3103 rmap_name
= zebra_get_import_table_route_map(afi
, re
->table
);
3104 zebra_add_import_table_entry(zvrf
, rn
, re
, rmap_name
);
3109 static void rib_addnode(struct route_node
*rn
,
3110 struct route_entry
*re
, int process
)
3112 /* RE node has been un-removed before route-node is processed.
3113 * route_node must hence already be on the queue for processing..
3115 if (CHECK_FLAG(re
->status
, ROUTE_ENTRY_REMOVED
)) {
3116 if (IS_ZEBRA_DEBUG_RIB
)
3117 rnode_debug(rn
, re
->vrf_id
, "rn %p, un-removed re %p",
3118 (void *)rn
, (void *)re
);
3120 UNSET_FLAG(re
->status
, ROUTE_ENTRY_REMOVED
);
3123 rib_link(rn
, re
, process
);
3126 static void rib_re_nhg_free(struct route_entry
*re
)
3128 if (re
->nhe
&& re
->nhe_id
) {
3129 assert(re
->nhe
->id
== re
->nhe_id
);
3130 route_entry_update_nhe(re
, NULL
);
3131 } else if (re
->nhe
&& re
->nhe
->nhg
.nexthop
)
3132 nexthops_free(re
->nhe
->nhg
.nexthop
);
3134 nexthops_free(re
->fib_ng
.nexthop
);
3140 * Detach a rib structure from a route_node.
3142 * Note that a call to rib_unlink() should be followed by a call to
3143 * rib_gc_dest() at some point. This allows a rib_dest_t that is no
3144 * longer required to be deleted.
3146 void rib_unlink(struct route_node
*rn
, struct route_entry
*re
)
3152 if (IS_ZEBRA_DEBUG_RIB
)
3153 rnode_debug(rn
, re
->vrf_id
, "rn %p, re %p", (void *)rn
,
3156 dest
= rib_dest_from_rnode(rn
);
3158 re_list_del(&dest
->routes
, re
);
3160 if (dest
->selected_fib
== re
)
3161 dest
->selected_fib
= NULL
;
3163 rib_re_nhg_free(re
);
3165 zapi_re_opaque_free(re
->opaque
);
3167 XFREE(MTYPE_RE
, re
);
3170 void rib_delnode(struct route_node
*rn
, struct route_entry
*re
)
3174 if (IS_ZEBRA_DEBUG_RIB
)
3175 rnode_debug(rn
, re
->vrf_id
, "rn %p, re %p, removing",
3176 (void *)rn
, (void *)re
);
3177 SET_FLAG(re
->status
, ROUTE_ENTRY_REMOVED
);
3179 afi
= (rn
->p
.family
== AF_INET
)
3181 : (rn
->p
.family
== AF_INET6
) ? AFI_IP6
: AFI_MAX
;
3182 if (is_zebra_import_table_enabled(afi
, re
->vrf_id
, re
->table
)) {
3183 struct zebra_vrf
*zvrf
= zebra_vrf_lookup_by_id(re
->vrf_id
);
3185 zebra_del_import_table_entry(zvrf
, rn
, re
);
3186 /* Just clean up if non main table */
3187 if (IS_ZEBRA_DEBUG_RIB
)
3188 zlog_debug("%s(%u):%pRN: Freeing route rn %p, re %p (%s)",
3189 vrf_id_to_name(re
->vrf_id
), re
->vrf_id
, rn
,
3190 rn
, re
, zebra_route_string(re
->type
));
3199 * Helper that debugs a single nexthop within a route-entry
3201 static void _route_entry_dump_nh(const struct route_entry
*re
,
3202 const char *straddr
,
3203 const struct nexthop
*nexthop
)
3205 char nhname
[PREFIX_STRLEN
];
3206 char backup_str
[50];
3209 char label_str
[MPLS_LABEL_STRLEN
];
3211 struct interface
*ifp
;
3212 struct vrf
*vrf
= vrf_lookup_by_id(nexthop
->vrf_id
);
3214 switch (nexthop
->type
) {
3215 case NEXTHOP_TYPE_BLACKHOLE
:
3216 snprintf(nhname
, sizeof(nhname
), "Blackhole");
3218 case NEXTHOP_TYPE_IFINDEX
:
3219 ifp
= if_lookup_by_index(nexthop
->ifindex
, nexthop
->vrf_id
);
3220 snprintf(nhname
, sizeof(nhname
), "%s",
3221 ifp
? ifp
->name
: "Unknown");
3223 case NEXTHOP_TYPE_IPV4
:
3225 case NEXTHOP_TYPE_IPV4_IFINDEX
:
3226 inet_ntop(AF_INET
, &nexthop
->gate
, nhname
, INET6_ADDRSTRLEN
);
3228 case NEXTHOP_TYPE_IPV6
:
3229 case NEXTHOP_TYPE_IPV6_IFINDEX
:
3230 inet_ntop(AF_INET6
, &nexthop
->gate
, nhname
, INET6_ADDRSTRLEN
);
3235 label_str
[0] = '\0';
3236 if (nexthop
->nh_label
&& nexthop
->nh_label
->num_labels
> 0) {
3237 mpls_label2str(nexthop
->nh_label
->num_labels
,
3238 nexthop
->nh_label
->label
, label_str
,
3239 sizeof(label_str
), 0 /*pretty*/);
3240 strlcat(label_str
, ", ", sizeof(label_str
));
3243 backup_str
[0] = '\0';
3244 if (CHECK_FLAG(nexthop
->flags
, NEXTHOP_FLAG_HAS_BACKUP
)) {
3245 snprintf(backup_str
, sizeof(backup_str
), "backup ");
3246 for (i
= 0; i
< nexthop
->backup_num
; i
++) {
3247 snprintf(temp_str
, sizeof(temp_str
), "%d, ",
3248 nexthop
->backup_idx
[i
]);
3249 strlcat(backup_str
, temp_str
, sizeof(backup_str
));
3254 if (nexthop
->weight
)
3255 snprintf(wgt_str
, sizeof(wgt_str
), "wgt %d,", nexthop
->weight
);
3257 zlog_debug("%s: %s %s[%u] %svrf %s(%u) %s%s with flags %s%s%s%s%s%s%s%s",
3258 straddr
, (nexthop
->rparent
? " NH" : "NH"), nhname
,
3259 nexthop
->ifindex
, label_str
, vrf
? vrf
->name
: "Unknown",
3261 wgt_str
, backup_str
,
3262 (CHECK_FLAG(nexthop
->flags
, NEXTHOP_FLAG_ACTIVE
)
3265 (CHECK_FLAG(re
->status
, ROUTE_ENTRY_INSTALLED
)
3268 (CHECK_FLAG(nexthop
->flags
, NEXTHOP_FLAG_RECURSIVE
)
3271 (CHECK_FLAG(nexthop
->flags
, NEXTHOP_FLAG_ONLINK
)
3274 (CHECK_FLAG(nexthop
->flags
, NEXTHOP_FLAG_DUPLICATE
)
3277 (CHECK_FLAG(nexthop
->flags
, NEXTHOP_FLAG_RNH_FILTERED
)
3278 ? "FILTERED " : ""),
3279 (CHECK_FLAG(nexthop
->flags
, NEXTHOP_FLAG_HAS_BACKUP
)
3281 (CHECK_FLAG(nexthop
->flags
, NEXTHOP_FLAG_SRTE
)
3286 /* This function dumps the contents of a given RE entry into
3287 * standard debug log. Calling function name and IP prefix in
3288 * question are passed as 1st and 2nd arguments.
3290 void _route_entry_dump(const char *func
, union prefixconstptr pp
,
3291 union prefixconstptr src_pp
,
3292 const struct route_entry
*re
)
3294 const struct prefix
*src_p
= src_pp
.p
;
3295 bool is_srcdst
= src_p
&& src_p
->prefixlen
;
3296 char straddr
[PREFIX_STRLEN
];
3297 char srcaddr
[PREFIX_STRLEN
];
3298 char flags_buf
[128];
3299 char status_buf
[128];
3300 struct nexthop
*nexthop
;
3301 struct vrf
*vrf
= vrf_lookup_by_id(re
->vrf_id
);
3302 struct nexthop_group
*nhg
;
3304 prefix2str(pp
, straddr
, sizeof(straddr
));
3306 zlog_debug("%s: dumping RE entry %p for %s%s%s vrf %s(%u)", func
,
3307 (const void *)re
, straddr
,
3308 is_srcdst
? " from " : "",
3309 is_srcdst
? prefix2str(src_pp
, srcaddr
, sizeof(srcaddr
))
3311 VRF_LOGNAME(vrf
), re
->vrf_id
);
3312 zlog_debug("%s: uptime == %lu, type == %u, instance == %d, table == %d",
3313 straddr
, (unsigned long)re
->uptime
, re
->type
, re
->instance
,
3316 "%s: metric == %u, mtu == %u, distance == %u, flags == %sstatus == %s",
3317 straddr
, re
->metric
, re
->mtu
, re
->distance
,
3318 zclient_dump_route_flags(re
->flags
, flags_buf
,
3320 _dump_re_status(re
, status_buf
, sizeof(status_buf
)));
3321 zlog_debug("%s: nexthop_num == %u, nexthop_active_num == %u", straddr
,
3322 nexthop_group_nexthop_num(&(re
->nhe
->nhg
)),
3323 nexthop_group_active_nexthop_num(&(re
->nhe
->nhg
)));
3326 for (ALL_NEXTHOPS(re
->nhe
->nhg
, nexthop
))
3327 _route_entry_dump_nh(re
, straddr
, nexthop
);
3329 if (zebra_nhg_get_backup_nhg(re
->nhe
)) {
3330 zlog_debug("%s: backup nexthops:", straddr
);
3332 nhg
= zebra_nhg_get_backup_nhg(re
->nhe
);
3333 for (ALL_NEXTHOPS_PTR(nhg
, nexthop
))
3334 _route_entry_dump_nh(re
, straddr
, nexthop
);
3337 zlog_debug("%s: dump complete", straddr
);
3341 * Internal route-add implementation; there are a couple of different public
3342 * signatures. Callers in this path are responsible for the memory they
3343 * allocate: if they allocate a nexthop_group or backup nexthop info, they
3344 * must free those objects. If this returns < 0, an error has occurred and the
3345 * route_entry 're' has not been captured; the caller should free that also.
3351 int rib_add_multipath_nhe(afi_t afi
, safi_t safi
, struct prefix
*p
,
3352 struct prefix_ipv6
*src_p
, struct route_entry
*re
,
3353 struct nhg_hash_entry
*re_nhe
, bool startup
)
3355 struct nhg_hash_entry
*nhe
= NULL
;
3356 struct route_table
*table
;
3357 struct route_node
*rn
;
3358 struct route_entry
*same
= NULL
, *first_same
= NULL
;
3366 assert(!src_p
|| !src_p
->prefixlen
|| afi
== AFI_IP6
);
3369 table
= zebra_vrf_get_table_with_table_id(afi
, safi
, re
->vrf_id
,
3374 if (re
->nhe_id
> 0) {
3375 nhe
= zebra_nhg_lookup_id(re
->nhe_id
);
3379 EC_ZEBRA_TABLE_LOOKUP_FAILED
,
3380 "Zebra failed to find the nexthop hash entry for id=%u in a route entry",
3386 /* Lookup nhe from route information */
3387 nhe
= zebra_nhg_rib_find_nhe(re_nhe
, afi
);
3389 char buf2
[PREFIX_STRLEN
] = "";
3392 EC_ZEBRA_TABLE_LOOKUP_FAILED
,
3393 "Zebra failed to find or create a nexthop hash entry for %pFX%s%s",
3394 p
, src_p
? " from " : "",
3395 src_p
? prefix2str(src_p
, buf2
, sizeof(buf2
))
3403 * Attach the re to the nhe's nexthop group.
3405 * TODO: This will need to change when we start getting IDs from upper
3406 * level protocols, as the refcnt might be wrong, since it checks
3407 * if old_id != new_id.
3409 route_entry_update_nhe(re
, nhe
);
3411 /* Make it sure prefixlen is applied to the prefix. */
3414 apply_mask_ipv6(src_p
);
3416 /* Set default distance by route type. */
3417 if (re
->distance
== 0)
3418 re
->distance
= route_distance(re
->type
);
3420 /* Lookup route node.*/
3421 rn
= srcdest_rnode_get(table
, p
, src_p
);
3424 * If same type of route are installed, treat it as a implicit
3425 * withdraw. If the user has specified the No route replace semantics
3426 * for the install don't do a route replace.
3428 RNODE_FOREACH_RE (rn
, same
) {
3429 if (CHECK_FLAG(same
->status
, ROUTE_ENTRY_REMOVED
)) {
3434 /* Compare various route_entry properties */
3435 if (rib_compare_routes(re
, same
)) {
3438 if (first_same
== NULL
)
3446 (re
->flags
& ZEBRA_FLAG_SELFROUTE
) && zrouter
.asic_offloaded
) {
3448 if (IS_ZEBRA_DEBUG_RIB
)
3449 zlog_debug("prefix: %pRN is a self route where we do not have an entry for it. Dropping this update, it's useless", rn
);
3451 * We are not on startup, this is a self route
3452 * and we have asic offload. Which means
3453 * we are getting a callback for a entry
3454 * that was already deleted to the kernel
3455 * but an earlier response was just handed
3456 * back. Drop it on the floor
3458 rib_re_nhg_free(re
);
3460 XFREE(MTYPE_RE
, re
);
3465 /* If this route is kernel/connected route, notify the dataplane. */
3466 if (RIB_SYSTEM_ROUTE(re
)) {
3467 /* Notify dataplane */
3468 dplane_sys_route_add(rn
, re
);
3471 /* Link new re to node.*/
3472 if (IS_ZEBRA_DEBUG_RIB
) {
3473 rnode_debug(rn
, re
->vrf_id
,
3474 "Inserting route rn %p, re %p (%s) existing %p, same_count %d",
3475 rn
, re
, zebra_route_string(re
->type
), same
,
3478 if (IS_ZEBRA_DEBUG_RIB_DETAILED
)
3479 route_entry_dump(p
, src_p
, re
);
3482 SET_FLAG(re
->status
, ROUTE_ENTRY_CHANGED
);
3483 rib_addnode(rn
, re
, 1);
3485 /* Free implicit route.*/
3488 rib_delnode(rn
, same
);
3491 /* See if we can remove some RE entries that are queued for
3492 * removal, but won't be considered in rib processing.
3494 dest
= rib_dest_from_rnode(rn
);
3495 RNODE_FOREACH_RE_SAFE (rn
, re
, same
) {
3496 if (CHECK_FLAG(re
->status
, ROUTE_ENTRY_REMOVED
)) {
3497 /* If the route was used earlier, must retain it. */
3498 if (dest
&& re
== dest
->selected_fib
)
3501 if (IS_ZEBRA_DEBUG_RIB
)
3502 rnode_debug(rn
, re
->vrf_id
, "rn %p, removing unneeded re %p",
3509 route_unlock_node(rn
);
3514 * Add a single route.
3516 int rib_add_multipath(afi_t afi
, safi_t safi
, struct prefix
*p
,
3517 struct prefix_ipv6
*src_p
, struct route_entry
*re
,
3518 struct nexthop_group
*ng
, bool startup
)
3521 struct nhg_hash_entry nhe
;
3526 /* We either need nexthop(s) or an existing nexthop id */
3527 if (ng
== NULL
&& re
->nhe_id
== 0)
3531 * Use a temporary nhe to convey info to the common/main api.
3533 zebra_nhe_init(&nhe
, afi
, (ng
? ng
->nexthop
: NULL
));
3535 nhe
.nhg
.nexthop
= ng
->nexthop
;
3536 else if (re
->nhe_id
> 0)
3537 nhe
.id
= re
->nhe_id
;
3539 ret
= rib_add_multipath_nhe(afi
, safi
, p
, src_p
, re
, &nhe
, startup
);
3541 /* In this path, the callers expect memory to be freed. */
3542 nexthop_group_delete(&ng
);
3544 /* In error cases, free the route also */
3546 XFREE(MTYPE_RE
, re
);
3551 void rib_delete(afi_t afi
, safi_t safi
, vrf_id_t vrf_id
, int type
,
3552 unsigned short instance
, uint32_t flags
, struct prefix
*p
,
3553 struct prefix_ipv6
*src_p
, const struct nexthop
*nh
,
3554 uint32_t nhe_id
, uint32_t table_id
, uint32_t metric
,
3555 uint8_t distance
, bool fromkernel
)
3557 struct route_table
*table
;
3558 struct route_node
*rn
;
3559 struct route_entry
*re
;
3560 struct route_entry
*fib
= NULL
;
3561 struct route_entry
*same
= NULL
;
3562 struct nexthop
*rtnh
;
3563 char buf2
[INET6_ADDRSTRLEN
];
3566 assert(!src_p
|| !src_p
->prefixlen
|| afi
== AFI_IP6
);
3569 table
= zebra_vrf_lookup_table_with_table_id(afi
, safi
, vrf_id
,
3577 apply_mask_ipv6(src_p
);
3579 /* Lookup route node. */
3580 rn
= srcdest_rnode_lookup(table
, p
, src_p
);
3582 if (IS_ZEBRA_DEBUG_RIB
) {
3583 char src_buf
[PREFIX_STRLEN
];
3584 struct vrf
*vrf
= vrf_lookup_by_id(vrf_id
);
3586 if (src_p
&& src_p
->prefixlen
)
3587 prefix2str(src_p
, src_buf
, sizeof(src_buf
));
3591 zlog_debug("%s[%d]:%pRN%s%s doesn't exist in rib",
3592 vrf
->name
, table_id
, rn
,
3593 (src_buf
[0] != '\0') ? " from " : "",
3599 dest
= rib_dest_from_rnode(rn
);
3600 fib
= dest
->selected_fib
;
3602 /* Lookup same type route. */
3603 RNODE_FOREACH_RE (rn
, re
) {
3604 if (CHECK_FLAG(re
->status
, ROUTE_ENTRY_REMOVED
))
3607 if (re
->type
!= type
)
3609 if (re
->instance
!= instance
)
3611 if (CHECK_FLAG(re
->flags
, ZEBRA_FLAG_RR_USE_DISTANCE
) &&
3612 distance
!= re
->distance
)
3615 if (re
->type
== ZEBRA_ROUTE_KERNEL
&& re
->metric
!= metric
)
3617 if (re
->type
== ZEBRA_ROUTE_CONNECT
&&
3618 (rtnh
= re
->nhe
->nhg
.nexthop
)
3619 && rtnh
->type
== NEXTHOP_TYPE_IFINDEX
&& nh
) {
3620 if (rtnh
->ifindex
!= nh
->ifindex
)
3626 /* Make sure that the route found has the same gateway. */
3627 if (nhe_id
&& re
->nhe_id
== nhe_id
) {
3636 for (ALL_NEXTHOPS(re
->nhe
->nhg
, rtnh
)) {
3638 * No guarantee all kernel send nh with labels
3641 if (nexthop_same_no_labels(rtnh
, nh
)) {
3650 /* If same type of route can't be found and this message is from
3654 * In the past(HA!) we could get here because
3655 * we were receiving a route delete from the
3656 * kernel and we're not marking the proto
3657 * as coming from it's appropriate originator.
3658 * Now that we are properly noticing the fact
3659 * that the kernel has deleted our route we
3660 * are not going to get called in this path
3661 * I am going to leave this here because
3662 * this might still work this way on non-linux
3663 * platforms as well as some weird state I have
3664 * not properly thought of yet.
3665 * If we can show that this code path is
3666 * dead then we can remove it.
3668 if (fib
&& CHECK_FLAG(flags
, ZEBRA_FLAG_SELFROUTE
)) {
3669 if (IS_ZEBRA_DEBUG_RIB
) {
3670 rnode_debug(rn
, vrf_id
,
3671 "rn %p, re %p (%s) was deleted from kernel, adding",
3673 zebra_route_string(fib
->type
));
3676 || CHECK_FLAG(dest
->flags
, RIB_ROUTE_ANY_QUEUED
)) {
3677 UNSET_FLAG(fib
->status
, ROUTE_ENTRY_INSTALLED
);
3679 for (rtnh
= fib
->nhe
->nhg
.nexthop
; rtnh
;
3681 UNSET_FLAG(rtnh
->flags
,
3685 * This is a non FRR route
3686 * as such we should mark
3689 dest
->selected_fib
= NULL
;
3691 /* This means someone else, other than Zebra,
3693 * a Zebra router from the kernel. We will add
3695 rib_install_kernel(rn
, fib
, NULL
);
3698 if (IS_ZEBRA_DEBUG_RIB
) {
3702 "via %s ifindex %d type %d doesn't exist in rib",
3703 inet_ntop(afi2family(afi
),
3710 "type %d doesn't exist in rib",
3713 route_unlock_node(rn
);
3719 if (fromkernel
&& CHECK_FLAG(flags
, ZEBRA_FLAG_SELFROUTE
)
3721 rib_install_kernel(rn
, same
, NULL
);
3722 route_unlock_node(rn
);
3727 /* Special handling for IPv4 or IPv6 routes sourced from
3728 * EVPN - the nexthop (and associated MAC) need to be
3729 * uninstalled if no more refs.
3731 if (CHECK_FLAG(flags
, ZEBRA_FLAG_EVPN_ROUTE
)) {
3732 struct nexthop
*tmp_nh
;
3734 for (ALL_NEXTHOPS(re
->nhe
->nhg
, tmp_nh
)) {
3735 struct ipaddr vtep_ip
;
3737 memset(&vtep_ip
, 0, sizeof(struct ipaddr
));
3738 if (afi
== AFI_IP
) {
3739 vtep_ip
.ipa_type
= IPADDR_V4
;
3740 memcpy(&(vtep_ip
.ipaddr_v4
),
3741 &(tmp_nh
->gate
.ipv4
),
3742 sizeof(struct in_addr
));
3744 vtep_ip
.ipa_type
= IPADDR_V6
;
3745 memcpy(&(vtep_ip
.ipaddr_v6
),
3746 &(tmp_nh
->gate
.ipv6
),
3747 sizeof(struct in6_addr
));
3749 zebra_rib_queue_evpn_route_del(re
->vrf_id
,
3754 /* Notify dplane if system route changes */
3755 if (RIB_SYSTEM_ROUTE(re
))
3756 dplane_sys_route_del(rn
, same
);
3758 rib_delnode(rn
, same
);
3761 route_unlock_node(rn
);
3766 int rib_add(afi_t afi
, safi_t safi
, vrf_id_t vrf_id
, int type
,
3767 unsigned short instance
, uint32_t flags
, struct prefix
*p
,
3768 struct prefix_ipv6
*src_p
, const struct nexthop
*nh
,
3769 uint32_t nhe_id
, uint32_t table_id
, uint32_t metric
, uint32_t mtu
,
3770 uint8_t distance
, route_tag_t tag
, bool startup
)
3772 struct route_entry
*re
= NULL
;
3773 struct nexthop
*nexthop
= NULL
;
3774 struct nexthop_group
*ng
= NULL
;
3776 /* Allocate new route_entry structure. */
3777 re
= XCALLOC(MTYPE_RE
, sizeof(struct route_entry
));
3779 re
->instance
= instance
;
3780 re
->distance
= distance
;
3782 re
->metric
= metric
;
3784 re
->table
= table_id
;
3785 re
->vrf_id
= vrf_id
;
3786 re
->uptime
= monotime(NULL
);
3788 re
->nhe_id
= nhe_id
;
3790 /* If the owner of the route supplies a shared nexthop-group id,
3791 * we'll use that. Otherwise, pass the nexthop along directly.
3794 ng
= nexthop_group_new();
3797 nexthop
= nexthop_new();
3799 nexthop_group_add_sorted(ng
, nexthop
);
3802 return rib_add_multipath(afi
, safi
, p
, src_p
, re
, ng
, startup
);
3805 static const char *rib_update_event2str(enum rib_update_event event
)
3807 const char *ret
= "UNKNOWN";
3810 case RIB_UPDATE_KERNEL
:
3811 ret
= "RIB_UPDATE_KERNEL";
3813 case RIB_UPDATE_RMAP_CHANGE
:
3814 ret
= "RIB_UPDATE_RMAP_CHANGE";
3816 case RIB_UPDATE_OTHER
:
3817 ret
= "RIB_UPDATE_OTHER";
3819 case RIB_UPDATE_MAX
:
3827 /* Schedule route nodes to be processed if they match the type */
3828 static void rib_update_route_node(struct route_node
*rn
, int type
)
3830 struct route_entry
*re
, *next
;
3831 bool re_changed
= false;
3833 RNODE_FOREACH_RE_SAFE (rn
, re
, next
) {
3834 if (type
== ZEBRA_ROUTE_ALL
|| type
== re
->type
) {
3835 SET_FLAG(re
->status
, ROUTE_ENTRY_CHANGED
);
3844 /* Schedule routes of a particular table (address-family) based on event. */
3845 void rib_update_table(struct route_table
*table
, enum rib_update_event event
,
3848 struct route_node
*rn
;
3850 if (IS_ZEBRA_DEBUG_EVENT
) {
3851 struct zebra_vrf
*zvrf
;
3855 ? ((struct rib_table_info
*)table
->info
)->zvrf
3857 vrf
= zvrf
? zvrf
->vrf
: NULL
;
3859 zlog_debug("%s: %s VRF %s Table %u event %s Route type: %s", __func__
,
3860 table
->info
? afi2str(
3861 ((struct rib_table_info
*)table
->info
)->afi
)
3863 VRF_LOGNAME(vrf
), zvrf
? zvrf
->table_id
: 0,
3864 rib_update_event2str(event
), zebra_route_string(rtype
));
3867 /* Walk all routes and queue for processing, if appropriate for
3868 * the trigger event.
3870 for (rn
= route_top(table
); rn
; rn
= srcdest_route_next(rn
)) {
3872 * If we are looking at a route node and the node
3873 * has already been queued we don't
3874 * need to queue it up again
3877 && CHECK_FLAG(rib_dest_from_rnode(rn
)->flags
,
3878 RIB_ROUTE_ANY_QUEUED
))
3882 case RIB_UPDATE_KERNEL
:
3883 rib_update_route_node(rn
, ZEBRA_ROUTE_KERNEL
);
3885 case RIB_UPDATE_RMAP_CHANGE
:
3886 case RIB_UPDATE_OTHER
:
3887 rib_update_route_node(rn
, rtype
);
3895 static void rib_update_handle_vrf(vrf_id_t vrf_id
, enum rib_update_event event
,
3898 struct route_table
*table
;
3900 if (IS_ZEBRA_DEBUG_EVENT
)
3901 zlog_debug("%s: Handling VRF %s event %s", __func__
,
3902 vrf_id_to_name(vrf_id
), rib_update_event2str(event
));
3904 /* Process routes of interested address-families. */
3905 table
= zebra_vrf_table(AFI_IP
, SAFI_UNICAST
, vrf_id
);
3907 rib_update_table(table
, event
, rtype
);
3909 table
= zebra_vrf_table(AFI_IP6
, SAFI_UNICAST
, vrf_id
);
3911 rib_update_table(table
, event
, rtype
);
3914 static void rib_update_handle_vrf_all(enum rib_update_event event
, int rtype
)
3916 struct zebra_router_table
*zrt
;
3918 if (IS_ZEBRA_DEBUG_EVENT
)
3919 zlog_debug("%s: Handling VRF (ALL) event %s", __func__
,
3920 rib_update_event2str(event
));
3922 /* Just iterate over all the route tables, rather than vrf lookups */
3923 RB_FOREACH (zrt
, zebra_router_table_head
, &zrouter
.tables
)
3924 rib_update_table(zrt
->table
, event
, rtype
);
3927 struct rib_update_ctx
{
3928 enum rib_update_event event
;
3933 static struct rib_update_ctx
*rib_update_ctx_init(vrf_id_t vrf_id
,
3934 enum rib_update_event event
)
3936 struct rib_update_ctx
*ctx
;
3938 ctx
= XCALLOC(MTYPE_RIB_UPDATE_CTX
, sizeof(struct rib_update_ctx
));
3941 ctx
->vrf_id
= vrf_id
;
3946 static void rib_update_ctx_fini(struct rib_update_ctx
**ctx
)
3948 XFREE(MTYPE_RIB_UPDATE_CTX
, *ctx
);
3951 static int rib_update_handler(struct thread
*thread
)
3953 struct rib_update_ctx
*ctx
;
3955 ctx
= THREAD_ARG(thread
);
3958 rib_update_handle_vrf_all(ctx
->event
, ZEBRA_ROUTE_ALL
);
3960 rib_update_handle_vrf(ctx
->vrf_id
, ctx
->event
, ZEBRA_ROUTE_ALL
);
3962 rib_update_ctx_fini(&ctx
);
3968 * Thread list to ensure we don't schedule a ton of events
3969 * if interfaces are flapping for instance.
3971 static struct thread
*t_rib_update_threads
[RIB_UPDATE_MAX
];
3973 /* Schedule a RIB update event for all vrfs */
3974 void rib_update(enum rib_update_event event
)
3976 struct rib_update_ctx
*ctx
;
3978 if (thread_is_scheduled(t_rib_update_threads
[event
]))
3981 ctx
= rib_update_ctx_init(0, event
);
3982 ctx
->vrf_all
= true;
3984 thread_add_event(zrouter
.master
, rib_update_handler
, ctx
, 0,
3985 &t_rib_update_threads
[event
]);
3987 if (IS_ZEBRA_DEBUG_EVENT
)
3988 zlog_debug("%s: Scheduled VRF (ALL), event %s", __func__
,
3989 rib_update_event2str(event
));
3992 /* Delete self installed routes after zebra is relaunched. */
3993 void rib_sweep_table(struct route_table
*table
)
3995 struct route_node
*rn
;
3996 struct route_entry
*re
;
3997 struct route_entry
*next
;
3998 struct nexthop
*nexthop
;
4003 if (IS_ZEBRA_DEBUG_RIB
)
4004 zlog_debug("%s: starting", __func__
);
4006 for (rn
= route_top(table
); rn
; rn
= srcdest_route_next(rn
)) {
4007 RNODE_FOREACH_RE_SAFE (rn
, re
, next
) {
4009 if (IS_ZEBRA_DEBUG_RIB
)
4010 route_entry_dump(&rn
->p
, NULL
, re
);
4012 if (CHECK_FLAG(re
->status
, ROUTE_ENTRY_REMOVED
))
4015 if (!CHECK_FLAG(re
->flags
, ZEBRA_FLAG_SELFROUTE
))
4019 * If routes are older than startup_time then
4020 * we know we read them in from the kernel.
4021 * As such we can safely remove them.
4023 if (zrouter
.startup_time
< re
->uptime
)
4027 * So we are starting up and have received
4028 * routes from the kernel that we have installed
4029 * from a previous run of zebra but not cleaned
4030 * up ( say a kill -9 )
4031 * But since we haven't actually installed
4032 * them yet( we received them from the kernel )
4033 * we don't think they are active.
4034 * So let's pretend they are active to actually
4036 * In all honesty I'm not sure if we should
4037 * mark them as active when we receive them
4038 * This is startup only so probably ok.
4040 * If we ever decide to move rib_sweep_table
4041 * to a different spot (ie startup )
4042 * this decision needs to be revisited
4044 SET_FLAG(re
->status
, ROUTE_ENTRY_INSTALLED
);
4045 for (ALL_NEXTHOPS(re
->nhe
->nhg
, nexthop
))
4046 SET_FLAG(nexthop
->flags
, NEXTHOP_FLAG_FIB
);
4048 rib_uninstall_kernel(rn
, re
);
4049 rib_delnode(rn
, re
);
4053 if (IS_ZEBRA_DEBUG_RIB
)
4054 zlog_debug("%s: ends", __func__
);
4057 /* Sweep all RIB tables. */
4058 int rib_sweep_route(struct thread
*t
)
4061 struct zebra_vrf
*zvrf
;
4063 RB_FOREACH (vrf
, vrf_id_head
, &vrfs_by_id
) {
4064 if ((zvrf
= vrf
->info
) == NULL
)
4067 rib_sweep_table(zvrf
->table
[AFI_IP
][SAFI_UNICAST
]);
4068 rib_sweep_table(zvrf
->table
[AFI_IP6
][SAFI_UNICAST
]);
4071 zebra_router_sweep_route();
4072 zebra_router_sweep_nhgs();
4077 /* Remove specific by protocol routes from 'table'. */
4078 unsigned long rib_score_proto_table(uint8_t proto
, unsigned short instance
,
4079 struct route_table
*table
)
4081 struct route_node
*rn
;
4082 struct route_entry
*re
;
4083 struct route_entry
*next
;
4084 unsigned long n
= 0;
4087 for (rn
= route_top(table
); rn
; rn
= srcdest_route_next(rn
))
4088 RNODE_FOREACH_RE_SAFE (rn
, re
, next
) {
4089 if (CHECK_FLAG(re
->status
, ROUTE_ENTRY_REMOVED
))
4091 if (re
->type
== proto
4092 && re
->instance
== instance
) {
4093 rib_delnode(rn
, re
);
4100 /* Remove specific by protocol routes. */
4101 unsigned long rib_score_proto(uint8_t proto
, unsigned short instance
)
4104 struct zebra_vrf
*zvrf
;
4105 struct other_route_table
*ort
;
4106 unsigned long cnt
= 0;
4108 RB_FOREACH (vrf
, vrf_id_head
, &vrfs_by_id
) {
4113 cnt
+= rib_score_proto_table(proto
, instance
,
4114 zvrf
->table
[AFI_IP
][SAFI_UNICAST
])
4115 + rib_score_proto_table(
4117 zvrf
->table
[AFI_IP6
][SAFI_UNICAST
]);
4119 frr_each(otable
, &zvrf
->other_tables
, ort
) cnt
+=
4120 rib_score_proto_table(proto
, instance
, ort
->table
);
4126 /* Close RIB and clean up kernel routes. */
4127 void rib_close_table(struct route_table
*table
)
4129 struct route_node
*rn
;
4130 struct rib_table_info
*info
;
4136 info
= route_table_get_info(table
);
4138 for (rn
= route_top(table
); rn
; rn
= srcdest_route_next(rn
)) {
4139 dest
= rib_dest_from_rnode(rn
);
4141 if (dest
&& dest
->selected_fib
) {
4142 if (info
->safi
== SAFI_UNICAST
)
4143 hook_call(rib_update
, rn
, NULL
);
4145 rib_uninstall_kernel(rn
, dest
->selected_fib
);
4146 dest
->selected_fib
= NULL
;
4152 * Handler for async dataplane results after a pseudowire installation
4154 static int handle_pw_result(struct zebra_dplane_ctx
*ctx
)
4156 struct zebra_pw
*pw
;
4157 struct zebra_vrf
*vrf
;
4159 /* The pseudowire code assumes success - we act on an error
4160 * result for installation attempts here.
4162 if (dplane_ctx_get_op(ctx
) != DPLANE_OP_PW_INSTALL
)
4165 if (dplane_ctx_get_status(ctx
) != ZEBRA_DPLANE_REQUEST_SUCCESS
) {
4166 vrf
= zebra_vrf_lookup_by_id(dplane_ctx_get_vrf(ctx
));
4167 pw
= zebra_pw_find(vrf
, dplane_ctx_get_ifname(ctx
));
4169 zebra_pw_install_failure(pw
,
4170 dplane_ctx_get_pw_status(ctx
));
4174 dplane_ctx_fini(&ctx
);
4181 * Handle results from the dataplane system. Dequeue update context
4182 * structs, dispatch to appropriate internal handlers.
4184 static int rib_process_dplane_results(struct thread
*thread
)
4186 struct zebra_dplane_ctx
*ctx
;
4187 struct dplane_ctx_q ctxlist
;
4188 bool shut_p
= false;
4190 /* Dequeue a list of completed updates with one lock/unlock cycle */
4193 TAILQ_INIT(&ctxlist
);
4195 /* Take lock controlling queue of results */
4196 frr_with_mutex(&dplane_mutex
) {
4197 /* Dequeue list of context structs */
4198 dplane_ctx_list_append(&ctxlist
, &rib_dplane_q
);
4201 /* Dequeue context block */
4202 ctx
= dplane_ctx_dequeue(&ctxlist
);
4204 /* If we've emptied the results queue, we're done */
4208 /* If zebra is shutting down, avoid processing results,
4209 * just drain the results queue.
4211 shut_p
= atomic_load_explicit(&zrouter
.in_shutdown
,
4212 memory_order_relaxed
);
4215 dplane_ctx_fini(&ctx
);
4217 ctx
= dplane_ctx_dequeue(&ctxlist
);
4223 #ifdef HAVE_SCRIPTING
4224 char *script_name
= frrscript_names_get_script_name(
4225 ZEBRA_ON_RIB_PROCESS_HOOK_CALL
);
4228 struct frrscript
*fs
;
4231 fs
= frrscript_new(script_name
);
4233 ret
= frrscript_load(
4234 fs
, ZEBRA_ON_RIB_PROCESS_HOOK_CALL
,
4237 #endif /* HAVE_SCRIPTING */
4241 #ifdef HAVE_SCRIPTING
4244 ZEBRA_ON_RIB_PROCESS_HOOK_CALL
,
4246 #endif /* HAVE_SCRIPTING */
4248 switch (dplane_ctx_get_op(ctx
)) {
4249 case DPLANE_OP_ROUTE_INSTALL
:
4250 case DPLANE_OP_ROUTE_UPDATE
:
4251 case DPLANE_OP_ROUTE_DELETE
:
4253 /* Bit of special case for route updates
4254 * that were generated by async notifications:
4255 * we don't want to continue processing these
4258 if (dplane_ctx_get_notif_provider(ctx
) == 0)
4259 rib_process_result(ctx
);
4261 dplane_ctx_fini(&ctx
);
4265 case DPLANE_OP_ROUTE_NOTIFY
:
4266 rib_process_dplane_notify(ctx
);
4269 case DPLANE_OP_NH_INSTALL
:
4270 case DPLANE_OP_NH_UPDATE
:
4271 case DPLANE_OP_NH_DELETE
:
4272 zebra_nhg_dplane_result(ctx
);
4275 case DPLANE_OP_LSP_INSTALL
:
4276 case DPLANE_OP_LSP_UPDATE
:
4277 case DPLANE_OP_LSP_DELETE
:
4279 /* Bit of special case for LSP updates
4280 * that were generated by async notifications:
4281 * we don't want to continue processing these.
4283 if (dplane_ctx_get_notif_provider(ctx
) == 0)
4284 zebra_mpls_lsp_dplane_result(ctx
);
4286 dplane_ctx_fini(&ctx
);
4290 case DPLANE_OP_LSP_NOTIFY
:
4291 zebra_mpls_process_dplane_notify(ctx
);
4294 case DPLANE_OP_PW_INSTALL
:
4295 case DPLANE_OP_PW_UNINSTALL
:
4296 handle_pw_result(ctx
);
4299 case DPLANE_OP_SYS_ROUTE_ADD
:
4300 case DPLANE_OP_SYS_ROUTE_DELETE
:
4301 /* No further processing in zebra for these. */
4302 dplane_ctx_fini(&ctx
);
4305 case DPLANE_OP_MAC_INSTALL
:
4306 case DPLANE_OP_MAC_DELETE
:
4307 zebra_vxlan_handle_result(ctx
);
4310 case DPLANE_OP_RULE_ADD
:
4311 case DPLANE_OP_RULE_DELETE
:
4312 case DPLANE_OP_RULE_UPDATE
:
4313 case DPLANE_OP_IPTABLE_ADD
:
4314 case DPLANE_OP_IPTABLE_DELETE
:
4315 case DPLANE_OP_IPSET_ADD
:
4316 case DPLANE_OP_IPSET_DELETE
:
4317 case DPLANE_OP_IPSET_ENTRY_ADD
:
4318 case DPLANE_OP_IPSET_ENTRY_DELETE
:
4319 zebra_pbr_dplane_result(ctx
);
4322 case DPLANE_OP_INTF_ADDR_ADD
:
4323 case DPLANE_OP_INTF_ADDR_DEL
:
4324 zebra_if_addr_update_ctx(ctx
);
4327 /* Some op codes not handled here */
4328 case DPLANE_OP_ADDR_INSTALL
:
4329 case DPLANE_OP_ADDR_UNINSTALL
:
4330 case DPLANE_OP_NEIGH_INSTALL
:
4331 case DPLANE_OP_NEIGH_UPDATE
:
4332 case DPLANE_OP_NEIGH_DELETE
:
4333 case DPLANE_OP_NEIGH_IP_INSTALL
:
4334 case DPLANE_OP_NEIGH_IP_DELETE
:
4335 case DPLANE_OP_VTEP_ADD
:
4336 case DPLANE_OP_VTEP_DELETE
:
4337 case DPLANE_OP_NEIGH_DISCOVER
:
4338 case DPLANE_OP_BR_PORT_UPDATE
:
4339 case DPLANE_OP_NEIGH_TABLE_UPDATE
:
4340 case DPLANE_OP_GRE_SET
:
4341 case DPLANE_OP_NONE
:
4342 /* Don't expect this: just return the struct? */
4343 dplane_ctx_fini(&ctx
);
4346 } /* Dispatch by op code */
4348 ctx
= dplane_ctx_dequeue(&ctxlist
);
4357 * Results are returned from the dataplane subsystem, in the context of
4358 * the dataplane pthread. We enqueue the results here for processing by
4359 * the main thread later.
4361 static int rib_dplane_results(struct dplane_ctx_q
*ctxlist
)
4363 /* Take lock controlling queue of results */
4364 frr_with_mutex(&dplane_mutex
) {
4365 /* Enqueue context blocks */
4366 dplane_ctx_list_append(&rib_dplane_q
, ctxlist
);
4369 /* Ensure event is signalled to zebra main pthread */
4370 thread_add_event(zrouter
.master
, rib_process_dplane_results
, NULL
, 0,
4377 * Ensure there are no empty slots in the route_info array.
4378 * Every route type in zebra should be present there.
4380 static void check_route_info(void)
4382 int len
= array_size(route_info
);
4385 * ZEBRA_ROUTE_SYSTEM is special cased since
4386 * its key is 0 anyway.
4388 * ZEBRA_ROUTE_ALL is also ignored.
4390 for (int i
= 0; i
< len
; i
++) {
4391 if (i
== ZEBRA_ROUTE_SYSTEM
|| i
== ZEBRA_ROUTE_ALL
)
4393 assert(route_info
[i
].key
);
4394 assert(route_info
[i
].meta_q_map
< MQ_SIZE
);
4398 /* Routing information base initialize. */
4405 /* Init dataplane, and register for results */
4406 pthread_mutex_init(&dplane_mutex
, NULL
);
4407 TAILQ_INIT(&rib_dplane_q
);
4408 zebra_dplane_init(rib_dplane_results
);
4414 * Get the first vrf id that is greater than the given vrf id if any.
4416 * Returns true if a vrf id was found, false otherwise.
4418 static inline int vrf_id_get_next(vrf_id_t vrf_id
, vrf_id_t
*next_id_p
)
4422 vrf
= vrf_lookup_by_id(vrf_id
);
4424 vrf
= RB_NEXT(vrf_id_head
, vrf
);
4426 *next_id_p
= vrf
->vrf_id
;
4435 * rib_tables_iter_next
4437 * Returns the next table in the iteration.
4439 struct route_table
*rib_tables_iter_next(rib_tables_iter_t
*iter
)
4441 struct route_table
*table
;
4444 * Array that helps us go over all AFI/SAFI combinations via one
4447 static const struct {
4451 {AFI_IP
, SAFI_UNICAST
}, {AFI_IP
, SAFI_MULTICAST
},
4452 {AFI_IP
, SAFI_LABELED_UNICAST
}, {AFI_IP6
, SAFI_UNICAST
},
4453 {AFI_IP6
, SAFI_MULTICAST
}, {AFI_IP6
, SAFI_LABELED_UNICAST
},
4458 switch (iter
->state
) {
4460 case RIB_TABLES_ITER_S_INIT
:
4461 iter
->vrf_id
= VRF_DEFAULT
;
4462 iter
->afi_safi_ix
= -1;
4466 case RIB_TABLES_ITER_S_ITERATING
:
4467 iter
->afi_safi_ix
++;
4470 while (iter
->afi_safi_ix
4471 < (int)array_size(afi_safis
)) {
4472 table
= zebra_vrf_table(
4473 afi_safis
[iter
->afi_safi_ix
].afi
,
4474 afi_safis
[iter
->afi_safi_ix
].safi
,
4479 iter
->afi_safi_ix
++;
4483 * Found another table in this vrf.
4489 * Done with all tables in the current vrf, go to the
4493 if (!vrf_id_get_next(iter
->vrf_id
, &iter
->vrf_id
))
4496 iter
->afi_safi_ix
= 0;
4501 case RIB_TABLES_ITER_S_DONE
:
4506 iter
->state
= RIB_TABLES_ITER_S_ITERATING
;
4508 iter
->state
= RIB_TABLES_ITER_S_DONE
;