From dd90823b1dc732e6dee4a5e2b601b62bf555a8f6 Mon Sep 17 00:00:00 2001 From: Chirag Shah Date: Thu, 27 Aug 2020 12:49:45 -0700 Subject: [PATCH] lib: handle exit cmd for bgp afi-safi nodes In transactional cli mode, bgp address-family node builds xpath on top of `router bgp` node's xpath. When `exit` is applied under afi-safi commands, retain xpath_index to 1 to keep using bgp global xpath. Signed-off-by: Chirag Shah --- lib/command.c | 32 +++++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/lib/command.c b/lib/command.c index 1e950fe483..7d335e1c36 100644 --- a/lib/command.c +++ b/lib/command.c @@ -139,6 +139,27 @@ static struct cmd_node config_node = { .node_exit = vty_config_node_exit, }; +static bool vty_check_node_for_xpath_decrement(enum node_type target_node, + enum node_type node) +{ + /* bgp afi-safi (`address-family `) node + * does not increment xpath_index. + * In order to use (`router bgp`) BGP_NODE's xpath as a base, + * retain xpath_index as 1 upon exiting from + * afi-safi node. + */ + + if (target_node == BGP_NODE + && (node == BGP_IPV4_NODE || node == BGP_IPV6_NODE + || node == BGP_IPV4M_NODE || node == BGP_IPV6M_NODE + || node == BGP_VPNV4_NODE || node == BGP_VPNV6_NODE + || node == BGP_EVPN_NODE || node == BGP_IPV4L_NODE + || node == BGP_IPV6L_NODE )) + return false; + + return true; +} + /* This is called from main when a daemon is invoked with -v or --version. */ void print_version(const char *progname) { @@ -985,7 +1006,9 @@ int cmd_execute_command(vector vline, struct vty *vty, while (vty->node > CONFIG_NODE) { try_node = node_parent(try_node); vty->node = try_node; - if (vty->xpath_index > 0) + if (vty->xpath_index > 0 + && vty_check_node_for_xpath_decrement(try_node, + onode)) vty->xpath_index--; ret = cmd_execute_command_real(vline, FILTER_RELAXED, vty, cmd); @@ -1194,7 +1217,9 @@ int command_config_read_one_line(struct vty *vty, && ret != CMD_SUCCESS && ret != CMD_WARNING && vty->node > CONFIG_NODE) { vty->node = node_parent(vty->node); - if (vty->xpath_index > 0) + if (vty->xpath_index > 0 + && vty_check_node_for_xpath_decrement(vty->node, + saved_node)) vty->xpath_index--; ret = cmd_execute_command_strict(vline, vty, cmd); } @@ -1316,7 +1341,8 @@ void cmd_exit(struct vty *vty) } if (cnode->parent_node) vty->node = cnode->parent_node; - if (vty->xpath_index > 0) + if (vty->xpath_index > 0 + && vty_check_node_for_xpath_decrement(vty->node, cnode->node)) vty->xpath_index--; }