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