📄 vtysh.c
字号:
intvtysh_rl_describe (){ int ret; int i; vector vline; vector describe; int width; struct desc *desc; vline = cmd_make_strvec (rl_line_buffer); /* In case of '> ?'. */ if (vline == NULL) { vline = vector_init (1); vector_set (vline, '\0'); } else if (rl_end && isspace ((int) rl_line_buffer[rl_end - 1])) vector_set (vline, '\0'); describe = cmd_describe_command (vline, vty, &ret); printf ("\n"); /* Ambiguous and no match error. */ switch (ret) { case CMD_ERR_AMBIGUOUS: cmd_free_strvec (vline); printf ("%% Ambiguous command.\n"); rl_on_new_line (); return 0; break; case CMD_ERR_NO_MATCH: cmd_free_strvec (vline); printf ("%% There is no matched command.\n"); rl_on_new_line (); return 0; break; } /* Get width of command string. */ width = 0; for (i = 0; i < vector_max (describe); i++) if ((desc = vector_slot (describe, i)) != NULL) { int len; if (desc->cmd[0] == '\0') continue; len = strlen (desc->cmd); if (desc->cmd[0] == '.') len--; if (width < len) width = len; } for (i = 0; i < vector_max (describe); i++) if ((desc = vector_slot (describe, i)) != NULL) { if (desc->cmd[0] == '\0') continue; if (! desc->str) printf (" %-s\n", desc->cmd[0] == '.' ? desc->cmd + 1 : desc->cmd); else printf (" %-*s %s\n", width, desc->cmd[0] == '.' ? desc->cmd + 1 : desc->cmd, desc->str); } cmd_free_strvec (vline); vector_free (describe); rl_on_new_line(); return 0;}/* result of cmd_complete_command() call will be stored here and used in new_completion() in order to put the space in correct places only */int complete_status;char *command_generator (char *text, int state){ vector vline; static char **matched = NULL; static int index = 0; /* First call. */ if (! state) { index = 0; if (vty->node == AUTH_NODE || vty->node == AUTH_ENABLE_NODE) return NULL; vline = cmd_make_strvec (rl_line_buffer); if (vline == NULL) return NULL; if (rl_end && isspace ((int) rl_line_buffer[rl_end - 1])) vector_set (vline, '\0'); matched = cmd_complete_command (vline, vty, &complete_status); } if (matched && matched[index]) return matched[index++]; return NULL;}char **new_completion (char *text, int start, int end){ char **matches; matches = completion_matches (text, command_generator); if (matches) { rl_point = rl_end; if (complete_status == CMD_COMPLETE_FULL_MATCH) rl_pending_input = ' '; } return matches;}char **vtysh_completion (char *text, int start, int end){ int ret; vector vline; char **matched = NULL; if (vty->node == AUTH_NODE || vty->node == AUTH_ENABLE_NODE) return NULL; vline = cmd_make_strvec (rl_line_buffer); if (vline == NULL) return NULL; /* In case of 'help \t'. */ if (rl_end && isspace ((int) rl_line_buffer[rl_end - 1])) vector_set (vline, '\0'); matched = cmd_complete_command (vline, vty, &ret); cmd_free_strvec (vline); return (char **) matched;}/* BGP node structure. */struct cmd_node bgp_node ={ BGP_NODE, "%s(config-router)# ",};/* BGP node structure. */struct cmd_node rip_node ={ RIP_NODE, "%s(config-router)# ",};struct cmd_node interface_node ={ INTERFACE_NODE, "%s(config-if)# ",};DEFUNSH (VTYSH_BGPD, router_bgp, router_bgp_cmd, "router bgp <1-65535>", ROUTER_STR BGP_STR AS_STR){ vty->node = BGP_NODE; return CMD_SUCCESS;}DEFUNSH (VTYSH_BGPD, address_family_vpnv4, address_family_vpnv4_cmd, "address-family vpnv4", "Enter Address Family command mode\n" "Address family\n"){ vty->node = BGP_VPNV4_NODE; return CMD_SUCCESS;}DEFUNSH (VTYSH_BGPD, address_family_vpnv4_unicast, address_family_vpnv4_unicast_cmd, "address-family vpnv4 unicast", "Enter Address Family command mode\n" "Address family\n" "Address Family Modifier\n"){ vty->node = BGP_VPNV4_NODE; return CMD_SUCCESS;}DEFUNSH (VTYSH_BGPD, address_family_ipv4_unicast, address_family_ipv4_unicast_cmd, "address-family ipv4 unicast", "Enter Address Family command mode\n" "Address family\n" "Address Family Modifier\n"){ vty->node = BGP_IPV4_NODE; return CMD_SUCCESS;}DEFUNSH (VTYSH_BGPD, address_family_ipv4_multicast, address_family_ipv4_multicast_cmd, "address-family ipv4 multicast", "Enter Address Family command mode\n" "Address family\n" "Address Family Modifier\n"){ vty->node = BGP_IPV4M_NODE; return CMD_SUCCESS;}DEFUNSH (VTYSH_BGPD, address_family_ipv6, address_family_ipv6_cmd, "address-family ipv6", "Enter Address Family command mode\n" "Address family\n"){ vty->node = BGP_IPV6_NODE; return CMD_SUCCESS;}DEFUNSH (VTYSH_BGPD, address_family_ipv6_unicast, address_family_ipv6_unicast_cmd, "address-family ipv6 unicast", "Enter Address Family command mode\n" "Address family\n" "Address Family Modifier\n"){ vty->node = BGP_IPV6_NODE; return CMD_SUCCESS;}DEFUNSH (VTYSH_RIPD, key_chain, key_chain_cmd, "key chain WORD", "Authentication key management\n" "Key-chain management\n" "Key-chain name\n"){ vty->node = KEYCHAIN_NODE; return CMD_SUCCESS;} DEFUNSH (VTYSH_RIPD, key, key_cmd, "key <0-2147483647>", "Configure a key\n" "Key identifier number\n"){ vty->node = KEYCHAIN_KEY_NODE; return CMD_SUCCESS;}DEFUNSH (VTYSH_RIPD, router_rip, router_rip_cmd, "router rip", ROUTER_STR "RIP"){ vty->node = RIP_NODE; return CMD_SUCCESS;}DEFUNSH (VTYSH_RIPNGD, router_ripng, router_ripng_cmd, "router ripng", ROUTER_STR "RIPng"){ vty->node = RIPNG_NODE; return CMD_SUCCESS;}DEFUNSH (VTYSH_OSPFD, router_ospf, router_ospf_cmd, "router ospf", "Enable a routing process\n" "Start OSPF configuration\n"){ vty->node = OSPF_NODE; return CMD_SUCCESS;}DEFUNSH (VTYSH_OSPF6D, router_ospf6, router_ospf6_cmd, "router ospf6", OSPF6_ROUTER_STR OSPF6_STR){ vty->node = OSPF6_NODE; return CMD_SUCCESS;}DEFUNSH (VTYSH_RMAP, route_map, route_map_cmd, "route-map WORD (deny|permit) <1-65535>", "Create route-map or enter route-map command mode\n" "Route map tag\n" "Route map denies set operations\n" "Route map permits set operations\n" "Sequence to insert to/delete from existing route-map entry\n"){ vty->node = RMAP_NODE; return CMD_SUCCESS;}/* Enable command */DEFUNSH (VTYSH_ALL, vtysh_enable, vtysh_enable_cmd, "enable", "Turn on privileged mode command\n"){ vty->node = ENABLE_NODE; return CMD_SUCCESS;}/* Disable command */DEFUNSH (VTYSH_ALL, vtysh_disable, vtysh_disable_cmd, "disable", "Turn off privileged mode command\n"){ if (vty->node == ENABLE_NODE) vty->node = VIEW_NODE; return CMD_SUCCESS;}/* Configration from terminal */DEFUNSH (VTYSH_ALL, vtysh_config_terminal, vtysh_config_terminal_cmd, "configure terminal", "Configuration from vty interface\n" "Configuration terminal\n"){ vty->node = CONFIG_NODE; return CMD_SUCCESS;}intvtysh_exit (struct vty *vty){ switch (vty->node) { case VIEW_NODE: case ENABLE_NODE: exit (0); break; case CONFIG_NODE: vty->node = ENABLE_NODE; break; case INTERFACE_NODE: case ZEBRA_NODE: case BGP_NODE: case RIP_NODE: case RIPNG_NODE: case OSPF_NODE: case OSPF6_NODE: case MASC_NODE: case RMAP_NODE: case VTY_NODE: case KEYCHAIN_NODE: vty->node = CONFIG_NODE; break; case BGP_VPNV4_NODE: case BGP_IPV4_NODE: case BGP_IPV4M_NODE: case BGP_IPV6_NODE: vty->node = BGP_NODE; break; case KEYCHAIN_KEY_NODE: vty->node = KEYCHAIN_NODE; break; default: break; } return CMD_SUCCESS;}DEFUNSH (VTYSH_ALL, vtysh_exit_all, vtysh_exit_all_cmd, "exit", "Exit current mode and down to previous mode\n"){ return vtysh_exit (vty);}ALIAS (vtysh_exit_all, vtysh_quit_all_cmd, "quit", "Exit current mode and down to previous mode\n");DEFUNSH (VTYSH_BGPD, exit_address_family, exit_address_family_cmd, "exit-address-family", "Exit from Address Family configuration mode\n"){ if (vty->node == BGP_IPV4_NODE || vty->node == BGP_IPV4M_NODE || vty->node == BGP_VPNV4_NODE || vty->node == BGP_IPV6_NODE) vty->node = BGP_NODE; return CMD_SUCCESS;}DEFUNSH (VTYSH_ZEBRA, vtysh_exit_zebra, vtysh_exit_zebra_cmd, "exit", "Exit current mode and down to previous mode\n"){ return vtysh_exit (vty);}ALIAS (vtysh_exit_zebra, vtysh_quit_zebra_cmd, "quit", "Exit current mode and down to previous mode\n");DEFUNSH (VTYSH_RIPD, vtysh_exit_ripd, vtysh_exit_ripd_cmd, "exit", "Exit current mode and down to previous mode\n"){ return vtysh_exit (vty);}ALIAS (vtysh_exit_ripd, vtysh_quit_ripd_cmd, "quit", "Exit current mode and down to previous mode\n");DEFUNSH (VTYSH_RIPNGD, vtysh_exit_ripngd, vtysh_exit_ripngd_cmd, "exit", "Exit current mode and down to previous mode\n"){ return vtysh_exit (vty);}ALIAS (vtysh_exit_ripngd, vtysh_quit_ripngd_cmd, "quit", "Exit current mode and down to previous mode\n");DEFUNSH (VTYSH_RMAP, vtysh_exit_rmap, vtysh_exit_rmap_cmd, "exit", "Exit current mode and down to previous mode\n"){ return vtysh_exit (vty);}ALIAS (vtysh_exit_rmap, vtysh_quit_rmap_cmd, "quit", "Exit current mode and down to previous mode\n");DEFUNSH (VTYSH_BGPD, vtysh_exit_bgpd, vtysh_exit_bgpd_cmd, "exit", "Exit current mode and down to previous mode\n"){ return vtysh_exit (vty);}ALIAS (vtysh_exit_bgpd, vtysh_quit_bgpd_cmd, "quit", "Exit current mode and down to previous mode\n");DEFUNSH (VTYSH_OSPFD, vtysh_exit_ospfd, vtysh_exit_ospfd_cmd, "exit", "Exit current mode and down to previous mode\n"){ return vtysh_exit (vty);}ALIAS (vtysh_exit_ospfd, vtysh_quit_ospfd_cmd, "quit", "Exit current mode and down to previous mode\n");DEFUNSH (VTYSH_OSPF6D, vtysh_exit_ospf6d, vtysh_exit_ospf6d_cmd, "exit", "Exit current mode and down to previous mode\n"){ return vtysh_exit (vty);}ALIAS (vtysh_exit_ospf6d, vtysh_quit_ospf6d_cmd, "quit", "Exit current mode and down to previous mode\n");DEFUNSH (VTYSH_ZEBRA|VTYSH_RIPD|VTYSH_OSPFD|VTYSH_OSPF6D, vtysh_interface, vtysh_interface_cmd, "interface IFNAME", "Select an interface to configure\n" "Interface's name\n"){ vty->node = INTERFACE_NODE; return CMD_SUCCESS;}DEFUNSH (VTYSH_ZEBRA|VTYSH_RIPD|VTYSH_OSPFD|VTYSH_OSPF6D, vtysh_exit_interface, vtysh_exit_interface_cmd, "exit", "Exit current mode and down to previous mode\n"){ return vtysh_exit (vty);}ALIAS (vtysh_exit_interface, vtysh_quit_interface_cmd, "quit", "Exit current mode and down to previous mode\n");DEFUN (vtysh_write_terminal, vtysh_write_terminal_cmd, "write terminal", "Write running configuration to memory, network, or terminal\n" "Write to terminal\n"){ int ret; char line[] = "write terminal\n"; FILE *fp = NULL; if (vtysh_pager_name) { fp = popen ("more", "w"); if (fp == NULL) { perror ("popen"); exit (1); } } else fp = stdout; vty_out (vty, "Building configuration...%s", VTY_NEWLINE); vty_out (vty, "%sCurrent configuration:%s", VTY_NEWLINE, VTY_NEWLINE); 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); ret = vtysh_client_config (&vtysh_client[VTYSH_INDEX_OSPF], line); ret = vtysh_client_config (&vtysh_client[VTYSH_INDEX_OSPF6], line); ret = vtysh_client_config (&vtysh_client[VTYSH_INDEX_BGP], line);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -