blob: 2d8805a88a833fc188277e976cf9c8f7c0a8512c [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
Feng Lu0d0686f2015-05-22 11:40:02 +020059 /* VRF identifier. */
60 vrf_id_t vrf_id;
61
paul718e3742002-12-13 20:15:29 +000062 /* Which routing table */
63 int table;
64
Paul Jakmae6d7d052006-03-30 13:32:09 +000065 /* Metric */
66 u_int32_t metric;
67
paul718e3742002-12-13 20:15:29 +000068 /* Distance. */
69 u_char distance;
70
Paul Jakma6d691122006-07-27 21:49:00 +000071 /* Flags of this route.
72 * This flag's definition is in lib/zebra.h ZEBRA_FLAG_* and is exposed
73 * to clients via Zserv
74 */
paul718e3742002-12-13 20:15:29 +000075 u_char flags;
76
Paul Jakma6d691122006-07-27 21:49:00 +000077 /* RIB internal status */
78 u_char status;
79#define RIB_ENTRY_REMOVED (1 << 0)
80
paul718e3742002-12-13 20:15:29 +000081 /* Nexthop information. */
82 u_char nexthop_num;
83 u_char nexthop_active_num;
84 u_char nexthop_fib_num;
paul718e3742002-12-13 20:15:29 +000085};
86
Denis Ovsienkoe96f9202008-06-02 12:03:22 +000087/* meta-queue structure:
88 * sub-queue 0: connected, kernel
89 * sub-queue 1: static
90 * sub-queue 2: RIP, RIPng, OSPF, OSPF6, IS-IS
91 * sub-queue 3: iBGP, eBGP
92 * sub-queue 4: any other origin (if any)
93 */
94#define MQ_SIZE 5
95struct meta_queue
96{
97 struct list *subq[MQ_SIZE];
98 u_int32_t size; /* sum of lengths of all subqueues */
99};
100
Avneesh Sachdev9fd92e32012-11-13 22:48:53 +0000101/*
102 * Structure that represents a single destination (prefix).
103 */
104typedef struct rib_dest_t_
105{
106
107 /*
108 * Back pointer to the route node for this destination. This helps
109 * us get to the prefix that this structure is for.
110 */
111 struct route_node *rnode;
112
113 /*
114 * Doubly-linked list of routes for this prefix.
115 */
116 struct rib *routes;
117
118 /*
119 * Flags, see below.
120 */
121 u_int32_t flags;
122
Avneesh Sachdev5adc2522012-11-13 22:48:59 +0000123 /*
124 * Linkage to put dest on the FPM processing queue.
125 */
126 TAILQ_ENTRY(rib_dest_t_) fpm_q_entries;
127
Avneesh Sachdev9fd92e32012-11-13 22:48:53 +0000128} rib_dest_t;
129
130#define RIB_ROUTE_QUEUED(x) (1 << (x))
131
132/*
133 * The maximum qindex that can be used.
134 */
135#define ZEBRA_MAX_QINDEX (MQ_SIZE - 1)
136
137/*
Avneesh Sachdev5adc2522012-11-13 22:48:59 +0000138 * This flag indicates that a given prefix has been 'advertised' to
139 * the FPM to be installed in the forwarding plane.
140 */
141#define RIB_DEST_SENT_TO_FPM (1 << (ZEBRA_MAX_QINDEX + 1))
142
143/*
144 * This flag is set when we need to send an update to the FPM about a
145 * dest.
146 */
147#define RIB_DEST_UPDATE_FPM (1 << (ZEBRA_MAX_QINDEX + 2))
148
149/*
Avneesh Sachdev9fd92e32012-11-13 22:48:53 +0000150 * Macro to iterate over each route for a destination (prefix).
151 */
152#define RIB_DEST_FOREACH_ROUTE(dest, rib) \
153 for ((rib) = (dest) ? (dest)->routes : NULL; (rib); (rib) = (rib)->next)
154
155/*
156 * Same as above, but allows the current node to be unlinked.
157 */
158#define RIB_DEST_FOREACH_ROUTE_SAFE(dest, rib, next) \
159 for ((rib) = (dest) ? (dest)->routes : NULL; \
160 (rib) && ((next) = (rib)->next, 1); \
161 (rib) = (next))
162
163#define RNODE_FOREACH_RIB(rn, rib) \
164 RIB_DEST_FOREACH_ROUTE (rib_dest_from_rnode (rn), rib)
165
166#define RNODE_FOREACH_RIB_SAFE(rn, rib, next) \
167 RIB_DEST_FOREACH_ROUTE_SAFE (rib_dest_from_rnode (rn), rib, next)
168
paul718e3742002-12-13 20:15:29 +0000169/* Static route information. */
170struct static_ipv4
171{
172 /* For linked list. */
173 struct static_ipv4 *prev;
174 struct static_ipv4 *next;
175
176 /* Administrative distance. */
177 u_char distance;
178
179 /* Flag for this static route's type. */
180 u_char type;
181#define STATIC_IPV4_GATEWAY 1
182#define STATIC_IPV4_IFNAME 2
paul595db7f2003-05-25 21:35:06 +0000183#define STATIC_IPV4_BLACKHOLE 3
paul718e3742002-12-13 20:15:29 +0000184
185 /* Nexthop value. */
186 union
187 {
188 struct in_addr ipv4;
189 char *ifname;
190 } gate;
hasso81dfcaa2003-05-25 19:21:25 +0000191
192 /* bit flags */
193 u_char flags;
194/*
195 see ZEBRA_FLAG_REJECT
196 ZEBRA_FLAG_BLACKHOLE
197 */
paul718e3742002-12-13 20:15:29 +0000198};
199
200#ifdef HAVE_IPV6
201/* Static route information. */
202struct static_ipv6
203{
204 /* For linked list. */
205 struct static_ipv6 *prev;
206 struct static_ipv6 *next;
207
208 /* Administrative distance. */
209 u_char distance;
210
211 /* Flag for this static route's type. */
212 u_char type;
213#define STATIC_IPV6_GATEWAY 1
214#define STATIC_IPV6_GATEWAY_IFNAME 2
215#define STATIC_IPV6_IFNAME 3
216
217 /* Nexthop value. */
218 struct in6_addr ipv6;
219 char *ifname;
hasso81dfcaa2003-05-25 19:21:25 +0000220
221 /* bit flags */
222 u_char flags;
223/*
224 see ZEBRA_FLAG_REJECT
225 ZEBRA_FLAG_BLACKHOLE
226 */
paul718e3742002-12-13 20:15:29 +0000227};
228#endif /* HAVE_IPV6 */
229
paul7021c422003-07-15 12:52:22 +0000230enum nexthop_types_t
231{
232 NEXTHOP_TYPE_IFINDEX = 1, /* Directly connected. */
233 NEXTHOP_TYPE_IFNAME, /* Interface route. */
234 NEXTHOP_TYPE_IPV4, /* IPv4 nexthop. */
235 NEXTHOP_TYPE_IPV4_IFINDEX, /* IPv4 nexthop with ifindex. */
236 NEXTHOP_TYPE_IPV4_IFNAME, /* IPv4 nexthop with ifname. */
237 NEXTHOP_TYPE_IPV6, /* IPv6 nexthop. */
238 NEXTHOP_TYPE_IPV6_IFINDEX, /* IPv6 nexthop with ifindex. */
239 NEXTHOP_TYPE_IPV6_IFNAME, /* IPv6 nexthop with ifname. */
240 NEXTHOP_TYPE_BLACKHOLE, /* Null0 nexthop. */
241};
242
paul718e3742002-12-13 20:15:29 +0000243/* Nexthop structure. */
244struct nexthop
245{
246 struct nexthop *next;
247 struct nexthop *prev;
248
Paul Jakmae6d7d052006-03-30 13:32:09 +0000249 /* Interface index. */
250 char *ifname;
251 unsigned int ifindex;
252
paul7021c422003-07-15 12:52:22 +0000253 enum nexthop_types_t type;
paul718e3742002-12-13 20:15:29 +0000254
255 u_char flags;
256#define NEXTHOP_FLAG_ACTIVE (1 << 0) /* This nexthop is alive. */
257#define NEXTHOP_FLAG_FIB (1 << 1) /* FIB nexthop. */
258#define NEXTHOP_FLAG_RECURSIVE (1 << 2) /* Recursive nexthop. */
Christian Frankee8d3d292013-07-05 15:35:39 +0000259#define NEXTHOP_FLAG_ONLINK (1 << 3) /* Nexthop should be installed onlink. */
paul718e3742002-12-13 20:15:29 +0000260
Christian Frankefa713d92013-07-05 15:35:37 +0000261 /* Nexthop address */
Paul Jakma7514fb72007-05-02 16:05:35 +0000262 union g_addr gate;
Paul Jakma7514fb72007-05-02 16:05:35 +0000263 union g_addr src;
Christian Frankefa713d92013-07-05 15:35:37 +0000264
265 /* Nexthops obtained by recursive resolution.
266 *
267 * If the nexthop struct needs to be resolved recursively,
268 * NEXTHOP_FLAG_RECURSIVE will be set in flags and the nexthops
269 * obtained by recursive resolution will be added to `resolved'.
270 * Only one level of recursive resolution is currently supported. */
271 struct nexthop *resolved;
paul718e3742002-12-13 20:15:29 +0000272};
273
Christian Frankefa713d92013-07-05 15:35:37 +0000274/* The following for loop allows to iterate over the nexthop
275 * structure of routes.
276 *
277 * We have to maintain quite a bit of state:
278 *
279 * nexthop: The pointer to the current nexthop, either in the
280 * top-level chain or in the resolved chain of ni.
281 * tnexthop: The pointer to the current nexthop in the top-level
282 * nexthop chain.
283 * recursing: Information if nh currently is in the top-level chain
284 * (0) or in a resolved chain (1).
285 *
286 * Initialization: Set `nexthop' and `tnexthop' to the head of the
287 * top-level chain. As nexthop is in the top level chain, set recursing
288 * to 0.
289 *
290 * Iteration check: Check that the `nexthop' pointer is not NULL.
291 *
292 * Iteration step: This is the tricky part. Check if `nexthop' has
293 * NEXTHOP_FLAG_RECURSIVE set. If yes, this implies that `nexthop' is in
294 * the top level chain and has at least one nexthop attached to
295 * `nexthop->resolved'. As we want to descend into `nexthop->resolved',
296 * set `recursing' to 1 and set `nexthop' to `nexthop->resolved'.
297 * `tnexthop' is left alone in that case so we can remember which nexthop
298 * in the top level chain we are currently handling.
299 *
300 * If NEXTHOP_FLAG_RECURSIVE is not set, `nexthop' will progress in its
301 * current chain. If we are recursing, `nexthop' will be set to
302 * `nexthop->next' and `tnexthop' will be left alone. If we are not
303 * recursing, both `tnexthop' and `nexthop' will be set to `nexthop->next'
304 * as we are progressing in the top level chain.
305 * If we encounter `nexthop->next == NULL', we will clear the `recursing'
306 * flag as we arived either at the end of the resolved chain or at the end
307 * of the top level chain. In both cases, we set `tnexthop' and `nexthop'
308 * to `tnexthop->next', progressing to the next position in the top-level
309 * chain and possibly to its end marked by NULL.
310 */
311#define ALL_NEXTHOPS_RO(head, nexthop, tnexthop, recursing) \
312 (tnexthop) = (nexthop) = (head), (recursing) = 0; \
313 (nexthop); \
314 (nexthop) = CHECK_FLAG((nexthop)->flags, NEXTHOP_FLAG_RECURSIVE) \
315 ? (((recursing) = 1), (nexthop)->resolved) \
316 : ((nexthop)->next ? ((recursing) ? (nexthop)->next \
317 : ((tnexthop) = (nexthop)->next)) \
318 : (((recursing) = 0),((tnexthop) = (tnexthop)->next)))
319
paul718e3742002-12-13 20:15:29 +0000320/* Routing table instance. */
Feng Lu41f44a22015-05-22 11:39:56 +0200321struct zebra_vrf
paul718e3742002-12-13 20:15:29 +0000322{
Feng Lu41f44a22015-05-22 11:39:56 +0200323 /* Identifier. */
324 vrf_id_t vrf_id;
paul718e3742002-12-13 20:15:29 +0000325
326 /* Routing table name. */
327 char *name;
328
329 /* Description. */
330 char *desc;
331
332 /* FIB identifier. */
333 u_char fib_id;
334
335 /* Routing table. */
336 struct route_table *table[AFI_MAX][SAFI_MAX];
337
338 /* Static route configuration. */
339 struct route_table *stable[AFI_MAX][SAFI_MAX];
340};
341
Avneesh Sachdev1b5ed1b2012-11-13 22:48:54 +0000342/*
343 * rib_table_info_t
344 *
345 * Structure that is hung off of a route_table that holds information about
346 * the table.
347 */
348typedef struct rib_table_info_t_
349{
350
351 /*
Feng Lu41f44a22015-05-22 11:39:56 +0200352 * Back pointer to zebra_vrf.
Avneesh Sachdev1b5ed1b2012-11-13 22:48:54 +0000353 */
Feng Lu41f44a22015-05-22 11:39:56 +0200354 struct zebra_vrf *zvrf;
Avneesh Sachdev1b5ed1b2012-11-13 22:48:54 +0000355 afi_t afi;
356 safi_t safi;
357
358} rib_table_info_t;
359
Avneesh Sachdev0915bb02012-11-13 22:48:55 +0000360typedef enum
361{
362 RIB_TABLES_ITER_S_INIT,
363 RIB_TABLES_ITER_S_ITERATING,
364 RIB_TABLES_ITER_S_DONE
365} rib_tables_iter_state_t;
366
367/*
368 * Structure that holds state for iterating over all tables in the
369 * Routing Information Base.
370 */
371typedef struct rib_tables_iter_t_
372{
Feng Lu41f44a22015-05-22 11:39:56 +0200373 vrf_id_t vrf_id;
Avneesh Sachdev0915bb02012-11-13 22:48:55 +0000374 int afi_safi_ix;
375
376 rib_tables_iter_state_t state;
377} rib_tables_iter_t;
378
David Lamparterbd078122015-01-06 19:53:24 +0100379/* RPF lookup behaviour */
380enum multicast_mode
381{
382 MCAST_NO_CONFIG = 0, /* MIX_MRIB_FIRST, but no show in config write */
383 MCAST_MRIB_ONLY, /* MRIB only */
384 MCAST_URIB_ONLY, /* URIB only */
385 MCAST_MIX_MRIB_FIRST, /* MRIB, if nothing at all then URIB */
386 MCAST_MIX_DISTANCE, /* MRIB & URIB, lower distance wins */
387 MCAST_MIX_PFXLEN, /* MRIB & URIB, longer prefix wins */
388 /* on equal value, MRIB wins for last 2 */
389};
390
391extern void multicast_mode_ipv4_set (enum multicast_mode mode);
392extern enum multicast_mode multicast_mode_ipv4_get (void);
393
Avneesh Sachdev78deec42012-11-13 22:48:56 +0000394extern const char *nexthop_type_to_str (enum nexthop_types_t nh_type);
paula1ac18c2005-06-28 17:17:12 +0000395extern struct nexthop *nexthop_ifindex_add (struct rib *, unsigned int);
396extern struct nexthop *nexthop_ifname_add (struct rib *, char *);
397extern struct nexthop *nexthop_blackhole_add (struct rib *);
Paul Jakma7514fb72007-05-02 16:05:35 +0000398extern struct nexthop *nexthop_ipv4_add (struct rib *, struct in_addr *,
399 struct in_addr *);
Josh Bailey26e2ae32012-03-22 01:09:21 -0700400extern struct nexthop *nexthop_ipv4_ifindex_add (struct rib *,
401 struct in_addr *,
402 struct in_addr *,
403 unsigned int);
Christian Frankefa713d92013-07-05 15:35:37 +0000404extern int nexthop_has_fib_child(struct nexthop *);
Denis Ovsienkodc958242007-08-13 16:03:06 +0000405extern void rib_lookup_and_dump (struct prefix_ipv4 *);
Denis Ovsienko20e5ff02008-02-26 14:02:24 +0000406extern void rib_lookup_and_pushup (struct prefix_ipv4 *);
David Lamparterf7bf4152013-10-22 17:10:21 +0000407#define rib_dump(prefix ,rib) _rib_dump(__func__, prefix, rib)
408extern void _rib_dump (const char *,
409 union prefix46constptr, const struct rib *);
Feng Lu0d0686f2015-05-22 11:40:02 +0200410extern int rib_lookup_ipv4_route (struct prefix_ipv4 *, union sockunion *,
411 vrf_id_t);
Denis Ovsienkodc958242007-08-13 16:03:06 +0000412#define ZEBRA_RIB_LOOKUP_ERROR -1
413#define ZEBRA_RIB_FOUND_EXACT 0
414#define ZEBRA_RIB_FOUND_NOGATE 1
415#define ZEBRA_RIB_FOUND_CONNECTED 2
416#define ZEBRA_RIB_NOTFOUND 3
417
paul718e3742002-12-13 20:15:29 +0000418#ifdef HAVE_IPV6
paula1ac18c2005-06-28 17:17:12 +0000419extern struct nexthop *nexthop_ipv6_add (struct rib *, struct in6_addr *);
paul718e3742002-12-13 20:15:29 +0000420#endif /* HAVE_IPV6 */
421
Feng Lu41f44a22015-05-22 11:39:56 +0200422extern struct zebra_vrf *zebra_vrf_alloc (vrf_id_t);
423extern struct route_table *zebra_vrf_table (afi_t, safi_t, vrf_id_t);
424extern struct route_table *zebra_vrf_static_table (afi_t, safi_t, vrf_id_t);
paul718e3742002-12-13 20:15:29 +0000425
hassod24af182005-09-24 14:00:26 +0000426/* NOTE:
427 * All rib_add_ipv[46]* functions will not just add prefix into RIB, but
428 * also implicitly withdraw equal prefix of same type. */
paula1ac18c2005-06-28 17:17:12 +0000429extern int rib_add_ipv4 (int type, int flags, struct prefix_ipv4 *p,
Paul Jakma7514fb72007-05-02 16:05:35 +0000430 struct in_addr *gate, struct in_addr *src,
Feng Lu0d0686f2015-05-22 11:40:02 +0200431 unsigned int ifindex, vrf_id_t vrf_id, int table_id,
G.Balajicddf3912011-11-26 21:59:32 +0400432 u_int32_t, u_char, safi_t);
paul718e3742002-12-13 20:15:29 +0000433
G.Balajicddf3912011-11-26 21:59:32 +0400434extern int rib_add_ipv4_multipath (struct prefix_ipv4 *, struct rib *, safi_t);
paul718e3742002-12-13 20:15:29 +0000435
paula1ac18c2005-06-28 17:17:12 +0000436extern int rib_delete_ipv4 (int type, int flags, struct prefix_ipv4 *p,
437 struct in_addr *gate, unsigned int ifindex,
Feng Lu0d0686f2015-05-22 11:40:02 +0200438 vrf_id_t, safi_t safi);
paul718e3742002-12-13 20:15:29 +0000439
David Lamparter24480d42015-01-22 19:09:36 +0100440extern struct rib *rib_match_ipv4_safi (struct in_addr addr, safi_t safi,
Feng Lu0d0686f2015-05-22 11:40:02 +0200441 int skip_bgp, struct route_node **rn_out,
442 vrf_id_t);
David Lamparterbd078122015-01-06 19:53:24 +0100443extern struct rib *rib_match_ipv4_multicast (struct in_addr addr,
Feng Lu0d0686f2015-05-22 11:40:02 +0200444 struct route_node **rn_out,
445 vrf_id_t);
paul718e3742002-12-13 20:15:29 +0000446
Feng Lu0d0686f2015-05-22 11:40:02 +0200447extern struct rib *rib_lookup_ipv4 (struct prefix_ipv4 *, vrf_id_t);
paul718e3742002-12-13 20:15:29 +0000448
Feng Lu0d0686f2015-05-22 11:40:02 +0200449extern void rib_update (vrf_id_t);
paula1ac18c2005-06-28 17:17:12 +0000450extern void rib_weed_tables (void);
451extern void rib_sweep_route (void);
452extern void rib_close (void);
453extern void rib_init (void);
Vyacheslav Trushkin2ea1ab12011-12-11 18:48:47 +0400454extern unsigned long rib_score_proto (u_char proto);
paul718e3742002-12-13 20:15:29 +0000455
paula1ac18c2005-06-28 17:17:12 +0000456extern int
Everton Marques33d86db2014-07-14 11:19:00 -0300457static_add_ipv4_safi (safi_t safi, struct prefix *p, struct in_addr *gate,
458 const char *ifname, u_char flags, u_char distance,
Feng Lu0d0686f2015-05-22 11:40:02 +0200459 vrf_id_t vrf_id);
paula1ac18c2005-06-28 17:17:12 +0000460extern int
Everton Marques33d86db2014-07-14 11:19:00 -0300461static_delete_ipv4_safi (safi_t safi, struct prefix *p, struct in_addr *gate,
Feng Lu0d0686f2015-05-22 11:40:02 +0200462 const char *ifname, u_char distance, vrf_id_t vrf_id);
paul718e3742002-12-13 20:15:29 +0000463
464#ifdef HAVE_IPV6
paula1ac18c2005-06-28 17:17:12 +0000465extern int
paul718e3742002-12-13 20:15:29 +0000466rib_add_ipv6 (int type, int flags, struct prefix_ipv6 *p,
Feng Lu0d0686f2015-05-22 11:40:02 +0200467 struct in6_addr *gate, unsigned int ifindex, vrf_id_t vrf_id,
468 int table_id, u_int32_t metric, u_char distance, safi_t safi);
paul718e3742002-12-13 20:15:29 +0000469
paula1ac18c2005-06-28 17:17:12 +0000470extern int
paul718e3742002-12-13 20:15:29 +0000471rib_delete_ipv6 (int type, int flags, struct prefix_ipv6 *p,
Feng Lu0d0686f2015-05-22 11:40:02 +0200472 struct in6_addr *gate, unsigned int ifindex, vrf_id_t vrf_id, safi_t safi);
paul718e3742002-12-13 20:15:29 +0000473
Feng Lu0d0686f2015-05-22 11:40:02 +0200474extern struct rib *rib_lookup_ipv6 (struct in6_addr *, vrf_id_t);
paul718e3742002-12-13 20:15:29 +0000475
Feng Lu0d0686f2015-05-22 11:40:02 +0200476extern struct rib *rib_match_ipv6 (struct in6_addr *, vrf_id_t);
paul718e3742002-12-13 20:15:29 +0000477
478extern struct route_table *rib_table_ipv6;
479
paula1ac18c2005-06-28 17:17:12 +0000480extern int
paul718e3742002-12-13 20:15:29 +0000481static_add_ipv6 (struct prefix *p, u_char type, struct in6_addr *gate,
hasso39db97e2004-10-12 20:50:58 +0000482 const char *ifname, u_char flags, u_char distance,
Feng Lu0d0686f2015-05-22 11:40:02 +0200483 vrf_id_t vrf_id);
paul718e3742002-12-13 20:15:29 +0000484
paula1ac18c2005-06-28 17:17:12 +0000485extern int
paul718e3742002-12-13 20:15:29 +0000486static_delete_ipv6 (struct prefix *p, u_char type, struct in6_addr *gate,
Feng Lu0d0686f2015-05-22 11:40:02 +0200487 const char *ifname, u_char distance, vrf_id_t vrf_id);
paul718e3742002-12-13 20:15:29 +0000488
489#endif /* HAVE_IPV6 */
490
Avneesh Sachdev9fd92e32012-11-13 22:48:53 +0000491extern int rib_gc_dest (struct route_node *rn);
Avneesh Sachdev0915bb02012-11-13 22:48:55 +0000492extern struct route_table *rib_tables_iter_next (rib_tables_iter_t *iter);
Avneesh Sachdev9fd92e32012-11-13 22:48:53 +0000493
494/*
495 * Inline functions.
496 */
497
498/*
Avneesh Sachdev1b5ed1b2012-11-13 22:48:54 +0000499 * rib_table_info
500 */
501static inline rib_table_info_t *
502rib_table_info (struct route_table *table)
503{
504 return (rib_table_info_t *) table->info;
505}
506
507/*
Avneesh Sachdev9fd92e32012-11-13 22:48:53 +0000508 * rib_dest_from_rnode
509 */
510static inline rib_dest_t *
511rib_dest_from_rnode (struct route_node *rn)
512{
513 return (rib_dest_t *) rn->info;
514}
515
516/*
517 * rnode_to_ribs
518 *
519 * Returns a pointer to the list of routes corresponding to the given
520 * route_node.
521 */
522static inline struct rib *
523rnode_to_ribs (struct route_node *rn)
524{
525 rib_dest_t *dest;
526
527 dest = rib_dest_from_rnode (rn);
528 if (!dest)
529 return NULL;
530
531 return dest->routes;
532}
533
534/*
535 * rib_dest_prefix
536 */
537static inline struct prefix *
538rib_dest_prefix (rib_dest_t *dest)
539{
540 return &dest->rnode->p;
541}
542
543/*
544 * rib_dest_af
545 *
546 * Returns the address family that the destination is for.
547 */
548static inline u_char
549rib_dest_af (rib_dest_t *dest)
550{
551 return dest->rnode->p.family;
552}
553
554/*
555 * rib_dest_table
556 */
557static inline struct route_table *
558rib_dest_table (rib_dest_t *dest)
559{
560 return dest->rnode->table;
561}
562
Avneesh Sachdev1b5ed1b2012-11-13 22:48:54 +0000563/*
564 * rib_dest_vrf
565 */
Feng Lu41f44a22015-05-22 11:39:56 +0200566static inline struct zebra_vrf *
Avneesh Sachdev1b5ed1b2012-11-13 22:48:54 +0000567rib_dest_vrf (rib_dest_t *dest)
568{
Feng Lu41f44a22015-05-22 11:39:56 +0200569 return rib_table_info (rib_dest_table (dest))->zvrf;
Avneesh Sachdev1b5ed1b2012-11-13 22:48:54 +0000570}
571
Avneesh Sachdev0915bb02012-11-13 22:48:55 +0000572/*
573 * rib_tables_iter_init
574 */
575static inline void
576rib_tables_iter_init (rib_tables_iter_t *iter)
577
578{
579 memset (iter, 0, sizeof (*iter));
580 iter->state = RIB_TABLES_ITER_S_INIT;
581}
582
583/*
584 * rib_tables_iter_started
585 *
586 * Returns TRUE if this iterator has started iterating over the set of
587 * tables.
588 */
589static inline int
590rib_tables_iter_started (rib_tables_iter_t *iter)
591{
592 return iter->state != RIB_TABLES_ITER_S_INIT;
593}
594
595/*
596 * rib_tables_iter_cleanup
597 */
598static inline void
599rib_tables_iter_cleanup (rib_tables_iter_t *iter)
600{
601 iter->state = RIB_TABLES_ITER_S_DONE;
602}
603
paul718e3742002-12-13 20:15:29 +0000604#endif /*_ZEBRA_RIB_H */