From b8ebb7fc62dc4e212e74189c8d53ee74f1b2d0e5 Mon Sep 17 00:00:00 2001 From: Igor Ryzhov Date: Wed, 27 Sep 2023 23:34:53 +0300 Subject: [PATCH 1/3] vty: fix configure terminal argument descriptions "terminal" and "file-lock" description are mixed up. Signed-off-by: Igor Ryzhov --- lib/command.c | 4 ++-- vtysh/vtysh.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/command.c b/lib/command.c index affb551b4598..b983ebb4e5b7 100644 --- a/lib/command.c +++ b/lib/command.c @@ -1331,8 +1331,8 @@ DEFUN (config_terminal, config_terminal_cmd, "configure [terminal [file-lock]]", "Configuration from vty interface\n" - "Configuration with locked datastores\n" - "Configuration terminal\n") + "Configuration terminal\n" + "Configuration with locked datastores\n") { return vty_config_enter(vty, false, false, argc == 3); } diff --git a/vtysh/vtysh.c b/vtysh/vtysh.c index 050807ccd8f9..2475ef0c8f62 100644 --- a/vtysh/vtysh.c +++ b/vtysh/vtysh.c @@ -2381,8 +2381,8 @@ DEFUNSH(VTYSH_REALLYALL, vtysh_disable, vtysh_disable_cmd, "disable", DEFUNSH(VTYSH_REALLYALL, vtysh_config_terminal, vtysh_config_terminal_cmd, "configure [terminal [file-lock]]", "Configuration from vty interface\n" - "Configuration with locked datastores\n" - "Configuration terminal\n") + "Configuration terminal\n" + "Configuration with locked datastores\n") { vty->node = CONFIG_NODE; return CMD_SUCCESS; From d3aa9adb8da2a3d2fc4c7d926e2135c261bd2764 Mon Sep 17 00:00:00 2001 From: Igor Ryzhov Date: Thu, 28 Sep 2023 02:41:16 +0300 Subject: [PATCH 2/3] vty: fix working in file-lock mode When the configuration node is entered in file-lock mode, candidate and running datastores are locked. Any configuration change is followed by an implicit commit which leads to a crash of mgmtd, because double lock is prohibited by an assert. When working in file-lock mode, we shouldn't do implicit commits which is disabled by allowing pending configuration changes. Signed-off-by: Igor Ryzhov --- lib/vty.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/lib/vty.c b/lib/vty.c index 15cc340eb0c5..ed8b71ed22d5 100644 --- a/lib/vty.c +++ b/lib/vty.c @@ -2890,6 +2890,12 @@ int vty_config_enter(struct vty *vty, bool private_config, bool exclusive, } assert(vty->mgmt_locked_candidate_ds); assert(vty->mgmt_locked_running_ds); + + /* + * As datastores are locked explicitly, we don't need implicit + * commits and should allow pending changes. + */ + vty->pending_allowed = true; } vty->node = CONFIG_NODE; @@ -2946,6 +2952,8 @@ int vty_config_node_exit(struct vty *vty) /* TODO: could we check for un-commited changes here? */ + vty->pending_allowed = false; + if (vty->mgmt_locked_running_ds) vty_mgmt_unlock_running_inline(vty); From 1a09cf38949c2f2ab6d926941329e264f50d6880 Mon Sep 17 00:00:00 2001 From: Igor Ryzhov Date: Thu, 28 Sep 2023 02:45:05 +0300 Subject: [PATCH 3/3] vtysh: fix entering configuration node in file-lock mode When the config node is entered in file-lock mode, we should actually remember it to correctly apply the workaround in `vtysh_exit`. Otherwise, the file-lock mode is dropped once we exit any node one level below the config node. Signed-off-by: Igor Ryzhov --- vtysh/vtysh.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/vtysh/vtysh.c b/vtysh/vtysh.c index 2475ef0c8f62..9c61146c2d86 100644 --- a/vtysh/vtysh.c +++ b/vtysh/vtysh.c @@ -2379,12 +2379,23 @@ DEFUNSH(VTYSH_REALLYALL, vtysh_disable, vtysh_disable_cmd, "disable", } DEFUNSH(VTYSH_REALLYALL, vtysh_config_terminal, vtysh_config_terminal_cmd, - "configure [terminal [file-lock]]", + "configure [terminal]", + "Configuration from vty interface\n" + "Configuration terminal\n") +{ + vty->node = CONFIG_NODE; + return CMD_SUCCESS; +} + +DEFUNSH(VTYSH_REALLYALL, vtysh_config_terminal_file_lock, + vtysh_config_terminal_file_lock_cmd, + "configure terminal file-lock", "Configuration from vty interface\n" "Configuration terminal\n" "Configuration with locked datastores\n") { vty->node = CONFIG_NODE; + vty->vtysh_file_locked = true; return CMD_SUCCESS; } @@ -5021,6 +5032,7 @@ void vtysh_init_vty(void) if (!user_mode) install_element(VIEW_NODE, &vtysh_enable_cmd); install_element(ENABLE_NODE, &vtysh_config_terminal_cmd); + install_element(ENABLE_NODE, &vtysh_config_terminal_file_lock_cmd); install_element(ENABLE_NODE, &vtysh_disable_cmd); /* "exit" command. */