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 | ec1a428 | 2005-11-24 15:15:17 +0000 | [diff] [blame] | 26 | #include "prefix.h" |
| 27 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 28 | #define DISTANCE_INFINITY 255 |
| 29 | |
| 30 | /* Routing information base. */ |
| 31 | struct rib |
| 32 | { |
Paul Jakma | 6d69112 | 2006-07-27 21:49:00 +0000 | [diff] [blame] | 33 | /* Status Flags for the *route_node*, but kept in the head RIB.. */ |
| 34 | u_char rn_status; |
| 35 | #define RIB_ROUTE_QUEUED (1 << 0) |
| 36 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 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 | |
| 47 | /* Uptime. */ |
| 48 | time_t uptime; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 49 | |
| 50 | /* Type fo this route. */ |
| 51 | int type; |
| 52 | |
| 53 | /* Which routing table */ |
| 54 | int table; |
| 55 | |
Paul Jakma | e6d7d05 | 2006-03-30 13:32:09 +0000 | [diff] [blame] | 56 | /* Metric */ |
| 57 | u_int32_t metric; |
| 58 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 59 | /* Distance. */ |
| 60 | u_char distance; |
| 61 | |
Paul Jakma | 6d69112 | 2006-07-27 21:49:00 +0000 | [diff] [blame] | 62 | /* Flags of this route. |
| 63 | * This flag's definition is in lib/zebra.h ZEBRA_FLAG_* and is exposed |
| 64 | * to clients via Zserv |
| 65 | */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 66 | u_char flags; |
| 67 | |
Paul Jakma | 6d69112 | 2006-07-27 21:49:00 +0000 | [diff] [blame] | 68 | /* RIB internal status */ |
| 69 | u_char status; |
| 70 | #define RIB_ENTRY_REMOVED (1 << 0) |
| 71 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 72 | /* Nexthop information. */ |
| 73 | u_char nexthop_num; |
| 74 | u_char nexthop_active_num; |
| 75 | u_char nexthop_fib_num; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 76 | }; |
| 77 | |
| 78 | /* Static route information. */ |
| 79 | struct static_ipv4 |
| 80 | { |
| 81 | /* For linked list. */ |
| 82 | struct static_ipv4 *prev; |
| 83 | struct static_ipv4 *next; |
| 84 | |
| 85 | /* Administrative distance. */ |
| 86 | u_char distance; |
| 87 | |
| 88 | /* Flag for this static route's type. */ |
| 89 | u_char type; |
| 90 | #define STATIC_IPV4_GATEWAY 1 |
| 91 | #define STATIC_IPV4_IFNAME 2 |
paul | 595db7f | 2003-05-25 21:35:06 +0000 | [diff] [blame] | 92 | #define STATIC_IPV4_BLACKHOLE 3 |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 93 | |
| 94 | /* Nexthop value. */ |
| 95 | union |
| 96 | { |
| 97 | struct in_addr ipv4; |
| 98 | char *ifname; |
| 99 | } gate; |
hasso | 81dfcaa | 2003-05-25 19:21:25 +0000 | [diff] [blame] | 100 | |
| 101 | /* bit flags */ |
| 102 | u_char flags; |
| 103 | /* |
| 104 | see ZEBRA_FLAG_REJECT |
| 105 | ZEBRA_FLAG_BLACKHOLE |
| 106 | */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 107 | }; |
| 108 | |
| 109 | #ifdef HAVE_IPV6 |
| 110 | /* Static route information. */ |
| 111 | struct static_ipv6 |
| 112 | { |
| 113 | /* For linked list. */ |
| 114 | struct static_ipv6 *prev; |
| 115 | struct static_ipv6 *next; |
| 116 | |
| 117 | /* Administrative distance. */ |
| 118 | u_char distance; |
| 119 | |
| 120 | /* Flag for this static route's type. */ |
| 121 | u_char type; |
| 122 | #define STATIC_IPV6_GATEWAY 1 |
| 123 | #define STATIC_IPV6_GATEWAY_IFNAME 2 |
| 124 | #define STATIC_IPV6_IFNAME 3 |
| 125 | |
| 126 | /* Nexthop value. */ |
| 127 | struct in6_addr ipv6; |
| 128 | char *ifname; |
hasso | 81dfcaa | 2003-05-25 19:21:25 +0000 | [diff] [blame] | 129 | |
| 130 | /* bit flags */ |
| 131 | u_char flags; |
| 132 | /* |
| 133 | see ZEBRA_FLAG_REJECT |
| 134 | ZEBRA_FLAG_BLACKHOLE |
| 135 | */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 136 | }; |
| 137 | #endif /* HAVE_IPV6 */ |
| 138 | |
paul | 7021c42 | 2003-07-15 12:52:22 +0000 | [diff] [blame] | 139 | enum nexthop_types_t |
| 140 | { |
| 141 | NEXTHOP_TYPE_IFINDEX = 1, /* Directly connected. */ |
| 142 | NEXTHOP_TYPE_IFNAME, /* Interface route. */ |
| 143 | NEXTHOP_TYPE_IPV4, /* IPv4 nexthop. */ |
| 144 | NEXTHOP_TYPE_IPV4_IFINDEX, /* IPv4 nexthop with ifindex. */ |
| 145 | NEXTHOP_TYPE_IPV4_IFNAME, /* IPv4 nexthop with ifname. */ |
| 146 | NEXTHOP_TYPE_IPV6, /* IPv6 nexthop. */ |
| 147 | NEXTHOP_TYPE_IPV6_IFINDEX, /* IPv6 nexthop with ifindex. */ |
| 148 | NEXTHOP_TYPE_IPV6_IFNAME, /* IPv6 nexthop with ifname. */ |
| 149 | NEXTHOP_TYPE_BLACKHOLE, /* Null0 nexthop. */ |
| 150 | }; |
| 151 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 152 | /* Nexthop structure. */ |
| 153 | struct nexthop |
| 154 | { |
| 155 | struct nexthop *next; |
| 156 | struct nexthop *prev; |
| 157 | |
Paul Jakma | e6d7d05 | 2006-03-30 13:32:09 +0000 | [diff] [blame] | 158 | /* Interface index. */ |
| 159 | char *ifname; |
| 160 | unsigned int ifindex; |
| 161 | |
paul | 7021c42 | 2003-07-15 12:52:22 +0000 | [diff] [blame] | 162 | enum nexthop_types_t type; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 163 | |
| 164 | u_char flags; |
| 165 | #define NEXTHOP_FLAG_ACTIVE (1 << 0) /* This nexthop is alive. */ |
| 166 | #define NEXTHOP_FLAG_FIB (1 << 1) /* FIB nexthop. */ |
| 167 | #define NEXTHOP_FLAG_RECURSIVE (1 << 2) /* Recursive nexthop. */ |
| 168 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 169 | /* Nexthop address or interface name. */ |
| 170 | union |
| 171 | { |
| 172 | struct in_addr ipv4; |
| 173 | #ifdef HAVE_IPV6 |
| 174 | struct in6_addr ipv6; |
| 175 | #endif /* HAVE_IPV6*/ |
| 176 | } gate; |
| 177 | |
| 178 | /* Recursive lookup nexthop. */ |
| 179 | u_char rtype; |
| 180 | unsigned int rifindex; |
| 181 | union |
| 182 | { |
| 183 | struct in_addr ipv4; |
| 184 | #ifdef HAVE_IPV6 |
| 185 | struct in6_addr ipv6; |
| 186 | #endif /* HAVE_IPV6 */ |
| 187 | } rgate; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 188 | }; |
| 189 | |
| 190 | /* Routing table instance. */ |
| 191 | struct vrf |
| 192 | { |
| 193 | /* Identifier. This is same as routing table vector index. */ |
| 194 | u_int32_t id; |
| 195 | |
| 196 | /* Routing table name. */ |
| 197 | char *name; |
| 198 | |
| 199 | /* Description. */ |
| 200 | char *desc; |
| 201 | |
| 202 | /* FIB identifier. */ |
| 203 | u_char fib_id; |
| 204 | |
| 205 | /* Routing table. */ |
| 206 | struct route_table *table[AFI_MAX][SAFI_MAX]; |
| 207 | |
| 208 | /* Static route configuration. */ |
| 209 | struct route_table *stable[AFI_MAX][SAFI_MAX]; |
| 210 | }; |
| 211 | |
paul | a1ac18c | 2005-06-28 17:17:12 +0000 | [diff] [blame] | 212 | extern struct nexthop *nexthop_ifindex_add (struct rib *, unsigned int); |
| 213 | extern struct nexthop *nexthop_ifname_add (struct rib *, char *); |
| 214 | extern struct nexthop *nexthop_blackhole_add (struct rib *); |
| 215 | extern struct nexthop *nexthop_ipv4_add (struct rib *, struct in_addr *); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 216 | #ifdef HAVE_IPV6 |
paul | a1ac18c | 2005-06-28 17:17:12 +0000 | [diff] [blame] | 217 | extern struct nexthop *nexthop_ipv6_add (struct rib *, struct in6_addr *); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 218 | #endif /* HAVE_IPV6 */ |
| 219 | |
paul | a1ac18c | 2005-06-28 17:17:12 +0000 | [diff] [blame] | 220 | extern struct vrf *vrf_lookup (u_int32_t); |
| 221 | extern struct route_table *vrf_table (afi_t afi, safi_t safi, u_int32_t id); |
| 222 | extern struct route_table *vrf_static_table (afi_t afi, safi_t safi, u_int32_t id); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 223 | |
hasso | d24af18 | 2005-09-24 14:00:26 +0000 | [diff] [blame] | 224 | /* NOTE: |
| 225 | * All rib_add_ipv[46]* functions will not just add prefix into RIB, but |
| 226 | * also implicitly withdraw equal prefix of same type. */ |
paul | a1ac18c | 2005-06-28 17:17:12 +0000 | [diff] [blame] | 227 | extern int rib_add_ipv4 (int type, int flags, struct prefix_ipv4 *p, |
| 228 | struct in_addr *gate, unsigned int ifindex, |
| 229 | u_int32_t vrf_id, u_int32_t, u_char); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 230 | |
paul | a1ac18c | 2005-06-28 17:17:12 +0000 | [diff] [blame] | 231 | extern int rib_add_ipv4_multipath (struct prefix_ipv4 *, struct rib *); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 232 | |
paul | a1ac18c | 2005-06-28 17:17:12 +0000 | [diff] [blame] | 233 | extern int rib_delete_ipv4 (int type, int flags, struct prefix_ipv4 *p, |
| 234 | struct in_addr *gate, unsigned int ifindex, |
| 235 | u_int32_t); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 236 | |
paul | a1ac18c | 2005-06-28 17:17:12 +0000 | [diff] [blame] | 237 | extern struct rib *rib_match_ipv4 (struct in_addr); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 238 | |
paul | a1ac18c | 2005-06-28 17:17:12 +0000 | [diff] [blame] | 239 | extern struct rib *rib_lookup_ipv4 (struct prefix_ipv4 *); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 240 | |
paul | a1ac18c | 2005-06-28 17:17:12 +0000 | [diff] [blame] | 241 | extern void rib_update (void); |
| 242 | extern void rib_weed_tables (void); |
| 243 | extern void rib_sweep_route (void); |
| 244 | extern void rib_close (void); |
| 245 | extern void rib_init (void); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 246 | |
paul | a1ac18c | 2005-06-28 17:17:12 +0000 | [diff] [blame] | 247 | extern int |
hasso | 39db97e | 2004-10-12 20:50:58 +0000 | [diff] [blame] | 248 | static_add_ipv4 (struct prefix *p, struct in_addr *gate, const char *ifname, |
hasso | 81dfcaa | 2003-05-25 19:21:25 +0000 | [diff] [blame] | 249 | u_char flags, u_char distance, u_int32_t vrf_id); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 250 | |
paul | a1ac18c | 2005-06-28 17:17:12 +0000 | [diff] [blame] | 251 | extern int |
hasso | 39db97e | 2004-10-12 20:50:58 +0000 | [diff] [blame] | 252 | static_delete_ipv4 (struct prefix *p, struct in_addr *gate, const char *ifname, |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 253 | u_char distance, u_int32_t vrf_id); |
| 254 | |
| 255 | #ifdef HAVE_IPV6 |
paul | a1ac18c | 2005-06-28 17:17:12 +0000 | [diff] [blame] | 256 | extern int |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 257 | rib_add_ipv6 (int type, int flags, struct prefix_ipv6 *p, |
hasso | be61c4e | 2005-08-27 06:05:47 +0000 | [diff] [blame] | 258 | struct in6_addr *gate, unsigned int ifindex, u_int32_t vrf_id, |
| 259 | u_int32_t metric, u_char distance); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 260 | |
paul | a1ac18c | 2005-06-28 17:17:12 +0000 | [diff] [blame] | 261 | extern int |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 262 | rib_delete_ipv6 (int type, int flags, struct prefix_ipv6 *p, |
| 263 | struct in6_addr *gate, unsigned int ifindex, u_int32_t vrf_id); |
| 264 | |
paul | a1ac18c | 2005-06-28 17:17:12 +0000 | [diff] [blame] | 265 | extern struct rib *rib_lookup_ipv6 (struct in6_addr *); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 266 | |
paul | a1ac18c | 2005-06-28 17:17:12 +0000 | [diff] [blame] | 267 | extern struct rib *rib_match_ipv6 (struct in6_addr *); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 268 | |
| 269 | extern struct route_table *rib_table_ipv6; |
| 270 | |
paul | a1ac18c | 2005-06-28 17:17:12 +0000 | [diff] [blame] | 271 | extern int |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 272 | static_add_ipv6 (struct prefix *p, u_char type, struct in6_addr *gate, |
hasso | 39db97e | 2004-10-12 20:50:58 +0000 | [diff] [blame] | 273 | const char *ifname, u_char flags, u_char distance, |
| 274 | u_int32_t vrf_id); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 275 | |
paul | a1ac18c | 2005-06-28 17:17:12 +0000 | [diff] [blame] | 276 | extern int |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 277 | static_delete_ipv6 (struct prefix *p, u_char type, struct in6_addr *gate, |
hasso | 39db97e | 2004-10-12 20:50:58 +0000 | [diff] [blame] | 278 | const char *ifname, u_char distance, u_int32_t vrf_id); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 279 | |
| 280 | #endif /* HAVE_IPV6 */ |
| 281 | |
| 282 | #endif /*_ZEBRA_RIB_H */ |