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