{
int ret = reset(false);
- vty_config_unlock(vty);
+ vty_config_exit(vty);
vty->node = ENABLE_NODE;
return ret == SUCCESS ? CMD_SUCCESS : CMD_WARNING;
}
}
}
- vty_config_lockless();
/* thread master */
master = frr_init();
master = frr_init();
- vty_config_lockless();
vrf_init(NULL, NULL, NULL, NULL, NULL);
access_list_init();
ldp_vty_init();
"Configuration from vty interface\n"
"Configuration terminal\n")
{
- if (vty_config_lock(vty))
- vty->node = CONFIG_NODE;
- else {
- vty_out(vty, "VTY configuration is locked by other VTY\n");
- return CMD_WARNING_CONFIG_FAILED;
- }
-
- vty->private_config = false;
- 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 CMD_SUCCESS;
+ return vty_config_enter(vty, false, false);
}
/* Enable command */
break;
case CONFIG_NODE:
vty->node = ENABLE_NODE;
- vty_config_unlock(vty);
+ vty_config_exit(vty);
break;
case INTERFACE_NODE:
case PW_NODE:
case LINK_PARAMS_NODE:
case BFD_NODE:
case BFD_PEER_NODE:
- vty_config_unlock(vty);
+ vty_config_exit(vty);
vty->node = ENABLE_NODE;
break;
default:
"Configuration from vty interface\n"
"Configure exclusively from this terminal\n")
{
- if (vty_config_exclusive_lock(vty))
- vty->node = CONFIG_NODE;
- else {
- vty_out(vty, "VTY configuration is locked by other VTY\n");
- return CMD_WARNING_CONFIG_FAILED;
- }
-
- vty->private_config = true;
- 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");
-
- return CMD_SUCCESS;
+ return vty_config_enter(vty, true, true);
}
/* Configure using a private candidate configuration. */
"Configuration from vty interface\n"
"Configure using a private candidate configuration\n")
{
- if (vty_config_lock(vty))
- vty->node = CONFIG_NODE;
- else {
- vty_out(vty, "VTY configuration is locked by other VTY\n");
- return CMD_WARNING_CONFIG_FAILED;
- }
-
- vty->private_config = true;
- 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");
-
- return CMD_SUCCESS;
+ return vty_config_enter(vty, true, false);
}
DEFPY (config_commit,
/* 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;
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:
case VTY_NODE:
case BFD_NODE:
case BFD_PEER_NODE:
- vty_config_unlock(vty);
+ vty_config_exit(vty);
vty->node = ENABLE_NODE;
break;
default:
}
/* Check configure. */
- vty_config_unlock(vty);
+ vty_config_exit(vty);
/* OK free vty. */
XFREE(MTYPE_VTY, vty);
}
}
-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);
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)
int xpath_index;
char xpath[VTY_MAXDEPTH][XPATH_MAXLEN];
+ /* In configure mode. */
+ bool config;
+
/* Private candidate configuration mode. */
bool private_config;
/* Terminal monitor. */
int monitor;
- /* In configure mode. */
- int config;
-
/* Read and write thread. */
struct thread *t_read;
struct thread *t_write;
extern char *vty_get_cwd(void);
extern void vty_log(const char *level, const char *proto, const char *fmt,
struct timestamp_control *, va_list);
-extern int vty_config_lock(struct vty *);
-extern int vty_config_unlock(struct vty *);
-extern void vty_config_lockless(void);
+extern int vty_config_enter(struct vty *vty, bool private_config,
+ bool exclusive);
+extern void vty_config_exit(struct vty *);
extern int vty_config_exclusive_lock(struct vty *vty);
extern void vty_config_exclusive_unlock(struct vty *vty);
extern int vty_shell(struct vty *);
}
}
- vty_config_lockless();
-
/* Prepare master thread. */
master = frr_init();
}
}
- vty_config_lockless();
zebrad.master = frr_init();
/* Zebra related initialize. */