diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-08-05 09:56:25 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-08-05 09:56:25 +0000 |
commit | 289582b3dcbeb23328325d224c7db7de66a3a55f (patch) | |
tree | 989c36d57aab945c36e34c952f438746ce18b3bd /vtysh | |
parent | Releasing progress-linux version 10.0.1-0.1~progress7.99u1. (diff) | |
download | frr-289582b3dcbeb23328325d224c7db7de66a3a55f.tar.xz frr-289582b3dcbeb23328325d224c7db7de66a3a55f.zip |
Merging upstream version 10.1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vtysh')
-rw-r--r-- | vtysh/vtysh.c | 341 | ||||
-rw-r--r-- | vtysh/vtysh.h | 20 |
2 files changed, 283 insertions, 78 deletions
diff --git a/vtysh/vtysh.c b/vtysh/vtysh.c index 12d22b1..b1c957d 100644 --- a/vtysh/vtysh.c +++ b/vtysh/vtysh.c @@ -39,7 +39,6 @@ #include "frrstr.h" #include "json.h" #include "ferr.h" -#include "bgpd/bgp_vty.h" DEFINE_MTYPE_STATIC(MVTYSH, VTYSH_CMD, "Vtysh cmd copy"); @@ -3474,6 +3473,259 @@ DEFPY (show_route_map, return CMD_SUCCESS; } +static void show_prefix_list_send(afi_t afi, const char *prefix_list, + const char *seq, enum display_type dtype, + bool json) +{ + unsigned int i; + bool first = true; + char command_line[128]; + + if (afi == AFI_IP) + snprintf(command_line, sizeof(command_line), + "do show ip prefix-list "); + else if (afi == AFI_IP6) + snprintf(command_line, sizeof(command_line), + "do show ipv6 prefix-list "); + if (dtype == detail_display) + strlcat(command_line, "detail ", sizeof(command_line)); + else if (dtype == summary_display) + strlcat(command_line, "summary ", sizeof(command_line)); + if (prefix_list) + strlcat(command_line, prefix_list, sizeof(command_line)); + if (dtype == sequential_display) { + strlcat(command_line, " seq ", sizeof(command_line)); + strlcat(command_line, seq, sizeof(command_line)); + } + if (json) + strlcat(command_line, " json", sizeof(command_line)); + + if (json) + vty_out(vty, "{"); + + for (i = 0; i < array_size(vtysh_client); i++) { + const struct vtysh_client *client = &vtysh_client[i]; + bool is_connected = true; + + if (!CHECK_FLAG(client->flag, VTYSH_PREFIX_LIST_SHOW)) + continue; + + for (; client; client = client->next) + if (client->fd < 0) + is_connected = false; + + if (!is_connected) + continue; + + if (json && !first) + vty_out(vty, ","); + else + first = false; + + if (json) + vty_out(vty, "\"%s\":", vtysh_client[i].name); + + vtysh_client_execute_name(vtysh_client[i].name, command_line); + } + + if (json) + vty_out(vty, "}\n"); +} + +DEFPY (show_ip_prefix_list, + show_ip_prefix_list_cmd, + "show ip prefix-list [PREFIXLIST4_NAME$name [seq$dseq (1-4294967295)$arg]] [json$uj]", + SHOW_STR + IP_STR + PREFIX_LIST_STR + "Name of a prefix list\n" + "sequence number of an entry\n" + "Sequence number\n" + JSON_STR) +{ + enum display_type dtype = normal_display; + + if (dseq) + dtype = sequential_display; + + show_prefix_list_send(AFI_IP, name, arg_str, dtype, !!uj); + return CMD_SUCCESS; +} + +DEFPY (show_ip_prefix_list_summary, + show_ip_prefix_list_summary_cmd, + "show ip prefix-list summary [PREFIXLIST4_NAME$name] [json$uj]", + SHOW_STR + IP_STR + PREFIX_LIST_STR + "Summary of prefix lists\n" + "Name of a prefix list\n" + JSON_STR) +{ + show_prefix_list_send(AFI_IP, name, NULL, summary_display, !!uj); + return CMD_SUCCESS; +} + +DEFPY (show_ip_prefix_list_detail, + show_ip_prefix_list_detail_cmd, + "show ip prefix-list detail [PREFIXLIST4_NAME$name] [json$uj]", + SHOW_STR + IP_STR + PREFIX_LIST_STR + "Detail of prefix lists\n" + "Name of a prefix list\n" + JSON_STR) +{ + show_prefix_list_send(AFI_IP, name, NULL, detail_display, !!uj); + return CMD_SUCCESS; +} + +DEFPY (show_ipv6_prefix_list, + show_ipv6_prefix_list_cmd, + "show ipv6 prefix-list [PREFIXLIST6_NAME$name [seq$dseq (1-4294967295)$arg]] [json$uj]", + SHOW_STR + IPV6_STR + PREFIX_LIST_STR + "Name of a prefix list\n" + "sequence number of an entry\n" + "Sequence number\n" + JSON_STR) +{ + enum display_type dtype = normal_display; + + if (dseq) + dtype = sequential_display; + + show_prefix_list_send(AFI_IP6, name, arg_str, dtype, !!uj); + return CMD_SUCCESS; +} + +DEFPY (show_ipv6_prefix_list_summary, + show_ipv6_prefix_list_summary_cmd, + "show ipv6 prefix-list summary [PREFIXLIST6_NAME$name] [json$uj]", + SHOW_STR + IPV6_STR + PREFIX_LIST_STR + "Summary of prefix lists\n" + "Name of a prefix list\n" + JSON_STR) +{ + show_prefix_list_send(AFI_IP6, name, NULL, summary_display, !!uj); + return CMD_SUCCESS; +} + +DEFPY (show_ipv6_prefix_list_detail, + show_ipv6_prefix_list_detail_cmd, + "show ipv6 prefix-list detail [PREFIXLIST6_NAME$name] [json$uj]", + SHOW_STR + IPV6_STR + PREFIX_LIST_STR + "Detail of prefix lists\n" + "Name of a prefix list\n" + JSON_STR) +{ + show_prefix_list_send(AFI_IP6, name, NULL, detail_display, !!uj); + return CMD_SUCCESS; +} + +static void show_access_list_send(afi_t afi, const char *access_list, bool json) +{ + unsigned int i; + bool first = true; + char command_line[128]; + + if (afi == AFI_IP) + snprintf(command_line, sizeof(command_line), + "do show ip access-list "); + else if (afi == AFI_IP6) + snprintf(command_line, sizeof(command_line), + "do show ipv6 access-list "); + if (access_list) + strlcat(command_line, access_list, sizeof(command_line)); + if (json) { + strlcat(command_line, " json", sizeof(command_line)); + vty_out(vty, "{"); + } + + for (i = 0; i < array_size(vtysh_client); i++) { + const struct vtysh_client *client = &vtysh_client[i]; + bool is_connected = true; + + if (!CHECK_FLAG(client->flag, VTYSH_ACCESS_LIST_SHOW)) + continue; + + for (; client; client = client->next) + if (client->fd < 0) + is_connected = false; + + if (!is_connected) + continue; + + if (json && !first) + vty_out(vty, ","); + else + first = false; + + if (json) + vty_out(vty, "\"%s\":", vtysh_client[i].name); + + vtysh_client_execute_name(vtysh_client[i].name, command_line); + } + + if (json) + vty_out(vty, "}\n"); +} + +DEFPY (show_ip_access_list, + show_ip_access_list_cmd, + "show ip access-list [json$uj]", + SHOW_STR + IP_STR + "List IP access lists\n" + JSON_STR) +{ + show_access_list_send(AFI_IP, NULL, !!uj); + return CMD_SUCCESS; +} + +DEFPY (show_ip_access_list_name, + show_ip_access_list_name_cmd, + "show ip access-list ACCESSLIST4_NAME$name [json$uj]", + SHOW_STR + IP_STR + "List IP access lists\n" + "IP access-list name\n" + JSON_STR) +{ + show_access_list_send(AFI_IP, name, !!uj); + return CMD_SUCCESS; +} + +DEFPY (show_ipv6_access_list, + show_ipv6_access_list_cmd, + "show ipv6 access-list [json$uj]", + SHOW_STR + IPV6_STR + "List IPv6 access lists\n" + JSON_STR) +{ + show_access_list_send(AFI_IP6, NULL, !!uj); + return CMD_SUCCESS; +} + +DEFPY (show_ipv6_access_list_name, + show_ipv6_access_list_name_cmd, + "show ipv6 access-list ACCESSLIST6_NAME$name [json$uj]", + SHOW_STR + IPV6_STR + "List IPv6 access lists\n" + "IPv6 access-list name\n" + JSON_STR) +{ + show_access_list_send(AFI_IP6, name, !!uj); + return CMD_SUCCESS; +} + DEFUN (vtysh_integrated_config, vtysh_integrated_config_cmd, "service integrated-vtysh-config", @@ -3498,8 +3750,8 @@ DEFUN (no_vtysh_integrated_config, static void backup_config_file(const char *fbackup) { char *integrate_sav = NULL; - size_t integrate_sav_sz = strlen(fbackup) + strlen(CONF_BACKUP_EXT) + 1; + integrate_sav = malloc(integrate_sav_sz); strlcpy(integrate_sav, fbackup, integrate_sav_sz); strlcat(integrate_sav, CONF_BACKUP_EXT, integrate_sav_sz); @@ -4208,71 +4460,6 @@ DEFUN (vtysh_traceroute6, return CMD_SUCCESS; } -#if CONFDATE > 20240201 -CPP_NOTICE("Remove HAVE_SHELL_ACCESS and it's documentation"); -#endif -#if defined(HAVE_SHELL_ACCESS) -DEFUN (vtysh_telnet, - vtysh_telnet_cmd, - "telnet WORD", - "Open a telnet connection\n" - "IP address or hostname of a remote system\n") -{ - execute_command("telnet", 1, argv[1]->arg, NULL); - return CMD_SUCCESS; -} - -DEFUN (vtysh_telnet_port, - vtysh_telnet_port_cmd, - "telnet WORD PORT", - "Open a telnet connection\n" - "IP address or hostname of a remote system\n" - "TCP Port number\n") -{ - execute_command("telnet", 2, argv[1]->arg, argv[2]->arg); - return CMD_SUCCESS; -} - -DEFUN (vtysh_ssh, - vtysh_ssh_cmd, - "ssh WORD", - "Open an ssh connection\n" - "[user@]host\n") -{ - execute_command("ssh", 1, argv[1]->arg, NULL); - return CMD_SUCCESS; -} - -DEFUN (vtysh_start_shell, - vtysh_start_shell_cmd, - "start-shell", - "Start UNIX shell\n") -{ - execute_command("sh", 0, NULL, NULL); - return CMD_SUCCESS; -} - -DEFUN (vtysh_start_bash, - vtysh_start_bash_cmd, - "start-shell bash", - "Start UNIX shell\n" - "Start bash\n") -{ - execute_command("bash", 0, NULL, NULL); - return CMD_SUCCESS; -} - -DEFUN (vtysh_start_zsh, - vtysh_start_zsh_cmd, - "start-shell zsh", - "Start UNIX shell\n" - "Start Z shell\n") -{ - execute_command("zsh", 0, NULL, NULL); - return CMD_SUCCESS; -} -#endif - DEFUN (config_list, config_list_cmd, "list [permutations]", @@ -5139,6 +5326,16 @@ void vtysh_init_vty(void) install_element(ENABLE_NODE, &vtysh_copy_to_running_cmd); install_element(ENABLE_NODE, &show_route_map_cmd); + install_element(ENABLE_NODE, &show_ip_prefix_list_cmd); + install_element(ENABLE_NODE, &show_ip_prefix_list_summary_cmd); + install_element(ENABLE_NODE, &show_ip_prefix_list_detail_cmd); + install_element(ENABLE_NODE, &show_ipv6_prefix_list_cmd); + install_element(ENABLE_NODE, &show_ipv6_prefix_list_summary_cmd); + install_element(ENABLE_NODE, &show_ipv6_prefix_list_detail_cmd); + install_element(ENABLE_NODE, &show_ip_access_list_cmd); + install_element(ENABLE_NODE, &show_ip_access_list_name_cmd); + install_element(ENABLE_NODE, &show_ipv6_access_list_cmd); + install_element(ENABLE_NODE, &show_ipv6_access_list_name_cmd); /* "write terminal" command. */ install_element(ENABLE_NODE, &vtysh_write_terminal_cmd); @@ -5169,16 +5366,6 @@ void vtysh_init_vty(void) install_element(VIEW_NODE, &vtysh_mtrace_cmd); install_element(VIEW_NODE, &vtysh_ping6_cmd); install_element(VIEW_NODE, &vtysh_traceroute6_cmd); -#if defined(HAVE_SHELL_ACCESS) - install_element(VIEW_NODE, &vtysh_telnet_cmd); - install_element(VIEW_NODE, &vtysh_telnet_port_cmd); - install_element(VIEW_NODE, &vtysh_ssh_cmd); -#endif -#if defined(HAVE_SHELL_ACCESS) - install_element(ENABLE_NODE, &vtysh_start_shell_cmd); - install_element(ENABLE_NODE, &vtysh_start_bash_cmd); - install_element(ENABLE_NODE, &vtysh_start_zsh_cmd); -#endif /* debugging */ install_element(VIEW_NODE, &vtysh_show_error_code_cmd); diff --git a/vtysh/vtysh.h b/vtysh/vtysh.h index 7758cea..b1d57aa 100644 --- a/vtysh/vtysh.h +++ b/vtysh/vtysh.h @@ -68,6 +68,14 @@ extern struct event_loop *master; VTYSH_ZEBRA | VTYSH_RIPD | VTYSH_RIPNGD | VTYSH_OSPFD | VTYSH_OSPF6D | \ VTYSH_BGPD | VTYSH_ISISD | VTYSH_PIMD | VTYSH_EIGRPD | \ VTYSH_FABRICD +#define VTYSH_ACCESS_LIST_SHOW \ + VTYSH_ZEBRA | VTYSH_RIPD | VTYSH_RIPNGD | VTYSH_OSPFD | VTYSH_OSPF6D | \ + VTYSH_BGPD | VTYSH_ISISD | VTYSH_PIMD | VTYSH_EIGRPD | \ + VTYSH_FABRICD +#define VTYSH_PREFIX_LIST_SHOW \ + VTYSH_ZEBRA | VTYSH_RIPD | VTYSH_RIPNGD | VTYSH_OSPFD | VTYSH_OSPF6D | \ + VTYSH_BGPD | VTYSH_ISISD | VTYSH_PIMD | VTYSH_EIGRPD | \ + VTYSH_FABRICD #define VTYSH_INTERFACE_SUBSET \ VTYSH_OSPFD | VTYSH_OSPF6D | \ VTYSH_ISISD | VTYSH_PIMD | VTYSH_PIM6D | VTYSH_NHRPD | \ @@ -75,7 +83,7 @@ extern struct event_loop *master; VTYSH_VRRPD | VTYSH_MGMTD #define VTYSH_INTERFACE VTYSH_INTERFACE_SUBSET | VTYSH_BGPD #define VTYSH_VRF VTYSH_INTERFACE_SUBSET | VTYSH_BGPD -#define VTYSH_KEYS VTYSH_RIPD | VTYSH_EIGRPD | VTYSH_OSPF6D | VTYSH_OSPFD +#define VTYSH_KEYS VTYSH_MGMTD | VTYSH_EIGRPD | VTYSH_OSPF6D | VTYSH_OSPFD /* Daemons who can process nexthop-group configs */ #define VTYSH_NH_GROUP VTYSH_PBRD|VTYSH_SHARPD #define VTYSH_SR VTYSH_ZEBRA|VTYSH_PATHD @@ -90,7 +98,17 @@ enum vtysh_write_integrated { WRITE_INTEGRATED_YES }; +enum display_type { + normal_display, + summary_display, + detail_display, + sequential_display, + longer_display, + first_match_display +}; + extern enum vtysh_write_integrated vtysh_write_integrated; +extern enum display_type display_type; extern char frr_config[]; extern char vtydir[]; |