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