]> git.proxmox.com Git - mirror_frr.git/commitdiff
lib: add possibility to search non-recursively for NB node entries
authorGalaxyGorilla <sascha@netdef.org>
Tue, 10 Mar 2020 09:30:20 +0000 (09:30 +0000)
committerSebastien Merle <sebastien@netdef.org>
Fri, 7 Aug 2020 09:08:49 +0000 (11:08 +0200)
Signed-off-by: GalaxyGorilla <sascha@netdef.org>
lib/northbound.c
lib/northbound.h

index 48b8499bfc067e7d2ac5a844d25deccc6487c210..11007e4309115db626175c0768d1b59c46ea8ce3 100644 (file)
@@ -2046,18 +2046,21 @@ void *nb_running_unset_entry(const struct lyd_node *dnode)
        return entry;
 }
 
-void *nb_running_get_entry(const struct lyd_node *dnode, const char *xpath,
-                          bool abort_if_not_found)
+static void *nb_running_get_entry_worker(const struct lyd_node *dnode,
+                                        const char *xpath,
+                                        bool abort_if_not_found,
+                                        bool rec_search)
 {
        const struct lyd_node *orig_dnode = dnode;
        char xpath_buf[XPATH_MAXLEN];
+       bool rec_flag = true;
 
        assert(dnode || xpath);
 
        if (!dnode)
                dnode = yang_dnode_get(running_config->dnode, xpath);
 
-       while (dnode) {
+       while (rec_flag && dnode) {
                struct nb_config_entry *config, s;
 
                yang_dnode_get_path(dnode, s.xpath, sizeof(s.xpath));
@@ -2065,6 +2068,8 @@ void *nb_running_get_entry(const struct lyd_node *dnode, const char *xpath,
                if (config)
                        return config->entry;
 
+               rec_flag = rec_search;
+
                dnode = dnode->parent;
        }
 
@@ -2078,6 +2083,20 @@ void *nb_running_get_entry(const struct lyd_node *dnode, const char *xpath,
        abort();
 }
 
+void *nb_running_get_entry(const struct lyd_node *dnode, const char *xpath,
+                          bool abort_if_not_found)
+{
+       return nb_running_get_entry_worker(dnode, xpath, abort_if_not_found,
+                                          true);
+}
+
+void *nb_running_get_entry_non_rec(const struct lyd_node *dnode,
+                                  const char *xpath, bool abort_if_not_found)
+{
+       return nb_running_get_entry_worker(dnode, xpath, abort_if_not_found,
+                                          false);
+}
+
 /* Logging functions. */
 const char *nb_event_name(enum nb_event event)
 {
index bd57013f59d6d10be35f1d8ef0a763e31e16104a..d5028ea7d2fe2d4c467d126fd7aeee872540ed16 100644 (file)
@@ -1164,6 +1164,14 @@ extern void *nb_running_unset_entry(const struct lyd_node *dnode);
 extern void *nb_running_get_entry(const struct lyd_node *dnode,
                                  const char *xpath, bool abort_if_not_found);
 
+/*
+ * Same as 'nb_running_get_entry', but doesn't search within parent nodes
+ * recursively if an user point is not found.
+ */
+extern void *nb_running_get_entry_non_rec(const struct lyd_node *dnode,
+                                         const char *xpath,
+                                         bool abort_if_not_found);
+
 /*
  * Return a human-readable string representing a northbound event.
  *