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
17 * along with GNU Zebra; see the file COPYING. If not, write to the
18 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 * Boston, MA 02111-1307, USA.
32 #include "ospf6_proto.h"
33 #include "ospf6_lsa.h"
34 #include "ospf6_lsdb.h"
35 #include "ospf6_route.h"
36 #include "ospf6_top.h"
37 #include "ospf6_area.h"
38 #include "ospf6_interface.h"
40 #include "ospf6_zebra.h"
42 unsigned char conf_debug_ospf6_route
= 0;
45 ospf6_route_table_name (struct ospf6_route_table
*table
)
48 switch (table
->scope_type
)
50 case OSPF6_SCOPE_TYPE_GLOBAL
:
52 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");
70 case OSPF6_SCOPE_TYPE_AREA
:
72 struct ospf6_area
*oa
= (struct ospf6_area
*) table
->scope
;
73 switch (table
->table_type
)
75 case OSPF6_TABLE_TYPE_SPF_RESULTS
:
76 snprintf (name
, sizeof (name
),
77 "area %s spf table", oa
->name
);
79 case OSPF6_TABLE_TYPE_ROUTES
:
80 snprintf (name
, sizeof (name
),
81 "area %s route table", oa
->name
);
83 case OSPF6_TABLE_TYPE_PREFIX_RANGES
:
84 snprintf (name
, sizeof (name
),
85 "area %s range table", oa
->name
);
87 case OSPF6_TABLE_TYPE_SUMMARY_PREFIXES
:
88 snprintf (name
, sizeof (name
),
89 "area %s summary prefix table", oa
->name
);
91 case OSPF6_TABLE_TYPE_SUMMARY_ROUTERS
:
92 snprintf (name
, sizeof (name
),
93 "area %s summary router table", oa
->name
);
96 snprintf (name
, sizeof (name
),
97 "area %s unknown table", oa
->name
);
103 case OSPF6_SCOPE_TYPE_INTERFACE
:
105 struct ospf6_interface
*oi
= (struct ospf6_interface
*) table
->scope
;
106 switch (table
->table_type
)
108 case OSPF6_TABLE_TYPE_CONNECTED_ROUTES
:
109 snprintf (name
, sizeof (name
), "interface %s connected table",
110 oi
->interface
->name
);
113 snprintf (name
, sizeof (name
), "interface %s unknown table",
114 oi
->interface
->name
);
122 switch (table
->table_type
)
124 case OSPF6_TABLE_TYPE_SPF_RESULTS
:
125 snprintf (name
, sizeof (name
), "temporary spf table");
128 snprintf (name
, sizeof (name
), "temporary unknown table");
138 ospf6_linkstate_prefix (u_int32_t adv_router
, u_int32_t id
,
139 struct prefix
*prefix
)
141 memset (prefix
, 0, sizeof (struct prefix
));
142 prefix
->family
= AF_INET6
;
143 prefix
->prefixlen
= 64;
144 memcpy (&prefix
->u
.prefix6
.s6_addr
[0], &adv_router
, 4);
145 memcpy (&prefix
->u
.prefix6
.s6_addr
[4], &id
, 4);
149 ospf6_linkstate_prefix2str (struct prefix
*prefix
, char *buf
, int size
)
151 u_int32_t adv_router
, id
;
152 char adv_router_str
[16], id_str
[16];
153 memcpy (&adv_router
, &prefix
->u
.prefix6
.s6_addr
[0], 4);
154 memcpy (&id
, &prefix
->u
.prefix6
.s6_addr
[4], 4);
155 inet_ntop (AF_INET
, &adv_router
, adv_router_str
, sizeof (adv_router_str
));
156 inet_ntop (AF_INET
, &id
, id_str
, sizeof (id_str
));
158 snprintf (buf
, size
, "%s Net-ID: %s", adv_router_str
, id_str
);
160 snprintf (buf
, size
, "%s", adv_router_str
);
163 /* Global strings for logging */
164 const char *ospf6_dest_type_str
[OSPF6_DEST_TYPE_MAX
] =
165 { "Unknown", "Router", "Network", "Discard", "Linkstate", "AddressRange", };
167 const char *ospf6_dest_type_substr
[OSPF6_DEST_TYPE_MAX
] =
168 { "?", "R", "N", "D", "L", "A", };
170 const char *ospf6_path_type_str
[OSPF6_PATH_TYPE_MAX
] =
171 { "Unknown", "Intra-Area", "Inter-Area", "External-1", "External-2", };
173 const char *ospf6_path_type_substr
[OSPF6_PATH_TYPE_MAX
] =
174 { "??", "IA", "IE", "E1", "E2", };
177 struct ospf6_nexthop
*
178 ospf6_nexthop_create (void)
180 struct ospf6_nexthop
*nh
;
182 nh
= XCALLOC (MTYPE_OSPF6_NEXTHOP
, sizeof (struct ospf6_nexthop
));
187 ospf6_nexthop_delete (struct ospf6_nexthop
*nh
)
190 XFREE (MTYPE_OSPF6_NEXTHOP
, nh
);
194 ospf6_free_nexthops (struct list
*nh_list
)
196 struct ospf6_nexthop
*nh
;
197 struct listnode
*node
, *nnode
;
201 for (ALL_LIST_ELEMENTS (nh_list
, node
, nnode
, nh
))
202 ospf6_nexthop_delete (nh
);
207 ospf6_clear_nexthops (struct list
*nh_list
)
209 struct listnode
*node
;
210 struct ospf6_nexthop
*nh
;
214 for (ALL_LIST_ELEMENTS_RO (nh_list
, node
, nh
))
215 ospf6_nexthop_clear (nh
);
219 static struct ospf6_nexthop
*
220 ospf6_route_find_nexthop (struct list
*nh_list
, struct ospf6_nexthop
*nh_match
)
222 struct listnode
*node
;
223 struct ospf6_nexthop
*nh
;
225 if (nh_list
&& nh_match
)
227 for (ALL_LIST_ELEMENTS_RO (nh_list
, node
, nh
))
229 if (ospf6_nexthop_is_same (nh
, nh_match
))
238 ospf6_copy_nexthops (struct list
*dst
, struct list
*src
)
240 struct ospf6_nexthop
*nh_new
, *nh
;
241 struct listnode
*node
;
245 for (ALL_LIST_ELEMENTS_RO (src
, node
, nh
))
247 if (ospf6_nexthop_is_set (nh
))
249 nh_new
= ospf6_nexthop_create ();
250 ospf6_nexthop_copy (nh_new
, nh
);
251 listnode_add (dst
, nh_new
);
258 ospf6_merge_nexthops (struct list
*dst
, struct list
*src
)
260 struct listnode
*node
;
261 struct ospf6_nexthop
*nh
, *nh_new
;
265 for (ALL_LIST_ELEMENTS_RO (src
, node
, nh
))
267 if (!ospf6_route_find_nexthop (dst
, nh
))
269 nh_new
= ospf6_nexthop_create ();
270 ospf6_nexthop_copy (nh_new
, nh
);
271 listnode_add (dst
, nh_new
);
278 ospf6_route_cmp_nexthops (struct ospf6_route
*a
, struct ospf6_route
*b
)
280 struct listnode
*anode
, *bnode
;
281 struct ospf6_nexthop
*anh
, *bnh
;
285 if (listcount(a
->nh_list
) == listcount(b
->nh_list
))
287 for (ALL_LIST_ELEMENTS_RO (a
->nh_list
, anode
, anh
))
289 for (ALL_LIST_ELEMENTS_RO (b
->nh_list
, bnode
, bnh
))
290 if (!ospf6_nexthop_is_same (anh
, bnh
))
298 /* One of the routes doesn't exist ? */
303 ospf6_num_nexthops (struct list
*nh_list
)
305 return (listcount(nh_list
));
309 ospf6_add_nexthop (struct list
*nh_list
, int ifindex
,
310 struct in6_addr
*addr
)
312 struct ospf6_nexthop
*nh
;
313 struct ospf6_nexthop nh_match
;
317 nh_match
.ifindex
= ifindex
;
319 memcpy (&nh_match
.address
, addr
, sizeof (struct in6_addr
));
321 memset (&nh_match
.address
, 0, sizeof (struct in6_addr
));
323 if (!ospf6_route_find_nexthop (nh_list
, &nh_match
))
325 nh
= ospf6_nexthop_create();
326 ospf6_nexthop_copy (nh
, &nh_match
);
327 listnode_add (nh_list
, nh
);
333 ospf6_route_zebra_copy_nexthops (struct ospf6_route
*route
,
334 ifindex_t
*ifindexes
,
335 struct in6_addr
**nexthop_addr
,
338 struct ospf6_nexthop
*nh
;
339 struct listnode
*node
;
346 for (ALL_LIST_ELEMENTS_RO (route
->nh_list
, node
, nh
))
348 if (IS_OSPF6_DEBUG_ZEBRA (SEND
))
351 inet_ntop (AF_INET6
, &nh
->address
, buf
, sizeof (buf
));
352 ifname
= ifindex2ifname (nh
->ifindex
, VRF_DEFAULT
);
353 zlog_debug (" nexthop: %s%%%.*s(%d)", buf
, IFNAMSIZ
, ifname
,
358 nexthop_addr
[i
] = &nh
->address
;
359 ifindexes
[i
] = nh
->ifindex
;
371 ospf6_route_get_first_nh_index (struct ospf6_route
*route
)
373 struct ospf6_nexthop
*nh
;
377 if ((nh
= (struct ospf6_nexthop
*)listhead (route
->nh_list
)))
378 return (nh
->ifindex
);
385 ospf6_route_create (void)
387 struct ospf6_route
*route
;
388 route
= XCALLOC (MTYPE_OSPF6_ROUTE
, sizeof (struct ospf6_route
));
389 route
->nh_list
= list_new();
394 ospf6_route_delete (struct ospf6_route
*route
)
398 ospf6_free_nexthops (route
->nh_list
);
399 list_free (route
->nh_list
);
400 XFREE (MTYPE_OSPF6_ROUTE
, route
);
405 ospf6_route_copy (struct ospf6_route
*route
)
407 struct ospf6_route
*new;
409 new = ospf6_route_create ();
410 new->type
= route
->type
;
411 memcpy (&new->prefix
, &route
->prefix
, sizeof (struct prefix
));
412 new->installed
= route
->installed
;
413 new->changed
= route
->changed
;
414 new->flag
= route
->flag
;
415 new->route_option
= route
->route_option
;
416 new->linkstate_id
= route
->linkstate_id
;
417 new->path
= route
->path
;
418 ospf6_copy_nexthops (new->nh_list
, route
->nh_list
);
428 ospf6_route_lock (struct ospf6_route
*route
)
434 ospf6_route_unlock (struct ospf6_route
*route
)
436 assert (route
->lock
> 0);
438 if (route
->lock
== 0)
440 /* Can't detach from the table until here
441 because ospf6_route_next () will use
442 the 'route->table' pointer for logging */
444 ospf6_route_delete (route
);
448 /* Route compare function. If ra is more preferred, it returns
449 less than 0. If rb is more preferred returns greater than 0.
450 Otherwise (neither one is preferred), returns 0 */
452 ospf6_route_cmp (struct ospf6_route
*ra
, struct ospf6_route
*rb
)
454 assert (ospf6_route_is_same (ra
, rb
));
455 assert (OSPF6_PATH_TYPE_NONE
< ra
->path
.type
&&
456 ra
->path
.type
< OSPF6_PATH_TYPE_MAX
);
457 assert (OSPF6_PATH_TYPE_NONE
< rb
->path
.type
&&
458 rb
->path
.type
< OSPF6_PATH_TYPE_MAX
);
460 if (ra
->type
!= rb
->type
)
461 return (ra
->type
- rb
->type
);
463 if (ra
->path
.area_id
!= rb
->path
.area_id
)
464 return (ntohl (ra
->path
.area_id
) - ntohl (rb
->path
.area_id
));
466 if (ra
->path
.type
!= rb
->path
.type
)
467 return (ra
->path
.type
- rb
->path
.type
);
469 if (ra
->path
.type
== OSPF6_PATH_TYPE_EXTERNAL2
)
471 if (ra
->path
.u
.cost_e2
!= rb
->path
.u
.cost_e2
)
472 return (ra
->path
.u
.cost_e2
- rb
->path
.u
.cost_e2
);
476 if (ra
->path
.cost
!= rb
->path
.cost
)
477 return (ra
->path
.cost
- rb
->path
.cost
);
484 ospf6_route_lookup (struct prefix
*prefix
,
485 struct ospf6_route_table
*table
)
487 struct route_node
*node
;
488 struct ospf6_route
*route
;
490 node
= route_node_lookup (table
->table
, prefix
);
494 route
= (struct ospf6_route
*) node
->info
;
499 ospf6_route_lookup_identical (struct ospf6_route
*route
,
500 struct ospf6_route_table
*table
)
502 struct ospf6_route
*target
;
504 for (target
= ospf6_route_lookup (&route
->prefix
, table
);
505 target
; target
= target
->next
)
507 if (ospf6_route_is_identical (target
, route
))
514 ospf6_route_lookup_bestmatch (struct prefix
*prefix
,
515 struct ospf6_route_table
*table
)
517 struct route_node
*node
;
518 struct ospf6_route
*route
;
520 node
= route_node_match (table
->table
, prefix
);
523 route_unlock_node (node
);
525 route
= (struct ospf6_route
*) node
->info
;
531 route_table_assert (struct ospf6_route_table
*table
)
533 struct ospf6_route
*prev
, *r
, *next
;
534 char buf
[PREFIX2STR_BUFFER
];
535 unsigned int link_error
= 0, num
= 0;
537 r
= ospf6_route_head (table
);
544 next
= ospf6_route_next (r
);
553 for (r
= ospf6_route_head (table
); r
; r
= ospf6_route_next (r
))
556 if (link_error
== 0 && num
== table
->count
)
559 zlog_err ("PANIC !!");
560 zlog_err ("Something has gone wrong with ospf6_route_table[%p]", table
);
561 zlog_debug ("table count = %d, real number = %d", table
->count
, num
);
562 zlog_debug ("DUMP START");
563 for (r
= ospf6_route_head (table
); r
; r
= ospf6_route_next (r
))
565 prefix2str (&r
->prefix
, buf
, sizeof (buf
));
566 zlog_info ("%p<-[%p]->%p : %s", r
->prev
, r
, r
->next
, buf
);
568 zlog_debug ("DUMP END");
570 assert (link_error
== 0 && num
== table
->count
);
572 #define ospf6_route_table_assert(t) (route_table_assert (t))
574 #define ospf6_route_table_assert(t) ((void) 0)
578 ospf6_route_add (struct ospf6_route
*route
,
579 struct ospf6_route_table
*table
)
581 struct route_node
*node
, *nextnode
, *prevnode
;
582 struct ospf6_route
*current
= NULL
;
583 struct ospf6_route
*prev
= NULL
, *old
= NULL
, *next
= NULL
;
584 char buf
[PREFIX2STR_BUFFER
];
587 assert (route
->rnode
== NULL
);
588 assert (route
->lock
== 0);
589 assert (route
->next
== NULL
);
590 assert (route
->prev
== NULL
);
592 if (route
->type
== OSPF6_DEST_TYPE_LINKSTATE
)
593 ospf6_linkstate_prefix2str (&route
->prefix
, buf
, sizeof (buf
));
595 prefix2str (&route
->prefix
, buf
, sizeof (buf
));
597 if (IS_OSPF6_DEBUG_ROUTE (MEMORY
))
598 zlog_debug ("%s %p: route add %p: %s", ospf6_route_table_name (table
),
599 (void *)table
, (void *)route
, buf
);
600 else if (IS_OSPF6_DEBUG_ROUTE (TABLE
))
601 zlog_debug ("%s: route add: %s", ospf6_route_table_name (table
), buf
);
605 node
= route_node_get (table
->table
, &route
->prefix
);
608 /* find place to insert */
609 for (current
= node
->info
; current
; current
= current
->next
)
611 if (! ospf6_route_is_same (current
, route
))
613 else if (current
->type
!= route
->type
)
615 else if (ospf6_route_is_same_origin (current
, route
))
617 else if (ospf6_route_cmp (current
, route
) > 0)
628 /* if route does not actually change, return unchanged */
629 if (ospf6_route_is_identical (old
, route
))
631 if (IS_OSPF6_DEBUG_ROUTE (MEMORY
))
632 zlog_debug ("%s %p: route add %p: needless update of %p",
633 ospf6_route_table_name (table
),
634 (void *)table
, (void *)route
, (void *)old
);
635 else if (IS_OSPF6_DEBUG_ROUTE (TABLE
))
636 zlog_debug ("%s: route add: needless update",
637 ospf6_route_table_name (table
));
639 ospf6_route_delete (route
);
640 SET_FLAG (old
->flag
, OSPF6_ROUTE_ADD
);
641 ospf6_route_table_assert (table
);
646 if (IS_OSPF6_DEBUG_ROUTE (MEMORY
))
647 zlog_debug ("%s %p: route add %p: update of %p",
648 ospf6_route_table_name (table
),
649 (void *)table
, (void *)route
, (void *)old
);
650 else if (IS_OSPF6_DEBUG_ROUTE (TABLE
))
651 zlog_debug ("%s: route add: update",
652 ospf6_route_table_name (table
));
654 /* replace old one if exists */
655 if (node
->info
== old
)
658 SET_FLAG (route
->flag
, OSPF6_ROUTE_BEST
);
662 old
->prev
->next
= route
;
663 route
->prev
= old
->prev
;
665 old
->next
->prev
= route
;
666 route
->next
= old
->next
;
668 route
->installed
= old
->installed
;
669 route
->changed
= now
;
670 assert (route
->table
== NULL
);
671 route
->table
= table
;
673 ospf6_route_unlock (old
); /* will be deleted later */
674 ospf6_route_lock (route
);
676 SET_FLAG (route
->flag
, OSPF6_ROUTE_CHANGE
);
677 ospf6_route_table_assert (table
);
680 (*table
->hook_add
) (route
);
685 /* insert if previous or next node found */
688 if (IS_OSPF6_DEBUG_ROUTE (MEMORY
))
689 zlog_debug ("%s %p: route add %p: another path: prev %p, next %p",
690 ospf6_route_table_name (table
),
691 (void *)table
, (void *)route
, (void *)prev
, (void *)next
);
692 else if (IS_OSPF6_DEBUG_ROUTE (TABLE
))
693 zlog_debug ("%s: route add: another path found",
694 ospf6_route_table_name (table
));
708 if (node
->info
== next
)
710 assert (next
->rnode
== node
);
712 UNSET_FLAG (next
->flag
, OSPF6_ROUTE_BEST
);
713 SET_FLAG (route
->flag
, OSPF6_ROUTE_BEST
);
714 if (IS_OSPF6_DEBUG_ROUTE (MEMORY
))
715 zlog_info ("%s %p: route add %p: replacing previous best: %p",
716 ospf6_route_table_name (table
),
717 (void *)table
, (void *)route
, (void *)next
);
720 route
->installed
= now
;
721 route
->changed
= now
;
722 assert (route
->table
== NULL
);
723 route
->table
= table
;
725 ospf6_route_lock (route
);
727 ospf6_route_table_assert (table
);
729 SET_FLAG (route
->flag
, OSPF6_ROUTE_ADD
);
731 (*table
->hook_add
) (route
);
736 /* Else, this is the brand new route regarding to the prefix */
737 if (IS_OSPF6_DEBUG_ROUTE (MEMORY
))
738 zlog_debug ("%s %p: route add %p: brand new route",
739 ospf6_route_table_name (table
), (void *)table
, (void *)route
);
740 else if (IS_OSPF6_DEBUG_ROUTE (TABLE
))
741 zlog_debug ("%s: route add: brand new route",
742 ospf6_route_table_name (table
));
744 assert (node
->info
== NULL
);
746 SET_FLAG (route
->flag
, OSPF6_ROUTE_BEST
);
747 ospf6_route_lock (route
);
748 route
->installed
= now
;
749 route
->changed
= now
;
750 assert (route
->table
== NULL
);
751 route
->table
= table
;
753 /* lookup real existing next route */
755 route_lock_node (nextnode
);
757 nextnode
= route_next (nextnode
);
758 } while (nextnode
&& nextnode
->info
== NULL
);
761 if (nextnode
== NULL
)
765 route_unlock_node (nextnode
);
767 next
= nextnode
->info
;
772 /* lookup real existing prev route */
774 route_lock_node (prevnode
);
776 prevnode
= route_prev (prevnode
);
777 } while (prevnode
&& prevnode
->info
== NULL
);
780 if (prevnode
== NULL
)
784 route_unlock_node (prevnode
);
786 prev
= prevnode
->info
;
787 while (prev
->next
&& ospf6_route_is_same (prev
, prev
->next
))
794 ospf6_route_table_assert (table
);
796 SET_FLAG (route
->flag
, OSPF6_ROUTE_ADD
);
798 (*table
->hook_add
) (route
);
804 ospf6_route_remove (struct ospf6_route
*route
,
805 struct ospf6_route_table
*table
)
807 struct route_node
*node
;
808 struct ospf6_route
*current
;
809 char buf
[PREFIX2STR_BUFFER
];
811 if (route
->type
== OSPF6_DEST_TYPE_LINKSTATE
)
812 ospf6_linkstate_prefix2str (&route
->prefix
, buf
, sizeof (buf
));
814 prefix2str (&route
->prefix
, buf
, sizeof (buf
));
816 if (IS_OSPF6_DEBUG_ROUTE (MEMORY
))
817 zlog_debug ("%s %p: route remove %p: %s",
818 ospf6_route_table_name (table
),
819 (void *)table
, (void *)route
, buf
);
820 else if (IS_OSPF6_DEBUG_ROUTE (TABLE
))
821 zlog_debug ("%s: route remove: %s", ospf6_route_table_name (table
), buf
);
823 node
= route_node_lookup (table
->table
, &route
->prefix
);
826 /* find the route to remove, making sure that the route pointer
827 is from the route table. */
828 current
= node
->info
;
829 while (current
&& ospf6_route_is_same (current
, route
))
831 if (current
== route
)
833 current
= current
->next
;
835 assert (current
== route
);
837 /* adjust doubly linked list */
839 route
->prev
->next
= route
->next
;
841 route
->next
->prev
= route
->prev
;
843 if (node
->info
== route
)
845 if (route
->next
&& route
->next
->rnode
== node
)
847 node
->info
= route
->next
;
848 SET_FLAG (route
->next
->flag
, OSPF6_ROUTE_BEST
);
851 node
->info
= NULL
; /* should unlock route_node here ? */
855 ospf6_route_table_assert (table
);
857 SET_FLAG (route
->flag
, OSPF6_ROUTE_WAS_REMOVED
);
859 if (table
->hook_remove
)
860 (*table
->hook_remove
) (route
);
862 ospf6_route_unlock (route
);
866 ospf6_route_head (struct ospf6_route_table
*table
)
868 struct route_node
*node
;
869 struct ospf6_route
*route
;
871 node
= route_top (table
->table
);
875 /* skip to the real existing entry */
876 while (node
&& node
->info
== NULL
)
877 node
= route_next (node
);
881 route_unlock_node (node
);
884 route
= (struct ospf6_route
*) node
->info
;
885 assert (route
->prev
== NULL
);
886 assert (route
->table
== table
);
887 ospf6_route_lock (route
);
889 if (IS_OSPF6_DEBUG_ROUTE (MEMORY
))
890 zlog_info ("%s %p: route head: %p<-[%p]->%p",
891 ospf6_route_table_name (table
), (void *)table
,
892 (void *)route
->prev
, (void *)route
, (void *)route
->next
);
898 ospf6_route_next (struct ospf6_route
*route
)
900 struct ospf6_route
*next
= route
->next
;
902 if (IS_OSPF6_DEBUG_ROUTE (MEMORY
))
903 zlog_info ("%s %p: route next: %p<-[%p]->%p",
904 ospf6_route_table_name (route
->table
), (void *)route
->table
,
905 (void *)route
->prev
, (void *)route
, (void *)route
->next
);
907 ospf6_route_unlock (route
);
909 ospf6_route_lock (next
);
915 ospf6_route_best_next (struct ospf6_route
*route
)
917 struct route_node
*rnode
;
918 struct ospf6_route
*next
;
920 ospf6_route_unlock (route
);
922 rnode
= route
->rnode
;
923 route_lock_node (rnode
);
924 rnode
= route_next (rnode
);
925 while (rnode
&& rnode
->info
== NULL
)
926 rnode
= route_next (rnode
);
929 route_unlock_node (rnode
);
931 assert (rnode
->info
);
932 next
= (struct ospf6_route
*) rnode
->info
;
933 ospf6_route_lock (next
);
938 ospf6_route_match_head (struct prefix
*prefix
,
939 struct ospf6_route_table
*table
)
941 struct route_node
*node
;
942 struct ospf6_route
*route
;
944 /* Walk down tree. */
945 node
= table
->table
->top
;
946 while (node
&& node
->p
.prefixlen
< prefix
->prefixlen
&&
947 prefix_match (&node
->p
, prefix
))
948 node
= node
->link
[prefix_bit(&prefix
->u
.prefix
, node
->p
.prefixlen
)];
951 route_lock_node (node
);
952 while (node
&& node
->info
== NULL
)
953 node
= route_next (node
);
956 route_unlock_node (node
);
958 if (! prefix_match (prefix
, &node
->p
))
962 ospf6_route_lock (route
);
967 ospf6_route_match_next (struct prefix
*prefix
,
968 struct ospf6_route
*route
)
970 struct ospf6_route
*next
;
972 next
= ospf6_route_next (route
);
973 if (next
&& ! prefix_match (prefix
, &next
->prefix
))
975 ospf6_route_unlock (next
);
983 ospf6_route_remove_all (struct ospf6_route_table
*table
)
985 struct ospf6_route
*route
;
986 for (route
= ospf6_route_head (table
); route
;
987 route
= ospf6_route_next (route
))
988 ospf6_route_remove (route
, table
);
991 struct ospf6_route_table
*
992 ospf6_route_table_create (int s
, int t
)
994 struct ospf6_route_table
*new;
995 new = XCALLOC (MTYPE_OSPF6_ROUTE
, sizeof (struct ospf6_route_table
));
996 new->table
= route_table_init ();
1003 ospf6_route_table_delete (struct ospf6_route_table
*table
)
1005 ospf6_route_remove_all (table
);
1006 route_table_finish (table
->table
);
1007 XFREE (MTYPE_OSPF6_ROUTE
, table
);
1013 ospf6_route_show (struct vty
*vty
, struct ospf6_route
*route
)
1016 char destination
[PREFIX2STR_BUFFER
], nexthop
[64];
1019 struct timeval now
, res
;
1020 struct listnode
*node
;
1021 struct ospf6_nexthop
*nh
;
1024 timersub (&now
, &route
->changed
, &res
);
1025 timerstring (&res
, duration
, sizeof (duration
));
1028 if (route
->type
== OSPF6_DEST_TYPE_LINKSTATE
)
1029 ospf6_linkstate_prefix2str (&route
->prefix
, destination
,
1030 sizeof (destination
));
1031 else if (route
->type
== OSPF6_DEST_TYPE_ROUTER
)
1032 inet_ntop (route
->prefix
.family
, &route
->prefix
.u
.prefix
,
1033 destination
, sizeof (destination
));
1035 prefix2str (&route
->prefix
, destination
, sizeof (destination
));
1038 for (ALL_LIST_ELEMENTS_RO (route
->nh_list
, node
, nh
))
1041 inet_ntop (AF_INET6
, &nh
->address
, nexthop
,
1043 ifname
= ifindex2ifname (nh
->ifindex
, VRF_DEFAULT
);
1047 vty_out (vty
, "%c%1s %2s %-30s %-25s %6.*s %s%s",
1048 (ospf6_route_is_best (route
) ? '*' : ' '),
1049 OSPF6_DEST_TYPE_SUBSTR (route
->type
),
1050 OSPF6_PATH_TYPE_SUBSTR (route
->path
.type
),
1051 destination
, nexthop
, IFNAMSIZ
, ifname
, duration
, VNL
);
1055 vty_out (vty
, "%c%1s %2s %-30s %-25s %6.*s %s%s",
1056 ' ', "", "", "", nexthop
, IFNAMSIZ
, ifname
, "", VNL
);
1061 ospf6_route_show_detail (struct vty
*vty
, struct ospf6_route
*route
)
1064 char destination
[PREFIX2STR_BUFFER
], nexthop
[64];
1065 char area_id
[16], id
[16], adv_router
[16], capa
[16], options
[16];
1066 struct timeval now
, res
;
1068 struct listnode
*node
;
1069 struct ospf6_nexthop
*nh
;
1074 if (route
->type
== OSPF6_DEST_TYPE_LINKSTATE
)
1075 ospf6_linkstate_prefix2str (&route
->prefix
, destination
,
1076 sizeof (destination
));
1077 else if (route
->type
== OSPF6_DEST_TYPE_ROUTER
)
1078 inet_ntop (route
->prefix
.family
, &route
->prefix
.u
.prefix
,
1079 destination
, sizeof (destination
));
1081 prefix2str (&route
->prefix
, destination
, sizeof (destination
));
1082 vty_out (vty
, "Destination: %s%s", destination
, VNL
);
1084 /* destination type */
1085 vty_out (vty
, "Destination type: %s%s",
1086 OSPF6_DEST_TYPE_NAME (route
->type
),
1090 timersub (&now
, &route
->installed
, &res
);
1091 timerstring (&res
, duration
, sizeof (duration
));
1092 vty_out (vty
, "Installed Time: %s ago%s", duration
, VNL
);
1094 timersub (&now
, &route
->changed
, &res
);
1095 timerstring (&res
, duration
, sizeof (duration
));
1096 vty_out (vty
, " Changed Time: %s ago%s", duration
, VNL
);
1098 /* Debugging info */
1099 vty_out (vty
, "Lock: %d Flags: %s%s%s%s%s", route
->lock
,
1100 (CHECK_FLAG (route
->flag
, OSPF6_ROUTE_BEST
) ? "B" : "-"),
1101 (CHECK_FLAG (route
->flag
, OSPF6_ROUTE_ADD
) ? "A" : "-"),
1102 (CHECK_FLAG (route
->flag
, OSPF6_ROUTE_REMOVE
) ? "R" : "-"),
1103 (CHECK_FLAG (route
->flag
, OSPF6_ROUTE_CHANGE
) ? "C" : "-"),
1105 vty_out (vty
, "Memory: prev: %p this: %p next: %p%s",
1106 (void *)route
->prev
, (void *)route
, (void *)route
->next
, VNL
);
1111 inet_ntop (AF_INET
, &route
->path
.area_id
, area_id
, sizeof (area_id
));
1112 vty_out (vty
, "Associated Area: %s%s", area_id
, VNL
);
1115 vty_out (vty
, "Path Type: %s%s",
1116 OSPF6_PATH_TYPE_NAME (route
->path
.type
), VNL
);
1119 inet_ntop (AF_INET
, &route
->path
.origin
.id
, id
, sizeof (id
));
1120 inet_ntop (AF_INET
, &route
->path
.origin
.adv_router
, adv_router
,
1121 sizeof (adv_router
));
1122 vty_out (vty
, "LS Origin: %s Id: %s Adv: %s%s",
1123 ospf6_lstype_name (route
->path
.origin
.type
),
1124 id
, adv_router
, VNL
);
1127 ospf6_options_printbuf (route
->path
.options
, options
, sizeof (options
));
1128 vty_out (vty
, "Options: %s%s", options
, VNL
);
1131 ospf6_capability_printbuf (route
->path
.router_bits
, capa
, sizeof (capa
));
1132 vty_out (vty
, "Router Bits: %s%s", capa
, VNL
);
1134 /* Prefix Options */
1135 vty_out (vty
, "Prefix Options: xxx%s", VNL
);
1138 vty_out (vty
, "Metric Type: %d%s", route
->path
.metric_type
,
1140 vty_out (vty
, "Metric: %d (%d)%s",
1141 route
->path
.cost
, route
->path
.u
.cost_e2
, VNL
);
1144 vty_out (vty
, "Nexthop:%s", VNL
);
1145 for (ALL_LIST_ELEMENTS_RO (route
->nh_list
, node
, nh
))
1148 inet_ntop (AF_INET6
, &nh
->address
, nexthop
, sizeof (nexthop
));
1149 ifname
= ifindex2ifname (nh
->ifindex
, VRF_DEFAULT
);
1150 vty_out (vty
, " %s %.*s%s", nexthop
, IFNAMSIZ
, ifname
, VNL
);
1152 vty_out (vty
, "%s", VNL
);
1156 ospf6_route_show_table_summary (struct vty
*vty
,
1157 struct ospf6_route_table
*table
)
1159 struct ospf6_route
*route
, *prev
= NULL
;
1160 int i
, pathtype
[OSPF6_PATH_TYPE_MAX
];
1161 unsigned int number
= 0;
1162 int nh_count
=0 , nhinval
= 0, ecmp
= 0;
1163 int alternative
= 0, destination
= 0;
1165 for (i
= 0; i
< OSPF6_PATH_TYPE_MAX
; i
++)
1168 for (route
= ospf6_route_head (table
); route
;
1169 route
= ospf6_route_next (route
))
1171 if (prev
== NULL
|| ! ospf6_route_is_same (prev
, route
))
1175 nh_count
= ospf6_num_nexthops (route
->nh_list
);
1178 else if (nh_count
> 1)
1180 pathtype
[route
->path
.type
]++;
1186 assert (number
== table
->count
);
1188 vty_out (vty
, "Number of OSPFv3 routes: %d%s", number
, VNL
);
1189 vty_out (vty
, "Number of Destination: %d%s", destination
, VNL
);
1190 vty_out (vty
, "Number of Alternative routes: %d%s", alternative
, VNL
);
1191 vty_out (vty
, "Number of Equal Cost Multi Path: %d%s", ecmp
, VNL
);
1192 for (i
= OSPF6_PATH_TYPE_INTRA
; i
<= OSPF6_PATH_TYPE_EXTERNAL2
; i
++)
1194 vty_out (vty
, "Number of %s routes: %d%s",
1195 OSPF6_PATH_TYPE_NAME (i
), pathtype
[i
], VNL
);
1200 ospf6_route_show_table_prefix (struct vty
*vty
,
1201 struct prefix
*prefix
,
1202 struct ospf6_route_table
*table
)
1204 struct ospf6_route
*route
;
1206 route
= ospf6_route_lookup (prefix
, table
);
1210 ospf6_route_lock (route
);
1211 while (route
&& ospf6_route_is_prefix (prefix
, route
))
1213 /* Specifying a prefix will always display details */
1214 ospf6_route_show_detail (vty
, route
);
1215 route
= ospf6_route_next (route
);
1218 ospf6_route_unlock (route
);
1222 ospf6_route_show_table_address (struct vty
*vty
,
1223 struct prefix
*prefix
,
1224 struct ospf6_route_table
*table
)
1226 struct ospf6_route
*route
;
1228 route
= ospf6_route_lookup_bestmatch (prefix
, table
);
1232 prefix
= &route
->prefix
;
1233 ospf6_route_lock (route
);
1234 while (route
&& ospf6_route_is_prefix (prefix
, route
))
1236 /* Specifying a prefix will always display details */
1237 ospf6_route_show_detail (vty
, route
);
1238 route
= ospf6_route_next (route
);
1241 ospf6_route_unlock (route
);
1245 ospf6_route_show_table_match (struct vty
*vty
, int detail
,
1246 struct prefix
*prefix
,
1247 struct ospf6_route_table
*table
)
1249 struct ospf6_route
*route
;
1250 assert (prefix
->family
);
1252 route
= ospf6_route_match_head (prefix
, table
);
1256 ospf6_route_show_detail (vty
, route
);
1258 ospf6_route_show (vty
, route
);
1259 route
= ospf6_route_match_next (prefix
, route
);
1264 ospf6_route_show_table_type (struct vty
*vty
, int detail
, u_char type
,
1265 struct ospf6_route_table
*table
)
1267 struct ospf6_route
*route
;
1269 route
= ospf6_route_head (table
);
1272 if (route
->path
.type
== type
)
1275 ospf6_route_show_detail (vty
, route
);
1277 ospf6_route_show (vty
, route
);
1279 route
= ospf6_route_next (route
);
1284 ospf6_route_show_table (struct vty
*vty
, int detail
,
1285 struct ospf6_route_table
*table
)
1287 struct ospf6_route
*route
;
1289 route
= ospf6_route_head (table
);
1293 ospf6_route_show_detail (vty
, route
);
1295 ospf6_route_show (vty
, route
);
1296 route
= ospf6_route_next (route
);
1301 ospf6_route_table_show (struct vty
*vty
, int argc_start
, int argc
, struct cmd_token
**argv
,
1302 struct ospf6_route_table
*table
)
1310 struct prefix prefix
;
1313 memset (&prefix
, 0, sizeof (struct prefix
));
1315 for (i
= argc_start
; i
< argc
; i
++)
1317 if (! strcmp (argv
[i
]->arg
, "summary"))
1323 if (! strcmp (argv
[i
]->arg
, "intra-area"))
1325 type
= OSPF6_PATH_TYPE_INTRA
;
1329 if (! strcmp (argv
[i
]->arg
, "inter-area"))
1331 type
= OSPF6_PATH_TYPE_INTER
;
1335 if (! strcmp (argv
[i
]->arg
, "external-1"))
1337 type
= OSPF6_PATH_TYPE_EXTERNAL1
;
1341 if (! strcmp (argv
[i
]->arg
, "external-2"))
1343 type
= OSPF6_PATH_TYPE_EXTERNAL2
;
1347 if (! strcmp (argv
[i
]->arg
, "detail"))
1353 if (! strcmp (argv
[i
]->arg
, "match"))
1359 ret
= str2prefix (argv
[i
]->arg
, &prefix
);
1360 if (ret
== 1 && prefix
.family
== AF_INET6
)
1363 if (strchr (argv
[i
]->arg
, '/'))
1368 vty_out (vty
, "Malformed argument: %s%s", argv
[i
]->arg
, VNL
);
1372 /* Give summary of this route table */
1375 ospf6_route_show_table_summary (vty
, table
);
1379 /* Give exact prefix-match route */
1380 if (isprefix
&& ! match
)
1382 /* If exact address, give best matching route */
1384 ospf6_route_show_table_address (vty
, &prefix
, table
);
1386 ospf6_route_show_table_prefix (vty
, &prefix
, table
);
1392 ospf6_route_show_table_match (vty
, detail
, &prefix
, table
);
1394 ospf6_route_show_table_type (vty
, detail
, type
, table
);
1396 ospf6_route_show_table (vty
, detail
, table
);
1402 ospf6_linkstate_show_header (struct vty
*vty
)
1404 vty_out (vty
, "%-7s %-15s %-15s %-8s %-14s %s%s",
1405 "Type", "Router-ID", "Net-ID", "Rtr-Bits", "Options", "Cost", VNL
);
1409 ospf6_linkstate_show (struct vty
*vty
, struct ospf6_route
*route
)
1411 u_int32_t router
, id
;
1412 char routername
[16], idname
[16], rbits
[16], options
[16];
1414 router
= ospf6_linkstate_prefix_adv_router (&route
->prefix
);
1415 inet_ntop (AF_INET
, &router
, routername
, sizeof (routername
));
1416 id
= ospf6_linkstate_prefix_id (&route
->prefix
);
1417 inet_ntop (AF_INET
, &id
, idname
, sizeof (idname
));
1419 ospf6_capability_printbuf (route
->path
.router_bits
, rbits
, sizeof (rbits
));
1420 ospf6_options_printbuf (route
->path
.options
, options
, sizeof (options
));
1423 vty_out (vty
, "%-7s %-15s %-15s %-8s %-14s %lu%s",
1424 "Network", routername
, idname
, rbits
, options
,
1425 (unsigned long) route
->path
.cost
, VNL
);
1427 vty_out (vty
, "%-7s %-15s %-15s %-8s %-14s %lu%s",
1428 "Router", routername
, idname
, rbits
, options
,
1429 (unsigned long) route
->path
.cost
, VNL
);
1434 ospf6_linkstate_show_table_exact (struct vty
*vty
,
1435 struct prefix
*prefix
,
1436 struct ospf6_route_table
*table
)
1438 struct ospf6_route
*route
;
1440 route
= ospf6_route_lookup (prefix
, table
);
1444 ospf6_route_lock (route
);
1445 while (route
&& ospf6_route_is_prefix (prefix
, route
))
1447 /* Specifying a prefix will always display details */
1448 ospf6_route_show_detail (vty
, route
);
1449 route
= ospf6_route_next (route
);
1452 ospf6_route_unlock (route
);
1456 ospf6_linkstate_show_table (struct vty
*vty
, int detail
,
1457 struct ospf6_route_table
*table
)
1459 struct ospf6_route
*route
;
1462 ospf6_linkstate_show_header (vty
);
1464 route
= ospf6_route_head (table
);
1468 ospf6_route_show_detail (vty
, route
);
1470 ospf6_linkstate_show (vty
, route
);
1471 route
= ospf6_route_next (route
);
1476 ospf6_linkstate_table_show (struct vty
*vty
, int idx_ipv4
, int argc
,
1477 struct cmd_token
**argv
,
1478 struct ospf6_route_table
*table
)
1484 struct prefix router
, id
, prefix
;
1486 memset (&router
, 0, sizeof (struct prefix
));
1487 memset (&id
, 0, sizeof (struct prefix
));
1488 memset (&prefix
, 0, sizeof (struct prefix
));
1490 for (i
= idx_ipv4
; i
< argc
; i
++)
1492 if (! strcmp (argv
[i
]->arg
, "detail"))
1500 ret
= str2prefix (argv
[i
]->arg
, &router
);
1501 if (ret
== 1 && router
.family
== AF_INET
)
1506 vty_out (vty
, "Malformed argument: %s%s", argv
[i
]->arg
, VNL
);
1512 ret
= str2prefix (argv
[i
]->arg
, &id
);
1513 if (ret
== 1 && id
.family
== AF_INET
)
1518 vty_out (vty
, "Malformed argument: %s%s", argv
[i
]->arg
, VNL
);
1522 vty_out (vty
, "Malformed argument: %s%s", argv
[i
]->arg
, VNL
);
1527 ospf6_linkstate_prefix (router
.u
.prefix4
.s_addr
,
1528 id
.u
.prefix4
.s_addr
, &prefix
);
1531 ospf6_linkstate_show_table_exact (vty
, &prefix
, table
);
1533 ospf6_linkstate_show_table (vty
, detail
, table
);
1540 ospf6_brouter_show_header (struct vty
*vty
)
1542 vty_out (vty
, "%-15s %-8s %-14s %-10s %-15s%s",
1543 "Router-ID", "Rtr-Bits", "Options", "Path-Type", "Area", VNL
);
1547 ospf6_brouter_show (struct vty
*vty
, struct ospf6_route
*route
)
1549 u_int32_t adv_router
;
1550 char adv
[16], rbits
[16], options
[16], area
[16];
1552 adv_router
= ospf6_linkstate_prefix_adv_router (&route
->prefix
);
1553 inet_ntop (AF_INET
, &adv_router
, adv
, sizeof (adv
));
1554 ospf6_capability_printbuf (route
->path
.router_bits
, rbits
, sizeof (rbits
));
1555 ospf6_options_printbuf (route
->path
.options
, options
, sizeof (options
));
1556 inet_ntop (AF_INET
, &route
->path
.area_id
, area
, sizeof (area
));
1558 /* vty_out (vty, "%-15s %-8s %-14s %-10s %-15s%s",
1559 "Router-ID", "Rtr-Bits", "Options", "Path-Type", "Area", VNL); */
1560 vty_out (vty
, "%-15s %-8s %-14s %-10s %-15s%s",
1561 adv
, rbits
, options
, OSPF6_PATH_TYPE_NAME (route
->path
.type
),
1565 DEFUN (debug_ospf6_route
,
1566 debug_ospf6_route_cmd
,
1567 "debug ospf6 route <table|intra-area|inter-area|memory>",
1571 "Debug route table calculation\n"
1572 "Debug intra-area route calculation\n"
1573 "Debug inter-area route calculation\n"
1574 "Debug route memory use\n"
1578 unsigned char level
= 0;
1580 if (! strncmp (argv
[idx_type
]->arg
, "table", 5))
1581 level
= OSPF6_DEBUG_ROUTE_TABLE
;
1582 else if (! strncmp (argv
[idx_type
]->arg
, "intra", 5))
1583 level
= OSPF6_DEBUG_ROUTE_INTRA
;
1584 else if (! strncmp (argv
[idx_type
]->arg
, "inter", 5))
1585 level
= OSPF6_DEBUG_ROUTE_INTER
;
1586 else if (! strncmp (argv
[idx_type
]->arg
, "memor", 5))
1587 level
= OSPF6_DEBUG_ROUTE_MEMORY
;
1588 OSPF6_DEBUG_ROUTE_ON (level
);
1592 DEFUN (no_debug_ospf6_route
,
1593 no_debug_ospf6_route_cmd
,
1594 "no debug ospf6 route <table|intra-area|inter-area|memory>",
1599 "Debug route table calculation\n"
1600 "Debug intra-area route calculation\n"
1601 "Debug inter-area route calculation\n"
1602 "Debug route memory use\n")
1605 unsigned char level
= 0;
1607 if (! strncmp (argv
[idx_type
]->arg
, "table", 5))
1608 level
= OSPF6_DEBUG_ROUTE_TABLE
;
1609 else if (! strncmp (argv
[idx_type
]->arg
, "intra", 5))
1610 level
= OSPF6_DEBUG_ROUTE_INTRA
;
1611 else if (! strncmp (argv
[idx_type
]->arg
, "inter", 5))
1612 level
= OSPF6_DEBUG_ROUTE_INTER
;
1613 else if (! strncmp (argv
[idx_type
]->arg
, "memor", 5))
1614 level
= OSPF6_DEBUG_ROUTE_MEMORY
;
1615 OSPF6_DEBUG_ROUTE_OFF (level
);
1620 config_write_ospf6_debug_route (struct vty
*vty
)
1622 if (IS_OSPF6_DEBUG_ROUTE (TABLE
))
1623 vty_out (vty
, "debug ospf6 route table%s", VNL
);
1624 if (IS_OSPF6_DEBUG_ROUTE (INTRA
))
1625 vty_out (vty
, "debug ospf6 route intra-area%s", VNL
);
1626 if (IS_OSPF6_DEBUG_ROUTE (INTER
))
1627 vty_out (vty
, "debug ospf6 route inter-area%s", VNL
);
1632 install_element_ospf6_debug_route (void)
1634 install_element (ENABLE_NODE
, &debug_ospf6_route_cmd
);
1635 install_element (ENABLE_NODE
, &no_debug_ospf6_route_cmd
);
1636 install_element (CONFIG_NODE
, &debug_ospf6_route_cmd
);
1637 install_element (CONFIG_NODE
, &no_debug_ospf6_route_cmd
);