vtysh.c
来自「zebra测试源代码用于 SOCKET 通信」· C语言 代码 · 共 2,119 行 · 第 1/4 页
C
2,119 行
continue; /* Execute configuration command : this is strict match */ ret = cmd_execute_command_strict (vline, vty, &cmd); /* Try again with setting node to CONFIG_NODE */ if (ret != CMD_SUCCESS && ret != CMD_SUCCESS_DAEMON && ret != CMD_WARNING) { if (vty->node == KEYCHAIN_KEY_NODE) { vty->node = KEYCHAIN_NODE; vtysh_exit_ripd_only (); ret = cmd_execute_command_strict (vline, vty, &cmd); if (ret != CMD_SUCCESS && ret != CMD_SUCCESS_DAEMON && ret != CMD_WARNING) { vtysh_exit_ripd_only (); vty->node = CONFIG_NODE; ret = cmd_execute_command_strict (vline, vty, &cmd); } } else { vtysh_execute ("end"); vtysh_execute ("configure terminal"); vty->node = CONFIG_NODE; ret = cmd_execute_command_strict (vline, vty, &cmd); } } cmd_free_strvec (vline); switch (ret) { case CMD_WARNING: if (vty->type == VTY_FILE) printf ("Warning...\n"); break; case CMD_ERR_AMBIGUOUS: printf ("%% Ambiguous command.\n"); break; case CMD_ERR_NO_MATCH: printf ("%% Unknown command: %s", vty->buf); break; case CMD_ERR_INCOMPLETE: printf ("%% Command incomplete.\n"); break; case CMD_SUCCESS_DAEMON: { if (cmd->daemon & VTYSH_ZEBRA) if (vtysh_client_execute (&vtysh_client[VTYSH_INDEX_ZEBRA], vty->buf, stdout) != CMD_SUCCESS) break; if (cmd->daemon & VTYSH_RIPD) if (vtysh_client_execute (&vtysh_client[VTYSH_INDEX_RIP], vty->buf, stdout) != CMD_SUCCESS) break; if (cmd->daemon & VTYSH_RIPNGD) if (vtysh_client_execute (&vtysh_client[VTYSH_INDEX_RIPNG], vty->buf, stdout) != CMD_SUCCESS) break; if (cmd->daemon & VTYSH_OSPFD) if (vtysh_client_execute (&vtysh_client[VTYSH_INDEX_OSPF], vty->buf, stdout) != CMD_SUCCESS) break; if (cmd->daemon & VTYSH_OSPF6D) if (vtysh_client_execute (&vtysh_client[VTYSH_INDEX_OSPF6], vty->buf, stdout) != CMD_SUCCESS) break; if (cmd->daemon & VTYSH_BGPD) if (vtysh_client_execute (&vtysh_client[VTYSH_INDEX_BGP], vty->buf, stdout) != CMD_SUCCESS) break; if (cmd->func) (*cmd->func) (cmd, vty, 0, NULL); } } } return CMD_SUCCESS;}/* We don't care about the point of the cursor when '?' is typed. */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
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?