📄 command.c
字号:
if ((*node->func) (vty)) vty_out (vty, "!%s", VTY_NEWLINE); } } else { vty_out (vty, "%sCurrent configuration:%s", VTY_NEWLINE, VTY_NEWLINE); vty_out (vty, "!%s", VTY_NEWLINE); for (i = 0; i < vector_max (cmdvec); i++) if ((node = vector_slot (cmdvec, i)) && node->func) { if ((*node->func) (vty)) vty_out (vty, "!%s", VTY_NEWLINE); } vty_out (vty, "end%s",VTY_NEWLINE); } return CMD_SUCCESS;}/* Write current configuration into the terminal. */ALIAS (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, show_startup_config_cmd, "show startup-config", SHOW_STR "Contentes of startup configuration\n"){ char buf[BUFSIZ]; FILE *confp; confp = fopen (host.config, "r"); if (confp == NULL) { vty_out (vty, "Can't open configuration file [%s]%s", host.config, VTY_NEWLINE); return CMD_WARNING; } while (fgets (buf, BUFSIZ, confp)) { char *cp = buf; while (*cp != '\r' && *cp != '\n' && *cp != '\0') cp++; *cp = '\0'; vty_out (vty, "%s%s", buf, VTY_NEWLINE); } fclose (confp); return CMD_SUCCESS;}/* Hostname configuration */DEFUN (config_hostname, hostname_cmd, "hostname WORD", "Set system's network name\n" "This system's network name\n"){ if (!isalpha((int) *argv[0])) { vty_out (vty, "Please specify string starting with alphabet%s", VTY_NEWLINE); return CMD_WARNING; } if (host.name) XFREE (0, host.name); host.name = strdup (argv[0]); return CMD_SUCCESS;}DEFUN (config_no_hostname, no_hostname_cmd, "no hostname [HOSTNAME]", NO_STR "Reset system's network name\n" "Host name of this router\n"){ if (host.name) XFREE (0, host.name); host.name = NULL; return CMD_SUCCESS;}/* VTY interface password set. */DEFUN (config_password, 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"){ /* Argument check. */ if (argc == 0) { vty_out (vty, "Please specify password.%s", VTY_NEWLINE); return CMD_WARNING; } if (argc == 2) { if (*argv[0] == '8') { if (host.password) XFREE (0, host.password); host.password = NULL; if (host.password_encrypt) XFREE (0, host.password_encrypt); host.password_encrypt = XSTRDUP (0, strdup (argv[1])); return CMD_SUCCESS; } else { vty_out (vty, "Unknown encryption type.%s", VTY_NEWLINE); return CMD_WARNING; } } if (!isalnum ((int) *argv[0])) { vty_out (vty, "Please specify string starting with alphanumeric%s", VTY_NEWLINE); return CMD_WARNING; } if (host.password) XFREE (0, host.password); host.password = NULL; if (host.encrypt) { if (host.password_encrypt) XFREE (0, host.password_encrypt); host.password_encrypt = XSTRDUP (0, zencrypt (argv[0])); } else host.password = XSTRDUP (0, argv[0]); return CMD_SUCCESS;}ALIAS (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, "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"){ /* Argument check. */ if (argc == 0) { vty_out (vty, "Please specify password.%s", VTY_NEWLINE); return CMD_WARNING; } /* Crypt type is specified. */ if (argc == 2) { if (*argv[0] == '8') { if (host.enable) XFREE (0, host.enable); host.enable = NULL; if (host.enable_encrypt) XFREE (0, host.enable_encrypt); host.enable_encrypt = XSTRDUP (0, argv[1]); return CMD_SUCCESS; } else { vty_out (vty, "Unknown encryption type.%s", VTY_NEWLINE); return CMD_WARNING; } } if (!isalnum ((int) *argv[0])) { vty_out (vty, "Please specify string starting with alphanumeric%s", VTY_NEWLINE); return CMD_WARNING; } if (host.enable) XFREE (0, host.enable); host.enable = NULL; /* Plain password input. */ if (host.encrypt) { if (host.enable_encrypt) XFREE (0, host.enable_encrypt); host.enable_encrypt = XSTRDUP (0, zencrypt (argv[0])); } else host.enable = XSTRDUP (0, argv[0]); return CMD_SUCCESS;}ALIAS (config_enable_password, enable_password_text_cmd, "enable password LINE", "Modify enable password parameters\n" "Assign the privileged level password\n" "The UNENCRYPTED (cleartext) 'enable' password\n");/* VTY enable password delete. */DEFUN (no_config_enable_password, no_enable_password_cmd, "no enable password", NO_STR "Modify enable password parameters\n" "Assign the privileged level password\n"){ if (host.enable) XFREE (0, host.enable); host.enable = NULL; if (host.enable_encrypt) XFREE (0, host.enable_encrypt); host.enable_encrypt = NULL; return CMD_SUCCESS;} DEFUN (service_password_encrypt, service_password_encrypt_cmd, "service password-encryption", "Set up miscellaneous service\n" "Enable encrypted passwords\n"){ if (host.encrypt) return CMD_SUCCESS; host.encrypt = 1; if (host.password) { if (host.password_encrypt) XFREE (0, host.password_encrypt); host.password_encrypt = XSTRDUP (0, zencrypt (host.password)); } if (host.enable) { if (host.enable_encrypt) XFREE (0, host.enable_encrypt); host.enable_encrypt = XSTRDUP (0, zencrypt (host.enable)); } return CMD_SUCCESS;}DEFUN (no_service_password_encrypt, no_service_password_encrypt_cmd, "no service password-encryption", NO_STR "Set up miscellaneous service\n" "Enable encrypted passwords\n"){ if (! host.encrypt) return CMD_SUCCESS; host.encrypt = 0; if (host.password_encrypt) XFREE (0, host.password_encrypt); host.password_encrypt = NULL; if (host.enable_encrypt) XFREE (0, host.enable_encrypt); host.enable_encrypt = NULL; return CMD_SUCCESS;}DEFUN (config_terminal_length, config_terminal_length_cmd, "terminal length <0-512>", "Set terminal line parameters\n" "Set number of lines on a screen\n" "Number of lines on screen (0 for no pausing)\n"){ int lines; char *endptr = NULL; lines = strtol (argv[0], &endptr, 10); if (lines < 0 || lines > 512 || *endptr != '\0') { vty_out (vty, "length is malformed%s", VTY_NEWLINE); return CMD_WARNING; } vty->lines = lines; return CMD_SUCCESS;}DEFUN (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; return CMD_SUCCESS;}DEFUN (service_terminal_length, service_terminal_length_cmd, "service terminal-length <0-512>", "Set up miscellaneous service\n" "System wide terminal length configuration\n" "Number of lines of VTY (0 means no line control)\n"){ int lines; char *endptr = NULL; lines = strtol (argv[0], &endptr, 10); if (lines < 0 || lines > 512 || *endptr != '\0') { vty_out (vty, "length is malformed%s", VTY_NEWLINE); return CMD_WARNING; } host.lines = lines; return CMD_SUCCESS;}DEFUN (no_service_terminal_length, no_service_terminal_length_cmd, "no service terminal-length [<0-512>]", NO_STR "Set up miscellaneous service\n" "System wide terminal length configuration\n" "Number of lines of VTY (0 means no line control)\n"){ host.lines = -1; return CMD_SUCCESS;}DEFUN (config_log_stdout, config_log_stdout_cmd, "log stdout", "Logging control\n" "Logging goes to stdout\n"){ zlog_set_flag (NULL, ZLOG_STDOUT); host.log_stdout = 1; return CMD_SUCCESS;}DEFUN (no_config_log_stdout, no_config_log_stdout_cmd, "no log stdout", NO_STR "Logging control\n" "Cancel logging to stdout\n"){ zlog_reset_flag (NULL, ZLOG_STDOUT); host.log_stdout = 0; return CMD_SUCCESS;}DEFUN (config_log_file, config_log_file_cmd, "log file FILENAME", "Logging control\n" "Logging to file\n" "Logging filename\n"){ int ret; char *cwd; char *fullpath; /* Path detection. */ if (! IS_DIRECTORY_SEP (*argv[0])) { cwd = getcwd (NULL, MAXPATHLEN); fullpath = XMALLOC (MTYPE_TMP, strlen (cwd) + strlen (argv[0]) + 2); sprintf (fullpath, "%s/%s", cwd, argv[0]); } else fullpath = argv[0]; ret = zlog_set_file (NULL, ZLOG_FILE, fullpath); if (!ret) { vty_out (vty, "can't open logfile %s\n", argv[0]); return CMD_WARNING; } if (host.logfile) XFREE (MTYPE_TMP, host.logfile); host.logfile = strdup (argv[0]); return CMD_SUCCESS;}DEFUN (no_config_log_file, no_config_log_file_cmd, "no log file [FILENAME]", NO_STR "Logging control\n" "Cancel logging to file\n" "Logging file name\n"){ zlog_reset_file (NULL); if (host.logfile) XFREE (MTYPE_TMP, host.logfile); host.logfile = NULL; return CMD_SUCCESS;}DEFUN (config_log_syslog, config_log_syslog_cmd, "log syslog", "Logging control\n" "Logging goes to syslog\n"){ zlog_set_flag (NULL, ZLOG_SYSLOG); host.log_syslog = 1; zlog_default->facility = LOG_DAEMON; return CMD_SUCCESS;}DEFUN (config_log_syslog_facility, config_log_syslog_facility_cmd, "log syslog facility (kern|user|mail|daemon|auth|syslog|lpr|news|uucp|cron|local0|local1|local2|local3|local4|local5|local6|local7)", "Logging control\n" "Logging goes to syslog\n" "Facility parameter for syslog messages\n" "Kernel\n" "User process\n" "Mail system\n" "System daemons\n" "Authorization system\n" "Syslog itself\n" "Line printer system\n" "USENET news\n" "Unix-to-Unix copy system\n" "Cron/at facility\n" "Local use\n" "Local use\n" "Local use\n" "Local use\n" "Local use\n" "Local use\n" "Local use\n" "Local use\n"){ int facility = LOG_DAEMON; zlog_set_flag (NULL, ZLOG_SYSLOG); host.log_syslog = 1; if (strncmp (argv[0], "kern", 1) == 0) facility = LOG_KERN; else if (strncmp (argv[0], "user", 2) == 0) facility = LOG_USER; else if (strncmp (argv[0], "mail", 1) == 0) facility = LOG_MAIL; else if (strncmp (argv[0], "daemon", 1) == 0) facility = LOG_DAEMON; else if (strncmp (argv[0], "auth", 1) == 0) facility = LOG_AUTH; else if (strncmp (argv[0], "syslog", 1) == 0) facility = LOG_SYSLOG; else if (strncmp (argv[0], "lpr", 2) == 0) facility = LOG_LPR; else if (strncmp (argv[0], "news", 1) == 0) facility = LOG_NEWS; else if (strncmp (argv[0], "uucp", 2) == 0) facility = LOG_UUCP; else if (strncmp (argv[0], "cron", 1) == 0) facility = LOG_CRON; else if (strncmp (argv[0], "local0", 6) == 0) facility = LOG_LOCAL0; else if (strncmp (argv[0], "local1", 6) == 0) facility = LOG_LOCAL1; else if (strncmp (argv[0], "local2", 6) == 0) facility = LOG_LOCAL2; else if (strncmp (argv[0], "local3", 6) == 0) facility = LOG_LOCAL3; else if (strncmp (argv[0], "local4", 6) == 0) facility = LOG_LOCAL4; else if (strncmp (argv[0], "local5", 6) == 0) facility = LOG_LOCAL5; else if (strncmp (argv[0], "local6", 6) == 0) facility = LOG_LOCAL6; else if (strncmp (argv[0], "local7", 6) == 0) facility = LOG_LOCAL7; zlog_default->facility = facility; return CMD_SUCCESS;}DEFUN (no_config_log_syslog, no_config_log_syslog_cmd, "no log syslog", NO_STR "Logging control\n" "Cancel logging to syslog\n"){ zlog_reset_flag (NULL, ZLOG_SYSLOG); host.log_syslog = 0; zlog_default->facility = LOG_DAEMON; return CMD_SUCCESS;}ALIAS (no_config_log_syslog, no_config_log_syslog_facility_cmd, "no log syslog facility (kern|user|mail|daemon|auth|syslog|lpr|news|uucp|cron|local0|local1|local2|local3|local4|local5|local6|local7)", NO_STR "Logging control\n" "Logging goes to syslog\n" "Facility parameter for syslog messages\n" "Kernel\n" "User process\n" "Mail system\n" "System daemons\n" "Authorization system\n" "Syslog itself\n" "Line printer system\n" "USENET news\n" "Unix-to-Unix copy system\n" "Cron/at facility\n" "Local use\n" "Local use\n" "Local use\n" "Local use\n" "Local use\n" "Local use\n" "Local use\n" "Local use\n");DEFUN (config_log_trap, config_log_trap_cmd, "log trap (emergencies|alerts|critical|errors|warnings|notifications|informational|debugging)", "Logging control\n" "Limit logging to specifed level\n"){ int new_level ; for ( new_level = 0 ; zlog_priority [new_level] != NULL ; new_level ++ ) { if ( strcmp ( argv[0], zlog_priority [new_level] ) == 0 ) /* found new logging level */ { zlog_default->maskpri = new_level; return CMD_SUCCESS; } } return CMD_ERR_NO_MATCH;}DEFUN (no_config_log_trap, no_config_log_trap_cmd, "no log trap", NO_STR "Logging control\n" "Permit all logging information\n"){ zlog_default->maskpri = LOG_DEBUG; return CMD_SUCCESS;}DEFUN (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 ; return CMD_SUCCESS;}DEFUN (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\
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -