summaryrefslogtreecommitdiff
path: root/lib/command.c
diff options
context:
space:
mode:
authorRenato Westphal <renato@opensourcerouting.org>2018-11-26 15:30:14 -0200
committerRenato Westphal <renato@opensourcerouting.org>2018-11-26 15:57:23 -0200
commita6233bfcb3b0678d24221e77cabea5c3ff859eda (patch)
treeb573f9054dd01c848f21c52d4bbd90a7606d9e9f /lib/command.c
parentbb5b9c10c14ee9b9578f9e0b363784aa815c548d (diff)
lib, ripd: rework API for converted CLI commands
When editing the candidate configuration, the northbound must ensure that either all changes made by a command are accepted or none are. This is done to prevent inconsistent states where only parts of a command are applied in the event any error happens. The previous API for converted commands, the nb_cli_cfg_change() function, required callers to pass an array containing all changes that needed to be applied in the candidate configuration. The problem with this API is that it was very inconvenient for complex commands, which change different configuration options depending on several factors. This required users to manipulate the array of configuration changes using low-level primitives, making it complicated to implement some commands. To solve this problem, introduce a new API based on the two following functions: - nb_cli_enqueue_change() - nb_cli_apply_changes() The first function is used to enqueue configuration changes, one at time. Then the nb_cli_apply_changes() function is used to apply all the enqueued configuration changes. To implement this, a static-sized array was allocated in the "vty" structure, along with a counter of enqueued changes. This eliminates the need to declare an array of configuration changes in every converted CLI command, simplifying things quite considerably. Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
Diffstat (limited to 'lib/command.c')
-rw-r--r--lib/command.c7
1 files changed, 6 insertions, 1 deletions
diff --git a/lib/command.c b/lib/command.c
index bd000c3746..a01aabcc2a 100644
--- a/lib/command.c
+++ b/lib/command.c
@@ -1051,8 +1051,13 @@ static int cmd_execute_command_real(vector vline, enum filter_type filter,
int ret;
if (matched_element->daemon)
ret = CMD_SUCCESS_DAEMON;
- else
+ else {
+ /* Clear enqueued configuration changes. */
+ vty->num_cfg_changes = 0;
+ memset(&vty->cfg_changes, 0, sizeof(vty->cfg_changes));
+
ret = matched_element->func(matched_element, vty, argc, argv);
+ }
// delete list and cmd_token's in it
list_delete(&argv_list);