diff options
| author | Donald Sharp <sharpd@cumulusnetworks.com> | 2017-05-30 10:58:03 -0400 | 
|---|---|---|
| committer | Donald Sharp <sharpd@cumulusnetworks.com> | 2017-05-30 10:58:03 -0400 | 
| commit | 293067f086565c294862b954bf58e1680d758280 (patch) | |
| tree | cf5ebe06faba962952846ab2dc682cbdd62dadcd /vtysh | |
| parent | 7217de2d8add45e71b49a15df965cc1d26389d5f (diff) | |
| parent | e22ab7727d231ca477eb4f45ffb1950d5e4d12c4 (diff) | |
Merge remote-tracking branch 'origin/master' into babel
Diffstat (limited to 'vtysh')
| -rw-r--r-- | vtysh/Makefile.am | 2 | ||||
| -rw-r--r-- | vtysh/vtysh.c | 168 | ||||
| -rw-r--r-- | vtysh/vtysh.h | 9 | ||||
| -rw-r--r-- | vtysh/vtysh_config.c | 44 | ||||
| -rw-r--r-- | vtysh/vtysh_main.c | 7 | ||||
| -rw-r--r-- | vtysh/vtysh_user.c | 7 | ||||
| -rw-r--r-- | vtysh/vtysh_user.h | 7 | 
7 files changed, 121 insertions, 123 deletions
diff --git a/vtysh/Makefile.am b/vtysh/Makefile.am index 49b96d1b9b..587f72c809 100644 --- a/vtysh/Makefile.am +++ b/vtysh/Makefile.am @@ -47,10 +47,10 @@ if BGPD  vtysh_scan += $(top_srcdir)/bgpd/bgp_bfd.c  vtysh_scan += $(top_srcdir)/bgpd/bgp_debug.c  vtysh_scan += $(top_srcdir)/bgpd/bgp_dump.c -vtysh_scan += $(top_srcdir)/bgpd/bgp_encap.c  vtysh_scan += $(top_srcdir)/bgpd/bgp_evpn_vty.c  vtysh_scan += $(top_srcdir)/bgpd/bgp_filter.c  vtysh_scan += $(top_srcdir)/bgpd/bgp_mplsvpn.c +vtysh_scan += $(top_srcdir)/bgpd/bgp_nexthop.c  vtysh_scan += $(top_srcdir)/bgpd/bgp_route.c  vtysh_scan += $(top_srcdir)/bgpd/bgp_routemap.c  vtysh_scan += $(top_srcdir)/bgpd/bgp_vty.c diff --git a/vtysh/vtysh.c b/vtysh/vtysh.c index 6e0aec2ede..137ce11829 100644 --- a/vtysh/vtysh.c +++ b/vtysh/vtysh.c @@ -13,10 +13,9 @@   * 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> @@ -108,12 +107,9 @@ begins_with(const char *str, const char *prefix)    return strncmp(str, prefix, lenprefix) == 0;  } -/* NB: multiplexed function: - *  if fp == NULL, this calls vtysh_config_parse_line - *  if fp != NULL, this prints lines to fp - */  static int -vtysh_client_run (struct vtysh_client *vclient, const char *line, FILE *fp) +vtysh_client_run (struct vtysh_client *vclient, const char *line, FILE *fp, +                  void (*callback)(void *, const char *), void *cbarg)  {    int ret;    char stackbuf[4096]; @@ -179,8 +175,8 @@ vtysh_client_run (struct vtysh_client *vclient, const char *line, FILE *fp)                fputs (buf, fp);                fputc ('\n', fp);              } -          else -            vtysh_config_parse_line (buf); +          if (callback) +            callback(cbarg, buf);            if (eol == end)              /* \n\0\0\0 */ @@ -224,14 +220,15 @@ out:  static int  vtysh_client_run_all (struct vtysh_client *head_client, const char *line, -                      int continue_on_err, FILE *fp) +                      int continue_on_err, FILE *fp, +                      void (*callback)(void *, const char *), void *cbarg)  {    struct vtysh_client *client;    int rc, rc_all = CMD_SUCCESS;    for (client = head_client; client; client = client->next)      { -      rc = vtysh_client_run(client, line, fp); +      rc = vtysh_client_run(client, line, fp, callback, cbarg);        if (rc != CMD_SUCCESS)          {            if (!continue_on_err) @@ -246,13 +243,13 @@ static int  vtysh_client_execute (struct vtysh_client *head_client, const char *line,                        FILE *fp)  { -  return vtysh_client_run_all (head_client, line, 0, fp); +  return vtysh_client_run_all (head_client, line, 0, fp, NULL, NULL);  }  static void  vtysh_client_config (struct vtysh_client *head_client, char *line)  { -  vtysh_client_run_all (head_client, line, 1, NULL); +  vtysh_client_run_all (head_client, line, 1, NULL, vtysh_config_parse_line, NULL);  }  void @@ -308,7 +305,6 @@ vtysh_execute_func (const char *line, int pager)    if (ret == CMD_SUCCESS || ret == CMD_SUCCESS_DAEMON || ret == CMD_WARNING)      {        if ((saved_node == BGP_VPNV4_NODE || saved_node == BGP_VPNV6_NODE -	   || saved_node == BGP_ENCAP_NODE || saved_node == BGP_ENCAPV6_NODE             || saved_node == BGP_IPV4_NODE  	   || saved_node == BGP_IPV6_NODE || saved_node == BGP_IPV4M_NODE  	   || saved_node == BGP_IPV4L_NODE || saved_node == BGP_IPV6L_NODE @@ -327,7 +323,11 @@ vtysh_execute_func (const char *line, int pager)  	{  	  vtysh_execute("exit-vnc");  	} -      else if ((saved_node == KEYCHAIN_KEY_NODE) && (tried == 1)) +      else if ((saved_node == KEYCHAIN_KEY_NODE +               || saved_node == LDP_PSEUDOWIRE_NODE +               || saved_node == LDP_IPV4_IFACE_NODE +               || saved_node == LDP_IPV6_IFACE_NODE) +               && (tried == 1))  	{  	  vtysh_execute("exit");  	} @@ -645,7 +645,7 @@ vtysh_mark_file (const char *filename)  	}      }    /* This is the end */ -  fprintf(stdout, "end\n"); +  fprintf(stdout, "\nend\n");    vty_close(vty);    XFREE(MTYPE_VTYSH_CMD, vty_buf_copy); @@ -797,6 +797,27 @@ vtysh_rl_describe (void)  		   width,  		   token->text,  		   token->desc); + +        if (IS_VARYING_TOKEN(token->type)) +          { +            const char *ref = vector_slot(vline, vector_active(vline) - 1); + +            vector varcomps = vector_init (VECTOR_MIN_SIZE); +            cmd_variable_complete (token, ref, varcomps); + +            if (vector_active (varcomps) > 0) +              { +                fprintf(stdout, "     "); +                for (size_t j = 0; j < vector_active (varcomps); j++) +                  { +                    char *item = vector_slot (varcomps, j); +                    fprintf (stdout, " %s", item); +                    XFREE (MTYPE_COMPLETION, item); +                  } +                vty_out (vty, "%s", VTY_NEWLINE); +              } +            vector_free (varcomps); +          }        }    cmd_free_strvec (vline); @@ -839,6 +860,7 @@ command_generator (const char *text, int state)      }    if (matched && matched[index]) +    /* this is free()'d by readline, but we leak 1 count of MTYPE_COMPLETION */      return matched[index++];    XFREE (MTYPE_TMP, matched); @@ -926,18 +948,6 @@ static struct cmd_node bgp_vpnv6_node =    "%s(config-router-af)# "  }; -static struct cmd_node bgp_encap_node = -{ -  BGP_ENCAP_NODE, -  "%s(config-router-af)# " -}; - -static struct cmd_node bgp_encapv6_node = -{ -  BGP_ENCAPV6_NODE, -  "%s(config-router-af)# " -}; -  static struct cmd_node bgp_ipv4_node =  {    BGP_IPV4_NODE, @@ -1161,31 +1171,6 @@ DEFUNSH (VTYSH_BGPD,  }  DEFUNSH (VTYSH_BGPD, -         address_family_encapv4, -         address_family_encapv4_cmd, -         "address-family [ipv4] <encap|encapv4>", -         "Enter Address Family command mode\n" -         "Address Family\n" -         "Address Family\n" -         "Address Family\n") -{ -  vty->node = BGP_ENCAP_NODE; -  return CMD_SUCCESS; -} - -DEFUNSH (VTYSH_BGPD, -         address_family_encapv6, -         address_family_encapv6_cmd, -         "address-family [ipv6] encapv6", -         "Enter Address Family command mode\n" -         "Address Family\n" -         "Address Family\n") -{ -  vty->node = BGP_ENCAPV6_NODE; -  return CMD_SUCCESS; -} - -DEFUNSH (VTYSH_BGPD,           address_family_ipv4,           address_family_ipv4_cmd,           "address-family ipv4 [unicast]", @@ -1366,22 +1351,22 @@ DEFUNSH (VTYSH_RIPD,  }  DEFUNSH (VTYSH_RIPD, -	 router_rip, -	 router_rip_cmd, -	 "router rip", -	 ROUTER_STR -	 "RIP") +         router_rip, +         router_rip_cmd, +         "router rip", +         ROUTER_STR +         "RIP\n")  {    vty->node = RIP_NODE;    return CMD_SUCCESS;  }  DEFUNSH (VTYSH_RIPNGD, -	 router_ripng, -	 router_ripng_cmd, -	 "router ripng", -	 ROUTER_STR -	 "RIPng") +         router_ripng, +         router_ripng_cmd, +         "router ripng", +         ROUTER_STR +         "RIPng\n")  {    vty->node = RIPNG_NODE;    return CMD_SUCCESS; @@ -1620,8 +1605,6 @@ vtysh_exit (struct vty *vty)        break;      case BGP_VPNV4_NODE:      case BGP_VPNV6_NODE: -    case BGP_ENCAP_NODE: -    case BGP_ENCAPV6_NODE:      case BGP_IPV4_NODE:      case BGP_IPV4M_NODE:      case BGP_IPV4L_NODE: @@ -1689,8 +1672,6 @@ DEFUNSH (VTYSH_BGPD,        || vty->node == BGP_IPV4L_NODE        || vty->node == BGP_VPNV4_NODE        || vty->node == BGP_VPNV6_NODE -      || vty->node == BGP_ENCAP_NODE -      || vty->node == BGP_ENCAPV6_NODE        || vty->node == BGP_IPV6_NODE        || vty->node == BGP_IPV6L_NODE        || vty->node == BGP_IPV6M_NODE) @@ -3230,6 +3211,40 @@ vtysh_prompt (void)    return buf;  } +static void vtysh_ac_line(void *arg, const char *line) +{ +  vector comps = arg; +  size_t i; +  for (i = 0; i < vector_active(comps); i++) +    if (!strcmp(line, (char *)vector_slot(comps, i))) +      return; +  vector_set(comps, XSTRDUP(MTYPE_COMPLETION, line)); +} + +static void vtysh_autocomplete(vector comps, struct cmd_token *token) +{ +  char accmd[256]; +  size_t i; + +  snprintf(accmd, sizeof(accmd), "autocomplete %d %s %s", token->type, +           token->text, token->varname ? token->varname : "-"); + +  for (i = 0; i < array_size(vtysh_client); i++) +    vtysh_client_run_all (&vtysh_client[i], accmd, 1, NULL, +                          vtysh_ac_line, comps); +} + +static const struct cmd_variable_handler vtysh_var_handler[] = { +    { +        /* match all */ +        .tokenname = NULL, +        .varname = NULL, +        .completions = vtysh_autocomplete +    }, { +        .completions = NULL +    } +}; +  void  vtysh_init_vty (void)  { @@ -3240,6 +3255,7 @@ vtysh_init_vty (void)    /* Initialize commands. */    cmd_init (0); +  cmd_variable_handler_register(vtysh_var_handler);    /* Install nodes. */    install_node (&bgp_node, NULL); @@ -3252,8 +3268,6 @@ vtysh_init_vty (void)    install_node (&zebra_node, NULL);    install_node (&bgp_vpnv4_node, NULL);    install_node (&bgp_vpnv6_node, NULL); -  install_node (&bgp_encap_node, NULL); -  install_node (&bgp_encapv6_node, NULL);    install_node (&bgp_ipv4_node, NULL);    install_node (&bgp_ipv4m_node, NULL);    install_node (&bgp_ipv4l_node, NULL); @@ -3294,8 +3308,6 @@ vtysh_init_vty (void)    vtysh_install_default (ZEBRA_NODE);    vtysh_install_default (BGP_VPNV4_NODE);    vtysh_install_default (BGP_VPNV6_NODE); -  vtysh_install_default (BGP_ENCAP_NODE); -  vtysh_install_default (BGP_ENCAPV6_NODE);    vtysh_install_default (BGP_IPV4_NODE);    vtysh_install_default (BGP_IPV4M_NODE);    vtysh_install_default (BGP_IPV4L_NODE); @@ -3369,10 +3381,6 @@ vtysh_init_vty (void)    install_element (BGP_VPNV4_NODE, &vtysh_quit_bgpd_cmd);    install_element (BGP_VPNV6_NODE, &vtysh_exit_bgpd_cmd);    install_element (BGP_VPNV6_NODE, &vtysh_quit_bgpd_cmd); -  install_element (BGP_ENCAP_NODE, &vtysh_exit_bgpd_cmd); -  install_element (BGP_ENCAP_NODE, &vtysh_quit_bgpd_cmd); -  install_element (BGP_ENCAPV6_NODE, &vtysh_exit_bgpd_cmd); -  install_element (BGP_ENCAPV6_NODE, &vtysh_quit_bgpd_cmd);    install_element (BGP_IPV4_NODE, &vtysh_exit_bgpd_cmd);    install_element (BGP_IPV4_NODE, &vtysh_quit_bgpd_cmd);    install_element (BGP_IPV4M_NODE, &vtysh_exit_bgpd_cmd); @@ -3429,8 +3437,6 @@ vtysh_init_vty (void)    install_element (BGP_IPV4L_NODE, &vtysh_end_all_cmd);    install_element (BGP_VPNV4_NODE, &vtysh_end_all_cmd);    install_element (BGP_VPNV6_NODE, &vtysh_end_all_cmd); -  install_element (BGP_ENCAP_NODE, &vtysh_end_all_cmd); -  install_element (BGP_ENCAPV6_NODE, &vtysh_end_all_cmd);    install_element (BGP_IPV6_NODE, &vtysh_end_all_cmd);    install_element (BGP_IPV6M_NODE, &vtysh_end_all_cmd);    install_element (BGP_IPV6L_NODE, &vtysh_end_all_cmd); @@ -3483,8 +3489,6 @@ vtysh_init_vty (void)    install_element (CONFIG_NODE, &router_bgp_cmd);    install_element (BGP_NODE, &address_family_vpnv4_cmd);    install_element (BGP_NODE, &address_family_vpnv6_cmd); -  install_element (BGP_NODE, &address_family_encapv4_cmd); -  install_element (BGP_NODE, &address_family_encapv6_cmd);  #if defined(ENABLE_BGP_VNC)    install_element (BGP_NODE, &vnc_vrf_policy_cmd);    install_element (BGP_NODE, &vnc_defaults_cmd); @@ -3502,8 +3506,6 @@ vtysh_init_vty (void)    install_element (BGP_NODE, &address_family_evpn_cmd);    install_element (BGP_VPNV4_NODE, &exit_address_family_cmd);    install_element (BGP_VPNV6_NODE, &exit_address_family_cmd); -  install_element (BGP_ENCAP_NODE, &exit_address_family_cmd); -  install_element (BGP_ENCAPV6_NODE, &exit_address_family_cmd);    install_element (BGP_IPV4_NODE, &exit_address_family_cmd);    install_element (BGP_IPV4M_NODE, &exit_address_family_cmd);    install_element (BGP_IPV4L_NODE, &exit_address_family_cmd); diff --git a/vtysh/vtysh.h b/vtysh/vtysh.h index b5f42bdaa0..71a0d876fd 100644 --- a/vtysh/vtysh.h +++ b/vtysh/vtysh.h @@ -13,10 +13,9 @@   * 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   */  #ifndef VTYSH_H @@ -86,7 +85,7 @@ int vtysh_mark_file(const char *filename);  int vtysh_read_config (const char *);  int vtysh_write_config_integrated (void); -void vtysh_config_parse_line (const char *); +void vtysh_config_parse_line (void *, const char *);  void vtysh_config_dump (FILE *); diff --git a/vtysh/vtysh_config.c b/vtysh/vtysh_config.c index a51d42415c..7ca74da10b 100644 --- a/vtysh/vtysh_config.c +++ b/vtysh/vtysh_config.c @@ -1,22 +1,22 @@  /* Configuration generator. -   Copyright (C) 2000 Kunihiro Ishiguro - -This file is part of GNU Zebra. - -GNU Zebra is free software; you can redistribute it and/or modify it -under the terms of the GNU General Public License as published by the -Free Software Foundation; either version 2, or (at your option) any -later version. - -GNU Zebra is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -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.  */ + * Copyright (C) 2000 Kunihiro Ishiguro + * + * This file is part of GNU Zebra. + * + * GNU Zebra is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2, or (at your option) any + * later version. + * + * GNU Zebra is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * 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 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> @@ -145,7 +145,7 @@ config_add_line_uniq (struct list *config, const char *line)  }  void -vtysh_config_parse_line (const char *line) +vtysh_config_parse_line (void *arg, const char *line)  {    char c;    static struct config *config = NULL; @@ -420,12 +420,12 @@ vtysh_config_write ()    if (host.name)      {        sprintf (line, "hostname %s", host.name); -      vtysh_config_parse_line(line); +      vtysh_config_parse_line(NULL, line);      }    if (vtysh_write_integrated == WRITE_INTEGRATED_NO) -    vtysh_config_parse_line ("no service integrated-vtysh-config"); +    vtysh_config_parse_line (NULL, "no service integrated-vtysh-config");    if (vtysh_write_integrated == WRITE_INTEGRATED_YES) -    vtysh_config_parse_line ("service integrated-vtysh-config"); +    vtysh_config_parse_line (NULL, "service integrated-vtysh-config");    user_config_write ();  } diff --git a/vtysh/vtysh_main.c b/vtysh/vtysh_main.c index bf62850e22..d2ac56c366 100644 --- a/vtysh/vtysh_main.c +++ b/vtysh/vtysh_main.c @@ -13,10 +13,9 @@   * 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> diff --git a/vtysh/vtysh_user.c b/vtysh/vtysh_user.c index cce797c932..97720e9fd6 100644 --- a/vtysh/vtysh_user.c +++ b/vtysh/vtysh_user.c @@ -13,10 +13,9 @@   * 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> diff --git a/vtysh/vtysh_user.h b/vtysh/vtysh_user.h index 16fcdd03a5..9d8f4ae62c 100644 --- a/vtysh/vtysh_user.h +++ b/vtysh/vtysh_user.h @@ -13,10 +13,9 @@   * 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   */  #ifndef _VTYSH_USER_H  | 
