summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorIgor Ryzhov <iryzhov@nfware.com>2024-01-13 23:41:54 +0100
committerIgor Ryzhov <iryzhov@nfware.com>2024-01-15 09:27:33 +0100
commit10eac0a54dd943cabe43c59bce3f880b2e43b367 (patch)
tree1eecfeb90f48427ee20ea85dcb7d06a040526264 /lib
parenttests: add tests for mgmt get-data with config (diff)
downloadfrr-10eac0a54dd943cabe43c59bce3f880b2e43b367.tar.xz
frr-10eac0a54dd943cabe43c59bce3f880b2e43b367.zip
lib: fix oper data leaf creation
When creating an initial tree trunk for oper data walk, if the xpath represents a leaf, the leaf is created with an incorrect empty value. If it doesn't actually exist in daemon's oper data, its value is not overwritten later and an empty value is returned in the result. For example, when requesting `/frr-interface:lib/interface[name='eth0']/description`, the result is: ``` { "frr-interface:lib": { "interface": [ { "name": "eth0", "description": "" } ] } } ``` instead of an empty JSON that it should be. Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/northbound_oper.c12
1 files changed, 11 insertions, 1 deletions
diff --git a/lib/northbound_oper.c b/lib/northbound_oper.c
index afce77318..2394b5e86 100644
--- a/lib/northbound_oper.c
+++ b/lib/northbound_oper.c
@@ -515,8 +515,18 @@ static enum nb_error nb_op_ys_init_node_infos(struct nb_op_yield_state *ys)
/* Move up to the container if on a leaf currently. */
if (node &&
- !CHECK_FLAG(node->schema->nodetype, LYS_CONTAINER | LYS_LIST))
+ !CHECK_FLAG(node->schema->nodetype, LYS_CONTAINER | LYS_LIST)) {
+ struct lyd_node *leaf = node;
+
node = &node->parent->node;
+
+ /*
+ * If the leaf is not a key, delete it, because it has a wrong
+ * empty value.
+ */
+ if (!lysc_is_key(leaf->schema))
+ lyd_free_tree(leaf);
+ }
assert(!node ||
CHECK_FLAG(node->schema->nodetype, LYS_CONTAINER | LYS_LIST));
if (!node)