From 59b69ae1f8b512481521de0669f2ea252c1e9f88 Mon Sep 17 00:00:00 2001 From: Christian Hopps Date: Fri, 14 Jul 2023 18:21:55 -0400 Subject: [PATCH] vtysh: track and fix file-lock use in the workaround from 2004 There's a workaround in the code from a bug from back in 2004, it ends and re-enters config mode anytime an `exit` is done from a level below the top-level config node (e.g., from a `router isis` node). We need to re-enter config mode with or without a lock according to how we actually entered it to begin with. fixes #13920 Signed-off-by: Christian Hopps --- lib/vty.h | 4 ++++ vtysh/vtysh.c | 7 ++++++- vtysh/vtysh_config.c | 4 +++- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/lib/vty.h b/lib/vty.h index ac3d2e5019..a8654f8b69 100644 --- a/lib/vty.h +++ b/lib/vty.h @@ -231,6 +231,10 @@ struct vty { const char *mgmt_req_pending_cmd; bool mgmt_locked_candidate_ds; bool mgmt_locked_running_ds; + /* Need to track when we file-lock in vtysh to re-lock on end/conf t + * workaround + */ + bool vtysh_file_locked; }; static inline void vty_push_context(struct vty *vty, int node, uint64_t id) diff --git a/vtysh/vtysh.c b/vtysh/vtysh.c index 6744bfe728..8b223d1aa4 100644 --- a/vtysh/vtysh.c +++ b/vtysh/vtysh.c @@ -2357,8 +2357,13 @@ static int vtysh_exit(struct vty *vty) /* resync in case one of the daemons is somewhere else */ vtysh_execute("end"); /* NOTE: a rather expensive thing to do, can we avoid it? */ - vtysh_execute("configure terminal file-lock"); + + if (vty->vtysh_file_locked) + vtysh_execute("configure terminal file-lock"); + else + vtysh_execute("configure terminal"); } + return CMD_SUCCESS; } diff --git a/vtysh/vtysh_config.c b/vtysh/vtysh_config.c index a5f790bbc6..593de7ffbc 100644 --- a/vtysh/vtysh_config.c +++ b/vtysh/vtysh_config.c @@ -607,7 +607,8 @@ static int vtysh_read_file(FILE *confp, bool dry_run) vty->node = CONFIG_NODE; vtysh_execute_no_pager("enable"); - vtysh_execute_no_pager("configure terminal file-lock"); + vtysh_execute_no_pager("conf term file-lock"); + vty->vtysh_file_locked = true; if (!dry_run) vtysh_execute_no_pager("XFRR_start_configuration"); @@ -619,6 +620,7 @@ static int vtysh_read_file(FILE *confp, bool dry_run) vtysh_execute_no_pager("XFRR_end_configuration"); vtysh_execute_no_pager("end"); + vty->vtysh_file_locked = false; vtysh_execute_no_pager("disable"); vty_close(vty); -- 2.39.5