2 * Copyright (C) 2003 Yasuhiro Ohara
4 * This file is part of GNU Zebra.
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
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.
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
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"
39 #include "ospf6_zebra.h"
41 DEFINE_MTYPE_STATIC(OSPF6D
, OSPF6_ROUTE
, "OSPF6 route");
42 DEFINE_MTYPE_STATIC(OSPF6D
, OSPF6_NEXTHOP
, "OSPF6 nexthop");
43 DEFINE_MTYPE_STATIC(OSPF6D
, OSPF6_PATH
, "OSPF6 Path");
45 unsigned char conf_debug_ospf6_route
= 0;
47 static char *ospf6_route_table_name(struct ospf6_route_table
*table
)
50 switch (table
->scope_type
) {
51 case OSPF6_SCOPE_TYPE_GLOBAL
: {
52 switch (table
->table_type
) {
53 case OSPF6_TABLE_TYPE_ROUTES
:
54 snprintf(name
, sizeof(name
), "global route table");
56 case OSPF6_TABLE_TYPE_BORDER_ROUTERS
:
57 snprintf(name
, sizeof(name
), "global brouter table");
59 case OSPF6_TABLE_TYPE_EXTERNAL_ROUTES
:
60 snprintf(name
, sizeof(name
), "global external table");
63 snprintf(name
, sizeof(name
), "global unknown table");
68 case OSPF6_SCOPE_TYPE_AREA
: {
69 struct ospf6_area
*oa
= (struct ospf6_area
*)table
->scope
;
70 switch (table
->table_type
) {
71 case OSPF6_TABLE_TYPE_SPF_RESULTS
:
72 snprintf(name
, sizeof(name
), "area %s spf table",
75 case OSPF6_TABLE_TYPE_ROUTES
:
76 snprintf(name
, sizeof(name
), "area %s route table",
79 case OSPF6_TABLE_TYPE_PREFIX_RANGES
:
80 snprintf(name
, sizeof(name
), "area %s range table",
83 case OSPF6_TABLE_TYPE_SUMMARY_PREFIXES
:
84 snprintf(name
, sizeof(name
),
85 "area %s summary prefix table", oa
->name
);
87 case OSPF6_TABLE_TYPE_SUMMARY_ROUTERS
:
88 snprintf(name
, sizeof(name
),
89 "area %s summary router table", oa
->name
);
92 snprintf(name
, sizeof(name
), "area %s unknown table",
98 case OSPF6_SCOPE_TYPE_INTERFACE
: {
99 struct ospf6_interface
*oi
=
100 (struct ospf6_interface
*)table
->scope
;
101 switch (table
->table_type
) {
102 case OSPF6_TABLE_TYPE_CONNECTED_ROUTES
:
103 snprintf(name
, sizeof(name
),
104 "interface %s connected table",
105 oi
->interface
->name
);
108 snprintf(name
, sizeof(name
),
109 "interface %s unknown table",
110 oi
->interface
->name
);
116 switch (table
->table_type
) {
117 case OSPF6_TABLE_TYPE_SPF_RESULTS
:
118 snprintf(name
, sizeof(name
), "temporary spf table");
121 snprintf(name
, sizeof(name
), "temporary unknown table");
129 void ospf6_linkstate_prefix(uint32_t adv_router
, uint32_t id
,
130 struct prefix
*prefix
)
132 memset(prefix
, 0, sizeof(struct prefix
));
133 prefix
->family
= AF_INET6
;
134 prefix
->prefixlen
= 64;
135 memcpy(&prefix
->u
.prefix6
.s6_addr
[0], &adv_router
, 4);
136 memcpy(&prefix
->u
.prefix6
.s6_addr
[4], &id
, 4);
139 void ospf6_linkstate_prefix2str(struct prefix
*prefix
, char *buf
, int size
)
141 uint32_t adv_router
, id
;
142 char adv_router_str
[16], id_str
[16];
143 memcpy(&adv_router
, &prefix
->u
.prefix6
.s6_addr
[0], 4);
144 memcpy(&id
, &prefix
->u
.prefix6
.s6_addr
[4], 4);
145 inet_ntop(AF_INET
, &adv_router
, adv_router_str
, sizeof(adv_router_str
));
146 inet_ntop(AF_INET
, &id
, id_str
, sizeof(id_str
));
148 snprintf(buf
, size
, "%s Net-ID: %s", adv_router_str
, id_str
);
150 snprintf(buf
, size
, "%s", adv_router_str
);
153 /* Global strings for logging */
154 const char *const ospf6_dest_type_str
[OSPF6_DEST_TYPE_MAX
] = {
155 "Unknown", "Router", "Network", "Discard", "Linkstate", "AddressRange",
158 const char *const ospf6_dest_type_substr
[OSPF6_DEST_TYPE_MAX
] = {
159 "?", "R", "N", "D", "L", "A",
162 const char *const ospf6_path_type_str
[OSPF6_PATH_TYPE_MAX
] = {
163 "Unknown", "Intra-Area", "Inter-Area", "External-1", "External-2",
166 const char *const ospf6_path_type_substr
[OSPF6_PATH_TYPE_MAX
] = {
167 "??", "IA", "IE", "E1", "E2",
170 const char *ospf6_path_type_json
[OSPF6_PATH_TYPE_MAX
] = {
171 "UnknownRoute", "IntraArea", "InterArea", "External1", "External2",
175 struct ospf6_nexthop
*ospf6_nexthop_create(void)
177 struct ospf6_nexthop
*nh
;
179 nh
= XCALLOC(MTYPE_OSPF6_NEXTHOP
, sizeof(struct ospf6_nexthop
));
183 void ospf6_nexthop_delete(struct ospf6_nexthop
*nh
)
185 XFREE(MTYPE_OSPF6_NEXTHOP
, nh
);
188 void ospf6_clear_nexthops(struct list
*nh_list
)
190 struct listnode
*node
;
191 struct ospf6_nexthop
*nh
;
194 for (ALL_LIST_ELEMENTS_RO(nh_list
, node
, nh
))
195 ospf6_nexthop_clear(nh
);
199 static struct ospf6_nexthop
*
200 ospf6_route_find_nexthop(struct list
*nh_list
, struct ospf6_nexthop
*nh_match
)
202 struct listnode
*node
;
203 struct ospf6_nexthop
*nh
;
205 if (nh_list
&& nh_match
) {
206 for (ALL_LIST_ELEMENTS_RO(nh_list
, node
, nh
)) {
207 if (ospf6_nexthop_is_same(nh
, nh_match
))
215 void ospf6_copy_nexthops(struct list
*dst
, struct list
*src
)
217 struct ospf6_nexthop
*nh_new
, *nh
;
218 struct listnode
*node
;
221 for (ALL_LIST_ELEMENTS_RO(src
, node
, nh
)) {
222 if (ospf6_nexthop_is_set(nh
)) {
223 nh_new
= ospf6_nexthop_create();
224 ospf6_nexthop_copy(nh_new
, nh
);
225 listnode_add_sort(dst
, nh_new
);
231 void ospf6_merge_nexthops(struct list
*dst
, struct list
*src
)
233 struct listnode
*node
;
234 struct ospf6_nexthop
*nh
, *nh_new
;
237 for (ALL_LIST_ELEMENTS_RO(src
, node
, nh
)) {
238 if (!ospf6_route_find_nexthop(dst
, nh
)) {
239 nh_new
= ospf6_nexthop_create();
240 ospf6_nexthop_copy(nh_new
, nh
);
241 listnode_add_sort(dst
, nh_new
);
247 int ospf6_route_cmp_nexthops(struct ospf6_route
*a
, struct ospf6_route
*b
)
249 struct listnode
*anode
, *bnode
;
250 struct ospf6_nexthop
*anh
, *bnh
;
251 bool identical
= false;
254 if (listcount(a
->nh_list
) == listcount(b
->nh_list
)) {
255 for (ALL_LIST_ELEMENTS_RO(a
->nh_list
, anode
, anh
)) {
257 for (ALL_LIST_ELEMENTS_RO(b
->nh_list
, bnode
,
259 if (ospf6_nexthop_is_same(anh
, bnh
))
262 /* Currnet List A element not found List B
263 * Non-Identical lists return */
264 if (identical
== false)
271 /* One of the routes doesn't exist ? */
275 int ospf6_num_nexthops(struct list
*nh_list
)
277 return (listcount(nh_list
));
280 void ospf6_add_nexthop(struct list
*nh_list
, int ifindex
, struct in6_addr
*addr
)
282 struct ospf6_nexthop
*nh
;
283 struct ospf6_nexthop nh_match
;
286 nh_match
.ifindex
= ifindex
;
288 memcpy(&nh_match
.address
, addr
,
289 sizeof(struct in6_addr
));
291 memset(&nh_match
.address
, 0, sizeof(struct in6_addr
));
293 if (!ospf6_route_find_nexthop(nh_list
, &nh_match
)) {
294 nh
= ospf6_nexthop_create();
295 ospf6_nexthop_copy(nh
, &nh_match
);
296 listnode_add(nh_list
, nh
);
301 void ospf6_route_zebra_copy_nexthops(struct ospf6_route
*route
,
302 struct zapi_nexthop nexthops
[],
303 int entries
, vrf_id_t vrf_id
)
305 struct ospf6_nexthop
*nh
;
306 struct listnode
*node
;
312 for (ALL_LIST_ELEMENTS_RO(route
->nh_list
, node
, nh
)) {
313 if (IS_OSPF6_DEBUG_ZEBRA(SEND
)) {
315 inet_ntop(AF_INET6
, &nh
->address
, buf
,
317 ifname
= ifindex2ifname(nh
->ifindex
, vrf_id
);
318 zlog_debug(" nexthop: %s%%%.*s(%d)", buf
,
319 IFNAMSIZ
, ifname
, nh
->ifindex
);
324 nexthops
[i
].vrf_id
= vrf_id
;
325 nexthops
[i
].ifindex
= nh
->ifindex
;
326 if (!IN6_IS_ADDR_UNSPECIFIED(&nh
->address
)) {
327 nexthops
[i
].gate
.ipv6
= nh
->address
;
328 nexthops
[i
].type
= NEXTHOP_TYPE_IPV6_IFINDEX
;
330 nexthops
[i
].type
= NEXTHOP_TYPE_IFINDEX
;
336 int ospf6_route_get_first_nh_index(struct ospf6_route
*route
)
338 struct ospf6_nexthop
*nh
;
341 nh
= listnode_head(route
->nh_list
);
349 int ospf6_nexthop_cmp(struct ospf6_nexthop
*a
, struct ospf6_nexthop
*b
)
351 if (a
->ifindex
< b
->ifindex
)
353 else if (a
->ifindex
> b
->ifindex
)
356 return memcmp(&a
->address
, &b
->address
,
357 sizeof(struct in6_addr
));
362 static int ospf6_path_cmp(struct ospf6_path
*a
, struct ospf6_path
*b
)
364 if (a
->origin
.adv_router
< b
->origin
.adv_router
)
366 else if (a
->origin
.adv_router
> b
->origin
.adv_router
)
372 void ospf6_path_free(struct ospf6_path
*op
)
375 list_delete(&op
->nh_list
);
376 XFREE(MTYPE_OSPF6_PATH
, op
);
379 struct ospf6_path
*ospf6_path_dup(struct ospf6_path
*path
)
381 struct ospf6_path
*new;
383 new = XCALLOC(MTYPE_OSPF6_PATH
, sizeof(struct ospf6_path
));
384 memcpy(new, path
, sizeof(struct ospf6_path
));
385 new->nh_list
= list_new();
386 new->nh_list
->cmp
= (int (*)(void *, void *))ospf6_nexthop_cmp
;
387 new->nh_list
->del
= (void (*)(void *))ospf6_nexthop_delete
;
392 void ospf6_copy_paths(struct list
*dst
, struct list
*src
)
394 struct ospf6_path
*path_new
, *path
;
395 struct listnode
*node
;
398 for (ALL_LIST_ELEMENTS_RO(src
, node
, path
)) {
399 path_new
= ospf6_path_dup(path
);
400 ospf6_copy_nexthops(path_new
->nh_list
, path
->nh_list
);
401 listnode_add_sort(dst
, path_new
);
406 struct ospf6_route
*ospf6_route_create(void)
408 struct ospf6_route
*route
;
410 route
= XCALLOC(MTYPE_OSPF6_ROUTE
, sizeof(struct ospf6_route
));
411 route
->nh_list
= list_new();
412 route
->nh_list
->cmp
= (int (*)(void *, void *))ospf6_nexthop_cmp
;
413 route
->nh_list
->del
= (void (*)(void *))ospf6_nexthop_delete
;
414 route
->paths
= list_new();
415 route
->paths
->cmp
= (int (*)(void *, void *))ospf6_path_cmp
;
416 route
->paths
->del
= (void (*)(void *))ospf6_path_free
;
420 void ospf6_route_delete(struct ospf6_route
*route
)
424 list_delete(&route
->nh_list
);
426 list_delete(&route
->paths
);
427 XFREE(MTYPE_OSPF6_ROUTE
, route
);
431 struct ospf6_route
*ospf6_route_copy(struct ospf6_route
*route
)
433 struct ospf6_route
*new;
435 new = ospf6_route_create();
436 new->type
= route
->type
;
437 memcpy(&new->prefix
, &route
->prefix
, sizeof(struct prefix
));
438 new->installed
= route
->installed
;
439 new->changed
= route
->changed
;
440 new->flag
= route
->flag
;
441 new->route_option
= route
->route_option
;
442 new->linkstate_id
= route
->linkstate_id
;
443 new->path
= route
->path
;
444 ospf6_copy_nexthops(new->nh_list
, route
->nh_list
);
445 ospf6_copy_paths(new->paths
, route
->paths
);
454 void ospf6_route_lock(struct ospf6_route
*route
)
459 void ospf6_route_unlock(struct ospf6_route
*route
)
461 assert(route
->lock
> 0);
463 if (route
->lock
== 0) {
464 /* Can't detach from the table until here
465 because ospf6_route_next () will use
466 the 'route->table' pointer for logging */
468 ospf6_route_delete(route
);
472 /* Route compare function. If ra is more preferred, it returns
473 less than 0. If rb is more preferred returns greater than 0.
474 Otherwise (neither one is preferred), returns 0 */
475 int ospf6_route_cmp(struct ospf6_route
*ra
, struct ospf6_route
*rb
)
477 assert(ospf6_route_is_same(ra
, rb
));
478 assert(OSPF6_PATH_TYPE_NONE
< ra
->path
.type
479 && ra
->path
.type
< OSPF6_PATH_TYPE_MAX
);
480 assert(OSPF6_PATH_TYPE_NONE
< rb
->path
.type
481 && rb
->path
.type
< OSPF6_PATH_TYPE_MAX
);
483 if (ra
->type
!= rb
->type
)
484 return (ra
->type
- rb
->type
);
486 if (ra
->path
.type
!= rb
->path
.type
)
487 return (ra
->path
.type
- rb
->path
.type
);
489 if (ra
->path
.type
== OSPF6_PATH_TYPE_EXTERNAL2
) {
490 if (ra
->path
.u
.cost_e2
!= rb
->path
.u
.cost_e2
)
491 return (ra
->path
.u
.cost_e2
- rb
->path
.u
.cost_e2
);
493 return (ra
->path
.cost
- rb
->path
.cost
);
495 if (ra
->path
.cost
!= rb
->path
.cost
)
496 return (ra
->path
.cost
- rb
->path
.cost
);
499 if (ra
->path
.area_id
!= rb
->path
.area_id
)
500 return (ntohl(ra
->path
.area_id
) - ntohl(rb
->path
.area_id
));
505 struct ospf6_route
*ospf6_route_lookup(struct prefix
*prefix
,
506 struct ospf6_route_table
*table
)
508 struct route_node
*node
;
509 struct ospf6_route
*route
;
511 node
= route_node_lookup(table
->table
, prefix
);
515 route
= (struct ospf6_route
*)node
->info
;
516 route_unlock_node(node
); /* to free the lookup lock */
521 ospf6_route_lookup_identical(struct ospf6_route
*route
,
522 struct ospf6_route_table
*table
)
524 struct ospf6_route
*target
;
526 for (target
= ospf6_route_lookup(&route
->prefix
, table
); target
;
527 target
= target
->next
) {
528 if (target
->type
== route
->type
529 && (memcmp(&target
->prefix
, &route
->prefix
,
530 sizeof(struct prefix
))
532 && target
->path
.type
== route
->path
.type
533 && target
->path
.cost
== route
->path
.cost
534 && target
->path
.u
.cost_e2
== route
->path
.u
.cost_e2
535 && ospf6_route_cmp_nexthops(target
, route
) == 0)
542 ospf6_route_lookup_bestmatch(struct prefix
*prefix
,
543 struct ospf6_route_table
*table
)
545 struct route_node
*node
;
546 struct ospf6_route
*route
;
548 node
= route_node_match(table
->table
, prefix
);
551 route_unlock_node(node
);
553 route
= (struct ospf6_route
*)node
->info
;
558 static void route_table_assert(struct ospf6_route_table
*table
)
560 struct ospf6_route
*prev
, *r
, *next
;
561 unsigned int link_error
= 0, num
= 0;
563 r
= ospf6_route_head(table
);
569 next
= ospf6_route_next(r
);
578 for (r
= ospf6_route_head(table
); r
; r
= ospf6_route_next(r
))
581 if (link_error
== 0 && num
== table
->count
)
584 flog_err(EC_LIB_DEVELOPMENT
, "PANIC !!");
585 flog_err(EC_LIB_DEVELOPMENT
,
586 "Something has gone wrong with ospf6_route_table[%p]", table
);
587 zlog_debug("table count = %d, real number = %d", table
->count
, num
);
588 zlog_debug("DUMP START");
589 for (r
= ospf6_route_head(table
); r
; r
= ospf6_route_next(r
))
590 zlog_info("%p<-[%p]->%p : %pFX", r
->prev
, r
, r
->next
,
592 zlog_debug("DUMP END");
594 assert(link_error
== 0 && num
== table
->count
);
596 #define ospf6_route_table_assert(t) (route_table_assert (t))
598 #define ospf6_route_table_assert(t) ((void) 0)
601 struct ospf6_route
*ospf6_route_add(struct ospf6_route
*route
,
602 struct ospf6_route_table
*table
)
604 struct route_node
*node
, *nextnode
, *prevnode
;
605 struct ospf6_route
*current
= NULL
;
606 struct ospf6_route
*prev
= NULL
, *old
= NULL
, *next
= NULL
;
607 char buf
[PREFIX2STR_BUFFER
];
610 assert(route
->rnode
== NULL
);
611 assert(route
->lock
== 0);
612 assert(route
->next
== NULL
);
613 assert(route
->prev
== NULL
);
615 if (route
->type
== OSPF6_DEST_TYPE_LINKSTATE
)
616 ospf6_linkstate_prefix2str(&route
->prefix
, buf
, sizeof(buf
));
618 prefix2str(&route
->prefix
, buf
, sizeof(buf
));
620 if (IS_OSPF6_DEBUG_ROUTE(MEMORY
))
621 zlog_debug("%s %p: route add %p: %s paths %u nh %u",
622 ospf6_route_table_name(table
), (void *)table
,
623 (void *)route
, buf
, listcount(route
->paths
),
624 listcount(route
->nh_list
));
625 else if (IS_OSPF6_DEBUG_ROUTE(TABLE
))
626 zlog_debug("%s: route add: %s", ospf6_route_table_name(table
),
631 node
= route_node_get(table
->table
, &route
->prefix
);
634 /* find place to insert */
635 for (current
= node
->info
; current
; current
= current
->next
) {
636 if (!ospf6_route_is_same(current
, route
))
638 else if (current
->type
!= route
->type
)
640 else if (ospf6_route_is_same_origin(current
, route
))
642 else if (ospf6_route_cmp(current
, route
) > 0)
652 /* if route does not actually change, return unchanged */
653 if (ospf6_route_is_identical(old
, route
)) {
654 if (IS_OSPF6_DEBUG_ROUTE(MEMORY
))
656 "%s %p: route add %p: needless update of %p old cost %u",
657 ospf6_route_table_name(table
),
658 (void *)table
, (void *)route
,
659 (void *)old
, old
->path
.cost
);
660 else if (IS_OSPF6_DEBUG_ROUTE(TABLE
))
661 zlog_debug("%s: route add: needless update",
662 ospf6_route_table_name(table
));
664 ospf6_route_delete(route
);
665 SET_FLAG(old
->flag
, OSPF6_ROUTE_ADD
);
666 ospf6_route_table_assert(table
);
668 /* to free the lookup lock */
669 route_unlock_node(node
);
673 if (IS_OSPF6_DEBUG_ROUTE(MEMORY
))
675 "%s %p: route add %p cost %u paths %u nh %u: update of %p cost %u paths %u nh %u",
676 ospf6_route_table_name(table
), (void *)table
,
677 (void *)route
, route
->path
.cost
,
678 listcount(route
->paths
),
679 listcount(route
->nh_list
), (void *)old
,
680 old
->path
.cost
, listcount(old
->paths
),
681 listcount(old
->nh_list
));
682 else if (IS_OSPF6_DEBUG_ROUTE(TABLE
))
683 zlog_debug("%s: route add: update",
684 ospf6_route_table_name(table
));
686 /* replace old one if exists */
687 if (node
->info
== old
) {
689 SET_FLAG(route
->flag
, OSPF6_ROUTE_BEST
);
693 old
->prev
->next
= route
;
694 route
->prev
= old
->prev
;
696 old
->next
->prev
= route
;
697 route
->next
= old
->next
;
699 route
->installed
= old
->installed
;
700 route
->changed
= now
;
701 assert(route
->table
== NULL
);
702 route
->table
= table
;
704 ospf6_route_unlock(old
); /* will be deleted later */
705 ospf6_route_lock(route
);
707 SET_FLAG(route
->flag
, OSPF6_ROUTE_CHANGE
);
708 ospf6_route_table_assert(table
);
711 (*table
->hook_add
)(route
);
716 /* insert if previous or next node found */
718 if (IS_OSPF6_DEBUG_ROUTE(MEMORY
))
720 "%s %p: route add %p cost %u: another path: prev %p, next %p node ref %u",
721 ospf6_route_table_name(table
), (void *)table
,
722 (void *)route
, route
->path
.cost
, (void *)prev
,
723 (void *)next
, route_node_get_lock_count(node
));
724 else if (IS_OSPF6_DEBUG_ROUTE(TABLE
))
725 zlog_debug("%s: route add cost %u: another path found",
726 ospf6_route_table_name(table
),
741 if (node
->info
== next
) {
742 assert(next
&& next
->rnode
== node
);
744 UNSET_FLAG(next
->flag
, OSPF6_ROUTE_BEST
);
745 SET_FLAG(route
->flag
, OSPF6_ROUTE_BEST
);
746 if (IS_OSPF6_DEBUG_ROUTE(MEMORY
))
748 "%s %p: route add %p cost %u: replacing previous best: %p cost %u",
749 ospf6_route_table_name(table
),
750 (void *)table
, (void *)route
,
752 (void *)next
, next
->path
.cost
);
755 route
->installed
= now
;
756 route
->changed
= now
;
757 assert(route
->table
== NULL
);
758 route
->table
= table
;
760 ospf6_route_lock(route
);
762 ospf6_route_table_assert(table
);
764 SET_FLAG(route
->flag
, OSPF6_ROUTE_ADD
);
766 (*table
->hook_add
)(route
);
771 /* Else, this is the brand new route regarding to the prefix */
772 if (IS_OSPF6_DEBUG_ROUTE(MEMORY
))
773 zlog_debug("%s %p: route add %p %s cost %u: brand new route",
774 ospf6_route_table_name(table
), (void *)table
,
775 (void *)route
, buf
, route
->path
.cost
);
776 else if (IS_OSPF6_DEBUG_ROUTE(TABLE
))
777 zlog_debug("%s: route add: brand new route",
778 ospf6_route_table_name(table
));
780 assert(node
->info
== NULL
);
782 SET_FLAG(route
->flag
, OSPF6_ROUTE_BEST
);
783 ospf6_route_lock(route
);
784 route
->installed
= now
;
785 route
->changed
= now
;
786 assert(route
->table
== NULL
);
787 route
->table
= table
;
789 /* lookup real existing next route */
791 route_lock_node(nextnode
);
793 nextnode
= route_next(nextnode
);
794 } while (nextnode
&& nextnode
->info
== NULL
);
797 if (nextnode
== NULL
)
800 route_unlock_node(nextnode
);
802 next
= nextnode
->info
;
807 /* lookup real existing prev route */
809 route_lock_node(prevnode
);
811 prevnode
= route_prev(prevnode
);
812 } while (prevnode
&& prevnode
->info
== NULL
);
815 if (prevnode
== NULL
)
818 route_unlock_node(prevnode
);
820 prev
= prevnode
->info
;
821 while (prev
->next
&& ospf6_route_is_same(prev
, prev
->next
))
828 ospf6_route_table_assert(table
);
830 SET_FLAG(route
->flag
, OSPF6_ROUTE_ADD
);
832 (*table
->hook_add
)(route
);
837 void ospf6_route_remove(struct ospf6_route
*route
,
838 struct ospf6_route_table
*table
)
840 struct route_node
*node
;
841 struct ospf6_route
*current
;
842 char buf
[PREFIX2STR_BUFFER
];
844 if (route
->type
== OSPF6_DEST_TYPE_LINKSTATE
)
845 ospf6_linkstate_prefix2str(&route
->prefix
, buf
, sizeof(buf
));
847 prefix2str(&route
->prefix
, buf
, sizeof(buf
));
849 if (IS_OSPF6_DEBUG_ROUTE(MEMORY
))
850 zlog_debug("%s %p: route remove %p: %s cost %u refcount %u",
851 ospf6_route_table_name(table
), (void *)table
,
852 (void *)route
, buf
, route
->path
.cost
, route
->lock
);
853 else if (IS_OSPF6_DEBUG_ROUTE(TABLE
))
854 zlog_debug("%s: route remove: %s",
855 ospf6_route_table_name(table
), buf
);
857 node
= route_node_lookup(table
->table
, &route
->prefix
);
860 /* find the route to remove, making sure that the route pointer
861 is from the route table. */
862 current
= node
->info
;
863 while (current
&& current
!= route
)
864 current
= current
->next
;
866 assert(current
== route
);
868 /* adjust doubly linked list */
870 route
->prev
->next
= route
->next
;
872 route
->next
->prev
= route
->prev
;
874 if (node
->info
== route
) {
875 if (route
->next
&& route
->next
->rnode
== node
) {
876 node
->info
= route
->next
;
877 SET_FLAG(route
->next
->flag
, OSPF6_ROUTE_BEST
);
881 route_unlock_node(node
); /* to free the original lock */
885 route_unlock_node(node
); /* to free the lookup lock */
887 ospf6_route_table_assert(table
);
889 SET_FLAG(route
->flag
, OSPF6_ROUTE_WAS_REMOVED
);
891 /* Note hook_remove may call ospf6_route_remove */
892 if (table
->hook_remove
)
893 (*table
->hook_remove
)(route
);
895 ospf6_route_unlock(route
);
898 struct ospf6_route
*ospf6_route_head(struct ospf6_route_table
*table
)
900 struct route_node
*node
;
901 struct ospf6_route
*route
;
903 node
= route_top(table
->table
);
907 /* skip to the real existing entry */
908 while (node
&& node
->info
== NULL
)
909 node
= route_next(node
);
913 route_unlock_node(node
);
916 route
= (struct ospf6_route
*)node
->info
;
917 assert(route
->prev
== NULL
);
918 assert(route
->table
== table
);
919 ospf6_route_lock(route
);
921 if (IS_OSPF6_DEBUG_ROUTE(MEMORY
))
922 zlog_info("%s %p: route head: %p<-[%p]->%p",
923 ospf6_route_table_name(table
), (void *)table
,
924 (void *)route
->prev
, (void *)route
,
925 (void *)route
->next
);
930 struct ospf6_route
*ospf6_route_next(struct ospf6_route
*route
)
932 struct ospf6_route
*next
= route
->next
;
934 if (IS_OSPF6_DEBUG_ROUTE(MEMORY
))
935 zlog_info("%s %p: route next: %p<-[%p]->%p , route ref count %u",
936 ospf6_route_table_name(route
->table
),
937 (void *)route
->table
, (void *)route
->prev
,
938 (void *)route
, (void *)route
->next
,
941 ospf6_route_unlock(route
);
943 ospf6_route_lock(next
);
948 struct ospf6_route
*ospf6_route_best_next(struct ospf6_route
*route
)
950 struct route_node
*rnode
;
951 struct ospf6_route
*next
;
953 ospf6_route_unlock(route
);
955 rnode
= route
->rnode
;
956 route_lock_node(rnode
);
957 rnode
= route_next(rnode
);
958 while (rnode
&& rnode
->info
== NULL
)
959 rnode
= route_next(rnode
);
962 route_unlock_node(rnode
);
965 next
= (struct ospf6_route
*)rnode
->info
;
966 ospf6_route_lock(next
);
970 struct ospf6_route
*ospf6_route_match_head(struct prefix
*prefix
,
971 struct ospf6_route_table
*table
)
973 struct route_node
*node
;
974 struct ospf6_route
*route
;
976 /* Walk down tree. */
977 node
= table
->table
->top
;
978 while (node
&& node
->p
.prefixlen
< prefix
->prefixlen
979 && prefix_match(&node
->p
, prefix
))
980 node
= node
->link
[prefix_bit(&prefix
->u
.prefix
,
984 route_lock_node(node
);
985 while (node
&& node
->info
== NULL
)
986 node
= route_next(node
);
989 route_unlock_node(node
);
991 if (!prefix_match(prefix
, &node
->p
))
995 ospf6_route_lock(route
);
999 struct ospf6_route
*ospf6_route_match_next(struct prefix
*prefix
,
1000 struct ospf6_route
*route
)
1002 struct ospf6_route
*next
;
1004 next
= ospf6_route_next(route
);
1005 if (next
&& !prefix_match(prefix
, &next
->prefix
)) {
1006 ospf6_route_unlock(next
);
1013 void ospf6_route_remove_all(struct ospf6_route_table
*table
)
1015 struct ospf6_route
*route
;
1016 for (route
= ospf6_route_head(table
); route
;
1017 route
= ospf6_route_next(route
))
1018 ospf6_route_remove(route
, table
);
1021 struct ospf6_route_table
*ospf6_route_table_create(int s
, int t
)
1023 struct ospf6_route_table
*new;
1024 new = XCALLOC(MTYPE_OSPF6_ROUTE
, sizeof(struct ospf6_route_table
));
1025 new->table
= route_table_init();
1026 new->scope_type
= s
;
1027 new->table_type
= t
;
1031 void ospf6_route_table_delete(struct ospf6_route_table
*table
)
1033 ospf6_route_remove_all(table
);
1034 bf_free(table
->idspace
);
1035 route_table_finish(table
->table
);
1036 XFREE(MTYPE_OSPF6_ROUTE
, table
);
1041 void ospf6_route_show(struct vty
*vty
, struct ospf6_route
*route
,
1042 json_object
*json_array_routes
, bool use_json
)
1045 char destination
[PREFIX2STR_BUFFER
], nexthop
[64];
1047 struct timeval now
, res
;
1048 struct listnode
*node
;
1049 struct ospf6_nexthop
*nh
;
1050 json_object
*json_route
= NULL
;
1051 json_object
*json_array_next_hops
= NULL
;
1052 json_object
*json_next_hop
;
1054 if (om6
->ospf6
== NULL
) {
1055 vty_out(vty
, "OSPFv3 is not running\n");
1060 timersub(&now
, &route
->changed
, &res
);
1061 timerstring(&res
, duration
, sizeof(duration
));
1064 if (route
->type
== OSPF6_DEST_TYPE_LINKSTATE
)
1065 ospf6_linkstate_prefix2str(&route
->prefix
, destination
,
1066 sizeof(destination
));
1067 else if (route
->type
== OSPF6_DEST_TYPE_ROUTER
)
1068 inet_ntop(route
->prefix
.family
, &route
->prefix
.u
.prefix
,
1069 destination
, sizeof(destination
));
1071 prefix2str(&route
->prefix
, destination
, sizeof(destination
));
1074 json_route
= json_object_new_object();
1075 json_object_string_add(json_route
, "destination", destination
);
1076 json_object_boolean_add(json_route
, "isBestRoute",
1077 ospf6_route_is_best(route
));
1078 json_object_string_add(json_route
, "destinationType",
1079 OSPF6_DEST_TYPE_SUBSTR(route
->type
));
1080 json_object_string_add(
1081 json_route
, "pathType",
1082 OSPF6_PATH_TYPE_SUBSTR(route
->path
.type
));
1083 json_object_string_add(json_route
, "duration", duration
);
1088 json_array_next_hops
= json_object_new_array();
1091 for (ALL_LIST_ELEMENTS_RO(route
->nh_list
, node
, nh
)) {
1092 struct interface
*ifp
;
1094 inet_ntop(AF_INET6
, &nh
->address
, nexthop
, sizeof(nexthop
));
1095 ifp
= if_lookup_by_index_all_vrf(nh
->ifindex
);
1097 json_next_hop
= json_object_new_object();
1098 json_object_string_add(json_next_hop
, "nextHop",
1100 json_object_string_add(json_next_hop
, "interfaceName",
1102 json_object_array_add(json_array_next_hops
,
1106 vty_out(vty
, "%c%1s %2s %-30s %-25s %6.*s %s\n",
1107 (ospf6_route_is_best(route
) ? '*'
1109 OSPF6_DEST_TYPE_SUBSTR(route
->type
),
1110 OSPF6_PATH_TYPE_SUBSTR(
1112 destination
, nexthop
, IFNAMSIZ
,
1113 ifp
->name
, duration
);
1116 vty_out(vty
, "%c%1s %2s %-30s %-25s %6.*s %s\n",
1117 ' ', "", "", "", nexthop
, IFNAMSIZ
,
1122 json_object_object_add(json_route
, "nextHops",
1123 json_array_next_hops
);
1124 json_object_array_add(json_array_routes
, json_route
);
1128 void ospf6_route_show_detail(struct vty
*vty
, struct ospf6_route
*route
,
1129 json_object
*json_array_routes
, bool use_json
)
1131 char destination
[PREFIX2STR_BUFFER
], nexthop
[64];
1132 char area_id
[16], id
[16], adv_router
[16], capa
[16], options
[16];
1133 struct timeval now
, res
;
1135 struct listnode
*node
;
1136 struct ospf6_nexthop
*nh
;
1138 json_object
*json_route
= NULL
;
1139 json_object
*json_array_next_hops
= NULL
;
1140 json_object
*json_next_hop
;
1142 if (om6
->ospf6
== NULL
) {
1143 vty_out(vty
, "OSPFv3 is not running\n");
1150 if (route
->type
== OSPF6_DEST_TYPE_LINKSTATE
)
1151 ospf6_linkstate_prefix2str(&route
->prefix
, destination
,
1152 sizeof(destination
));
1153 else if (route
->type
== OSPF6_DEST_TYPE_ROUTER
)
1154 inet_ntop(route
->prefix
.family
, &route
->prefix
.u
.prefix
,
1155 destination
, sizeof(destination
));
1157 prefix2str(&route
->prefix
, destination
, sizeof(destination
));
1160 json_route
= json_object_new_object();
1161 json_object_string_add(json_route
, "destination", destination
);
1162 json_object_string_add(json_route
, "destinationType",
1163 OSPF6_DEST_TYPE_NAME(route
->type
));
1165 vty_out(vty
, "Destination: %s\n", destination
);
1166 vty_out(vty
, "Destination type: %s\n",
1167 OSPF6_DEST_TYPE_NAME(route
->type
));
1171 timersub(&now
, &route
->installed
, &res
);
1172 timerstring(&res
, duration
, sizeof(duration
));
1174 json_object_string_add(json_route
, "installedTimeSince",
1177 vty_out(vty
, "Installed Time: %s ago\n", duration
);
1179 timersub(&now
, &route
->changed
, &res
);
1180 timerstring(&res
, duration
, sizeof(duration
));
1182 json_object_string_add(json_route
, "changedTimeSince",
1185 vty_out(vty
, "Changed Time: %s ago\n", duration
);
1187 /* Debugging info */
1189 json_object_int_add(json_route
, "numberOfLock", route
->lock
);
1191 flag
, sizeof(flag
), "%s%s%s%s",
1192 (CHECK_FLAG(route
->flag
, OSPF6_ROUTE_BEST
) ? "B" : "-"),
1193 (CHECK_FLAG(route
->flag
, OSPF6_ROUTE_ADD
) ? "A" : "-"),
1194 (CHECK_FLAG(route
->flag
, OSPF6_ROUTE_REMOVE
) ? "R"
1196 (CHECK_FLAG(route
->flag
, OSPF6_ROUTE_CHANGE
) ? "C"
1198 json_object_string_add(json_route
, "flags", flag
);
1200 vty_out(vty
, "Lock: %d Flags: %s%s%s%s\n", route
->lock
,
1201 (CHECK_FLAG(route
->flag
, OSPF6_ROUTE_BEST
) ? "B" : "-"),
1202 (CHECK_FLAG(route
->flag
, OSPF6_ROUTE_ADD
) ? "A" : "-"),
1203 (CHECK_FLAG(route
->flag
, OSPF6_ROUTE_REMOVE
) ? "R"
1205 (CHECK_FLAG(route
->flag
, OSPF6_ROUTE_CHANGE
) ? "C"
1207 vty_out(vty
, "Memory: prev: %p this: %p next: %p\n",
1208 (void *)route
->prev
, (void *)route
,
1209 (void *)route
->next
);
1215 inet_ntop(AF_INET
, &route
->path
.area_id
, area_id
, sizeof(area_id
));
1217 json_object_string_add(json_route
, "associatedArea", area_id
);
1219 vty_out(vty
, "Associated Area: %s\n", area_id
);
1223 json_object_string_add(json_route
, "pathType",
1224 OSPF6_PATH_TYPE_NAME(route
->path
.type
));
1226 vty_out(vty
, "Path Type: %s\n",
1227 OSPF6_PATH_TYPE_NAME(route
->path
.type
));
1230 inet_ntop(AF_INET
, &route
->path
.origin
.id
, id
, sizeof(id
));
1231 inet_ntop(AF_INET
, &route
->path
.origin
.adv_router
, adv_router
,
1232 sizeof(adv_router
));
1234 json_object_string_add(
1235 json_route
, "lsOriginRoutePathType",
1236 ospf6_lstype_name(route
->path
.origin
.type
));
1237 json_object_string_add(json_route
, "lsId", id
);
1238 json_object_string_add(json_route
, "lsAdvertisingRouter",
1241 vty_out(vty
, "LS Origin: %s Id: %s Adv: %s\n",
1242 ospf6_lstype_name(route
->path
.origin
.type
), id
,
1247 ospf6_options_printbuf(route
->path
.options
, options
, sizeof(options
));
1249 json_object_string_add(json_route
, "options", options
);
1251 vty_out(vty
, "Options: %s\n", options
);
1254 ospf6_capability_printbuf(route
->path
.router_bits
, capa
, sizeof(capa
));
1256 json_object_string_add(json_route
, "routerBits", capa
);
1258 vty_out(vty
, "Router Bits: %s\n", capa
);
1260 /* Prefix Options */
1262 json_object_string_add(json_route
, "prefixOptions", "xxx");
1264 vty_out(vty
, "Prefix Options: xxx\n");
1268 json_object_int_add(json_route
, "metricType",
1269 route
->path
.metric_type
);
1270 json_object_int_add(json_route
, "metricCost", route
->path
.cost
);
1271 json_object_int_add(json_route
, "metricCostE2",
1272 route
->path
.u
.cost_e2
);
1274 json_object_int_add(json_route
, "pathsCount",
1275 route
->paths
->count
);
1276 json_object_int_add(json_route
, "nextHopCount",
1277 route
->nh_list
->count
);
1279 vty_out(vty
, "Metric Type: %d\n", route
->path
.metric_type
);
1280 vty_out(vty
, "Metric: %d (%d)\n", route
->path
.cost
,
1281 route
->path
.u
.cost_e2
);
1283 vty_out(vty
, "Paths count: %u\n", route
->paths
->count
);
1284 vty_out(vty
, "Nexthop count: %u\n", route
->nh_list
->count
);
1289 json_array_next_hops
= json_object_new_array();
1291 vty_out(vty
, "Nexthop:\n");
1293 for (ALL_LIST_ELEMENTS_RO(route
->nh_list
, node
, nh
)) {
1294 struct interface
*ifp
;
1295 ifp
= if_lookup_by_index_all_vrf(nh
->ifindex
);
1298 inet_ntop(AF_INET6
, &nh
->address
, nexthop
,
1300 json_next_hop
= json_object_new_object();
1301 json_object_string_add(json_next_hop
, "nextHop",
1303 json_object_string_add(json_next_hop
, "interfaceName",
1305 json_object_array_add(json_array_next_hops
,
1308 vty_out(vty
, " %pI6 %.*s\n", &nh
->address
, IFNAMSIZ
,
1312 json_object_object_add(json_route
, "nextHops",
1313 json_array_next_hops
);
1314 json_object_array_add(json_array_routes
, json_route
);
1319 static void ospf6_route_show_table_summary(struct vty
*vty
,
1320 struct ospf6_route_table
*table
,
1321 json_object
*json
, bool use_json
)
1323 struct ospf6_route
*route
, *prev
= NULL
;
1324 int i
, pathtype
[OSPF6_PATH_TYPE_MAX
];
1325 unsigned int number
= 0;
1326 int nh_count
= 0, nhinval
= 0, ecmp
= 0;
1327 int alternative
= 0, destination
= 0;
1330 for (i
= 0; i
< OSPF6_PATH_TYPE_MAX
; i
++)
1333 for (route
= ospf6_route_head(table
); route
;
1334 route
= ospf6_route_next(route
)) {
1335 if (prev
== NULL
|| !ospf6_route_is_same(prev
, route
))
1339 nh_count
= ospf6_num_nexthops(route
->nh_list
);
1342 else if (nh_count
> 1)
1344 pathtype
[route
->path
.type
]++;
1350 assert(number
== table
->count
);
1352 json_object_int_add(json
, "numberOfOspfv3Routes", number
);
1353 json_object_int_add(json
, "numberOfDestination", destination
);
1354 json_object_int_add(json
, "numberOfAlternativeRoutes",
1356 json_object_int_add(json
, "numberOfEcmp", ecmp
);
1358 vty_out(vty
, "Number of OSPFv3 routes: %d\n", number
);
1359 vty_out(vty
, "Number of Destination: %d\n", destination
);
1360 vty_out(vty
, "Number of Alternative routes: %d\n", alternative
);
1361 vty_out(vty
, "Number of Equal Cost Multi Path: %d\n", ecmp
);
1363 for (i
= OSPF6_PATH_TYPE_INTRA
; i
<= OSPF6_PATH_TYPE_EXTERNAL2
; i
++) {
1365 snprintf(path_str
, sizeof(path_str
), "numberOf%sRoutes",
1366 OSPF6_PATH_TYPE_JSON(i
));
1367 json_object_int_add(json
, path_str
, pathtype
[i
]);
1369 vty_out(vty
, "Number of %s routes: %d\n",
1370 OSPF6_PATH_TYPE_NAME(i
), pathtype
[i
]);
1374 static void ospf6_route_show_table_prefix(struct vty
*vty
,
1375 struct prefix
*prefix
,
1376 struct ospf6_route_table
*table
,
1377 json_object
*json
, bool use_json
)
1379 struct ospf6_route
*route
;
1380 json_object
*json_array_routes
= NULL
;
1382 route
= ospf6_route_lookup(prefix
, table
);
1387 json_array_routes
= json_object_new_array();
1388 ospf6_route_lock(route
);
1389 while (route
&& ospf6_route_is_prefix(prefix
, route
)) {
1390 /* Specifying a prefix will always display details */
1391 ospf6_route_show_detail(vty
, route
, json_array_routes
,
1393 route
= ospf6_route_next(route
);
1397 json_object_object_add(json
, "routes", json_array_routes
);
1399 ospf6_route_unlock(route
);
1402 static void ospf6_route_show_table_address(struct vty
*vty
,
1403 struct prefix
*prefix
,
1404 struct ospf6_route_table
*table
,
1405 json_object
*json
, bool use_json
)
1407 struct ospf6_route
*route
;
1408 json_object
*json_array_routes
= NULL
;
1410 route
= ospf6_route_lookup_bestmatch(prefix
, table
);
1415 json_array_routes
= json_object_new_array();
1416 prefix
= &route
->prefix
;
1417 ospf6_route_lock(route
);
1418 while (route
&& ospf6_route_is_prefix(prefix
, route
)) {
1419 /* Specifying a prefix will always display details */
1420 ospf6_route_show_detail(vty
, route
, json_array_routes
,
1422 route
= ospf6_route_next(route
);
1425 json_object_object_add(json
, "routes", json_array_routes
);
1427 ospf6_route_unlock(route
);
1430 static void ospf6_route_show_table_match(struct vty
*vty
, int detail
,
1431 struct prefix
*prefix
,
1432 struct ospf6_route_table
*table
,
1433 json_object
*json
, bool use_json
)
1435 struct ospf6_route
*route
;
1436 json_object
*json_array_routes
= NULL
;
1438 assert(prefix
->family
);
1440 route
= ospf6_route_match_head(prefix
, table
);
1442 json_array_routes
= json_object_new_array();
1445 ospf6_route_show_detail(vty
, route
, json_array_routes
,
1448 ospf6_route_show(vty
, route
, json_array_routes
,
1450 route
= ospf6_route_match_next(prefix
, route
);
1453 json_object_object_add(json
, "routes", json_array_routes
);
1456 static void ospf6_route_show_table_type(struct vty
*vty
, int detail
,
1458 struct ospf6_route_table
*table
,
1459 json_object
*json
, bool use_json
)
1461 struct ospf6_route
*route
;
1462 json_object
*json_array_routes
= NULL
;
1464 route
= ospf6_route_head(table
);
1466 json_array_routes
= json_object_new_array();
1468 if (route
->path
.type
== type
) {
1470 ospf6_route_show_detail(vty
, route
,
1474 ospf6_route_show(vty
, route
, json_array_routes
,
1477 route
= ospf6_route_next(route
);
1480 json_object_object_add(json
, "routes", json_array_routes
);
1483 static void ospf6_route_show_table(struct vty
*vty
, int detail
,
1484 struct ospf6_route_table
*table
,
1485 json_object
*json
, bool use_json
)
1487 struct ospf6_route
*route
;
1488 json_object
*json_array_routes
= NULL
;
1490 route
= ospf6_route_head(table
);
1492 json_array_routes
= json_object_new_array();
1495 ospf6_route_show_detail(vty
, route
, json_array_routes
,
1498 ospf6_route_show(vty
, route
, json_array_routes
,
1500 route
= ospf6_route_next(route
);
1503 json_object_object_add(json
, "routes", json_array_routes
);
1506 int ospf6_route_table_show(struct vty
*vty
, int argc_start
, int argc
,
1507 struct cmd_token
**argv
,
1508 struct ospf6_route_table
*table
, bool use_json
)
1516 struct prefix prefix
;
1518 int arg_end
= use_json
? (argc
- 1) : argc
;
1519 json_object
*json
= NULL
;
1521 memset(&prefix
, 0, sizeof(struct prefix
));
1524 json
= json_object_new_object();
1526 for (i
= argc_start
; i
< arg_end
; i
++) {
1527 if (strmatch(argv
[i
]->text
, "summary")) {
1532 if (strmatch(argv
[i
]->text
, "intra-area")) {
1533 type
= OSPF6_PATH_TYPE_INTRA
;
1537 if (strmatch(argv
[i
]->text
, "inter-area")) {
1538 type
= OSPF6_PATH_TYPE_INTER
;
1542 if (strmatch(argv
[i
]->text
, "external-1")) {
1543 type
= OSPF6_PATH_TYPE_EXTERNAL1
;
1547 if (strmatch(argv
[i
]->text
, "external-2")) {
1548 type
= OSPF6_PATH_TYPE_EXTERNAL2
;
1552 if (strmatch(argv
[i
]->text
, "detail")) {
1557 if (strmatch(argv
[i
]->text
, "match")) {
1562 ret
= str2prefix(argv
[i
]->arg
, &prefix
);
1563 if (ret
== 1 && prefix
.family
== AF_INET6
) {
1565 if (strchr(argv
[i
]->arg
, '/'))
1570 json_object_string_add(json
, "malformedArgument",
1573 vty_out(vty
, "Malformed argument: %s\n", argv
[i
]->arg
);
1578 /* Give summary of this route table */
1580 ospf6_route_show_table_summary(vty
, table
, json
, use_json
);
1582 vty_out(vty
, "%s\n",
1583 json_object_to_json_string_ext(
1584 json
, JSON_C_TO_STRING_PRETTY
));
1585 json_object_free(json
);
1590 /* Give exact prefix-match route */
1591 if (isprefix
&& !match
) {
1592 /* If exact address, give best matching route */
1594 ospf6_route_show_table_address(vty
, &prefix
, table
,
1597 ospf6_route_show_table_prefix(vty
, &prefix
, table
, json
,
1601 vty_out(vty
, "%s\n",
1602 json_object_to_json_string_ext(
1603 json
, JSON_C_TO_STRING_PRETTY
));
1604 json_object_free(json
);
1610 ospf6_route_show_table_match(vty
, detail
, &prefix
, table
, json
,
1613 ospf6_route_show_table_type(vty
, detail
, type
, table
, json
,
1616 ospf6_route_show_table(vty
, detail
, table
, json
, use_json
);
1619 vty_out(vty
, "%s\n",
1620 json_object_to_json_string_ext(
1621 json
, JSON_C_TO_STRING_PRETTY
));
1622 json_object_free(json
);
1627 static void ospf6_linkstate_show_header(struct vty
*vty
)
1629 vty_out(vty
, "%-7s %-15s %-15s %-8s %-14s %s\n", "Type", "Router-ID",
1630 "Net-ID", "Rtr-Bits", "Options", "Cost");
1633 static void ospf6_linkstate_show(struct vty
*vty
, struct ospf6_route
*route
)
1635 uint32_t router
, id
;
1636 char routername
[16], idname
[16], rbits
[16], options
[16];
1638 router
= ospf6_linkstate_prefix_adv_router(&route
->prefix
);
1639 inet_ntop(AF_INET
, &router
, routername
, sizeof(routername
));
1640 id
= ospf6_linkstate_prefix_id(&route
->prefix
);
1641 inet_ntop(AF_INET
, &id
, idname
, sizeof(idname
));
1643 ospf6_capability_printbuf(route
->path
.router_bits
, rbits
,
1645 ospf6_options_printbuf(route
->path
.options
, options
, sizeof(options
));
1648 vty_out(vty
, "%-7s %-15s %-15s %-8s %-14s %lu\n", "Network",
1649 routername
, idname
, rbits
, options
,
1650 (unsigned long)route
->path
.cost
);
1652 vty_out(vty
, "%-7s %-15s %-15s %-8s %-14s %lu\n", "Router",
1653 routername
, idname
, rbits
, options
,
1654 (unsigned long)route
->path
.cost
);
1658 static void ospf6_linkstate_show_table_exact(struct vty
*vty
,
1659 struct prefix
*prefix
,
1660 struct ospf6_route_table
*table
)
1662 struct ospf6_route
*route
;
1664 route
= ospf6_route_lookup(prefix
, table
);
1668 ospf6_route_lock(route
);
1669 while (route
&& ospf6_route_is_prefix(prefix
, route
)) {
1670 /* Specifying a prefix will always display details */
1671 ospf6_route_show_detail(vty
, route
, NULL
, false);
1672 route
= ospf6_route_next(route
);
1675 ospf6_route_unlock(route
);
1678 static void ospf6_linkstate_show_table(struct vty
*vty
, int detail
,
1679 struct ospf6_route_table
*table
)
1681 struct ospf6_route
*route
;
1684 ospf6_linkstate_show_header(vty
);
1686 route
= ospf6_route_head(table
);
1689 ospf6_route_show_detail(vty
, route
, NULL
, false);
1691 ospf6_linkstate_show(vty
, route
);
1692 route
= ospf6_route_next(route
);
1696 int ospf6_linkstate_table_show(struct vty
*vty
, int idx_ipv4
, int argc
,
1697 struct cmd_token
**argv
,
1698 struct ospf6_route_table
*table
)
1704 struct prefix router
, id
, prefix
;
1706 memset(&router
, 0, sizeof(struct prefix
));
1707 memset(&id
, 0, sizeof(struct prefix
));
1708 memset(&prefix
, 0, sizeof(struct prefix
));
1710 for (i
= idx_ipv4
; i
< argc
; i
++) {
1711 if (strmatch(argv
[i
]->text
, "detail")) {
1717 ret
= str2prefix(argv
[i
]->arg
, &router
);
1718 if (ret
== 1 && router
.family
== AF_INET
) {
1722 vty_out(vty
, "Malformed argument: %s\n", argv
[i
]->arg
);
1727 ret
= str2prefix(argv
[i
]->arg
, &id
);
1728 if (ret
== 1 && id
.family
== AF_INET
) {
1732 vty_out(vty
, "Malformed argument: %s\n", argv
[i
]->arg
);
1736 vty_out(vty
, "Malformed argument: %s\n", argv
[i
]->arg
);
1741 ospf6_linkstate_prefix(router
.u
.prefix4
.s_addr
,
1742 id
.u
.prefix4
.s_addr
, &prefix
);
1745 ospf6_linkstate_show_table_exact(vty
, &prefix
, table
);
1747 ospf6_linkstate_show_table(vty
, detail
, table
);
1753 void ospf6_brouter_show_header(struct vty
*vty
)
1755 vty_out(vty
, "%-15s %-8s %-14s %-10s %-15s\n", "Router-ID", "Rtr-Bits",
1756 "Options", "Path-Type", "Area");
1759 void ospf6_brouter_show(struct vty
*vty
, struct ospf6_route
*route
)
1761 uint32_t adv_router
;
1762 char adv
[16], rbits
[16], options
[16], area
[16];
1764 adv_router
= ospf6_linkstate_prefix_adv_router(&route
->prefix
);
1765 inet_ntop(AF_INET
, &adv_router
, adv
, sizeof(adv
));
1766 ospf6_capability_printbuf(route
->path
.router_bits
, rbits
,
1768 ospf6_options_printbuf(route
->path
.options
, options
, sizeof(options
));
1769 inet_ntop(AF_INET
, &route
->path
.area_id
, area
, sizeof(area
));
1771 /* vty_out (vty, "%-15s %-8s %-14s %-10s %-15s\n",
1772 "Router-ID", "Rtr-Bits", "Options", "Path-Type", "Area"); */
1773 vty_out(vty
, "%-15s %-8s %-14s %-10s %-15s\n", adv
, rbits
, options
,
1774 OSPF6_PATH_TYPE_NAME(route
->path
.type
), area
);
1777 DEFUN (debug_ospf6_route
,
1778 debug_ospf6_route_cmd
,
1779 "debug ospf6 route <table|intra-area|inter-area|memory>",
1783 "Debug route table calculation\n"
1784 "Debug intra-area route calculation\n"
1785 "Debug inter-area route calculation\n"
1786 "Debug route memory use\n"
1790 unsigned char level
= 0;
1792 if (!strcmp(argv
[idx_type
]->text
, "table"))
1793 level
= OSPF6_DEBUG_ROUTE_TABLE
;
1794 else if (!strcmp(argv
[idx_type
]->text
, "intra-area"))
1795 level
= OSPF6_DEBUG_ROUTE_INTRA
;
1796 else if (!strcmp(argv
[idx_type
]->text
, "inter-area"))
1797 level
= OSPF6_DEBUG_ROUTE_INTER
;
1798 else if (!strcmp(argv
[idx_type
]->text
, "memory"))
1799 level
= OSPF6_DEBUG_ROUTE_MEMORY
;
1800 OSPF6_DEBUG_ROUTE_ON(level
);
1804 DEFUN (no_debug_ospf6_route
,
1805 no_debug_ospf6_route_cmd
,
1806 "no debug ospf6 route <table|intra-area|inter-area|memory>",
1811 "Debug route table calculation\n"
1812 "Debug intra-area route calculation\n"
1813 "Debug inter-area route calculation\n"
1814 "Debug route memory use\n")
1817 unsigned char level
= 0;
1819 if (!strcmp(argv
[idx_type
]->text
, "table"))
1820 level
= OSPF6_DEBUG_ROUTE_TABLE
;
1821 else if (!strcmp(argv
[idx_type
]->text
, "intra-area"))
1822 level
= OSPF6_DEBUG_ROUTE_INTRA
;
1823 else if (!strcmp(argv
[idx_type
]->text
, "inter-area"))
1824 level
= OSPF6_DEBUG_ROUTE_INTER
;
1825 else if (!strcmp(argv
[idx_type
]->text
, "memory"))
1826 level
= OSPF6_DEBUG_ROUTE_MEMORY
;
1827 OSPF6_DEBUG_ROUTE_OFF(level
);
1831 int config_write_ospf6_debug_route(struct vty
*vty
)
1833 if (IS_OSPF6_DEBUG_ROUTE(TABLE
))
1834 vty_out(vty
, "debug ospf6 route table\n");
1835 if (IS_OSPF6_DEBUG_ROUTE(INTRA
))
1836 vty_out(vty
, "debug ospf6 route intra-area\n");
1837 if (IS_OSPF6_DEBUG_ROUTE(INTER
))
1838 vty_out(vty
, "debug ospf6 route inter-area\n");
1839 if (IS_OSPF6_DEBUG_ROUTE(MEMORY
))
1840 vty_out(vty
, "debug ospf6 route memory\n");
1845 void install_element_ospf6_debug_route(void)
1847 install_element(ENABLE_NODE
, &debug_ospf6_route_cmd
);
1848 install_element(ENABLE_NODE
, &no_debug_ospf6_route_cmd
);
1849 install_element(CONFIG_NODE
, &debug_ospf6_route_cmd
);
1850 install_element(CONFIG_NODE
, &no_debug_ospf6_route_cmd
);