schema compile CHANGE leafref config type
- if leafref has require-instance true and it is a configuration node,
it must not point to a status node
diff --git a/src/tree_schema.h b/src/tree_schema.h
index da640f1..bb018c3 100644
--- a/src/tree_schema.h
+++ b/src/tree_schema.h
@@ -1211,6 +1211,7 @@
struct lysc_must *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
struct lysc_type *type; /**< type of the leaf node (mandatory) */
+
const char *units; /**< units of the leaf's type */
const char *dflt; /**< default value */
};
@@ -1229,6 +1230,12 @@
const char *name; /**< node name (mandatory) */
struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
+ struct lysc_when *when; /**< when statement */
+ struct lysc_iffeature *iffeatures; /**< list of if-feature expressions ([sized array](@ref sizedarrays)) */
+
+ struct lysc_must *musts; /**< list of must restrictions ([sized array](@ref sizedarrays)) */
+ struct lysc_type *type; /**< type of the leaf node (mandatory) */
+
};
struct lysc_node_list {
diff --git a/src/tree_schema_compile.c b/src/tree_schema_compile.c
index ad66bfb..bff9332 100644
--- a/src/tree_schema_compile.c
+++ b/src/tree_schema_compile.c
@@ -2024,6 +2024,16 @@
return LY_EVALID;
}
+ /* check config */
+ if (leafref->require_instance && (startnode->flags & LYS_CONFIG_W)) {
+ if (node->flags & LYS_CONFIG_R) {
+ LOGVAL(ctx->ctx, LY_VLOG_STR, ctx->path, LYVE_REFERENCE,
+ "Invalid leafref path \"%s\" - target is supposed to represent configuration data (as the leafref does), but it does not.",
+ leafref->path);
+ return LY_EVALID;
+ }
+ }
+
/* store the target's type and check for circular chain of leafrefs */
leafref->realtype = ((struct lysc_node_leaf*)node)->type;
for (type = leafref->realtype; type && type->basetype == LY_TYPE_LEAFREF; type = ((struct lysc_type_leafref*)type)->realtype) {
diff --git a/tests/src/test_tree_schema_compile.c b/tests/src/test_tree_schema_compile.c
index 9323bd9..221ca1c 100644
--- a/tests/src/test_tree_schema_compile.c
+++ b/tests/src/test_tree_schema_compile.c
@@ -1404,12 +1404,15 @@
"leaf ref1 {type mytype;}}", LYS_IN_YANG));
assert_int_equal(LY_EVALID, lys_compile(mod, 0));
logbuf_assert("Missing path substatement for leafref type mytype.");
-
assert_non_null(mod = lys_parse_mem(ctx, "module jj {namespace urn:jj;prefix jj;feature f;"
"leaf ref {type leafref {path /target;}}leaf target {if-feature f;type string;}}", LYS_IN_YANG));
assert_int_equal(LY_EVALID, lys_compile(mod, 0));
logbuf_assert("Invalid leafref path \"/target\" - set of features applicable to the leafref target is not a subset of features "
"applicable to the leafref itself.");
+ assert_non_null(mod = lys_parse_mem(ctx, "module kk {namespace urn:kk;prefix kk;"
+ "leaf ref {type leafref {path /target;}}leaf target {type string;config false;}}", LYS_IN_YANG));
+ assert_int_equal(LY_EVALID, lys_compile(mod, 0));
+ logbuf_assert("Invalid leafref path \"/target\" - target is supposed to represent configuration data (as the leafref does), but it does not.");
/* circular chain */
assert_non_null(mod = lys_parse_mem(ctx, "module aaa {namespace urn:aaa;prefix aaa;"