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