Added YANG deviate flag to not follow orig links

Fixed unbounded loop in deviation
This commit is contained in:
Olof hagsand 2024-08-15 18:43:45 +02:00
parent 05263e942a
commit 442e0391cc
5 changed files with 66 additions and 5 deletions

View file

@ -94,6 +94,7 @@
* augment/grouping */
#define YANG_FLAG_MYMODULE 0x800 /* Use external map to access my-module for
* UNKNOWNS and augment/grouping */
#define YANG_FLAG_NOORIG 0x1000 /* Node different from orig, do not use orig-link */
/*
* Types

View file

@ -2358,6 +2358,7 @@ yang_deviation(yang_stmt *ys,
enum rfc_6020 kw;
int min;
int max;
int inext0;
int inext;
if (yang_keyword_get(ys) != Y_DEVIATION)
@ -2379,8 +2380,8 @@ yang_deviation(yang_stmt *ys,
*/
}
/* Go through deviates of deviation */
inext = 0;
while ((yd = yn_iter(ys, &inext)) != NULL) {
inext0 = 0;
while ((yd = yn_iter(ys, &inext0)) != NULL) {
/* description / if-feature / reference */
if (yang_keyword_get(yd) != Y_DEVIATE)
continue;
@ -2448,6 +2449,7 @@ yang_deviation(yang_stmt *ys,
/* Make a copy of deviate child and insert. */
if ((yc1 = ys_dup(yc)) == NULL)
goto done;
yang_flag_set(yc1, YANG_FLAG_NOORIG);
if (yn_insert(ytarget, yc1) < 0)
goto done;
}

View file

@ -924,7 +924,7 @@ yang_lib2yspec(clixon_handle h,
if ((modmin = yang_len_get(yspec) - (1+veclen - modmin)) < 0)
goto fail;
if (yang_parse_post(h, yspec, modmin) < 0)
goto done;
goto fail;
retval = 1;
done:
if (vec)

View file

@ -1482,8 +1482,16 @@ yang_type_get(yang_stmt *ys,
if (options)
*options = 0x0;
/* Use original tree to resolve types */
if ((yorig = yang_orig_get(ys)) != NULL) {
if ((ytype = yang_find(ys, Y_TYPE, NULL)) == NULL){
clixon_err(OE_DB, ENOENT, "mandatory type object is not found");
goto done;
}
if ((yorig = yang_orig_get(ys)) != NULL && yang_flag_get(ytype, YANG_FLAG_NOORIG) == 0){
ys = yorig;
if ((ytype = yang_find(ys, Y_TYPE, NULL)) == NULL){
clixon_err(OE_DB, ENOENT, "mandatory type object is not found");
goto done;
}
}
/* Find mandatory type */
if ((ytype = yang_find(ys, Y_TYPE, NULL)) == NULL){

View file

@ -76,11 +76,61 @@ cat <<EOF > $cfg
</clixon-config>
EOF
new "$clixon_cli -D $DBG -1f $cfg -o CLICON_YANG_MAIN_FILE=$f show version"
new "$clixon_cli -D $DBG -1f $cfg -y $f show version"
expectpart "$($clixon_cli -D $DBG -1f $cfg -y $f show version)" 0 "${CLIXON_VERSION}"
fi
done
# The following test is a special case: A deviation of a grouped type did not appear in
# type resolution
f=$dir/my.yang
cat <<EOF > $f
module my {
namespace "urn:example:clixon";
prefix "ex";
import "openconfig-network-instance" {
prefix "oc-netinst";
}
deviation "/oc-netinst:network-instances/oc-netinst:network-instance/oc-netinst:protocols/oc-netinst:protocol/oc-netinst:isis/oc-netinst:interfaces/oc-netinst:interface/oc-netinst:levels/oc-netinst:level/oc-netinst:afi-safi/oc-netinst:af/oc-netinst:config/oc-netinst:metric" {
description "metric range is restricted";
deviate "replace" {
type "union" {
type "uint32";
type "enumeration" {
enum "MYTEXT";
}
}
default "MYTEXT";
}
}
}
EOF
modname=$(basename $f | awk -F "." '{print $1}')
# Generate autocli for these modules
AUTOCLI=$(autocli_config openconfig-* kw-nokey false)
cat <<EOF > $cfg
<clixon-config xmlns="http://clicon.org/config">
<CLICON_CONFIGFILE>$cfg</CLICON_CONFIGFILE>
<CLICON_FEATURE>ietf-netconf:startup</CLICON_FEATURE>
<CLICON_YANG_DIR>${OPENCONFIG}</CLICON_YANG_DIR>
<CLICON_YANG_DIR>${YANG_INSTALLDIR}</CLICON_YANG_DIR>
<CLICON_YANG_AUGMENT_ACCEPT_BROKEN>true</CLICON_YANG_AUGMENT_ACCEPT_BROKEN>
<CLICON_CLISPEC_DIR>/usr/local/lib/$APPNAME/clispec</CLICON_CLISPEC_DIR>
<CLICON_CLI_DIR>/usr/local/lib/$APPNAME/cli</CLICON_CLI_DIR>
<CLICON_CLI_MODE>$APPNAME</CLICON_CLI_MODE>
<CLICON_SOCK>/usr/local/var/run/$APPNAME.sock</CLICON_SOCK>
<CLICON_BACKEND_PIDFILE>/usr/local/var/run/$APPNAME.pidfile</CLICON_BACKEND_PIDFILE>
<CLICON_XMLDB_DIR>$dir</CLICON_XMLDB_DIR>
${AUTOCLI}
</clixon-config>
EOF
new "deviation: $clixon_cli -D $DBG -1f $cfg -y $f show version"
expectpart "$($clixon_cli -D $DBG -1f $cfg -y $f show version)" 0 "${CLIXON_VERSION}"
rm -rf $dir
new "endtest"