From e7168df4eff0d377621c45deb32cfcfa72e0dd83 Mon Sep 17 00:00:00 2001 From: hasso Date: Sun, 3 Oct 2004 20:11:32 +0000 Subject: Big vtysh cleanup. See changelogs for details. --- doc/ChangeLog | 5 + doc/vtysh.1 | 13 +-- lib/ChangeLog | 7 ++ lib/command.c | 30 +++--- lib/command.h | 1 + lib/vty.c | 1 + vtysh/ChangeLog | 25 +++++ vtysh/Makefile.am | 8 +- vtysh/extract.pl.in | 8 ++ vtysh/vtysh.c | 256 ++++++++++++++++++++++++++++++++++-------------- vtysh/vtysh.conf.sample | 7 +- vtysh/vtysh.h | 2 +- vtysh/vtysh_config.c | 88 +++++++---------- vtysh/vtysh_main.c | 33 +++---- 14 files changed, 307 insertions(+), 177 deletions(-) diff --git a/doc/ChangeLog b/doc/ChangeLog index bb2e4771..625b2a74 100644 --- a/doc/ChangeLog +++ b/doc/ChangeLog @@ -1,3 +1,8 @@ +2004-10-03 Hasso Tepper + + * vtysh.1: Update vtysh man page to reflect changes in shell. Remove + info about -f command line switch. + 2004-09-11 Paul Jakma * quagga.texi: Update copyright. Contents should be at beginning diff --git a/doc/vtysh.1 b/doc/vtysh.1 index 90aaff1b..e5fccb11 100644 --- a/doc/vtysh.1 +++ b/doc/vtysh.1 @@ -1,22 +1,14 @@ -.TH VTYSH 1 "27 August 2004" "Quagga VTY shell" "Version 0.96.5" +.TH VTYSH 1 "3 October 2004" "Quagga VTY shell" "Version 0.96.5" .SH NAME vtysh \- a integrated shell for Quagga routing software .SH SYNOPSIS .B vtysh [ -.B \-f -.I config-file -] -[ .B \-b ] .br .B vtysh [ -.B \-f -.I config-file -] -[ .B \-c .I command ] @@ -44,9 +36,6 @@ etc. .IP "\fB\-e, \-\-execute \fIcommand\fP" Alias for -c. It's here only for compatibility with Zebra routing software and older Quagga versions. This will be removed in future. -.IP "\fB\-f, \-\-config-file \fIconfig-file\fP" -Specifies the config file to use for startup. If not specified this option will -likely default to \fB\fI/usr/local/etc/vtysh.conf\fR. .IP "\fB\-h, \-\-help\fP" Display a usage message on standard output and exit. .SH ENVIRONMENT VARIABLES diff --git a/lib/ChangeLog b/lib/ChangeLog index e92147f3..3049b95a 100644 --- a/lib/ChangeLog +++ b/lib/ChangeLog @@ -1,3 +1,10 @@ +2004-10-03 Hasso Tepper + + * command.h: Introduce SERVICE_NODE for "service <...>" commands. + * command.c: Don't initialize commands that don't make sense if vtysh + is used. + * vty.c: Make VTY_NODE appear in vtysh. + 2004-10-03 James R. Leu * zclient.c, zclient.h: zclient functions for router id handling. diff --git a/lib/command.c b/lib/command.c index 2ed62526..a4cf9ebf 100644 --- a/lib/command.c +++ b/lib/command.c @@ -3300,23 +3300,22 @@ cmd_init (int terminal) } install_element (ENABLE_NODE, &show_startup_config_cmd); install_element (ENABLE_NODE, &show_version_cmd); - if (terminal) - { - install_element (ENABLE_NODE, &config_terminal_length_cmd); - install_element (ENABLE_NODE, &config_terminal_no_length_cmd); - } - if (terminal) - install_default (CONFIG_NODE); - install_element (CONFIG_NODE, &hostname_cmd); - install_element (CONFIG_NODE, &no_hostname_cmd); - install_element (CONFIG_NODE, &password_cmd); - install_element (CONFIG_NODE, &password_text_cmd); - install_element (CONFIG_NODE, &enable_password_cmd); - install_element (CONFIG_NODE, &enable_password_text_cmd); - install_element (CONFIG_NODE, &no_enable_password_cmd); if (terminal) { + install_element (ENABLE_NODE, &config_terminal_length_cmd); + install_element (ENABLE_NODE, &config_terminal_no_length_cmd); + + install_default (CONFIG_NODE); + + install_element (CONFIG_NODE, &hostname_cmd); + install_element (CONFIG_NODE, &no_hostname_cmd); + install_element (CONFIG_NODE, &password_cmd); + install_element (CONFIG_NODE, &password_text_cmd); + install_element (CONFIG_NODE, &enable_password_cmd); + install_element (CONFIG_NODE, &enable_password_text_cmd); + install_element (CONFIG_NODE, &no_enable_password_cmd); + install_element (CONFIG_NODE, &config_log_stdout_cmd); install_element (CONFIG_NODE, &no_config_log_stdout_cmd); install_element (CONFIG_NODE, &config_log_file_cmd); @@ -3335,10 +3334,7 @@ cmd_init (int terminal) install_element (CONFIG_NODE, &no_banner_motd_cmd); install_element (CONFIG_NODE, &service_terminal_length_cmd); install_element (CONFIG_NODE, &no_service_terminal_length_cmd); - } - if (terminal) - { install_element(VIEW_NODE, &show_thread_cpu_cmd); install_element(ENABLE_NODE, &show_thread_cpu_cmd); } diff --git a/lib/command.h b/lib/command.h index 32a347fc..d1648d68 100644 --- a/lib/command.h +++ b/lib/command.h @@ -71,6 +71,7 @@ enum node_type AUTH_ENABLE_NODE, /* Authentication mode for change enable. */ ENABLE_NODE, /* Enable node. */ CONFIG_NODE, /* Config node. Default mode of config file. */ + SERVICE_NODE, /* Service node. */ DEBUG_NODE, /* Debug node. */ AAA_NODE, /* AAA node. */ KEYCHAIN_NODE, /* Key-chain node. */ diff --git a/lib/vty.c b/lib/vty.c index fdd5bbdb..3e799b88 100644 --- a/lib/vty.c +++ b/lib/vty.c @@ -2670,6 +2670,7 @@ struct cmd_node vty_node = { VTY_NODE, "%s(config-line)# ", + 1, }; /* Reset all VTY status. */ diff --git a/vtysh/ChangeLog b/vtysh/ChangeLog index bca51bbc..5d8b7e44 100644 --- a/vtysh/ChangeLog +++ b/vtysh/ChangeLog @@ -1,3 +1,28 @@ +2004-10-03 Hasso Tepper + + * vtsyh_main.c: Enter into enable node by default. Disable node doesn't + make sense if we don't have any authentication for enable. + * vtysh.c: Implement "show running-daemons" command. + * vtysh.c: Use either integrated conf or daemon conf not both. Move + configuration command into "service" level. + * vtysh.c: Remove "write ..." commands from other nodes than enable. + We have "do ..." extension for that. + * vtysh_config.c, vtysh.c: Integrate vtysh configuration into + integrated one. + * vtysh_config.c: Use FORWARD_NODE and SERVICE_NODE vty nodes. + * vtysh_config.c: Make "service" lines unique in integrated config. + * vtysh.c: Make "service password-encryption" command work in vtysh. + * vtysh_config.c, vtysh.c, Makefile.am, extract.pl.in: Introduce line + vty commands in vtysh. Parse lib/vty.c for commands, but ignore + commands that don't make sense in vtysh. Closes Bugzilla #104. + * vtysh.c: Make "[enable] password" commands work in vtysh. Behavior + is similar to "log" commands - vtysh just passes commands to all + daemons. + * vtysh_main.c, vtysh_config.c, vtysh.h: Remove any code dealing with + configuration files specified from command line. We read/write files + from/to system location only (ie. remove -f again). + * Makefile.am: Parse zebra/router-id.c. + 2004-09-26 Hasso Tepper * vtysh.c: Fix compiler warning. diff --git a/vtysh/Makefile.am b/vtysh/Makefile.am index 1ac5ee45..830ed809 100644 --- a/vtysh/Makefile.am +++ b/vtysh/Makefile.am @@ -24,13 +24,13 @@ rebuild4: vtysh_cmd.c: $(top_srcdir)/ripd/*.c $(top_srcdir)/ripngd/*.c $(top_srcdir)/ospfd/*.c $(top_srcdir)/ospf6d/*.c \ $(top_srcdir)/isisd/*.c $(top_srcdir)/bgpd/*.c $(top_srcdir)/lib/keychain.c $(top_srcdir)/lib/routemap.c \ $(top_srcdir)/lib/filter.c $(top_srcdir)/lib/plist.c $(top_srcdir)/lib/distribute.c $(top_srcdir)/lib/if_rmap.c \ - $(top_srcdir)/zebra/debug.c $(top_srcdir)/zebra/interface.c \ + $(top_srcdir)/lib/vty.c $(top_srcdir)/zebra/debug.c $(top_srcdir)/zebra/interface.c \ $(top_srcdir)/zebra/irdp_interface.c $(top_srcdir)/zebra/rtadv.c $(top_srcdir)/zebra/zebra_vty.c \ - $(top_srcdir)/zebra/zserv.c + $(top_srcdir)/zebra/zserv.c $(top_srcdir)/zebra/router-id.c ./extract.pl $(top_srcdir)/ripd/*.c $(top_srcdir)/ripngd/*.c $(top_srcdir)/ospfd/*.c $(top_srcdir)/ospf6d/*.c \ $(top_srcdir)/isisd/*.c $(top_srcdir)/bgpd/*.c $(top_srcdir)/lib/keychain.c $(top_srcdir)/lib/routemap.c \ $(top_srcdir)/lib/filter.c $(top_srcdir)/lib/plist.c $(top_srcdir)/lib/distribute.c $(top_srcdir)/lib/if_rmap.c \ - $(top_srcdir)/zebra/debug.c $(top_srcdir)/zebra/interface.c \ + $(top_srcdir)/lib/vty.c $(top_srcdir)/zebra/debug.c $(top_srcdir)/zebra/interface.c \ $(top_srcdir)/zebra/irdp_interface.c $(top_srcdir)/zebra/rtadv.c $(top_srcdir)/zebra/zebra_vty.c \ - $(top_srcdir)/zebra/zserv.c > vtysh_cmd.c + $(top_srcdir)/zebra/zserv.c $(top_srcdir)/zebra/router-id.c > vtysh_cmd.c diff --git a/vtysh/extract.pl.in b/vtysh/extract.pl.in index 053b17e9..d2fc42ba 100755 --- a/vtysh/extract.pl.in +++ b/vtysh/extract.pl.in @@ -52,6 +52,11 @@ $ignore{'"key chain WORD"'} = "ignore"; $ignore{'"key <0-2147483647>"'} = "ignore"; $ignore{'"route-map WORD (deny|permit) <1-65535>"'} = "ignore"; $ignore{'"show route-map"'} = "ignore"; +$ignore{'"line vty"'} = "ignore"; +$ignore{'"who"'} = "ignore"; +$ignore{'"terminal monitor"'} = "ignore"; +$ignore{'"terminal no monitor"'} = "ignore"; +$ignore{'"show history"'} = "ignore"; foreach (@ARGV) { $file = $_; @@ -118,6 +123,9 @@ foreach (@ARGV) { $protocol = "VTYSH_RIPD"; } } + if ($file =~ /vty.c/) { + $protocol = "VTYSH_ALL"; + } } else { ($protocol) = ($file =~ /^.*\/([a-z0-9]+)\/[a-zA-Z0-9_\-]+\.c$/); $protocol = "VTYSH_" . uc $protocol; diff --git a/vtysh/vtysh.c b/vtysh/vtysh.c index ba49edee..79e07420 100644 --- a/vtysh/vtysh.c +++ b/vtysh/vtysh.c @@ -46,6 +46,11 @@ struct vtysh_client int fd; } vtysh_client[VTYSH_INDEX_MAX]; +/* Using integrated config from Quagga.conf. Default is no. */ +int vtysh_writeconfig_integrated = 0; + +extern char config_default[]; + void vclient_close (struct vtysh_client *vclient) { @@ -148,6 +153,7 @@ vtysh_client_config (struct vtysh_client *vclient, char *line) } /* Parse anything left in the buffer. */ + vtysh_config_parse (buf); XFREE(MTYPE_TMP, buf); @@ -756,6 +762,9 @@ struct cmd_node keychain_key_node = "%s(config-keychain-key)# " }; +/* Defined in lib/vty.c */ +extern struct cmd_node vty_node; + /* When '^Z' is received from vty, move down to the enable mode. */ int vtysh_end () @@ -777,7 +786,7 @@ DEFUNSH (VTYSH_ALL, vtysh_end_all, vtysh_end_all_cmd, "end", - "End current mode and down to previous mode\n") + "End current mode and change to enable mode\n") { return vtysh_end (); } @@ -957,6 +966,17 @@ DEFUNSH (VTYSH_RMAP, return CMD_SUCCESS; } +DEFUNSH (VTYSH_ALL, + vtysh_line_vty, + vtysh_line_vty_cmd, + "line vty", + "Configure a terminal line\n" + "Virtual terminal\n") +{ + vty->node = VTY_NODE; + return CMD_SUCCESS; +} + DEFUNSH (VTYSH_ALL, vtysh_enable, vtysh_enable_cmd, @@ -1172,6 +1192,20 @@ ALIAS (vtysh_exit_isisd, "quit", "Exit current mode and down to previous mode\n") +DEFUNSH (VTYSH_ALL, + vtysh_exit_line_vty, + vtysh_exit_line_vty_cmd, + "exit", + "Exit current mode and down to previous mode\n") +{ + return vtysh_exit (vty); +} + +ALIAS (vtysh_exit_line_vty, + vtysh_quit_line_vty_cmd, + "quit", + "Exit current mode and down to previous mode\n") + DEFUNSH (VTYSH_INTERFACE, vtysh_interface, vtysh_interface_cmd, @@ -1328,6 +1362,84 @@ DEFUNSH (VTYSH_ALL, return CMD_SUCCESS; } +DEFUNSH (VTYSH_ALL, + vtysh_service_password_encrypt, + vtysh_service_password_encrypt_cmd, + "service password-encryption", + "Set up miscellaneous service\n" + "Enable encrypted passwords\n") +{ + return CMD_SUCCESS; +} + +DEFUNSH (VTYSH_ALL, + no_vtysh_service_password_encrypt, + no_vtysh_service_password_encrypt_cmd, + "no service password-encryption", + NO_STR + "Set up miscellaneous service\n" + "Enable encrypted passwords\n") +{ + return CMD_SUCCESS; +} + +DEFUNSH (VTYSH_ALL, + vtysh_config_password, + vtysh_password_cmd, + "password (8|) WORD", + "Assign the terminal connection password\n" + "Specifies a HIDDEN password will follow\n" + "dummy string \n" + "The HIDDEN line password string\n") +{ + return CMD_SUCCESS; +} + +DEFUNSH (VTYSH_ALL, + vtysh_password_text, + vtysh_password_text_cmd, + "password LINE", + "Assign the terminal connection password\n" + "The UNENCRYPTED (cleartext) line password\n") +{ + return CMD_SUCCESS; +} + +DEFUNSH (VTYSH_ALL, + vtysh_config_enable_password, + vtysh_enable_password_cmd, + "enable password (8|) WORD", + "Modify enable password parameters\n" + "Assign the privileged level password\n" + "Specifies a HIDDEN password will follow\n" + "dummy string \n" + "The HIDDEN 'enable' password string\n") +{ + return CMD_SUCCESS; +} + +DEFUNSH (VTYSH_ALL, + vtysh_enable_password_text, + vtysh_enable_password_text_cmd, + "enable password LINE", + "Modify enable password parameters\n" + "Assign the privileged level password\n" + "The UNENCRYPTED (cleartext) 'enable' password\n") +{ + return CMD_SUCCESS; +} + +DEFUNSH (VTYSH_ALL, + no_vtysh_config_enable_password, + no_vtysh_enable_password_cmd, + "no enable password", + NO_STR + "Modify enable password parameters\n" + "Assign the privileged level password\n") +{ + return CMD_SUCCESS; +} + DEFUN (vtysh_write_terminal, vtysh_write_terminal_cmd, "write terminal", @@ -1353,8 +1465,7 @@ DEFUN (vtysh_write_terminal, vty_out (vty, "Building configuration...%s", VTY_NEWLINE); vty_out (vty, "%sCurrent configuration:%s", VTY_NEWLINE, VTY_NEWLINE); - - vtysh_config_write (fp); + vty_out (vty, "!%s", VTY_NEWLINE); ret = vtysh_client_config (&vtysh_client[VTYSH_INDEX_ZEBRA], line); ret = vtysh_client_config (&vtysh_client[VTYSH_INDEX_RIP], line); @@ -1364,6 +1475,9 @@ DEFUN (vtysh_write_terminal, ret = vtysh_client_config (&vtysh_client[VTYSH_INDEX_BGP], line); ret = vtysh_client_config (&vtysh_client[VTYSH_INDEX_ISIS], line); + /* Integrate vtysh specific configuration. */ + vtysh_config_write (); + vtysh_config_dump (fp); if (vtysh_pager_name && fp) @@ -1380,37 +1494,25 @@ DEFUN (vtysh_write_terminal, return CMD_SUCCESS; } -struct vtysh_writeconfig_t { - int daemon; - int integrated; -} vtysh_wc = {-1,0}; - -DEFUN (vtysh_write_config, - vtysh_write_config_cmd, - "write-config (daemon|integrated)", - "Specify config files to write to\n" - "Write per daemon file\n" - "Write integrated file\n") +DEFUN (vtysh_integrated_config, + vtysh_integrated_config_cmd, + "service integrated-vtysh-config", + "Set up miscellaneous service\n" + "Write configuration into integrated file\n") { - if (!strncmp(argv[0],"d",1)) - vtysh_wc.daemon = 1; - else if (!strncmp(argv[0],"i",1)) - vtysh_wc.integrated = 1; - - return CMD_SUCCESS; + vtysh_writeconfig_integrated = 1; + return CMD_SUCCESS; } -DEFUN (no_vtysh_write_config, - no_vtysh_write_config_cmd, - "no write-config (daemon|integrated)", - "Negate per daemon and/or integrated config files\n") +DEFUN (no_vtysh_integrated_config, + no_vtysh_integrated_config_cmd, + "no service integrated-vtysh-config", + NO_STR + "Set up miscellaneous service\n" + "Write configuration into integrated file\n") { - if (!strncmp(argv[0],"d",1)) - vtysh_wc.daemon = 0; - else if (!strncmp(argv[0],"i",1)) - vtysh_wc.integrated = 0; - - return CMD_SUCCESS; + vtysh_writeconfig_integrated = 0; + return CMD_SUCCESS; } int write_config_integrated(void) @@ -1440,8 +1542,6 @@ int write_config_integrated(void) return CMD_SUCCESS; } - vtysh_config_write (fp); - ret = vtysh_client_config (&vtysh_client[VTYSH_INDEX_ZEBRA], line); ret = vtysh_client_config (&vtysh_client[VTYSH_INDEX_RIP], line); ret = vtysh_client_config (&vtysh_client[VTYSH_INDEX_RIPNG], line); @@ -1476,13 +1576,13 @@ DEFUN (vtysh_write_memory, { int ret = CMD_SUCCESS; char line[] = "write memory\n"; + char *vtysh_conf; + extern struct host host; + FILE *fp; - /* If integrated Zebra.conf explicitely set. */ - if (vtysh_wc.integrated == 1) - ret = write_config_integrated(); - - if (!vtysh_wc.daemon) - return ret; + /* If integrated Quagga.conf explicitely set. */ + if (vtysh_writeconfig_integrated) + return write_config_integrated(); fprintf (stdout,"Building Configuration...\n"); @@ -1493,7 +1593,7 @@ DEFUN (vtysh_write_memory, ret = vtysh_client_execute (&vtysh_client[VTYSH_INDEX_OSPF6], line, stdout); ret = vtysh_client_execute (&vtysh_client[VTYSH_INDEX_BGP], line, stdout); ret = vtysh_client_execute (&vtysh_client[VTYSH_INDEX_ISIS], line, stdout); - + fprintf (stdout,"[OK]\n"); return ret; @@ -1573,6 +1673,31 @@ DEFUN (vtysh_terminal_no_length, return CMD_SUCCESS; } +DEFUN (vtysh_show_running_daemons, + vtysh_show_running_daemons_cmd, + "show running-daemons", + SHOW_STR + "Show list of running daemons\n") +{ + if ( vtysh_client[VTYSH_INDEX_ZEBRA].fd > 0 ) + vty_out(vty, " zebra"); + if ( vtysh_client[VTYSH_INDEX_RIP].fd > 0 ) + vty_out(vty, " ripd"); + if ( vtysh_client[VTYSH_INDEX_RIPNG].fd > 0 ) + vty_out(vty, " ripngd"); + if ( vtysh_client[VTYSH_INDEX_OSPF].fd > 0 ) + vty_out(vty, " ospfd"); + if ( vtysh_client[VTYSH_INDEX_OSPF6].fd > 0 ) + vty_out(vty, " ospf6d"); + if ( vtysh_client[VTYSH_INDEX_BGP].fd > 0 ) + vty_out(vty, " bgpd"); + if ( vtysh_client[VTYSH_INDEX_ISIS].fd > 0 ) + vty_out(vty, " isisd"); + vty_out(vty, "%s", VTY_NEWLINE); + + return CMD_SUCCESS; +} + /* Execute command in child process. */ int execute_command (char *command, int argc, char *arg1, char *arg2) @@ -1898,6 +2023,7 @@ vtysh_init_vty () install_node (&keychain_node, NULL); install_node (&keychain_key_node, NULL); install_node (&isis_node, NULL); + install_node (&vty_node, NULL); vtysh_install_default (VIEW_NODE); vtysh_install_default (ENABLE_NODE); @@ -1917,6 +2043,7 @@ vtysh_init_vty () vtysh_install_default (ISIS_NODE); vtysh_install_default (KEYCHAIN_NODE); vtysh_install_default (KEYCHAIN_KEY_NODE); + vtysh_install_default (VTY_NODE); install_element (VIEW_NODE, &vtysh_enable_cmd); install_element (ENABLE_NODE, &vtysh_config_terminal_cmd); @@ -1955,6 +2082,8 @@ vtysh_init_vty () install_element (KEYCHAIN_KEY_NODE, &vtysh_quit_ripd_cmd); install_element (RMAP_NODE, &vtysh_exit_rmap_cmd); install_element (RMAP_NODE, &vtysh_quit_rmap_cmd); + install_element (VTY_NODE, &vtysh_exit_line_vty_cmd); + install_element (VTY_NODE, &vtysh_quit_line_vty_cmd); /* "end" command. */ install_element (CONFIG_NODE, &vtysh_end_all_cmd); @@ -1972,6 +2101,7 @@ vtysh_init_vty () install_element (KEYCHAIN_NODE, &vtysh_end_all_cmd); install_element (KEYCHAIN_KEY_NODE, &vtysh_end_all_cmd); install_element (RMAP_NODE, &vtysh_end_all_cmd); + install_element (VTY_NODE, &vtysh_end_all_cmd); install_element (INTERFACE_NODE, &interface_desc_cmd); install_element (INTERFACE_NODE, &no_interface_desc_cmd); @@ -2002,6 +2132,7 @@ vtysh_init_vty () install_element (BGP_IPV6_NODE, &exit_address_family_cmd); install_element (CONFIG_NODE, &key_chain_cmd); install_element (CONFIG_NODE, &route_map_cmd); + install_element (CONFIG_NODE, &vtysh_line_vty_cmd); install_element (KEYCHAIN_NODE, &key_cmd); install_element (KEYCHAIN_NODE, &key_chain_cmd); install_element (KEYCHAIN_KEY_NODE, &key_chain_cmd); @@ -2014,44 +2145,19 @@ vtysh_init_vty () /* "write terminal" command. */ install_element (ENABLE_NODE, &vtysh_write_terminal_cmd); - install_element (CONFIG_NODE, &vtysh_write_terminal_cmd); - install_element (BGP_NODE, &vtysh_write_terminal_cmd); - install_element (BGP_VPNV4_NODE, &vtysh_write_terminal_cmd); - install_element (BGP_IPV4_NODE, &vtysh_write_terminal_cmd); - install_element (BGP_IPV4M_NODE, &vtysh_write_terminal_cmd); - install_element (BGP_IPV6_NODE, &vtysh_write_terminal_cmd); - install_element (RIP_NODE, &vtysh_write_terminal_cmd); - install_element (RIPNG_NODE, &vtysh_write_terminal_cmd); - install_element (OSPF_NODE, &vtysh_write_terminal_cmd); - install_element (OSPF6_NODE, &vtysh_write_terminal_cmd); - install_element (ISIS_NODE, &vtysh_write_terminal_cmd); - install_element (INTERFACE_NODE, &vtysh_write_terminal_cmd); - install_element (RMAP_NODE, &vtysh_write_terminal_cmd); - install_element (KEYCHAIN_NODE, &vtysh_write_terminal_cmd); - install_element (KEYCHAIN_KEY_NODE, &vtysh_write_terminal_cmd); + + install_element (CONFIG_NODE, &vtysh_integrated_config_cmd); + install_element (CONFIG_NODE, &no_vtysh_integrated_config_cmd); /* "write memory" command. */ install_element (ENABLE_NODE, &vtysh_write_memory_cmd); - install_element (CONFIG_NODE, &vtysh_write_memory_cmd); - install_element (BGP_NODE, &vtysh_write_memory_cmd); - install_element (BGP_VPNV4_NODE, &vtysh_write_memory_cmd); - install_element (BGP_IPV4_NODE, &vtysh_write_memory_cmd); - install_element (BGP_IPV4M_NODE, &vtysh_write_memory_cmd); - install_element (BGP_IPV6_NODE, &vtysh_write_memory_cmd); - install_element (RIP_NODE, &vtysh_write_memory_cmd); - install_element (RIPNG_NODE, &vtysh_write_memory_cmd); - install_element (OSPF_NODE, &vtysh_write_memory_cmd); - install_element (OSPF6_NODE, &vtysh_write_memory_cmd); - install_element (ISIS_NODE, &vtysh_write_memory_cmd); - install_element (INTERFACE_NODE, &vtysh_write_memory_cmd); - install_element (RMAP_NODE, &vtysh_write_memory_cmd); - install_element (KEYCHAIN_NODE, &vtysh_write_memory_cmd); - install_element (KEYCHAIN_KEY_NODE, &vtysh_write_memory_cmd); install_element (VIEW_NODE, &vtysh_terminal_length_cmd); install_element (ENABLE_NODE, &vtysh_terminal_length_cmd); install_element (VIEW_NODE, &vtysh_terminal_no_length_cmd); install_element (ENABLE_NODE, &vtysh_terminal_no_length_cmd); + install_element (VIEW_NODE, &vtysh_show_running_daemons_cmd); + install_element (ENABLE_NODE, &vtysh_show_running_daemons_cmd); install_element (VIEW_NODE, &vtysh_ping_cmd); install_element (VIEW_NODE, &vtysh_ping_ip_cmd); @@ -2089,6 +2195,14 @@ vtysh_init_vty () install_element (CONFIG_NODE, &no_vtysh_log_trap_cmd); install_element (CONFIG_NODE, &vtysh_log_record_priority_cmd); install_element (CONFIG_NODE, &no_vtysh_log_record_priority_cmd); - install_element (CONFIG_NODE, &vtysh_write_config_cmd); - install_element (CONFIG_NODE, &no_vtysh_write_config_cmd); + + install_element (CONFIG_NODE, &vtysh_service_password_encrypt_cmd); + install_element (CONFIG_NODE, &no_vtysh_service_password_encrypt_cmd); + + install_element (CONFIG_NODE, &vtysh_password_cmd); + install_element (CONFIG_NODE, &vtysh_password_text_cmd); + install_element (CONFIG_NODE, &vtysh_enable_password_cmd); + install_element (CONFIG_NODE, &vtysh_enable_password_text_cmd); + install_element (CONFIG_NODE, &no_vtysh_enable_password_cmd); + } diff --git a/vtysh/vtysh.conf.sample b/vtysh/vtysh.conf.sample index 29d68087..e2aa5646 100644 --- a/vtysh/vtysh.conf.sample +++ b/vtysh/vtysh.conf.sample @@ -1,4 +1,7 @@ ! -! vtysh sample configuratin file +! Sample configuration file for vtysh. +! +!service integrated-vtysh-conf +!hostname quagga-router +!username root nopassword ! -!username kunihiro nopassword diff --git a/vtysh/vtysh.h b/vtysh/vtysh.h index 895c8c01..b632b6de 100644 --- a/vtysh/vtysh.h +++ b/vtysh/vtysh.h @@ -60,7 +60,7 @@ void vtysh_config_write (); int vtysh_config_from_file (struct vty *, FILE *); -void vtysh_read_config (char *, char *); +int vtysh_read_config (char *); void vtysh_config_parse (char *); diff --git a/vtysh/vtysh_config.c b/vtysh/vtysh_config.c index 86f5731b..26879186 100644 --- a/vtysh/vtysh_config.c +++ b/vtysh/vtysh_config.c @@ -28,6 +28,8 @@ Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA vector configvec; +extern int vtysh_writeconfig_integrated; + struct config { /* Configuration node name. */ @@ -174,7 +176,8 @@ vtysh_config_parse_line (char *line) strlen (" address-family ipv6")) == 0) config = config_get (BGP_IPV6_NODE, line); else if (config->index == RMAP_NODE || - config->index == INTERFACE_NODE ) + config->index == INTERFACE_NODE || + config->index == VTY_NODE) config_add_line_uniq (config->line, line); else config_add_line (config->line, line); @@ -224,13 +227,24 @@ vtysh_config_parse_line (char *line) config = config_get (IP_NODE, line); else if (strncmp (line, "key", strlen ("key")) == 0) config = config_get (KEYCHAIN_NODE, line); + else if (strncmp (line, "line", strlen ("line")) == 0) + config = config_get (VTY_NODE, line); + else if ( (strncmp (line, "ipv6 forwarding", + strlen ("ipv6 forwarding")) == 0) + || (strncmp (line, "ip forwarding", + strlen ("ip forwarding")) == 0) ) + config = config_get (FORWARDING_NODE, line); + else if (strncmp (line, "service", strlen ("service")) == 0) + config = config_get (SERVICE_NODE, line); else { if (strncmp (line, "log", strlen ("log")) == 0 || strncmp (line, "hostname", strlen ("hostname")) == 0 || strncmp (line, "password", strlen ("password")) == 0 || strncmp (line, "enable password", - strlen ("enable password")) == 0) + strlen ("enable password")) == 0 + || strncmp (line, "service", strlen ("service")) == 0 + ) config_add_line_uniq (config_top, line); else config_add_line (config_top, line); @@ -268,7 +282,8 @@ vtysh_config_parse (char *line) #define NO_DELIMITER(I) \ ((I) == ACCESS_NODE || (I) == PREFIX_NODE || (I) == IP_NODE \ || (I) == AS_LIST_NODE || (I) == COMMUNITY_LIST_NODE || \ - (I) == ACCESS_IPV6_NODE || (I) == PREFIX_IPV6_NODE) + (I) == ACCESS_IPV6_NODE || (I) == PREFIX_IPV6_NODE \ + || (I) == SERVICE_NODE) /* Display configuration to file pointer. */ void @@ -364,67 +379,40 @@ vtysh_read_file (FILE *confp) } } -/* Read up configuration file from file_name. */ -void -vtysh_read_config (char *config_file, - char *config_default_dir) +/* Read up configuration file from config_default_dir. */ +int +vtysh_read_config (char *config_default_dir) { - char *cwd; FILE *confp = NULL; - char *fullpath; - /* If -f flag specified. */ - if (config_file != NULL) - { - if (! IS_DIRECTORY_SEP (config_file[0])) - { - cwd = getcwd (NULL, MAXPATHLEN); - fullpath = XMALLOC (MTYPE_TMP, - strlen (cwd) + strlen (config_file) + 2); - sprintf (fullpath, "%s/%s", cwd, config_file); - } - else - fullpath = config_file; - - confp = fopen (fullpath, "r"); - - if (confp == NULL) - { - fprintf (stderr, "can't open configuration file [%s]\n", - config_file); - exit(1); - } - } - else - { - /* No configuration specified from command line. Open system - * default file. */ - confp = fopen (config_default_dir, "r"); - if (confp == NULL) - { - fprintf (stderr, "can't open configuration file [%s]\n", - config_default_dir); - exit (1); - } - else - fullpath = config_default_dir; - } + confp = fopen (config_default_dir, "r"); + if (confp == NULL) + return (1); vtysh_read_file (confp); - fclose (confp); + host_config_set (config_default_dir); - host_config_set (fullpath); + return (0); } +/* We don't write vtysh specific into file from vtysh. vtysh.conf should + * be edited by hand. So, we handle only "write terminal" case here and + * integrate vtysh specific conf with conf from daemons. + */ void -vtysh_config_write (FILE *fp) +vtysh_config_write () { + char *line; extern struct host host; if (host.name) - fprintf (fp, "hostname %s\n", host.name); - fprintf (fp, "!\n"); + { + sprintf (line, "hostname %s", host.name); + vtysh_config_parse_line(line); + } + if (vtysh_writeconfig_integrated) + vtysh_config_parse_line ("service integrated-vtysh-config"); } void diff --git a/vtysh/vtysh_main.c b/vtysh/vtysh_main.c index 223f0c6e..5f7856cf 100644 --- a/vtysh/vtysh_main.c +++ b/vtysh/vtysh_main.c @@ -40,16 +40,8 @@ char *progname; /* Configuration file name and directory. */ -char *config_file = NULL; char config_default[] = SYSCONFDIR VTYSH_DEFAULT_CONFIG; -/* Integrated configuration file. */ -char *integrate_file = NULL; -char *integrate_current = NULL; -#if 0 -char integrate_default[] = SYSCONFDIR INTEGRATE_DEFAULT_CONFIG; -#endif - /* Flag for indicate executing child command. */ int execute_flag = 0; @@ -143,7 +135,6 @@ usage (int status) "Integrated shell for Quagga routing software suite. \n\n"\ "-b, --boot Execute boot startup configuration\n" \ "-c, --command Execute argument as command\n "\ - "-f, --config_file Set configuration file name\n"\ "-h, --help Display this help and exit\n\n" \ "Report bugs to %s\n", progname, ZEBRA_BUG_ADDRESS); @@ -158,7 +149,6 @@ struct option longopts[] = { "eval", required_argument, NULL, 'e'}, { "command", required_argument, NULL, 'c'}, { "help", no_argument, NULL, 'h'}, - { "config_file", required_argument, NULL, 'f'}, { 0 } }; @@ -208,7 +198,7 @@ main (int argc, char **argv, char **env) /* Option handling. */ while (1) { - opt = getopt_long (argc, argv, "be:c:hf:", longopts, 0); + opt = getopt_long (argc, argv, "be:c:h", longopts, 0); if (opt == EOF) break; @@ -228,12 +218,6 @@ main (int argc, char **argv, char **env) case 'h': usage (0); break; - /* XXX It isn't used in any way. */ - case 'i': - integrated_file = strdup (optarg); - case 'f': - config_file = optarg; - break; default: usage (1); break; @@ -259,7 +243,7 @@ main (int argc, char **argv, char **env) vtysh_connect_all (); /* Read vtysh configuration file. */ - vtysh_read_config (config_file, config_default); + vtysh_read_config (config_default); /* If eval mode. */ if (eval_flag) @@ -271,8 +255,14 @@ main (int argc, char **argv, char **env) /* Boot startup configuration file. */ if (boot_flag) { - vtysh_read_config (integrate_file, integrate_default); - exit (0); + if (vtysh_read_config (integrate_default)) + { + fprintf (stderr, "Can't open configuration file [%s]\n", + integrate_default); + exit (1); + } + else + exit (0); } vtysh_pager_init (); @@ -283,6 +273,9 @@ main (int argc, char **argv, char **env) vtysh_auth (); + /* Enter into enable node. */ + vtysh_execute ("enable"); + /* Preparation for longjmp() in sigtstp(). */ sigsetjmp (jmpbuf, 1); jmpflag = 1; -- cgit v1.2.1