]> git.proxmox.com Git - mirror_frr.git/commitdiff
lib: introduce function to retrieve the schema name of a data node
authorRenato Westphal <renato@opensourcerouting.org>
Sat, 24 Nov 2018 23:56:48 +0000 (21:56 -0200)
committerRenato Westphal <renato@opensourcerouting.org>
Mon, 26 Nov 2018 17:52:12 +0000 (15:52 -0200)
In some cases it might be desirable to obtain the schema name of
a libyang data node. Introduce the yang_dnode_get_schema_name()
function for this purpose.

Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
lib/yang.c
lib/yang.h

index 6236dc5a6696ec7ebe6d85c5b7e6ac5eebe533ca..f41c645758a6287a27825727836d95b09bbb8994 100644 (file)
@@ -344,6 +344,29 @@ void yang_dnode_get_path(const struct lyd_node *dnode, char *xpath,
        free(xpath_ptr);
 }
 
+const char *yang_dnode_get_schema_name(const struct lyd_node *dnode,
+                                      const char *xpath_fmt, ...)
+{
+       if (xpath_fmt) {
+               va_list ap;
+               char xpath[XPATH_MAXLEN];
+
+               va_start(ap, xpath_fmt);
+               vsnprintf(xpath, sizeof(xpath), xpath_fmt, ap);
+               va_end(ap);
+
+               dnode = yang_dnode_get(dnode, xpath);
+               if (!dnode) {
+                       flog_err(EC_LIB_YANG_DNODE_NOT_FOUND,
+                                "%s: couldn't find %s", __func__, xpath);
+                       zlog_backtrace(LOG_ERR);
+                       abort();
+               }
+       }
+
+       return dnode->schema->name;
+}
+
 struct lyd_node *yang_dnode_get(const struct lyd_node *dnode,
                                const char *xpath_fmt, ...)
 {
index b0348e320b3b6ab5b7073e2357c8f53acfe4b150..eac9796df95a12e4f85c86196808a85fc9307d10 100644 (file)
@@ -284,6 +284,22 @@ extern const struct lys_type *yang_snode_get_type(const struct lys_node *snode);
 extern void yang_dnode_get_path(const struct lyd_node *dnode, char *xpath,
                                size_t xpath_len);
 
+/*
+ * Return the schema name of the given libyang data node.
+ *
+ * dnode
+ *    libyang data node.
+ *
+ * xpath_fmt
+ *    Optional XPath expression (absolute or relative) to specify a different
+ *    data node to operate on in the same data tree.
+ *
+ * Returns:
+ *    Schema name of the libyang data node.
+ */
+extern const char *yang_dnode_get_schema_name(const struct lyd_node *dnode,
+                                             const char *xpath_fmt, ...);
+
 /*
  * Find a libyang data node by its YANG data path.
  *