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_ROUTE_TABLE
, "OSPF6 route table");
43 DEFINE_MTYPE_STATIC(OSPF6D
, OSPF6_NEXTHOP
, "OSPF6 nexthop");
44 DEFINE_MTYPE_STATIC(OSPF6D
, OSPF6_PATH
, "OSPF6 Path");
46 unsigned char conf_debug_ospf6_route
= 0;
48 static char *ospf6_route_table_name(struct ospf6_route_table
*table
)
51 switch (table
->scope_type
) {
52 case OSPF6_SCOPE_TYPE_GLOBAL
: {
53 switch (table
->table_type
) {
54 case OSPF6_TABLE_TYPE_ROUTES
:
55 snprintf(name
, sizeof(name
), "global route table");
57 case OSPF6_TABLE_TYPE_BORDER_ROUTERS
:
58 snprintf(name
, sizeof(name
), "global brouter table");
60 case OSPF6_TABLE_TYPE_EXTERNAL_ROUTES
:
61 snprintf(name
, sizeof(name
), "global external table");
64 snprintf(name
, sizeof(name
), "global unknown table");
69 case OSPF6_SCOPE_TYPE_AREA
: {
70 struct ospf6_area
*oa
= (struct ospf6_area
*)table
->scope
;
71 switch (table
->table_type
) {
72 case OSPF6_TABLE_TYPE_SPF_RESULTS
:
73 snprintf(name
, sizeof(name
), "area %s spf table",
76 case OSPF6_TABLE_TYPE_ROUTES
:
77 snprintf(name
, sizeof(name
), "area %s route table",
80 case OSPF6_TABLE_TYPE_PREFIX_RANGES
:
81 snprintf(name
, sizeof(name
), "area %s range table",
84 case OSPF6_TABLE_TYPE_SUMMARY_PREFIXES
:
85 snprintf(name
, sizeof(name
),
86 "area %s summary prefix table", oa
->name
);
88 case OSPF6_TABLE_TYPE_SUMMARY_ROUTERS
:
89 snprintf(name
, sizeof(name
),
90 "area %s summary router table", oa
->name
);
93 snprintf(name
, sizeof(name
), "area %s unknown table",
99 case OSPF6_SCOPE_TYPE_INTERFACE
: {
100 struct ospf6_interface
*oi
=
101 (struct ospf6_interface
*)table
->scope
;
102 switch (table
->table_type
) {
103 case OSPF6_TABLE_TYPE_CONNECTED_ROUTES
:
104 snprintf(name
, sizeof(name
),
105 "interface %s connected table",
106 oi
->interface
->name
);
109 snprintf(name
, sizeof(name
),
110 "interface %s unknown table",
111 oi
->interface
->name
);
117 switch (table
->table_type
) {
118 case OSPF6_TABLE_TYPE_SPF_RESULTS
:
119 snprintf(name
, sizeof(name
), "temporary spf table");
122 snprintf(name
, sizeof(name
), "temporary unknown table");
130 void ospf6_linkstate_prefix(uint32_t adv_router
, uint32_t id
,
131 struct prefix
*prefix
)
133 memset(prefix
, 0, sizeof(struct prefix
));
134 prefix
->family
= AF_INET6
;
135 prefix
->prefixlen
= 64;
136 memcpy(&prefix
->u
.prefix6
.s6_addr
[0], &adv_router
, 4);
137 memcpy(&prefix
->u
.prefix6
.s6_addr
[4], &id
, 4);
140 void ospf6_linkstate_prefix2str(struct prefix
*prefix
, char *buf
, int size
)
142 uint32_t adv_router
, id
;
143 char adv_router_str
[16], id_str
[16];
144 memcpy(&adv_router
, &prefix
->u
.prefix6
.s6_addr
[0], 4);
145 memcpy(&id
, &prefix
->u
.prefix6
.s6_addr
[4], 4);
146 inet_ntop(AF_INET
, &adv_router
, adv_router_str
, sizeof(adv_router_str
));
147 inet_ntop(AF_INET
, &id
, id_str
, sizeof(id_str
));
149 snprintf(buf
, size
, "%s Net-ID: %s", adv_router_str
, id_str
);
151 snprintf(buf
, size
, "%s", adv_router_str
);
154 /* Global strings for logging */
155 const char *const ospf6_dest_type_str
[OSPF6_DEST_TYPE_MAX
] = {
156 "Unknown", "Router", "Network", "Discard", "Linkstate", "AddressRange",
159 const char *const ospf6_dest_type_substr
[OSPF6_DEST_TYPE_MAX
] = {
160 "?", "R", "N", "D", "L", "A",
163 const char *const ospf6_path_type_str
[OSPF6_PATH_TYPE_MAX
] = {
164 "Unknown", "Intra-Area", "Inter-Area", "External-1", "External-2",
167 const char *const ospf6_path_type_substr
[OSPF6_PATH_TYPE_MAX
] = {
168 "??", "IA", "IE", "E1", "E2",
171 const char *ospf6_path_type_json
[OSPF6_PATH_TYPE_MAX
] = {
172 "UnknownRoute", "IntraArea", "InterArea", "External1", "External2",
176 struct ospf6_nexthop
*ospf6_nexthop_create(void)
178 struct ospf6_nexthop
*nh
;
180 nh
= XCALLOC(MTYPE_OSPF6_NEXTHOP
, sizeof(struct ospf6_nexthop
));
184 void ospf6_nexthop_delete(struct ospf6_nexthop
*nh
)
186 XFREE(MTYPE_OSPF6_NEXTHOP
, nh
);
189 void ospf6_clear_nexthops(struct list
*nh_list
)
191 struct listnode
*node
;
192 struct ospf6_nexthop
*nh
;
195 for (ALL_LIST_ELEMENTS_RO(nh_list
, node
, nh
))
196 ospf6_nexthop_clear(nh
);
200 static struct ospf6_nexthop
*
201 ospf6_route_find_nexthop(struct list
*nh_list
, struct ospf6_nexthop
*nh_match
)
203 struct listnode
*node
;
204 struct ospf6_nexthop
*nh
;
206 if (nh_list
&& nh_match
) {
207 for (ALL_LIST_ELEMENTS_RO(nh_list
, node
, nh
)) {
208 if (ospf6_nexthop_is_same(nh
, nh_match
))
216 void ospf6_copy_nexthops(struct list
*dst
, struct list
*src
)
218 struct ospf6_nexthop
*nh_new
, *nh
;
219 struct listnode
*node
;
222 for (ALL_LIST_ELEMENTS_RO(src
, node
, nh
)) {
223 if (ospf6_nexthop_is_set(nh
)) {
224 nh_new
= ospf6_nexthop_create();
225 ospf6_nexthop_copy(nh_new
, nh
);
226 listnode_add_sort(dst
, nh_new
);
232 void ospf6_merge_nexthops(struct list
*dst
, struct list
*src
)
234 struct listnode
*node
;
235 struct ospf6_nexthop
*nh
, *nh_new
;
238 for (ALL_LIST_ELEMENTS_RO(src
, node
, nh
)) {
239 if (!ospf6_route_find_nexthop(dst
, nh
)) {
240 nh_new
= ospf6_nexthop_create();
241 ospf6_nexthop_copy(nh_new
, nh
);
242 listnode_add_sort(dst
, nh_new
);
248 int ospf6_route_cmp_nexthops(struct ospf6_route
*a
, struct ospf6_route
*b
)
250 struct listnode
*anode
, *bnode
;
251 struct ospf6_nexthop
*anh
, *bnh
;
252 bool identical
= false;
255 if (listcount(a
->nh_list
) == listcount(b
->nh_list
)) {
256 for (ALL_LIST_ELEMENTS_RO(a
->nh_list
, anode
, anh
)) {
258 for (ALL_LIST_ELEMENTS_RO(b
->nh_list
, bnode
,
260 if (ospf6_nexthop_is_same(anh
, bnh
))
263 /* Currnet List A element not found List B
264 * Non-Identical lists return */
265 if (identical
== false)
272 /* One of the routes doesn't exist ? */
276 int ospf6_num_nexthops(struct list
*nh_list
)
278 return (listcount(nh_list
));
281 void ospf6_add_nexthop(struct list
*nh_list
, int ifindex
, struct in6_addr
*addr
)
283 struct ospf6_nexthop
*nh
;
284 struct ospf6_nexthop nh_match
;
287 nh_match
.ifindex
= ifindex
;
289 memcpy(&nh_match
.address
, addr
,
290 sizeof(struct in6_addr
));
292 memset(&nh_match
.address
, 0, sizeof(struct in6_addr
));
294 if (!ospf6_route_find_nexthop(nh_list
, &nh_match
)) {
295 nh
= ospf6_nexthop_create();
296 ospf6_nexthop_copy(nh
, &nh_match
);
297 listnode_add(nh_list
, nh
);
302 void ospf6_route_zebra_copy_nexthops(struct ospf6_route
*route
,
303 struct zapi_nexthop nexthops
[],
304 int entries
, vrf_id_t vrf_id
)
306 struct ospf6_nexthop
*nh
;
307 struct listnode
*node
;
313 for (ALL_LIST_ELEMENTS_RO(route
->nh_list
, node
, nh
)) {
314 if (IS_OSPF6_DEBUG_ZEBRA(SEND
)) {
316 inet_ntop(AF_INET6
, &nh
->address
, buf
,
318 ifname
= ifindex2ifname(nh
->ifindex
, vrf_id
);
319 zlog_debug(" nexthop: %s%%%.*s(%d)", buf
,
320 IFNAMSIZ
, ifname
, nh
->ifindex
);
325 nexthops
[i
].vrf_id
= vrf_id
;
326 nexthops
[i
].ifindex
= nh
->ifindex
;
327 if (!IN6_IS_ADDR_UNSPECIFIED(&nh
->address
)) {
328 nexthops
[i
].gate
.ipv6
= nh
->address
;
329 nexthops
[i
].type
= NEXTHOP_TYPE_IPV6_IFINDEX
;
331 nexthops
[i
].type
= NEXTHOP_TYPE_IFINDEX
;
337 int ospf6_route_get_first_nh_index(struct ospf6_route
*route
)
339 struct ospf6_nexthop
*nh
;
342 nh
= listnode_head(route
->nh_list
);
350 int ospf6_nexthop_cmp(struct ospf6_nexthop
*a
, struct ospf6_nexthop
*b
)
352 if (a
->ifindex
< b
->ifindex
)
354 else if (a
->ifindex
> b
->ifindex
)
357 return memcmp(&a
->address
, &b
->address
,
358 sizeof(struct in6_addr
));
363 static int ospf6_path_cmp(struct ospf6_path
*a
, struct ospf6_path
*b
)
365 if (a
->origin
.adv_router
< b
->origin
.adv_router
)
367 else if (a
->origin
.adv_router
> b
->origin
.adv_router
)
373 void ospf6_path_free(struct ospf6_path
*op
)
376 list_delete(&op
->nh_list
);
377 XFREE(MTYPE_OSPF6_PATH
, op
);
380 struct ospf6_path
*ospf6_path_dup(struct ospf6_path
*path
)
382 struct ospf6_path
*new;
384 new = XCALLOC(MTYPE_OSPF6_PATH
, sizeof(struct ospf6_path
));
385 memcpy(new, path
, sizeof(struct ospf6_path
));
386 new->nh_list
= list_new();
387 new->nh_list
->cmp
= (int (*)(void *, void *))ospf6_nexthop_cmp
;
388 new->nh_list
->del
= (void (*)(void *))ospf6_nexthop_delete
;
393 void ospf6_copy_paths(struct list
*dst
, struct list
*src
)
395 struct ospf6_path
*path_new
, *path
;
396 struct listnode
*node
;
399 for (ALL_LIST_ELEMENTS_RO(src
, node
, path
)) {
400 path_new
= ospf6_path_dup(path
);
401 ospf6_copy_nexthops(path_new
->nh_list
, path
->nh_list
);
402 listnode_add_sort(dst
, path_new
);
407 struct ospf6_route
*ospf6_route_create(void)
409 struct ospf6_route
*route
;
411 route
= XCALLOC(MTYPE_OSPF6_ROUTE
, sizeof(struct ospf6_route
));
412 route
->nh_list
= list_new();
413 route
->nh_list
->cmp
= (int (*)(void *, void *))ospf6_nexthop_cmp
;
414 route
->nh_list
->del
= (void (*)(void *))ospf6_nexthop_delete
;
415 route
->paths
= list_new();
416 route
->paths
->cmp
= (int (*)(void *, void *))ospf6_path_cmp
;
417 route
->paths
->del
= (void (*)(void *))ospf6_path_free
;
421 void ospf6_route_delete(struct ospf6_route
*route
)
425 list_delete(&route
->nh_list
);
427 list_delete(&route
->paths
);
428 XFREE(MTYPE_OSPF6_ROUTE
, route
);
432 struct ospf6_route
*ospf6_route_copy(struct ospf6_route
*route
)
434 struct ospf6_route
*new;
436 new = ospf6_route_create();
437 new->type
= route
->type
;
438 memcpy(&new->prefix
, &route
->prefix
, sizeof(struct prefix
));
439 new->installed
= route
->installed
;
440 new->changed
= route
->changed
;
441 new->flag
= route
->flag
;
442 new->route_option
= route
->route_option
;
443 new->linkstate_id
= route
->linkstate_id
;
444 new->path
= route
->path
;
445 ospf6_copy_nexthops(new->nh_list
, route
->nh_list
);
446 ospf6_copy_paths(new->paths
, route
->paths
);
455 void ospf6_route_lock(struct ospf6_route
*route
)
460 void ospf6_route_unlock(struct ospf6_route
*route
)
462 assert(route
->lock
> 0);
464 if (route
->lock
== 0) {
465 /* Can't detach from the table until here
466 because ospf6_route_next () will use
467 the 'route->table' pointer for logging */
469 ospf6_route_delete(route
);
473 /* Route compare function. If ra is more preferred, it returns
474 less than 0. If rb is more preferred returns greater than 0.
475 Otherwise (neither one is preferred), returns 0 */
476 int ospf6_route_cmp(struct ospf6_route
*ra
, struct ospf6_route
*rb
)
478 assert(ospf6_route_is_same(ra
, rb
));
479 assert(OSPF6_PATH_TYPE_NONE
< ra
->path
.type
480 && ra
->path
.type
< OSPF6_PATH_TYPE_MAX
);
481 assert(OSPF6_PATH_TYPE_NONE
< rb
->path
.type
482 && rb
->path
.type
< OSPF6_PATH_TYPE_MAX
);
484 if (ra
->type
!= rb
->type
)
485 return (ra
->type
- rb
->type
);
487 if (ra
->path
.type
!= rb
->path
.type
)
488 return (ra
->path
.type
- rb
->path
.type
);
490 if (ra
->path
.type
== OSPF6_PATH_TYPE_EXTERNAL2
) {
491 if (ra
->path
.u
.cost_e2
!= rb
->path
.u
.cost_e2
)
492 return (ra
->path
.u
.cost_e2
- rb
->path
.u
.cost_e2
);
494 return (ra
->path
.cost
- rb
->path
.cost
);
496 if (ra
->path
.cost
!= rb
->path
.cost
)
497 return (ra
->path
.cost
- rb
->path
.cost
);
500 if (ra
->path
.area_id
!= rb
->path
.area_id
)
501 return (ntohl(ra
->path
.area_id
) - ntohl(rb
->path
.area_id
));
506 struct ospf6_route
*ospf6_route_lookup(struct prefix
*prefix
,
507 struct ospf6_route_table
*table
)
509 struct route_node
*node
;
510 struct ospf6_route
*route
;
512 node
= route_node_lookup(table
->table
, prefix
);
516 route
= (struct ospf6_route
*)node
->info
;
517 route_unlock_node(node
); /* to free the lookup lock */
522 ospf6_route_lookup_identical(struct ospf6_route
*route
,
523 struct ospf6_route_table
*table
)
525 struct ospf6_route
*target
;
527 for (target
= ospf6_route_lookup(&route
->prefix
, table
); target
;
528 target
= target
->next
) {
529 if (target
->type
== route
->type
530 && (memcmp(&target
->prefix
, &route
->prefix
,
531 sizeof(struct prefix
))
533 && target
->path
.type
== route
->path
.type
534 && target
->path
.cost
== route
->path
.cost
535 && target
->path
.u
.cost_e2
== route
->path
.u
.cost_e2
536 && ospf6_route_cmp_nexthops(target
, route
) == 0)
543 ospf6_route_lookup_bestmatch(struct prefix
*prefix
,
544 struct ospf6_route_table
*table
)
546 struct route_node
*node
;
547 struct ospf6_route
*route
;
549 node
= route_node_match(table
->table
, prefix
);
552 route_unlock_node(node
);
554 route
= (struct ospf6_route
*)node
->info
;
559 static void route_table_assert(struct ospf6_route_table
*table
)
561 struct ospf6_route
*prev
, *r
, *next
;
562 unsigned int link_error
= 0, num
= 0;
564 r
= ospf6_route_head(table
);
570 next
= ospf6_route_next(r
);
579 for (r
= ospf6_route_head(table
); r
; r
= ospf6_route_next(r
))
582 if (link_error
== 0 && num
== table
->count
)
585 flog_err(EC_LIB_DEVELOPMENT
, "PANIC !!");
586 flog_err(EC_LIB_DEVELOPMENT
,
587 "Something has gone wrong with ospf6_route_table[%p]", table
);
588 zlog_debug("table count = %d, real number = %d", table
->count
, num
);
589 zlog_debug("DUMP START");
590 for (r
= ospf6_route_head(table
); r
; r
= ospf6_route_next(r
))
591 zlog_info("%p<-[%p]->%p : %pFX", r
->prev
, r
, r
->next
,
593 zlog_debug("DUMP END");
595 assert(link_error
== 0 && num
== table
->count
);
597 #define ospf6_route_table_assert(t) (route_table_assert (t))
599 #define ospf6_route_table_assert(t) ((void) 0)
602 struct ospf6_route
*ospf6_route_add(struct ospf6_route
*route
,
603 struct ospf6_route_table
*table
)
605 struct route_node
*node
, *nextnode
, *prevnode
;
606 struct ospf6_route
*current
= NULL
;
607 struct ospf6_route
*prev
= NULL
, *old
= NULL
, *next
= NULL
;
608 char buf
[PREFIX2STR_BUFFER
];
611 assert(route
->rnode
== NULL
);
612 assert(route
->lock
== 0);
613 assert(route
->next
== NULL
);
614 assert(route
->prev
== NULL
);
616 if (route
->type
== OSPF6_DEST_TYPE_LINKSTATE
)
617 ospf6_linkstate_prefix2str(&route
->prefix
, buf
, sizeof(buf
));
619 prefix2str(&route
->prefix
, buf
, sizeof(buf
));
621 if (IS_OSPF6_DEBUG_ROUTE(MEMORY
))
622 zlog_debug("%s %p: route add %p: %s paths %u nh %u",
623 ospf6_route_table_name(table
), (void *)table
,
624 (void *)route
, buf
, listcount(route
->paths
),
625 listcount(route
->nh_list
));
626 else if (IS_OSPF6_DEBUG_ROUTE(TABLE
))
627 zlog_debug("%s: route add: %s", ospf6_route_table_name(table
),
632 node
= route_node_get(table
->table
, &route
->prefix
);
635 /* find place to insert */
636 for (current
= node
->info
; current
; current
= current
->next
) {
637 if (!ospf6_route_is_same(current
, route
))
639 else if (current
->type
!= route
->type
)
641 else if (ospf6_route_is_same_origin(current
, route
))
643 else if (ospf6_route_cmp(current
, route
) > 0)
653 /* if route does not actually change, return unchanged */
654 if (ospf6_route_is_identical(old
, route
)) {
655 if (IS_OSPF6_DEBUG_ROUTE(MEMORY
))
657 "%s %p: route add %p: needless update of %p old cost %u",
658 ospf6_route_table_name(table
),
659 (void *)table
, (void *)route
,
660 (void *)old
, old
->path
.cost
);
661 else if (IS_OSPF6_DEBUG_ROUTE(TABLE
))
662 zlog_debug("%s: route add: needless update",
663 ospf6_route_table_name(table
));
665 ospf6_route_delete(route
);
666 SET_FLAG(old
->flag
, OSPF6_ROUTE_ADD
);
667 ospf6_route_table_assert(table
);
669 /* to free the lookup lock */
670 route_unlock_node(node
);
674 if (IS_OSPF6_DEBUG_ROUTE(MEMORY
))
676 "%s %p: route add %p cost %u paths %u nh %u: update of %p cost %u paths %u nh %u",
677 ospf6_route_table_name(table
), (void *)table
,
678 (void *)route
, route
->path
.cost
,
679 listcount(route
->paths
),
680 listcount(route
->nh_list
), (void *)old
,
681 old
->path
.cost
, listcount(old
->paths
),
682 listcount(old
->nh_list
));
683 else if (IS_OSPF6_DEBUG_ROUTE(TABLE
))
684 zlog_debug("%s: route add: update",
685 ospf6_route_table_name(table
));
687 /* replace old one if exists */
688 if (node
->info
== old
) {
690 SET_FLAG(route
->flag
, OSPF6_ROUTE_BEST
);
691 if (IS_OSPF6_DEBUG_ROUTE(MEMORY
))
692 zlog_debug("%s: replace old route %s",
697 old
->prev
->next
= route
;
698 route
->prev
= old
->prev
;
700 old
->next
->prev
= route
;
701 route
->next
= old
->next
;
703 route
->installed
= old
->installed
;
704 route
->changed
= now
;
705 assert(route
->table
== NULL
);
706 route
->table
= table
;
708 ospf6_route_unlock(old
); /* will be deleted later */
709 ospf6_route_lock(route
);
711 SET_FLAG(route
->flag
, OSPF6_ROUTE_CHANGE
);
712 ospf6_route_table_assert(table
);
715 (*table
->hook_add
)(route
);
720 /* insert if previous or next node found */
722 if (IS_OSPF6_DEBUG_ROUTE(MEMORY
))
724 "%s %p: route add %p cost %u: another path: prev %p, next %p node ref %u",
725 ospf6_route_table_name(table
), (void *)table
,
726 (void *)route
, route
->path
.cost
, (void *)prev
,
727 (void *)next
, route_node_get_lock_count(node
));
728 else if (IS_OSPF6_DEBUG_ROUTE(TABLE
))
729 zlog_debug("%s: route add cost %u: another path found",
730 ospf6_route_table_name(table
),
745 if (node
->info
== next
) {
746 assert(next
&& next
->rnode
== node
);
748 UNSET_FLAG(next
->flag
, OSPF6_ROUTE_BEST
);
749 SET_FLAG(route
->flag
, OSPF6_ROUTE_BEST
);
750 if (IS_OSPF6_DEBUG_ROUTE(MEMORY
))
752 "%s %p: route add %p cost %u: replacing previous best: %p cost %u",
753 ospf6_route_table_name(table
),
754 (void *)table
, (void *)route
,
755 route
->path
.cost
, (void *)next
,
759 route
->installed
= now
;
760 route
->changed
= now
;
761 assert(route
->table
== NULL
);
762 route
->table
= table
;
764 ospf6_route_lock(route
);
766 ospf6_route_table_assert(table
);
768 SET_FLAG(route
->flag
, OSPF6_ROUTE_ADD
);
770 (*table
->hook_add
)(route
);
775 /* Else, this is the brand new route regarding to the prefix */
776 if (IS_OSPF6_DEBUG_ROUTE(MEMORY
))
777 zlog_debug("%s %p: route add %p %s cost %u: brand new route",
778 ospf6_route_table_name(table
), (void *)table
,
779 (void *)route
, buf
, route
->path
.cost
);
780 else if (IS_OSPF6_DEBUG_ROUTE(TABLE
))
781 zlog_debug("%s: route add: brand new route",
782 ospf6_route_table_name(table
));
784 assert(node
->info
== NULL
);
786 SET_FLAG(route
->flag
, OSPF6_ROUTE_BEST
);
787 ospf6_route_lock(route
);
788 route
->installed
= now
;
789 route
->changed
= now
;
790 assert(route
->table
== NULL
);
791 route
->table
= table
;
793 /* lookup real existing next route */
795 route_lock_node(nextnode
);
797 nextnode
= route_next(nextnode
);
798 } while (nextnode
&& nextnode
->info
== NULL
);
801 if (nextnode
== NULL
)
804 route_unlock_node(nextnode
);
806 next
= nextnode
->info
;
811 /* lookup real existing prev route */
813 route_lock_node(prevnode
);
815 prevnode
= route_prev(prevnode
);
816 } while (prevnode
&& prevnode
->info
== NULL
);
819 if (prevnode
== NULL
)
822 route_unlock_node(prevnode
);
824 prev
= prevnode
->info
;
825 while (prev
->next
&& ospf6_route_is_same(prev
, prev
->next
))
832 ospf6_route_table_assert(table
);
834 SET_FLAG(route
->flag
, OSPF6_ROUTE_ADD
);
836 (*table
->hook_add
)(route
);
841 void ospf6_route_remove(struct ospf6_route
*route
,
842 struct ospf6_route_table
*table
)
844 struct route_node
*node
;
845 struct ospf6_route
*current
;
846 char buf
[PREFIX2STR_BUFFER
];
848 if (route
->type
== OSPF6_DEST_TYPE_LINKSTATE
)
849 ospf6_linkstate_prefix2str(&route
->prefix
, buf
, sizeof(buf
));
851 prefix2str(&route
->prefix
, buf
, sizeof(buf
));
853 if (IS_OSPF6_DEBUG_ROUTE(MEMORY
))
854 zlog_debug("%s %p: route remove %p: %s cost %u refcount %u",
855 ospf6_route_table_name(table
), (void *)table
,
856 (void *)route
, buf
, route
->path
.cost
, route
->lock
);
857 else if (IS_OSPF6_DEBUG_ROUTE(TABLE
))
858 zlog_debug("%s: route remove: %s",
859 ospf6_route_table_name(table
), buf
);
861 node
= route_node_lookup(table
->table
, &route
->prefix
);
864 /* find the route to remove, making sure that the route pointer
865 is from the route table. */
866 current
= node
->info
;
867 while (current
&& current
!= route
)
868 current
= current
->next
;
870 assert(current
== route
);
872 /* adjust doubly linked list */
874 route
->prev
->next
= route
->next
;
876 route
->next
->prev
= route
->prev
;
878 if (node
->info
== route
) {
879 if (route
->next
&& route
->next
->rnode
== node
) {
880 node
->info
= route
->next
;
881 SET_FLAG(route
->next
->flag
, OSPF6_ROUTE_BEST
);
882 if (IS_OSPF6_DEBUG_ROUTE(MEMORY
))
883 zlog_debug("%s: remove route %s", __func__
,
888 route_unlock_node(node
); /* to free the original lock */
892 route_unlock_node(node
); /* to free the lookup lock */
894 ospf6_route_table_assert(table
);
896 SET_FLAG(route
->flag
, OSPF6_ROUTE_WAS_REMOVED
);
898 /* Note hook_remove may call ospf6_route_remove */
899 if (table
->hook_remove
)
900 (*table
->hook_remove
)(route
);
902 ospf6_route_unlock(route
);
905 struct ospf6_route
*ospf6_route_head(struct ospf6_route_table
*table
)
907 struct route_node
*node
;
908 struct ospf6_route
*route
;
910 node
= route_top(table
->table
);
914 /* skip to the real existing entry */
915 while (node
&& node
->info
== NULL
)
916 node
= route_next(node
);
920 route_unlock_node(node
);
923 route
= (struct ospf6_route
*)node
->info
;
924 assert(route
->prev
== NULL
);
925 assert(route
->table
== table
);
926 ospf6_route_lock(route
);
928 if (IS_OSPF6_DEBUG_ROUTE(MEMORY
))
929 zlog_info("%s %p: route head: %p<-[%p]->%p",
930 ospf6_route_table_name(table
), (void *)table
,
931 (void *)route
->prev
, (void *)route
,
932 (void *)route
->next
);
937 struct ospf6_route
*ospf6_route_next(struct ospf6_route
*route
)
939 struct ospf6_route
*next
= route
->next
;
941 if (IS_OSPF6_DEBUG_ROUTE(MEMORY
))
942 zlog_info("%s %p: route next: %p<-[%p]->%p , route ref count %u",
943 ospf6_route_table_name(route
->table
),
944 (void *)route
->table
, (void *)route
->prev
,
945 (void *)route
, (void *)route
->next
,
948 ospf6_route_unlock(route
);
950 ospf6_route_lock(next
);
955 struct ospf6_route
*ospf6_route_best_next(struct ospf6_route
*route
)
957 struct route_node
*rnode
;
958 struct ospf6_route
*next
;
960 ospf6_route_unlock(route
);
962 rnode
= route
->rnode
;
963 route_lock_node(rnode
);
964 rnode
= route_next(rnode
);
965 while (rnode
&& rnode
->info
== NULL
)
966 rnode
= route_next(rnode
);
969 route_unlock_node(rnode
);
972 next
= (struct ospf6_route
*)rnode
->info
;
973 ospf6_route_lock(next
);
977 struct ospf6_route
*ospf6_route_match_head(struct prefix
*prefix
,
978 struct ospf6_route_table
*table
)
980 struct route_node
*node
;
981 struct ospf6_route
*route
;
983 /* Walk down tree. */
984 node
= table
->table
->top
;
985 while (node
&& node
->p
.prefixlen
< prefix
->prefixlen
986 && prefix_match(&node
->p
, prefix
))
987 node
= node
->link
[prefix_bit(&prefix
->u
.prefix
,
991 route_lock_node(node
);
992 while (node
&& node
->info
== NULL
)
993 node
= route_next(node
);
996 route_unlock_node(node
);
998 if (!prefix_match(prefix
, &node
->p
))
1002 ospf6_route_lock(route
);
1006 struct ospf6_route
*ospf6_route_match_next(struct prefix
*prefix
,
1007 struct ospf6_route
*route
)
1009 struct ospf6_route
*next
;
1011 next
= ospf6_route_next(route
);
1012 if (next
&& !prefix_match(prefix
, &next
->prefix
)) {
1013 ospf6_route_unlock(next
);
1020 void ospf6_route_remove_all(struct ospf6_route_table
*table
)
1022 struct ospf6_route
*route
;
1023 for (route
= ospf6_route_head(table
); route
;
1024 route
= ospf6_route_next(route
))
1025 ospf6_route_remove(route
, table
);
1028 struct ospf6_route_table
*ospf6_route_table_create(int s
, int t
)
1030 struct ospf6_route_table
*new;
1031 new = XCALLOC(MTYPE_OSPF6_ROUTE_TABLE
,
1032 sizeof(struct ospf6_route_table
));
1033 new->table
= route_table_init();
1034 new->scope_type
= s
;
1035 new->table_type
= t
;
1039 void ospf6_route_table_delete(struct ospf6_route_table
*table
)
1041 ospf6_route_remove_all(table
);
1042 bf_free(table
->idspace
);
1043 route_table_finish(table
->table
);
1044 XFREE(MTYPE_OSPF6_ROUTE_TABLE
, table
);
1049 void ospf6_route_show(struct vty
*vty
, struct ospf6_route
*route
,
1050 json_object
*json_routes
, bool use_json
)
1053 char destination
[PREFIX2STR_BUFFER
], nexthop
[64];
1055 struct timeval now
, res
;
1056 struct listnode
*node
;
1057 struct ospf6_nexthop
*nh
;
1058 json_object
*json_route
= NULL
;
1059 json_object
*json_array_next_hops
= NULL
;
1060 json_object
*json_next_hop
;
1062 if (om6
->ospf6
== NULL
) {
1063 vty_out(vty
, "OSPFv3 is not running\n");
1068 timersub(&now
, &route
->changed
, &res
);
1069 timerstring(&res
, duration
, sizeof(duration
));
1072 if (route
->type
== OSPF6_DEST_TYPE_LINKSTATE
)
1073 ospf6_linkstate_prefix2str(&route
->prefix
, destination
,
1074 sizeof(destination
));
1075 else if (route
->type
== OSPF6_DEST_TYPE_ROUTER
)
1076 inet_ntop(route
->prefix
.family
, &route
->prefix
.u
.prefix
,
1077 destination
, sizeof(destination
));
1079 prefix2str(&route
->prefix
, destination
, sizeof(destination
));
1082 json_route
= json_object_new_object();
1083 json_object_boolean_add(json_route
, "isBestRoute",
1084 ospf6_route_is_best(route
));
1085 json_object_string_add(json_route
, "destinationType",
1086 OSPF6_DEST_TYPE_SUBSTR(route
->type
));
1087 json_object_string_add(
1088 json_route
, "pathType",
1089 OSPF6_PATH_TYPE_SUBSTR(route
->path
.type
));
1090 json_object_string_add(json_route
, "duration", duration
);
1095 json_array_next_hops
= json_object_new_array();
1098 for (ALL_LIST_ELEMENTS_RO(route
->nh_list
, node
, nh
)) {
1099 struct interface
*ifp
;
1101 inet_ntop(AF_INET6
, &nh
->address
, nexthop
, sizeof(nexthop
));
1102 ifp
= if_lookup_by_index_all_vrf(nh
->ifindex
);
1104 json_next_hop
= json_object_new_object();
1105 json_object_string_add(json_next_hop
, "nextHop",
1107 json_object_string_add(json_next_hop
, "interfaceName",
1109 json_object_array_add(json_array_next_hops
,
1113 vty_out(vty
, "%c%1s %2s %-30s %-25s %6.*s %s\n",
1114 (ospf6_route_is_best(route
) ? '*'
1116 OSPF6_DEST_TYPE_SUBSTR(route
->type
),
1117 OSPF6_PATH_TYPE_SUBSTR(
1119 destination
, nexthop
, IFNAMSIZ
,
1120 ifp
->name
, duration
);
1123 vty_out(vty
, "%c%1s %2s %-30s %-25s %6.*s %s\n",
1124 ' ', "", "", "", nexthop
, IFNAMSIZ
,
1129 json_object_object_add(json_route
, "nextHops",
1130 json_array_next_hops
);
1131 json_object_object_add(json_routes
, destination
, json_route
);
1135 void ospf6_route_show_detail(struct vty
*vty
, struct ospf6_route
*route
,
1136 json_object
*json_routes
, bool use_json
)
1138 char destination
[PREFIX2STR_BUFFER
], nexthop
[64];
1139 char area_id
[16], id
[16], adv_router
[16], capa
[16], options
[16];
1140 struct timeval now
, res
;
1142 struct listnode
*node
;
1143 struct ospf6_nexthop
*nh
;
1145 json_object
*json_route
= NULL
;
1146 json_object
*json_array_next_hops
= NULL
;
1147 json_object
*json_next_hop
;
1149 if (om6
->ospf6
== NULL
) {
1150 vty_out(vty
, "OSPFv3 is not running\n");
1157 if (route
->type
== OSPF6_DEST_TYPE_LINKSTATE
)
1158 ospf6_linkstate_prefix2str(&route
->prefix
, destination
,
1159 sizeof(destination
));
1160 else if (route
->type
== OSPF6_DEST_TYPE_ROUTER
)
1161 inet_ntop(route
->prefix
.family
, &route
->prefix
.u
.prefix
,
1162 destination
, sizeof(destination
));
1164 prefix2str(&route
->prefix
, destination
, sizeof(destination
));
1167 json_route
= json_object_new_object();
1168 json_object_string_add(json_route
, "destinationType",
1169 OSPF6_DEST_TYPE_NAME(route
->type
));
1171 vty_out(vty
, "Destination: %s\n", destination
);
1172 vty_out(vty
, "Destination type: %s\n",
1173 OSPF6_DEST_TYPE_NAME(route
->type
));
1177 timersub(&now
, &route
->installed
, &res
);
1178 timerstring(&res
, duration
, sizeof(duration
));
1180 json_object_string_add(json_route
, "installedTimeSince",
1183 vty_out(vty
, "Installed Time: %s ago\n", duration
);
1185 timersub(&now
, &route
->changed
, &res
);
1186 timerstring(&res
, duration
, sizeof(duration
));
1188 json_object_string_add(json_route
, "changedTimeSince",
1191 vty_out(vty
, "Changed Time: %s ago\n", duration
);
1193 /* Debugging info */
1195 json_object_int_add(json_route
, "numberOfLock", route
->lock
);
1197 flag
, sizeof(flag
), "%s%s%s%s",
1198 (CHECK_FLAG(route
->flag
, OSPF6_ROUTE_BEST
) ? "B" : "-"),
1199 (CHECK_FLAG(route
->flag
, OSPF6_ROUTE_ADD
) ? "A" : "-"),
1200 (CHECK_FLAG(route
->flag
, OSPF6_ROUTE_REMOVE
) ? "R"
1202 (CHECK_FLAG(route
->flag
, OSPF6_ROUTE_CHANGE
) ? "C"
1204 json_object_string_add(json_route
, "flags", flag
);
1206 vty_out(vty
, "Lock: %d Flags: %s%s%s%s\n", route
->lock
,
1207 (CHECK_FLAG(route
->flag
, OSPF6_ROUTE_BEST
) ? "B" : "-"),
1208 (CHECK_FLAG(route
->flag
, OSPF6_ROUTE_ADD
) ? "A" : "-"),
1209 (CHECK_FLAG(route
->flag
, OSPF6_ROUTE_REMOVE
) ? "R"
1211 (CHECK_FLAG(route
->flag
, OSPF6_ROUTE_CHANGE
) ? "C"
1213 vty_out(vty
, "Memory: prev: %p this: %p next: %p\n",
1214 (void *)route
->prev
, (void *)route
,
1215 (void *)route
->next
);
1221 inet_ntop(AF_INET
, &route
->path
.area_id
, area_id
, sizeof(area_id
));
1223 json_object_string_add(json_route
, "associatedArea", area_id
);
1225 vty_out(vty
, "Associated Area: %s\n", area_id
);
1229 json_object_string_add(json_route
, "pathType",
1230 OSPF6_PATH_TYPE_NAME(route
->path
.type
));
1232 vty_out(vty
, "Path Type: %s\n",
1233 OSPF6_PATH_TYPE_NAME(route
->path
.type
));
1236 inet_ntop(AF_INET
, &route
->path
.origin
.id
, id
, sizeof(id
));
1237 inet_ntop(AF_INET
, &route
->path
.origin
.adv_router
, adv_router
,
1238 sizeof(adv_router
));
1240 json_object_string_add(
1241 json_route
, "lsOriginRoutePathType",
1242 ospf6_lstype_name(route
->path
.origin
.type
));
1243 json_object_string_add(json_route
, "lsId", id
);
1244 json_object_string_add(json_route
, "lsAdvertisingRouter",
1247 vty_out(vty
, "LS Origin: %s Id: %s Adv: %s\n",
1248 ospf6_lstype_name(route
->path
.origin
.type
), id
,
1253 ospf6_options_printbuf(route
->path
.options
, options
, sizeof(options
));
1255 json_object_string_add(json_route
, "options", options
);
1257 vty_out(vty
, "Options: %s\n", options
);
1260 ospf6_capability_printbuf(route
->path
.router_bits
, capa
, sizeof(capa
));
1262 json_object_string_add(json_route
, "routerBits", capa
);
1264 vty_out(vty
, "Router Bits: %s\n", capa
);
1266 /* Prefix Options */
1268 json_object_string_add(json_route
, "prefixOptions", "xxx");
1270 vty_out(vty
, "Prefix Options: xxx\n");
1274 json_object_int_add(json_route
, "metricType",
1275 route
->path
.metric_type
);
1276 json_object_int_add(json_route
, "metricCost", route
->path
.cost
);
1277 json_object_int_add(json_route
, "metricCostE2",
1278 route
->path
.u
.cost_e2
);
1280 json_object_int_add(json_route
, "pathsCount",
1281 route
->paths
->count
);
1282 json_object_int_add(json_route
, "nextHopCount",
1283 route
->nh_list
->count
);
1285 vty_out(vty
, "Metric Type: %d\n", route
->path
.metric_type
);
1286 vty_out(vty
, "Metric: %d (%d)\n", route
->path
.cost
,
1287 route
->path
.u
.cost_e2
);
1289 vty_out(vty
, "Paths count: %u\n", route
->paths
->count
);
1290 vty_out(vty
, "Nexthop count: %u\n", route
->nh_list
->count
);
1295 json_array_next_hops
= json_object_new_array();
1297 vty_out(vty
, "Nexthop:\n");
1299 for (ALL_LIST_ELEMENTS_RO(route
->nh_list
, node
, nh
)) {
1300 struct interface
*ifp
;
1301 ifp
= if_lookup_by_index_all_vrf(nh
->ifindex
);
1304 inet_ntop(AF_INET6
, &nh
->address
, nexthop
,
1306 json_next_hop
= json_object_new_object();
1307 json_object_string_add(json_next_hop
, "nextHop",
1309 json_object_string_add(json_next_hop
, "interfaceName",
1311 json_object_array_add(json_array_next_hops
,
1314 vty_out(vty
, " %pI6 %.*s\n", &nh
->address
, IFNAMSIZ
,
1318 json_object_object_add(json_route
, "nextHops",
1319 json_array_next_hops
);
1320 json_object_object_add(json_routes
, destination
, json_route
);
1325 static void ospf6_route_show_table_summary(struct vty
*vty
,
1326 struct ospf6_route_table
*table
,
1327 json_object
*json
, bool use_json
)
1329 struct ospf6_route
*route
, *prev
= NULL
;
1330 int i
, pathtype
[OSPF6_PATH_TYPE_MAX
];
1331 unsigned int number
= 0;
1332 int nh_count
= 0, nhinval
= 0, ecmp
= 0;
1333 int alternative
= 0, destination
= 0;
1336 for (i
= 0; i
< OSPF6_PATH_TYPE_MAX
; i
++)
1339 for (route
= ospf6_route_head(table
); route
;
1340 route
= ospf6_route_next(route
)) {
1341 if (prev
== NULL
|| !ospf6_route_is_same(prev
, route
))
1345 nh_count
= ospf6_num_nexthops(route
->nh_list
);
1348 else if (nh_count
> 1)
1350 pathtype
[route
->path
.type
]++;
1356 assert(number
== table
->count
);
1358 json_object_int_add(json
, "numberOfOspfv3Routes", number
);
1359 json_object_int_add(json
, "numberOfDestination", destination
);
1360 json_object_int_add(json
, "numberOfAlternativeRoutes",
1362 json_object_int_add(json
, "numberOfEcmp", ecmp
);
1364 vty_out(vty
, "Number of OSPFv3 routes: %d\n", number
);
1365 vty_out(vty
, "Number of Destination: %d\n", destination
);
1366 vty_out(vty
, "Number of Alternative routes: %d\n", alternative
);
1367 vty_out(vty
, "Number of Equal Cost Multi Path: %d\n", ecmp
);
1369 for (i
= OSPF6_PATH_TYPE_INTRA
; i
<= OSPF6_PATH_TYPE_EXTERNAL2
; i
++) {
1371 snprintf(path_str
, sizeof(path_str
), "numberOf%sRoutes",
1372 OSPF6_PATH_TYPE_JSON(i
));
1373 json_object_int_add(json
, path_str
, pathtype
[i
]);
1375 vty_out(vty
, "Number of %s routes: %d\n",
1376 OSPF6_PATH_TYPE_NAME(i
), pathtype
[i
]);
1380 static void ospf6_route_show_table_prefix(struct vty
*vty
,
1381 struct prefix
*prefix
,
1382 struct ospf6_route_table
*table
,
1383 json_object
*json
, bool use_json
)
1385 struct ospf6_route
*route
;
1386 json_object
*json_routes
= NULL
;
1388 route
= ospf6_route_lookup(prefix
, table
);
1393 json_routes
= json_object_new_object();
1394 ospf6_route_lock(route
);
1395 while (route
&& ospf6_route_is_prefix(prefix
, route
)) {
1396 /* Specifying a prefix will always display details */
1397 ospf6_route_show_detail(vty
, route
, json_routes
, use_json
);
1398 route
= ospf6_route_next(route
);
1402 json_object_object_add(json
, "routes", json_routes
);
1404 ospf6_route_unlock(route
);
1407 static void ospf6_route_show_table_address(struct vty
*vty
,
1408 struct prefix
*prefix
,
1409 struct ospf6_route_table
*table
,
1410 json_object
*json
, bool use_json
)
1412 struct ospf6_route
*route
;
1413 json_object
*json_routes
= NULL
;
1415 route
= ospf6_route_lookup_bestmatch(prefix
, table
);
1420 json_routes
= json_object_new_object();
1421 prefix
= &route
->prefix
;
1422 ospf6_route_lock(route
);
1423 while (route
&& ospf6_route_is_prefix(prefix
, route
)) {
1424 /* Specifying a prefix will always display details */
1425 ospf6_route_show_detail(vty
, route
, json_routes
, use_json
);
1426 route
= ospf6_route_next(route
);
1429 json_object_object_add(json
, "routes", json_routes
);
1431 ospf6_route_unlock(route
);
1434 static void ospf6_route_show_table_match(struct vty
*vty
, int detail
,
1435 struct prefix
*prefix
,
1436 struct ospf6_route_table
*table
,
1437 json_object
*json
, bool use_json
)
1439 struct ospf6_route
*route
;
1440 json_object
*json_routes
= NULL
;
1442 assert(prefix
->family
);
1444 route
= ospf6_route_match_head(prefix
, table
);
1446 json_routes
= json_object_new_object();
1449 ospf6_route_show_detail(vty
, route
, json_routes
,
1452 ospf6_route_show(vty
, route
, json_routes
, use_json
);
1453 route
= ospf6_route_match_next(prefix
, route
);
1456 json_object_object_add(json
, "routes", json_routes
);
1459 static void ospf6_route_show_table_type(struct vty
*vty
, int detail
,
1461 struct ospf6_route_table
*table
,
1462 json_object
*json
, bool use_json
)
1464 struct ospf6_route
*route
;
1465 json_object
*json_routes
= NULL
;
1467 route
= ospf6_route_head(table
);
1469 json_routes
= json_object_new_object();
1471 if (route
->path
.type
== type
) {
1473 ospf6_route_show_detail(vty
, route
, json_routes
,
1476 ospf6_route_show(vty
, route
, json_routes
,
1479 route
= ospf6_route_next(route
);
1482 json_object_object_add(json
, "routes", json_routes
);
1485 static void ospf6_route_show_table(struct vty
*vty
, int detail
,
1486 struct ospf6_route_table
*table
,
1487 json_object
*json
, bool use_json
)
1489 struct ospf6_route
*route
;
1490 json_object
*json_routes
= NULL
;
1492 route
= ospf6_route_head(table
);
1494 json_routes
= json_object_new_object();
1497 ospf6_route_show_detail(vty
, route
, json_routes
,
1500 ospf6_route_show(vty
, route
, json_routes
, use_json
);
1501 route
= ospf6_route_next(route
);
1504 json_object_object_add(json
, "routes", json_routes
);
1507 int ospf6_route_table_show(struct vty
*vty
, int argc_start
, int argc
,
1508 struct cmd_token
**argv
,
1509 struct ospf6_route_table
*table
, bool use_json
)
1517 struct prefix prefix
;
1519 int arg_end
= use_json
? (argc
- 1) : argc
;
1520 json_object
*json
= NULL
;
1522 memset(&prefix
, 0, sizeof(struct prefix
));
1525 json
= json_object_new_object();
1527 for (i
= argc_start
; i
< arg_end
; i
++) {
1528 if (strmatch(argv
[i
]->text
, "summary")) {
1533 if (strmatch(argv
[i
]->text
, "intra-area")) {
1534 type
= OSPF6_PATH_TYPE_INTRA
;
1538 if (strmatch(argv
[i
]->text
, "inter-area")) {
1539 type
= OSPF6_PATH_TYPE_INTER
;
1543 if (strmatch(argv
[i
]->text
, "external-1")) {
1544 type
= OSPF6_PATH_TYPE_EXTERNAL1
;
1548 if (strmatch(argv
[i
]->text
, "external-2")) {
1549 type
= OSPF6_PATH_TYPE_EXTERNAL2
;
1553 if (strmatch(argv
[i
]->text
, "detail")) {
1558 if (strmatch(argv
[i
]->text
, "match")) {
1563 ret
= str2prefix(argv
[i
]->arg
, &prefix
);
1564 if (ret
== 1 && prefix
.family
== AF_INET6
) {
1566 if (strchr(argv
[i
]->arg
, '/'))
1571 json_object_string_add(json
, "malformedArgument",
1574 vty_out(vty
, "Malformed argument: %s\n", argv
[i
]->arg
);
1579 /* Give summary of this route table */
1581 ospf6_route_show_table_summary(vty
, table
, json
, use_json
);
1583 vty_out(vty
, "%s\n",
1584 json_object_to_json_string_ext(
1585 json
, JSON_C_TO_STRING_PRETTY
));
1586 json_object_free(json
);
1591 /* Give exact prefix-match route */
1592 if (isprefix
&& !match
) {
1593 /* If exact address, give best matching route */
1595 ospf6_route_show_table_address(vty
, &prefix
, table
,
1598 ospf6_route_show_table_prefix(vty
, &prefix
, table
, json
,
1602 vty_out(vty
, "%s\n",
1603 json_object_to_json_string_ext(
1604 json
, JSON_C_TO_STRING_PRETTY
));
1605 json_object_free(json
);
1611 ospf6_route_show_table_match(vty
, detail
, &prefix
, table
, json
,
1614 ospf6_route_show_table_type(vty
, detail
, type
, table
, json
,
1617 ospf6_route_show_table(vty
, detail
, table
, json
, use_json
);
1620 vty_out(vty
, "%s\n",
1621 json_object_to_json_string_ext(
1622 json
, JSON_C_TO_STRING_PRETTY
));
1623 json_object_free(json
);
1628 static void ospf6_linkstate_show_header(struct vty
*vty
)
1630 vty_out(vty
, "%-7s %-15s %-15s %-8s %-14s %s\n", "Type", "Router-ID",
1631 "Net-ID", "Rtr-Bits", "Options", "Cost");
1634 static void ospf6_linkstate_show(struct vty
*vty
, struct ospf6_route
*route
)
1636 uint32_t router
, id
;
1637 char routername
[16], idname
[16], rbits
[16], options
[16];
1639 router
= ospf6_linkstate_prefix_adv_router(&route
->prefix
);
1640 inet_ntop(AF_INET
, &router
, routername
, sizeof(routername
));
1641 id
= ospf6_linkstate_prefix_id(&route
->prefix
);
1642 inet_ntop(AF_INET
, &id
, idname
, sizeof(idname
));
1644 ospf6_capability_printbuf(route
->path
.router_bits
, rbits
,
1646 ospf6_options_printbuf(route
->path
.options
, options
, sizeof(options
));
1649 vty_out(vty
, "%-7s %-15s %-15s %-8s %-14s %lu\n", "Network",
1650 routername
, idname
, rbits
, options
,
1651 (unsigned long)route
->path
.cost
);
1653 vty_out(vty
, "%-7s %-15s %-15s %-8s %-14s %lu\n", "Router",
1654 routername
, idname
, rbits
, options
,
1655 (unsigned long)route
->path
.cost
);
1659 static void ospf6_linkstate_show_table_exact(struct vty
*vty
,
1660 struct prefix
*prefix
,
1661 struct ospf6_route_table
*table
)
1663 struct ospf6_route
*route
;
1665 route
= ospf6_route_lookup(prefix
, table
);
1669 ospf6_route_lock(route
);
1670 while (route
&& ospf6_route_is_prefix(prefix
, route
)) {
1671 /* Specifying a prefix will always display details */
1672 ospf6_route_show_detail(vty
, route
, NULL
, false);
1673 route
= ospf6_route_next(route
);
1676 ospf6_route_unlock(route
);
1679 static void ospf6_linkstate_show_table(struct vty
*vty
, int detail
,
1680 struct ospf6_route_table
*table
)
1682 struct ospf6_route
*route
;
1685 ospf6_linkstate_show_header(vty
);
1687 route
= ospf6_route_head(table
);
1690 ospf6_route_show_detail(vty
, route
, NULL
, false);
1692 ospf6_linkstate_show(vty
, route
);
1693 route
= ospf6_route_next(route
);
1697 int ospf6_linkstate_table_show(struct vty
*vty
, int idx_ipv4
, int argc
,
1698 struct cmd_token
**argv
,
1699 struct ospf6_route_table
*table
)
1705 struct prefix router
, id
, prefix
;
1707 memset(&router
, 0, sizeof(struct prefix
));
1708 memset(&id
, 0, sizeof(struct prefix
));
1709 memset(&prefix
, 0, sizeof(struct prefix
));
1711 for (i
= idx_ipv4
; i
< argc
; i
++) {
1712 if (strmatch(argv
[i
]->text
, "detail")) {
1718 ret
= str2prefix(argv
[i
]->arg
, &router
);
1719 if (ret
== 1 && router
.family
== AF_INET
) {
1723 vty_out(vty
, "Malformed argument: %s\n", argv
[i
]->arg
);
1728 ret
= str2prefix(argv
[i
]->arg
, &id
);
1729 if (ret
== 1 && id
.family
== AF_INET
) {
1733 vty_out(vty
, "Malformed argument: %s\n", argv
[i
]->arg
);
1737 vty_out(vty
, "Malformed argument: %s\n", argv
[i
]->arg
);
1742 ospf6_linkstate_prefix(router
.u
.prefix4
.s_addr
,
1743 id
.u
.prefix4
.s_addr
, &prefix
);
1746 ospf6_linkstate_show_table_exact(vty
, &prefix
, table
);
1748 ospf6_linkstate_show_table(vty
, detail
, table
);
1754 void ospf6_brouter_show_header(struct vty
*vty
)
1756 vty_out(vty
, "%-15s %-8s %-14s %-10s %-15s\n", "Router-ID", "Rtr-Bits",
1757 "Options", "Path-Type", "Area");
1760 void ospf6_brouter_show(struct vty
*vty
, struct ospf6_route
*route
)
1762 uint32_t adv_router
;
1763 char adv
[16], rbits
[16], options
[16], area
[16];
1765 adv_router
= ospf6_linkstate_prefix_adv_router(&route
->prefix
);
1766 inet_ntop(AF_INET
, &adv_router
, adv
, sizeof(adv
));
1767 ospf6_capability_printbuf(route
->path
.router_bits
, rbits
,
1769 ospf6_options_printbuf(route
->path
.options
, options
, sizeof(options
));
1770 inet_ntop(AF_INET
, &route
->path
.area_id
, area
, sizeof(area
));
1772 /* vty_out (vty, "%-15s %-8s %-14s %-10s %-15s\n",
1773 "Router-ID", "Rtr-Bits", "Options", "Path-Type", "Area"); */
1774 vty_out(vty
, "%-15s %-8s %-14s %-10s %-15s\n", adv
, rbits
, options
,
1775 OSPF6_PATH_TYPE_NAME(route
->path
.type
), area
);
1778 DEFUN (debug_ospf6_route
,
1779 debug_ospf6_route_cmd
,
1780 "debug ospf6 route <table|intra-area|inter-area|memory>",
1784 "Debug route table calculation\n"
1785 "Debug intra-area route calculation\n"
1786 "Debug inter-area route calculation\n"
1787 "Debug route memory use\n"
1791 unsigned char level
= 0;
1793 if (!strcmp(argv
[idx_type
]->text
, "table"))
1794 level
= OSPF6_DEBUG_ROUTE_TABLE
;
1795 else if (!strcmp(argv
[idx_type
]->text
, "intra-area"))
1796 level
= OSPF6_DEBUG_ROUTE_INTRA
;
1797 else if (!strcmp(argv
[idx_type
]->text
, "inter-area"))
1798 level
= OSPF6_DEBUG_ROUTE_INTER
;
1799 else if (!strcmp(argv
[idx_type
]->text
, "memory"))
1800 level
= OSPF6_DEBUG_ROUTE_MEMORY
;
1801 OSPF6_DEBUG_ROUTE_ON(level
);
1805 DEFUN (no_debug_ospf6_route
,
1806 no_debug_ospf6_route_cmd
,
1807 "no debug ospf6 route <table|intra-area|inter-area|memory>",
1812 "Debug route table calculation\n"
1813 "Debug intra-area route calculation\n"
1814 "Debug inter-area route calculation\n"
1815 "Debug route memory use\n")
1818 unsigned char level
= 0;
1820 if (!strcmp(argv
[idx_type
]->text
, "table"))
1821 level
= OSPF6_DEBUG_ROUTE_TABLE
;
1822 else if (!strcmp(argv
[idx_type
]->text
, "intra-area"))
1823 level
= OSPF6_DEBUG_ROUTE_INTRA
;
1824 else if (!strcmp(argv
[idx_type
]->text
, "inter-area"))
1825 level
= OSPF6_DEBUG_ROUTE_INTER
;
1826 else if (!strcmp(argv
[idx_type
]->text
, "memory"))
1827 level
= OSPF6_DEBUG_ROUTE_MEMORY
;
1828 OSPF6_DEBUG_ROUTE_OFF(level
);
1832 int config_write_ospf6_debug_route(struct vty
*vty
)
1834 if (IS_OSPF6_DEBUG_ROUTE(TABLE
))
1835 vty_out(vty
, "debug ospf6 route table\n");
1836 if (IS_OSPF6_DEBUG_ROUTE(INTRA
))
1837 vty_out(vty
, "debug ospf6 route intra-area\n");
1838 if (IS_OSPF6_DEBUG_ROUTE(INTER
))
1839 vty_out(vty
, "debug ospf6 route inter-area\n");
1840 if (IS_OSPF6_DEBUG_ROUTE(MEMORY
))
1841 vty_out(vty
, "debug ospf6 route memory\n");
1846 void install_element_ospf6_debug_route(void)
1848 install_element(ENABLE_NODE
, &debug_ospf6_route_cmd
);
1849 install_element(ENABLE_NODE
, &no_debug_ospf6_route_cmd
);
1850 install_element(CONFIG_NODE
, &debug_ospf6_route_cmd
);
1851 install_element(CONFIG_NODE
, &no_debug_ospf6_route_cmd
);