diff options
author | Igor Ryzhov <iryzhov@nfware.com> | 2021-08-18 12:51:39 +0200 |
---|---|---|
committer | Igor Ryzhov <iryzhov@nfware.com> | 2021-08-26 23:09:21 +0200 |
commit | af581c003b8707a86448e6c0ba77f576f87fd4ac (patch) | |
tree | 6cf7be1b7093c0a7101d0ecd7dfb9c51363d5b68 /vtysh | |
parent | lib: make node_parent more generic (diff) | |
download | frr-af581c003b8707a86448e6c0ba77f576f87fd4ac.tar.xz frr-af581c003b8707a86448e6c0ba77f576f87fd4ac.zip |
vtysh: make node walkup code more generic
No need to have special processing for every single node. Just always
use "exit" the necessary number of times - it works for all nodes.
Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
Diffstat (limited to 'vtysh')
-rw-r--r-- | vtysh/vtysh.c | 126 |
1 files changed, 2 insertions, 124 deletions
diff --git a/vtysh/vtysh.c b/vtysh/vtysh.c index bc2923468..b47cca76f 100644 --- a/vtysh/vtysh.c +++ b/vtysh/vtysh.c @@ -509,51 +509,8 @@ static int vtysh_execute_func(const char *line, int pager) */ if (ret == CMD_SUCCESS || ret == CMD_SUCCESS_DAEMON || ret == CMD_WARNING) { - if ((saved_node == BGP_VPNV4_NODE - || saved_node == BGP_VPNV6_NODE - || saved_node == BGP_IPV4_NODE - || saved_node == BGP_IPV6_NODE - || saved_node == BGP_FLOWSPECV4_NODE - || saved_node == BGP_FLOWSPECV6_NODE - || saved_node == BGP_IPV4M_NODE - || saved_node == BGP_IPV4L_NODE - || saved_node == BGP_IPV6L_NODE - || saved_node == BGP_IPV6M_NODE - || saved_node == BGP_EVPN_NODE - || saved_node == LDP_IPV4_NODE - || saved_node == LDP_IPV6_NODE) - && (tried == 1)) { - vtysh_execute("exit-address-family"); - } else if ((saved_node == BGP_EVPN_VNI_NODE) && (tried == 1)) { - vtysh_execute("exit-vni"); - } else if (saved_node == BGP_VRF_POLICY_NODE && (tried == 1)) { - vtysh_execute("exit-vrf-policy"); - } else if ((saved_node == BGP_VNC_DEFAULTS_NODE - || saved_node == BGP_VNC_NVE_GROUP_NODE - || saved_node == BGP_VNC_L2_GROUP_NODE) - && (tried == 1)) { - vtysh_execute("exit-vnc"); - } else if (saved_node == VRF_NODE && (tried == 1)) { - vtysh_execute("exit-vrf"); - } else if ((saved_node == KEYCHAIN_KEY_NODE - || saved_node == LDP_PSEUDOWIRE_NODE - || saved_node == LDP_IPV4_IFACE_NODE - || saved_node == LDP_IPV6_IFACE_NODE) - && (tried == 1)) { + while (tried-- > 0) vtysh_execute("exit"); - } else if ((saved_node == SR_SEGMENT_LIST_NODE - || saved_node == SR_POLICY_NODE - || saved_node == SR_CANDIDATE_DYN_NODE - || saved_node == PCEP_NODE - || saved_node == PCEP_PCE_CONFIG_NODE - || saved_node == PCEP_PCE_NODE - || saved_node == PCEP_PCC_NODE) - && (tried > 0)) { - vtysh_execute("exit"); - } else if (tried) { - vtysh_execute("end"); - vtysh_execute("configure"); - } } /* * If command didn't succeed in any node, continue with return value @@ -701,7 +658,6 @@ int vtysh_mark_file(const char *filename) int ret; vector vline; int tried = 0; - bool ending; const struct cmd_element *cmd; int saved_ret, prev_node; int lineno = 0; @@ -734,35 +690,6 @@ int vtysh_mark_file(const char *filename) strlcpy(vty_buf_copy, vty->buf, VTY_BUFSIZ); vty_buf_trimmed = trim(vty_buf_copy); - switch (vty->node) { - case LDP_IPV4_IFACE_NODE: - if (strncmp(vty_buf_copy, " ", 3)) { - vty_out(vty, " exit-ldp-if\n"); - vty->node = LDP_IPV4_NODE; - } - break; - case LDP_IPV6_IFACE_NODE: - if (strncmp(vty_buf_copy, " ", 3)) { - vty_out(vty, " exit-ldp-if\n"); - vty->node = LDP_IPV6_NODE; - } - break; - case LDP_PSEUDOWIRE_NODE: - if (strncmp(vty_buf_copy, " ", 2)) { - vty_out(vty, " exit\n"); - vty->node = LDP_L2VPN_NODE; - } - break; - case SR_CANDIDATE_DYN_NODE: - if (strncmp(vty_buf_copy, " ", 2)) { - vty_out(vty, " exit\n"); - vty->node = SR_POLICY_NODE; - } - break; - default: - break; - } - if (vty_buf_trimmed[0] == '!' || vty_buf_trimmed[0] == '#') { vty_out(vty, "%s", vty->buf); continue; @@ -810,57 +737,8 @@ int vtysh_mark_file(const char *filename) */ if (ret == CMD_SUCCESS || ret == CMD_SUCCESS_DAEMON || ret == CMD_WARNING) { - if ((prev_node == BGP_VPNV4_NODE - || prev_node == BGP_VPNV6_NODE - || prev_node == BGP_IPV4_NODE - || prev_node == BGP_IPV6_NODE - || prev_node == BGP_FLOWSPECV4_NODE - || prev_node == BGP_FLOWSPECV6_NODE - || prev_node == BGP_IPV4L_NODE - || prev_node == BGP_IPV6L_NODE - || prev_node == BGP_IPV4M_NODE - || prev_node == BGP_IPV6M_NODE - || prev_node == BGP_EVPN_NODE) - && (tried == 1)) { - vty_out(vty, "exit-address-family\n"); - } else if ((prev_node == BGP_EVPN_VNI_NODE) - && (tried == 1)) { - vty_out(vty, "exit-vni\n"); - } else if ((prev_node == KEYCHAIN_KEY_NODE) - && (tried == 1)) { - vty_out(vty, "exit\n"); - } else if ((prev_node == BFD_PEER_NODE - || prev_node == BFD_PROFILE_NODE) - && (tried == 1)) { + while (tried-- > 0) vty_out(vty, "exit\n"); - } else if (((prev_node == SEGMENT_ROUTING_NODE) - || (prev_node == SR_TRAFFIC_ENG_NODE) - || (prev_node == SR_SEGMENT_LIST_NODE) - || (prev_node == SR_POLICY_NODE) - || (prev_node == SR_CANDIDATE_DYN_NODE) - || (prev_node == PCEP_NODE) - || (prev_node == PCEP_PCE_CONFIG_NODE) - || (prev_node == PCEP_PCE_NODE) - || (prev_node == PCEP_PCC_NODE)) - && (tried > 0)) { - ending = (vty->node != SEGMENT_ROUTING_NODE) - && (vty->node != SR_TRAFFIC_ENG_NODE) - && (vty->node != SR_SEGMENT_LIST_NODE) - && (vty->node != SR_POLICY_NODE) - && (vty->node != SR_CANDIDATE_DYN_NODE) - && (vty->node != PCEP_NODE) - && (vty->node != PCEP_PCE_CONFIG_NODE) - && (vty->node != PCEP_PCE_NODE) - && (vty->node != PCEP_PCC_NODE); - if (ending) - tried--; - while (tried-- > 0) - vty_out(vty, "exit\n"); - if (ending) - vty_out(vty, "end\n"); - } else if (tried) { - vty_out(vty, "end\n"); - } } /* * If command didn't succeed in any node, continue with return |