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 | |
| 204 | struct nexthop *nexthop_ifindex_add (struct rib *, unsigned int); |
| 205 | struct nexthop *nexthop_ifname_add (struct rib *, char *); |
paul | 595db7f | 2003-05-25 21:35:06 +0000 | [diff] [blame] | 206 | struct nexthop *nexthop_blackhole_add (struct rib *); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 207 | struct nexthop *nexthop_ipv4_add (struct rib *, struct in_addr *); |
| 208 | #ifdef HAVE_IPV6 |
| 209 | struct nexthop *nexthop_ipv6_add (struct rib *, struct in6_addr *); |
| 210 | #endif /* HAVE_IPV6 */ |
| 211 | |
| 212 | struct vrf *vrf_lookup (u_int32_t); |
| 213 | struct route_table *vrf_table (afi_t afi, safi_t safi, u_int32_t id); |
| 214 | struct route_table *vrf_static_table (afi_t afi, safi_t safi, u_int32_t id); |
| 215 | |
| 216 | int |
| 217 | rib_add_ipv4 (int type, int flags, struct prefix_ipv4 *p, |
| 218 | struct in_addr *gate, unsigned int ifindex, u_int32_t vrf_id, |
| 219 | u_int32_t, u_char); |
| 220 | |
| 221 | int |
| 222 | rib_add_ipv4_multipath (struct prefix_ipv4 *, struct rib *); |
| 223 | |
| 224 | int |
| 225 | rib_delete_ipv4 (int type, int flags, struct prefix_ipv4 *p, |
| 226 | struct in_addr *gate, unsigned int ifindex, u_int32_t); |
| 227 | |
| 228 | struct rib * |
| 229 | rib_match_ipv4 (struct in_addr); |
| 230 | |
| 231 | struct rib * |
| 232 | rib_lookup_ipv4 (struct prefix_ipv4 *); |
| 233 | |
| 234 | void rib_update (); |
| 235 | void rib_sweep_route (); |
| 236 | void rib_close (); |
| 237 | void rib_init (); |
| 238 | |
| 239 | 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 | |
| 243 | 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 |
| 248 | int |
| 249 | rib_add_ipv6 (int type, int flags, struct prefix_ipv6 *p, |
| 250 | struct in6_addr *gate, unsigned int ifindex, u_int32_t vrf_id); |
| 251 | |
| 252 | int |
| 253 | rib_delete_ipv6 (int type, int flags, struct prefix_ipv6 *p, |
| 254 | struct in6_addr *gate, unsigned int ifindex, u_int32_t vrf_id); |
| 255 | |
| 256 | struct rib *rib_lookup_ipv6 (struct in6_addr *); |
| 257 | |
| 258 | struct rib *rib_match_ipv6 (struct in6_addr *); |
| 259 | |
| 260 | extern struct route_table *rib_table_ipv6; |
| 261 | |
| 262 | int |
| 263 | static_add_ipv6 (struct prefix *p, u_char type, struct in6_addr *gate, |
hasso | 39db97e | 2004-10-12 20:50:58 +0000 | [diff] [blame] | 264 | const char *ifname, u_char flags, u_char distance, |
| 265 | u_int32_t vrf_id); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 266 | |
| 267 | int |
| 268 | static_delete_ipv6 (struct prefix *p, u_char type, struct in6_addr *gate, |
hasso | 39db97e | 2004-10-12 20:50:58 +0000 | [diff] [blame] | 269 | const char *ifname, u_char distance, u_int32_t vrf_id); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 270 | |
| 271 | #endif /* HAVE_IPV6 */ |
| 272 | |
| 273 | #endif /*_ZEBRA_RIB_H */ |