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