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