blob: d31db557950b5e35c4342085edd75b2c23f2de42 [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
Piotr Chytłade24f822007-06-28 00:09:28 +020068 /* Tag */
69 u_short tag;
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)
Timo Teräs7eb61362015-11-02 16:50:05 +020080#define RIB_ENTRY_CHANGED (1 << 1)
Timo Teräs325823a2016-01-15 17:36:31 +020081#define RIB_ENTRY_SELECTED_FIB (1 << 2)
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. */
Donald Sharpd4c27d62015-11-04 13:26:35 -0500172struct static_route
paul718e3742002-12-13 20:15:29 +0000173{
174 /* For linked list. */
Donald Sharpd4c27d62015-11-04 13:26:35 -0500175 struct static_route *prev;
176 struct static_route *next;
paul718e3742002-12-13 20:15:29 +0000177
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
Piotr Chytłade24f822007-06-28 00:09:28 +0200184 /* Tag */
185 u_short tag;
186
paul718e3742002-12-13 20:15:29 +0000187 /* Flag for this static route's type. */
188 u_char type;
Donald Sharpd4c27d62015-11-04 13:26:35 -0500189#define STATIC_IPV4_GATEWAY 1
190#define STATIC_IPV4_IFNAME 2
191#define STATIC_IPV4_BLACKHOLE 3
192#define STATIC_IPV6_GATEWAY 4
193#define STATIC_IPV6_GATEWAY_IFNAME 5
194#define STATIC_IPV6_IFNAME 6
paul718e3742002-12-13 20:15:29 +0000195
196 /* Nexthop value. */
Donald Sharpd4c27d62015-11-04 13:26:35 -0500197 union g_addr addr;
paul718e3742002-12-13 20:15:29 +0000198 char *ifname;
hasso81dfcaa2003-05-25 19:21:25 +0000199
200 /* bit flags */
201 u_char flags;
202/*
203 see ZEBRA_FLAG_REJECT
204 ZEBRA_FLAG_BLACKHOLE
205 */
paul718e3742002-12-13 20:15:29 +0000206};
paul718e3742002-12-13 20:15:29 +0000207
Christian Frankefa713d92013-07-05 15:35:37 +0000208/* The following for loop allows to iterate over the nexthop
209 * structure of routes.
210 *
211 * We have to maintain quite a bit of state:
212 *
213 * nexthop: The pointer to the current nexthop, either in the
214 * top-level chain or in the resolved chain of ni.
215 * tnexthop: The pointer to the current nexthop in the top-level
216 * nexthop chain.
217 * recursing: Information if nh currently is in the top-level chain
218 * (0) or in a resolved chain (1).
219 *
220 * Initialization: Set `nexthop' and `tnexthop' to the head of the
221 * top-level chain. As nexthop is in the top level chain, set recursing
222 * to 0.
223 *
224 * Iteration check: Check that the `nexthop' pointer is not NULL.
225 *
226 * Iteration step: This is the tricky part. Check if `nexthop' has
227 * NEXTHOP_FLAG_RECURSIVE set. If yes, this implies that `nexthop' is in
228 * the top level chain and has at least one nexthop attached to
229 * `nexthop->resolved'. As we want to descend into `nexthop->resolved',
230 * set `recursing' to 1 and set `nexthop' to `nexthop->resolved'.
231 * `tnexthop' is left alone in that case so we can remember which nexthop
232 * in the top level chain we are currently handling.
233 *
234 * If NEXTHOP_FLAG_RECURSIVE is not set, `nexthop' will progress in its
235 * current chain. If we are recursing, `nexthop' will be set to
236 * `nexthop->next' and `tnexthop' will be left alone. If we are not
237 * recursing, both `tnexthop' and `nexthop' will be set to `nexthop->next'
238 * as we are progressing in the top level chain.
239 * If we encounter `nexthop->next == NULL', we will clear the `recursing'
240 * flag as we arived either at the end of the resolved chain or at the end
241 * of the top level chain. In both cases, we set `tnexthop' and `nexthop'
242 * to `tnexthop->next', progressing to the next position in the top-level
243 * chain and possibly to its end marked by NULL.
244 */
245#define ALL_NEXTHOPS_RO(head, nexthop, tnexthop, recursing) \
246 (tnexthop) = (nexthop) = (head), (recursing) = 0; \
247 (nexthop); \
248 (nexthop) = CHECK_FLAG((nexthop)->flags, NEXTHOP_FLAG_RECURSIVE) \
249 ? (((recursing) = 1), (nexthop)->resolved) \
250 : ((nexthop)->next ? ((recursing) ? (nexthop)->next \
251 : ((tnexthop) = (nexthop)->next)) \
252 : (((recursing) = 0),((tnexthop) = (tnexthop)->next)))
253
Feng Lu1885d0a2015-05-22 11:40:04 +0200254/* Structure holding nexthop & VRF identifier,
255 * used for applying the route-map. */
256struct nexthop_vrfid
257{
258 struct nexthop *nexthop;
259 vrf_id_t vrf_id;
260};
261
Feng Lu49f76092015-05-22 11:40:10 +0200262
Donald Sharp64257732015-11-20 08:33:30 -0500263#if defined (HAVE_RTADV)
Feng Lu49f76092015-05-22 11:40:10 +0200264/* Structure which hold status of router advertisement. */
265struct rtadv
266{
267 int sock;
268
269 int adv_if_count;
270 int adv_msec_if_count;
271
272 struct thread *ra_read;
273 struct thread *ra_timer;
274};
Donald Sharp64257732015-11-20 08:33:30 -0500275#endif /* HAVE_RTADV */
Feng Lu49f76092015-05-22 11:40:10 +0200276
Feng Lu758fb8f2014-07-03 18:23:09 +0800277#ifdef HAVE_NETLINK
278/* Socket interface to kernel */
279struct nlsock
280{
281 int sock;
282 int seq;
283 struct sockaddr_nl snl;
284 const char *name;
285};
286#endif
287
paul718e3742002-12-13 20:15:29 +0000288/* Routing table instance. */
Feng Lu41f44a22015-05-22 11:39:56 +0200289struct zebra_vrf
paul718e3742002-12-13 20:15:29 +0000290{
Feng Lu41f44a22015-05-22 11:39:56 +0200291 /* Identifier. */
292 vrf_id_t vrf_id;
paul718e3742002-12-13 20:15:29 +0000293
294 /* Routing table name. */
295 char *name;
296
297 /* Description. */
298 char *desc;
299
300 /* FIB identifier. */
301 u_char fib_id;
302
303 /* Routing table. */
304 struct route_table *table[AFI_MAX][SAFI_MAX];
305
306 /* Static route configuration. */
307 struct route_table *stable[AFI_MAX][SAFI_MAX];
Feng Luac19a442015-05-22 11:40:07 +0200308
Feng Lu758fb8f2014-07-03 18:23:09 +0800309#ifdef HAVE_NETLINK
310 struct nlsock netlink; /* kernel messages */
311 struct nlsock netlink_cmd; /* command channel */
312 struct thread *t_netlink;
313#endif
314
Feng Luac19a442015-05-22 11:40:07 +0200315 /* 2nd pointer type used primarily to quell a warning on
316 * ALL_LIST_ELEMENTS_RO
317 */
318 struct list _rid_all_sorted_list;
319 struct list _rid_lo_sorted_list;
320 struct list *rid_all_sorted_list;
321 struct list *rid_lo_sorted_list;
322 struct prefix rid_user_assigned;
Feng Lu49f76092015-05-22 11:40:10 +0200323
Donald Sharp64257732015-11-20 08:33:30 -0500324#if defined (HAVE_RTADV)
Feng Lu49f76092015-05-22 11:40:10 +0200325 struct rtadv rtadv;
Donald Sharp64257732015-11-20 08:33:30 -0500326#endif /* HAVE_RTADV */
Pradosh Mohapatra60cc9592015-11-09 20:21:41 -0500327
328 /* Recursive Nexthop table */
329 struct route_table *rnh_table[AFI_MAX];
paul718e3742002-12-13 20:15:29 +0000330};
331
Avneesh Sachdev1b5ed1b2012-11-13 22:48:54 +0000332/*
333 * rib_table_info_t
334 *
335 * Structure that is hung off of a route_table that holds information about
336 * the table.
337 */
338typedef struct rib_table_info_t_
339{
340
341 /*
Feng Lu41f44a22015-05-22 11:39:56 +0200342 * Back pointer to zebra_vrf.
Avneesh Sachdev1b5ed1b2012-11-13 22:48:54 +0000343 */
Feng Lu41f44a22015-05-22 11:39:56 +0200344 struct zebra_vrf *zvrf;
Avneesh Sachdev1b5ed1b2012-11-13 22:48:54 +0000345 afi_t afi;
346 safi_t safi;
347
348} rib_table_info_t;
349
Avneesh Sachdev0915bb02012-11-13 22:48:55 +0000350typedef enum
351{
352 RIB_TABLES_ITER_S_INIT,
353 RIB_TABLES_ITER_S_ITERATING,
354 RIB_TABLES_ITER_S_DONE
355} rib_tables_iter_state_t;
356
357/*
358 * Structure that holds state for iterating over all tables in the
359 * Routing Information Base.
360 */
361typedef struct rib_tables_iter_t_
362{
Feng Lu41f44a22015-05-22 11:39:56 +0200363 vrf_id_t vrf_id;
Avneesh Sachdev0915bb02012-11-13 22:48:55 +0000364 int afi_safi_ix;
365
366 rib_tables_iter_state_t state;
367} rib_tables_iter_t;
368
David Lamparterbd078122015-01-06 19:53:24 +0100369/* RPF lookup behaviour */
370enum multicast_mode
371{
372 MCAST_NO_CONFIG = 0, /* MIX_MRIB_FIRST, but no show in config write */
373 MCAST_MRIB_ONLY, /* MRIB only */
374 MCAST_URIB_ONLY, /* URIB only */
375 MCAST_MIX_MRIB_FIRST, /* MRIB, if nothing at all then URIB */
376 MCAST_MIX_DISTANCE, /* MRIB & URIB, lower distance wins */
377 MCAST_MIX_PFXLEN, /* MRIB & URIB, longer prefix wins */
378 /* on equal value, MRIB wins for last 2 */
379};
380
381extern void multicast_mode_ipv4_set (enum multicast_mode mode);
382extern enum multicast_mode multicast_mode_ipv4_get (void);
383
Avneesh Sachdev78deec42012-11-13 22:48:56 +0000384extern const char *nexthop_type_to_str (enum nexthop_types_t nh_type);
Pradosh Mohapatra60cc9592015-11-09 20:21:41 -0500385extern struct nexthop *rib_nexthop_ifindex_add (struct rib *, ifindex_t);
386extern struct nexthop *rib_nexthop_ifname_add (struct rib *, char *);
387extern struct nexthop *rib_nexthop_blackhole_add (struct rib *);
388extern struct nexthop *rib_nexthop_ipv4_add (struct rib *, struct in_addr *,
389 struct in_addr *);
390extern struct nexthop *rib_nexthop_ipv4_ifindex_add (struct rib *,
391 struct in_addr *,
392 struct in_addr *,
393 ifindex_t);
394
395extern void rib_nexthop_add (struct rib *rib, struct nexthop *nexthop);
396
Christian Frankefa713d92013-07-05 15:35:37 +0000397extern int nexthop_has_fib_child(struct nexthop *);
Denis Ovsienkodc958242007-08-13 16:03:06 +0000398extern void rib_lookup_and_dump (struct prefix_ipv4 *);
David Lamparterf7bf4152013-10-22 17:10:21 +0000399#define rib_dump(prefix ,rib) _rib_dump(__func__, prefix, rib)
400extern void _rib_dump (const char *,
401 union prefix46constptr, const struct rib *);
Feng Lu0d0686f2015-05-22 11:40:02 +0200402extern int rib_lookup_ipv4_route (struct prefix_ipv4 *, union sockunion *,
403 vrf_id_t);
Denis Ovsienkodc958242007-08-13 16:03:06 +0000404#define ZEBRA_RIB_LOOKUP_ERROR -1
405#define ZEBRA_RIB_FOUND_EXACT 0
406#define ZEBRA_RIB_FOUND_NOGATE 1
407#define ZEBRA_RIB_FOUND_CONNECTED 2
408#define ZEBRA_RIB_NOTFOUND 3
409
Pradosh Mohapatra60cc9592015-11-09 20:21:41 -0500410extern struct nexthop *rib_nexthop_ipv6_add (struct rib *, struct in6_addr *);
411extern struct nexthop *rib_nexthop_ipv6_ifindex_add (struct rib *,
412 struct in6_addr *,
413 ifindex_t);
paul718e3742002-12-13 20:15:29 +0000414
Pradosh Mohapatra60cc9592015-11-09 20:21:41 -0500415extern struct zebra_vrf *zebra_vrf_lookup (vrf_id_t vrf_id);
Feng Lu41f44a22015-05-22 11:39:56 +0200416extern struct zebra_vrf *zebra_vrf_alloc (vrf_id_t);
417extern struct route_table *zebra_vrf_table (afi_t, safi_t, vrf_id_t);
418extern struct route_table *zebra_vrf_static_table (afi_t, safi_t, vrf_id_t);
paul718e3742002-12-13 20:15:29 +0000419
hassod24af182005-09-24 14:00:26 +0000420/* NOTE:
421 * All rib_add_ipv[46]* functions will not just add prefix into RIB, but
422 * also implicitly withdraw equal prefix of same type. */
paula1ac18c2005-06-28 17:17:12 +0000423extern int rib_add_ipv4 (int type, int flags, struct prefix_ipv4 *p,
Paul Jakma7514fb72007-05-02 16:05:35 +0000424 struct in_addr *gate, struct in_addr *src,
Paul Jakma9099f9b2016-01-18 10:12:10 +0000425 ifindex_t ifindex, vrf_id_t vrf_id, int table_id,
Timo Teräsb11f3b52015-11-02 16:50:07 +0200426 u_int32_t, u_int32_t, u_char, safi_t);
paul718e3742002-12-13 20:15:29 +0000427
G.Balajicddf3912011-11-26 21:59:32 +0400428extern int rib_add_ipv4_multipath (struct prefix_ipv4 *, struct rib *, safi_t);
paul718e3742002-12-13 20:15:29 +0000429
paula1ac18c2005-06-28 17:17:12 +0000430extern int rib_delete_ipv4 (int type, int flags, struct prefix_ipv4 *p,
Paul Jakma9099f9b2016-01-18 10:12:10 +0000431 struct in_addr *gate, ifindex_t ifindex,
Feng Lu0d0686f2015-05-22 11:40:02 +0200432 vrf_id_t, safi_t safi);
paul718e3742002-12-13 20:15:29 +0000433
David Lamparter24480d42015-01-22 19:09:36 +0100434extern struct rib *rib_match_ipv4_safi (struct in_addr addr, safi_t safi,
Feng Lu0d0686f2015-05-22 11:40:02 +0200435 int skip_bgp, struct route_node **rn_out,
436 vrf_id_t);
David Lamparterbd078122015-01-06 19:53:24 +0100437extern struct rib *rib_match_ipv4_multicast (struct in_addr addr,
Feng Lu0d0686f2015-05-22 11:40:02 +0200438 struct route_node **rn_out,
439 vrf_id_t);
paul718e3742002-12-13 20:15:29 +0000440
Feng Lu0d0686f2015-05-22 11:40:02 +0200441extern struct rib *rib_lookup_ipv4 (struct prefix_ipv4 *, vrf_id_t);
paul718e3742002-12-13 20:15:29 +0000442
Feng Lu0d0686f2015-05-22 11:40:02 +0200443extern void rib_update (vrf_id_t);
paula1ac18c2005-06-28 17:17:12 +0000444extern void rib_weed_tables (void);
445extern void rib_sweep_route (void);
Feng Lu267ceb22015-05-22 11:40:09 +0200446extern void rib_close_table (struct route_table *);
paula1ac18c2005-06-28 17:17:12 +0000447extern void rib_close (void);
448extern void rib_init (void);
Vyacheslav Trushkin2ea1ab12011-12-11 18:48:47 +0400449extern unsigned long rib_score_proto (u_char proto);
paul718e3742002-12-13 20:15:29 +0000450
paula1ac18c2005-06-28 17:17:12 +0000451extern int
Everton Marques33d86db2014-07-14 11:19:00 -0300452static_add_ipv4_safi (safi_t safi, struct prefix *p, struct in_addr *gate,
Piotr Chytłade24f822007-06-28 00:09:28 +0200453 const char *ifname, u_char flags, u_short tag, u_char distance,
Feng Lu0d0686f2015-05-22 11:40:02 +0200454 vrf_id_t vrf_id);
paula1ac18c2005-06-28 17:17:12 +0000455extern int
Everton Marques33d86db2014-07-14 11:19:00 -0300456static_delete_ipv4_safi (safi_t safi, struct prefix *p, struct in_addr *gate,
Piotr Chytłade24f822007-06-28 00:09:28 +0200457 const char *ifname, u_short tag, u_char distance, vrf_id_t vrf_id);
paul718e3742002-12-13 20:15:29 +0000458
paula1ac18c2005-06-28 17:17:12 +0000459extern int
paul718e3742002-12-13 20:15:29 +0000460rib_add_ipv6 (int type, int flags, struct prefix_ipv6 *p,
Paul Jakma9099f9b2016-01-18 10:12:10 +0000461 struct in6_addr *gate, ifindex_t ifindex, vrf_id_t vrf_id,
Timo Teräsb11f3b52015-11-02 16:50:07 +0200462 int table_id, u_int32_t metric, u_int32_t mtu,
463 u_char distance, safi_t safi);
paul718e3742002-12-13 20:15:29 +0000464
paula1ac18c2005-06-28 17:17:12 +0000465extern int
paul718e3742002-12-13 20:15:29 +0000466rib_delete_ipv6 (int type, int flags, struct prefix_ipv6 *p,
Paul Jakma9099f9b2016-01-18 10:12:10 +0000467 struct in6_addr *gate, ifindex_t ifindex, vrf_id_t vrf_id, safi_t safi);
paul718e3742002-12-13 20:15:29 +0000468
Feng Lu0d0686f2015-05-22 11:40:02 +0200469extern struct rib *rib_lookup_ipv6 (struct in6_addr *, vrf_id_t);
paul718e3742002-12-13 20:15:29 +0000470
Feng Lu0d0686f2015-05-22 11:40:02 +0200471extern struct rib *rib_match_ipv6 (struct in6_addr *, vrf_id_t);
paul718e3742002-12-13 20:15:29 +0000472
473extern struct route_table *rib_table_ipv6;
474
paula1ac18c2005-06-28 17:17:12 +0000475extern int
paul718e3742002-12-13 20:15:29 +0000476static_add_ipv6 (struct prefix *p, u_char type, struct in6_addr *gate,
Piotr Chytłade24f822007-06-28 00:09:28 +0200477 const char *ifname, u_char flags, u_short tag, u_char distance,
Feng Lu0d0686f2015-05-22 11:40:02 +0200478 vrf_id_t vrf_id);
paul718e3742002-12-13 20:15:29 +0000479
paula1ac18c2005-06-28 17:17:12 +0000480extern int
Ayan Banerjee34c5d892015-11-09 20:14:53 -0500481rib_add_ipv6_multipath (struct prefix_ipv6 *, struct rib *, safi_t);
482
483extern int
paul718e3742002-12-13 20:15:29 +0000484static_delete_ipv6 (struct prefix *p, u_char type, struct in6_addr *gate,
Piotr Chytłade24f822007-06-28 00:09:28 +0200485 const char *ifname, u_short tag, u_char distance, vrf_id_t vrf_id);
paul718e3742002-12-13 20:15:29 +0000486
Avneesh Sachdev9fd92e32012-11-13 22:48:53 +0000487extern int rib_gc_dest (struct route_node *rn);
Avneesh Sachdev0915bb02012-11-13 22:48:55 +0000488extern struct route_table *rib_tables_iter_next (rib_tables_iter_t *iter);
Avneesh Sachdev9fd92e32012-11-13 22:48:53 +0000489
490/*
491 * Inline functions.
492 */
493
494/*
Avneesh Sachdev1b5ed1b2012-11-13 22:48:54 +0000495 * rib_table_info
496 */
497static inline rib_table_info_t *
498rib_table_info (struct route_table *table)
499{
500 return (rib_table_info_t *) table->info;
501}
502
503/*
Avneesh Sachdev9fd92e32012-11-13 22:48:53 +0000504 * rib_dest_from_rnode
505 */
506static inline rib_dest_t *
507rib_dest_from_rnode (struct route_node *rn)
508{
509 return (rib_dest_t *) rn->info;
510}
511
512/*
513 * rnode_to_ribs
514 *
515 * Returns a pointer to the list of routes corresponding to the given
516 * route_node.
517 */
518static inline struct rib *
519rnode_to_ribs (struct route_node *rn)
520{
521 rib_dest_t *dest;
522
523 dest = rib_dest_from_rnode (rn);
524 if (!dest)
525 return NULL;
526
527 return dest->routes;
528}
529
530/*
531 * rib_dest_prefix
532 */
533static inline struct prefix *
534rib_dest_prefix (rib_dest_t *dest)
535{
536 return &dest->rnode->p;
537}
538
539/*
540 * rib_dest_af
541 *
542 * Returns the address family that the destination is for.
543 */
544static inline u_char
545rib_dest_af (rib_dest_t *dest)
546{
547 return dest->rnode->p.family;
548}
549
550/*
551 * rib_dest_table
552 */
553static inline struct route_table *
554rib_dest_table (rib_dest_t *dest)
555{
556 return dest->rnode->table;
557}
558
Avneesh Sachdev1b5ed1b2012-11-13 22:48:54 +0000559/*
560 * rib_dest_vrf
561 */
Feng Lu41f44a22015-05-22 11:39:56 +0200562static inline struct zebra_vrf *
Avneesh Sachdev1b5ed1b2012-11-13 22:48:54 +0000563rib_dest_vrf (rib_dest_t *dest)
564{
Feng Lu41f44a22015-05-22 11:39:56 +0200565 return rib_table_info (rib_dest_table (dest))->zvrf;
Avneesh Sachdev1b5ed1b2012-11-13 22:48:54 +0000566}
567
Avneesh Sachdev0915bb02012-11-13 22:48:55 +0000568/*
569 * rib_tables_iter_init
570 */
571static inline void
572rib_tables_iter_init (rib_tables_iter_t *iter)
573
574{
575 memset (iter, 0, sizeof (*iter));
576 iter->state = RIB_TABLES_ITER_S_INIT;
577}
578
579/*
580 * rib_tables_iter_started
581 *
582 * Returns TRUE if this iterator has started iterating over the set of
583 * tables.
584 */
585static inline int
586rib_tables_iter_started (rib_tables_iter_t *iter)
587{
588 return iter->state != RIB_TABLES_ITER_S_INIT;
589}
590
591/*
592 * rib_tables_iter_cleanup
593 */
594static inline void
595rib_tables_iter_cleanup (rib_tables_iter_t *iter)
596{
597 iter->state = RIB_TABLES_ITER_S_DONE;
598}
599
paul718e3742002-12-13 20:15:29 +0000600#endif /*_ZEBRA_RIB_H */