]>
Commit | Line | Data |
---|---|---|
718e3744 | 1 | /* |
508e53e2 | 2 | * Copyright (C) 2003 Yasuhiro Ohara |
718e3744 | 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 | ||
ddae3015 DL |
25 | #include "command.h" |
26 | ||
508e53e2 | 27 | #define OSPF6_MULTI_PATH_LIMIT 4 |
718e3744 | 28 | |
508e53e2 | 29 | /* Debug option */ |
30 | extern unsigned char conf_debug_ospf6_route; | |
31 | #define OSPF6_DEBUG_ROUTE_TABLE 0x01 | |
32 | #define OSPF6_DEBUG_ROUTE_INTRA 0x02 | |
33 | #define OSPF6_DEBUG_ROUTE_INTER 0x04 | |
cf1ce250 | 34 | #define OSPF6_DEBUG_ROUTE_MEMORY 0x80 |
508e53e2 | 35 | #define OSPF6_DEBUG_ROUTE_ON(level) \ |
36 | (conf_debug_ospf6_route |= (level)) | |
37 | #define OSPF6_DEBUG_ROUTE_OFF(level) \ | |
38 | (conf_debug_ospf6_route &= ~(level)) | |
39 | #define IS_OSPF6_DEBUG_ROUTE(e) \ | |
40 | (conf_debug_ospf6_route & OSPF6_DEBUG_ROUTE_ ## e) | |
718e3744 | 41 | |
508e53e2 | 42 | /* Nexthop */ |
43 | struct ospf6_nexthop | |
718e3744 | 44 | { |
508e53e2 | 45 | /* Interface index */ |
b892f1dd | 46 | ifindex_t ifindex; |
718e3744 | 47 | |
508e53e2 | 48 | /* IP address, if any */ |
49 | struct in6_addr address; | |
718e3744 | 50 | }; |
51 | ||
508e53e2 | 52 | #define ospf6_nexthop_is_set(x) \ |
53 | ((x)->ifindex || ! IN6_IS_ADDR_UNSPECIFIED (&(x)->address)) | |
54 | #define ospf6_nexthop_is_same(a,b) \ | |
55 | ((a)->ifindex == (b)->ifindex && \ | |
56 | IN6_ARE_ADDR_EQUAL (&(a)->address, &(b)->address)) | |
57 | #define ospf6_nexthop_clear(x) \ | |
58 | do { \ | |
59 | (x)->ifindex = 0; \ | |
60 | memset (&(x)->address, 0, sizeof (struct in6_addr)); \ | |
61 | } while (0) | |
62 | #define ospf6_nexthop_copy(a, b) \ | |
63 | do { \ | |
64 | (a)->ifindex = (b)->ifindex; \ | |
65 | memcpy (&(a)->address, &(b)->address, \ | |
66 | sizeof (struct in6_addr)); \ | |
67 | } while (0) | |
68 | ||
718e3744 | 69 | /* Path */ |
508e53e2 | 70 | struct ospf6_ls_origin |
718e3744 | 71 | { |
72 | u_int16_t type; | |
73 | u_int32_t id; | |
74 | u_int32_t adv_router; | |
75 | }; | |
76 | ||
77 | struct ospf6_path | |
78 | { | |
79 | /* Link State Origin */ | |
508e53e2 | 80 | struct ospf6_ls_origin origin; |
718e3744 | 81 | |
82 | /* Router bits */ | |
83 | u_char router_bits; | |
84 | ||
85 | /* Optional Capabilities */ | |
508e53e2 | 86 | u_char options[3]; |
718e3744 | 87 | |
88 | /* Prefix Options */ | |
89 | u_char prefix_options; | |
90 | ||
91 | /* Associated Area */ | |
92 | u_int32_t area_id; | |
93 | ||
94 | /* Path-type */ | |
95 | u_char type; | |
6452df09 | 96 | u_char subtype; /* only used for redistribute i.e ZEBRA_ROUTE_XXX */ |
718e3744 | 97 | |
98 | /* Cost */ | |
99 | u_int8_t metric_type; | |
100 | u_int32_t cost; | |
c3c0ac83 DS |
101 | union { |
102 | u_int32_t cost_e2; | |
103 | u_int32_t cost_config; | |
104 | } u; | |
464015fa | 105 | u_int32_t tag; |
718e3744 | 106 | }; |
107 | ||
6452df09 | 108 | #define OSPF6_PATH_TYPE_NONE 0 |
109 | #define OSPF6_PATH_TYPE_INTRA 1 | |
110 | #define OSPF6_PATH_TYPE_INTER 2 | |
111 | #define OSPF6_PATH_TYPE_EXTERNAL1 3 | |
112 | #define OSPF6_PATH_TYPE_EXTERNAL2 4 | |
113 | #define OSPF6_PATH_TYPE_REDISTRIBUTE 5 | |
114 | #define OSPF6_PATH_TYPE_MAX 6 | |
718e3744 | 115 | |
ca1f4309 DS |
116 | #define OSPF6_PATH_SUBTYPE_DEFAULT_RT 1 |
117 | ||
118 | #define OSPF6_PATH_COST_IS_CONFIGURED(path) (path.u.cost_config != OSPF_AREA_RANGE_COST_UNSPEC) | |
119 | ||
508e53e2 | 120 | #include "prefix.h" |
121 | #include "table.h" | |
c3c0ac83 | 122 | #include "bitfield.h" |
718e3744 | 123 | |
508e53e2 | 124 | struct ospf6_route |
718e3744 | 125 | { |
508e53e2 | 126 | struct route_node *rnode; |
cf1ce250 | 127 | struct ospf6_route_table *table; |
508e53e2 | 128 | struct ospf6_route *prev; |
129 | struct ospf6_route *next; | |
718e3744 | 130 | |
508e53e2 | 131 | unsigned int lock; |
718e3744 | 132 | |
508e53e2 | 133 | /* Destination Type */ |
134 | u_char type; | |
135 | ||
1f9a9fff PJ |
136 | /* XXX: It would likely be better to use separate struct in_addr's |
137 | * for the advertising router-ID and prefix IDs, instead of stuffing them | |
138 | * into one. See also XXX below. | |
139 | */ | |
508e53e2 | 140 | /* Destination ID */ |
141 | struct prefix prefix; | |
142 | ||
143 | /* Time */ | |
718e3744 | 144 | struct timeval installed; |
508e53e2 | 145 | struct timeval changed; |
718e3744 | 146 | |
508e53e2 | 147 | /* flag */ |
148 | u_char flag; | |
718e3744 | 149 | |
508e53e2 | 150 | /* route option */ |
151 | void *route_option; | |
049207c3 | 152 | |
153 | /* link state id for advertising */ | |
154 | u_int32_t linkstate_id; | |
c3c0ac83 DS |
155 | |
156 | /* path */ | |
157 | struct ospf6_path path; | |
158 | ||
159 | /* nexthop */ | |
160 | struct list *nh_list; | |
161 | ||
718e3744 | 162 | }; |
163 | ||
164 | #define OSPF6_DEST_TYPE_NONE 0 | |
165 | #define OSPF6_DEST_TYPE_ROUTER 1 | |
166 | #define OSPF6_DEST_TYPE_NETWORK 2 | |
167 | #define OSPF6_DEST_TYPE_DISCARD 3 | |
508e53e2 | 168 | #define OSPF6_DEST_TYPE_LINKSTATE 4 |
6452df09 | 169 | #define OSPF6_DEST_TYPE_RANGE 5 |
170 | #define OSPF6_DEST_TYPE_MAX 6 | |
718e3744 | 171 | |
6452df09 | 172 | #define OSPF6_ROUTE_CHANGE 0x01 |
173 | #define OSPF6_ROUTE_ADD 0x02 | |
174 | #define OSPF6_ROUTE_REMOVE 0x04 | |
175 | #define OSPF6_ROUTE_BEST 0x08 | |
4846ef64 | 176 | #define OSPF6_ROUTE_ACTIVE_SUMMARY 0x10 |
177 | #define OSPF6_ROUTE_DO_NOT_ADVERTISE 0x20 | |
9428f2dc | 178 | #define OSPF6_ROUTE_WAS_REMOVED 0x40 |
c3c0ac83 | 179 | #define OSPF6_ROUTE_BLACKHOLE_ADDED 0x80 |
718e3744 | 180 | |
508e53e2 | 181 | struct ospf6_route_table |
182 | { | |
cf1ce250 PJ |
183 | int scope_type; |
184 | int table_type; | |
185 | void *scope; | |
186 | ||
508e53e2 | 187 | /* patricia tree */ |
188 | struct route_table *table; | |
718e3744 | 189 | |
508e53e2 | 190 | u_int32_t count; |
718e3744 | 191 | |
c3c0ac83 DS |
192 | bitfield_t idspace; |
193 | ||
508e53e2 | 194 | /* hooks */ |
195 | void (*hook_add) (struct ospf6_route *); | |
196 | void (*hook_change) (struct ospf6_route *); | |
197 | void (*hook_remove) (struct ospf6_route *); | |
198 | }; | |
718e3744 | 199 | |
cf1ce250 PJ |
200 | #define OSPF6_SCOPE_TYPE_NONE 0 |
201 | #define OSPF6_SCOPE_TYPE_GLOBAL 1 | |
202 | #define OSPF6_SCOPE_TYPE_AREA 2 | |
203 | #define OSPF6_SCOPE_TYPE_INTERFACE 3 | |
204 | ||
205 | #define OSPF6_TABLE_TYPE_NONE 0 | |
206 | #define OSPF6_TABLE_TYPE_ROUTES 1 | |
207 | #define OSPF6_TABLE_TYPE_BORDER_ROUTERS 2 | |
208 | #define OSPF6_TABLE_TYPE_CONNECTED_ROUTES 3 | |
209 | #define OSPF6_TABLE_TYPE_EXTERNAL_ROUTES 4 | |
210 | #define OSPF6_TABLE_TYPE_SPF_RESULTS 5 | |
211 | #define OSPF6_TABLE_TYPE_PREFIX_RANGES 6 | |
212 | #define OSPF6_TABLE_TYPE_SUMMARY_PREFIXES 7 | |
213 | #define OSPF6_TABLE_TYPE_SUMMARY_ROUTERS 8 | |
214 | ||
215 | #define OSPF6_ROUTE_TABLE_CREATE(s, t) \ | |
216 | ospf6_route_table_create (OSPF6_SCOPE_TYPE_ ## s, \ | |
217 | OSPF6_TABLE_TYPE_ ## t) | |
218 | ||
0c083ee9 | 219 | extern const char *ospf6_dest_type_str[OSPF6_DEST_TYPE_MAX]; |
220 | extern const char *ospf6_dest_type_substr[OSPF6_DEST_TYPE_MAX]; | |
508e53e2 | 221 | #define OSPF6_DEST_TYPE_NAME(x) \ |
222 | (0 < (x) && (x) < OSPF6_DEST_TYPE_MAX ? \ | |
223 | ospf6_dest_type_str[(x)] : ospf6_dest_type_str[0]) | |
224 | #define OSPF6_DEST_TYPE_SUBSTR(x) \ | |
225 | (0 < (x) && (x) < OSPF6_DEST_TYPE_MAX ? \ | |
226 | ospf6_dest_type_substr[(x)] : ospf6_dest_type_substr[0]) | |
227 | ||
0c083ee9 | 228 | extern const char *ospf6_path_type_str[OSPF6_PATH_TYPE_MAX]; |
229 | extern const char *ospf6_path_type_substr[OSPF6_PATH_TYPE_MAX]; | |
508e53e2 | 230 | #define OSPF6_PATH_TYPE_NAME(x) \ |
231 | (0 < (x) && (x) < OSPF6_PATH_TYPE_MAX ? \ | |
232 | ospf6_path_type_str[(x)] : ospf6_path_type_str[0]) | |
233 | #define OSPF6_PATH_TYPE_SUBSTR(x) \ | |
234 | (0 < (x) && (x) < OSPF6_PATH_TYPE_MAX ? \ | |
235 | ospf6_path_type_substr[(x)] : ospf6_path_type_substr[0]) | |
236 | ||
237 | #define OSPF6_ROUTE_ADDRESS_STR "Display the route bestmatches the address\n" | |
238 | #define OSPF6_ROUTE_PREFIX_STR "Display the route\n" | |
239 | #define OSPF6_ROUTE_MATCH_STR "Display the route matches the prefix\n" | |
240 | ||
241 | #define ospf6_route_is_prefix(p, r) \ | |
242 | (memcmp (p, &(r)->prefix, sizeof (struct prefix)) == 0) | |
243 | #define ospf6_route_is_same(ra, rb) \ | |
244 | (prefix_same (&(ra)->prefix, &(rb)->prefix)) | |
245 | #define ospf6_route_is_same_origin(ra, rb) \ | |
246 | ((ra)->path.area_id == (rb)->path.area_id && \ | |
247 | memcmp (&(ra)->path.origin, &(rb)->path.origin, \ | |
248 | sizeof (struct ospf6_ls_origin)) == 0) | |
249 | #define ospf6_route_is_identical(ra, rb) \ | |
250 | ((ra)->type == (rb)->type && \ | |
251 | memcmp (&(ra)->prefix, &(rb)->prefix, sizeof (struct prefix)) == 0 && \ | |
252 | memcmp (&(ra)->path, &(rb)->path, sizeof (struct ospf6_path)) == 0 && \ | |
c3c0ac83 DS |
253 | ospf6_route_cmp_nexthops (ra, rb) == 0) |
254 | ||
508e53e2 | 255 | #define ospf6_route_is_best(r) (CHECK_FLAG ((r)->flag, OSPF6_ROUTE_BEST)) |
256 | ||
257 | #define ospf6_linkstate_prefix_adv_router(x) \ | |
81382410 | 258 | ((x)->u.lp.id.s_addr) |
508e53e2 | 259 | #define ospf6_linkstate_prefix_id(x) \ |
81382410 | 260 | ((x)->u.lp.adv_router.s_addr) |
508e53e2 | 261 | |
3b68735f | 262 | #define ADV_ROUTER_IN_PREFIX(x) \ |
81382410 | 263 | ((x)->u.lp.id.s_addr) |
3b68735f | 264 | |
508e53e2 | 265 | /* Function prototype */ |
6ac29a51 PJ |
266 | extern void ospf6_linkstate_prefix (u_int32_t adv_router, u_int32_t id, |
267 | struct prefix *prefix); | |
268 | extern void ospf6_linkstate_prefix2str (struct prefix *prefix, char *buf, | |
269 | int size); | |
270 | ||
c3c0ac83 DS |
271 | extern struct ospf6_nexthop *ospf6_nexthop_create (void); |
272 | extern void ospf6_nexthop_delete (struct ospf6_nexthop *nh); | |
273 | extern void ospf6_free_nexthops (struct list *nh_list); | |
274 | extern void ospf6_clear_nexthops (struct list *nh_list); | |
275 | extern int ospf6_num_nexthops (struct list *nh_list); | |
276 | extern void ospf6_copy_nexthops (struct list *dst, struct list *src); | |
277 | extern void ospf6_merge_nexthops (struct list *dst, struct list *src); | |
278 | extern void ospf6_add_nexthop (struct list *nh_list, int ifindex, | |
279 | struct in6_addr *addr); | |
280 | extern int ospf6_num_nexthops (struct list *nh_list); | |
281 | extern int ospf6_route_cmp_nexthops (struct ospf6_route *a, | |
282 | struct ospf6_route *b); | |
283 | extern void ospf6_route_zebra_copy_nexthops (struct ospf6_route *route, | |
b892f1dd | 284 | ifindex_t *ifindices, |
c3c0ac83 DS |
285 | struct in6_addr **addr, |
286 | int entries); | |
287 | extern int ospf6_route_get_first_nh_index (struct ospf6_route *route); | |
288 | ||
289 | /* Hide abstraction of nexthop implementation in route from outsiders */ | |
290 | #define ospf6_route_copy_nexthops(dst, src) ospf6_copy_nexthops(dst->nh_list, src->nh_list) | |
291 | #define ospf6_route_merge_nexthops(dst, src) ospf6_merge_nexthops(dst->nh_list, src->nh_list) | |
292 | #define ospf6_route_num_nexthops(route) ospf6_num_nexthops(route->nh_list) | |
293 | #define ospf6_route_add_nexthop(route, ifindex, addr) \ | |
294 | ospf6_add_nexthop(route->nh_list, ifindex, addr) | |
295 | ||
6ac29a51 PJ |
296 | extern struct ospf6_route *ospf6_route_create (void); |
297 | extern void ospf6_route_delete (struct ospf6_route *); | |
298 | extern struct ospf6_route *ospf6_route_copy (struct ospf6_route *route); | |
c3c0ac83 | 299 | extern int ospf6_route_cmp (struct ospf6_route *ra, struct ospf6_route *rb); |
6ac29a51 PJ |
300 | |
301 | extern void ospf6_route_lock (struct ospf6_route *route); | |
302 | extern void ospf6_route_unlock (struct ospf6_route *route); | |
303 | ||
304 | extern struct ospf6_route *ospf6_route_lookup (struct prefix *prefix, | |
305 | struct ospf6_route_table *table); | |
306 | extern struct ospf6_route *ospf6_route_lookup_identical (struct ospf6_route *route, | |
307 | struct ospf6_route_table *table); | |
308 | extern struct ospf6_route *ospf6_route_lookup_bestmatch (struct prefix *prefix, | |
309 | struct ospf6_route_table *table); | |
310 | ||
311 | extern struct ospf6_route *ospf6_route_add (struct ospf6_route *route, | |
312 | struct ospf6_route_table *table); | |
313 | extern void ospf6_route_remove (struct ospf6_route *route, | |
314 | struct ospf6_route_table *table); | |
315 | ||
316 | extern struct ospf6_route *ospf6_route_head (struct ospf6_route_table *table); | |
317 | extern struct ospf6_route *ospf6_route_next (struct ospf6_route *route); | |
318 | extern struct ospf6_route *ospf6_route_best_next (struct ospf6_route *route); | |
319 | ||
320 | extern struct ospf6_route *ospf6_route_match_head (struct prefix *prefix, | |
508e53e2 | 321 | struct ospf6_route_table *table); |
6ac29a51 | 322 | extern struct ospf6_route *ospf6_route_match_next (struct prefix *prefix, |
508e53e2 | 323 | struct ospf6_route *route); |
324 | ||
6ac29a51 PJ |
325 | extern void ospf6_route_remove_all (struct ospf6_route_table *); |
326 | extern struct ospf6_route_table *ospf6_route_table_create (int s, int t); | |
327 | extern void ospf6_route_table_delete (struct ospf6_route_table *); | |
328 | extern void ospf6_route_dump (struct ospf6_route_table *table); | |
718e3744 | 329 | |
6452df09 | 330 | |
6ac29a51 PJ |
331 | extern void ospf6_route_show (struct vty *vty, struct ospf6_route *route); |
332 | extern void ospf6_route_show_detail (struct vty *vty, struct ospf6_route *route); | |
6452df09 | 333 | |
1d68dbfe | 334 | extern int ospf6_route_table_show (struct vty *, int, int, struct cmd_token **, |
6ac29a51 | 335 | struct ospf6_route_table *); |
8749a04c | 336 | extern int ospf6_linkstate_table_show (struct vty *vty, int idx_ipv4, int argc, |
cc9de1ba | 337 | struct cmd_token **argv, |
6ac29a51 | 338 | struct ospf6_route_table *table); |
508e53e2 | 339 | |
6ac29a51 PJ |
340 | extern void ospf6_brouter_show_header (struct vty *vty); |
341 | extern void ospf6_brouter_show (struct vty *vty, struct ospf6_route *route); | |
6452df09 | 342 | |
6ac29a51 PJ |
343 | extern int config_write_ospf6_debug_route (struct vty *vty); |
344 | extern void install_element_ospf6_debug_route (void); | |
345 | extern void ospf6_route_init (void); | |
ef2d5d10 | 346 | extern void ospf6_clean (void); |
718e3744 | 347 | |
348 | #endif /* OSPF6_ROUTE_H */ | |
349 |