diff --git a/CHANGELOG.md b/CHANGELOG.md
index baf2da92..a3f922a9 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -46,6 +46,9 @@ Expected: March 2022
Users may have to change how they access the system
+* YANG leafref `require-instance` default changed to `true`
+ * This makes leafref validation stricter
+ * See [statement: require-instance should be true if not present according to rfc7950 Sec 9.9.3](https://github.com/clicon/clixon/issues/302)
* `configure --with-wwwdir=
` is removed
* Command field of clixon-lib:process-control RPC reply used CDATA encoding but now uses regular XML encoding
@@ -59,9 +62,8 @@ Users may have to change how they access the system
### Corrected Bugs
-
-
-
+* Fixed: [statement: require-instance should be true if not present according to rfc7950 Sec 9.9.3](https://github.com/clicon/clixon/issues/302)
+ * See also API changes
* Fixed: input RPC validation of choice (non-case)
* Fixed: More than one unknown/extension in combination with augment of extension resulted in extension being skipped.
diff --git a/lib/src/clixon_validate.c b/lib/src/clixon_validate.c
index 27279337..13052cdd 100644
--- a/lib/src/clixon_validate.c
+++ b/lib/src/clixon_validate.c
@@ -134,7 +134,7 @@ validate_leafref(cxobj *xt,
char *path_arg;
yang_stmt *ymod;
cg_var *cv;
- int require_instance = 0;
+ int require_instance = 1;
/* require instance */
if ((yreqi = yang_find(ytype, Y_REQUIRE_INSTANCE, NULL)) != NULL){
diff --git a/test/test_cli_leafref.sh b/test/test_cli_leafref.sh
index ea7a00d3..85f36448 100755
--- a/test/test_cli_leafref.sh
+++ b/test/test_cli_leafref.sh
@@ -1,5 +1,6 @@
#!/usr/bin/env bash
# transitive leafref->leafref leafref->identityref completion
+#
# Magic line must be first in script (see README.md)
s="$_" ; . ./lib.sh || if [ "$s" = $0 ]; then exit 0; else return 0; fi
@@ -67,31 +68,33 @@ module example-leafref{
}
/* first level leafref */
container leafrefs {
- description "Relative path";
+ description "Leafref relative path, no require-instance";
list leafref{
key name;
leaf name {
type leafref{
path "../../../table/parameter/name";
+ require-instance false;
}
}
}
}
/* first level leafref absolute */
- container leafrefstop {
- description "Same but absolute path";
+ container leafrefsabs {
+ description "Leafref absolute path, no require-instance";
list leafref{
key name;
leaf name {
type leafref{
path "/table/parameter/name";
+ require-instance false;
}
}
}
}
/* first level leafref require-instance */
- container leafrefsreqi {
- description "Same but absolute path";
+ container leafrefsreqinst {
+ description "Leafref absolute path, require-instance true";
list leafref{
key name;
leaf name {
@@ -105,6 +108,7 @@ module example-leafref{
/* first level identityrefs */
container identityrefs {
list identityref{
+ description "Identityref base";
key name;
leaf name {
type identityref{
@@ -120,6 +124,7 @@ module example-leafref{
leaf name {
type leafref{
path "../../../leafrefs/leafref/name";
+ require-instance false;
}
}
}
@@ -131,6 +136,7 @@ module example-leafref{
leaf name {
type leafref{
path "../../../identityrefs/identityref/name";
+ require-instance false;
}
}
}
@@ -175,10 +181,10 @@ new "expand leafref 1st level"
expectpart "$(echo "set leafrefs leafref ?" | $clixon_cli -f $cfg 2> /dev/null)" 0 "91" "92" "93"
new "expand leafref top"
-expectpart "$(echo "set leafrefstop leafref ?" | $clixon_cli -f $cfg 2> /dev/null)" 0 "91" "92" "93"
+expectpart "$(echo "set leafrefsabs leafref ?" | $clixon_cli -f $cfg 2> /dev/null)" 0 "91" "92" "93"
new "expand leafref require-instance"
-expectpart "$(echo "set leafrefsreqi leafref ?" | $clixon_cli -f $cfg 2> /dev/null)" 0 "91" "92" "93"
+expectpart "$(echo "set leafrefsreqinst leafref ?" | $clixon_cli -f $cfg 2> /dev/null)" 0 "91" "92" "93"
# First level id/leaf refs
new "set identityref des"
@@ -217,7 +223,7 @@ expectpart "$($clixon_cli -1 -f $cfg -l o commit)" 0 "^$"
# require-instance
new "set leafref require-instance 99 (non-existent)"
-expectpart "$($clixon_cli -1 -f $cfg set leafrefsreqi leafref 99)" 0 "^"$
+expectpart "$($clixon_cli -1 -f $cfg set leafrefsreqinst leafref 99)" 0 "^"$
new "cli validate expect failure"
expectpart "$($clixon_cli -1 -f $cfg -l o validate)" 255 "Leafref validation failed: No leaf 99 matching path"
diff --git a/test/test_leafref_state.sh b/test/test_leafref_state.sh
index 887aee1d..fecb2bf3 100755
--- a/test/test_leafref_state.sh
+++ b/test/test_leafref_state.sh
@@ -63,7 +63,6 @@ module leafref{
leaf ref{
type leafref {
path "/ex:sender-config/ex:name";
- require-instance true;
}
}
}
@@ -90,6 +89,7 @@ module leafref{
leaf ref{
type leafref {
path "/ex:sender-config/ex:name";
+ require-instance false;
}
}
}
diff --git a/test/test_openconfig_network_instance.sh b/test/test_openconfig_network_instance.sh
index dc2917ae..303c5dd7 100755
--- a/test/test_openconfig_network_instance.sh
+++ b/test/test_openconfig_network_instance.sh
@@ -79,6 +79,7 @@ cat < $dir/startup_db
+ default
oc-ni-types:DEFAULT_INSTANCE
true
1.2.3.4