Skip to content

Commit

Permalink
Added YANG deviate flag to not follow orig links
Browse files Browse the repository at this point in the history
Fixed unbounded loop in deviation
  • Loading branch information
olofhagsand committed Aug 15, 2024
1 parent 05263e9 commit 442e039
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 5 deletions.
1 change: 1 addition & 0 deletions lib/clixon/clixon_yang.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions lib/src/clixon_yang.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/src/clixon_yang_module.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 9 additions & 1 deletion lib/src/clixon_yang_type.c
Original file line number Diff line number Diff line change
Expand Up @@ -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){
Expand Down
52 changes: 51 additions & 1 deletion test/test_openconfig.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 442e039

Please sign in to comment.