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 | |
Feng Lu | ac19a44 | 2015-05-22 11:40:07 +0200 | [diff] [blame] | 26 | #include "linklist.h" |
paul | ec1a428 | 2005-11-24 15:15:17 +0000 | [diff] [blame] | 27 | #include "prefix.h" |
Avneesh Sachdev | 9fd92e3 | 2012-11-13 22:48:53 +0000 | [diff] [blame] | 28 | #include "table.h" |
Avneesh Sachdev | 5adc252 | 2012-11-13 22:48:59 +0000 | [diff] [blame] | 29 | #include "queue.h" |
Pradosh Mohapatra | 60cc959 | 2015-11-09 20:21:41 -0500 | [diff] [blame] | 30 | #include "nexthop.h" |
paul | ec1a428 | 2005-11-24 15:15:17 +0000 | [diff] [blame] | 31 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 32 | #define DISTANCE_INFINITY 255 |
| 33 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 34 | struct rib |
| 35 | { |
| 36 | /* Link list. */ |
| 37 | struct rib *next; |
| 38 | struct rib *prev; |
Paul Jakma | e6d7d05 | 2006-03-30 13:32:09 +0000 | [diff] [blame] | 39 | |
| 40 | /* Nexthop structure */ |
| 41 | struct nexthop *nexthop; |
| 42 | |
| 43 | /* Refrence count. */ |
| 44 | unsigned long refcnt; |
| 45 | |
| 46 | /* Uptime. */ |
| 47 | time_t uptime; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 48 | |
| 49 | /* Type fo this route. */ |
| 50 | int type; |
| 51 | |
Feng Lu | 0d0686f | 2015-05-22 11:40:02 +0200 | [diff] [blame] | 52 | /* VRF identifier. */ |
| 53 | vrf_id_t vrf_id; |
| 54 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 55 | /* Which routing table */ |
| 56 | int table; |
| 57 | |
Paul Jakma | e6d7d05 | 2006-03-30 13:32:09 +0000 | [diff] [blame] | 58 | /* Metric */ |
| 59 | u_int32_t metric; |
| 60 | |
Timo Teräs | b11f3b5 | 2015-11-02 16:50:07 +0200 | [diff] [blame] | 61 | /* MTU */ |
| 62 | u_int32_t mtu; |
| 63 | u_int32_t nexthop_mtu; |
| 64 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 65 | /* Distance. */ |
| 66 | u_char distance; |
| 67 | |
Piotr Chytła | de24f82 | 2007-06-28 00:09:28 +0200 | [diff] [blame] | 68 | /* Tag */ |
| 69 | u_short tag; |
| 70 | |
Paul Jakma | 6d69112 | 2006-07-27 21:49:00 +0000 | [diff] [blame] | 71 | /* Flags of this route. |
| 72 | * This flag's definition is in lib/zebra.h ZEBRA_FLAG_* and is exposed |
| 73 | * to clients via Zserv |
| 74 | */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 75 | u_char flags; |
| 76 | |
Paul Jakma | 6d69112 | 2006-07-27 21:49:00 +0000 | [diff] [blame] | 77 | /* RIB internal status */ |
| 78 | u_char status; |
| 79 | #define RIB_ENTRY_REMOVED (1 << 0) |
Timo Teräs | 7eb6136 | 2015-11-02 16:50:05 +0200 | [diff] [blame] | 80 | #define RIB_ENTRY_CHANGED (1 << 1) |
Timo Teräs | 325823a | 2016-01-15 17:36:31 +0200 | [diff] [blame] | 81 | #define RIB_ENTRY_SELECTED_FIB (1 << 2) |
Paul Jakma | 6d69112 | 2006-07-27 21:49:00 +0000 | [diff] [blame] | 82 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 83 | /* Nexthop information. */ |
| 84 | u_char nexthop_num; |
| 85 | u_char nexthop_active_num; |
| 86 | u_char nexthop_fib_num; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 87 | }; |
| 88 | |
Denis Ovsienko | e96f920 | 2008-06-02 12:03:22 +0000 | [diff] [blame] | 89 | /* meta-queue structure: |
| 90 | * sub-queue 0: connected, kernel |
| 91 | * sub-queue 1: static |
| 92 | * sub-queue 2: RIP, RIPng, OSPF, OSPF6, IS-IS |
| 93 | * sub-queue 3: iBGP, eBGP |
| 94 | * sub-queue 4: any other origin (if any) |
| 95 | */ |
| 96 | #define MQ_SIZE 5 |
| 97 | struct meta_queue |
| 98 | { |
| 99 | struct list *subq[MQ_SIZE]; |
| 100 | u_int32_t size; /* sum of lengths of all subqueues */ |
| 101 | }; |
| 102 | |
Avneesh Sachdev | 9fd92e3 | 2012-11-13 22:48:53 +0000 | [diff] [blame] | 103 | /* |
| 104 | * Structure that represents a single destination (prefix). |
| 105 | */ |
| 106 | typedef struct rib_dest_t_ |
| 107 | { |
| 108 | |
| 109 | /* |
| 110 | * Back pointer to the route node for this destination. This helps |
| 111 | * us get to the prefix that this structure is for. |
| 112 | */ |
| 113 | struct route_node *rnode; |
| 114 | |
| 115 | /* |
| 116 | * Doubly-linked list of routes for this prefix. |
| 117 | */ |
| 118 | struct rib *routes; |
| 119 | |
| 120 | /* |
| 121 | * Flags, see below. |
| 122 | */ |
| 123 | u_int32_t flags; |
| 124 | |
Avneesh Sachdev | 5adc252 | 2012-11-13 22:48:59 +0000 | [diff] [blame] | 125 | /* |
| 126 | * Linkage to put dest on the FPM processing queue. |
| 127 | */ |
| 128 | TAILQ_ENTRY(rib_dest_t_) fpm_q_entries; |
| 129 | |
Avneesh Sachdev | 9fd92e3 | 2012-11-13 22:48:53 +0000 | [diff] [blame] | 130 | } rib_dest_t; |
| 131 | |
| 132 | #define RIB_ROUTE_QUEUED(x) (1 << (x)) |
| 133 | |
| 134 | /* |
| 135 | * The maximum qindex that can be used. |
| 136 | */ |
| 137 | #define ZEBRA_MAX_QINDEX (MQ_SIZE - 1) |
| 138 | |
| 139 | /* |
Avneesh Sachdev | 5adc252 | 2012-11-13 22:48:59 +0000 | [diff] [blame] | 140 | * This flag indicates that a given prefix has been 'advertised' to |
| 141 | * the FPM to be installed in the forwarding plane. |
| 142 | */ |
| 143 | #define RIB_DEST_SENT_TO_FPM (1 << (ZEBRA_MAX_QINDEX + 1)) |
| 144 | |
| 145 | /* |
| 146 | * This flag is set when we need to send an update to the FPM about a |
| 147 | * dest. |
| 148 | */ |
| 149 | #define RIB_DEST_UPDATE_FPM (1 << (ZEBRA_MAX_QINDEX + 2)) |
| 150 | |
| 151 | /* |
Avneesh Sachdev | 9fd92e3 | 2012-11-13 22:48:53 +0000 | [diff] [blame] | 152 | * Macro to iterate over each route for a destination (prefix). |
| 153 | */ |
| 154 | #define RIB_DEST_FOREACH_ROUTE(dest, rib) \ |
| 155 | for ((rib) = (dest) ? (dest)->routes : NULL; (rib); (rib) = (rib)->next) |
| 156 | |
| 157 | /* |
| 158 | * Same as above, but allows the current node to be unlinked. |
| 159 | */ |
| 160 | #define RIB_DEST_FOREACH_ROUTE_SAFE(dest, rib, next) \ |
| 161 | for ((rib) = (dest) ? (dest)->routes : NULL; \ |
| 162 | (rib) && ((next) = (rib)->next, 1); \ |
| 163 | (rib) = (next)) |
| 164 | |
| 165 | #define RNODE_FOREACH_RIB(rn, rib) \ |
| 166 | RIB_DEST_FOREACH_ROUTE (rib_dest_from_rnode (rn), rib) |
| 167 | |
| 168 | #define RNODE_FOREACH_RIB_SAFE(rn, rib, next) \ |
| 169 | RIB_DEST_FOREACH_ROUTE_SAFE (rib_dest_from_rnode (rn), rib, next) |
| 170 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 171 | /* Static route information. */ |
Donald Sharp | d4c27d6 | 2015-11-04 13:26:35 -0500 | [diff] [blame] | 172 | struct static_route |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 173 | { |
| 174 | /* For linked list. */ |
Donald Sharp | d4c27d6 | 2015-11-04 13:26:35 -0500 | [diff] [blame] | 175 | struct static_route *prev; |
| 176 | struct static_route *next; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 177 | |
Feng Lu | 7aaf4ea | 2015-05-22 11:40:06 +0200 | [diff] [blame] | 178 | /* VRF identifier. */ |
| 179 | vrf_id_t vrf_id; |
| 180 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 181 | /* Administrative distance. */ |
| 182 | u_char distance; |
| 183 | |
Piotr Chytła | de24f82 | 2007-06-28 00:09:28 +0200 | [diff] [blame] | 184 | /* Tag */ |
| 185 | u_short tag; |
| 186 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 187 | /* Flag for this static route's type. */ |
| 188 | u_char type; |
Donald Sharp | d4c27d6 | 2015-11-04 13:26:35 -0500 | [diff] [blame] | 189 | #define STATIC_IPV4_GATEWAY 1 |
| 190 | #define STATIC_IPV4_IFNAME 2 |
| 191 | #define STATIC_IPV4_BLACKHOLE 3 |
| 192 | #define STATIC_IPV6_GATEWAY 4 |
| 193 | #define STATIC_IPV6_GATEWAY_IFNAME 5 |
| 194 | #define STATIC_IPV6_IFNAME 6 |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 195 | |
| 196 | /* Nexthop value. */ |
Donald Sharp | d4c27d6 | 2015-11-04 13:26:35 -0500 | [diff] [blame] | 197 | union g_addr addr; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 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 | }; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 207 | |
Christian Franke | fa713d9 | 2013-07-05 15:35:37 +0000 | [diff] [blame] | 208 | /* The following for loop allows to iterate over the nexthop |
| 209 | * structure of routes. |
| 210 | * |
| 211 | * We have to maintain quite a bit of state: |
| 212 | * |
| 213 | * nexthop: The pointer to the current nexthop, either in the |
| 214 | * top-level chain or in the resolved chain of ni. |
| 215 | * tnexthop: The pointer to the current nexthop in the top-level |
| 216 | * nexthop chain. |
| 217 | * recursing: Information if nh currently is in the top-level chain |
| 218 | * (0) or in a resolved chain (1). |
| 219 | * |
| 220 | * Initialization: Set `nexthop' and `tnexthop' to the head of the |
| 221 | * top-level chain. As nexthop is in the top level chain, set recursing |
| 222 | * to 0. |
| 223 | * |
| 224 | * Iteration check: Check that the `nexthop' pointer is not NULL. |
| 225 | * |
| 226 | * Iteration step: This is the tricky part. Check if `nexthop' has |
| 227 | * NEXTHOP_FLAG_RECURSIVE set. If yes, this implies that `nexthop' is in |
| 228 | * the top level chain and has at least one nexthop attached to |
| 229 | * `nexthop->resolved'. As we want to descend into `nexthop->resolved', |
| 230 | * set `recursing' to 1 and set `nexthop' to `nexthop->resolved'. |
| 231 | * `tnexthop' is left alone in that case so we can remember which nexthop |
| 232 | * in the top level chain we are currently handling. |
| 233 | * |
| 234 | * If NEXTHOP_FLAG_RECURSIVE is not set, `nexthop' will progress in its |
| 235 | * current chain. If we are recursing, `nexthop' will be set to |
| 236 | * `nexthop->next' and `tnexthop' will be left alone. If we are not |
| 237 | * recursing, both `tnexthop' and `nexthop' will be set to `nexthop->next' |
| 238 | * as we are progressing in the top level chain. |
| 239 | * If we encounter `nexthop->next == NULL', we will clear the `recursing' |
| 240 | * flag as we arived either at the end of the resolved chain or at the end |
| 241 | * of the top level chain. In both cases, we set `tnexthop' and `nexthop' |
| 242 | * to `tnexthop->next', progressing to the next position in the top-level |
| 243 | * chain and possibly to its end marked by NULL. |
| 244 | */ |
| 245 | #define ALL_NEXTHOPS_RO(head, nexthop, tnexthop, recursing) \ |
| 246 | (tnexthop) = (nexthop) = (head), (recursing) = 0; \ |
| 247 | (nexthop); \ |
| 248 | (nexthop) = CHECK_FLAG((nexthop)->flags, NEXTHOP_FLAG_RECURSIVE) \ |
| 249 | ? (((recursing) = 1), (nexthop)->resolved) \ |
| 250 | : ((nexthop)->next ? ((recursing) ? (nexthop)->next \ |
| 251 | : ((tnexthop) = (nexthop)->next)) \ |
| 252 | : (((recursing) = 0),((tnexthop) = (tnexthop)->next))) |
| 253 | |
Feng Lu | 1885d0a | 2015-05-22 11:40:04 +0200 | [diff] [blame] | 254 | /* Structure holding nexthop & VRF identifier, |
| 255 | * used for applying the route-map. */ |
| 256 | struct nexthop_vrfid |
| 257 | { |
| 258 | struct nexthop *nexthop; |
| 259 | vrf_id_t vrf_id; |
| 260 | }; |
| 261 | |
Feng Lu | 49f7609 | 2015-05-22 11:40:10 +0200 | [diff] [blame] | 262 | |
Donald Sharp | 6425773 | 2015-11-20 08:33:30 -0500 | [diff] [blame] | 263 | #if defined (HAVE_RTADV) |
Feng Lu | 49f7609 | 2015-05-22 11:40:10 +0200 | [diff] [blame] | 264 | /* Structure which hold status of router advertisement. */ |
| 265 | struct rtadv |
| 266 | { |
| 267 | int sock; |
| 268 | |
| 269 | int adv_if_count; |
| 270 | int adv_msec_if_count; |
| 271 | |
| 272 | struct thread *ra_read; |
| 273 | struct thread *ra_timer; |
| 274 | }; |
Donald Sharp | 6425773 | 2015-11-20 08:33:30 -0500 | [diff] [blame] | 275 | #endif /* HAVE_RTADV */ |
Feng Lu | 49f7609 | 2015-05-22 11:40:10 +0200 | [diff] [blame] | 276 | |
Feng Lu | 758fb8f | 2014-07-03 18:23:09 +0800 | [diff] [blame] | 277 | #ifdef HAVE_NETLINK |
| 278 | /* Socket interface to kernel */ |
| 279 | struct nlsock |
| 280 | { |
| 281 | int sock; |
| 282 | int seq; |
| 283 | struct sockaddr_nl snl; |
| 284 | const char *name; |
| 285 | }; |
| 286 | #endif |
| 287 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 288 | /* Routing table instance. */ |
Feng Lu | 41f44a2 | 2015-05-22 11:39:56 +0200 | [diff] [blame] | 289 | struct zebra_vrf |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 290 | { |
Feng Lu | 41f44a2 | 2015-05-22 11:39:56 +0200 | [diff] [blame] | 291 | /* Identifier. */ |
| 292 | vrf_id_t vrf_id; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 293 | |
| 294 | /* Routing table name. */ |
| 295 | char *name; |
| 296 | |
| 297 | /* Description. */ |
| 298 | char *desc; |
| 299 | |
| 300 | /* FIB identifier. */ |
| 301 | u_char fib_id; |
| 302 | |
| 303 | /* Routing table. */ |
| 304 | struct route_table *table[AFI_MAX][SAFI_MAX]; |
| 305 | |
| 306 | /* Static route configuration. */ |
| 307 | struct route_table *stable[AFI_MAX][SAFI_MAX]; |
Feng Lu | ac19a44 | 2015-05-22 11:40:07 +0200 | [diff] [blame] | 308 | |
Feng Lu | 758fb8f | 2014-07-03 18:23:09 +0800 | [diff] [blame] | 309 | #ifdef HAVE_NETLINK |
| 310 | struct nlsock netlink; /* kernel messages */ |
| 311 | struct nlsock netlink_cmd; /* command channel */ |
| 312 | struct thread *t_netlink; |
| 313 | #endif |
| 314 | |
Feng Lu | ac19a44 | 2015-05-22 11:40:07 +0200 | [diff] [blame] | 315 | /* 2nd pointer type used primarily to quell a warning on |
| 316 | * ALL_LIST_ELEMENTS_RO |
| 317 | */ |
| 318 | struct list _rid_all_sorted_list; |
| 319 | struct list _rid_lo_sorted_list; |
| 320 | struct list *rid_all_sorted_list; |
| 321 | struct list *rid_lo_sorted_list; |
| 322 | struct prefix rid_user_assigned; |
Feng Lu | 49f7609 | 2015-05-22 11:40:10 +0200 | [diff] [blame] | 323 | |
Donald Sharp | 6425773 | 2015-11-20 08:33:30 -0500 | [diff] [blame] | 324 | #if defined (HAVE_RTADV) |
Feng Lu | 49f7609 | 2015-05-22 11:40:10 +0200 | [diff] [blame] | 325 | struct rtadv rtadv; |
Donald Sharp | 6425773 | 2015-11-20 08:33:30 -0500 | [diff] [blame] | 326 | #endif /* HAVE_RTADV */ |
Pradosh Mohapatra | 60cc959 | 2015-11-09 20:21:41 -0500 | [diff] [blame] | 327 | |
| 328 | /* Recursive Nexthop table */ |
| 329 | struct route_table *rnh_table[AFI_MAX]; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 330 | }; |
| 331 | |
Avneesh Sachdev | 1b5ed1b | 2012-11-13 22:48:54 +0000 | [diff] [blame] | 332 | /* |
| 333 | * rib_table_info_t |
| 334 | * |
| 335 | * Structure that is hung off of a route_table that holds information about |
| 336 | * the table. |
| 337 | */ |
| 338 | typedef struct rib_table_info_t_ |
| 339 | { |
| 340 | |
| 341 | /* |
Feng Lu | 41f44a2 | 2015-05-22 11:39:56 +0200 | [diff] [blame] | 342 | * Back pointer to zebra_vrf. |
Avneesh Sachdev | 1b5ed1b | 2012-11-13 22:48:54 +0000 | [diff] [blame] | 343 | */ |
Feng Lu | 41f44a2 | 2015-05-22 11:39:56 +0200 | [diff] [blame] | 344 | struct zebra_vrf *zvrf; |
Avneesh Sachdev | 1b5ed1b | 2012-11-13 22:48:54 +0000 | [diff] [blame] | 345 | afi_t afi; |
| 346 | safi_t safi; |
| 347 | |
| 348 | } rib_table_info_t; |
| 349 | |
Avneesh Sachdev | 0915bb0 | 2012-11-13 22:48:55 +0000 | [diff] [blame] | 350 | typedef enum |
| 351 | { |
| 352 | RIB_TABLES_ITER_S_INIT, |
| 353 | RIB_TABLES_ITER_S_ITERATING, |
| 354 | RIB_TABLES_ITER_S_DONE |
| 355 | } rib_tables_iter_state_t; |
| 356 | |
| 357 | /* |
| 358 | * Structure that holds state for iterating over all tables in the |
| 359 | * Routing Information Base. |
| 360 | */ |
| 361 | typedef struct rib_tables_iter_t_ |
| 362 | { |
Feng Lu | 41f44a2 | 2015-05-22 11:39:56 +0200 | [diff] [blame] | 363 | vrf_id_t vrf_id; |
Avneesh Sachdev | 0915bb0 | 2012-11-13 22:48:55 +0000 | [diff] [blame] | 364 | int afi_safi_ix; |
| 365 | |
| 366 | rib_tables_iter_state_t state; |
| 367 | } rib_tables_iter_t; |
| 368 | |
David Lamparter | bd07812 | 2015-01-06 19:53:24 +0100 | [diff] [blame] | 369 | /* RPF lookup behaviour */ |
| 370 | enum multicast_mode |
| 371 | { |
| 372 | MCAST_NO_CONFIG = 0, /* MIX_MRIB_FIRST, but no show in config write */ |
| 373 | MCAST_MRIB_ONLY, /* MRIB only */ |
| 374 | MCAST_URIB_ONLY, /* URIB only */ |
| 375 | MCAST_MIX_MRIB_FIRST, /* MRIB, if nothing at all then URIB */ |
| 376 | MCAST_MIX_DISTANCE, /* MRIB & URIB, lower distance wins */ |
| 377 | MCAST_MIX_PFXLEN, /* MRIB & URIB, longer prefix wins */ |
| 378 | /* on equal value, MRIB wins for last 2 */ |
| 379 | }; |
| 380 | |
| 381 | extern void multicast_mode_ipv4_set (enum multicast_mode mode); |
| 382 | extern enum multicast_mode multicast_mode_ipv4_get (void); |
| 383 | |
Avneesh Sachdev | 78deec4 | 2012-11-13 22:48:56 +0000 | [diff] [blame] | 384 | extern const char *nexthop_type_to_str (enum nexthop_types_t nh_type); |
Pradosh Mohapatra | 60cc959 | 2015-11-09 20:21:41 -0500 | [diff] [blame] | 385 | extern struct nexthop *rib_nexthop_ifindex_add (struct rib *, ifindex_t); |
| 386 | extern struct nexthop *rib_nexthop_ifname_add (struct rib *, char *); |
| 387 | extern struct nexthop *rib_nexthop_blackhole_add (struct rib *); |
| 388 | extern struct nexthop *rib_nexthop_ipv4_add (struct rib *, struct in_addr *, |
| 389 | struct in_addr *); |
| 390 | extern struct nexthop *rib_nexthop_ipv4_ifindex_add (struct rib *, |
| 391 | struct in_addr *, |
| 392 | struct in_addr *, |
| 393 | ifindex_t); |
| 394 | |
| 395 | extern void rib_nexthop_add (struct rib *rib, struct nexthop *nexthop); |
| 396 | |
Christian Franke | fa713d9 | 2013-07-05 15:35:37 +0000 | [diff] [blame] | 397 | extern int nexthop_has_fib_child(struct nexthop *); |
Denis Ovsienko | dc95824 | 2007-08-13 16:03:06 +0000 | [diff] [blame] | 398 | extern void rib_lookup_and_dump (struct prefix_ipv4 *); |
David Lamparter | f7bf415 | 2013-10-22 17:10:21 +0000 | [diff] [blame] | 399 | #define rib_dump(prefix ,rib) _rib_dump(__func__, prefix, rib) |
| 400 | extern void _rib_dump (const char *, |
| 401 | union prefix46constptr, const struct rib *); |
Feng Lu | 0d0686f | 2015-05-22 11:40:02 +0200 | [diff] [blame] | 402 | extern int rib_lookup_ipv4_route (struct prefix_ipv4 *, union sockunion *, |
| 403 | vrf_id_t); |
Denis Ovsienko | dc95824 | 2007-08-13 16:03:06 +0000 | [diff] [blame] | 404 | #define ZEBRA_RIB_LOOKUP_ERROR -1 |
| 405 | #define ZEBRA_RIB_FOUND_EXACT 0 |
| 406 | #define ZEBRA_RIB_FOUND_NOGATE 1 |
| 407 | #define ZEBRA_RIB_FOUND_CONNECTED 2 |
| 408 | #define ZEBRA_RIB_NOTFOUND 3 |
| 409 | |
Pradosh Mohapatra | 60cc959 | 2015-11-09 20:21:41 -0500 | [diff] [blame] | 410 | extern struct nexthop *rib_nexthop_ipv6_add (struct rib *, struct in6_addr *); |
| 411 | extern struct nexthop *rib_nexthop_ipv6_ifindex_add (struct rib *, |
| 412 | struct in6_addr *, |
| 413 | ifindex_t); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 414 | |
Pradosh Mohapatra | 60cc959 | 2015-11-09 20:21:41 -0500 | [diff] [blame] | 415 | extern struct zebra_vrf *zebra_vrf_lookup (vrf_id_t vrf_id); |
Feng Lu | 41f44a2 | 2015-05-22 11:39:56 +0200 | [diff] [blame] | 416 | extern struct zebra_vrf *zebra_vrf_alloc (vrf_id_t); |
| 417 | extern struct route_table *zebra_vrf_table (afi_t, safi_t, vrf_id_t); |
| 418 | extern struct route_table *zebra_vrf_static_table (afi_t, safi_t, vrf_id_t); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 419 | |
hasso | d24af18 | 2005-09-24 14:00:26 +0000 | [diff] [blame] | 420 | /* NOTE: |
| 421 | * All rib_add_ipv[46]* functions will not just add prefix into RIB, but |
| 422 | * also implicitly withdraw equal prefix of same type. */ |
paul | a1ac18c | 2005-06-28 17:17:12 +0000 | [diff] [blame] | 423 | 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] | 424 | struct in_addr *gate, struct in_addr *src, |
Paul Jakma | 9099f9b | 2016-01-18 10:12:10 +0000 | [diff] [blame] | 425 | ifindex_t ifindex, vrf_id_t vrf_id, int table_id, |
Timo Teräs | b11f3b5 | 2015-11-02 16:50:07 +0200 | [diff] [blame] | 426 | u_int32_t, u_int32_t, u_char, safi_t); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 427 | |
G.Balaji | cddf391 | 2011-11-26 21:59:32 +0400 | [diff] [blame] | 428 | extern int rib_add_ipv4_multipath (struct prefix_ipv4 *, struct rib *, safi_t); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 429 | |
paul | a1ac18c | 2005-06-28 17:17:12 +0000 | [diff] [blame] | 430 | extern int rib_delete_ipv4 (int type, int flags, struct prefix_ipv4 *p, |
Paul Jakma | 9099f9b | 2016-01-18 10:12:10 +0000 | [diff] [blame] | 431 | struct in_addr *gate, ifindex_t ifindex, |
Feng Lu | 0d0686f | 2015-05-22 11:40:02 +0200 | [diff] [blame] | 432 | vrf_id_t, safi_t safi); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 433 | |
David Lamparter | 24480d4 | 2015-01-22 19:09:36 +0100 | [diff] [blame] | 434 | extern struct rib *rib_match_ipv4_safi (struct in_addr addr, safi_t safi, |
Feng Lu | 0d0686f | 2015-05-22 11:40:02 +0200 | [diff] [blame] | 435 | int skip_bgp, struct route_node **rn_out, |
| 436 | vrf_id_t); |
David Lamparter | bd07812 | 2015-01-06 19:53:24 +0100 | [diff] [blame] | 437 | extern struct rib *rib_match_ipv4_multicast (struct in_addr addr, |
Feng Lu | 0d0686f | 2015-05-22 11:40:02 +0200 | [diff] [blame] | 438 | struct route_node **rn_out, |
| 439 | vrf_id_t); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 440 | |
Feng Lu | 0d0686f | 2015-05-22 11:40:02 +0200 | [diff] [blame] | 441 | extern struct rib *rib_lookup_ipv4 (struct prefix_ipv4 *, vrf_id_t); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 442 | |
Feng Lu | 0d0686f | 2015-05-22 11:40:02 +0200 | [diff] [blame] | 443 | extern void rib_update (vrf_id_t); |
paul | a1ac18c | 2005-06-28 17:17:12 +0000 | [diff] [blame] | 444 | extern void rib_weed_tables (void); |
| 445 | extern void rib_sweep_route (void); |
Feng Lu | 267ceb2 | 2015-05-22 11:40:09 +0200 | [diff] [blame] | 446 | extern void rib_close_table (struct route_table *); |
paul | a1ac18c | 2005-06-28 17:17:12 +0000 | [diff] [blame] | 447 | extern void rib_close (void); |
| 448 | extern void rib_init (void); |
Vyacheslav Trushkin | 2ea1ab1 | 2011-12-11 18:48:47 +0400 | [diff] [blame] | 449 | extern unsigned long rib_score_proto (u_char proto); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 450 | |
paul | a1ac18c | 2005-06-28 17:17:12 +0000 | [diff] [blame] | 451 | extern int |
Everton Marques | 33d86db | 2014-07-14 11:19:00 -0300 | [diff] [blame] | 452 | static_add_ipv4_safi (safi_t safi, struct prefix *p, struct in_addr *gate, |
Piotr Chytła | de24f82 | 2007-06-28 00:09:28 +0200 | [diff] [blame] | 453 | const char *ifname, u_char flags, u_short tag, u_char distance, |
Feng Lu | 0d0686f | 2015-05-22 11:40:02 +0200 | [diff] [blame] | 454 | vrf_id_t vrf_id); |
paul | a1ac18c | 2005-06-28 17:17:12 +0000 | [diff] [blame] | 455 | extern int |
Everton Marques | 33d86db | 2014-07-14 11:19:00 -0300 | [diff] [blame] | 456 | static_delete_ipv4_safi (safi_t safi, struct prefix *p, struct in_addr *gate, |
Piotr Chytła | de24f82 | 2007-06-28 00:09:28 +0200 | [diff] [blame] | 457 | const char *ifname, u_short tag, u_char distance, vrf_id_t vrf_id); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 458 | |
paul | a1ac18c | 2005-06-28 17:17:12 +0000 | [diff] [blame] | 459 | extern int |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 460 | rib_add_ipv6 (int type, int flags, struct prefix_ipv6 *p, |
Paul Jakma | 9099f9b | 2016-01-18 10:12:10 +0000 | [diff] [blame] | 461 | struct in6_addr *gate, ifindex_t ifindex, vrf_id_t vrf_id, |
Timo Teräs | b11f3b5 | 2015-11-02 16:50:07 +0200 | [diff] [blame] | 462 | int table_id, u_int32_t metric, u_int32_t mtu, |
| 463 | u_char distance, safi_t safi); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 464 | |
paul | a1ac18c | 2005-06-28 17:17:12 +0000 | [diff] [blame] | 465 | extern int |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 466 | rib_delete_ipv6 (int type, int flags, struct prefix_ipv6 *p, |
Paul Jakma | 9099f9b | 2016-01-18 10:12:10 +0000 | [diff] [blame] | 467 | struct in6_addr *gate, ifindex_t ifindex, vrf_id_t vrf_id, safi_t safi); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 468 | |
Feng Lu | 0d0686f | 2015-05-22 11:40:02 +0200 | [diff] [blame] | 469 | extern struct rib *rib_lookup_ipv6 (struct in6_addr *, vrf_id_t); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 470 | |
Feng Lu | 0d0686f | 2015-05-22 11:40:02 +0200 | [diff] [blame] | 471 | extern struct rib *rib_match_ipv6 (struct in6_addr *, vrf_id_t); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 472 | |
| 473 | extern struct route_table *rib_table_ipv6; |
| 474 | |
paul | a1ac18c | 2005-06-28 17:17:12 +0000 | [diff] [blame] | 475 | extern int |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 476 | static_add_ipv6 (struct prefix *p, u_char type, struct in6_addr *gate, |
Piotr Chytła | de24f82 | 2007-06-28 00:09:28 +0200 | [diff] [blame] | 477 | const char *ifname, u_char flags, u_short tag, u_char distance, |
Feng Lu | 0d0686f | 2015-05-22 11:40:02 +0200 | [diff] [blame] | 478 | vrf_id_t vrf_id); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 479 | |
paul | a1ac18c | 2005-06-28 17:17:12 +0000 | [diff] [blame] | 480 | extern int |
Ayan Banerjee | 34c5d89 | 2015-11-09 20:14:53 -0500 | [diff] [blame] | 481 | rib_add_ipv6_multipath (struct prefix_ipv6 *, struct rib *, safi_t); |
| 482 | |
| 483 | extern int |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 484 | static_delete_ipv6 (struct prefix *p, u_char type, struct in6_addr *gate, |
Piotr Chytła | de24f82 | 2007-06-28 00:09:28 +0200 | [diff] [blame] | 485 | const char *ifname, u_short tag, u_char distance, vrf_id_t vrf_id); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 486 | |
Avneesh Sachdev | 9fd92e3 | 2012-11-13 22:48:53 +0000 | [diff] [blame] | 487 | extern int rib_gc_dest (struct route_node *rn); |
Avneesh Sachdev | 0915bb0 | 2012-11-13 22:48:55 +0000 | [diff] [blame] | 488 | 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] | 489 | |
| 490 | /* |
| 491 | * Inline functions. |
| 492 | */ |
| 493 | |
| 494 | /* |
Avneesh Sachdev | 1b5ed1b | 2012-11-13 22:48:54 +0000 | [diff] [blame] | 495 | * rib_table_info |
| 496 | */ |
| 497 | static inline rib_table_info_t * |
| 498 | rib_table_info (struct route_table *table) |
| 499 | { |
| 500 | return (rib_table_info_t *) table->info; |
| 501 | } |
| 502 | |
| 503 | /* |
Avneesh Sachdev | 9fd92e3 | 2012-11-13 22:48:53 +0000 | [diff] [blame] | 504 | * rib_dest_from_rnode |
| 505 | */ |
| 506 | static inline rib_dest_t * |
| 507 | rib_dest_from_rnode (struct route_node *rn) |
| 508 | { |
| 509 | return (rib_dest_t *) rn->info; |
| 510 | } |
| 511 | |
| 512 | /* |
| 513 | * rnode_to_ribs |
| 514 | * |
| 515 | * Returns a pointer to the list of routes corresponding to the given |
| 516 | * route_node. |
| 517 | */ |
| 518 | static inline struct rib * |
| 519 | rnode_to_ribs (struct route_node *rn) |
| 520 | { |
| 521 | rib_dest_t *dest; |
| 522 | |
| 523 | dest = rib_dest_from_rnode (rn); |
| 524 | if (!dest) |
| 525 | return NULL; |
| 526 | |
| 527 | return dest->routes; |
| 528 | } |
| 529 | |
| 530 | /* |
| 531 | * rib_dest_prefix |
| 532 | */ |
| 533 | static inline struct prefix * |
| 534 | rib_dest_prefix (rib_dest_t *dest) |
| 535 | { |
| 536 | return &dest->rnode->p; |
| 537 | } |
| 538 | |
| 539 | /* |
| 540 | * rib_dest_af |
| 541 | * |
| 542 | * Returns the address family that the destination is for. |
| 543 | */ |
| 544 | static inline u_char |
| 545 | rib_dest_af (rib_dest_t *dest) |
| 546 | { |
| 547 | return dest->rnode->p.family; |
| 548 | } |
| 549 | |
| 550 | /* |
| 551 | * rib_dest_table |
| 552 | */ |
| 553 | static inline struct route_table * |
| 554 | rib_dest_table (rib_dest_t *dest) |
| 555 | { |
| 556 | return dest->rnode->table; |
| 557 | } |
| 558 | |
Avneesh Sachdev | 1b5ed1b | 2012-11-13 22:48:54 +0000 | [diff] [blame] | 559 | /* |
| 560 | * rib_dest_vrf |
| 561 | */ |
Feng Lu | 41f44a2 | 2015-05-22 11:39:56 +0200 | [diff] [blame] | 562 | static inline struct zebra_vrf * |
Avneesh Sachdev | 1b5ed1b | 2012-11-13 22:48:54 +0000 | [diff] [blame] | 563 | rib_dest_vrf (rib_dest_t *dest) |
| 564 | { |
Feng Lu | 41f44a2 | 2015-05-22 11:39:56 +0200 | [diff] [blame] | 565 | return rib_table_info (rib_dest_table (dest))->zvrf; |
Avneesh Sachdev | 1b5ed1b | 2012-11-13 22:48:54 +0000 | [diff] [blame] | 566 | } |
| 567 | |
Avneesh Sachdev | 0915bb0 | 2012-11-13 22:48:55 +0000 | [diff] [blame] | 568 | /* |
| 569 | * rib_tables_iter_init |
| 570 | */ |
| 571 | static inline void |
| 572 | rib_tables_iter_init (rib_tables_iter_t *iter) |
| 573 | |
| 574 | { |
| 575 | memset (iter, 0, sizeof (*iter)); |
| 576 | iter->state = RIB_TABLES_ITER_S_INIT; |
| 577 | } |
| 578 | |
| 579 | /* |
| 580 | * rib_tables_iter_started |
| 581 | * |
| 582 | * Returns TRUE if this iterator has started iterating over the set of |
| 583 | * tables. |
| 584 | */ |
| 585 | static inline int |
| 586 | rib_tables_iter_started (rib_tables_iter_t *iter) |
| 587 | { |
| 588 | return iter->state != RIB_TABLES_ITER_S_INIT; |
| 589 | } |
| 590 | |
| 591 | /* |
| 592 | * rib_tables_iter_cleanup |
| 593 | */ |
| 594 | static inline void |
| 595 | rib_tables_iter_cleanup (rib_tables_iter_t *iter) |
| 596 | { |
| 597 | iter->state = RIB_TABLES_ITER_S_DONE; |
| 598 | } |
| 599 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 600 | #endif /*_ZEBRA_RIB_H */ |