]> git.puffer.fish Git - mirror/frr.git/commitdiff
mgmtd: remove heavy duplication in mgmtd config read 15176/head
authorChristian Hopps <chopps@labn.net>
Thu, 18 Jan 2024 17:06:45 +0000 (17:06 +0000)
committerChristian Hopps <chopps@labn.net>
Fri, 19 Jan 2024 15:27:24 +0000 (15:27 +0000)
Previously each container created all it's decendents before descending into
the children and repeating the process.

Signed-off-by: Christian Hopps <chopps@labn.net>
lib/northbound.c
lib/northbound.h
mgmtd/mgmt_be_adapter.c
mgmtd/mgmt_be_adapter.h

index 1deeb36fd1b551d8a28214c6ce151812b091ada9..a831fc58b2af7fa9ba3333c016b34e8ad2aef1e4 100644 (file)
@@ -417,10 +417,9 @@ static inline int nb_config_cb_compare(const struct nb_config_cb *a,
 }
 RB_GENERATE(nb_config_cbs, nb_config_cb, entry, nb_config_cb_compare);
 
-static void nb_config_diff_add_change(struct nb_config_cbs *changes,
-                                     enum nb_cb_operation operation,
-                                     uint32_t *seq,
-                                     const struct lyd_node *dnode)
+void nb_config_diff_add_change(struct nb_config_cbs *changes,
+                              enum nb_cb_operation operation, uint32_t *seq,
+                              const struct lyd_node *dnode)
 {
        struct nb_config_change *change;
 
@@ -699,9 +698,10 @@ int nb_candidate_edit(struct nb_config *candidate, const struct nb_node *nb_node
                      bool in_backend, const struct yang_data *previous,
                      const struct yang_data *data)
 {
-       struct lyd_node *dnode, *dep_dnode, *old_dnode, *parent;
+       struct lyd_node *dnode, *dep_dnode, *old_dnode;
        char xpath_edit[XPATH_MAXLEN];
        char dep_xpath[XPATH_MAXLEN];
+       struct lyd_node *parent = NULL;
        uint32_t options = 0;
        LY_ERR err;
 
@@ -876,10 +876,17 @@ void nb_candidate_edit_config_changes(struct nb_config *candidate_config,
                /* Find the northbound node associated to the data path. */
                nb_node = nb_node_find(xpath);
                if (!nb_node) {
-                       flog_warn(EC_LIB_YANG_UNKNOWN_DATA_PATH,
-                                 "%s: unknown data path: %s", __func__, xpath);
-                       if (error)
-                               *error = true;
+                       if (in_backend)
+                               DEBUGD(&nb_dbg_cbs_config,
+                                      "%s: ignoring non-handled path: %s",
+                                      __func__, xpath);
+                       else {
+                               flog_warn(EC_LIB_YANG_UNKNOWN_DATA_PATH,
+                                         "%s: unknown data path: %s", __func__,
+                                         xpath);
+                               if (error)
+                                       *error = true;
+                       }
                        continue;
                }
                /* Find if the node to be edited is not a key node */
index 482a0559651f0ee8f3b3485186c3acd7a2a8876e..0a6bc88921cf1854e167fb006bea8c72478f15fd 100644 (file)
@@ -1031,6 +1031,11 @@ extern void nb_candidate_edit_config_changes(struct nb_config *candidate_config,
                                             bool in_backend, char *err_buf,
                                             int err_bufsize, bool *error);
 
+
+extern void nb_config_diff_add_change(struct nb_config_cbs *changes,
+                                     enum nb_cb_operation operation,
+                                     uint32_t *seq,
+                                     const struct lyd_node *dnode);
 /*
  * Delete candidate configuration changes.
  *
index 2be70901a8403cfe9f821970d7a73f4b2e72152d..c8f52a101c87391514d8cfa778d4ee6e461e4a51 100644 (file)
@@ -597,20 +597,6 @@ struct mgmt_be_get_adapter_config_params {
        uint32_t seq;
 };
 
-/*
- * Callback to store the change a node in the datastore if it should be sync'd
- * to the adapter (i.e., if the adapter is subscribed to it).
- */
-static void mgmt_be_iter_and_get_cfg(const char *xpath, struct lyd_node *node,
-                                    struct nb_node *nb_node, void *ctx)
-{
-       struct mgmt_be_get_adapter_config_params *parms = ctx;
-       struct mgmt_be_client_adapter *adapter = parms->adapter;
-
-       if (be_is_client_interested(xpath, adapter->id, true))
-               nb_config_diff_created(node, &parms->seq, parms->cfg_chgs);
-}
-
 /*
  * Initialize a BE client over a new connection
  */
@@ -769,32 +755,32 @@ void mgmt_be_adapter_toggle_client_debug(bool set)
  * Get a full set of changes for all the config that an adapter is subscribed to
  * receive.
  */
-int mgmt_be_get_adapter_config(struct mgmt_be_client_adapter *adapter,
-                              struct nb_config_cbs **cfg_chgs)
-{
-       struct mgmt_be_get_adapter_config_params parms;
-       struct nb_config *cfg_root = mgmt_ds_get_nb_config(mm->running_ds);
-
-       assert(cfg_chgs);
-
-       /*
-        * TODO: we should consider making this an assertable condition and
-        * guaranteeing it be true when this function is called. B/c what is
-        * going to happen if there are some changes being sent, and we don't
-        * gather a new snapshot, what new changes that came after the previous
-        * snapshot will then be lost?
-        */
-       if (RB_EMPTY(nb_config_cbs, &adapter->cfg_chgs)) {
-               parms.adapter = adapter;
-               parms.cfg_chgs = &adapter->cfg_chgs;
-               parms.seq = 0;
-
-               mgmt_ds_iter_data(MGMTD_DS_RUNNING, cfg_root, "",
-                                 mgmt_be_iter_and_get_cfg, (void *)&parms);
+void mgmt_be_get_adapter_config(struct mgmt_be_client_adapter *adapter,
+                              struct nb_config_cbs **changes)
+{
+       const struct lyd_node *root, *dnode;
+       uint32_t seq = 0;
+       char *xpath;
+
+       /* We can't be in the middle of sending other chgs when here. */
+       assert(RB_EMPTY(nb_config_cbs, &adapter->cfg_chgs));
+
+       *changes = &adapter->cfg_chgs;
+       LY_LIST_FOR (running_config->dnode, root) {
+               LYD_TREE_DFS_BEGIN (root, dnode) {
+                       if (lysc_is_key(dnode->schema))
+                               goto walk_cont;
+
+                       xpath = lyd_path(dnode, LYD_PATH_STD, NULL, 0);
+                       if (be_is_client_interested(xpath, adapter->id, true))
+                               nb_config_diff_add_change(*changes, NB_CB_CREATE, &seq, dnode);
+                       else
+                               LYD_TREE_DFS_continue = 1; /* skip any subtree */
+                       free(xpath);
+               walk_cont:
+                       LYD_TREE_DFS_END(root, dnode);
+               }
        }
-
-       *cfg_chgs = &adapter->cfg_chgs;
-       return 0;
 }
 
 uint64_t mgmt_be_interested_clients(const char *xpath, bool config)
index 96e807f6c41920fa4e4be087f4652307edb81c67..3407d4c6a73abf2b5c270cfed0bf319e8d14dee1 100644 (file)
@@ -157,8 +157,8 @@ extern const char *mgmt_be_client_id2name(enum mgmt_be_client_id id);
 extern void mgmt_be_adapter_toggle_client_debug(bool set);
 
 /* Fetch backend adapter config. */
-extern int mgmt_be_get_adapter_config(struct mgmt_be_client_adapter *adapter,
-                                     struct nb_config_cbs **cfg_chgs);
+extern void mgmt_be_get_adapter_config(struct mgmt_be_client_adapter *adapter,
+                                      struct nb_config_cbs **changes);
 
 /* Create/destroy a transaction. */
 extern int mgmt_be_send_txn_req(struct mgmt_be_client_adapter *adapter,