blob: 9773cba8737081d6876cd379dff0fd9250498af5 [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"
Pradosh Mohapatra60cc9592015-11-09 20:21:41 -050030#include "nexthop.h"
paulec1a4282005-11-24 15:15:17 +000031
paul718e3742002-12-13 20:15:29 +000032#define DISTANCE_INFINITY 255
33
paul718e3742002-12-13 20:15:29 +000034struct rib
35{
36 /* Link list. */
37 struct rib *next;
38 struct rib *prev;
Paul Jakmae6d7d052006-03-30 13:32:09 +000039
40 /* Nexthop structure */
41 struct nexthop *nexthop;
42
43 /* Refrence count. */
44 unsigned long refcnt;
45
46 /* Uptime. */
47 time_t uptime;
paul718e3742002-12-13 20:15:29 +000048
49 /* Type fo this route. */
50 int type;
51
Feng Lu0d0686f2015-05-22 11:40:02 +020052 /* VRF identifier. */
53 vrf_id_t vrf_id;
54
paul718e3742002-12-13 20:15:29 +000055 /* Which routing table */
56 int table;
57
Paul Jakmae6d7d052006-03-30 13:32:09 +000058 /* Metric */
59 u_int32_t metric;
60
Timo Teräsb11f3b52015-11-02 16:50:07 +020061 /* MTU */
62 u_int32_t mtu;
63 u_int32_t nexthop_mtu;
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)
Timo Teräs7eb61362015-11-02 16:50:05 +020077#define RIB_ENTRY_CHANGED (1 << 1)
Timo Teräs325823a2016-01-15 17:36:31 +020078#define RIB_ENTRY_SELECTED_FIB (1 << 2)
Paul Jakma6d691122006-07-27 21:49:00 +000079
paul718e3742002-12-13 20:15:29 +000080 /* Nexthop information. */
81 u_char nexthop_num;
82 u_char nexthop_active_num;
83 u_char nexthop_fib_num;
paul718e3742002-12-13 20:15:29 +000084};
85
Denis Ovsienkoe96f9202008-06-02 12:03:22 +000086/* meta-queue structure:
87 * sub-queue 0: connected, kernel
88 * sub-queue 1: static
89 * sub-queue 2: RIP, RIPng, OSPF, OSPF6, IS-IS
90 * sub-queue 3: iBGP, eBGP
91 * sub-queue 4: any other origin (if any)
92 */
93#define MQ_SIZE 5
94struct meta_queue
95{
96 struct list *subq[MQ_SIZE];
97 u_int32_t size; /* sum of lengths of all subqueues */
98};
99
Avneesh Sachdev9fd92e32012-11-13 22:48:53 +0000100/*
101 * Structure that represents a single destination (prefix).
102 */
103typedef struct rib_dest_t_
104{
105
106 /*
107 * Back pointer to the route node for this destination. This helps
108 * us get to the prefix that this structure is for.
109 */
110 struct route_node *rnode;
111
112 /*
113 * Doubly-linked list of routes for this prefix.
114 */
115 struct rib *routes;
116
117 /*
118 * Flags, see below.
119 */
120 u_int32_t flags;
121
Avneesh Sachdev5adc2522012-11-13 22:48:59 +0000122 /*
123 * Linkage to put dest on the FPM processing queue.
124 */
125 TAILQ_ENTRY(rib_dest_t_) fpm_q_entries;
126
Avneesh Sachdev9fd92e32012-11-13 22:48:53 +0000127} rib_dest_t;
128
129#define RIB_ROUTE_QUEUED(x) (1 << (x))
130
131/*
132 * The maximum qindex that can be used.
133 */
134#define ZEBRA_MAX_QINDEX (MQ_SIZE - 1)
135
136/*
Avneesh Sachdev5adc2522012-11-13 22:48:59 +0000137 * This flag indicates that a given prefix has been 'advertised' to
138 * the FPM to be installed in the forwarding plane.
139 */
140#define RIB_DEST_SENT_TO_FPM (1 << (ZEBRA_MAX_QINDEX + 1))
141
142/*
143 * This flag is set when we need to send an update to the FPM about a
144 * dest.
145 */
146#define RIB_DEST_UPDATE_FPM (1 << (ZEBRA_MAX_QINDEX + 2))
147
148/*
Avneesh Sachdev9fd92e32012-11-13 22:48:53 +0000149 * Macro to iterate over each route for a destination (prefix).
150 */
151#define RIB_DEST_FOREACH_ROUTE(dest, rib) \
152 for ((rib) = (dest) ? (dest)->routes : NULL; (rib); (rib) = (rib)->next)
153
154/*
155 * Same as above, but allows the current node to be unlinked.
156 */
157#define RIB_DEST_FOREACH_ROUTE_SAFE(dest, rib, next) \
158 for ((rib) = (dest) ? (dest)->routes : NULL; \
159 (rib) && ((next) = (rib)->next, 1); \
160 (rib) = (next))
161
162#define RNODE_FOREACH_RIB(rn, rib) \
163 RIB_DEST_FOREACH_ROUTE (rib_dest_from_rnode (rn), rib)
164
165#define RNODE_FOREACH_RIB_SAFE(rn, rib, next) \
166 RIB_DEST_FOREACH_ROUTE_SAFE (rib_dest_from_rnode (rn), rib, next)
167
paul718e3742002-12-13 20:15:29 +0000168/* Static route information. */
Donald Sharpd4c27d62015-11-04 13:26:35 -0500169struct static_route
paul718e3742002-12-13 20:15:29 +0000170{
171 /* For linked list. */
Donald Sharpd4c27d62015-11-04 13:26:35 -0500172 struct static_route *prev;
173 struct static_route *next;
paul718e3742002-12-13 20:15:29 +0000174
Feng Lu7aaf4ea2015-05-22 11:40:06 +0200175 /* VRF identifier. */
176 vrf_id_t vrf_id;
177
paul718e3742002-12-13 20:15:29 +0000178 /* Administrative distance. */
179 u_char distance;
180
181 /* Flag for this static route's type. */
182 u_char type;
Donald Sharpd4c27d62015-11-04 13:26:35 -0500183#define STATIC_IPV4_GATEWAY 1
184#define STATIC_IPV4_IFNAME 2
185#define STATIC_IPV4_BLACKHOLE 3
186#define STATIC_IPV6_GATEWAY 4
187#define STATIC_IPV6_GATEWAY_IFNAME 5
188#define STATIC_IPV6_IFNAME 6
paul718e3742002-12-13 20:15:29 +0000189
190 /* Nexthop value. */
Donald Sharpd4c27d62015-11-04 13:26:35 -0500191 union g_addr addr;
paul718e3742002-12-13 20:15:29 +0000192 char *ifname;
hasso81dfcaa2003-05-25 19:21:25 +0000193
194 /* bit flags */
195 u_char flags;
196/*
197 see ZEBRA_FLAG_REJECT
198 ZEBRA_FLAG_BLACKHOLE
199 */
paul718e3742002-12-13 20:15:29 +0000200};
paul718e3742002-12-13 20:15:29 +0000201
Christian Frankefa713d92013-07-05 15:35:37 +0000202/* The following for loop allows to iterate over the nexthop
203 * structure of routes.
204 *
205 * We have to maintain quite a bit of state:
206 *
207 * nexthop: The pointer to the current nexthop, either in the
208 * top-level chain or in the resolved chain of ni.
209 * tnexthop: The pointer to the current nexthop in the top-level
210 * nexthop chain.
211 * recursing: Information if nh currently is in the top-level chain
212 * (0) or in a resolved chain (1).
213 *
214 * Initialization: Set `nexthop' and `tnexthop' to the head of the
215 * top-level chain. As nexthop is in the top level chain, set recursing
216 * to 0.
217 *
218 * Iteration check: Check that the `nexthop' pointer is not NULL.
219 *
220 * Iteration step: This is the tricky part. Check if `nexthop' has
221 * NEXTHOP_FLAG_RECURSIVE set. If yes, this implies that `nexthop' is in
222 * the top level chain and has at least one nexthop attached to
223 * `nexthop->resolved'. As we want to descend into `nexthop->resolved',
224 * set `recursing' to 1 and set `nexthop' to `nexthop->resolved'.
225 * `tnexthop' is left alone in that case so we can remember which nexthop
226 * in the top level chain we are currently handling.
227 *
228 * If NEXTHOP_FLAG_RECURSIVE is not set, `nexthop' will progress in its
229 * current chain. If we are recursing, `nexthop' will be set to
230 * `nexthop->next' and `tnexthop' will be left alone. If we are not
231 * recursing, both `tnexthop' and `nexthop' will be set to `nexthop->next'
232 * as we are progressing in the top level chain.
233 * If we encounter `nexthop->next == NULL', we will clear the `recursing'
234 * flag as we arived either at the end of the resolved chain or at the end
235 * of the top level chain. In both cases, we set `tnexthop' and `nexthop'
236 * to `tnexthop->next', progressing to the next position in the top-level
237 * chain and possibly to its end marked by NULL.
238 */
239#define ALL_NEXTHOPS_RO(head, nexthop, tnexthop, recursing) \
240 (tnexthop) = (nexthop) = (head), (recursing) = 0; \
241 (nexthop); \
242 (nexthop) = CHECK_FLAG((nexthop)->flags, NEXTHOP_FLAG_RECURSIVE) \
243 ? (((recursing) = 1), (nexthop)->resolved) \
244 : ((nexthop)->next ? ((recursing) ? (nexthop)->next \
245 : ((tnexthop) = (nexthop)->next)) \
246 : (((recursing) = 0),((tnexthop) = (tnexthop)->next)))
247
Feng Lu1885d0a2015-05-22 11:40:04 +0200248/* Structure holding nexthop & VRF identifier,
249 * used for applying the route-map. */
250struct nexthop_vrfid
251{
252 struct nexthop *nexthop;
253 vrf_id_t vrf_id;
254};
255
Feng Lu49f76092015-05-22 11:40:10 +0200256
Donald Sharp64257732015-11-20 08:33:30 -0500257#if defined (HAVE_RTADV)
Feng Lu49f76092015-05-22 11:40:10 +0200258/* Structure which hold status of router advertisement. */
259struct rtadv
260{
261 int sock;
262
263 int adv_if_count;
264 int adv_msec_if_count;
265
266 struct thread *ra_read;
267 struct thread *ra_timer;
268};
Donald Sharp64257732015-11-20 08:33:30 -0500269#endif /* HAVE_RTADV */
Feng Lu49f76092015-05-22 11:40:10 +0200270
Feng Lu758fb8f2014-07-03 18:23:09 +0800271#ifdef HAVE_NETLINK
272/* Socket interface to kernel */
273struct nlsock
274{
275 int sock;
276 int seq;
277 struct sockaddr_nl snl;
278 const char *name;
279};
280#endif
281
paul718e3742002-12-13 20:15:29 +0000282/* Routing table instance. */
Feng Lu41f44a22015-05-22 11:39:56 +0200283struct zebra_vrf
paul718e3742002-12-13 20:15:29 +0000284{
Feng Lu41f44a22015-05-22 11:39:56 +0200285 /* Identifier. */
286 vrf_id_t vrf_id;
paul718e3742002-12-13 20:15:29 +0000287
288 /* Routing table name. */
289 char *name;
290
291 /* Description. */
292 char *desc;
293
294 /* FIB identifier. */
295 u_char fib_id;
296
297 /* Routing table. */
298 struct route_table *table[AFI_MAX][SAFI_MAX];
299
300 /* Static route configuration. */
301 struct route_table *stable[AFI_MAX][SAFI_MAX];
Feng Luac19a442015-05-22 11:40:07 +0200302
Feng Lu758fb8f2014-07-03 18:23:09 +0800303#ifdef HAVE_NETLINK
304 struct nlsock netlink; /* kernel messages */
305 struct nlsock netlink_cmd; /* command channel */
306 struct thread *t_netlink;
307#endif
308
Feng Luac19a442015-05-22 11:40:07 +0200309 /* 2nd pointer type used primarily to quell a warning on
310 * ALL_LIST_ELEMENTS_RO
311 */
312 struct list _rid_all_sorted_list;
313 struct list _rid_lo_sorted_list;
314 struct list *rid_all_sorted_list;
315 struct list *rid_lo_sorted_list;
316 struct prefix rid_user_assigned;
Feng Lu49f76092015-05-22 11:40:10 +0200317
Donald Sharp64257732015-11-20 08:33:30 -0500318#if defined (HAVE_RTADV)
Feng Lu49f76092015-05-22 11:40:10 +0200319 struct rtadv rtadv;
Donald Sharp64257732015-11-20 08:33:30 -0500320#endif /* HAVE_RTADV */
Pradosh Mohapatra60cc9592015-11-09 20:21:41 -0500321
322 /* Recursive Nexthop table */
323 struct route_table *rnh_table[AFI_MAX];
paul718e3742002-12-13 20:15:29 +0000324};
325
Avneesh Sachdev1b5ed1b2012-11-13 22:48:54 +0000326/*
327 * rib_table_info_t
328 *
329 * Structure that is hung off of a route_table that holds information about
330 * the table.
331 */
332typedef struct rib_table_info_t_
333{
334
335 /*
Feng Lu41f44a22015-05-22 11:39:56 +0200336 * Back pointer to zebra_vrf.
Avneesh Sachdev1b5ed1b2012-11-13 22:48:54 +0000337 */
Feng Lu41f44a22015-05-22 11:39:56 +0200338 struct zebra_vrf *zvrf;
Avneesh Sachdev1b5ed1b2012-11-13 22:48:54 +0000339 afi_t afi;
340 safi_t safi;
341
342} rib_table_info_t;
343
Avneesh Sachdev0915bb02012-11-13 22:48:55 +0000344typedef enum
345{
346 RIB_TABLES_ITER_S_INIT,
347 RIB_TABLES_ITER_S_ITERATING,
348 RIB_TABLES_ITER_S_DONE
349} rib_tables_iter_state_t;
350
351/*
352 * Structure that holds state for iterating over all tables in the
353 * Routing Information Base.
354 */
355typedef struct rib_tables_iter_t_
356{
Feng Lu41f44a22015-05-22 11:39:56 +0200357 vrf_id_t vrf_id;
Avneesh Sachdev0915bb02012-11-13 22:48:55 +0000358 int afi_safi_ix;
359
360 rib_tables_iter_state_t state;
361} rib_tables_iter_t;
362
David Lamparterbd078122015-01-06 19:53:24 +0100363/* RPF lookup behaviour */
364enum multicast_mode
365{
366 MCAST_NO_CONFIG = 0, /* MIX_MRIB_FIRST, but no show in config write */
367 MCAST_MRIB_ONLY, /* MRIB only */
368 MCAST_URIB_ONLY, /* URIB only */
369 MCAST_MIX_MRIB_FIRST, /* MRIB, if nothing at all then URIB */
370 MCAST_MIX_DISTANCE, /* MRIB & URIB, lower distance wins */
371 MCAST_MIX_PFXLEN, /* MRIB & URIB, longer prefix wins */
372 /* on equal value, MRIB wins for last 2 */
373};
374
375extern void multicast_mode_ipv4_set (enum multicast_mode mode);
376extern enum multicast_mode multicast_mode_ipv4_get (void);
377
Avneesh Sachdev78deec42012-11-13 22:48:56 +0000378extern const char *nexthop_type_to_str (enum nexthop_types_t nh_type);
Pradosh Mohapatra60cc9592015-11-09 20:21:41 -0500379extern struct nexthop *rib_nexthop_ifindex_add (struct rib *, ifindex_t);
380extern struct nexthop *rib_nexthop_ifname_add (struct rib *, char *);
381extern struct nexthop *rib_nexthop_blackhole_add (struct rib *);
382extern struct nexthop *rib_nexthop_ipv4_add (struct rib *, struct in_addr *,
383 struct in_addr *);
384extern struct nexthop *rib_nexthop_ipv4_ifindex_add (struct rib *,
385 struct in_addr *,
386 struct in_addr *,
387 ifindex_t);
388
389extern void rib_nexthop_add (struct rib *rib, struct nexthop *nexthop);
390
Christian Frankefa713d92013-07-05 15:35:37 +0000391extern int nexthop_has_fib_child(struct nexthop *);
Denis Ovsienkodc958242007-08-13 16:03:06 +0000392extern void rib_lookup_and_dump (struct prefix_ipv4 *);
David Lamparterf7bf4152013-10-22 17:10:21 +0000393#define rib_dump(prefix ,rib) _rib_dump(__func__, prefix, rib)
394extern void _rib_dump (const char *,
395 union prefix46constptr, const struct rib *);
Feng Lu0d0686f2015-05-22 11:40:02 +0200396extern int rib_lookup_ipv4_route (struct prefix_ipv4 *, union sockunion *,
397 vrf_id_t);
Denis Ovsienkodc958242007-08-13 16:03:06 +0000398#define ZEBRA_RIB_LOOKUP_ERROR -1
399#define ZEBRA_RIB_FOUND_EXACT 0
400#define ZEBRA_RIB_FOUND_NOGATE 1
401#define ZEBRA_RIB_FOUND_CONNECTED 2
402#define ZEBRA_RIB_NOTFOUND 3
403
Pradosh Mohapatra60cc9592015-11-09 20:21:41 -0500404extern struct nexthop *rib_nexthop_ipv6_add (struct rib *, struct in6_addr *);
405extern struct nexthop *rib_nexthop_ipv6_ifindex_add (struct rib *,
406 struct in6_addr *,
407 ifindex_t);
paul718e3742002-12-13 20:15:29 +0000408
Pradosh Mohapatra60cc9592015-11-09 20:21:41 -0500409extern struct zebra_vrf *zebra_vrf_lookup (vrf_id_t vrf_id);
Feng Lu41f44a22015-05-22 11:39:56 +0200410extern struct zebra_vrf *zebra_vrf_alloc (vrf_id_t);
411extern struct route_table *zebra_vrf_table (afi_t, safi_t, vrf_id_t);
412extern struct route_table *zebra_vrf_static_table (afi_t, safi_t, vrf_id_t);
paul718e3742002-12-13 20:15:29 +0000413
hassod24af182005-09-24 14:00:26 +0000414/* NOTE:
415 * All rib_add_ipv[46]* functions will not just add prefix into RIB, but
416 * also implicitly withdraw equal prefix of same type. */
paula1ac18c2005-06-28 17:17:12 +0000417extern int rib_add_ipv4 (int type, int flags, struct prefix_ipv4 *p,
Paul Jakma7514fb72007-05-02 16:05:35 +0000418 struct in_addr *gate, struct in_addr *src,
Paul Jakma9099f9b2016-01-18 10:12:10 +0000419 ifindex_t ifindex, vrf_id_t vrf_id, int table_id,
Timo Teräsb11f3b52015-11-02 16:50:07 +0200420 u_int32_t, u_int32_t, u_char, safi_t);
paul718e3742002-12-13 20:15:29 +0000421
G.Balajicddf3912011-11-26 21:59:32 +0400422extern int rib_add_ipv4_multipath (struct prefix_ipv4 *, struct rib *, safi_t);
paul718e3742002-12-13 20:15:29 +0000423
paula1ac18c2005-06-28 17:17:12 +0000424extern int rib_delete_ipv4 (int type, int flags, struct prefix_ipv4 *p,
Paul Jakma9099f9b2016-01-18 10:12:10 +0000425 struct in_addr *gate, ifindex_t ifindex,
Feng Lu0d0686f2015-05-22 11:40:02 +0200426 vrf_id_t, safi_t safi);
paul718e3742002-12-13 20:15:29 +0000427
David Lamparter24480d42015-01-22 19:09:36 +0100428extern struct rib *rib_match_ipv4_safi (struct in_addr addr, safi_t safi,
Feng Lu0d0686f2015-05-22 11:40:02 +0200429 int skip_bgp, struct route_node **rn_out,
430 vrf_id_t);
David Lamparterbd078122015-01-06 19:53:24 +0100431extern struct rib *rib_match_ipv4_multicast (struct in_addr addr,
Feng Lu0d0686f2015-05-22 11:40:02 +0200432 struct route_node **rn_out,
433 vrf_id_t);
paul718e3742002-12-13 20:15:29 +0000434
Feng Lu0d0686f2015-05-22 11:40:02 +0200435extern struct rib *rib_lookup_ipv4 (struct prefix_ipv4 *, vrf_id_t);
paul718e3742002-12-13 20:15:29 +0000436
Feng Lu0d0686f2015-05-22 11:40:02 +0200437extern void rib_update (vrf_id_t);
paula1ac18c2005-06-28 17:17:12 +0000438extern void rib_weed_tables (void);
439extern void rib_sweep_route (void);
Feng Lu267ceb22015-05-22 11:40:09 +0200440extern void rib_close_table (struct route_table *);
paula1ac18c2005-06-28 17:17:12 +0000441extern void rib_close (void);
442extern void rib_init (void);
Vyacheslav Trushkin2ea1ab12011-12-11 18:48:47 +0400443extern unsigned long rib_score_proto (u_char proto);
paul718e3742002-12-13 20:15:29 +0000444
paula1ac18c2005-06-28 17:17:12 +0000445extern int
Everton Marques33d86db2014-07-14 11:19:00 -0300446static_add_ipv4_safi (safi_t safi, struct prefix *p, struct in_addr *gate,
447 const char *ifname, u_char flags, u_char distance,
Feng Lu0d0686f2015-05-22 11:40:02 +0200448 vrf_id_t vrf_id);
paula1ac18c2005-06-28 17:17:12 +0000449extern int
Everton Marques33d86db2014-07-14 11:19:00 -0300450static_delete_ipv4_safi (safi_t safi, struct prefix *p, struct in_addr *gate,
Feng Lu0d0686f2015-05-22 11:40:02 +0200451 const char *ifname, u_char distance, vrf_id_t vrf_id);
paul718e3742002-12-13 20:15:29 +0000452
paula1ac18c2005-06-28 17:17:12 +0000453extern int
paul718e3742002-12-13 20:15:29 +0000454rib_add_ipv6 (int type, int flags, struct prefix_ipv6 *p,
Paul Jakma9099f9b2016-01-18 10:12:10 +0000455 struct in6_addr *gate, ifindex_t ifindex, vrf_id_t vrf_id,
Timo Teräsb11f3b52015-11-02 16:50:07 +0200456 int table_id, u_int32_t metric, u_int32_t mtu,
457 u_char distance, safi_t safi);
paul718e3742002-12-13 20:15:29 +0000458
paula1ac18c2005-06-28 17:17:12 +0000459extern int
paul718e3742002-12-13 20:15:29 +0000460rib_delete_ipv6 (int type, int flags, struct prefix_ipv6 *p,
Paul Jakma9099f9b2016-01-18 10:12:10 +0000461 struct in6_addr *gate, ifindex_t ifindex, vrf_id_t vrf_id, safi_t safi);
paul718e3742002-12-13 20:15:29 +0000462
Feng Lu0d0686f2015-05-22 11:40:02 +0200463extern struct rib *rib_lookup_ipv6 (struct in6_addr *, vrf_id_t);
paul718e3742002-12-13 20:15:29 +0000464
Feng Lu0d0686f2015-05-22 11:40:02 +0200465extern struct rib *rib_match_ipv6 (struct in6_addr *, vrf_id_t);
paul718e3742002-12-13 20:15:29 +0000466
467extern struct route_table *rib_table_ipv6;
468
paula1ac18c2005-06-28 17:17:12 +0000469extern int
paul718e3742002-12-13 20:15:29 +0000470static_add_ipv6 (struct prefix *p, u_char type, struct in6_addr *gate,
hasso39db97e2004-10-12 20:50:58 +0000471 const char *ifname, u_char flags, u_char distance,
Feng Lu0d0686f2015-05-22 11:40:02 +0200472 vrf_id_t vrf_id);
paul718e3742002-12-13 20:15:29 +0000473
paula1ac18c2005-06-28 17:17:12 +0000474extern int
Ayan Banerjee34c5d892015-11-09 20:14:53 -0500475rib_add_ipv6_multipath (struct prefix_ipv6 *, struct rib *, safi_t);
476
477extern int
paul718e3742002-12-13 20:15:29 +0000478static_delete_ipv6 (struct prefix *p, u_char type, struct in6_addr *gate,
Feng Lu0d0686f2015-05-22 11:40:02 +0200479 const char *ifname, u_char distance, vrf_id_t vrf_id);
paul718e3742002-12-13 20:15:29 +0000480
Avneesh Sachdev9fd92e32012-11-13 22:48:53 +0000481extern int rib_gc_dest (struct route_node *rn);
Avneesh Sachdev0915bb02012-11-13 22:48:55 +0000482extern struct route_table *rib_tables_iter_next (rib_tables_iter_t *iter);
Avneesh Sachdev9fd92e32012-11-13 22:48:53 +0000483
484/*
485 * Inline functions.
486 */
487
488/*
Avneesh Sachdev1b5ed1b2012-11-13 22:48:54 +0000489 * rib_table_info
490 */
491static inline rib_table_info_t *
492rib_table_info (struct route_table *table)
493{
494 return (rib_table_info_t *) table->info;
495}
496
497/*
Avneesh Sachdev9fd92e32012-11-13 22:48:53 +0000498 * rib_dest_from_rnode
499 */
500static inline rib_dest_t *
501rib_dest_from_rnode (struct route_node *rn)
502{
503 return (rib_dest_t *) rn->info;
504}
505
506/*
507 * rnode_to_ribs
508 *
509 * Returns a pointer to the list of routes corresponding to the given
510 * route_node.
511 */
512static inline struct rib *
513rnode_to_ribs (struct route_node *rn)
514{
515 rib_dest_t *dest;
516
517 dest = rib_dest_from_rnode (rn);
518 if (!dest)
519 return NULL;
520
521 return dest->routes;
522}
523
524/*
525 * rib_dest_prefix
526 */
527static inline struct prefix *
528rib_dest_prefix (rib_dest_t *dest)
529{
530 return &dest->rnode->p;
531}
532
533/*
534 * rib_dest_af
535 *
536 * Returns the address family that the destination is for.
537 */
538static inline u_char
539rib_dest_af (rib_dest_t *dest)
540{
541 return dest->rnode->p.family;
542}
543
544/*
545 * rib_dest_table
546 */
547static inline struct route_table *
548rib_dest_table (rib_dest_t *dest)
549{
550 return dest->rnode->table;
551}
552
Avneesh Sachdev1b5ed1b2012-11-13 22:48:54 +0000553/*
554 * rib_dest_vrf
555 */
Feng Lu41f44a22015-05-22 11:39:56 +0200556static inline struct zebra_vrf *
Avneesh Sachdev1b5ed1b2012-11-13 22:48:54 +0000557rib_dest_vrf (rib_dest_t *dest)
558{
Feng Lu41f44a22015-05-22 11:39:56 +0200559 return rib_table_info (rib_dest_table (dest))->zvrf;
Avneesh Sachdev1b5ed1b2012-11-13 22:48:54 +0000560}
561
Avneesh Sachdev0915bb02012-11-13 22:48:55 +0000562/*
563 * rib_tables_iter_init
564 */
565static inline void
566rib_tables_iter_init (rib_tables_iter_t *iter)
567
568{
569 memset (iter, 0, sizeof (*iter));
570 iter->state = RIB_TABLES_ITER_S_INIT;
571}
572
573/*
574 * rib_tables_iter_started
575 *
576 * Returns TRUE if this iterator has started iterating over the set of
577 * tables.
578 */
579static inline int
580rib_tables_iter_started (rib_tables_iter_t *iter)
581{
582 return iter->state != RIB_TABLES_ITER_S_INIT;
583}
584
585/*
586 * rib_tables_iter_cleanup
587 */
588static inline void
589rib_tables_iter_cleanup (rib_tables_iter_t *iter)
590{
591 iter->state = RIB_TABLES_ITER_S_DONE;
592}
593
paul718e3742002-12-13 20:15:29 +0000594#endif /*_ZEBRA_RIB_H */