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