diff options
author | Renato Westphal <renato@opensourcerouting.org> | 2018-11-26 19:47:22 +0100 |
---|---|---|
committer | Renato Westphal <renato@opensourcerouting.org> | 2018-11-26 19:47:35 +0100 |
commit | f344c66ea358c151a218e986173e60bb0295e003 (patch) | |
tree | 77515eb03791559325a50336ad170cb6b8832cd2 /lib/vty.c | |
parent | Merge pull request #3351 from chiragshah6/ospfv3_dev (diff) | |
download | frr-f344c66ea358c151a218e986173e60bb0295e003.tar.xz frr-f344c66ea358c151a218e986173e60bb0295e003.zip |
*: remove the configuration lock from all daemons
A while ago all FRR configuration commands were converted to use the
QOBJ infrastructure to keep track of configuration objects. This
means the configuration lock isn't necessary anymore because the
QOBJ code detects when someones tries to edit a configuration object
that was deleted and react accordingly (log an error and abort the
command). The possibility of accessing dangling pointers doesn't
exist anymore since vty->index was removed.
Summary of the changes:
* remove the configuration lock and the vty_config_lockless() function.
* rename vty_config_unlock() to vty_config_exit() since we need to
clean up a few things when exiting from the configuration mode.
* rename vty_config_lock() to vty_config_enter() to remove code
duplication that existed between the three different "configuration"
commands (terminal, private and exclusive).
Configuration commands converted to the new northbound model don't
need the configuration lock either since the northbound API also
detects when someone tries to edit a configuration object that
doesn't exist anymore.
Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
Diffstat (limited to 'lib/vty.c')
-rw-r--r-- | lib/vty.c | 54 |
1 files changed, 26 insertions, 28 deletions
@@ -86,10 +86,6 @@ static vector Vvty_serv_thread; /* Current directory. */ char *vty_cwd = NULL; -/* Configure lock. */ -static int vty_config; -static int vty_config_is_lockless = 0; - /* Exclusive configuration lock. */ struct vty *vty_exclusive_lock; @@ -824,7 +820,7 @@ static void vty_end_config(struct vty *vty) case BGP_EVPN_VNI_NODE: case BFD_NODE: case BFD_PEER_NODE: - vty_config_unlock(vty); + vty_config_exit(vty); vty->node = ENABLE_NODE; break; default: @@ -1225,7 +1221,7 @@ static void vty_stop_input(struct vty *vty) case VTY_NODE: case BFD_NODE: case BFD_PEER_NODE: - vty_config_unlock(vty); + vty_config_exit(vty); vty->node = ENABLE_NODE; break; default: @@ -2351,7 +2347,7 @@ void vty_close(struct vty *vty) } /* Check configure. */ - vty_config_unlock(vty); + vty_config_exit(vty); /* OK free vty. */ XFREE(MTYPE_VTY, vty); @@ -2690,18 +2686,33 @@ void vty_log_fixed(char *buf, size_t len) } } -int vty_config_lock(struct vty *vty) +int vty_config_enter(struct vty *vty, bool private_config, bool exclusive) { - if (vty_config_is_lockless) - return 1; - if (vty_config == 0) { - vty->config = 1; - vty_config = 1; + if (exclusive && !vty_config_exclusive_lock(vty)) { + vty_out(vty, "VTY configuration is locked by other VTY\n"); + return CMD_WARNING; + } + + vty->node = CONFIG_NODE; + vty->config = true; + vty->private_config = private_config; + + if (private_config) { + vty->candidate_config = nb_config_dup(running_config); + vty->candidate_config_base = nb_config_dup(running_config); + vty_out(vty, + "Warning: uncommitted changes will be discarded on exit.\n\n"); + } else { + vty->candidate_config = vty_shared_candidate_config; + if (frr_get_cli_mode() == FRR_CLI_TRANSACTIONAL) + vty->candidate_config_base = + nb_config_dup(running_config); } - return vty->config; + + return CMD_SUCCESS; } -int vty_config_unlock(struct vty *vty) +void vty_config_exit(struct vty *vty) { vty_config_exclusive_unlock(vty); @@ -2714,19 +2725,6 @@ int vty_config_unlock(struct vty *vty) nb_config_free(vty->candidate_config_base); vty->candidate_config_base = NULL; } - - if (vty_config_is_lockless) - return 0; - if (vty_config == 1 && vty->config == 1) { - vty->config = 0; - vty_config = 0; - } - return vty->config; -} - -void vty_config_lockless(void) -{ - vty_config_is_lockless = 1; } int vty_config_exclusive_lock(struct vty *vty) |