From: Feng Lu <[email protected]>

The present "show ip[v6] [m]route [xxx]" and "show ip rpf [xxx]"
commands now show routes only in the default VRF.

A new option is introduced to show routes in a specified VRF:
    show ip[v6] [m]route [xxx] vrf N
    show ip rpf [xxx] vrf N

and a new option is used to show routes through all VRFs:
    show ip[v6] [m]route [xxx] vrf all
    show ip rpf [xxx] vrf all

Signed-off-by: Feng Lu <[email protected]>
Reviewed-by: Alain Ritoux <[email protected]>
Signed-off-by: Nicolas Dichtel <[email protected]>
---
 zebra/zebra_vty.c | 1338 +++++++++++++++++++++++++++++++++++++++++++++++------
 1 file changed, 1200 insertions(+), 138 deletions(-)

diff --git a/zebra/zebra_vty.c b/zebra/zebra_vty.c
index fff76c19678b..67b5084abcd2 100644
--- a/zebra/zebra_vty.c
+++ b/zebra/zebra_vty.c
@@ -31,9 +31,11 @@
 
 #include "zebra/zserv.h"
 
-static int do_show_ip_route(struct vty *vty, safi_t safi);
+static int do_show_ip_route(struct vty *vty, safi_t safi, vrf_id_t vrf_id);
 static void vty_show_ip_route_detail (struct vty *vty, struct route_node *rn,
                                       int mcast);
+static void vty_show_ip_route (struct vty *vty, struct route_node *rn,
+                               struct rib *rib);
 
 /* General function for static route. */
 static int
@@ -259,10 +261,23 @@ DEFUN (show_ip_rpf,
        IP_STR
        "Display RPF information for multicast source\n")
 {
+  vrf_id_t vrf_id = VRF_DEFAULT;
+
+  if (argc > 0)
+    VTY_GET_INTEGER ("VRF ID", vrf_id, argv[0]);
+
   VTY_WARN_EXPERIMENTAL();
-  return do_show_ip_route(vty, SAFI_MULTICAST);
+  return do_show_ip_route(vty, SAFI_MULTICAST, vrf_id);
 }
 
+ALIAS (show_ip_rpf,
+       show_ip_rpf_vrf_cmd,
+       "show ip rpf " VRF_CMD_STR,
+       SHOW_STR
+       IP_STR
+       "Display RPF information for multicast source\n"
+       VRF_CMD_HELP_STR)
+
 DEFUN (show_ip_rpf_addr,
        show_ip_rpf_addr_cmd,
        "show ip rpf A.B.C.D",
@@ -274,8 +289,12 @@ DEFUN (show_ip_rpf_addr,
   struct in_addr addr;
   struct route_node *rn;
   struct rib *rib;
+  vrf_id_t vrf_id = VRF_DEFAULT;
   int ret;
 
+  if (argc > 1)
+    VTY_GET_INTEGER ("VRF ID", vrf_id, argv[1]);
+
   VTY_WARN_EXPERIMENTAL();
 
   ret = inet_aton (argv[0], &addr);
@@ -285,7 +304,7 @@ DEFUN (show_ip_rpf_addr,
       return CMD_WARNING;
     }
 
-  rib = rib_match_ipv4_multicast (addr, &rn, VRF_DEFAULT);
+  rib = rib_match_ipv4_multicast (addr, &rn, vrf_id);
 
   if (rib)
     vty_show_ip_route_detail (vty, rn, 1);
@@ -295,6 +314,86 @@ DEFUN (show_ip_rpf_addr,
   return CMD_SUCCESS;
 }
 
+ALIAS (show_ip_rpf_addr,
+       show_ip_rpf_addr_vrf_cmd,
+       "show ip rpf A.B.C.D " VRF_CMD_STR,
+       SHOW_STR
+       IP_STR
+       "Display RPF information for multicast source\n"
+       "IP multicast source address (e.g. 10.0.0.0)\n"
+       VRF_CMD_HELP_STR)
+
+DEFUN (show_ip_rpf_vrf_all,
+       show_ip_rpf_vrf_all_cmd,
+       "show ip rpf " VRF_ALL_CMD_STR,
+       SHOW_STR
+       IP_STR
+       "Display RPF information for multicast source\n"
+       VRF_ALL_CMD_HELP_STR)
+{
+  struct zebra_vrf *zvrf;
+  struct route_table *table;
+  struct route_node *rn;
+  struct rib *rib;
+  vrf_iter_t iter;
+  int first = 1;
+
+  VTY_WARN_EXPERIMENTAL();
+
+  for (iter = vrf_first (); iter != VRF_ITER_INVALID; iter = vrf_next (iter))
+    {
+      if ((zvrf = vrf_iter2info (iter)) == NULL ||
+          (table = zvrf->table[AFI_IP][SAFI_MULTICAST]) == NULL)
+        continue;
+
+      /* Show all IPv4 routes. */
+      for (rn = route_top (table); rn; rn = route_next (rn))
+        RNODE_FOREACH_RIB (rn, rib)
+          {
+            if (first)
+              {
+                vty_out (vty, SHOW_ROUTE_V4_HEADER);
+                first = 0;
+              }
+            vty_show_ip_route (vty, rn, rib);
+          }
+    }
+
+  return CMD_SUCCESS;
+}
+
+DEFUN (show_ip_rpf_addr_vrf_all,
+       show_ip_rpf_addr_vrf_all_cmd,
+       "show ip rpf A.B.C.D " VRF_ALL_CMD_STR,
+       SHOW_STR
+       IP_STR
+       "Display RPF information for multicast source\n"
+       "IP multicast source address (e.g. 10.0.0.0)\n"
+       VRF_ALL_CMD_HELP_STR)
+{
+  struct in_addr addr;
+  struct route_node *rn;
+  vrf_iter_t iter;
+  int ret;
+
+  VTY_WARN_EXPERIMENTAL();
+
+  ret = inet_aton (argv[0], &addr);
+  if (ret == 0)
+    {
+      vty_out (vty, "%% Malformed address%s", VTY_NEWLINE);
+      return CMD_WARNING;
+    }
+
+  for (iter = vrf_first (); iter != VRF_ITER_INVALID; iter = vrf_next (iter))
+    {
+      if (rib_match_ipv4_multicast (addr, &rn, vrf_iter2id (iter)))
+        vty_show_ip_route_detail (vty, rn, 1);
+    }
+
+  return CMD_SUCCESS;
+}
+
 /* Static route configuration.  */
 DEFUN (ip_route, 
        ip_route_cmd,
@@ -716,6 +815,7 @@ vty_show_ip_route_detail (struct vty *vty, struct 
route_node *rn, int mcast)
               VTY_NEWLINE);
       vty_out (vty, "  Known via \"%s\"", zebra_route_string (rib->type));
       vty_out (vty, ", distance %u, metric %u", rib->distance, rib->metric);
+      vty_out (vty, ", vrf %u", rib->vrf_id);
       if (CHECK_FLAG (rib->flags, ZEBRA_FLAG_SELECTED))
        vty_out (vty, ", best");
       if (rib->refcnt)
@@ -855,6 +955,9 @@ vty_show_ip_route (struct vty *vty, struct route_node *rn, 
struct rib *rib)
              && rib->type != ZEBRA_ROUTE_KERNEL)
            len += vty_out (vty, " [%d/%d]", rib->distance,
                            rib->metric);
+
+          if (rib->vrf_id != VRF_DEFAULT)
+            len += vty_out (vty, " [vrf %u]", rib->vrf_id);
        }
       else
        vty_out (vty, "  %c%*c",
@@ -960,16 +1063,22 @@ DEFUN (show_ip_route,
        IP_STR
        "IP routing table\n")
 {
-  return do_show_ip_route(vty, SAFI_UNICAST);
+  vrf_id_t vrf_id = VRF_DEFAULT;
+
+  if (argc > 0)
+    VTY_GET_INTEGER ("VRF ID", vrf_id, argv[0]);
+
+  return do_show_ip_route(vty, SAFI_UNICAST, vrf_id);
 }
 
-static int do_show_ip_route(struct vty *vty, safi_t safi) {
+static int do_show_ip_route(struct vty *vty, safi_t safi, vrf_id_t vrf_id)
+{
   struct route_table *table;
   struct route_node *rn;
   struct rib *rib;
   int first = 1;
 
-  table = zebra_vrf_table (AFI_IP, safi, VRF_DEFAULT);
+  table = zebra_vrf_table (AFI_IP, safi, vrf_id);
   if (! table)
     return CMD_SUCCESS;
 
@@ -987,6 +1096,14 @@ static int do_show_ip_route(struct vty *vty, safi_t safi) 
{
   return CMD_SUCCESS;
 }
 
+ALIAS (show_ip_route,
+       show_ip_route_vrf_cmd,
+       "show ip route " VRF_CMD_STR,
+       SHOW_STR
+       IP_STR
+       "IP routing table\n"
+       VRF_CMD_HELP_STR)
+
 DEFUN (show_ip_route_prefix_longer,
        show_ip_route_prefix_longer_cmd,
        "show ip route A.B.C.D/M longer-prefixes",
@@ -1002,6 +1119,7 @@ DEFUN (show_ip_route_prefix_longer,
   struct prefix p;
   int ret;
   int first = 1;
+  vrf_id_t vrf_id = VRF_DEFAULT;
 
   ret = str2prefix (argv[0], &p);
   if (! ret)
@@ -1009,8 +1127,11 @@ DEFUN (show_ip_route_prefix_longer,
       vty_out (vty, "%% Malformed Prefix%s", VTY_NEWLINE);
       return CMD_WARNING;
     }
-  
-  table = zebra_vrf_table (AFI_IP, SAFI_UNICAST, VRF_DEFAULT);
+
+  if (argc > 1)
+    VTY_GET_INTEGER ("VRF ID", vrf_id, argv[1]);
+
+  table = zebra_vrf_table (AFI_IP, SAFI_UNICAST, vrf_id);
   if (! table)
     return CMD_SUCCESS;
 
@@ -1029,6 +1150,16 @@ DEFUN (show_ip_route_prefix_longer,
   return CMD_SUCCESS;
 }
 
+ALIAS (show_ip_route_prefix_longer,
+       show_ip_route_prefix_longer_vrf_cmd,
+       "show ip route A.B.C.D/M longer-prefixes " VRF_CMD_STR,
+       SHOW_STR
+       IP_STR
+       "IP routing table\n"
+       "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
+       "Show route matching the specified Network/Mask pair only\n"
+       VRF_CMD_HELP_STR)
+
 DEFUN (show_ip_route_supernets,
        show_ip_route_supernets_cmd,
        "show ip route supernets-only",
@@ -1040,10 +1171,14 @@ DEFUN (show_ip_route_supernets,
   struct route_table *table;
   struct route_node *rn;
   struct rib *rib;
-  u_int32_t addr; 
+  u_int32_t addr;
   int first = 1;
+  vrf_id_t vrf_id = VRF_DEFAULT;
 
-  table = zebra_vrf_table (AFI_IP, SAFI_UNICAST, VRF_DEFAULT);
+  if (argc > 0)
+    VTY_GET_INTEGER ("VRF ID", vrf_id, argv[0]);
+
+  table = zebra_vrf_table (AFI_IP, SAFI_UNICAST, vrf_id);
   if (! table)
     return CMD_SUCCESS;
 
@@ -1055,7 +1190,7 @@ DEFUN (show_ip_route_supernets,
 
        if ((IN_CLASSC (addr) && rn->p.prefixlen < 24)
           || (IN_CLASSB (addr) && rn->p.prefixlen < 16)
-          || (IN_CLASSA (addr) && rn->p.prefixlen < 8)) 
+          || (IN_CLASSA (addr) && rn->p.prefixlen < 8))
          {
            if (first)
              {
@@ -1068,6 +1203,15 @@ DEFUN (show_ip_route_supernets,
   return CMD_SUCCESS;
 }
 
+ALIAS (show_ip_route_supernets,
+       show_ip_route_supernets_vrf_cmd,
+       "show ip route supernets-only " VRF_CMD_STR,
+       SHOW_STR
+       IP_STR
+       "IP routing table\n"
+       "Show supernet entries only\n"
+       VRF_CMD_HELP_STR)
+
 DEFUN (show_ip_route_protocol,
        show_ip_route_protocol_cmd,
        "show ip route " QUAGGA_IP_REDIST_STR_ZEBRA,
@@ -1081,6 +1225,7 @@ DEFUN (show_ip_route_protocol,
   struct route_node *rn;
   struct rib *rib;
   int first = 1;
+  vrf_id_t vrf_id = VRF_DEFAULT;
 
   type = proto_redistnum (AFI_IP, argv[0]);
   if (type < 0)
@@ -1088,8 +1233,11 @@ DEFUN (show_ip_route_protocol,
       vty_out (vty, "Unknown route type%s", VTY_NEWLINE);
       return CMD_WARNING;
     }
-  
-  table = zebra_vrf_table (AFI_IP, SAFI_UNICAST, VRF_DEFAULT);
+
+  if (argc > 1)
+    VTY_GET_INTEGER ("VRF ID", vrf_id, argv[1]);
+
+  table = zebra_vrf_table (AFI_IP, SAFI_UNICAST, vrf_id);
   if (! table)
     return CMD_SUCCESS;
 
@@ -1108,6 +1256,15 @@ DEFUN (show_ip_route_protocol,
   return CMD_SUCCESS;
 }
 
+ALIAS (show_ip_route_protocol,
+       show_ip_route_protocol_vrf_cmd,
+       "show ip route " QUAGGA_IP_REDIST_STR_ZEBRA " " VRF_CMD_STR,
+       SHOW_STR
+       IP_STR
+       "IP routing table\n"
+       QUAGGA_IP_REDIST_HELP_STR_ZEBRA
+       VRF_CMD_HELP_STR)
+
 DEFUN (show_ip_route_addr,
        show_ip_route_addr_cmd,
        "show ip route A.B.C.D",
@@ -1120,6 +1277,7 @@ DEFUN (show_ip_route_addr,
   struct prefix_ipv4 p;
   struct route_table *table;
   struct route_node *rn;
+  vrf_id_t vrf_id = VRF_DEFAULT;
 
   ret = str2prefix_ipv4 (argv[0], &p);
   if (ret <= 0)
@@ -1128,7 +1286,10 @@ DEFUN (show_ip_route_addr,
       return CMD_WARNING;
     }
 
-  table = zebra_vrf_table (AFI_IP, SAFI_UNICAST, VRF_DEFAULT);
+  if (argc > 1)
+    VTY_GET_INTEGER ("VRF ID", vrf_id, argv[1]);
+
+  table = zebra_vrf_table (AFI_IP, SAFI_UNICAST, vrf_id);
   if (! table)
     return CMD_SUCCESS;
 
@@ -1146,6 +1307,15 @@ DEFUN (show_ip_route_addr,
   return CMD_SUCCESS;
 }
 
+ALIAS (show_ip_route_addr,
+       show_ip_route_addr_vrf_cmd,
+       "show ip route A.B.C.D " VRF_CMD_STR,
+       SHOW_STR
+       IP_STR
+       "IP routing table\n"
+       "Network in the IP routing table to display\n"
+       VRF_CMD_HELP_STR)
+
 DEFUN (show_ip_route_prefix,
        show_ip_route_prefix_cmd,
        "show ip route A.B.C.D/M",
@@ -1158,6 +1328,7 @@ DEFUN (show_ip_route_prefix,
   struct prefix_ipv4 p;
   struct route_table *table;
   struct route_node *rn;
+  vrf_id_t vrf_id = VRF_DEFAULT;
 
   ret = str2prefix_ipv4 (argv[0], &p);
   if (ret <= 0)
@@ -1166,7 +1337,10 @@ DEFUN (show_ip_route_prefix,
       return CMD_WARNING;
     }
 
-  table = zebra_vrf_table (AFI_IP, SAFI_UNICAST, VRF_DEFAULT);
+  if (argc > 1)
+    VTY_GET_INTEGER ("VRF ID", vrf_id, argv[1]);
+
+  table = zebra_vrf_table (AFI_IP, SAFI_UNICAST, vrf_id);
   if (! table)
     return CMD_SUCCESS;
 
@@ -1186,6 +1360,15 @@ DEFUN (show_ip_route_prefix,
   return CMD_SUCCESS;
 }
 
+ALIAS (show_ip_route_prefix,
+       show_ip_route_prefix_vrf_cmd,
+       "show ip route A.B.C.D/M " VRF_CMD_STR,
+       SHOW_STR
+       IP_STR
+       "IP routing table\n"
+       "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
+       VRF_CMD_HELP_STR)
+
 static void
 vty_show_ip_route_summary (struct vty *vty, struct route_table *table)
 {
@@ -1222,8 +1405,10 @@ vty_show_ip_route_summary (struct vty *vty, struct 
route_table *table)
            }
        }
 
-  vty_out (vty, "%-20s %-20s %-20s %s", 
-          "Route Source", "Routes", "FIB", VTY_NEWLINE);
+  vty_out (vty, "%-20s %-20s %s  (vrf %u)%s",
+           "Route Source", "Routes", "FIB",
+           ((rib_table_info_t *)table->info)->zvrf->vrf_id,
+           VTY_NEWLINE);
 
   for (i = 0; i < ZEBRA_ROUTE_MAX; i++) 
     {
@@ -1248,6 +1433,7 @@ vty_show_ip_route_summary (struct vty *vty, struct 
route_table *table)
   vty_out (vty, "------%s", VTY_NEWLINE);
   vty_out (vty, "%-20s %-20d %-20d %s", "Totals", rib_cnt[ZEBRA_ROUTE_TOTAL], 
           fib_cnt[ZEBRA_ROUTE_TOTAL], VTY_NEWLINE);  
+  vty_out (vty, "%s", VTY_NEWLINE);
 }
 
 /*
@@ -1300,8 +1486,10 @@ vty_show_ip_route_summary_prefix (struct vty *vty, 
struct route_table *table)
             }
       }
 
-  vty_out (vty, "%-20s %-20s %-20s %s",
-          "Route Source", "Prefix Routes", "FIB", VTY_NEWLINE);
+  vty_out (vty, "%-20s %-20s %s  (vrf %u)%s",
+           "Route Source", "Prefix Routes", "FIB",
+           ((rib_table_info_t *)table->info)->zvrf->vrf_id,
+           VTY_NEWLINE);
 
   for (i = 0; i < ZEBRA_ROUTE_MAX; i++)
     {
@@ -1326,6 +1514,7 @@ vty_show_ip_route_summary_prefix (struct vty *vty, struct 
route_table *table)
   vty_out (vty, "------%s", VTY_NEWLINE);
   vty_out (vty, "%-20s %-20d %-20d %s", "Totals", rib_cnt[ZEBRA_ROUTE_TOTAL],
           fib_cnt[ZEBRA_ROUTE_TOTAL], VTY_NEWLINE);
+  vty_out (vty, "%s", VTY_NEWLINE);
 }
 
 /* Show route summary.  */
@@ -1338,8 +1527,12 @@ DEFUN (show_ip_route_summary,
        "Summary of all routes\n")
 {
   struct route_table *table;
+  vrf_id_t vrf_id = VRF_DEFAULT;
+
+  if (argc > 0)
+    VTY_GET_INTEGER ("VRF ID", vrf_id, argv[0]);
 
-  table = zebra_vrf_table (AFI_IP, SAFI_UNICAST, VRF_DEFAULT);
+  table = zebra_vrf_table (AFI_IP, SAFI_UNICAST, vrf_id);
   if (! table)
     return CMD_SUCCESS;
 
@@ -1348,6 +1541,15 @@ DEFUN (show_ip_route_summary,
   return CMD_SUCCESS;
 }
 
+ALIAS (show_ip_route_summary,
+       show_ip_route_summary_vrf_cmd,
+       "show ip route summary " VRF_CMD_STR,
+       SHOW_STR
+       IP_STR
+       "IP routing table\n"
+       "Summary of all routes\n"
+       VRF_CMD_HELP_STR)
+
 /* Show route summary prefix.  */
 DEFUN (show_ip_route_summary_prefix,
        show_ip_route_summary_prefix_cmd,
@@ -1359,8 +1561,12 @@ DEFUN (show_ip_route_summary_prefix,
        "Prefix routes\n")
 {
   struct route_table *table;
+  vrf_id_t vrf_id = VRF_DEFAULT;
+
+  if (argc > 0)
+    VTY_GET_INTEGER ("VRF ID", vrf_id, argv[0]);
 
-  table = zebra_vrf_table (AFI_IP, SAFI_UNICAST, VRF_DEFAULT);
+  table = zebra_vrf_table (AFI_IP, SAFI_UNICAST, vrf_id);
   if (! table)
     return CMD_SUCCESS;
 
@@ -1369,140 +1575,503 @@ DEFUN (show_ip_route_summary_prefix,
   return CMD_SUCCESS;
 }
 
-/* Write IPv4 static route configuration. */
-static int
-static_config_ipv4 (struct vty *vty, safi_t safi, const char *cmd)
+ALIAS (show_ip_route_summary_prefix,
+       show_ip_route_summary_prefix_vrf_cmd,
+       "show ip route summary prefix " VRF_CMD_STR,
+       SHOW_STR
+       IP_STR
+       "IP routing table\n"
+       "Summary of all routes\n"
+       "Prefix routes\n"
+       VRF_CMD_HELP_STR)
+
+DEFUN (show_ip_route_vrf_all,
+       show_ip_route_vrf_all_cmd,
+       "show ip route " VRF_ALL_CMD_STR,
+       SHOW_STR
+       IP_STR
+       "IP routing table\n"
+       VRF_ALL_CMD_HELP_STR)
 {
+  struct route_table *table;
   struct route_node *rn;
-  struct static_ipv4 *si;  
-  struct route_table *stable;
-  int write;
-
-  write = 0;
-
-  /* Lookup table.  */
-  stable = zebra_vrf_static_table (AFI_IP, safi, VRF_DEFAULT);
-  if (! stable)
-    return -1;
+  struct rib *rib;
+  struct zebra_vrf *zvrf;
+  vrf_iter_t iter;
+  int first = 1;
 
-  for (rn = route_top (stable); rn; rn = route_next (rn))
-    for (si = rn->info; si; si = si->next)
-      {
-        vty_out (vty, "%s %s/%d", cmd, inet_ntoa (rn->p.u.prefix4),
-                 rn->p.prefixlen);
+  for (iter = vrf_first (); iter != VRF_ITER_INVALID; iter = vrf_next (iter))
+    {
+      if ((zvrf = vrf_iter2info (iter)) == NULL ||
+          (table = zvrf->table[AFI_IP][SAFI_UNICAST]) == NULL)
+        continue;
 
-        switch (si->type)
-          {
-            case STATIC_IPV4_GATEWAY:
-              vty_out (vty, " %s", inet_ntoa (si->gate.ipv4));
-              break;
-            case STATIC_IPV4_IFNAME:
-              vty_out (vty, " %s", si->gate.ifname);
-              break;
-            case STATIC_IPV4_BLACKHOLE:
-              vty_out (vty, " Null0");
-              break;
-          }
-        
-        /* flags are incompatible with STATIC_IPV4_BLACKHOLE */
-        if (si->type != STATIC_IPV4_BLACKHOLE)
+      /* Show all IPv4 routes. */
+      for (rn = route_top (table); rn; rn = route_next (rn))
+        RNODE_FOREACH_RIB (rn, rib)
           {
-            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 (first)
+              {
+                vty_out (vty, SHOW_ROUTE_V4_HEADER);
+                first = 0;
+              }
+            vty_show_ip_route (vty, rn, rib);
           }
+    }
 
-        if (si->distance != ZEBRA_STATIC_DISTANCE_DEFAULT)
-          vty_out (vty, " %d", si->distance);
-
-        vty_out (vty, "%s", VTY_NEWLINE);
-
-        write = 1;
-      }
-  return write;
+  return CMD_SUCCESS;
 }
 
-DEFUN (show_ip_protocol,
-       show_ip_protocol_cmd,
-       "show ip protocol",
-        SHOW_STR
-        IP_STR
-       "IP protocol filtering status\n")
+DEFUN (show_ip_route_prefix_longer_vrf_all,
+       show_ip_route_prefix_longer_vrf_all_cmd,
+       "show ip route A.B.C.D/M longer-prefixes " VRF_ALL_CMD_STR,
+       SHOW_STR
+       IP_STR
+       "IP routing table\n"
+       "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
+       "Show route matching the specified Network/Mask pair only\n"
+       VRF_ALL_CMD_HELP_STR)
 {
-    int i; 
+  struct route_table *table;
+  struct route_node *rn;
+  struct rib *rib;
+  struct prefix p;
+  struct zebra_vrf *zvrf;
+  vrf_iter_t iter;
+  int ret;
+  int first = 1;
 
-    vty_out(vty, "Protocol    : route-map %s", VTY_NEWLINE);
-    vty_out(vty, "------------------------%s", VTY_NEWLINE);
-    for (i=0;i<ZEBRA_ROUTE_MAX;i++)
+  ret = str2prefix (argv[0], &p);
+  if (! ret)
     {
-        if (proto_rm[AFI_IP][i])
-          vty_out (vty, "%-10s  : %-10s%s", zebra_route_string(i),
-                                       proto_rm[AFI_IP][i],
-                                       VTY_NEWLINE);
-        else
-          vty_out (vty, "%-10s  : none%s", zebra_route_string(i), VTY_NEWLINE);
+      vty_out (vty, "%% Malformed Prefix%s", VTY_NEWLINE);
+      return CMD_WARNING;
     }
-    if (proto_rm[AFI_IP][i])
-      vty_out (vty, "%-10s  : %-10s%s", "any", proto_rm[AFI_IP][i],
-                                       VTY_NEWLINE);
-    else
-      vty_out (vty, "%-10s  : none%s", "any", VTY_NEWLINE);
 
-    return CMD_SUCCESS;
+  for (iter = vrf_first (); iter != VRF_ITER_INVALID; iter = vrf_next (iter))
+    {
+      if ((zvrf = vrf_iter2info (iter)) == NULL ||
+          (table = zvrf->table[AFI_IP][SAFI_UNICAST]) == NULL)
+        continue;
+
+      /* Show matched type IPv4 routes. */
+      for (rn = route_top (table); rn; rn = route_next (rn))
+        RNODE_FOREACH_RIB (rn, rib)
+          if (prefix_match (&p, &rn->p))
+            {
+              if (first)
+                {
+                  vty_out (vty, SHOW_ROUTE_V4_HEADER);
+                  first = 0;
+                }
+              vty_show_ip_route (vty, rn, rib);
+            }
+    }
+
+  return CMD_SUCCESS;
 }
 
-/*
- * Show IP mroute command to dump the BGP Multicast
- * routing table
- */
-DEFUN (show_ip_mroute,
-       show_ip_mroute_cmd,
-       "show ip mroute",
+DEFUN (show_ip_route_supernets_vrf_all,
+       show_ip_route_supernets_vrf_all_cmd,
+       "show ip route supernets-only " VRF_ALL_CMD_STR,
        SHOW_STR
        IP_STR
-       "IP Multicast routing table\n")
+       "IP routing table\n"
+       "Show supernet entries only\n"
+       VRF_ALL_CMD_HELP_STR)
 {
   struct route_table *table;
   struct route_node *rn;
   struct rib *rib;
+  struct zebra_vrf *zvrf;
+  vrf_iter_t iter;
+  u_int32_t addr;
   int first = 1;
 
-  table = zebra_vrf_table (AFI_IP, SAFI_MULTICAST, VRF_DEFAULT);
-  if (! table)
-    return CMD_SUCCESS;
+  for (iter = vrf_first (); iter != VRF_ITER_INVALID; iter = vrf_next (iter))
+    {
+      if ((zvrf = vrf_iter2info (iter)) == NULL ||
+          (table = zvrf->table[AFI_IP][SAFI_UNICAST]) == NULL)
+        continue;
+
+      /* Show matched type IPv4 routes. */
+      for (rn = route_top (table); rn; rn = route_next (rn))
+        RNODE_FOREACH_RIB (rn, rib)
+          {
+            addr = ntohl (rn->p.u.prefix4.s_addr);
+
+            if ((IN_CLASSC (addr) && rn->p.prefixlen < 24)
+               || (IN_CLASSB (addr) && rn->p.prefixlen < 16)
+               || (IN_CLASSA (addr) && rn->p.prefixlen < 8))
+              {
+                if (first)
+                  {
+                    vty_out (vty, SHOW_ROUTE_V4_HEADER);
+                    first = 0;
+                  }
+                vty_show_ip_route (vty, rn, rib);
+              }
+          }
+    }
 
-  /* Show all IPv4 routes. */
-  for (rn = route_top (table); rn; rn = route_next (rn))
-    RNODE_FOREACH_RIB (rn, rib)
-      {
-       if (first)
-         {
-          vty_out (vty, SHOW_ROUTE_V4_HEADER);
-           first = 0;
-         }
-       vty_show_ip_route (vty, rn, rib);
-      }
   return CMD_SUCCESS;
 }
 
-
-#ifdef HAVE_IPV6
-/* General fucntion for IPv6 static route. */
-static int
-static_ipv6_func (struct vty *vty, int add_cmd, const char *dest_str,
-                 const char *gate_str, const char *ifname,
-                 const char *flag_str, const char *distance_str)
+DEFUN (show_ip_route_protocol_vrf_all,
+       show_ip_route_protocol_vrf_all_cmd,
+       "show ip route " QUAGGA_IP_REDIST_STR_ZEBRA " " VRF_ALL_CMD_STR,
+       SHOW_STR
+       IP_STR
+       "IP routing table\n"
+       QUAGGA_IP_REDIST_HELP_STR_ZEBRA
+       VRF_ALL_CMD_HELP_STR)
 {
-  int ret;
-  u_char distance;
-  struct prefix p;
-  struct in6_addr *gate = NULL;
-  struct in6_addr gate_addr;
-  u_char type = 0;
-  int table = 0;
-  u_char flag = 0;
+  int type;
+  struct route_table *table;
+  struct route_node *rn;
+  struct rib *rib;
+  struct zebra_vrf *zvrf;
+  vrf_iter_t iter;
+  int first = 1;
+
+  type = proto_redistnum (AFI_IP, argv[0]);
+  if (type < 0)
+    {
+      vty_out (vty, "Unknown route type%s", VTY_NEWLINE);
+      return CMD_WARNING;
+    }
+
+  for (iter = vrf_first (); iter != VRF_ITER_INVALID; iter = vrf_next (iter))
+    {
+      if ((zvrf = vrf_iter2info (iter)) == NULL ||
+          (table = zvrf->table[AFI_IP][SAFI_UNICAST]) == NULL)
+        continue;
+
+      /* Show matched type IPv4 routes. */
+      for (rn = route_top (table); rn; rn = route_next (rn))
+        RNODE_FOREACH_RIB (rn, rib)
+          if (rib->type == type)
+            {
+              if (first)
+                {
+                  vty_out (vty, SHOW_ROUTE_V4_HEADER);
+                  first = 0;
+                }
+              vty_show_ip_route (vty, rn, rib);
+            }
+    }
+
+  return CMD_SUCCESS;
+}
+
+DEFUN (show_ip_route_addr_vrf_all,
+       show_ip_route_addr_vrf_all_cmd,
+       "show ip route A.B.C.D " VRF_ALL_CMD_STR,
+       SHOW_STR
+       IP_STR
+       "IP routing table\n"
+       "Network in the IP routing table to display\n"
+       VRF_ALL_CMD_HELP_STR)
+{
+  int ret;
+  struct prefix_ipv4 p;
+  struct route_table *table;
+  struct route_node *rn;
+  struct zebra_vrf *zvrf;
+  vrf_iter_t iter;
+
+  ret = str2prefix_ipv4 (argv[0], &p);
+  if (ret <= 0)
+    {
+      vty_out (vty, "%% Malformed IPv4 address%s", VTY_NEWLINE);
+      return CMD_WARNING;
+    }
+
+  for (iter = vrf_first (); iter != VRF_ITER_INVALID; iter = vrf_next (iter))
+    {
+      if ((zvrf = vrf_iter2info (iter)) == NULL ||
+          (table = zvrf->table[AFI_IP][SAFI_UNICAST]) == NULL)
+        continue;
+
+      rn = route_node_match (table, (struct prefix *) &p);
+      if (! rn)
+        continue;
+
+      vty_show_ip_route_detail (vty, rn, 0);
+
+      route_unlock_node (rn);
+    }
+
+  return CMD_SUCCESS;
+}
+
+DEFUN (show_ip_route_prefix_vrf_all,
+       show_ip_route_prefix_vrf_all_cmd,
+       "show ip route A.B.C.D/M " VRF_ALL_CMD_STR,
+       SHOW_STR
+       IP_STR
+       "IP routing table\n"
+       "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
+       VRF_ALL_CMD_HELP_STR)
+{
+  int ret;
+  struct prefix_ipv4 p;
+  struct route_table *table;
+  struct route_node *rn;
+  struct zebra_vrf *zvrf;
+  vrf_iter_t iter;
+
+  ret = str2prefix_ipv4 (argv[0], &p);
+  if (ret <= 0)
+    {
+      vty_out (vty, "%% Malformed IPv4 address%s", VTY_NEWLINE);
+      return CMD_WARNING;
+    }
+
+  for (iter = vrf_first (); iter != VRF_ITER_INVALID; iter = vrf_next (iter))
+    {
+      if ((zvrf = vrf_iter2info (iter)) == NULL ||
+          (table = zvrf->table[AFI_IP][SAFI_UNICAST]) == NULL)
+        continue;
+
+      rn = route_node_match (table, (struct prefix *) &p);
+      if (! rn)
+        continue;
+      if (rn->p.prefixlen != p.prefixlen)
+        {
+          route_unlock_node (rn);
+          continue;
+        }
+
+      vty_show_ip_route_detail (vty, rn, 0);
+
+      route_unlock_node (rn);
+    }
+
+  return CMD_SUCCESS;
+}
+
+DEFUN (show_ip_route_summary_vrf_all,
+       show_ip_route_summary_vrf_all_cmd,
+       "show ip route summary " VRF_ALL_CMD_STR,
+       SHOW_STR
+       IP_STR
+       "IP routing table\n"
+       "Summary of all routes\n"
+       VRF_ALL_CMD_HELP_STR)
+{
+  struct zebra_vrf *zvrf;
+  vrf_iter_t iter;
+
+  for (iter = vrf_first (); iter != VRF_ITER_INVALID; iter = vrf_next (iter))
+    if ((zvrf = vrf_iter2info (iter)) != NULL)
+      vty_show_ip_route_summary (vty, zvrf->table[AFI_IP][SAFI_UNICAST]);
+
+  return CMD_SUCCESS;
+}
+
+DEFUN (show_ip_route_summary_prefix_vrf_all,
+       show_ip_route_summary_prefix_vrf_all_cmd,
+       "show ip route summary prefix " VRF_ALL_CMD_STR,
+       SHOW_STR
+       IP_STR
+       "IP routing table\n"
+       "Summary of all routes\n"
+       "Prefix routes\n"
+       VRF_ALL_CMD_HELP_STR)
+{
+  struct zebra_vrf *zvrf;
+  vrf_iter_t iter;
+
+  for (iter = vrf_first (); iter != VRF_ITER_INVALID; iter = vrf_next (iter))
+    if ((zvrf = vrf_iter2info (iter)) != NULL)
+      vty_show_ip_route_summary_prefix (vty, 
zvrf->table[AFI_IP][SAFI_UNICAST]);
+
+  return CMD_SUCCESS;
+}
+
+/* Write IPv4 static route configuration. */
+static int
+static_config_ipv4 (struct vty *vty, safi_t safi, const char *cmd)
+{
+  struct route_node *rn;
+  struct static_ipv4 *si;  
+  struct route_table *stable;
+  int write;
+
+  write = 0;
+
+  /* Lookup table.  */
+  stable = zebra_vrf_static_table (AFI_IP, safi, VRF_DEFAULT);
+  if (! stable)
+    return -1;
+
+  for (rn = route_top (stable); rn; rn = route_next (rn))
+    for (si = rn->info; si; si = si->next)
+      {
+        vty_out (vty, "%s %s/%d", cmd, inet_ntoa (rn->p.u.prefix4),
+                 rn->p.prefixlen);
+
+        switch (si->type)
+          {
+            case STATIC_IPV4_GATEWAY:
+              vty_out (vty, " %s", inet_ntoa (si->gate.ipv4));
+              break;
+            case STATIC_IPV4_IFNAME:
+              vty_out (vty, " %s", si->gate.ifname);
+              break;
+            case STATIC_IPV4_BLACKHOLE:
+              vty_out (vty, " Null0");
+              break;
+          }
+        
+        /* flags are incompatible with STATIC_IPV4_BLACKHOLE */
+        if (si->type != STATIC_IPV4_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->distance != ZEBRA_STATIC_DISTANCE_DEFAULT)
+          vty_out (vty, " %d", si->distance);
+
+        vty_out (vty, "%s", VTY_NEWLINE);
+
+        write = 1;
+      }
+  return write;
+}
+
+DEFUN (show_ip_protocol,
+       show_ip_protocol_cmd,
+       "show ip protocol",
+        SHOW_STR
+        IP_STR
+       "IP protocol filtering status\n")
+{
+    int i; 
+
+    vty_out(vty, "Protocol    : route-map %s", VTY_NEWLINE);
+    vty_out(vty, "------------------------%s", VTY_NEWLINE);
+    for (i=0;i<ZEBRA_ROUTE_MAX;i++)
+    {
+        if (proto_rm[AFI_IP][i])
+          vty_out (vty, "%-10s  : %-10s%s", zebra_route_string(i),
+                                       proto_rm[AFI_IP][i],
+                                       VTY_NEWLINE);
+        else
+          vty_out (vty, "%-10s  : none%s", zebra_route_string(i), VTY_NEWLINE);
+    }
+    if (proto_rm[AFI_IP][i])
+      vty_out (vty, "%-10s  : %-10s%s", "any", proto_rm[AFI_IP][i],
+                                       VTY_NEWLINE);
+    else
+      vty_out (vty, "%-10s  : none%s", "any", VTY_NEWLINE);
+
+    return CMD_SUCCESS;
+}
+
+/*
+ * Show IP mroute command to dump the BGP Multicast
+ * routing table
+ */
+DEFUN (show_ip_mroute,
+       show_ip_mroute_cmd,
+       "show ip mroute",
+       SHOW_STR
+       IP_STR
+       "IP Multicast routing table\n")
+{
+  struct route_table *table;
+  struct route_node *rn;
+  struct rib *rib;
+  int first = 1;
+  vrf_id_t vrf_id = VRF_DEFAULT;
+
+  if (argc > 0)
+    VTY_GET_INTEGER ("VRF ID", vrf_id, argv[0]);
+
+  table = zebra_vrf_table (AFI_IP, SAFI_MULTICAST, vrf_id);
+  if (! table)
+    return CMD_SUCCESS;
+
+  /* Show all IPv4 routes. */
+  for (rn = route_top (table); rn; rn = route_next (rn))
+    RNODE_FOREACH_RIB (rn, rib)
+      {
+       if (first)
+         {
+          vty_out (vty, SHOW_ROUTE_V4_HEADER);
+           first = 0;
+         }
+       vty_show_ip_route (vty, rn, rib);
+      }
+  return CMD_SUCCESS;
+}
+
+ALIAS (show_ip_mroute,
+       show_ip_mroute_vrf_cmd,
+       "show ip mroute " VRF_CMD_STR,
+       SHOW_STR
+       IP_STR
+       "IP Multicast routing table\n"
+       VRF_CMD_HELP_STR)
+
+DEFUN (show_ip_mroute_vrf_all,
+       show_ip_mroute_vrf_all_cmd,
+       "show ip mroute " VRF_ALL_CMD_STR,
+       SHOW_STR
+       IP_STR
+       "IP Multicast routing table\n"
+       VRF_ALL_CMD_HELP_STR)
+{
+  struct route_table *table;
+  struct route_node *rn;
+  struct rib *rib;
+  struct zebra_vrf *zvrf;
+  vrf_iter_t iter;
+  int first = 1;
+
+  for (iter = vrf_first (); iter != VRF_ITER_INVALID; iter = vrf_next (iter))
+    {
+      if ((zvrf = vrf_iter2info (iter)) == NULL ||
+          (table = zvrf->table[AFI_IP][SAFI_UNICAST]) == NULL)
+        continue;
+
+      /* Show all IPv4 routes. */
+      for (rn = route_top (table); rn; rn = route_next (rn))
+        RNODE_FOREACH_RIB (rn, rib)
+          {
+           if (first)
+             {
+               vty_out (vty, SHOW_ROUTE_V4_HEADER);
+               first = 0;
+             }
+           vty_show_ip_route (vty, rn, rib);
+          }
+    }
+
+  return CMD_SUCCESS;
+}
+
+#ifdef HAVE_IPV6
+/* General fucntion for IPv6 static route. */
+static int
+static_ipv6_func (struct vty *vty, int add_cmd, const char *dest_str,
+                 const char *gate_str, const char *ifname,
+                 const char *flag_str, const char *distance_str)
+{
+  int ret;
+  u_char distance;
+  struct prefix p;
+  struct in6_addr *gate = NULL;
+  struct in6_addr gate_addr;
+  u_char type = 0;
+  int table = 0;
+  u_char flag = 0;
   
   ret = str2prefix (dest_str, &p);
   if (ret <= 0)
@@ -1811,6 +2380,7 @@ vty_show_ipv6_route_detail (struct vty *vty, struct 
route_node *rn)
               VTY_NEWLINE);
       vty_out (vty, "  Known via \"%s\"", zebra_route_string (rib->type));
       vty_out (vty, ", distance %u, metric %u", rib->distance, rib->metric);
+      vty_out (vty, ", vrf %u", rib->vrf_id);
       if (CHECK_FLAG (rib->flags, ZEBRA_FLAG_SELECTED))
        vty_out (vty, ", best");
       if (rib->refcnt)
@@ -1924,6 +2494,9 @@ vty_show_ipv6_route (struct vty *vty, struct route_node 
*rn,
              && rib->type != ZEBRA_ROUTE_KERNEL)
            len += vty_out (vty, " [%d/%d]", rib->distance,
                            rib->metric);
+
+          if (rib->vrf_id != VRF_DEFAULT)
+            len += vty_out (vty, " [vrf %u]", rib->vrf_id);
        }
       else
        vty_out (vty, "  %c%*c",
@@ -2006,8 +2579,12 @@ DEFUN (show_ipv6_route,
   struct route_node *rn;
   struct rib *rib;
   int first = 1;
+  vrf_id_t vrf_id = VRF_DEFAULT;
 
-  table = zebra_vrf_table (AFI_IP6, SAFI_UNICAST, VRF_DEFAULT);
+  if (argc > 0)
+    VTY_GET_INTEGER ("VRF ID", vrf_id, argv[0]);
+
+  table = zebra_vrf_table (AFI_IP6, SAFI_UNICAST, vrf_id);
   if (! table)
     return CMD_SUCCESS;
 
@@ -2025,6 +2602,14 @@ DEFUN (show_ipv6_route,
   return CMD_SUCCESS;
 }
 
+ALIAS (show_ipv6_route,
+       show_ipv6_route_vrf_cmd,
+       "show ipv6 route " VRF_CMD_STR,
+       SHOW_STR
+       IP_STR
+       "IPv6 routing table\n"
+       VRF_CMD_HELP_STR)
+
 DEFUN (show_ipv6_route_prefix_longer,
        show_ipv6_route_prefix_longer_cmd,
        "show ipv6 route X:X::X:X/M longer-prefixes",
@@ -2040,10 +2625,7 @@ DEFUN (show_ipv6_route_prefix_longer,
   struct prefix p;
   int ret;
   int first = 1;
-
-  table = zebra_vrf_table (AFI_IP6, SAFI_UNICAST, VRF_DEFAULT);
-  if (! table)
-    return CMD_SUCCESS;
+  vrf_id_t vrf_id = VRF_DEFAULT;
 
   ret = str2prefix (argv[0], &p);
   if (! ret)
@@ -2052,6 +2634,13 @@ DEFUN (show_ipv6_route_prefix_longer,
       return CMD_WARNING;
     }
 
+  if (argc > 1)
+    VTY_GET_INTEGER ("VRF ID", vrf_id, argv[1]);
+
+  table = zebra_vrf_table (AFI_IP6, SAFI_UNICAST, vrf_id);
+  if (! table)
+    return CMD_SUCCESS;
+
   /* Show matched type IPv6 routes. */
   for (rn = route_top (table); rn; rn = route_next (rn))
     RNODE_FOREACH_RIB (rn, rib)
@@ -2067,6 +2656,16 @@ DEFUN (show_ipv6_route_prefix_longer,
   return CMD_SUCCESS;
 }
 
+ALIAS (show_ipv6_route_prefix_longer,
+       show_ipv6_route_prefix_longer_vrf_cmd,
+       "show ipv6 route X:X::X:X/M longer-prefixes " VRF_CMD_STR,
+       SHOW_STR
+       IP_STR
+       "IPv6 routing table\n"
+       "IPv6 prefix\n"
+       "Show route matching the specified Network/Mask pair only\n"
+       VRF_CMD_HELP_STR)
+
 DEFUN (show_ipv6_route_protocol,
        show_ipv6_route_protocol_cmd,
        "show ipv6 route " QUAGGA_IP6_REDIST_STR_ZEBRA,
@@ -2080,6 +2679,7 @@ DEFUN (show_ipv6_route_protocol,
   struct route_node *rn;
   struct rib *rib;
   int first = 1;
+  vrf_id_t vrf_id = VRF_DEFAULT;
 
   type = proto_redistnum (AFI_IP6, argv[0]);
   if (type < 0)
@@ -2087,8 +2687,11 @@ DEFUN (show_ipv6_route_protocol,
       vty_out (vty, "Unknown route type%s", VTY_NEWLINE);
       return CMD_WARNING;
     }
-  
-  table = zebra_vrf_table (AFI_IP6, SAFI_UNICAST, VRF_DEFAULT);
+
+  if (argc > 1)
+    VTY_GET_INTEGER ("VRF ID", vrf_id, argv[1]);
+
+  table = zebra_vrf_table (AFI_IP6, SAFI_UNICAST, vrf_id);
   if (! table)
     return CMD_SUCCESS;
 
@@ -2107,6 +2710,15 @@ DEFUN (show_ipv6_route_protocol,
   return CMD_SUCCESS;
 }
 
+ALIAS (show_ipv6_route_protocol,
+       show_ipv6_route_protocol_vrf_cmd,
+       "show ipv6 route " QUAGGA_IP6_REDIST_STR_ZEBRA " " VRF_CMD_STR,
+       SHOW_STR
+       IP_STR
+       "IP routing table\n"
+       QUAGGA_IP6_REDIST_HELP_STR_ZEBRA
+       VRF_CMD_HELP_STR)
+
 DEFUN (show_ipv6_route_addr,
        show_ipv6_route_addr_cmd,
        "show ipv6 route X:X::X:X",
@@ -2119,6 +2731,7 @@ DEFUN (show_ipv6_route_addr,
   struct prefix_ipv6 p;
   struct route_table *table;
   struct route_node *rn;
+  vrf_id_t vrf_id = VRF_DEFAULT;
 
   ret = str2prefix_ipv6 (argv[0], &p);
   if (ret <= 0)
@@ -2127,7 +2740,10 @@ DEFUN (show_ipv6_route_addr,
       return CMD_WARNING;
     }
 
-  table = zebra_vrf_table (AFI_IP6, SAFI_UNICAST, VRF_DEFAULT);
+  if (argc > 1)
+    VTY_GET_INTEGER ("VRF ID", vrf_id, argv[1]);
+
+  table = zebra_vrf_table (AFI_IP6, SAFI_UNICAST, vrf_id);
   if (! table)
     return CMD_SUCCESS;
 
@@ -2145,6 +2761,15 @@ DEFUN (show_ipv6_route_addr,
   return CMD_SUCCESS;
 }
 
+ALIAS (show_ipv6_route_addr,
+       show_ipv6_route_addr_vrf_cmd,
+       "show ipv6 route X:X::X:X " VRF_CMD_STR,
+       SHOW_STR
+       IP_STR
+       "IPv6 routing table\n"
+       "IPv6 Address\n"
+       VRF_CMD_HELP_STR)
+
 DEFUN (show_ipv6_route_prefix,
        show_ipv6_route_prefix_cmd,
        "show ipv6 route X:X::X:X/M",
@@ -2157,6 +2782,7 @@ DEFUN (show_ipv6_route_prefix,
   struct prefix_ipv6 p;
   struct route_table *table;
   struct route_node *rn;
+  vrf_id_t vrf_id = VRF_DEFAULT;
 
   ret = str2prefix_ipv6 (argv[0], &p);
   if (ret <= 0)
@@ -2165,7 +2791,10 @@ DEFUN (show_ipv6_route_prefix,
       return CMD_WARNING;
     }
 
-  table = zebra_vrf_table (AFI_IP6, SAFI_UNICAST, VRF_DEFAULT);
+  if (argc > 1)
+    VTY_GET_INTEGER ("VRF ID", vrf_id, argv[1]);
+
+  table = zebra_vrf_table (AFI_IP6, SAFI_UNICAST, vrf_id);
   if (! table)
     return CMD_SUCCESS;
 
@@ -2185,6 +2814,15 @@ DEFUN (show_ipv6_route_prefix,
   return CMD_SUCCESS;
 }
 
+ALIAS (show_ipv6_route_prefix,
+       show_ipv6_route_prefix_vrf_cmd,
+       "show ipv6 route X:X::X:X/M " VRF_CMD_STR,
+       SHOW_STR
+       IP_STR
+       "IPv6 routing table\n"
+       "IPv6 prefix\n"
+       VRF_CMD_HELP_STR)
+
 /* Show route summary.  */
 DEFUN (show_ipv6_route_summary,
        show_ipv6_route_summary_cmd,
@@ -2195,8 +2833,12 @@ DEFUN (show_ipv6_route_summary,
        "Summary of all IPv6 routes\n")
 {
   struct route_table *table;
+  vrf_id_t vrf_id = VRF_DEFAULT;
+
+  if (argc > 0)
+    VTY_GET_INTEGER ("VRF ID", vrf_id, argv[0]);
 
-  table = zebra_vrf_table (AFI_IP6, SAFI_UNICAST, VRF_DEFAULT);
+  table = zebra_vrf_table (AFI_IP6, SAFI_UNICAST, vrf_id);
   if (! table)
     return CMD_SUCCESS;
 
@@ -2205,6 +2847,15 @@ DEFUN (show_ipv6_route_summary,
   return CMD_SUCCESS;
 }
 
+ALIAS (show_ipv6_route_summary,
+       show_ipv6_route_summary_vrf_cmd,
+       "show ipv6 route summary " VRF_CMD_STR,
+       SHOW_STR
+       IP_STR
+       "IPv6 routing table\n"
+       "Summary of all IPv6 routes\n"
+       VRF_CMD_HELP_STR)
+
 /* Show ipv6 route summary prefix.  */
 DEFUN (show_ipv6_route_summary_prefix,
        show_ipv6_route_summary_prefix_cmd,
@@ -2216,8 +2867,12 @@ DEFUN (show_ipv6_route_summary_prefix,
        "Prefix routes\n")
 {
   struct route_table *table;
+  vrf_id_t vrf_id = VRF_DEFAULT;
 
-  table = zebra_vrf_table (AFI_IP6, SAFI_UNICAST, VRF_DEFAULT);
+  if (argc > 0)
+    VTY_GET_INTEGER ("VRF ID", vrf_id, argv[0]);
+
+  table = zebra_vrf_table (AFI_IP6, SAFI_UNICAST, vrf_id);
   if (! table)
     return CMD_SUCCESS;
 
@@ -2226,6 +2881,16 @@ DEFUN (show_ipv6_route_summary_prefix,
   return CMD_SUCCESS;
 }
 
+ALIAS (show_ipv6_route_summary_prefix,
+       show_ipv6_route_summary_prefix_vrf_cmd,
+       "show ipv6 route summary prefix " VRF_CMD_STR,
+       SHOW_STR
+       IP_STR
+       "IPv6 routing table\n"
+       "Summary of all IPv6 routes\n"
+       "Prefix routes\n"
+       VRF_CMD_HELP_STR)
+
 /*
  * Show IPv6 mroute command.Used to dump
  * the Multicast routing table.
@@ -2242,8 +2907,12 @@ DEFUN (show_ipv6_mroute,
   struct route_node *rn;
   struct rib *rib;
   int first = 1;
+  vrf_id_t vrf_id = VRF_DEFAULT;
+
+  if (argc > 0)
+    VTY_GET_INTEGER ("VRF ID", vrf_id, argv[0]);
 
-  table = zebra_vrf_table (AFI_IP6, SAFI_MULTICAST, VRF_DEFAULT);
+  table = zebra_vrf_table (AFI_IP6, SAFI_MULTICAST, vrf_id);
   if (! table)
     return CMD_SUCCESS;
 
@@ -2261,6 +2930,310 @@ DEFUN (show_ipv6_mroute,
   return CMD_SUCCESS;
 }
 
+ALIAS (show_ipv6_mroute,
+       show_ipv6_mroute_vrf_cmd,
+       "show ipv6 mroute " VRF_CMD_STR,
+       SHOW_STR
+       IP_STR
+       "IPv6 Multicast routing table\n"
+       VRF_CMD_HELP_STR)
+
+DEFUN (show_ipv6_route_vrf_all,
+       show_ipv6_route_vrf_all_cmd,
+       "show ipv6 route " VRF_ALL_CMD_STR,
+       SHOW_STR
+       IP_STR
+       "IPv6 routing table\n"
+       VRF_ALL_CMD_HELP_STR)
+{
+  struct route_table *table;
+  struct route_node *rn;
+  struct rib *rib;
+  struct zebra_vrf *zvrf;
+  vrf_iter_t iter;
+  int first = 1;
+
+  for (iter = vrf_first (); iter != VRF_ITER_INVALID; iter = vrf_next (iter))
+    {
+      if ((zvrf = vrf_iter2info (iter)) == NULL ||
+          (table = zvrf->table[AFI_IP6][SAFI_UNICAST]) == NULL)
+        continue;
+
+      /* Show all IPv6 route. */
+      for (rn = route_top (table); rn; rn = route_next (rn))
+        RNODE_FOREACH_RIB (rn, rib)
+          {
+            if (first)
+              {
+                vty_out (vty, SHOW_ROUTE_V6_HEADER);
+                first = 0;
+              }
+            vty_show_ipv6_route (vty, rn, rib);
+          }
+    }
+
+  return CMD_SUCCESS;
+}
+
+DEFUN (show_ipv6_route_prefix_longer_vrf_all,
+       show_ipv6_route_prefix_longer_vrf_all_cmd,
+       "show ipv6 route X:X::X:X/M longer-prefixes " VRF_ALL_CMD_STR,
+       SHOW_STR
+       IP_STR
+       "IPv6 routing table\n"
+       "IPv6 prefix\n"
+       "Show route matching the specified Network/Mask pair only\n"
+       VRF_ALL_CMD_HELP_STR)
+{
+  struct route_table *table;
+  struct route_node *rn;
+  struct rib *rib;
+  struct prefix p;
+  struct zebra_vrf *zvrf;
+  vrf_iter_t iter;
+  int ret;
+  int first = 1;
+
+  ret = str2prefix (argv[0], &p);
+  if (! ret)
+    {
+      vty_out (vty, "%% Malformed Prefix%s", VTY_NEWLINE);
+      return CMD_WARNING;
+    }
+
+  for (iter = vrf_first (); iter != VRF_ITER_INVALID; iter = vrf_next (iter))
+    {
+      if ((zvrf = vrf_iter2info (iter)) == NULL ||
+          (table = zvrf->table[AFI_IP6][SAFI_UNICAST]) == NULL)
+        continue;
+
+      /* Show matched type IPv6 routes. */
+      for (rn = route_top (table); rn; rn = route_next (rn))
+        RNODE_FOREACH_RIB (rn, rib)
+          if (prefix_match (&p, &rn->p))
+            {
+              if (first)
+                {
+                  vty_out (vty, SHOW_ROUTE_V6_HEADER);
+                  first = 0;
+                }
+              vty_show_ipv6_route (vty, rn, rib);
+            }
+    }
+
+  return CMD_SUCCESS;
+}
+
+DEFUN (show_ipv6_route_protocol_vrf_all,
+       show_ipv6_route_protocol_vrf_all_cmd,
+       "show ipv6 route " QUAGGA_IP6_REDIST_STR_ZEBRA " " VRF_ALL_CMD_STR,
+       SHOW_STR
+       IP_STR
+       "IP routing table\n"
+       QUAGGA_IP6_REDIST_HELP_STR_ZEBRA
+       VRF_ALL_CMD_HELP_STR)
+{
+  int type;
+  struct route_table *table;
+  struct route_node *rn;
+  struct rib *rib;
+  struct zebra_vrf *zvrf;
+  vrf_iter_t iter;
+  int first = 1;
+
+  type = proto_redistnum (AFI_IP6, argv[0]);
+  if (type < 0)
+    {
+      vty_out (vty, "Unknown route type%s", VTY_NEWLINE);
+      return CMD_WARNING;
+    }
+
+  for (iter = vrf_first (); iter != VRF_ITER_INVALID; iter = vrf_next (iter))
+    {
+      if ((zvrf = vrf_iter2info (iter)) == NULL ||
+          (table = zvrf->table[AFI_IP6][SAFI_UNICAST]) == NULL)
+        continue;
+
+      /* Show matched type IPv6 routes. */
+      for (rn = route_top (table); rn; rn = route_next (rn))
+        RNODE_FOREACH_RIB (rn, rib)
+          if (rib->type == type)
+            {
+              if (first)
+                {
+                  vty_out (vty, SHOW_ROUTE_V6_HEADER);
+                  first = 0;
+                }
+              vty_show_ipv6_route (vty, rn, rib);
+            }
+    }
+
+  return CMD_SUCCESS;
+}
+
+DEFUN (show_ipv6_route_addr_vrf_all,
+       show_ipv6_route_addr_vrf_all_cmd,
+       "show ipv6 route X:X::X:X " VRF_ALL_CMD_STR,
+       SHOW_STR
+       IP_STR
+       "IPv6 routing table\n"
+       "IPv6 Address\n"
+       VRF_ALL_CMD_HELP_STR)
+{
+  int ret;
+  struct prefix_ipv6 p;
+  struct route_table *table;
+  struct route_node *rn;
+  struct zebra_vrf *zvrf;
+  vrf_iter_t iter;
+
+  ret = str2prefix_ipv6 (argv[0], &p);
+  if (ret <= 0)
+    {
+      vty_out (vty, "Malformed IPv6 address%s", VTY_NEWLINE);
+      return CMD_WARNING;
+    }
+
+  for (iter = vrf_first (); iter != VRF_ITER_INVALID; iter = vrf_next (iter))
+    {
+      if ((zvrf = vrf_iter2info (iter)) == NULL ||
+          (table = zvrf->table[AFI_IP6][SAFI_UNICAST]) == NULL)
+        continue;
+
+      rn = route_node_match (table, (struct prefix *) &p);
+      if (! rn)
+        continue;
+
+      vty_show_ipv6_route_detail (vty, rn);
+
+      route_unlock_node (rn);
+    }
+
+  return CMD_SUCCESS;
+}
+
+DEFUN (show_ipv6_route_prefix_vrf_all,
+       show_ipv6_route_prefix_vrf_all_cmd,
+       "show ipv6 route X:X::X:X/M " VRF_ALL_CMD_STR,
+       SHOW_STR
+       IP_STR
+       "IPv6 routing table\n"
+       "IPv6 prefix\n"
+       VRF_ALL_CMD_HELP_STR)
+{
+  int ret;
+  struct prefix_ipv6 p;
+  struct route_table *table;
+  struct route_node *rn;
+  struct zebra_vrf *zvrf;
+  vrf_iter_t iter;
+
+  ret = str2prefix_ipv6 (argv[0], &p);
+  if (ret <= 0)
+    {
+      vty_out (vty, "Malformed IPv6 prefix%s", VTY_NEWLINE);
+      return CMD_WARNING;
+    }
+
+  for (iter = vrf_first (); iter != VRF_ITER_INVALID; iter = vrf_next (iter))
+    {
+      if ((zvrf = vrf_iter2info (iter)) == NULL ||
+          (table = zvrf->table[AFI_IP6][SAFI_UNICAST]) == NULL)
+        continue;
+
+      rn = route_node_match (table, (struct prefix *) &p);
+      if (! rn)
+        continue;
+      if (rn->p.prefixlen != p.prefixlen)
+        {
+          route_unlock_node (rn);
+          continue;
+        }
+
+      vty_show_ipv6_route_detail (vty, rn);
+
+      route_unlock_node (rn);
+    }
+
+  return CMD_SUCCESS;
+}
+
+/* Show route summary.  */
+DEFUN (show_ipv6_route_summary_vrf_all,
+       show_ipv6_route_summary_vrf_all_cmd,
+       "show ipv6 route summary " VRF_ALL_CMD_STR,
+       SHOW_STR
+       IP_STR
+       "IPv6 routing table\n"
+       "Summary of all IPv6 routes\n"
+       VRF_ALL_CMD_HELP_STR)
+{
+  struct zebra_vrf *zvrf;
+  vrf_iter_t iter;
+
+  for (iter = vrf_first (); iter != VRF_ITER_INVALID; iter = vrf_next (iter))
+    if ((zvrf = vrf_iter2info (iter)) != NULL)
+      vty_show_ip_route_summary (vty, zvrf->table[AFI_IP6][SAFI_UNICAST]);
+
+  return CMD_SUCCESS;
+}
+
+DEFUN (show_ipv6_mroute_vrf_all,
+       show_ipv6_mroute_vrf_all_cmd,
+       "show ipv6 mroute " VRF_ALL_CMD_STR,
+       SHOW_STR
+       IP_STR
+       "IPv6 Multicast routing table\n"
+       VRF_ALL_CMD_HELP_STR)
+{
+  struct route_table *table;
+  struct route_node *rn;
+  struct rib *rib;
+  struct zebra_vrf *zvrf;
+  vrf_iter_t iter;
+  int first = 1;
+
+  for (iter = vrf_first (); iter != VRF_ITER_INVALID; iter = vrf_next (iter))
+    {
+      if ((zvrf = vrf_iter2info (iter)) == NULL ||
+          (table = zvrf->table[AFI_IP6][SAFI_UNICAST]) == NULL)
+        continue;
+
+      /* Show all IPv6 route. */
+      for (rn = route_top (table); rn; rn = route_next (rn))
+        RNODE_FOREACH_RIB (rn, rib)
+          {
+           if (first)
+             {
+               vty_out (vty, SHOW_ROUTE_V6_HEADER);
+               first = 0;
+             }
+           vty_show_ipv6_route (vty, rn, rib);
+          }
+    }
+  return CMD_SUCCESS;
+}
+
+DEFUN (show_ipv6_route_summary_prefix_vrf_all,
+       show_ipv6_route_summary_prefix_vrf_all_cmd,
+       "show ipv6 route summary prefix " VRF_ALL_CMD_STR,
+       SHOW_STR
+       IP_STR
+       "IPv6 routing table\n"
+       "Summary of all IPv6 routes\n"
+       "Prefix routes\n"
+       VRF_ALL_CMD_HELP_STR)
+{
+  struct zebra_vrf *zvrf;
+  vrf_iter_t iter;
+
+  for (iter = vrf_first (); iter != VRF_ITER_INVALID; iter = vrf_next (iter))
+    if ((zvrf = vrf_iter2info (iter)) != NULL)
+      vty_show_ip_route_summary_prefix (vty, 
zvrf->table[AFI_IP6][SAFI_UNICAST]);
+
+  return CMD_SUCCESS;
+}
+
 /* Write IPv6 static route configuration. */
 static int
 static_config_ipv6 (struct vty *vty)
@@ -2430,6 +3403,57 @@ zebra_vty_init (void)
   install_element (VIEW_NODE, &show_ip_rpf_addr_cmd);
   install_element (ENABLE_NODE, &show_ip_rpf_addr_cmd);
 
+  /* Commands for VRF */
+
+  install_element (VIEW_NODE, &show_ip_route_vrf_cmd);
+  install_element (VIEW_NODE, &show_ip_route_addr_vrf_cmd);
+  install_element (VIEW_NODE, &show_ip_route_prefix_vrf_cmd);
+  install_element (VIEW_NODE, &show_ip_route_prefix_longer_vrf_cmd);
+  install_element (VIEW_NODE, &show_ip_route_protocol_vrf_cmd);
+  install_element (VIEW_NODE, &show_ip_route_supernets_vrf_cmd);
+  install_element (VIEW_NODE, &show_ip_route_summary_vrf_cmd);
+  install_element (VIEW_NODE, &show_ip_route_summary_prefix_vrf_cmd);
+  install_element (ENABLE_NODE, &show_ip_route_vrf_cmd);
+  install_element (ENABLE_NODE, &show_ip_route_addr_vrf_cmd);
+  install_element (ENABLE_NODE, &show_ip_route_prefix_vrf_cmd);
+  install_element (ENABLE_NODE, &show_ip_route_prefix_longer_vrf_cmd);
+  install_element (ENABLE_NODE, &show_ip_route_protocol_vrf_cmd);
+  install_element (ENABLE_NODE, &show_ip_route_supernets_vrf_cmd);
+  install_element (ENABLE_NODE, &show_ip_route_summary_vrf_cmd);
+  install_element (ENABLE_NODE, &show_ip_route_summary_prefix_vrf_cmd);
+
+  install_element (VIEW_NODE, &show_ip_route_vrf_all_cmd);
+  install_element (VIEW_NODE, &show_ip_route_addr_vrf_all_cmd);
+  install_element (VIEW_NODE, &show_ip_route_prefix_vrf_all_cmd);
+  install_element (VIEW_NODE, &show_ip_route_prefix_longer_vrf_all_cmd);
+  install_element (VIEW_NODE, &show_ip_route_protocol_vrf_all_cmd);
+  install_element (VIEW_NODE, &show_ip_route_supernets_vrf_all_cmd);
+  install_element (VIEW_NODE, &show_ip_route_summary_vrf_all_cmd);
+  install_element (VIEW_NODE, &show_ip_route_summary_prefix_vrf_all_cmd);
+  install_element (ENABLE_NODE, &show_ip_route_vrf_all_cmd);
+  install_element (ENABLE_NODE, &show_ip_route_addr_vrf_all_cmd);
+  install_element (ENABLE_NODE, &show_ip_route_prefix_vrf_all_cmd);
+  install_element (ENABLE_NODE, &show_ip_route_prefix_longer_vrf_all_cmd);
+  install_element (ENABLE_NODE, &show_ip_route_protocol_vrf_all_cmd);
+  install_element (ENABLE_NODE, &show_ip_route_supernets_vrf_all_cmd);
+  install_element (ENABLE_NODE, &show_ip_route_summary_vrf_all_cmd);
+  install_element (ENABLE_NODE, &show_ip_route_summary_prefix_vrf_all_cmd);
+
+  install_element (VIEW_NODE, &show_ip_mroute_vrf_cmd);
+  install_element (ENABLE_NODE, &show_ip_mroute_vrf_cmd);
+
+  install_element (VIEW_NODE, &show_ip_mroute_vrf_all_cmd);
+  install_element (ENABLE_NODE, &show_ip_mroute_vrf_all_cmd);
+
+  install_element (VIEW_NODE, &show_ip_rpf_vrf_cmd);
+  install_element (VIEW_NODE, &show_ip_rpf_vrf_all_cmd);
+  install_element (VIEW_NODE, &show_ip_rpf_addr_vrf_cmd);
+  install_element (VIEW_NODE, &show_ip_rpf_addr_vrf_all_cmd);
+  install_element (ENABLE_NODE, &show_ip_rpf_vrf_cmd);
+  install_element (ENABLE_NODE, &show_ip_rpf_vrf_all_cmd);
+  install_element (ENABLE_NODE, &show_ip_rpf_addr_vrf_cmd);
+  install_element (ENABLE_NODE, &show_ip_rpf_addr_vrf_all_cmd);
+
 #ifdef HAVE_IPV6
   install_element (CONFIG_NODE, &ipv6_route_cmd);
   install_element (CONFIG_NODE, &ipv6_route_flags_cmd);
@@ -2464,5 +3488,43 @@ zebra_vty_init (void)
 
   install_element (VIEW_NODE, &show_ipv6_mroute_cmd);
   install_element (ENABLE_NODE, &show_ipv6_mroute_cmd);
+
+  /* Commands for VRF */
+
+  install_element (VIEW_NODE, &show_ipv6_route_vrf_cmd);
+  install_element (VIEW_NODE, &show_ipv6_route_summary_vrf_cmd);
+  install_element (VIEW_NODE, &show_ipv6_route_summary_prefix_vrf_cmd);
+  install_element (VIEW_NODE, &show_ipv6_route_protocol_vrf_cmd);
+  install_element (VIEW_NODE, &show_ipv6_route_addr_vrf_cmd);
+  install_element (VIEW_NODE, &show_ipv6_route_prefix_vrf_cmd);
+  install_element (VIEW_NODE, &show_ipv6_route_prefix_longer_vrf_cmd);
+  install_element (ENABLE_NODE, &show_ipv6_route_vrf_cmd);
+  install_element (ENABLE_NODE, &show_ipv6_route_protocol_vrf_cmd);
+  install_element (ENABLE_NODE, &show_ipv6_route_addr_vrf_cmd);
+  install_element (ENABLE_NODE, &show_ipv6_route_prefix_vrf_cmd);
+  install_element (ENABLE_NODE, &show_ipv6_route_prefix_longer_vrf_cmd);
+  install_element (ENABLE_NODE, &show_ipv6_route_summary_vrf_cmd);
+  install_element (ENABLE_NODE, &show_ipv6_route_summary_prefix_vrf_cmd);
+
+  install_element (VIEW_NODE, &show_ipv6_route_vrf_all_cmd);
+  install_element (VIEW_NODE, &show_ipv6_route_summary_vrf_all_cmd);
+  install_element (VIEW_NODE, &show_ipv6_route_summary_prefix_vrf_all_cmd);
+  install_element (VIEW_NODE, &show_ipv6_route_protocol_vrf_all_cmd);
+  install_element (VIEW_NODE, &show_ipv6_route_addr_vrf_all_cmd);
+  install_element (VIEW_NODE, &show_ipv6_route_prefix_vrf_all_cmd);
+  install_element (VIEW_NODE, &show_ipv6_route_prefix_longer_vrf_all_cmd);
+  install_element (ENABLE_NODE, &show_ipv6_route_vrf_all_cmd);
+  install_element (ENABLE_NODE, &show_ipv6_route_protocol_vrf_all_cmd);
+  install_element (ENABLE_NODE, &show_ipv6_route_addr_vrf_all_cmd);
+  install_element (ENABLE_NODE, &show_ipv6_route_prefix_vrf_all_cmd);
+  install_element (ENABLE_NODE, &show_ipv6_route_prefix_longer_vrf_all_cmd);
+  install_element (ENABLE_NODE, &show_ipv6_route_summary_vrf_all_cmd);
+  install_element (ENABLE_NODE, &show_ipv6_route_summary_prefix_vrf_all_cmd);
+
+  install_element (VIEW_NODE, &show_ipv6_mroute_vrf_cmd);
+  install_element (ENABLE_NODE, &show_ipv6_mroute_vrf_cmd);
+
+  install_element (VIEW_NODE, &show_ipv6_mroute_vrf_all_cmd);
+  install_element (ENABLE_NODE, &show_ipv6_mroute_vrf_all_cmd);
 #endif /* HAVE_IPV6 */
 }
-- 
2.2.2


_______________________________________________
Quagga-dev mailing list
[email protected]
https://lists.quagga.net/mailman/listinfo/quagga-dev

Reply via email to