blob: 94a74194fc252fd3524c112c431fed62956a768c [file] [log] [blame]
paul718e3742002-12-13 20:15:29 +00001/*
2 * Routing Information Base header
3 * Copyright (C) 1997 Kunihiro Ishiguro
4 *
5 * This file is part of GNU Zebra.
6 *
7 * GNU Zebra is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation; either version 2, or (at your option) any
10 * later version.
11 *
12 * GNU Zebra is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with GNU Zebra; see the file COPYING. If not, write to the Free
19 * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
20 * 02111-1307, USA.
21 */
22
23#ifndef _ZEBRA_RIB_H
24#define _ZEBRA_RIB_H
25
paulec1a4282005-11-24 15:15:17 +000026#include "prefix.h"
Avneesh Sachdev9fd92e32012-11-13 22:48:53 +000027#include "table.h"
Avneesh Sachdev5adc2522012-11-13 22:48:59 +000028#include "queue.h"
paulec1a4282005-11-24 15:15:17 +000029
paul718e3742002-12-13 20:15:29 +000030#define DISTANCE_INFINITY 255
31
32/* Routing information base. */
Paul Jakma7514fb72007-05-02 16:05:35 +000033
34union g_addr {
35 struct in_addr ipv4;
36#ifdef HAVE_IPV6
37 struct in6_addr ipv6;
38#endif /* HAVE_IPV6 */
39};
40
paul718e3742002-12-13 20:15:29 +000041struct rib
42{
43 /* Link list. */
44 struct rib *next;
45 struct rib *prev;
Paul Jakmae6d7d052006-03-30 13:32:09 +000046
47 /* Nexthop structure */
48 struct nexthop *nexthop;
49
50 /* Refrence count. */
51 unsigned long refcnt;
52
53 /* Uptime. */
54 time_t uptime;
paul718e3742002-12-13 20:15:29 +000055
56 /* Type fo this route. */
57 int type;
58
59 /* Which routing table */
60 int table;
61
Paul Jakmae6d7d052006-03-30 13:32:09 +000062 /* Metric */
63 u_int32_t metric;
64
paul718e3742002-12-13 20:15:29 +000065 /* Distance. */
66 u_char distance;
67
Paul Jakma6d691122006-07-27 21:49:00 +000068 /* Flags of this route.
69 * This flag's definition is in lib/zebra.h ZEBRA_FLAG_* and is exposed
70 * to clients via Zserv
71 */
paul718e3742002-12-13 20:15:29 +000072 u_char flags;
73
Paul Jakma6d691122006-07-27 21:49:00 +000074 /* RIB internal status */
75 u_char status;
76#define RIB_ENTRY_REMOVED (1 << 0)
77
paul718e3742002-12-13 20:15:29 +000078 /* Nexthop information. */
79 u_char nexthop_num;
80 u_char nexthop_active_num;
81 u_char nexthop_fib_num;
paul718e3742002-12-13 20:15:29 +000082};
83
Denis Ovsienkoe96f9202008-06-02 12:03:22 +000084/* meta-queue structure:
85 * sub-queue 0: connected, kernel
86 * sub-queue 1: static
87 * sub-queue 2: RIP, RIPng, OSPF, OSPF6, IS-IS
88 * sub-queue 3: iBGP, eBGP
89 * sub-queue 4: any other origin (if any)
90 */
91#define MQ_SIZE 5
92struct meta_queue
93{
94 struct list *subq[MQ_SIZE];
95 u_int32_t size; /* sum of lengths of all subqueues */
96};
97
Avneesh Sachdev9fd92e32012-11-13 22:48:53 +000098/*
99 * Structure that represents a single destination (prefix).
100 */
101typedef struct rib_dest_t_
102{
103
104 /*
105 * Back pointer to the route node for this destination. This helps
106 * us get to the prefix that this structure is for.
107 */
108 struct route_node *rnode;
109
110 /*
111 * Doubly-linked list of routes for this prefix.
112 */
113 struct rib *routes;
114
115 /*
116 * Flags, see below.
117 */
118 u_int32_t flags;
119
Avneesh Sachdev5adc2522012-11-13 22:48:59 +0000120 /*
121 * Linkage to put dest on the FPM processing queue.
122 */
123 TAILQ_ENTRY(rib_dest_t_) fpm_q_entries;
124
Avneesh Sachdev9fd92e32012-11-13 22:48:53 +0000125} rib_dest_t;
126
127#define RIB_ROUTE_QUEUED(x) (1 << (x))
128
129/*
130 * The maximum qindex that can be used.
131 */
132#define ZEBRA_MAX_QINDEX (MQ_SIZE - 1)
133
134/*
Avneesh Sachdev5adc2522012-11-13 22:48:59 +0000135 * This flag indicates that a given prefix has been 'advertised' to
136 * the FPM to be installed in the forwarding plane.
137 */
138#define RIB_DEST_SENT_TO_FPM (1 << (ZEBRA_MAX_QINDEX + 1))
139
140/*
141 * This flag is set when we need to send an update to the FPM about a
142 * dest.
143 */
144#define RIB_DEST_UPDATE_FPM (1 << (ZEBRA_MAX_QINDEX + 2))
145
146/*
Avneesh Sachdev9fd92e32012-11-13 22:48:53 +0000147 * Macro to iterate over each route for a destination (prefix).
148 */
149#define RIB_DEST_FOREACH_ROUTE(dest, rib) \
150 for ((rib) = (dest) ? (dest)->routes : NULL; (rib); (rib) = (rib)->next)
151
152/*
153 * Same as above, but allows the current node to be unlinked.
154 */
155#define RIB_DEST_FOREACH_ROUTE_SAFE(dest, rib, next) \
156 for ((rib) = (dest) ? (dest)->routes : NULL; \
157 (rib) && ((next) = (rib)->next, 1); \
158 (rib) = (next))
159
160#define RNODE_FOREACH_RIB(rn, rib) \
161 RIB_DEST_FOREACH_ROUTE (rib_dest_from_rnode (rn), rib)
162
163#define RNODE_FOREACH_RIB_SAFE(rn, rib, next) \
164 RIB_DEST_FOREACH_ROUTE_SAFE (rib_dest_from_rnode (rn), rib, next)
165
paul718e3742002-12-13 20:15:29 +0000166/* Static route information. */
167struct static_ipv4
168{
169 /* For linked list. */
170 struct static_ipv4 *prev;
171 struct static_ipv4 *next;
172
173 /* Administrative distance. */
174 u_char distance;
175
176 /* Flag for this static route's type. */
177 u_char type;
178#define STATIC_IPV4_GATEWAY 1
179#define STATIC_IPV4_IFNAME 2
paul595db7f2003-05-25 21:35:06 +0000180#define STATIC_IPV4_BLACKHOLE 3
paul718e3742002-12-13 20:15:29 +0000181
182 /* Nexthop value. */
183 union
184 {
185 struct in_addr ipv4;
186 char *ifname;
187 } gate;
hasso81dfcaa2003-05-25 19:21:25 +0000188
189 /* bit flags */
190 u_char flags;
191/*
192 see ZEBRA_FLAG_REJECT
193 ZEBRA_FLAG_BLACKHOLE
194 */
paul718e3742002-12-13 20:15:29 +0000195};
196
197#ifdef HAVE_IPV6
198/* Static route information. */
199struct static_ipv6
200{
201 /* For linked list. */
202 struct static_ipv6 *prev;
203 struct static_ipv6 *next;
204
205 /* Administrative distance. */
206 u_char distance;
207
208 /* Flag for this static route's type. */
209 u_char type;
210#define STATIC_IPV6_GATEWAY 1
211#define STATIC_IPV6_GATEWAY_IFNAME 2
212#define STATIC_IPV6_IFNAME 3
213
214 /* Nexthop value. */
215 struct in6_addr ipv6;
216 char *ifname;
hasso81dfcaa2003-05-25 19:21:25 +0000217
218 /* bit flags */
219 u_char flags;
220/*
221 see ZEBRA_FLAG_REJECT
222 ZEBRA_FLAG_BLACKHOLE
223 */
paul718e3742002-12-13 20:15:29 +0000224};
225#endif /* HAVE_IPV6 */
226
paul7021c422003-07-15 12:52:22 +0000227enum nexthop_types_t
228{
229 NEXTHOP_TYPE_IFINDEX = 1, /* Directly connected. */
230 NEXTHOP_TYPE_IFNAME, /* Interface route. */
231 NEXTHOP_TYPE_IPV4, /* IPv4 nexthop. */
232 NEXTHOP_TYPE_IPV4_IFINDEX, /* IPv4 nexthop with ifindex. */
233 NEXTHOP_TYPE_IPV4_IFNAME, /* IPv4 nexthop with ifname. */
234 NEXTHOP_TYPE_IPV6, /* IPv6 nexthop. */
235 NEXTHOP_TYPE_IPV6_IFINDEX, /* IPv6 nexthop with ifindex. */
236 NEXTHOP_TYPE_IPV6_IFNAME, /* IPv6 nexthop with ifname. */
237 NEXTHOP_TYPE_BLACKHOLE, /* Null0 nexthop. */
238};
239
paul718e3742002-12-13 20:15:29 +0000240/* Nexthop structure. */
241struct nexthop
242{
243 struct nexthop *next;
244 struct nexthop *prev;
245
Paul Jakmae6d7d052006-03-30 13:32:09 +0000246 /* Interface index. */
247 char *ifname;
248 unsigned int ifindex;
249
paul7021c422003-07-15 12:52:22 +0000250 enum nexthop_types_t type;
paul718e3742002-12-13 20:15:29 +0000251
252 u_char flags;
253#define NEXTHOP_FLAG_ACTIVE (1 << 0) /* This nexthop is alive. */
254#define NEXTHOP_FLAG_FIB (1 << 1) /* FIB nexthop. */
255#define NEXTHOP_FLAG_RECURSIVE (1 << 2) /* Recursive nexthop. */
Christian Frankee8d3d292013-07-05 15:35:39 +0000256#define NEXTHOP_FLAG_ONLINK (1 << 3) /* Nexthop should be installed onlink. */
paul718e3742002-12-13 20:15:29 +0000257
Christian Frankefa713d92013-07-05 15:35:37 +0000258 /* Nexthop address */
Paul Jakma7514fb72007-05-02 16:05:35 +0000259 union g_addr gate;
Paul Jakma7514fb72007-05-02 16:05:35 +0000260 union g_addr src;
Christian Frankefa713d92013-07-05 15:35:37 +0000261
262 /* Nexthops obtained by recursive resolution.
263 *
264 * If the nexthop struct needs to be resolved recursively,
265 * NEXTHOP_FLAG_RECURSIVE will be set in flags and the nexthops
266 * obtained by recursive resolution will be added to `resolved'.
267 * Only one level of recursive resolution is currently supported. */
268 struct nexthop *resolved;
paul718e3742002-12-13 20:15:29 +0000269};
270
Christian Frankefa713d92013-07-05 15:35:37 +0000271/* The following for loop allows to iterate over the nexthop
272 * structure of routes.
273 *
274 * We have to maintain quite a bit of state:
275 *
276 * nexthop: The pointer to the current nexthop, either in the
277 * top-level chain or in the resolved chain of ni.
278 * tnexthop: The pointer to the current nexthop in the top-level
279 * nexthop chain.
280 * recursing: Information if nh currently is in the top-level chain
281 * (0) or in a resolved chain (1).
282 *
283 * Initialization: Set `nexthop' and `tnexthop' to the head of the
284 * top-level chain. As nexthop is in the top level chain, set recursing
285 * to 0.
286 *
287 * Iteration check: Check that the `nexthop' pointer is not NULL.
288 *
289 * Iteration step: This is the tricky part. Check if `nexthop' has
290 * NEXTHOP_FLAG_RECURSIVE set. If yes, this implies that `nexthop' is in
291 * the top level chain and has at least one nexthop attached to
292 * `nexthop->resolved'. As we want to descend into `nexthop->resolved',
293 * set `recursing' to 1 and set `nexthop' to `nexthop->resolved'.
294 * `tnexthop' is left alone in that case so we can remember which nexthop
295 * in the top level chain we are currently handling.
296 *
297 * If NEXTHOP_FLAG_RECURSIVE is not set, `nexthop' will progress in its
298 * current chain. If we are recursing, `nexthop' will be set to
299 * `nexthop->next' and `tnexthop' will be left alone. If we are not
300 * recursing, both `tnexthop' and `nexthop' will be set to `nexthop->next'
301 * as we are progressing in the top level chain.
302 * If we encounter `nexthop->next == NULL', we will clear the `recursing'
303 * flag as we arived either at the end of the resolved chain or at the end
304 * of the top level chain. In both cases, we set `tnexthop' and `nexthop'
305 * to `tnexthop->next', progressing to the next position in the top-level
306 * chain and possibly to its end marked by NULL.
307 */
308#define ALL_NEXTHOPS_RO(head, nexthop, tnexthop, recursing) \
309 (tnexthop) = (nexthop) = (head), (recursing) = 0; \
310 (nexthop); \
311 (nexthop) = CHECK_FLAG((nexthop)->flags, NEXTHOP_FLAG_RECURSIVE) \
312 ? (((recursing) = 1), (nexthop)->resolved) \
313 : ((nexthop)->next ? ((recursing) ? (nexthop)->next \
314 : ((tnexthop) = (nexthop)->next)) \
315 : (((recursing) = 0),((tnexthop) = (tnexthop)->next)))
316
paul718e3742002-12-13 20:15:29 +0000317/* Routing table instance. */
318struct vrf
319{
320 /* Identifier. This is same as routing table vector index. */
321 u_int32_t id;
322
323 /* Routing table name. */
324 char *name;
325
326 /* Description. */
327 char *desc;
328
329 /* FIB identifier. */
330 u_char fib_id;
331
332 /* Routing table. */
333 struct route_table *table[AFI_MAX][SAFI_MAX];
334
335 /* Static route configuration. */
336 struct route_table *stable[AFI_MAX][SAFI_MAX];
337};
338
Avneesh Sachdev1b5ed1b2012-11-13 22:48:54 +0000339/*
340 * rib_table_info_t
341 *
342 * Structure that is hung off of a route_table that holds information about
343 * the table.
344 */
345typedef struct rib_table_info_t_
346{
347
348 /*
349 * Back pointer to vrf.
350 */
351 struct vrf *vrf;
352 afi_t afi;
353 safi_t safi;
354
355} rib_table_info_t;
356
Avneesh Sachdev0915bb02012-11-13 22:48:55 +0000357typedef enum
358{
359 RIB_TABLES_ITER_S_INIT,
360 RIB_TABLES_ITER_S_ITERATING,
361 RIB_TABLES_ITER_S_DONE
362} rib_tables_iter_state_t;
363
364/*
365 * Structure that holds state for iterating over all tables in the
366 * Routing Information Base.
367 */
368typedef struct rib_tables_iter_t_
369{
370 uint32_t vrf_id;
371 int afi_safi_ix;
372
373 rib_tables_iter_state_t state;
374} rib_tables_iter_t;
375
David Lamparterbd078122015-01-06 19:53:24 +0100376/* RPF lookup behaviour */
377enum multicast_mode
378{
379 MCAST_NO_CONFIG = 0, /* MIX_MRIB_FIRST, but no show in config write */
380 MCAST_MRIB_ONLY, /* MRIB only */
381 MCAST_URIB_ONLY, /* URIB only */
382 MCAST_MIX_MRIB_FIRST, /* MRIB, if nothing at all then URIB */
383 MCAST_MIX_DISTANCE, /* MRIB & URIB, lower distance wins */
384 MCAST_MIX_PFXLEN, /* MRIB & URIB, longer prefix wins */
385 /* on equal value, MRIB wins for last 2 */
386};
387
388extern void multicast_mode_ipv4_set (enum multicast_mode mode);
389extern enum multicast_mode multicast_mode_ipv4_get (void);
390
Avneesh Sachdev78deec42012-11-13 22:48:56 +0000391extern const char *nexthop_type_to_str (enum nexthop_types_t nh_type);
paula1ac18c2005-06-28 17:17:12 +0000392extern struct nexthop *nexthop_ifindex_add (struct rib *, unsigned int);
393extern struct nexthop *nexthop_ifname_add (struct rib *, char *);
394extern struct nexthop *nexthop_blackhole_add (struct rib *);
Paul Jakma7514fb72007-05-02 16:05:35 +0000395extern struct nexthop *nexthop_ipv4_add (struct rib *, struct in_addr *,
396 struct in_addr *);
Josh Bailey26e2ae32012-03-22 01:09:21 -0700397extern struct nexthop *nexthop_ipv4_ifindex_add (struct rib *,
398 struct in_addr *,
399 struct in_addr *,
400 unsigned int);
Christian Frankefa713d92013-07-05 15:35:37 +0000401extern int nexthop_has_fib_child(struct nexthop *);
Denis Ovsienkodc958242007-08-13 16:03:06 +0000402extern void rib_lookup_and_dump (struct prefix_ipv4 *);
Denis Ovsienko20e5ff02008-02-26 14:02:24 +0000403extern void rib_lookup_and_pushup (struct prefix_ipv4 *);
David Lamparterf7bf4152013-10-22 17:10:21 +0000404#define rib_dump(prefix ,rib) _rib_dump(__func__, prefix, rib)
405extern void _rib_dump (const char *,
406 union prefix46constptr, const struct rib *);
Denis Ovsienkodc958242007-08-13 16:03:06 +0000407extern int rib_lookup_ipv4_route (struct prefix_ipv4 *, union sockunion *);
408#define ZEBRA_RIB_LOOKUP_ERROR -1
409#define ZEBRA_RIB_FOUND_EXACT 0
410#define ZEBRA_RIB_FOUND_NOGATE 1
411#define ZEBRA_RIB_FOUND_CONNECTED 2
412#define ZEBRA_RIB_NOTFOUND 3
413
paul718e3742002-12-13 20:15:29 +0000414#ifdef HAVE_IPV6
paula1ac18c2005-06-28 17:17:12 +0000415extern struct nexthop *nexthop_ipv6_add (struct rib *, struct in6_addr *);
paul718e3742002-12-13 20:15:29 +0000416#endif /* HAVE_IPV6 */
417
paula1ac18c2005-06-28 17:17:12 +0000418extern struct vrf *vrf_lookup (u_int32_t);
419extern struct route_table *vrf_table (afi_t afi, safi_t safi, u_int32_t id);
420extern struct route_table *vrf_static_table (afi_t afi, safi_t safi, u_int32_t id);
paul718e3742002-12-13 20:15:29 +0000421
hassod24af182005-09-24 14:00:26 +0000422/* NOTE:
423 * All rib_add_ipv[46]* functions will not just add prefix into RIB, but
424 * also implicitly withdraw equal prefix of same type. */
paula1ac18c2005-06-28 17:17:12 +0000425extern int rib_add_ipv4 (int type, int flags, struct prefix_ipv4 *p,
Paul Jakma7514fb72007-05-02 16:05:35 +0000426 struct in_addr *gate, struct in_addr *src,
427 unsigned int ifindex, u_int32_t vrf_id,
G.Balajicddf3912011-11-26 21:59:32 +0400428 u_int32_t, u_char, safi_t);
paul718e3742002-12-13 20:15:29 +0000429
G.Balajicddf3912011-11-26 21:59:32 +0400430extern int rib_add_ipv4_multipath (struct prefix_ipv4 *, struct rib *, safi_t);
paul718e3742002-12-13 20:15:29 +0000431
paula1ac18c2005-06-28 17:17:12 +0000432extern int rib_delete_ipv4 (int type, int flags, struct prefix_ipv4 *p,
433 struct in_addr *gate, unsigned int ifindex,
G.Balajicddf3912011-11-26 21:59:32 +0400434 u_int32_t, safi_t safi);
paul718e3742002-12-13 20:15:29 +0000435
David Lamparter24480d42015-01-22 19:09:36 +0100436extern struct rib *rib_match_ipv4_safi (struct in_addr addr, safi_t safi,
437 int skip_bgp, struct route_node **rn_out);
David Lamparterbd078122015-01-06 19:53:24 +0100438extern struct rib *rib_match_ipv4_multicast (struct in_addr addr,
439 struct route_node **rn_out);
paul718e3742002-12-13 20:15:29 +0000440
paula1ac18c2005-06-28 17:17:12 +0000441extern struct rib *rib_lookup_ipv4 (struct prefix_ipv4 *);
paul718e3742002-12-13 20:15:29 +0000442
paula1ac18c2005-06-28 17:17:12 +0000443extern void rib_update (void);
444extern void rib_weed_tables (void);
445extern void rib_sweep_route (void);
446extern void rib_close (void);
447extern void rib_init (void);
Vyacheslav Trushkin2ea1ab12011-12-11 18:48:47 +0400448extern unsigned long rib_score_proto (u_char proto);
paul718e3742002-12-13 20:15:29 +0000449
paula1ac18c2005-06-28 17:17:12 +0000450extern int
Everton Marques33d86db2014-07-14 11:19:00 -0300451static_add_ipv4_safi (safi_t safi, struct prefix *p, struct in_addr *gate,
452 const char *ifname, u_char flags, u_char distance,
453 u_int32_t vrf_id);
paula1ac18c2005-06-28 17:17:12 +0000454extern int
Everton Marques33d86db2014-07-14 11:19:00 -0300455static_delete_ipv4_safi (safi_t safi, struct prefix *p, struct in_addr *gate,
456 const char *ifname, u_char distance, u_int32_t vrf_id);
paul718e3742002-12-13 20:15:29 +0000457
458#ifdef HAVE_IPV6
paula1ac18c2005-06-28 17:17:12 +0000459extern int
paul718e3742002-12-13 20:15:29 +0000460rib_add_ipv6 (int type, int flags, struct prefix_ipv6 *p,
hassobe61c4e2005-08-27 06:05:47 +0000461 struct in6_addr *gate, unsigned int ifindex, u_int32_t vrf_id,
G.Balajif768f362011-11-26 22:10:39 +0400462 u_int32_t metric, u_char distance, safi_t safi);
paul718e3742002-12-13 20:15:29 +0000463
paula1ac18c2005-06-28 17:17:12 +0000464extern int
paul718e3742002-12-13 20:15:29 +0000465rib_delete_ipv6 (int type, int flags, struct prefix_ipv6 *p,
G.Balajif768f362011-11-26 22:10:39 +0400466 struct in6_addr *gate, unsigned int ifindex, u_int32_t vrf_id, safi_t safi);
paul718e3742002-12-13 20:15:29 +0000467
paula1ac18c2005-06-28 17:17:12 +0000468extern struct rib *rib_lookup_ipv6 (struct in6_addr *);
paul718e3742002-12-13 20:15:29 +0000469
paula1ac18c2005-06-28 17:17:12 +0000470extern struct rib *rib_match_ipv6 (struct in6_addr *);
paul718e3742002-12-13 20:15:29 +0000471
472extern struct route_table *rib_table_ipv6;
473
paula1ac18c2005-06-28 17:17:12 +0000474extern int
paul718e3742002-12-13 20:15:29 +0000475static_add_ipv6 (struct prefix *p, u_char type, struct in6_addr *gate,
hasso39db97e2004-10-12 20:50:58 +0000476 const char *ifname, u_char flags, u_char distance,
477 u_int32_t vrf_id);
paul718e3742002-12-13 20:15:29 +0000478
paula1ac18c2005-06-28 17:17:12 +0000479extern int
paul718e3742002-12-13 20:15:29 +0000480static_delete_ipv6 (struct prefix *p, u_char type, struct in6_addr *gate,
hasso39db97e2004-10-12 20:50:58 +0000481 const char *ifname, u_char distance, u_int32_t vrf_id);
paul718e3742002-12-13 20:15:29 +0000482
483#endif /* HAVE_IPV6 */
484
Avneesh Sachdev9fd92e32012-11-13 22:48:53 +0000485extern int rib_gc_dest (struct route_node *rn);
Avneesh Sachdev0915bb02012-11-13 22:48:55 +0000486extern struct route_table *rib_tables_iter_next (rib_tables_iter_t *iter);
Avneesh Sachdev9fd92e32012-11-13 22:48:53 +0000487
488/*
489 * Inline functions.
490 */
491
492/*
Avneesh Sachdev1b5ed1b2012-11-13 22:48:54 +0000493 * rib_table_info
494 */
495static inline rib_table_info_t *
496rib_table_info (struct route_table *table)
497{
498 return (rib_table_info_t *) table->info;
499}
500
501/*
Avneesh Sachdev9fd92e32012-11-13 22:48:53 +0000502 * rib_dest_from_rnode
503 */
504static inline rib_dest_t *
505rib_dest_from_rnode (struct route_node *rn)
506{
507 return (rib_dest_t *) rn->info;
508}
509
510/*
511 * rnode_to_ribs
512 *
513 * Returns a pointer to the list of routes corresponding to the given
514 * route_node.
515 */
516static inline struct rib *
517rnode_to_ribs (struct route_node *rn)
518{
519 rib_dest_t *dest;
520
521 dest = rib_dest_from_rnode (rn);
522 if (!dest)
523 return NULL;
524
525 return dest->routes;
526}
527
528/*
529 * rib_dest_prefix
530 */
531static inline struct prefix *
532rib_dest_prefix (rib_dest_t *dest)
533{
534 return &dest->rnode->p;
535}
536
537/*
538 * rib_dest_af
539 *
540 * Returns the address family that the destination is for.
541 */
542static inline u_char
543rib_dest_af (rib_dest_t *dest)
544{
545 return dest->rnode->p.family;
546}
547
548/*
549 * rib_dest_table
550 */
551static inline struct route_table *
552rib_dest_table (rib_dest_t *dest)
553{
554 return dest->rnode->table;
555}
556
Avneesh Sachdev1b5ed1b2012-11-13 22:48:54 +0000557/*
558 * rib_dest_vrf
559 */
560static inline struct vrf *
561rib_dest_vrf (rib_dest_t *dest)
562{
563 return rib_table_info (rib_dest_table (dest))->vrf;
564}
565
Avneesh Sachdev0915bb02012-11-13 22:48:55 +0000566/*
567 * rib_tables_iter_init
568 */
569static inline void
570rib_tables_iter_init (rib_tables_iter_t *iter)
571
572{
573 memset (iter, 0, sizeof (*iter));
574 iter->state = RIB_TABLES_ITER_S_INIT;
575}
576
577/*
578 * rib_tables_iter_started
579 *
580 * Returns TRUE if this iterator has started iterating over the set of
581 * tables.
582 */
583static inline int
584rib_tables_iter_started (rib_tables_iter_t *iter)
585{
586 return iter->state != RIB_TABLES_ITER_S_INIT;
587}
588
589/*
590 * rib_tables_iter_cleanup
591 */
592static inline void
593rib_tables_iter_cleanup (rib_tables_iter_t *iter)
594{
595 iter->state = RIB_TABLES_ITER_S_DONE;
596}
597
paul718e3742002-12-13 20:15:29 +0000598#endif /*_ZEBRA_RIB_H */