paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1 | /* |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 2 | * Copyright (C) 2003 Yasuhiro Ohara |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 3 | * |
| 4 | * This file is part of GNU Zebra. |
| 5 | * |
| 6 | * GNU Zebra is free software; you can redistribute it and/or modify it |
| 7 | * under the terms of the GNU General Public License as published by the |
| 8 | * Free Software Foundation; either version 2, or (at your option) any |
| 9 | * later version. |
| 10 | * |
| 11 | * GNU Zebra is distributed in the hope that it will be useful, but |
| 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 14 | * General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License |
| 17 | * along with GNU Zebra; see the file COPYING. If not, write to the |
| 18 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
| 19 | * Boston, MA 02111-1307, USA. |
| 20 | */ |
| 21 | |
| 22 | #ifndef OSPF6_ROUTE_H |
| 23 | #define OSPF6_ROUTE_H |
| 24 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 25 | #define OSPF6_MULTI_PATH_LIMIT 4 |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 26 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 27 | /* Debug option */ |
| 28 | extern unsigned char conf_debug_ospf6_route; |
| 29 | #define OSPF6_DEBUG_ROUTE_TABLE 0x01 |
| 30 | #define OSPF6_DEBUG_ROUTE_INTRA 0x02 |
| 31 | #define OSPF6_DEBUG_ROUTE_INTER 0x04 |
| 32 | #define OSPF6_DEBUG_ROUTE_ON(level) \ |
| 33 | (conf_debug_ospf6_route |= (level)) |
| 34 | #define OSPF6_DEBUG_ROUTE_OFF(level) \ |
| 35 | (conf_debug_ospf6_route &= ~(level)) |
| 36 | #define IS_OSPF6_DEBUG_ROUTE(e) \ |
| 37 | (conf_debug_ospf6_route & OSPF6_DEBUG_ROUTE_ ## e) |
| 38 | |
| 39 | /* Nexthop */ |
| 40 | struct ospf6_nexthop |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 41 | { |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 42 | /* Interface index */ |
| 43 | unsigned int ifindex; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 44 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 45 | /* IP address, if any */ |
| 46 | struct in6_addr address; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 47 | }; |
| 48 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 49 | #define ospf6_nexthop_is_set(x) \ |
| 50 | ((x)->ifindex || ! IN6_IS_ADDR_UNSPECIFIED (&(x)->address)) |
| 51 | #define ospf6_nexthop_is_same(a,b) \ |
| 52 | ((a)->ifindex == (b)->ifindex && \ |
| 53 | IN6_ARE_ADDR_EQUAL (&(a)->address, &(b)->address)) |
| 54 | #define ospf6_nexthop_clear(x) \ |
| 55 | do { \ |
| 56 | (x)->ifindex = 0; \ |
| 57 | memset (&(x)->address, 0, sizeof (struct in6_addr)); \ |
| 58 | } while (0) |
| 59 | #define ospf6_nexthop_copy(a, b) \ |
| 60 | do { \ |
| 61 | (a)->ifindex = (b)->ifindex; \ |
| 62 | memcpy (&(a)->address, &(b)->address, \ |
| 63 | sizeof (struct in6_addr)); \ |
| 64 | } while (0) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 65 | |
| 66 | /* Path */ |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 67 | struct ospf6_ls_origin |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 68 | { |
| 69 | u_int16_t type; |
| 70 | u_int32_t id; |
| 71 | u_int32_t adv_router; |
| 72 | }; |
| 73 | |
| 74 | struct ospf6_path |
| 75 | { |
| 76 | /* Link State Origin */ |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 77 | struct ospf6_ls_origin origin; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 78 | |
| 79 | /* Router bits */ |
| 80 | u_char router_bits; |
| 81 | |
| 82 | /* Optional Capabilities */ |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 83 | u_char options[3]; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 84 | |
| 85 | /* Prefix Options */ |
| 86 | u_char prefix_options; |
| 87 | |
| 88 | /* Associated Area */ |
| 89 | u_int32_t area_id; |
| 90 | |
| 91 | /* Path-type */ |
| 92 | u_char type; |
| 93 | |
| 94 | /* Cost */ |
| 95 | u_int8_t metric_type; |
| 96 | u_int32_t cost; |
| 97 | u_int32_t cost_e2; |
| 98 | }; |
| 99 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 100 | #define OSPF6_PATH_TYPE_NONE 0 |
| 101 | #define OSPF6_PATH_TYPE_INTRA 1 |
| 102 | #define OSPF6_PATH_TYPE_INTER 2 |
| 103 | #define OSPF6_PATH_TYPE_EXTERNAL1 3 |
| 104 | #define OSPF6_PATH_TYPE_EXTERNAL2 4 |
| 105 | #define OSPF6_PATH_TYPE_MAX 5 |
| 106 | |
| 107 | #include "prefix.h" |
| 108 | #include "table.h" |
| 109 | |
| 110 | struct ospf6_route |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 111 | { |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 112 | struct route_node *rnode; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 113 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 114 | struct ospf6_route *prev; |
| 115 | struct ospf6_route *next; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 116 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 117 | unsigned int lock; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 118 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 119 | /* Destination Type */ |
| 120 | u_char type; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 121 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 122 | /* Destination ID */ |
| 123 | struct prefix prefix; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 124 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 125 | /* Time */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 126 | struct timeval installed; |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 127 | struct timeval changed; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 128 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 129 | /* flag */ |
| 130 | u_char flag; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 131 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 132 | /* path */ |
| 133 | struct ospf6_path path; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 134 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 135 | /* nexthop */ |
| 136 | struct ospf6_nexthop nexthop[OSPF6_MULTI_PATH_LIMIT]; |
| 137 | |
| 138 | /* route option */ |
| 139 | void *route_option; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 140 | }; |
| 141 | |
| 142 | #define OSPF6_DEST_TYPE_NONE 0 |
| 143 | #define OSPF6_DEST_TYPE_ROUTER 1 |
| 144 | #define OSPF6_DEST_TYPE_NETWORK 2 |
| 145 | #define OSPF6_DEST_TYPE_DISCARD 3 |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 146 | #define OSPF6_DEST_TYPE_LINKSTATE 4 |
| 147 | #define OSPF6_DEST_TYPE_MAX 5 |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 148 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 149 | #define OSPF6_ROUTE_CHANGE 0x01 |
| 150 | #define OSPF6_ROUTE_ADD 0x02 |
| 151 | #define OSPF6_ROUTE_REMOVE 0x04 |
| 152 | #define OSPF6_ROUTE_BEST 0x08 |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 153 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 154 | struct ospf6_route_table |
| 155 | { |
| 156 | /* patricia tree */ |
| 157 | struct route_table *table; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 158 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 159 | u_int32_t count; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 160 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 161 | /* hooks */ |
| 162 | void (*hook_add) (struct ospf6_route *); |
| 163 | void (*hook_change) (struct ospf6_route *); |
| 164 | void (*hook_remove) (struct ospf6_route *); |
| 165 | }; |
| 166 | |
| 167 | extern char *ospf6_dest_type_str[OSPF6_DEST_TYPE_MAX]; |
| 168 | extern char *ospf6_dest_type_substr[OSPF6_DEST_TYPE_MAX]; |
| 169 | #define OSPF6_DEST_TYPE_NAME(x) \ |
| 170 | (0 < (x) && (x) < OSPF6_DEST_TYPE_MAX ? \ |
| 171 | ospf6_dest_type_str[(x)] : ospf6_dest_type_str[0]) |
| 172 | #define OSPF6_DEST_TYPE_SUBSTR(x) \ |
| 173 | (0 < (x) && (x) < OSPF6_DEST_TYPE_MAX ? \ |
| 174 | ospf6_dest_type_substr[(x)] : ospf6_dest_type_substr[0]) |
| 175 | |
| 176 | extern char *ospf6_path_type_str[OSPF6_PATH_TYPE_MAX]; |
| 177 | extern char *ospf6_path_type_substr[OSPF6_PATH_TYPE_MAX]; |
| 178 | #define OSPF6_PATH_TYPE_NAME(x) \ |
| 179 | (0 < (x) && (x) < OSPF6_PATH_TYPE_MAX ? \ |
| 180 | ospf6_path_type_str[(x)] : ospf6_path_type_str[0]) |
| 181 | #define OSPF6_PATH_TYPE_SUBSTR(x) \ |
| 182 | (0 < (x) && (x) < OSPF6_PATH_TYPE_MAX ? \ |
| 183 | ospf6_path_type_substr[(x)] : ospf6_path_type_substr[0]) |
| 184 | |
| 185 | #define OSPF6_ROUTE_ADDRESS_STR "Display the route bestmatches the address\n" |
| 186 | #define OSPF6_ROUTE_PREFIX_STR "Display the route\n" |
| 187 | #define OSPF6_ROUTE_MATCH_STR "Display the route matches the prefix\n" |
| 188 | |
| 189 | #define ospf6_route_is_prefix(p, r) \ |
| 190 | (memcmp (p, &(r)->prefix, sizeof (struct prefix)) == 0) |
| 191 | #define ospf6_route_is_same(ra, rb) \ |
| 192 | (prefix_same (&(ra)->prefix, &(rb)->prefix)) |
| 193 | #define ospf6_route_is_same_origin(ra, rb) \ |
| 194 | ((ra)->path.area_id == (rb)->path.area_id && \ |
| 195 | memcmp (&(ra)->path.origin, &(rb)->path.origin, \ |
| 196 | sizeof (struct ospf6_ls_origin)) == 0) |
| 197 | #define ospf6_route_is_identical(ra, rb) \ |
| 198 | ((ra)->type == (rb)->type && \ |
| 199 | memcmp (&(ra)->prefix, &(rb)->prefix, sizeof (struct prefix)) == 0 && \ |
| 200 | memcmp (&(ra)->path, &(rb)->path, sizeof (struct ospf6_path)) == 0 && \ |
| 201 | memcmp (&(ra)->nexthop, &(rb)->nexthop, \ |
| 202 | sizeof (struct ospf6_nexthop) * OSPF6_MULTI_PATH_LIMIT) == 0) |
| 203 | #define ospf6_route_is_best(r) (CHECK_FLAG ((r)->flag, OSPF6_ROUTE_BEST)) |
| 204 | |
| 205 | #define ospf6_linkstate_prefix_adv_router(x) \ |
| 206 | (*(u_int32_t *)(&(x)->u.prefix6.s6_addr[0])) |
| 207 | #define ospf6_linkstate_prefix_id(x) \ |
| 208 | (*(u_int32_t *)(&(x)->u.prefix6.s6_addr[4])) |
| 209 | |
| 210 | /* Function prototype */ |
| 211 | void ospf6_linkstate_prefix (u_int32_t adv_router, u_int32_t id, |
| 212 | struct prefix *prefix); |
| 213 | void ospf6_linkstate_prefix2str (struct prefix *prefix, char *buf, int size); |
| 214 | |
| 215 | struct ospf6_route *ospf6_route_create (); |
| 216 | void ospf6_route_delete (struct ospf6_route *); |
| 217 | struct ospf6_route *ospf6_route_copy (struct ospf6_route *route); |
| 218 | |
| 219 | void ospf6_route_lock (struct ospf6_route *route); |
| 220 | void ospf6_route_unlock (struct ospf6_route *route); |
| 221 | |
| 222 | struct ospf6_route * |
| 223 | ospf6_route_lookup (struct prefix *prefix, |
| 224 | struct ospf6_route_table *table); |
| 225 | struct ospf6_route * |
| 226 | ospf6_route_lookup_identical (struct ospf6_route *route, |
| 227 | struct ospf6_route_table *table); |
| 228 | struct ospf6_route * |
| 229 | ospf6_route_lookup_bestmatch (struct prefix *prefix, |
| 230 | struct ospf6_route_table *table); |
| 231 | |
| 232 | struct ospf6_route * |
| 233 | ospf6_route_add (struct ospf6_route *route, struct ospf6_route_table *table); |
| 234 | void |
| 235 | ospf6_route_remove (struct ospf6_route *route, struct ospf6_route_table *table); |
| 236 | |
| 237 | struct ospf6_route *ospf6_route_head (struct ospf6_route_table *table); |
| 238 | struct ospf6_route *ospf6_route_next (struct ospf6_route *route); |
| 239 | struct ospf6_route *ospf6_route_best_next (struct ospf6_route *route); |
| 240 | |
| 241 | struct ospf6_route *ospf6_route_match_head (struct prefix *prefix, |
| 242 | struct ospf6_route_table *table); |
| 243 | struct ospf6_route *ospf6_route_match_next (struct prefix *prefix, |
| 244 | struct ospf6_route *route); |
| 245 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 246 | void ospf6_route_remove_all (struct ospf6_route_table *); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 247 | struct ospf6_route_table *ospf6_route_table_create (); |
| 248 | void ospf6_route_table_delete (struct ospf6_route_table *); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 249 | void ospf6_route_dump (struct ospf6_route_table *table); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 250 | |
| 251 | int ospf6_route_table_show (struct vty *, int, char **, |
| 252 | struct ospf6_route_table *); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 253 | int ospf6_lsentry_table_show (struct vty *, int, char **, |
| 254 | struct ospf6_route_table *); |
| 255 | |
| 256 | int config_write_ospf6_debug_route (struct vty *vty); |
| 257 | void install_element_ospf6_debug_route (); |
| 258 | void ospf6_route_init (); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 259 | |
| 260 | #endif /* OSPF6_ROUTE_H */ |
| 261 | |