summaryrefslogtreecommitdiff
path: root/mgmtd/mgmt_txn.c
diff options
context:
space:
mode:
authorIgor Ryzhov <iryzhov@nfware.com>2023-10-06 02:58:58 +0300
committerIgor Ryzhov <iryzhov@nfware.com>2024-01-11 15:06:53 +0200
commit76e4eb84dd815ddee7d7e46bb5a2635bfe2501f5 (patch)
treeea6bd2707b0146d203feabcf2c820a0756f1dbfd /mgmtd/mgmt_txn.c
parent5d1a31403832a069d1b655bc3410fcd770ad8313 (diff)
mgmtd, lib: implement CREATE_EXCL operation
Currently, there's no difference between CREATE and MODIFY operations. To be compatible with NETCONF/RESTCONF, add new CREATE_EXCL operation that throws an error if the configuration data already exists. Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
Diffstat (limited to 'mgmtd/mgmt_txn.c')
-rw-r--r--mgmtd/mgmt_txn.c40
1 files changed, 28 insertions, 12 deletions
diff --git a/mgmtd/mgmt_txn.c b/mgmtd/mgmt_txn.c
index d25302ab6a..abae2a6a53 100644
--- a/mgmtd/mgmt_txn.c
+++ b/mgmtd/mgmt_txn.c
@@ -911,6 +911,11 @@ static int mgmt_txn_create_config_batches(struct mgmt_txn_req *txn_req,
batch->cfg_datap[batch->num_cfg_data] =
&batch->cfg_data[batch->num_cfg_data];
+ /*
+ * On the backend, we don't really care if it's CREATE
+ * or MODIFY, because the existence was already checked
+ * on the frontend. Therefore we use SET for both.
+ */
if (chg->cb.operation == NB_CB_DESTROY)
batch->cfg_data[batch->num_cfg_data].req_type =
MGMTD__CFG_DATA_REQ_TYPE__DELETE_DATA;
@@ -2026,6 +2031,7 @@ int mgmt_txn_send_set_config_req(uint64_t txn_id, uint64_t req_id,
size_t indx;
uint16_t *num_chgs;
struct nb_cfg_change *cfg_chg;
+ struct nb_node *node;
txn = mgmt_txn_id2ctx(txn_id);
if (!txn)
@@ -2044,20 +2050,30 @@ int mgmt_txn_send_set_config_req(uint64_t txn_id, uint64_t req_id,
for (indx = 0; indx < num_req; indx++) {
cfg_chg = &txn_req->req.set_cfg->cfg_changes[*num_chgs];
- if (cfg_req[indx]->req_type ==
- MGMTD__CFG_DATA_REQ_TYPE__DELETE_DATA)
+ switch (cfg_req[indx]->req_type) {
+ case MGMTD__CFG_DATA_REQ_TYPE__DELETE_DATA:
cfg_chg->operation = NB_OP_DESTROY;
- else if (cfg_req[indx]->req_type ==
- MGMTD__CFG_DATA_REQ_TYPE__SET_DATA)
- cfg_chg->operation =
- mgmt_ds_find_data_node_by_xpath(ds_ctx,
- cfg_req[indx]
- ->data
- ->xpath)
- ? NB_OP_MODIFY
- : NB_OP_CREATE;
- else
+ break;
+ case MGMTD__CFG_DATA_REQ_TYPE__SET_DATA:
+ /*
+ * For backward compatibility, we need to allow creating
+ * *new* list keys with SET_DATA operation. NB_OP_MODIFY
+ * is not allowed for keys, so use NB_OP_CREATE_EXCL.
+ */
+ node = nb_node_find(cfg_req[indx]->data->xpath);
+ if (node && lysc_is_key(node->snode))
+ cfg_chg->operation = NB_OP_CREATE_EXCL;
+ else
+ cfg_chg->operation = NB_OP_MODIFY;
+ break;
+ case MGMTD__CFG_DATA_REQ_TYPE__CREATE_DATA:
+ cfg_chg->operation = NB_OP_CREATE_EXCL;
+ break;
+ case MGMTD__CFG_DATA_REQ_TYPE__REQ_TYPE_NONE:
+ case _MGMTD__CFG_DATA_REQ_TYPE_IS_INT_SIZE:
+ default:
continue;
+ }
MGMTD_TXN_DBG("XPath: '%s', Value: '%s'",
cfg_req[indx]->data->xpath,