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