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
27 #include "zebra_memory.h"
31 #include "sockunion.h"
34 #include "workqueue.h"
40 #include "srcdest_table.h"
42 #include "zebra/rib.h"
44 #include "zebra/zebra_ns.h"
45 #include "zebra/zserv.h"
46 #include "zebra/zebra_vrf.h"
47 #include "zebra/redistribute.h"
48 #include "zebra/zebra_routemap.h"
49 #include "zebra/debug.h"
50 #include "zebra/zebra_rnh.h"
51 #include "zebra/interface.h"
52 #include "zebra/connected.h"
53 #include "zebra/zebra_vxlan.h"
55 DEFINE_HOOK(rib_update
, (struct route_node
* rn
, const char *reason
),
58 /* Should we allow non Quagga processes to delete our routes */
59 extern int allow_delete
;
61 /* Each route type's string and default distance value. */
65 } route_info
[ZEBRA_ROUTE_MAX
] = {
66 [ZEBRA_ROUTE_SYSTEM
] = {ZEBRA_ROUTE_SYSTEM
, 0},
67 [ZEBRA_ROUTE_KERNEL
] = {ZEBRA_ROUTE_KERNEL
, 0},
68 [ZEBRA_ROUTE_CONNECT
] = {ZEBRA_ROUTE_CONNECT
, 0},
69 [ZEBRA_ROUTE_STATIC
] = {ZEBRA_ROUTE_STATIC
, 1},
70 [ZEBRA_ROUTE_RIP
] = {ZEBRA_ROUTE_RIP
, 120},
71 [ZEBRA_ROUTE_RIPNG
] = {ZEBRA_ROUTE_RIPNG
, 120},
72 [ZEBRA_ROUTE_OSPF
] = {ZEBRA_ROUTE_OSPF
, 110},
73 [ZEBRA_ROUTE_OSPF6
] = {ZEBRA_ROUTE_OSPF6
, 110},
74 [ZEBRA_ROUTE_ISIS
] = {ZEBRA_ROUTE_ISIS
, 115},
75 [ZEBRA_ROUTE_BGP
] = {ZEBRA_ROUTE_BGP
, 20 /* IBGP is 200. */},
76 [ZEBRA_ROUTE_PIM
] = {ZEBRA_ROUTE_PIM
, 255},
77 [ZEBRA_ROUTE_EIGRP
] = {ZEBRA_ROUTE_EIGRP
, 90},
78 [ZEBRA_ROUTE_NHRP
] = {ZEBRA_ROUTE_NHRP
, 10},
79 [ZEBRA_ROUTE_HSLS
] = {ZEBRA_ROUTE_HSLS
, 255},
80 [ZEBRA_ROUTE_OLSR
] = {ZEBRA_ROUTE_OLSR
, 255},
81 [ZEBRA_ROUTE_TABLE
] = {ZEBRA_ROUTE_TABLE
, 150},
82 [ZEBRA_ROUTE_LDP
] = {ZEBRA_ROUTE_LDP
, 150},
83 [ZEBRA_ROUTE_VNC
] = {ZEBRA_ROUTE_VNC
, 20},
84 [ZEBRA_ROUTE_VNC_DIRECT
] = {ZEBRA_ROUTE_VNC_DIRECT
, 20},
85 [ZEBRA_ROUTE_VNC_DIRECT_RH
] = {ZEBRA_ROUTE_VNC_DIRECT_RH
, 20},
86 [ZEBRA_ROUTE_BGP_DIRECT
] = {ZEBRA_ROUTE_BGP_DIRECT
, 20},
87 [ZEBRA_ROUTE_BGP_DIRECT_EXT
] = {ZEBRA_ROUTE_BGP_DIRECT_EXT
, 20},
88 [ZEBRA_ROUTE_BABEL
] = {ZEBRA_ROUTE_BABEL
, 100},
90 /* no entry/default: 150 */
93 /* RPF lookup behaviour */
94 static enum multicast_mode ipv4_multicast_mode
= MCAST_NO_CONFIG
;
97 static void __attribute__((format(printf
, 5, 6)))
98 _rnode_zlog(const char *_func
, vrf_id_t vrf_id
, struct route_node
*rn
,
99 int priority
, const char *msgfmt
, ...)
101 char buf
[SRCDEST2STR_BUFFER
+ sizeof(" (MRIB)")];
105 va_start(ap
, msgfmt
);
106 vsnprintf(msgbuf
, sizeof(msgbuf
), msgfmt
, ap
);
110 rib_table_info_t
*info
= srcdest_rnode_table_info(rn
);
111 srcdest_rnode2str(rn
, buf
, sizeof(buf
));
113 if (info
->safi
== SAFI_MULTICAST
)
114 strcat(buf
, " (MRIB)");
116 snprintf(buf
, sizeof(buf
), "{(route_node *) NULL}");
119 zlog(priority
, "%s: %d:%s: %s", _func
, vrf_id
, buf
, msgbuf
);
122 #define rnode_debug(node, vrf_id, ...) \
123 _rnode_zlog(__func__, vrf_id, node, LOG_DEBUG, __VA_ARGS__)
124 #define rnode_info(node, ...) \
125 _rnode_zlog(__func__, vrf_id, node, LOG_INFO, __VA_ARGS__)
127 uint8_t route_distance(int type
)
131 if ((unsigned)type
>= array_size(route_info
))
134 distance
= route_info
[type
].distance
;
139 int is_zebra_valid_kernel_table(u_int32_t table_id
)
141 if ((table_id
> ZEBRA_KERNEL_TABLE_MAX
))
145 if ((table_id
== RT_TABLE_UNSPEC
) || (table_id
== RT_TABLE_LOCAL
)
146 || (table_id
== RT_TABLE_COMPAT
))
153 int is_zebra_main_routing_table(u_int32_t table_id
)
155 if ((table_id
== RT_TABLE_MAIN
)
156 || (table_id
== zebrad
.rtm_table_default
))
161 int zebra_check_addr(struct prefix
*p
)
163 if (p
->family
== AF_INET
) {
166 addr
= p
->u
.prefix4
.s_addr
;
169 if (IPV4_NET127(addr
) || IN_CLASSD(addr
)
170 || IPV4_LINKLOCAL(addr
))
173 if (p
->family
== AF_INET6
) {
174 if (IN6_IS_ADDR_LOOPBACK(&p
->u
.prefix6
))
176 if (IN6_IS_ADDR_LINKLOCAL(&p
->u
.prefix6
))
182 /* Add nexthop to the end of a rib node's nexthop list */
183 void route_entry_nexthop_add(struct route_entry
*re
, struct nexthop
*nexthop
)
185 nexthop_add(&re
->nexthop
, nexthop
);
191 * copy_nexthop - copy a nexthop to the rib structure.
193 void route_entry_copy_nexthops(struct route_entry
*re
, struct nexthop
*nh
)
195 assert(!re
->nexthop
);
196 copy_nexthops(&re
->nexthop
, nh
, NULL
);
197 for (struct nexthop
*nexthop
= nh
; nexthop
; nexthop
= nexthop
->next
)
201 /* Delete specified nexthop from the list. */
202 void route_entry_nexthop_delete(struct route_entry
*re
, struct nexthop
*nexthop
)
205 nexthop
->next
->prev
= nexthop
->prev
;
207 nexthop
->prev
->next
= nexthop
->next
;
209 re
->nexthop
= nexthop
->next
;
214 struct nexthop
*route_entry_nexthop_ifindex_add(struct route_entry
*re
,
217 struct nexthop
*nexthop
;
219 nexthop
= nexthop_new();
220 nexthop
->type
= NEXTHOP_TYPE_IFINDEX
;
221 nexthop
->ifindex
= ifindex
;
223 route_entry_nexthop_add(re
, nexthop
);
228 struct nexthop
*route_entry_nexthop_ipv4_add(struct route_entry
*re
,
229 struct in_addr
*ipv4
,
232 struct nexthop
*nexthop
;
234 nexthop
= nexthop_new();
235 nexthop
->type
= NEXTHOP_TYPE_IPV4
;
236 nexthop
->gate
.ipv4
= *ipv4
;
238 nexthop
->src
.ipv4
= *src
;
240 route_entry_nexthop_add(re
, nexthop
);
245 struct nexthop
*route_entry_nexthop_ipv4_ifindex_add(struct route_entry
*re
,
246 struct in_addr
*ipv4
,
250 struct nexthop
*nexthop
;
251 struct interface
*ifp
;
253 nexthop
= nexthop_new();
254 nexthop
->type
= NEXTHOP_TYPE_IPV4_IFINDEX
;
255 nexthop
->gate
.ipv4
= *ipv4
;
257 nexthop
->src
.ipv4
= *src
;
258 nexthop
->ifindex
= ifindex
;
259 ifp
= if_lookup_by_index(nexthop
->ifindex
, re
->nh_vrf_id
);
260 /*Pending: need to think if null ifp here is ok during bootup?
261 There was a crash because ifp here was coming to be NULL */
263 if (connected_is_unnumbered(ifp
) ||
264 CHECK_FLAG(re
->flags
, ZEBRA_FLAG_EVPN_ROUTE
)) {
265 SET_FLAG(nexthop
->flags
, NEXTHOP_FLAG_ONLINK
);
268 route_entry_nexthop_add(re
, nexthop
);
273 struct nexthop
*route_entry_nexthop_ipv6_add(struct route_entry
*re
,
274 struct in6_addr
*ipv6
)
276 struct nexthop
*nexthop
;
278 nexthop
= nexthop_new();
279 nexthop
->type
= NEXTHOP_TYPE_IPV6
;
280 nexthop
->gate
.ipv6
= *ipv6
;
282 route_entry_nexthop_add(re
, nexthop
);
287 struct nexthop
*route_entry_nexthop_ipv6_ifindex_add(struct route_entry
*re
,
288 struct in6_addr
*ipv6
,
291 struct nexthop
*nexthop
;
293 nexthop
= nexthop_new();
294 nexthop
->type
= NEXTHOP_TYPE_IPV6_IFINDEX
;
295 nexthop
->gate
.ipv6
= *ipv6
;
296 nexthop
->ifindex
= ifindex
;
298 route_entry_nexthop_add(re
, nexthop
);
303 struct nexthop
*route_entry_nexthop_blackhole_add(struct route_entry
*re
,
304 enum blackhole_type bh_type
)
306 struct nexthop
*nexthop
;
308 nexthop
= nexthop_new();
309 nexthop
->type
= NEXTHOP_TYPE_BLACKHOLE
;
310 nexthop
->bh_type
= bh_type
;
312 route_entry_nexthop_add(re
, nexthop
);
317 static void nexthop_set_resolved(afi_t afi
, struct nexthop
*newhop
,
318 struct nexthop
*nexthop
)
320 struct nexthop
*resolved_hop
;
322 resolved_hop
= nexthop_new();
323 SET_FLAG(resolved_hop
->flags
, NEXTHOP_FLAG_ACTIVE
);
325 switch (newhop
->type
) {
326 case NEXTHOP_TYPE_IPV4
:
327 case NEXTHOP_TYPE_IPV4_IFINDEX
:
328 /* If the resolving route specifies a gateway, use it */
329 resolved_hop
->type
= newhop
->type
;
330 resolved_hop
->gate
.ipv4
= newhop
->gate
.ipv4
;
332 if (newhop
->ifindex
) {
333 resolved_hop
->type
= NEXTHOP_TYPE_IPV4_IFINDEX
;
334 resolved_hop
->ifindex
= newhop
->ifindex
;
335 if (newhop
->flags
& NEXTHOP_FLAG_ONLINK
)
336 resolved_hop
->flags
|= NEXTHOP_FLAG_ONLINK
;
339 case NEXTHOP_TYPE_IPV6
:
340 case NEXTHOP_TYPE_IPV6_IFINDEX
:
341 resolved_hop
->type
= newhop
->type
;
342 resolved_hop
->gate
.ipv6
= newhop
->gate
.ipv6
;
344 if (newhop
->ifindex
) {
345 resolved_hop
->type
= NEXTHOP_TYPE_IPV6_IFINDEX
;
346 resolved_hop
->ifindex
= newhop
->ifindex
;
349 case NEXTHOP_TYPE_IFINDEX
:
350 /* If the resolving route is an interface route,
351 * it means the gateway we are looking up is connected
352 * to that interface. (The actual network is _not_ onlink).
353 * Therefore, the resolved route should have the original
354 * gateway as nexthop as it is directly connected.
356 * On Linux, we have to set the onlink netlink flag because
357 * otherwise, the kernel won't accept the route.
359 resolved_hop
->flags
|= NEXTHOP_FLAG_ONLINK
;
361 resolved_hop
->type
= NEXTHOP_TYPE_IPV4_IFINDEX
;
362 resolved_hop
->gate
.ipv4
= nexthop
->gate
.ipv4
;
363 } else if (afi
== AFI_IP6
) {
364 resolved_hop
->type
= NEXTHOP_TYPE_IPV6_IFINDEX
;
365 resolved_hop
->gate
.ipv6
= nexthop
->gate
.ipv6
;
367 resolved_hop
->ifindex
= newhop
->ifindex
;
369 case NEXTHOP_TYPE_BLACKHOLE
:
370 resolved_hop
->type
= NEXTHOP_TYPE_BLACKHOLE
;
371 resolved_hop
->bh_type
= nexthop
->bh_type
;
375 /* Copy labels of the resolved route */
376 if (newhop
->nh_label
)
377 nexthop_add_labels(resolved_hop
, newhop
->nh_label_type
,
378 newhop
->nh_label
->num_labels
,
379 &newhop
->nh_label
->label
[0]);
381 resolved_hop
->rparent
= nexthop
;
382 nexthop_add(&nexthop
->resolved
, resolved_hop
);
385 /* If force flag is not set, do not modify falgs at all for uninstall
386 the route from FIB. */
387 static int nexthop_active(afi_t afi
, struct route_entry
*re
,
388 struct nexthop
*nexthop
, int set
,
389 struct route_node
*top
)
392 struct route_table
*table
;
393 struct route_node
*rn
;
394 struct route_entry
*match
= NULL
;
396 struct nexthop
*newhop
;
397 struct interface
*ifp
;
400 if ((nexthop
->type
== NEXTHOP_TYPE_IPV4
)
401 || nexthop
->type
== NEXTHOP_TYPE_IPV6
)
402 nexthop
->ifindex
= 0;
405 UNSET_FLAG(nexthop
->flags
, NEXTHOP_FLAG_RECURSIVE
);
406 zebra_deregister_rnh_static_nexthops(re
->nh_vrf_id
,
407 nexthop
->resolved
, top
);
408 nexthops_free(nexthop
->resolved
);
409 nexthop
->resolved
= NULL
;
413 /* Skip nexthops that have been filtered out due to route-map */
414 /* The nexthops are specific to this route and so the same */
415 /* nexthop for a different route may not have this flag set */
416 if (CHECK_FLAG(nexthop
->flags
, NEXTHOP_FLAG_FILTERED
))
420 * Check to see if we should trust the passed in information
421 * for UNNUMBERED interfaces as that we won't find the GW
422 * address in the routing table.
424 if (CHECK_FLAG(nexthop
->flags
, NEXTHOP_FLAG_ONLINK
)) {
425 ifp
= if_lookup_by_index(nexthop
->ifindex
, re
->nh_vrf_id
);
426 if (ifp
&& connected_is_unnumbered(ifp
)) {
427 if (if_is_operative(ifp
))
435 /* Make lookup prefix. */
436 memset(&p
, 0, sizeof(struct prefix
));
440 p
.prefixlen
= IPV4_MAX_PREFIXLEN
;
441 p
.u
.prefix4
= nexthop
->gate
.ipv4
;
445 p
.prefixlen
= IPV6_MAX_PREFIXLEN
;
446 p
.u
.prefix6
= nexthop
->gate
.ipv6
;
449 assert(afi
!= AFI_IP
&& afi
!= AFI_IP6
);
453 table
= zebra_vrf_table(afi
, SAFI_UNICAST
, re
->nh_vrf_id
);
457 rn
= route_node_match(table
, (struct prefix
*)&p
);
459 route_unlock_node(rn
);
461 /* Lookup should halt if we've matched against ourselves ('top',
462 * if specified) - i.e., we cannot have a nexthop NH1 is
463 * resolved by a route NH1. The exception is if the route is a
466 if (top
&& rn
== top
)
467 if (((afi
== AFI_IP
) && (rn
->p
.prefixlen
!= 32)) ||
468 ((afi
== AFI_IP6
) && (rn
->p
.prefixlen
!= 128)))
471 /* Pick up selected route. */
472 /* However, do not resolve over default route unless explicitly
474 if (is_default_prefix(&rn
->p
)
475 && !nh_resolve_via_default(p
.family
))
478 dest
= rib_dest_from_rnode(rn
);
479 if (dest
&& dest
->selected_fib
&&
480 !CHECK_FLAG(dest
->selected_fib
->status
,
481 ROUTE_ENTRY_REMOVED
) &&
482 dest
->selected_fib
->type
!= ZEBRA_ROUTE_TABLE
)
483 match
= dest
->selected_fib
;
485 /* If there is no selected route or matched route is EGP, go up
490 } while (rn
&& rn
->info
== NULL
);
497 if (match
->type
== ZEBRA_ROUTE_CONNECT
) {
498 /* Directly point connected route. */
499 newhop
= match
->nexthop
;
501 if (nexthop
->type
== NEXTHOP_TYPE_IPV4
502 || nexthop
->type
== NEXTHOP_TYPE_IPV6
)
503 nexthop
->ifindex
= newhop
->ifindex
;
506 } else if (CHECK_FLAG(re
->flags
, ZEBRA_FLAG_INTERNAL
)) {
508 for (ALL_NEXTHOPS(match
->nexthop
, newhop
)) {
509 if (!CHECK_FLAG(newhop
->flags
,
512 if (CHECK_FLAG(newhop
->flags
,
513 NEXTHOP_FLAG_RECURSIVE
))
517 SET_FLAG(nexthop
->flags
,
518 NEXTHOP_FLAG_RECURSIVE
);
520 ROUTE_ENTRY_NEXTHOPS_CHANGED
);
521 nexthop_set_resolved(afi
, newhop
,
527 re
->nexthop_mtu
= match
->mtu
;
529 } else if (re
->type
== ZEBRA_ROUTE_STATIC
) {
531 for (ALL_NEXTHOPS(match
->nexthop
, newhop
)) {
532 if (!CHECK_FLAG(newhop
->flags
,
537 SET_FLAG(nexthop
->flags
,
538 NEXTHOP_FLAG_RECURSIVE
);
539 nexthop_set_resolved(afi
, newhop
,
545 re
->nexthop_mtu
= match
->mtu
;
554 struct route_entry
*rib_match(afi_t afi
, safi_t safi
, vrf_id_t vrf_id
,
555 union g_addr
*addr
, struct route_node
**rn_out
)
558 struct route_table
*table
;
559 struct route_node
*rn
;
560 struct route_entry
*match
= NULL
;
561 struct nexthop
*newhop
;
564 table
= zebra_vrf_table(afi
, safi
, vrf_id
);
568 memset(&p
, 0, sizeof(struct prefix
));
571 p
.u
.prefix4
= addr
->ipv4
;
572 p
.prefixlen
= IPV4_MAX_PREFIXLEN
;
574 p
.u
.prefix6
= addr
->ipv6
;
575 p
.prefixlen
= IPV6_MAX_PREFIXLEN
;
578 rn
= route_node_match(table
, (struct prefix
*)&p
);
583 route_unlock_node(rn
);
585 dest
= rib_dest_from_rnode(rn
);
586 if (dest
&& dest
->selected_fib
&&
587 !CHECK_FLAG(dest
->selected_fib
->status
, ROUTE_ENTRY_REMOVED
))
588 match
= dest
->selected_fib
;
590 /* If there is no selected route or matched route is EGP, go up
595 } while (rn
&& rn
->info
== NULL
);
599 if (match
->type
!= ZEBRA_ROUTE_CONNECT
) {
601 for (ALL_NEXTHOPS(match
->nexthop
, newhop
))
602 if (CHECK_FLAG(newhop
->flags
,
619 struct route_entry
*rib_match_ipv4_multicast(vrf_id_t vrf_id
,
621 struct route_node
**rn_out
)
623 struct route_entry
*re
= NULL
, *mre
= NULL
, *ure
= NULL
;
624 struct route_node
*m_rn
= NULL
, *u_rn
= NULL
;
625 union g_addr gaddr
= {.ipv4
= addr
};
627 switch (ipv4_multicast_mode
) {
628 case MCAST_MRIB_ONLY
:
629 return rib_match(AFI_IP
, SAFI_MULTICAST
, vrf_id
, &gaddr
,
631 case MCAST_URIB_ONLY
:
632 return rib_match(AFI_IP
, SAFI_UNICAST
, vrf_id
, &gaddr
, rn_out
);
633 case MCAST_NO_CONFIG
:
634 case MCAST_MIX_MRIB_FIRST
:
635 re
= mre
= rib_match(AFI_IP
, SAFI_MULTICAST
, vrf_id
, &gaddr
,
638 re
= ure
= rib_match(AFI_IP
, SAFI_UNICAST
, vrf_id
,
641 case MCAST_MIX_DISTANCE
:
642 mre
= rib_match(AFI_IP
, SAFI_MULTICAST
, vrf_id
, &gaddr
, &m_rn
);
643 ure
= rib_match(AFI_IP
, SAFI_UNICAST
, vrf_id
, &gaddr
, &u_rn
);
645 re
= ure
->distance
< mre
->distance
? ure
: mre
;
651 case MCAST_MIX_PFXLEN
:
652 mre
= rib_match(AFI_IP
, SAFI_MULTICAST
, vrf_id
, &gaddr
, &m_rn
);
653 ure
= rib_match(AFI_IP
, SAFI_UNICAST
, vrf_id
, &gaddr
, &u_rn
);
655 re
= u_rn
->p
.prefixlen
> m_rn
->p
.prefixlen
? ure
: mre
;
664 *rn_out
= (re
== mre
) ? m_rn
: u_rn
;
666 if (IS_ZEBRA_DEBUG_RIB
) {
668 inet_ntop(AF_INET
, &addr
, buf
, BUFSIZ
);
670 zlog_debug("%s: %s: found %s, using %s", __func__
, buf
,
671 mre
? (ure
? "MRIB+URIB" : "MRIB")
672 : ure
? "URIB" : "nothing",
673 re
== ure
? "URIB" : re
== mre
? "MRIB" : "none");
678 void multicast_mode_ipv4_set(enum multicast_mode mode
)
680 if (IS_ZEBRA_DEBUG_RIB
)
681 zlog_debug("%s: multicast lookup mode set (%d)", __func__
,
683 ipv4_multicast_mode
= mode
;
686 enum multicast_mode
multicast_mode_ipv4_get(void)
688 return ipv4_multicast_mode
;
691 struct route_entry
*rib_lookup_ipv4(struct prefix_ipv4
*p
, vrf_id_t vrf_id
)
693 struct route_table
*table
;
694 struct route_node
*rn
;
695 struct route_entry
*match
= NULL
;
696 struct nexthop
*nexthop
;
700 table
= zebra_vrf_table(AFI_IP
, SAFI_UNICAST
, vrf_id
);
704 rn
= route_node_lookup(table
, (struct prefix
*)p
);
706 /* No route for this prefix. */
711 route_unlock_node(rn
);
712 dest
= rib_dest_from_rnode(rn
);
714 if (dest
&& dest
->selected_fib
&&
715 !CHECK_FLAG(dest
->selected_fib
->status
, ROUTE_ENTRY_REMOVED
))
716 match
= dest
->selected_fib
;
721 if (match
->type
== ZEBRA_ROUTE_CONNECT
)
724 for (ALL_NEXTHOPS(match
->nexthop
, nexthop
))
725 if (CHECK_FLAG(nexthop
->flags
, NEXTHOP_FLAG_FIB
))
732 * This clone function, unlike its original rib_lookup_ipv4(), checks
733 * if specified IPv4 route record (prefix/mask -> gate) exists in
734 * the whole RIB and has ROUTE_ENTRY_SELECTED_FIB set.
738 * 0: exact match found
739 * 1: a match was found with a different gate
740 * 2: connected route found
741 * 3: no matches found
743 int rib_lookup_ipv4_route(struct prefix_ipv4
*p
, union sockunion
*qgate
,
746 struct route_table
*table
;
747 struct route_node
*rn
;
748 struct route_entry
*match
= NULL
;
749 struct nexthop
*nexthop
;
754 table
= zebra_vrf_table(AFI_IP
, SAFI_UNICAST
, vrf_id
);
756 return ZEBRA_RIB_LOOKUP_ERROR
;
758 /* Scan the RIB table for exactly matching RIB entry. */
759 rn
= route_node_lookup(table
, (struct prefix
*)p
);
761 /* No route for this prefix. */
763 return ZEBRA_RIB_NOTFOUND
;
766 route_unlock_node(rn
);
767 dest
= rib_dest_from_rnode(rn
);
769 /* Find out if a "selected" RR for the discovered RIB entry exists ever.
771 if (dest
&& dest
->selected_fib
&&
772 !CHECK_FLAG(dest
->selected_fib
->status
, ROUTE_ENTRY_REMOVED
))
773 match
= dest
->selected_fib
;
775 /* None such found :( */
777 return ZEBRA_RIB_NOTFOUND
;
779 if (match
->type
== ZEBRA_ROUTE_CONNECT
)
780 return ZEBRA_RIB_FOUND_CONNECTED
;
782 /* Ok, we have a cood candidate, let's check it's nexthop list... */
784 for (ALL_NEXTHOPS(match
->nexthop
, nexthop
))
785 if (CHECK_FLAG(nexthop
->flags
, NEXTHOP_FLAG_FIB
)) {
787 if (nexthop
->gate
.ipv4
.s_addr
== sockunion2ip(qgate
))
788 return ZEBRA_RIB_FOUND_EXACT
;
789 if (IS_ZEBRA_DEBUG_RIB
) {
790 char gate_buf
[INET_ADDRSTRLEN
],
791 qgate_buf
[INET_ADDRSTRLEN
];
792 inet_ntop(AF_INET
, &nexthop
->gate
.ipv4
.s_addr
,
793 gate_buf
, INET_ADDRSTRLEN
);
794 inet_ntop(AF_INET
, &sockunion2ip(qgate
),
795 qgate_buf
, INET_ADDRSTRLEN
);
796 zlog_debug("%s: qgate == %s, %s == %s",
798 nexthop
->rparent
? "rgate" : "gate",
804 return ZEBRA_RIB_FOUND_NOGATE
;
806 return ZEBRA_RIB_NOTFOUND
;
809 #define RIB_SYSTEM_ROUTE(R) \
810 ((R)->type == ZEBRA_ROUTE_KERNEL || (R)->type == ZEBRA_ROUTE_CONNECT)
812 /* This function verifies reachability of one given nexthop, which can be
813 * numbered or unnumbered, IPv4 or IPv6. The result is unconditionally stored
814 * in nexthop->flags field. If the 4th parameter, 'set', is non-zero,
815 * nexthop->ifindex will be updated appropriately as well.
816 * An existing route map can turn (otherwise active) nexthop into inactive, but
819 * The return value is the final value of 'ACTIVE' flag.
822 static unsigned nexthop_active_check(struct route_node
*rn
,
823 struct route_entry
*re
,
824 struct nexthop
*nexthop
, int set
)
826 struct interface
*ifp
;
827 route_map_result_t ret
= RMAP_MATCH
;
829 char buf
[SRCDEST2STR_BUFFER
];
830 struct prefix
*p
, *src_p
;
831 srcdest_rnode_prefixes(rn
, &p
, &src_p
);
833 if (rn
->p
.family
== AF_INET
)
835 else if (rn
->p
.family
== AF_INET6
)
839 switch (nexthop
->type
) {
840 case NEXTHOP_TYPE_IFINDEX
:
841 ifp
= if_lookup_by_index(nexthop
->ifindex
, re
->nh_vrf_id
);
842 if (ifp
&& if_is_operative(ifp
))
843 SET_FLAG(nexthop
->flags
, NEXTHOP_FLAG_ACTIVE
);
845 UNSET_FLAG(nexthop
->flags
, NEXTHOP_FLAG_ACTIVE
);
847 case NEXTHOP_TYPE_IPV4
:
848 case NEXTHOP_TYPE_IPV4_IFINDEX
:
850 if (CHECK_FLAG(nexthop
->flags
, NEXTHOP_FLAG_EVPN_RVTEP
))
851 SET_FLAG(nexthop
->flags
, NEXTHOP_FLAG_ACTIVE
);
852 else if (nexthop_active(AFI_IP
, re
, nexthop
, set
, rn
))
853 SET_FLAG(nexthop
->flags
, NEXTHOP_FLAG_ACTIVE
);
855 UNSET_FLAG(nexthop
->flags
, NEXTHOP_FLAG_ACTIVE
);
857 case NEXTHOP_TYPE_IPV6
:
859 if (nexthop_active(AFI_IP6
, re
, nexthop
, set
, rn
))
860 SET_FLAG(nexthop
->flags
, NEXTHOP_FLAG_ACTIVE
);
862 UNSET_FLAG(nexthop
->flags
, NEXTHOP_FLAG_ACTIVE
);
864 case NEXTHOP_TYPE_IPV6_IFINDEX
:
865 /* RFC 5549, v4 prefix with v6 NH */
866 if (rn
->p
.family
!= AF_INET
)
868 if (IN6_IS_ADDR_LINKLOCAL(&nexthop
->gate
.ipv6
)) {
869 ifp
= if_lookup_by_index(nexthop
->ifindex
,
871 if (ifp
&& if_is_operative(ifp
))
872 SET_FLAG(nexthop
->flags
, NEXTHOP_FLAG_ACTIVE
);
874 UNSET_FLAG(nexthop
->flags
, NEXTHOP_FLAG_ACTIVE
);
876 if (nexthop_active(AFI_IP6
, re
, nexthop
, set
, rn
))
877 SET_FLAG(nexthop
->flags
, NEXTHOP_FLAG_ACTIVE
);
879 UNSET_FLAG(nexthop
->flags
, NEXTHOP_FLAG_ACTIVE
);
882 case NEXTHOP_TYPE_BLACKHOLE
:
883 SET_FLAG(nexthop
->flags
, NEXTHOP_FLAG_ACTIVE
);
888 if (!CHECK_FLAG(nexthop
->flags
, NEXTHOP_FLAG_ACTIVE
))
891 /* XXX: What exactly do those checks do? Do we support
892 * e.g. IPv4 routes with IPv6 nexthops or vice versa? */
893 if (RIB_SYSTEM_ROUTE(re
) || (family
== AFI_IP
&& p
->family
!= AF_INET
)
894 || (family
== AFI_IP6
&& p
->family
!= AF_INET6
))
895 return CHECK_FLAG(nexthop
->flags
, NEXTHOP_FLAG_ACTIVE
);
897 /* The original code didn't determine the family correctly
898 * e.g. for NEXTHOP_TYPE_IFINDEX. Retrieve the correct afi
899 * from the rib_table_info in those cases.
900 * Possibly it may be better to use only the rib_table_info
904 rib_table_info_t
*info
;
906 info
= srcdest_rnode_table_info(rn
);
910 memset(&nexthop
->rmap_src
.ipv6
, 0, sizeof(union g_addr
));
912 /* It'll get set if required inside */
913 ret
= zebra_route_map_check(family
, re
->type
, p
, nexthop
, re
->nh_vrf_id
,
915 if (ret
== RMAP_DENYMATCH
) {
916 if (IS_ZEBRA_DEBUG_RIB
) {
917 srcdest_rnode2str(rn
, buf
, sizeof(buf
));
919 "%u:%s: Filtering out with NH out %s due to route map",
921 ifindex2ifname(nexthop
->ifindex
,
924 UNSET_FLAG(nexthop
->flags
, NEXTHOP_FLAG_ACTIVE
);
926 return CHECK_FLAG(nexthop
->flags
, NEXTHOP_FLAG_ACTIVE
);
929 /* Iterate over all nexthops of the given RIB entry and refresh their
930 * ACTIVE flag. re->nexthop_active_num is updated accordingly. If any
931 * nexthop is found to toggle the ACTIVE flag, the whole re structure
932 * is flagged with ROUTE_ENTRY_CHANGED. The 4th 'set' argument is
933 * transparently passed to nexthop_active_check().
935 * Return value is the new number of active nexthops.
938 static int nexthop_active_update(struct route_node
*rn
, struct route_entry
*re
,
941 struct nexthop
*nexthop
;
942 union g_addr prev_src
;
943 unsigned int prev_active
, new_active
, old_num_nh
;
944 ifindex_t prev_index
;
945 old_num_nh
= re
->nexthop_active_num
;
947 re
->nexthop_active_num
= 0;
948 UNSET_FLAG(re
->status
, ROUTE_ENTRY_CHANGED
);
950 for (nexthop
= re
->nexthop
; nexthop
; nexthop
= nexthop
->next
) {
951 /* No protocol daemon provides src and so we're skipping
953 prev_src
= nexthop
->rmap_src
;
954 prev_active
= CHECK_FLAG(nexthop
->flags
, NEXTHOP_FLAG_ACTIVE
);
955 prev_index
= nexthop
->ifindex
;
956 if ((new_active
= nexthop_active_check(rn
, re
, nexthop
, set
)))
957 re
->nexthop_active_num
++;
958 /* Don't allow src setting on IPv6 addr for now */
959 if (prev_active
!= new_active
|| prev_index
!= nexthop
->ifindex
960 || ((nexthop
->type
>= NEXTHOP_TYPE_IFINDEX
961 && nexthop
->type
< NEXTHOP_TYPE_IPV6
)
962 && prev_src
.ipv4
.s_addr
963 != nexthop
->rmap_src
.ipv4
.s_addr
)
964 || ((nexthop
->type
>= NEXTHOP_TYPE_IPV6
965 && nexthop
->type
< NEXTHOP_TYPE_BLACKHOLE
)
966 && !(IPV6_ADDR_SAME(&prev_src
.ipv6
,
967 &nexthop
->rmap_src
.ipv6
)))) {
968 SET_FLAG(re
->status
, ROUTE_ENTRY_CHANGED
);
969 SET_FLAG(re
->status
, ROUTE_ENTRY_NEXTHOPS_CHANGED
);
973 if (old_num_nh
!= re
->nexthop_active_num
)
974 SET_FLAG(re
->status
, ROUTE_ENTRY_CHANGED
);
976 if (CHECK_FLAG(re
->status
, ROUTE_ENTRY_CHANGED
)) {
977 SET_FLAG(re
->status
, ROUTE_ENTRY_NEXTHOPS_CHANGED
);
980 return re
->nexthop_active_num
;
984 * Is this RIB labeled-unicast? It must be of type BGP and all paths
985 * (nexthops) must have a label.
987 int zebra_rib_labeled_unicast(struct route_entry
*re
)
989 struct nexthop
*nexthop
= NULL
;
991 if (re
->type
!= ZEBRA_ROUTE_BGP
)
994 for (ALL_NEXTHOPS(re
->nexthop
, nexthop
))
995 if (!nexthop
->nh_label
|| !nexthop
->nh_label
->num_labels
)
1001 void kernel_route_rib_pass_fail(struct route_node
*rn
, struct prefix
*p
,
1002 struct route_entry
*re
,
1003 enum southbound_results res
)
1005 struct nexthop
*nexthop
;
1006 char buf
[PREFIX_STRLEN
];
1009 dest
= rib_dest_from_rnode(rn
);
1012 case SOUTHBOUND_INSTALL_SUCCESS
:
1013 dest
->selected_fib
= re
;
1014 for (ALL_NEXTHOPS(re
->nexthop
, nexthop
)) {
1015 if (CHECK_FLAG(nexthop
->flags
, NEXTHOP_FLAG_RECURSIVE
))
1018 if (CHECK_FLAG(nexthop
->flags
, NEXTHOP_FLAG_ACTIVE
))
1019 SET_FLAG(nexthop
->flags
, NEXTHOP_FLAG_FIB
);
1021 UNSET_FLAG(nexthop
->flags
, NEXTHOP_FLAG_FIB
);
1023 zsend_route_notify_owner(re
->type
, re
->instance
, re
->vrf_id
,
1024 p
, ZAPI_ROUTE_INSTALLED
);
1026 case SOUTHBOUND_INSTALL_FAILURE
:
1028 * I am not sure this is the right thing to do here
1029 * but the code always set selected_fib before
1030 * this assignment was moved here.
1032 dest
->selected_fib
= re
;
1034 zsend_route_notify_owner(re
->type
, re
->instance
, re
->vrf_id
,
1035 p
, ZAPI_ROUTE_FAIL_INSTALL
);
1036 zlog_warn("%u:%s: Route install failed", re
->vrf_id
,
1037 prefix2str(p
, buf
, sizeof(buf
)));
1039 case SOUTHBOUND_DELETE_SUCCESS
:
1041 * The case where selected_fib is not re is
1042 * when we have received a system route
1043 * that is overriding our installed route
1044 * as such we should leave the selected_fib
1047 if (dest
->selected_fib
== re
)
1048 dest
->selected_fib
= NULL
;
1049 for (ALL_NEXTHOPS(re
->nexthop
, nexthop
))
1050 UNSET_FLAG(nexthop
->flags
, NEXTHOP_FLAG_FIB
);
1052 case SOUTHBOUND_DELETE_FAILURE
:
1054 * Should we set this to NULL if the
1057 dest
->selected_fib
= NULL
;
1058 zlog_warn("%u:%s: Route Deletion failure", re
->vrf_id
,
1059 prefix2str(p
, buf
, sizeof(buf
)));
1064 /* Update flag indicates whether this is a "replace" or not. Currently, this
1065 * is only used for IPv4.
1067 void rib_install_kernel(struct route_node
*rn
, struct route_entry
*re
,
1068 struct route_entry
*old
)
1070 struct nexthop
*nexthop
;
1071 rib_table_info_t
*info
= srcdest_rnode_table_info(rn
);
1072 struct prefix
*p
, *src_p
;
1073 struct zebra_vrf
*zvrf
= vrf_info_lookup(re
->vrf_id
);
1075 srcdest_rnode_prefixes(rn
, &p
, &src_p
);
1077 if (info
->safi
!= SAFI_UNICAST
) {
1078 for (ALL_NEXTHOPS(re
->nexthop
, nexthop
))
1079 SET_FLAG(nexthop
->flags
, NEXTHOP_FLAG_FIB
);
1082 struct nexthop
*prev
;
1084 for (ALL_NEXTHOPS(re
->nexthop
, nexthop
)) {
1085 UNSET_FLAG (nexthop
->flags
, NEXTHOP_FLAG_DUPLICATE
);
1086 for (ALL_NEXTHOPS(re
->nexthop
, prev
)) {
1087 if (prev
== nexthop
)
1089 if (nexthop_same_firsthop (nexthop
, prev
))
1091 SET_FLAG (nexthop
->flags
, NEXTHOP_FLAG_DUPLICATE
);
1099 * If this is a replace to a new RE let the originator of the RE
1100 * know that they've lost
1102 if (old
&& old
!= re
)
1103 zsend_route_notify_owner(old
->type
, old
->instance
,
1105 ZAPI_ROUTE_BETTER_ADMIN_WON
);
1108 * Make sure we update the FPM any time we send new information to
1111 hook_call(rib_update
, rn
, "installing in kernel");
1112 kernel_route_rib(rn
, p
, src_p
, old
, re
);
1118 /* Uninstall the route from kernel. */
1119 void rib_uninstall_kernel(struct route_node
*rn
, struct route_entry
*re
)
1121 struct nexthop
*nexthop
;
1122 rib_table_info_t
*info
= srcdest_rnode_table_info(rn
);
1123 struct prefix
*p
, *src_p
;
1124 struct zebra_vrf
*zvrf
= vrf_info_lookup(re
->vrf_id
);
1126 srcdest_rnode_prefixes(rn
, &p
, &src_p
);
1128 if (info
->safi
!= SAFI_UNICAST
) {
1129 for (ALL_NEXTHOPS(re
->nexthop
, nexthop
))
1130 UNSET_FLAG(nexthop
->flags
, NEXTHOP_FLAG_FIB
);
1135 * Make sure we update the FPM any time we send new information to
1138 hook_call(rib_update
, rn
, "uninstalling from kernel");
1139 kernel_route_rib(rn
, p
, src_p
, re
, NULL
);
1145 /* Uninstall the route from kernel. */
1146 static void rib_uninstall(struct route_node
*rn
, struct route_entry
*re
)
1148 rib_table_info_t
*info
= srcdest_rnode_table_info(rn
);
1149 rib_dest_t
*dest
= rib_dest_from_rnode(rn
);
1151 if (dest
&& dest
->selected_fib
== re
) {
1152 if (info
->safi
== SAFI_UNICAST
)
1153 hook_call(rib_update
, rn
, "rib_uninstall");
1155 if (!RIB_SYSTEM_ROUTE(re
))
1156 rib_uninstall_kernel(rn
, re
);
1158 /* If labeled-unicast route, uninstall transit LSP. */
1159 if (zebra_rib_labeled_unicast(re
))
1160 zebra_mpls_lsp_uninstall(info
->zvrf
, rn
, re
);
1163 if (CHECK_FLAG(re
->flags
, ZEBRA_FLAG_SELECTED
)) {
1164 struct prefix
*p
, *src_p
;
1165 srcdest_rnode_prefixes(rn
, &p
, &src_p
);
1167 redistribute_delete(p
, src_p
, re
);
1168 UNSET_FLAG(re
->flags
, ZEBRA_FLAG_SELECTED
);
1173 * rib_can_delete_dest
1175 * Returns TRUE if the given dest can be deleted from the table.
1177 static int rib_can_delete_dest(rib_dest_t
*dest
)
1184 * Don't delete the dest if we have to update the FPM about this
1187 if (CHECK_FLAG(dest
->flags
, RIB_DEST_UPDATE_FPM
)
1188 || CHECK_FLAG(dest
->flags
, RIB_DEST_SENT_TO_FPM
))
1197 * Garbage collect the rib dest corresponding to the given route node
1200 * Returns TRUE if the dest was deleted, FALSE otherwise.
1202 int rib_gc_dest(struct route_node
*rn
)
1206 dest
= rib_dest_from_rnode(rn
);
1210 if (!rib_can_delete_dest(dest
))
1213 if (IS_ZEBRA_DEBUG_RIB
) {
1214 struct zebra_vrf
*zvrf
;
1216 zvrf
= rib_dest_vrf(dest
);
1217 rnode_debug(rn
, zvrf_id(zvrf
), "removing dest from table");
1221 XFREE(MTYPE_RIB_DEST
, dest
);
1225 * Release the one reference that we keep on the route node.
1227 route_unlock_node(rn
);
1231 static void rib_process_add_fib(struct zebra_vrf
*zvrf
, struct route_node
*rn
,
1232 struct route_entry
*new)
1234 rib_dest_t
*dest
= rib_dest_from_rnode(rn
);
1236 hook_call(rib_update
, rn
, "new route selected");
1238 /* Update real nexthop. This may actually determine if nexthop is active
1240 if (!nexthop_active_update(rn
, new, 1)) {
1241 UNSET_FLAG(new->status
, ROUTE_ENTRY_CHANGED
);
1245 if (IS_ZEBRA_DEBUG_RIB
) {
1246 char buf
[SRCDEST2STR_BUFFER
];
1247 srcdest_rnode2str(rn
, buf
, sizeof(buf
));
1248 zlog_debug("%u:%s: Adding route rn %p, re %p (type %d)",
1249 zvrf_id(zvrf
), buf
, rn
, new, new->type
);
1252 /* If labeled-unicast route, install transit LSP. */
1253 if (zebra_rib_labeled_unicast(new))
1254 zebra_mpls_lsp_install(zvrf
, rn
, new);
1256 if (!RIB_SYSTEM_ROUTE(new))
1257 rib_install_kernel(rn
, new, NULL
);
1259 dest
->selected_fib
= new;
1261 UNSET_FLAG(new->status
, ROUTE_ENTRY_CHANGED
);
1264 static void rib_process_del_fib(struct zebra_vrf
*zvrf
, struct route_node
*rn
,
1265 struct route_entry
*old
)
1267 rib_dest_t
*dest
= rib_dest_from_rnode(rn
);
1268 hook_call(rib_update
, rn
, "removing existing route");
1270 /* Uninstall from kernel. */
1271 if (IS_ZEBRA_DEBUG_RIB
) {
1272 char buf
[SRCDEST2STR_BUFFER
];
1273 srcdest_rnode2str(rn
, buf
, sizeof(buf
));
1274 zlog_debug("%u:%s: Deleting route rn %p, re %p (type %d)",
1275 zvrf_id(zvrf
), buf
, rn
, old
, old
->type
);
1278 /* If labeled-unicast route, uninstall transit LSP. */
1279 if (zebra_rib_labeled_unicast(old
))
1280 zebra_mpls_lsp_uninstall(zvrf
, rn
, old
);
1282 if (!RIB_SYSTEM_ROUTE(old
))
1283 rib_uninstall_kernel(rn
, old
);
1286 * We are setting this to NULL here
1287 * because that is what we traditionally
1288 * have been doing. I am not positive
1289 * that this is the right thing to do
1290 * but let's leave the code alone
1291 * for the RIB_SYSTEM_ROUTE case
1293 dest
->selected_fib
= NULL
;
1296 /* Update nexthop for route, reset changed flag. */
1297 nexthop_active_update(rn
, old
, 1);
1298 UNSET_FLAG(old
->status
, ROUTE_ENTRY_CHANGED
);
1301 static void rib_process_update_fib(struct zebra_vrf
*zvrf
,
1302 struct route_node
*rn
,
1303 struct route_entry
*old
,
1304 struct route_entry
*new)
1306 struct nexthop
*nexthop
= NULL
;
1308 rib_dest_t
*dest
= rib_dest_from_rnode(rn
);
1311 * We have to install or update if a new route has been selected or
1312 * something has changed.
1314 if (new != old
|| CHECK_FLAG(new->status
, ROUTE_ENTRY_CHANGED
)) {
1315 hook_call(rib_update
, rn
, "updating existing route");
1317 /* Update the nexthop; we could determine here that nexthop is
1319 if (nexthop_active_update(rn
, new, 1))
1322 /* If nexthop is active, install the selected route, if
1324 * the install succeeds, cleanup flags for prior route, if
1329 if (IS_ZEBRA_DEBUG_RIB
) {
1330 char buf
[SRCDEST2STR_BUFFER
];
1331 srcdest_rnode2str(rn
, buf
, sizeof(buf
));
1334 "%u:%s: Updating route rn %p, re %p (type %d) "
1336 zvrf_id(zvrf
), buf
, rn
, new,
1337 new->type
, old
, old
->type
);
1340 "%u:%s: Updating route rn %p, re %p (type %d)",
1341 zvrf_id(zvrf
), buf
, rn
, new,
1345 /* If labeled-unicast route, uninstall transit LSP. */
1346 if (zebra_rib_labeled_unicast(old
))
1347 zebra_mpls_lsp_uninstall(zvrf
, rn
, old
);
1349 /* Non-system route should be installed. */
1350 if (!RIB_SYSTEM_ROUTE(new)) {
1351 /* If labeled-unicast route, install transit
1353 if (zebra_rib_labeled_unicast(new))
1354 zebra_mpls_lsp_install(zvrf
, rn
, new);
1356 rib_install_kernel(rn
, new, old
);
1359 * We do not need to install the
1360 * selected route because it
1361 * is already isntalled by
1362 * the system( ie not us )
1363 * so just mark it as winning
1364 * we do need to ensure that
1365 * if we uninstall a route
1366 * from ourselves we don't
1367 * over write this pointer
1369 dest
->selected_fib
= NULL
;
1371 /* If install succeeded or system route, cleanup flags
1372 * for prior route. */
1374 if (RIB_SYSTEM_ROUTE(new)) {
1375 if (!RIB_SYSTEM_ROUTE(old
))
1376 rib_uninstall_kernel(rn
, old
);
1378 for (nexthop
= old
->nexthop
; nexthop
;
1379 nexthop
= nexthop
->next
)
1380 UNSET_FLAG(nexthop
->flags
,
1387 * If nexthop for selected route is not active or install
1389 * may need to uninstall and delete for redistribution.
1392 if (IS_ZEBRA_DEBUG_RIB
) {
1393 char buf
[SRCDEST2STR_BUFFER
];
1394 srcdest_rnode2str(rn
, buf
, sizeof(buf
));
1397 "%u:%s: Deleting route rn %p, re %p (type %d) "
1398 "old %p (type %d) - %s",
1399 zvrf_id(zvrf
), buf
, rn
, new,
1400 new->type
, old
, old
->type
,
1401 nh_active
? "install failed"
1402 : "nexthop inactive");
1405 "%u:%s: Deleting route rn %p, re %p (type %d) - %s",
1406 zvrf_id(zvrf
), buf
, rn
, new,
1408 nh_active
? "install failed"
1409 : "nexthop inactive");
1412 /* If labeled-unicast route, uninstall transit LSP. */
1413 if (zebra_rib_labeled_unicast(old
))
1414 zebra_mpls_lsp_uninstall(zvrf
, rn
, old
);
1416 if (!RIB_SYSTEM_ROUTE(old
))
1417 rib_uninstall_kernel(rn
, old
);
1419 dest
->selected_fib
= NULL
;
1423 * Same route selected; check if in the FIB and if not,
1425 * is housekeeping code to deal with race conditions in kernel
1427 * netlink reporting interface up before IPv4 or IPv6 protocol
1431 if (!RIB_SYSTEM_ROUTE(new)) {
1432 bool in_fib
= false;
1434 for (ALL_NEXTHOPS(new->nexthop
, nexthop
))
1435 if (CHECK_FLAG(nexthop
->flags
,
1436 NEXTHOP_FLAG_FIB
)) {
1441 rib_install_kernel(rn
, new, NULL
);
1445 /* Update prior route. */
1447 /* Set real nexthop. */
1448 nexthop_active_update(rn
, old
, 1);
1449 UNSET_FLAG(old
->status
, ROUTE_ENTRY_CHANGED
);
1452 /* Clear changed flag. */
1453 UNSET_FLAG(new->status
, ROUTE_ENTRY_CHANGED
);
1456 /* Check if 'alternate' RIB entry is better than 'current'. */
1457 static struct route_entry
*rib_choose_best(struct route_entry
*current
,
1458 struct route_entry
*alternate
)
1460 if (current
== NULL
)
1463 /* filter route selection in following order:
1464 * - connected beats other types
1465 * - lower distance beats higher
1466 * - lower metric beats higher for equal distance
1467 * - last, hence oldest, route wins tie break.
1470 /* Connected routes. Pick the last connected
1471 * route of the set of lowest metric connected routes.
1473 if (alternate
->type
== ZEBRA_ROUTE_CONNECT
) {
1474 if (current
->type
!= ZEBRA_ROUTE_CONNECT
1475 || alternate
->metric
<= current
->metric
)
1481 if (current
->type
== ZEBRA_ROUTE_CONNECT
)
1484 /* higher distance loses */
1485 if (alternate
->distance
< current
->distance
)
1487 if (current
->distance
< alternate
->distance
)
1490 /* metric tie-breaks equal distance */
1491 if (alternate
->metric
<= current
->metric
)
1497 /* Core function for processing routing information base. */
1498 static void rib_process(struct route_node
*rn
)
1500 struct route_entry
*re
;
1501 struct route_entry
*next
;
1502 struct route_entry
*old_selected
= NULL
;
1503 struct route_entry
*new_selected
= NULL
;
1504 struct route_entry
*old_fib
= NULL
;
1505 struct route_entry
*new_fib
= NULL
;
1506 struct route_entry
*best
= NULL
;
1507 char buf
[SRCDEST2STR_BUFFER
];
1509 struct zebra_vrf
*zvrf
= NULL
;
1510 struct prefix
*p
, *src_p
;
1511 srcdest_rnode_prefixes(rn
, &p
, &src_p
);
1512 vrf_id_t vrf_id
= VRF_UNKNOWN
;
1516 dest
= rib_dest_from_rnode(rn
);
1518 zvrf
= rib_dest_vrf(dest
);
1519 vrf_id
= zvrf_id(zvrf
);
1522 if (IS_ZEBRA_DEBUG_RIB
)
1523 srcdest_rnode2str(rn
, buf
, sizeof(buf
));
1525 if (IS_ZEBRA_DEBUG_RIB_DETAILED
)
1526 zlog_debug("%u:%s: Processing rn %p", vrf_id
, buf
, rn
);
1529 * we can have rn's that have a NULL info pointer
1530 * (dest). As such let's not let the deref happen
1531 * additionally we know RNODE_FOREACH_RE_SAFE
1532 * will not iterate so we are ok.
1535 old_fib
= dest
->selected_fib
;
1537 RNODE_FOREACH_RE_SAFE (rn
, re
, next
) {
1538 if (IS_ZEBRA_DEBUG_RIB_DETAILED
)
1540 "%u:%s: Examine re %p (type %d) status %x flags %x "
1541 "dist %d metric %d",
1542 vrf_id
, buf
, re
, re
->type
, re
->status
,
1543 re
->flags
, re
->distance
, re
->metric
);
1545 UNSET_FLAG(re
->status
, ROUTE_ENTRY_NEXTHOPS_CHANGED
);
1547 /* Currently selected re. */
1548 if (CHECK_FLAG(re
->flags
, ZEBRA_FLAG_SELECTED
)) {
1549 assert(old_selected
== NULL
);
1553 /* Skip deleted entries from selection */
1554 if (CHECK_FLAG(re
->status
, ROUTE_ENTRY_REMOVED
))
1557 /* Skip unreachable nexthop. */
1558 /* This first call to nexthop_active_update is merely to
1560 * there's any change to nexthops associated with this RIB
1562 * rib_process() can be invoked due to an external event such as
1564 * down or due to next-hop-tracking evaluation. In the latter
1566 * a decision has already been made that the NHs have changed.
1568 * need to invoke a potentially expensive call again. Further,
1570 * the change might be in a recursive NH which is not caught in
1571 * the nexthop_active_update() code. Thus, we might miss changes
1575 if (!CHECK_FLAG(re
->status
, ROUTE_ENTRY_CHANGED
)
1576 && !nexthop_active_update(rn
, re
, 0)) {
1577 if (re
->type
== ZEBRA_ROUTE_TABLE
) {
1578 /* XXX: HERE BE DRAGONS!!!!!
1579 * In all honesty, I have not yet figured out
1581 * does or why the ROUTE_ENTRY_CHANGED test
1583 * or why we need to delete a route here, and
1585 * this concerns both selected and fib route, or
1588 /* This entry was denied by the 'ip protocol
1589 * table' route-map, we
1590 * need to delete it */
1591 if (re
!= old_selected
) {
1592 if (IS_ZEBRA_DEBUG_RIB
)
1594 "%s: %s: imported via import-table but denied "
1595 "by the ip protocol table route-map",
1599 SET_FLAG(re
->status
,
1600 ROUTE_ENTRY_REMOVED
);
1606 /* Infinite distance. */
1607 if (re
->distance
== DISTANCE_INFINITY
) {
1608 UNSET_FLAG(re
->status
, ROUTE_ENTRY_CHANGED
);
1612 if (CHECK_FLAG(re
->flags
, ZEBRA_FLAG_FIB_OVERRIDE
)) {
1613 best
= rib_choose_best(new_fib
, re
);
1614 if (new_fib
&& best
!= new_fib
)
1615 UNSET_FLAG(new_fib
->status
,
1616 ROUTE_ENTRY_CHANGED
);
1619 best
= rib_choose_best(new_selected
, re
);
1620 if (new_selected
&& best
!= new_selected
)
1621 UNSET_FLAG(new_selected
->status
,
1622 ROUTE_ENTRY_CHANGED
);
1623 new_selected
= best
;
1626 UNSET_FLAG(re
->status
, ROUTE_ENTRY_CHANGED
);
1627 } /* RNODE_FOREACH_RE */
1629 /* If no FIB override route, use the selected route also for FIB */
1630 if (new_fib
== NULL
)
1631 new_fib
= new_selected
;
1633 /* After the cycle is finished, the following pointers will be set:
1634 * old_selected --- RE entry currently having SELECTED
1635 * new_selected --- RE entry that is newly SELECTED
1636 * old_fib --- RE entry currently in kernel FIB
1637 * new_fib --- RE entry that is newly to be in kernel FIB
1639 * new_selected will get SELECTED flag, and is going to be redistributed
1640 * the zclients. new_fib (which can be new_selected) will be installed
1644 if (IS_ZEBRA_DEBUG_RIB_DETAILED
) {
1646 "%u:%s: After processing: old_selected %p new_selected %p old_fib %p new_fib %p",
1647 vrf_id
, buf
, (void *)old_selected
, (void *)new_selected
,
1648 (void *)old_fib
, (void *)new_fib
);
1651 /* Buffer ROUTE_ENTRY_CHANGED here, because it will get cleared if
1652 * fib == selected */
1653 bool selected_changed
= new_selected
&& CHECK_FLAG(new_selected
->status
,
1654 ROUTE_ENTRY_CHANGED
);
1656 /* Update fib according to selection results */
1657 if (new_fib
&& old_fib
)
1658 rib_process_update_fib(zvrf
, rn
, old_fib
, new_fib
);
1660 rib_process_add_fib(zvrf
, rn
, new_fib
);
1662 rib_process_del_fib(zvrf
, rn
, old_fib
);
1664 /* Redistribute SELECTED entry */
1665 if (old_selected
!= new_selected
|| selected_changed
) {
1666 struct nexthop
*nexthop
;
1668 /* Check if we have a FIB route for the destination, otherwise,
1669 * don't redistribute it */
1670 for (ALL_NEXTHOPS(new_fib
? new_fib
->nexthop
: NULL
, nexthop
)) {
1671 if (CHECK_FLAG(nexthop
->flags
, NEXTHOP_FLAG_FIB
)) {
1676 new_selected
= NULL
;
1678 if (new_selected
&& new_selected
!= new_fib
) {
1679 nexthop_active_update(rn
, new_selected
, 1);
1680 UNSET_FLAG(new_selected
->status
, ROUTE_ENTRY_CHANGED
);
1685 redistribute_delete(p
, src_p
, old_selected
);
1686 if (old_selected
!= new_selected
)
1687 UNSET_FLAG(old_selected
->flags
,
1688 ZEBRA_FLAG_SELECTED
);
1692 /* Install new or replace existing redistributed entry
1694 SET_FLAG(new_selected
->flags
, ZEBRA_FLAG_SELECTED
);
1695 redistribute_update(p
, src_p
, new_selected
,
1700 /* Remove all RE entries queued for removal */
1701 RNODE_FOREACH_RE_SAFE (rn
, re
, next
) {
1702 if (CHECK_FLAG(re
->status
, ROUTE_ENTRY_REMOVED
)) {
1703 if (IS_ZEBRA_DEBUG_RIB
) {
1704 rnode_debug(rn
, vrf_id
, "rn %p, removing re %p",
1705 (void *)rn
, (void *)re
);
1712 * Check if the dest can be deleted now.
1717 /* Take a list of route_node structs and return 1, if there was a record
1718 * picked from it and processed by rib_process(). Don't process more,
1719 * than one RN record; operate only in the specified sub-queue.
1721 static unsigned int process_subq(struct list
*subq
, u_char qindex
)
1723 struct listnode
*lnode
= listhead(subq
);
1724 struct route_node
*rnode
;
1726 struct zebra_vrf
*zvrf
= NULL
;
1731 rnode
= listgetdata(lnode
);
1732 dest
= rib_dest_from_rnode(rnode
);
1734 zvrf
= rib_dest_vrf(dest
);
1738 if (IS_ZEBRA_DEBUG_RIB_DETAILED
) {
1739 char buf
[SRCDEST2STR_BUFFER
];
1740 srcdest_rnode2str(rnode
, buf
, sizeof(buf
));
1741 zlog_debug("%u:%s: rn %p dequeued from sub-queue %u",
1742 zvrf
? zvrf_id(zvrf
) : 0, buf
, rnode
, qindex
);
1746 UNSET_FLAG(rib_dest_from_rnode(rnode
)->flags
,
1747 RIB_ROUTE_QUEUED(qindex
));
1752 zlog_debug ("%s: called for route_node (%p, %d) with no ribs",
1753 __func__
, rnode
, rnode
->lock
);
1754 zlog_backtrace(LOG_DEBUG
);
1757 route_unlock_node(rnode
);
1758 list_delete_node(subq
, lnode
);
1763 * All meta queues have been processed. Trigger next-hop evaluation.
1765 static void meta_queue_process_complete(struct work_queue
*dummy
)
1768 struct zebra_vrf
*zvrf
;
1770 /* Evaluate nexthops for those VRFs which underwent route processing.
1772 * should limit the evaluation to the necessary VRFs in most common
1775 RB_FOREACH (vrf
, vrf_id_head
, &vrfs_by_id
) {
1777 if (zvrf
== NULL
|| !(zvrf
->flags
& ZEBRA_VRF_RIB_SCHEDULED
))
1780 zvrf
->flags
&= ~ZEBRA_VRF_RIB_SCHEDULED
;
1781 zebra_evaluate_rnh(zvrf_id(zvrf
), AF_INET
, 0, RNH_NEXTHOP_TYPE
,
1783 zebra_evaluate_rnh(zvrf_id(zvrf
), AF_INET
, 0,
1784 RNH_IMPORT_CHECK_TYPE
, NULL
);
1785 zebra_evaluate_rnh(zvrf_id(zvrf
), AF_INET6
, 0, RNH_NEXTHOP_TYPE
,
1787 zebra_evaluate_rnh(zvrf_id(zvrf
), AF_INET6
, 0,
1788 RNH_IMPORT_CHECK_TYPE
, NULL
);
1791 /* Schedule LSPs for processing, if needed. */
1792 zvrf
= vrf_info_lookup(VRF_DEFAULT
);
1793 if (mpls_should_lsps_be_processed(zvrf
)) {
1794 if (IS_ZEBRA_DEBUG_MPLS
)
1796 "%u: Scheduling all LSPs upon RIB completion",
1798 zebra_mpls_lsp_schedule(zvrf
);
1799 mpls_unmark_lsps_for_processing(zvrf
);
1803 /* Dispatch the meta queue by picking, processing and unlocking the next RN from
1804 * a non-empty sub-queue with lowest priority. wq is equal to zebra->ribq and
1806 * is pointed to the meta queue structure.
1808 static wq_item_status
meta_queue_process(struct work_queue
*dummy
, void *data
)
1810 struct meta_queue
*mq
= data
;
1813 for (i
= 0; i
< MQ_SIZE
; i
++)
1814 if (process_subq(mq
->subq
[i
], i
)) {
1818 return mq
->size
? WQ_REQUEUE
: WQ_SUCCESS
;
1822 * Map from rib types to queue type (priority) in meta queue
1824 static const u_char meta_queue_map
[ZEBRA_ROUTE_MAX
] = {
1825 [ZEBRA_ROUTE_SYSTEM
] = 4,
1826 [ZEBRA_ROUTE_KERNEL
] = 0,
1827 [ZEBRA_ROUTE_CONNECT
] = 0,
1828 [ZEBRA_ROUTE_STATIC
] = 1,
1829 [ZEBRA_ROUTE_RIP
] = 2,
1830 [ZEBRA_ROUTE_RIPNG
] = 2,
1831 [ZEBRA_ROUTE_OSPF
] = 2,
1832 [ZEBRA_ROUTE_OSPF6
] = 2,
1833 [ZEBRA_ROUTE_ISIS
] = 2,
1834 [ZEBRA_ROUTE_BGP
] = 3,
1835 [ZEBRA_ROUTE_PIM
] = 4, // Shouldn't happen but for safety
1836 [ZEBRA_ROUTE_EIGRP
] = 2,
1837 [ZEBRA_ROUTE_NHRP
] = 2,
1838 [ZEBRA_ROUTE_HSLS
] = 4,
1839 [ZEBRA_ROUTE_OLSR
] = 4,
1840 [ZEBRA_ROUTE_TABLE
] = 1,
1841 [ZEBRA_ROUTE_LDP
] = 4,
1842 [ZEBRA_ROUTE_VNC
] = 3,
1843 [ZEBRA_ROUTE_VNC_DIRECT
] = 3,
1844 [ZEBRA_ROUTE_VNC_DIRECT_RH
] = 3,
1845 [ZEBRA_ROUTE_BGP_DIRECT
] = 3,
1846 [ZEBRA_ROUTE_BGP_DIRECT_EXT
] = 3,
1847 [ZEBRA_ROUTE_BABEL
] = 2,
1848 [ZEBRA_ROUTE_ALL
] = 4, // Shouldn't happen but for safety
1851 /* Look into the RN and queue it into one or more priority queues,
1852 * increasing the size for each data push done.
1854 static void rib_meta_queue_add(struct meta_queue
*mq
, struct route_node
*rn
)
1856 struct route_entry
*re
;
1858 RNODE_FOREACH_RE (rn
, re
) {
1859 u_char qindex
= meta_queue_map
[re
->type
];
1860 struct zebra_vrf
*zvrf
;
1862 /* Invariant: at this point we always have rn->info set. */
1863 if (CHECK_FLAG(rib_dest_from_rnode(rn
)->flags
,
1864 RIB_ROUTE_QUEUED(qindex
))) {
1865 if (IS_ZEBRA_DEBUG_RIB_DETAILED
)
1868 "rn %p is already queued in sub-queue %u",
1869 (void *)rn
, qindex
);
1873 SET_FLAG(rib_dest_from_rnode(rn
)->flags
,
1874 RIB_ROUTE_QUEUED(qindex
));
1875 listnode_add(mq
->subq
[qindex
], rn
);
1876 route_lock_node(rn
);
1879 if (IS_ZEBRA_DEBUG_RIB_DETAILED
)
1880 rnode_debug(rn
, re
->vrf_id
,
1881 "queued rn %p into sub-queue %u",
1882 (void *)rn
, qindex
);
1884 zvrf
= zebra_vrf_lookup_by_id(re
->vrf_id
);
1886 zvrf
->flags
|= ZEBRA_VRF_RIB_SCHEDULED
;
1890 /* Add route_node to work queue and schedule processing */
1891 void rib_queue_add(struct route_node
*rn
)
1895 /* Pointless to queue a route_node with no RIB entries to add or remove
1897 if (!rnode_to_ribs(rn
)) {
1898 zlog_debug("%s: called for route_node (%p, %d) with no ribs",
1899 __func__
, (void *)rn
, rn
->lock
);
1900 zlog_backtrace(LOG_DEBUG
);
1904 if (zebrad
.ribq
== NULL
) {
1905 zlog_err("%s: work_queue does not exist!", __func__
);
1910 * The RIB queue should normally be either empty or holding the only
1911 * work_queue_item element. In the latter case this element would
1912 * hold a pointer to the meta queue structure, which must be used to
1913 * actually queue the route nodes to process. So create the MQ
1914 * holder, if necessary, then push the work into it in any case.
1915 * This semantics was introduced after 0.99.9 release.
1917 if (work_queue_empty(zebrad
.ribq
))
1918 work_queue_add(zebrad
.ribq
, zebrad
.mq
);
1920 rib_meta_queue_add(zebrad
.mq
, rn
);
1925 /* Create new meta queue.
1926 A destructor function doesn't seem to be necessary here.
1928 static struct meta_queue
*meta_queue_new(void)
1930 struct meta_queue
*new;
1933 new = XCALLOC(MTYPE_WORK_QUEUE
, sizeof(struct meta_queue
));
1936 for (i
= 0; i
< MQ_SIZE
; i
++) {
1937 new->subq
[i
] = list_new();
1938 assert(new->subq
[i
]);
1944 void meta_queue_free(struct meta_queue
*mq
)
1948 for (i
= 0; i
< MQ_SIZE
; i
++)
1949 list_delete_and_null(&mq
->subq
[i
]);
1951 XFREE(MTYPE_WORK_QUEUE
, mq
);
1954 /* initialise zebra rib work queue */
1955 static void rib_queue_init(struct zebra_t
*zebra
)
1960 work_queue_new(zebra
->master
, "route_node processing"))) {
1961 zlog_err("%s: could not initialise work queue!", __func__
);
1965 /* fill in the work queue spec */
1966 zebra
->ribq
->spec
.workfunc
= &meta_queue_process
;
1967 zebra
->ribq
->spec
.errorfunc
= NULL
;
1968 zebra
->ribq
->spec
.completion_func
= &meta_queue_process_complete
;
1969 /* XXX: TODO: These should be runtime configurable via vty */
1970 zebra
->ribq
->spec
.max_retries
= 3;
1971 zebra
->ribq
->spec
.hold
= ZEBRA_RIB_PROCESS_HOLD_TIME
;
1973 if (!(zebra
->mq
= meta_queue_new())) {
1974 zlog_err("%s: could not initialise meta queue!", __func__
);
1980 /* RIB updates are processed via a queue of pointers to route_nodes.
1982 * The queue length is bounded by the maximal size of the routing table,
1983 * as a route_node will not be requeued, if already queued.
1985 * REs are submitted via rib_addnode or rib_delnode which set minimal
1986 * state, or static_install_route (when an existing RE is updated)
1987 * and then submit route_node to queue for best-path selection later.
1988 * Order of add/delete state changes are preserved for any given RE.
1990 * Deleted REs are reaped during best-path selection.
1993 * |-> rib_link or unset ROUTE_ENTRY_REMOVE |->Update kernel with
1994 * |-------->| | best RE, if required
1996 * static_install->|->rib_addqueue...... -> rib_process
1998 * |-------->| |-> rib_unlink
1999 * |-> set ROUTE_ENTRY_REMOVE |
2000 * rib_delnode (RE freed)
2002 * The 'info' pointer of a route_node points to a rib_dest_t
2003 * ('dest'). Queueing state for a route_node is kept on the dest. The
2004 * dest is created on-demand by rib_link() and is kept around at least
2005 * as long as there are ribs hanging off it (@see rib_gc_dest()).
2007 * Refcounting (aka "locking" throughout the GNU Zebra and Quagga code):
2009 * - route_nodes: refcounted by:
2010 * - dest attached to route_node:
2011 * - managed by: rib_link/rib_gc_dest
2012 * - route_node processing queue
2013 * - managed by: rib_addqueue, rib_process.
2017 /* Add RE to head of the route node. */
2018 static void rib_link(struct route_node
*rn
, struct route_entry
*re
, int process
)
2020 struct route_entry
*head
;
2023 const char *rmap_name
;
2027 dest
= rib_dest_from_rnode(rn
);
2029 if (IS_ZEBRA_DEBUG_RIB_DETAILED
)
2030 rnode_debug(rn
, re
->vrf_id
, "rn %p adding dest", rn
);
2032 dest
= XCALLOC(MTYPE_RIB_DEST
, sizeof(rib_dest_t
));
2033 route_lock_node(rn
); /* rn route table reference */
2038 head
= dest
->routes
;
2045 afi
= (rn
->p
.family
== AF_INET
)
2047 : (rn
->p
.family
== AF_INET6
) ? AFI_IP6
: AFI_MAX
;
2048 if (is_zebra_import_table_enabled(afi
, re
->table
)) {
2049 rmap_name
= zebra_get_import_table_route_map(afi
, re
->table
);
2050 zebra_add_import_table_entry(rn
, re
, rmap_name
);
2055 void rib_addnode(struct route_node
*rn
, struct route_entry
*re
, int process
)
2057 /* RE node has been un-removed before route-node is processed.
2058 * route_node must hence already be on the queue for processing..
2060 if (CHECK_FLAG(re
->status
, ROUTE_ENTRY_REMOVED
)) {
2061 if (IS_ZEBRA_DEBUG_RIB
)
2062 rnode_debug(rn
, re
->vrf_id
, "rn %p, un-removed re %p",
2063 (void *)rn
, (void *)re
);
2065 UNSET_FLAG(re
->status
, ROUTE_ENTRY_REMOVED
);
2068 rib_link(rn
, re
, process
);
2074 * Detach a rib structure from a route_node.
2076 * Note that a call to rib_unlink() should be followed by a call to
2077 * rib_gc_dest() at some point. This allows a rib_dest_t that is no
2078 * longer required to be deleted.
2080 void rib_unlink(struct route_node
*rn
, struct route_entry
*re
)
2086 if (IS_ZEBRA_DEBUG_RIB
)
2087 rnode_debug(rn
, re
->vrf_id
, "rn %p, re %p", (void *)rn
,
2090 dest
= rib_dest_from_rnode(rn
);
2093 re
->next
->prev
= re
->prev
;
2096 re
->prev
->next
= re
->next
;
2098 dest
->routes
= re
->next
;
2101 if (dest
->selected_fib
== re
)
2102 dest
->selected_fib
= NULL
;
2104 /* free RE and nexthops */
2105 zebra_deregister_rnh_static_nexthops(re
->vrf_id
, re
->nexthop
, rn
);
2106 nexthops_free(re
->nexthop
);
2107 XFREE(MTYPE_RE
, re
);
2110 void rib_delnode(struct route_node
*rn
, struct route_entry
*re
)
2114 if (IS_ZEBRA_DEBUG_RIB
)
2115 rnode_debug(rn
, re
->vrf_id
, "rn %p, re %p, removing",
2116 (void *)rn
, (void *)re
);
2117 SET_FLAG(re
->status
, ROUTE_ENTRY_REMOVED
);
2119 afi
= (rn
->p
.family
== AF_INET
)
2121 : (rn
->p
.family
== AF_INET6
) ? AFI_IP6
: AFI_MAX
;
2122 if (is_zebra_import_table_enabled(afi
, re
->table
)) {
2123 zebra_del_import_table_entry(rn
, re
);
2124 /* Just clean up if non main table */
2125 if (IS_ZEBRA_DEBUG_RIB
) {
2126 char buf
[SRCDEST2STR_BUFFER
];
2127 srcdest_rnode2str(rn
, buf
, sizeof(buf
));
2129 "%u:%s: Freeing route rn %p, re %p (type %d)",
2130 re
->vrf_id
, buf
, rn
, re
, re
->type
);
2139 /* This function dumps the contents of a given RE entry into
2140 * standard debug log. Calling function name and IP prefix in
2141 * question are passed as 1st and 2nd arguments.
2144 void _route_entry_dump(const char *func
, union prefixconstptr pp
,
2145 union prefixconstptr src_pp
,
2146 const struct route_entry
*re
)
2148 const struct prefix
*p
= pp
.p
;
2149 const struct prefix
*src_p
= src_pp
.p
;
2150 bool is_srcdst
= src_p
&& src_p
->prefixlen
;
2151 char straddr
[PREFIX_STRLEN
];
2152 char srcaddr
[PREFIX_STRLEN
];
2153 struct nexthop
*nexthop
;
2155 zlog_debug("%s: dumping RE entry %p for %s%s%s vrf %u", func
,
2156 (const void *)re
, prefix2str(pp
, straddr
, sizeof(straddr
)),
2157 is_srcdst
? " from " : "",
2158 is_srcdst
? prefix2str(src_pp
, srcaddr
, sizeof(srcaddr
))
2161 zlog_debug("%s: uptime == %lu, type == %u, instance == %d, table == %d",
2162 func
, (unsigned long)re
->uptime
, re
->type
, re
->instance
,
2165 "%s: metric == %u, mtu == %u, distance == %u, flags == %u, status == %u",
2166 func
, re
->metric
, re
->mtu
, re
->distance
, re
->flags
, re
->status
);
2167 zlog_debug("%s: nexthop_num == %u, nexthop_active_num == %u", func
,
2168 re
->nexthop_num
, re
->nexthop_active_num
);
2170 for (ALL_NEXTHOPS(re
->nexthop
, nexthop
)) {
2171 inet_ntop(p
->family
, &nexthop
->gate
, straddr
, INET6_ADDRSTRLEN
);
2172 zlog_debug("%s: %s %s[%u] with flags %s%s%s", func
,
2173 (nexthop
->rparent
? " NH" : "NH"), straddr
,
2175 (CHECK_FLAG(nexthop
->flags
, NEXTHOP_FLAG_ACTIVE
)
2178 (CHECK_FLAG(nexthop
->flags
, NEXTHOP_FLAG_FIB
)
2181 (CHECK_FLAG(nexthop
->flags
, NEXTHOP_FLAG_RECURSIVE
)
2185 zlog_debug("%s: dump complete", func
);
2188 /* This is an exported helper to rtm_read() to dump the strange
2189 * RE entry found by rib_lookup_ipv4_route()
2192 void rib_lookup_and_dump(struct prefix_ipv4
*p
, vrf_id_t vrf_id
)
2194 struct route_table
*table
;
2195 struct route_node
*rn
;
2196 struct route_entry
*re
;
2197 char prefix_buf
[INET_ADDRSTRLEN
];
2200 table
= zebra_vrf_table(AFI_IP
, SAFI_UNICAST
, vrf_id
);
2202 zlog_err("%s: zebra_vrf_table() returned NULL", __func__
);
2206 /* Scan the RIB table for exactly matching RE entry. */
2207 rn
= route_node_lookup(table
, (struct prefix
*)p
);
2209 /* No route for this prefix. */
2211 zlog_debug("%s: lookup failed for %s", __func__
,
2212 prefix2str((struct prefix
*)p
, prefix_buf
,
2213 sizeof(prefix_buf
)));
2218 route_unlock_node(rn
);
2221 RNODE_FOREACH_RE (rn
, re
) {
2222 zlog_debug("%s: rn %p, re %p: %s, %s", __func__
, (void *)rn
,
2224 (CHECK_FLAG(re
->status
, ROUTE_ENTRY_REMOVED
)
2227 (CHECK_FLAG(re
->flags
, ZEBRA_FLAG_SELECTED
)
2230 route_entry_dump(p
, NULL
, re
);
2234 /* Check if requested address assignment will fail due to another
2235 * route being installed by zebra in FIB already. Take necessary
2236 * actions, if needed: remove such a route from FIB and deSELECT
2237 * corresponding RE entry. Then put affected RN into RIBQ head.
2239 void rib_lookup_and_pushup(struct prefix_ipv4
*p
, vrf_id_t vrf_id
)
2241 struct route_table
*table
;
2242 struct route_node
*rn
;
2243 unsigned changed
= 0;
2246 if (NULL
== (table
= zebra_vrf_table(AFI_IP
, SAFI_UNICAST
, vrf_id
))) {
2247 zlog_err("%s: zebra_vrf_table() returned NULL", __func__
);
2251 /* No matches would be the simplest case. */
2252 if (NULL
== (rn
= route_node_lookup(table
, (struct prefix
*)p
)))
2256 route_unlock_node(rn
);
2258 dest
= rib_dest_from_rnode(rn
);
2259 /* Check all RE entries. In case any changes have to be done, requeue
2260 * the RN into RIBQ head. If the routing message about the new connected
2261 * route (generated by the IP address we are going to assign very soon)
2262 * comes before the RIBQ is processed, the new RE entry will join
2263 * RIBQ record already on head. This is necessary for proper
2265 * of the rest of the RE.
2267 if (dest
->selected_fib
&& !RIB_SYSTEM_ROUTE(dest
->selected_fib
)) {
2269 if (IS_ZEBRA_DEBUG_RIB
) {
2270 char buf
[PREFIX_STRLEN
];
2272 zlog_debug("%u:%s: freeing way for connected prefix",
2273 dest
->selected_fib
->vrf_id
,
2274 prefix2str(&rn
->p
, buf
, sizeof(buf
)));
2275 route_entry_dump(&rn
->p
, NULL
, dest
->selected_fib
);
2277 rib_uninstall(rn
, dest
->selected_fib
);
2283 int rib_add_multipath(afi_t afi
, safi_t safi
, struct prefix
*p
,
2284 struct prefix_ipv6
*src_p
, struct route_entry
*re
)
2286 struct route_table
*table
;
2287 struct route_node
*rn
;
2288 struct route_entry
*same
;
2289 struct nexthop
*nexthop
;
2295 assert(!src_p
|| afi
== AFI_IP6
);
2298 table
= zebra_vrf_table_with_table_id(afi
, safi
, re
->vrf_id
, re
->table
);
2300 XFREE(MTYPE_RE
, re
);
2304 /* Make it sure prefixlen is applied to the prefix. */
2307 apply_mask_ipv6(src_p
);
2309 /* Set default distance by route type. */
2310 if (re
->distance
== 0) {
2311 re
->distance
= route_distance(re
->type
);
2313 /* iBGP distance is 200. */
2314 if (re
->type
== ZEBRA_ROUTE_BGP
2315 && CHECK_FLAG(re
->flags
, ZEBRA_FLAG_IBGP
))
2319 /* Lookup route node.*/
2320 rn
= srcdest_rnode_get(table
, p
, src_p
);
2322 /* If same type of route are installed, treat it as a implicit
2324 RNODE_FOREACH_RE (rn
, same
) {
2325 if (CHECK_FLAG(same
->status
, ROUTE_ENTRY_REMOVED
))
2328 if (same
->type
!= re
->type
)
2330 if (same
->instance
!= re
->instance
)
2332 if (same
->type
== ZEBRA_ROUTE_KERNEL
&&
2333 same
->metric
!= re
->metric
)
2336 * We should allow duplicate connected routes because of
2337 * IPv6 link-local routes and unnumbered interfaces on Linux.
2339 if (same
->type
!= ZEBRA_ROUTE_CONNECT
)
2343 /* If this route is kernel route, set FIB flag to the route. */
2344 if (RIB_SYSTEM_ROUTE(re
))
2345 for (nexthop
= re
->nexthop
; nexthop
; nexthop
= nexthop
->next
)
2346 SET_FLAG(nexthop
->flags
, NEXTHOP_FLAG_FIB
);
2348 /* Link new re to node.*/
2349 if (IS_ZEBRA_DEBUG_RIB
) {
2352 "Inserting route rn %p, re %p (type %d) existing %p",
2353 (void *)rn
, (void *)re
, re
->type
, (void *)same
);
2355 if (IS_ZEBRA_DEBUG_RIB_DETAILED
)
2356 route_entry_dump(p
, src_p
, re
);
2358 rib_addnode(rn
, re
, 1);
2361 /* Free implicit route.*/
2363 rib_delnode(rn
, same
);
2367 route_unlock_node(rn
);
2371 void rib_delete(afi_t afi
, safi_t safi
, vrf_id_t vrf_id
, int type
,
2372 u_short instance
, int flags
, struct prefix
*p
,
2373 struct prefix_ipv6
*src_p
, const struct nexthop
*nh
,
2374 u_int32_t table_id
, u_int32_t metric
, bool fromkernel
,
2375 struct ethaddr
*rmac
)
2377 struct route_table
*table
;
2378 struct route_node
*rn
;
2379 struct route_entry
*re
;
2380 struct route_entry
*fib
= NULL
;
2381 struct route_entry
*same
= NULL
;
2382 struct nexthop
*rtnh
;
2383 char buf2
[INET6_ADDRSTRLEN
];
2386 assert(!src_p
|| afi
== AFI_IP6
);
2389 table
= zebra_vrf_table_with_table_id(afi
, safi
, vrf_id
, table_id
);
2396 apply_mask_ipv6(src_p
);
2398 /* Lookup route node. */
2399 rn
= srcdest_rnode_lookup(table
, p
, src_p
);
2401 char dst_buf
[PREFIX_STRLEN
], src_buf
[PREFIX_STRLEN
];
2403 prefix2str(p
, dst_buf
, sizeof(dst_buf
));
2404 if (src_p
&& src_p
->prefixlen
)
2405 prefix2str(src_p
, src_buf
, sizeof(src_buf
));
2409 if (IS_ZEBRA_DEBUG_RIB
)
2410 zlog_debug("%u:%s%s%s doesn't exist in rib", vrf_id
,
2412 (src_buf
[0] != '\0') ? " from " : "",
2417 dest
= rib_dest_from_rnode(rn
);
2418 fib
= dest
->selected_fib
;
2420 /* Lookup same type route. */
2421 RNODE_FOREACH_RE (rn
, re
) {
2422 if (CHECK_FLAG(re
->status
, ROUTE_ENTRY_REMOVED
))
2425 if (re
->type
!= type
)
2427 if (re
->instance
!= instance
)
2429 if (re
->type
== ZEBRA_ROUTE_KERNEL
&&
2430 re
->metric
!= metric
)
2432 if (re
->type
== ZEBRA_ROUTE_CONNECT
&& (rtnh
= re
->nexthop
)
2433 && rtnh
->type
== NEXTHOP_TYPE_IFINDEX
&& nh
) {
2434 if (rtnh
->ifindex
!= nh
->ifindex
)
2439 /* Make sure that the route found has the same gateway. */
2445 for (ALL_NEXTHOPS(re
->nexthop
, rtnh
))
2446 if (nexthop_same_no_recurse(rtnh
, nh
)) {
2454 /* If same type of route can't be found and this message is from
2458 * In the past(HA!) we could get here because
2459 * we were receiving a route delete from the
2460 * kernel and we're not marking the proto
2461 * as coming from it's appropriate originator.
2462 * Now that we are properly noticing the fact
2463 * that the kernel has deleted our route we
2464 * are not going to get called in this path
2465 * I am going to leave this here because
2466 * this might still work this way on non-linux
2467 * platforms as well as some weird state I have
2468 * not properly thought of yet.
2469 * If we can show that this code path is
2470 * dead then we can remove it.
2472 if (fib
&& type
== ZEBRA_ROUTE_KERNEL
2473 && CHECK_FLAG(flags
, ZEBRA_FLAG_SELFROUTE
)) {
2474 if (IS_ZEBRA_DEBUG_RIB
) {
2477 "rn %p, re %p (type %d) was deleted from kernel, adding",
2478 rn
, fib
, fib
->type
);
2482 for (rtnh
= fib
->nexthop
; rtnh
;
2484 UNSET_FLAG(rtnh
->flags
,
2488 * This is a non FRR route
2489 * as such we should mark
2492 dest
->selected_fib
= NULL
;
2494 /* This means someone else, other than Zebra,
2496 * a Zebra router from the kernel. We will add
2498 rib_install_kernel(rn
, fib
, NULL
);
2501 if (IS_ZEBRA_DEBUG_RIB
) {
2505 "via %s ifindex %d type %d "
2506 "doesn't exist in rib",
2510 INET_ADDRSTRLEN
), /* FIXME
2516 "type %d doesn't exist in rib",
2519 route_unlock_node(rn
);
2526 CHECK_FLAG(flags
, ZEBRA_FLAG_SELFROUTE
) &&
2528 rib_install_kernel(rn
, same
, NULL
);
2529 route_unlock_node(rn
);
2534 if (CHECK_FLAG(flags
, ZEBRA_FLAG_EVPN_ROUTE
)) {
2535 struct nexthop
*tmp_nh
;
2537 for (ALL_NEXTHOPS(re
->nexthop
, tmp_nh
)) {
2538 struct ipaddr vtep_ip
;
2540 memset(&vtep_ip
, 0, sizeof(struct ipaddr
));
2541 vtep_ip
.ipa_type
= IPADDR_V4
;
2542 memcpy(&(vtep_ip
.ipaddr_v4
),
2543 &(tmp_nh
->gate
.ipv4
),
2544 sizeof(struct in_addr
));
2545 zebra_vxlan_evpn_vrf_route_del(re
->vrf_id
, rmac
,
2549 rib_delnode(rn
, same
);
2552 route_unlock_node(rn
);
2557 int rib_add(afi_t afi
, safi_t safi
, vrf_id_t vrf_id
, vrf_id_t nh_vrf_id
,
2558 int type
, u_short instance
, int flags
, struct prefix
*p
,
2559 struct prefix_ipv6
*src_p
, const struct nexthop
*nh
,
2560 u_int32_t table_id
, u_int32_t metric
,
2561 u_int32_t mtu
, uint8_t distance
, route_tag_t tag
)
2563 struct route_entry
*re
;
2564 struct nexthop
*nexthop
;
2566 /* Allocate new route_entry structure. */
2567 re
= XCALLOC(MTYPE_RE
, sizeof(struct route_entry
));
2569 re
->instance
= instance
;
2570 re
->distance
= distance
;
2572 re
->metric
= metric
;
2574 re
->table
= table_id
;
2575 re
->vrf_id
= vrf_id
;
2576 re
->nh_vrf_id
= nh_vrf_id
;
2577 re
->nexthop_num
= 0;
2578 re
->uptime
= time(NULL
);
2582 nexthop
= nexthop_new();
2584 route_entry_nexthop_add(re
, nexthop
);
2586 return rib_add_multipath(afi
, safi
, p
, src_p
, re
);
2589 /* Schedule routes of a particular table (address-family) based on event. */
2590 static void rib_update_table(struct route_table
*table
,
2591 rib_update_event_t event
)
2593 struct route_node
*rn
;
2594 struct route_entry
*re
, *next
;
2596 /* Walk all routes and queue for processing, if appropriate for
2597 * the trigger event.
2599 for (rn
= route_top(table
); rn
; rn
= srcdest_route_next(rn
)) {
2601 * If we are looking at a route node and the node
2602 * has already been queued we don't
2603 * need to queue it up again
2606 && CHECK_FLAG(rib_dest_from_rnode(rn
)->flags
,
2607 RIB_ROUTE_ANY_QUEUED
))
2610 case RIB_UPDATE_IF_CHANGE
:
2611 /* Examine all routes that won't get processed by the
2613 * triggered by nexthop evaluation (NHT). This would be
2615 * kernel and certain static routes. Note that NHT will
2617 * triggered upon an interface event as connected routes
2619 * get queued for processing.
2621 RNODE_FOREACH_RE_SAFE (rn
, re
, next
) {
2624 if (re
->type
!= ZEBRA_ROUTE_SYSTEM
&&
2625 re
->type
!= ZEBRA_ROUTE_KERNEL
&&
2626 re
->type
!= ZEBRA_ROUTE_CONNECT
&&
2627 re
->type
!= ZEBRA_ROUTE_STATIC
)
2630 if (re
->type
!= ZEBRA_ROUTE_STATIC
) {
2635 for (nh
= re
->nexthop
; nh
; nh
= nh
->next
)
2636 if (!(nh
->type
== NEXTHOP_TYPE_IPV4
2637 || nh
->type
== NEXTHOP_TYPE_IPV6
))
2640 /* If we only have nexthops to a
2649 case RIB_UPDATE_RMAP_CHANGE
:
2650 case RIB_UPDATE_OTHER
:
2651 /* Right now, examine all routes. Can restrict to a
2653 * some cases (TODO).
2655 if (rnode_to_ribs(rn
))
2665 /* RIB update function. */
2666 void rib_update(vrf_id_t vrf_id
, rib_update_event_t event
)
2668 struct route_table
*table
;
2670 /* Process routes of interested address-families. */
2671 table
= zebra_vrf_table(AFI_IP
, SAFI_UNICAST
, vrf_id
);
2673 rib_update_table(table
, event
);
2675 table
= zebra_vrf_table(AFI_IP6
, SAFI_UNICAST
, vrf_id
);
2677 rib_update_table(table
, event
);
2680 /* Remove all routes which comes from non main table. */
2681 static void rib_weed_table(struct route_table
*table
)
2683 struct route_node
*rn
;
2684 struct route_entry
*re
;
2685 struct route_entry
*next
;
2688 for (rn
= route_top(table
); rn
; rn
= srcdest_route_next(rn
))
2689 RNODE_FOREACH_RE_SAFE (rn
, re
, next
) {
2690 if (CHECK_FLAG(re
->status
, ROUTE_ENTRY_REMOVED
))
2693 if (re
->table
!= zebrad
.rtm_table_default
2694 && re
->table
!= RT_TABLE_MAIN
)
2695 rib_delnode(rn
, re
);
2699 /* Delete all routes from non main table. */
2700 void rib_weed_tables(void)
2703 struct zebra_vrf
*zvrf
;
2705 RB_FOREACH (vrf
, vrf_id_head
, &vrfs_by_id
)
2706 if ((zvrf
= vrf
->info
) != NULL
) {
2707 rib_weed_table(zvrf
->table
[AFI_IP
][SAFI_UNICAST
]);
2708 rib_weed_table(zvrf
->table
[AFI_IP6
][SAFI_UNICAST
]);
2712 /* Delete self installed routes after zebra is relaunched. */
2713 static void rib_sweep_table(struct route_table
*table
)
2715 struct route_node
*rn
;
2716 struct route_entry
*re
;
2717 struct route_entry
*next
;
2718 struct nexthop
*nexthop
;
2723 for (rn
= route_top(table
); rn
; rn
= srcdest_route_next(rn
)) {
2724 RNODE_FOREACH_RE_SAFE (rn
, re
, next
) {
2725 if (IS_ZEBRA_DEBUG_RIB
)
2726 route_entry_dump(&rn
->p
, NULL
, re
);
2728 if (CHECK_FLAG(re
->status
, ROUTE_ENTRY_REMOVED
))
2731 if (!CHECK_FLAG(re
->flags
, ZEBRA_FLAG_SELFROUTE
))
2735 * So we are starting up and have received
2736 * routes from the kernel that we have installed
2737 * from a previous run of zebra but not cleaned
2738 * up ( say a kill -9 )
2739 * But since we haven't actually installed
2740 * them yet( we received them from the kernel )
2741 * we don't think they are active.
2742 * So let's pretend they are active to actually
2744 * In all honesty I'm not sure if we should
2745 * mark them as active when we receive them
2746 * This is startup only so probably ok.
2748 * If we ever decide to move rib_sweep_table
2749 * to a different spot (ie startup )
2750 * this decision needs to be revisited
2752 for (ALL_NEXTHOPS(re
->nexthop
, nexthop
))
2753 SET_FLAG(nexthop
->flags
, NEXTHOP_FLAG_FIB
);
2755 rib_uninstall_kernel(rn
, re
);
2756 rib_delnode(rn
, re
);
2761 /* Sweep all RIB tables. */
2762 void rib_sweep_route(void)
2765 struct zebra_vrf
*zvrf
;
2767 RB_FOREACH (vrf
, vrf_id_head
, &vrfs_by_id
) {
2768 if ((zvrf
= vrf
->info
) == NULL
)
2771 rib_sweep_table(zvrf
->table
[AFI_IP
][SAFI_UNICAST
]);
2772 rib_sweep_table(zvrf
->table
[AFI_IP6
][SAFI_UNICAST
]);
2776 /* Remove specific by protocol routes from 'table'. */
2777 static unsigned long rib_score_proto_table(u_char proto
, u_short instance
,
2778 struct route_table
*table
)
2780 struct route_node
*rn
;
2781 struct route_entry
*re
;
2782 struct route_entry
*next
;
2783 unsigned long n
= 0;
2786 for (rn
= route_top(table
); rn
; rn
= srcdest_route_next(rn
))
2787 RNODE_FOREACH_RE_SAFE (rn
, re
, next
) {
2788 if (CHECK_FLAG(re
->status
, ROUTE_ENTRY_REMOVED
))
2790 if (re
->type
== proto
2791 && re
->instance
== instance
) {
2792 rib_delnode(rn
, re
);
2799 /* Remove specific by protocol routes. */
2800 unsigned long rib_score_proto(u_char proto
, u_short instance
)
2803 struct zebra_vrf
*zvrf
;
2804 unsigned long cnt
= 0;
2806 RB_FOREACH (vrf
, vrf_id_head
, &vrfs_by_id
)
2807 if ((zvrf
= vrf
->info
) != NULL
)
2808 cnt
+= rib_score_proto_table(
2810 zvrf
->table
[AFI_IP
][SAFI_UNICAST
])
2811 + rib_score_proto_table(
2813 zvrf
->table
[AFI_IP6
][SAFI_UNICAST
]);
2818 /* Close RIB and clean up kernel routes. */
2819 void rib_close_table(struct route_table
*table
)
2821 struct route_node
*rn
;
2822 rib_table_info_t
*info
;
2830 for (rn
= route_top(table
); rn
; rn
= srcdest_route_next(rn
)) {
2831 dest
= rib_dest_from_rnode(rn
);
2833 if (dest
&& dest
->selected_fib
) {
2834 if (info
->safi
== SAFI_UNICAST
)
2835 hook_call(rib_update
, rn
, NULL
);
2837 if (!RIB_SYSTEM_ROUTE(dest
->selected_fib
))
2838 rib_uninstall_kernel(rn
, dest
->selected_fib
);
2843 /* Routing information base initialize. */
2846 rib_queue_init(&zebrad
);
2852 * Get the first vrf id that is greater than the given vrf id if any.
2854 * Returns TRUE if a vrf id was found, FALSE otherwise.
2856 static inline int vrf_id_get_next(vrf_id_t vrf_id
, vrf_id_t
*next_id_p
)
2860 vrf
= vrf_lookup_by_id(vrf_id
);
2862 vrf
= RB_NEXT(vrf_id_head
, vrf
);
2864 *next_id_p
= vrf
->vrf_id
;
2873 * rib_tables_iter_next
2875 * Returns the next table in the iteration.
2877 struct route_table
*rib_tables_iter_next(rib_tables_iter_t
*iter
)
2879 struct route_table
*table
;
2882 * Array that helps us go over all AFI/SAFI combinations via one
2889 {AFI_IP
, SAFI_UNICAST
}, {AFI_IP
, SAFI_MULTICAST
},
2890 {AFI_IP
, SAFI_LABELED_UNICAST
}, {AFI_IP6
, SAFI_UNICAST
},
2891 {AFI_IP6
, SAFI_MULTICAST
}, {AFI_IP6
, SAFI_LABELED_UNICAST
},
2896 switch (iter
->state
) {
2898 case RIB_TABLES_ITER_S_INIT
:
2899 iter
->vrf_id
= VRF_DEFAULT
;
2900 iter
->afi_safi_ix
= -1;
2904 case RIB_TABLES_ITER_S_ITERATING
:
2905 iter
->afi_safi_ix
++;
2908 while (iter
->afi_safi_ix
2909 < (int)ZEBRA_NUM_OF(afi_safis
)) {
2910 table
= zebra_vrf_table(
2911 afi_safis
[iter
->afi_safi_ix
].afi
,
2912 afi_safis
[iter
->afi_safi_ix
].safi
,
2917 iter
->afi_safi_ix
++;
2921 * Found another table in this vrf.
2927 * Done with all tables in the current vrf, go to the
2931 if (!vrf_id_get_next(iter
->vrf_id
, &iter
->vrf_id
))
2934 iter
->afi_safi_ix
= 0;
2939 case RIB_TABLES_ITER_S_DONE
:
2944 iter
->state
= RIB_TABLES_ITER_S_ITERATING
;
2946 iter
->state
= RIB_TABLES_ITER_S_DONE
;