Fixed: [YANG when condition evaluated as false combined with a mandatory leaf does not work](https://github.com/clicon/clixon/issues/380)
Replaced yang_mandatory() with yang_xml_mandatory() by extending existing it with when check
This commit is contained in:
parent
83663d4d15
commit
1eb78a78f8
7 changed files with 424 additions and 88 deletions
|
|
@ -3213,65 +3213,6 @@ yang_desc_schema_nodeid(yang_stmt *yn,
|
|||
return retval;
|
||||
}
|
||||
|
||||
/*! Check if this leaf is mandatory or not
|
||||
* Note: one can cache this value in ys_cvec instead of functionally evaluating it.
|
||||
* @retval 1 yang statement is leaf and it has a mandatory sub-stmt with value true
|
||||
* @retval 0 The negation of conditions for return value 1.
|
||||
* @see RFC7950 Sec 3:
|
||||
* o mandatory node: A mandatory node is one of:
|
||||
* 1) A leaf, choice, anydata, or anyxml node with a "mandatory"
|
||||
* statement with the value "true".
|
||||
* 2) # see below
|
||||
* 3) A container node without a "presence" statement and that has at
|
||||
* least one mandatory node as a child.
|
||||
*
|
||||
* @note There is also this statement
|
||||
* 2) A list or leaf-list node with a "min-elements" statement with a
|
||||
* value greater than zero.
|
||||
* which we ignore here since:
|
||||
* (a) it does not consider the XML siblings and therefore returns false positives
|
||||
* (b) where the actual check is catched by check_list_unique_minmax()
|
||||
*/
|
||||
int
|
||||
yang_mandatory(yang_stmt *ys)
|
||||
{
|
||||
yang_stmt *ym;
|
||||
cg_var *cv;
|
||||
|
||||
/* 1) A leaf, choice, anydata, or anyxml node with a "mandatory"
|
||||
* statement with the value "true". */
|
||||
if (ys->ys_keyword == Y_LEAF || ys->ys_keyword == Y_CHOICE ||
|
||||
ys->ys_keyword == Y_ANYDATA || ys->ys_keyword == Y_ANYXML){
|
||||
if ((ym = yang_find(ys, Y_MANDATORY, NULL)) != NULL){
|
||||
if ((cv = yang_cv_get(ym)) != NULL) /* shouldnt happen */
|
||||
return cv_bool_get(cv);
|
||||
}
|
||||
}
|
||||
#if 0 /* See note above */
|
||||
/* 2) A list or leaf-list node with a "min-elements" statement with a
|
||||
* value greater than zero. */
|
||||
else if (ys->ys_keyword == Y_LIST || ys->ys_keyword == Y_LEAF_LIST){
|
||||
if ((ym = yang_find(ys, Y_MIN_ELEMENTS, NULL)) != NULL){
|
||||
cv = yang_cv_get(ym);
|
||||
return cv_uint32_get(cv) > 0; /* Not true if XML considered */
|
||||
}
|
||||
}
|
||||
#endif
|
||||
/* 3) A container node without a "presence" statement and that has at
|
||||
* least one mandatory node as a child. */
|
||||
else if (ys->ys_keyword == Y_CONTAINER &&
|
||||
yang_find(ys, Y_PRESENCE, NULL) == NULL){
|
||||
yang_stmt *yc;
|
||||
int i;
|
||||
for (i=0; i<ys->ys_len; i++){
|
||||
yc = ys->ys_stmt[i];
|
||||
if (yang_mandatory(yc))
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*! Return config state of this node
|
||||
* @param[in] ys Yang statement
|
||||
* @retval 0 If node has a config sub-statement and it is false
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue