summaryrefslogtreecommitdiffstats
path: root/lib/yang.c
diff options
context:
space:
mode:
authorChristian Hopps <chopps@labn.net>2023-04-17 07:09:05 +0200
committerChristian Hopps <chopps@labn.net>2023-04-17 07:43:48 +0200
commit9e0241c8fb9996833e7d8e104562a57276b6f906 (patch)
tree426f77f66aa1de555aa838573d38f76e149db561 /lib/yang.c
parentMerge pull request #13141 from mjstapp/fix_ospf_json_keys (diff)
downloadfrr-9e0241c8fb9996833e7d8e104562a57276b6f906.tar.xz
frr-9e0241c8fb9996833e7d8e104562a57276b6f906.zip
lib: add and use new yang function for finding schema nodes
Add a wrapper around lys_find_xpath which has an unfortunate API returning an allocated set of schema nodes when we only ever expect and want one. Another libyang function `lys_find_path` returns a single node; however, that function can assert/abort on invalid path values so is unsuitable for user input. Replace previous uses of `lys_find_path` with new API when dealing with possible invalid path values (i.e., from a user). Signed-off-by: Christian Hopps <chopps@labn.net>
Diffstat (limited to 'lib/yang.c')
-rw-r--r--lib/yang.c17
1 files changed, 17 insertions, 0 deletions
diff --git a/lib/yang.c b/lib/yang.c
index 70a3251ab..4dd865421 100644
--- a/lib/yang.c
+++ b/lib/yang.c
@@ -250,6 +250,23 @@ void yang_snode_get_path(const struct lysc_node *snode,
}
}
+struct lysc_node *yang_find_snode(struct ly_ctx *ly_ctx, const char *xpath,
+ uint32_t options)
+{
+ struct lysc_node *snode;
+ struct ly_set *set;
+ LY_ERR err;
+
+ err = lys_find_xpath(ly_native_ctx, NULL, xpath, options, &set);
+ if (err || !set->count)
+ return NULL;
+
+ snode = set->snodes[0];
+ ly_set_free(set, NULL);
+
+ return snode;
+}
+
struct lysc_node *yang_snode_real_parent(const struct lysc_node *snode)
{
struct lysc_node *parent = snode->parent;