diff options
Diffstat (limited to 'lib/command.c')
-rw-r--r-- | lib/command.c | 352 |
1 files changed, 176 insertions, 176 deletions
diff --git a/lib/command.c b/lib/command.c index 60880f49..f1ec15c5 100644 --- a/lib/command.c +++ b/lib/command.c @@ -32,6 +32,7 @@ Boston, MA 02111-1307, USA. */ #include "vty.h" #include "command.h" #include "workqueue.h" +#include "command_queue.h" /* Command vector which includes some level of command lists. Normally each daemon maintains each own cmdvec. */ @@ -548,57 +549,57 @@ config_write_host (struct vty *vty) vty_out (vty, "enable password %s%s", host.enable, VTY_NEWLINE); } - if (zlog_default->default_lvl != LOG_DEBUG) + if (zlog_get_default_lvl(NULL) != LOG_DEBUG) { vty_out (vty, "! N.B. The 'log trap' command is deprecated.%s", VTY_NEWLINE); vty_out (vty, "log trap %s%s", - zlog_priority[zlog_default->default_lvl], VTY_NEWLINE); + zlog_priority[zlog_get_default_lvl(NULL)], VTY_NEWLINE); } - if (host.logfile && (zlog_default->maxlvl[ZLOG_DEST_FILE] != ZLOG_DISABLED)) + if (host.logfile && (zlog_get_maxlvl(NULL, ZLOG_DEST_FILE) != ZLOG_DISABLED)) { vty_out (vty, "log file %s", host.logfile); - if (zlog_default->maxlvl[ZLOG_DEST_FILE] != zlog_default->default_lvl) + if (zlog_get_maxlvl(NULL, ZLOG_DEST_FILE) != zlog_get_default_lvl(NULL)) vty_out (vty, " %s", - zlog_priority[zlog_default->maxlvl[ZLOG_DEST_FILE]]); + zlog_priority[zlog_get_maxlvl(NULL, ZLOG_DEST_FILE)]); vty_out (vty, "%s", VTY_NEWLINE); } - if (zlog_default->maxlvl[ZLOG_DEST_STDOUT] != ZLOG_DISABLED) + if (zlog_get_maxlvl(NULL, ZLOG_DEST_STDOUT) != ZLOG_DISABLED) { vty_out (vty, "log stdout"); - if (zlog_default->maxlvl[ZLOG_DEST_STDOUT] != zlog_default->default_lvl) + if (zlog_get_maxlvl(NULL, ZLOG_DEST_STDOUT) != zlog_get_default_lvl(NULL)) vty_out (vty, " %s", - zlog_priority[zlog_default->maxlvl[ZLOG_DEST_STDOUT]]); + zlog_priority[zlog_get_maxlvl(NULL, ZLOG_DEST_STDOUT)]); vty_out (vty, "%s", VTY_NEWLINE); } - if (zlog_default->maxlvl[ZLOG_DEST_MONITOR] == ZLOG_DISABLED) + if (zlog_get_maxlvl(NULL, ZLOG_DEST_MONITOR) == ZLOG_DISABLED) vty_out(vty,"no log monitor%s",VTY_NEWLINE); - else if (zlog_default->maxlvl[ZLOG_DEST_MONITOR] != zlog_default->default_lvl) + else if (zlog_get_maxlvl(NULL, ZLOG_DEST_MONITOR) != zlog_get_default_lvl(NULL)) vty_out(vty,"log monitor %s%s", - zlog_priority[zlog_default->maxlvl[ZLOG_DEST_MONITOR]],VTY_NEWLINE); + zlog_priority[zlog_get_maxlvl(NULL, ZLOG_DEST_MONITOR)],VTY_NEWLINE); - if (zlog_default->maxlvl[ZLOG_DEST_SYSLOG] != ZLOG_DISABLED) + if (zlog_get_maxlvl(NULL, ZLOG_DEST_SYSLOG) != ZLOG_DISABLED) { vty_out (vty, "log syslog"); - if (zlog_default->maxlvl[ZLOG_DEST_SYSLOG] != zlog_default->default_lvl) + if (zlog_get_maxlvl(NULL, ZLOG_DEST_SYSLOG) != zlog_get_default_lvl(NULL)) vty_out (vty, " %s", - zlog_priority[zlog_default->maxlvl[ZLOG_DEST_SYSLOG]]); + zlog_priority[zlog_get_maxlvl(NULL, ZLOG_DEST_SYSLOG)]); vty_out (vty, "%s", VTY_NEWLINE); } - if (zlog_default->facility != LOG_DAEMON) + if (zlog_get_facility(NULL) != LOG_DAEMON) vty_out (vty, "log facility %s%s", - facility_name(zlog_default->facility), VTY_NEWLINE); + facility_name(zlog_get_facility(NULL)), VTY_NEWLINE); - if (zlog_default->record_priority == 1) + if (zlog_get_record_priority(NULL) == 1) vty_out (vty, "log record-priority%s", VTY_NEWLINE); - if (zlog_default->timestamp_precision > 0) + if (zlog_get_timestamp_precision(NULL) > 0) vty_out (vty, "log timestamp precision %d%s", - zlog_default->timestamp_precision, VTY_NEWLINE); + zlog_get_timestamp_precision(NULL), VTY_NEWLINE); if (host.advanced) vty_out (vty, "service advanced-vty%s", VTY_NEWLINE); @@ -1573,7 +1574,7 @@ cmd_try_do_shortcut (enum node_type node, char* first_word) { /* '?' describe command support. */ static vector -cmd_describe_command_real (vector vline, struct vty *vty, int *status) +cmd_describe_command_real (vector vline, int node, int *status) { unsigned int i; vector cmd_vector; @@ -1595,7 +1596,7 @@ cmd_describe_command_real (vector vline, struct vty *vty, int *status) index = vector_active (vline) - 1; /* Make copy vector of current node's command vector. */ - cmd_vector = vector_copy (cmd_node_vector (cmdvec, vty->node)); + cmd_vector = vector_copy (cmd_node_vector (cmdvec, node)); /* Prepare match vector */ matchvec = vector_init (INIT_MATCHVEC_SIZE); @@ -1709,18 +1710,15 @@ cmd_describe_command_real (vector vline, struct vty *vty, int *status) } vector -cmd_describe_command (vector vline, struct vty *vty, int *status) +cmd_describe_command (vector vline, int node, int *status) { vector ret; - if ( cmd_try_do_shortcut(vty->node, vector_slot(vline, 0) ) ) + if ( cmd_try_do_shortcut(node, vector_slot(vline, 0) ) ) { - enum node_type onode; - vector shifted_vline; + vector shifted_vline; unsigned int index; - onode = vty->node; - vty->node = ENABLE_NODE; /* We can try it on enable node, cos' the vty is authenticated */ shifted_vline = vector_init (vector_count(vline)); @@ -1730,15 +1728,13 @@ cmd_describe_command (vector vline, struct vty *vty, int *status) vector_set_index (shifted_vline, index-1, vector_lookup(vline, index)); } - ret = cmd_describe_command_real (shifted_vline, vty, status); + ret = cmd_describe_command_real (shifted_vline, ENABLE_NODE, status); vector_free(shifted_vline); - vty->node = onode; return ret; } - - return cmd_describe_command_real (vline, vty, status); + return cmd_describe_command_real (vline, node, status); } @@ -1777,10 +1773,10 @@ cmd_lcd (char **matched) /* Command line completion support. */ static char ** -cmd_complete_command_real (vector vline, struct vty *vty, int *status) +cmd_complete_command_real (vector vline, int node, int *status) { unsigned int i; - vector cmd_vector = vector_copy (cmd_node_vector (cmdvec, vty->node)); + vector cmd_vector = vector_copy (cmd_node_vector (cmdvec, node)); #define INIT_MATCHVEC_SIZE 10 vector matchvec; struct cmd_element *cmd_element; @@ -1933,18 +1929,15 @@ cmd_complete_command_real (vector vline, struct vty *vty, int *status) } char ** -cmd_complete_command (vector vline, struct vty *vty, int *status) +cmd_complete_command (vector vline, int node, int *status) { char **ret; - if ( cmd_try_do_shortcut(vty->node, vector_slot(vline, 0) ) ) + if ( cmd_try_do_shortcut(node, vector_slot(vline, 0) ) ) { - enum node_type onode; vector shifted_vline; unsigned int index; - onode = vty->node; - vty->node = ENABLE_NODE; /* We can try it on enable node, cos' the vty is authenticated */ shifted_vline = vector_init (vector_count(vline)); @@ -1954,15 +1947,13 @@ cmd_complete_command (vector vline, struct vty *vty, int *status) vector_set_index (shifted_vline, index-1, vector_lookup(vline, index)); } - ret = cmd_complete_command_real (shifted_vline, vty, status); + ret = cmd_complete_command_real (shifted_vline, ENABLE_NODE, status); vector_free(shifted_vline); - vty->node = onode; return ret; } - - return cmd_complete_command_real (vline, vty, status); + return cmd_complete_command_real (vline, node, status); } /* return parent node */ @@ -1996,7 +1987,7 @@ node_parent ( enum node_type node ) /* Execute command by argument vline vector. */ static int cmd_execute_command_real (vector vline, struct vty *vty, - struct cmd_element **cmd) + struct cmd_element **cmd, qpn_nexus bgp_nexus) { unsigned int i; unsigned int index; @@ -2011,7 +2002,7 @@ cmd_execute_command_real (vector vline, struct vty *vty, char *command; /* Make copy of command elements. */ - cmd_vector = vector_copy (cmd_node_vector (cmdvec, vty->node)); + cmd_vector = vector_copy (cmd_node_vector (cmdvec, vty_get_node(vty))); for (index = 0; index < vector_active (vline); index++) if ((command = vector_slot (vline, index))) @@ -2112,23 +2103,32 @@ cmd_execute_command_real (vector vline, struct vty *vty, return CMD_SUCCESS_DAEMON; /* Execute matched command. */ - return (*matched_element->func) (matched_element, vty, argc, argv); + if (qpthreads_enabled && !(matched_element->attr & CMD_ATTR_CALL)) + { + /* Don't do it now, but send to bgp qpthread */ + cq_enqueue(matched_element, vty, argc, argv, bgp_nexus); + return CMD_QUEUED; + } + else + { + return (*matched_element->func) (matched_element, vty, argc, argv); + } } int cmd_execute_command (vector vline, struct vty *vty, struct cmd_element **cmd, - int vtysh) { + qpn_nexus bgp_nexus, int vtysh) { int ret, saved_ret, tried = 0; enum node_type onode, try_node; - onode = try_node = vty->node; + onode = try_node = vty_get_node(vty); - if ( cmd_try_do_shortcut(vty->node, vector_slot(vline, 0) ) ) + if ( cmd_try_do_shortcut(vty_get_node(vty), vector_slot(vline, 0) ) ) { vector shifted_vline; unsigned int index; - vty->node = ENABLE_NODE; + vty_set_node(vty, ENABLE_NODE); /* We can try it on enable node, cos' the vty is authenticated */ shifted_vline = vector_init (vector_count(vline)); @@ -2138,26 +2138,26 @@ cmd_execute_command (vector vline, struct vty *vty, struct cmd_element **cmd, vector_set_index (shifted_vline, index-1, vector_lookup(vline, index)); } - ret = cmd_execute_command_real (shifted_vline, vty, cmd); + ret = cmd_execute_command_real (shifted_vline, vty, cmd, bgp_nexus); vector_free(shifted_vline); - vty->node = onode; + vty_set_node(vty, onode); return ret; } - saved_ret = ret = cmd_execute_command_real (vline, vty, cmd); + saved_ret = ret = cmd_execute_command_real (vline, vty, cmd, bgp_nexus); if (vtysh) return saved_ret; /* This assumes all nodes above CONFIG_NODE are childs of CONFIG_NODE */ while ( ret != CMD_SUCCESS && ret != CMD_WARNING - && vty->node > CONFIG_NODE ) + && vty_get_node(vty) > CONFIG_NODE ) { try_node = node_parent(try_node); - vty->node = try_node; - ret = cmd_execute_command_real (vline, vty, cmd); + vty_set_node(vty, try_node); + ret = cmd_execute_command_real (vline, vty, cmd, bgp_nexus); tried = 1; if (ret == CMD_SUCCESS || ret == CMD_WARNING) { @@ -2168,7 +2168,7 @@ cmd_execute_command (vector vline, struct vty *vty, struct cmd_element **cmd, /* no command succeeded, reset the vty to the original node and return the error for this node */ if ( tried ) - vty->node = onode; + vty_set_node(vty, onode); return saved_ret; } @@ -2190,7 +2190,7 @@ cmd_execute_command_strict (vector vline, struct vty *vty, char *command; /* Make copy of command element */ - cmd_vector = vector_copy (cmd_node_vector (cmdvec, vty->node)); + cmd_vector = vector_copy (cmd_node_vector (cmdvec, vty_get_node(vty))); for (index = 0; index < vector_active (vline); index++) if ((command = vector_slot (vline, index))) @@ -2310,9 +2310,9 @@ config_from_file (struct vty *vty, FILE *fp) /* Try again with setting node to CONFIG_NODE */ while (ret != CMD_SUCCESS && ret != CMD_WARNING - && ret != CMD_ERR_NOTHING_TODO && vty->node != CONFIG_NODE) + && ret != CMD_ERR_NOTHING_TODO && vty_get_node(vty) != CONFIG_NODE) { - vty->node = node_parent(vty->node); + vty_set_node(vty, node_parent(vty_get_node(vty))); ret = cmd_execute_command_strict (vline, vty, NULL); } @@ -2326,14 +2326,14 @@ config_from_file (struct vty *vty, FILE *fp) } /* Configration from terminal */ -DEFUN (config_terminal, +DEFUN_CALL (config_terminal, config_terminal_cmd, "configure terminal", "Configuration from vty interface\n" "Configuration terminal\n") { if (vty_config_lock (vty)) - vty->node = CONFIG_NODE; + vty_set_node(vty, CONFIG_NODE); else { vty_out (vty, "VTY configuration is locked by other VTY%s", VTY_NEWLINE); @@ -2343,39 +2343,39 @@ DEFUN (config_terminal, } /* Enable command */ -DEFUN (enable, +DEFUN_CALL (enable, config_enable_cmd, "enable", "Turn on privileged mode command\n") { /* If enable password is NULL, change to ENABLE_NODE */ if ((host.enable == NULL && host.enable_encrypt == NULL) || - vty->type == VTY_SHELL_SERV) - vty->node = ENABLE_NODE; + vty_get_type(vty) == VTY_SHELL_SERV) + vty_set_node(vty, ENABLE_NODE); else - vty->node = AUTH_ENABLE_NODE; + vty_set_node(vty, AUTH_ENABLE_NODE); return CMD_SUCCESS; } /* Disable command */ -DEFUN (disable, +DEFUN_CALL (disable, config_disable_cmd, "disable", "Turn off privileged mode command\n") { - if (vty->node == ENABLE_NODE) - vty->node = VIEW_NODE; + if (vty_get_node(vty) == ENABLE_NODE) + vty_set_node(vty, VIEW_NODE); return CMD_SUCCESS; } /* Down vty node level. */ -DEFUN (config_exit, +DEFUN_CALL (config_exit, config_exit_cmd, "exit", "Exit current mode and down to previous mode\n") { - switch (vty->node) + switch (vty_get_node(vty)) { case VIEW_NODE: case ENABLE_NODE: @@ -2383,10 +2383,10 @@ DEFUN (config_exit, if (vty_shell (vty)) exit (0); else - vty->status = VTY_CLOSE; + vty_set_status(vty, VTY_CLOSE); break; case CONFIG_NODE: - vty->node = ENABLE_NODE; + vty_set_node(vty, ENABLE_NODE); vty_config_unlock (vty); break; case INTERFACE_NODE: @@ -2401,17 +2401,17 @@ DEFUN (config_exit, case MASC_NODE: case RMAP_NODE: case VTY_NODE: - vty->node = CONFIG_NODE; + vty_set_node(vty, CONFIG_NODE); break; case BGP_VPNV4_NODE: case BGP_IPV4_NODE: case BGP_IPV4M_NODE: case BGP_IPV6_NODE: case BGP_IPV6M_NODE: - vty->node = BGP_NODE; + vty_set_node(vty, BGP_NODE); break; case KEYCHAIN_KEY_NODE: - vty->node = KEYCHAIN_NODE; + vty_set_node(vty, KEYCHAIN_NODE); break; default: break; @@ -2420,18 +2420,18 @@ DEFUN (config_exit, } /* quit is alias of exit. */ -ALIAS (config_exit, +ALIAS_CALL (config_exit, config_quit_cmd, "quit", "Exit current mode and down to previous mode\n") /* End of configuration. */ -DEFUN (config_end, +DEFUN_CALL (config_end, config_end_cmd, "end", "End current mode and change to enable mode.") { - switch (vty->node) + switch (vty_get_node(vty)) { case VIEW_NODE: case ENABLE_NODE: @@ -2458,7 +2458,7 @@ DEFUN (config_end, case MASC_NODE: case VTY_NODE: vty_config_unlock (vty); - vty->node = ENABLE_NODE; + vty_set_node(vty, ENABLE_NODE); break; default: break; @@ -2467,7 +2467,7 @@ DEFUN (config_end, } /* Show version. */ -DEFUN (show_version, +DEFUN_CALL (show_version, show_version_cmd, "show version", SHOW_STR @@ -2481,7 +2481,7 @@ DEFUN (show_version, } /* Help display function for all node. */ -DEFUN (config_help, +DEFUN_CALL (config_help, config_help_cmd, "help", "Description of the interactive help system\n") @@ -2505,26 +2505,25 @@ argument.%s\ } /* Help display function for all node. */ -DEFUN (config_list, +DEFUN_CALL (config_list, config_list_cmd, "list", "Print command list\n") { unsigned int i; - struct cmd_node *cnode = vector_slot (cmdvec, vty->node); + struct cmd_node *cnode = vector_slot (cmdvec, vty_get_node(vty)); struct cmd_element *cmd; for (i = 0; i < vector_active (cnode->cmd_vector); i++) if ((cmd = vector_slot (cnode->cmd_vector, i)) != NULL - && !(cmd->attr == CMD_ATTR_DEPRECATED - || cmd->attr == CMD_ATTR_HIDDEN)) + && !(cmd->attr & (CMD_ATTR_DEPRECATED | CMD_ATTR_HIDDEN))) vty_out (vty, " %s%s", cmd->string, VTY_NEWLINE); return CMD_SUCCESS; } /* Write current configuration into file. */ -DEFUN (config_write_file, +DEFUN_CALL (config_write_file, config_write_file_cmd, "write file", "Write running configuration to memory, network, or terminal\n" @@ -2569,9 +2568,7 @@ DEFUN (config_write_file, } /* Make vty for configuration file. */ - file_vty = vty_new (); - file_vty->fd = fd; - file_vty->type = VTY_FILE; + file_vty = vty_new (fd, VTY_FILE); /* Config file header print. */ vty_out (file_vty, "!\n! Zebra configuration saved from vty\n! "); @@ -2632,18 +2629,18 @@ finished: return ret; } -ALIAS (config_write_file, +ALIAS_CALL (config_write_file, config_write_cmd, "write", "Write running configuration to memory, network, or terminal\n") -ALIAS (config_write_file, +ALIAS_CALL (config_write_file, config_write_memory_cmd, "write memory", "Write running configuration to memory, network, or terminal\n" "Write configuration to the file (same as write file)\n") -ALIAS (config_write_file, +ALIAS_CALL (config_write_file, copy_runningconfig_startupconfig_cmd, "copy running-config startup-config", "Copy configuration\n" @@ -2651,7 +2648,7 @@ ALIAS (config_write_file, "Copy running config to startup config (same as write file)\n") /* Write current configuration into the terminal. */ -DEFUN (config_write_terminal, +DEFUN_CALL (config_write_terminal, config_write_terminal_cmd, "write terminal", "Write running configuration to memory, network, or terminal\n" @@ -2660,7 +2657,7 @@ DEFUN (config_write_terminal, unsigned int i; struct cmd_node *node; - if (vty->type == VTY_SHELL_SERV) + if (vty_get_type(vty) == VTY_SHELL_SERV) { for (i = 0; i < vector_active (cmdvec); i++) if ((node = vector_slot (cmdvec, i)) && node->func && node->vtysh) @@ -2687,14 +2684,14 @@ DEFUN (config_write_terminal, } /* Write current configuration into the terminal. */ -ALIAS (config_write_terminal, +ALIAS_CALL (config_write_terminal, show_running_config_cmd, "show running-config", SHOW_STR "running configuration\n") /* Write startup configuration into the terminal. */ -DEFUN (show_startup_config, +DEFUN_CALL (show_startup_config, show_startup_config_cmd, "show startup-config", SHOW_STR @@ -2728,7 +2725,7 @@ DEFUN (show_startup_config, } /* Hostname configuration */ -DEFUN (config_hostname, +DEFUN_CALL (config_hostname, hostname_cmd, "hostname WORD", "Set system's network name\n" @@ -2747,7 +2744,7 @@ DEFUN (config_hostname, return CMD_SUCCESS; } -DEFUN (config_no_hostname, +DEFUN_CALL (config_no_hostname, no_hostname_cmd, "no hostname [HOSTNAME]", NO_STR @@ -2761,7 +2758,7 @@ DEFUN (config_no_hostname, } /* VTY interface password set. */ -DEFUN (config_password, password_cmd, +DEFUN_CALL (config_password, password_cmd, "password (8|) WORD", "Assign the terminal connection password\n" "Specifies a HIDDEN password will follow\n" @@ -2817,13 +2814,13 @@ DEFUN (config_password, password_cmd, return CMD_SUCCESS; } -ALIAS (config_password, password_text_cmd, +ALIAS_CALL (config_password, password_text_cmd, "password LINE", "Assign the terminal connection password\n" "The UNENCRYPTED (cleartext) line password\n") /* VTY enable password set. */ -DEFUN (config_enable_password, enable_password_cmd, +DEFUN_CALL (config_enable_password, enable_password_cmd, "enable password (8|) WORD", "Modify enable password parameters\n" "Assign the privileged level password\n" @@ -2884,7 +2881,7 @@ DEFUN (config_enable_password, enable_password_cmd, return CMD_SUCCESS; } -ALIAS (config_enable_password, +ALIAS_CALL (config_enable_password, enable_password_text_cmd, "enable password LINE", "Modify enable password parameters\n" @@ -2892,7 +2889,7 @@ ALIAS (config_enable_password, "The UNENCRYPTED (cleartext) 'enable' password\n") /* VTY enable password delete. */ -DEFUN (no_config_enable_password, no_enable_password_cmd, +DEFUN_CALL (no_config_enable_password, no_enable_password_cmd, "no enable password", NO_STR "Modify enable password parameters\n" @@ -2909,7 +2906,7 @@ DEFUN (no_config_enable_password, no_enable_password_cmd, return CMD_SUCCESS; } -DEFUN (service_password_encrypt, +DEFUN_CALL (service_password_encrypt, service_password_encrypt_cmd, "service password-encryption", "Set up miscellaneous service\n" @@ -2936,7 +2933,7 @@ DEFUN (service_password_encrypt, return CMD_SUCCESS; } -DEFUN (no_service_password_encrypt, +DEFUN_CALL (no_service_password_encrypt, no_service_password_encrypt_cmd, "no service password-encryption", NO_STR @@ -2959,7 +2956,7 @@ DEFUN (no_service_password_encrypt, return CMD_SUCCESS; } -DEFUN (config_terminal_length, config_terminal_length_cmd, +DEFUN_CALL (config_terminal_length, config_terminal_length_cmd, "terminal length <0-512>", "Set terminal line parameters\n" "Set number of lines on a screen\n" @@ -2974,22 +2971,22 @@ DEFUN (config_terminal_length, config_terminal_length_cmd, vty_out (vty, "length is malformed%s", VTY_NEWLINE); return CMD_WARNING; } - vty->lines = lines; + vty_set_lines(vty, lines); return CMD_SUCCESS; } -DEFUN (config_terminal_no_length, config_terminal_no_length_cmd, +DEFUN_CALL (config_terminal_no_length, config_terminal_no_length_cmd, "terminal no length", "Set terminal line parameters\n" NO_STR "Set number of lines on a screen\n") { - vty->lines = -1; + vty_set_lines(vty, -1); return CMD_SUCCESS; } -DEFUN (service_terminal_length, service_terminal_length_cmd, +DEFUN_CALL (service_terminal_length, service_terminal_length_cmd, "service terminal-length <0-512>", "Set up miscellaneous service\n" "System wide terminal length configuration\n" @@ -3009,7 +3006,7 @@ DEFUN (service_terminal_length, service_terminal_length_cmd, return CMD_SUCCESS; } -DEFUN (no_service_terminal_length, no_service_terminal_length_cmd, +DEFUN_CALL (no_service_terminal_length, no_service_terminal_length_cmd, "no service terminal-length [<0-512>]", NO_STR "Set up miscellaneous service\n" @@ -3020,7 +3017,7 @@ DEFUN (no_service_terminal_length, no_service_terminal_length_cmd, return CMD_SUCCESS; } -DEFUN_HIDDEN (do_echo, +DEFUN_HID_CALL (do_echo, echo_cmd, "echo .MESSAGE", "Echo a message back to the vty\n" @@ -3035,7 +3032,7 @@ DEFUN_HIDDEN (do_echo, return CMD_SUCCESS; } -DEFUN (config_logmsg, +DEFUN_CALL (config_logmsg, config_logmsg_cmd, "logmsg "LOG_LEVELS" .MESSAGE", "Send a message to enabled logging destinations\n" @@ -3048,76 +3045,79 @@ DEFUN (config_logmsg, if ((level = level_match(argv[0])) == ZLOG_DISABLED) return CMD_ERR_NO_MATCH; - zlog(NULL, level, ((message = argv_concat(argv, argc, 1)) ? message : "")); + message = argv_concat(argv, argc, 1); + zlog(NULL, level, "%s", (message ? message : "")); if (message) XFREE(MTYPE_TMP, message); return CMD_SUCCESS; } -DEFUN (show_logging, +DEFUN_CALL (show_logging, show_logging_cmd, "show logging", SHOW_STR "Show current logging configuration\n") { - struct zlog *zl = zlog_default; - vty_out (vty, "Syslog logging: "); - if (zl->maxlvl[ZLOG_DEST_SYSLOG] == ZLOG_DISABLED) + if (zlog_get_maxlvl(NULL, ZLOG_DEST_SYSLOG) == ZLOG_DISABLED) vty_out (vty, "disabled"); else vty_out (vty, "level %s, facility %s, ident %s", - zlog_priority[zl->maxlvl[ZLOG_DEST_SYSLOG]], - facility_name(zl->facility), zl->ident); + zlog_priority[zlog_get_maxlvl(NULL, ZLOG_DEST_SYSLOG)], + facility_name(zlog_get_facility(NULL)), zlog_get_ident(NULL)); vty_out (vty, "%s", VTY_NEWLINE); vty_out (vty, "Stdout logging: "); - if (zl->maxlvl[ZLOG_DEST_STDOUT] == ZLOG_DISABLED) + if (zlog_get_maxlvl(NULL, ZLOG_DEST_STDOUT) == ZLOG_DISABLED) vty_out (vty, "disabled"); else vty_out (vty, "level %s", - zlog_priority[zl->maxlvl[ZLOG_DEST_STDOUT]]); + zlog_priority[zlog_get_maxlvl(NULL, ZLOG_DEST_STDOUT)]); vty_out (vty, "%s", VTY_NEWLINE); vty_out (vty, "Monitor logging: "); - if (zl->maxlvl[ZLOG_DEST_MONITOR] == ZLOG_DISABLED) + if (zlog_get_maxlvl(NULL, ZLOG_DEST_MONITOR) == ZLOG_DISABLED) vty_out (vty, "disabled"); else vty_out (vty, "level %s", - zlog_priority[zl->maxlvl[ZLOG_DEST_MONITOR]]); + zlog_priority[zlog_get_maxlvl(NULL, ZLOG_DEST_MONITOR)]); vty_out (vty, "%s", VTY_NEWLINE); vty_out (vty, "File logging: "); - if ((zl->maxlvl[ZLOG_DEST_FILE] == ZLOG_DISABLED) || - !zl->fp) + if ((zlog_get_maxlvl(NULL, ZLOG_DEST_FILE) == ZLOG_DISABLED) || + !zlog_is_file(NULL)) vty_out (vty, "disabled"); else - vty_out (vty, "level %s, filename %s", - zlog_priority[zl->maxlvl[ZLOG_DEST_FILE]], - zl->filename); + { + char * filename = zlog_get_filename(NULL); + vty_out (vty, "level %s, filename %s", + zlog_priority[zlog_get_maxlvl(NULL, ZLOG_DEST_FILE)], + filename); + free(filename); + } vty_out (vty, "%s", VTY_NEWLINE); vty_out (vty, "Protocol name: %s%s", - zlog_proto_names[zl->protocol], VTY_NEWLINE); + zlog_get_proto_name(NULL), VTY_NEWLINE); vty_out (vty, "Record priority: %s%s", - (zl->record_priority ? "enabled" : "disabled"), VTY_NEWLINE); + (zlog_get_record_priority(NULL) ? "enabled" : "disabled"), VTY_NEWLINE); vty_out (vty, "Timestamp precision: %d%s", - zl->timestamp_precision, VTY_NEWLINE); + zlog_get_timestamp_precision(NULL), VTY_NEWLINE); return CMD_SUCCESS; } -DEFUN (config_log_stdout, +DEFUN_CALL (config_log_stdout, config_log_stdout_cmd, "log stdout", "Logging control\n" "Set stdout logging level\n") { - zlog_set_level (NULL, ZLOG_DEST_STDOUT, zlog_default->default_lvl); + zlog_set_level (NULL, ZLOG_DEST_STDOUT, zlog_get_default_lvl(NULL)); return CMD_SUCCESS; } -DEFUN (config_log_stdout_level, +DEFUN_CALL (config_log_stdout_level, config_log_stdout_level_cmd, "log stdout "LOG_LEVELS, "Logging control\n" @@ -3132,7 +3132,7 @@ DEFUN (config_log_stdout_level, return CMD_SUCCESS; } -DEFUN (no_config_log_stdout, +DEFUN_CALL (no_config_log_stdout, no_config_log_stdout_cmd, "no log stdout [LEVEL]", NO_STR @@ -3144,17 +3144,17 @@ DEFUN (no_config_log_stdout, return CMD_SUCCESS; } -DEFUN (config_log_monitor, +DEFUN_CALL (config_log_monitor, config_log_monitor_cmd, "log monitor", "Logging control\n" "Set terminal line (monitor) logging level\n") { - zlog_set_level (NULL, ZLOG_DEST_MONITOR, zlog_default->default_lvl); + zlog_set_level (NULL, ZLOG_DEST_MONITOR, zlog_get_default_lvl(NULL)); return CMD_SUCCESS; } -DEFUN (config_log_monitor_level, +DEFUN_CALL (config_log_monitor_level, config_log_monitor_level_cmd, "log monitor "LOG_LEVELS, "Logging control\n" @@ -3169,7 +3169,7 @@ DEFUN (config_log_monitor_level, return CMD_SUCCESS; } -DEFUN (no_config_log_monitor, +DEFUN_CALL (no_config_log_monitor, no_config_log_monitor_cmd, "no log monitor [LEVEL]", NO_STR @@ -3231,17 +3231,17 @@ set_log_file(struct vty *vty, const char *fname, int loglevel) return CMD_SUCCESS; } -DEFUN (config_log_file, +DEFUN_CALL (config_log_file, config_log_file_cmd, "log file FILENAME", "Logging control\n" "Logging to file\n" "Logging filename\n") { - return set_log_file(vty, argv[0], zlog_default->default_lvl); + return set_log_file(vty, argv[0], zlog_get_default_lvl(NULL)); } -DEFUN (config_log_file_level, +DEFUN_CALL (config_log_file_level, config_log_file_level_cmd, "log file FILENAME "LOG_LEVELS, "Logging control\n" @@ -3256,7 +3256,7 @@ DEFUN (config_log_file_level, return set_log_file(vty, argv[0], level); } -DEFUN (no_config_log_file, +DEFUN_CALL (no_config_log_file, no_config_log_file_cmd, "no log file [FILENAME]", NO_STR @@ -3274,7 +3274,7 @@ DEFUN (no_config_log_file, return CMD_SUCCESS; } -ALIAS (no_config_log_file, +ALIAS_CALL (no_config_log_file, no_config_log_file_level_cmd, "no log file FILENAME LEVEL", NO_STR @@ -3283,17 +3283,17 @@ ALIAS (no_config_log_file, "Logging file name\n" "Logging level\n") -DEFUN (config_log_syslog, +DEFUN_CALL (config_log_syslog, config_log_syslog_cmd, "log syslog", "Logging control\n" "Set syslog logging level\n") { - zlog_set_level (NULL, ZLOG_DEST_SYSLOG, zlog_default->default_lvl); + zlog_set_level (NULL, ZLOG_DEST_SYSLOG, zlog_get_default_lvl(NULL)); return CMD_SUCCESS; } -DEFUN (config_log_syslog_level, +DEFUN_CALL (config_log_syslog_level, config_log_syslog_level_cmd, "log syslog "LOG_LEVELS, "Logging control\n" @@ -3308,7 +3308,7 @@ DEFUN (config_log_syslog_level, return CMD_SUCCESS; } -DEFUN_DEPRECATED (config_log_syslog_facility, +DEFUN_DEP_CALL (config_log_syslog_facility, config_log_syslog_facility_cmd, "log syslog facility "LOG_FACILITIES, "Logging control\n" @@ -3321,12 +3321,12 @@ DEFUN_DEPRECATED (config_log_syslog_facility, if ((facility = facility_match(argv[0])) < 0) return CMD_ERR_NO_MATCH; - zlog_set_level (NULL, ZLOG_DEST_SYSLOG, zlog_default->default_lvl); - zlog_default->facility = facility; + zlog_set_level (NULL, ZLOG_DEST_SYSLOG, zlog_get_default_lvl(NULL)); + zlog_set_facility(NULL, facility); return CMD_SUCCESS; } -DEFUN (no_config_log_syslog, +DEFUN_CALL (no_config_log_syslog, no_config_log_syslog_cmd, "no log syslog [LEVEL]", NO_STR @@ -3338,7 +3338,7 @@ DEFUN (no_config_log_syslog, return CMD_SUCCESS; } -ALIAS (no_config_log_syslog, +ALIAS_CALL (no_config_log_syslog, no_config_log_syslog_facility_cmd, "no log syslog facility "LOG_FACILITIES, NO_STR @@ -3347,7 +3347,7 @@ ALIAS (no_config_log_syslog, "Facility parameter for syslog messages\n" LOG_FACILITY_DESC) -DEFUN (config_log_facility, +DEFUN_CALL (config_log_facility, config_log_facility_cmd, "log facility "LOG_FACILITIES, "Logging control\n" @@ -3358,11 +3358,11 @@ DEFUN (config_log_facility, if ((facility = facility_match(argv[0])) < 0) return CMD_ERR_NO_MATCH; - zlog_default->facility = facility; + zlog_set_facility(NULL, facility); return CMD_SUCCESS; } -DEFUN (no_config_log_facility, +DEFUN_CALL (no_config_log_facility, no_config_log_facility_cmd, "no log facility [FACILITY]", NO_STR @@ -3370,11 +3370,11 @@ DEFUN (no_config_log_facility, "Reset syslog facility to default (daemon)\n" "Syslog facility\n") { - zlog_default->facility = LOG_DAEMON; + zlog_set_facility(NULL, LOG_DAEMON); return CMD_SUCCESS; } -DEFUN_DEPRECATED (config_log_trap, +DEFUN_DEP_CALL (config_log_trap, config_log_trap_cmd, "log trap "LOG_LEVELS, "Logging control\n" @@ -3382,19 +3382,15 @@ DEFUN_DEPRECATED (config_log_trap, LOG_LEVEL_DESC) { int new_level ; - int i; if ((new_level = level_match(argv[0])) == ZLOG_DISABLED) return CMD_ERR_NO_MATCH; - zlog_default->default_lvl = new_level; - for (i = 0; i < ZLOG_NUM_DESTS; i++) - if (zlog_default->maxlvl[i] != ZLOG_DISABLED) - zlog_default->maxlvl[i] = new_level; + zlog_set_default_lvl_dest (NULL, new_level); return CMD_SUCCESS; } -DEFUN_DEPRECATED (no_config_log_trap, +DEFUN_DEP_CALL (no_config_log_trap, no_config_log_trap_cmd, "no log trap [LEVEL]", NO_STR @@ -3402,32 +3398,32 @@ DEFUN_DEPRECATED (no_config_log_trap, "Permit all logging information\n" "Logging level\n") { - zlog_default->default_lvl = LOG_DEBUG; + zlog_set_default_lvl(NULL, LOG_DEBUG); return CMD_SUCCESS; } -DEFUN (config_log_record_priority, +DEFUN_CALL (config_log_record_priority, config_log_record_priority_cmd, "log record-priority", "Logging control\n" "Log the priority of the message within the message\n") { - zlog_default->record_priority = 1 ; + zlog_set_record_priority(NULL, 1) ; return CMD_SUCCESS; } -DEFUN (no_config_log_record_priority, +DEFUN_CALL (no_config_log_record_priority, no_config_log_record_priority_cmd, "no log record-priority", NO_STR "Logging control\n" "Do not log the priority of the message within the message\n") { - zlog_default->record_priority = 0 ; + zlog_set_record_priority(NULL, 0) ; return CMD_SUCCESS; } -DEFUN (config_log_timestamp_precision, +DEFUN_CALL (config_log_timestamp_precision, config_log_timestamp_precision_cmd, "log timestamp precision <0-6>", "Logging control\n" @@ -3435,6 +3431,8 @@ DEFUN (config_log_timestamp_precision, "Set the timestamp precision\n" "Number of subsecond digits\n") { + int timestamp_precision; + if (argc != 1) { vty_out (vty, "Insufficient arguments%s", VTY_NEWLINE); @@ -3442,11 +3440,13 @@ DEFUN (config_log_timestamp_precision, } VTY_GET_INTEGER_RANGE("Timestamp Precision", - zlog_default->timestamp_precision, argv[0], 0, 6); + timestamp_precision, argv[0], 0, 6); + zlog_set_timestamp_precision(NULL, timestamp_precision); + return CMD_SUCCESS; } -DEFUN (no_config_log_timestamp_precision, +DEFUN_CALL (no_config_log_timestamp_precision, no_config_log_timestamp_precision_cmd, "no log timestamp precision", NO_STR @@ -3454,11 +3454,11 @@ DEFUN (no_config_log_timestamp_precision, "Timestamp configuration\n" "Reset the timestamp precision to the default value of 0\n") { - zlog_default->timestamp_precision = 0 ; + zlog_set_timestamp_precision(NULL, 0); return CMD_SUCCESS; } -DEFUN (banner_motd_file, +DEFUN_CALL (banner_motd_file, banner_motd_file_cmd, "banner motd file [FILE]", "Set banner\n" @@ -3473,7 +3473,7 @@ DEFUN (banner_motd_file, return CMD_SUCCESS; } -DEFUN (banner_motd_default, +DEFUN_CALL (banner_motd_default, banner_motd_default_cmd, "banner motd default", "Set banner string\n" @@ -3484,7 +3484,7 @@ DEFUN (banner_motd_default, return CMD_SUCCESS; } -DEFUN (no_banner_motd, +DEFUN_CALL (no_banner_motd, no_banner_motd_cmd, "no banner motd", NO_STR |