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/zebra_vrf.h"
46 #include "zebra/redistribute.h"
47 #include "zebra/zebra_routemap.h"
48 #include "zebra/debug.h"
49 #include "zebra/zebra_rnh.h"
50 #include "zebra/interface.h"
51 #include "zebra/connected.h"
52 #include "zebra/zebra_vxlan.h"
53 #include "zebra/zapi_msg.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(uint32_t table_id
)
143 if ((table_id
== RT_TABLE_UNSPEC
) || (table_id
== RT_TABLE_LOCAL
)
144 || (table_id
== RT_TABLE_COMPAT
))
151 int is_zebra_main_routing_table(uint32_t table_id
)
153 if ((table_id
== RT_TABLE_MAIN
)
154 || (table_id
== zebrad
.rtm_table_default
))
159 int zebra_check_addr(const struct prefix
*p
)
161 if (p
->family
== AF_INET
) {
164 addr
= p
->u
.prefix4
.s_addr
;
167 if (IPV4_NET127(addr
) || IN_CLASSD(addr
)
168 || IPV4_LINKLOCAL(addr
))
171 if (p
->family
== AF_INET6
) {
172 if (IN6_IS_ADDR_LOOPBACK(&p
->u
.prefix6
))
174 if (IN6_IS_ADDR_LINKLOCAL(&p
->u
.prefix6
))
180 /* Add nexthop to the end of a rib node's nexthop list */
181 void route_entry_nexthop_add(struct route_entry
*re
, struct nexthop
*nexthop
)
183 nexthop_add(&re
->ng
.nexthop
, nexthop
);
189 * copy_nexthop - copy a nexthop to the rib structure.
191 void route_entry_copy_nexthops(struct route_entry
*re
, struct nexthop
*nh
)
193 assert(!re
->ng
.nexthop
);
194 copy_nexthops(&re
->ng
.nexthop
, nh
, NULL
);
195 for (struct nexthop
*nexthop
= nh
; nexthop
; nexthop
= nexthop
->next
)
199 /* Delete specified nexthop from the list. */
200 void route_entry_nexthop_delete(struct route_entry
*re
, struct nexthop
*nexthop
)
203 nexthop
->next
->prev
= nexthop
->prev
;
205 nexthop
->prev
->next
= nexthop
->next
;
207 re
->ng
.nexthop
= nexthop
->next
;
212 struct nexthop
*route_entry_nexthop_ifindex_add(struct route_entry
*re
,
216 struct nexthop
*nexthop
;
218 nexthop
= nexthop_new();
219 nexthop
->type
= NEXTHOP_TYPE_IFINDEX
;
220 nexthop
->ifindex
= ifindex
;
221 nexthop
->vrf_id
= nh_vrf_id
;
223 route_entry_nexthop_add(re
, nexthop
);
228 struct nexthop
*route_entry_nexthop_ipv4_add(struct route_entry
*re
,
229 struct in_addr
*ipv4
,
233 struct nexthop
*nexthop
;
235 nexthop
= nexthop_new();
236 nexthop
->type
= NEXTHOP_TYPE_IPV4
;
237 nexthop
->vrf_id
= nh_vrf_id
;
238 nexthop
->gate
.ipv4
= *ipv4
;
240 nexthop
->src
.ipv4
= *src
;
242 route_entry_nexthop_add(re
, nexthop
);
247 struct nexthop
*route_entry_nexthop_ipv4_ifindex_add(struct route_entry
*re
,
248 struct in_addr
*ipv4
,
253 struct nexthop
*nexthop
;
254 struct interface
*ifp
;
256 nexthop
= nexthop_new();
257 nexthop
->vrf_id
= nh_vrf_id
;
258 nexthop
->type
= NEXTHOP_TYPE_IPV4_IFINDEX
;
259 nexthop
->gate
.ipv4
= *ipv4
;
261 nexthop
->src
.ipv4
= *src
;
262 nexthop
->ifindex
= ifindex
;
263 ifp
= if_lookup_by_index(nexthop
->ifindex
, nh_vrf_id
);
264 /*Pending: need to think if null ifp here is ok during bootup?
265 There was a crash because ifp here was coming to be NULL */
267 if (connected_is_unnumbered(ifp
)
268 || CHECK_FLAG(re
->flags
, ZEBRA_FLAG_EVPN_ROUTE
)) {
269 SET_FLAG(nexthop
->flags
, NEXTHOP_FLAG_ONLINK
);
272 route_entry_nexthop_add(re
, nexthop
);
277 struct nexthop
*route_entry_nexthop_ipv6_add(struct route_entry
*re
,
278 struct in6_addr
*ipv6
,
281 struct nexthop
*nexthop
;
283 nexthop
= nexthop_new();
284 nexthop
->vrf_id
= nh_vrf_id
;
285 nexthop
->type
= NEXTHOP_TYPE_IPV6
;
286 nexthop
->gate
.ipv6
= *ipv6
;
288 route_entry_nexthop_add(re
, nexthop
);
293 struct nexthop
*route_entry_nexthop_ipv6_ifindex_add(struct route_entry
*re
,
294 struct in6_addr
*ipv6
,
298 struct nexthop
*nexthop
;
300 nexthop
= nexthop_new();
301 nexthop
->vrf_id
= nh_vrf_id
;
302 nexthop
->type
= NEXTHOP_TYPE_IPV6_IFINDEX
;
303 nexthop
->gate
.ipv6
= *ipv6
;
304 nexthop
->ifindex
= ifindex
;
305 if (CHECK_FLAG(re
->flags
, ZEBRA_FLAG_EVPN_ROUTE
))
306 SET_FLAG(nexthop
->flags
, NEXTHOP_FLAG_ONLINK
);
308 route_entry_nexthop_add(re
, nexthop
);
313 struct nexthop
*route_entry_nexthop_blackhole_add(struct route_entry
*re
,
314 enum blackhole_type bh_type
)
316 struct nexthop
*nexthop
;
318 nexthop
= nexthop_new();
319 nexthop
->vrf_id
= VRF_DEFAULT
;
320 nexthop
->type
= NEXTHOP_TYPE_BLACKHOLE
;
321 nexthop
->bh_type
= bh_type
;
323 route_entry_nexthop_add(re
, nexthop
);
328 static void nexthop_set_resolved(afi_t afi
, const struct nexthop
*newhop
,
329 struct nexthop
*nexthop
)
331 struct nexthop
*resolved_hop
;
333 resolved_hop
= nexthop_new();
334 SET_FLAG(resolved_hop
->flags
, NEXTHOP_FLAG_ACTIVE
);
336 resolved_hop
->vrf_id
= nexthop
->vrf_id
;
337 switch (newhop
->type
) {
338 case NEXTHOP_TYPE_IPV4
:
339 case NEXTHOP_TYPE_IPV4_IFINDEX
:
340 /* If the resolving route specifies a gateway, use it */
341 resolved_hop
->type
= newhop
->type
;
342 resolved_hop
->gate
.ipv4
= newhop
->gate
.ipv4
;
344 if (newhop
->ifindex
) {
345 resolved_hop
->type
= NEXTHOP_TYPE_IPV4_IFINDEX
;
346 resolved_hop
->ifindex
= newhop
->ifindex
;
347 if (newhop
->flags
& NEXTHOP_FLAG_ONLINK
)
348 resolved_hop
->flags
|= NEXTHOP_FLAG_ONLINK
;
351 case NEXTHOP_TYPE_IPV6
:
352 case NEXTHOP_TYPE_IPV6_IFINDEX
:
353 resolved_hop
->type
= newhop
->type
;
354 resolved_hop
->gate
.ipv6
= newhop
->gate
.ipv6
;
356 if (newhop
->ifindex
) {
357 resolved_hop
->type
= NEXTHOP_TYPE_IPV6_IFINDEX
;
358 resolved_hop
->ifindex
= newhop
->ifindex
;
361 case NEXTHOP_TYPE_IFINDEX
:
362 /* If the resolving route is an interface route,
363 * it means the gateway we are looking up is connected
364 * to that interface. (The actual network is _not_ onlink).
365 * Therefore, the resolved route should have the original
366 * gateway as nexthop as it is directly connected.
368 * On Linux, we have to set the onlink netlink flag because
369 * otherwise, the kernel won't accept the route.
371 resolved_hop
->flags
|= NEXTHOP_FLAG_ONLINK
;
373 resolved_hop
->type
= NEXTHOP_TYPE_IPV4_IFINDEX
;
374 resolved_hop
->gate
.ipv4
= nexthop
->gate
.ipv4
;
375 } else if (afi
== AFI_IP6
) {
376 resolved_hop
->type
= NEXTHOP_TYPE_IPV6_IFINDEX
;
377 resolved_hop
->gate
.ipv6
= nexthop
->gate
.ipv6
;
379 resolved_hop
->ifindex
= newhop
->ifindex
;
381 case NEXTHOP_TYPE_BLACKHOLE
:
382 resolved_hop
->type
= NEXTHOP_TYPE_BLACKHOLE
;
383 resolved_hop
->bh_type
= nexthop
->bh_type
;
387 /* Copy labels of the resolved route */
388 if (newhop
->nh_label
)
389 nexthop_add_labels(resolved_hop
, newhop
->nh_label_type
,
390 newhop
->nh_label
->num_labels
,
391 &newhop
->nh_label
->label
[0]);
393 resolved_hop
->rparent
= nexthop
;
394 nexthop_add(&nexthop
->resolved
, resolved_hop
);
397 /* If force flag is not set, do not modify falgs at all for uninstall
398 the route from FIB. */
399 static int nexthop_active(afi_t afi
, struct route_entry
*re
,
400 struct nexthop
*nexthop
, int set
,
401 struct route_node
*top
)
404 struct route_table
*table
;
405 struct route_node
*rn
;
406 struct route_entry
*match
= NULL
;
408 struct nexthop
*newhop
;
409 struct interface
*ifp
;
412 if ((nexthop
->type
== NEXTHOP_TYPE_IPV4
)
413 || nexthop
->type
== NEXTHOP_TYPE_IPV6
)
414 nexthop
->ifindex
= 0;
417 UNSET_FLAG(nexthop
->flags
, NEXTHOP_FLAG_RECURSIVE
);
418 nexthops_free(nexthop
->resolved
);
419 nexthop
->resolved
= NULL
;
423 /* Next hops (remote VTEPs) for EVPN routes are fully resolved. */
424 if (CHECK_FLAG(nexthop
->flags
, NEXTHOP_FLAG_EVPN_RVTEP
))
427 /* Skip nexthops that have been filtered out due to route-map */
428 /* The nexthops are specific to this route and so the same */
429 /* nexthop for a different route may not have this flag set */
430 if (CHECK_FLAG(nexthop
->flags
, NEXTHOP_FLAG_FILTERED
))
434 * Check to see if we should trust the passed in information
435 * for UNNUMBERED interfaces as that we won't find the GW
436 * address in the routing table.
438 if (CHECK_FLAG(nexthop
->flags
, NEXTHOP_FLAG_ONLINK
)) {
439 ifp
= if_lookup_by_index(nexthop
->ifindex
, nexthop
->vrf_id
);
440 if (ifp
&& connected_is_unnumbered(ifp
)) {
441 if (if_is_operative(ifp
))
449 /* Make lookup prefix. */
450 memset(&p
, 0, sizeof(struct prefix
));
454 p
.prefixlen
= IPV4_MAX_PREFIXLEN
;
455 p
.u
.prefix4
= nexthop
->gate
.ipv4
;
459 p
.prefixlen
= IPV6_MAX_PREFIXLEN
;
460 p
.u
.prefix6
= nexthop
->gate
.ipv6
;
463 assert(afi
!= AFI_IP
&& afi
!= AFI_IP6
);
467 table
= zebra_vrf_table(afi
, SAFI_UNICAST
, nexthop
->vrf_id
);
471 rn
= route_node_match(table
, (struct prefix
*)&p
);
473 route_unlock_node(rn
);
475 /* Lookup should halt if we've matched against ourselves ('top',
476 * if specified) - i.e., we cannot have a nexthop NH1 is
477 * resolved by a route NH1. The exception is if the route is a
480 if (top
&& rn
== top
)
481 if (((afi
== AFI_IP
) && (rn
->p
.prefixlen
!= 32))
482 || ((afi
== AFI_IP6
) && (rn
->p
.prefixlen
!= 128)))
485 /* Pick up selected route. */
486 /* However, do not resolve over default route unless explicitly
488 if (is_default_prefix(&rn
->p
)
489 && !rnh_resolve_via_default(p
.family
))
492 dest
= rib_dest_from_rnode(rn
);
493 if (dest
&& dest
->selected_fib
494 && !CHECK_FLAG(dest
->selected_fib
->status
,
496 && dest
->selected_fib
->type
!= ZEBRA_ROUTE_TABLE
)
497 match
= dest
->selected_fib
;
499 /* If there is no selected route or matched route is EGP, go up
504 } while (rn
&& rn
->info
== NULL
);
511 if (match
->type
== ZEBRA_ROUTE_CONNECT
) {
512 /* Directly point connected route. */
513 newhop
= match
->ng
.nexthop
;
515 if (nexthop
->type
== NEXTHOP_TYPE_IPV4
516 || nexthop
->type
== NEXTHOP_TYPE_IPV6
)
517 nexthop
->ifindex
= newhop
->ifindex
;
520 } else if (CHECK_FLAG(re
->flags
, ZEBRA_FLAG_ALLOW_RECURSION
)) {
522 for (ALL_NEXTHOPS(match
->ng
, newhop
)) {
523 if (!CHECK_FLAG(newhop
->flags
,
526 if (CHECK_FLAG(newhop
->flags
,
527 NEXTHOP_FLAG_RECURSIVE
))
531 SET_FLAG(nexthop
->flags
,
532 NEXTHOP_FLAG_RECURSIVE
);
534 ROUTE_ENTRY_NEXTHOPS_CHANGED
);
535 nexthop_set_resolved(afi
, newhop
,
541 re
->nexthop_mtu
= match
->mtu
;
543 } else if (re
->type
== ZEBRA_ROUTE_STATIC
) {
545 for (ALL_NEXTHOPS(match
->ng
, newhop
)) {
546 if (!CHECK_FLAG(newhop
->flags
,
551 SET_FLAG(nexthop
->flags
,
552 NEXTHOP_FLAG_RECURSIVE
);
553 nexthop_set_resolved(afi
, newhop
,
559 re
->nexthop_mtu
= match
->mtu
;
568 struct route_entry
*rib_match(afi_t afi
, safi_t safi
, vrf_id_t vrf_id
,
569 union g_addr
*addr
, struct route_node
**rn_out
)
572 struct route_table
*table
;
573 struct route_node
*rn
;
574 struct route_entry
*match
= NULL
;
575 struct nexthop
*newhop
;
578 table
= zebra_vrf_table(afi
, safi
, vrf_id
);
582 memset(&p
, 0, sizeof(struct prefix
));
585 p
.u
.prefix4
= addr
->ipv4
;
586 p
.prefixlen
= IPV4_MAX_PREFIXLEN
;
588 p
.u
.prefix6
= addr
->ipv6
;
589 p
.prefixlen
= IPV6_MAX_PREFIXLEN
;
592 rn
= route_node_match(table
, (struct prefix
*)&p
);
597 route_unlock_node(rn
);
599 dest
= rib_dest_from_rnode(rn
);
600 if (dest
&& dest
->selected_fib
601 && !CHECK_FLAG(dest
->selected_fib
->status
,
602 ROUTE_ENTRY_REMOVED
))
603 match
= dest
->selected_fib
;
605 /* If there is no selected route or matched route is EGP, go up
610 } while (rn
&& rn
->info
== NULL
);
614 if (match
->type
!= ZEBRA_ROUTE_CONNECT
) {
616 for (ALL_NEXTHOPS(match
->ng
, newhop
))
617 if (CHECK_FLAG(newhop
->flags
,
634 struct route_entry
*rib_match_ipv4_multicast(vrf_id_t vrf_id
,
636 struct route_node
**rn_out
)
638 struct route_entry
*re
= NULL
, *mre
= NULL
, *ure
= NULL
;
639 struct route_node
*m_rn
= NULL
, *u_rn
= NULL
;
640 union g_addr gaddr
= {.ipv4
= addr
};
642 switch (ipv4_multicast_mode
) {
643 case MCAST_MRIB_ONLY
:
644 return rib_match(AFI_IP
, SAFI_MULTICAST
, vrf_id
, &gaddr
,
646 case MCAST_URIB_ONLY
:
647 return rib_match(AFI_IP
, SAFI_UNICAST
, vrf_id
, &gaddr
, rn_out
);
648 case MCAST_NO_CONFIG
:
649 case MCAST_MIX_MRIB_FIRST
:
650 re
= mre
= rib_match(AFI_IP
, SAFI_MULTICAST
, vrf_id
, &gaddr
,
653 re
= ure
= rib_match(AFI_IP
, SAFI_UNICAST
, vrf_id
,
656 case MCAST_MIX_DISTANCE
:
657 mre
= rib_match(AFI_IP
, SAFI_MULTICAST
, vrf_id
, &gaddr
, &m_rn
);
658 ure
= rib_match(AFI_IP
, SAFI_UNICAST
, vrf_id
, &gaddr
, &u_rn
);
660 re
= ure
->distance
< mre
->distance
? ure
: mre
;
666 case MCAST_MIX_PFXLEN
:
667 mre
= rib_match(AFI_IP
, SAFI_MULTICAST
, vrf_id
, &gaddr
, &m_rn
);
668 ure
= rib_match(AFI_IP
, SAFI_UNICAST
, vrf_id
, &gaddr
, &u_rn
);
670 re
= u_rn
->p
.prefixlen
> m_rn
->p
.prefixlen
? ure
: mre
;
679 *rn_out
= (re
== mre
) ? m_rn
: u_rn
;
681 if (IS_ZEBRA_DEBUG_RIB
) {
683 inet_ntop(AF_INET
, &addr
, buf
, BUFSIZ
);
685 zlog_debug("%s: %s: vrf: %u found %s, using %s",
686 __func__
, buf
, vrf_id
,
687 mre
? (ure
? "MRIB+URIB" : "MRIB")
688 : ure
? "URIB" : "nothing",
689 re
== ure
? "URIB" : re
== mre
? "MRIB" : "none");
694 void multicast_mode_ipv4_set(enum multicast_mode mode
)
696 if (IS_ZEBRA_DEBUG_RIB
)
697 zlog_debug("%s: multicast lookup mode set (%d)", __func__
,
699 ipv4_multicast_mode
= mode
;
702 enum multicast_mode
multicast_mode_ipv4_get(void)
704 return ipv4_multicast_mode
;
707 struct route_entry
*rib_lookup_ipv4(struct prefix_ipv4
*p
, vrf_id_t vrf_id
)
709 struct route_table
*table
;
710 struct route_node
*rn
;
711 struct route_entry
*match
= NULL
;
712 struct nexthop
*nexthop
;
716 table
= zebra_vrf_table(AFI_IP
, SAFI_UNICAST
, vrf_id
);
720 rn
= route_node_lookup(table
, (struct prefix
*)p
);
722 /* No route for this prefix. */
727 route_unlock_node(rn
);
728 dest
= rib_dest_from_rnode(rn
);
730 if (dest
&& dest
->selected_fib
731 && !CHECK_FLAG(dest
->selected_fib
->status
, ROUTE_ENTRY_REMOVED
))
732 match
= dest
->selected_fib
;
737 if (match
->type
== ZEBRA_ROUTE_CONNECT
)
740 for (ALL_NEXTHOPS(match
->ng
, nexthop
))
741 if (CHECK_FLAG(nexthop
->flags
, NEXTHOP_FLAG_FIB
))
748 * This clone function, unlike its original rib_lookup_ipv4(), checks
749 * if specified IPv4 route record (prefix/mask -> gate) exists in
750 * the whole RIB and has ROUTE_ENTRY_SELECTED_FIB set.
754 * 0: exact match found
755 * 1: a match was found with a different gate
756 * 2: connected route found
757 * 3: no matches found
759 int rib_lookup_ipv4_route(struct prefix_ipv4
*p
, union sockunion
*qgate
,
762 struct route_table
*table
;
763 struct route_node
*rn
;
764 struct route_entry
*match
= NULL
;
765 struct nexthop
*nexthop
;
770 table
= zebra_vrf_table(AFI_IP
, SAFI_UNICAST
, vrf_id
);
772 return ZEBRA_RIB_LOOKUP_ERROR
;
774 /* Scan the RIB table for exactly matching RIB entry. */
775 rn
= route_node_lookup(table
, (struct prefix
*)p
);
777 /* No route for this prefix. */
779 return ZEBRA_RIB_NOTFOUND
;
782 route_unlock_node(rn
);
783 dest
= rib_dest_from_rnode(rn
);
785 /* Find out if a "selected" RR for the discovered RIB entry exists ever.
787 if (dest
&& dest
->selected_fib
788 && !CHECK_FLAG(dest
->selected_fib
->status
, ROUTE_ENTRY_REMOVED
))
789 match
= dest
->selected_fib
;
791 /* None such found :( */
793 return ZEBRA_RIB_NOTFOUND
;
795 if (match
->type
== ZEBRA_ROUTE_CONNECT
)
796 return ZEBRA_RIB_FOUND_CONNECTED
;
798 /* Ok, we have a cood candidate, let's check it's nexthop list... */
800 for (ALL_NEXTHOPS(match
->ng
, nexthop
))
801 if (CHECK_FLAG(nexthop
->flags
, NEXTHOP_FLAG_FIB
)) {
803 if (nexthop
->gate
.ipv4
.s_addr
== sockunion2ip(qgate
))
804 return ZEBRA_RIB_FOUND_EXACT
;
805 if (IS_ZEBRA_DEBUG_RIB
) {
806 char gate_buf
[INET_ADDRSTRLEN
],
807 qgate_buf
[INET_ADDRSTRLEN
];
808 inet_ntop(AF_INET
, &nexthop
->gate
.ipv4
.s_addr
,
809 gate_buf
, INET_ADDRSTRLEN
);
810 inet_ntop(AF_INET
, &sockunion2ip(qgate
),
811 qgate_buf
, INET_ADDRSTRLEN
);
812 zlog_debug("%s: qgate == %s, %s == %s",
814 nexthop
->rparent
? "rgate" : "gate",
820 return ZEBRA_RIB_FOUND_NOGATE
;
822 return ZEBRA_RIB_NOTFOUND
;
825 #define RIB_SYSTEM_ROUTE(R) \
826 ((R)->type == ZEBRA_ROUTE_KERNEL || (R)->type == ZEBRA_ROUTE_CONNECT)
828 /* This function verifies reachability of one given nexthop, which can be
829 * numbered or unnumbered, IPv4 or IPv6. The result is unconditionally stored
830 * in nexthop->flags field. If the 4th parameter, 'set', is non-zero,
831 * nexthop->ifindex will be updated appropriately as well.
832 * An existing route map can turn (otherwise active) nexthop into inactive, but
835 * The return value is the final value of 'ACTIVE' flag.
838 static unsigned nexthop_active_check(struct route_node
*rn
,
839 struct route_entry
*re
,
840 struct nexthop
*nexthop
, int set
)
842 struct interface
*ifp
;
843 route_map_result_t ret
= RMAP_MATCH
;
845 char buf
[SRCDEST2STR_BUFFER
];
846 const struct prefix
*p
, *src_p
;
847 srcdest_rnode_prefixes(rn
, &p
, &src_p
);
849 if (rn
->p
.family
== AF_INET
)
851 else if (rn
->p
.family
== AF_INET6
)
855 switch (nexthop
->type
) {
856 case NEXTHOP_TYPE_IFINDEX
:
857 ifp
= if_lookup_by_index(nexthop
->ifindex
, nexthop
->vrf_id
);
858 if (ifp
&& if_is_operative(ifp
))
859 SET_FLAG(nexthop
->flags
, NEXTHOP_FLAG_ACTIVE
);
861 UNSET_FLAG(nexthop
->flags
, NEXTHOP_FLAG_ACTIVE
);
863 case NEXTHOP_TYPE_IPV4
:
864 case NEXTHOP_TYPE_IPV4_IFINDEX
:
866 if (nexthop_active(AFI_IP
, re
, nexthop
, set
, rn
))
867 SET_FLAG(nexthop
->flags
, NEXTHOP_FLAG_ACTIVE
);
869 UNSET_FLAG(nexthop
->flags
, NEXTHOP_FLAG_ACTIVE
);
871 case NEXTHOP_TYPE_IPV6
:
873 if (nexthop_active(AFI_IP6
, re
, nexthop
, set
, rn
))
874 SET_FLAG(nexthop
->flags
, NEXTHOP_FLAG_ACTIVE
);
876 UNSET_FLAG(nexthop
->flags
, NEXTHOP_FLAG_ACTIVE
);
878 case NEXTHOP_TYPE_IPV6_IFINDEX
:
879 /* RFC 5549, v4 prefix with v6 NH */
880 if (rn
->p
.family
!= AF_INET
)
882 if (IN6_IS_ADDR_LINKLOCAL(&nexthop
->gate
.ipv6
)) {
883 ifp
= if_lookup_by_index(nexthop
->ifindex
,
885 if (ifp
&& if_is_operative(ifp
))
886 SET_FLAG(nexthop
->flags
, NEXTHOP_FLAG_ACTIVE
);
888 UNSET_FLAG(nexthop
->flags
, NEXTHOP_FLAG_ACTIVE
);
890 if (nexthop_active(AFI_IP6
, re
, nexthop
, set
, rn
))
891 SET_FLAG(nexthop
->flags
, NEXTHOP_FLAG_ACTIVE
);
893 UNSET_FLAG(nexthop
->flags
, NEXTHOP_FLAG_ACTIVE
);
896 case NEXTHOP_TYPE_BLACKHOLE
:
897 SET_FLAG(nexthop
->flags
, NEXTHOP_FLAG_ACTIVE
);
902 if (!CHECK_FLAG(nexthop
->flags
, NEXTHOP_FLAG_ACTIVE
))
905 /* XXX: What exactly do those checks do? Do we support
906 * e.g. IPv4 routes with IPv6 nexthops or vice versa? */
907 if (RIB_SYSTEM_ROUTE(re
) || (family
== AFI_IP
&& p
->family
!= AF_INET
)
908 || (family
== AFI_IP6
&& p
->family
!= AF_INET6
))
909 return CHECK_FLAG(nexthop
->flags
, NEXTHOP_FLAG_ACTIVE
);
911 /* The original code didn't determine the family correctly
912 * e.g. for NEXTHOP_TYPE_IFINDEX. Retrieve the correct afi
913 * from the rib_table_info in those cases.
914 * Possibly it may be better to use only the rib_table_info
918 rib_table_info_t
*info
;
920 info
= srcdest_rnode_table_info(rn
);
924 memset(&nexthop
->rmap_src
.ipv6
, 0, sizeof(union g_addr
));
926 /* It'll get set if required inside */
927 ret
= zebra_route_map_check(family
, re
->type
, re
->instance
, p
, nexthop
,
928 nexthop
->vrf_id
, re
->tag
);
929 if (ret
== RMAP_DENYMATCH
) {
930 if (IS_ZEBRA_DEBUG_RIB
) {
931 srcdest_rnode2str(rn
, buf
, sizeof(buf
));
933 "%u:%s: Filtering out with NH out %s due to route map",
935 ifindex2ifname(nexthop
->ifindex
,
938 UNSET_FLAG(nexthop
->flags
, NEXTHOP_FLAG_ACTIVE
);
940 return CHECK_FLAG(nexthop
->flags
, NEXTHOP_FLAG_ACTIVE
);
943 /* Iterate over all nexthops of the given RIB entry and refresh their
944 * ACTIVE flag. re->nexthop_active_num is updated accordingly. If any
945 * nexthop is found to toggle the ACTIVE flag, the whole re structure
946 * is flagged with ROUTE_ENTRY_CHANGED. The 4th 'set' argument is
947 * transparently passed to nexthop_active_check().
949 * Return value is the new number of active nexthops.
952 static int nexthop_active_update(struct route_node
*rn
, struct route_entry
*re
,
955 struct nexthop
*nexthop
;
956 union g_addr prev_src
;
957 unsigned int prev_active
, new_active
, old_num_nh
;
958 ifindex_t prev_index
;
959 old_num_nh
= re
->nexthop_active_num
;
961 re
->nexthop_active_num
= 0;
962 UNSET_FLAG(re
->status
, ROUTE_ENTRY_CHANGED
);
964 for (nexthop
= re
->ng
.nexthop
; nexthop
; nexthop
= nexthop
->next
) {
965 /* No protocol daemon provides src and so we're skipping
967 prev_src
= nexthop
->rmap_src
;
968 prev_active
= CHECK_FLAG(nexthop
->flags
, NEXTHOP_FLAG_ACTIVE
);
969 prev_index
= nexthop
->ifindex
;
970 if ((new_active
= nexthop_active_check(rn
, re
, nexthop
, set
)))
971 re
->nexthop_active_num
++;
972 /* Don't allow src setting on IPv6 addr for now */
973 if (prev_active
!= new_active
|| prev_index
!= nexthop
->ifindex
974 || ((nexthop
->type
>= NEXTHOP_TYPE_IFINDEX
975 && nexthop
->type
< NEXTHOP_TYPE_IPV6
)
976 && prev_src
.ipv4
.s_addr
977 != nexthop
->rmap_src
.ipv4
.s_addr
)
978 || ((nexthop
->type
>= NEXTHOP_TYPE_IPV6
979 && nexthop
->type
< NEXTHOP_TYPE_BLACKHOLE
)
980 && !(IPV6_ADDR_SAME(&prev_src
.ipv6
,
981 &nexthop
->rmap_src
.ipv6
)))) {
982 SET_FLAG(re
->status
, ROUTE_ENTRY_CHANGED
);
983 SET_FLAG(re
->status
, ROUTE_ENTRY_NEXTHOPS_CHANGED
);
987 if (old_num_nh
!= re
->nexthop_active_num
)
988 SET_FLAG(re
->status
, ROUTE_ENTRY_CHANGED
);
990 if (CHECK_FLAG(re
->status
, ROUTE_ENTRY_CHANGED
)) {
991 SET_FLAG(re
->status
, ROUTE_ENTRY_NEXTHOPS_CHANGED
);
994 return re
->nexthop_active_num
;
998 * Is this RIB labeled-unicast? It must be of type BGP and all paths
999 * (nexthops) must have a label.
1001 int zebra_rib_labeled_unicast(struct route_entry
*re
)
1003 struct nexthop
*nexthop
= NULL
;
1005 if (re
->type
!= ZEBRA_ROUTE_BGP
)
1008 for (ALL_NEXTHOPS(re
->ng
, nexthop
))
1009 if (!nexthop
->nh_label
|| !nexthop
->nh_label
->num_labels
)
1015 void kernel_route_rib_pass_fail(struct route_node
*rn
, const struct prefix
*p
,
1016 struct route_entry
*re
,
1017 enum dp_results res
)
1019 struct nexthop
*nexthop
;
1020 char buf
[PREFIX_STRLEN
];
1023 dest
= rib_dest_from_rnode(rn
);
1026 case DP_INSTALL_SUCCESS
:
1027 dest
->selected_fib
= re
;
1028 for (ALL_NEXTHOPS(re
->ng
, nexthop
)) {
1029 if (CHECK_FLAG(nexthop
->flags
, NEXTHOP_FLAG_RECURSIVE
))
1032 if (CHECK_FLAG(nexthop
->flags
, NEXTHOP_FLAG_ACTIVE
))
1033 SET_FLAG(nexthop
->flags
, NEXTHOP_FLAG_FIB
);
1035 UNSET_FLAG(nexthop
->flags
, NEXTHOP_FLAG_FIB
);
1037 zsend_route_notify_owner(re
, p
, ZAPI_ROUTE_INSTALLED
);
1039 case DP_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
, p
, ZAPI_ROUTE_FAIL_INSTALL
);
1048 zlog_warn("%u:%s: Route install failed", re
->vrf_id
,
1049 prefix2str(p
, buf
, sizeof(buf
)));
1051 case DP_DELETE_SUCCESS
:
1053 * The case where selected_fib is not re is
1054 * when we have received a system route
1055 * that is overriding our installed route
1056 * as such we should leave the selected_fib
1059 if (dest
->selected_fib
== re
)
1060 dest
->selected_fib
= NULL
;
1061 for (ALL_NEXTHOPS(re
->ng
, nexthop
))
1062 UNSET_FLAG(nexthop
->flags
, NEXTHOP_FLAG_FIB
);
1064 zsend_route_notify_owner(re
, p
, ZAPI_ROUTE_REMOVED
);
1066 case DP_DELETE_FAILURE
:
1068 * Should we set this to NULL if the
1071 dest
->selected_fib
= NULL
;
1072 zlog_warn("%u:%s: Route Deletion failure", re
->vrf_id
,
1073 prefix2str(p
, buf
, sizeof(buf
)));
1075 zsend_route_notify_owner(re
, p
, ZAPI_ROUTE_REMOVE_FAIL
);
1080 /* Update flag indicates whether this is a "replace" or not. Currently, this
1081 * is only used for IPv4.
1083 void rib_install_kernel(struct route_node
*rn
, struct route_entry
*re
,
1084 struct route_entry
*old
)
1086 struct nexthop
*nexthop
;
1087 rib_table_info_t
*info
= srcdest_rnode_table_info(rn
);
1088 const struct prefix
*p
, *src_p
;
1089 struct zebra_vrf
*zvrf
= vrf_info_lookup(re
->vrf_id
);
1091 srcdest_rnode_prefixes(rn
, &p
, &src_p
);
1093 if (info
->safi
!= SAFI_UNICAST
) {
1094 for (ALL_NEXTHOPS(re
->ng
, nexthop
))
1095 SET_FLAG(nexthop
->flags
, NEXTHOP_FLAG_FIB
);
1098 struct nexthop
*prev
;
1100 for (ALL_NEXTHOPS(re
->ng
, nexthop
)) {
1101 UNSET_FLAG (nexthop
->flags
, NEXTHOP_FLAG_DUPLICATE
);
1102 for (ALL_NEXTHOPS(re
->ng
, prev
)) {
1103 if (prev
== nexthop
)
1105 if (nexthop_same_firsthop(nexthop
, prev
)) {
1106 SET_FLAG(nexthop
->flags
,
1107 NEXTHOP_FLAG_DUPLICATE
);
1115 * If this is a replace to a new RE let the originator of the RE
1116 * know that they've lost
1118 if (old
&& (old
!= re
) && (old
->type
!= re
->type
))
1119 zsend_route_notify_owner(old
, p
, ZAPI_ROUTE_BETTER_ADMIN_WON
);
1122 * Make sure we update the FPM any time we send new information to
1125 hook_call(rib_update
, rn
, "installing in kernel");
1126 switch (kernel_route_rib(rn
, p
, src_p
, old
, re
)) {
1127 case DP_REQUEST_QUEUED
:
1128 zlog_err("No current known DataPlane interfaces can return this, please fix");
1130 case DP_REQUEST_FAILURE
:
1131 zlog_err("No current known Rib Install Failure cases, please fix");
1133 case DP_REQUEST_SUCCESS
:
1141 /* Uninstall the route from kernel. */
1142 void rib_uninstall_kernel(struct route_node
*rn
, struct route_entry
*re
)
1144 struct nexthop
*nexthop
;
1145 rib_table_info_t
*info
= srcdest_rnode_table_info(rn
);
1146 const struct prefix
*p
, *src_p
;
1147 struct zebra_vrf
*zvrf
= vrf_info_lookup(re
->vrf_id
);
1149 srcdest_rnode_prefixes(rn
, &p
, &src_p
);
1151 if (info
->safi
!= SAFI_UNICAST
) {
1152 for (ALL_NEXTHOPS(re
->ng
, nexthop
))
1153 UNSET_FLAG(nexthop
->flags
, NEXTHOP_FLAG_FIB
);
1158 * Make sure we update the FPM any time we send new information to
1161 hook_call(rib_update
, rn
, "uninstalling from kernel");
1162 switch (kernel_route_rib(rn
, p
, src_p
, re
, NULL
)) {
1163 case DP_REQUEST_QUEUED
:
1164 zlog_err("No current known DataPlane interfaces can return this, please fix");
1166 case DP_REQUEST_FAILURE
:
1167 zlog_err("No current known RIB Install Failure cases, please fix");
1169 case DP_REQUEST_SUCCESS
:
1178 /* Uninstall the route from kernel. */
1179 static void rib_uninstall(struct route_node
*rn
, struct route_entry
*re
)
1181 rib_table_info_t
*info
= srcdest_rnode_table_info(rn
);
1182 rib_dest_t
*dest
= rib_dest_from_rnode(rn
);
1184 if (dest
&& dest
->selected_fib
== re
) {
1185 if (info
->safi
== SAFI_UNICAST
)
1186 hook_call(rib_update
, rn
, "rib_uninstall");
1188 if (!RIB_SYSTEM_ROUTE(re
))
1189 rib_uninstall_kernel(rn
, re
);
1191 /* If labeled-unicast route, uninstall transit LSP. */
1192 if (zebra_rib_labeled_unicast(re
))
1193 zebra_mpls_lsp_uninstall(info
->zvrf
, rn
, re
);
1196 if (CHECK_FLAG(re
->flags
, ZEBRA_FLAG_SELECTED
)) {
1197 const struct prefix
*p
, *src_p
;
1199 srcdest_rnode_prefixes(rn
, &p
, &src_p
);
1201 redistribute_delete(p
, src_p
, re
);
1202 UNSET_FLAG(re
->flags
, ZEBRA_FLAG_SELECTED
);
1207 * rib_can_delete_dest
1209 * Returns TRUE if the given dest can be deleted from the table.
1211 static int rib_can_delete_dest(rib_dest_t
*dest
)
1218 * Don't delete the dest if we have to update the FPM about this
1221 if (CHECK_FLAG(dest
->flags
, RIB_DEST_UPDATE_FPM
)
1222 || CHECK_FLAG(dest
->flags
, RIB_DEST_SENT_TO_FPM
))
1231 * Garbage collect the rib dest corresponding to the given route node
1234 * Returns TRUE if the dest was deleted, FALSE otherwise.
1236 int rib_gc_dest(struct route_node
*rn
)
1240 dest
= rib_dest_from_rnode(rn
);
1244 if (!rib_can_delete_dest(dest
))
1247 if (IS_ZEBRA_DEBUG_RIB
) {
1248 struct zebra_vrf
*zvrf
;
1250 zvrf
= rib_dest_vrf(dest
);
1251 rnode_debug(rn
, zvrf_id(zvrf
), "removing dest from table");
1255 XFREE(MTYPE_RIB_DEST
, dest
);
1259 * Release the one reference that we keep on the route node.
1261 route_unlock_node(rn
);
1265 static void rib_process_add_fib(struct zebra_vrf
*zvrf
, struct route_node
*rn
,
1266 struct route_entry
*new)
1268 rib_dest_t
*dest
= rib_dest_from_rnode(rn
);
1270 hook_call(rib_update
, rn
, "new route selected");
1272 /* Update real nexthop. This may actually determine if nexthop is active
1274 if (!nexthop_active_update(rn
, new, 1)) {
1275 UNSET_FLAG(new->status
, ROUTE_ENTRY_CHANGED
);
1279 if (IS_ZEBRA_DEBUG_RIB
) {
1280 char buf
[SRCDEST2STR_BUFFER
];
1281 srcdest_rnode2str(rn
, buf
, sizeof(buf
));
1282 zlog_debug("%u:%s: Adding route rn %p, re %p (type %d)",
1283 zvrf_id(zvrf
), buf
, rn
, new, new->type
);
1286 /* If labeled-unicast route, install transit LSP. */
1287 if (zebra_rib_labeled_unicast(new))
1288 zebra_mpls_lsp_install(zvrf
, rn
, new);
1290 if (!RIB_SYSTEM_ROUTE(new))
1291 rib_install_kernel(rn
, new, NULL
);
1293 dest
->selected_fib
= new;
1295 UNSET_FLAG(new->status
, ROUTE_ENTRY_CHANGED
);
1298 static void rib_process_del_fib(struct zebra_vrf
*zvrf
, struct route_node
*rn
,
1299 struct route_entry
*old
)
1301 rib_dest_t
*dest
= rib_dest_from_rnode(rn
);
1302 hook_call(rib_update
, rn
, "removing existing route");
1304 /* Uninstall from kernel. */
1305 if (IS_ZEBRA_DEBUG_RIB
) {
1306 char buf
[SRCDEST2STR_BUFFER
];
1307 srcdest_rnode2str(rn
, buf
, sizeof(buf
));
1308 zlog_debug("%u:%s: Deleting route rn %p, re %p (type %d)",
1309 zvrf_id(zvrf
), buf
, rn
, old
, old
->type
);
1312 /* If labeled-unicast route, uninstall transit LSP. */
1313 if (zebra_rib_labeled_unicast(old
))
1314 zebra_mpls_lsp_uninstall(zvrf
, rn
, old
);
1316 if (!RIB_SYSTEM_ROUTE(old
))
1317 rib_uninstall_kernel(rn
, old
);
1320 * We are setting this to NULL here
1321 * because that is what we traditionally
1322 * have been doing. I am not positive
1323 * that this is the right thing to do
1324 * but let's leave the code alone
1325 * for the RIB_SYSTEM_ROUTE case
1327 dest
->selected_fib
= NULL
;
1330 /* Update nexthop for route, reset changed flag. */
1331 nexthop_active_update(rn
, old
, 1);
1332 UNSET_FLAG(old
->status
, ROUTE_ENTRY_CHANGED
);
1335 static void rib_process_update_fib(struct zebra_vrf
*zvrf
,
1336 struct route_node
*rn
,
1337 struct route_entry
*old
,
1338 struct route_entry
*new)
1340 struct nexthop
*nexthop
= NULL
;
1342 rib_dest_t
*dest
= rib_dest_from_rnode(rn
);
1345 * We have to install or update if a new route has been selected or
1346 * something has changed.
1348 if (new != old
|| CHECK_FLAG(new->status
, ROUTE_ENTRY_CHANGED
)) {
1349 hook_call(rib_update
, rn
, "updating existing route");
1351 /* Update the nexthop; we could determine here that nexthop is
1353 if (nexthop_active_update(rn
, new, 1))
1356 /* If nexthop is active, install the selected route, if
1358 * the install succeeds, cleanup flags for prior route, if
1363 if (IS_ZEBRA_DEBUG_RIB
) {
1364 char buf
[SRCDEST2STR_BUFFER
];
1365 srcdest_rnode2str(rn
, buf
, sizeof(buf
));
1368 "%u:%s: Updating route rn %p, re %p (type %d) "
1370 zvrf_id(zvrf
), buf
, rn
, new,
1371 new->type
, old
, old
->type
);
1374 "%u:%s: Updating route rn %p, re %p (type %d)",
1375 zvrf_id(zvrf
), buf
, rn
, new,
1379 /* If labeled-unicast route, uninstall transit LSP. */
1380 if (zebra_rib_labeled_unicast(old
))
1381 zebra_mpls_lsp_uninstall(zvrf
, rn
, old
);
1383 /* Non-system route should be installed. */
1384 if (!RIB_SYSTEM_ROUTE(new)) {
1385 /* If labeled-unicast route, install transit
1387 if (zebra_rib_labeled_unicast(new))
1388 zebra_mpls_lsp_install(zvrf
, rn
, new);
1390 rib_install_kernel(rn
, new, old
);
1393 * We do not need to install the
1394 * selected route because it
1395 * is already isntalled by
1396 * the system( ie not us )
1397 * so just mark it as winning
1398 * we do need to ensure that
1399 * if we uninstall a route
1400 * from ourselves we don't
1401 * over write this pointer
1403 dest
->selected_fib
= NULL
;
1405 /* If install succeeded or system route, cleanup flags
1406 * for prior route. */
1408 if (RIB_SYSTEM_ROUTE(new)) {
1409 if (!RIB_SYSTEM_ROUTE(old
))
1410 rib_uninstall_kernel(rn
, old
);
1412 for (nexthop
= old
->ng
.nexthop
; nexthop
;
1413 nexthop
= nexthop
->next
)
1414 UNSET_FLAG(nexthop
->flags
,
1421 * If nexthop for selected route is not active or install
1423 * may need to uninstall and delete for redistribution.
1426 if (IS_ZEBRA_DEBUG_RIB
) {
1427 char buf
[SRCDEST2STR_BUFFER
];
1428 srcdest_rnode2str(rn
, buf
, sizeof(buf
));
1431 "%u:%s: Deleting route rn %p, re %p (type %d) "
1432 "old %p (type %d) - nexthop inactive",
1433 zvrf_id(zvrf
), buf
, rn
, new,
1434 new->type
, old
, old
->type
);
1437 "%u:%s: Deleting route rn %p, re %p (type %d) - nexthop inactive",
1438 zvrf_id(zvrf
), buf
, rn
, new,
1442 /* If labeled-unicast route, uninstall transit LSP. */
1443 if (zebra_rib_labeled_unicast(old
))
1444 zebra_mpls_lsp_uninstall(zvrf
, rn
, old
);
1446 if (!RIB_SYSTEM_ROUTE(old
))
1447 rib_uninstall_kernel(rn
, old
);
1449 dest
->selected_fib
= NULL
;
1453 * Same route selected; check if in the FIB and if not,
1455 * is housekeeping code to deal with race conditions in kernel
1457 * netlink reporting interface up before IPv4 or IPv6 protocol
1461 if (!RIB_SYSTEM_ROUTE(new)) {
1462 bool in_fib
= false;
1464 for (ALL_NEXTHOPS(new->ng
, nexthop
))
1465 if (CHECK_FLAG(nexthop
->flags
,
1466 NEXTHOP_FLAG_FIB
)) {
1471 rib_install_kernel(rn
, new, NULL
);
1475 /* Update prior route. */
1477 /* Set real nexthop. */
1478 nexthop_active_update(rn
, old
, 1);
1479 UNSET_FLAG(old
->status
, ROUTE_ENTRY_CHANGED
);
1482 /* Clear changed flag. */
1483 UNSET_FLAG(new->status
, ROUTE_ENTRY_CHANGED
);
1486 /* Check if 'alternate' RIB entry is better than 'current'. */
1487 static struct route_entry
*rib_choose_best(struct route_entry
*current
,
1488 struct route_entry
*alternate
)
1490 if (current
== NULL
)
1493 /* filter route selection in following order:
1494 * - connected beats other types
1495 * - lower distance beats higher
1496 * - lower metric beats higher for equal distance
1497 * - last, hence oldest, route wins tie break.
1500 /* Connected routes. Pick the last connected
1501 * route of the set of lowest metric connected routes.
1503 if (alternate
->type
== ZEBRA_ROUTE_CONNECT
) {
1504 if (current
->type
!= ZEBRA_ROUTE_CONNECT
1505 || alternate
->metric
<= current
->metric
)
1511 if (current
->type
== ZEBRA_ROUTE_CONNECT
)
1514 /* higher distance loses */
1515 if (alternate
->distance
< current
->distance
)
1517 if (current
->distance
< alternate
->distance
)
1520 /* metric tie-breaks equal distance */
1521 if (alternate
->metric
<= current
->metric
)
1527 /* Core function for processing routing information base. */
1528 static void rib_process(struct route_node
*rn
)
1530 struct route_entry
*re
;
1531 struct route_entry
*next
;
1532 struct route_entry
*old_selected
= NULL
;
1533 struct route_entry
*new_selected
= NULL
;
1534 struct route_entry
*old_fib
= NULL
;
1535 struct route_entry
*new_fib
= NULL
;
1536 struct route_entry
*best
= NULL
;
1537 char buf
[SRCDEST2STR_BUFFER
];
1539 struct zebra_vrf
*zvrf
= NULL
;
1540 const struct prefix
*p
, *src_p
;
1542 srcdest_rnode_prefixes(rn
, &p
, &src_p
);
1543 vrf_id_t vrf_id
= VRF_UNKNOWN
;
1547 dest
= rib_dest_from_rnode(rn
);
1549 zvrf
= rib_dest_vrf(dest
);
1550 vrf_id
= zvrf_id(zvrf
);
1553 if (IS_ZEBRA_DEBUG_RIB
)
1554 srcdest_rnode2str(rn
, buf
, sizeof(buf
));
1556 if (IS_ZEBRA_DEBUG_RIB_DETAILED
)
1557 zlog_debug("%u:%s: Processing rn %p", vrf_id
, buf
, rn
);
1560 * we can have rn's that have a NULL info pointer
1561 * (dest). As such let's not let the deref happen
1562 * additionally we know RNODE_FOREACH_RE_SAFE
1563 * will not iterate so we are ok.
1566 old_fib
= dest
->selected_fib
;
1568 RNODE_FOREACH_RE_SAFE (rn
, re
, next
) {
1569 if (IS_ZEBRA_DEBUG_RIB_DETAILED
)
1571 "%u:%s: Examine re %p (type %d) status %x flags %x "
1572 "dist %d metric %d",
1573 vrf_id
, buf
, re
, re
->type
, re
->status
,
1574 re
->flags
, re
->distance
, re
->metric
);
1576 UNSET_FLAG(re
->status
, ROUTE_ENTRY_NEXTHOPS_CHANGED
);
1578 /* Currently selected re. */
1579 if (CHECK_FLAG(re
->flags
, ZEBRA_FLAG_SELECTED
)) {
1580 assert(old_selected
== NULL
);
1584 /* Skip deleted entries from selection */
1585 if (CHECK_FLAG(re
->status
, ROUTE_ENTRY_REMOVED
))
1588 /* Skip unreachable nexthop. */
1589 /* This first call to nexthop_active_update is merely to
1591 * there's any change to nexthops associated with this RIB
1593 * rib_process() can be invoked due to an external event such as
1595 * down or due to next-hop-tracking evaluation. In the latter
1597 * a decision has already been made that the NHs have changed.
1599 * need to invoke a potentially expensive call again. Further,
1601 * the change might be in a recursive NH which is not caught in
1602 * the nexthop_active_update() code. Thus, we might miss changes
1606 if (!CHECK_FLAG(re
->status
, ROUTE_ENTRY_CHANGED
)
1607 && !nexthop_active_update(rn
, re
, 0)) {
1608 if (re
->type
== ZEBRA_ROUTE_TABLE
) {
1609 /* XXX: HERE BE DRAGONS!!!!!
1610 * In all honesty, I have not yet figured out
1612 * does or why the ROUTE_ENTRY_CHANGED test
1614 * or why we need to delete a route here, and
1616 * this concerns both selected and fib route, or
1619 /* This entry was denied by the 'ip protocol
1620 * table' route-map, we
1621 * need to delete it */
1622 if (re
!= old_selected
) {
1623 if (IS_ZEBRA_DEBUG_RIB
)
1625 "%s: %u:%s: imported via import-table but denied "
1626 "by the ip protocol table route-map",
1627 __func__
, vrf_id
, buf
);
1630 SET_FLAG(re
->status
,
1631 ROUTE_ENTRY_REMOVED
);
1637 /* Infinite distance. */
1638 if (re
->distance
== DISTANCE_INFINITY
) {
1639 UNSET_FLAG(re
->status
, ROUTE_ENTRY_CHANGED
);
1643 if (CHECK_FLAG(re
->flags
, ZEBRA_FLAG_FIB_OVERRIDE
)) {
1644 best
= rib_choose_best(new_fib
, re
);
1645 if (new_fib
&& best
!= new_fib
)
1646 UNSET_FLAG(new_fib
->status
,
1647 ROUTE_ENTRY_CHANGED
);
1650 best
= rib_choose_best(new_selected
, re
);
1651 if (new_selected
&& best
!= new_selected
)
1652 UNSET_FLAG(new_selected
->status
,
1653 ROUTE_ENTRY_CHANGED
);
1654 new_selected
= best
;
1657 UNSET_FLAG(re
->status
, ROUTE_ENTRY_CHANGED
);
1658 } /* RNODE_FOREACH_RE */
1660 /* If no FIB override route, use the selected route also for FIB */
1661 if (new_fib
== NULL
)
1662 new_fib
= new_selected
;
1664 /* After the cycle is finished, the following pointers will be set:
1665 * old_selected --- RE entry currently having SELECTED
1666 * new_selected --- RE entry that is newly SELECTED
1667 * old_fib --- RE entry currently in kernel FIB
1668 * new_fib --- RE entry that is newly to be in kernel FIB
1670 * new_selected will get SELECTED flag, and is going to be redistributed
1671 * the zclients. new_fib (which can be new_selected) will be installed
1675 if (IS_ZEBRA_DEBUG_RIB_DETAILED
) {
1677 "%u:%s: After processing: old_selected %p new_selected %p old_fib %p new_fib %p",
1678 vrf_id
, buf
, (void *)old_selected
, (void *)new_selected
,
1679 (void *)old_fib
, (void *)new_fib
);
1682 /* Buffer ROUTE_ENTRY_CHANGED here, because it will get cleared if
1683 * fib == selected */
1684 bool selected_changed
= new_selected
&& CHECK_FLAG(new_selected
->status
,
1685 ROUTE_ENTRY_CHANGED
);
1687 /* Update fib according to selection results */
1688 if (new_fib
&& old_fib
)
1689 rib_process_update_fib(zvrf
, rn
, old_fib
, new_fib
);
1691 rib_process_add_fib(zvrf
, rn
, new_fib
);
1693 rib_process_del_fib(zvrf
, rn
, old_fib
);
1695 /* Redistribute SELECTED entry */
1696 if (old_selected
!= new_selected
|| selected_changed
) {
1697 struct nexthop
*nexthop
= NULL
;
1699 /* Check if we have a FIB route for the destination, otherwise,
1700 * don't redistribute it */
1702 for (ALL_NEXTHOPS(new_fib
->ng
, nexthop
)) {
1703 if (CHECK_FLAG(nexthop
->flags
,
1704 NEXTHOP_FLAG_FIB
)) {
1710 new_selected
= NULL
;
1712 if (new_selected
&& new_selected
!= new_fib
) {
1713 nexthop_active_update(rn
, new_selected
, 1);
1714 UNSET_FLAG(new_selected
->status
, ROUTE_ENTRY_CHANGED
);
1719 redistribute_delete(p
, src_p
, old_selected
);
1720 if (old_selected
!= new_selected
)
1721 UNSET_FLAG(old_selected
->flags
,
1722 ZEBRA_FLAG_SELECTED
);
1726 /* Install new or replace existing redistributed entry
1728 SET_FLAG(new_selected
->flags
, ZEBRA_FLAG_SELECTED
);
1729 redistribute_update(p
, src_p
, new_selected
,
1734 /* Remove all RE entries queued for removal */
1735 RNODE_FOREACH_RE_SAFE (rn
, re
, next
) {
1736 if (CHECK_FLAG(re
->status
, ROUTE_ENTRY_REMOVED
)) {
1737 if (IS_ZEBRA_DEBUG_RIB
) {
1738 rnode_debug(rn
, vrf_id
, "rn %p, removing re %p",
1739 (void *)rn
, (void *)re
);
1746 * Check if the dest can be deleted now.
1751 /* Take a list of route_node structs and return 1, if there was a record
1752 * picked from it and processed by rib_process(). Don't process more,
1753 * than one RN record; operate only in the specified sub-queue.
1755 static unsigned int process_subq(struct list
*subq
, uint8_t qindex
)
1757 struct listnode
*lnode
= listhead(subq
);
1758 struct route_node
*rnode
;
1760 struct zebra_vrf
*zvrf
= NULL
;
1765 rnode
= listgetdata(lnode
);
1766 dest
= rib_dest_from_rnode(rnode
);
1768 zvrf
= rib_dest_vrf(dest
);
1772 if (IS_ZEBRA_DEBUG_RIB_DETAILED
) {
1773 char buf
[SRCDEST2STR_BUFFER
];
1774 srcdest_rnode2str(rnode
, buf
, sizeof(buf
));
1775 zlog_debug("%u:%s: rn %p dequeued from sub-queue %u",
1776 zvrf
? zvrf_id(zvrf
) : 0, buf
, rnode
, qindex
);
1780 UNSET_FLAG(rib_dest_from_rnode(rnode
)->flags
,
1781 RIB_ROUTE_QUEUED(qindex
));
1786 zlog_debug ("%s: called for route_node (%p, %d) with no ribs",
1787 __func__
, rnode
, rnode
->lock
);
1788 zlog_backtrace(LOG_DEBUG
);
1791 route_unlock_node(rnode
);
1792 list_delete_node(subq
, lnode
);
1797 * All meta queues have been processed. Trigger next-hop evaluation.
1799 static void meta_queue_process_complete(struct work_queue
*dummy
)
1802 struct zebra_vrf
*zvrf
;
1804 /* Evaluate nexthops for those VRFs which underwent route processing.
1806 * should limit the evaluation to the necessary VRFs in most common
1809 RB_FOREACH (vrf
, vrf_id_head
, &vrfs_by_id
) {
1811 if (zvrf
== NULL
|| !(zvrf
->flags
& ZEBRA_VRF_RIB_SCHEDULED
))
1814 zvrf
->flags
&= ~ZEBRA_VRF_RIB_SCHEDULED
;
1815 zebra_evaluate_rnh(zvrf_id(zvrf
), AF_INET
, 0, RNH_NEXTHOP_TYPE
,
1817 zebra_evaluate_rnh(zvrf_id(zvrf
), AF_INET
, 0,
1818 RNH_IMPORT_CHECK_TYPE
, NULL
);
1819 zebra_evaluate_rnh(zvrf_id(zvrf
), AF_INET6
, 0, RNH_NEXTHOP_TYPE
,
1821 zebra_evaluate_rnh(zvrf_id(zvrf
), AF_INET6
, 0,
1822 RNH_IMPORT_CHECK_TYPE
, NULL
);
1825 /* Schedule LSPs for processing, if needed. */
1826 zvrf
= vrf_info_lookup(VRF_DEFAULT
);
1827 if (mpls_should_lsps_be_processed(zvrf
)) {
1828 if (IS_ZEBRA_DEBUG_MPLS
)
1830 "%u: Scheduling all LSPs upon RIB completion",
1832 zebra_mpls_lsp_schedule(zvrf
);
1833 mpls_unmark_lsps_for_processing(zvrf
);
1837 /* Dispatch the meta queue by picking, processing and unlocking the next RN from
1838 * a non-empty sub-queue with lowest priority. wq is equal to zebra->ribq and
1840 * is pointed to the meta queue structure.
1842 static wq_item_status
meta_queue_process(struct work_queue
*dummy
, void *data
)
1844 struct meta_queue
*mq
= data
;
1847 for (i
= 0; i
< MQ_SIZE
; i
++)
1848 if (process_subq(mq
->subq
[i
], i
)) {
1852 return mq
->size
? WQ_REQUEUE
: WQ_SUCCESS
;
1856 * Map from rib types to queue type (priority) in meta queue
1858 static const uint8_t meta_queue_map
[ZEBRA_ROUTE_MAX
] = {
1859 [ZEBRA_ROUTE_SYSTEM
] = 4,
1860 [ZEBRA_ROUTE_KERNEL
] = 0,
1861 [ZEBRA_ROUTE_CONNECT
] = 0,
1862 [ZEBRA_ROUTE_STATIC
] = 1,
1863 [ZEBRA_ROUTE_RIP
] = 2,
1864 [ZEBRA_ROUTE_RIPNG
] = 2,
1865 [ZEBRA_ROUTE_OSPF
] = 2,
1866 [ZEBRA_ROUTE_OSPF6
] = 2,
1867 [ZEBRA_ROUTE_ISIS
] = 2,
1868 [ZEBRA_ROUTE_BGP
] = 3,
1869 [ZEBRA_ROUTE_PIM
] = 4, // Shouldn't happen but for safety
1870 [ZEBRA_ROUTE_EIGRP
] = 2,
1871 [ZEBRA_ROUTE_NHRP
] = 2,
1872 [ZEBRA_ROUTE_HSLS
] = 4,
1873 [ZEBRA_ROUTE_OLSR
] = 4,
1874 [ZEBRA_ROUTE_TABLE
] = 1,
1875 [ZEBRA_ROUTE_LDP
] = 4,
1876 [ZEBRA_ROUTE_VNC
] = 3,
1877 [ZEBRA_ROUTE_VNC_DIRECT
] = 3,
1878 [ZEBRA_ROUTE_VNC_DIRECT_RH
] = 3,
1879 [ZEBRA_ROUTE_BGP_DIRECT
] = 3,
1880 [ZEBRA_ROUTE_BGP_DIRECT_EXT
] = 3,
1881 [ZEBRA_ROUTE_BABEL
] = 2,
1882 [ZEBRA_ROUTE_ALL
] = 4, // Shouldn't happen but for safety
1885 /* Look into the RN and queue it into one or more priority queues,
1886 * increasing the size for each data push done.
1888 static void rib_meta_queue_add(struct meta_queue
*mq
, struct route_node
*rn
)
1890 struct route_entry
*re
;
1892 RNODE_FOREACH_RE (rn
, re
) {
1893 uint8_t qindex
= meta_queue_map
[re
->type
];
1894 struct zebra_vrf
*zvrf
;
1896 /* Invariant: at this point we always have rn->info set. */
1897 if (CHECK_FLAG(rib_dest_from_rnode(rn
)->flags
,
1898 RIB_ROUTE_QUEUED(qindex
))) {
1899 if (IS_ZEBRA_DEBUG_RIB_DETAILED
)
1902 "rn %p is already queued in sub-queue %u",
1903 (void *)rn
, qindex
);
1907 SET_FLAG(rib_dest_from_rnode(rn
)->flags
,
1908 RIB_ROUTE_QUEUED(qindex
));
1909 listnode_add(mq
->subq
[qindex
], rn
);
1910 route_lock_node(rn
);
1913 if (IS_ZEBRA_DEBUG_RIB_DETAILED
)
1914 rnode_debug(rn
, re
->vrf_id
,
1915 "queued rn %p into sub-queue %u",
1916 (void *)rn
, qindex
);
1918 zvrf
= zebra_vrf_lookup_by_id(re
->vrf_id
);
1920 zvrf
->flags
|= ZEBRA_VRF_RIB_SCHEDULED
;
1924 /* Add route_node to work queue and schedule processing */
1925 void rib_queue_add(struct route_node
*rn
)
1929 /* Pointless to queue a route_node with no RIB entries to add or remove
1931 if (!rnode_to_ribs(rn
)) {
1932 zlog_debug("%s: called for route_node (%p, %d) with no ribs",
1933 __func__
, (void *)rn
, rn
->lock
);
1934 zlog_backtrace(LOG_DEBUG
);
1938 if (zebrad
.ribq
== NULL
) {
1939 zlog_err("%s: work_queue does not exist!", __func__
);
1944 * The RIB queue should normally be either empty or holding the only
1945 * work_queue_item element. In the latter case this element would
1946 * hold a pointer to the meta queue structure, which must be used to
1947 * actually queue the route nodes to process. So create the MQ
1948 * holder, if necessary, then push the work into it in any case.
1949 * This semantics was introduced after 0.99.9 release.
1951 if (work_queue_empty(zebrad
.ribq
))
1952 work_queue_add(zebrad
.ribq
, zebrad
.mq
);
1954 rib_meta_queue_add(zebrad
.mq
, rn
);
1959 /* Create new meta queue.
1960 A destructor function doesn't seem to be necessary here.
1962 static struct meta_queue
*meta_queue_new(void)
1964 struct meta_queue
*new;
1967 new = XCALLOC(MTYPE_WORK_QUEUE
, sizeof(struct meta_queue
));
1970 for (i
= 0; i
< MQ_SIZE
; i
++) {
1971 new->subq
[i
] = list_new();
1972 assert(new->subq
[i
]);
1978 void meta_queue_free(struct meta_queue
*mq
)
1982 for (i
= 0; i
< MQ_SIZE
; i
++)
1983 list_delete_and_null(&mq
->subq
[i
]);
1985 XFREE(MTYPE_WORK_QUEUE
, mq
);
1988 /* initialise zebra rib work queue */
1989 static void rib_queue_init(struct zebra_t
*zebra
)
1994 work_queue_new(zebra
->master
, "route_node processing"))) {
1995 zlog_err("%s: could not initialise work queue!", __func__
);
1999 /* fill in the work queue spec */
2000 zebra
->ribq
->spec
.workfunc
= &meta_queue_process
;
2001 zebra
->ribq
->spec
.errorfunc
= NULL
;
2002 zebra
->ribq
->spec
.completion_func
= &meta_queue_process_complete
;
2003 /* XXX: TODO: These should be runtime configurable via vty */
2004 zebra
->ribq
->spec
.max_retries
= 3;
2005 zebra
->ribq
->spec
.hold
= ZEBRA_RIB_PROCESS_HOLD_TIME
;
2007 if (!(zebra
->mq
= meta_queue_new())) {
2008 zlog_err("%s: could not initialise meta queue!", __func__
);
2014 /* RIB updates are processed via a queue of pointers to route_nodes.
2016 * The queue length is bounded by the maximal size of the routing table,
2017 * as a route_node will not be requeued, if already queued.
2019 * REs are submitted via rib_addnode or rib_delnode which set minimal
2020 * state, or static_install_route (when an existing RE is updated)
2021 * and then submit route_node to queue for best-path selection later.
2022 * Order of add/delete state changes are preserved for any given RE.
2024 * Deleted REs are reaped during best-path selection.
2027 * |-> rib_link or unset ROUTE_ENTRY_REMOVE |->Update kernel with
2028 * |-------->| | best RE, if required
2030 * static_install->|->rib_addqueue...... -> rib_process
2032 * |-------->| |-> rib_unlink
2033 * |-> set ROUTE_ENTRY_REMOVE |
2034 * rib_delnode (RE freed)
2036 * The 'info' pointer of a route_node points to a rib_dest_t
2037 * ('dest'). Queueing state for a route_node is kept on the dest. The
2038 * dest is created on-demand by rib_link() and is kept around at least
2039 * as long as there are ribs hanging off it (@see rib_gc_dest()).
2041 * Refcounting (aka "locking" throughout the GNU Zebra and Quagga code):
2043 * - route_nodes: refcounted by:
2044 * - dest attached to route_node:
2045 * - managed by: rib_link/rib_gc_dest
2046 * - route_node processing queue
2047 * - managed by: rib_addqueue, rib_process.
2051 /* Add RE to head of the route node. */
2052 static void rib_link(struct route_node
*rn
, struct route_entry
*re
, int process
)
2054 struct route_entry
*head
;
2057 const char *rmap_name
;
2061 dest
= rib_dest_from_rnode(rn
);
2063 if (IS_ZEBRA_DEBUG_RIB_DETAILED
)
2064 rnode_debug(rn
, re
->vrf_id
, "rn %p adding dest", rn
);
2066 dest
= XCALLOC(MTYPE_RIB_DEST
, sizeof(rib_dest_t
));
2067 route_lock_node(rn
); /* rn route table reference */
2072 head
= dest
->routes
;
2079 afi
= (rn
->p
.family
== AF_INET
)
2081 : (rn
->p
.family
== AF_INET6
) ? AFI_IP6
: AFI_MAX
;
2082 if (is_zebra_import_table_enabled(afi
, re
->table
)) {
2083 rmap_name
= zebra_get_import_table_route_map(afi
, re
->table
);
2084 zebra_add_import_table_entry(rn
, re
, rmap_name
);
2089 static void rib_addnode(struct route_node
*rn
,
2090 struct route_entry
*re
, int process
)
2092 /* RE node has been un-removed before route-node is processed.
2093 * route_node must hence already be on the queue for processing..
2095 if (CHECK_FLAG(re
->status
, ROUTE_ENTRY_REMOVED
)) {
2096 if (IS_ZEBRA_DEBUG_RIB
)
2097 rnode_debug(rn
, re
->vrf_id
, "rn %p, un-removed re %p",
2098 (void *)rn
, (void *)re
);
2100 UNSET_FLAG(re
->status
, ROUTE_ENTRY_REMOVED
);
2103 rib_link(rn
, re
, process
);
2109 * Detach a rib structure from a route_node.
2111 * Note that a call to rib_unlink() should be followed by a call to
2112 * rib_gc_dest() at some point. This allows a rib_dest_t that is no
2113 * longer required to be deleted.
2115 void rib_unlink(struct route_node
*rn
, struct route_entry
*re
)
2121 if (IS_ZEBRA_DEBUG_RIB
)
2122 rnode_debug(rn
, re
->vrf_id
, "rn %p, re %p", (void *)rn
,
2125 dest
= rib_dest_from_rnode(rn
);
2128 re
->next
->prev
= re
->prev
;
2131 re
->prev
->next
= re
->next
;
2133 dest
->routes
= re
->next
;
2136 if (dest
->selected_fib
== re
)
2137 dest
->selected_fib
= NULL
;
2139 nexthops_free(re
->ng
.nexthop
);
2140 XFREE(MTYPE_RE
, re
);
2143 void rib_delnode(struct route_node
*rn
, struct route_entry
*re
)
2147 if (IS_ZEBRA_DEBUG_RIB
)
2148 rnode_debug(rn
, re
->vrf_id
, "rn %p, re %p, removing",
2149 (void *)rn
, (void *)re
);
2150 SET_FLAG(re
->status
, ROUTE_ENTRY_REMOVED
);
2152 afi
= (rn
->p
.family
== AF_INET
)
2154 : (rn
->p
.family
== AF_INET6
) ? AFI_IP6
: AFI_MAX
;
2155 if (is_zebra_import_table_enabled(afi
, re
->table
)) {
2156 zebra_del_import_table_entry(rn
, re
);
2157 /* Just clean up if non main table */
2158 if (IS_ZEBRA_DEBUG_RIB
) {
2159 char buf
[SRCDEST2STR_BUFFER
];
2160 srcdest_rnode2str(rn
, buf
, sizeof(buf
));
2162 "%u:%s: Freeing route rn %p, re %p (type %d)",
2163 re
->vrf_id
, buf
, rn
, re
, re
->type
);
2172 /* This function dumps the contents of a given RE entry into
2173 * standard debug log. Calling function name and IP prefix in
2174 * question are passed as 1st and 2nd arguments.
2177 void _route_entry_dump(const char *func
, union prefixconstptr pp
,
2178 union prefixconstptr src_pp
,
2179 const struct route_entry
*re
)
2181 const struct prefix
*p
= pp
.p
;
2182 const struct prefix
*src_p
= src_pp
.p
;
2183 bool is_srcdst
= src_p
&& src_p
->prefixlen
;
2184 char straddr
[PREFIX_STRLEN
];
2185 char srcaddr
[PREFIX_STRLEN
];
2186 struct nexthop
*nexthop
;
2188 zlog_debug("%s: dumping RE entry %p for %s%s%s vrf %u", func
,
2189 (const void *)re
, prefix2str(pp
, straddr
, sizeof(straddr
)),
2190 is_srcdst
? " from " : "",
2191 is_srcdst
? prefix2str(src_pp
, srcaddr
, sizeof(srcaddr
))
2194 zlog_debug("%s: uptime == %lu, type == %u, instance == %d, table == %d",
2195 func
, (unsigned long)re
->uptime
, re
->type
, re
->instance
,
2198 "%s: metric == %u, mtu == %u, distance == %u, flags == %u, status == %u",
2199 func
, re
->metric
, re
->mtu
, re
->distance
, re
->flags
, re
->status
);
2200 zlog_debug("%s: nexthop_num == %u, nexthop_active_num == %u", func
,
2201 re
->nexthop_num
, re
->nexthop_active_num
);
2203 for (ALL_NEXTHOPS(re
->ng
, nexthop
)) {
2204 inet_ntop(p
->family
, &nexthop
->gate
, straddr
, INET6_ADDRSTRLEN
);
2205 zlog_debug("%s: %s %s[%u] vrf %u with flags %s%s%s", func
,
2206 (nexthop
->rparent
? " NH" : "NH"), straddr
,
2207 nexthop
->ifindex
, nexthop
->vrf_id
,
2208 (CHECK_FLAG(nexthop
->flags
, NEXTHOP_FLAG_ACTIVE
)
2211 (CHECK_FLAG(nexthop
->flags
, NEXTHOP_FLAG_FIB
)
2214 (CHECK_FLAG(nexthop
->flags
, NEXTHOP_FLAG_RECURSIVE
)
2218 zlog_debug("%s: dump complete", func
);
2221 /* This is an exported helper to rtm_read() to dump the strange
2222 * RE entry found by rib_lookup_ipv4_route()
2225 void rib_lookup_and_dump(struct prefix_ipv4
*p
, vrf_id_t vrf_id
)
2227 struct route_table
*table
;
2228 struct route_node
*rn
;
2229 struct route_entry
*re
;
2230 char prefix_buf
[INET_ADDRSTRLEN
];
2233 table
= zebra_vrf_table(AFI_IP
, SAFI_UNICAST
, vrf_id
);
2235 zlog_err("%s:%u zebra_vrf_table() returned NULL",
2240 /* Scan the RIB table for exactly matching RE entry. */
2241 rn
= route_node_lookup(table
, (struct prefix
*)p
);
2243 /* No route for this prefix. */
2245 zlog_debug("%s:%u lookup failed for %s", __func__
, vrf_id
,
2246 prefix2str((struct prefix
*)p
, prefix_buf
,
2247 sizeof(prefix_buf
)));
2252 route_unlock_node(rn
);
2255 RNODE_FOREACH_RE (rn
, re
) {
2256 zlog_debug("%s:%u rn %p, re %p: %s, %s",
2258 (void *)rn
, (void *)re
,
2259 (CHECK_FLAG(re
->status
, ROUTE_ENTRY_REMOVED
)
2262 (CHECK_FLAG(re
->flags
, ZEBRA_FLAG_SELECTED
)
2265 route_entry_dump(p
, NULL
, re
);
2269 /* Check if requested address assignment will fail due to another
2270 * route being installed by zebra in FIB already. Take necessary
2271 * actions, if needed: remove such a route from FIB and deSELECT
2272 * corresponding RE entry. Then put affected RN into RIBQ head.
2274 void rib_lookup_and_pushup(struct prefix_ipv4
*p
, vrf_id_t vrf_id
)
2276 struct route_table
*table
;
2277 struct route_node
*rn
;
2278 unsigned changed
= 0;
2281 if (NULL
== (table
= zebra_vrf_table(AFI_IP
, SAFI_UNICAST
, vrf_id
))) {
2282 zlog_err("%s:%u zebra_vrf_table() returned NULL",
2287 /* No matches would be the simplest case. */
2288 if (NULL
== (rn
= route_node_lookup(table
, (struct prefix
*)p
)))
2292 route_unlock_node(rn
);
2294 dest
= rib_dest_from_rnode(rn
);
2295 /* Check all RE entries. In case any changes have to be done, requeue
2296 * the RN into RIBQ head. If the routing message about the new connected
2297 * route (generated by the IP address we are going to assign very soon)
2298 * comes before the RIBQ is processed, the new RE entry will join
2299 * RIBQ record already on head. This is necessary for proper
2301 * of the rest of the RE.
2303 if (dest
->selected_fib
&& !RIB_SYSTEM_ROUTE(dest
->selected_fib
)) {
2305 if (IS_ZEBRA_DEBUG_RIB
) {
2306 char buf
[PREFIX_STRLEN
];
2308 zlog_debug("%u:%s: freeing way for connected prefix",
2309 dest
->selected_fib
->vrf_id
,
2310 prefix2str(&rn
->p
, buf
, sizeof(buf
)));
2311 route_entry_dump(&rn
->p
, NULL
, dest
->selected_fib
);
2313 rib_uninstall(rn
, dest
->selected_fib
);
2319 int rib_add_multipath(afi_t afi
, safi_t safi
, struct prefix
*p
,
2320 struct prefix_ipv6
*src_p
, struct route_entry
*re
)
2322 struct route_table
*table
;
2323 struct route_node
*rn
;
2324 struct route_entry
*same
= NULL
;
2325 struct nexthop
*nexthop
;
2331 assert(!src_p
|| !src_p
->prefixlen
|| afi
== AFI_IP6
);
2334 table
= zebra_vrf_table_with_table_id(afi
, safi
, re
->vrf_id
, re
->table
);
2336 XFREE(MTYPE_RE
, re
);
2340 /* Make it sure prefixlen is applied to the prefix. */
2343 apply_mask_ipv6(src_p
);
2345 /* Set default distance by route type. */
2346 if (re
->distance
== 0) {
2347 re
->distance
= route_distance(re
->type
);
2349 /* iBGP distance is 200. */
2350 if (re
->type
== ZEBRA_ROUTE_BGP
2351 && CHECK_FLAG(re
->flags
, ZEBRA_FLAG_IBGP
))
2355 /* Lookup route node.*/
2356 rn
= srcdest_rnode_get(table
, p
, src_p
);
2358 zlog_debug("Distance: %d", re
->distance
);
2360 * If same type of route are installed, treat it as a implicit
2362 * If the user has specified the No route replace semantics
2363 * for the install don't do a route replace.
2365 RNODE_FOREACH_RE (rn
, same
) {
2366 if (CHECK_FLAG(same
->status
, ROUTE_ENTRY_REMOVED
))
2369 if (same
->type
!= re
->type
)
2371 if (same
->instance
!= re
->instance
)
2373 if (same
->type
== ZEBRA_ROUTE_KERNEL
2374 && same
->metric
!= re
->metric
)
2377 if (CHECK_FLAG(re
->flags
, ZEBRA_FLAG_RR_USE_DISTANCE
) &&
2378 same
->distance
!= re
->distance
)
2382 * We should allow duplicate connected routes
2383 * because of IPv6 link-local routes and unnumbered
2384 * interfaces on Linux.
2386 if (same
->type
!= ZEBRA_ROUTE_CONNECT
)
2390 zlog_debug("same: %p distance: %d", same
, same
? same
->distance
: -1);
2391 /* If this route is kernel route, set FIB flag to the route. */
2392 if (RIB_SYSTEM_ROUTE(re
))
2393 for (nexthop
= re
->ng
.nexthop
; nexthop
; nexthop
= nexthop
->next
)
2394 SET_FLAG(nexthop
->flags
, NEXTHOP_FLAG_FIB
);
2396 /* Link new re to node.*/
2397 if (IS_ZEBRA_DEBUG_RIB
) {
2400 "Inserting route rn %p, re %p (type %d) existing %p",
2401 (void *)rn
, (void *)re
, re
->type
, (void *)same
);
2403 if (IS_ZEBRA_DEBUG_RIB_DETAILED
)
2404 route_entry_dump(p
, src_p
, re
);
2406 rib_addnode(rn
, re
, 1);
2409 /* Free implicit route.*/
2411 rib_delnode(rn
, same
);
2415 route_unlock_node(rn
);
2419 void rib_delete(afi_t afi
, safi_t safi
, vrf_id_t vrf_id
, int type
,
2420 unsigned short instance
, int flags
, struct prefix
*p
,
2421 struct prefix_ipv6
*src_p
, const struct nexthop
*nh
,
2422 uint32_t table_id
, uint32_t metric
, uint8_t distance
,
2425 struct route_table
*table
;
2426 struct route_node
*rn
;
2427 struct route_entry
*re
;
2428 struct route_entry
*fib
= NULL
;
2429 struct route_entry
*same
= NULL
;
2430 struct nexthop
*rtnh
;
2431 char buf2
[INET6_ADDRSTRLEN
];
2434 assert(!src_p
|| !src_p
->prefixlen
|| afi
== AFI_IP6
);
2437 table
= zebra_vrf_table_with_table_id(afi
, safi
, vrf_id
, table_id
);
2444 apply_mask_ipv6(src_p
);
2446 /* Lookup route node. */
2447 rn
= srcdest_rnode_lookup(table
, p
, src_p
);
2449 char dst_buf
[PREFIX_STRLEN
], src_buf
[PREFIX_STRLEN
];
2451 prefix2str(p
, dst_buf
, sizeof(dst_buf
));
2452 if (src_p
&& src_p
->prefixlen
)
2453 prefix2str(src_p
, src_buf
, sizeof(src_buf
));
2457 if (IS_ZEBRA_DEBUG_RIB
)
2458 zlog_debug("%u:%s%s%s doesn't exist in rib", vrf_id
,
2460 (src_buf
[0] != '\0') ? " from " : "",
2465 dest
= rib_dest_from_rnode(rn
);
2466 fib
= dest
->selected_fib
;
2468 /* Lookup same type route. */
2469 RNODE_FOREACH_RE (rn
, re
) {
2470 if (CHECK_FLAG(re
->status
, ROUTE_ENTRY_REMOVED
))
2473 if (re
->type
!= type
)
2475 if (re
->instance
!= instance
)
2477 if (CHECK_FLAG(re
->flags
, ZEBRA_FLAG_RR_USE_DISTANCE
) &&
2478 distance
!= re
->distance
)
2481 if (re
->type
== ZEBRA_ROUTE_KERNEL
&& re
->metric
!= metric
)
2483 if (re
->type
== ZEBRA_ROUTE_CONNECT
&& (rtnh
= re
->ng
.nexthop
)
2484 && rtnh
->type
== NEXTHOP_TYPE_IFINDEX
&& nh
) {
2485 if (rtnh
->ifindex
!= nh
->ifindex
)
2490 /* Make sure that the route found has the same gateway. */
2496 for (ALL_NEXTHOPS(re
->ng
, rtnh
))
2497 if (nexthop_same_no_recurse(rtnh
, nh
)) {
2505 /* If same type of route can't be found and this message is from
2509 * In the past(HA!) we could get here because
2510 * we were receiving a route delete from the
2511 * kernel and we're not marking the proto
2512 * as coming from it's appropriate originator.
2513 * Now that we are properly noticing the fact
2514 * that the kernel has deleted our route we
2515 * are not going to get called in this path
2516 * I am going to leave this here because
2517 * this might still work this way on non-linux
2518 * platforms as well as some weird state I have
2519 * not properly thought of yet.
2520 * If we can show that this code path is
2521 * dead then we can remove it.
2523 if (fib
&& CHECK_FLAG(flags
, ZEBRA_FLAG_SELFROUTE
)) {
2524 if (IS_ZEBRA_DEBUG_RIB
) {
2527 "rn %p, re %p (type %d) was deleted from kernel, adding",
2528 rn
, fib
, fib
->type
);
2532 for (rtnh
= fib
->ng
.nexthop
; rtnh
;
2534 UNSET_FLAG(rtnh
->flags
,
2538 * This is a non FRR route
2539 * as such we should mark
2542 dest
->selected_fib
= NULL
;
2544 /* This means someone else, other than Zebra,
2546 * a Zebra router from the kernel. We will add
2548 rib_install_kernel(rn
, fib
, NULL
);
2551 if (IS_ZEBRA_DEBUG_RIB
) {
2555 "via %s ifindex %d type %d "
2556 "doesn't exist in rib",
2557 inet_ntop(afi2family(afi
),
2564 "type %d doesn't exist in rib",
2567 route_unlock_node(rn
);
2573 if (fromkernel
&& CHECK_FLAG(flags
, ZEBRA_FLAG_SELFROUTE
)
2575 rib_install_kernel(rn
, same
, NULL
);
2576 route_unlock_node(rn
);
2581 if (CHECK_FLAG(flags
, ZEBRA_FLAG_EVPN_ROUTE
)) {
2582 struct nexthop
*tmp_nh
;
2584 for (ALL_NEXTHOPS(re
->ng
, tmp_nh
)) {
2585 struct ipaddr vtep_ip
;
2587 memset(&vtep_ip
, 0, sizeof(struct ipaddr
));
2588 if (afi
== AFI_IP
) {
2589 vtep_ip
.ipa_type
= IPADDR_V4
;
2590 memcpy(&(vtep_ip
.ipaddr_v4
),
2591 &(tmp_nh
->gate
.ipv4
),
2592 sizeof(struct in_addr
));
2594 vtep_ip
.ipa_type
= IPADDR_V6
;
2595 memcpy(&(vtep_ip
.ipaddr_v6
),
2596 &(tmp_nh
->gate
.ipv6
),
2597 sizeof(struct in6_addr
));
2599 zebra_vxlan_evpn_vrf_route_del(re
->vrf_id
,
2603 rib_delnode(rn
, same
);
2606 route_unlock_node(rn
);
2611 int rib_add(afi_t afi
, safi_t safi
, vrf_id_t vrf_id
, int type
,
2612 unsigned short instance
, int flags
, struct prefix
*p
,
2613 struct prefix_ipv6
*src_p
, const struct nexthop
*nh
,
2614 uint32_t table_id
, uint32_t metric
, uint32_t mtu
, uint8_t distance
,
2617 struct route_entry
*re
;
2618 struct nexthop
*nexthop
;
2620 /* Allocate new route_entry structure. */
2621 re
= XCALLOC(MTYPE_RE
, sizeof(struct route_entry
));
2623 re
->instance
= instance
;
2624 re
->distance
= distance
;
2626 re
->metric
= metric
;
2628 re
->table
= table_id
;
2629 re
->vrf_id
= vrf_id
;
2630 re
->nexthop_num
= 0;
2631 re
->uptime
= time(NULL
);
2635 nexthop
= nexthop_new();
2637 route_entry_nexthop_add(re
, nexthop
);
2639 return rib_add_multipath(afi
, safi
, p
, src_p
, re
);
2642 /* Schedule routes of a particular table (address-family) based on event. */
2643 static void rib_update_table(struct route_table
*table
,
2644 rib_update_event_t event
)
2646 struct route_node
*rn
;
2647 struct route_entry
*re
, *next
;
2649 /* Walk all routes and queue for processing, if appropriate for
2650 * the trigger event.
2652 for (rn
= route_top(table
); rn
; rn
= srcdest_route_next(rn
)) {
2654 * If we are looking at a route node and the node
2655 * has already been queued we don't
2656 * need to queue it up again
2658 if (rn
->info
&& CHECK_FLAG(rib_dest_from_rnode(rn
)->flags
,
2659 RIB_ROUTE_ANY_QUEUED
))
2662 case RIB_UPDATE_IF_CHANGE
:
2663 /* Examine all routes that won't get processed by the
2665 * triggered by nexthop evaluation (NHT). This would be
2667 * kernel and certain static routes. Note that NHT will
2669 * triggered upon an interface event as connected routes
2671 * get queued for processing.
2673 RNODE_FOREACH_RE_SAFE (rn
, re
, next
) {
2676 if (re
->type
!= ZEBRA_ROUTE_SYSTEM
2677 && re
->type
!= ZEBRA_ROUTE_KERNEL
2678 && re
->type
!= ZEBRA_ROUTE_CONNECT
2679 && re
->type
!= ZEBRA_ROUTE_STATIC
)
2682 if (re
->type
!= ZEBRA_ROUTE_STATIC
) {
2687 for (nh
= re
->ng
.nexthop
; nh
; nh
= nh
->next
)
2688 if (!(nh
->type
== NEXTHOP_TYPE_IPV4
2689 || nh
->type
== NEXTHOP_TYPE_IPV6
))
2692 /* If we only have nexthops to a
2701 case RIB_UPDATE_RMAP_CHANGE
:
2702 case RIB_UPDATE_OTHER
:
2703 /* Right now, examine all routes. Can restrict to a
2705 * some cases (TODO).
2707 if (rnode_to_ribs(rn
))
2717 /* RIB update function. */
2718 void rib_update(vrf_id_t vrf_id
, rib_update_event_t event
)
2720 struct route_table
*table
;
2722 /* Process routes of interested address-families. */
2723 table
= zebra_vrf_table(AFI_IP
, SAFI_UNICAST
, vrf_id
);
2725 rib_update_table(table
, event
);
2727 table
= zebra_vrf_table(AFI_IP6
, SAFI_UNICAST
, vrf_id
);
2729 rib_update_table(table
, event
);
2732 /* Delete self installed routes after zebra is relaunched. */
2733 void rib_sweep_table(struct route_table
*table
)
2735 struct route_node
*rn
;
2736 struct route_entry
*re
;
2737 struct route_entry
*next
;
2738 struct nexthop
*nexthop
;
2743 for (rn
= route_top(table
); rn
; rn
= srcdest_route_next(rn
)) {
2744 RNODE_FOREACH_RE_SAFE (rn
, re
, next
) {
2745 if (IS_ZEBRA_DEBUG_RIB
)
2746 route_entry_dump(&rn
->p
, NULL
, re
);
2748 if (CHECK_FLAG(re
->status
, ROUTE_ENTRY_REMOVED
))
2751 if (!CHECK_FLAG(re
->flags
, ZEBRA_FLAG_SELFROUTE
))
2755 * So we are starting up and have received
2756 * routes from the kernel that we have installed
2757 * from a previous run of zebra but not cleaned
2758 * up ( say a kill -9 )
2759 * But since we haven't actually installed
2760 * them yet( we received them from the kernel )
2761 * we don't think they are active.
2762 * So let's pretend they are active to actually
2764 * In all honesty I'm not sure if we should
2765 * mark them as active when we receive them
2766 * This is startup only so probably ok.
2768 * If we ever decide to move rib_sweep_table
2769 * to a different spot (ie startup )
2770 * this decision needs to be revisited
2772 for (ALL_NEXTHOPS(re
->ng
, nexthop
))
2773 SET_FLAG(nexthop
->flags
, NEXTHOP_FLAG_FIB
);
2775 rib_uninstall_kernel(rn
, re
);
2776 rib_delnode(rn
, re
);
2781 /* Sweep all RIB tables. */
2782 void rib_sweep_route(void)
2785 struct zebra_vrf
*zvrf
;
2787 RB_FOREACH (vrf
, vrf_id_head
, &vrfs_by_id
) {
2788 if ((zvrf
= vrf
->info
) == NULL
)
2791 rib_sweep_table(zvrf
->table
[AFI_IP
][SAFI_UNICAST
]);
2792 rib_sweep_table(zvrf
->table
[AFI_IP6
][SAFI_UNICAST
]);
2795 zebra_ns_sweep_route();
2798 /* Remove specific by protocol routes from 'table'. */
2799 unsigned long rib_score_proto_table(uint8_t proto
, unsigned short instance
,
2800 struct route_table
*table
)
2802 struct route_node
*rn
;
2803 struct route_entry
*re
;
2804 struct route_entry
*next
;
2805 unsigned long n
= 0;
2808 for (rn
= route_top(table
); rn
; rn
= srcdest_route_next(rn
))
2809 RNODE_FOREACH_RE_SAFE (rn
, re
, next
) {
2810 if (CHECK_FLAG(re
->status
, ROUTE_ENTRY_REMOVED
))
2812 if (re
->type
== proto
2813 && re
->instance
== instance
) {
2814 rib_delnode(rn
, re
);
2821 /* Remove specific by protocol routes. */
2822 unsigned long rib_score_proto(uint8_t proto
, unsigned short instance
)
2825 struct zebra_vrf
*zvrf
;
2826 unsigned long cnt
= 0;
2828 RB_FOREACH (vrf
, vrf_id_head
, &vrfs_by_id
)
2829 if ((zvrf
= vrf
->info
) != NULL
)
2830 cnt
+= rib_score_proto_table(
2832 zvrf
->table
[AFI_IP
][SAFI_UNICAST
])
2833 + rib_score_proto_table(
2835 zvrf
->table
[AFI_IP6
][SAFI_UNICAST
]);
2837 cnt
+= zebra_ns_score_proto(proto
, instance
);
2842 /* Close RIB and clean up kernel routes. */
2843 void rib_close_table(struct route_table
*table
)
2845 struct route_node
*rn
;
2846 rib_table_info_t
*info
;
2854 for (rn
= route_top(table
); rn
; rn
= srcdest_route_next(rn
)) {
2855 dest
= rib_dest_from_rnode(rn
);
2857 if (dest
&& dest
->selected_fib
) {
2858 if (info
->safi
== SAFI_UNICAST
)
2859 hook_call(rib_update
, rn
, NULL
);
2861 if (!RIB_SYSTEM_ROUTE(dest
->selected_fib
))
2862 rib_uninstall_kernel(rn
, dest
->selected_fib
);
2867 /* Routing information base initialize. */
2870 rib_queue_init(&zebrad
);
2876 * Get the first vrf id that is greater than the given vrf id if any.
2878 * Returns TRUE if a vrf id was found, FALSE otherwise.
2880 static inline int vrf_id_get_next(vrf_id_t vrf_id
, vrf_id_t
*next_id_p
)
2884 vrf
= vrf_lookup_by_id(vrf_id
);
2886 vrf
= RB_NEXT(vrf_id_head
, vrf
);
2888 *next_id_p
= vrf
->vrf_id
;
2897 * rib_tables_iter_next
2899 * Returns the next table in the iteration.
2901 struct route_table
*rib_tables_iter_next(rib_tables_iter_t
*iter
)
2903 struct route_table
*table
;
2906 * Array that helps us go over all AFI/SAFI combinations via one
2913 {AFI_IP
, SAFI_UNICAST
}, {AFI_IP
, SAFI_MULTICAST
},
2914 {AFI_IP
, SAFI_LABELED_UNICAST
}, {AFI_IP6
, SAFI_UNICAST
},
2915 {AFI_IP6
, SAFI_MULTICAST
}, {AFI_IP6
, SAFI_LABELED_UNICAST
},
2920 switch (iter
->state
) {
2922 case RIB_TABLES_ITER_S_INIT
:
2923 iter
->vrf_id
= VRF_DEFAULT
;
2924 iter
->afi_safi_ix
= -1;
2928 case RIB_TABLES_ITER_S_ITERATING
:
2929 iter
->afi_safi_ix
++;
2932 while (iter
->afi_safi_ix
2933 < (int)ZEBRA_NUM_OF(afi_safis
)) {
2934 table
= zebra_vrf_table(
2935 afi_safis
[iter
->afi_safi_ix
].afi
,
2936 afi_safis
[iter
->afi_safi_ix
].safi
,
2941 iter
->afi_safi_ix
++;
2945 * Found another table in this vrf.
2951 * Done with all tables in the current vrf, go to the
2955 if (!vrf_id_get_next(iter
->vrf_id
, &iter
->vrf_id
))
2958 iter
->afi_safi_ix
= 0;
2963 case RIB_TABLES_ITER_S_DONE
:
2968 iter
->state
= RIB_TABLES_ITER_S_ITERATING
;
2970 iter
->state
= RIB_TABLES_ITER_S_DONE
;