]> git.puffer.fish Git - mirror/frr.git/commitdiff
lib: simplify detection of when the user is leaving the CLI config mode
authorRenato Westphal <renato@opensourcerouting.org>
Sat, 19 Jan 2019 01:23:45 +0000 (23:23 -0200)
committerRenato Westphal <renato@opensourcerouting.org>
Tue, 19 Feb 2019 12:42:34 +0000 (09:42 -0300)
We can make use of the vty->config variable to know when the CLI
user is in the configuration mode or not. This is much simpler
than obtaining this information from the vty node, and also a more
robust solution (the three switch statements below, for example,
were out of sync).

Also, fix a bug where vty->config wasn't being unset in the
vty_config_exit() function (bug introduced by commit f344c66ea3).

Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
lib/command.c
lib/vty.c

index 317a41cf491c0f4fd324badf391d091fd041900a..fca3bcd72394e61d2eb62f6c6ff4908a6bbfb927 100644 (file)
@@ -1535,63 +1535,9 @@ DEFUN (config_end,
        "end",
        "End current mode and change to enable mode.\n")
 {
-       switch (vty->node) {
-       case VIEW_NODE:
-       case ENABLE_NODE:
-               /* Nothing to do. */
-               break;
-       case CONFIG_NODE:
-       case INTERFACE_NODE:
-       case PW_NODE:
-       case LOGICALROUTER_NODE:
-       case VRF_NODE:
-       case NH_GROUP_NODE:
-       case ZEBRA_NODE:
-       case RIP_NODE:
-       case RIPNG_NODE:
-       case EIGRP_NODE:
-       case BABEL_NODE:
-       case BGP_NODE:
-       case BGP_VRF_POLICY_NODE:
-       case BGP_VNC_DEFAULTS_NODE:
-       case BGP_VNC_NVE_GROUP_NODE:
-       case BGP_VNC_L2_GROUP_NODE:
-       case BGP_VPNV4_NODE:
-       case BGP_VPNV6_NODE:
-       case BGP_FLOWSPECV4_NODE:
-       case BGP_FLOWSPECV6_NODE:
-       case BGP_IPV4_NODE:
-       case BGP_IPV4M_NODE:
-       case BGP_IPV4L_NODE:
-       case BGP_IPV6_NODE:
-       case BGP_IPV6M_NODE:
-       case BGP_EVPN_NODE:
-       case BGP_EVPN_VNI_NODE:
-       case BGP_IPV6L_NODE:
-       case RMAP_NODE:
-       case PBRMAP_NODE:
-       case OSPF_NODE:
-       case OSPF6_NODE:
-       case LDP_NODE:
-       case LDP_IPV4_NODE:
-       case LDP_IPV6_NODE:
-       case LDP_IPV4_IFACE_NODE:
-       case LDP_IPV6_IFACE_NODE:
-       case LDP_L2VPN_NODE:
-       case LDP_PSEUDOWIRE_NODE:
-       case ISIS_NODE:
-       case OPENFABRIC_NODE:
-       case KEYCHAIN_NODE:
-       case KEYCHAIN_KEY_NODE:
-       case VTY_NODE:
-       case LINK_PARAMS_NODE:
-       case BFD_NODE:
-       case BFD_PEER_NODE:
+       if (vty->config) {
                vty_config_exit(vty);
                vty->node = ENABLE_NODE;
-               break;
-       default:
-               break;
        }
 
        return CMD_SUCCESS;
index f93301170a6954624c9942d12d7697dbb035bc55..8450922c2bb26e2554da72ff469c1fe15239dc37 100644 (file)
--- a/lib/vty.c
+++ b/lib/vty.c
@@ -775,57 +775,9 @@ static void vty_end_config(struct vty *vty)
 {
        vty_out(vty, "\n");
 
-       switch (vty->node) {
-       case VIEW_NODE:
-       case ENABLE_NODE:
-               /* Nothing to do. */
-               break;
-       case CONFIG_NODE:
-       case INTERFACE_NODE:
-       case PW_NODE:
-       case ZEBRA_NODE:
-       case RIP_NODE:
-       case RIPNG_NODE:
-       case EIGRP_NODE:
-       case BGP_NODE:
-       case BGP_VPNV4_NODE:
-       case BGP_VPNV6_NODE:
-       case BGP_VRF_POLICY_NODE:
-       case BGP_VNC_DEFAULTS_NODE:
-       case BGP_VNC_NVE_GROUP_NODE:
-       case BGP_VNC_L2_GROUP_NODE:
-       case BGP_IPV4_NODE:
-       case BGP_IPV4M_NODE:
-       case BGP_IPV4L_NODE:
-       case BGP_IPV6_NODE:
-       case BGP_IPV6M_NODE:
-       case BGP_EVPN_NODE:
-       case BGP_IPV6L_NODE:
-       case RMAP_NODE:
-       case PBRMAP_NODE:
-       case OSPF_NODE:
-       case OSPF6_NODE:
-       case LDP_NODE:
-       case LDP_IPV4_NODE:
-       case LDP_IPV6_NODE:
-       case LDP_IPV4_IFACE_NODE:
-       case LDP_IPV6_IFACE_NODE:
-       case LDP_L2VPN_NODE:
-       case LDP_PSEUDOWIRE_NODE:
-       case ISIS_NODE:
-       case OPENFABRIC_NODE:
-       case KEYCHAIN_NODE:
-       case KEYCHAIN_KEY_NODE:
-       case VTY_NODE:
-       case BGP_EVPN_VNI_NODE:
-       case BFD_NODE:
-       case BFD_PEER_NODE:
+       if (vty->config) {
                vty_config_exit(vty);
                vty->node = ENABLE_NODE;
-               break;
-       default:
-               /* Unknown node, we have to ignore it. */
-               break;
        }
 
        vty_prompt(vty);
@@ -1188,44 +1140,11 @@ static void vty_stop_input(struct vty *vty)
        vty_clear_buf(vty);
        vty_out(vty, "\n");
 
-       switch (vty->node) {
-       case VIEW_NODE:
-       case ENABLE_NODE:
-               /* Nothing to do. */
-               break;
-       case CONFIG_NODE:
-       case INTERFACE_NODE:
-       case PW_NODE:
-       case ZEBRA_NODE:
-       case RIP_NODE:
-       case RIPNG_NODE:
-       case EIGRP_NODE:
-       case BGP_NODE:
-       case RMAP_NODE:
-       case PBRMAP_NODE:
-       case OSPF_NODE:
-       case OSPF6_NODE:
-       case LDP_NODE:
-       case LDP_IPV4_NODE:
-       case LDP_IPV6_NODE:
-       case LDP_IPV4_IFACE_NODE:
-       case LDP_IPV6_IFACE_NODE:
-       case LDP_L2VPN_NODE:
-       case LDP_PSEUDOWIRE_NODE:
-       case ISIS_NODE:
-       case OPENFABRIC_NODE:
-       case KEYCHAIN_NODE:
-       case KEYCHAIN_KEY_NODE:
-       case VTY_NODE:
-       case BFD_NODE:
-       case BFD_PEER_NODE:
+       if (vty->config) {
                vty_config_exit(vty);
                vty->node = ENABLE_NODE;
-               break;
-       default:
-               /* Unknown node, we have to ignore it. */
-               break;
        }
+
        vty_prompt(vty);
 
        /* Set history pointer to the latest one. */
@@ -2732,6 +2651,8 @@ void vty_config_exit(struct vty *vty)
                nb_config_free(vty->candidate_config_base);
                vty->candidate_config_base = NULL;
        }
+
+       vty->config = false;
 }
 
 int vty_config_exclusive_lock(struct vty *vty)