paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1 | /* |
| 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 | ec1a428 | 2005-11-24 15:15:17 +0000 | [diff] [blame] | 26 | #include "prefix.h" |
Avneesh Sachdev | 9fd92e3 | 2012-11-13 22:48:53 +0000 | [diff] [blame] | 27 | #include "table.h" |
Avneesh Sachdev | 5adc252 | 2012-11-13 22:48:59 +0000 | [diff] [blame] | 28 | #include "queue.h" |
paul | ec1a428 | 2005-11-24 15:15:17 +0000 | [diff] [blame] | 29 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 30 | #define DISTANCE_INFINITY 255 |
| 31 | |
| 32 | /* Routing information base. */ |
Paul Jakma | 7514fb7 | 2007-05-02 16:05:35 +0000 | [diff] [blame] | 33 | |
| 34 | union g_addr { |
| 35 | struct in_addr ipv4; |
| 36 | #ifdef HAVE_IPV6 |
| 37 | struct in6_addr ipv6; |
| 38 | #endif /* HAVE_IPV6 */ |
| 39 | }; |
| 40 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 41 | struct rib |
| 42 | { |
| 43 | /* Link list. */ |
| 44 | struct rib *next; |
| 45 | struct rib *prev; |
Paul Jakma | e6d7d05 | 2006-03-30 13:32:09 +0000 | [diff] [blame] | 46 | |
| 47 | /* Nexthop structure */ |
| 48 | struct nexthop *nexthop; |
| 49 | |
| 50 | /* Refrence count. */ |
| 51 | unsigned long refcnt; |
| 52 | |
| 53 | /* Uptime. */ |
| 54 | time_t uptime; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 55 | |
| 56 | /* Type fo this route. */ |
| 57 | int type; |
| 58 | |
| 59 | /* Which routing table */ |
| 60 | int table; |
| 61 | |
Paul Jakma | e6d7d05 | 2006-03-30 13:32:09 +0000 | [diff] [blame] | 62 | /* Metric */ |
| 63 | u_int32_t metric; |
| 64 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 65 | /* Distance. */ |
| 66 | u_char distance; |
| 67 | |
Paul Jakma | 6d69112 | 2006-07-27 21:49:00 +0000 | [diff] [blame] | 68 | /* 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 | */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 72 | u_char flags; |
| 73 | |
Paul Jakma | 6d69112 | 2006-07-27 21:49:00 +0000 | [diff] [blame] | 74 | /* RIB internal status */ |
| 75 | u_char status; |
| 76 | #define RIB_ENTRY_REMOVED (1 << 0) |
| 77 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 78 | /* Nexthop information. */ |
| 79 | u_char nexthop_num; |
| 80 | u_char nexthop_active_num; |
| 81 | u_char nexthop_fib_num; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 82 | }; |
| 83 | |
Denis Ovsienko | e96f920 | 2008-06-02 12:03:22 +0000 | [diff] [blame] | 84 | /* meta-queue structure: |
| 85 | * sub-queue 0: connected, kernel |
| 86 | * sub-queue 1: static |
| 87 | * sub-queue 2: RIP, RIPng, OSPF, OSPF6, IS-IS |
| 88 | * sub-queue 3: iBGP, eBGP |
| 89 | * sub-queue 4: any other origin (if any) |
| 90 | */ |
| 91 | #define MQ_SIZE 5 |
| 92 | struct meta_queue |
| 93 | { |
| 94 | struct list *subq[MQ_SIZE]; |
| 95 | u_int32_t size; /* sum of lengths of all subqueues */ |
| 96 | }; |
| 97 | |
Avneesh Sachdev | 9fd92e3 | 2012-11-13 22:48:53 +0000 | [diff] [blame] | 98 | /* |
| 99 | * Structure that represents a single destination (prefix). |
| 100 | */ |
| 101 | typedef struct rib_dest_t_ |
| 102 | { |
| 103 | |
| 104 | /* |
| 105 | * Back pointer to the route node for this destination. This helps |
| 106 | * us get to the prefix that this structure is for. |
| 107 | */ |
| 108 | struct route_node *rnode; |
| 109 | |
| 110 | /* |
| 111 | * Doubly-linked list of routes for this prefix. |
| 112 | */ |
| 113 | struct rib *routes; |
| 114 | |
| 115 | /* |
| 116 | * Flags, see below. |
| 117 | */ |
| 118 | u_int32_t flags; |
| 119 | |
Avneesh Sachdev | 5adc252 | 2012-11-13 22:48:59 +0000 | [diff] [blame] | 120 | /* |
| 121 | * Linkage to put dest on the FPM processing queue. |
| 122 | */ |
| 123 | TAILQ_ENTRY(rib_dest_t_) fpm_q_entries; |
| 124 | |
Avneesh Sachdev | 9fd92e3 | 2012-11-13 22:48:53 +0000 | [diff] [blame] | 125 | } rib_dest_t; |
| 126 | |
| 127 | #define RIB_ROUTE_QUEUED(x) (1 << (x)) |
| 128 | |
| 129 | /* |
| 130 | * The maximum qindex that can be used. |
| 131 | */ |
| 132 | #define ZEBRA_MAX_QINDEX (MQ_SIZE - 1) |
| 133 | |
| 134 | /* |
Avneesh Sachdev | 5adc252 | 2012-11-13 22:48:59 +0000 | [diff] [blame] | 135 | * This flag indicates that a given prefix has been 'advertised' to |
| 136 | * the FPM to be installed in the forwarding plane. |
| 137 | */ |
| 138 | #define RIB_DEST_SENT_TO_FPM (1 << (ZEBRA_MAX_QINDEX + 1)) |
| 139 | |
| 140 | /* |
| 141 | * This flag is set when we need to send an update to the FPM about a |
| 142 | * dest. |
| 143 | */ |
| 144 | #define RIB_DEST_UPDATE_FPM (1 << (ZEBRA_MAX_QINDEX + 2)) |
| 145 | |
| 146 | /* |
Avneesh Sachdev | 9fd92e3 | 2012-11-13 22:48:53 +0000 | [diff] [blame] | 147 | * Macro to iterate over each route for a destination (prefix). |
| 148 | */ |
| 149 | #define RIB_DEST_FOREACH_ROUTE(dest, rib) \ |
| 150 | for ((rib) = (dest) ? (dest)->routes : NULL; (rib); (rib) = (rib)->next) |
| 151 | |
| 152 | /* |
| 153 | * Same as above, but allows the current node to be unlinked. |
| 154 | */ |
| 155 | #define RIB_DEST_FOREACH_ROUTE_SAFE(dest, rib, next) \ |
| 156 | for ((rib) = (dest) ? (dest)->routes : NULL; \ |
| 157 | (rib) && ((next) = (rib)->next, 1); \ |
| 158 | (rib) = (next)) |
| 159 | |
| 160 | #define RNODE_FOREACH_RIB(rn, rib) \ |
| 161 | RIB_DEST_FOREACH_ROUTE (rib_dest_from_rnode (rn), rib) |
| 162 | |
| 163 | #define RNODE_FOREACH_RIB_SAFE(rn, rib, next) \ |
| 164 | RIB_DEST_FOREACH_ROUTE_SAFE (rib_dest_from_rnode (rn), rib, next) |
| 165 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 166 | /* Static route information. */ |
| 167 | struct static_ipv4 |
| 168 | { |
| 169 | /* For linked list. */ |
| 170 | struct static_ipv4 *prev; |
| 171 | struct static_ipv4 *next; |
| 172 | |
| 173 | /* Administrative distance. */ |
| 174 | u_char distance; |
| 175 | |
| 176 | /* Flag for this static route's type. */ |
| 177 | u_char type; |
| 178 | #define STATIC_IPV4_GATEWAY 1 |
| 179 | #define STATIC_IPV4_IFNAME 2 |
paul | 595db7f | 2003-05-25 21:35:06 +0000 | [diff] [blame] | 180 | #define STATIC_IPV4_BLACKHOLE 3 |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 181 | |
| 182 | /* Nexthop value. */ |
| 183 | union |
| 184 | { |
| 185 | struct in_addr ipv4; |
| 186 | char *ifname; |
| 187 | } gate; |
hasso | 81dfcaa | 2003-05-25 19:21:25 +0000 | [diff] [blame] | 188 | |
| 189 | /* bit flags */ |
| 190 | u_char flags; |
| 191 | /* |
| 192 | see ZEBRA_FLAG_REJECT |
| 193 | ZEBRA_FLAG_BLACKHOLE |
| 194 | */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 195 | }; |
| 196 | |
| 197 | #ifdef HAVE_IPV6 |
| 198 | /* Static route information. */ |
| 199 | struct static_ipv6 |
| 200 | { |
| 201 | /* For linked list. */ |
| 202 | struct static_ipv6 *prev; |
| 203 | struct static_ipv6 *next; |
| 204 | |
| 205 | /* Administrative distance. */ |
| 206 | u_char distance; |
| 207 | |
| 208 | /* Flag for this static route's type. */ |
| 209 | u_char type; |
| 210 | #define STATIC_IPV6_GATEWAY 1 |
| 211 | #define STATIC_IPV6_GATEWAY_IFNAME 2 |
| 212 | #define STATIC_IPV6_IFNAME 3 |
| 213 | |
| 214 | /* Nexthop value. */ |
| 215 | struct in6_addr ipv6; |
| 216 | char *ifname; |
hasso | 81dfcaa | 2003-05-25 19:21:25 +0000 | [diff] [blame] | 217 | |
| 218 | /* bit flags */ |
| 219 | u_char flags; |
| 220 | /* |
| 221 | see ZEBRA_FLAG_REJECT |
| 222 | ZEBRA_FLAG_BLACKHOLE |
| 223 | */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 224 | }; |
| 225 | #endif /* HAVE_IPV6 */ |
| 226 | |
paul | 7021c42 | 2003-07-15 12:52:22 +0000 | [diff] [blame] | 227 | enum nexthop_types_t |
| 228 | { |
| 229 | NEXTHOP_TYPE_IFINDEX = 1, /* Directly connected. */ |
| 230 | NEXTHOP_TYPE_IFNAME, /* Interface route. */ |
| 231 | NEXTHOP_TYPE_IPV4, /* IPv4 nexthop. */ |
| 232 | NEXTHOP_TYPE_IPV4_IFINDEX, /* IPv4 nexthop with ifindex. */ |
| 233 | NEXTHOP_TYPE_IPV4_IFNAME, /* IPv4 nexthop with ifname. */ |
| 234 | NEXTHOP_TYPE_IPV6, /* IPv6 nexthop. */ |
| 235 | NEXTHOP_TYPE_IPV6_IFINDEX, /* IPv6 nexthop with ifindex. */ |
| 236 | NEXTHOP_TYPE_IPV6_IFNAME, /* IPv6 nexthop with ifname. */ |
| 237 | NEXTHOP_TYPE_BLACKHOLE, /* Null0 nexthop. */ |
| 238 | }; |
| 239 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 240 | /* Nexthop structure. */ |
| 241 | struct nexthop |
| 242 | { |
| 243 | struct nexthop *next; |
| 244 | struct nexthop *prev; |
| 245 | |
Paul Jakma | e6d7d05 | 2006-03-30 13:32:09 +0000 | [diff] [blame] | 246 | /* Interface index. */ |
| 247 | char *ifname; |
| 248 | unsigned int ifindex; |
| 249 | |
paul | 7021c42 | 2003-07-15 12:52:22 +0000 | [diff] [blame] | 250 | enum nexthop_types_t type; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 251 | |
| 252 | u_char flags; |
| 253 | #define NEXTHOP_FLAG_ACTIVE (1 << 0) /* This nexthop is alive. */ |
| 254 | #define NEXTHOP_FLAG_FIB (1 << 1) /* FIB nexthop. */ |
| 255 | #define NEXTHOP_FLAG_RECURSIVE (1 << 2) /* Recursive nexthop. */ |
| 256 | |
Christian Franke | fa713d9 | 2013-07-05 15:35:37 +0000 | [diff] [blame] | 257 | /* Nexthop address */ |
Paul Jakma | 7514fb7 | 2007-05-02 16:05:35 +0000 | [diff] [blame] | 258 | union g_addr gate; |
Paul Jakma | 7514fb7 | 2007-05-02 16:05:35 +0000 | [diff] [blame] | 259 | union g_addr src; |
Christian Franke | fa713d9 | 2013-07-05 15:35:37 +0000 | [diff] [blame] | 260 | |
| 261 | /* Nexthops obtained by recursive resolution. |
| 262 | * |
| 263 | * If the nexthop struct needs to be resolved recursively, |
| 264 | * NEXTHOP_FLAG_RECURSIVE will be set in flags and the nexthops |
| 265 | * obtained by recursive resolution will be added to `resolved'. |
| 266 | * Only one level of recursive resolution is currently supported. */ |
| 267 | struct nexthop *resolved; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 268 | }; |
| 269 | |
Christian Franke | fa713d9 | 2013-07-05 15:35:37 +0000 | [diff] [blame] | 270 | /* The following for loop allows to iterate over the nexthop |
| 271 | * structure of routes. |
| 272 | * |
| 273 | * We have to maintain quite a bit of state: |
| 274 | * |
| 275 | * nexthop: The pointer to the current nexthop, either in the |
| 276 | * top-level chain or in the resolved chain of ni. |
| 277 | * tnexthop: The pointer to the current nexthop in the top-level |
| 278 | * nexthop chain. |
| 279 | * recursing: Information if nh currently is in the top-level chain |
| 280 | * (0) or in a resolved chain (1). |
| 281 | * |
| 282 | * Initialization: Set `nexthop' and `tnexthop' to the head of the |
| 283 | * top-level chain. As nexthop is in the top level chain, set recursing |
| 284 | * to 0. |
| 285 | * |
| 286 | * Iteration check: Check that the `nexthop' pointer is not NULL. |
| 287 | * |
| 288 | * Iteration step: This is the tricky part. Check if `nexthop' has |
| 289 | * NEXTHOP_FLAG_RECURSIVE set. If yes, this implies that `nexthop' is in |
| 290 | * the top level chain and has at least one nexthop attached to |
| 291 | * `nexthop->resolved'. As we want to descend into `nexthop->resolved', |
| 292 | * set `recursing' to 1 and set `nexthop' to `nexthop->resolved'. |
| 293 | * `tnexthop' is left alone in that case so we can remember which nexthop |
| 294 | * in the top level chain we are currently handling. |
| 295 | * |
| 296 | * If NEXTHOP_FLAG_RECURSIVE is not set, `nexthop' will progress in its |
| 297 | * current chain. If we are recursing, `nexthop' will be set to |
| 298 | * `nexthop->next' and `tnexthop' will be left alone. If we are not |
| 299 | * recursing, both `tnexthop' and `nexthop' will be set to `nexthop->next' |
| 300 | * as we are progressing in the top level chain. |
| 301 | * If we encounter `nexthop->next == NULL', we will clear the `recursing' |
| 302 | * flag as we arived either at the end of the resolved chain or at the end |
| 303 | * of the top level chain. In both cases, we set `tnexthop' and `nexthop' |
| 304 | * to `tnexthop->next', progressing to the next position in the top-level |
| 305 | * chain and possibly to its end marked by NULL. |
| 306 | */ |
| 307 | #define ALL_NEXTHOPS_RO(head, nexthop, tnexthop, recursing) \ |
| 308 | (tnexthop) = (nexthop) = (head), (recursing) = 0; \ |
| 309 | (nexthop); \ |
| 310 | (nexthop) = CHECK_FLAG((nexthop)->flags, NEXTHOP_FLAG_RECURSIVE) \ |
| 311 | ? (((recursing) = 1), (nexthop)->resolved) \ |
| 312 | : ((nexthop)->next ? ((recursing) ? (nexthop)->next \ |
| 313 | : ((tnexthop) = (nexthop)->next)) \ |
| 314 | : (((recursing) = 0),((tnexthop) = (tnexthop)->next))) |
| 315 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 316 | /* Routing table instance. */ |
| 317 | struct vrf |
| 318 | { |
| 319 | /* Identifier. This is same as routing table vector index. */ |
| 320 | u_int32_t id; |
| 321 | |
| 322 | /* Routing table name. */ |
| 323 | char *name; |
| 324 | |
| 325 | /* Description. */ |
| 326 | char *desc; |
| 327 | |
| 328 | /* FIB identifier. */ |
| 329 | u_char fib_id; |
| 330 | |
| 331 | /* Routing table. */ |
| 332 | struct route_table *table[AFI_MAX][SAFI_MAX]; |
| 333 | |
| 334 | /* Static route configuration. */ |
| 335 | struct route_table *stable[AFI_MAX][SAFI_MAX]; |
| 336 | }; |
| 337 | |
Avneesh Sachdev | 1b5ed1b | 2012-11-13 22:48:54 +0000 | [diff] [blame] | 338 | /* |
| 339 | * rib_table_info_t |
| 340 | * |
| 341 | * Structure that is hung off of a route_table that holds information about |
| 342 | * the table. |
| 343 | */ |
| 344 | typedef struct rib_table_info_t_ |
| 345 | { |
| 346 | |
| 347 | /* |
| 348 | * Back pointer to vrf. |
| 349 | */ |
| 350 | struct vrf *vrf; |
| 351 | afi_t afi; |
| 352 | safi_t safi; |
| 353 | |
| 354 | } rib_table_info_t; |
| 355 | |
Avneesh Sachdev | 0915bb0 | 2012-11-13 22:48:55 +0000 | [diff] [blame] | 356 | typedef enum |
| 357 | { |
| 358 | RIB_TABLES_ITER_S_INIT, |
| 359 | RIB_TABLES_ITER_S_ITERATING, |
| 360 | RIB_TABLES_ITER_S_DONE |
| 361 | } rib_tables_iter_state_t; |
| 362 | |
| 363 | /* |
| 364 | * Structure that holds state for iterating over all tables in the |
| 365 | * Routing Information Base. |
| 366 | */ |
| 367 | typedef struct rib_tables_iter_t_ |
| 368 | { |
| 369 | uint32_t vrf_id; |
| 370 | int afi_safi_ix; |
| 371 | |
| 372 | rib_tables_iter_state_t state; |
| 373 | } rib_tables_iter_t; |
| 374 | |
Avneesh Sachdev | 78deec4 | 2012-11-13 22:48:56 +0000 | [diff] [blame] | 375 | extern const char *nexthop_type_to_str (enum nexthop_types_t nh_type); |
paul | a1ac18c | 2005-06-28 17:17:12 +0000 | [diff] [blame] | 376 | extern struct nexthop *nexthop_ifindex_add (struct rib *, unsigned int); |
| 377 | extern struct nexthop *nexthop_ifname_add (struct rib *, char *); |
| 378 | extern struct nexthop *nexthop_blackhole_add (struct rib *); |
Paul Jakma | 7514fb7 | 2007-05-02 16:05:35 +0000 | [diff] [blame] | 379 | extern struct nexthop *nexthop_ipv4_add (struct rib *, struct in_addr *, |
| 380 | struct in_addr *); |
Josh Bailey | 26e2ae3 | 2012-03-22 01:09:21 -0700 | [diff] [blame] | 381 | extern struct nexthop *nexthop_ipv4_ifindex_add (struct rib *, |
| 382 | struct in_addr *, |
| 383 | struct in_addr *, |
| 384 | unsigned int); |
Christian Franke | fa713d9 | 2013-07-05 15:35:37 +0000 | [diff] [blame] | 385 | extern int nexthop_has_fib_child(struct nexthop *); |
Denis Ovsienko | dc95824 | 2007-08-13 16:03:06 +0000 | [diff] [blame] | 386 | extern void rib_lookup_and_dump (struct prefix_ipv4 *); |
Denis Ovsienko | 20e5ff0 | 2008-02-26 14:02:24 +0000 | [diff] [blame] | 387 | extern void rib_lookup_and_pushup (struct prefix_ipv4 *); |
Denis Ovsienko | dc95824 | 2007-08-13 16:03:06 +0000 | [diff] [blame] | 388 | extern void rib_dump (const char *, const struct prefix_ipv4 *, const struct rib *); |
| 389 | extern int rib_lookup_ipv4_route (struct prefix_ipv4 *, union sockunion *); |
| 390 | #define ZEBRA_RIB_LOOKUP_ERROR -1 |
| 391 | #define ZEBRA_RIB_FOUND_EXACT 0 |
| 392 | #define ZEBRA_RIB_FOUND_NOGATE 1 |
| 393 | #define ZEBRA_RIB_FOUND_CONNECTED 2 |
| 394 | #define ZEBRA_RIB_NOTFOUND 3 |
| 395 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 396 | #ifdef HAVE_IPV6 |
paul | a1ac18c | 2005-06-28 17:17:12 +0000 | [diff] [blame] | 397 | extern struct nexthop *nexthop_ipv6_add (struct rib *, struct in6_addr *); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 398 | #endif /* HAVE_IPV6 */ |
| 399 | |
paul | a1ac18c | 2005-06-28 17:17:12 +0000 | [diff] [blame] | 400 | extern struct vrf *vrf_lookup (u_int32_t); |
| 401 | extern struct route_table *vrf_table (afi_t afi, safi_t safi, u_int32_t id); |
| 402 | extern struct route_table *vrf_static_table (afi_t afi, safi_t safi, u_int32_t id); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 403 | |
hasso | d24af18 | 2005-09-24 14:00:26 +0000 | [diff] [blame] | 404 | /* NOTE: |
| 405 | * All rib_add_ipv[46]* functions will not just add prefix into RIB, but |
| 406 | * also implicitly withdraw equal prefix of same type. */ |
paul | a1ac18c | 2005-06-28 17:17:12 +0000 | [diff] [blame] | 407 | extern int rib_add_ipv4 (int type, int flags, struct prefix_ipv4 *p, |
Paul Jakma | 7514fb7 | 2007-05-02 16:05:35 +0000 | [diff] [blame] | 408 | struct in_addr *gate, struct in_addr *src, |
| 409 | unsigned int ifindex, u_int32_t vrf_id, |
G.Balaji | cddf391 | 2011-11-26 21:59:32 +0400 | [diff] [blame] | 410 | u_int32_t, u_char, safi_t); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 411 | |
G.Balaji | cddf391 | 2011-11-26 21:59:32 +0400 | [diff] [blame] | 412 | extern int rib_add_ipv4_multipath (struct prefix_ipv4 *, struct rib *, safi_t); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 413 | |
paul | a1ac18c | 2005-06-28 17:17:12 +0000 | [diff] [blame] | 414 | extern int rib_delete_ipv4 (int type, int flags, struct prefix_ipv4 *p, |
| 415 | struct in_addr *gate, unsigned int ifindex, |
G.Balaji | cddf391 | 2011-11-26 21:59:32 +0400 | [diff] [blame] | 416 | u_int32_t, safi_t safi); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 417 | |
paul | a1ac18c | 2005-06-28 17:17:12 +0000 | [diff] [blame] | 418 | extern struct rib *rib_match_ipv4 (struct in_addr); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 419 | |
paul | a1ac18c | 2005-06-28 17:17:12 +0000 | [diff] [blame] | 420 | extern struct rib *rib_lookup_ipv4 (struct prefix_ipv4 *); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 421 | |
paul | a1ac18c | 2005-06-28 17:17:12 +0000 | [diff] [blame] | 422 | extern void rib_update (void); |
| 423 | extern void rib_weed_tables (void); |
| 424 | extern void rib_sweep_route (void); |
| 425 | extern void rib_close (void); |
| 426 | extern void rib_init (void); |
Vyacheslav Trushkin | 2ea1ab1 | 2011-12-11 18:48:47 +0400 | [diff] [blame] | 427 | extern unsigned long rib_score_proto (u_char proto); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 428 | |
paul | a1ac18c | 2005-06-28 17:17:12 +0000 | [diff] [blame] | 429 | extern int |
hasso | 39db97e | 2004-10-12 20:50:58 +0000 | [diff] [blame] | 430 | static_add_ipv4 (struct prefix *p, struct in_addr *gate, const char *ifname, |
hasso | 81dfcaa | 2003-05-25 19:21:25 +0000 | [diff] [blame] | 431 | u_char flags, u_char distance, u_int32_t vrf_id); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 432 | |
paul | a1ac18c | 2005-06-28 17:17:12 +0000 | [diff] [blame] | 433 | extern int |
hasso | 39db97e | 2004-10-12 20:50:58 +0000 | [diff] [blame] | 434 | static_delete_ipv4 (struct prefix *p, struct in_addr *gate, const char *ifname, |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 435 | u_char distance, u_int32_t vrf_id); |
| 436 | |
| 437 | #ifdef HAVE_IPV6 |
paul | a1ac18c | 2005-06-28 17:17:12 +0000 | [diff] [blame] | 438 | extern int |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 439 | rib_add_ipv6 (int type, int flags, struct prefix_ipv6 *p, |
hasso | be61c4e | 2005-08-27 06:05:47 +0000 | [diff] [blame] | 440 | struct in6_addr *gate, unsigned int ifindex, u_int32_t vrf_id, |
G.Balaji | f768f36 | 2011-11-26 22:10:39 +0400 | [diff] [blame] | 441 | u_int32_t metric, u_char distance, safi_t safi); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 442 | |
paul | a1ac18c | 2005-06-28 17:17:12 +0000 | [diff] [blame] | 443 | extern int |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 444 | rib_delete_ipv6 (int type, int flags, struct prefix_ipv6 *p, |
G.Balaji | f768f36 | 2011-11-26 22:10:39 +0400 | [diff] [blame] | 445 | struct in6_addr *gate, unsigned int ifindex, u_int32_t vrf_id, safi_t safi); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 446 | |
paul | a1ac18c | 2005-06-28 17:17:12 +0000 | [diff] [blame] | 447 | extern struct rib *rib_lookup_ipv6 (struct in6_addr *); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 448 | |
paul | a1ac18c | 2005-06-28 17:17:12 +0000 | [diff] [blame] | 449 | extern struct rib *rib_match_ipv6 (struct in6_addr *); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 450 | |
| 451 | extern struct route_table *rib_table_ipv6; |
| 452 | |
paul | a1ac18c | 2005-06-28 17:17:12 +0000 | [diff] [blame] | 453 | extern int |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 454 | static_add_ipv6 (struct prefix *p, u_char type, struct in6_addr *gate, |
hasso | 39db97e | 2004-10-12 20:50:58 +0000 | [diff] [blame] | 455 | const char *ifname, u_char flags, u_char distance, |
| 456 | u_int32_t vrf_id); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 457 | |
paul | a1ac18c | 2005-06-28 17:17:12 +0000 | [diff] [blame] | 458 | extern int |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 459 | static_delete_ipv6 (struct prefix *p, u_char type, struct in6_addr *gate, |
hasso | 39db97e | 2004-10-12 20:50:58 +0000 | [diff] [blame] | 460 | const char *ifname, u_char distance, u_int32_t vrf_id); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 461 | |
| 462 | #endif /* HAVE_IPV6 */ |
| 463 | |
Avneesh Sachdev | 9fd92e3 | 2012-11-13 22:48:53 +0000 | [diff] [blame] | 464 | extern int rib_gc_dest (struct route_node *rn); |
Avneesh Sachdev | 0915bb0 | 2012-11-13 22:48:55 +0000 | [diff] [blame] | 465 | extern struct route_table *rib_tables_iter_next (rib_tables_iter_t *iter); |
Avneesh Sachdev | 9fd92e3 | 2012-11-13 22:48:53 +0000 | [diff] [blame] | 466 | |
| 467 | /* |
| 468 | * Inline functions. |
| 469 | */ |
| 470 | |
| 471 | /* |
Avneesh Sachdev | 1b5ed1b | 2012-11-13 22:48:54 +0000 | [diff] [blame] | 472 | * rib_table_info |
| 473 | */ |
| 474 | static inline rib_table_info_t * |
| 475 | rib_table_info (struct route_table *table) |
| 476 | { |
| 477 | return (rib_table_info_t *) table->info; |
| 478 | } |
| 479 | |
| 480 | /* |
Avneesh Sachdev | 9fd92e3 | 2012-11-13 22:48:53 +0000 | [diff] [blame] | 481 | * rib_dest_from_rnode |
| 482 | */ |
| 483 | static inline rib_dest_t * |
| 484 | rib_dest_from_rnode (struct route_node *rn) |
| 485 | { |
| 486 | return (rib_dest_t *) rn->info; |
| 487 | } |
| 488 | |
| 489 | /* |
| 490 | * rnode_to_ribs |
| 491 | * |
| 492 | * Returns a pointer to the list of routes corresponding to the given |
| 493 | * route_node. |
| 494 | */ |
| 495 | static inline struct rib * |
| 496 | rnode_to_ribs (struct route_node *rn) |
| 497 | { |
| 498 | rib_dest_t *dest; |
| 499 | |
| 500 | dest = rib_dest_from_rnode (rn); |
| 501 | if (!dest) |
| 502 | return NULL; |
| 503 | |
| 504 | return dest->routes; |
| 505 | } |
| 506 | |
| 507 | /* |
| 508 | * rib_dest_prefix |
| 509 | */ |
| 510 | static inline struct prefix * |
| 511 | rib_dest_prefix (rib_dest_t *dest) |
| 512 | { |
| 513 | return &dest->rnode->p; |
| 514 | } |
| 515 | |
| 516 | /* |
| 517 | * rib_dest_af |
| 518 | * |
| 519 | * Returns the address family that the destination is for. |
| 520 | */ |
| 521 | static inline u_char |
| 522 | rib_dest_af (rib_dest_t *dest) |
| 523 | { |
| 524 | return dest->rnode->p.family; |
| 525 | } |
| 526 | |
| 527 | /* |
| 528 | * rib_dest_table |
| 529 | */ |
| 530 | static inline struct route_table * |
| 531 | rib_dest_table (rib_dest_t *dest) |
| 532 | { |
| 533 | return dest->rnode->table; |
| 534 | } |
| 535 | |
Avneesh Sachdev | 1b5ed1b | 2012-11-13 22:48:54 +0000 | [diff] [blame] | 536 | /* |
| 537 | * rib_dest_vrf |
| 538 | */ |
| 539 | static inline struct vrf * |
| 540 | rib_dest_vrf (rib_dest_t *dest) |
| 541 | { |
| 542 | return rib_table_info (rib_dest_table (dest))->vrf; |
| 543 | } |
| 544 | |
Avneesh Sachdev | 0915bb0 | 2012-11-13 22:48:55 +0000 | [diff] [blame] | 545 | /* |
| 546 | * rib_tables_iter_init |
| 547 | */ |
| 548 | static inline void |
| 549 | rib_tables_iter_init (rib_tables_iter_t *iter) |
| 550 | |
| 551 | { |
| 552 | memset (iter, 0, sizeof (*iter)); |
| 553 | iter->state = RIB_TABLES_ITER_S_INIT; |
| 554 | } |
| 555 | |
| 556 | /* |
| 557 | * rib_tables_iter_started |
| 558 | * |
| 559 | * Returns TRUE if this iterator has started iterating over the set of |
| 560 | * tables. |
| 561 | */ |
| 562 | static inline int |
| 563 | rib_tables_iter_started (rib_tables_iter_t *iter) |
| 564 | { |
| 565 | return iter->state != RIB_TABLES_ITER_S_INIT; |
| 566 | } |
| 567 | |
| 568 | /* |
| 569 | * rib_tables_iter_cleanup |
| 570 | */ |
| 571 | static inline void |
| 572 | rib_tables_iter_cleanup (rib_tables_iter_t *iter) |
| 573 | { |
| 574 | iter->state = RIB_TABLES_ITER_S_DONE; |
| 575 | } |
| 576 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 577 | #endif /*_ZEBRA_RIB_H */ |