From e9d94ea7731e49dc5d9d4202b2f6e1226c021c0e Mon Sep 17 00:00:00 2001 From: Donald Sharp Date: Tue, 2 Feb 2016 04:34:29 -0800 Subject: [PATCH] vtysh: Add VRF sub-mode Add the VRF submode to vtysh. Signed-off-by: Vipin Kumar --- vtysh/extract.pl.in | 4 ++- vtysh/vtysh.c | 59 ++++++++++++++++++++++++++++++++++++++++---- vtysh/vtysh.h | 1 + vtysh/vtysh_config.c | 17 +++---------- 4 files changed, 62 insertions(+), 19 deletions(-) diff --git a/vtysh/extract.pl.in b/vtysh/extract.pl.in index da0e4563e1..cee63190be 100755 --- a/vtysh/extract.pl.in +++ b/vtysh/extract.pl.in @@ -32,6 +32,8 @@ EOF $ignore{'"interface IFNAME"'} = "ignore"; $ignore{'"interface IFNAME " "vrf <0-65535>"'} = "ignore"; +$ignore{'"interface IFNAME " "vrf NAME"'} = "ignore"; +$ignore{'"vrf NAME"'} = "ignore"; $ignore{'"ip vrf NAME"'} = "ignore"; $ignore{'"router rip"'} = "ignore"; $ignore{'"router ripng"'} = "ignore"; @@ -41,7 +43,7 @@ $ignore{'"router ospf6"'} = "ignore"; $ignore{'"router babel"'} = "ignore"; $ignore{'"router bgp"'} = "ignore"; $ignore{'"router bgp " "<1-4294967295>"'} = "ignore"; -$ignore{'"router bgp " "<1-4294967295>" " view WORD"'} = "ignore"; +$ignore{'"router bgp " "<1-4294967295>" " (view|vrf) WORD"'} = "ignore"; $ignore{'"router isis WORD"'} = "ignore"; $ignore{'"router zebra"'} = "ignore"; $ignore{'"address-family ipv4"'} = "ignore"; diff --git a/vtysh/vtysh.c b/vtysh/vtysh.c index 5786c68c9b..d0c7104945 100644 --- a/vtysh/vtysh.c +++ b/vtysh/vtysh.c @@ -922,6 +922,12 @@ static struct cmd_node interface_node = "%s(config-if)# ", }; +static struct cmd_node vrf_node = +{ + VRF_NODE, + "%s(config-vrf)# ", +}; + static struct cmd_node rmap_node = { RMAP_NODE, @@ -1051,12 +1057,12 @@ ALIAS_SH (VTYSH_BGPD, ALIAS_SH (VTYSH_BGPD, router_bgp, router_bgp_view_cmd, - "router bgp " CMD_AS_RANGE " view WORD", + "router bgp " CMD_AS_RANGE " (view|vrf) WORD", ROUTER_STR BGP_STR AS_STR - "BGP view\n" - "view name\n") + "BGP view\nBGP VRF\n" + "View/VRF name\n") DEFUNSH (VTYSH_BGPD, address_family_vpnv4, @@ -1308,6 +1314,7 @@ vtysh_exit (struct vty *vty) vty->node = ENABLE_NODE; break; case INTERFACE_NODE: + case VRF_NODE: case ZEBRA_NODE: case BGP_NODE: case RIP_NODE: @@ -1511,8 +1518,8 @@ ALIAS_SH (VTYSH_ZEBRA, vtysh_interface_vrf_cmd, "interface IFNAME " VRF_CMD_STR, "Select an interface to configure\n" - "Interface's name\n" - VRF_CMD_HELP_STR) + "Interface's name\n" + VRF_CMD_HELP_STR) /* TODO Implement "no interface command in isisd. */ DEFSH (VTYSH_ZEBRA|VTYSH_RIPD|VTYSH_RIPNGD|VTYSH_OSPFD|VTYSH_OSPF6D, @@ -1530,6 +1537,38 @@ DEFSH (VTYSH_ZEBRA, "Interface's name\n" VRF_CMD_HELP_STR) +DEFUNSH (VTYSH_VRF, + vtysh_vrf, + vtysh_vrf_cmd, + "vrf NAME", + "Select a VRF to configure\n" + "VRF's name\n") +{ + vty->node = VRF_NODE; + return CMD_SUCCESS; +} + +DEFSH (VTYSH_ZEBRA, + vtysh_no_vrf_cmd, + "no vrf NAME", + NO_STR + "Delete a pseudo vrf's configuration\n" + "VRF's name\n") + +DEFUNSH (VTYSH_VRF, + vtysh_exit_vrf, + vtysh_exit_vrf_cmd, + "exit", + "Exit current mode and down to previous mode\n") +{ + return vtysh_exit (vty); +} + +ALIAS (vtysh_exit_vrf, + vtysh_quit_vrf_cmd, + "quit", + "Exit current mode and down to previous mode\n") + /* TODO Implement interface description commands in ripngd, ospf6d * and isisd. */ DEFSH (VTYSH_ZEBRA|VTYSH_RIPD|VTYSH_OSPFD, @@ -2703,6 +2742,7 @@ vtysh_init_vty (void) install_node (&bgp_node, NULL); install_node (&rip_node, NULL); install_node (&interface_node, NULL); + install_node (&vrf_node, NULL); install_node (&rmap_node, NULL); install_node (&zebra_node, NULL); install_node (&bgp_vpnv4_node, NULL); @@ -2729,6 +2769,7 @@ vtysh_init_vty (void) vtysh_install_default (BGP_NODE); vtysh_install_default (RIP_NODE); vtysh_install_default (INTERFACE_NODE); + vtysh_install_default (VRF_NODE); vtysh_install_default (RMAP_NODE); vtysh_install_default (ZEBRA_NODE); vtysh_install_default (BGP_VPNV4_NODE); @@ -2812,6 +2853,11 @@ vtysh_init_vty (void) install_element (INTERFACE_NODE, &vtysh_end_all_cmd); install_element (INTERFACE_NODE, &vtysh_exit_interface_cmd); install_element (INTERFACE_NODE, &vtysh_quit_interface_cmd); + + install_element (VRF_NODE, &vtysh_end_all_cmd); + install_element (VRF_NODE, &vtysh_exit_vrf_cmd); + install_element (VRF_NODE, &vtysh_quit_vrf_cmd); + install_element (CONFIG_NODE, &router_rip_cmd); #ifdef HAVE_IPV6 install_element (CONFIG_NODE, &router_ripng_cmd); @@ -2856,6 +2902,9 @@ vtysh_init_vty (void) install_element (ENABLE_NODE, &vtysh_write_file_cmd); install_element (ENABLE_NODE, &vtysh_write_cmd); + install_element (CONFIG_NODE, &vtysh_vrf_cmd); + install_element (CONFIG_NODE, &vtysh_no_vrf_cmd); + /* "write terminal" command. */ install_element (ENABLE_NODE, &vtysh_write_terminal_cmd); install_element (ENABLE_NODE, &vtysh_write_terminal_daemon_cmd); diff --git a/vtysh/vtysh.h b/vtysh/vtysh.h index 36128eed03..6126afab7a 100644 --- a/vtysh/vtysh.h +++ b/vtysh/vtysh.h @@ -33,6 +33,7 @@ #define VTYSH_ALL VTYSH_ZEBRA|VTYSH_RIPD|VTYSH_RIPNGD|VTYSH_OSPFD|VTYSH_OSPF6D|VTYSH_BGPD|VTYSH_ISISD|VTYSH_BABELD #define VTYSH_RMAP VTYSH_ZEBRA|VTYSH_RIPD|VTYSH_RIPNGD|VTYSH_OSPFD|VTYSH_OSPF6D|VTYSH_BGPD|VTYSH_BABELD #define VTYSH_INTERFACE VTYSH_ZEBRA|VTYSH_RIPD|VTYSH_RIPNGD|VTYSH_OSPFD|VTYSH_OSPF6D|VTYSH_ISISD|VTYSH_BABELD +#define VTYSH_VRF VTYSH_ZEBRA|VTYSH_RIPD|VTYSH_RIPNGD|VTYSH_OSPFD|VTYSH_OSPF6D|VTYSH_ISISD|VTYSH_BABELD //Pending: see if all other components are to be added. /* vtysh local configuration file. */ #define VTYSH_DEFAULT_CONFIG "vtysh.conf" diff --git a/vtysh/vtysh_config.c b/vtysh/vtysh_config.c index d8a568f769..2fe08f10dc 100644 --- a/vtysh/vtysh_config.c +++ b/vtysh/vtysh_config.c @@ -184,20 +184,9 @@ vtysh_config_parse_line (const char *line) /* Store line to current configuration. */ if (config) { - if (strncmp (line, " address-family vpnv4", - strlen (" address-family vpnv4")) == 0) - config = config_get (BGP_VPNV4_NODE, line); - else if (strncmp (line, " address-family ipv4 multicast", - strlen (" address-family ipv4 multicast")) == 0) - config = config_get (BGP_IPV4M_NODE, line); - else if (strncmp (line, " address-family ipv4", strlen (" address-family ipv4")) == 0 || - strncmp (line, " address-family ipv4 unicast", strlen (" address-family ipv4 unicast")) == 0) - config = config_get (BGP_IPV4_NODE, line); - else if (strncmp (line, " address-family ipv6", strlen (" address-family ipv6")) == 0 || - strncmp (line, " address-family ipv6 unicast", strlen (" address-family ipv6 unicast")) == 0) - config = config_get (BGP_IPV6_NODE, line); - else if (config->index == RMAP_NODE || + if (config->index == RMAP_NODE || config->index == INTERFACE_NODE || + config->index == VRF_NODE || config->index == VTY_NODE) config_add_line_uniq (config->line, line); else @@ -209,6 +198,8 @@ vtysh_config_parse_line (const char *line) default: if (strncmp (line, "interface", strlen ("interface")) == 0) config = config_get (INTERFACE_NODE, line); + else if (strncmp (line, "vrf", strlen ("vrf")) == 0) + config = config_get (VRF_NODE, line); else if (strncmp (line, "router-id", strlen ("router-id")) == 0) config = config_get (ZEBRA_NODE, line); else if (strncmp (line, "router rip", strlen ("router rip")) == 0) -- 2.39.5