]> git.proxmox.com Git - mirror_frr.git/blobdiff - ospf6d/ospf6_route.c
Merge remote-tracking branch 'origin/stable/3.0'
[mirror_frr.git] / ospf6d / ospf6_route.c
index 38fc0c50565b091934455d7824bafac03b6ad2cd..117f7af6eeee20973af05cc0e7b7a2f688797082 100644 (file)
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  * General Public License for more details.
  *
- * You should have received a copy of the GNU General Public License
- * along with GNU Zebra; see the file COPYING.  If not, write to the 
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 
- * Boston, MA 02111-1307, USA.  
+ * You should have received a copy of the GNU General Public License along
+ * with this program; see the file COPYING; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
 #include <zebra.h>
@@ -331,7 +330,7 @@ ospf6_add_nexthop (struct list *nh_list, int ifindex,
 
 void
 ospf6_route_zebra_copy_nexthops (struct ospf6_route *route,
-                                unsigned int *ifindexes,
+                                ifindex_t *ifindexes,
                                 struct in6_addr **nexthop_addr,
                                 int entries)
 {
@@ -347,10 +346,9 @@ ospf6_route_zebra_copy_nexthops (struct ospf6_route *route,
        {
          if (IS_OSPF6_DEBUG_ZEBRA (SEND))
            {
-             char ifname[IFNAMSIZ];
+             const char *ifname;
              inet_ntop (AF_INET6, &nh->address, buf, sizeof (buf));
-             if (!if_indextoname(nh->ifindex, ifname))
-               strlcpy(ifname, "unknown", sizeof(ifname));
+             ifname = ifindex2ifname (nh->ifindex, VRF_DEFAULT);
              zlog_debug ("  nexthop: %s%%%.*s(%d)", buf, IFNAMSIZ, ifname,
                          nh->ifindex);
            }
@@ -532,7 +530,7 @@ static void
 route_table_assert (struct ospf6_route_table *table)
 {
   struct ospf6_route *prev, *r, *next;
-  char buf[64];
+  char buf[PREFIX2STR_BUFFER];
   unsigned int link_error = 0, num = 0;
   
   r = ospf6_route_head (table);
@@ -582,7 +580,7 @@ ospf6_route_add (struct ospf6_route *route,
   struct route_node *node, *nextnode, *prevnode;
   struct ospf6_route *current = NULL;
   struct ospf6_route *prev = NULL, *old = NULL, *next = NULL;
-  char buf[64];
+  char buf[PREFIX2STR_BUFFER];
   struct timeval now;
 
   assert (route->rnode == NULL);
@@ -597,11 +595,11 @@ ospf6_route_add (struct ospf6_route *route,
 
   if (IS_OSPF6_DEBUG_ROUTE (MEMORY))
     zlog_debug ("%s %p: route add %p: %s", ospf6_route_table_name (table),
-                table, route, buf);
+                (void *)table, (void *)route, buf);
   else if (IS_OSPF6_DEBUG_ROUTE (TABLE))
     zlog_debug ("%s: route add: %s", ospf6_route_table_name (table), buf);
 
-  quagga_gettime (QUAGGA_CLK_MONOTONIC, &now);
+  monotime(&now);
 
   node = route_node_get (table->table, &route->prefix);
   route->rnode = node;
@@ -631,7 +629,8 @@ ospf6_route_add (struct ospf6_route *route,
         {
           if (IS_OSPF6_DEBUG_ROUTE (MEMORY))
             zlog_debug ("%s %p: route add %p: needless update of %p",
-                        ospf6_route_table_name (table), table, route, old);
+                        ospf6_route_table_name (table),
+                        (void *)table, (void *)route, (void *)old);
           else if (IS_OSPF6_DEBUG_ROUTE (TABLE))
             zlog_debug ("%s: route add: needless update",
                         ospf6_route_table_name (table));
@@ -645,7 +644,8 @@ ospf6_route_add (struct ospf6_route *route,
 
       if (IS_OSPF6_DEBUG_ROUTE (MEMORY))
         zlog_debug ("%s %p: route add %p: update of %p",
-                    ospf6_route_table_name (table), table, route, old);
+                    ospf6_route_table_name (table),
+                    (void *)table, (void *)route, (void *)old);
       else if (IS_OSPF6_DEBUG_ROUTE (TABLE))
         zlog_debug ("%s: route add: update",
                     ospf6_route_table_name (table));
@@ -686,7 +686,8 @@ ospf6_route_add (struct ospf6_route *route,
     {
       if (IS_OSPF6_DEBUG_ROUTE (MEMORY))
         zlog_debug ("%s %p: route add %p: another path: prev %p, next %p",
-                   ospf6_route_table_name (table), table, route, prev, next);
+                    ospf6_route_table_name (table),
+                    (void *)table, (void *)route, (void *)prev, (void *)next);
       else if (IS_OSPF6_DEBUG_ROUTE (TABLE))
         zlog_debug ("%s: route add: another path found",
                     ospf6_route_table_name (table));
@@ -711,7 +712,8 @@ ospf6_route_add (struct ospf6_route *route,
           SET_FLAG (route->flag, OSPF6_ROUTE_BEST);
           if (IS_OSPF6_DEBUG_ROUTE (MEMORY))
             zlog_info ("%s %p: route add %p: replacing previous best: %p",
-                       ospf6_route_table_name (table), table, route, next);
+                       ospf6_route_table_name (table),
+                       (void *)table, (void *)route, (void *)next);
         }
 
       route->installed = now;
@@ -733,7 +735,7 @@ ospf6_route_add (struct ospf6_route *route,
   /* Else, this is the brand new route regarding to the prefix */
   if (IS_OSPF6_DEBUG_ROUTE (MEMORY))
     zlog_debug ("%s %p: route add %p: brand new route",
-                ospf6_route_table_name (table), table, route);
+                ospf6_route_table_name (table), (void *)table, (void *)route);
   else if (IS_OSPF6_DEBUG_ROUTE (TABLE))
     zlog_debug ("%s: route add: brand new route",
                 ospf6_route_table_name (table));
@@ -803,7 +805,7 @@ ospf6_route_remove (struct ospf6_route *route,
 {
   struct route_node *node;
   struct ospf6_route *current;
-  char buf[64];
+  char buf[PREFIX2STR_BUFFER];
 
   if (route->type == OSPF6_DEST_TYPE_LINKSTATE)
     ospf6_linkstate_prefix2str (&route->prefix, buf, sizeof (buf));
@@ -812,7 +814,8 @@ ospf6_route_remove (struct ospf6_route *route,
 
   if (IS_OSPF6_DEBUG_ROUTE (MEMORY))
     zlog_debug ("%s %p: route remove %p: %s",
-                ospf6_route_table_name (table), table, route, buf);
+                ospf6_route_table_name (table),
+                (void *)table, (void *)route, buf);
   else if (IS_OSPF6_DEBUG_ROUTE (TABLE))
     zlog_debug ("%s: route remove: %s", ospf6_route_table_name (table), buf);
 
@@ -884,8 +887,8 @@ ospf6_route_head (struct ospf6_route_table *table)
 
   if (IS_OSPF6_DEBUG_ROUTE (MEMORY))
     zlog_info ("%s %p: route head: %p<-[%p]->%p",
-               ospf6_route_table_name (table), table,
-               route->prev, route, route->next);
+               ospf6_route_table_name (table), (void *)table,
+               (void *)route->prev, (void *)route, (void *)route->next);
 
   return route;
 }
@@ -897,8 +900,8 @@ ospf6_route_next (struct ospf6_route *route)
 
   if (IS_OSPF6_DEBUG_ROUTE (MEMORY))
     zlog_info ("%s %p: route next: %p<-[%p]->%p",
-               ospf6_route_table_name (route->table), route->table,
-               route->prev, route, route->next);
+               ospf6_route_table_name (route->table), (void *)route->table,
+               (void *)route->prev, (void *)route, (void *)route->next);
 
   ospf6_route_unlock (route);
   if (next)
@@ -1009,13 +1012,14 @@ void
 ospf6_route_show (struct vty *vty, struct ospf6_route *route)
 {
   int i;
-  char destination[64], nexthop[64];
-  char duration[16], ifname[IFNAMSIZ];
+  char destination[PREFIX2STR_BUFFER], nexthop[64];
+  char duration[16];
+  const char *ifname;
   struct timeval now, res;
   struct listnode *node;
   struct ospf6_nexthop *nh;
 
-  quagga_gettime (QUAGGA_CLK_MONOTONIC, &now);
+  monotime(&now);
   timersub (&now, &route->changed, &res);
   timerstring (&res, duration, sizeof (duration));
 
@@ -1029,15 +1033,13 @@ ospf6_route_show (struct vty *vty, struct ospf6_route *route)
   else
     prefix2str (&route->prefix, destination, sizeof (destination));
 
-
   i = 0;
   for (ALL_LIST_ELEMENTS_RO (route->nh_list, node, nh))
     {
       /* nexthop */
       inet_ntop (AF_INET6, &nh->address, nexthop,
                  sizeof (nexthop));
-      if (! if_indextoname (nh->ifindex, ifname))
-        snprintf (ifname, sizeof (ifname), "%d", nh->ifindex);
+      ifname = ifindex2ifname (nh->ifindex, VRF_DEFAULT);
 
       if (!i)
        {
@@ -1057,14 +1059,15 @@ ospf6_route_show (struct vty *vty, struct ospf6_route *route)
 void
 ospf6_route_show_detail (struct vty *vty, struct ospf6_route *route)
 {
-  char destination[64], nexthop[64], ifname[IFNAMSIZ];
+  const char *ifname;
+  char destination[PREFIX2STR_BUFFER], nexthop[64];
   char area_id[16], id[16], adv_router[16], capa[16], options[16];
   struct timeval now, res;
   char duration[16];
   struct listnode *node;
   struct ospf6_nexthop *nh;
 
-  quagga_gettime (QUAGGA_CLK_MONOTONIC, &now);
+  monotime(&now);
 
   /* destination */
   if (route->type == OSPF6_DEST_TYPE_LINKSTATE)
@@ -1099,7 +1102,7 @@ ospf6_route_show_detail (struct vty *vty, struct ospf6_route *route)
            (CHECK_FLAG (route->flag, OSPF6_ROUTE_CHANGE) ? "C" : "-"),
            VNL);
   vty_out (vty, "Memory: prev: %p this: %p next: %p%s",
-           route->prev, route, route->next, VNL);
+           (void *)route->prev, (void *)route, (void *)route->next, VNL);
 
   /* Path section */
 
@@ -1142,8 +1145,7 @@ ospf6_route_show_detail (struct vty *vty, struct ospf6_route *route)
     {
       /* nexthop */
       inet_ntop (AF_INET6, &nh->address, nexthop, sizeof (nexthop));
-      if (! if_indextoname (nh->ifindex, ifname))
-        snprintf (ifname, sizeof (ifname), "%d", nh->ifindex);
+      ifname = ifindex2ifname (nh->ifindex, VRF_DEFAULT);
       vty_out (vty, "  %s %.*s%s", nexthop, IFNAMSIZ, ifname, VNL);
     }
   vty_out (vty, "%s", VNL);
@@ -1295,7 +1297,7 @@ ospf6_route_show_table (struct vty *vty, int detail,
 }
 
 int
-ospf6_route_table_show (struct vty *vty, int argc, const char *argv[],
+ospf6_route_table_show (struct vty *vty, int argc_start, int argc, struct cmd_token **argv,
                         struct ospf6_route_table *table)
 {
   int summary = 0;
@@ -1309,60 +1311,60 @@ ospf6_route_table_show (struct vty *vty, int argc, const char *argv[],
 
   memset (&prefix, 0, sizeof (struct prefix));
 
-  for (i = 0; i < argc; i++)
+  for (i = argc_start; i < argc; i++)
     {
-      if (! strcmp (argv[i], "summary"))
+      if (! strcmp (argv[i]->arg, "summary"))
         {
           summary++;
           continue;
         }
 
-      if (! strcmp (argv[i], "intra-area"))
+      if (! strcmp (argv[i]->arg, "intra-area"))
         {
           type = OSPF6_PATH_TYPE_INTRA;
           continue;
         }
 
-      if (! strcmp (argv[i], "inter-area"))
+      if (! strcmp (argv[i]->arg, "inter-area"))
         {
           type = OSPF6_PATH_TYPE_INTER;
           continue;
         }
 
-      if (! strcmp (argv[i], "external-1"))
+      if (! strcmp (argv[i]->arg, "external-1"))
         {
           type = OSPF6_PATH_TYPE_EXTERNAL1;
           continue;
         }
 
-      if (! strcmp (argv[i], "external-2"))
+      if (! strcmp (argv[i]->arg, "external-2"))
         {
           type = OSPF6_PATH_TYPE_EXTERNAL2;
           continue;
         }
 
-      if (! strcmp (argv[i], "detail"))
+      if (! strcmp (argv[i]->arg, "detail"))
         {
           detail++;
           continue;
         }
 
-      if (! strcmp (argv[i], "match"))
+      if (! strcmp (argv[i]->arg, "match"))
         {
           match++;
           continue;
         }
 
-      ret = str2prefix (argv[i], &prefix);
+      ret = str2prefix (argv[i]->arg, &prefix);
       if (ret == 1 && prefix.family == AF_INET6)
         {
           isprefix++;
-          if (strchr (argv[i], '/'))
+          if (strchr (argv[i]->arg, '/'))
             slash++;
           continue;
         }
 
-      vty_out (vty, "Malformed argument: %s%s", argv[i], VNL);
+      vty_out (vty, "Malformed argument: %s%s", argv[i]->arg, VNL);
       return CMD_SUCCESS;
     }
 
@@ -1470,7 +1472,8 @@ ospf6_linkstate_show_table (struct vty *vty, int detail,
 }
 
 int
-ospf6_linkstate_table_show (struct vty *vty, int argc, const char *argv[],
+ospf6_linkstate_table_show (struct vty *vty, int idx_ipv4, int argc,
+                            struct cmd_token **argv,
                             struct ospf6_route_table *table)
 {
   int detail = 0;
@@ -1483,9 +1486,9 @@ ospf6_linkstate_table_show (struct vty *vty, int argc, const char *argv[],
   memset (&id, 0, sizeof (struct prefix));
   memset (&prefix, 0, sizeof (struct prefix));
 
-  for (i = 0; i < argc; i++)
+  for (i = idx_ipv4; i < argc; i++)
     {
-      if (! strcmp (argv[i], "detail"))
+      if (! strcmp (argv[i]->arg, "detail"))
         {
           detail++;
           continue;
@@ -1493,29 +1496,29 @@ ospf6_linkstate_table_show (struct vty *vty, int argc, const char *argv[],
 
       if (! is_router)
         {
-          ret = str2prefix (argv[i], &router);
+          ret = str2prefix (argv[i]->arg, &router);
           if (ret == 1 && router.family == AF_INET)
             {
               is_router++;
               continue;
             }
-          vty_out (vty, "Malformed argument: %s%s", argv[i], VNL);
+          vty_out (vty, "Malformed argument: %s%s", argv[i]->arg, VNL);
           return CMD_SUCCESS;
         }
 
       if (! is_id)
         {
-          ret = str2prefix (argv[i], &id);
+          ret = str2prefix (argv[i]->arg, &id);
           if (ret == 1 && id.family == AF_INET)
             {
               is_id++;
               continue;
             }
-          vty_out (vty, "Malformed argument: %s%s", argv[i], VNL);
+          vty_out (vty, "Malformed argument: %s%s", argv[i]->arg, VNL);
           return CMD_SUCCESS;
         }
 
-      vty_out (vty, "Malformed argument: %s%s", argv[i], VNL);
+      vty_out (vty, "Malformed argument: %s%s", argv[i]->arg, VNL);
       return CMD_SUCCESS;
     }
 
@@ -1560,25 +1563,26 @@ ospf6_brouter_show (struct vty *vty, struct ospf6_route *route)
 
 DEFUN (debug_ospf6_route,
        debug_ospf6_route_cmd,
-       "debug ospf6 route (table|intra-area|inter-area|memory)",
+       "debug ospf6 route <table|intra-area|inter-area|memory>",
        DEBUG_STR
        OSPF6_STR
+       "Debug routes\n"
        "Debug route table calculation\n"
-       "Debug detail\n"
        "Debug intra-area route calculation\n"
        "Debug inter-area route calculation\n"
        "Debug route memory use\n"
        )
 {
+  int idx_type = 3;
   unsigned char level = 0;
 
-  if (! strncmp (argv[0], "table", 5))
+  if (! strncmp (argv[idx_type]->arg, "table", 5))
     level = OSPF6_DEBUG_ROUTE_TABLE;
-  else if (! strncmp (argv[0], "intra", 5))
+  else if (! strncmp (argv[idx_type]->arg, "intra", 5))
     level = OSPF6_DEBUG_ROUTE_INTRA;
-  else if (! strncmp (argv[0], "inter", 5))
+  else if (! strncmp (argv[idx_type]->arg, "inter", 5))
     level = OSPF6_DEBUG_ROUTE_INTER;
-  else if (! strncmp (argv[0], "memor", 5))
+  else if (! strncmp (argv[idx_type]->arg, "memor", 5))
     level = OSPF6_DEBUG_ROUTE_MEMORY;
   OSPF6_DEBUG_ROUTE_ON (level);
   return CMD_SUCCESS;
@@ -1586,23 +1590,26 @@ DEFUN (debug_ospf6_route,
 
 DEFUN (no_debug_ospf6_route,
        no_debug_ospf6_route_cmd,
-       "no debug ospf6 route (table|intra-area|inter-area|memory)",
+       "no debug ospf6 route <table|intra-area|inter-area|memory>",
        NO_STR
        DEBUG_STR
        OSPF6_STR
+       "Debug routes\n"
        "Debug route table calculation\n"
        "Debug intra-area route calculation\n"
+       "Debug inter-area route calculation\n"
        "Debug route memory use\n")
 {
+  int idx_type = 4;
   unsigned char level = 0;
 
-  if (! strncmp (argv[0], "table", 5))
+  if (! strncmp (argv[idx_type]->arg, "table", 5))
     level = OSPF6_DEBUG_ROUTE_TABLE;
-  else if (! strncmp (argv[0], "intra", 5))
+  else if (! strncmp (argv[idx_type]->arg, "intra", 5))
     level = OSPF6_DEBUG_ROUTE_INTRA;
-  else if (! strncmp (argv[0], "inter", 5))
+  else if (! strncmp (argv[idx_type]->arg, "inter", 5))
     level = OSPF6_DEBUG_ROUTE_INTER;
-  else if (! strncmp (argv[0], "memor", 5))
+  else if (! strncmp (argv[idx_type]->arg, "memor", 5))
     level = OSPF6_DEBUG_ROUTE_MEMORY;
   OSPF6_DEBUG_ROUTE_OFF (level);
   return CMD_SUCCESS;