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; |
Denis Ovsienko | e96f920 | 2008-06-02 12:03:22 +0000 | [diff] [blame] | 43 | #define RIB_ROUTE_QUEUED(x) (1 << (x)) |
Paul Jakma | 6d69112 | 2006-07-27 21:49:00 +0000 | [diff] [blame] | 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 | |
Denis Ovsienko | e96f920 | 2008-06-02 12:03:22 +0000 | [diff] [blame] | 86 | /* meta-queue structure: |
| 87 | * sub-queue 0: connected, kernel |
| 88 | * sub-queue 1: static |
| 89 | * sub-queue 2: RIP, RIPng, OSPF, OSPF6, IS-IS |
| 90 | * sub-queue 3: iBGP, eBGP |
| 91 | * sub-queue 4: any other origin (if any) |
| 92 | */ |
| 93 | #define MQ_SIZE 5 |
| 94 | struct meta_queue |
| 95 | { |
| 96 | struct list *subq[MQ_SIZE]; |
| 97 | u_int32_t size; /* sum of lengths of all subqueues */ |
| 98 | }; |
| 99 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 100 | /* Static route information. */ |
| 101 | struct static_ipv4 |
| 102 | { |
| 103 | /* For linked list. */ |
| 104 | struct static_ipv4 *prev; |
| 105 | struct static_ipv4 *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_IPV4_GATEWAY 1 |
| 113 | #define STATIC_IPV4_IFNAME 2 |
paul | 595db7f | 2003-05-25 21:35:06 +0000 | [diff] [blame] | 114 | #define STATIC_IPV4_BLACKHOLE 3 |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 115 | |
| 116 | /* Nexthop value. */ |
| 117 | union |
| 118 | { |
| 119 | struct in_addr ipv4; |
| 120 | char *ifname; |
| 121 | } gate; |
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 | |
| 131 | #ifdef HAVE_IPV6 |
| 132 | /* Static route information. */ |
| 133 | struct static_ipv6 |
| 134 | { |
| 135 | /* For linked list. */ |
| 136 | struct static_ipv6 *prev; |
| 137 | struct static_ipv6 *next; |
| 138 | |
| 139 | /* Administrative distance. */ |
| 140 | u_char distance; |
| 141 | |
| 142 | /* Flag for this static route's type. */ |
| 143 | u_char type; |
| 144 | #define STATIC_IPV6_GATEWAY 1 |
| 145 | #define STATIC_IPV6_GATEWAY_IFNAME 2 |
| 146 | #define STATIC_IPV6_IFNAME 3 |
| 147 | |
| 148 | /* Nexthop value. */ |
| 149 | struct in6_addr ipv6; |
| 150 | char *ifname; |
hasso | 81dfcaa | 2003-05-25 19:21:25 +0000 | [diff] [blame] | 151 | |
| 152 | /* bit flags */ |
| 153 | u_char flags; |
| 154 | /* |
| 155 | see ZEBRA_FLAG_REJECT |
| 156 | ZEBRA_FLAG_BLACKHOLE |
| 157 | */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 158 | }; |
| 159 | #endif /* HAVE_IPV6 */ |
| 160 | |
paul | 7021c42 | 2003-07-15 12:52:22 +0000 | [diff] [blame] | 161 | enum nexthop_types_t |
| 162 | { |
| 163 | NEXTHOP_TYPE_IFINDEX = 1, /* Directly connected. */ |
| 164 | NEXTHOP_TYPE_IFNAME, /* Interface route. */ |
| 165 | NEXTHOP_TYPE_IPV4, /* IPv4 nexthop. */ |
| 166 | NEXTHOP_TYPE_IPV4_IFINDEX, /* IPv4 nexthop with ifindex. */ |
| 167 | NEXTHOP_TYPE_IPV4_IFNAME, /* IPv4 nexthop with ifname. */ |
| 168 | NEXTHOP_TYPE_IPV6, /* IPv6 nexthop. */ |
| 169 | NEXTHOP_TYPE_IPV6_IFINDEX, /* IPv6 nexthop with ifindex. */ |
| 170 | NEXTHOP_TYPE_IPV6_IFNAME, /* IPv6 nexthop with ifname. */ |
| 171 | NEXTHOP_TYPE_BLACKHOLE, /* Null0 nexthop. */ |
| 172 | }; |
| 173 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 174 | /* Nexthop structure. */ |
| 175 | struct nexthop |
| 176 | { |
| 177 | struct nexthop *next; |
| 178 | struct nexthop *prev; |
| 179 | |
Paul Jakma | e6d7d05 | 2006-03-30 13:32:09 +0000 | [diff] [blame] | 180 | /* Interface index. */ |
| 181 | char *ifname; |
| 182 | unsigned int ifindex; |
| 183 | |
paul | 7021c42 | 2003-07-15 12:52:22 +0000 | [diff] [blame] | 184 | enum nexthop_types_t type; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 185 | |
| 186 | u_char flags; |
| 187 | #define NEXTHOP_FLAG_ACTIVE (1 << 0) /* This nexthop is alive. */ |
| 188 | #define NEXTHOP_FLAG_FIB (1 << 1) /* FIB nexthop. */ |
| 189 | #define NEXTHOP_FLAG_RECURSIVE (1 << 2) /* Recursive nexthop. */ |
| 190 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 191 | /* Nexthop address or interface name. */ |
Paul Jakma | 7514fb7 | 2007-05-02 16:05:35 +0000 | [diff] [blame] | 192 | union g_addr gate; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 193 | |
| 194 | /* Recursive lookup nexthop. */ |
| 195 | u_char rtype; |
| 196 | unsigned int rifindex; |
Paul Jakma | 7514fb7 | 2007-05-02 16:05:35 +0000 | [diff] [blame] | 197 | union g_addr rgate; |
| 198 | union g_addr src; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 199 | }; |
| 200 | |
| 201 | /* Routing table instance. */ |
| 202 | struct vrf |
| 203 | { |
| 204 | /* Identifier. This is same as routing table vector index. */ |
| 205 | u_int32_t id; |
| 206 | |
| 207 | /* Routing table name. */ |
| 208 | char *name; |
| 209 | |
| 210 | /* Description. */ |
| 211 | char *desc; |
| 212 | |
| 213 | /* FIB identifier. */ |
| 214 | u_char fib_id; |
| 215 | |
| 216 | /* Routing table. */ |
| 217 | struct route_table *table[AFI_MAX][SAFI_MAX]; |
| 218 | |
| 219 | /* Static route configuration. */ |
| 220 | struct route_table *stable[AFI_MAX][SAFI_MAX]; |
| 221 | }; |
| 222 | |
paul | a1ac18c | 2005-06-28 17:17:12 +0000 | [diff] [blame] | 223 | extern struct nexthop *nexthop_ifindex_add (struct rib *, unsigned int); |
| 224 | extern struct nexthop *nexthop_ifname_add (struct rib *, char *); |
| 225 | extern struct nexthop *nexthop_blackhole_add (struct rib *); |
Paul Jakma | 7514fb7 | 2007-05-02 16:05:35 +0000 | [diff] [blame] | 226 | extern struct nexthop *nexthop_ipv4_add (struct rib *, struct in_addr *, |
| 227 | struct in_addr *); |
Denis Ovsienko | dc95824 | 2007-08-13 16:03:06 +0000 | [diff] [blame] | 228 | extern void rib_lookup_and_dump (struct prefix_ipv4 *); |
Denis Ovsienko | 20e5ff0 | 2008-02-26 14:02:24 +0000 | [diff] [blame] | 229 | extern void rib_lookup_and_pushup (struct prefix_ipv4 *); |
Denis Ovsienko | dc95824 | 2007-08-13 16:03:06 +0000 | [diff] [blame] | 230 | extern void rib_dump (const char *, const struct prefix_ipv4 *, const struct rib *); |
| 231 | extern int rib_lookup_ipv4_route (struct prefix_ipv4 *, union sockunion *); |
| 232 | #define ZEBRA_RIB_LOOKUP_ERROR -1 |
| 233 | #define ZEBRA_RIB_FOUND_EXACT 0 |
| 234 | #define ZEBRA_RIB_FOUND_NOGATE 1 |
| 235 | #define ZEBRA_RIB_FOUND_CONNECTED 2 |
| 236 | #define ZEBRA_RIB_NOTFOUND 3 |
| 237 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 238 | #ifdef HAVE_IPV6 |
paul | a1ac18c | 2005-06-28 17:17:12 +0000 | [diff] [blame] | 239 | extern struct nexthop *nexthop_ipv6_add (struct rib *, struct in6_addr *); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 240 | #endif /* HAVE_IPV6 */ |
| 241 | |
paul | a1ac18c | 2005-06-28 17:17:12 +0000 | [diff] [blame] | 242 | extern struct vrf *vrf_lookup (u_int32_t); |
| 243 | extern struct route_table *vrf_table (afi_t afi, safi_t safi, u_int32_t id); |
| 244 | 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] | 245 | |
hasso | d24af18 | 2005-09-24 14:00:26 +0000 | [diff] [blame] | 246 | /* NOTE: |
| 247 | * All rib_add_ipv[46]* functions will not just add prefix into RIB, but |
| 248 | * also implicitly withdraw equal prefix of same type. */ |
paul | a1ac18c | 2005-06-28 17:17:12 +0000 | [diff] [blame] | 249 | 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] | 250 | struct in_addr *gate, struct in_addr *src, |
| 251 | unsigned int ifindex, u_int32_t vrf_id, |
G.Balaji | cddf391 | 2011-11-26 21:59:32 +0400 | [diff] [blame] | 252 | u_int32_t, u_char, safi_t); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 253 | |
G.Balaji | cddf391 | 2011-11-26 21:59:32 +0400 | [diff] [blame] | 254 | extern int rib_add_ipv4_multipath (struct prefix_ipv4 *, struct rib *, safi_t); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 255 | |
paul | a1ac18c | 2005-06-28 17:17:12 +0000 | [diff] [blame] | 256 | extern int rib_delete_ipv4 (int type, int flags, struct prefix_ipv4 *p, |
| 257 | struct in_addr *gate, unsigned int ifindex, |
G.Balaji | cddf391 | 2011-11-26 21:59:32 +0400 | [diff] [blame] | 258 | u_int32_t, safi_t safi); |
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_ipv4 (struct in_addr); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 261 | |
paul | a1ac18c | 2005-06-28 17:17:12 +0000 | [diff] [blame] | 262 | extern struct rib *rib_lookup_ipv4 (struct prefix_ipv4 *); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 263 | |
paul | a1ac18c | 2005-06-28 17:17:12 +0000 | [diff] [blame] | 264 | extern void rib_update (void); |
| 265 | extern void rib_weed_tables (void); |
| 266 | extern void rib_sweep_route (void); |
| 267 | extern void rib_close (void); |
| 268 | extern void rib_init (void); |
Vyacheslav Trushkin | 2ea1ab1 | 2011-12-11 18:48:47 +0400 | [diff] [blame] | 269 | extern unsigned long rib_score_proto (u_char proto); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 270 | |
paul | a1ac18c | 2005-06-28 17:17:12 +0000 | [diff] [blame] | 271 | extern int |
hasso | 39db97e | 2004-10-12 20:50:58 +0000 | [diff] [blame] | 272 | static_add_ipv4 (struct prefix *p, struct in_addr *gate, const char *ifname, |
hasso | 81dfcaa | 2003-05-25 19:21:25 +0000 | [diff] [blame] | 273 | u_char flags, u_char distance, 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 |
hasso | 39db97e | 2004-10-12 20:50:58 +0000 | [diff] [blame] | 276 | static_delete_ipv4 (struct prefix *p, struct in_addr *gate, const char *ifname, |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 277 | u_char distance, u_int32_t vrf_id); |
| 278 | |
| 279 | #ifdef HAVE_IPV6 |
paul | a1ac18c | 2005-06-28 17:17:12 +0000 | [diff] [blame] | 280 | extern int |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 281 | rib_add_ipv6 (int type, int flags, struct prefix_ipv6 *p, |
hasso | be61c4e | 2005-08-27 06:05:47 +0000 | [diff] [blame] | 282 | struct in6_addr *gate, unsigned int ifindex, u_int32_t vrf_id, |
G.Balaji | f768f36 | 2011-11-26 22:10:39 +0400 | [diff] [blame] | 283 | u_int32_t metric, u_char distance, safi_t safi); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 284 | |
paul | a1ac18c | 2005-06-28 17:17:12 +0000 | [diff] [blame] | 285 | extern int |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 286 | rib_delete_ipv6 (int type, int flags, struct prefix_ipv6 *p, |
G.Balaji | f768f36 | 2011-11-26 22:10:39 +0400 | [diff] [blame] | 287 | struct in6_addr *gate, unsigned int ifindex, u_int32_t vrf_id, safi_t safi); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 288 | |
paul | a1ac18c | 2005-06-28 17:17:12 +0000 | [diff] [blame] | 289 | extern struct rib *rib_lookup_ipv6 (struct in6_addr *); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 290 | |
paul | a1ac18c | 2005-06-28 17:17:12 +0000 | [diff] [blame] | 291 | extern struct rib *rib_match_ipv6 (struct in6_addr *); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 292 | |
| 293 | extern struct route_table *rib_table_ipv6; |
| 294 | |
paul | a1ac18c | 2005-06-28 17:17:12 +0000 | [diff] [blame] | 295 | extern int |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 296 | static_add_ipv6 (struct prefix *p, u_char type, struct in6_addr *gate, |
hasso | 39db97e | 2004-10-12 20:50:58 +0000 | [diff] [blame] | 297 | const char *ifname, u_char flags, u_char distance, |
| 298 | u_int32_t vrf_id); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 299 | |
paul | a1ac18c | 2005-06-28 17:17:12 +0000 | [diff] [blame] | 300 | extern int |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 301 | static_delete_ipv6 (struct prefix *p, u_char type, struct in6_addr *gate, |
hasso | 39db97e | 2004-10-12 20:50:58 +0000 | [diff] [blame] | 302 | const char *ifname, u_char distance, u_int32_t vrf_id); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 303 | |
| 304 | #endif /* HAVE_IPV6 */ |
| 305 | |
| 306 | #endif /*_ZEBRA_RIB_H */ |