]> git.puffer.fish Git - matthieu/frr.git/commitdiff
*: Add vrf autocompletion for commands
authorDonald Sharp <sharpd@cumulusnetworks.com>
Thu, 15 Jun 2017 17:43:26 +0000 (13:43 -0400)
committerDonald Sharp <sharpd@cumulusnetworks.com>
Fri, 16 Jun 2017 17:01:51 +0000 (13:01 -0400)
Switch NAME to VRFNAME and add vrf autocompletion
to commands that have them

Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
lib/if.c
lib/vrf.c
vtysh/vtysh.c
zebra/interface.c
zebra/router-id.c
zebra/zebra_vty.c

index dc417f8e3c2c2af311cb0cfbe8c53f1a7c4ceacf..d4b3d3f7a4a20dae6f261f91afbf16d722b11a7b 100644 (file)
--- a/lib/if.c
+++ b/lib/if.c
@@ -678,7 +678,7 @@ if_sunwzebra_get (const char *name, size_t nlen, vrf_id_t vrf_id)
 
 DEFUN (interface,
        interface_cmd,
-       "interface IFNAME [vrf NAME]",
+       "interface IFNAME [vrf VRFNAME]",
        "Select an interface to configure\n"
        "Interface's name\n"
        VRF_CMD_HELP_STR)
@@ -723,7 +723,7 @@ DEFUN (interface,
 
 DEFUN_NOSH (no_interface,
            no_interface_cmd,
-           "no interface IFNAME [vrf NAME]",
+           "no interface IFNAME [vrf VRFNAME]",
            NO_STR
            "Delete a pseudo interface's configuration\n"
            "Interface's name\n"
@@ -774,7 +774,7 @@ if_cmd_init (void)
 /* For debug purpose. */
 DEFUN (show_address,
        show_address_cmd,
-       "show address [vrf NAME]",
+       "show address [vrf VRFNAME]",
        SHOW_STR
        "address\n"
        VRF_CMD_HELP_STR)
index c4e527db5b69cccfc94a57647ac672c5b7367ecd..dbba67164f28cf11024bb6047317e004dd4529a8 100644 (file)
--- a/lib/vrf.c
+++ b/lib/vrf.c
@@ -377,6 +377,29 @@ vrf_bitmap_check (vrf_bitmap_t bmap, vrf_id_t vrf_id)
                      VRF_BITMAP_FLAG (offset)) ? 1 : 0;
 }
 
+static void
+vrf_autocomplete (vector comps, struct cmd_token *token)
+{
+  struct vrf *vrf = NULL;
+
+  RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name)
+    {
+      if (vrf->vrf_id != 0)
+        vector_set (comps, XSTRDUP (MTYPE_COMPLETION, vrf->name));
+    }
+}
+
+static const struct cmd_variable_handler vrf_var_handlers[] = {
+  {
+    .tokenname = "VRFNAME",
+    .completions = vrf_autocomplete,
+  },
+  {
+    .completions = NULL
+  },
+};
+
+
 /* Initialize VRF module. */
 void
 vrf_init (int (*create)(struct vrf *),
@@ -408,6 +431,8 @@ vrf_init (int (*create)(struct vrf *),
       zlog_err ("vrf_init: failed to enable the default VRF!");
       exit (1);
     }
+
+  cmd_variable_handler_register (vrf_var_handlers);
 }
 
 /* Terminate VRF module. */
@@ -439,7 +464,7 @@ vrf_socket (int domain, int type, int protocol, vrf_id_t vrf_id)
 /* vrf CLI commands */
 DEFUN_NOSH (vrf,
        vrf_cmd,
-       "vrf NAME",
+       "vrf VRFNAME",
        "Select a VRF to configure\n"
        "VRF's name\n")
 {
@@ -464,7 +489,7 @@ DEFUN_NOSH (vrf,
 
 DEFUN_NOSH (no_vrf,
            no_vrf_cmd,
-           "no vrf NAME",
+           "no vrf VRFNAME",
            NO_STR
            "Delete a pseudo VRF's configuration\n"
            "VRF's name\n")
index ffdfd5d7254172ed7294fb6609f772658826e3c2..27077951b0d7d42389cd1bf9a2b3de56d5e7e778 100644 (file)
@@ -1902,7 +1902,7 @@ DEFUNSH (VTYSH_ALL,
 DEFUNSH (VTYSH_INTERFACE,
         vtysh_interface,
         vtysh_interface_cmd,
-        "interface IFNAME [vrf NAME]",
+        "interface IFNAME vrf VRFNAME",
         "Select an interface to configure\n"
         "Interface's name\n"
          VRF_CMD_HELP_STR)
@@ -1921,7 +1921,7 @@ DEFSH (VTYSH_ZEBRA|VTYSH_RIPD|VTYSH_RIPNGD|VTYSH_OSPFD|VTYSH_OSPF6D|VTYSH_EIGRPD
 
 DEFSH (VTYSH_ZEBRA,
        vtysh_no_interface_vrf_cmd,
-       "no interface IFNAME vrf NAME",
+       "no interface IFNAME vrf VRFNAME",
        NO_STR
        "Delete a pseudo interface's configuration\n"
        "Interface's name\n"
@@ -1943,7 +1943,7 @@ DEFUNSH (VTYSH_NS,
 DEFUNSH (VTYSH_VRF,
         vtysh_vrf,
         vtysh_vrf_cmd,
-        "vrf NAME",
+        "vrf VRFNAME",
         "Select a VRF to configure\n"
         "VRF's name\n")
 {
@@ -1953,7 +1953,7 @@ DEFUNSH (VTYSH_VRF,
 
 DEFSH (VTYSH_ZEBRA,
        vtysh_no_vrf_cmd,
-       "no vrf NAME",
+       "no vrf VRFNAME",
        NO_STR
        "Delete a pseudo vrf's configuration\n"
        "VRF's name\n")
index 9393305f06f89e307e8bf3c4d512f034aa30382a..39476c61191796203ec547c442e6fc2fb82af1c4 100644 (file)
@@ -1282,7 +1282,7 @@ struct cmd_node interface_node =
 /* Show all interfaces to vty. */
 DEFUN (show_interface,
        show_interface_cmd,
-       "show interface [vrf NAME]",
+       "show interface [vrf VRFNAME]",
        SHOW_STR
        "Interface status and configuration\n"
        VRF_CMD_HELP_STR)
@@ -1330,7 +1330,7 @@ DEFUN (show_interface_vrf_all,
 
 DEFUN (show_interface_name_vrf,
        show_interface_name_vrf_cmd,
-       "show interface IFNAME vrf NAME",
+       "show interface IFNAME vrf VRFNAME",
        SHOW_STR
        "Interface status and configuration\n"
        "Interface name\n"
@@ -1438,7 +1438,7 @@ if_show_description (struct vty *vty, vrf_id_t vrf_id)
 
 DEFUN (show_interface_desc,
        show_interface_desc_cmd,
-       "show interface description [vrf NAME]",
+       "show interface description [vrf VRFNAME]",
        SHOW_STR
        "Interface status and configuration\n"
        "Interface description\n"
index 318986c1b79c0b8a25649033d5b08ed80d2d9495..f4306ba21efef33fbfa3963c025cf44e568c230a 100644 (file)
@@ -215,7 +215,7 @@ router_id_write (struct vty *vty)
 
 DEFUN (router_id,
        router_id_cmd,
-       "router-id A.B.C.D [vrf NAME]",
+       "router-id A.B.C.D [vrf VRFNAME]",
        "Manually set the router-id\n"
        "IP address to use for router-id\n"
        VRF_CMD_HELP_STR)
@@ -243,7 +243,7 @@ DEFUN (router_id,
 
 DEFUN (no_router_id,
        no_router_id_cmd,
-       "no router-id [A.B.C.D [vrf NAME]]",
+       "no router-id [A.B.C.D [vrf VRFNAME]]",
        NO_STR
        "Remove the manually configured router-id\n"
        "IP address to use for router-id\n"
index 88778e491ba96764e649e0294e86c25d85b2830e..d1ca6d0a392bce39e7ee47135e71ef51fc9a798f 100644 (file)
@@ -395,7 +395,7 @@ zebra_vty_ip_route_tdv_helper (int argc, struct cmd_token *argv[],
 /* Static route configuration.  */
 DEFUN (ip_route,
        ip_route_cmd,
-       "ip route A.B.C.D/M <A.B.C.D|INTERFACE|null0> [tag (1-4294967295)] [(1-255)] [vrf NAME]",
+       "ip route A.B.C.D/M <A.B.C.D|INTERFACE|null0> [tag (1-4294967295)] [(1-255)] [vrf VRFNAME]",
        IP_STR
        "Establish static routes\n"
        "IP destination prefix (e.g. 10.0.0.0/8)\n"
@@ -425,7 +425,7 @@ DEFUN (ip_route,
 
 DEFUN (ip_route_flags,
        ip_route_flags_cmd,
-       "ip route A.B.C.D/M <reject|blackhole> [tag (1-4294967295)] [(1-255)] [vrf NAME]",
+       "ip route A.B.C.D/M <reject|blackhole> [tag (1-4294967295)] [(1-255)] [vrf VRFNAME]",
        IP_STR
        "Establish static routes\n"
        "IP destination prefix (e.g. 10.0.0.0/8)\n"
@@ -456,7 +456,7 @@ DEFUN (ip_route_flags,
 /* Mask as A.B.C.D format.  */
 DEFUN (ip_route_mask,
        ip_route_mask_cmd,
-       "ip route A.B.C.D A.B.C.D <A.B.C.D|INTERFACE|null0> [tag (1-4294967295)] [(1-255)] [vrf NAME]",
+       "ip route A.B.C.D A.B.C.D <A.B.C.D|INTERFACE|null0> [tag (1-4294967295)] [(1-255)] [vrf VRFNAME]",
        IP_STR
        "Establish static routes\n"
        "IP destination prefix\n"
@@ -488,7 +488,7 @@ DEFUN (ip_route_mask,
 
 DEFUN (ip_route_mask_flags,
        ip_route_mask_flags_cmd,
-       "ip route A.B.C.D A.B.C.D <reject|blackhole> [tag (1-4294967295)] [(1-255)] [vrf NAME]",
+       "ip route A.B.C.D A.B.C.D <reject|blackhole> [tag (1-4294967295)] [(1-255)] [vrf VRFNAME]",
        IP_STR
        "Establish static routes\n"
        "IP destination prefix\n"
@@ -520,7 +520,7 @@ DEFUN (ip_route_mask_flags,
 
 DEFUN (no_ip_route,
        no_ip_route_cmd,
-       "no ip route A.B.C.D/M <A.B.C.D|INTERFACE|null0> [tag (1-4294967295)] [(1-255)] [vrf NAME]",
+       "no ip route A.B.C.D/M <A.B.C.D|INTERFACE|null0> [tag (1-4294967295)] [(1-255)] [vrf VRFNAME]",
        NO_STR
        IP_STR
        "Establish static routes\n"
@@ -552,7 +552,7 @@ DEFUN (no_ip_route,
 
 DEFUN (no_ip_route_flags,
        no_ip_route_flags_cmd,
-       "no ip route A.B.C.D/M <reject|blackhole> [tag (1-4294967295)] [(1-255)] [vrf NAME]",
+       "no ip route A.B.C.D/M <reject|blackhole> [tag (1-4294967295)] [(1-255)] [vrf VRFNAME]",
        NO_STR
        IP_STR
        "Establish static routes\n"
@@ -580,7 +580,7 @@ DEFUN (no_ip_route_flags,
 
 DEFUN (no_ip_route_mask,
        no_ip_route_mask_cmd,
-       "no ip route A.B.C.D A.B.C.D <A.B.C.D|INTERFACE|null0> [tag (1-4294967295)] [(1-255)] [vrf NAME]",
+       "no ip route A.B.C.D A.B.C.D <A.B.C.D|INTERFACE|null0> [tag (1-4294967295)] [(1-255)] [vrf VRFNAME]",
        NO_STR
        IP_STR
        "Establish static routes\n"
@@ -614,7 +614,7 @@ DEFUN (no_ip_route_mask,
 
 DEFUN (no_ip_route_mask_flags,
        no_ip_route_mask_flags_cmd,
-       "no ip route A.B.C.D A.B.C.D <reject|blackhole> [tag (1-4294967295)] [(1-255)] [vrf NAME]",
+       "no ip route A.B.C.D A.B.C.D <reject|blackhole> [tag (1-4294967295)] [(1-255)] [vrf VRFNAME]",
        NO_STR
        IP_STR
        "Establish static routes\n"
@@ -1219,7 +1219,7 @@ do_show_ip_route (struct vty *vty, const char *vrf_name, afi_t afi, safi_t safi,
 
 DEFUN (show_ip_nht,
        show_ip_nht_cmd,
-       "show ip nht [vrf NAME]",
+       "show ip nht [vrf VRFNAME]",
        SHOW_STR
        IP_STR
        "IP nexthop tracking table\n"
@@ -1259,7 +1259,7 @@ DEFUN (show_ip_nht_vrf_all,
 
 DEFUN (show_ipv6_nht,
        show_ipv6_nht_cmd,
-       "show ipv6 nht [vrf NAME]",
+       "show ipv6 nht [vrf VRFNAME]",
        SHOW_STR
        IPV6_STR
        "IPv6 nexthop tracking table\n"
@@ -1362,7 +1362,7 @@ DEFUN (no_ipv6_nht_default_route,
 // dwalton one "show ip route" to rule them all
 DEFUN (show_ip_route,
        show_ip_route_cmd,
-       "show ip <fib|route> [vrf NAME] [tag (1-4294967295)|A.B.C.D/M longer-prefixes|supernets-only|" FRR_IP_REDIST_STR_ZEBRA "|ospf (1-65535)] [json]",
+       "show ip <fib|route> [vrf VRFNAME] [tag (1-4294967295)|A.B.C.D/M longer-prefixes|supernets-only|" FRR_IP_REDIST_STR_ZEBRA "|ospf (1-65535)] [json]",
        SHOW_STR
        IP_STR
        "IP forwarding table\n"
@@ -1475,7 +1475,7 @@ DEFUN (show_ip_route,
 
 DEFUN (show_ip_route_addr,
        show_ip_route_addr_cmd,
-       "show ip route [vrf NAME] A.B.C.D",
+       "show ip route [vrf VRFNAME] A.B.C.D",
        SHOW_STR
        IP_STR
        "IP routing table\n"
@@ -1524,7 +1524,7 @@ DEFUN (show_ip_route_addr,
 
 DEFUN (show_ip_route_prefix,
        show_ip_route_prefix_cmd,
-       "show ip route [vrf NAME] A.B.C.D/M",
+       "show ip route [vrf VRFNAME] A.B.C.D/M",
        SHOW_STR
        IP_STR
        "IP routing table\n"
@@ -1724,7 +1724,7 @@ vty_show_ip_route_summary_prefix (struct vty *vty, struct route_table *table)
 /* Show route summary.  */
 DEFUN (show_ip_route_summary,
        show_ip_route_summary_cmd,
-       "show ip route [vrf NAME] summary",
+       "show ip route [vrf VRFNAME] summary",
        SHOW_STR
        IP_STR
        "IP routing table\n"
@@ -1749,7 +1749,7 @@ DEFUN (show_ip_route_summary,
 /* Show route summary prefix.  */
 DEFUN (show_ip_route_summary_prefix,
        show_ip_route_summary_prefix_cmd,
-       "show ip route [vrf NAME] summary prefix",
+       "show ip route [vrf VRFNAME] summary prefix",
        SHOW_STR
        IP_STR
        "IP routing table\n"
@@ -2165,7 +2165,7 @@ static_ipv6_func (struct vty *vty, int add_cmd, const char *dest_str,
 
 DEFUN (ipv6_route,
        ipv6_route_cmd,
-       "ipv6 route X:X::X:X/M [from X:X::X:X/M] <X:X::X:X|INTERFACE|null0> [tag (1-4294967295)] [(1-255)] [vrf NAME]",
+       "ipv6 route X:X::X:X/M [from X:X::X:X/M] <X:X::X:X|INTERFACE|null0> [tag (1-4294967295)] [(1-255)] [vrf VRFNAME]",
        IP_STR
        "Establish static routes\n"
        "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
@@ -2211,7 +2211,7 @@ DEFUN (ipv6_route,
 
 DEFUN (ipv6_route_flags,
        ipv6_route_flags_cmd,
-       "ipv6 route X:X::X:X/M [from X:X::X:X/M] <X:X::X:X|INTERFACE> <reject|blackhole> [tag (1-4294967295)] [(1-255)] [vrf NAME]",
+       "ipv6 route X:X::X:X/M [from X:X::X:X/M] <X:X::X:X|INTERFACE> <reject|blackhole> [tag (1-4294967295)] [(1-255)] [vrf VRFNAME]",
        IP_STR
        "Establish static routes\n"
        "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
@@ -2263,7 +2263,7 @@ DEFUN (ipv6_route_flags,
 
 DEFUN (ipv6_route_ifname,
        ipv6_route_ifname_cmd,
-       "ipv6 route X:X::X:X/M [from X:X::X:X/M] X:X::X:X INTERFACE [tag (1-4294967295)] [(1-255)] [vrf NAME]",
+       "ipv6 route X:X::X:X/M [from X:X::X:X/M] X:X::X:X INTERFACE [tag (1-4294967295)] [(1-255)] [vrf VRFNAME]",
        IP_STR
        "Establish static routes\n"
        "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
@@ -2312,7 +2312,7 @@ DEFUN (ipv6_route_ifname,
 
 DEFUN (ipv6_route_ifname_flags,
        ipv6_route_ifname_flags_cmd,
-       "ipv6 route X:X::X:X/M [from X:X::X:X/M] X:X::X:X INTERFACE <reject|blackhole> [tag (1-4294967295)] [(1-255)] [vrf NAME]",
+       "ipv6 route X:X::X:X/M [from X:X::X:X/M] X:X::X:X INTERFACE <reject|blackhole> [tag (1-4294967295)] [(1-255)] [vrf VRFNAME]",
        IP_STR
        "Establish static routes\n"
        "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
@@ -2366,7 +2366,7 @@ DEFUN (ipv6_route_ifname_flags,
 
 DEFUN (no_ipv6_route,
        no_ipv6_route_cmd,
-       "no ipv6 route X:X::X:X/M [from X:X::X:X/M] <X:X::X:X|INTERFACE|null0> [tag (1-4294967295)] [(1-255)] [vrf NAME]",
+       "no ipv6 route X:X::X:X/M [from X:X::X:X/M] <X:X::X:X|INTERFACE|null0> [tag (1-4294967295)] [(1-255)] [vrf VRFNAME]",
        NO_STR
        IP_STR
        "Establish static routes\n"
@@ -2413,7 +2413,7 @@ DEFUN (no_ipv6_route,
 
 DEFUN (no_ipv6_route_flags,
        no_ipv6_route_flags_cmd,
-       "no ipv6 route X:X::X:X/M [from X:X::X:X/M] <X:X::X:X|INTERFACE> <reject|blackhole> [tag (1-4294967295)] [(1-255)] [vrf NAME]",
+       "no ipv6 route X:X::X:X/M [from X:X::X:X/M] <X:X::X:X|INTERFACE> <reject|blackhole> [tag (1-4294967295)] [(1-255)] [vrf VRFNAME]",
        NO_STR
        IP_STR
        "Establish static routes\n"
@@ -2465,7 +2465,7 @@ DEFUN (no_ipv6_route_flags,
 
 DEFUN (no_ipv6_route_ifname,
        no_ipv6_route_ifname_cmd,
-       "no ipv6 route X:X::X:X/M [from X:X::X:X/M] X:X::X:X INTERFACE [tag (1-4294967295)] [(1-255)] [vrf NAME]",
+       "no ipv6 route X:X::X:X/M [from X:X::X:X/M] X:X::X:X INTERFACE [tag (1-4294967295)] [(1-255)] [vrf VRFNAME]",
        NO_STR
        IP_STR
        "Establish static routes\n"
@@ -2515,7 +2515,7 @@ DEFUN (no_ipv6_route_ifname,
 
 DEFUN (no_ipv6_route_ifname_flags,
        no_ipv6_route_ifname_flags_cmd,
-       "no ipv6 route X:X::X:X/M [from X:X::X:X/M] X:X::X:X INTERFACE <reject|blackhole> [tag (1-4294967295)] [(1-255)] [vrf NAME]",
+       "no ipv6 route X:X::X:X/M [from X:X::X:X/M] X:X::X:X INTERFACE <reject|blackhole> [tag (1-4294967295)] [(1-255)] [vrf VRFNAME]",
        NO_STR
        IP_STR
        "Establish static routes\n"
@@ -2571,7 +2571,7 @@ DEFUN (no_ipv6_route_ifname_flags,
 // dwalton duplicate to here
 DEFUN (show_ipv6_route,
        show_ipv6_route_cmd,
-       "show ipv6 <fib|route> [vrf NAME] [tag (1-4294967295)|X:X::X:X/M longer-prefixes|" FRR_IP6_REDIST_STR_ZEBRA "] [json]",
+       "show ipv6 <fib|route> [vrf VRFNAME] [tag (1-4294967295)|X:X::X:X/M longer-prefixes|" FRR_IP6_REDIST_STR_ZEBRA "] [json]",
        SHOW_STR
        IP_STR
        "IP forwarding table\n"
@@ -2670,7 +2670,7 @@ DEFUN (show_ipv6_route,
 
 DEFUN (show_ipv6_route_addr,
        show_ipv6_route_addr_cmd,
-       "show ipv6 route [vrf NAME] X:X::X:X",
+       "show ipv6 route [vrf VRFNAME] X:X::X:X",
        SHOW_STR
        IP_STR
        "IPv6 routing table\n"
@@ -2719,7 +2719,7 @@ DEFUN (show_ipv6_route_addr,
 
 DEFUN (show_ipv6_route_prefix,
        show_ipv6_route_prefix_cmd,
-       "show ipv6 route [vrf NAME] X:X::X:X/M",
+       "show ipv6 route [vrf VRFNAME] X:X::X:X/M",
        SHOW_STR
        IP_STR
        "IPv6 routing table\n"
@@ -2768,7 +2768,7 @@ DEFUN (show_ipv6_route_prefix,
 /* Show route summary.  */
 DEFUN (show_ipv6_route_summary,
        show_ipv6_route_summary_cmd,
-       "show ipv6 route [vrf NAME] summary",
+       "show ipv6 route [vrf VRFNAME] summary",
        SHOW_STR
        IP_STR
        "IPv6 routing table\n"
@@ -2794,7 +2794,7 @@ DEFUN (show_ipv6_route_summary,
 /* Show ipv6 route summary prefix.  */
 DEFUN (show_ipv6_route_summary_prefix,
        show_ipv6_route_summary_prefix_cmd,
-       "show ipv6 route [vrf NAME] summary prefix",
+       "show ipv6 route [vrf VRFNAME] summary prefix",
        SHOW_STR
        IP_STR
        "IPv6 routing table\n"
@@ -2824,7 +2824,7 @@ DEFUN (show_ipv6_route_summary_prefix,
  */
 DEFUN (show_ipv6_mroute,
        show_ipv6_mroute_cmd,
-       "show ipv6 mroute [vrf NAME]",
+       "show ipv6 mroute [vrf VRFNAME]",
        SHOW_STR
        IP_STR
        "IPv6 Multicast routing table\n"