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