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},
89 [ZEBRA_ROUTE_SHARP
] = {ZEBRA_ROUTE_SHARP
, 150},
91 /* no entry/default: 150 */
94 /* RPF lookup behaviour */
95 static enum multicast_mode ipv4_multicast_mode
= MCAST_NO_CONFIG
;
98 static void __attribute__((format(printf
, 5, 6)))
99 _rnode_zlog(const char *_func
, vrf_id_t vrf_id
, struct route_node
*rn
,
100 int priority
, const char *msgfmt
, ...)
102 char buf
[SRCDEST2STR_BUFFER
+ sizeof(" (MRIB)")];
106 va_start(ap
, msgfmt
);
107 vsnprintf(msgbuf
, sizeof(msgbuf
), msgfmt
, ap
);
111 rib_table_info_t
*info
= srcdest_rnode_table_info(rn
);
112 srcdest_rnode2str(rn
, buf
, sizeof(buf
));
114 if (info
->safi
== SAFI_MULTICAST
)
115 strcat(buf
, " (MRIB)");
117 snprintf(buf
, sizeof(buf
), "{(route_node *) NULL}");
120 zlog(priority
, "%s: %d:%s: %s", _func
, vrf_id
, buf
, msgbuf
);
123 #define rnode_debug(node, vrf_id, ...) \
124 _rnode_zlog(__func__, vrf_id, node, LOG_DEBUG, __VA_ARGS__)
125 #define rnode_info(node, ...) \
126 _rnode_zlog(__func__, vrf_id, node, LOG_INFO, __VA_ARGS__)
128 uint8_t route_distance(int type
)
132 if ((unsigned)type
>= array_size(route_info
))
135 distance
= route_info
[type
].distance
;
140 int is_zebra_valid_kernel_table(u_int32_t table_id
)
142 if ((table_id
> ZEBRA_KERNEL_TABLE_MAX
))
146 if ((table_id
== RT_TABLE_UNSPEC
) || (table_id
== RT_TABLE_LOCAL
)
147 || (table_id
== RT_TABLE_COMPAT
))
154 int is_zebra_main_routing_table(u_int32_t table_id
)
156 if ((table_id
== RT_TABLE_MAIN
)
157 || (table_id
== zebrad
.rtm_table_default
))
162 int zebra_check_addr(struct prefix
*p
)
164 if (p
->family
== AF_INET
) {
167 addr
= p
->u
.prefix4
.s_addr
;
170 if (IPV4_NET127(addr
) || IN_CLASSD(addr
)
171 || IPV4_LINKLOCAL(addr
))
174 if (p
->family
== AF_INET6
) {
175 if (IN6_IS_ADDR_LOOPBACK(&p
->u
.prefix6
))
177 if (IN6_IS_ADDR_LINKLOCAL(&p
->u
.prefix6
))
183 /* Add nexthop to the end of a rib node's nexthop list */
184 void route_entry_nexthop_add(struct route_entry
*re
, struct nexthop
*nexthop
)
186 nexthop_add(&re
->nexthop
, nexthop
);
192 * copy_nexthop - copy a nexthop to the rib structure.
194 void route_entry_copy_nexthops(struct route_entry
*re
, struct nexthop
*nh
)
196 assert(!re
->nexthop
);
197 copy_nexthops(&re
->nexthop
, nh
, NULL
);
198 for (struct nexthop
*nexthop
= nh
; nexthop
; nexthop
= nexthop
->next
)
202 /* Delete specified nexthop from the list. */
203 void route_entry_nexthop_delete(struct route_entry
*re
, struct nexthop
*nexthop
)
206 nexthop
->next
->prev
= nexthop
->prev
;
208 nexthop
->prev
->next
= nexthop
->next
;
210 re
->nexthop
= nexthop
->next
;
215 struct nexthop
*route_entry_nexthop_ifindex_add(struct route_entry
*re
,
219 struct nexthop
*nexthop
;
221 nexthop
= nexthop_new();
222 nexthop
->type
= NEXTHOP_TYPE_IFINDEX
;
223 nexthop
->ifindex
= ifindex
;
224 nexthop
->vrf_id
= nh_vrf_id
;
226 route_entry_nexthop_add(re
, nexthop
);
231 struct nexthop
*route_entry_nexthop_ipv4_add(struct route_entry
*re
,
232 struct in_addr
*ipv4
,
236 struct nexthop
*nexthop
;
238 nexthop
= nexthop_new();
239 nexthop
->type
= NEXTHOP_TYPE_IPV4
;
240 nexthop
->vrf_id
= nh_vrf_id
;
241 nexthop
->gate
.ipv4
= *ipv4
;
243 nexthop
->src
.ipv4
= *src
;
245 route_entry_nexthop_add(re
, nexthop
);
250 struct nexthop
*route_entry_nexthop_ipv4_ifindex_add(struct route_entry
*re
,
251 struct in_addr
*ipv4
,
256 struct nexthop
*nexthop
;
257 struct interface
*ifp
;
259 nexthop
= nexthop_new();
260 nexthop
->vrf_id
= nh_vrf_id
;
261 nexthop
->type
= NEXTHOP_TYPE_IPV4_IFINDEX
;
262 nexthop
->gate
.ipv4
= *ipv4
;
264 nexthop
->src
.ipv4
= *src
;
265 nexthop
->ifindex
= ifindex
;
266 ifp
= if_lookup_by_index(nexthop
->ifindex
, nh_vrf_id
);
267 /*Pending: need to think if null ifp here is ok during bootup?
268 There was a crash because ifp here was coming to be NULL */
270 if (connected_is_unnumbered(ifp
) ||
271 CHECK_FLAG(re
->flags
, ZEBRA_FLAG_EVPN_ROUTE
)) {
272 SET_FLAG(nexthop
->flags
, NEXTHOP_FLAG_ONLINK
);
275 route_entry_nexthop_add(re
, nexthop
);
280 struct nexthop
*route_entry_nexthop_ipv6_add(struct route_entry
*re
,
281 struct in6_addr
*ipv6
,
284 struct nexthop
*nexthop
;
286 nexthop
= nexthop_new();
287 nexthop
->vrf_id
= nh_vrf_id
;
288 nexthop
->type
= NEXTHOP_TYPE_IPV6
;
289 nexthop
->gate
.ipv6
= *ipv6
;
291 route_entry_nexthop_add(re
, nexthop
);
296 struct nexthop
*route_entry_nexthop_ipv6_ifindex_add(struct route_entry
*re
,
297 struct in6_addr
*ipv6
,
301 struct nexthop
*nexthop
;
303 nexthop
= nexthop_new();
304 nexthop
->vrf_id
= nh_vrf_id
;
305 nexthop
->type
= NEXTHOP_TYPE_IPV6_IFINDEX
;
306 nexthop
->gate
.ipv6
= *ipv6
;
307 nexthop
->ifindex
= ifindex
;
309 route_entry_nexthop_add(re
, nexthop
);
314 struct nexthop
*route_entry_nexthop_blackhole_add(struct route_entry
*re
,
315 enum blackhole_type bh_type
)
317 struct nexthop
*nexthop
;
319 nexthop
= nexthop_new();
320 nexthop
->vrf_id
= VRF_DEFAULT
;
321 nexthop
->type
= NEXTHOP_TYPE_BLACKHOLE
;
322 nexthop
->bh_type
= bh_type
;
324 route_entry_nexthop_add(re
, nexthop
);
329 static void nexthop_set_resolved(afi_t afi
, struct nexthop
*newhop
,
330 struct nexthop
*nexthop
)
332 struct nexthop
*resolved_hop
;
334 resolved_hop
= nexthop_new();
335 SET_FLAG(resolved_hop
->flags
, NEXTHOP_FLAG_ACTIVE
);
337 resolved_hop
->vrf_id
= nexthop
->vrf_id
;
338 switch (newhop
->type
) {
339 case NEXTHOP_TYPE_IPV4
:
340 case NEXTHOP_TYPE_IPV4_IFINDEX
:
341 /* If the resolving route specifies a gateway, use it */
342 resolved_hop
->type
= newhop
->type
;
343 resolved_hop
->gate
.ipv4
= newhop
->gate
.ipv4
;
345 if (newhop
->ifindex
) {
346 resolved_hop
->type
= NEXTHOP_TYPE_IPV4_IFINDEX
;
347 resolved_hop
->ifindex
= newhop
->ifindex
;
348 if (newhop
->flags
& NEXTHOP_FLAG_ONLINK
)
349 resolved_hop
->flags
|= NEXTHOP_FLAG_ONLINK
;
352 case NEXTHOP_TYPE_IPV6
:
353 case NEXTHOP_TYPE_IPV6_IFINDEX
:
354 resolved_hop
->type
= newhop
->type
;
355 resolved_hop
->gate
.ipv6
= newhop
->gate
.ipv6
;
357 if (newhop
->ifindex
) {
358 resolved_hop
->type
= NEXTHOP_TYPE_IPV6_IFINDEX
;
359 resolved_hop
->ifindex
= newhop
->ifindex
;
362 case NEXTHOP_TYPE_IFINDEX
:
363 /* If the resolving route is an interface route,
364 * it means the gateway we are looking up is connected
365 * to that interface. (The actual network is _not_ onlink).
366 * Therefore, the resolved route should have the original
367 * gateway as nexthop as it is directly connected.
369 * On Linux, we have to set the onlink netlink flag because
370 * otherwise, the kernel won't accept the route.
372 resolved_hop
->flags
|= NEXTHOP_FLAG_ONLINK
;
374 resolved_hop
->type
= NEXTHOP_TYPE_IPV4_IFINDEX
;
375 resolved_hop
->gate
.ipv4
= nexthop
->gate
.ipv4
;
376 } else if (afi
== AFI_IP6
) {
377 resolved_hop
->type
= NEXTHOP_TYPE_IPV6_IFINDEX
;
378 resolved_hop
->gate
.ipv6
= nexthop
->gate
.ipv6
;
380 resolved_hop
->ifindex
= newhop
->ifindex
;
382 case NEXTHOP_TYPE_BLACKHOLE
:
383 resolved_hop
->type
= NEXTHOP_TYPE_BLACKHOLE
;
384 resolved_hop
->bh_type
= nexthop
->bh_type
;
388 /* Copy labels of the resolved route */
389 if (newhop
->nh_label
)
390 nexthop_add_labels(resolved_hop
, newhop
->nh_label_type
,
391 newhop
->nh_label
->num_labels
,
392 &newhop
->nh_label
->label
[0]);
394 resolved_hop
->rparent
= nexthop
;
395 nexthop_add(&nexthop
->resolved
, resolved_hop
);
398 /* If force flag is not set, do not modify falgs at all for uninstall
399 the route from FIB. */
400 static int nexthop_active(afi_t afi
, struct route_entry
*re
,
401 struct nexthop
*nexthop
, int set
,
402 struct route_node
*top
)
405 struct route_table
*table
;
406 struct route_node
*rn
;
407 struct route_entry
*match
= NULL
;
409 struct nexthop
*newhop
;
410 struct interface
*ifp
;
413 if ((nexthop
->type
== NEXTHOP_TYPE_IPV4
)
414 || nexthop
->type
== NEXTHOP_TYPE_IPV6
)
415 nexthop
->ifindex
= 0;
418 UNSET_FLAG(nexthop
->flags
, NEXTHOP_FLAG_RECURSIVE
);
419 zebra_deregister_rnh_static_nexthops(nexthop
->vrf_id
,
420 nexthop
->resolved
, top
);
421 nexthops_free(nexthop
->resolved
);
422 nexthop
->resolved
= NULL
;
426 /* Skip nexthops that have been filtered out due to route-map */
427 /* The nexthops are specific to this route and so the same */
428 /* nexthop for a different route may not have this flag set */
429 if (CHECK_FLAG(nexthop
->flags
, NEXTHOP_FLAG_FILTERED
))
433 * Check to see if we should trust the passed in information
434 * for UNNUMBERED interfaces as that we won't find the GW
435 * address in the routing table.
437 if (CHECK_FLAG(nexthop
->flags
, NEXTHOP_FLAG_ONLINK
)) {
438 ifp
= if_lookup_by_index(nexthop
->ifindex
, nexthop
->vrf_id
);
439 if (ifp
&& connected_is_unnumbered(ifp
)) {
440 if (if_is_operative(ifp
))
448 /* Make lookup prefix. */
449 memset(&p
, 0, sizeof(struct prefix
));
453 p
.prefixlen
= IPV4_MAX_PREFIXLEN
;
454 p
.u
.prefix4
= nexthop
->gate
.ipv4
;
458 p
.prefixlen
= IPV6_MAX_PREFIXLEN
;
459 p
.u
.prefix6
= nexthop
->gate
.ipv6
;
462 assert(afi
!= AFI_IP
&& afi
!= AFI_IP6
);
466 table
= zebra_vrf_table(afi
, SAFI_UNICAST
, nexthop
->vrf_id
);
470 rn
= route_node_match(table
, (struct prefix
*)&p
);
472 route_unlock_node(rn
);
474 /* Lookup should halt if we've matched against ourselves ('top',
475 * if specified) - i.e., we cannot have a nexthop NH1 is
476 * resolved by a route NH1. The exception is if the route is a
479 if (top
&& rn
== top
)
480 if (((afi
== AFI_IP
) && (rn
->p
.prefixlen
!= 32)) ||
481 ((afi
== AFI_IP6
) && (rn
->p
.prefixlen
!= 128)))
484 /* Pick up selected route. */
485 /* However, do not resolve over default route unless explicitly
487 if (is_default_prefix(&rn
->p
)
488 && !rnh_resolve_via_default(p
.family
))
491 dest
= rib_dest_from_rnode(rn
);
492 if (dest
&& dest
->selected_fib
&&
493 !CHECK_FLAG(dest
->selected_fib
->status
,
494 ROUTE_ENTRY_REMOVED
) &&
495 dest
->selected_fib
->type
!= ZEBRA_ROUTE_TABLE
)
496 match
= dest
->selected_fib
;
498 /* If there is no selected route or matched route is EGP, go up
503 } while (rn
&& rn
->info
== NULL
);
510 if (match
->type
== ZEBRA_ROUTE_CONNECT
) {
511 /* Directly point connected route. */
512 newhop
= match
->nexthop
;
514 if (nexthop
->type
== NEXTHOP_TYPE_IPV4
515 || nexthop
->type
== NEXTHOP_TYPE_IPV6
)
516 nexthop
->ifindex
= newhop
->ifindex
;
519 } else if (CHECK_FLAG(re
->flags
, ZEBRA_FLAG_INTERNAL
)) {
521 for (ALL_NEXTHOPS(match
->nexthop
, newhop
)) {
522 if (!CHECK_FLAG(newhop
->flags
,
525 if (CHECK_FLAG(newhop
->flags
,
526 NEXTHOP_FLAG_RECURSIVE
))
530 SET_FLAG(nexthop
->flags
,
531 NEXTHOP_FLAG_RECURSIVE
);
533 ROUTE_ENTRY_NEXTHOPS_CHANGED
);
534 nexthop_set_resolved(afi
, newhop
,
540 re
->nexthop_mtu
= match
->mtu
;
542 } else if (re
->type
== ZEBRA_ROUTE_STATIC
) {
544 for (ALL_NEXTHOPS(match
->nexthop
, newhop
)) {
545 if (!CHECK_FLAG(newhop
->flags
,
550 SET_FLAG(nexthop
->flags
,
551 NEXTHOP_FLAG_RECURSIVE
);
552 nexthop_set_resolved(afi
, newhop
,
558 re
->nexthop_mtu
= match
->mtu
;
567 struct route_entry
*rib_match(afi_t afi
, safi_t safi
, vrf_id_t vrf_id
,
568 union g_addr
*addr
, struct route_node
**rn_out
)
571 struct route_table
*table
;
572 struct route_node
*rn
;
573 struct route_entry
*match
= NULL
;
574 struct nexthop
*newhop
;
577 table
= zebra_vrf_table(afi
, safi
, vrf_id
);
581 memset(&p
, 0, sizeof(struct prefix
));
584 p
.u
.prefix4
= addr
->ipv4
;
585 p
.prefixlen
= IPV4_MAX_PREFIXLEN
;
587 p
.u
.prefix6
= addr
->ipv6
;
588 p
.prefixlen
= IPV6_MAX_PREFIXLEN
;
591 rn
= route_node_match(table
, (struct prefix
*)&p
);
596 route_unlock_node(rn
);
598 dest
= rib_dest_from_rnode(rn
);
599 if (dest
&& dest
->selected_fib
&&
600 !CHECK_FLAG(dest
->selected_fib
->status
, ROUTE_ENTRY_REMOVED
))
601 match
= dest
->selected_fib
;
603 /* If there is no selected route or matched route is EGP, go up
608 } while (rn
&& rn
->info
== NULL
);
612 if (match
->type
!= ZEBRA_ROUTE_CONNECT
) {
614 for (ALL_NEXTHOPS(match
->nexthop
, newhop
))
615 if (CHECK_FLAG(newhop
->flags
,
632 struct route_entry
*rib_match_ipv4_multicast(vrf_id_t vrf_id
,
634 struct route_node
**rn_out
)
636 struct route_entry
*re
= NULL
, *mre
= NULL
, *ure
= NULL
;
637 struct route_node
*m_rn
= NULL
, *u_rn
= NULL
;
638 union g_addr gaddr
= {.ipv4
= addr
};
640 switch (ipv4_multicast_mode
) {
641 case MCAST_MRIB_ONLY
:
642 return rib_match(AFI_IP
, SAFI_MULTICAST
, vrf_id
, &gaddr
,
644 case MCAST_URIB_ONLY
:
645 return rib_match(AFI_IP
, SAFI_UNICAST
, vrf_id
, &gaddr
, rn_out
);
646 case MCAST_NO_CONFIG
:
647 case MCAST_MIX_MRIB_FIRST
:
648 re
= mre
= rib_match(AFI_IP
, SAFI_MULTICAST
, vrf_id
, &gaddr
,
651 re
= ure
= rib_match(AFI_IP
, SAFI_UNICAST
, vrf_id
,
654 case MCAST_MIX_DISTANCE
:
655 mre
= rib_match(AFI_IP
, SAFI_MULTICAST
, vrf_id
, &gaddr
, &m_rn
);
656 ure
= rib_match(AFI_IP
, SAFI_UNICAST
, vrf_id
, &gaddr
, &u_rn
);
658 re
= ure
->distance
< mre
->distance
? ure
: mre
;
664 case MCAST_MIX_PFXLEN
:
665 mre
= rib_match(AFI_IP
, SAFI_MULTICAST
, vrf_id
, &gaddr
, &m_rn
);
666 ure
= rib_match(AFI_IP
, SAFI_UNICAST
, vrf_id
, &gaddr
, &u_rn
);
668 re
= u_rn
->p
.prefixlen
> m_rn
->p
.prefixlen
? ure
: mre
;
677 *rn_out
= (re
== mre
) ? m_rn
: u_rn
;
679 if (IS_ZEBRA_DEBUG_RIB
) {
681 inet_ntop(AF_INET
, &addr
, buf
, BUFSIZ
);
683 zlog_debug("%s: %s: found %s, using %s", __func__
, buf
,
684 mre
? (ure
? "MRIB+URIB" : "MRIB")
685 : ure
? "URIB" : "nothing",
686 re
== ure
? "URIB" : re
== mre
? "MRIB" : "none");
691 void multicast_mode_ipv4_set(enum multicast_mode mode
)
693 if (IS_ZEBRA_DEBUG_RIB
)
694 zlog_debug("%s: multicast lookup mode set (%d)", __func__
,
696 ipv4_multicast_mode
= mode
;
699 enum multicast_mode
multicast_mode_ipv4_get(void)
701 return ipv4_multicast_mode
;
704 struct route_entry
*rib_lookup_ipv4(struct prefix_ipv4
*p
, vrf_id_t vrf_id
)
706 struct route_table
*table
;
707 struct route_node
*rn
;
708 struct route_entry
*match
= NULL
;
709 struct nexthop
*nexthop
;
713 table
= zebra_vrf_table(AFI_IP
, SAFI_UNICAST
, vrf_id
);
717 rn
= route_node_lookup(table
, (struct prefix
*)p
);
719 /* No route for this prefix. */
724 route_unlock_node(rn
);
725 dest
= rib_dest_from_rnode(rn
);
727 if (dest
&& dest
->selected_fib
&&
728 !CHECK_FLAG(dest
->selected_fib
->status
, ROUTE_ENTRY_REMOVED
))
729 match
= dest
->selected_fib
;
734 if (match
->type
== ZEBRA_ROUTE_CONNECT
)
737 for (ALL_NEXTHOPS(match
->nexthop
, nexthop
))
738 if (CHECK_FLAG(nexthop
->flags
, NEXTHOP_FLAG_FIB
))
745 * This clone function, unlike its original rib_lookup_ipv4(), checks
746 * if specified IPv4 route record (prefix/mask -> gate) exists in
747 * the whole RIB and has ROUTE_ENTRY_SELECTED_FIB set.
751 * 0: exact match found
752 * 1: a match was found with a different gate
753 * 2: connected route found
754 * 3: no matches found
756 int rib_lookup_ipv4_route(struct prefix_ipv4
*p
, union sockunion
*qgate
,
759 struct route_table
*table
;
760 struct route_node
*rn
;
761 struct route_entry
*match
= NULL
;
762 struct nexthop
*nexthop
;
767 table
= zebra_vrf_table(AFI_IP
, SAFI_UNICAST
, vrf_id
);
769 return ZEBRA_RIB_LOOKUP_ERROR
;
771 /* Scan the RIB table for exactly matching RIB entry. */
772 rn
= route_node_lookup(table
, (struct prefix
*)p
);
774 /* No route for this prefix. */
776 return ZEBRA_RIB_NOTFOUND
;
779 route_unlock_node(rn
);
780 dest
= rib_dest_from_rnode(rn
);
782 /* Find out if a "selected" RR for the discovered RIB entry exists ever.
784 if (dest
&& dest
->selected_fib
&&
785 !CHECK_FLAG(dest
->selected_fib
->status
, ROUTE_ENTRY_REMOVED
))
786 match
= dest
->selected_fib
;
788 /* None such found :( */
790 return ZEBRA_RIB_NOTFOUND
;
792 if (match
->type
== ZEBRA_ROUTE_CONNECT
)
793 return ZEBRA_RIB_FOUND_CONNECTED
;
795 /* Ok, we have a cood candidate, let's check it's nexthop list... */
797 for (ALL_NEXTHOPS(match
->nexthop
, nexthop
))
798 if (CHECK_FLAG(nexthop
->flags
, NEXTHOP_FLAG_FIB
)) {
800 if (nexthop
->gate
.ipv4
.s_addr
== sockunion2ip(qgate
))
801 return ZEBRA_RIB_FOUND_EXACT
;
802 if (IS_ZEBRA_DEBUG_RIB
) {
803 char gate_buf
[INET_ADDRSTRLEN
],
804 qgate_buf
[INET_ADDRSTRLEN
];
805 inet_ntop(AF_INET
, &nexthop
->gate
.ipv4
.s_addr
,
806 gate_buf
, INET_ADDRSTRLEN
);
807 inet_ntop(AF_INET
, &sockunion2ip(qgate
),
808 qgate_buf
, INET_ADDRSTRLEN
);
809 zlog_debug("%s: qgate == %s, %s == %s",
811 nexthop
->rparent
? "rgate" : "gate",
817 return ZEBRA_RIB_FOUND_NOGATE
;
819 return ZEBRA_RIB_NOTFOUND
;
822 #define RIB_SYSTEM_ROUTE(R) \
823 ((R)->type == ZEBRA_ROUTE_KERNEL || (R)->type == ZEBRA_ROUTE_CONNECT)
825 /* This function verifies reachability of one given nexthop, which can be
826 * numbered or unnumbered, IPv4 or IPv6. The result is unconditionally stored
827 * in nexthop->flags field. If the 4th parameter, 'set', is non-zero,
828 * nexthop->ifindex will be updated appropriately as well.
829 * An existing route map can turn (otherwise active) nexthop into inactive, but
832 * The return value is the final value of 'ACTIVE' flag.
835 static unsigned nexthop_active_check(struct route_node
*rn
,
836 struct route_entry
*re
,
837 struct nexthop
*nexthop
, int set
)
839 struct interface
*ifp
;
840 route_map_result_t ret
= RMAP_MATCH
;
842 char buf
[SRCDEST2STR_BUFFER
];
843 struct prefix
*p
, *src_p
;
844 srcdest_rnode_prefixes(rn
, &p
, &src_p
);
846 if (rn
->p
.family
== AF_INET
)
848 else if (rn
->p
.family
== AF_INET6
)
852 switch (nexthop
->type
) {
853 case NEXTHOP_TYPE_IFINDEX
:
854 ifp
= if_lookup_by_index(nexthop
->ifindex
, nexthop
->vrf_id
);
855 if (ifp
&& if_is_operative(ifp
))
856 SET_FLAG(nexthop
->flags
, NEXTHOP_FLAG_ACTIVE
);
858 UNSET_FLAG(nexthop
->flags
, NEXTHOP_FLAG_ACTIVE
);
860 case NEXTHOP_TYPE_IPV4
:
861 case NEXTHOP_TYPE_IPV4_IFINDEX
:
863 if (CHECK_FLAG(nexthop
->flags
, NEXTHOP_FLAG_EVPN_RVTEP
))
864 SET_FLAG(nexthop
->flags
, NEXTHOP_FLAG_ACTIVE
);
865 else if (nexthop_active(AFI_IP
, re
, nexthop
, set
, rn
))
866 SET_FLAG(nexthop
->flags
, NEXTHOP_FLAG_ACTIVE
);
868 UNSET_FLAG(nexthop
->flags
, NEXTHOP_FLAG_ACTIVE
);
870 case NEXTHOP_TYPE_IPV6
:
872 if (nexthop_active(AFI_IP6
, re
, nexthop
, set
, rn
))
873 SET_FLAG(nexthop
->flags
, NEXTHOP_FLAG_ACTIVE
);
875 UNSET_FLAG(nexthop
->flags
, NEXTHOP_FLAG_ACTIVE
);
877 case NEXTHOP_TYPE_IPV6_IFINDEX
:
878 /* RFC 5549, v4 prefix with v6 NH */
879 if (rn
->p
.family
!= AF_INET
)
881 if (IN6_IS_ADDR_LINKLOCAL(&nexthop
->gate
.ipv6
)) {
882 ifp
= if_lookup_by_index(nexthop
->ifindex
,
884 if (ifp
&& if_is_operative(ifp
))
885 SET_FLAG(nexthop
->flags
, NEXTHOP_FLAG_ACTIVE
);
887 UNSET_FLAG(nexthop
->flags
, NEXTHOP_FLAG_ACTIVE
);
889 if (nexthop_active(AFI_IP6
, re
, nexthop
, set
, rn
))
890 SET_FLAG(nexthop
->flags
, NEXTHOP_FLAG_ACTIVE
);
892 UNSET_FLAG(nexthop
->flags
, NEXTHOP_FLAG_ACTIVE
);
895 case NEXTHOP_TYPE_BLACKHOLE
:
896 SET_FLAG(nexthop
->flags
, NEXTHOP_FLAG_ACTIVE
);
901 if (!CHECK_FLAG(nexthop
->flags
, NEXTHOP_FLAG_ACTIVE
))
904 /* XXX: What exactly do those checks do? Do we support
905 * e.g. IPv4 routes with IPv6 nexthops or vice versa? */
906 if (RIB_SYSTEM_ROUTE(re
) || (family
== AFI_IP
&& p
->family
!= AF_INET
)
907 || (family
== AFI_IP6
&& p
->family
!= AF_INET6
))
908 return CHECK_FLAG(nexthop
->flags
, NEXTHOP_FLAG_ACTIVE
);
910 /* The original code didn't determine the family correctly
911 * e.g. for NEXTHOP_TYPE_IFINDEX. Retrieve the correct afi
912 * from the rib_table_info in those cases.
913 * Possibly it may be better to use only the rib_table_info
917 rib_table_info_t
*info
;
919 info
= srcdest_rnode_table_info(rn
);
923 memset(&nexthop
->rmap_src
.ipv6
, 0, sizeof(union g_addr
));
925 /* It'll get set if required inside */
926 ret
= zebra_route_map_check(family
, re
->type
, p
, nexthop
,
927 nexthop
->vrf_id
, re
->tag
);
928 if (ret
== RMAP_DENYMATCH
) {
929 if (IS_ZEBRA_DEBUG_RIB
) {
930 srcdest_rnode2str(rn
, buf
, sizeof(buf
));
932 "%u:%s: Filtering out with NH out %s due to route map",
934 ifindex2ifname(nexthop
->ifindex
,
937 UNSET_FLAG(nexthop
->flags
, NEXTHOP_FLAG_ACTIVE
);
939 return CHECK_FLAG(nexthop
->flags
, NEXTHOP_FLAG_ACTIVE
);
942 /* Iterate over all nexthops of the given RIB entry and refresh their
943 * ACTIVE flag. re->nexthop_active_num is updated accordingly. If any
944 * nexthop is found to toggle the ACTIVE flag, the whole re structure
945 * is flagged with ROUTE_ENTRY_CHANGED. The 4th 'set' argument is
946 * transparently passed to nexthop_active_check().
948 * Return value is the new number of active nexthops.
951 static int nexthop_active_update(struct route_node
*rn
, struct route_entry
*re
,
954 struct nexthop
*nexthop
;
955 union g_addr prev_src
;
956 unsigned int prev_active
, new_active
, old_num_nh
;
957 ifindex_t prev_index
;
958 old_num_nh
= re
->nexthop_active_num
;
960 re
->nexthop_active_num
= 0;
961 UNSET_FLAG(re
->status
, ROUTE_ENTRY_CHANGED
);
963 for (nexthop
= re
->nexthop
; nexthop
; nexthop
= nexthop
->next
) {
964 /* No protocol daemon provides src and so we're skipping
966 prev_src
= nexthop
->rmap_src
;
967 prev_active
= CHECK_FLAG(nexthop
->flags
, NEXTHOP_FLAG_ACTIVE
);
968 prev_index
= nexthop
->ifindex
;
969 if ((new_active
= nexthop_active_check(rn
, re
, nexthop
, set
)))
970 re
->nexthop_active_num
++;
971 /* Don't allow src setting on IPv6 addr for now */
972 if (prev_active
!= new_active
|| prev_index
!= nexthop
->ifindex
973 || ((nexthop
->type
>= NEXTHOP_TYPE_IFINDEX
974 && nexthop
->type
< NEXTHOP_TYPE_IPV6
)
975 && prev_src
.ipv4
.s_addr
976 != nexthop
->rmap_src
.ipv4
.s_addr
)
977 || ((nexthop
->type
>= NEXTHOP_TYPE_IPV6
978 && nexthop
->type
< NEXTHOP_TYPE_BLACKHOLE
)
979 && !(IPV6_ADDR_SAME(&prev_src
.ipv6
,
980 &nexthop
->rmap_src
.ipv6
)))) {
981 SET_FLAG(re
->status
, ROUTE_ENTRY_CHANGED
);
982 SET_FLAG(re
->status
, ROUTE_ENTRY_NEXTHOPS_CHANGED
);
986 if (old_num_nh
!= re
->nexthop_active_num
)
987 SET_FLAG(re
->status
, ROUTE_ENTRY_CHANGED
);
989 if (CHECK_FLAG(re
->status
, ROUTE_ENTRY_CHANGED
)) {
990 SET_FLAG(re
->status
, ROUTE_ENTRY_NEXTHOPS_CHANGED
);
993 return re
->nexthop_active_num
;
997 * Is this RIB labeled-unicast? It must be of type BGP and all paths
998 * (nexthops) must have a label.
1000 int zebra_rib_labeled_unicast(struct route_entry
*re
)
1002 struct nexthop
*nexthop
= NULL
;
1004 if (re
->type
!= ZEBRA_ROUTE_BGP
)
1007 for (ALL_NEXTHOPS(re
->nexthop
, nexthop
))
1008 if (!nexthop
->nh_label
|| !nexthop
->nh_label
->num_labels
)
1014 void kernel_route_rib_pass_fail(struct route_node
*rn
, struct prefix
*p
,
1015 struct route_entry
*re
,
1016 enum southbound_results res
)
1018 struct nexthop
*nexthop
;
1019 char buf
[PREFIX_STRLEN
];
1022 dest
= rib_dest_from_rnode(rn
);
1025 case SOUTHBOUND_INSTALL_SUCCESS
:
1026 dest
->selected_fib
= re
;
1027 for (ALL_NEXTHOPS(re
->nexthop
, nexthop
)) {
1028 if (CHECK_FLAG(nexthop
->flags
, NEXTHOP_FLAG_RECURSIVE
))
1031 if (CHECK_FLAG(nexthop
->flags
, NEXTHOP_FLAG_ACTIVE
))
1032 SET_FLAG(nexthop
->flags
, NEXTHOP_FLAG_FIB
);
1034 UNSET_FLAG(nexthop
->flags
, NEXTHOP_FLAG_FIB
);
1036 zsend_route_notify_owner(re
->type
, re
->instance
, re
->vrf_id
,
1037 p
, ZAPI_ROUTE_INSTALLED
);
1039 case SOUTHBOUND_INSTALL_FAILURE
:
1041 * I am not sure this is the right thing to do here
1042 * but the code always set selected_fib before
1043 * this assignment was moved here.
1045 dest
->selected_fib
= re
;
1047 zsend_route_notify_owner(re
->type
, re
->instance
, re
->vrf_id
,
1048 p
, ZAPI_ROUTE_FAIL_INSTALL
);
1049 zlog_warn("%u:%s: Route install failed", re
->vrf_id
,
1050 prefix2str(p
, buf
, sizeof(buf
)));
1052 case SOUTHBOUND_DELETE_SUCCESS
:
1054 * The case where selected_fib is not re is
1055 * when we have received a system route
1056 * that is overriding our installed route
1057 * as such we should leave the selected_fib
1060 if (dest
->selected_fib
== re
)
1061 dest
->selected_fib
= NULL
;
1062 for (ALL_NEXTHOPS(re
->nexthop
, nexthop
))
1063 UNSET_FLAG(nexthop
->flags
, NEXTHOP_FLAG_FIB
);
1065 case SOUTHBOUND_DELETE_FAILURE
:
1067 * Should we set this to NULL if the
1070 dest
->selected_fib
= NULL
;
1071 zlog_warn("%u:%s: Route Deletion failure", re
->vrf_id
,
1072 prefix2str(p
, buf
, sizeof(buf
)));
1077 /* Update flag indicates whether this is a "replace" or not. Currently, this
1078 * is only used for IPv4.
1080 void rib_install_kernel(struct route_node
*rn
, struct route_entry
*re
,
1081 struct route_entry
*old
)
1083 struct nexthop
*nexthop
;
1084 rib_table_info_t
*info
= srcdest_rnode_table_info(rn
);
1085 struct prefix
*p
, *src_p
;
1086 struct zebra_vrf
*zvrf
= vrf_info_lookup(re
->vrf_id
);
1088 srcdest_rnode_prefixes(rn
, &p
, &src_p
);
1090 if (info
->safi
!= SAFI_UNICAST
) {
1091 for (ALL_NEXTHOPS(re
->nexthop
, nexthop
))
1092 SET_FLAG(nexthop
->flags
, NEXTHOP_FLAG_FIB
);
1095 struct nexthop
*prev
;
1097 for (ALL_NEXTHOPS(re
->nexthop
, nexthop
)) {
1098 UNSET_FLAG (nexthop
->flags
, NEXTHOP_FLAG_DUPLICATE
);
1099 for (ALL_NEXTHOPS(re
->nexthop
, prev
)) {
1100 if (prev
== nexthop
)
1102 if (nexthop_same_firsthop (nexthop
, prev
))
1104 SET_FLAG (nexthop
->flags
, NEXTHOP_FLAG_DUPLICATE
);
1112 * If this is a replace to a new RE let the originator of the RE
1113 * know that they've lost
1115 if (old
&& old
!= re
)
1116 zsend_route_notify_owner(old
->type
, old
->instance
,
1118 ZAPI_ROUTE_BETTER_ADMIN_WON
);
1121 * Make sure we update the FPM any time we send new information to
1124 hook_call(rib_update
, rn
, "installing in kernel");
1125 kernel_route_rib(rn
, p
, src_p
, old
, re
);
1131 /* Uninstall the route from kernel. */
1132 void rib_uninstall_kernel(struct route_node
*rn
, struct route_entry
*re
)
1134 struct nexthop
*nexthop
;
1135 rib_table_info_t
*info
= srcdest_rnode_table_info(rn
);
1136 struct prefix
*p
, *src_p
;
1137 struct zebra_vrf
*zvrf
= vrf_info_lookup(re
->vrf_id
);
1139 srcdest_rnode_prefixes(rn
, &p
, &src_p
);
1141 if (info
->safi
!= SAFI_UNICAST
) {
1142 for (ALL_NEXTHOPS(re
->nexthop
, nexthop
))
1143 UNSET_FLAG(nexthop
->flags
, NEXTHOP_FLAG_FIB
);
1148 * Make sure we update the FPM any time we send new information to
1151 hook_call(rib_update
, rn
, "uninstalling from kernel");
1152 kernel_route_rib(rn
, p
, src_p
, re
, NULL
);
1159 /* Uninstall the route from kernel. */
1160 static void rib_uninstall(struct route_node
*rn
, struct route_entry
*re
)
1162 rib_table_info_t
*info
= srcdest_rnode_table_info(rn
);
1163 rib_dest_t
*dest
= rib_dest_from_rnode(rn
);
1165 if (dest
&& dest
->selected_fib
== re
) {
1166 if (info
->safi
== SAFI_UNICAST
)
1167 hook_call(rib_update
, rn
, "rib_uninstall");
1169 if (!RIB_SYSTEM_ROUTE(re
))
1170 rib_uninstall_kernel(rn
, re
);
1172 /* If labeled-unicast route, uninstall transit LSP. */
1173 if (zebra_rib_labeled_unicast(re
))
1174 zebra_mpls_lsp_uninstall(info
->zvrf
, rn
, re
);
1177 if (CHECK_FLAG(re
->flags
, ZEBRA_FLAG_SELECTED
)) {
1178 struct prefix
*p
, *src_p
;
1179 srcdest_rnode_prefixes(rn
, &p
, &src_p
);
1181 redistribute_delete(p
, src_p
, re
);
1182 UNSET_FLAG(re
->flags
, ZEBRA_FLAG_SELECTED
);
1187 * rib_can_delete_dest
1189 * Returns TRUE if the given dest can be deleted from the table.
1191 static int rib_can_delete_dest(rib_dest_t
*dest
)
1198 * Don't delete the dest if we have to update the FPM about this
1201 if (CHECK_FLAG(dest
->flags
, RIB_DEST_UPDATE_FPM
)
1202 || CHECK_FLAG(dest
->flags
, RIB_DEST_SENT_TO_FPM
))
1211 * Garbage collect the rib dest corresponding to the given route node
1214 * Returns TRUE if the dest was deleted, FALSE otherwise.
1216 int rib_gc_dest(struct route_node
*rn
)
1220 dest
= rib_dest_from_rnode(rn
);
1224 if (!rib_can_delete_dest(dest
))
1227 if (IS_ZEBRA_DEBUG_RIB
) {
1228 struct zebra_vrf
*zvrf
;
1230 zvrf
= rib_dest_vrf(dest
);
1231 rnode_debug(rn
, zvrf_id(zvrf
), "removing dest from table");
1235 XFREE(MTYPE_RIB_DEST
, dest
);
1239 * Release the one reference that we keep on the route node.
1241 route_unlock_node(rn
);
1245 static void rib_process_add_fib(struct zebra_vrf
*zvrf
, struct route_node
*rn
,
1246 struct route_entry
*new)
1248 rib_dest_t
*dest
= rib_dest_from_rnode(rn
);
1250 hook_call(rib_update
, rn
, "new route selected");
1252 /* Update real nexthop. This may actually determine if nexthop is active
1254 if (!nexthop_active_update(rn
, new, 1)) {
1255 UNSET_FLAG(new->status
, ROUTE_ENTRY_CHANGED
);
1259 if (IS_ZEBRA_DEBUG_RIB
) {
1260 char buf
[SRCDEST2STR_BUFFER
];
1261 srcdest_rnode2str(rn
, buf
, sizeof(buf
));
1262 zlog_debug("%u:%s: Adding route rn %p, re %p (type %d)",
1263 zvrf_id(zvrf
), buf
, rn
, new, new->type
);
1266 /* If labeled-unicast route, install transit LSP. */
1267 if (zebra_rib_labeled_unicast(new))
1268 zebra_mpls_lsp_install(zvrf
, rn
, new);
1270 if (!RIB_SYSTEM_ROUTE(new))
1271 rib_install_kernel(rn
, new, NULL
);
1273 dest
->selected_fib
= new;
1275 UNSET_FLAG(new->status
, ROUTE_ENTRY_CHANGED
);
1278 static void rib_process_del_fib(struct zebra_vrf
*zvrf
, struct route_node
*rn
,
1279 struct route_entry
*old
)
1281 rib_dest_t
*dest
= rib_dest_from_rnode(rn
);
1282 hook_call(rib_update
, rn
, "removing existing route");
1284 /* Uninstall from kernel. */
1285 if (IS_ZEBRA_DEBUG_RIB
) {
1286 char buf
[SRCDEST2STR_BUFFER
];
1287 srcdest_rnode2str(rn
, buf
, sizeof(buf
));
1288 zlog_debug("%u:%s: Deleting route rn %p, re %p (type %d)",
1289 zvrf_id(zvrf
), buf
, rn
, old
, old
->type
);
1292 /* If labeled-unicast route, uninstall transit LSP. */
1293 if (zebra_rib_labeled_unicast(old
))
1294 zebra_mpls_lsp_uninstall(zvrf
, rn
, old
);
1296 if (!RIB_SYSTEM_ROUTE(old
))
1297 rib_uninstall_kernel(rn
, old
);
1300 * We are setting this to NULL here
1301 * because that is what we traditionally
1302 * have been doing. I am not positive
1303 * that this is the right thing to do
1304 * but let's leave the code alone
1305 * for the RIB_SYSTEM_ROUTE case
1307 dest
->selected_fib
= NULL
;
1310 /* Update nexthop for route, reset changed flag. */
1311 nexthop_active_update(rn
, old
, 1);
1312 UNSET_FLAG(old
->status
, ROUTE_ENTRY_CHANGED
);
1315 static void rib_process_update_fib(struct zebra_vrf
*zvrf
,
1316 struct route_node
*rn
,
1317 struct route_entry
*old
,
1318 struct route_entry
*new)
1320 struct nexthop
*nexthop
= NULL
;
1322 rib_dest_t
*dest
= rib_dest_from_rnode(rn
);
1325 * We have to install or update if a new route has been selected or
1326 * something has changed.
1328 if (new != old
|| CHECK_FLAG(new->status
, ROUTE_ENTRY_CHANGED
)) {
1329 hook_call(rib_update
, rn
, "updating existing route");
1331 /* Update the nexthop; we could determine here that nexthop is
1333 if (nexthop_active_update(rn
, new, 1))
1336 /* If nexthop is active, install the selected route, if
1338 * the install succeeds, cleanup flags for prior route, if
1343 if (IS_ZEBRA_DEBUG_RIB
) {
1344 char buf
[SRCDEST2STR_BUFFER
];
1345 srcdest_rnode2str(rn
, buf
, sizeof(buf
));
1348 "%u:%s: Updating route rn %p, re %p (type %d) "
1350 zvrf_id(zvrf
), buf
, rn
, new,
1351 new->type
, old
, old
->type
);
1354 "%u:%s: Updating route rn %p, re %p (type %d)",
1355 zvrf_id(zvrf
), buf
, rn
, new,
1359 /* If labeled-unicast route, uninstall transit LSP. */
1360 if (zebra_rib_labeled_unicast(old
))
1361 zebra_mpls_lsp_uninstall(zvrf
, rn
, old
);
1363 /* Non-system route should be installed. */
1364 if (!RIB_SYSTEM_ROUTE(new)) {
1365 /* If labeled-unicast route, install transit
1367 if (zebra_rib_labeled_unicast(new))
1368 zebra_mpls_lsp_install(zvrf
, rn
, new);
1370 rib_install_kernel(rn
, new, old
);
1373 * We do not need to install the
1374 * selected route because it
1375 * is already isntalled by
1376 * the system( ie not us )
1377 * so just mark it as winning
1378 * we do need to ensure that
1379 * if we uninstall a route
1380 * from ourselves we don't
1381 * over write this pointer
1383 dest
->selected_fib
= NULL
;
1385 /* If install succeeded or system route, cleanup flags
1386 * for prior route. */
1388 if (RIB_SYSTEM_ROUTE(new)) {
1389 if (!RIB_SYSTEM_ROUTE(old
))
1390 rib_uninstall_kernel(rn
, old
);
1392 for (nexthop
= old
->nexthop
; nexthop
;
1393 nexthop
= nexthop
->next
)
1394 UNSET_FLAG(nexthop
->flags
,
1401 * If nexthop for selected route is not active or install
1403 * may need to uninstall and delete for redistribution.
1406 if (IS_ZEBRA_DEBUG_RIB
) {
1407 char buf
[SRCDEST2STR_BUFFER
];
1408 srcdest_rnode2str(rn
, buf
, sizeof(buf
));
1411 "%u:%s: Deleting route rn %p, re %p (type %d) "
1412 "old %p (type %d) - %s",
1413 zvrf_id(zvrf
), buf
, rn
, new,
1414 new->type
, old
, old
->type
,
1415 nh_active
? "install failed"
1416 : "nexthop inactive");
1419 "%u:%s: Deleting route rn %p, re %p (type %d) - %s",
1420 zvrf_id(zvrf
), buf
, rn
, new,
1422 nh_active
? "install failed"
1423 : "nexthop inactive");
1426 /* If labeled-unicast route, uninstall transit LSP. */
1427 if (zebra_rib_labeled_unicast(old
))
1428 zebra_mpls_lsp_uninstall(zvrf
, rn
, old
);
1430 if (!RIB_SYSTEM_ROUTE(old
))
1431 rib_uninstall_kernel(rn
, old
);
1433 dest
->selected_fib
= NULL
;
1437 * Same route selected; check if in the FIB and if not,
1439 * is housekeeping code to deal with race conditions in kernel
1441 * netlink reporting interface up before IPv4 or IPv6 protocol
1445 if (!RIB_SYSTEM_ROUTE(new)) {
1446 bool in_fib
= false;
1448 for (ALL_NEXTHOPS(new->nexthop
, nexthop
))
1449 if (CHECK_FLAG(nexthop
->flags
,
1450 NEXTHOP_FLAG_FIB
)) {
1455 rib_install_kernel(rn
, new, NULL
);
1459 /* Update prior route. */
1461 /* Set real nexthop. */
1462 nexthop_active_update(rn
, old
, 1);
1463 UNSET_FLAG(old
->status
, ROUTE_ENTRY_CHANGED
);
1466 /* Clear changed flag. */
1467 UNSET_FLAG(new->status
, ROUTE_ENTRY_CHANGED
);
1470 /* Check if 'alternate' RIB entry is better than 'current'. */
1471 static struct route_entry
*rib_choose_best(struct route_entry
*current
,
1472 struct route_entry
*alternate
)
1474 if (current
== NULL
)
1477 /* filter route selection in following order:
1478 * - connected beats other types
1479 * - lower distance beats higher
1480 * - lower metric beats higher for equal distance
1481 * - last, hence oldest, route wins tie break.
1484 /* Connected routes. Pick the last connected
1485 * route of the set of lowest metric connected routes.
1487 if (alternate
->type
== ZEBRA_ROUTE_CONNECT
) {
1488 if (current
->type
!= ZEBRA_ROUTE_CONNECT
1489 || alternate
->metric
<= current
->metric
)
1495 if (current
->type
== ZEBRA_ROUTE_CONNECT
)
1498 /* higher distance loses */
1499 if (alternate
->distance
< current
->distance
)
1501 if (current
->distance
< alternate
->distance
)
1504 /* metric tie-breaks equal distance */
1505 if (alternate
->metric
<= current
->metric
)
1511 /* Core function for processing routing information base. */
1512 static void rib_process(struct route_node
*rn
)
1514 struct route_entry
*re
;
1515 struct route_entry
*next
;
1516 struct route_entry
*old_selected
= NULL
;
1517 struct route_entry
*new_selected
= NULL
;
1518 struct route_entry
*old_fib
= NULL
;
1519 struct route_entry
*new_fib
= NULL
;
1520 struct route_entry
*best
= NULL
;
1521 char buf
[SRCDEST2STR_BUFFER
];
1523 struct zebra_vrf
*zvrf
= NULL
;
1524 struct prefix
*p
, *src_p
;
1525 srcdest_rnode_prefixes(rn
, &p
, &src_p
);
1526 vrf_id_t vrf_id
= VRF_UNKNOWN
;
1530 dest
= rib_dest_from_rnode(rn
);
1532 zvrf
= rib_dest_vrf(dest
);
1533 vrf_id
= zvrf_id(zvrf
);
1536 if (IS_ZEBRA_DEBUG_RIB
)
1537 srcdest_rnode2str(rn
, buf
, sizeof(buf
));
1539 if (IS_ZEBRA_DEBUG_RIB_DETAILED
)
1540 zlog_debug("%u:%s: Processing rn %p", vrf_id
, buf
, rn
);
1543 * we can have rn's that have a NULL info pointer
1544 * (dest). As such let's not let the deref happen
1545 * additionally we know RNODE_FOREACH_RE_SAFE
1546 * will not iterate so we are ok.
1549 old_fib
= dest
->selected_fib
;
1551 RNODE_FOREACH_RE_SAFE (rn
, re
, next
) {
1552 if (IS_ZEBRA_DEBUG_RIB_DETAILED
)
1554 "%u:%s: Examine re %p (type %d) status %x flags %x "
1555 "dist %d metric %d",
1556 vrf_id
, buf
, re
, re
->type
, re
->status
,
1557 re
->flags
, re
->distance
, re
->metric
);
1559 UNSET_FLAG(re
->status
, ROUTE_ENTRY_NEXTHOPS_CHANGED
);
1561 /* Currently selected re. */
1562 if (CHECK_FLAG(re
->flags
, ZEBRA_FLAG_SELECTED
)) {
1563 assert(old_selected
== NULL
);
1567 /* Skip deleted entries from selection */
1568 if (CHECK_FLAG(re
->status
, ROUTE_ENTRY_REMOVED
))
1571 /* Skip unreachable nexthop. */
1572 /* This first call to nexthop_active_update is merely to
1574 * there's any change to nexthops associated with this RIB
1576 * rib_process() can be invoked due to an external event such as
1578 * down or due to next-hop-tracking evaluation. In the latter
1580 * a decision has already been made that the NHs have changed.
1582 * need to invoke a potentially expensive call again. Further,
1584 * the change might be in a recursive NH which is not caught in
1585 * the nexthop_active_update() code. Thus, we might miss changes
1589 if (!CHECK_FLAG(re
->status
, ROUTE_ENTRY_CHANGED
)
1590 && !nexthop_active_update(rn
, re
, 0)) {
1591 if (re
->type
== ZEBRA_ROUTE_TABLE
) {
1592 /* XXX: HERE BE DRAGONS!!!!!
1593 * In all honesty, I have not yet figured out
1595 * does or why the ROUTE_ENTRY_CHANGED test
1597 * or why we need to delete a route here, and
1599 * this concerns both selected and fib route, or
1602 /* This entry was denied by the 'ip protocol
1603 * table' route-map, we
1604 * need to delete it */
1605 if (re
!= old_selected
) {
1606 if (IS_ZEBRA_DEBUG_RIB
)
1608 "%s: %s: imported via import-table but denied "
1609 "by the ip protocol table route-map",
1613 SET_FLAG(re
->status
,
1614 ROUTE_ENTRY_REMOVED
);
1620 /* Infinite distance. */
1621 if (re
->distance
== DISTANCE_INFINITY
) {
1622 UNSET_FLAG(re
->status
, ROUTE_ENTRY_CHANGED
);
1626 if (CHECK_FLAG(re
->flags
, ZEBRA_FLAG_FIB_OVERRIDE
)) {
1627 best
= rib_choose_best(new_fib
, re
);
1628 if (new_fib
&& best
!= new_fib
)
1629 UNSET_FLAG(new_fib
->status
,
1630 ROUTE_ENTRY_CHANGED
);
1633 best
= rib_choose_best(new_selected
, re
);
1634 if (new_selected
&& best
!= new_selected
)
1635 UNSET_FLAG(new_selected
->status
,
1636 ROUTE_ENTRY_CHANGED
);
1637 new_selected
= best
;
1640 UNSET_FLAG(re
->status
, ROUTE_ENTRY_CHANGED
);
1641 } /* RNODE_FOREACH_RE */
1643 /* If no FIB override route, use the selected route also for FIB */
1644 if (new_fib
== NULL
)
1645 new_fib
= new_selected
;
1647 /* After the cycle is finished, the following pointers will be set:
1648 * old_selected --- RE entry currently having SELECTED
1649 * new_selected --- RE entry that is newly SELECTED
1650 * old_fib --- RE entry currently in kernel FIB
1651 * new_fib --- RE entry that is newly to be in kernel FIB
1653 * new_selected will get SELECTED flag, and is going to be redistributed
1654 * the zclients. new_fib (which can be new_selected) will be installed
1658 if (IS_ZEBRA_DEBUG_RIB_DETAILED
) {
1660 "%u:%s: After processing: old_selected %p new_selected %p old_fib %p new_fib %p",
1661 vrf_id
, buf
, (void *)old_selected
, (void *)new_selected
,
1662 (void *)old_fib
, (void *)new_fib
);
1665 /* Buffer ROUTE_ENTRY_CHANGED here, because it will get cleared if
1666 * fib == selected */
1667 bool selected_changed
= new_selected
&& CHECK_FLAG(new_selected
->status
,
1668 ROUTE_ENTRY_CHANGED
);
1670 /* Update fib according to selection results */
1671 if (new_fib
&& old_fib
)
1672 rib_process_update_fib(zvrf
, rn
, old_fib
, new_fib
);
1674 rib_process_add_fib(zvrf
, rn
, new_fib
);
1676 rib_process_del_fib(zvrf
, rn
, old_fib
);
1678 /* Redistribute SELECTED entry */
1679 if (old_selected
!= new_selected
|| selected_changed
) {
1680 struct nexthop
*nexthop
;
1682 /* Check if we have a FIB route for the destination, otherwise,
1683 * don't redistribute it */
1684 for (ALL_NEXTHOPS(new_fib
? new_fib
->nexthop
: NULL
, nexthop
)) {
1685 if (CHECK_FLAG(nexthop
->flags
, NEXTHOP_FLAG_FIB
)) {
1690 new_selected
= NULL
;
1692 if (new_selected
&& new_selected
!= new_fib
) {
1693 nexthop_active_update(rn
, new_selected
, 1);
1694 UNSET_FLAG(new_selected
->status
, ROUTE_ENTRY_CHANGED
);
1699 redistribute_delete(p
, src_p
, old_selected
);
1700 if (old_selected
!= new_selected
)
1701 UNSET_FLAG(old_selected
->flags
,
1702 ZEBRA_FLAG_SELECTED
);
1706 /* Install new or replace existing redistributed entry
1708 SET_FLAG(new_selected
->flags
, ZEBRA_FLAG_SELECTED
);
1709 redistribute_update(p
, src_p
, new_selected
,
1714 /* Remove all RE entries queued for removal */
1715 RNODE_FOREACH_RE_SAFE (rn
, re
, next
) {
1716 if (CHECK_FLAG(re
->status
, ROUTE_ENTRY_REMOVED
)) {
1717 if (IS_ZEBRA_DEBUG_RIB
) {
1718 rnode_debug(rn
, vrf_id
, "rn %p, removing re %p",
1719 (void *)rn
, (void *)re
);
1726 * Check if the dest can be deleted now.
1731 /* Take a list of route_node structs and return 1, if there was a record
1732 * picked from it and processed by rib_process(). Don't process more,
1733 * than one RN record; operate only in the specified sub-queue.
1735 static unsigned int process_subq(struct list
*subq
, u_char qindex
)
1737 struct listnode
*lnode
= listhead(subq
);
1738 struct route_node
*rnode
;
1740 struct zebra_vrf
*zvrf
= NULL
;
1745 rnode
= listgetdata(lnode
);
1746 dest
= rib_dest_from_rnode(rnode
);
1748 zvrf
= rib_dest_vrf(dest
);
1752 if (IS_ZEBRA_DEBUG_RIB_DETAILED
) {
1753 char buf
[SRCDEST2STR_BUFFER
];
1754 srcdest_rnode2str(rnode
, buf
, sizeof(buf
));
1755 zlog_debug("%u:%s: rn %p dequeued from sub-queue %u",
1756 zvrf
? zvrf_id(zvrf
) : 0, buf
, rnode
, qindex
);
1760 UNSET_FLAG(rib_dest_from_rnode(rnode
)->flags
,
1761 RIB_ROUTE_QUEUED(qindex
));
1766 zlog_debug ("%s: called for route_node (%p, %d) with no ribs",
1767 __func__
, rnode
, rnode
->lock
);
1768 zlog_backtrace(LOG_DEBUG
);
1771 route_unlock_node(rnode
);
1772 list_delete_node(subq
, lnode
);
1777 * All meta queues have been processed. Trigger next-hop evaluation.
1779 static void meta_queue_process_complete(struct work_queue
*dummy
)
1782 struct zebra_vrf
*zvrf
;
1784 /* Evaluate nexthops for those VRFs which underwent route processing.
1786 * should limit the evaluation to the necessary VRFs in most common
1789 RB_FOREACH (vrf
, vrf_id_head
, &vrfs_by_id
) {
1791 if (zvrf
== NULL
|| !(zvrf
->flags
& ZEBRA_VRF_RIB_SCHEDULED
))
1794 zvrf
->flags
&= ~ZEBRA_VRF_RIB_SCHEDULED
;
1795 zebra_evaluate_rnh(zvrf_id(zvrf
), AF_INET
, 0, RNH_NEXTHOP_TYPE
,
1797 zebra_evaluate_rnh(zvrf_id(zvrf
), AF_INET
, 0,
1798 RNH_IMPORT_CHECK_TYPE
, NULL
);
1799 zebra_evaluate_rnh(zvrf_id(zvrf
), AF_INET6
, 0, RNH_NEXTHOP_TYPE
,
1801 zebra_evaluate_rnh(zvrf_id(zvrf
), AF_INET6
, 0,
1802 RNH_IMPORT_CHECK_TYPE
, NULL
);
1805 /* Schedule LSPs for processing, if needed. */
1806 zvrf
= vrf_info_lookup(VRF_DEFAULT
);
1807 if (mpls_should_lsps_be_processed(zvrf
)) {
1808 if (IS_ZEBRA_DEBUG_MPLS
)
1810 "%u: Scheduling all LSPs upon RIB completion",
1812 zebra_mpls_lsp_schedule(zvrf
);
1813 mpls_unmark_lsps_for_processing(zvrf
);
1817 /* Dispatch the meta queue by picking, processing and unlocking the next RN from
1818 * a non-empty sub-queue with lowest priority. wq is equal to zebra->ribq and
1820 * is pointed to the meta queue structure.
1822 static wq_item_status
meta_queue_process(struct work_queue
*dummy
, void *data
)
1824 struct meta_queue
*mq
= data
;
1827 for (i
= 0; i
< MQ_SIZE
; i
++)
1828 if (process_subq(mq
->subq
[i
], i
)) {
1832 return mq
->size
? WQ_REQUEUE
: WQ_SUCCESS
;
1836 * Map from rib types to queue type (priority) in meta queue
1838 static const u_char meta_queue_map
[ZEBRA_ROUTE_MAX
] = {
1839 [ZEBRA_ROUTE_SYSTEM
] = 4,
1840 [ZEBRA_ROUTE_KERNEL
] = 0,
1841 [ZEBRA_ROUTE_CONNECT
] = 0,
1842 [ZEBRA_ROUTE_STATIC
] = 1,
1843 [ZEBRA_ROUTE_RIP
] = 2,
1844 [ZEBRA_ROUTE_RIPNG
] = 2,
1845 [ZEBRA_ROUTE_OSPF
] = 2,
1846 [ZEBRA_ROUTE_OSPF6
] = 2,
1847 [ZEBRA_ROUTE_ISIS
] = 2,
1848 [ZEBRA_ROUTE_BGP
] = 3,
1849 [ZEBRA_ROUTE_PIM
] = 4, // Shouldn't happen but for safety
1850 [ZEBRA_ROUTE_EIGRP
] = 2,
1851 [ZEBRA_ROUTE_NHRP
] = 2,
1852 [ZEBRA_ROUTE_HSLS
] = 4,
1853 [ZEBRA_ROUTE_OLSR
] = 4,
1854 [ZEBRA_ROUTE_TABLE
] = 1,
1855 [ZEBRA_ROUTE_LDP
] = 4,
1856 [ZEBRA_ROUTE_VNC
] = 3,
1857 [ZEBRA_ROUTE_VNC_DIRECT
] = 3,
1858 [ZEBRA_ROUTE_VNC_DIRECT_RH
] = 3,
1859 [ZEBRA_ROUTE_BGP_DIRECT
] = 3,
1860 [ZEBRA_ROUTE_BGP_DIRECT_EXT
] = 3,
1861 [ZEBRA_ROUTE_BABEL
] = 2,
1862 [ZEBRA_ROUTE_ALL
] = 4, // Shouldn't happen but for safety
1865 /* Look into the RN and queue it into one or more priority queues,
1866 * increasing the size for each data push done.
1868 static void rib_meta_queue_add(struct meta_queue
*mq
, struct route_node
*rn
)
1870 struct route_entry
*re
;
1872 RNODE_FOREACH_RE (rn
, re
) {
1873 u_char qindex
= meta_queue_map
[re
->type
];
1874 struct zebra_vrf
*zvrf
;
1876 /* Invariant: at this point we always have rn->info set. */
1877 if (CHECK_FLAG(rib_dest_from_rnode(rn
)->flags
,
1878 RIB_ROUTE_QUEUED(qindex
))) {
1879 if (IS_ZEBRA_DEBUG_RIB_DETAILED
)
1882 "rn %p is already queued in sub-queue %u",
1883 (void *)rn
, qindex
);
1887 SET_FLAG(rib_dest_from_rnode(rn
)->flags
,
1888 RIB_ROUTE_QUEUED(qindex
));
1889 listnode_add(mq
->subq
[qindex
], rn
);
1890 route_lock_node(rn
);
1893 if (IS_ZEBRA_DEBUG_RIB_DETAILED
)
1894 rnode_debug(rn
, re
->vrf_id
,
1895 "queued rn %p into sub-queue %u",
1896 (void *)rn
, qindex
);
1898 zvrf
= zebra_vrf_lookup_by_id(re
->vrf_id
);
1900 zvrf
->flags
|= ZEBRA_VRF_RIB_SCHEDULED
;
1904 /* Add route_node to work queue and schedule processing */
1905 void rib_queue_add(struct route_node
*rn
)
1909 /* Pointless to queue a route_node with no RIB entries to add or remove
1911 if (!rnode_to_ribs(rn
)) {
1912 zlog_debug("%s: called for route_node (%p, %d) with no ribs",
1913 __func__
, (void *)rn
, rn
->lock
);
1914 zlog_backtrace(LOG_DEBUG
);
1918 if (zebrad
.ribq
== NULL
) {
1919 zlog_err("%s: work_queue does not exist!", __func__
);
1924 * The RIB queue should normally be either empty or holding the only
1925 * work_queue_item element. In the latter case this element would
1926 * hold a pointer to the meta queue structure, which must be used to
1927 * actually queue the route nodes to process. So create the MQ
1928 * holder, if necessary, then push the work into it in any case.
1929 * This semantics was introduced after 0.99.9 release.
1931 if (work_queue_empty(zebrad
.ribq
))
1932 work_queue_add(zebrad
.ribq
, zebrad
.mq
);
1934 rib_meta_queue_add(zebrad
.mq
, rn
);
1939 /* Create new meta queue.
1940 A destructor function doesn't seem to be necessary here.
1942 static struct meta_queue
*meta_queue_new(void)
1944 struct meta_queue
*new;
1947 new = XCALLOC(MTYPE_WORK_QUEUE
, sizeof(struct meta_queue
));
1950 for (i
= 0; i
< MQ_SIZE
; i
++) {
1951 new->subq
[i
] = list_new();
1952 assert(new->subq
[i
]);
1958 void meta_queue_free(struct meta_queue
*mq
)
1962 for (i
= 0; i
< MQ_SIZE
; i
++)
1963 list_delete_and_null(&mq
->subq
[i
]);
1965 XFREE(MTYPE_WORK_QUEUE
, mq
);
1968 /* initialise zebra rib work queue */
1969 static void rib_queue_init(struct zebra_t
*zebra
)
1974 work_queue_new(zebra
->master
, "route_node processing"))) {
1975 zlog_err("%s: could not initialise work queue!", __func__
);
1979 /* fill in the work queue spec */
1980 zebra
->ribq
->spec
.workfunc
= &meta_queue_process
;
1981 zebra
->ribq
->spec
.errorfunc
= NULL
;
1982 zebra
->ribq
->spec
.completion_func
= &meta_queue_process_complete
;
1983 /* XXX: TODO: These should be runtime configurable via vty */
1984 zebra
->ribq
->spec
.max_retries
= 3;
1985 zebra
->ribq
->spec
.hold
= ZEBRA_RIB_PROCESS_HOLD_TIME
;
1987 if (!(zebra
->mq
= meta_queue_new())) {
1988 zlog_err("%s: could not initialise meta queue!", __func__
);
1994 /* RIB updates are processed via a queue of pointers to route_nodes.
1996 * The queue length is bounded by the maximal size of the routing table,
1997 * as a route_node will not be requeued, if already queued.
1999 * REs are submitted via rib_addnode or rib_delnode which set minimal
2000 * state, or static_install_route (when an existing RE is updated)
2001 * and then submit route_node to queue for best-path selection later.
2002 * Order of add/delete state changes are preserved for any given RE.
2004 * Deleted REs are reaped during best-path selection.
2007 * |-> rib_link or unset ROUTE_ENTRY_REMOVE |->Update kernel with
2008 * |-------->| | best RE, if required
2010 * static_install->|->rib_addqueue...... -> rib_process
2012 * |-------->| |-> rib_unlink
2013 * |-> set ROUTE_ENTRY_REMOVE |
2014 * rib_delnode (RE freed)
2016 * The 'info' pointer of a route_node points to a rib_dest_t
2017 * ('dest'). Queueing state for a route_node is kept on the dest. The
2018 * dest is created on-demand by rib_link() and is kept around at least
2019 * as long as there are ribs hanging off it (@see rib_gc_dest()).
2021 * Refcounting (aka "locking" throughout the GNU Zebra and Quagga code):
2023 * - route_nodes: refcounted by:
2024 * - dest attached to route_node:
2025 * - managed by: rib_link/rib_gc_dest
2026 * - route_node processing queue
2027 * - managed by: rib_addqueue, rib_process.
2031 /* Add RE to head of the route node. */
2032 static void rib_link(struct route_node
*rn
, struct route_entry
*re
, int process
)
2034 struct route_entry
*head
;
2037 const char *rmap_name
;
2041 dest
= rib_dest_from_rnode(rn
);
2043 if (IS_ZEBRA_DEBUG_RIB_DETAILED
)
2044 rnode_debug(rn
, re
->vrf_id
, "rn %p adding dest", rn
);
2046 dest
= XCALLOC(MTYPE_RIB_DEST
, sizeof(rib_dest_t
));
2047 route_lock_node(rn
); /* rn route table reference */
2052 head
= dest
->routes
;
2059 afi
= (rn
->p
.family
== AF_INET
)
2061 : (rn
->p
.family
== AF_INET6
) ? AFI_IP6
: AFI_MAX
;
2062 if (is_zebra_import_table_enabled(afi
, re
->table
)) {
2063 rmap_name
= zebra_get_import_table_route_map(afi
, re
->table
);
2064 zebra_add_import_table_entry(rn
, re
, rmap_name
);
2069 void rib_addnode(struct route_node
*rn
, struct route_entry
*re
, int process
)
2071 /* RE node has been un-removed before route-node is processed.
2072 * route_node must hence already be on the queue for processing..
2074 if (CHECK_FLAG(re
->status
, ROUTE_ENTRY_REMOVED
)) {
2075 if (IS_ZEBRA_DEBUG_RIB
)
2076 rnode_debug(rn
, re
->vrf_id
, "rn %p, un-removed re %p",
2077 (void *)rn
, (void *)re
);
2079 UNSET_FLAG(re
->status
, ROUTE_ENTRY_REMOVED
);
2082 rib_link(rn
, re
, process
);
2088 * Detach a rib structure from a route_node.
2090 * Note that a call to rib_unlink() should be followed by a call to
2091 * rib_gc_dest() at some point. This allows a rib_dest_t that is no
2092 * longer required to be deleted.
2094 void rib_unlink(struct route_node
*rn
, struct route_entry
*re
)
2100 if (IS_ZEBRA_DEBUG_RIB
)
2101 rnode_debug(rn
, re
->vrf_id
, "rn %p, re %p", (void *)rn
,
2104 dest
= rib_dest_from_rnode(rn
);
2107 re
->next
->prev
= re
->prev
;
2110 re
->prev
->next
= re
->next
;
2112 dest
->routes
= re
->next
;
2115 if (dest
->selected_fib
== re
)
2116 dest
->selected_fib
= NULL
;
2118 /* free RE and nexthops */
2119 zebra_deregister_rnh_static_nexthops(re
->vrf_id
, re
->nexthop
, rn
);
2120 nexthops_free(re
->nexthop
);
2121 XFREE(MTYPE_RE
, re
);
2124 void rib_delnode(struct route_node
*rn
, struct route_entry
*re
)
2128 if (IS_ZEBRA_DEBUG_RIB
)
2129 rnode_debug(rn
, re
->vrf_id
, "rn %p, re %p, removing",
2130 (void *)rn
, (void *)re
);
2131 SET_FLAG(re
->status
, ROUTE_ENTRY_REMOVED
);
2133 afi
= (rn
->p
.family
== AF_INET
)
2135 : (rn
->p
.family
== AF_INET6
) ? AFI_IP6
: AFI_MAX
;
2136 if (is_zebra_import_table_enabled(afi
, re
->table
)) {
2137 zebra_del_import_table_entry(rn
, re
);
2138 /* Just clean up if non main table */
2139 if (IS_ZEBRA_DEBUG_RIB
) {
2140 char buf
[SRCDEST2STR_BUFFER
];
2141 srcdest_rnode2str(rn
, buf
, sizeof(buf
));
2143 "%u:%s: Freeing route rn %p, re %p (type %d)",
2144 re
->vrf_id
, buf
, rn
, re
, re
->type
);
2153 /* This function dumps the contents of a given RE entry into
2154 * standard debug log. Calling function name and IP prefix in
2155 * question are passed as 1st and 2nd arguments.
2158 void _route_entry_dump(const char *func
, union prefixconstptr pp
,
2159 union prefixconstptr src_pp
,
2160 const struct route_entry
*re
)
2162 const struct prefix
*p
= pp
.p
;
2163 const struct prefix
*src_p
= src_pp
.p
;
2164 bool is_srcdst
= src_p
&& src_p
->prefixlen
;
2165 char straddr
[PREFIX_STRLEN
];
2166 char srcaddr
[PREFIX_STRLEN
];
2167 struct nexthop
*nexthop
;
2169 zlog_debug("%s: dumping RE entry %p for %s%s%s vrf %u", func
,
2170 (const void *)re
, prefix2str(pp
, straddr
, sizeof(straddr
)),
2171 is_srcdst
? " from " : "",
2172 is_srcdst
? prefix2str(src_pp
, srcaddr
, sizeof(srcaddr
))
2175 zlog_debug("%s: uptime == %lu, type == %u, instance == %d, table == %d",
2176 func
, (unsigned long)re
->uptime
, re
->type
, re
->instance
,
2179 "%s: metric == %u, mtu == %u, distance == %u, flags == %u, status == %u",
2180 func
, re
->metric
, re
->mtu
, re
->distance
, re
->flags
, re
->status
);
2181 zlog_debug("%s: nexthop_num == %u, nexthop_active_num == %u", func
,
2182 re
->nexthop_num
, re
->nexthop_active_num
);
2184 for (ALL_NEXTHOPS(re
->nexthop
, nexthop
)) {
2185 inet_ntop(p
->family
, &nexthop
->gate
, straddr
, INET6_ADDRSTRLEN
);
2186 zlog_debug("%s: %s %s[%u] with flags %s%s%s", func
,
2187 (nexthop
->rparent
? " NH" : "NH"), straddr
,
2189 (CHECK_FLAG(nexthop
->flags
, NEXTHOP_FLAG_ACTIVE
)
2192 (CHECK_FLAG(nexthop
->flags
, NEXTHOP_FLAG_FIB
)
2195 (CHECK_FLAG(nexthop
->flags
, NEXTHOP_FLAG_RECURSIVE
)
2199 zlog_debug("%s: dump complete", func
);
2202 /* This is an exported helper to rtm_read() to dump the strange
2203 * RE entry found by rib_lookup_ipv4_route()
2206 void rib_lookup_and_dump(struct prefix_ipv4
*p
, vrf_id_t vrf_id
)
2208 struct route_table
*table
;
2209 struct route_node
*rn
;
2210 struct route_entry
*re
;
2211 char prefix_buf
[INET_ADDRSTRLEN
];
2214 table
= zebra_vrf_table(AFI_IP
, SAFI_UNICAST
, vrf_id
);
2216 zlog_err("%s: zebra_vrf_table() returned NULL", __func__
);
2220 /* Scan the RIB table for exactly matching RE entry. */
2221 rn
= route_node_lookup(table
, (struct prefix
*)p
);
2223 /* No route for this prefix. */
2225 zlog_debug("%s: lookup failed for %s", __func__
,
2226 prefix2str((struct prefix
*)p
, prefix_buf
,
2227 sizeof(prefix_buf
)));
2232 route_unlock_node(rn
);
2235 RNODE_FOREACH_RE (rn
, re
) {
2236 zlog_debug("%s: rn %p, re %p: %s, %s", __func__
, (void *)rn
,
2238 (CHECK_FLAG(re
->status
, ROUTE_ENTRY_REMOVED
)
2241 (CHECK_FLAG(re
->flags
, ZEBRA_FLAG_SELECTED
)
2244 route_entry_dump(p
, NULL
, re
);
2248 /* Check if requested address assignment will fail due to another
2249 * route being installed by zebra in FIB already. Take necessary
2250 * actions, if needed: remove such a route from FIB and deSELECT
2251 * corresponding RE entry. Then put affected RN into RIBQ head.
2253 void rib_lookup_and_pushup(struct prefix_ipv4
*p
, vrf_id_t vrf_id
)
2255 struct route_table
*table
;
2256 struct route_node
*rn
;
2257 unsigned changed
= 0;
2260 if (NULL
== (table
= zebra_vrf_table(AFI_IP
, SAFI_UNICAST
, vrf_id
))) {
2261 zlog_err("%s: zebra_vrf_table() returned NULL", __func__
);
2265 /* No matches would be the simplest case. */
2266 if (NULL
== (rn
= route_node_lookup(table
, (struct prefix
*)p
)))
2270 route_unlock_node(rn
);
2272 dest
= rib_dest_from_rnode(rn
);
2273 /* Check all RE entries. In case any changes have to be done, requeue
2274 * the RN into RIBQ head. If the routing message about the new connected
2275 * route (generated by the IP address we are going to assign very soon)
2276 * comes before the RIBQ is processed, the new RE entry will join
2277 * RIBQ record already on head. This is necessary for proper
2279 * of the rest of the RE.
2281 if (dest
->selected_fib
&& !RIB_SYSTEM_ROUTE(dest
->selected_fib
)) {
2283 if (IS_ZEBRA_DEBUG_RIB
) {
2284 char buf
[PREFIX_STRLEN
];
2286 zlog_debug("%u:%s: freeing way for connected prefix",
2287 dest
->selected_fib
->vrf_id
,
2288 prefix2str(&rn
->p
, buf
, sizeof(buf
)));
2289 route_entry_dump(&rn
->p
, NULL
, dest
->selected_fib
);
2291 rib_uninstall(rn
, dest
->selected_fib
);
2297 int rib_add_multipath(afi_t afi
, safi_t safi
, struct prefix
*p
,
2298 struct prefix_ipv6
*src_p
, struct route_entry
*re
)
2300 struct route_table
*table
;
2301 struct route_node
*rn
;
2302 struct route_entry
*same
;
2303 struct nexthop
*nexthop
;
2309 assert(!src_p
|| afi
== AFI_IP6
);
2312 table
= zebra_vrf_table_with_table_id(afi
, safi
, re
->vrf_id
, re
->table
);
2314 XFREE(MTYPE_RE
, re
);
2318 /* Make it sure prefixlen is applied to the prefix. */
2321 apply_mask_ipv6(src_p
);
2323 /* Set default distance by route type. */
2324 if (re
->distance
== 0) {
2325 re
->distance
= route_distance(re
->type
);
2327 /* iBGP distance is 200. */
2328 if (re
->type
== ZEBRA_ROUTE_BGP
2329 && CHECK_FLAG(re
->flags
, ZEBRA_FLAG_IBGP
))
2333 /* Lookup route node.*/
2334 rn
= srcdest_rnode_get(table
, p
, src_p
);
2336 /* If same type of route are installed, treat it as a implicit
2338 RNODE_FOREACH_RE (rn
, same
) {
2339 if (CHECK_FLAG(same
->status
, ROUTE_ENTRY_REMOVED
))
2342 if (same
->type
!= re
->type
)
2344 if (same
->instance
!= re
->instance
)
2346 if (same
->type
== ZEBRA_ROUTE_KERNEL
&&
2347 same
->metric
!= re
->metric
)
2350 * We should allow duplicate connected routes because of
2351 * IPv6 link-local routes and unnumbered interfaces on Linux.
2353 if (same
->type
!= ZEBRA_ROUTE_CONNECT
)
2357 /* If this route is kernel route, set FIB flag to the route. */
2358 if (RIB_SYSTEM_ROUTE(re
))
2359 for (nexthop
= re
->nexthop
; nexthop
; nexthop
= nexthop
->next
)
2360 SET_FLAG(nexthop
->flags
, NEXTHOP_FLAG_FIB
);
2362 /* Link new re to node.*/
2363 if (IS_ZEBRA_DEBUG_RIB
) {
2366 "Inserting route rn %p, re %p (type %d) existing %p",
2367 (void *)rn
, (void *)re
, re
->type
, (void *)same
);
2369 if (IS_ZEBRA_DEBUG_RIB_DETAILED
)
2370 route_entry_dump(p
, src_p
, re
);
2372 rib_addnode(rn
, re
, 1);
2375 /* Free implicit route.*/
2377 rib_delnode(rn
, same
);
2381 route_unlock_node(rn
);
2385 void rib_delete(afi_t afi
, safi_t safi
, vrf_id_t vrf_id
, int type
,
2386 u_short instance
, int flags
, struct prefix
*p
,
2387 struct prefix_ipv6
*src_p
, const struct nexthop
*nh
,
2388 u_int32_t table_id
, u_int32_t metric
, bool fromkernel
,
2389 struct ethaddr
*rmac
)
2391 struct route_table
*table
;
2392 struct route_node
*rn
;
2393 struct route_entry
*re
;
2394 struct route_entry
*fib
= NULL
;
2395 struct route_entry
*same
= NULL
;
2396 struct nexthop
*rtnh
;
2397 char buf2
[INET6_ADDRSTRLEN
];
2400 assert(!src_p
|| afi
== AFI_IP6
);
2403 table
= zebra_vrf_table_with_table_id(afi
, safi
, vrf_id
, table_id
);
2410 apply_mask_ipv6(src_p
);
2412 /* Lookup route node. */
2413 rn
= srcdest_rnode_lookup(table
, p
, src_p
);
2415 char dst_buf
[PREFIX_STRLEN
], src_buf
[PREFIX_STRLEN
];
2417 prefix2str(p
, dst_buf
, sizeof(dst_buf
));
2418 if (src_p
&& src_p
->prefixlen
)
2419 prefix2str(src_p
, src_buf
, sizeof(src_buf
));
2423 if (IS_ZEBRA_DEBUG_RIB
)
2424 zlog_debug("%u:%s%s%s doesn't exist in rib", vrf_id
,
2426 (src_buf
[0] != '\0') ? " from " : "",
2431 dest
= rib_dest_from_rnode(rn
);
2432 fib
= dest
->selected_fib
;
2434 /* Lookup same type route. */
2435 RNODE_FOREACH_RE (rn
, re
) {
2436 if (CHECK_FLAG(re
->status
, ROUTE_ENTRY_REMOVED
))
2439 if (re
->type
!= type
)
2441 if (re
->instance
!= instance
)
2443 if (re
->type
== ZEBRA_ROUTE_KERNEL
&&
2444 re
->metric
!= metric
)
2446 if (re
->type
== ZEBRA_ROUTE_CONNECT
&& (rtnh
= re
->nexthop
)
2447 && rtnh
->type
== NEXTHOP_TYPE_IFINDEX
&& nh
) {
2448 if (rtnh
->ifindex
!= nh
->ifindex
)
2453 /* Make sure that the route found has the same gateway. */
2459 for (ALL_NEXTHOPS(re
->nexthop
, rtnh
))
2460 if (nexthop_same_no_recurse(rtnh
, nh
)) {
2468 /* If same type of route can't be found and this message is from
2472 * In the past(HA!) we could get here because
2473 * we were receiving a route delete from the
2474 * kernel and we're not marking the proto
2475 * as coming from it's appropriate originator.
2476 * Now that we are properly noticing the fact
2477 * that the kernel has deleted our route we
2478 * are not going to get called in this path
2479 * I am going to leave this here because
2480 * this might still work this way on non-linux
2481 * platforms as well as some weird state I have
2482 * not properly thought of yet.
2483 * If we can show that this code path is
2484 * dead then we can remove it.
2486 if (fib
&& type
== ZEBRA_ROUTE_KERNEL
2487 && CHECK_FLAG(flags
, ZEBRA_FLAG_SELFROUTE
)) {
2488 if (IS_ZEBRA_DEBUG_RIB
) {
2491 "rn %p, re %p (type %d) was deleted from kernel, adding",
2492 rn
, fib
, fib
->type
);
2496 for (rtnh
= fib
->nexthop
; rtnh
;
2498 UNSET_FLAG(rtnh
->flags
,
2502 * This is a non FRR route
2503 * as such we should mark
2506 dest
->selected_fib
= NULL
;
2508 /* This means someone else, other than Zebra,
2510 * a Zebra router from the kernel. We will add
2512 rib_install_kernel(rn
, fib
, NULL
);
2515 if (IS_ZEBRA_DEBUG_RIB
) {
2519 "via %s ifindex %d type %d "
2520 "doesn't exist in rib",
2524 INET_ADDRSTRLEN
), /* FIXME
2530 "type %d doesn't exist in rib",
2533 route_unlock_node(rn
);
2540 CHECK_FLAG(flags
, ZEBRA_FLAG_SELFROUTE
) &&
2542 rib_install_kernel(rn
, same
, NULL
);
2543 route_unlock_node(rn
);
2548 if (CHECK_FLAG(flags
, ZEBRA_FLAG_EVPN_ROUTE
)) {
2549 struct nexthop
*tmp_nh
;
2551 for (ALL_NEXTHOPS(re
->nexthop
, tmp_nh
)) {
2552 struct ipaddr vtep_ip
;
2554 memset(&vtep_ip
, 0, sizeof(struct ipaddr
));
2555 vtep_ip
.ipa_type
= IPADDR_V4
;
2556 memcpy(&(vtep_ip
.ipaddr_v4
),
2557 &(tmp_nh
->gate
.ipv4
),
2558 sizeof(struct in_addr
));
2559 zebra_vxlan_evpn_vrf_route_del(re
->vrf_id
, rmac
,
2563 rib_delnode(rn
, same
);
2566 route_unlock_node(rn
);
2571 int rib_add(afi_t afi
, safi_t safi
, vrf_id_t vrf_id
, int type
, u_short instance
,
2572 int flags
, struct prefix
*p
, struct prefix_ipv6
*src_p
,
2573 const struct nexthop
*nh
, u_int32_t table_id
, u_int32_t metric
,
2574 u_int32_t mtu
, uint8_t distance
, route_tag_t tag
)
2576 struct route_entry
*re
;
2577 struct nexthop
*nexthop
;
2579 /* Allocate new route_entry structure. */
2580 re
= XCALLOC(MTYPE_RE
, sizeof(struct route_entry
));
2582 re
->instance
= instance
;
2583 re
->distance
= distance
;
2585 re
->metric
= metric
;
2587 re
->table
= table_id
;
2588 re
->vrf_id
= vrf_id
;
2589 re
->nexthop_num
= 0;
2590 re
->uptime
= time(NULL
);
2594 nexthop
= nexthop_new();
2596 route_entry_nexthop_add(re
, nexthop
);
2598 return rib_add_multipath(afi
, safi
, p
, src_p
, re
);
2601 /* Schedule routes of a particular table (address-family) based on event. */
2602 static void rib_update_table(struct route_table
*table
,
2603 rib_update_event_t event
)
2605 struct route_node
*rn
;
2606 struct route_entry
*re
, *next
;
2608 /* Walk all routes and queue for processing, if appropriate for
2609 * the trigger event.
2611 for (rn
= route_top(table
); rn
; rn
= srcdest_route_next(rn
)) {
2613 * If we are looking at a route node and the node
2614 * has already been queued we don't
2615 * need to queue it up again
2618 && CHECK_FLAG(rib_dest_from_rnode(rn
)->flags
,
2619 RIB_ROUTE_ANY_QUEUED
))
2622 case RIB_UPDATE_IF_CHANGE
:
2623 /* Examine all routes that won't get processed by the
2625 * triggered by nexthop evaluation (NHT). This would be
2627 * kernel and certain static routes. Note that NHT will
2629 * triggered upon an interface event as connected routes
2631 * get queued for processing.
2633 RNODE_FOREACH_RE_SAFE (rn
, re
, next
) {
2636 if (re
->type
!= ZEBRA_ROUTE_SYSTEM
&&
2637 re
->type
!= ZEBRA_ROUTE_KERNEL
&&
2638 re
->type
!= ZEBRA_ROUTE_CONNECT
&&
2639 re
->type
!= ZEBRA_ROUTE_STATIC
)
2642 if (re
->type
!= ZEBRA_ROUTE_STATIC
) {
2647 for (nh
= re
->nexthop
; nh
; nh
= nh
->next
)
2648 if (!(nh
->type
== NEXTHOP_TYPE_IPV4
2649 || nh
->type
== NEXTHOP_TYPE_IPV6
))
2652 /* If we only have nexthops to a
2661 case RIB_UPDATE_RMAP_CHANGE
:
2662 case RIB_UPDATE_OTHER
:
2663 /* Right now, examine all routes. Can restrict to a
2665 * some cases (TODO).
2667 if (rnode_to_ribs(rn
))
2677 /* RIB update function. */
2678 void rib_update(vrf_id_t vrf_id
, rib_update_event_t event
)
2680 struct route_table
*table
;
2682 /* Process routes of interested address-families. */
2683 table
= zebra_vrf_table(AFI_IP
, SAFI_UNICAST
, vrf_id
);
2685 rib_update_table(table
, event
);
2687 table
= zebra_vrf_table(AFI_IP6
, SAFI_UNICAST
, vrf_id
);
2689 rib_update_table(table
, event
);
2692 /* Remove all routes which comes from non main table. */
2693 static void rib_weed_table(struct route_table
*table
)
2695 struct route_node
*rn
;
2696 struct route_entry
*re
;
2697 struct route_entry
*next
;
2700 for (rn
= route_top(table
); rn
; rn
= srcdest_route_next(rn
))
2701 RNODE_FOREACH_RE_SAFE (rn
, re
, next
) {
2702 if (CHECK_FLAG(re
->status
, ROUTE_ENTRY_REMOVED
))
2705 if (re
->table
!= zebrad
.rtm_table_default
2706 && re
->table
!= RT_TABLE_MAIN
)
2707 rib_delnode(rn
, re
);
2711 /* Delete all routes from non main table. */
2712 void rib_weed_tables(void)
2715 struct zebra_vrf
*zvrf
;
2717 RB_FOREACH (vrf
, vrf_id_head
, &vrfs_by_id
)
2718 if ((zvrf
= vrf
->info
) != NULL
) {
2719 rib_weed_table(zvrf
->table
[AFI_IP
][SAFI_UNICAST
]);
2720 rib_weed_table(zvrf
->table
[AFI_IP6
][SAFI_UNICAST
]);
2724 /* Delete self installed routes after zebra is relaunched. */
2725 static void rib_sweep_table(struct route_table
*table
)
2727 struct route_node
*rn
;
2728 struct route_entry
*re
;
2729 struct route_entry
*next
;
2730 struct nexthop
*nexthop
;
2735 for (rn
= route_top(table
); rn
; rn
= srcdest_route_next(rn
)) {
2736 RNODE_FOREACH_RE_SAFE (rn
, re
, next
) {
2737 if (IS_ZEBRA_DEBUG_RIB
)
2738 route_entry_dump(&rn
->p
, NULL
, re
);
2740 if (CHECK_FLAG(re
->status
, ROUTE_ENTRY_REMOVED
))
2743 if (!CHECK_FLAG(re
->flags
, ZEBRA_FLAG_SELFROUTE
))
2747 * So we are starting up and have received
2748 * routes from the kernel that we have installed
2749 * from a previous run of zebra but not cleaned
2750 * up ( say a kill -9 )
2751 * But since we haven't actually installed
2752 * them yet( we received them from the kernel )
2753 * we don't think they are active.
2754 * So let's pretend they are active to actually
2756 * In all honesty I'm not sure if we should
2757 * mark them as active when we receive them
2758 * This is startup only so probably ok.
2760 * If we ever decide to move rib_sweep_table
2761 * to a different spot (ie startup )
2762 * this decision needs to be revisited
2764 for (ALL_NEXTHOPS(re
->nexthop
, nexthop
))
2765 SET_FLAG(nexthop
->flags
, NEXTHOP_FLAG_FIB
);
2767 rib_uninstall_kernel(rn
, re
);
2768 rib_delnode(rn
, re
);
2773 /* Sweep all RIB tables. */
2774 void rib_sweep_route(void)
2777 struct zebra_vrf
*zvrf
;
2779 RB_FOREACH (vrf
, vrf_id_head
, &vrfs_by_id
) {
2780 if ((zvrf
= vrf
->info
) == NULL
)
2783 rib_sweep_table(zvrf
->table
[AFI_IP
][SAFI_UNICAST
]);
2784 rib_sweep_table(zvrf
->table
[AFI_IP6
][SAFI_UNICAST
]);
2788 /* Remove specific by protocol routes from 'table'. */
2789 static unsigned long rib_score_proto_table(u_char proto
, u_short instance
,
2790 struct route_table
*table
)
2792 struct route_node
*rn
;
2793 struct route_entry
*re
;
2794 struct route_entry
*next
;
2795 unsigned long n
= 0;
2798 for (rn
= route_top(table
); rn
; rn
= srcdest_route_next(rn
))
2799 RNODE_FOREACH_RE_SAFE (rn
, re
, next
) {
2800 if (CHECK_FLAG(re
->status
, ROUTE_ENTRY_REMOVED
))
2802 if (re
->type
== proto
2803 && re
->instance
== instance
) {
2804 rib_delnode(rn
, re
);
2811 /* Remove specific by protocol routes. */
2812 unsigned long rib_score_proto(u_char proto
, u_short instance
)
2815 struct zebra_vrf
*zvrf
;
2816 unsigned long cnt
= 0;
2818 RB_FOREACH (vrf
, vrf_id_head
, &vrfs_by_id
)
2819 if ((zvrf
= vrf
->info
) != NULL
)
2820 cnt
+= rib_score_proto_table(
2822 zvrf
->table
[AFI_IP
][SAFI_UNICAST
])
2823 + rib_score_proto_table(
2825 zvrf
->table
[AFI_IP6
][SAFI_UNICAST
]);
2830 /* Close RIB and clean up kernel routes. */
2831 void rib_close_table(struct route_table
*table
)
2833 struct route_node
*rn
;
2834 rib_table_info_t
*info
;
2842 for (rn
= route_top(table
); rn
; rn
= srcdest_route_next(rn
)) {
2843 dest
= rib_dest_from_rnode(rn
);
2845 if (dest
&& dest
->selected_fib
) {
2846 if (info
->safi
== SAFI_UNICAST
)
2847 hook_call(rib_update
, rn
, NULL
);
2849 if (!RIB_SYSTEM_ROUTE(dest
->selected_fib
))
2850 rib_uninstall_kernel(rn
, dest
->selected_fib
);
2855 /* Routing information base initialize. */
2858 rib_queue_init(&zebrad
);
2864 * Get the first vrf id that is greater than the given vrf id if any.
2866 * Returns TRUE if a vrf id was found, FALSE otherwise.
2868 static inline int vrf_id_get_next(vrf_id_t vrf_id
, vrf_id_t
*next_id_p
)
2872 vrf
= vrf_lookup_by_id(vrf_id
);
2874 vrf
= RB_NEXT(vrf_id_head
, vrf
);
2876 *next_id_p
= vrf
->vrf_id
;
2885 * rib_tables_iter_next
2887 * Returns the next table in the iteration.
2889 struct route_table
*rib_tables_iter_next(rib_tables_iter_t
*iter
)
2891 struct route_table
*table
;
2894 * Array that helps us go over all AFI/SAFI combinations via one
2901 {AFI_IP
, SAFI_UNICAST
}, {AFI_IP
, SAFI_MULTICAST
},
2902 {AFI_IP
, SAFI_LABELED_UNICAST
}, {AFI_IP6
, SAFI_UNICAST
},
2903 {AFI_IP6
, SAFI_MULTICAST
}, {AFI_IP6
, SAFI_LABELED_UNICAST
},
2908 switch (iter
->state
) {
2910 case RIB_TABLES_ITER_S_INIT
:
2911 iter
->vrf_id
= VRF_DEFAULT
;
2912 iter
->afi_safi_ix
= -1;
2916 case RIB_TABLES_ITER_S_ITERATING
:
2917 iter
->afi_safi_ix
++;
2920 while (iter
->afi_safi_ix
2921 < (int)ZEBRA_NUM_OF(afi_safis
)) {
2922 table
= zebra_vrf_table(
2923 afi_safis
[iter
->afi_safi_ix
].afi
,
2924 afi_safis
[iter
->afi_safi_ix
].safi
,
2929 iter
->afi_safi_ix
++;
2933 * Found another table in this vrf.
2939 * Done with all tables in the current vrf, go to the
2943 if (!vrf_id_get_next(iter
->vrf_id
, &iter
->vrf_id
))
2946 iter
->afi_safi_ix
= 0;
2951 case RIB_TABLES_ITER_S_DONE
:
2956 iter
->state
= RIB_TABLES_ITER_S_ITERATING
;
2958 iter
->state
= RIB_TABLES_ITER_S_DONE
;