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