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