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