]> git.puffer.fish Git - mirror/frr.git/commitdiff
lib: better conditionalize leaf-list predicate xpath addition
authorChristian Hopps <chopps@labn.net>
Thu, 18 Jan 2024 04:17:35 +0000 (04:17 +0000)
committerChristian Hopps <chopps@labn.net>
Fri, 19 Jan 2024 15:27:24 +0000 (15:27 +0000)
If we're in the backend we already have the predicate added by mgmtd -- don't
add it again.

Signed-off-by: Christian Hopps <chopps@labn.net>
lib/mgmt_be_client.c
lib/northbound.c
lib/northbound.h
lib/northbound_cli.c
lib/northbound_confd.c
lib/northbound_sysrepo.c
mgmtd/mgmt_txn.c

index 16aea249a43042347754d3b7331696db4de284d1..d50dd03fdc566e617d30b6a88ece71ab7aaf115c 100644 (file)
@@ -449,7 +449,7 @@ static int mgmt_be_txn_cfg_prepare(struct mgmt_be_txn_ctx *txn)
                                client_ctx->candidate_config,
                                txn_req->req.set_cfg.cfg_changes,
                                (size_t)txn_req->req.set_cfg.num_cfg_changes,
-                               NULL, err_buf, sizeof(err_buf), &error);
+                               NULL, true, err_buf, sizeof(err_buf), &error);
                        if (error) {
                                err_buf[sizeof(err_buf) - 1] = 0;
                                MGMTD_BE_CLIENT_ERR(
index ea34c9cc03de11e18ef797548659bde21dd6c6f0..1deeb36fd1b551d8a28214c6ce151812b091ada9 100644 (file)
@@ -694,10 +694,9 @@ static int dnode_create(struct nb_config *candidate, const char *xpath,
        return NB_OK;
 }
 
-int nb_candidate_edit(struct nb_config *candidate,
-                     const struct nb_node *nb_node,
+int nb_candidate_edit(struct nb_config *candidate, const struct nb_node *nb_node,
                      enum nb_operation operation, const char *xpath,
-                     const struct yang_data *previous,
+                     bool in_backend, const struct yang_data *previous,
                      const struct yang_data *data)
 {
        struct lyd_node *dnode, *dep_dnode, *old_dnode, *parent;
@@ -706,8 +705,13 @@ int nb_candidate_edit(struct nb_config *candidate,
        uint32_t options = 0;
        LY_ERR err;
 
-       /* Use special notation for leaf-lists (RFC 6020, section 9.13.5). */
-       if (nb_node->snode->nodetype == LYS_LEAFLIST)
+       /*
+        * Use special notation for leaf-lists (RFC 6020, section 9.13.5).
+        * if we are in a backend client this notation was already applied
+        * by mgmtd before sending to us.
+        */
+       if (!in_backend && nb_node->snode->nodetype == LYS_LEAFLIST &&
+           (operation == NB_OP_DESTROY || operation == NB_OP_DELETE))
                snprintf(xpath_edit, sizeof(xpath_edit), "%s[.='%s']", xpath,
                         data->value);
        else
@@ -838,10 +842,12 @@ bool nb_is_operation_allowed(struct nb_node *nb_node, enum nb_operation oper)
        return true;
 }
 
-void nb_candidate_edit_config_changes(
-       struct nb_config *candidate_config, struct nb_cfg_change cfg_changes[],
-       size_t num_cfg_changes, const char *xpath_base, char *err_buf,
-       int err_bufsize, bool *error)
+void nb_candidate_edit_config_changes(struct nb_config *candidate_config,
+                                     struct nb_cfg_change cfg_changes[],
+                                     size_t num_cfg_changes,
+                                     const char *xpath_base, bool in_backend,
+                                     char *err_buf, int err_bufsize,
+                                     bool *error)
 {
        if (error)
                *error = false;
@@ -895,7 +901,8 @@ void nb_candidate_edit_config_changes(
                 * configuration.
                 */
                ret = nb_candidate_edit(candidate_config, nb_node,
-                                       change->operation, xpath, NULL, data);
+                                       change->operation, xpath, in_backend,
+                                       NULL, data);
                yang_data_free(data);
                if (ret != NB_OK) {
                        flog_warn(
index 4f9ab565d90ecd8bc7bfb200516fdc8d36ec12a5..482a0559651f0ee8f3b3485186c3acd7a2a8876e 100644 (file)
@@ -950,6 +950,9 @@ extern bool nb_is_operation_allowed(struct nb_node *nb_node,
  * xpath
  *    XPath of the configuration node being edited.
  *
+ * in_backend
+ *    Specify whether the changes are being applied in the backend or not.
+ *
  * previous
  *    Previous value of the configuration node. Should be used only when the
  *    operation is NB_OP_MOVE, otherwise this parameter is ignored.
@@ -964,7 +967,7 @@ extern bool nb_is_operation_allowed(struct nb_node *nb_node,
 extern int nb_candidate_edit(struct nb_config *candidate,
                             const struct nb_node *nb_node,
                             enum nb_operation operation, const char *xpath,
-                            const struct yang_data *previous,
+                            bool in_backend, const struct yang_data *previous,
                             const struct yang_data *data);
 
 /*
@@ -1009,6 +1012,9 @@ extern bool nb_candidate_needs_update(const struct nb_config *candidate);
  * xpath_base
  *    Base xpath for config.
  *
+ * in_backend
+ *    Specify whether the changes are being applied in the backend or not.
+ *
  * err_buf
  *    Buffer to store human-readable error message in case of error.
  *
@@ -1018,10 +1024,12 @@ extern bool nb_candidate_needs_update(const struct nb_config *candidate);
  * error
  *    TRUE on error, FALSE on success
  */
-extern void nb_candidate_edit_config_changes(
-       struct nb_config *candidate_config, struct nb_cfg_change cfg_changes[],
-       size_t num_cfg_changes, const char *xpath_base, char *err_buf,
-       int err_bufsize, bool *error);
+extern void nb_candidate_edit_config_changes(struct nb_config *candidate_config,
+                                            struct nb_cfg_change cfg_changes[],
+                                            size_t num_cfg_changes,
+                                            const char *xpath_base,
+                                            bool in_backend, char *err_buf,
+                                            int err_bufsize, bool *error);
 
 /*
  * Delete candidate configuration changes.
index 92d4ffb2bad1b84e3e648998483551a1c44fe678..0358a0f377c7bbaf74e8002d714049b204f05094 100644 (file)
@@ -146,9 +146,9 @@ static int nb_cli_apply_changes_internal(struct vty *vty,
 
        VTY_CHECK_XPATH;
 
-       nb_candidate_edit_config_changes(
-               vty->candidate_config, vty->cfg_changes, vty->num_cfg_changes,
-               xpath_base, buf, sizeof(buf), &error);
+       nb_candidate_edit_config_changes(vty->candidate_config, vty->cfg_changes,
+                                        vty->num_cfg_changes, xpath_base,
+                                        false, buf, sizeof(buf), &error);
        if (error) {
                /*
                 * Failure to edit the candidate configuration should never
index 8503d18002c7f47b95da8345b46688cf77328f95..c866b0afb466000e606d9ed3490058bcfff8f6e7 100644 (file)
@@ -256,7 +256,7 @@ frr_confd_cdb_diff_iter(confd_hkeypath_t *kp, enum cdb_iter_op cdb_op,
        /* Edit the candidate configuration. */
        data = yang_data_new(xpath, value_str);
        ret = nb_candidate_edit(iter_args->candidate, nb_node, nb_op, xpath,
-                               NULL, data);
+                               false, NULL, data);
        yang_data_free(data);
        if (ret != NB_OK) {
                flog_warn(
index 198d96e3811cd98e3ad9cc8425bda11b8c66d01f..050477af9177d0230ccf683b0a88a268ae881e6e 100644 (file)
@@ -219,7 +219,7 @@ static int frr_sr_process_change(struct nb_config *candidate,
        sr_val_to_buff(sr_data, value_str, sizeof(value_str));
        data = yang_data_new(xpath, value_str);
 
-       ret = nb_candidate_edit(candidate, nb_node, nb_op, xpath, NULL, data);
+       ret = nb_candidate_edit(candidate, nb_node, nb_op, xpath, false, NULL, data);
        yang_data_free(data);
        if (ret != NB_OK) {
                flog_warn(
index 842e13cf117b116ef0a36527061bd1b4f6a39ef6..b4b67b4551580bbbd395c9d98ffbe4e94f582893 100644 (file)
@@ -587,8 +587,8 @@ static void mgmt_txn_process_set_cfg(struct event *thread)
                                                 txn_req->req.set_cfg->cfg_changes,
                                                 (size_t)txn_req->req.set_cfg
                                                         ->num_cfg_changes,
-                                                NULL, err_buf, sizeof(err_buf),
-                                                &error);
+                                                NULL, false, err_buf,
+                                                sizeof(err_buf), &error);
                if (error) {
                        mgmt_fe_send_set_cfg_reply(txn->session_id, txn->txn_id,
                                                   txn_req->req.set_cfg->ds_id,