summaryrefslogtreecommitdiff
path: root/lib/vty.c
diff options
context:
space:
mode:
authorIgor Ryzhov <iryzhov@nfware.com>2023-11-11 02:13:17 +0200
committerIgor Ryzhov <iryzhov@nfware.com>2023-11-12 20:28:08 +0200
commitb8a2efbf2f062dd5dc6ab0c660b3cba3f2f469f5 (patch)
treec04a1318de46e9a7e97214290dbc2d69308d4017 /lib/vty.c
parent19bcca4f2e9a3ee3c8cc16608dcf303241bbf014 (diff)
lib, mgmtd: respect base xpath in mgmtd
`nb_cli_apply_changes` can be called with base xpath which should be prepended to xpaths of every change in a transaction. This base xpath is respected by regular northbound CLI but not by mgmtd. This commit fixes the problem. Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
Diffstat (limited to 'lib/vty.c')
-rw-r--r--lib/vty.c20
1 files changed, 18 insertions, 2 deletions
diff --git a/lib/vty.c b/lib/vty.c
index f395fd3ea1..2cfe34f211 100644
--- a/lib/vty.c
+++ b/lib/vty.c
@@ -3718,12 +3718,15 @@ int vty_mgmt_send_lockds_req(struct vty *vty, Mgmtd__DatastoreId ds_id,
return 0;
}
-int vty_mgmt_send_config_data(struct vty *vty, bool implicit_commit)
+int vty_mgmt_send_config_data(struct vty *vty, const char *xpath_base,
+ bool implicit_commit)
{
Mgmtd__YangDataValue value[VTY_MAXCFGCHANGES];
Mgmtd__YangData cfg_data[VTY_MAXCFGCHANGES];
Mgmtd__YangCfgDataReq cfg_req[VTY_MAXCFGCHANGES];
Mgmtd__YangCfgDataReq *cfgreq[VTY_MAXCFGCHANGES] = {0};
+ char xpath[VTY_MAXCFGCHANGES][XPATH_MAXLEN];
+ char *change_xpath;
size_t indx;
if (vty->type == VTY_FILE) {
@@ -3759,6 +3762,9 @@ int vty_mgmt_send_config_data(struct vty *vty, bool implicit_commit)
}
}
+ if (xpath_base == NULL)
+ xpath_base = "";
+
for (indx = 0; indx < vty->num_cfg_changes; indx++) {
mgmt_yang_data_init(&cfg_data[indx]);
@@ -3771,7 +3777,17 @@ int vty_mgmt_send_config_data(struct vty *vty, bool implicit_commit)
cfg_data[indx].value = &value[indx];
}
- cfg_data[indx].xpath = vty->cfg_changes[indx].xpath;
+ change_xpath = vty->cfg_changes[indx].xpath;
+
+ memset(xpath[indx], 0, sizeof(xpath[indx]));
+ /* If change xpath is relative, prepend base xpath. */
+ if (change_xpath[0] == '.') {
+ strlcpy(xpath[indx], xpath_base, sizeof(xpath[indx]));
+ change_xpath++; /* skip '.' */
+ }
+ strlcat(xpath[indx], change_xpath, sizeof(xpath[indx]));
+
+ cfg_data[indx].xpath = xpath[indx];
mgmt_yang_cfg_data_req_init(&cfg_req[indx]);
cfg_req[indx].data = &cfg_data[indx];