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