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