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. */ 29struct 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. */ 66struct 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 79 80 /* Nexthop value. */ 81 union 82 { 83 struct in_addr ipv4; 84 char *ifname; 85 } gate; 86}; 87 88#ifdef HAVE_IPV6 89/* Static route information. */ 90struct static_ipv6 91{ 92 /* For linked list. */ 93 struct static_ipv6 *prev; 94 struct static_ipv6 *next; 95 96 /* Administrative distance. */ 97 u_char distance; 98 99 /* Flag for this static route's type. */ 100 u_char type; 101#define STATIC_IPV6_GATEWAY 1 102#define STATIC_IPV6_GATEWAY_IFNAME 2 103#define STATIC_IPV6_IFNAME 3 104 105 /* Nexthop value. */ 106 struct in6_addr ipv6; 107 char *ifname; 108}; 109#endif /* HAVE_IPV6 */ 110 111/* Nexthop structure. */ 112struct nexthop 113{ 114 struct nexthop *next; 115 struct nexthop *prev; 116 117 u_char type; 118#define NEXTHOP_TYPE_IFINDEX 1 /* Directly connected. */ 119#define NEXTHOP_TYPE_IFNAME 2 /* Interface route. */ 120#define NEXTHOP_TYPE_IPV4 3 /* IPv4 nexthop. */ 121#define NEXTHOP_TYPE_IPV4_IFINDEX 4 /* IPv4 nexthop with ifindex. */ 122#define NEXTHOP_TYPE_IPV4_IFNAME 5 /* IPv4 nexthop with ifname. */ 123#define NEXTHOP_TYPE_IPV6 6 /* IPv6 nexthop. */ 124#define NEXTHOP_TYPE_IPV6_IFINDEX 7 /* IPv6 nexthop with ifindex. */ 125#define NEXTHOP_TYPE_IPV6_IFNAME 8 /* IPv6 nexthop with ifname. */ 126 127 u_char flags; 128#define NEXTHOP_FLAG_ACTIVE (1 << 0) /* This nexthop is alive. */ 129#define NEXTHOP_FLAG_FIB (1 << 1) /* FIB nexthop. */ 130#define NEXTHOP_FLAG_RECURSIVE (1 << 2) /* Recursive nexthop. */ 131 132 /* Interface index. */ 133 unsigned int ifindex; 134 char *ifname; 135 136 /* Nexthop address or interface name. */ 137 union 138 { 139 struct in_addr ipv4; 140#ifdef HAVE_IPV6 141 struct in6_addr ipv6; 142#endif /* HAVE_IPV6*/ 143 } gate; 144 145 /* Recursive lookup nexthop. */ 146 u_char rtype; 147 unsigned int rifindex; 148 union 149 { 150 struct in_addr ipv4; 151#ifdef HAVE_IPV6 152 struct in6_addr ipv6; 153#endif /* HAVE_IPV6 */ 154 } rgate; 155 156 struct nexthop *indirect; 157}; 158 159struct nexthop *nexthop_ifindex_add (struct rib *, unsigned int); 160struct nexthop *nexthop_ifname_add (struct rib *, char *); 161struct nexthop *nexthop_ipv4_add (struct rib *, struct in_addr *); 162#ifdef HAVE_IPV6 163struct nexthop *nexthop_ipv6_add (struct rib *, struct in6_addr *); 164#endif /* HAVE_IPV6 */ 165 166int 167rib_add_ipv4 (int type, int flags, struct prefix_ipv4 *p, 168 struct in_addr *gate, unsigned int ifindex, int table, 169 u_int32_t, u_char); 170 171int 172rib_add_ipv4_multipath (struct prefix_ipv4 *, struct rib *); 173 174int 175rib_delete_ipv4 (int type, int flags, struct prefix_ipv4 *p, 176 struct in_addr *gate, unsigned int ifindex, int table); 177 178struct rib * 179rib_match_ipv4 (struct in_addr); 180 181struct rib * 182rib_lookup_ipv4 (struct prefix_ipv4 *); 183 184void rib_update (); 185void rib_sweep_route (); 186void rib_close (); 187void rib_init (); 188 189extern struct route_table *rib_table_ipv4; 190 191#ifdef HAVE_IPV6 192int 193rib_add_ipv6 (int type, int flags, struct prefix_ipv6 *p, 194 struct in6_addr *gate, unsigned int ifindex, int table); 195 196int 197rib_delete_ipv6 (int type, int flags, struct prefix_ipv6 *p, 198 struct in6_addr *gate, unsigned int ifindex, int table); 199 200struct rib *rib_lookup_ipv6 (struct in6_addr *); 201 202struct rib *rib_match_ipv6 (struct in6_addr *); 203 204extern struct route_table *rib_table_ipv6; 205#endif /* HAVE_IPV6 */ 206 207#endif /*_ZEBRA_RIB_H */ 208