summaryrefslogtreecommitdiff
path: root/lib/if.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/if.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/if.c')
-rw-r--r--lib/if.c44
1 files changed, 10 insertions, 34 deletions
diff --git a/lib/if.c b/lib/if.c
index 03a83f4a38..0fd65da03a 100644
--- a/lib/if.c
+++ b/lib/if.c
@@ -1086,12 +1086,6 @@ DEFPY_NOSH (interface,
VRF_CMD_HELP_STR)
{
char xpath_list[XPATH_MAXLEN];
- struct cli_config_change changes[] = {
- {
- .xpath = ".",
- .operation = NB_OP_CREATE,
- },
- };
vrf_id_t vrf_id;
struct interface *ifp;
int ret;
@@ -1136,7 +1130,8 @@ DEFPY_NOSH (interface,
"/frr-interface:lib/interface[name='%s'][vrf='%s']", ifname,
vrfname);
- ret = nb_cli_cfg_change(vty, xpath_list, changes, array_size(changes));
+ nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
+ ret = nb_cli_apply_changes(vty, xpath_list);
if (ret == CMD_SUCCESS) {
VTY_PUSH_XPATH(INTERFACE_NODE, xpath_list);
@@ -1162,22 +1157,14 @@ DEFPY (no_interface,
"Interface's name\n"
VRF_CMD_HELP_STR)
{
- char xpath_list[XPATH_MAXLEN];
- struct cli_config_change changes[] = {
- {
- .xpath = ".",
- .operation = NB_OP_DELETE,
- },
- };
-
if (!vrfname)
vrfname = VRF_DEFAULT_NAME;
- snprintf(xpath_list, sizeof(xpath_list),
- "/frr-interface:lib/interface[name='%s'][vrf='%s']", ifname,
- vrfname);
+ nb_cli_enqueue_change(vty, ".", NB_OP_DELETE, NULL);
- return nb_cli_cfg_change(vty, xpath_list, changes, array_size(changes));
+ return nb_cli_apply_changes(
+ vty, "/frr-interface:lib/interface[name='%s'][vrf='%s']",
+ ifname, vrfname);
}
static void cli_show_interface(struct vty *vty, struct lyd_node *dnode,
@@ -1203,18 +1190,12 @@ DEFPY (interface_desc,
"Interface specific description\n"
"Characters describing this interface\n")
{
- struct cli_config_change changes[] = {
- {
- .xpath = "./description",
- .operation = NB_OP_MODIFY,
- },
- };
char *desc;
int ret;
desc = argv_concat(argv, argc, 1);
- changes[0].value = desc;
- ret = nb_cli_cfg_change(vty, NULL, changes, array_size(changes));
+ nb_cli_enqueue_change(vty, "./description", NB_OP_MODIFY, desc);
+ ret = nb_cli_apply_changes(vty, NULL);
XFREE(MTYPE_TMP, desc);
return ret;
@@ -1226,14 +1207,9 @@ DEFPY (no_interface_desc,
NO_STR
"Interface specific description\n")
{
- struct cli_config_change changes[] = {
- {
- .xpath = "./description",
- .operation = NB_OP_DELETE,
- },
- };
+ nb_cli_enqueue_change(vty, "./description", NB_OP_DELETE, NULL);
- return nb_cli_cfg_change(vty, NULL, changes, array_size(changes));
+ return nb_cli_apply_changes(vty, NULL);
}
static void cli_show_interface_desc(struct vty *vty, struct lyd_node *dnode,