]> git.puffer.fish Git - mirror/frr.git/commitdiff
zebra: Consolidate static_config_ipv[4|6] into one function.
authorDonald Sharp <sharpd@cumulusnetworks.com>
Sun, 13 Nov 2016 02:52:32 +0000 (21:52 -0500)
committerDonald Sharp <sharpd@cumulusnetworks.com>
Wed, 17 May 2017 11:51:19 +0000 (07:51 -0400)
Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
zebra/zebra_vty.c

index c5c462c8daefbc548af1b4655f219c86bdcfce83..7ee5b1b21b7f319e0ffe73049d7f983fa9a9e210 100644 (file)
@@ -2317,49 +2317,49 @@ DEFUN (show_ip_route_vrf_all_summary_prefix,
   return CMD_SUCCESS;
 }
 
-/* Write IPv4 static route configuration. */
+/* Write static route configuration. */
 static int
-static_config_ipv4 (struct vty *vty, safi_t safi, const char *cmd)
+static_config (struct vty *vty, afi_t afi, safi_t safi, const char *cmd)
 {
   struct route_node *rn;
   struct static_route *si;
   struct route_table *stable;
   struct vrf *vrf;
   struct zebra_vrf *zvrf;
-  char buf[BUFSIZ];
+  char buf[SRCDEST2STR_BUFFER];
   int write =0;
 
   RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name)
     {
       if (!(zvrf = vrf->info))
         continue;
-      if ((stable = zvrf->stable[AFI_IP][safi]) == NULL)
+      if ((stable = zvrf->stable[afi][safi]) == NULL)
         continue;
 
-      for (rn = route_top (stable); rn; rn = route_next (rn))
+      for (rn = route_top (stable); rn; rn = srcdest_route_next (rn))
         for (si = rn->info; si; si = si->next)
           {
-            vty_out (vty, "%s %s", cmd, prefix2str (&rn->p, buf, sizeof buf));
+            vty_out (vty, "%s %s", cmd, srcdest_rnode2str (rn, buf, sizeof buf));
 
             switch (si->type)
               {
               case STATIC_IPV4_GATEWAY:
                 vty_out (vty, " %s", inet_ntoa (si->addr.ipv4));
                 break;
+              case STATIC_IPV6_GATEWAY:
+                vty_out (vty, " %s", inet_ntop (AF_INET6, &si->addr.ipv6, buf, BUFSIZ));
+                break;
               case STATIC_IFINDEX:
                 vty_out (vty, " %s", si->ifname);
                 break;
               case STATIC_BLACKHOLE:
                 vty_out (vty, " Null0");
                 break;
-             case STATIC_IPV6_GATEWAY:
-               vty_out (vty, " %s", inet_ntop (AF_INET6, &si->addr.ipv6, buf, BUFSIZ));
-               break;
-             case STATIC_IPV6_GATEWAY_IFINDEX:
-               vty_out (vty, " %s %s",
-                        inet_ntop (AF_INET6, &si->addr.ipv6, buf, BUFSIZ),
-                        ifindex2ifname (si->ifindex, si->vrf_id));
-               break;
+              case STATIC_IPV6_GATEWAY_IFINDEX:
+                vty_out (vty, " %s %s",
+                         inet_ntop (AF_INET6, &si->addr.ipv6, buf, BUFSIZ),
+                         ifindex2ifname (si->ifindex, si->vrf_id));
+                break;
               }
 
             /* flags are incompatible with STATIC_BLACKHOLE */
@@ -2379,7 +2379,7 @@ static_config_ipv4 (struct vty *vty, safi_t safi, const char *cmd)
               vty_out (vty, " %d", si->distance);
 
             if (si->vrf_id != VRF_DEFAULT)
-                vty_out (vty, " vrf %s", zvrf ? zvrf_name (zvrf) : "");
+                vty_out (vty, " vrf %s", zvrf_name (zvrf));
 
             /* Label information */
             if (si->snh_label.num_labels)
@@ -3843,85 +3843,6 @@ DEFUN (show_ipv6_route_vrf_all_summary_prefix,
   return CMD_SUCCESS;
 }
 
-/* Write IPv6 static route configuration. */
-static int
-static_config_ipv6 (struct vty *vty)
-{
-  struct route_node *rn;
-  struct static_route *si;
-  int write = 0;
-  char buf[SRCDEST2STR_BUFFER];
-  struct route_table *stable;
-  struct vrf *vrf;
-  struct zebra_vrf *zvrf;
-
-  RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name)
-    {
-      if (!(zvrf = vrf->info))
-        continue;
-      if ((stable = zvrf->stable[AFI_IP6][SAFI_UNICAST]) == NULL)
-        continue;
-
-      for (rn = route_top (stable); rn; rn = srcdest_route_next (rn))
-        for (si = rn->info; si; si = si->next)
-          {
-            vty_out (vty, "ipv6 route %s", srcdest_rnode2str (rn, buf, sizeof buf));
-
-           switch (si->type)
-             {
-             case STATIC_IPV4_GATEWAY:
-                vty_out (vty, " %s", inet_ntoa (si->addr.ipv4));
-                break;
-             case STATIC_IPV6_GATEWAY:
-               vty_out (vty, " %s", inet_ntop (AF_INET6, &si->addr.ipv6, buf, BUFSIZ));
-               break;
-             case STATIC_IFINDEX:
-               vty_out (vty, " %s", si->ifname);
-               break;
-             case STATIC_BLACKHOLE:
-               vty_out (vty, " Null0" );
-               break;
-             case STATIC_IPV6_GATEWAY_IFINDEX:
-               vty_out (vty, " %s %s",
-                        inet_ntop (AF_INET6, &si->addr.ipv6, buf, BUFSIZ),
-                        ifindex2ifname (si->ifindex, si->vrf_id));
-               break;
-             }
-
-            /* flags are incompatible with STATIC_BLACKHOLE */
-            if (si->type != STATIC_BLACKHOLE)
-              {
-                if (CHECK_FLAG(si->flags, ZEBRA_FLAG_REJECT))
-                  vty_out (vty, " %s", "reject");
-                if (CHECK_FLAG(si->flags, ZEBRA_FLAG_BLACKHOLE))
-                  vty_out (vty, " %s", "blackhole");
-              }
-
-            if (si->tag)
-              vty_out (vty, " tag %"ROUTE_TAG_PRI, si->tag);
-
-            if (si->distance != ZEBRA_STATIC_DISTANCE_DEFAULT)
-              vty_out (vty, " %d", si->distance);
-
-            if (si->vrf_id != VRF_DEFAULT)
-              {
-                vty_out (vty, " vrf %s", zvrf_name (zvrf));
-              }
-
-            /* Label information */
-            if (si->snh_label.num_labels)
-              vty_out (vty, " label %s",
-                       mpls_label2str (si->snh_label.num_labels,
-                                       si->snh_label.label, buf, sizeof buf, 0));
-
-            vty_out (vty, "%s", VTY_NEWLINE);
-
-            write = 1;
-          }
-    }
-  return write;
-}
-
 DEFUN (allow_external_route_update,
        allow_external_route_update_cmd,
        "allow-external-route-update",
@@ -3978,9 +3899,9 @@ zebra_ip_config (struct vty *vty)
 {
   int write = 0;
 
-  write += static_config_ipv4 (vty, SAFI_UNICAST, "ip route");
-  write += static_config_ipv4 (vty, SAFI_MULTICAST, "ip mroute");
-  write += static_config_ipv6 (vty);
+  write += static_config (vty, AFI_IP, SAFI_UNICAST, "ip route");
+  write += static_config (vty, AFI_IP, SAFI_MULTICAST, "ip mroute");
+  write += static_config (vty, AFI_IP6, SAFI_UNICAST, "ipv6 route");
 
   write += zebra_import_table_config (vty);
   return write;