blob: fbf4fc42f37cffaca49105d6734876b195ad2f82 [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
Timo Teräsb11f3b52015-11-02 16:50:07 +020069 /* MTU */
70 u_int32_t mtu;
71 u_int32_t nexthop_mtu;
72
paul718e3742002-12-13 20:15:29 +000073 /* Distance. */
74 u_char distance;
75
Paul Jakma6d691122006-07-27 21:49:00 +000076 /* Flags of this route.
77 * This flag's definition is in lib/zebra.h ZEBRA_FLAG_* and is exposed
78 * to clients via Zserv
79 */
paul718e3742002-12-13 20:15:29 +000080 u_char flags;
81
Paul Jakma6d691122006-07-27 21:49:00 +000082 /* RIB internal status */
83 u_char status;
84#define RIB_ENTRY_REMOVED (1 << 0)
Timo Teräs7eb61362015-11-02 16:50:05 +020085#define RIB_ENTRY_CHANGED (1 << 1)
Paul Jakma6d691122006-07-27 21:49:00 +000086
paul718e3742002-12-13 20:15:29 +000087 /* Nexthop information. */
88 u_char nexthop_num;
89 u_char nexthop_active_num;
90 u_char nexthop_fib_num;
paul718e3742002-12-13 20:15:29 +000091};
92
Denis Ovsienkoe96f9202008-06-02 12:03:22 +000093/* meta-queue structure:
94 * sub-queue 0: connected, kernel
95 * sub-queue 1: static
96 * sub-queue 2: RIP, RIPng, OSPF, OSPF6, IS-IS
97 * sub-queue 3: iBGP, eBGP
98 * sub-queue 4: any other origin (if any)
99 */
100#define MQ_SIZE 5
101struct meta_queue
102{
103 struct list *subq[MQ_SIZE];
104 u_int32_t size; /* sum of lengths of all subqueues */
105};
106
Avneesh Sachdev9fd92e32012-11-13 22:48:53 +0000107/*
108 * Structure that represents a single destination (prefix).
109 */
110typedef struct rib_dest_t_
111{
112
113 /*
114 * Back pointer to the route node for this destination. This helps
115 * us get to the prefix that this structure is for.
116 */
117 struct route_node *rnode;
118
119 /*
120 * Doubly-linked list of routes for this prefix.
121 */
122 struct rib *routes;
123
124 /*
125 * Flags, see below.
126 */
127 u_int32_t flags;
128
Avneesh Sachdev5adc2522012-11-13 22:48:59 +0000129 /*
130 * Linkage to put dest on the FPM processing queue.
131 */
132 TAILQ_ENTRY(rib_dest_t_) fpm_q_entries;
133
Avneesh Sachdev9fd92e32012-11-13 22:48:53 +0000134} rib_dest_t;
135
136#define RIB_ROUTE_QUEUED(x) (1 << (x))
137
138/*
139 * The maximum qindex that can be used.
140 */
141#define ZEBRA_MAX_QINDEX (MQ_SIZE - 1)
142
143/*
Avneesh Sachdev5adc2522012-11-13 22:48:59 +0000144 * This flag indicates that a given prefix has been 'advertised' to
145 * the FPM to be installed in the forwarding plane.
146 */
147#define RIB_DEST_SENT_TO_FPM (1 << (ZEBRA_MAX_QINDEX + 1))
148
149/*
150 * This flag is set when we need to send an update to the FPM about a
151 * dest.
152 */
153#define RIB_DEST_UPDATE_FPM (1 << (ZEBRA_MAX_QINDEX + 2))
154
155/*
Avneesh Sachdev9fd92e32012-11-13 22:48:53 +0000156 * Macro to iterate over each route for a destination (prefix).
157 */
158#define RIB_DEST_FOREACH_ROUTE(dest, rib) \
159 for ((rib) = (dest) ? (dest)->routes : NULL; (rib); (rib) = (rib)->next)
160
161/*
162 * Same as above, but allows the current node to be unlinked.
163 */
164#define RIB_DEST_FOREACH_ROUTE_SAFE(dest, rib, next) \
165 for ((rib) = (dest) ? (dest)->routes : NULL; \
166 (rib) && ((next) = (rib)->next, 1); \
167 (rib) = (next))
168
169#define RNODE_FOREACH_RIB(rn, rib) \
170 RIB_DEST_FOREACH_ROUTE (rib_dest_from_rnode (rn), rib)
171
172#define RNODE_FOREACH_RIB_SAFE(rn, rib, next) \
173 RIB_DEST_FOREACH_ROUTE_SAFE (rib_dest_from_rnode (rn), rib, next)
174
paul718e3742002-12-13 20:15:29 +0000175/* Static route information. */
176struct static_ipv4
177{
178 /* For linked list. */
179 struct static_ipv4 *prev;
180 struct static_ipv4 *next;
181
Feng Lu7aaf4ea2015-05-22 11:40:06 +0200182 /* VRF identifier. */
183 vrf_id_t vrf_id;
184
paul718e3742002-12-13 20:15:29 +0000185 /* Administrative distance. */
186 u_char distance;
187
188 /* Flag for this static route's type. */
189 u_char type;
190#define STATIC_IPV4_GATEWAY 1
191#define STATIC_IPV4_IFNAME 2
paul595db7f2003-05-25 21:35:06 +0000192#define STATIC_IPV4_BLACKHOLE 3
paul718e3742002-12-13 20:15:29 +0000193
194 /* Nexthop value. */
195 union
196 {
197 struct in_addr ipv4;
198 char *ifname;
199 } gate;
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};
208
209#ifdef HAVE_IPV6
210/* Static route information. */
211struct static_ipv6
212{
213 /* For linked list. */
214 struct static_ipv6 *prev;
215 struct static_ipv6 *next;
216
Feng Lu7aaf4ea2015-05-22 11:40:06 +0200217 /* VRF identifier. */
218 vrf_id_t vrf_id;
219
paul718e3742002-12-13 20:15:29 +0000220 /* Administrative distance. */
221 u_char distance;
222
223 /* Flag for this static route's type. */
224 u_char type;
225#define STATIC_IPV6_GATEWAY 1
226#define STATIC_IPV6_GATEWAY_IFNAME 2
227#define STATIC_IPV6_IFNAME 3
228
229 /* Nexthop value. */
230 struct in6_addr ipv6;
231 char *ifname;
hasso81dfcaa2003-05-25 19:21:25 +0000232
233 /* bit flags */
234 u_char flags;
235/*
236 see ZEBRA_FLAG_REJECT
237 ZEBRA_FLAG_BLACKHOLE
238 */
paul718e3742002-12-13 20:15:29 +0000239};
240#endif /* HAVE_IPV6 */
241
paul7021c422003-07-15 12:52:22 +0000242enum nexthop_types_t
243{
244 NEXTHOP_TYPE_IFINDEX = 1, /* Directly connected. */
245 NEXTHOP_TYPE_IFNAME, /* Interface route. */
246 NEXTHOP_TYPE_IPV4, /* IPv4 nexthop. */
247 NEXTHOP_TYPE_IPV4_IFINDEX, /* IPv4 nexthop with ifindex. */
248 NEXTHOP_TYPE_IPV4_IFNAME, /* IPv4 nexthop with ifname. */
249 NEXTHOP_TYPE_IPV6, /* IPv6 nexthop. */
250 NEXTHOP_TYPE_IPV6_IFINDEX, /* IPv6 nexthop with ifindex. */
251 NEXTHOP_TYPE_IPV6_IFNAME, /* IPv6 nexthop with ifname. */
252 NEXTHOP_TYPE_BLACKHOLE, /* Null0 nexthop. */
253};
254
paul718e3742002-12-13 20:15:29 +0000255/* Nexthop structure. */
256struct nexthop
257{
258 struct nexthop *next;
259 struct nexthop *prev;
260
Paul Jakmae6d7d052006-03-30 13:32:09 +0000261 /* Interface index. */
262 char *ifname;
263 unsigned int ifindex;
264
paul7021c422003-07-15 12:52:22 +0000265 enum nexthop_types_t type;
paul718e3742002-12-13 20:15:29 +0000266
267 u_char flags;
268#define NEXTHOP_FLAG_ACTIVE (1 << 0) /* This nexthop is alive. */
269#define NEXTHOP_FLAG_FIB (1 << 1) /* FIB nexthop. */
270#define NEXTHOP_FLAG_RECURSIVE (1 << 2) /* Recursive nexthop. */
Christian Frankee8d3d292013-07-05 15:35:39 +0000271#define NEXTHOP_FLAG_ONLINK (1 << 3) /* Nexthop should be installed onlink. */
paul718e3742002-12-13 20:15:29 +0000272
Christian Frankefa713d92013-07-05 15:35:37 +0000273 /* Nexthop address */
Paul Jakma7514fb72007-05-02 16:05:35 +0000274 union g_addr gate;
Paul Jakma7514fb72007-05-02 16:05:35 +0000275 union g_addr src;
Christian Frankefa713d92013-07-05 15:35:37 +0000276
277 /* Nexthops obtained by recursive resolution.
278 *
279 * If the nexthop struct needs to be resolved recursively,
280 * NEXTHOP_FLAG_RECURSIVE will be set in flags and the nexthops
281 * obtained by recursive resolution will be added to `resolved'.
282 * Only one level of recursive resolution is currently supported. */
283 struct nexthop *resolved;
paul718e3742002-12-13 20:15:29 +0000284};
285
Christian Frankefa713d92013-07-05 15:35:37 +0000286/* The following for loop allows to iterate over the nexthop
287 * structure of routes.
288 *
289 * We have to maintain quite a bit of state:
290 *
291 * nexthop: The pointer to the current nexthop, either in the
292 * top-level chain or in the resolved chain of ni.
293 * tnexthop: The pointer to the current nexthop in the top-level
294 * nexthop chain.
295 * recursing: Information if nh currently is in the top-level chain
296 * (0) or in a resolved chain (1).
297 *
298 * Initialization: Set `nexthop' and `tnexthop' to the head of the
299 * top-level chain. As nexthop is in the top level chain, set recursing
300 * to 0.
301 *
302 * Iteration check: Check that the `nexthop' pointer is not NULL.
303 *
304 * Iteration step: This is the tricky part. Check if `nexthop' has
305 * NEXTHOP_FLAG_RECURSIVE set. If yes, this implies that `nexthop' is in
306 * the top level chain and has at least one nexthop attached to
307 * `nexthop->resolved'. As we want to descend into `nexthop->resolved',
308 * set `recursing' to 1 and set `nexthop' to `nexthop->resolved'.
309 * `tnexthop' is left alone in that case so we can remember which nexthop
310 * in the top level chain we are currently handling.
311 *
312 * If NEXTHOP_FLAG_RECURSIVE is not set, `nexthop' will progress in its
313 * current chain. If we are recursing, `nexthop' will be set to
314 * `nexthop->next' and `tnexthop' will be left alone. If we are not
315 * recursing, both `tnexthop' and `nexthop' will be set to `nexthop->next'
316 * as we are progressing in the top level chain.
317 * If we encounter `nexthop->next == NULL', we will clear the `recursing'
318 * flag as we arived either at the end of the resolved chain or at the end
319 * of the top level chain. In both cases, we set `tnexthop' and `nexthop'
320 * to `tnexthop->next', progressing to the next position in the top-level
321 * chain and possibly to its end marked by NULL.
322 */
323#define ALL_NEXTHOPS_RO(head, nexthop, tnexthop, recursing) \
324 (tnexthop) = (nexthop) = (head), (recursing) = 0; \
325 (nexthop); \
326 (nexthop) = CHECK_FLAG((nexthop)->flags, NEXTHOP_FLAG_RECURSIVE) \
327 ? (((recursing) = 1), (nexthop)->resolved) \
328 : ((nexthop)->next ? ((recursing) ? (nexthop)->next \
329 : ((tnexthop) = (nexthop)->next)) \
330 : (((recursing) = 0),((tnexthop) = (tnexthop)->next)))
331
Feng Lu1885d0a2015-05-22 11:40:04 +0200332/* Structure holding nexthop & VRF identifier,
333 * used for applying the route-map. */
334struct nexthop_vrfid
335{
336 struct nexthop *nexthop;
337 vrf_id_t vrf_id;
338};
339
Feng Lu49f76092015-05-22 11:40:10 +0200340/* Router advertisement feature. */
Timo Teräs983525e2015-10-22 11:35:16 +0300341#if !defined(RTADV) && defined(LINUX_IPV6) && defined(HAVE_RTADV)
342# define RTADV
Feng Lu49f76092015-05-22 11:40:10 +0200343#endif
344
345#if defined (HAVE_IPV6) && defined (RTADV)
346/* Structure which hold status of router advertisement. */
347struct rtadv
348{
349 int sock;
350
351 int adv_if_count;
352 int adv_msec_if_count;
353
354 struct thread *ra_read;
355 struct thread *ra_timer;
356};
357#endif /* RTADV && HAVE_IPV6 */
358
Feng Lu758fb8f2014-07-03 18:23:09 +0800359#ifdef HAVE_NETLINK
360/* Socket interface to kernel */
361struct nlsock
362{
363 int sock;
364 int seq;
365 struct sockaddr_nl snl;
366 const char *name;
367};
368#endif
369
paul718e3742002-12-13 20:15:29 +0000370/* Routing table instance. */
Feng Lu41f44a22015-05-22 11:39:56 +0200371struct zebra_vrf
paul718e3742002-12-13 20:15:29 +0000372{
Feng Lu41f44a22015-05-22 11:39:56 +0200373 /* Identifier. */
374 vrf_id_t vrf_id;
paul718e3742002-12-13 20:15:29 +0000375
376 /* Routing table name. */
377 char *name;
378
379 /* Description. */
380 char *desc;
381
382 /* FIB identifier. */
383 u_char fib_id;
384
385 /* Routing table. */
386 struct route_table *table[AFI_MAX][SAFI_MAX];
387
388 /* Static route configuration. */
389 struct route_table *stable[AFI_MAX][SAFI_MAX];
Feng Luac19a442015-05-22 11:40:07 +0200390
Feng Lu758fb8f2014-07-03 18:23:09 +0800391#ifdef HAVE_NETLINK
392 struct nlsock netlink; /* kernel messages */
393 struct nlsock netlink_cmd; /* command channel */
394 struct thread *t_netlink;
395#endif
396
Feng Luac19a442015-05-22 11:40:07 +0200397 /* 2nd pointer type used primarily to quell a warning on
398 * ALL_LIST_ELEMENTS_RO
399 */
400 struct list _rid_all_sorted_list;
401 struct list _rid_lo_sorted_list;
402 struct list *rid_all_sorted_list;
403 struct list *rid_lo_sorted_list;
404 struct prefix rid_user_assigned;
Feng Lu49f76092015-05-22 11:40:10 +0200405
406#if defined (HAVE_IPV6) && defined (RTADV)
407 struct rtadv rtadv;
408#endif /* RTADV && HAVE_IPV6 */
paul718e3742002-12-13 20:15:29 +0000409};
410
Avneesh Sachdev1b5ed1b2012-11-13 22:48:54 +0000411/*
412 * rib_table_info_t
413 *
414 * Structure that is hung off of a route_table that holds information about
415 * the table.
416 */
417typedef struct rib_table_info_t_
418{
419
420 /*
Feng Lu41f44a22015-05-22 11:39:56 +0200421 * Back pointer to zebra_vrf.
Avneesh Sachdev1b5ed1b2012-11-13 22:48:54 +0000422 */
Feng Lu41f44a22015-05-22 11:39:56 +0200423 struct zebra_vrf *zvrf;
Avneesh Sachdev1b5ed1b2012-11-13 22:48:54 +0000424 afi_t afi;
425 safi_t safi;
426
427} rib_table_info_t;
428
Avneesh Sachdev0915bb02012-11-13 22:48:55 +0000429typedef enum
430{
431 RIB_TABLES_ITER_S_INIT,
432 RIB_TABLES_ITER_S_ITERATING,
433 RIB_TABLES_ITER_S_DONE
434} rib_tables_iter_state_t;
435
436/*
437 * Structure that holds state for iterating over all tables in the
438 * Routing Information Base.
439 */
440typedef struct rib_tables_iter_t_
441{
Feng Lu41f44a22015-05-22 11:39:56 +0200442 vrf_id_t vrf_id;
Avneesh Sachdev0915bb02012-11-13 22:48:55 +0000443 int afi_safi_ix;
444
445 rib_tables_iter_state_t state;
446} rib_tables_iter_t;
447
David Lamparterbd078122015-01-06 19:53:24 +0100448/* RPF lookup behaviour */
449enum multicast_mode
450{
451 MCAST_NO_CONFIG = 0, /* MIX_MRIB_FIRST, but no show in config write */
452 MCAST_MRIB_ONLY, /* MRIB only */
453 MCAST_URIB_ONLY, /* URIB only */
454 MCAST_MIX_MRIB_FIRST, /* MRIB, if nothing at all then URIB */
455 MCAST_MIX_DISTANCE, /* MRIB & URIB, lower distance wins */
456 MCAST_MIX_PFXLEN, /* MRIB & URIB, longer prefix wins */
457 /* on equal value, MRIB wins for last 2 */
458};
459
460extern void multicast_mode_ipv4_set (enum multicast_mode mode);
461extern enum multicast_mode multicast_mode_ipv4_get (void);
462
Avneesh Sachdev78deec42012-11-13 22:48:56 +0000463extern const char *nexthop_type_to_str (enum nexthop_types_t nh_type);
paula1ac18c2005-06-28 17:17:12 +0000464extern struct nexthop *nexthop_ifindex_add (struct rib *, unsigned int);
465extern struct nexthop *nexthop_ifname_add (struct rib *, char *);
466extern struct nexthop *nexthop_blackhole_add (struct rib *);
Paul Jakma7514fb72007-05-02 16:05:35 +0000467extern struct nexthop *nexthop_ipv4_add (struct rib *, struct in_addr *,
468 struct in_addr *);
Josh Bailey26e2ae32012-03-22 01:09:21 -0700469extern struct nexthop *nexthop_ipv4_ifindex_add (struct rib *,
470 struct in_addr *,
471 struct in_addr *,
472 unsigned int);
Christian Frankefa713d92013-07-05 15:35:37 +0000473extern int nexthop_has_fib_child(struct nexthop *);
Denis Ovsienkodc958242007-08-13 16:03:06 +0000474extern void rib_lookup_and_dump (struct prefix_ipv4 *);
Denis Ovsienko20e5ff02008-02-26 14:02:24 +0000475extern void rib_lookup_and_pushup (struct prefix_ipv4 *);
David Lamparterf7bf4152013-10-22 17:10:21 +0000476#define rib_dump(prefix ,rib) _rib_dump(__func__, prefix, rib)
477extern void _rib_dump (const char *,
478 union prefix46constptr, const struct rib *);
Feng Lu0d0686f2015-05-22 11:40:02 +0200479extern int rib_lookup_ipv4_route (struct prefix_ipv4 *, union sockunion *,
480 vrf_id_t);
Denis Ovsienkodc958242007-08-13 16:03:06 +0000481#define ZEBRA_RIB_LOOKUP_ERROR -1
482#define ZEBRA_RIB_FOUND_EXACT 0
483#define ZEBRA_RIB_FOUND_NOGATE 1
484#define ZEBRA_RIB_FOUND_CONNECTED 2
485#define ZEBRA_RIB_NOTFOUND 3
486
paul718e3742002-12-13 20:15:29 +0000487#ifdef HAVE_IPV6
paula1ac18c2005-06-28 17:17:12 +0000488extern struct nexthop *nexthop_ipv6_add (struct rib *, struct in6_addr *);
paul718e3742002-12-13 20:15:29 +0000489#endif /* HAVE_IPV6 */
490
Feng Lu41f44a22015-05-22 11:39:56 +0200491extern struct zebra_vrf *zebra_vrf_alloc (vrf_id_t);
492extern struct route_table *zebra_vrf_table (afi_t, safi_t, vrf_id_t);
493extern struct route_table *zebra_vrf_static_table (afi_t, safi_t, vrf_id_t);
paul718e3742002-12-13 20:15:29 +0000494
hassod24af182005-09-24 14:00:26 +0000495/* NOTE:
496 * All rib_add_ipv[46]* functions will not just add prefix into RIB, but
497 * also implicitly withdraw equal prefix of same type. */
paula1ac18c2005-06-28 17:17:12 +0000498extern int rib_add_ipv4 (int type, int flags, struct prefix_ipv4 *p,
Paul Jakma7514fb72007-05-02 16:05:35 +0000499 struct in_addr *gate, struct in_addr *src,
Feng Lu0d0686f2015-05-22 11:40:02 +0200500 unsigned int ifindex, vrf_id_t vrf_id, int table_id,
Timo Teräsb11f3b52015-11-02 16:50:07 +0200501 u_int32_t, u_int32_t, u_char, safi_t);
paul718e3742002-12-13 20:15:29 +0000502
G.Balajicddf3912011-11-26 21:59:32 +0400503extern int rib_add_ipv4_multipath (struct prefix_ipv4 *, struct rib *, safi_t);
paul718e3742002-12-13 20:15:29 +0000504
paula1ac18c2005-06-28 17:17:12 +0000505extern int rib_delete_ipv4 (int type, int flags, struct prefix_ipv4 *p,
506 struct in_addr *gate, unsigned int ifindex,
Feng Lu0d0686f2015-05-22 11:40:02 +0200507 vrf_id_t, safi_t safi);
paul718e3742002-12-13 20:15:29 +0000508
David Lamparter24480d42015-01-22 19:09:36 +0100509extern struct rib *rib_match_ipv4_safi (struct in_addr addr, safi_t safi,
Feng Lu0d0686f2015-05-22 11:40:02 +0200510 int skip_bgp, struct route_node **rn_out,
511 vrf_id_t);
David Lamparterbd078122015-01-06 19:53:24 +0100512extern struct rib *rib_match_ipv4_multicast (struct in_addr addr,
Feng Lu0d0686f2015-05-22 11:40:02 +0200513 struct route_node **rn_out,
514 vrf_id_t);
paul718e3742002-12-13 20:15:29 +0000515
Feng Lu0d0686f2015-05-22 11:40:02 +0200516extern struct rib *rib_lookup_ipv4 (struct prefix_ipv4 *, vrf_id_t);
paul718e3742002-12-13 20:15:29 +0000517
Feng Lu0d0686f2015-05-22 11:40:02 +0200518extern void rib_update (vrf_id_t);
paula1ac18c2005-06-28 17:17:12 +0000519extern void rib_weed_tables (void);
520extern void rib_sweep_route (void);
Feng Lu267ceb22015-05-22 11:40:09 +0200521extern void rib_close_table (struct route_table *);
paula1ac18c2005-06-28 17:17:12 +0000522extern void rib_close (void);
523extern void rib_init (void);
Vyacheslav Trushkin2ea1ab12011-12-11 18:48:47 +0400524extern unsigned long rib_score_proto (u_char proto);
paul718e3742002-12-13 20:15:29 +0000525
paula1ac18c2005-06-28 17:17:12 +0000526extern int
Everton Marques33d86db2014-07-14 11:19:00 -0300527static_add_ipv4_safi (safi_t safi, struct prefix *p, struct in_addr *gate,
528 const char *ifname, u_char flags, u_char distance,
Feng Lu0d0686f2015-05-22 11:40:02 +0200529 vrf_id_t vrf_id);
paula1ac18c2005-06-28 17:17:12 +0000530extern int
Everton Marques33d86db2014-07-14 11:19:00 -0300531static_delete_ipv4_safi (safi_t safi, struct prefix *p, struct in_addr *gate,
Feng Lu0d0686f2015-05-22 11:40:02 +0200532 const char *ifname, u_char distance, vrf_id_t vrf_id);
paul718e3742002-12-13 20:15:29 +0000533
534#ifdef HAVE_IPV6
paula1ac18c2005-06-28 17:17:12 +0000535extern int
paul718e3742002-12-13 20:15:29 +0000536rib_add_ipv6 (int type, int flags, struct prefix_ipv6 *p,
Feng Lu0d0686f2015-05-22 11:40:02 +0200537 struct in6_addr *gate, unsigned int ifindex, vrf_id_t vrf_id,
Timo Teräsb11f3b52015-11-02 16:50:07 +0200538 int table_id, u_int32_t metric, u_int32_t mtu,
539 u_char distance, safi_t safi);
paul718e3742002-12-13 20:15:29 +0000540
paula1ac18c2005-06-28 17:17:12 +0000541extern int
paul718e3742002-12-13 20:15:29 +0000542rib_delete_ipv6 (int type, int flags, struct prefix_ipv6 *p,
Feng Lu0d0686f2015-05-22 11:40:02 +0200543 struct in6_addr *gate, unsigned int ifindex, vrf_id_t vrf_id, safi_t safi);
paul718e3742002-12-13 20:15:29 +0000544
Feng Lu0d0686f2015-05-22 11:40:02 +0200545extern struct rib *rib_lookup_ipv6 (struct in6_addr *, vrf_id_t);
paul718e3742002-12-13 20:15:29 +0000546
Feng Lu0d0686f2015-05-22 11:40:02 +0200547extern struct rib *rib_match_ipv6 (struct in6_addr *, vrf_id_t);
paul718e3742002-12-13 20:15:29 +0000548
549extern struct route_table *rib_table_ipv6;
550
paula1ac18c2005-06-28 17:17:12 +0000551extern int
paul718e3742002-12-13 20:15:29 +0000552static_add_ipv6 (struct prefix *p, u_char type, struct in6_addr *gate,
hasso39db97e2004-10-12 20:50:58 +0000553 const char *ifname, u_char flags, u_char distance,
Feng Lu0d0686f2015-05-22 11:40:02 +0200554 vrf_id_t vrf_id);
paul718e3742002-12-13 20:15:29 +0000555
paula1ac18c2005-06-28 17:17:12 +0000556extern int
paul718e3742002-12-13 20:15:29 +0000557static_delete_ipv6 (struct prefix *p, u_char type, struct in6_addr *gate,
Feng Lu0d0686f2015-05-22 11:40:02 +0200558 const char *ifname, u_char distance, vrf_id_t vrf_id);
paul718e3742002-12-13 20:15:29 +0000559
560#endif /* HAVE_IPV6 */
561
Avneesh Sachdev9fd92e32012-11-13 22:48:53 +0000562extern int rib_gc_dest (struct route_node *rn);
Avneesh Sachdev0915bb02012-11-13 22:48:55 +0000563extern struct route_table *rib_tables_iter_next (rib_tables_iter_t *iter);
Avneesh Sachdev9fd92e32012-11-13 22:48:53 +0000564
565/*
566 * Inline functions.
567 */
568
569/*
Avneesh Sachdev1b5ed1b2012-11-13 22:48:54 +0000570 * rib_table_info
571 */
572static inline rib_table_info_t *
573rib_table_info (struct route_table *table)
574{
575 return (rib_table_info_t *) table->info;
576}
577
578/*
Avneesh Sachdev9fd92e32012-11-13 22:48:53 +0000579 * rib_dest_from_rnode
580 */
581static inline rib_dest_t *
582rib_dest_from_rnode (struct route_node *rn)
583{
584 return (rib_dest_t *) rn->info;
585}
586
587/*
588 * rnode_to_ribs
589 *
590 * Returns a pointer to the list of routes corresponding to the given
591 * route_node.
592 */
593static inline struct rib *
594rnode_to_ribs (struct route_node *rn)
595{
596 rib_dest_t *dest;
597
598 dest = rib_dest_from_rnode (rn);
599 if (!dest)
600 return NULL;
601
602 return dest->routes;
603}
604
605/*
606 * rib_dest_prefix
607 */
608static inline struct prefix *
609rib_dest_prefix (rib_dest_t *dest)
610{
611 return &dest->rnode->p;
612}
613
614/*
615 * rib_dest_af
616 *
617 * Returns the address family that the destination is for.
618 */
619static inline u_char
620rib_dest_af (rib_dest_t *dest)
621{
622 return dest->rnode->p.family;
623}
624
625/*
626 * rib_dest_table
627 */
628static inline struct route_table *
629rib_dest_table (rib_dest_t *dest)
630{
631 return dest->rnode->table;
632}
633
Avneesh Sachdev1b5ed1b2012-11-13 22:48:54 +0000634/*
635 * rib_dest_vrf
636 */
Feng Lu41f44a22015-05-22 11:39:56 +0200637static inline struct zebra_vrf *
Avneesh Sachdev1b5ed1b2012-11-13 22:48:54 +0000638rib_dest_vrf (rib_dest_t *dest)
639{
Feng Lu41f44a22015-05-22 11:39:56 +0200640 return rib_table_info (rib_dest_table (dest))->zvrf;
Avneesh Sachdev1b5ed1b2012-11-13 22:48:54 +0000641}
642
Avneesh Sachdev0915bb02012-11-13 22:48:55 +0000643/*
644 * rib_tables_iter_init
645 */
646static inline void
647rib_tables_iter_init (rib_tables_iter_t *iter)
648
649{
650 memset (iter, 0, sizeof (*iter));
651 iter->state = RIB_TABLES_ITER_S_INIT;
652}
653
654/*
655 * rib_tables_iter_started
656 *
657 * Returns TRUE if this iterator has started iterating over the set of
658 * tables.
659 */
660static inline int
661rib_tables_iter_started (rib_tables_iter_t *iter)
662{
663 return iter->state != RIB_TABLES_ITER_S_INIT;
664}
665
666/*
667 * rib_tables_iter_cleanup
668 */
669static inline void
670rib_tables_iter_cleanup (rib_tables_iter_t *iter)
671{
672 iter->state = RIB_TABLES_ITER_S_DONE;
673}
674
paul718e3742002-12-13 20:15:29 +0000675#endif /*_ZEBRA_RIB_H */