blob: 0191f57ec090c8c4b949580caf51aaf3c8c8a1fb [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
Paul Jakma96d10602016-07-01 14:23:45 +010026#include "zebra.h"
Feng Luac19a442015-05-22 11:40:07 +020027#include "linklist.h"
paulec1a4282005-11-24 15:15:17 +000028#include "prefix.h"
Avneesh Sachdev9fd92e32012-11-13 22:48:53 +000029#include "table.h"
Avneesh Sachdev5adc2522012-11-13 22:48:59 +000030#include "queue.h"
Pradosh Mohapatra60cc9592015-11-09 20:21:41 -050031#include "nexthop.h"
paulec1a4282005-11-24 15:15:17 +000032
paul718e3742002-12-13 20:15:29 +000033#define DISTANCE_INFINITY 255
34
paul718e3742002-12-13 20:15:29 +000035struct rib
36{
37 /* Link list. */
38 struct rib *next;
39 struct rib *prev;
Paul Jakmae6d7d052006-03-30 13:32:09 +000040
41 /* Nexthop structure */
42 struct nexthop *nexthop;
43
44 /* Refrence count. */
45 unsigned long refcnt;
46
Paul Jakma96d10602016-07-01 14:23:45 +010047 /* Tag */
48 route_tag_t tag;
49
Paul Jakmae6d7d052006-03-30 13:32:09 +000050 /* Uptime. */
51 time_t uptime;
paul718e3742002-12-13 20:15:29 +000052
53 /* Type fo this route. */
54 int type;
55
Feng Lu0d0686f2015-05-22 11:40:02 +020056 /* VRF identifier. */
57 vrf_id_t vrf_id;
58
paul718e3742002-12-13 20:15:29 +000059 /* Which routing table */
60 int table;
61
Paul Jakmae6d7d052006-03-30 13:32:09 +000062 /* Metric */
63 u_int32_t metric;
64
Timo Teräsb11f3b52015-11-02 16:50:07 +020065 /* MTU */
66 u_int32_t mtu;
67 u_int32_t nexthop_mtu;
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)
Timo Teräs325823a2016-01-15 17:36:31 +020082#define RIB_ENTRY_SELECTED_FIB (1 << 2)
Paul Jakma6d691122006-07-27 21:49:00 +000083
paul718e3742002-12-13 20:15:29 +000084 /* Nexthop information. */
85 u_char nexthop_num;
86 u_char nexthop_active_num;
87 u_char nexthop_fib_num;
paul718e3742002-12-13 20:15:29 +000088};
89
Denis Ovsienkoe96f9202008-06-02 12:03:22 +000090/* meta-queue structure:
91 * sub-queue 0: connected, kernel
92 * sub-queue 1: static
93 * sub-queue 2: RIP, RIPng, OSPF, OSPF6, IS-IS
94 * sub-queue 3: iBGP, eBGP
95 * sub-queue 4: any other origin (if any)
96 */
97#define MQ_SIZE 5
98struct meta_queue
99{
100 struct list *subq[MQ_SIZE];
101 u_int32_t size; /* sum of lengths of all subqueues */
102};
103
Avneesh Sachdev9fd92e32012-11-13 22:48:53 +0000104/*
105 * Structure that represents a single destination (prefix).
106 */
107typedef struct rib_dest_t_
108{
109
110 /*
111 * Back pointer to the route node for this destination. This helps
112 * us get to the prefix that this structure is for.
113 */
114 struct route_node *rnode;
115
116 /*
117 * Doubly-linked list of routes for this prefix.
118 */
119 struct rib *routes;
120
121 /*
122 * Flags, see below.
123 */
124 u_int32_t flags;
125
Avneesh Sachdev5adc2522012-11-13 22:48:59 +0000126 /*
127 * Linkage to put dest on the FPM processing queue.
128 */
129 TAILQ_ENTRY(rib_dest_t_) fpm_q_entries;
130
Avneesh Sachdev9fd92e32012-11-13 22:48:53 +0000131} rib_dest_t;
132
133#define RIB_ROUTE_QUEUED(x) (1 << (x))
134
135/*
136 * The maximum qindex that can be used.
137 */
138#define ZEBRA_MAX_QINDEX (MQ_SIZE - 1)
139
140/*
Avneesh Sachdev5adc2522012-11-13 22:48:59 +0000141 * This flag indicates that a given prefix has been 'advertised' to
142 * the FPM to be installed in the forwarding plane.
143 */
144#define RIB_DEST_SENT_TO_FPM (1 << (ZEBRA_MAX_QINDEX + 1))
145
146/*
147 * This flag is set when we need to send an update to the FPM about a
148 * dest.
149 */
150#define RIB_DEST_UPDATE_FPM (1 << (ZEBRA_MAX_QINDEX + 2))
151
152/*
Avneesh Sachdev9fd92e32012-11-13 22:48:53 +0000153 * Macro to iterate over each route for a destination (prefix).
154 */
155#define RIB_DEST_FOREACH_ROUTE(dest, rib) \
156 for ((rib) = (dest) ? (dest)->routes : NULL; (rib); (rib) = (rib)->next)
157
158/*
159 * Same as above, but allows the current node to be unlinked.
160 */
161#define RIB_DEST_FOREACH_ROUTE_SAFE(dest, rib, next) \
162 for ((rib) = (dest) ? (dest)->routes : NULL; \
163 (rib) && ((next) = (rib)->next, 1); \
164 (rib) = (next))
165
166#define RNODE_FOREACH_RIB(rn, rib) \
167 RIB_DEST_FOREACH_ROUTE (rib_dest_from_rnode (rn), rib)
168
169#define RNODE_FOREACH_RIB_SAFE(rn, rib, next) \
170 RIB_DEST_FOREACH_ROUTE_SAFE (rib_dest_from_rnode (rn), rib, next)
171
paul718e3742002-12-13 20:15:29 +0000172/* Static route information. */
Donald Sharpd4c27d62015-11-04 13:26:35 -0500173struct static_route
paul718e3742002-12-13 20:15:29 +0000174{
175 /* For linked list. */
Donald Sharpd4c27d62015-11-04 13:26:35 -0500176 struct static_route *prev;
177 struct static_route *next;
paul718e3742002-12-13 20:15:29 +0000178
Feng Lu7aaf4ea2015-05-22 11:40:06 +0200179 /* VRF identifier. */
180 vrf_id_t vrf_id;
181
paul718e3742002-12-13 20:15:29 +0000182 /* Administrative distance. */
183 u_char distance;
184
Piotr Chytłade24f822007-06-28 00:09:28 +0200185 /* Tag */
Paul Jakma96d10602016-07-01 14:23:45 +0100186 route_tag_t tag;
Piotr Chytłade24f822007-06-28 00:09:28 +0200187
paul718e3742002-12-13 20:15:29 +0000188 /* Flag for this static route's type. */
189 u_char type;
Donald Sharpd4c27d62015-11-04 13:26:35 -0500190#define STATIC_IPV4_GATEWAY 1
191#define STATIC_IPV4_IFNAME 2
192#define STATIC_IPV4_BLACKHOLE 3
193#define STATIC_IPV6_GATEWAY 4
194#define STATIC_IPV6_GATEWAY_IFNAME 5
195#define STATIC_IPV6_IFNAME 6
paul718e3742002-12-13 20:15:29 +0000196
197 /* Nexthop value. */
Donald Sharpd4c27d62015-11-04 13:26:35 -0500198 union g_addr addr;
paul718e3742002-12-13 20:15:29 +0000199 char *ifname;
hasso81dfcaa2003-05-25 19:21:25 +0000200
201 /* bit flags */
202 u_char flags;
203/*
204 see ZEBRA_FLAG_REJECT
205 ZEBRA_FLAG_BLACKHOLE
206 */
paul718e3742002-12-13 20:15:29 +0000207};
paul718e3742002-12-13 20:15:29 +0000208
Christian Frankefa713d92013-07-05 15:35:37 +0000209/* The following for loop allows to iterate over the nexthop
210 * structure of routes.
211 *
212 * We have to maintain quite a bit of state:
213 *
214 * nexthop: The pointer to the current nexthop, either in the
215 * top-level chain or in the resolved chain of ni.
216 * tnexthop: The pointer to the current nexthop in the top-level
217 * nexthop chain.
218 * recursing: Information if nh currently is in the top-level chain
219 * (0) or in a resolved chain (1).
220 *
221 * Initialization: Set `nexthop' and `tnexthop' to the head of the
222 * top-level chain. As nexthop is in the top level chain, set recursing
223 * to 0.
224 *
225 * Iteration check: Check that the `nexthop' pointer is not NULL.
226 *
227 * Iteration step: This is the tricky part. Check if `nexthop' has
228 * NEXTHOP_FLAG_RECURSIVE set. If yes, this implies that `nexthop' is in
229 * the top level chain and has at least one nexthop attached to
230 * `nexthop->resolved'. As we want to descend into `nexthop->resolved',
231 * set `recursing' to 1 and set `nexthop' to `nexthop->resolved'.
232 * `tnexthop' is left alone in that case so we can remember which nexthop
233 * in the top level chain we are currently handling.
234 *
235 * If NEXTHOP_FLAG_RECURSIVE is not set, `nexthop' will progress in its
236 * current chain. If we are recursing, `nexthop' will be set to
237 * `nexthop->next' and `tnexthop' will be left alone. If we are not
238 * recursing, both `tnexthop' and `nexthop' will be set to `nexthop->next'
239 * as we are progressing in the top level chain.
240 * If we encounter `nexthop->next == NULL', we will clear the `recursing'
241 * flag as we arived either at the end of the resolved chain or at the end
242 * of the top level chain. In both cases, we set `tnexthop' and `nexthop'
243 * to `tnexthop->next', progressing to the next position in the top-level
244 * chain and possibly to its end marked by NULL.
245 */
246#define ALL_NEXTHOPS_RO(head, nexthop, tnexthop, recursing) \
247 (tnexthop) = (nexthop) = (head), (recursing) = 0; \
248 (nexthop); \
249 (nexthop) = CHECK_FLAG((nexthop)->flags, NEXTHOP_FLAG_RECURSIVE) \
250 ? (((recursing) = 1), (nexthop)->resolved) \
251 : ((nexthop)->next ? ((recursing) ? (nexthop)->next \
252 : ((tnexthop) = (nexthop)->next)) \
253 : (((recursing) = 0),((tnexthop) = (tnexthop)->next)))
254
Feng Lu1885d0a2015-05-22 11:40:04 +0200255/* Structure holding nexthop & VRF identifier,
256 * used for applying the route-map. */
257struct nexthop_vrfid
258{
259 struct nexthop *nexthop;
260 vrf_id_t vrf_id;
261};
262
Feng Lu49f76092015-05-22 11:40:10 +0200263
Donald Sharp64257732015-11-20 08:33:30 -0500264#if defined (HAVE_RTADV)
Feng Lu49f76092015-05-22 11:40:10 +0200265/* Structure which hold status of router advertisement. */
266struct rtadv
267{
268 int sock;
269
270 int adv_if_count;
271 int adv_msec_if_count;
272
273 struct thread *ra_read;
274 struct thread *ra_timer;
275};
Donald Sharp64257732015-11-20 08:33:30 -0500276#endif /* HAVE_RTADV */
Feng Lu49f76092015-05-22 11:40:10 +0200277
Feng Lu758fb8f2014-07-03 18:23:09 +0800278#ifdef HAVE_NETLINK
279/* Socket interface to kernel */
280struct nlsock
281{
282 int sock;
283 int seq;
284 struct sockaddr_nl snl;
285 const char *name;
286};
287#endif
288
paul718e3742002-12-13 20:15:29 +0000289/* Routing table instance. */
Feng Lu41f44a22015-05-22 11:39:56 +0200290struct zebra_vrf
paul718e3742002-12-13 20:15:29 +0000291{
Feng Lu41f44a22015-05-22 11:39:56 +0200292 /* Identifier. */
293 vrf_id_t vrf_id;
paul718e3742002-12-13 20:15:29 +0000294
295 /* Routing table name. */
296 char *name;
297
298 /* Description. */
299 char *desc;
300
301 /* FIB identifier. */
302 u_char fib_id;
303
304 /* Routing table. */
305 struct route_table *table[AFI_MAX][SAFI_MAX];
306
307 /* Static route configuration. */
308 struct route_table *stable[AFI_MAX][SAFI_MAX];
Feng Luac19a442015-05-22 11:40:07 +0200309
Feng Lu758fb8f2014-07-03 18:23:09 +0800310#ifdef HAVE_NETLINK
311 struct nlsock netlink; /* kernel messages */
312 struct nlsock netlink_cmd; /* command channel */
313 struct thread *t_netlink;
314#endif
315
Feng Luac19a442015-05-22 11:40:07 +0200316 /* 2nd pointer type used primarily to quell a warning on
317 * ALL_LIST_ELEMENTS_RO
318 */
319 struct list _rid_all_sorted_list;
320 struct list _rid_lo_sorted_list;
321 struct list *rid_all_sorted_list;
322 struct list *rid_lo_sorted_list;
323 struct prefix rid_user_assigned;
Feng Lu49f76092015-05-22 11:40:10 +0200324
Donald Sharp64257732015-11-20 08:33:30 -0500325#if defined (HAVE_RTADV)
Feng Lu49f76092015-05-22 11:40:10 +0200326 struct rtadv rtadv;
Donald Sharp64257732015-11-20 08:33:30 -0500327#endif /* HAVE_RTADV */
Pradosh Mohapatra60cc9592015-11-09 20:21:41 -0500328
329 /* Recursive Nexthop table */
330 struct route_table *rnh_table[AFI_MAX];
paul718e3742002-12-13 20:15:29 +0000331};
332
Avneesh Sachdev1b5ed1b2012-11-13 22:48:54 +0000333/*
334 * rib_table_info_t
335 *
336 * Structure that is hung off of a route_table that holds information about
337 * the table.
338 */
339typedef struct rib_table_info_t_
340{
341
342 /*
Feng Lu41f44a22015-05-22 11:39:56 +0200343 * Back pointer to zebra_vrf.
Avneesh Sachdev1b5ed1b2012-11-13 22:48:54 +0000344 */
Feng Lu41f44a22015-05-22 11:39:56 +0200345 struct zebra_vrf *zvrf;
Avneesh Sachdev1b5ed1b2012-11-13 22:48:54 +0000346 afi_t afi;
347 safi_t safi;
348
349} rib_table_info_t;
350
Avneesh Sachdev0915bb02012-11-13 22:48:55 +0000351typedef enum
352{
353 RIB_TABLES_ITER_S_INIT,
354 RIB_TABLES_ITER_S_ITERATING,
355 RIB_TABLES_ITER_S_DONE
356} rib_tables_iter_state_t;
357
358/*
359 * Structure that holds state for iterating over all tables in the
360 * Routing Information Base.
361 */
362typedef struct rib_tables_iter_t_
363{
Feng Lu41f44a22015-05-22 11:39:56 +0200364 vrf_id_t vrf_id;
Avneesh Sachdev0915bb02012-11-13 22:48:55 +0000365 int afi_safi_ix;
366
367 rib_tables_iter_state_t state;
368} rib_tables_iter_t;
369
David Lamparterbd078122015-01-06 19:53:24 +0100370/* RPF lookup behaviour */
371enum multicast_mode
372{
373 MCAST_NO_CONFIG = 0, /* MIX_MRIB_FIRST, but no show in config write */
374 MCAST_MRIB_ONLY, /* MRIB only */
375 MCAST_URIB_ONLY, /* URIB only */
376 MCAST_MIX_MRIB_FIRST, /* MRIB, if nothing at all then URIB */
377 MCAST_MIX_DISTANCE, /* MRIB & URIB, lower distance wins */
378 MCAST_MIX_PFXLEN, /* MRIB & URIB, longer prefix wins */
379 /* on equal value, MRIB wins for last 2 */
380};
381
382extern void multicast_mode_ipv4_set (enum multicast_mode mode);
383extern enum multicast_mode multicast_mode_ipv4_get (void);
384
Avneesh Sachdev78deec42012-11-13 22:48:56 +0000385extern const char *nexthop_type_to_str (enum nexthop_types_t nh_type);
Pradosh Mohapatra60cc9592015-11-09 20:21:41 -0500386extern struct nexthop *rib_nexthop_ifindex_add (struct rib *, ifindex_t);
387extern struct nexthop *rib_nexthop_ifname_add (struct rib *, char *);
388extern struct nexthop *rib_nexthop_blackhole_add (struct rib *);
389extern struct nexthop *rib_nexthop_ipv4_add (struct rib *, struct in_addr *,
390 struct in_addr *);
391extern struct nexthop *rib_nexthop_ipv4_ifindex_add (struct rib *,
392 struct in_addr *,
393 struct in_addr *,
394 ifindex_t);
395
396extern void rib_nexthop_add (struct rib *rib, struct nexthop *nexthop);
397
Christian Frankefa713d92013-07-05 15:35:37 +0000398extern int nexthop_has_fib_child(struct nexthop *);
Denis Ovsienkodc958242007-08-13 16:03:06 +0000399extern void rib_lookup_and_dump (struct prefix_ipv4 *);
David Lamparterf7bf4152013-10-22 17:10:21 +0000400#define rib_dump(prefix ,rib) _rib_dump(__func__, prefix, rib)
401extern void _rib_dump (const char *,
402 union prefix46constptr, const struct rib *);
Feng Lu0d0686f2015-05-22 11:40:02 +0200403extern int rib_lookup_ipv4_route (struct prefix_ipv4 *, union sockunion *,
404 vrf_id_t);
Denis Ovsienkodc958242007-08-13 16:03:06 +0000405#define ZEBRA_RIB_LOOKUP_ERROR -1
406#define ZEBRA_RIB_FOUND_EXACT 0
407#define ZEBRA_RIB_FOUND_NOGATE 1
408#define ZEBRA_RIB_FOUND_CONNECTED 2
409#define ZEBRA_RIB_NOTFOUND 3
410
Pradosh Mohapatra60cc9592015-11-09 20:21:41 -0500411extern struct nexthop *rib_nexthop_ipv6_add (struct rib *, struct in6_addr *);
412extern struct nexthop *rib_nexthop_ipv6_ifindex_add (struct rib *,
413 struct in6_addr *,
414 ifindex_t);
paul718e3742002-12-13 20:15:29 +0000415
Pradosh Mohapatra60cc9592015-11-09 20:21:41 -0500416extern struct zebra_vrf *zebra_vrf_lookup (vrf_id_t vrf_id);
Feng Lu41f44a22015-05-22 11:39:56 +0200417extern struct zebra_vrf *zebra_vrf_alloc (vrf_id_t);
418extern struct route_table *zebra_vrf_table (afi_t, safi_t, vrf_id_t);
419extern struct route_table *zebra_vrf_static_table (afi_t, safi_t, vrf_id_t);
paul718e3742002-12-13 20:15:29 +0000420
hassod24af182005-09-24 14:00:26 +0000421/* NOTE:
422 * All rib_add_ipv[46]* functions will not just add prefix into RIB, but
423 * also implicitly withdraw equal prefix of same type. */
paula1ac18c2005-06-28 17:17:12 +0000424extern int rib_add_ipv4 (int type, int flags, struct prefix_ipv4 *p,
Paul Jakma7514fb72007-05-02 16:05:35 +0000425 struct in_addr *gate, struct in_addr *src,
Paul Jakma9099f9b2016-01-18 10:12:10 +0000426 ifindex_t ifindex, vrf_id_t vrf_id, int table_id,
Timo Teräsb11f3b52015-11-02 16:50:07 +0200427 u_int32_t, u_int32_t, u_char, safi_t);
paul718e3742002-12-13 20:15:29 +0000428
G.Balajicddf3912011-11-26 21:59:32 +0400429extern int rib_add_ipv4_multipath (struct prefix_ipv4 *, struct rib *, safi_t);
paul718e3742002-12-13 20:15:29 +0000430
paula1ac18c2005-06-28 17:17:12 +0000431extern int rib_delete_ipv4 (int type, int flags, struct prefix_ipv4 *p,
Paul Jakma9099f9b2016-01-18 10:12:10 +0000432 struct in_addr *gate, ifindex_t ifindex,
Feng Lu0d0686f2015-05-22 11:40:02 +0200433 vrf_id_t, safi_t safi);
paul718e3742002-12-13 20:15:29 +0000434
David Lamparter24480d42015-01-22 19:09:36 +0100435extern struct rib *rib_match_ipv4_safi (struct in_addr addr, safi_t safi,
Feng Lu0d0686f2015-05-22 11:40:02 +0200436 int skip_bgp, struct route_node **rn_out,
437 vrf_id_t);
David Lamparterbd078122015-01-06 19:53:24 +0100438extern struct rib *rib_match_ipv4_multicast (struct in_addr addr,
Feng Lu0d0686f2015-05-22 11:40:02 +0200439 struct route_node **rn_out,
440 vrf_id_t);
paul718e3742002-12-13 20:15:29 +0000441
Feng Lu0d0686f2015-05-22 11:40:02 +0200442extern struct rib *rib_lookup_ipv4 (struct prefix_ipv4 *, vrf_id_t);
paul718e3742002-12-13 20:15:29 +0000443
Feng Lu0d0686f2015-05-22 11:40:02 +0200444extern void rib_update (vrf_id_t);
paula1ac18c2005-06-28 17:17:12 +0000445extern void rib_weed_tables (void);
446extern void rib_sweep_route (void);
Feng Lu267ceb22015-05-22 11:40:09 +0200447extern void rib_close_table (struct route_table *);
paula1ac18c2005-06-28 17:17:12 +0000448extern void rib_close (void);
449extern void rib_init (void);
Vyacheslav Trushkin2ea1ab12011-12-11 18:48:47 +0400450extern unsigned long rib_score_proto (u_char proto);
paul718e3742002-12-13 20:15:29 +0000451
paula1ac18c2005-06-28 17:17:12 +0000452extern int
Everton Marques33d86db2014-07-14 11:19:00 -0300453static_add_ipv4_safi (safi_t safi, struct prefix *p, struct in_addr *gate,
Paul Jakma96d10602016-07-01 14:23:45 +0100454 const char *ifname, u_char flags, route_tag_t,
455 u_char distance, vrf_id_t vrf_id);
paula1ac18c2005-06-28 17:17:12 +0000456extern int
Everton Marques33d86db2014-07-14 11:19:00 -0300457static_delete_ipv4_safi (safi_t safi, struct prefix *p, struct in_addr *gate,
Paul Jakma96d10602016-07-01 14:23:45 +0100458 const char *ifname, route_tag_t tag, u_char distance,
459 vrf_id_t vrf_id);
paul718e3742002-12-13 20:15:29 +0000460
paula1ac18c2005-06-28 17:17:12 +0000461extern int
paul718e3742002-12-13 20:15:29 +0000462rib_add_ipv6 (int type, int flags, struct prefix_ipv6 *p,
Paul Jakma9099f9b2016-01-18 10:12:10 +0000463 struct in6_addr *gate, ifindex_t ifindex, vrf_id_t vrf_id,
Timo Teräsb11f3b52015-11-02 16:50:07 +0200464 int table_id, u_int32_t metric, u_int32_t mtu,
465 u_char distance, safi_t safi);
paul718e3742002-12-13 20:15:29 +0000466
paula1ac18c2005-06-28 17:17:12 +0000467extern int
paul718e3742002-12-13 20:15:29 +0000468rib_delete_ipv6 (int type, int flags, struct prefix_ipv6 *p,
Paul Jakma9099f9b2016-01-18 10:12:10 +0000469 struct in6_addr *gate, ifindex_t ifindex, vrf_id_t vrf_id, safi_t safi);
paul718e3742002-12-13 20:15:29 +0000470
Feng Lu0d0686f2015-05-22 11:40:02 +0200471extern struct rib *rib_lookup_ipv6 (struct in6_addr *, vrf_id_t);
paul718e3742002-12-13 20:15:29 +0000472
Feng Lu0d0686f2015-05-22 11:40:02 +0200473extern struct rib *rib_match_ipv6 (struct in6_addr *, vrf_id_t);
paul718e3742002-12-13 20:15:29 +0000474
475extern struct route_table *rib_table_ipv6;
476
paula1ac18c2005-06-28 17:17:12 +0000477extern int
paul718e3742002-12-13 20:15:29 +0000478static_add_ipv6 (struct prefix *p, u_char type, struct in6_addr *gate,
Paul Jakma96d10602016-07-01 14:23:45 +0100479 const char *ifname, u_char flags, route_tag_t,
480 u_char distance, vrf_id_t vrf_id);
paul718e3742002-12-13 20:15:29 +0000481
paula1ac18c2005-06-28 17:17:12 +0000482extern int
Ayan Banerjee34c5d892015-11-09 20:14:53 -0500483rib_add_ipv6_multipath (struct prefix_ipv6 *, struct rib *, safi_t);
484
485extern int
paul718e3742002-12-13 20:15:29 +0000486static_delete_ipv6 (struct prefix *p, u_char type, struct in6_addr *gate,
Paul Jakma96d10602016-07-01 14:23:45 +0100487 const char *ifname, route_tag_t, u_char distance,
488 vrf_id_t vrf_id);
paul718e3742002-12-13 20:15:29 +0000489
Avneesh Sachdev9fd92e32012-11-13 22:48:53 +0000490extern int rib_gc_dest (struct route_node *rn);
Avneesh Sachdev0915bb02012-11-13 22:48:55 +0000491extern struct route_table *rib_tables_iter_next (rib_tables_iter_t *iter);
Avneesh Sachdev9fd92e32012-11-13 22:48:53 +0000492
493/*
494 * Inline functions.
495 */
496
497/*
Avneesh Sachdev1b5ed1b2012-11-13 22:48:54 +0000498 * rib_table_info
499 */
500static inline rib_table_info_t *
501rib_table_info (struct route_table *table)
502{
503 return (rib_table_info_t *) table->info;
504}
505
506/*
Avneesh Sachdev9fd92e32012-11-13 22:48:53 +0000507 * rib_dest_from_rnode
508 */
509static inline rib_dest_t *
510rib_dest_from_rnode (struct route_node *rn)
511{
512 return (rib_dest_t *) rn->info;
513}
514
515/*
516 * rnode_to_ribs
517 *
518 * Returns a pointer to the list of routes corresponding to the given
519 * route_node.
520 */
521static inline struct rib *
522rnode_to_ribs (struct route_node *rn)
523{
524 rib_dest_t *dest;
525
526 dest = rib_dest_from_rnode (rn);
527 if (!dest)
528 return NULL;
529
530 return dest->routes;
531}
532
533/*
534 * rib_dest_prefix
535 */
536static inline struct prefix *
537rib_dest_prefix (rib_dest_t *dest)
538{
539 return &dest->rnode->p;
540}
541
542/*
543 * rib_dest_af
544 *
545 * Returns the address family that the destination is for.
546 */
547static inline u_char
548rib_dest_af (rib_dest_t *dest)
549{
550 return dest->rnode->p.family;
551}
552
553/*
554 * rib_dest_table
555 */
556static inline struct route_table *
557rib_dest_table (rib_dest_t *dest)
558{
559 return dest->rnode->table;
560}
561
Avneesh Sachdev1b5ed1b2012-11-13 22:48:54 +0000562/*
563 * rib_dest_vrf
564 */
Feng Lu41f44a22015-05-22 11:39:56 +0200565static inline struct zebra_vrf *
Avneesh Sachdev1b5ed1b2012-11-13 22:48:54 +0000566rib_dest_vrf (rib_dest_t *dest)
567{
Feng Lu41f44a22015-05-22 11:39:56 +0200568 return rib_table_info (rib_dest_table (dest))->zvrf;
Avneesh Sachdev1b5ed1b2012-11-13 22:48:54 +0000569}
570
Avneesh Sachdev0915bb02012-11-13 22:48:55 +0000571/*
572 * rib_tables_iter_init
573 */
574static inline void
575rib_tables_iter_init (rib_tables_iter_t *iter)
576
577{
578 memset (iter, 0, sizeof (*iter));
579 iter->state = RIB_TABLES_ITER_S_INIT;
580}
581
582/*
583 * rib_tables_iter_started
584 *
585 * Returns TRUE if this iterator has started iterating over the set of
586 * tables.
587 */
588static inline int
589rib_tables_iter_started (rib_tables_iter_t *iter)
590{
591 return iter->state != RIB_TABLES_ITER_S_INIT;
592}
593
594/*
595 * rib_tables_iter_cleanup
596 */
597static inline void
598rib_tables_iter_cleanup (rib_tables_iter_t *iter)
599{
600 iter->state = RIB_TABLES_ITER_S_DONE;
601}
602
paul718e3742002-12-13 20:15:29 +0000603#endif /*_ZEBRA_RIB_H */