]>
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 | ||
508e53e2 | 21 | #include <zebra.h> |
22 | ||
23 | #include "log.h" | |
24 | #include "memory.h" | |
25 | #include "prefix.h" | |
26 | #include "table.h" | |
27 | #include "vty.h" | |
28 | #include "command.h" | |
cf1ce250 | 29 | #include "linklist.h" |
508e53e2 | 30 | |
508e53e2 | 31 | #include "ospf6_proto.h" |
32 | #include "ospf6_lsa.h" | |
049207c3 | 33 | #include "ospf6_lsdb.h" |
508e53e2 | 34 | #include "ospf6_route.h" |
cf1ce250 PJ |
35 | #include "ospf6_top.h" |
36 | #include "ospf6_area.h" | |
37 | #include "ospf6_interface.h" | |
049207c3 | 38 | #include "ospf6d.h" |
c3c0ac83 | 39 | #include "ospf6_zebra.h" |
718e3744 | 40 | |
508e53e2 | 41 | unsigned char conf_debug_ospf6_route = 0; |
718e3744 | 42 | |
d62a17ae | 43 | static char *ospf6_route_table_name(struct ospf6_route_table *table) |
cf1ce250 | 44 | { |
d62a17ae | 45 | static char name[64]; |
46 | switch (table->scope_type) { | |
47 | case OSPF6_SCOPE_TYPE_GLOBAL: { | |
48 | switch (table->table_type) { | |
49 | case OSPF6_TABLE_TYPE_ROUTES: | |
50 | snprintf(name, sizeof(name), "global route table"); | |
51 | break; | |
52 | case OSPF6_TABLE_TYPE_BORDER_ROUTERS: | |
53 | snprintf(name, sizeof(name), "global brouter table"); | |
54 | break; | |
55 | case OSPF6_TABLE_TYPE_EXTERNAL_ROUTES: | |
56 | snprintf(name, sizeof(name), "global external table"); | |
57 | break; | |
58 | default: | |
59 | snprintf(name, sizeof(name), "global unknown table"); | |
60 | break; | |
61 | } | |
62 | } break; | |
63 | ||
64 | case OSPF6_SCOPE_TYPE_AREA: { | |
65 | struct ospf6_area *oa = (struct ospf6_area *)table->scope; | |
66 | switch (table->table_type) { | |
67 | case OSPF6_TABLE_TYPE_SPF_RESULTS: | |
68 | snprintf(name, sizeof(name), "area %s spf table", | |
69 | oa->name); | |
70 | break; | |
71 | case OSPF6_TABLE_TYPE_ROUTES: | |
72 | snprintf(name, sizeof(name), "area %s route table", | |
73 | oa->name); | |
74 | break; | |
75 | case OSPF6_TABLE_TYPE_PREFIX_RANGES: | |
76 | snprintf(name, sizeof(name), "area %s range table", | |
77 | oa->name); | |
78 | break; | |
79 | case OSPF6_TABLE_TYPE_SUMMARY_PREFIXES: | |
80 | snprintf(name, sizeof(name), | |
81 | "area %s summary prefix table", oa->name); | |
82 | break; | |
83 | case OSPF6_TABLE_TYPE_SUMMARY_ROUTERS: | |
84 | snprintf(name, sizeof(name), | |
85 | "area %s summary router table", oa->name); | |
86 | break; | |
87 | default: | |
88 | snprintf(name, sizeof(name), "area %s unknown table", | |
89 | oa->name); | |
90 | break; | |
91 | } | |
92 | } break; | |
93 | ||
94 | case OSPF6_SCOPE_TYPE_INTERFACE: { | |
95 | struct ospf6_interface *oi = | |
96 | (struct ospf6_interface *)table->scope; | |
97 | switch (table->table_type) { | |
98 | case OSPF6_TABLE_TYPE_CONNECTED_ROUTES: | |
99 | snprintf(name, sizeof(name), | |
100 | "interface %s connected table", | |
101 | oi->interface->name); | |
102 | break; | |
103 | default: | |
104 | snprintf(name, sizeof(name), | |
105 | "interface %s unknown table", | |
106 | oi->interface->name); | |
107 | break; | |
108 | } | |
109 | } break; | |
110 | ||
111 | default: { | |
112 | switch (table->table_type) { | |
113 | case OSPF6_TABLE_TYPE_SPF_RESULTS: | |
114 | snprintf(name, sizeof(name), "temporary spf table"); | |
115 | break; | |
116 | default: | |
117 | snprintf(name, sizeof(name), "temporary unknown table"); | |
118 | break; | |
119 | } | |
120 | } break; | |
121 | } | |
122 | return name; | |
cf1ce250 PJ |
123 | } |
124 | ||
d7c0a89a | 125 | void ospf6_linkstate_prefix(uint32_t adv_router, uint32_t id, |
d62a17ae | 126 | struct prefix *prefix) |
508e53e2 | 127 | { |
d62a17ae | 128 | memset(prefix, 0, sizeof(struct prefix)); |
129 | prefix->family = AF_INET6; | |
130 | prefix->prefixlen = 64; | |
131 | memcpy(&prefix->u.prefix6.s6_addr[0], &adv_router, 4); | |
132 | memcpy(&prefix->u.prefix6.s6_addr[4], &id, 4); | |
508e53e2 | 133 | } |
718e3744 | 134 | |
d62a17ae | 135 | void ospf6_linkstate_prefix2str(struct prefix *prefix, char *buf, int size) |
718e3744 | 136 | { |
d7c0a89a | 137 | uint32_t adv_router, id; |
d62a17ae | 138 | char adv_router_str[16], id_str[16]; |
139 | memcpy(&adv_router, &prefix->u.prefix6.s6_addr[0], 4); | |
140 | memcpy(&id, &prefix->u.prefix6.s6_addr[4], 4); | |
141 | inet_ntop(AF_INET, &adv_router, adv_router_str, sizeof(adv_router_str)); | |
142 | inet_ntop(AF_INET, &id, id_str, sizeof(id_str)); | |
143 | if (ntohl(id)) | |
144 | snprintf(buf, size, "%s Net-ID: %s", adv_router_str, id_str); | |
145 | else | |
146 | snprintf(buf, size, "%s", adv_router_str); | |
508e53e2 | 147 | } |
718e3744 | 148 | |
508e53e2 | 149 | /* Global strings for logging */ |
d62a17ae | 150 | const char *ospf6_dest_type_str[OSPF6_DEST_TYPE_MAX] = { |
151 | "Unknown", "Router", "Network", "Discard", "Linkstate", "AddressRange", | |
152 | }; | |
718e3744 | 153 | |
d62a17ae | 154 | const char *ospf6_dest_type_substr[OSPF6_DEST_TYPE_MAX] = { |
155 | "?", "R", "N", "D", "L", "A", | |
156 | }; | |
718e3744 | 157 | |
d62a17ae | 158 | const char *ospf6_path_type_str[OSPF6_PATH_TYPE_MAX] = { |
159 | "Unknown", "Intra-Area", "Inter-Area", "External-1", "External-2", | |
160 | }; | |
718e3744 | 161 | |
d62a17ae | 162 | const char *ospf6_path_type_substr[OSPF6_PATH_TYPE_MAX] = { |
163 | "??", "IA", "IE", "E1", "E2", | |
164 | }; | |
718e3744 | 165 | |
718e3744 | 166 | |
d62a17ae | 167 | struct ospf6_nexthop *ospf6_nexthop_create(void) |
c3c0ac83 | 168 | { |
d62a17ae | 169 | struct ospf6_nexthop *nh; |
c3c0ac83 | 170 | |
d62a17ae | 171 | nh = XCALLOC(MTYPE_OSPF6_NEXTHOP, sizeof(struct ospf6_nexthop)); |
172 | return nh; | |
c3c0ac83 DS |
173 | } |
174 | ||
d62a17ae | 175 | void ospf6_nexthop_delete(struct ospf6_nexthop *nh) |
c3c0ac83 | 176 | { |
0a22ddfb | 177 | XFREE(MTYPE_OSPF6_NEXTHOP, nh); |
c3c0ac83 DS |
178 | } |
179 | ||
d62a17ae | 180 | void ospf6_clear_nexthops(struct list *nh_list) |
c3c0ac83 | 181 | { |
d62a17ae | 182 | struct listnode *node; |
183 | struct ospf6_nexthop *nh; | |
184 | ||
185 | if (nh_list) { | |
186 | for (ALL_LIST_ELEMENTS_RO(nh_list, node, nh)) | |
187 | ospf6_nexthop_clear(nh); | |
188 | } | |
c3c0ac83 DS |
189 | } |
190 | ||
191 | static struct ospf6_nexthop * | |
d62a17ae | 192 | ospf6_route_find_nexthop(struct list *nh_list, struct ospf6_nexthop *nh_match) |
c3c0ac83 | 193 | { |
d62a17ae | 194 | struct listnode *node; |
195 | struct ospf6_nexthop *nh; | |
196 | ||
197 | if (nh_list && nh_match) { | |
198 | for (ALL_LIST_ELEMENTS_RO(nh_list, node, nh)) { | |
199 | if (ospf6_nexthop_is_same(nh, nh_match)) | |
200 | return (nh); | |
201 | } | |
c3c0ac83 | 202 | } |
c3c0ac83 | 203 | |
d62a17ae | 204 | return (NULL); |
c3c0ac83 DS |
205 | } |
206 | ||
d62a17ae | 207 | void ospf6_copy_nexthops(struct list *dst, struct list *src) |
c3c0ac83 | 208 | { |
d62a17ae | 209 | struct ospf6_nexthop *nh_new, *nh; |
210 | struct listnode *node; | |
211 | ||
212 | if (dst && src) { | |
213 | for (ALL_LIST_ELEMENTS_RO(src, node, nh)) { | |
214 | if (ospf6_nexthop_is_set(nh)) { | |
215 | nh_new = ospf6_nexthop_create(); | |
216 | ospf6_nexthop_copy(nh_new, nh); | |
064d4355 | 217 | listnode_add_sort(dst, nh_new); |
d62a17ae | 218 | } |
219 | } | |
c3c0ac83 | 220 | } |
c3c0ac83 DS |
221 | } |
222 | ||
d62a17ae | 223 | void ospf6_merge_nexthops(struct list *dst, struct list *src) |
c3c0ac83 | 224 | { |
d62a17ae | 225 | struct listnode *node; |
226 | struct ospf6_nexthop *nh, *nh_new; | |
227 | ||
228 | if (src && dst) { | |
229 | for (ALL_LIST_ELEMENTS_RO(src, node, nh)) { | |
230 | if (!ospf6_route_find_nexthop(dst, nh)) { | |
231 | nh_new = ospf6_nexthop_create(); | |
232 | ospf6_nexthop_copy(nh_new, nh); | |
064d4355 | 233 | listnode_add_sort(dst, nh_new); |
d62a17ae | 234 | } |
235 | } | |
c3c0ac83 | 236 | } |
c3c0ac83 DS |
237 | } |
238 | ||
d62a17ae | 239 | int ospf6_route_cmp_nexthops(struct ospf6_route *a, struct ospf6_route *b) |
c3c0ac83 | 240 | { |
d62a17ae | 241 | struct listnode *anode, *bnode; |
242 | struct ospf6_nexthop *anh, *bnh; | |
f867df18 | 243 | bool identical = false; |
d62a17ae | 244 | |
245 | if (a && b) { | |
246 | if (listcount(a->nh_list) == listcount(b->nh_list)) { | |
247 | for (ALL_LIST_ELEMENTS_RO(a->nh_list, anode, anh)) { | |
f867df18 | 248 | identical = false; |
d62a17ae | 249 | for (ALL_LIST_ELEMENTS_RO(b->nh_list, bnode, |
f867df18 CS |
250 | bnh)) { |
251 | if (ospf6_nexthop_is_same(anh, bnh)) | |
252 | identical = true; | |
253 | } | |
254 | /* Currnet List A element not found List B | |
255 | * Non-Identical lists return */ | |
256 | if (identical == false) | |
257 | return 1; | |
d62a17ae | 258 | } |
f867df18 | 259 | return 0; |
d62a17ae | 260 | } else |
f867df18 | 261 | return 1; |
c3c0ac83 | 262 | } |
d62a17ae | 263 | /* One of the routes doesn't exist ? */ |
c3c0ac83 | 264 | return (1); |
c3c0ac83 DS |
265 | } |
266 | ||
d62a17ae | 267 | int ospf6_num_nexthops(struct list *nh_list) |
c3c0ac83 | 268 | { |
d62a17ae | 269 | return (listcount(nh_list)); |
c3c0ac83 DS |
270 | } |
271 | ||
d62a17ae | 272 | void ospf6_add_nexthop(struct list *nh_list, int ifindex, struct in6_addr *addr) |
c3c0ac83 | 273 | { |
d62a17ae | 274 | struct ospf6_nexthop *nh; |
275 | struct ospf6_nexthop nh_match; | |
276 | ||
277 | if (nh_list) { | |
278 | nh_match.ifindex = ifindex; | |
279 | if (addr != NULL) | |
280 | memcpy(&nh_match.address, addr, | |
281 | sizeof(struct in6_addr)); | |
282 | else | |
283 | memset(&nh_match.address, 0, sizeof(struct in6_addr)); | |
284 | ||
285 | if (!ospf6_route_find_nexthop(nh_list, &nh_match)) { | |
286 | nh = ospf6_nexthop_create(); | |
287 | ospf6_nexthop_copy(nh, &nh_match); | |
288 | listnode_add(nh_list, nh); | |
289 | } | |
c3c0ac83 | 290 | } |
c3c0ac83 DS |
291 | } |
292 | ||
d62a17ae | 293 | void ospf6_route_zebra_copy_nexthops(struct ospf6_route *route, |
5afa1c6b | 294 | struct zapi_nexthop nexthops[], |
d62a17ae | 295 | int entries) |
c3c0ac83 | 296 | { |
d62a17ae | 297 | struct ospf6_nexthop *nh; |
298 | struct listnode *node; | |
299 | char buf[64]; | |
300 | int i; | |
301 | ||
302 | if (route) { | |
303 | i = 0; | |
304 | for (ALL_LIST_ELEMENTS_RO(route->nh_list, node, nh)) { | |
305 | if (IS_OSPF6_DEBUG_ZEBRA(SEND)) { | |
306 | const char *ifname; | |
307 | inet_ntop(AF_INET6, &nh->address, buf, | |
308 | sizeof(buf)); | |
309 | ifname = ifindex2ifname(nh->ifindex, | |
310 | VRF_DEFAULT); | |
311 | zlog_debug(" nexthop: %s%%%.*s(%d)", buf, | |
312 | IFNAMSIZ, ifname, nh->ifindex); | |
313 | } | |
b30f3b91 RW |
314 | if (i >= entries) |
315 | return; | |
316 | ||
4a7371e9 | 317 | nexthops[i].vrf_id = VRF_DEFAULT; |
b30f3b91 RW |
318 | nexthops[i].ifindex = nh->ifindex; |
319 | if (!IN6_IS_ADDR_UNSPECIFIED(&nh->address)) { | |
5afa1c6b | 320 | nexthops[i].gate.ipv6 = nh->address; |
5afa1c6b | 321 | nexthops[i].type = NEXTHOP_TYPE_IPV6_IFINDEX; |
b30f3b91 RW |
322 | } else |
323 | nexthops[i].type = NEXTHOP_TYPE_IFINDEX; | |
324 | i++; | |
d62a17ae | 325 | } |
c3c0ac83 | 326 | } |
c3c0ac83 DS |
327 | } |
328 | ||
d62a17ae | 329 | int ospf6_route_get_first_nh_index(struct ospf6_route *route) |
c3c0ac83 | 330 | { |
d62a17ae | 331 | struct ospf6_nexthop *nh; |
c3c0ac83 | 332 | |
d62a17ae | 333 | if (route) { |
10197318 DS |
334 | nh = listnode_head(route->nh_list); |
335 | if (nh) | |
336 | return nh->ifindex; | |
d62a17ae | 337 | } |
c3c0ac83 | 338 | |
d62a17ae | 339 | return (-1); |
c3c0ac83 DS |
340 | } |
341 | ||
064d4355 | 342 | int ospf6_nexthop_cmp(struct ospf6_nexthop *a, struct ospf6_nexthop *b) |
d107621d | 343 | { |
f867df18 CS |
344 | if (a->ifindex < b->ifindex) |
345 | return -1; | |
346 | else if (a->ifindex > b->ifindex) | |
d107621d | 347 | return 1; |
f867df18 CS |
348 | else |
349 | return memcmp(&a->address, &b->address, | |
350 | sizeof(struct in6_addr)); | |
351 | ||
d107621d CS |
352 | return 0; |
353 | } | |
354 | ||
064d4355 CS |
355 | static int ospf6_path_cmp(struct ospf6_path *a, struct ospf6_path *b) |
356 | { | |
357 | if (a->origin.adv_router < b->origin.adv_router) | |
358 | return -1; | |
359 | else if (a->origin.adv_router > b->origin.adv_router) | |
360 | return 1; | |
361 | else | |
362 | return 0; | |
363 | } | |
364 | ||
365 | void ospf6_path_free(struct ospf6_path *op) | |
366 | { | |
367 | if (op->nh_list) | |
6a154c88 | 368 | list_delete(&op->nh_list); |
064d4355 CS |
369 | XFREE(MTYPE_OSPF6_PATH, op); |
370 | } | |
371 | ||
372 | struct ospf6_path *ospf6_path_dup(struct ospf6_path *path) | |
373 | { | |
374 | struct ospf6_path *new; | |
375 | ||
376 | new = XCALLOC(MTYPE_OSPF6_PATH, sizeof(struct ospf6_path)); | |
377 | memcpy(new, path, sizeof(struct ospf6_path)); | |
378 | new->nh_list = list_new(); | |
379 | new->nh_list->cmp = (int (*)(void *, void *))ospf6_nexthop_cmp; | |
996c9314 | 380 | new->nh_list->del = (void (*)(void *))ospf6_nexthop_delete; |
064d4355 CS |
381 | |
382 | return new; | |
383 | } | |
384 | ||
03f3c1c1 CS |
385 | void ospf6_copy_paths(struct list *dst, struct list *src) |
386 | { | |
387 | struct ospf6_path *path_new, *path; | |
388 | struct listnode *node; | |
389 | ||
390 | if (dst && src) { | |
391 | for (ALL_LIST_ELEMENTS_RO(src, node, path)) { | |
392 | path_new = ospf6_path_dup(path); | |
393 | ospf6_copy_nexthops(path_new->nh_list, path->nh_list); | |
394 | listnode_add_sort(dst, path_new); | |
395 | } | |
396 | } | |
397 | } | |
398 | ||
d62a17ae | 399 | struct ospf6_route *ospf6_route_create(void) |
718e3744 | 400 | { |
d62a17ae | 401 | struct ospf6_route *route; |
402 | route = XCALLOC(MTYPE_OSPF6_ROUTE, sizeof(struct ospf6_route)); | |
403 | route->nh_list = list_new(); | |
d107621d | 404 | route->nh_list->cmp = (int (*)(void *, void *))ospf6_nexthop_cmp; |
996c9314 | 405 | route->nh_list->del = (void (*)(void *))ospf6_nexthop_delete; |
064d4355 CS |
406 | route->paths = list_new(); |
407 | route->paths->cmp = (int (*)(void *, void *))ospf6_path_cmp; | |
996c9314 | 408 | route->paths->del = (void (*)(void *))ospf6_path_free; |
d62a17ae | 409 | return route; |
508e53e2 | 410 | } |
718e3744 | 411 | |
d62a17ae | 412 | void ospf6_route_delete(struct ospf6_route *route) |
508e53e2 | 413 | { |
d62a17ae | 414 | if (route) { |
d107621d | 415 | if (route->nh_list) |
6a154c88 | 416 | list_delete(&route->nh_list); |
064d4355 | 417 | if (route->paths) |
6a154c88 | 418 | list_delete(&route->paths); |
d62a17ae | 419 | XFREE(MTYPE_OSPF6_ROUTE, route); |
420 | } | |
718e3744 | 421 | } |
422 | ||
d62a17ae | 423 | struct ospf6_route *ospf6_route_copy(struct ospf6_route *route) |
718e3744 | 424 | { |
d62a17ae | 425 | struct ospf6_route *new; |
426 | ||
427 | new = ospf6_route_create(); | |
428 | new->type = route->type; | |
429 | memcpy(&new->prefix, &route->prefix, sizeof(struct prefix)); | |
430 | new->installed = route->installed; | |
431 | new->changed = route->changed; | |
432 | new->flag = route->flag; | |
433 | new->route_option = route->route_option; | |
434 | new->linkstate_id = route->linkstate_id; | |
435 | new->path = route->path; | |
436 | ospf6_copy_nexthops(new->nh_list, route->nh_list); | |
03f3c1c1 | 437 | ospf6_copy_paths(new->paths, route->paths); |
d62a17ae | 438 | new->rnode = NULL; |
439 | new->prev = NULL; | |
440 | new->next = NULL; | |
441 | new->table = NULL; | |
442 | new->lock = 0; | |
443 | return new; | |
508e53e2 | 444 | } |
718e3744 | 445 | |
d62a17ae | 446 | void ospf6_route_lock(struct ospf6_route *route) |
508e53e2 | 447 | { |
d62a17ae | 448 | route->lock++; |
508e53e2 | 449 | } |
718e3744 | 450 | |
d62a17ae | 451 | void ospf6_route_unlock(struct ospf6_route *route) |
508e53e2 | 452 | { |
d62a17ae | 453 | assert(route->lock > 0); |
454 | route->lock--; | |
455 | if (route->lock == 0) { | |
456 | /* Can't detach from the table until here | |
457 | because ospf6_route_next () will use | |
458 | the 'route->table' pointer for logging */ | |
459 | route->table = NULL; | |
460 | ospf6_route_delete(route); | |
461 | } | |
508e53e2 | 462 | } |
718e3744 | 463 | |
508e53e2 | 464 | /* Route compare function. If ra is more preferred, it returns |
465 | less than 0. If rb is more preferred returns greater than 0. | |
466 | Otherwise (neither one is preferred), returns 0 */ | |
d62a17ae | 467 | int ospf6_route_cmp(struct ospf6_route *ra, struct ospf6_route *rb) |
508e53e2 | 468 | { |
d62a17ae | 469 | assert(ospf6_route_is_same(ra, rb)); |
470 | assert(OSPF6_PATH_TYPE_NONE < ra->path.type | |
471 | && ra->path.type < OSPF6_PATH_TYPE_MAX); | |
472 | assert(OSPF6_PATH_TYPE_NONE < rb->path.type | |
473 | && rb->path.type < OSPF6_PATH_TYPE_MAX); | |
474 | ||
475 | if (ra->type != rb->type) | |
476 | return (ra->type - rb->type); | |
477 | ||
d62a17ae | 478 | if (ra->path.type != rb->path.type) |
479 | return (ra->path.type - rb->path.type); | |
480 | ||
481 | if (ra->path.type == OSPF6_PATH_TYPE_EXTERNAL2) { | |
482 | if (ra->path.u.cost_e2 != rb->path.u.cost_e2) | |
483 | return (ra->path.u.cost_e2 - rb->path.u.cost_e2); | |
07b37f93 CS |
484 | else |
485 | return (ra->path.cost - rb->path.cost); | |
d62a17ae | 486 | } else { |
487 | if (ra->path.cost != rb->path.cost) | |
488 | return (ra->path.cost - rb->path.cost); | |
489 | } | |
490 | ||
10efbdc2 CS |
491 | if (ra->path.area_id != rb->path.area_id) |
492 | return (ntohl(ra->path.area_id) - ntohl(rb->path.area_id)); | |
493 | ||
d62a17ae | 494 | return 0; |
718e3744 | 495 | } |
496 | ||
d62a17ae | 497 | struct ospf6_route *ospf6_route_lookup(struct prefix *prefix, |
498 | struct ospf6_route_table *table) | |
718e3744 | 499 | { |
d62a17ae | 500 | struct route_node *node; |
501 | struct ospf6_route *route; | |
718e3744 | 502 | |
d62a17ae | 503 | node = route_node_lookup(table->table, prefix); |
504 | if (node == NULL) | |
505 | return NULL; | |
508e53e2 | 506 | |
d62a17ae | 507 | route = (struct ospf6_route *)node->info; |
d107621d | 508 | route_unlock_node(node); /* to free the lookup lock */ |
d62a17ae | 509 | return route; |
508e53e2 | 510 | } |
718e3744 | 511 | |
508e53e2 | 512 | struct ospf6_route * |
d62a17ae | 513 | ospf6_route_lookup_identical(struct ospf6_route *route, |
514 | struct ospf6_route_table *table) | |
508e53e2 | 515 | { |
d62a17ae | 516 | struct ospf6_route *target; |
517 | ||
518 | for (target = ospf6_route_lookup(&route->prefix, table); target; | |
519 | target = target->next) { | |
996c9314 LB |
520 | if (target->type == route->type |
521 | && (memcmp(&target->prefix, &route->prefix, | |
522 | sizeof(struct prefix)) | |
523 | == 0) | |
524 | && target->path.type == route->path.type | |
525 | && target->path.cost == route->path.cost | |
526 | && target->path.u.cost_e2 == route->path.u.cost_e2 | |
527 | && ospf6_route_cmp_nexthops(target, route) == 0) | |
d62a17ae | 528 | return target; |
529 | } | |
530 | return NULL; | |
718e3744 | 531 | } |
532 | ||
508e53e2 | 533 | struct ospf6_route * |
d62a17ae | 534 | ospf6_route_lookup_bestmatch(struct prefix *prefix, |
535 | struct ospf6_route_table *table) | |
718e3744 | 536 | { |
d62a17ae | 537 | struct route_node *node; |
538 | struct ospf6_route *route; | |
718e3744 | 539 | |
d62a17ae | 540 | node = route_node_match(table->table, prefix); |
541 | if (node == NULL) | |
542 | return NULL; | |
543 | route_unlock_node(node); | |
718e3744 | 544 | |
d62a17ae | 545 | route = (struct ospf6_route *)node->info; |
546 | return route; | |
718e3744 | 547 | } |
548 | ||
e39d0538 | 549 | #ifdef DEBUG |
d62a17ae | 550 | static void route_table_assert(struct ospf6_route_table *table) |
718e3744 | 551 | { |
d62a17ae | 552 | struct ospf6_route *prev, *r, *next; |
553 | char buf[PREFIX2STR_BUFFER]; | |
554 | unsigned int link_error = 0, num = 0; | |
555 | ||
556 | r = ospf6_route_head(table); | |
557 | prev = NULL; | |
558 | while (r) { | |
559 | if (r->prev != prev) | |
560 | link_error++; | |
561 | ||
562 | next = ospf6_route_next(r); | |
563 | ||
564 | if (r->next != next) | |
565 | link_error++; | |
566 | ||
567 | prev = r; | |
568 | r = next; | |
569 | } | |
570 | ||
571 | for (r = ospf6_route_head(table); r; r = ospf6_route_next(r)) | |
572 | num++; | |
573 | ||
574 | if (link_error == 0 && num == table->count) | |
575 | return; | |
576 | ||
450971aa | 577 | flog_err(EC_LIB_DEVELOPMENT, "PANIC !!"); |
1c50c1c0 QY |
578 | flog_err(EC_LIB_DEVELOPMENT, |
579 | "Something has gone wrong with ospf6_route_table[%p]", table); | |
d62a17ae | 580 | zlog_debug("table count = %d, real number = %d", table->count, num); |
581 | zlog_debug("DUMP START"); | |
582 | for (r = ospf6_route_head(table); r; r = ospf6_route_next(r)) { | |
583 | prefix2str(&r->prefix, buf, sizeof(buf)); | |
584 | zlog_info("%p<-[%p]->%p : %s", r->prev, r, r->next, buf); | |
585 | } | |
586 | zlog_debug("DUMP END"); | |
587 | ||
588 | assert(link_error == 0 && num == table->count); | |
718e3744 | 589 | } |
cf1ce250 | 590 | #define ospf6_route_table_assert(t) (route_table_assert (t)) |
508e53e2 | 591 | #else |
cf1ce250 | 592 | #define ospf6_route_table_assert(t) ((void) 0) |
e39d0538 | 593 | #endif /*DEBUG*/ |
718e3744 | 594 | |
d62a17ae | 595 | struct ospf6_route *ospf6_route_add(struct ospf6_route *route, |
596 | struct ospf6_route_table *table) | |
718e3744 | 597 | { |
d62a17ae | 598 | struct route_node *node, *nextnode, *prevnode; |
599 | struct ospf6_route *current = NULL; | |
600 | struct ospf6_route *prev = NULL, *old = NULL, *next = NULL; | |
601 | char buf[PREFIX2STR_BUFFER]; | |
602 | struct timeval now; | |
603 | ||
604 | assert(route->rnode == NULL); | |
605 | assert(route->lock == 0); | |
606 | assert(route->next == NULL); | |
607 | assert(route->prev == NULL); | |
608 | ||
609 | if (route->type == OSPF6_DEST_TYPE_LINKSTATE) | |
610 | ospf6_linkstate_prefix2str(&route->prefix, buf, sizeof(buf)); | |
611 | else | |
612 | prefix2str(&route->prefix, buf, sizeof(buf)); | |
613 | ||
614 | if (IS_OSPF6_DEBUG_ROUTE(MEMORY)) | |
6942698d | 615 | zlog_debug("%s %p: route add %p: %s paths %u nh %u", |
d62a17ae | 616 | ospf6_route_table_name(table), (void *)table, |
6942698d CS |
617 | (void *)route, buf, listcount(route->paths), |
618 | listcount(route->nh_list)); | |
d62a17ae | 619 | else if (IS_OSPF6_DEBUG_ROUTE(TABLE)) |
620 | zlog_debug("%s: route add: %s", ospf6_route_table_name(table), | |
621 | buf); | |
622 | ||
623 | monotime(&now); | |
624 | ||
625 | node = route_node_get(table->table, &route->prefix); | |
626 | route->rnode = node; | |
627 | ||
628 | /* find place to insert */ | |
629 | for (current = node->info; current; current = current->next) { | |
630 | if (!ospf6_route_is_same(current, route)) | |
631 | next = current; | |
632 | else if (current->type != route->type) | |
633 | prev = current; | |
634 | else if (ospf6_route_is_same_origin(current, route)) | |
635 | old = current; | |
636 | else if (ospf6_route_cmp(current, route) > 0) | |
637 | next = current; | |
638 | else | |
639 | prev = current; | |
640 | ||
641 | if (old || next) | |
642 | break; | |
643 | } | |
718e3744 | 644 | |
d62a17ae | 645 | if (old) { |
646 | /* if route does not actually change, return unchanged */ | |
647 | if (ospf6_route_is_identical(old, route)) { | |
648 | if (IS_OSPF6_DEBUG_ROUTE(MEMORY)) | |
649 | zlog_debug( | |
07b37f93 | 650 | "%s %p: route add %p: needless update of %p old cost %u", |
d62a17ae | 651 | ospf6_route_table_name(table), |
652 | (void *)table, (void *)route, | |
07b37f93 | 653 | (void *)old, old->path.cost); |
d62a17ae | 654 | else if (IS_OSPF6_DEBUG_ROUTE(TABLE)) |
655 | zlog_debug("%s: route add: needless update", | |
656 | ospf6_route_table_name(table)); | |
657 | ||
658 | ospf6_route_delete(route); | |
659 | SET_FLAG(old->flag, OSPF6_ROUTE_ADD); | |
660 | ospf6_route_table_assert(table); | |
661 | ||
d107621d CS |
662 | /* to free the lookup lock */ |
663 | route_unlock_node(node); | |
d62a17ae | 664 | return old; |
665 | } | |
666 | ||
667 | if (IS_OSPF6_DEBUG_ROUTE(MEMORY)) | |
996c9314 | 668 | zlog_debug( |
6942698d | 669 | "%s %p: route add %p cost %u paths %u nh %u: update of %p cost %u paths %u nh %u", |
996c9314 | 670 | ospf6_route_table_name(table), (void *)table, |
03f3c1c1 | 671 | (void *)route, route->path.cost, |
6942698d | 672 | listcount(route->paths), |
03f3c1c1 | 673 | listcount(route->nh_list), (void *)old, |
6942698d CS |
674 | old->path.cost, listcount(old->paths), |
675 | listcount(old->nh_list)); | |
d62a17ae | 676 | else if (IS_OSPF6_DEBUG_ROUTE(TABLE)) |
677 | zlog_debug("%s: route add: update", | |
678 | ospf6_route_table_name(table)); | |
679 | ||
680 | /* replace old one if exists */ | |
681 | if (node->info == old) { | |
682 | node->info = route; | |
683 | SET_FLAG(route->flag, OSPF6_ROUTE_BEST); | |
684 | } | |
685 | ||
686 | if (old->prev) | |
687 | old->prev->next = route; | |
688 | route->prev = old->prev; | |
689 | if (old->next) | |
690 | old->next->prev = route; | |
691 | route->next = old->next; | |
692 | ||
693 | route->installed = old->installed; | |
694 | route->changed = now; | |
695 | assert(route->table == NULL); | |
696 | route->table = table; | |
697 | ||
698 | ospf6_route_unlock(old); /* will be deleted later */ | |
699 | ospf6_route_lock(route); | |
700 | ||
701 | SET_FLAG(route->flag, OSPF6_ROUTE_CHANGE); | |
702 | ospf6_route_table_assert(table); | |
703 | ||
704 | if (table->hook_add) | |
705 | (*table->hook_add)(route); | |
706 | ||
707 | return route; | |
708 | } | |
709 | ||
710 | /* insert if previous or next node found */ | |
711 | if (prev || next) { | |
712 | if (IS_OSPF6_DEBUG_ROUTE(MEMORY)) | |
713 | zlog_debug( | |
07b37f93 | 714 | "%s %p: route add %p cost %u: another path: prev %p, next %p node ref %u", |
d62a17ae | 715 | ospf6_route_table_name(table), (void *)table, |
07b37f93 CS |
716 | (void *)route, route->path.cost, (void *)prev, |
717 | (void *)next, node->lock); | |
d62a17ae | 718 | else if (IS_OSPF6_DEBUG_ROUTE(TABLE)) |
07b37f93 CS |
719 | zlog_debug("%s: route add cost %u: another path found", |
720 | ospf6_route_table_name(table), | |
721 | route->path.cost); | |
d62a17ae | 722 | |
723 | if (prev == NULL) | |
724 | prev = next->prev; | |
725 | if (next == NULL) | |
726 | next = prev->next; | |
727 | ||
728 | if (prev) | |
729 | prev->next = route; | |
730 | route->prev = prev; | |
731 | if (next) | |
732 | next->prev = route; | |
733 | route->next = next; | |
734 | ||
735 | if (node->info == next) { | |
4f4060f6 | 736 | assert(next && next->rnode == node); |
d62a17ae | 737 | node->info = route; |
738 | UNSET_FLAG(next->flag, OSPF6_ROUTE_BEST); | |
739 | SET_FLAG(route->flag, OSPF6_ROUTE_BEST); | |
740 | if (IS_OSPF6_DEBUG_ROUTE(MEMORY)) | |
741 | zlog_info( | |
c601fa3f | 742 | "%s %p: route add %p cost %u: replacing previous best: %p cost %u", |
d62a17ae | 743 | ospf6_route_table_name(table), |
744 | (void *)table, (void *)route, | |
c601fa3f CS |
745 | route->path.cost, |
746 | (void *)next, next->path.cost); | |
d62a17ae | 747 | } |
748 | ||
749 | route->installed = now; | |
750 | route->changed = now; | |
751 | assert(route->table == NULL); | |
752 | route->table = table; | |
753 | ||
754 | ospf6_route_lock(route); | |
755 | table->count++; | |
756 | ospf6_route_table_assert(table); | |
757 | ||
758 | SET_FLAG(route->flag, OSPF6_ROUTE_ADD); | |
759 | if (table->hook_add) | |
760 | (*table->hook_add)(route); | |
761 | ||
762 | return route; | |
763 | } | |
764 | ||
765 | /* Else, this is the brand new route regarding to the prefix */ | |
766 | if (IS_OSPF6_DEBUG_ROUTE(MEMORY)) | |
c601fa3f | 767 | zlog_debug("%s %p: route add %p %s cost %u: brand new route", |
d62a17ae | 768 | ospf6_route_table_name(table), (void *)table, |
c601fa3f | 769 | (void *)route, buf, route->path.cost); |
d62a17ae | 770 | else if (IS_OSPF6_DEBUG_ROUTE(TABLE)) |
771 | zlog_debug("%s: route add: brand new route", | |
772 | ospf6_route_table_name(table)); | |
773 | ||
774 | assert(node->info == NULL); | |
775 | node->info = route; | |
776 | SET_FLAG(route->flag, OSPF6_ROUTE_BEST); | |
777 | ospf6_route_lock(route); | |
778 | route->installed = now; | |
779 | route->changed = now; | |
780 | assert(route->table == NULL); | |
781 | route->table = table; | |
782 | ||
783 | /* lookup real existing next route */ | |
784 | nextnode = node; | |
785 | route_lock_node(nextnode); | |
786 | do { | |
787 | nextnode = route_next(nextnode); | |
788 | } while (nextnode && nextnode->info == NULL); | |
789 | ||
790 | /* set next link */ | |
791 | if (nextnode == NULL) | |
792 | route->next = NULL; | |
793 | else { | |
794 | route_unlock_node(nextnode); | |
795 | ||
796 | next = nextnode->info; | |
797 | route->next = next; | |
798 | next->prev = route; | |
799 | } | |
800 | ||
801 | /* lookup real existing prev route */ | |
802 | prevnode = node; | |
803 | route_lock_node(prevnode); | |
804 | do { | |
805 | prevnode = route_prev(prevnode); | |
806 | } while (prevnode && prevnode->info == NULL); | |
807 | ||
808 | /* set prev link */ | |
809 | if (prevnode == NULL) | |
810 | route->prev = NULL; | |
811 | else { | |
812 | route_unlock_node(prevnode); | |
813 | ||
814 | prev = prevnode->info; | |
815 | while (prev->next && ospf6_route_is_same(prev, prev->next)) | |
816 | prev = prev->next; | |
817 | route->prev = prev; | |
818 | prev->next = route; | |
819 | } | |
820 | ||
821 | table->count++; | |
822 | ospf6_route_table_assert(table); | |
823 | ||
824 | SET_FLAG(route->flag, OSPF6_ROUTE_ADD); | |
825 | if (table->hook_add) | |
826 | (*table->hook_add)(route); | |
827 | ||
828 | return route; | |
508e53e2 | 829 | } |
718e3744 | 830 | |
d62a17ae | 831 | void ospf6_route_remove(struct ospf6_route *route, |
832 | struct ospf6_route_table *table) | |
508e53e2 | 833 | { |
d62a17ae | 834 | struct route_node *node; |
835 | struct ospf6_route *current; | |
836 | char buf[PREFIX2STR_BUFFER]; | |
837 | ||
838 | if (route->type == OSPF6_DEST_TYPE_LINKSTATE) | |
839 | ospf6_linkstate_prefix2str(&route->prefix, buf, sizeof(buf)); | |
840 | else | |
841 | prefix2str(&route->prefix, buf, sizeof(buf)); | |
842 | ||
843 | if (IS_OSPF6_DEBUG_ROUTE(MEMORY)) | |
07b37f93 | 844 | zlog_debug("%s %p: route remove %p: %s cost %u refcount %u", |
d62a17ae | 845 | ospf6_route_table_name(table), (void *)table, |
07b37f93 | 846 | (void *)route, buf, route->path.cost, route->lock); |
d62a17ae | 847 | else if (IS_OSPF6_DEBUG_ROUTE(TABLE)) |
848 | zlog_debug("%s: route remove: %s", | |
849 | ospf6_route_table_name(table), buf); | |
850 | ||
851 | node = route_node_lookup(table->table, &route->prefix); | |
852 | assert(node); | |
853 | ||
854 | /* find the route to remove, making sure that the route pointer | |
855 | is from the route table. */ | |
856 | current = node->info; | |
d107621d | 857 | while (current && current != route) |
d62a17ae | 858 | current = current->next; |
d107621d | 859 | |
d62a17ae | 860 | assert(current == route); |
861 | ||
862 | /* adjust doubly linked list */ | |
863 | if (route->prev) | |
864 | route->prev->next = route->next; | |
865 | if (route->next) | |
866 | route->next->prev = route->prev; | |
867 | ||
868 | if (node->info == route) { | |
869 | if (route->next && route->next->rnode == node) { | |
870 | node->info = route->next; | |
871 | SET_FLAG(route->next->flag, OSPF6_ROUTE_BEST); | |
d107621d CS |
872 | } else { |
873 | node->info = NULL; | |
874 | route->rnode = NULL; | |
875 | route_unlock_node(node); /* to free the original lock */ | |
876 | } | |
d62a17ae | 877 | } |
508e53e2 | 878 | |
d107621d | 879 | route_unlock_node(node); /* to free the lookup lock */ |
d62a17ae | 880 | table->count--; |
881 | ospf6_route_table_assert(table); | |
718e3744 | 882 | |
d62a17ae | 883 | SET_FLAG(route->flag, OSPF6_ROUTE_WAS_REMOVED); |
508e53e2 | 884 | |
dd2395e1 | 885 | /* Note hook_remove may call ospf6_route_remove */ |
d62a17ae | 886 | if (table->hook_remove) |
887 | (*table->hook_remove)(route); | |
cf1ce250 | 888 | |
d62a17ae | 889 | ospf6_route_unlock(route); |
890 | } | |
cf1ce250 | 891 | |
d62a17ae | 892 | struct ospf6_route *ospf6_route_head(struct ospf6_route_table *table) |
893 | { | |
894 | struct route_node *node; | |
895 | struct ospf6_route *route; | |
896 | ||
897 | node = route_top(table->table); | |
898 | if (node == NULL) | |
899 | return NULL; | |
900 | ||
901 | /* skip to the real existing entry */ | |
902 | while (node && node->info == NULL) | |
903 | node = route_next(node); | |
904 | if (node == NULL) | |
905 | return NULL; | |
906 | ||
907 | route_unlock_node(node); | |
908 | assert(node->info); | |
909 | ||
910 | route = (struct ospf6_route *)node->info; | |
911 | assert(route->prev == NULL); | |
912 | assert(route->table == table); | |
913 | ospf6_route_lock(route); | |
914 | ||
915 | if (IS_OSPF6_DEBUG_ROUTE(MEMORY)) | |
916 | zlog_info("%s %p: route head: %p<-[%p]->%p", | |
917 | ospf6_route_table_name(table), (void *)table, | |
918 | (void *)route->prev, (void *)route, | |
919 | (void *)route->next); | |
920 | ||
921 | return route; | |
718e3744 | 922 | } |
923 | ||
d62a17ae | 924 | struct ospf6_route *ospf6_route_next(struct ospf6_route *route) |
718e3744 | 925 | { |
d62a17ae | 926 | struct ospf6_route *next = route->next; |
718e3744 | 927 | |
d62a17ae | 928 | if (IS_OSPF6_DEBUG_ROUTE(MEMORY)) |
a2d0055a | 929 | zlog_info("%s %p: route next: %p<-[%p]->%p , route ref count %u", |
d62a17ae | 930 | ospf6_route_table_name(route->table), |
931 | (void *)route->table, (void *)route->prev, | |
a2d0055a CS |
932 | (void *)route, (void *)route->next, |
933 | route->lock); | |
cf1ce250 | 934 | |
d62a17ae | 935 | ospf6_route_unlock(route); |
936 | if (next) | |
937 | ospf6_route_lock(next); | |
718e3744 | 938 | |
d62a17ae | 939 | return next; |
508e53e2 | 940 | } |
718e3744 | 941 | |
d62a17ae | 942 | struct ospf6_route *ospf6_route_best_next(struct ospf6_route *route) |
508e53e2 | 943 | { |
d62a17ae | 944 | struct route_node *rnode; |
945 | struct ospf6_route *next; | |
946 | ||
947 | ospf6_route_unlock(route); | |
948 | ||
949 | rnode = route->rnode; | |
950 | route_lock_node(rnode); | |
951 | rnode = route_next(rnode); | |
952 | while (rnode && rnode->info == NULL) | |
953 | rnode = route_next(rnode); | |
954 | if (rnode == NULL) | |
955 | return NULL; | |
956 | route_unlock_node(rnode); | |
957 | ||
958 | assert(rnode->info); | |
959 | next = (struct ospf6_route *)rnode->info; | |
960 | ospf6_route_lock(next); | |
961 | return next; | |
508e53e2 | 962 | } |
718e3744 | 963 | |
d62a17ae | 964 | struct ospf6_route *ospf6_route_match_head(struct prefix *prefix, |
965 | struct ospf6_route_table *table) | |
508e53e2 | 966 | { |
d62a17ae | 967 | struct route_node *node; |
968 | struct ospf6_route *route; | |
969 | ||
970 | /* Walk down tree. */ | |
971 | node = table->table->top; | |
972 | while (node && node->p.prefixlen < prefix->prefixlen | |
973 | && prefix_match(&node->p, prefix)) | |
974 | node = node->link[prefix_bit(&prefix->u.prefix, | |
975 | node->p.prefixlen)]; | |
976 | ||
977 | if (node) | |
978 | route_lock_node(node); | |
979 | while (node && node->info == NULL) | |
980 | node = route_next(node); | |
981 | if (node == NULL) | |
982 | return NULL; | |
983 | route_unlock_node(node); | |
984 | ||
985 | if (!prefix_match(prefix, &node->p)) | |
986 | return NULL; | |
987 | ||
988 | route = node->info; | |
989 | ospf6_route_lock(route); | |
990 | return route; | |
508e53e2 | 991 | } |
718e3744 | 992 | |
d62a17ae | 993 | struct ospf6_route *ospf6_route_match_next(struct prefix *prefix, |
994 | struct ospf6_route *route) | |
508e53e2 | 995 | { |
d62a17ae | 996 | struct ospf6_route *next; |
508e53e2 | 997 | |
d62a17ae | 998 | next = ospf6_route_next(route); |
999 | if (next && !prefix_match(prefix, &next->prefix)) { | |
1000 | ospf6_route_unlock(next); | |
1001 | next = NULL; | |
1002 | } | |
508e53e2 | 1003 | |
d62a17ae | 1004 | return next; |
718e3744 | 1005 | } |
1006 | ||
d62a17ae | 1007 | void ospf6_route_remove_all(struct ospf6_route_table *table) |
718e3744 | 1008 | { |
d62a17ae | 1009 | struct ospf6_route *route; |
1010 | for (route = ospf6_route_head(table); route; | |
1011 | route = ospf6_route_next(route)) | |
1012 | ospf6_route_remove(route, table); | |
718e3744 | 1013 | } |
1014 | ||
d62a17ae | 1015 | struct ospf6_route_table *ospf6_route_table_create(int s, int t) |
718e3744 | 1016 | { |
d62a17ae | 1017 | struct ospf6_route_table *new; |
1018 | new = XCALLOC(MTYPE_OSPF6_ROUTE, sizeof(struct ospf6_route_table)); | |
1019 | new->table = route_table_init(); | |
1020 | new->scope_type = s; | |
1021 | new->table_type = t; | |
1022 | return new; | |
718e3744 | 1023 | } |
1024 | ||
d62a17ae | 1025 | void ospf6_route_table_delete(struct ospf6_route_table *table) |
718e3744 | 1026 | { |
d62a17ae | 1027 | ospf6_route_remove_all(table); |
d107621d | 1028 | bf_free(table->idspace); |
d62a17ae | 1029 | route_table_finish(table->table); |
1030 | XFREE(MTYPE_OSPF6_ROUTE, table); | |
718e3744 | 1031 | } |
1032 | ||
6b0655a2 | 1033 | |
508e53e2 | 1034 | /* VTY commands */ |
d62a17ae | 1035 | void ospf6_route_show(struct vty *vty, struct ospf6_route *route) |
718e3744 | 1036 | { |
d62a17ae | 1037 | int i; |
1038 | char destination[PREFIX2STR_BUFFER], nexthop[64]; | |
68bfcc05 | 1039 | char duration[64]; |
d62a17ae | 1040 | const char *ifname; |
1041 | struct timeval now, res; | |
1042 | struct listnode *node; | |
1043 | struct ospf6_nexthop *nh; | |
1044 | ||
1045 | monotime(&now); | |
1046 | timersub(&now, &route->changed, &res); | |
1047 | timerstring(&res, duration, sizeof(duration)); | |
1048 | ||
1049 | /* destination */ | |
1050 | if (route->type == OSPF6_DEST_TYPE_LINKSTATE) | |
1051 | ospf6_linkstate_prefix2str(&route->prefix, destination, | |
1052 | sizeof(destination)); | |
1053 | else if (route->type == OSPF6_DEST_TYPE_ROUTER) | |
1054 | inet_ntop(route->prefix.family, &route->prefix.u.prefix, | |
1055 | destination, sizeof(destination)); | |
1056 | else | |
1057 | prefix2str(&route->prefix, destination, sizeof(destination)); | |
1058 | ||
1059 | i = 0; | |
1060 | for (ALL_LIST_ELEMENTS_RO(route->nh_list, node, nh)) { | |
1061 | /* nexthop */ | |
1062 | inet_ntop(AF_INET6, &nh->address, nexthop, sizeof(nexthop)); | |
1063 | ifname = ifindex2ifname(nh->ifindex, VRF_DEFAULT); | |
1064 | ||
1065 | if (!i) { | |
1066 | vty_out(vty, "%c%1s %2s %-30s %-25s %6.*s %s\n", | |
1067 | (ospf6_route_is_best(route) ? '*' : ' '), | |
1068 | OSPF6_DEST_TYPE_SUBSTR(route->type), | |
1069 | OSPF6_PATH_TYPE_SUBSTR(route->path.type), | |
1070 | destination, nexthop, IFNAMSIZ, ifname, | |
1071 | duration); | |
1072 | i++; | |
1073 | } else | |
1074 | vty_out(vty, "%c%1s %2s %-30s %-25s %6.*s %s\n", ' ', | |
1075 | "", "", "", nexthop, IFNAMSIZ, ifname, ""); | |
c3c0ac83 | 1076 | } |
718e3744 | 1077 | } |
1078 | ||
d62a17ae | 1079 | void ospf6_route_show_detail(struct vty *vty, struct ospf6_route *route) |
718e3744 | 1080 | { |
d62a17ae | 1081 | const char *ifname; |
1082 | char destination[PREFIX2STR_BUFFER], nexthop[64]; | |
1083 | char area_id[16], id[16], adv_router[16], capa[16], options[16]; | |
1084 | struct timeval now, res; | |
68bfcc05 | 1085 | char duration[64]; |
d62a17ae | 1086 | struct listnode *node; |
1087 | struct ospf6_nexthop *nh; | |
1088 | ||
1089 | monotime(&now); | |
1090 | ||
1091 | /* destination */ | |
1092 | if (route->type == OSPF6_DEST_TYPE_LINKSTATE) | |
1093 | ospf6_linkstate_prefix2str(&route->prefix, destination, | |
1094 | sizeof(destination)); | |
1095 | else if (route->type == OSPF6_DEST_TYPE_ROUTER) | |
1096 | inet_ntop(route->prefix.family, &route->prefix.u.prefix, | |
1097 | destination, sizeof(destination)); | |
1098 | else | |
1099 | prefix2str(&route->prefix, destination, sizeof(destination)); | |
1100 | vty_out(vty, "Destination: %s\n", destination); | |
1101 | ||
1102 | /* destination type */ | |
1103 | vty_out(vty, "Destination type: %s\n", | |
1104 | OSPF6_DEST_TYPE_NAME(route->type)); | |
1105 | ||
1106 | /* Time */ | |
1107 | timersub(&now, &route->installed, &res); | |
1108 | timerstring(&res, duration, sizeof(duration)); | |
1109 | vty_out(vty, "Installed Time: %s ago\n", duration); | |
1110 | ||
1111 | timersub(&now, &route->changed, &res); | |
1112 | timerstring(&res, duration, sizeof(duration)); | |
1113 | vty_out(vty, " Changed Time: %s ago\n", duration); | |
1114 | ||
1115 | /* Debugging info */ | |
1116 | vty_out(vty, "Lock: %d Flags: %s%s%s%s\n", route->lock, | |
1117 | (CHECK_FLAG(route->flag, OSPF6_ROUTE_BEST) ? "B" : "-"), | |
1118 | (CHECK_FLAG(route->flag, OSPF6_ROUTE_ADD) ? "A" : "-"), | |
1119 | (CHECK_FLAG(route->flag, OSPF6_ROUTE_REMOVE) ? "R" : "-"), | |
1120 | (CHECK_FLAG(route->flag, OSPF6_ROUTE_CHANGE) ? "C" : "-")); | |
1121 | vty_out(vty, "Memory: prev: %p this: %p next: %p\n", | |
1122 | (void *)route->prev, (void *)route, (void *)route->next); | |
1123 | ||
1124 | /* Path section */ | |
1125 | ||
1126 | /* Area-ID */ | |
1127 | inet_ntop(AF_INET, &route->path.area_id, area_id, sizeof(area_id)); | |
1128 | vty_out(vty, "Associated Area: %s\n", area_id); | |
1129 | ||
1130 | /* Path type */ | |
1131 | vty_out(vty, "Path Type: %s\n", OSPF6_PATH_TYPE_NAME(route->path.type)); | |
1132 | ||
1133 | /* LS Origin */ | |
1134 | inet_ntop(AF_INET, &route->path.origin.id, id, sizeof(id)); | |
1135 | inet_ntop(AF_INET, &route->path.origin.adv_router, adv_router, | |
1136 | sizeof(adv_router)); | |
1137 | vty_out(vty, "LS Origin: %s Id: %s Adv: %s\n", | |
1138 | ospf6_lstype_name(route->path.origin.type), id, adv_router); | |
1139 | ||
1140 | /* Options */ | |
1141 | ospf6_options_printbuf(route->path.options, options, sizeof(options)); | |
1142 | vty_out(vty, "Options: %s\n", options); | |
1143 | ||
1144 | /* Router Bits */ | |
1145 | ospf6_capability_printbuf(route->path.router_bits, capa, sizeof(capa)); | |
1146 | vty_out(vty, "Router Bits: %s\n", capa); | |
1147 | ||
1148 | /* Prefix Options */ | |
1149 | vty_out(vty, "Prefix Options: xxx\n"); | |
1150 | ||
1151 | /* Metrics */ | |
1152 | vty_out(vty, "Metric Type: %d\n", route->path.metric_type); | |
1153 | vty_out(vty, "Metric: %d (%d)\n", route->path.cost, | |
1154 | route->path.u.cost_e2); | |
1155 | ||
064d4355 | 1156 | vty_out(vty, "Paths count: %u\n", route->paths->count); |
d107621d | 1157 | vty_out(vty, "Nexthop count: %u\n", route->nh_list->count); |
d62a17ae | 1158 | /* Nexthops */ |
1159 | vty_out(vty, "Nexthop:\n"); | |
1160 | for (ALL_LIST_ELEMENTS_RO(route->nh_list, node, nh)) { | |
1161 | /* nexthop */ | |
1162 | inet_ntop(AF_INET6, &nh->address, nexthop, sizeof(nexthop)); | |
1163 | ifname = ifindex2ifname(nh->ifindex, VRF_DEFAULT); | |
1164 | vty_out(vty, " %s %.*s\n", nexthop, IFNAMSIZ, ifname); | |
1165 | } | |
1166 | vty_out(vty, "\n"); | |
508e53e2 | 1167 | } |
718e3744 | 1168 | |
d62a17ae | 1169 | static void ospf6_route_show_table_summary(struct vty *vty, |
1170 | struct ospf6_route_table *table) | |
508e53e2 | 1171 | { |
d62a17ae | 1172 | struct ospf6_route *route, *prev = NULL; |
1173 | int i, pathtype[OSPF6_PATH_TYPE_MAX]; | |
1174 | unsigned int number = 0; | |
1175 | int nh_count = 0, nhinval = 0, ecmp = 0; | |
1176 | int alternative = 0, destination = 0; | |
1177 | ||
1178 | for (i = 0; i < OSPF6_PATH_TYPE_MAX; i++) | |
1179 | pathtype[i] = 0; | |
1180 | ||
1181 | for (route = ospf6_route_head(table); route; | |
1182 | route = ospf6_route_next(route)) { | |
1183 | if (prev == NULL || !ospf6_route_is_same(prev, route)) | |
1184 | destination++; | |
1185 | else | |
1186 | alternative++; | |
1187 | nh_count = ospf6_num_nexthops(route->nh_list); | |
1188 | if (!nh_count) | |
1189 | nhinval++; | |
1190 | else if (nh_count > 1) | |
1191 | ecmp++; | |
1192 | pathtype[route->path.type]++; | |
1193 | number++; | |
1194 | ||
1195 | prev = route; | |
1196 | } | |
1197 | ||
1198 | assert(number == table->count); | |
1199 | ||
1200 | vty_out(vty, "Number of OSPFv3 routes: %d\n", number); | |
1201 | vty_out(vty, "Number of Destination: %d\n", destination); | |
1202 | vty_out(vty, "Number of Alternative routes: %d\n", alternative); | |
1203 | vty_out(vty, "Number of Equal Cost Multi Path: %d\n", ecmp); | |
1204 | for (i = OSPF6_PATH_TYPE_INTRA; i <= OSPF6_PATH_TYPE_EXTERNAL2; i++) { | |
1205 | vty_out(vty, "Number of %s routes: %d\n", | |
1206 | OSPF6_PATH_TYPE_NAME(i), pathtype[i]); | |
1207 | } | |
4846ef64 | 1208 | } |
1209 | ||
d62a17ae | 1210 | static void ospf6_route_show_table_prefix(struct vty *vty, |
1211 | struct prefix *prefix, | |
1212 | struct ospf6_route_table *table) | |
4846ef64 | 1213 | { |
d62a17ae | 1214 | struct ospf6_route *route; |
1215 | ||
1216 | route = ospf6_route_lookup(prefix, table); | |
1217 | if (route == NULL) | |
1218 | return; | |
1219 | ||
1220 | ospf6_route_lock(route); | |
1221 | while (route && ospf6_route_is_prefix(prefix, route)) { | |
1222 | /* Specifying a prefix will always display details */ | |
1223 | ospf6_route_show_detail(vty, route); | |
1224 | route = ospf6_route_next(route); | |
1225 | } | |
1226 | if (route) | |
1227 | ospf6_route_unlock(route); | |
4846ef64 | 1228 | } |
1229 | ||
d62a17ae | 1230 | static void ospf6_route_show_table_address(struct vty *vty, |
1231 | struct prefix *prefix, | |
1232 | struct ospf6_route_table *table) | |
4846ef64 | 1233 | { |
d62a17ae | 1234 | struct ospf6_route *route; |
1235 | ||
1236 | route = ospf6_route_lookup_bestmatch(prefix, table); | |
1237 | if (route == NULL) | |
1238 | return; | |
1239 | ||
1240 | prefix = &route->prefix; | |
1241 | ospf6_route_lock(route); | |
1242 | while (route && ospf6_route_is_prefix(prefix, route)) { | |
1243 | /* Specifying a prefix will always display details */ | |
1244 | ospf6_route_show_detail(vty, route); | |
1245 | route = ospf6_route_next(route); | |
1246 | } | |
1247 | if (route) | |
1248 | ospf6_route_unlock(route); | |
4846ef64 | 1249 | } |
1250 | ||
d62a17ae | 1251 | static void ospf6_route_show_table_match(struct vty *vty, int detail, |
1252 | struct prefix *prefix, | |
1253 | struct ospf6_route_table *table) | |
4846ef64 | 1254 | { |
d62a17ae | 1255 | struct ospf6_route *route; |
1256 | assert(prefix->family); | |
1257 | ||
1258 | route = ospf6_route_match_head(prefix, table); | |
1259 | while (route) { | |
1260 | if (detail) | |
1261 | ospf6_route_show_detail(vty, route); | |
1262 | else | |
1263 | ospf6_route_show(vty, route); | |
1264 | route = ospf6_route_match_next(prefix, route); | |
1265 | } | |
4846ef64 | 1266 | } |
1267 | ||
d62a17ae | 1268 | static void ospf6_route_show_table_type(struct vty *vty, int detail, |
d7c0a89a | 1269 | uint8_t type, |
d62a17ae | 1270 | struct ospf6_route_table *table) |
4846ef64 | 1271 | { |
d62a17ae | 1272 | struct ospf6_route *route; |
1273 | ||
1274 | route = ospf6_route_head(table); | |
1275 | while (route) { | |
1276 | if (route->path.type == type) { | |
1277 | if (detail) | |
1278 | ospf6_route_show_detail(vty, route); | |
1279 | else | |
1280 | ospf6_route_show(vty, route); | |
1281 | } | |
1282 | route = ospf6_route_next(route); | |
1283 | } | |
4846ef64 | 1284 | } |
1285 | ||
d62a17ae | 1286 | static void ospf6_route_show_table(struct vty *vty, int detail, |
1287 | struct ospf6_route_table *table) | |
4846ef64 | 1288 | { |
d62a17ae | 1289 | struct ospf6_route *route; |
1290 | ||
1291 | route = ospf6_route_head(table); | |
1292 | while (route) { | |
1293 | if (detail) | |
1294 | ospf6_route_show_detail(vty, route); | |
1295 | else | |
1296 | ospf6_route_show(vty, route); | |
1297 | route = ospf6_route_next(route); | |
1298 | } | |
718e3744 | 1299 | } |
1300 | ||
d62a17ae | 1301 | int ospf6_route_table_show(struct vty *vty, int argc_start, int argc, |
1302 | struct cmd_token **argv, | |
1303 | struct ospf6_route_table *table) | |
718e3744 | 1304 | { |
d62a17ae | 1305 | int summary = 0; |
1306 | int match = 0; | |
1307 | int detail = 0; | |
1308 | int slash = 0; | |
1309 | int isprefix = 0; | |
1310 | int i, ret; | |
1311 | struct prefix prefix; | |
d7c0a89a | 1312 | uint8_t type = 0; |
d62a17ae | 1313 | |
1314 | memset(&prefix, 0, sizeof(struct prefix)); | |
1315 | ||
1316 | for (i = argc_start; i < argc; i++) { | |
1317 | if (strmatch(argv[i]->text, "summary")) { | |
1318 | summary++; | |
1319 | continue; | |
1320 | } | |
1321 | ||
1322 | if (strmatch(argv[i]->text, "intra-area")) { | |
1323 | type = OSPF6_PATH_TYPE_INTRA; | |
1324 | continue; | |
1325 | } | |
1326 | ||
1327 | if (strmatch(argv[i]->text, "inter-area")) { | |
1328 | type = OSPF6_PATH_TYPE_INTER; | |
1329 | continue; | |
1330 | } | |
1331 | ||
1332 | if (strmatch(argv[i]->text, "external-1")) { | |
1333 | type = OSPF6_PATH_TYPE_EXTERNAL1; | |
1334 | continue; | |
1335 | } | |
1336 | ||
1337 | if (strmatch(argv[i]->text, "external-2")) { | |
1338 | type = OSPF6_PATH_TYPE_EXTERNAL2; | |
1339 | continue; | |
1340 | } | |
1341 | ||
1342 | if (strmatch(argv[i]->text, "detail")) { | |
1343 | detail++; | |
1344 | continue; | |
1345 | } | |
1346 | ||
1347 | if (strmatch(argv[i]->text, "match")) { | |
1348 | match++; | |
1349 | continue; | |
1350 | } | |
1351 | ||
1352 | ret = str2prefix(argv[i]->arg, &prefix); | |
1353 | if (ret == 1 && prefix.family == AF_INET6) { | |
1354 | isprefix++; | |
1355 | if (strchr(argv[i]->arg, '/')) | |
1356 | slash++; | |
1357 | continue; | |
1358 | } | |
1359 | ||
1360 | vty_out(vty, "Malformed argument: %s\n", argv[i]->arg); | |
1361 | return CMD_SUCCESS; | |
1362 | } | |
1363 | ||
1364 | /* Give summary of this route table */ | |
1365 | if (summary) { | |
1366 | ospf6_route_show_table_summary(vty, table); | |
1367 | return CMD_SUCCESS; | |
1368 | } | |
1369 | ||
1370 | /* Give exact prefix-match route */ | |
1371 | if (isprefix && !match) { | |
1372 | /* If exact address, give best matching route */ | |
1373 | if (!slash) | |
1374 | ospf6_route_show_table_address(vty, &prefix, table); | |
1375 | else | |
1376 | ospf6_route_show_table_prefix(vty, &prefix, table); | |
1377 | ||
1378 | return CMD_SUCCESS; | |
1379 | } | |
1380 | ||
1381 | if (match) | |
1382 | ospf6_route_show_table_match(vty, detail, &prefix, table); | |
1383 | else if (type) | |
1384 | ospf6_route_show_table_type(vty, detail, type, table); | |
1385 | else | |
1386 | ospf6_route_show_table(vty, detail, table); | |
1387 | ||
1388 | return CMD_SUCCESS; | |
4846ef64 | 1389 | } |
508e53e2 | 1390 | |
d62a17ae | 1391 | static void ospf6_linkstate_show_header(struct vty *vty) |
4846ef64 | 1392 | { |
d62a17ae | 1393 | vty_out(vty, "%-7s %-15s %-15s %-8s %-14s %s\n", "Type", "Router-ID", |
1394 | "Net-ID", "Rtr-Bits", "Options", "Cost"); | |
4846ef64 | 1395 | } |
1396 | ||
d62a17ae | 1397 | static void ospf6_linkstate_show(struct vty *vty, struct ospf6_route *route) |
4846ef64 | 1398 | { |
d7c0a89a | 1399 | uint32_t router, id; |
d62a17ae | 1400 | char routername[16], idname[16], rbits[16], options[16]; |
1401 | ||
1402 | router = ospf6_linkstate_prefix_adv_router(&route->prefix); | |
1403 | inet_ntop(AF_INET, &router, routername, sizeof(routername)); | |
1404 | id = ospf6_linkstate_prefix_id(&route->prefix); | |
1405 | inet_ntop(AF_INET, &id, idname, sizeof(idname)); | |
1406 | ||
1407 | ospf6_capability_printbuf(route->path.router_bits, rbits, | |
1408 | sizeof(rbits)); | |
1409 | ospf6_options_printbuf(route->path.options, options, sizeof(options)); | |
1410 | ||
1411 | if (ntohl(id)) | |
1412 | vty_out(vty, "%-7s %-15s %-15s %-8s %-14s %lu\n", "Network", | |
1413 | routername, idname, rbits, options, | |
1414 | (unsigned long)route->path.cost); | |
1415 | else | |
1416 | vty_out(vty, "%-7s %-15s %-15s %-8s %-14s %lu\n", "Router", | |
1417 | routername, idname, rbits, options, | |
1418 | (unsigned long)route->path.cost); | |
4846ef64 | 1419 | } |
1420 | ||
1421 | ||
d62a17ae | 1422 | static void ospf6_linkstate_show_table_exact(struct vty *vty, |
1423 | struct prefix *prefix, | |
1424 | struct ospf6_route_table *table) | |
4846ef64 | 1425 | { |
d62a17ae | 1426 | struct ospf6_route *route; |
1427 | ||
1428 | route = ospf6_route_lookup(prefix, table); | |
1429 | if (route == NULL) | |
1430 | return; | |
1431 | ||
1432 | ospf6_route_lock(route); | |
1433 | while (route && ospf6_route_is_prefix(prefix, route)) { | |
1434 | /* Specifying a prefix will always display details */ | |
1435 | ospf6_route_show_detail(vty, route); | |
1436 | route = ospf6_route_next(route); | |
1437 | } | |
1438 | if (route) | |
1439 | ospf6_route_unlock(route); | |
4846ef64 | 1440 | } |
1441 | ||
d62a17ae | 1442 | static void ospf6_linkstate_show_table(struct vty *vty, int detail, |
1443 | struct ospf6_route_table *table) | |
4846ef64 | 1444 | { |
d62a17ae | 1445 | struct ospf6_route *route; |
1446 | ||
1447 | if (!detail) | |
1448 | ospf6_linkstate_show_header(vty); | |
1449 | ||
1450 | route = ospf6_route_head(table); | |
1451 | while (route) { | |
1452 | if (detail) | |
1453 | ospf6_route_show_detail(vty, route); | |
1454 | else | |
1455 | ospf6_linkstate_show(vty, route); | |
1456 | route = ospf6_route_next(route); | |
1457 | } | |
718e3744 | 1458 | } |
1459 | ||
d62a17ae | 1460 | int ospf6_linkstate_table_show(struct vty *vty, int idx_ipv4, int argc, |
1461 | struct cmd_token **argv, | |
1462 | struct ospf6_route_table *table) | |
718e3744 | 1463 | { |
d62a17ae | 1464 | int detail = 0; |
1465 | int is_id = 0; | |
1466 | int is_router = 0; | |
1467 | int i, ret; | |
1468 | struct prefix router, id, prefix; | |
1469 | ||
1470 | memset(&router, 0, sizeof(struct prefix)); | |
1471 | memset(&id, 0, sizeof(struct prefix)); | |
1472 | memset(&prefix, 0, sizeof(struct prefix)); | |
1473 | ||
1474 | for (i = idx_ipv4; i < argc; i++) { | |
1475 | if (strmatch(argv[i]->text, "detail")) { | |
1476 | detail++; | |
1477 | continue; | |
1478 | } | |
1479 | ||
1480 | if (!is_router) { | |
1481 | ret = str2prefix(argv[i]->arg, &router); | |
1482 | if (ret == 1 && router.family == AF_INET) { | |
1483 | is_router++; | |
1484 | continue; | |
1485 | } | |
1486 | vty_out(vty, "Malformed argument: %s\n", argv[i]->arg); | |
1487 | return CMD_SUCCESS; | |
1488 | } | |
1489 | ||
1490 | if (!is_id) { | |
1491 | ret = str2prefix(argv[i]->arg, &id); | |
1492 | if (ret == 1 && id.family == AF_INET) { | |
1493 | is_id++; | |
1494 | continue; | |
1495 | } | |
1496 | vty_out(vty, "Malformed argument: %s\n", argv[i]->arg); | |
1497 | return CMD_SUCCESS; | |
1498 | } | |
1499 | ||
1500 | vty_out(vty, "Malformed argument: %s\n", argv[i]->arg); | |
1501 | return CMD_SUCCESS; | |
1502 | } | |
1503 | ||
1504 | if (is_router) | |
1505 | ospf6_linkstate_prefix(router.u.prefix4.s_addr, | |
1506 | id.u.prefix4.s_addr, &prefix); | |
1507 | ||
1508 | if (prefix.family) | |
1509 | ospf6_linkstate_show_table_exact(vty, &prefix, table); | |
1510 | else | |
1511 | ospf6_linkstate_show_table(vty, detail, table); | |
1512 | ||
1513 | return CMD_SUCCESS; | |
508e53e2 | 1514 | } |
718e3744 | 1515 | |
4846ef64 | 1516 | |
d62a17ae | 1517 | void ospf6_brouter_show_header(struct vty *vty) |
6452df09 | 1518 | { |
d62a17ae | 1519 | vty_out(vty, "%-15s %-8s %-14s %-10s %-15s\n", "Router-ID", "Rtr-Bits", |
1520 | "Options", "Path-Type", "Area"); | |
6452df09 | 1521 | } |
1522 | ||
d62a17ae | 1523 | void ospf6_brouter_show(struct vty *vty, struct ospf6_route *route) |
6452df09 | 1524 | { |
d7c0a89a | 1525 | uint32_t adv_router; |
d62a17ae | 1526 | char adv[16], rbits[16], options[16], area[16]; |
1527 | ||
1528 | adv_router = ospf6_linkstate_prefix_adv_router(&route->prefix); | |
1529 | inet_ntop(AF_INET, &adv_router, adv, sizeof(adv)); | |
1530 | ospf6_capability_printbuf(route->path.router_bits, rbits, | |
1531 | sizeof(rbits)); | |
1532 | ospf6_options_printbuf(route->path.options, options, sizeof(options)); | |
1533 | inet_ntop(AF_INET, &route->path.area_id, area, sizeof(area)); | |
1534 | ||
1535 | /* vty_out (vty, "%-15s %-8s %-14s %-10s %-15s\n", | |
1536 | "Router-ID", "Rtr-Bits", "Options", "Path-Type", "Area"); */ | |
1537 | vty_out(vty, "%-15s %-8s %-14s %-10s %-15s\n", adv, rbits, options, | |
1538 | OSPF6_PATH_TYPE_NAME(route->path.type), area); | |
6452df09 | 1539 | } |
1540 | ||
508e53e2 | 1541 | DEFUN (debug_ospf6_route, |
1542 | debug_ospf6_route_cmd, | |
6147e2c6 | 1543 | "debug ospf6 route <table|intra-area|inter-area|memory>", |
508e53e2 | 1544 | DEBUG_STR |
1545 | OSPF6_STR | |
16cedbb0 | 1546 | "Debug routes\n" |
508e53e2 | 1547 | "Debug route table calculation\n" |
508e53e2 | 1548 | "Debug intra-area route calculation\n" |
1549 | "Debug inter-area route calculation\n" | |
8f228de7 | 1550 | "Debug route memory use\n" |
508e53e2 | 1551 | ) |
1552 | { | |
d62a17ae | 1553 | int idx_type = 3; |
1554 | unsigned char level = 0; | |
1555 | ||
8034beff | 1556 | if (!strcmp(argv[idx_type]->text, "table")) |
d62a17ae | 1557 | level = OSPF6_DEBUG_ROUTE_TABLE; |
8034beff | 1558 | else if (!strcmp(argv[idx_type]->text, "intra-area")) |
d62a17ae | 1559 | level = OSPF6_DEBUG_ROUTE_INTRA; |
8034beff | 1560 | else if (!strcmp(argv[idx_type]->text, "inter-area")) |
d62a17ae | 1561 | level = OSPF6_DEBUG_ROUTE_INTER; |
8034beff | 1562 | else if (!strcmp(argv[idx_type]->text, "memory")) |
d62a17ae | 1563 | level = OSPF6_DEBUG_ROUTE_MEMORY; |
1564 | OSPF6_DEBUG_ROUTE_ON(level); | |
1565 | return CMD_SUCCESS; | |
508e53e2 | 1566 | } |
1567 | ||
1568 | DEFUN (no_debug_ospf6_route, | |
1569 | no_debug_ospf6_route_cmd, | |
6147e2c6 | 1570 | "no debug ospf6 route <table|intra-area|inter-area|memory>", |
508e53e2 | 1571 | NO_STR |
1572 | DEBUG_STR | |
1573 | OSPF6_STR | |
16cedbb0 | 1574 | "Debug routes\n" |
508e53e2 | 1575 | "Debug route table calculation\n" |
8f228de7 | 1576 | "Debug intra-area route calculation\n" |
16cedbb0 | 1577 | "Debug inter-area route calculation\n" |
8f228de7 | 1578 | "Debug route memory use\n") |
508e53e2 | 1579 | { |
d62a17ae | 1580 | int idx_type = 4; |
1581 | unsigned char level = 0; | |
1582 | ||
8034beff | 1583 | if (!strcmp(argv[idx_type]->text, "table")) |
d62a17ae | 1584 | level = OSPF6_DEBUG_ROUTE_TABLE; |
8034beff | 1585 | else if (!strcmp(argv[idx_type]->text, "intra-area")) |
d62a17ae | 1586 | level = OSPF6_DEBUG_ROUTE_INTRA; |
8034beff | 1587 | else if (!strcmp(argv[idx_type]->text, "inter-area")) |
d62a17ae | 1588 | level = OSPF6_DEBUG_ROUTE_INTER; |
8034beff | 1589 | else if (!strcmp(argv[idx_type]->text, "memory")) |
d62a17ae | 1590 | level = OSPF6_DEBUG_ROUTE_MEMORY; |
1591 | OSPF6_DEBUG_ROUTE_OFF(level); | |
1592 | return CMD_SUCCESS; | |
718e3744 | 1593 | } |
1594 | ||
d62a17ae | 1595 | int config_write_ospf6_debug_route(struct vty *vty) |
508e53e2 | 1596 | { |
d62a17ae | 1597 | if (IS_OSPF6_DEBUG_ROUTE(TABLE)) |
1598 | vty_out(vty, "debug ospf6 route table\n"); | |
1599 | if (IS_OSPF6_DEBUG_ROUTE(INTRA)) | |
1600 | vty_out(vty, "debug ospf6 route intra-area\n"); | |
1601 | if (IS_OSPF6_DEBUG_ROUTE(INTER)) | |
1602 | vty_out(vty, "debug ospf6 route inter-area\n"); | |
6f7af48c CS |
1603 | if (IS_OSPF6_DEBUG_ROUTE(MEMORY)) |
1604 | vty_out(vty, "debug ospf6 route memory\n"); | |
1605 | ||
d62a17ae | 1606 | return 0; |
508e53e2 | 1607 | } |
1608 | ||
d62a17ae | 1609 | void install_element_ospf6_debug_route(void) |
508e53e2 | 1610 | { |
d62a17ae | 1611 | install_element(ENABLE_NODE, &debug_ospf6_route_cmd); |
1612 | install_element(ENABLE_NODE, &no_debug_ospf6_route_cmd); | |
1613 | install_element(CONFIG_NODE, &debug_ospf6_route_cmd); | |
1614 | install_element(CONFIG_NODE, &no_debug_ospf6_route_cmd); | |
508e53e2 | 1615 | } |