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