vty: fix vty->index for implicit go_parent_node

After this patch, most vty_go_parent() functions are really obsolete, as
originally intended: A vty_go_parent() is only needed if the program
requires an action to run on VTY node exit.

vty_transcript_test.vty shows the fixed behavior.

For details, see preceding patch
"vty: show bug in implicit go_parent_node"
I2472daed7436a1947655b06d34eb217e595bc7f3

Change-Id: Id408c678d18ba19b1c1394c3fb657536153d2094
This commit is contained in:
Neels Hofmeyr 2023-05-01 02:59:01 +02:00 committed by neels
parent cc9b699931
commit 67d84d2131
3 changed files with 8 additions and 8 deletions

View File

@ -61,6 +61,7 @@ struct vty_parent_node {
/*! private data, specified by creator */ /*! private data, specified by creator */
void *priv; void *priv;
void *index;
/*! Node status of this vty */ /*! Node status of this vty */
int node; int node;

View File

@ -2438,6 +2438,7 @@ static bool vty_pop_parent(struct vty *vty)
llist_del(&parent->entry); llist_del(&parent->entry);
vty->node = parent->node; vty->node = parent->node;
vty->priv = parent->priv; vty->priv = parent->priv;
vty->index = parent->index;
if (vty->indent) if (vty->indent)
talloc_free(vty->indent); talloc_free(vty->indent);
vty->indent = parent->indent; vty->indent = parent->indent;
@ -2648,6 +2649,7 @@ cmd_execute_command_real(vector vline, struct vty *vty,
struct vty_parent_node this_node = { struct vty_parent_node this_node = {
.node = vty->node, .node = vty->node,
.priv = vty->priv, .priv = vty->priv,
.index = vty->index,
.indent = vty->indent, .indent = vty->indent,
}; };
struct vty_parent_node *parent = vty_parent(vty); struct vty_parent_node *parent = vty_parent(vty);
@ -2923,6 +2925,7 @@ int config_from_file(struct vty *vty, FILE * fp)
this_node = (struct vty_parent_node){ this_node = (struct vty_parent_node){
.node = vty->node, .node = vty->node,
.priv = vty->priv, .priv = vty->priv,
.index = vty->index,
.indent = vty->indent, .indent = vty->indent,
}; };

View File

@ -191,12 +191,10 @@ vty_transcript_test(config-c)# state
C C
vty_transcript_test(config-c)# exit vty_transcript_test(config-c)# exit
vty_transcript_test(config-b)# state vty_transcript_test(config-b)# state
C B
vty_transcript_test(config-b)# ### ^ EXPECTED ERROR: this should say B
vty_transcript_test(config-b)# exit vty_transcript_test(config-b)# exit
vty_transcript_test(config-a)# state vty_transcript_test(config-a)# state
C A
vty_transcript_test(config-a)# ### ^ EXPECTED ERROR: this should say A
vty_transcript_test(config-a)# nest B2 vty_transcript_test(config-a)# nest B2
vty_transcript_test(config-b)# state vty_transcript_test(config-b)# state
B2 B2
@ -205,9 +203,7 @@ vty_transcript_test(config-c)# state
C2 C2
vty_transcript_test(config-c)# exit vty_transcript_test(config-c)# exit
vty_transcript_test(config-b)# state vty_transcript_test(config-b)# state
C2 B2
vty_transcript_test(config-b)# ### ^ EXPECTED ERROR: this should say B2
vty_transcript_test(config-b)# exit vty_transcript_test(config-b)# exit
vty_transcript_test(config-a)# state vty_transcript_test(config-a)# state
C2 A
vty_transcript_test(config-a)# ### ^ EXPECTED ERROR: this should say A