]> git.proxmox.com Git - mirror_frr.git/blobdiff - vtysh/vtysh.c
lib: enforce vrf_name_to_id by returning default_vrf when name is null
[mirror_frr.git] / vtysh / vtysh.c
index ef4d1a083506fcc83d89a57b00d069a2a2688dfc..2327f2b46d7e04219518ab89d5d7fe849d307db9 100644 (file)
@@ -104,7 +104,7 @@ static int vty_close_pager(struct vty *vty)
        return 0;
 }
 
-void vtysh_pager_init(void)
+static void vtysh_pager_envdef(void)
 {
        char *pager_defined;
 
@@ -132,6 +132,7 @@ struct vtysh_client vtysh_client[] = {
        {.fd = -1, .name = "eigrpd", .flag = VTYSH_EIGRPD, .next = NULL},
        {.fd = -1, .name = "babeld", .flag = VTYSH_BABELD, .next = NULL},
        {.fd = -1, .name = "sharpd", .flag = VTYSH_SHARPD, .next = NULL},
+       {.fd = -1, .name = "fabricd", .flag = VTYSH_FABRICD, .next = NULL},
        {.fd = -1, .name = "watchfrr", .flag = VTYSH_WATCHFRR, .next = NULL},
        {.fd = -1, .name = "pbrd", .flag = VTYSH_PBRD, .next = NULL},
        {.fd = -1, .name = "staticd", .flag = VTYSH_STATICD, .next = NULL},
@@ -576,7 +577,7 @@ static int vtysh_execute_func(const char *line, int pager)
                                    && (cmd->daemon == vtysh_client[i].flag)) {
                                        for (vc = &vtysh_client[i]; vc;
                                             vc = vc->next)
-                                               if (vc->fd < 0)
+                                               if (vc->fd == VTYSH_WAS_ACTIVE)
                                                        vtysh_reconnect(vc);
                                }
                                if (vtysh_client[i].fd < 0
@@ -855,7 +856,7 @@ int vtysh_config_from_file(struct vty *vty, FILE *fp)
        while (fgets(vty->buf, VTY_BUFSIZ, fp)) {
                lineno++;
 
-               ret = command_config_read_one_line(vty, &cmd, 1);
+               ret = command_config_read_one_line(vty, &cmd, lineno, 1);
 
                switch (ret) {
                case CMD_WARNING:
@@ -1112,7 +1113,7 @@ static char *command_generator(const char *text, int state)
        return NULL;
 }
 
-static char **new_completion(char *text, int start, int end)
+static char **new_completion(const char *text, int start, int end)
 {
        char **matches;
 
@@ -1141,6 +1142,10 @@ static struct cmd_node isis_node = {
        ISIS_NODE, "%s(config-router)# ",
 };
 
+static struct cmd_node openfabric_node = {
+       OPENFABRIC_NODE, "%s(config-router)# ",
+};
+
 static struct cmd_node interface_node = {
        INTERFACE_NODE, "%s(config-if)# ",
 };
@@ -1252,9 +1257,7 @@ struct cmd_node link_params_node = {
        LINK_PARAMS_NODE, "%s(config-link-params)# ",
 };
 
-#if defined(HAVE_RPKI)
 static struct cmd_node rpki_node = {RPKI_NODE, "%s(config-rpki)# ", 1};
-#endif
 
 #if HAVE_BFDD > 0
 static struct cmd_node bfd_node = {
@@ -1424,7 +1427,6 @@ DEFUNSH(VTYSH_BGPD, address_family_ipv6_labeled_unicast,
        return CMD_SUCCESS;
 }
 
-#if defined(HAVE_RPKI)
 DEFUNSH(VTYSH_BGPD,
        rpki,
        rpki_cmd,
@@ -1435,26 +1437,6 @@ DEFUNSH(VTYSH_BGPD,
        return CMD_SUCCESS;
 }
 
-DEFUNSH(VTYSH_BGPD,
-       rpki_exit,
-       rpki_exit_cmd,
-       "exit",
-       "Exit current mode and down to previous mode\n")
-{
-       vty->node = CONFIG_NODE;
-       return CMD_SUCCESS;
-}
-
-DEFUNSH(VTYSH_BGPD,
-       rpki_quit,
-       rpki_quit_cmd,
-       "quit",
-       "Exit current mode and down to previous mode\n")
-{
-       return rpki_exit(self, vty, argc, argv);
-}
-#endif
-
 DEFUNSH(VTYSH_BGPD, address_family_evpn, address_family_evpn_cmd,
        "address-family <l2vpn evpn>",
        "Enter Address Family command mode\n"
@@ -1476,7 +1458,7 @@ DEFUNSH_HIDDEN(VTYSH_BGPD, address_family_evpn2, address_family_evpn2_cmd,
 }
 #endif
 
-DEFUNSH(VTYSH_BGPD, bgp_evpn_vni, bgp_evpn_vni_cmd, "vni (1-16777215)",
+DEFUNSH(VTYSH_BGPD, bgp_evpn_vni, bgp_evpn_vni_cmd, "vni " CMD_VNI_RANGE,
        "VXLAN Network Identifier\n"
        "VNI number\n")
 {
@@ -1520,7 +1502,7 @@ DEFUNSH(VTYSH_BGPD, vnc_l2_group, vnc_l2_group_cmd, "vnc l2-group NAME",
 }
 #endif
 
-DEFUNSH(VTYSH_RIPD, key_chain, key_chain_cmd, "key chain WORD",
+DEFUNSH(VTYSH_KEYS, key_chain, key_chain_cmd, "key chain WORD",
        "Authentication key management\n"
        "Key-chain management\n"
        "Key-chain name\n")
@@ -1529,7 +1511,7 @@ DEFUNSH(VTYSH_RIPD, key_chain, key_chain_cmd, "key chain WORD",
        return CMD_SUCCESS;
 }
 
-DEFUNSH(VTYSH_RIPD, key, key_cmd, "key (0-2147483647)",
+DEFUNSH(VTYSH_KEYS, key, key_cmd, "key (0-2147483647)",
        "Configure a key\n"
        "Key identifier number\n")
 {
@@ -1671,6 +1653,15 @@ DEFUNSH(VTYSH_ISISD, router_isis, router_isis_cmd, "router isis WORD",
        return CMD_SUCCESS;
 }
 
+DEFUNSH(VTYSH_FABRICD, router_openfabric, router_openfabric_cmd, "router openfabric WORD",
+       ROUTER_STR
+       "OpenFabric routing protocol\n"
+       "ISO Routing area tag\n")
+{
+       vty->node = OPENFABRIC_NODE;
+       return CMD_SUCCESS;
+}
+
 DEFUNSH(VTYSH_RMAP, vtysh_route_map, vtysh_route_map_cmd,
        "route-map WORD <deny|permit> (1-65535)",
        "Create route-map or enter route-map command mode\n"
@@ -1785,11 +1776,13 @@ static int vtysh_exit(struct vty *vty)
        case LDP_NODE:
        case LDP_L2VPN_NODE:
        case ISIS_NODE:
+       case OPENFABRIC_NODE:
        case RMAP_NODE:
        case PBRMAP_NODE:
        case VTY_NODE:
        case KEYCHAIN_NODE:
        case BFD_NODE:
+       case RPKI_NODE:
                vtysh_execute("end");
                vtysh_execute("configure terminal");
                vty->node = CONFIG_NODE;
@@ -1883,6 +1876,20 @@ DEFUNSH(VTYSH_BGPD, exit_vnc_config, exit_vnc_config_cmd, "exit-vnc",
            || vty->node == BGP_VNC_L2_GROUP_NODE)
                vty->node = BGP_NODE;
        return CMD_SUCCESS;
+
+}
+
+DEFUNSH(VTYSH_BGPD, rpki_exit, rpki_exit_cmd, "exit",
+       "Exit current mode and down to previous mode\n")
+{
+       vtysh_exit(vty);
+       return CMD_SUCCESS;
+}
+
+DEFUNSH(VTYSH_BGPD, rpki_quit, rpki_quit_cmd, "quit",
+       "Exit current mode and down to previous mode\n")
+{
+       return rpki_exit(self, vty, argc, argv);
 }
 
 DEFUNSH(VTYSH_PIMD|VTYSH_ZEBRA, exit_vrf_config, exit_vrf_config_cmd, "exit-vrf",
@@ -2043,6 +2050,18 @@ ALIAS(vtysh_exit_bfdd, vtysh_quit_bfdd_cmd, "quit",
       "Exit current mode and down to previous mode\n")
 #endif
 
+DEFUNSH(VTYSH_FABRICD, vtysh_exit_fabricd, vtysh_exit_fabricd_cmd, "exit",
+       "Exit current mode and down to previous mode\n")
+{
+       return vtysh_exit(vty);
+}
+
+DEFUNSH(VTYSH_FABRICD, vtysh_quit_fabricd, vtysh_quit_fabricd_cmd, "quit",
+       "Exit current mode and down to previous mode\n")
+{
+       return vtysh_exit_fabricd(self, vty, argc, argv);
+}
+
 DEFUNSH(VTYSH_ALL, vtysh_exit_line_vty, vtysh_exit_line_vty_cmd, "exit",
        "Exit current mode and down to previous mode\n")
 {
@@ -2246,7 +2265,7 @@ DEFUN (vtysh_show_work_queues,
 
 DEFUN (vtysh_show_work_queues_daemon,
        vtysh_show_work_queues_daemon_cmd,
-       "show work-queues <zebra|ripd|ripngd|ospfd|ospf6d|bgpd|isisd|pbrd>",
+       "show work-queues <zebra|ripd|ripngd|ospfd|ospf6d|bgpd|isisd|pbrd|fabricd|pimd|staticd>",
        SHOW_STR
        "Work Queue information\n"
        "For the zebra daemon\n"
@@ -2256,7 +2275,10 @@ DEFUN (vtysh_show_work_queues_daemon,
        "For the ospfv6 daemon\n"
        "For the bgp daemon\n"
        "For the isis daemon\n"
-       "For the pbr daemon\n")
+       "For the pbr daemon\n"
+       "For the fabricd daemon\n"
+       "For the pim daemon\n"
+       "For the static daemon\n")
 {
        int idx_protocol = 2;
        unsigned int i;
@@ -2594,7 +2616,7 @@ DEFUNSH(VTYSH_ALL, no_vtysh_config_enable_password,
 
 DEFUN (vtysh_write_terminal,
        vtysh_write_terminal_cmd,
-       "write terminal [<zebra|ripd|ripngd|ospfd|ospf6d|ldpd|bgpd|isisd|pimd>]",
+       "write terminal [<zebra|ripd|ripngd|ospfd|ospf6d|ldpd|bgpd|isisd|fabricd|pimd|staticd>]",
        "Write running configuration to memory, network, or terminal\n"
        "Write to terminal\n"
        "For the zebra daemon\n"
@@ -2605,7 +2627,9 @@ DEFUN (vtysh_write_terminal,
        "For the ldpd daemon\n"
        "For the bgp daemon\n"
        "For the isis daemon\n"
-       "For the pim daemon\n")
+       "For the fabricd daemon\n"
+       "For the pim daemon\n"
+       "For the static daemon\n")
 {
        unsigned int i;
        char line[] = "do write terminal\n";
@@ -2631,7 +2655,7 @@ DEFUN (vtysh_write_terminal,
 
 DEFUN (vtysh_show_running_config,
        vtysh_show_running_config_cmd,
-       "show running-config [<zebra|ripd|ripngd|ospfd|ospf6d|ldpd|bgpd|isisd|pimd>]",
+       "show running-config [<zebra|ripd|ripngd|ospfd|ospf6d|ldpd|bgpd|isisd|fabricd|pimd|staticd>]",
        SHOW_STR
        "Current operating configuration\n"
        "For the zebra daemon\n"
@@ -2642,7 +2666,9 @@ DEFUN (vtysh_show_running_config,
        "For the ldp daemon\n"
        "For the bgp daemon\n"
        "For the isis daemon\n"
-       "For the pim daemon\n")
+       "For the fabricd daemon\n"
+       "For the pim daemon\n"
+       "For the static daemon\n")
 {
        return vtysh_write_terminal(self, vty, argc, argv);
 }
@@ -2855,52 +2881,58 @@ DEFUN (vtysh_copy_running_config,
        return vtysh_write_memory(self, vty, argc, argv);
 }
 
+DEFUN (vtysh_terminal_paginate,
+       vtysh_terminal_paginate_cmd,
+       "[no] terminal paginate",
+       NO_STR
+       "Set terminal line parameters\n"
+       "Use pager for output scrolling\n")
+{
+       free(vtysh_pager_name);
+       vtysh_pager_name = NULL;
+
+       if (strcmp(argv[0]->text, "no"))
+               vtysh_pager_envdef();
+       return CMD_SUCCESS;
+}
+
 DEFUN (vtysh_terminal_length,
        vtysh_terminal_length_cmd,
-       "terminal length (0-512)",
+       "[no] terminal length (0-4294967295)",
+       NO_STR
        "Set terminal line parameters\n"
        "Set number of lines on a screen\n"
-       "Number of lines on screen (0 for no pausing)\n")
+       "Number of lines on screen (0 for no pausing, nonzero to use pager)\n")
 {
        int idx_number = 2;
-       int lines;
-       char *endptr = NULL;
-       char default_pager[10];
+       unsigned long lines;
 
-       lines = strtol(argv[idx_number]->arg, &endptr, 10);
-       if (lines < 0 || lines > 512 || *endptr != '\0') {
-               vty_out(vty, "length is malformed\n");
-               return CMD_WARNING;
-       }
+       free(vtysh_pager_name);
+       vtysh_pager_name = NULL;
 
-       if (vtysh_pager_name) {
-               free(vtysh_pager_name);
-               vtysh_pager_name = NULL;
+       if (!strcmp(argv[0]->text, "no") || !strcmp(argv[1]->text, "no")) {
+               /* "terminal no length" = use VTYSH_PAGER */
+               vtysh_pager_envdef();
+               return CMD_SUCCESS;
        }
 
+       lines = strtoul(argv[idx_number]->arg, NULL, 10);
        if (lines != 0) {
-               snprintf(default_pager, 10, "more -%i", lines);
-               vtysh_pager_name = strdup(default_pager);
+               vty_out(vty,
+                       "%% The \"terminal length\" command is deprecated and its value is ignored.\n"
+                       "%% Please use \"terminal paginate\" instead with OS TTY length handling.\n");
+               vtysh_pager_envdef();
        }
 
        return CMD_SUCCESS;
 }
 
-DEFUN (vtysh_terminal_no_length,
+ALIAS_DEPRECATED(vtysh_terminal_length,
        vtysh_terminal_no_length_cmd,
        "terminal no length",
        "Set terminal line parameters\n"
        NO_STR
        "Set number of lines on a screen\n")
-{
-       if (vtysh_pager_name) {
-               free(vtysh_pager_name);
-               vtysh_pager_name = NULL;
-       }
-
-       vtysh_pager_init();
-       return CMD_SUCCESS;
-}
 
 DEFUN (vtysh_show_daemons,
        vtysh_show_daemons_cmd,
@@ -3387,8 +3419,7 @@ void vtysh_readline_init(void)
        rl_initialize();
        rl_bind_key('?', (rl_command_func_t *)vtysh_rl_describe);
        rl_completion_entry_function = vtysh_completion_entry_function;
-       rl_attempted_completion_function =
-               (rl_completion_func_t *)new_completion;
+       rl_attempted_completion_function = new_completion;
 }
 
 char *vtysh_prompt(void)
@@ -3495,10 +3526,9 @@ void vtysh_init_vty(void)
        install_node(&keychain_node, NULL);
        install_node(&keychain_key_node, NULL);
        install_node(&isis_node, NULL);
+       install_node(&openfabric_node, NULL);
        install_node(&vty_node, NULL);
-#if defined(HAVE_RPKI)
        install_node(&rpki_node, NULL);
-#endif
 #if HAVE_BFDD > 0
        install_node(&bfd_node, NULL);
        install_node(&bfd_peer_node, NULL);
@@ -3589,6 +3619,8 @@ void vtysh_init_vty(void)
 #endif
        install_element(ISIS_NODE, &vtysh_exit_isisd_cmd);
        install_element(ISIS_NODE, &vtysh_quit_isisd_cmd);
+       install_element(OPENFABRIC_NODE, &vtysh_exit_fabricd_cmd);
+       install_element(OPENFABRIC_NODE, &vtysh_quit_fabricd_cmd);
        install_element(KEYCHAIN_NODE, &vtysh_exit_ripd_cmd);
        install_element(KEYCHAIN_NODE, &vtysh_quit_ripd_cmd);
        install_element(KEYCHAIN_KEY_NODE, &vtysh_exit_ripd_cmd);
@@ -3649,6 +3681,7 @@ void vtysh_init_vty(void)
        install_element(BGP_VNC_NVE_GROUP_NODE, &vtysh_end_all_cmd);
        install_element(BGP_VNC_L2_GROUP_NODE, &vtysh_end_all_cmd);
        install_element(ISIS_NODE, &vtysh_end_all_cmd);
+       install_element(OPENFABRIC_NODE, &vtysh_end_all_cmd);
        install_element(KEYCHAIN_NODE, &vtysh_end_all_cmd);
        install_element(KEYCHAIN_KEY_NODE, &vtysh_end_all_cmd);
        install_element(RMAP_NODE, &vtysh_end_all_cmd);
@@ -3698,6 +3731,7 @@ void vtysh_init_vty(void)
        install_element(LDP_L2VPN_NODE, &ldp_member_pseudowire_ifname_cmd);
 #endif
        install_element(CONFIG_NODE, &router_isis_cmd);
+       install_element(CONFIG_NODE, &router_openfabric_cmd);
        install_element(CONFIG_NODE, &router_bgp_cmd);
        install_element(BGP_NODE, &address_family_vpnv4_cmd);
        install_element(BGP_NODE, &address_family_vpnv6_cmd);
@@ -3733,12 +3767,10 @@ void vtysh_init_vty(void)
        install_element(BGP_FLOWSPECV4_NODE, &exit_address_family_cmd);
        install_element(BGP_FLOWSPECV6_NODE, &exit_address_family_cmd);
 
-#if defined(HAVE_RPKI)
        install_element(CONFIG_NODE, &rpki_cmd);
        install_element(RPKI_NODE, &rpki_exit_cmd);
        install_element(RPKI_NODE, &rpki_quit_cmd);
        install_element(RPKI_NODE, &vtysh_end_all_cmd);
-#endif
 
        /* EVPN commands */
        install_element(BGP_EVPN_NODE, &bgp_evpn_vni_cmd);
@@ -3779,6 +3811,7 @@ void vtysh_init_vty(void)
        /* "write memory" command. */
        install_element(ENABLE_NODE, &vtysh_write_memory_cmd);
 
+       install_element(VIEW_NODE, &vtysh_terminal_paginate_cmd);
        install_element(VIEW_NODE, &vtysh_terminal_length_cmd);
        install_element(VIEW_NODE, &vtysh_terminal_no_length_cmd);
        install_element(VIEW_NODE, &vtysh_show_daemons_cmd);