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 unsigned char conf_debug_ospf6_route
= 0;
43 static char *ospf6_route_table_name(struct ospf6_route_table
*table
)
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");
52 case OSPF6_TABLE_TYPE_BORDER_ROUTERS
:
53 snprintf(name
, sizeof(name
), "global brouter table");
55 case OSPF6_TABLE_TYPE_EXTERNAL_ROUTES
:
56 snprintf(name
, sizeof(name
), "global external table");
59 snprintf(name
, sizeof(name
), "global unknown table");
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",
71 case OSPF6_TABLE_TYPE_ROUTES
:
72 snprintf(name
, sizeof(name
), "area %s route table",
75 case OSPF6_TABLE_TYPE_PREFIX_RANGES
:
76 snprintf(name
, sizeof(name
), "area %s range table",
79 case OSPF6_TABLE_TYPE_SUMMARY_PREFIXES
:
80 snprintf(name
, sizeof(name
),
81 "area %s summary prefix table", oa
->name
);
83 case OSPF6_TABLE_TYPE_SUMMARY_ROUTERS
:
84 snprintf(name
, sizeof(name
),
85 "area %s summary router table", oa
->name
);
88 snprintf(name
, sizeof(name
), "area %s unknown table",
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
);
104 snprintf(name
, sizeof(name
),
105 "interface %s unknown table",
106 oi
->interface
->name
);
112 switch (table
->table_type
) {
113 case OSPF6_TABLE_TYPE_SPF_RESULTS
:
114 snprintf(name
, sizeof(name
), "temporary spf table");
117 snprintf(name
, sizeof(name
), "temporary unknown table");
125 void ospf6_linkstate_prefix(uint32_t adv_router
, uint32_t id
,
126 struct prefix
*prefix
)
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);
135 void ospf6_linkstate_prefix2str(struct prefix
*prefix
, char *buf
, int size
)
137 uint32_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
));
144 snprintf(buf
, size
, "%s Net-ID: %s", adv_router_str
, id_str
);
146 snprintf(buf
, size
, "%s", adv_router_str
);
149 /* Global strings for logging */
150 const char *const ospf6_dest_type_str
[OSPF6_DEST_TYPE_MAX
] = {
151 "Unknown", "Router", "Network", "Discard", "Linkstate", "AddressRange",
154 const char *const ospf6_dest_type_substr
[OSPF6_DEST_TYPE_MAX
] = {
155 "?", "R", "N", "D", "L", "A",
158 const char *const ospf6_path_type_str
[OSPF6_PATH_TYPE_MAX
] = {
159 "Unknown", "Intra-Area", "Inter-Area", "External-1", "External-2",
162 const char *const ospf6_path_type_substr
[OSPF6_PATH_TYPE_MAX
] = {
163 "??", "IA", "IE", "E1", "E2",
166 const char *ospf6_path_type_json
[OSPF6_PATH_TYPE_MAX
] = {
167 "UnknownRoute", "IntraArea", "InterArea", "External1", "External2",
171 struct ospf6_nexthop
*ospf6_nexthop_create(void)
173 struct ospf6_nexthop
*nh
;
175 nh
= XCALLOC(MTYPE_OSPF6_NEXTHOP
, sizeof(struct ospf6_nexthop
));
179 void ospf6_nexthop_delete(struct ospf6_nexthop
*nh
)
181 XFREE(MTYPE_OSPF6_NEXTHOP
, nh
);
184 void ospf6_clear_nexthops(struct list
*nh_list
)
186 struct listnode
*node
;
187 struct ospf6_nexthop
*nh
;
190 for (ALL_LIST_ELEMENTS_RO(nh_list
, node
, nh
))
191 ospf6_nexthop_clear(nh
);
195 static struct ospf6_nexthop
*
196 ospf6_route_find_nexthop(struct list
*nh_list
, struct ospf6_nexthop
*nh_match
)
198 struct listnode
*node
;
199 struct ospf6_nexthop
*nh
;
201 if (nh_list
&& nh_match
) {
202 for (ALL_LIST_ELEMENTS_RO(nh_list
, node
, nh
)) {
203 if (ospf6_nexthop_is_same(nh
, nh_match
))
211 void ospf6_copy_nexthops(struct list
*dst
, struct list
*src
)
213 struct ospf6_nexthop
*nh_new
, *nh
;
214 struct listnode
*node
;
217 for (ALL_LIST_ELEMENTS_RO(src
, node
, nh
)) {
218 if (ospf6_nexthop_is_set(nh
)) {
219 nh_new
= ospf6_nexthop_create();
220 ospf6_nexthop_copy(nh_new
, nh
);
221 listnode_add_sort(dst
, nh_new
);
227 void ospf6_merge_nexthops(struct list
*dst
, struct list
*src
)
229 struct listnode
*node
;
230 struct ospf6_nexthop
*nh
, *nh_new
;
233 for (ALL_LIST_ELEMENTS_RO(src
, node
, nh
)) {
234 if (!ospf6_route_find_nexthop(dst
, nh
)) {
235 nh_new
= ospf6_nexthop_create();
236 ospf6_nexthop_copy(nh_new
, nh
);
237 listnode_add_sort(dst
, nh_new
);
243 int ospf6_route_cmp_nexthops(struct ospf6_route
*a
, struct ospf6_route
*b
)
245 struct listnode
*anode
, *bnode
;
246 struct ospf6_nexthop
*anh
, *bnh
;
247 bool identical
= false;
250 if (listcount(a
->nh_list
) == listcount(b
->nh_list
)) {
251 for (ALL_LIST_ELEMENTS_RO(a
->nh_list
, anode
, anh
)) {
253 for (ALL_LIST_ELEMENTS_RO(b
->nh_list
, bnode
,
255 if (ospf6_nexthop_is_same(anh
, bnh
))
258 /* Currnet List A element not found List B
259 * Non-Identical lists return */
260 if (identical
== false)
267 /* One of the routes doesn't exist ? */
271 int ospf6_num_nexthops(struct list
*nh_list
)
273 return (listcount(nh_list
));
276 void ospf6_add_nexthop(struct list
*nh_list
, int ifindex
, struct in6_addr
*addr
)
278 struct ospf6_nexthop
*nh
;
279 struct ospf6_nexthop nh_match
;
282 nh_match
.ifindex
= ifindex
;
284 memcpy(&nh_match
.address
, addr
,
285 sizeof(struct in6_addr
));
287 memset(&nh_match
.address
, 0, sizeof(struct in6_addr
));
289 if (!ospf6_route_find_nexthop(nh_list
, &nh_match
)) {
290 nh
= ospf6_nexthop_create();
291 ospf6_nexthop_copy(nh
, &nh_match
);
292 listnode_add(nh_list
, nh
);
297 void ospf6_route_zebra_copy_nexthops(struct ospf6_route
*route
,
298 struct zapi_nexthop nexthops
[],
299 int entries
, vrf_id_t vrf_id
)
301 struct ospf6_nexthop
*nh
;
302 struct listnode
*node
;
308 for (ALL_LIST_ELEMENTS_RO(route
->nh_list
, node
, nh
)) {
309 if (IS_OSPF6_DEBUG_ZEBRA(SEND
)) {
311 inet_ntop(AF_INET6
, &nh
->address
, buf
,
313 ifname
= ifindex2ifname(nh
->ifindex
, vrf_id
);
314 zlog_debug(" nexthop: %s%%%.*s(%d)", buf
,
315 IFNAMSIZ
, ifname
, nh
->ifindex
);
320 nexthops
[i
].vrf_id
= vrf_id
;
321 nexthops
[i
].ifindex
= nh
->ifindex
;
322 if (!IN6_IS_ADDR_UNSPECIFIED(&nh
->address
)) {
323 nexthops
[i
].gate
.ipv6
= nh
->address
;
324 nexthops
[i
].type
= NEXTHOP_TYPE_IPV6_IFINDEX
;
326 nexthops
[i
].type
= NEXTHOP_TYPE_IFINDEX
;
332 int ospf6_route_get_first_nh_index(struct ospf6_route
*route
)
334 struct ospf6_nexthop
*nh
;
337 nh
= listnode_head(route
->nh_list
);
345 int ospf6_nexthop_cmp(struct ospf6_nexthop
*a
, struct ospf6_nexthop
*b
)
347 if (a
->ifindex
< b
->ifindex
)
349 else if (a
->ifindex
> b
->ifindex
)
352 return memcmp(&a
->address
, &b
->address
,
353 sizeof(struct in6_addr
));
358 static int ospf6_path_cmp(struct ospf6_path
*a
, struct ospf6_path
*b
)
360 if (a
->origin
.adv_router
< b
->origin
.adv_router
)
362 else if (a
->origin
.adv_router
> b
->origin
.adv_router
)
368 void ospf6_path_free(struct ospf6_path
*op
)
371 list_delete(&op
->nh_list
);
372 XFREE(MTYPE_OSPF6_PATH
, op
);
375 struct ospf6_path
*ospf6_path_dup(struct ospf6_path
*path
)
377 struct ospf6_path
*new;
379 new = XCALLOC(MTYPE_OSPF6_PATH
, sizeof(struct ospf6_path
));
380 memcpy(new, path
, sizeof(struct ospf6_path
));
381 new->nh_list
= list_new();
382 new->nh_list
->cmp
= (int (*)(void *, void *))ospf6_nexthop_cmp
;
383 new->nh_list
->del
= (void (*)(void *))ospf6_nexthop_delete
;
388 void ospf6_copy_paths(struct list
*dst
, struct list
*src
)
390 struct ospf6_path
*path_new
, *path
;
391 struct listnode
*node
;
394 for (ALL_LIST_ELEMENTS_RO(src
, node
, path
)) {
395 path_new
= ospf6_path_dup(path
);
396 ospf6_copy_nexthops(path_new
->nh_list
, path
->nh_list
);
397 listnode_add_sort(dst
, path_new
);
402 struct ospf6_route
*ospf6_route_create(void)
404 struct ospf6_route
*route
;
406 route
= XCALLOC(MTYPE_OSPF6_ROUTE
, sizeof(struct ospf6_route
));
407 route
->nh_list
= list_new();
408 route
->nh_list
->cmp
= (int (*)(void *, void *))ospf6_nexthop_cmp
;
409 route
->nh_list
->del
= (void (*)(void *))ospf6_nexthop_delete
;
410 route
->paths
= list_new();
411 route
->paths
->cmp
= (int (*)(void *, void *))ospf6_path_cmp
;
412 route
->paths
->del
= (void (*)(void *))ospf6_path_free
;
416 void ospf6_route_delete(struct ospf6_route
*route
)
420 list_delete(&route
->nh_list
);
422 list_delete(&route
->paths
);
423 XFREE(MTYPE_OSPF6_ROUTE
, route
);
427 struct ospf6_route
*ospf6_route_copy(struct ospf6_route
*route
)
429 struct ospf6_route
*new;
431 new = ospf6_route_create();
432 new->type
= route
->type
;
433 memcpy(&new->prefix
, &route
->prefix
, sizeof(struct prefix
));
434 new->installed
= route
->installed
;
435 new->changed
= route
->changed
;
436 new->flag
= route
->flag
;
437 new->route_option
= route
->route_option
;
438 new->linkstate_id
= route
->linkstate_id
;
439 new->path
= route
->path
;
440 ospf6_copy_nexthops(new->nh_list
, route
->nh_list
);
441 ospf6_copy_paths(new->paths
, route
->paths
);
450 void ospf6_route_lock(struct ospf6_route
*route
)
455 void ospf6_route_unlock(struct ospf6_route
*route
)
457 assert(route
->lock
> 0);
459 if (route
->lock
== 0) {
460 /* Can't detach from the table until here
461 because ospf6_route_next () will use
462 the 'route->table' pointer for logging */
464 ospf6_route_delete(route
);
468 /* Route compare function. If ra is more preferred, it returns
469 less than 0. If rb is more preferred returns greater than 0.
470 Otherwise (neither one is preferred), returns 0 */
471 int ospf6_route_cmp(struct ospf6_route
*ra
, struct ospf6_route
*rb
)
473 assert(ospf6_route_is_same(ra
, rb
));
474 assert(OSPF6_PATH_TYPE_NONE
< ra
->path
.type
475 && ra
->path
.type
< OSPF6_PATH_TYPE_MAX
);
476 assert(OSPF6_PATH_TYPE_NONE
< rb
->path
.type
477 && rb
->path
.type
< OSPF6_PATH_TYPE_MAX
);
479 if (ra
->type
!= rb
->type
)
480 return (ra
->type
- rb
->type
);
482 if (ra
->path
.type
!= rb
->path
.type
)
483 return (ra
->path
.type
- rb
->path
.type
);
485 if (ra
->path
.type
== OSPF6_PATH_TYPE_EXTERNAL2
) {
486 if (ra
->path
.u
.cost_e2
!= rb
->path
.u
.cost_e2
)
487 return (ra
->path
.u
.cost_e2
- rb
->path
.u
.cost_e2
);
489 return (ra
->path
.cost
- rb
->path
.cost
);
491 if (ra
->path
.cost
!= rb
->path
.cost
)
492 return (ra
->path
.cost
- rb
->path
.cost
);
495 if (ra
->path
.area_id
!= rb
->path
.area_id
)
496 return (ntohl(ra
->path
.area_id
) - ntohl(rb
->path
.area_id
));
501 struct ospf6_route
*ospf6_route_lookup(struct prefix
*prefix
,
502 struct ospf6_route_table
*table
)
504 struct route_node
*node
;
505 struct ospf6_route
*route
;
507 node
= route_node_lookup(table
->table
, prefix
);
511 route
= (struct ospf6_route
*)node
->info
;
512 route_unlock_node(node
); /* to free the lookup lock */
517 ospf6_route_lookup_identical(struct ospf6_route
*route
,
518 struct ospf6_route_table
*table
)
520 struct ospf6_route
*target
;
522 for (target
= ospf6_route_lookup(&route
->prefix
, table
); target
;
523 target
= target
->next
) {
524 if (target
->type
== route
->type
525 && (memcmp(&target
->prefix
, &route
->prefix
,
526 sizeof(struct prefix
))
528 && target
->path
.type
== route
->path
.type
529 && target
->path
.cost
== route
->path
.cost
530 && target
->path
.u
.cost_e2
== route
->path
.u
.cost_e2
531 && ospf6_route_cmp_nexthops(target
, route
) == 0)
538 ospf6_route_lookup_bestmatch(struct prefix
*prefix
,
539 struct ospf6_route_table
*table
)
541 struct route_node
*node
;
542 struct ospf6_route
*route
;
544 node
= route_node_match(table
->table
, prefix
);
547 route_unlock_node(node
);
549 route
= (struct ospf6_route
*)node
->info
;
554 static void route_table_assert(struct ospf6_route_table
*table
)
556 struct ospf6_route
*prev
, *r
, *next
;
557 unsigned int link_error
= 0, num
= 0;
559 r
= ospf6_route_head(table
);
565 next
= ospf6_route_next(r
);
574 for (r
= ospf6_route_head(table
); r
; r
= ospf6_route_next(r
))
577 if (link_error
== 0 && num
== table
->count
)
580 flog_err(EC_LIB_DEVELOPMENT
, "PANIC !!");
581 flog_err(EC_LIB_DEVELOPMENT
,
582 "Something has gone wrong with ospf6_route_table[%p]", table
);
583 zlog_debug("table count = %d, real number = %d", table
->count
, num
);
584 zlog_debug("DUMP START");
585 for (r
= ospf6_route_head(table
); r
; r
= ospf6_route_next(r
))
586 zlog_info("%p<-[%p]->%p : %pFX", r
->prev
, r
, r
->next
,
588 zlog_debug("DUMP END");
590 assert(link_error
== 0 && num
== table
->count
);
592 #define ospf6_route_table_assert(t) (route_table_assert (t))
594 #define ospf6_route_table_assert(t) ((void) 0)
597 struct ospf6_route
*ospf6_route_add(struct ospf6_route
*route
,
598 struct ospf6_route_table
*table
)
600 struct route_node
*node
, *nextnode
, *prevnode
;
601 struct ospf6_route
*current
= NULL
;
602 struct ospf6_route
*prev
= NULL
, *old
= NULL
, *next
= NULL
;
603 char buf
[PREFIX2STR_BUFFER
];
606 assert(route
->rnode
== NULL
);
607 assert(route
->lock
== 0);
608 assert(route
->next
== NULL
);
609 assert(route
->prev
== NULL
);
611 if (route
->type
== OSPF6_DEST_TYPE_LINKSTATE
)
612 ospf6_linkstate_prefix2str(&route
->prefix
, buf
, sizeof(buf
));
614 prefix2str(&route
->prefix
, buf
, sizeof(buf
));
616 if (IS_OSPF6_DEBUG_ROUTE(MEMORY
))
617 zlog_debug("%s %p: route add %p: %s paths %u nh %u",
618 ospf6_route_table_name(table
), (void *)table
,
619 (void *)route
, buf
, listcount(route
->paths
),
620 listcount(route
->nh_list
));
621 else if (IS_OSPF6_DEBUG_ROUTE(TABLE
))
622 zlog_debug("%s: route add: %s", ospf6_route_table_name(table
),
627 node
= route_node_get(table
->table
, &route
->prefix
);
630 /* find place to insert */
631 for (current
= node
->info
; current
; current
= current
->next
) {
632 if (!ospf6_route_is_same(current
, route
))
634 else if (current
->type
!= route
->type
)
636 else if (ospf6_route_is_same_origin(current
, route
))
638 else if (ospf6_route_cmp(current
, route
) > 0)
648 /* if route does not actually change, return unchanged */
649 if (ospf6_route_is_identical(old
, route
)) {
650 if (IS_OSPF6_DEBUG_ROUTE(MEMORY
))
652 "%s %p: route add %p: needless update of %p old cost %u",
653 ospf6_route_table_name(table
),
654 (void *)table
, (void *)route
,
655 (void *)old
, old
->path
.cost
);
656 else if (IS_OSPF6_DEBUG_ROUTE(TABLE
))
657 zlog_debug("%s: route add: needless update",
658 ospf6_route_table_name(table
));
660 ospf6_route_delete(route
);
661 SET_FLAG(old
->flag
, OSPF6_ROUTE_ADD
);
662 ospf6_route_table_assert(table
);
664 /* to free the lookup lock */
665 route_unlock_node(node
);
669 if (IS_OSPF6_DEBUG_ROUTE(MEMORY
))
671 "%s %p: route add %p cost %u paths %u nh %u: update of %p cost %u paths %u nh %u",
672 ospf6_route_table_name(table
), (void *)table
,
673 (void *)route
, route
->path
.cost
,
674 listcount(route
->paths
),
675 listcount(route
->nh_list
), (void *)old
,
676 old
->path
.cost
, listcount(old
->paths
),
677 listcount(old
->nh_list
));
678 else if (IS_OSPF6_DEBUG_ROUTE(TABLE
))
679 zlog_debug("%s: route add: update",
680 ospf6_route_table_name(table
));
682 /* replace old one if exists */
683 if (node
->info
== old
) {
685 SET_FLAG(route
->flag
, OSPF6_ROUTE_BEST
);
689 old
->prev
->next
= route
;
690 route
->prev
= old
->prev
;
692 old
->next
->prev
= route
;
693 route
->next
= old
->next
;
695 route
->installed
= old
->installed
;
696 route
->changed
= now
;
697 assert(route
->table
== NULL
);
698 route
->table
= table
;
700 ospf6_route_unlock(old
); /* will be deleted later */
701 ospf6_route_lock(route
);
703 SET_FLAG(route
->flag
, OSPF6_ROUTE_CHANGE
);
704 ospf6_route_table_assert(table
);
707 (*table
->hook_add
)(route
);
712 /* insert if previous or next node found */
714 if (IS_OSPF6_DEBUG_ROUTE(MEMORY
))
716 "%s %p: route add %p cost %u: another path: prev %p, next %p node ref %u",
717 ospf6_route_table_name(table
), (void *)table
,
718 (void *)route
, route
->path
.cost
, (void *)prev
,
719 (void *)next
, route_node_get_lock_count(node
));
720 else if (IS_OSPF6_DEBUG_ROUTE(TABLE
))
721 zlog_debug("%s: route add cost %u: another path found",
722 ospf6_route_table_name(table
),
737 if (node
->info
== next
) {
738 assert(next
&& next
->rnode
== node
);
740 UNSET_FLAG(next
->flag
, OSPF6_ROUTE_BEST
);
741 SET_FLAG(route
->flag
, OSPF6_ROUTE_BEST
);
742 if (IS_OSPF6_DEBUG_ROUTE(MEMORY
))
744 "%s %p: route add %p cost %u: replacing previous best: %p cost %u",
745 ospf6_route_table_name(table
),
746 (void *)table
, (void *)route
,
748 (void *)next
, next
->path
.cost
);
751 route
->installed
= now
;
752 route
->changed
= now
;
753 assert(route
->table
== NULL
);
754 route
->table
= table
;
756 ospf6_route_lock(route
);
758 ospf6_route_table_assert(table
);
760 SET_FLAG(route
->flag
, OSPF6_ROUTE_ADD
);
762 (*table
->hook_add
)(route
);
767 /* Else, this is the brand new route regarding to the prefix */
768 if (IS_OSPF6_DEBUG_ROUTE(MEMORY
))
769 zlog_debug("%s %p: route add %p %s cost %u: brand new route",
770 ospf6_route_table_name(table
), (void *)table
,
771 (void *)route
, buf
, route
->path
.cost
);
772 else if (IS_OSPF6_DEBUG_ROUTE(TABLE
))
773 zlog_debug("%s: route add: brand new route",
774 ospf6_route_table_name(table
));
776 assert(node
->info
== NULL
);
778 SET_FLAG(route
->flag
, OSPF6_ROUTE_BEST
);
779 ospf6_route_lock(route
);
780 route
->installed
= now
;
781 route
->changed
= now
;
782 assert(route
->table
== NULL
);
783 route
->table
= table
;
785 /* lookup real existing next route */
787 route_lock_node(nextnode
);
789 nextnode
= route_next(nextnode
);
790 } while (nextnode
&& nextnode
->info
== NULL
);
793 if (nextnode
== NULL
)
796 route_unlock_node(nextnode
);
798 next
= nextnode
->info
;
803 /* lookup real existing prev route */
805 route_lock_node(prevnode
);
807 prevnode
= route_prev(prevnode
);
808 } while (prevnode
&& prevnode
->info
== NULL
);
811 if (prevnode
== NULL
)
814 route_unlock_node(prevnode
);
816 prev
= prevnode
->info
;
817 while (prev
->next
&& ospf6_route_is_same(prev
, prev
->next
))
824 ospf6_route_table_assert(table
);
826 SET_FLAG(route
->flag
, OSPF6_ROUTE_ADD
);
828 (*table
->hook_add
)(route
);
833 void ospf6_route_remove(struct ospf6_route
*route
,
834 struct ospf6_route_table
*table
)
836 struct route_node
*node
;
837 struct ospf6_route
*current
;
838 char buf
[PREFIX2STR_BUFFER
];
840 if (route
->type
== OSPF6_DEST_TYPE_LINKSTATE
)
841 ospf6_linkstate_prefix2str(&route
->prefix
, buf
, sizeof(buf
));
843 prefix2str(&route
->prefix
, buf
, sizeof(buf
));
845 if (IS_OSPF6_DEBUG_ROUTE(MEMORY
))
846 zlog_debug("%s %p: route remove %p: %s cost %u refcount %u",
847 ospf6_route_table_name(table
), (void *)table
,
848 (void *)route
, buf
, route
->path
.cost
, route
->lock
);
849 else if (IS_OSPF6_DEBUG_ROUTE(TABLE
))
850 zlog_debug("%s: route remove: %s",
851 ospf6_route_table_name(table
), buf
);
853 node
= route_node_lookup(table
->table
, &route
->prefix
);
856 /* find the route to remove, making sure that the route pointer
857 is from the route table. */
858 current
= node
->info
;
859 while (current
&& current
!= route
)
860 current
= current
->next
;
862 assert(current
== route
);
864 /* adjust doubly linked list */
866 route
->prev
->next
= route
->next
;
868 route
->next
->prev
= route
->prev
;
870 if (node
->info
== route
) {
871 if (route
->next
&& route
->next
->rnode
== node
) {
872 node
->info
= route
->next
;
873 SET_FLAG(route
->next
->flag
, OSPF6_ROUTE_BEST
);
877 route_unlock_node(node
); /* to free the original lock */
881 route_unlock_node(node
); /* to free the lookup lock */
883 ospf6_route_table_assert(table
);
885 SET_FLAG(route
->flag
, OSPF6_ROUTE_WAS_REMOVED
);
887 /* Note hook_remove may call ospf6_route_remove */
888 if (table
->hook_remove
)
889 (*table
->hook_remove
)(route
);
891 ospf6_route_unlock(route
);
894 struct ospf6_route
*ospf6_route_head(struct ospf6_route_table
*table
)
896 struct route_node
*node
;
897 struct ospf6_route
*route
;
899 node
= route_top(table
->table
);
903 /* skip to the real existing entry */
904 while (node
&& node
->info
== NULL
)
905 node
= route_next(node
);
909 route_unlock_node(node
);
912 route
= (struct ospf6_route
*)node
->info
;
913 assert(route
->prev
== NULL
);
914 assert(route
->table
== table
);
915 ospf6_route_lock(route
);
917 if (IS_OSPF6_DEBUG_ROUTE(MEMORY
))
918 zlog_info("%s %p: route head: %p<-[%p]->%p",
919 ospf6_route_table_name(table
), (void *)table
,
920 (void *)route
->prev
, (void *)route
,
921 (void *)route
->next
);
926 struct ospf6_route
*ospf6_route_next(struct ospf6_route
*route
)
928 struct ospf6_route
*next
= route
->next
;
930 if (IS_OSPF6_DEBUG_ROUTE(MEMORY
))
931 zlog_info("%s %p: route next: %p<-[%p]->%p , route ref count %u",
932 ospf6_route_table_name(route
->table
),
933 (void *)route
->table
, (void *)route
->prev
,
934 (void *)route
, (void *)route
->next
,
937 ospf6_route_unlock(route
);
939 ospf6_route_lock(next
);
944 struct ospf6_route
*ospf6_route_best_next(struct ospf6_route
*route
)
946 struct route_node
*rnode
;
947 struct ospf6_route
*next
;
949 ospf6_route_unlock(route
);
951 rnode
= route
->rnode
;
952 route_lock_node(rnode
);
953 rnode
= route_next(rnode
);
954 while (rnode
&& rnode
->info
== NULL
)
955 rnode
= route_next(rnode
);
958 route_unlock_node(rnode
);
961 next
= (struct ospf6_route
*)rnode
->info
;
962 ospf6_route_lock(next
);
966 struct ospf6_route
*ospf6_route_match_head(struct prefix
*prefix
,
967 struct ospf6_route_table
*table
)
969 struct route_node
*node
;
970 struct ospf6_route
*route
;
972 /* Walk down tree. */
973 node
= table
->table
->top
;
974 while (node
&& node
->p
.prefixlen
< prefix
->prefixlen
975 && prefix_match(&node
->p
, prefix
))
976 node
= node
->link
[prefix_bit(&prefix
->u
.prefix
,
980 route_lock_node(node
);
981 while (node
&& node
->info
== NULL
)
982 node
= route_next(node
);
985 route_unlock_node(node
);
987 if (!prefix_match(prefix
, &node
->p
))
991 ospf6_route_lock(route
);
995 struct ospf6_route
*ospf6_route_match_next(struct prefix
*prefix
,
996 struct ospf6_route
*route
)
998 struct ospf6_route
*next
;
1000 next
= ospf6_route_next(route
);
1001 if (next
&& !prefix_match(prefix
, &next
->prefix
)) {
1002 ospf6_route_unlock(next
);
1009 void ospf6_route_remove_all(struct ospf6_route_table
*table
)
1011 struct ospf6_route
*route
;
1012 for (route
= ospf6_route_head(table
); route
;
1013 route
= ospf6_route_next(route
))
1014 ospf6_route_remove(route
, table
);
1017 struct ospf6_route_table
*ospf6_route_table_create(int s
, int t
)
1019 struct ospf6_route_table
*new;
1020 new = XCALLOC(MTYPE_OSPF6_ROUTE
, sizeof(struct ospf6_route_table
));
1021 new->table
= route_table_init();
1022 new->scope_type
= s
;
1023 new->table_type
= t
;
1027 void ospf6_route_table_delete(struct ospf6_route_table
*table
)
1029 ospf6_route_remove_all(table
);
1030 bf_free(table
->idspace
);
1031 route_table_finish(table
->table
);
1032 XFREE(MTYPE_OSPF6_ROUTE
, table
);
1037 void ospf6_route_show(struct vty
*vty
, struct ospf6_route
*route
,
1038 json_object
*json_array_routes
, bool use_json
)
1041 char destination
[PREFIX2STR_BUFFER
], nexthop
[64];
1043 struct timeval now
, res
;
1044 struct listnode
*node
;
1045 struct ospf6_nexthop
*nh
;
1046 json_object
*json_route
= NULL
;
1047 json_object
*json_array_next_hops
= NULL
;
1048 json_object
*json_next_hop
;
1050 if (om6
->ospf6
== NULL
) {
1051 vty_out(vty
, "OSPFv3 is not running\n");
1056 timersub(&now
, &route
->changed
, &res
);
1057 timerstring(&res
, duration
, sizeof(duration
));
1060 if (route
->type
== OSPF6_DEST_TYPE_LINKSTATE
)
1061 ospf6_linkstate_prefix2str(&route
->prefix
, destination
,
1062 sizeof(destination
));
1063 else if (route
->type
== OSPF6_DEST_TYPE_ROUTER
)
1064 inet_ntop(route
->prefix
.family
, &route
->prefix
.u
.prefix
,
1065 destination
, sizeof(destination
));
1067 prefix2str(&route
->prefix
, destination
, sizeof(destination
));
1070 json_route
= json_object_new_object();
1071 json_object_string_add(json_route
, "destination", destination
);
1072 json_object_boolean_add(json_route
, "isBestRoute",
1073 ospf6_route_is_best(route
));
1074 json_object_string_add(json_route
, "destinationType",
1075 OSPF6_DEST_TYPE_SUBSTR(route
->type
));
1076 json_object_string_add(
1077 json_route
, "pathType",
1078 OSPF6_PATH_TYPE_SUBSTR(route
->path
.type
));
1079 json_object_string_add(json_route
, "duration", duration
);
1084 json_array_next_hops
= json_object_new_array();
1087 for (ALL_LIST_ELEMENTS_RO(route
->nh_list
, node
, nh
)) {
1088 struct interface
*ifp
;
1090 inet_ntop(AF_INET6
, &nh
->address
, nexthop
, sizeof(nexthop
));
1091 ifp
= if_lookup_by_index_all_vrf(nh
->ifindex
);
1093 json_next_hop
= json_object_new_object();
1094 json_object_string_add(json_next_hop
, "nextHop",
1096 json_object_string_add(json_next_hop
, "interfaceName",
1098 json_object_array_add(json_array_next_hops
,
1102 vty_out(vty
, "%c%1s %2s %-30s %-25s %6.*s %s\n",
1103 (ospf6_route_is_best(route
) ? '*'
1105 OSPF6_DEST_TYPE_SUBSTR(route
->type
),
1106 OSPF6_PATH_TYPE_SUBSTR(
1108 destination
, nexthop
, IFNAMSIZ
,
1109 ifp
->name
, duration
);
1112 vty_out(vty
, "%c%1s %2s %-30s %-25s %6.*s %s\n",
1113 ' ', "", "", "", nexthop
, IFNAMSIZ
,
1118 json_object_object_add(json_route
, "nextHops",
1119 json_array_next_hops
);
1120 json_object_array_add(json_array_routes
, json_route
);
1124 void ospf6_route_show_detail(struct vty
*vty
, struct ospf6_route
*route
,
1125 json_object
*json_array_routes
, bool use_json
)
1127 char destination
[PREFIX2STR_BUFFER
], nexthop
[64];
1128 char area_id
[16], id
[16], adv_router
[16], capa
[16], options
[16];
1129 struct timeval now
, res
;
1131 struct listnode
*node
;
1132 struct ospf6_nexthop
*nh
;
1134 json_object
*json_route
= NULL
;
1135 json_object
*json_array_next_hops
= NULL
;
1136 json_object
*json_next_hop
;
1138 if (om6
->ospf6
== NULL
) {
1139 vty_out(vty
, "OSPFv3 is not running\n");
1146 if (route
->type
== OSPF6_DEST_TYPE_LINKSTATE
)
1147 ospf6_linkstate_prefix2str(&route
->prefix
, destination
,
1148 sizeof(destination
));
1149 else if (route
->type
== OSPF6_DEST_TYPE_ROUTER
)
1150 inet_ntop(route
->prefix
.family
, &route
->prefix
.u
.prefix
,
1151 destination
, sizeof(destination
));
1153 prefix2str(&route
->prefix
, destination
, sizeof(destination
));
1156 json_route
= json_object_new_object();
1157 json_object_string_add(json_route
, "destination", destination
);
1158 json_object_string_add(json_route
, "destinationType",
1159 OSPF6_DEST_TYPE_NAME(route
->type
));
1161 vty_out(vty
, "Destination: %s\n", destination
);
1162 vty_out(vty
, "Destination type: %s\n",
1163 OSPF6_DEST_TYPE_NAME(route
->type
));
1167 timersub(&now
, &route
->installed
, &res
);
1168 timerstring(&res
, duration
, sizeof(duration
));
1170 json_object_string_add(json_route
, "installedTimeSince",
1173 vty_out(vty
, "Installed Time: %s ago\n", duration
);
1175 timersub(&now
, &route
->changed
, &res
);
1176 timerstring(&res
, duration
, sizeof(duration
));
1178 json_object_string_add(json_route
, "changedTimeSince",
1181 vty_out(vty
, "Changed Time: %s ago\n", duration
);
1183 /* Debugging info */
1185 json_object_int_add(json_route
, "numberOfLock", route
->lock
);
1187 flag
, sizeof(flag
), "%s%s%s%s",
1188 (CHECK_FLAG(route
->flag
, OSPF6_ROUTE_BEST
) ? "B" : "-"),
1189 (CHECK_FLAG(route
->flag
, OSPF6_ROUTE_ADD
) ? "A" : "-"),
1190 (CHECK_FLAG(route
->flag
, OSPF6_ROUTE_REMOVE
) ? "R"
1192 (CHECK_FLAG(route
->flag
, OSPF6_ROUTE_CHANGE
) ? "C"
1194 json_object_string_add(json_route
, "flags", flag
);
1196 vty_out(vty
, "Lock: %d Flags: %s%s%s%s\n", route
->lock
,
1197 (CHECK_FLAG(route
->flag
, OSPF6_ROUTE_BEST
) ? "B" : "-"),
1198 (CHECK_FLAG(route
->flag
, OSPF6_ROUTE_ADD
) ? "A" : "-"),
1199 (CHECK_FLAG(route
->flag
, OSPF6_ROUTE_REMOVE
) ? "R"
1201 (CHECK_FLAG(route
->flag
, OSPF6_ROUTE_CHANGE
) ? "C"
1203 vty_out(vty
, "Memory: prev: %p this: %p next: %p\n",
1204 (void *)route
->prev
, (void *)route
,
1205 (void *)route
->next
);
1211 inet_ntop(AF_INET
, &route
->path
.area_id
, area_id
, sizeof(area_id
));
1213 json_object_string_add(json_route
, "associatedArea", area_id
);
1215 vty_out(vty
, "Associated Area: %s\n", area_id
);
1219 json_object_string_add(json_route
, "pathType",
1220 OSPF6_PATH_TYPE_NAME(route
->path
.type
));
1222 vty_out(vty
, "Path Type: %s\n",
1223 OSPF6_PATH_TYPE_NAME(route
->path
.type
));
1226 inet_ntop(AF_INET
, &route
->path
.origin
.id
, id
, sizeof(id
));
1227 inet_ntop(AF_INET
, &route
->path
.origin
.adv_router
, adv_router
,
1228 sizeof(adv_router
));
1230 json_object_string_add(
1231 json_route
, "lsOriginRoutePathType",
1232 ospf6_lstype_name(route
->path
.origin
.type
));
1233 json_object_string_add(json_route
, "lsId", id
);
1234 json_object_string_add(json_route
, "lsAdvertisingRouter",
1237 vty_out(vty
, "LS Origin: %s Id: %s Adv: %s\n",
1238 ospf6_lstype_name(route
->path
.origin
.type
), id
,
1243 ospf6_options_printbuf(route
->path
.options
, options
, sizeof(options
));
1245 json_object_string_add(json_route
, "options", options
);
1247 vty_out(vty
, "Options: %s\n", options
);
1250 ospf6_capability_printbuf(route
->path
.router_bits
, capa
, sizeof(capa
));
1252 json_object_string_add(json_route
, "routerBits", capa
);
1254 vty_out(vty
, "Router Bits: %s\n", capa
);
1256 /* Prefix Options */
1258 json_object_string_add(json_route
, "prefixOptions", "xxx");
1260 vty_out(vty
, "Prefix Options: xxx\n");
1264 json_object_int_add(json_route
, "metricType",
1265 route
->path
.metric_type
);
1266 json_object_int_add(json_route
, "metricCost", route
->path
.cost
);
1267 json_object_int_add(json_route
, "metricCostE2",
1268 route
->path
.u
.cost_e2
);
1270 json_object_int_add(json_route
, "pathsCount",
1271 route
->paths
->count
);
1272 json_object_int_add(json_route
, "nextHopCount",
1273 route
->nh_list
->count
);
1275 vty_out(vty
, "Metric Type: %d\n", route
->path
.metric_type
);
1276 vty_out(vty
, "Metric: %d (%d)\n", route
->path
.cost
,
1277 route
->path
.u
.cost_e2
);
1279 vty_out(vty
, "Paths count: %u\n", route
->paths
->count
);
1280 vty_out(vty
, "Nexthop count: %u\n", route
->nh_list
->count
);
1285 json_array_next_hops
= json_object_new_array();
1287 vty_out(vty
, "Nexthop:\n");
1289 for (ALL_LIST_ELEMENTS_RO(route
->nh_list
, node
, nh
)) {
1290 struct interface
*ifp
;
1291 ifp
= if_lookup_by_index_all_vrf(nh
->ifindex
);
1294 inet_ntop(AF_INET6
, &nh
->address
, nexthop
,
1296 json_next_hop
= json_object_new_object();
1297 json_object_string_add(json_next_hop
, "nextHop",
1299 json_object_string_add(json_next_hop
, "interfaceName",
1301 json_object_array_add(json_array_next_hops
,
1304 vty_out(vty
, " %pI6 %.*s\n", &nh
->address
, IFNAMSIZ
,
1308 json_object_object_add(json_route
, "nextHops",
1309 json_array_next_hops
);
1310 json_object_array_add(json_array_routes
, json_route
);
1315 static void ospf6_route_show_table_summary(struct vty
*vty
,
1316 struct ospf6_route_table
*table
,
1317 json_object
*json
, bool use_json
)
1319 struct ospf6_route
*route
, *prev
= NULL
;
1320 int i
, pathtype
[OSPF6_PATH_TYPE_MAX
];
1321 unsigned int number
= 0;
1322 int nh_count
= 0, nhinval
= 0, ecmp
= 0;
1323 int alternative
= 0, destination
= 0;
1326 for (i
= 0; i
< OSPF6_PATH_TYPE_MAX
; i
++)
1329 for (route
= ospf6_route_head(table
); route
;
1330 route
= ospf6_route_next(route
)) {
1331 if (prev
== NULL
|| !ospf6_route_is_same(prev
, route
))
1335 nh_count
= ospf6_num_nexthops(route
->nh_list
);
1338 else if (nh_count
> 1)
1340 pathtype
[route
->path
.type
]++;
1346 assert(number
== table
->count
);
1348 json_object_int_add(json
, "numberOfOspfv3Routes", number
);
1349 json_object_int_add(json
, "numberOfDestination", destination
);
1350 json_object_int_add(json
, "numberOfAlternativeRoutes",
1352 json_object_int_add(json
, "numberOfEcmp", ecmp
);
1354 vty_out(vty
, "Number of OSPFv3 routes: %d\n", number
);
1355 vty_out(vty
, "Number of Destination: %d\n", destination
);
1356 vty_out(vty
, "Number of Alternative routes: %d\n", alternative
);
1357 vty_out(vty
, "Number of Equal Cost Multi Path: %d\n", ecmp
);
1359 for (i
= OSPF6_PATH_TYPE_INTRA
; i
<= OSPF6_PATH_TYPE_EXTERNAL2
; i
++) {
1361 snprintf(path_str
, sizeof(path_str
), "numberOf%sRoutes",
1362 OSPF6_PATH_TYPE_JSON(i
));
1363 json_object_int_add(json
, path_str
, pathtype
[i
]);
1365 vty_out(vty
, "Number of %s routes: %d\n",
1366 OSPF6_PATH_TYPE_NAME(i
), pathtype
[i
]);
1370 static void ospf6_route_show_table_prefix(struct vty
*vty
,
1371 struct prefix
*prefix
,
1372 struct ospf6_route_table
*table
,
1373 json_object
*json
, bool use_json
)
1375 struct ospf6_route
*route
;
1376 json_object
*json_array_routes
= NULL
;
1378 route
= ospf6_route_lookup(prefix
, table
);
1383 json_array_routes
= json_object_new_array();
1384 ospf6_route_lock(route
);
1385 while (route
&& ospf6_route_is_prefix(prefix
, route
)) {
1386 /* Specifying a prefix will always display details */
1387 ospf6_route_show_detail(vty
, route
, json_array_routes
,
1389 route
= ospf6_route_next(route
);
1393 json_object_object_add(json
, "routes", json_array_routes
);
1395 ospf6_route_unlock(route
);
1398 static void ospf6_route_show_table_address(struct vty
*vty
,
1399 struct prefix
*prefix
,
1400 struct ospf6_route_table
*table
,
1401 json_object
*json
, bool use_json
)
1403 struct ospf6_route
*route
;
1404 json_object
*json_array_routes
= NULL
;
1406 route
= ospf6_route_lookup_bestmatch(prefix
, table
);
1411 json_array_routes
= json_object_new_array();
1412 prefix
= &route
->prefix
;
1413 ospf6_route_lock(route
);
1414 while (route
&& ospf6_route_is_prefix(prefix
, route
)) {
1415 /* Specifying a prefix will always display details */
1416 ospf6_route_show_detail(vty
, route
, json_array_routes
,
1418 route
= ospf6_route_next(route
);
1421 json_object_object_add(json
, "routes", json_array_routes
);
1423 ospf6_route_unlock(route
);
1426 static void ospf6_route_show_table_match(struct vty
*vty
, int detail
,
1427 struct prefix
*prefix
,
1428 struct ospf6_route_table
*table
,
1429 json_object
*json
, bool use_json
)
1431 struct ospf6_route
*route
;
1432 json_object
*json_array_routes
= NULL
;
1434 assert(prefix
->family
);
1436 route
= ospf6_route_match_head(prefix
, table
);
1438 json_array_routes
= json_object_new_array();
1441 ospf6_route_show_detail(vty
, route
, json_array_routes
,
1444 ospf6_route_show(vty
, route
, json_array_routes
,
1446 route
= ospf6_route_match_next(prefix
, route
);
1449 json_object_object_add(json
, "routes", json_array_routes
);
1452 static void ospf6_route_show_table_type(struct vty
*vty
, int detail
,
1454 struct ospf6_route_table
*table
,
1455 json_object
*json
, bool use_json
)
1457 struct ospf6_route
*route
;
1458 json_object
*json_array_routes
= NULL
;
1460 route
= ospf6_route_head(table
);
1462 json_array_routes
= json_object_new_array();
1464 if (route
->path
.type
== type
) {
1466 ospf6_route_show_detail(vty
, route
,
1470 ospf6_route_show(vty
, route
, json_array_routes
,
1473 route
= ospf6_route_next(route
);
1476 json_object_object_add(json
, "routes", json_array_routes
);
1479 static void ospf6_route_show_table(struct vty
*vty
, int detail
,
1480 struct ospf6_route_table
*table
,
1481 json_object
*json
, bool use_json
)
1483 struct ospf6_route
*route
;
1484 json_object
*json_array_routes
= NULL
;
1486 route
= ospf6_route_head(table
);
1488 json_array_routes
= json_object_new_array();
1491 ospf6_route_show_detail(vty
, route
, json_array_routes
,
1494 ospf6_route_show(vty
, route
, json_array_routes
,
1496 route
= ospf6_route_next(route
);
1499 json_object_object_add(json
, "routes", json_array_routes
);
1502 int ospf6_route_table_show(struct vty
*vty
, int argc_start
, int argc
,
1503 struct cmd_token
**argv
,
1504 struct ospf6_route_table
*table
, bool use_json
)
1512 struct prefix prefix
;
1514 int arg_end
= use_json
? (argc
- 1) : argc
;
1515 json_object
*json
= NULL
;
1517 memset(&prefix
, 0, sizeof(struct prefix
));
1520 json
= json_object_new_object();
1522 for (i
= argc_start
; i
< arg_end
; i
++) {
1523 if (strmatch(argv
[i
]->text
, "summary")) {
1528 if (strmatch(argv
[i
]->text
, "intra-area")) {
1529 type
= OSPF6_PATH_TYPE_INTRA
;
1533 if (strmatch(argv
[i
]->text
, "inter-area")) {
1534 type
= OSPF6_PATH_TYPE_INTER
;
1538 if (strmatch(argv
[i
]->text
, "external-1")) {
1539 type
= OSPF6_PATH_TYPE_EXTERNAL1
;
1543 if (strmatch(argv
[i
]->text
, "external-2")) {
1544 type
= OSPF6_PATH_TYPE_EXTERNAL2
;
1548 if (strmatch(argv
[i
]->text
, "detail")) {
1553 if (strmatch(argv
[i
]->text
, "match")) {
1558 ret
= str2prefix(argv
[i
]->arg
, &prefix
);
1559 if (ret
== 1 && prefix
.family
== AF_INET6
) {
1561 if (strchr(argv
[i
]->arg
, '/'))
1566 json_object_string_add(json
, "malformedArgument",
1569 vty_out(vty
, "Malformed argument: %s\n", argv
[i
]->arg
);
1574 /* Give summary of this route table */
1576 ospf6_route_show_table_summary(vty
, table
, json
, use_json
);
1578 vty_out(vty
, "%s\n",
1579 json_object_to_json_string_ext(
1580 json
, JSON_C_TO_STRING_PRETTY
));
1581 json_object_free(json
);
1586 /* Give exact prefix-match route */
1587 if (isprefix
&& !match
) {
1588 /* If exact address, give best matching route */
1590 ospf6_route_show_table_address(vty
, &prefix
, table
,
1593 ospf6_route_show_table_prefix(vty
, &prefix
, table
, json
,
1597 vty_out(vty
, "%s\n",
1598 json_object_to_json_string_ext(
1599 json
, JSON_C_TO_STRING_PRETTY
));
1600 json_object_free(json
);
1606 ospf6_route_show_table_match(vty
, detail
, &prefix
, table
, json
,
1609 ospf6_route_show_table_type(vty
, detail
, type
, table
, json
,
1612 ospf6_route_show_table(vty
, detail
, table
, json
, use_json
);
1615 vty_out(vty
, "%s\n",
1616 json_object_to_json_string_ext(
1617 json
, JSON_C_TO_STRING_PRETTY
));
1618 json_object_free(json
);
1623 static void ospf6_linkstate_show_header(struct vty
*vty
)
1625 vty_out(vty
, "%-7s %-15s %-15s %-8s %-14s %s\n", "Type", "Router-ID",
1626 "Net-ID", "Rtr-Bits", "Options", "Cost");
1629 static void ospf6_linkstate_show(struct vty
*vty
, struct ospf6_route
*route
)
1631 uint32_t router
, id
;
1632 char routername
[16], idname
[16], rbits
[16], options
[16];
1634 router
= ospf6_linkstate_prefix_adv_router(&route
->prefix
);
1635 inet_ntop(AF_INET
, &router
, routername
, sizeof(routername
));
1636 id
= ospf6_linkstate_prefix_id(&route
->prefix
);
1637 inet_ntop(AF_INET
, &id
, idname
, sizeof(idname
));
1639 ospf6_capability_printbuf(route
->path
.router_bits
, rbits
,
1641 ospf6_options_printbuf(route
->path
.options
, options
, sizeof(options
));
1644 vty_out(vty
, "%-7s %-15s %-15s %-8s %-14s %lu\n", "Network",
1645 routername
, idname
, rbits
, options
,
1646 (unsigned long)route
->path
.cost
);
1648 vty_out(vty
, "%-7s %-15s %-15s %-8s %-14s %lu\n", "Router",
1649 routername
, idname
, rbits
, options
,
1650 (unsigned long)route
->path
.cost
);
1654 static void ospf6_linkstate_show_table_exact(struct vty
*vty
,
1655 struct prefix
*prefix
,
1656 struct ospf6_route_table
*table
)
1658 struct ospf6_route
*route
;
1660 route
= ospf6_route_lookup(prefix
, table
);
1664 ospf6_route_lock(route
);
1665 while (route
&& ospf6_route_is_prefix(prefix
, route
)) {
1666 /* Specifying a prefix will always display details */
1667 ospf6_route_show_detail(vty
, route
, NULL
, false);
1668 route
= ospf6_route_next(route
);
1671 ospf6_route_unlock(route
);
1674 static void ospf6_linkstate_show_table(struct vty
*vty
, int detail
,
1675 struct ospf6_route_table
*table
)
1677 struct ospf6_route
*route
;
1680 ospf6_linkstate_show_header(vty
);
1682 route
= ospf6_route_head(table
);
1685 ospf6_route_show_detail(vty
, route
, NULL
, false);
1687 ospf6_linkstate_show(vty
, route
);
1688 route
= ospf6_route_next(route
);
1692 int ospf6_linkstate_table_show(struct vty
*vty
, int idx_ipv4
, int argc
,
1693 struct cmd_token
**argv
,
1694 struct ospf6_route_table
*table
)
1700 struct prefix router
, id
, prefix
;
1702 memset(&router
, 0, sizeof(struct prefix
));
1703 memset(&id
, 0, sizeof(struct prefix
));
1704 memset(&prefix
, 0, sizeof(struct prefix
));
1706 for (i
= idx_ipv4
; i
< argc
; i
++) {
1707 if (strmatch(argv
[i
]->text
, "detail")) {
1713 ret
= str2prefix(argv
[i
]->arg
, &router
);
1714 if (ret
== 1 && router
.family
== AF_INET
) {
1718 vty_out(vty
, "Malformed argument: %s\n", argv
[i
]->arg
);
1723 ret
= str2prefix(argv
[i
]->arg
, &id
);
1724 if (ret
== 1 && id
.family
== AF_INET
) {
1728 vty_out(vty
, "Malformed argument: %s\n", argv
[i
]->arg
);
1732 vty_out(vty
, "Malformed argument: %s\n", argv
[i
]->arg
);
1737 ospf6_linkstate_prefix(router
.u
.prefix4
.s_addr
,
1738 id
.u
.prefix4
.s_addr
, &prefix
);
1741 ospf6_linkstate_show_table_exact(vty
, &prefix
, table
);
1743 ospf6_linkstate_show_table(vty
, detail
, table
);
1749 void ospf6_brouter_show_header(struct vty
*vty
)
1751 vty_out(vty
, "%-15s %-8s %-14s %-10s %-15s\n", "Router-ID", "Rtr-Bits",
1752 "Options", "Path-Type", "Area");
1755 void ospf6_brouter_show(struct vty
*vty
, struct ospf6_route
*route
)
1757 uint32_t adv_router
;
1758 char adv
[16], rbits
[16], options
[16], area
[16];
1760 adv_router
= ospf6_linkstate_prefix_adv_router(&route
->prefix
);
1761 inet_ntop(AF_INET
, &adv_router
, adv
, sizeof(adv
));
1762 ospf6_capability_printbuf(route
->path
.router_bits
, rbits
,
1764 ospf6_options_printbuf(route
->path
.options
, options
, sizeof(options
));
1765 inet_ntop(AF_INET
, &route
->path
.area_id
, area
, sizeof(area
));
1767 /* vty_out (vty, "%-15s %-8s %-14s %-10s %-15s\n",
1768 "Router-ID", "Rtr-Bits", "Options", "Path-Type", "Area"); */
1769 vty_out(vty
, "%-15s %-8s %-14s %-10s %-15s\n", adv
, rbits
, options
,
1770 OSPF6_PATH_TYPE_NAME(route
->path
.type
), area
);
1773 DEFUN (debug_ospf6_route
,
1774 debug_ospf6_route_cmd
,
1775 "debug ospf6 route <table|intra-area|inter-area|memory>",
1779 "Debug route table calculation\n"
1780 "Debug intra-area route calculation\n"
1781 "Debug inter-area route calculation\n"
1782 "Debug route memory use\n"
1786 unsigned char level
= 0;
1788 if (!strcmp(argv
[idx_type
]->text
, "table"))
1789 level
= OSPF6_DEBUG_ROUTE_TABLE
;
1790 else if (!strcmp(argv
[idx_type
]->text
, "intra-area"))
1791 level
= OSPF6_DEBUG_ROUTE_INTRA
;
1792 else if (!strcmp(argv
[idx_type
]->text
, "inter-area"))
1793 level
= OSPF6_DEBUG_ROUTE_INTER
;
1794 else if (!strcmp(argv
[idx_type
]->text
, "memory"))
1795 level
= OSPF6_DEBUG_ROUTE_MEMORY
;
1796 OSPF6_DEBUG_ROUTE_ON(level
);
1800 DEFUN (no_debug_ospf6_route
,
1801 no_debug_ospf6_route_cmd
,
1802 "no debug ospf6 route <table|intra-area|inter-area|memory>",
1807 "Debug route table calculation\n"
1808 "Debug intra-area route calculation\n"
1809 "Debug inter-area route calculation\n"
1810 "Debug route memory use\n")
1813 unsigned char level
= 0;
1815 if (!strcmp(argv
[idx_type
]->text
, "table"))
1816 level
= OSPF6_DEBUG_ROUTE_TABLE
;
1817 else if (!strcmp(argv
[idx_type
]->text
, "intra-area"))
1818 level
= OSPF6_DEBUG_ROUTE_INTRA
;
1819 else if (!strcmp(argv
[idx_type
]->text
, "inter-area"))
1820 level
= OSPF6_DEBUG_ROUTE_INTER
;
1821 else if (!strcmp(argv
[idx_type
]->text
, "memory"))
1822 level
= OSPF6_DEBUG_ROUTE_MEMORY
;
1823 OSPF6_DEBUG_ROUTE_OFF(level
);
1827 int config_write_ospf6_debug_route(struct vty
*vty
)
1829 if (IS_OSPF6_DEBUG_ROUTE(TABLE
))
1830 vty_out(vty
, "debug ospf6 route table\n");
1831 if (IS_OSPF6_DEBUG_ROUTE(INTRA
))
1832 vty_out(vty
, "debug ospf6 route intra-area\n");
1833 if (IS_OSPF6_DEBUG_ROUTE(INTER
))
1834 vty_out(vty
, "debug ospf6 route inter-area\n");
1835 if (IS_OSPF6_DEBUG_ROUTE(MEMORY
))
1836 vty_out(vty
, "debug ospf6 route memory\n");
1841 void install_element_ospf6_debug_route(void)
1843 install_element(ENABLE_NODE
, &debug_ospf6_route_cmd
);
1844 install_element(ENABLE_NODE
, &no_debug_ospf6_route_cmd
);
1845 install_element(CONFIG_NODE
, &debug_ospf6_route_cmd
);
1846 install_element(CONFIG_NODE
, &no_debug_ospf6_route_cmd
);