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