]> git.proxmox.com Git - mirror_frr.git/blobdiff - zebra/zebra_vty.c
Merge branch 'frr/pull/546' ("bgpd: resolve issue with sending vpn labels")
[mirror_frr.git] / zebra / zebra_vty.c
index 41f471ad4d91e3aa99d350b0652d4b1873e8b277..eedd38f3f9eb3baaf32c207c53eafbdfe5a8fcec 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>
@@ -781,9 +780,9 @@ vty_show_ip_route_detail (struct vty *vty, struct route_node *rn, int mcast)
           /* Label information */
          if (nexthop->nh_label && nexthop->nh_label->num_labels)
            {
-             vty_out (vty, " label %s",
+             vty_out (vty, ", label %s",
                       mpls_label2str (nexthop->nh_label->num_labels,
-                                      nexthop->nh_label->label, buf, BUFSIZ));
+                                      nexthop->nh_label->label, buf, BUFSIZ, 1));
            }
 
          vty_out (vty, "%s", VTY_NEWLINE);
@@ -803,6 +802,7 @@ vty_show_ip_route (struct vty *vty, struct route_node *rn, struct rib *rib,
   json_object *json_nexthops = NULL;
   json_object *json_nexthop = NULL;
   json_object *json_route = NULL;
+  json_object *json_labels = NULL;
 
   if (json)
     {
@@ -932,6 +932,16 @@ vty_show_ip_route (struct vty *vty, struct route_node *rn, struct rib *rib,
                 break;
             }
 
+          if (nexthop->nh_label && nexthop->nh_label->num_labels)
+            {
+              json_labels = json_object_new_array();
+
+              for (int label_index = 0; label_index < nexthop->nh_label->num_labels; label_index++)
+                json_object_array_add(json_labels, json_object_new_int(nexthop->nh_label->label[label_index]));
+
+              json_object_object_add(json_nexthop, "labels", json_labels);
+            }
+
           json_object_array_add(json_nexthops, json_nexthop);
         }
 
@@ -1030,9 +1040,9 @@ vty_show_ip_route (struct vty *vty, struct route_node *rn, struct rib *rib,
       /* Label information */
       if (nexthop->nh_label && nexthop->nh_label->num_labels)
        {
-         vty_out (vty, " label %s",
+         vty_out (vty, ", label %s",
                   mpls_label2str (nexthop->nh_label->num_labels,
-                                  nexthop->nh_label->label, buf, BUFSIZ));
+                                  nexthop->nh_label->label, buf, BUFSIZ, 1));
        }
 
       if (CHECK_FLAG (rib->flags, ZEBRA_FLAG_BLACKHOLE))
@@ -2306,49 +2316,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 */
@@ -2368,13 +2378,13 @@ 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)
               vty_out (vty, " label %s",
                        mpls_label2str (si->snh_label.num_labels,
-                                       si->snh_label.label, buf, sizeof buf));
+                                       si->snh_label.label, buf, sizeof buf, 0));
 
             vty_out (vty, "%s", VTY_NEWLINE);
 
@@ -3832,85 +3842,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));
-
-            vty_out (vty, "%s", VTY_NEWLINE);
-
-            write = 1;
-          }
-    }
-  return write;
-}
-
 DEFUN (allow_external_route_update,
        allow_external_route_update_cmd,
        "allow-external-route-update",
@@ -3967,9 +3898,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;