yang augment sanity checks

This commit is contained in:
Olof hagsand 2020-10-05 15:49:22 +02:00
parent b7cb2e2526
commit 1db43ca45b
3 changed files with 88 additions and 11 deletions

View file

@ -49,7 +49,7 @@ RUN apk add --update libevent cmake libevent-dev
WORKDIR /clixon WORKDIR /clixon
RUN git clone https://github.com/criticalstack/libevhtp.git RUN git clone https://github.com/criticalstack/libevhtp.git
WORKDIR /clixon/libevhtp/build WORKDIR /clixon/libevhtp/build
RUN cmake -DEVHTP_DISABLE_REGEX=ON -DEVHTP_DISABLE_EVTHR=ON .. RUN cmake -DEVHTP_DISABLE_REGEX=ON -DEVHTP_DISABLE_EVTHR=ON -DBUILD_SHARED_LIBS=OFF ..
RUN make RUN make
RUN make install RUN make install

View file

@ -1404,7 +1404,7 @@ ys_real_module(yang_stmt *ys,
* @param[in] ys Any yang statement in a yang tree * @param[in] ys Any yang statement in a yang tree
* @retval yspec The top yang specification * @retval yspec The top yang specification
* @see ys_module * @see ys_module
* @see ys_yang_augment_node where shortcut is set * @see yang_augment_node where shortcut is set
*/ */
yang_stmt * yang_stmt *
ys_spec(yang_stmt *ys) ys_spec(yang_stmt *ys)
@ -2590,6 +2590,7 @@ schema_nodeid_iterate(yang_stmt *yn,
while ((ys = yn_each(yp, ys)) != NULL) { while ((ys = yn_each(yp, ys)) != NULL) {
if (!yang_schemanode(ys)) if (!yang_schemanode(ys))
continue; continue;
/* some keys dont have arguments, match on key */ /* some keys dont have arguments, match on key */
if (ys->ys_keyword == Y_INPUT || ys->ys_keyword == Y_OUTPUT){ if (ys->ys_keyword == Y_INPUT || ys->ys_keyword == Y_OUTPUT){
if (strcmp(id, yang_key2str(ys->ys_keyword)) == 0){ if (strcmp(id, yang_key2str(ys->ys_keyword)) == 0){

View file

@ -223,6 +223,8 @@ yang_augment_node(yang_stmt *ys)
yang_stmt *ywhen; yang_stmt *ywhen;
char *wxpath = NULL; /* xpath of when statement */ char *wxpath = NULL; /* xpath of when statement */
cvec *wnsc = NULL; /* namespace context of when statement */ cvec *wnsc = NULL; /* namespace context of when statement */
enum rfc_6020 targetkey;
enum rfc_6020 childkey;
if ((ymod = ys_module(ys)) == NULL){ if ((ymod = ys_module(ys)) == NULL){
clicon_err(OE_YANG, 0, "My yang module not found"); clicon_err(OE_YANG, 0, "My yang module not found");
@ -248,6 +250,18 @@ yang_augment_node(yang_stmt *ys)
goto ok; goto ok;
#endif #endif
} }
/* The target node MUST be either a container, list, choice, case, input, output, or notification node.
* which means it is slightly different than a schema-nodeid ? */
targetkey = yang_keyword_get(ytarget);
if (targetkey != Y_CONTAINER && targetkey != Y_LIST && targetkey != Y_CHOICE &&
targetkey != Y_CASE && targetkey != Y_INPUT &&
targetkey != Y_OUTPUT && targetkey != Y_NOTIFICATION){
clicon_log(LOG_WARNING, "Warning: Augment failed in module %s: target node %s has wrong type %s",
yang_argument_get(ys_module(ys)),
schema_nodeid,
yang_key2str(targetkey));
goto ok;
}
/* Find when statement, if present */ /* Find when statement, if present */
if ((ywhen = yang_find(ys, Y_WHEN, NULL)) != NULL){ if ((ywhen = yang_find(ys, Y_WHEN, NULL)) != NULL){
@ -260,9 +274,71 @@ yang_augment_node(yang_stmt *ys)
while ((yc0 = yn_each(ys, yc0)) != NULL) { while ((yc0 = yn_each(ys, yc0)) != NULL) {
if (!yang_schemanode(yc0)) if (!yang_schemanode(yc0))
continue; continue;
childkey = yang_keyword_get(yc0);
switch (targetkey){
case Y_CONTAINER:
case Y_LIST:
/* If the target node is a container or list node, the "action" and
"notification" statements can be used within the "augment" statement.
*/
if (childkey != Y_ACTION && childkey != Y_NOTIFICATION &&
childkey != Y_CONTAINER && childkey != Y_LEAF && childkey != Y_LIST &&
childkey != Y_LEAF_LIST && childkey != Y_USES && childkey != Y_CHOICE){
clicon_log(LOG_WARNING, "Warning: A Augment failed in module %s: node %s %d cannot be added to target node %s",
yang_argument_get(ys_module(ys)),
yang_key2str(childkey),
childkey,
schema_nodeid);
goto ok;
}
break;
case Y_CASE:
case Y_INPUT:
case Y_OUTPUT:
case Y_NOTIFICATION:
/* If the target node is a container, list, case, input, output, or
notification node, the "container", "leaf", "list", "leaf-list",
"uses", and "choice" statements can be used within the "augment"
statement. */
if (childkey != Y_CONTAINER && childkey != Y_LEAF && childkey != Y_LIST &&
childkey != Y_LEAF_LIST && childkey != Y_USES && childkey != Y_CHOICE){
clicon_log(LOG_WARNING, "Warning: B Augment failed in module %s: node %s %d cannot be added to target node %s",
yang_argument_get(ys_module(ys)),
yang_key2str(childkey),
childkey,
schema_nodeid);
goto ok;
}
break;
case Y_CHOICE:
/* If the target node is a choice node, the "case" statement or a
shorthand "case" statement (see Section 7.9.2) can be used within the
"augment" statement.
XXX could be more or less anything?
As a shorthand, the "case" statement can be omitted if the branch
contains a single "anydata", "anyxml", "choice", "container", "leaf",
"list", or "leaf-list" statement.
*/
if (childkey != Y_CASE && childkey != Y_ANYDATA && childkey != Y_ANYXML &&
childkey != Y_CHOICE && childkey != Y_CONTAINER && childkey != Y_LEAF &&
childkey != Y_LIST && childkey != Y_LEAF_LIST){
clicon_log(LOG_WARNING, "Warning: C Augment failed in module %s: node %s %d cannot be added to target node %s",
yang_argument_get(ys_module(ys)),
yang_key2str(childkey),
childkey,
schema_nodeid);
goto ok;
}
break;
default:
break;
}
if ((yc = ys_dup(yc0)) == NULL) if ((yc = ys_dup(yc0)) == NULL)
goto done; goto done;
yc->ys_mymodule = ymod; yc->ys_mymodule = ymod;
if (yn_insert(ytarget, yc) < 0) if (yn_insert(ytarget, yc) < 0)
goto done; goto done;
/* If there is an associated when statement, add a special when struct to the yang */ /* If there is an associated when statement, add a special when struct to the yang */