blob: 6e0966abaa8769c4af2ff0814f2c08d5391c1c91 [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)
Timo Teräs7eb61362015-11-02 16:50:05 +020081#define RIB_ENTRY_CHANGED (1 << 1)
Paul Jakma6d691122006-07-27 21:49:00 +000082
paul718e3742002-12-13 20:15:29 +000083 /* Nexthop information. */
84 u_char nexthop_num;
85 u_char nexthop_active_num;
86 u_char nexthop_fib_num;
paul718e3742002-12-13 20:15:29 +000087};
88
Denis Ovsienkoe96f9202008-06-02 12:03:22 +000089/* meta-queue structure:
90 * sub-queue 0: connected, kernel
91 * sub-queue 1: static
92 * sub-queue 2: RIP, RIPng, OSPF, OSPF6, IS-IS
93 * sub-queue 3: iBGP, eBGP
94 * sub-queue 4: any other origin (if any)
95 */
96#define MQ_SIZE 5
97struct meta_queue
98{
99 struct list *subq[MQ_SIZE];
100 u_int32_t size; /* sum of lengths of all subqueues */
101};
102
Avneesh Sachdev9fd92e32012-11-13 22:48:53 +0000103/*
104 * Structure that represents a single destination (prefix).
105 */
106typedef struct rib_dest_t_
107{
108
109 /*
110 * Back pointer to the route node for this destination. This helps
111 * us get to the prefix that this structure is for.
112 */
113 struct route_node *rnode;
114
115 /*
116 * Doubly-linked list of routes for this prefix.
117 */
118 struct rib *routes;
119
120 /*
121 * Flags, see below.
122 */
123 u_int32_t flags;
124
Avneesh Sachdev5adc2522012-11-13 22:48:59 +0000125 /*
126 * Linkage to put dest on the FPM processing queue.
127 */
128 TAILQ_ENTRY(rib_dest_t_) fpm_q_entries;
129
Avneesh Sachdev9fd92e32012-11-13 22:48:53 +0000130} rib_dest_t;
131
132#define RIB_ROUTE_QUEUED(x) (1 << (x))
133
134/*
135 * The maximum qindex that can be used.
136 */
137#define ZEBRA_MAX_QINDEX (MQ_SIZE - 1)
138
139/*
Avneesh Sachdev5adc2522012-11-13 22:48:59 +0000140 * This flag indicates that a given prefix has been 'advertised' to
141 * the FPM to be installed in the forwarding plane.
142 */
143#define RIB_DEST_SENT_TO_FPM (1 << (ZEBRA_MAX_QINDEX + 1))
144
145/*
146 * This flag is set when we need to send an update to the FPM about a
147 * dest.
148 */
149#define RIB_DEST_UPDATE_FPM (1 << (ZEBRA_MAX_QINDEX + 2))
150
151/*
Avneesh Sachdev9fd92e32012-11-13 22:48:53 +0000152 * Macro to iterate over each route for a destination (prefix).
153 */
154#define RIB_DEST_FOREACH_ROUTE(dest, rib) \
155 for ((rib) = (dest) ? (dest)->routes : NULL; (rib); (rib) = (rib)->next)
156
157/*
158 * Same as above, but allows the current node to be unlinked.
159 */
160#define RIB_DEST_FOREACH_ROUTE_SAFE(dest, rib, next) \
161 for ((rib) = (dest) ? (dest)->routes : NULL; \
162 (rib) && ((next) = (rib)->next, 1); \
163 (rib) = (next))
164
165#define RNODE_FOREACH_RIB(rn, rib) \
166 RIB_DEST_FOREACH_ROUTE (rib_dest_from_rnode (rn), rib)
167
168#define RNODE_FOREACH_RIB_SAFE(rn, rib, next) \
169 RIB_DEST_FOREACH_ROUTE_SAFE (rib_dest_from_rnode (rn), rib, next)
170
paul718e3742002-12-13 20:15:29 +0000171/* Static route information. */
172struct static_ipv4
173{
174 /* For linked list. */
175 struct static_ipv4 *prev;
176 struct static_ipv4 *next;
177
Feng Lu7aaf4ea2015-05-22 11:40:06 +0200178 /* VRF identifier. */
179 vrf_id_t vrf_id;
180
paul718e3742002-12-13 20:15:29 +0000181 /* Administrative distance. */
182 u_char distance;
183
184 /* Flag for this static route's type. */
185 u_char type;
186#define STATIC_IPV4_GATEWAY 1
187#define STATIC_IPV4_IFNAME 2
paul595db7f2003-05-25 21:35:06 +0000188#define STATIC_IPV4_BLACKHOLE 3
paul718e3742002-12-13 20:15:29 +0000189
190 /* Nexthop value. */
191 union
192 {
193 struct in_addr ipv4;
194 char *ifname;
195 } gate;
hasso81dfcaa2003-05-25 19:21:25 +0000196
197 /* bit flags */
198 u_char flags;
199/*
200 see ZEBRA_FLAG_REJECT
201 ZEBRA_FLAG_BLACKHOLE
202 */
paul718e3742002-12-13 20:15:29 +0000203};
204
205#ifdef HAVE_IPV6
206/* Static route information. */
207struct static_ipv6
208{
209 /* For linked list. */
210 struct static_ipv6 *prev;
211 struct static_ipv6 *next;
212
Feng Lu7aaf4ea2015-05-22 11:40:06 +0200213 /* VRF identifier. */
214 vrf_id_t vrf_id;
215
paul718e3742002-12-13 20:15:29 +0000216 /* Administrative distance. */
217 u_char distance;
218
219 /* Flag for this static route's type. */
220 u_char type;
221#define STATIC_IPV6_GATEWAY 1
222#define STATIC_IPV6_GATEWAY_IFNAME 2
223#define STATIC_IPV6_IFNAME 3
224
225 /* Nexthop value. */
226 struct in6_addr ipv6;
227 char *ifname;
hasso81dfcaa2003-05-25 19:21:25 +0000228
229 /* bit flags */
230 u_char flags;
231/*
232 see ZEBRA_FLAG_REJECT
233 ZEBRA_FLAG_BLACKHOLE
234 */
paul718e3742002-12-13 20:15:29 +0000235};
236#endif /* HAVE_IPV6 */
237
paul7021c422003-07-15 12:52:22 +0000238enum nexthop_types_t
239{
240 NEXTHOP_TYPE_IFINDEX = 1, /* Directly connected. */
241 NEXTHOP_TYPE_IFNAME, /* Interface route. */
242 NEXTHOP_TYPE_IPV4, /* IPv4 nexthop. */
243 NEXTHOP_TYPE_IPV4_IFINDEX, /* IPv4 nexthop with ifindex. */
244 NEXTHOP_TYPE_IPV4_IFNAME, /* IPv4 nexthop with ifname. */
245 NEXTHOP_TYPE_IPV6, /* IPv6 nexthop. */
246 NEXTHOP_TYPE_IPV6_IFINDEX, /* IPv6 nexthop with ifindex. */
247 NEXTHOP_TYPE_IPV6_IFNAME, /* IPv6 nexthop with ifname. */
248 NEXTHOP_TYPE_BLACKHOLE, /* Null0 nexthop. */
249};
250
paul718e3742002-12-13 20:15:29 +0000251/* Nexthop structure. */
252struct nexthop
253{
254 struct nexthop *next;
255 struct nexthop *prev;
256
Paul Jakmae6d7d052006-03-30 13:32:09 +0000257 /* Interface index. */
258 char *ifname;
259 unsigned int ifindex;
260
paul7021c422003-07-15 12:52:22 +0000261 enum nexthop_types_t type;
paul718e3742002-12-13 20:15:29 +0000262
263 u_char flags;
264#define NEXTHOP_FLAG_ACTIVE (1 << 0) /* This nexthop is alive. */
265#define NEXTHOP_FLAG_FIB (1 << 1) /* FIB nexthop. */
266#define NEXTHOP_FLAG_RECURSIVE (1 << 2) /* Recursive nexthop. */
Christian Frankee8d3d292013-07-05 15:35:39 +0000267#define NEXTHOP_FLAG_ONLINK (1 << 3) /* Nexthop should be installed onlink. */
paul718e3742002-12-13 20:15:29 +0000268
Christian Frankefa713d92013-07-05 15:35:37 +0000269 /* Nexthop address */
Paul Jakma7514fb72007-05-02 16:05:35 +0000270 union g_addr gate;
Paul Jakma7514fb72007-05-02 16:05:35 +0000271 union g_addr src;
Christian Frankefa713d92013-07-05 15:35:37 +0000272
273 /* Nexthops obtained by recursive resolution.
274 *
275 * If the nexthop struct needs to be resolved recursively,
276 * NEXTHOP_FLAG_RECURSIVE will be set in flags and the nexthops
277 * obtained by recursive resolution will be added to `resolved'.
278 * Only one level of recursive resolution is currently supported. */
279 struct nexthop *resolved;
paul718e3742002-12-13 20:15:29 +0000280};
281
Christian Frankefa713d92013-07-05 15:35:37 +0000282/* The following for loop allows to iterate over the nexthop
283 * structure of routes.
284 *
285 * We have to maintain quite a bit of state:
286 *
287 * nexthop: The pointer to the current nexthop, either in the
288 * top-level chain or in the resolved chain of ni.
289 * tnexthop: The pointer to the current nexthop in the top-level
290 * nexthop chain.
291 * recursing: Information if nh currently is in the top-level chain
292 * (0) or in a resolved chain (1).
293 *
294 * Initialization: Set `nexthop' and `tnexthop' to the head of the
295 * top-level chain. As nexthop is in the top level chain, set recursing
296 * to 0.
297 *
298 * Iteration check: Check that the `nexthop' pointer is not NULL.
299 *
300 * Iteration step: This is the tricky part. Check if `nexthop' has
301 * NEXTHOP_FLAG_RECURSIVE set. If yes, this implies that `nexthop' is in
302 * the top level chain and has at least one nexthop attached to
303 * `nexthop->resolved'. As we want to descend into `nexthop->resolved',
304 * set `recursing' to 1 and set `nexthop' to `nexthop->resolved'.
305 * `tnexthop' is left alone in that case so we can remember which nexthop
306 * in the top level chain we are currently handling.
307 *
308 * If NEXTHOP_FLAG_RECURSIVE is not set, `nexthop' will progress in its
309 * current chain. If we are recursing, `nexthop' will be set to
310 * `nexthop->next' and `tnexthop' will be left alone. If we are not
311 * recursing, both `tnexthop' and `nexthop' will be set to `nexthop->next'
312 * as we are progressing in the top level chain.
313 * If we encounter `nexthop->next == NULL', we will clear the `recursing'
314 * flag as we arived either at the end of the resolved chain or at the end
315 * of the top level chain. In both cases, we set `tnexthop' and `nexthop'
316 * to `tnexthop->next', progressing to the next position in the top-level
317 * chain and possibly to its end marked by NULL.
318 */
319#define ALL_NEXTHOPS_RO(head, nexthop, tnexthop, recursing) \
320 (tnexthop) = (nexthop) = (head), (recursing) = 0; \
321 (nexthop); \
322 (nexthop) = CHECK_FLAG((nexthop)->flags, NEXTHOP_FLAG_RECURSIVE) \
323 ? (((recursing) = 1), (nexthop)->resolved) \
324 : ((nexthop)->next ? ((recursing) ? (nexthop)->next \
325 : ((tnexthop) = (nexthop)->next)) \
326 : (((recursing) = 0),((tnexthop) = (tnexthop)->next)))
327
Feng Lu1885d0a2015-05-22 11:40:04 +0200328/* Structure holding nexthop & VRF identifier,
329 * used for applying the route-map. */
330struct nexthop_vrfid
331{
332 struct nexthop *nexthop;
333 vrf_id_t vrf_id;
334};
335
Feng Lu49f76092015-05-22 11:40:10 +0200336/* Router advertisement feature. */
Timo Teräs983525e2015-10-22 11:35:16 +0300337#if !defined(RTADV) && defined(LINUX_IPV6) && defined(HAVE_RTADV)
338# define RTADV
Feng Lu49f76092015-05-22 11:40:10 +0200339#endif
340
341#if defined (HAVE_IPV6) && defined (RTADV)
342/* Structure which hold status of router advertisement. */
343struct rtadv
344{
345 int sock;
346
347 int adv_if_count;
348 int adv_msec_if_count;
349
350 struct thread *ra_read;
351 struct thread *ra_timer;
352};
353#endif /* RTADV && HAVE_IPV6 */
354
Feng Lu758fb8f2014-07-03 18:23:09 +0800355#ifdef HAVE_NETLINK
356/* Socket interface to kernel */
357struct nlsock
358{
359 int sock;
360 int seq;
361 struct sockaddr_nl snl;
362 const char *name;
363};
364#endif
365
paul718e3742002-12-13 20:15:29 +0000366/* Routing table instance. */
Feng Lu41f44a22015-05-22 11:39:56 +0200367struct zebra_vrf
paul718e3742002-12-13 20:15:29 +0000368{
Feng Lu41f44a22015-05-22 11:39:56 +0200369 /* Identifier. */
370 vrf_id_t vrf_id;
paul718e3742002-12-13 20:15:29 +0000371
372 /* Routing table name. */
373 char *name;
374
375 /* Description. */
376 char *desc;
377
378 /* FIB identifier. */
379 u_char fib_id;
380
381 /* Routing table. */
382 struct route_table *table[AFI_MAX][SAFI_MAX];
383
384 /* Static route configuration. */
385 struct route_table *stable[AFI_MAX][SAFI_MAX];
Feng Luac19a442015-05-22 11:40:07 +0200386
Feng Lu758fb8f2014-07-03 18:23:09 +0800387#ifdef HAVE_NETLINK
388 struct nlsock netlink; /* kernel messages */
389 struct nlsock netlink_cmd; /* command channel */
390 struct thread *t_netlink;
391#endif
392
Feng Luac19a442015-05-22 11:40:07 +0200393 /* 2nd pointer type used primarily to quell a warning on
394 * ALL_LIST_ELEMENTS_RO
395 */
396 struct list _rid_all_sorted_list;
397 struct list _rid_lo_sorted_list;
398 struct list *rid_all_sorted_list;
399 struct list *rid_lo_sorted_list;
400 struct prefix rid_user_assigned;
Feng Lu49f76092015-05-22 11:40:10 +0200401
402#if defined (HAVE_IPV6) && defined (RTADV)
403 struct rtadv rtadv;
404#endif /* RTADV && HAVE_IPV6 */
paul718e3742002-12-13 20:15:29 +0000405};
406
Avneesh Sachdev1b5ed1b2012-11-13 22:48:54 +0000407/*
408 * rib_table_info_t
409 *
410 * Structure that is hung off of a route_table that holds information about
411 * the table.
412 */
413typedef struct rib_table_info_t_
414{
415
416 /*
Feng Lu41f44a22015-05-22 11:39:56 +0200417 * Back pointer to zebra_vrf.
Avneesh Sachdev1b5ed1b2012-11-13 22:48:54 +0000418 */
Feng Lu41f44a22015-05-22 11:39:56 +0200419 struct zebra_vrf *zvrf;
Avneesh Sachdev1b5ed1b2012-11-13 22:48:54 +0000420 afi_t afi;
421 safi_t safi;
422
423} rib_table_info_t;
424
Avneesh Sachdev0915bb02012-11-13 22:48:55 +0000425typedef enum
426{
427 RIB_TABLES_ITER_S_INIT,
428 RIB_TABLES_ITER_S_ITERATING,
429 RIB_TABLES_ITER_S_DONE
430} rib_tables_iter_state_t;
431
432/*
433 * Structure that holds state for iterating over all tables in the
434 * Routing Information Base.
435 */
436typedef struct rib_tables_iter_t_
437{
Feng Lu41f44a22015-05-22 11:39:56 +0200438 vrf_id_t vrf_id;
Avneesh Sachdev0915bb02012-11-13 22:48:55 +0000439 int afi_safi_ix;
440
441 rib_tables_iter_state_t state;
442} rib_tables_iter_t;
443
David Lamparterbd078122015-01-06 19:53:24 +0100444/* RPF lookup behaviour */
445enum multicast_mode
446{
447 MCAST_NO_CONFIG = 0, /* MIX_MRIB_FIRST, but no show in config write */
448 MCAST_MRIB_ONLY, /* MRIB only */
449 MCAST_URIB_ONLY, /* URIB only */
450 MCAST_MIX_MRIB_FIRST, /* MRIB, if nothing at all then URIB */
451 MCAST_MIX_DISTANCE, /* MRIB & URIB, lower distance wins */
452 MCAST_MIX_PFXLEN, /* MRIB & URIB, longer prefix wins */
453 /* on equal value, MRIB wins for last 2 */
454};
455
456extern void multicast_mode_ipv4_set (enum multicast_mode mode);
457extern enum multicast_mode multicast_mode_ipv4_get (void);
458
Avneesh Sachdev78deec42012-11-13 22:48:56 +0000459extern const char *nexthop_type_to_str (enum nexthop_types_t nh_type);
paula1ac18c2005-06-28 17:17:12 +0000460extern struct nexthop *nexthop_ifindex_add (struct rib *, unsigned int);
461extern struct nexthop *nexthop_ifname_add (struct rib *, char *);
462extern struct nexthop *nexthop_blackhole_add (struct rib *);
Paul Jakma7514fb72007-05-02 16:05:35 +0000463extern struct nexthop *nexthop_ipv4_add (struct rib *, struct in_addr *,
464 struct in_addr *);
Josh Bailey26e2ae32012-03-22 01:09:21 -0700465extern struct nexthop *nexthop_ipv4_ifindex_add (struct rib *,
466 struct in_addr *,
467 struct in_addr *,
468 unsigned int);
Christian Frankefa713d92013-07-05 15:35:37 +0000469extern int nexthop_has_fib_child(struct nexthop *);
Denis Ovsienkodc958242007-08-13 16:03:06 +0000470extern void rib_lookup_and_dump (struct prefix_ipv4 *);
Denis Ovsienko20e5ff02008-02-26 14:02:24 +0000471extern void rib_lookup_and_pushup (struct prefix_ipv4 *);
David Lamparterf7bf4152013-10-22 17:10:21 +0000472#define rib_dump(prefix ,rib) _rib_dump(__func__, prefix, rib)
473extern void _rib_dump (const char *,
474 union prefix46constptr, const struct rib *);
Feng Lu0d0686f2015-05-22 11:40:02 +0200475extern int rib_lookup_ipv4_route (struct prefix_ipv4 *, union sockunion *,
476 vrf_id_t);
Denis Ovsienkodc958242007-08-13 16:03:06 +0000477#define ZEBRA_RIB_LOOKUP_ERROR -1
478#define ZEBRA_RIB_FOUND_EXACT 0
479#define ZEBRA_RIB_FOUND_NOGATE 1
480#define ZEBRA_RIB_FOUND_CONNECTED 2
481#define ZEBRA_RIB_NOTFOUND 3
482
paul718e3742002-12-13 20:15:29 +0000483#ifdef HAVE_IPV6
paula1ac18c2005-06-28 17:17:12 +0000484extern struct nexthop *nexthop_ipv6_add (struct rib *, struct in6_addr *);
paul718e3742002-12-13 20:15:29 +0000485#endif /* HAVE_IPV6 */
486
Feng Lu41f44a22015-05-22 11:39:56 +0200487extern struct zebra_vrf *zebra_vrf_alloc (vrf_id_t);
488extern struct route_table *zebra_vrf_table (afi_t, safi_t, vrf_id_t);
489extern struct route_table *zebra_vrf_static_table (afi_t, safi_t, vrf_id_t);
paul718e3742002-12-13 20:15:29 +0000490
hassod24af182005-09-24 14:00:26 +0000491/* NOTE:
492 * All rib_add_ipv[46]* functions will not just add prefix into RIB, but
493 * also implicitly withdraw equal prefix of same type. */
paula1ac18c2005-06-28 17:17:12 +0000494extern int rib_add_ipv4 (int type, int flags, struct prefix_ipv4 *p,
Paul Jakma7514fb72007-05-02 16:05:35 +0000495 struct in_addr *gate, struct in_addr *src,
Feng Lu0d0686f2015-05-22 11:40:02 +0200496 unsigned int ifindex, vrf_id_t vrf_id, int table_id,
G.Balajicddf3912011-11-26 21:59:32 +0400497 u_int32_t, u_char, safi_t);
paul718e3742002-12-13 20:15:29 +0000498
G.Balajicddf3912011-11-26 21:59:32 +0400499extern int rib_add_ipv4_multipath (struct prefix_ipv4 *, struct rib *, safi_t);
paul718e3742002-12-13 20:15:29 +0000500
paula1ac18c2005-06-28 17:17:12 +0000501extern int rib_delete_ipv4 (int type, int flags, struct prefix_ipv4 *p,
502 struct in_addr *gate, unsigned int ifindex,
Feng Lu0d0686f2015-05-22 11:40:02 +0200503 vrf_id_t, safi_t safi);
paul718e3742002-12-13 20:15:29 +0000504
David Lamparter24480d42015-01-22 19:09:36 +0100505extern struct rib *rib_match_ipv4_safi (struct in_addr addr, safi_t safi,
Feng Lu0d0686f2015-05-22 11:40:02 +0200506 int skip_bgp, struct route_node **rn_out,
507 vrf_id_t);
David Lamparterbd078122015-01-06 19:53:24 +0100508extern struct rib *rib_match_ipv4_multicast (struct in_addr addr,
Feng Lu0d0686f2015-05-22 11:40:02 +0200509 struct route_node **rn_out,
510 vrf_id_t);
paul718e3742002-12-13 20:15:29 +0000511
Feng Lu0d0686f2015-05-22 11:40:02 +0200512extern struct rib *rib_lookup_ipv4 (struct prefix_ipv4 *, vrf_id_t);
paul718e3742002-12-13 20:15:29 +0000513
Feng Lu0d0686f2015-05-22 11:40:02 +0200514extern void rib_update (vrf_id_t);
paula1ac18c2005-06-28 17:17:12 +0000515extern void rib_weed_tables (void);
516extern void rib_sweep_route (void);
Feng Lu267ceb22015-05-22 11:40:09 +0200517extern void rib_close_table (struct route_table *);
paula1ac18c2005-06-28 17:17:12 +0000518extern void rib_close (void);
519extern void rib_init (void);
Vyacheslav Trushkin2ea1ab12011-12-11 18:48:47 +0400520extern unsigned long rib_score_proto (u_char proto);
paul718e3742002-12-13 20:15:29 +0000521
paula1ac18c2005-06-28 17:17:12 +0000522extern int
Everton Marques33d86db2014-07-14 11:19:00 -0300523static_add_ipv4_safi (safi_t safi, struct prefix *p, struct in_addr *gate,
524 const char *ifname, u_char flags, u_char distance,
Feng Lu0d0686f2015-05-22 11:40:02 +0200525 vrf_id_t vrf_id);
paula1ac18c2005-06-28 17:17:12 +0000526extern int
Everton Marques33d86db2014-07-14 11:19:00 -0300527static_delete_ipv4_safi (safi_t safi, struct prefix *p, struct in_addr *gate,
Feng Lu0d0686f2015-05-22 11:40:02 +0200528 const char *ifname, u_char distance, vrf_id_t vrf_id);
paul718e3742002-12-13 20:15:29 +0000529
530#ifdef HAVE_IPV6
paula1ac18c2005-06-28 17:17:12 +0000531extern int
paul718e3742002-12-13 20:15:29 +0000532rib_add_ipv6 (int type, int flags, struct prefix_ipv6 *p,
Feng Lu0d0686f2015-05-22 11:40:02 +0200533 struct in6_addr *gate, unsigned int ifindex, vrf_id_t vrf_id,
534 int table_id, u_int32_t metric, u_char distance, safi_t safi);
paul718e3742002-12-13 20:15:29 +0000535
paula1ac18c2005-06-28 17:17:12 +0000536extern int
paul718e3742002-12-13 20:15:29 +0000537rib_delete_ipv6 (int type, int flags, struct prefix_ipv6 *p,
Feng Lu0d0686f2015-05-22 11:40:02 +0200538 struct in6_addr *gate, unsigned int ifindex, vrf_id_t vrf_id, safi_t safi);
paul718e3742002-12-13 20:15:29 +0000539
Feng Lu0d0686f2015-05-22 11:40:02 +0200540extern struct rib *rib_lookup_ipv6 (struct in6_addr *, vrf_id_t);
paul718e3742002-12-13 20:15:29 +0000541
Feng Lu0d0686f2015-05-22 11:40:02 +0200542extern struct rib *rib_match_ipv6 (struct in6_addr *, vrf_id_t);
paul718e3742002-12-13 20:15:29 +0000543
544extern struct route_table *rib_table_ipv6;
545
paula1ac18c2005-06-28 17:17:12 +0000546extern int
paul718e3742002-12-13 20:15:29 +0000547static_add_ipv6 (struct prefix *p, u_char type, struct in6_addr *gate,
hasso39db97e2004-10-12 20:50:58 +0000548 const char *ifname, u_char flags, u_char distance,
Feng Lu0d0686f2015-05-22 11:40:02 +0200549 vrf_id_t vrf_id);
paul718e3742002-12-13 20:15:29 +0000550
paula1ac18c2005-06-28 17:17:12 +0000551extern int
paul718e3742002-12-13 20:15:29 +0000552static_delete_ipv6 (struct prefix *p, u_char type, struct in6_addr *gate,
Feng Lu0d0686f2015-05-22 11:40:02 +0200553 const char *ifname, u_char distance, vrf_id_t vrf_id);
paul718e3742002-12-13 20:15:29 +0000554
555#endif /* HAVE_IPV6 */
556
Avneesh Sachdev9fd92e32012-11-13 22:48:53 +0000557extern int rib_gc_dest (struct route_node *rn);
Avneesh Sachdev0915bb02012-11-13 22:48:55 +0000558extern struct route_table *rib_tables_iter_next (rib_tables_iter_t *iter);
Avneesh Sachdev9fd92e32012-11-13 22:48:53 +0000559
560/*
561 * Inline functions.
562 */
563
564/*
Avneesh Sachdev1b5ed1b2012-11-13 22:48:54 +0000565 * rib_table_info
566 */
567static inline rib_table_info_t *
568rib_table_info (struct route_table *table)
569{
570 return (rib_table_info_t *) table->info;
571}
572
573/*
Avneesh Sachdev9fd92e32012-11-13 22:48:53 +0000574 * rib_dest_from_rnode
575 */
576static inline rib_dest_t *
577rib_dest_from_rnode (struct route_node *rn)
578{
579 return (rib_dest_t *) rn->info;
580}
581
582/*
583 * rnode_to_ribs
584 *
585 * Returns a pointer to the list of routes corresponding to the given
586 * route_node.
587 */
588static inline struct rib *
589rnode_to_ribs (struct route_node *rn)
590{
591 rib_dest_t *dest;
592
593 dest = rib_dest_from_rnode (rn);
594 if (!dest)
595 return NULL;
596
597 return dest->routes;
598}
599
600/*
601 * rib_dest_prefix
602 */
603static inline struct prefix *
604rib_dest_prefix (rib_dest_t *dest)
605{
606 return &dest->rnode->p;
607}
608
609/*
610 * rib_dest_af
611 *
612 * Returns the address family that the destination is for.
613 */
614static inline u_char
615rib_dest_af (rib_dest_t *dest)
616{
617 return dest->rnode->p.family;
618}
619
620/*
621 * rib_dest_table
622 */
623static inline struct route_table *
624rib_dest_table (rib_dest_t *dest)
625{
626 return dest->rnode->table;
627}
628
Avneesh Sachdev1b5ed1b2012-11-13 22:48:54 +0000629/*
630 * rib_dest_vrf
631 */
Feng Lu41f44a22015-05-22 11:39:56 +0200632static inline struct zebra_vrf *
Avneesh Sachdev1b5ed1b2012-11-13 22:48:54 +0000633rib_dest_vrf (rib_dest_t *dest)
634{
Feng Lu41f44a22015-05-22 11:39:56 +0200635 return rib_table_info (rib_dest_table (dest))->zvrf;
Avneesh Sachdev1b5ed1b2012-11-13 22:48:54 +0000636}
637
Avneesh Sachdev0915bb02012-11-13 22:48:55 +0000638/*
639 * rib_tables_iter_init
640 */
641static inline void
642rib_tables_iter_init (rib_tables_iter_t *iter)
643
644{
645 memset (iter, 0, sizeof (*iter));
646 iter->state = RIB_TABLES_ITER_S_INIT;
647}
648
649/*
650 * rib_tables_iter_started
651 *
652 * Returns TRUE if this iterator has started iterating over the set of
653 * tables.
654 */
655static inline int
656rib_tables_iter_started (rib_tables_iter_t *iter)
657{
658 return iter->state != RIB_TABLES_ITER_S_INIT;
659}
660
661/*
662 * rib_tables_iter_cleanup
663 */
664static inline void
665rib_tables_iter_cleanup (rib_tables_iter_t *iter)
666{
667 iter->state = RIB_TABLES_ITER_S_DONE;
668}
669
paul718e3742002-12-13 20:15:29 +0000670#endif /*_ZEBRA_RIB_H */