blob: 99729411fc388486c63e9cf02c0f6b74d91c43c1 [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
Feng Luac19a442015-05-22 11:40:07 +020026#include "linklist.h"
paulec1a4282005-11-24 15:15:17 +000027#include "prefix.h"
Avneesh Sachdev9fd92e32012-11-13 22:48:53 +000028#include "table.h"
Avneesh Sachdev5adc2522012-11-13 22:48:59 +000029#include "queue.h"
paulec1a4282005-11-24 15:15:17 +000030
paul718e3742002-12-13 20:15:29 +000031#define DISTANCE_INFINITY 255
32
33/* Routing information base. */
Paul Jakma7514fb72007-05-02 16:05:35 +000034
35union g_addr {
36 struct in_addr ipv4;
37#ifdef HAVE_IPV6
38 struct in6_addr ipv6;
39#endif /* HAVE_IPV6 */
40};
41
paul718e3742002-12-13 20:15:29 +000042struct rib
43{
44 /* Link list. */
45 struct rib *next;
46 struct rib *prev;
Paul Jakmae6d7d052006-03-30 13:32:09 +000047
48 /* Nexthop structure */
49 struct nexthop *nexthop;
50
51 /* Refrence count. */
52 unsigned long refcnt;
53
54 /* Uptime. */
55 time_t uptime;
paul718e3742002-12-13 20:15:29 +000056
57 /* Type fo this route. */
58 int type;
59
Feng Lu0d0686f2015-05-22 11:40:02 +020060 /* VRF identifier. */
61 vrf_id_t vrf_id;
62
paul718e3742002-12-13 20:15:29 +000063 /* Which routing table */
64 int table;
65
Paul Jakmae6d7d052006-03-30 13:32:09 +000066 /* Metric */
67 u_int32_t metric;
68
paul718e3742002-12-13 20:15:29 +000069 /* Distance. */
70 u_char distance;
71
Paul Jakma6d691122006-07-27 21:49:00 +000072 /* Flags of this route.
73 * This flag's definition is in lib/zebra.h ZEBRA_FLAG_* and is exposed
74 * to clients via Zserv
75 */
paul718e3742002-12-13 20:15:29 +000076 u_char flags;
77
Paul Jakma6d691122006-07-27 21:49:00 +000078 /* RIB internal status */
79 u_char status;
80#define RIB_ENTRY_REMOVED (1 << 0)
81
paul718e3742002-12-13 20:15:29 +000082 /* Nexthop information. */
83 u_char nexthop_num;
84 u_char nexthop_active_num;
85 u_char nexthop_fib_num;
paul718e3742002-12-13 20:15:29 +000086};
87
Denis Ovsienkoe96f9202008-06-02 12:03:22 +000088/* meta-queue structure:
89 * sub-queue 0: connected, kernel
90 * sub-queue 1: static
91 * sub-queue 2: RIP, RIPng, OSPF, OSPF6, IS-IS
92 * sub-queue 3: iBGP, eBGP
93 * sub-queue 4: any other origin (if any)
94 */
95#define MQ_SIZE 5
96struct meta_queue
97{
98 struct list *subq[MQ_SIZE];
99 u_int32_t size; /* sum of lengths of all subqueues */
100};
101
Avneesh Sachdev9fd92e32012-11-13 22:48:53 +0000102/*
103 * Structure that represents a single destination (prefix).
104 */
105typedef struct rib_dest_t_
106{
107
108 /*
109 * Back pointer to the route node for this destination. This helps
110 * us get to the prefix that this structure is for.
111 */
112 struct route_node *rnode;
113
114 /*
115 * Doubly-linked list of routes for this prefix.
116 */
117 struct rib *routes;
118
119 /*
120 * Flags, see below.
121 */
122 u_int32_t flags;
123
Avneesh Sachdev5adc2522012-11-13 22:48:59 +0000124 /*
125 * Linkage to put dest on the FPM processing queue.
126 */
127 TAILQ_ENTRY(rib_dest_t_) fpm_q_entries;
128
Avneesh Sachdev9fd92e32012-11-13 22:48:53 +0000129} rib_dest_t;
130
131#define RIB_ROUTE_QUEUED(x) (1 << (x))
132
133/*
134 * The maximum qindex that can be used.
135 */
136#define ZEBRA_MAX_QINDEX (MQ_SIZE - 1)
137
138/*
Avneesh Sachdev5adc2522012-11-13 22:48:59 +0000139 * This flag indicates that a given prefix has been 'advertised' to
140 * the FPM to be installed in the forwarding plane.
141 */
142#define RIB_DEST_SENT_TO_FPM (1 << (ZEBRA_MAX_QINDEX + 1))
143
144/*
145 * This flag is set when we need to send an update to the FPM about a
146 * dest.
147 */
148#define RIB_DEST_UPDATE_FPM (1 << (ZEBRA_MAX_QINDEX + 2))
149
150/*
Avneesh Sachdev9fd92e32012-11-13 22:48:53 +0000151 * Macro to iterate over each route for a destination (prefix).
152 */
153#define RIB_DEST_FOREACH_ROUTE(dest, rib) \
154 for ((rib) = (dest) ? (dest)->routes : NULL; (rib); (rib) = (rib)->next)
155
156/*
157 * Same as above, but allows the current node to be unlinked.
158 */
159#define RIB_DEST_FOREACH_ROUTE_SAFE(dest, rib, next) \
160 for ((rib) = (dest) ? (dest)->routes : NULL; \
161 (rib) && ((next) = (rib)->next, 1); \
162 (rib) = (next))
163
164#define RNODE_FOREACH_RIB(rn, rib) \
165 RIB_DEST_FOREACH_ROUTE (rib_dest_from_rnode (rn), rib)
166
167#define RNODE_FOREACH_RIB_SAFE(rn, rib, next) \
168 RIB_DEST_FOREACH_ROUTE_SAFE (rib_dest_from_rnode (rn), rib, next)
169
paul718e3742002-12-13 20:15:29 +0000170/* Static route information. */
171struct static_ipv4
172{
173 /* For linked list. */
174 struct static_ipv4 *prev;
175 struct static_ipv4 *next;
176
Feng Lu7aaf4ea2015-05-22 11:40:06 +0200177 /* VRF identifier. */
178 vrf_id_t vrf_id;
179
paul718e3742002-12-13 20:15:29 +0000180 /* Administrative distance. */
181 u_char distance;
182
183 /* Flag for this static route's type. */
184 u_char type;
185#define STATIC_IPV4_GATEWAY 1
186#define STATIC_IPV4_IFNAME 2
paul595db7f2003-05-25 21:35:06 +0000187#define STATIC_IPV4_BLACKHOLE 3
paul718e3742002-12-13 20:15:29 +0000188
189 /* Nexthop value. */
190 union
191 {
192 struct in_addr ipv4;
193 char *ifname;
194 } gate;
hasso81dfcaa2003-05-25 19:21:25 +0000195
196 /* bit flags */
197 u_char flags;
198/*
199 see ZEBRA_FLAG_REJECT
200 ZEBRA_FLAG_BLACKHOLE
201 */
paul718e3742002-12-13 20:15:29 +0000202};
203
204#ifdef HAVE_IPV6
205/* Static route information. */
206struct static_ipv6
207{
208 /* For linked list. */
209 struct static_ipv6 *prev;
210 struct static_ipv6 *next;
211
Feng Lu7aaf4ea2015-05-22 11:40:06 +0200212 /* VRF identifier. */
213 vrf_id_t vrf_id;
214
paul718e3742002-12-13 20:15:29 +0000215 /* Administrative distance. */
216 u_char distance;
217
218 /* Flag for this static route's type. */
219 u_char type;
220#define STATIC_IPV6_GATEWAY 1
221#define STATIC_IPV6_GATEWAY_IFNAME 2
222#define STATIC_IPV6_IFNAME 3
223
224 /* Nexthop value. */
225 struct in6_addr ipv6;
226 char *ifname;
hasso81dfcaa2003-05-25 19:21:25 +0000227
228 /* bit flags */
229 u_char flags;
230/*
231 see ZEBRA_FLAG_REJECT
232 ZEBRA_FLAG_BLACKHOLE
233 */
paul718e3742002-12-13 20:15:29 +0000234};
235#endif /* HAVE_IPV6 */
236
paul7021c422003-07-15 12:52:22 +0000237enum nexthop_types_t
238{
239 NEXTHOP_TYPE_IFINDEX = 1, /* Directly connected. */
240 NEXTHOP_TYPE_IFNAME, /* Interface route. */
241 NEXTHOP_TYPE_IPV4, /* IPv4 nexthop. */
242 NEXTHOP_TYPE_IPV4_IFINDEX, /* IPv4 nexthop with ifindex. */
243 NEXTHOP_TYPE_IPV4_IFNAME, /* IPv4 nexthop with ifname. */
244 NEXTHOP_TYPE_IPV6, /* IPv6 nexthop. */
245 NEXTHOP_TYPE_IPV6_IFINDEX, /* IPv6 nexthop with ifindex. */
246 NEXTHOP_TYPE_IPV6_IFNAME, /* IPv6 nexthop with ifname. */
247 NEXTHOP_TYPE_BLACKHOLE, /* Null0 nexthop. */
248};
249
paul718e3742002-12-13 20:15:29 +0000250/* Nexthop structure. */
251struct nexthop
252{
253 struct nexthop *next;
254 struct nexthop *prev;
255
Paul Jakmae6d7d052006-03-30 13:32:09 +0000256 /* Interface index. */
257 char *ifname;
258 unsigned int ifindex;
259
paul7021c422003-07-15 12:52:22 +0000260 enum nexthop_types_t type;
paul718e3742002-12-13 20:15:29 +0000261
262 u_char flags;
263#define NEXTHOP_FLAG_ACTIVE (1 << 0) /* This nexthop is alive. */
264#define NEXTHOP_FLAG_FIB (1 << 1) /* FIB nexthop. */
265#define NEXTHOP_FLAG_RECURSIVE (1 << 2) /* Recursive nexthop. */
Christian Frankee8d3d292013-07-05 15:35:39 +0000266#define NEXTHOP_FLAG_ONLINK (1 << 3) /* Nexthop should be installed onlink. */
paul718e3742002-12-13 20:15:29 +0000267
Christian Frankefa713d92013-07-05 15:35:37 +0000268 /* Nexthop address */
Paul Jakma7514fb72007-05-02 16:05:35 +0000269 union g_addr gate;
Paul Jakma7514fb72007-05-02 16:05:35 +0000270 union g_addr src;
Christian Frankefa713d92013-07-05 15:35:37 +0000271
272 /* Nexthops obtained by recursive resolution.
273 *
274 * If the nexthop struct needs to be resolved recursively,
275 * NEXTHOP_FLAG_RECURSIVE will be set in flags and the nexthops
276 * obtained by recursive resolution will be added to `resolved'.
277 * Only one level of recursive resolution is currently supported. */
278 struct nexthop *resolved;
paul718e3742002-12-13 20:15:29 +0000279};
280
Christian Frankefa713d92013-07-05 15:35:37 +0000281/* The following for loop allows to iterate over the nexthop
282 * structure of routes.
283 *
284 * We have to maintain quite a bit of state:
285 *
286 * nexthop: The pointer to the current nexthop, either in the
287 * top-level chain or in the resolved chain of ni.
288 * tnexthop: The pointer to the current nexthop in the top-level
289 * nexthop chain.
290 * recursing: Information if nh currently is in the top-level chain
291 * (0) or in a resolved chain (1).
292 *
293 * Initialization: Set `nexthop' and `tnexthop' to the head of the
294 * top-level chain. As nexthop is in the top level chain, set recursing
295 * to 0.
296 *
297 * Iteration check: Check that the `nexthop' pointer is not NULL.
298 *
299 * Iteration step: This is the tricky part. Check if `nexthop' has
300 * NEXTHOP_FLAG_RECURSIVE set. If yes, this implies that `nexthop' is in
301 * the top level chain and has at least one nexthop attached to
302 * `nexthop->resolved'. As we want to descend into `nexthop->resolved',
303 * set `recursing' to 1 and set `nexthop' to `nexthop->resolved'.
304 * `tnexthop' is left alone in that case so we can remember which nexthop
305 * in the top level chain we are currently handling.
306 *
307 * If NEXTHOP_FLAG_RECURSIVE is not set, `nexthop' will progress in its
308 * current chain. If we are recursing, `nexthop' will be set to
309 * `nexthop->next' and `tnexthop' will be left alone. If we are not
310 * recursing, both `tnexthop' and `nexthop' will be set to `nexthop->next'
311 * as we are progressing in the top level chain.
312 * If we encounter `nexthop->next == NULL', we will clear the `recursing'
313 * flag as we arived either at the end of the resolved chain or at the end
314 * of the top level chain. In both cases, we set `tnexthop' and `nexthop'
315 * to `tnexthop->next', progressing to the next position in the top-level
316 * chain and possibly to its end marked by NULL.
317 */
318#define ALL_NEXTHOPS_RO(head, nexthop, tnexthop, recursing) \
319 (tnexthop) = (nexthop) = (head), (recursing) = 0; \
320 (nexthop); \
321 (nexthop) = CHECK_FLAG((nexthop)->flags, NEXTHOP_FLAG_RECURSIVE) \
322 ? (((recursing) = 1), (nexthop)->resolved) \
323 : ((nexthop)->next ? ((recursing) ? (nexthop)->next \
324 : ((tnexthop) = (nexthop)->next)) \
325 : (((recursing) = 0),((tnexthop) = (tnexthop)->next)))
326
Feng Lu1885d0a2015-05-22 11:40:04 +0200327/* Structure holding nexthop & VRF identifier,
328 * used for applying the route-map. */
329struct nexthop_vrfid
330{
331 struct nexthop *nexthop;
332 vrf_id_t vrf_id;
333};
334
Feng Lu49f76092015-05-22 11:40:10 +0200335/* Router advertisement feature. */
336#ifndef RTADV
337#if (defined(LINUX_IPV6) && (defined(__GLIBC__) && __GLIBC__ >= 2 && __GLIBC_MINOR__ >= 1)) || defined(KAME)
338 #ifdef HAVE_RTADV
339 #define RTADV
340 #endif
341#endif
342#endif
343
344#if defined (HAVE_IPV6) && defined (RTADV)
345/* Structure which hold status of router advertisement. */
346struct rtadv
347{
348 int sock;
349
350 int adv_if_count;
351 int adv_msec_if_count;
352
353 struct thread *ra_read;
354 struct thread *ra_timer;
355};
356#endif /* RTADV && HAVE_IPV6 */
357
paul718e3742002-12-13 20:15:29 +0000358/* Routing table instance. */
Feng Lu41f44a22015-05-22 11:39:56 +0200359struct zebra_vrf
paul718e3742002-12-13 20:15:29 +0000360{
Feng Lu41f44a22015-05-22 11:39:56 +0200361 /* Identifier. */
362 vrf_id_t vrf_id;
paul718e3742002-12-13 20:15:29 +0000363
364 /* Routing table name. */
365 char *name;
366
367 /* Description. */
368 char *desc;
369
370 /* FIB identifier. */
371 u_char fib_id;
372
373 /* Routing table. */
374 struct route_table *table[AFI_MAX][SAFI_MAX];
375
376 /* Static route configuration. */
377 struct route_table *stable[AFI_MAX][SAFI_MAX];
Feng Luac19a442015-05-22 11:40:07 +0200378
379 /* 2nd pointer type used primarily to quell a warning on
380 * ALL_LIST_ELEMENTS_RO
381 */
382 struct list _rid_all_sorted_list;
383 struct list _rid_lo_sorted_list;
384 struct list *rid_all_sorted_list;
385 struct list *rid_lo_sorted_list;
386 struct prefix rid_user_assigned;
Feng Lu49f76092015-05-22 11:40:10 +0200387
388#if defined (HAVE_IPV6) && defined (RTADV)
389 struct rtadv rtadv;
390#endif /* RTADV && HAVE_IPV6 */
paul718e3742002-12-13 20:15:29 +0000391};
392
Avneesh Sachdev1b5ed1b2012-11-13 22:48:54 +0000393/*
394 * rib_table_info_t
395 *
396 * Structure that is hung off of a route_table that holds information about
397 * the table.
398 */
399typedef struct rib_table_info_t_
400{
401
402 /*
Feng Lu41f44a22015-05-22 11:39:56 +0200403 * Back pointer to zebra_vrf.
Avneesh Sachdev1b5ed1b2012-11-13 22:48:54 +0000404 */
Feng Lu41f44a22015-05-22 11:39:56 +0200405 struct zebra_vrf *zvrf;
Avneesh Sachdev1b5ed1b2012-11-13 22:48:54 +0000406 afi_t afi;
407 safi_t safi;
408
409} rib_table_info_t;
410
Avneesh Sachdev0915bb02012-11-13 22:48:55 +0000411typedef enum
412{
413 RIB_TABLES_ITER_S_INIT,
414 RIB_TABLES_ITER_S_ITERATING,
415 RIB_TABLES_ITER_S_DONE
416} rib_tables_iter_state_t;
417
418/*
419 * Structure that holds state for iterating over all tables in the
420 * Routing Information Base.
421 */
422typedef struct rib_tables_iter_t_
423{
Feng Lu41f44a22015-05-22 11:39:56 +0200424 vrf_id_t vrf_id;
Avneesh Sachdev0915bb02012-11-13 22:48:55 +0000425 int afi_safi_ix;
426
427 rib_tables_iter_state_t state;
428} rib_tables_iter_t;
429
David Lamparterbd078122015-01-06 19:53:24 +0100430/* RPF lookup behaviour */
431enum multicast_mode
432{
433 MCAST_NO_CONFIG = 0, /* MIX_MRIB_FIRST, but no show in config write */
434 MCAST_MRIB_ONLY, /* MRIB only */
435 MCAST_URIB_ONLY, /* URIB only */
436 MCAST_MIX_MRIB_FIRST, /* MRIB, if nothing at all then URIB */
437 MCAST_MIX_DISTANCE, /* MRIB & URIB, lower distance wins */
438 MCAST_MIX_PFXLEN, /* MRIB & URIB, longer prefix wins */
439 /* on equal value, MRIB wins for last 2 */
440};
441
442extern void multicast_mode_ipv4_set (enum multicast_mode mode);
443extern enum multicast_mode multicast_mode_ipv4_get (void);
444
Avneesh Sachdev78deec42012-11-13 22:48:56 +0000445extern const char *nexthop_type_to_str (enum nexthop_types_t nh_type);
paula1ac18c2005-06-28 17:17:12 +0000446extern struct nexthop *nexthop_ifindex_add (struct rib *, unsigned int);
447extern struct nexthop *nexthop_ifname_add (struct rib *, char *);
448extern struct nexthop *nexthop_blackhole_add (struct rib *);
Paul Jakma7514fb72007-05-02 16:05:35 +0000449extern struct nexthop *nexthop_ipv4_add (struct rib *, struct in_addr *,
450 struct in_addr *);
Josh Bailey26e2ae32012-03-22 01:09:21 -0700451extern struct nexthop *nexthop_ipv4_ifindex_add (struct rib *,
452 struct in_addr *,
453 struct in_addr *,
454 unsigned int);
Christian Frankefa713d92013-07-05 15:35:37 +0000455extern int nexthop_has_fib_child(struct nexthop *);
Denis Ovsienkodc958242007-08-13 16:03:06 +0000456extern void rib_lookup_and_dump (struct prefix_ipv4 *);
Denis Ovsienko20e5ff02008-02-26 14:02:24 +0000457extern void rib_lookup_and_pushup (struct prefix_ipv4 *);
David Lamparterf7bf4152013-10-22 17:10:21 +0000458#define rib_dump(prefix ,rib) _rib_dump(__func__, prefix, rib)
459extern void _rib_dump (const char *,
460 union prefix46constptr, const struct rib *);
Feng Lu0d0686f2015-05-22 11:40:02 +0200461extern int rib_lookup_ipv4_route (struct prefix_ipv4 *, union sockunion *,
462 vrf_id_t);
Denis Ovsienkodc958242007-08-13 16:03:06 +0000463#define ZEBRA_RIB_LOOKUP_ERROR -1
464#define ZEBRA_RIB_FOUND_EXACT 0
465#define ZEBRA_RIB_FOUND_NOGATE 1
466#define ZEBRA_RIB_FOUND_CONNECTED 2
467#define ZEBRA_RIB_NOTFOUND 3
468
paul718e3742002-12-13 20:15:29 +0000469#ifdef HAVE_IPV6
paula1ac18c2005-06-28 17:17:12 +0000470extern struct nexthop *nexthop_ipv6_add (struct rib *, struct in6_addr *);
paul718e3742002-12-13 20:15:29 +0000471#endif /* HAVE_IPV6 */
472
Feng Lu41f44a22015-05-22 11:39:56 +0200473extern struct zebra_vrf *zebra_vrf_alloc (vrf_id_t);
474extern struct route_table *zebra_vrf_table (afi_t, safi_t, vrf_id_t);
475extern struct route_table *zebra_vrf_static_table (afi_t, safi_t, vrf_id_t);
paul718e3742002-12-13 20:15:29 +0000476
hassod24af182005-09-24 14:00:26 +0000477/* NOTE:
478 * All rib_add_ipv[46]* functions will not just add prefix into RIB, but
479 * also implicitly withdraw equal prefix of same type. */
paula1ac18c2005-06-28 17:17:12 +0000480extern int rib_add_ipv4 (int type, int flags, struct prefix_ipv4 *p,
Paul Jakma7514fb72007-05-02 16:05:35 +0000481 struct in_addr *gate, struct in_addr *src,
Feng Lu0d0686f2015-05-22 11:40:02 +0200482 unsigned int ifindex, vrf_id_t vrf_id, int table_id,
G.Balajicddf3912011-11-26 21:59:32 +0400483 u_int32_t, u_char, safi_t);
paul718e3742002-12-13 20:15:29 +0000484
G.Balajicddf3912011-11-26 21:59:32 +0400485extern int rib_add_ipv4_multipath (struct prefix_ipv4 *, struct rib *, safi_t);
paul718e3742002-12-13 20:15:29 +0000486
paula1ac18c2005-06-28 17:17:12 +0000487extern int rib_delete_ipv4 (int type, int flags, struct prefix_ipv4 *p,
488 struct in_addr *gate, unsigned int ifindex,
Feng Lu0d0686f2015-05-22 11:40:02 +0200489 vrf_id_t, safi_t safi);
paul718e3742002-12-13 20:15:29 +0000490
David Lamparter24480d42015-01-22 19:09:36 +0100491extern struct rib *rib_match_ipv4_safi (struct in_addr addr, safi_t safi,
Feng Lu0d0686f2015-05-22 11:40:02 +0200492 int skip_bgp, struct route_node **rn_out,
493 vrf_id_t);
David Lamparterbd078122015-01-06 19:53:24 +0100494extern struct rib *rib_match_ipv4_multicast (struct in_addr addr,
Feng Lu0d0686f2015-05-22 11:40:02 +0200495 struct route_node **rn_out,
496 vrf_id_t);
paul718e3742002-12-13 20:15:29 +0000497
Feng Lu0d0686f2015-05-22 11:40:02 +0200498extern struct rib *rib_lookup_ipv4 (struct prefix_ipv4 *, vrf_id_t);
paul718e3742002-12-13 20:15:29 +0000499
Feng Lu0d0686f2015-05-22 11:40:02 +0200500extern void rib_update (vrf_id_t);
paula1ac18c2005-06-28 17:17:12 +0000501extern void rib_weed_tables (void);
502extern void rib_sweep_route (void);
Feng Lu267ceb22015-05-22 11:40:09 +0200503extern void rib_close_table (struct route_table *);
paula1ac18c2005-06-28 17:17:12 +0000504extern void rib_close (void);
505extern void rib_init (void);
Vyacheslav Trushkin2ea1ab12011-12-11 18:48:47 +0400506extern unsigned long rib_score_proto (u_char proto);
paul718e3742002-12-13 20:15:29 +0000507
paula1ac18c2005-06-28 17:17:12 +0000508extern int
Everton Marques33d86db2014-07-14 11:19:00 -0300509static_add_ipv4_safi (safi_t safi, struct prefix *p, struct in_addr *gate,
510 const char *ifname, u_char flags, u_char distance,
Feng Lu0d0686f2015-05-22 11:40:02 +0200511 vrf_id_t vrf_id);
paula1ac18c2005-06-28 17:17:12 +0000512extern int
Everton Marques33d86db2014-07-14 11:19:00 -0300513static_delete_ipv4_safi (safi_t safi, struct prefix *p, struct in_addr *gate,
Feng Lu0d0686f2015-05-22 11:40:02 +0200514 const char *ifname, u_char distance, vrf_id_t vrf_id);
paul718e3742002-12-13 20:15:29 +0000515
516#ifdef HAVE_IPV6
paula1ac18c2005-06-28 17:17:12 +0000517extern int
paul718e3742002-12-13 20:15:29 +0000518rib_add_ipv6 (int type, int flags, struct prefix_ipv6 *p,
Feng Lu0d0686f2015-05-22 11:40:02 +0200519 struct in6_addr *gate, unsigned int ifindex, vrf_id_t vrf_id,
520 int table_id, u_int32_t metric, u_char distance, safi_t safi);
paul718e3742002-12-13 20:15:29 +0000521
paula1ac18c2005-06-28 17:17:12 +0000522extern int
paul718e3742002-12-13 20:15:29 +0000523rib_delete_ipv6 (int type, int flags, struct prefix_ipv6 *p,
Feng Lu0d0686f2015-05-22 11:40:02 +0200524 struct in6_addr *gate, unsigned int ifindex, vrf_id_t vrf_id, safi_t safi);
paul718e3742002-12-13 20:15:29 +0000525
Feng Lu0d0686f2015-05-22 11:40:02 +0200526extern struct rib *rib_lookup_ipv6 (struct in6_addr *, vrf_id_t);
paul718e3742002-12-13 20:15:29 +0000527
Feng Lu0d0686f2015-05-22 11:40:02 +0200528extern struct rib *rib_match_ipv6 (struct in6_addr *, vrf_id_t);
paul718e3742002-12-13 20:15:29 +0000529
530extern struct route_table *rib_table_ipv6;
531
paula1ac18c2005-06-28 17:17:12 +0000532extern int
paul718e3742002-12-13 20:15:29 +0000533static_add_ipv6 (struct prefix *p, u_char type, struct in6_addr *gate,
hasso39db97e2004-10-12 20:50:58 +0000534 const char *ifname, u_char flags, u_char distance,
Feng Lu0d0686f2015-05-22 11:40:02 +0200535 vrf_id_t vrf_id);
paul718e3742002-12-13 20:15:29 +0000536
paula1ac18c2005-06-28 17:17:12 +0000537extern int
paul718e3742002-12-13 20:15:29 +0000538static_delete_ipv6 (struct prefix *p, u_char type, struct in6_addr *gate,
Feng Lu0d0686f2015-05-22 11:40:02 +0200539 const char *ifname, u_char distance, vrf_id_t vrf_id);
paul718e3742002-12-13 20:15:29 +0000540
541#endif /* HAVE_IPV6 */
542
Avneesh Sachdev9fd92e32012-11-13 22:48:53 +0000543extern int rib_gc_dest (struct route_node *rn);
Avneesh Sachdev0915bb02012-11-13 22:48:55 +0000544extern struct route_table *rib_tables_iter_next (rib_tables_iter_t *iter);
Avneesh Sachdev9fd92e32012-11-13 22:48:53 +0000545
546/*
547 * Inline functions.
548 */
549
550/*
Avneesh Sachdev1b5ed1b2012-11-13 22:48:54 +0000551 * rib_table_info
552 */
553static inline rib_table_info_t *
554rib_table_info (struct route_table *table)
555{
556 return (rib_table_info_t *) table->info;
557}
558
559/*
Avneesh Sachdev9fd92e32012-11-13 22:48:53 +0000560 * rib_dest_from_rnode
561 */
562static inline rib_dest_t *
563rib_dest_from_rnode (struct route_node *rn)
564{
565 return (rib_dest_t *) rn->info;
566}
567
568/*
569 * rnode_to_ribs
570 *
571 * Returns a pointer to the list of routes corresponding to the given
572 * route_node.
573 */
574static inline struct rib *
575rnode_to_ribs (struct route_node *rn)
576{
577 rib_dest_t *dest;
578
579 dest = rib_dest_from_rnode (rn);
580 if (!dest)
581 return NULL;
582
583 return dest->routes;
584}
585
586/*
587 * rib_dest_prefix
588 */
589static inline struct prefix *
590rib_dest_prefix (rib_dest_t *dest)
591{
592 return &dest->rnode->p;
593}
594
595/*
596 * rib_dest_af
597 *
598 * Returns the address family that the destination is for.
599 */
600static inline u_char
601rib_dest_af (rib_dest_t *dest)
602{
603 return dest->rnode->p.family;
604}
605
606/*
607 * rib_dest_table
608 */
609static inline struct route_table *
610rib_dest_table (rib_dest_t *dest)
611{
612 return dest->rnode->table;
613}
614
Avneesh Sachdev1b5ed1b2012-11-13 22:48:54 +0000615/*
616 * rib_dest_vrf
617 */
Feng Lu41f44a22015-05-22 11:39:56 +0200618static inline struct zebra_vrf *
Avneesh Sachdev1b5ed1b2012-11-13 22:48:54 +0000619rib_dest_vrf (rib_dest_t *dest)
620{
Feng Lu41f44a22015-05-22 11:39:56 +0200621 return rib_table_info (rib_dest_table (dest))->zvrf;
Avneesh Sachdev1b5ed1b2012-11-13 22:48:54 +0000622}
623
Avneesh Sachdev0915bb02012-11-13 22:48:55 +0000624/*
625 * rib_tables_iter_init
626 */
627static inline void
628rib_tables_iter_init (rib_tables_iter_t *iter)
629
630{
631 memset (iter, 0, sizeof (*iter));
632 iter->state = RIB_TABLES_ITER_S_INIT;
633}
634
635/*
636 * rib_tables_iter_started
637 *
638 * Returns TRUE if this iterator has started iterating over the set of
639 * tables.
640 */
641static inline int
642rib_tables_iter_started (rib_tables_iter_t *iter)
643{
644 return iter->state != RIB_TABLES_ITER_S_INIT;
645}
646
647/*
648 * rib_tables_iter_cleanup
649 */
650static inline void
651rib_tables_iter_cleanup (rib_tables_iter_t *iter)
652{
653 iter->state = RIB_TABLES_ITER_S_DONE;
654}
655
paul718e3742002-12-13 20:15:29 +0000656#endif /*_ZEBRA_RIB_H */