Yang schema mount: replaced config --enable-yang-schame-mount with runtime option CLICON_YANG_SCHEMA_MOUNT

Added config and validation-level as parameters to ca_yang_mount
This commit is contained in:
Olof hagsand 2023-02-17 15:36:11 +01:00
parent 02841e5c36
commit 585e725aec
19 changed files with 183 additions and 198 deletions

View file

@ -487,10 +487,8 @@ text_modify(clicon_handle h,
char *createstr = NULL;
yang_stmt *yrestype = NULL;
char *restype;
#ifdef CLIXON_YANG_SCHEMA_MOUNT
int ismount = 0;
yang_stmt *mount_yspec = NULL;
#endif
if (x1 == NULL){
clicon_err(OE_XML, EINVAL, "x1 is missing");
@ -860,9 +858,8 @@ text_modify(clicon_handle h,
x1cname = xml_name(x1c);
/* Get yang spec of the child by child matching */
if ((yc = yang_find_datanode(y0, x1cname)) == NULL){
#ifdef CLIXON_YANG_SCHEMA_MOUNT
yc = xml_spec(x1c);
#endif
if (clicon_option_bool(h, "CLICON_YANG_SCHEMA_MOUNT"))
yc = xml_spec(x1c);
if (yc == NULL){
if (clicon_option_bool(h, "CLICON_YANG_UNKNOWN_ANYDATA") == 1){
/* Add dummy Y_ANYDATA yang stmt, see ysp_add */
@ -908,22 +905,26 @@ text_modify(clicon_handle h,
x0c = x0vec[i++];
x1cname = xml_name(x1c);
if ((yc = yang_find_datanode(y0, x1cname)) == NULL){
#ifdef CLIXON_YANG_SCHEMA_MOUNT
yc = xml_spec(x1c);
#endif
if (clicon_option_bool(h, "CLICON_YANG_SCHEMA_MOUNT"))
yc = xml_spec(x1c);
}
#ifdef CLIXON_YANG_SCHEMA_MOUNT
/* Check if xc is unresolved mountpoint, ie no yang mount binding yet */
if ((ismount = xml_yang_mount_get(x1c, &mount_yspec)) < 0)
goto done;
if (ismount && mount_yspec == NULL){
ret = 1;
if (clicon_option_bool(h, "CLICON_YANG_SCHEMA_MOUNT")){
/* Check if xc is unresolved mountpoint, ie no yang mount binding yet */
if ((ismount = xml_yang_mount_get(h, x1c, NULL, &mount_yspec)) < 0)
goto done;
if (ismount && mount_yspec == NULL){
ret = 1;
}
else{
if ((ret = text_modify(h, x0c, x0, x0t, x1c, x1t,
yc, op,
username, xnacm, permit, cbret)) < 0)
goto done;
}
}
else
#endif
if ((ret = text_modify(h, x0c, x0, x0t, x1c, x1t,
yc, op,
username, xnacm, permit, cbret)) < 0)
else if ((ret = text_modify(h, x0c, x0, x0t, x1c, x1t,
yc, op,
username, xnacm, permit, cbret)) < 0)
goto done;
/* If xml return - ie netconf error xml tree, then stop and return OK */
if (ret == 0)

View file

@ -1010,6 +1010,8 @@ clixon_plugin_datastore_upgrade_all(clicon_handle h,
* @param[in] cp Plugin handle
* @param[in] h Clixon handle
* @param[in] xt XML mount-point in XML tree
* @param[out] config If '0' all data nodes in the mounted schema are read-only
* @param[out] validate Do or dont do full RFC 7950 validation
* @param[out] yanglib XML yang-lib module-set tree
* @retval 0 OK
* @retval -1 Error
@ -1018,6 +1020,8 @@ int
clixon_plugin_yang_mount_one(clixon_plugin_t *cp,
clicon_handle h,
cxobj *xt,
int *config,
validate_level *vl,
cxobj **yanglib)
{
int retval = -1;
@ -1028,7 +1032,7 @@ clixon_plugin_yang_mount_one(clixon_plugin_t *cp,
wh = NULL;
if (plugin_context_check(h, &wh, cp->cp_name, __FUNCTION__) < 0)
goto done;
if (fn(h, xt, yanglib) < 0) {
if (fn(h, xt, config, vl, yanglib) < 0) {
if (clicon_errno < 0)
clicon_log(LOG_WARNING, "%s: Internal error: Yang mount callback in plugin: %s returned -1 but did not make a clicon_err call",
__FUNCTION__, cp->cp_name);
@ -1046,22 +1050,27 @@ clixon_plugin_yang_mount_one(clixon_plugin_t *cp,
*
* @param[in] h Clixon handle
* @param[in] xt XML mount-point in XML tree
* @param[out] config If '0' all data nodes in the mounted schema are read-only
* @param[out] validate Do or dont do full RFC 7950 validation
* @param[out] yanglib XML yang-lib module-set tree (freed by caller)
* @retval 0 OK
* @retval -1 Error
*/
int
clixon_plugin_yang_mount_all(clicon_handle h,
cxobj *xt,
cxobj **yanglib)
clixon_plugin_yang_mount_all(clicon_handle h,
cxobj *xt,
int *config,
validate_level *vl,
cxobj **yanglib)
{
int retval = -1;
clixon_plugin_t *cp = NULL;
while ((cp = clixon_plugin_each(h, cp)) != NULL) {
if (clixon_plugin_yang_mount_one(cp, h, xt, yanglib) < 0)
if (clixon_plugin_yang_mount_one(cp, h, xt, config, vl, yanglib) < 0)
goto done;
if (*yanglib)
/* Break if find yanglib */
if (yanglib && *yanglib)
break;
}
retval = 0;

View file

@ -1007,16 +1007,15 @@ xml_yang_validate_add(clicon_handle h,
cxobj *x;
cg_var *cv0;
enum cv_type cvtype;
#ifdef CLIXON_YANG_SCHEMA_MOUNT
/* Do not validate beyond mountpoints */
if ((ret = xml_yang_mount_get(xt, NULL)) < 0)
goto done;
if (ret == 1){
retval = 1;
goto done;
validate_level vl = VL_NONE;
if (clicon_option_bool(h, "CLICON_YANG_SCHEMA_MOUNT")){
if ((ret = xml_yang_mount_get(h, xt, &vl, NULL)) < 0)
goto done;
/* Check if validate beyond mountpoints */
if (ret == 1 && vl == VL_NONE)
goto ok;
}
#endif
/* if not given by argument (overide) use default link
and !Node has a config sub-statement and it is false */
if ((yt = xml_spec(xt)) != NULL && yang_config(yt) != 0){
@ -1076,6 +1075,7 @@ xml_yang_validate_add(clicon_handle h,
if (ret == 0)
goto fail;
}
ok:
retval = 1;
done:
if (cv)
@ -1224,14 +1224,15 @@ xml_yang_validate_all(clicon_handle h,
cbuf *cb = NULL;
cvec *nsc = NULL;
int hit = 0;
validate_level vl = VL_NONE;
#ifdef CLIXON_YANG_SCHEMA_MOUNT
/* Do not validate beyond mountpoints */
if ((ret = xml_yang_mount_get(xt, NULL)) < 0)
goto done;
if (ret == 1)
goto ok; /* Actually this may be somewhat too strict */
#endif
if (clicon_option_bool(h, "CLICON_YANG_SCHEMA_MOUNT")){
if ((ret = xml_yang_mount_get(h, xt, &vl, NULL)) < 0)
goto done;
/* Check if validate beyond mountpoints */
if (ret == 1 && vl == VL_NONE)
goto ok;
}
/* if not given by argument (overide) use default link
and !Node has a config sub-statement and it is false */
if ((yt = xml_spec(xt)) == NULL){

View file

@ -453,34 +453,34 @@ xml_bind_yang0_opt(clicon_handle h,
goto ok;
strip_body_objects(xt);
ybc = YB_PARENT;
#ifdef CLIXON_YANG_SCHEMA_MOUNT
yspec1 = NULL;
if ((ret = xml_yang_mount_get(xt, &yspec1)) < 0)
goto done;
if (ret == 0)
yspec1 = yspec;
else{
if (yspec1)
ybc = YB_MODULE;
else if (h == NULL)
goto ok; /* treat as anydata */
if (h && clicon_option_bool(h, "CLICON_YANG_SCHEMA_MOUNT")){
yspec1 = NULL;
if ((ret = xml_yang_mount_get(h, xt, NULL, &yspec1)) < 0)
goto done;
if (ret == 0)
yspec1 = yspec;
else{
if ((ret = yang_schema_yanglib_parse_mount(h, xt)) < 0)
goto done;
if (ret == 0)
goto ok;
/* Try again */
if ((ret = xml_yang_mount_get(xt, &yspec1)) < 0)
goto done;
if (yspec1)
ybc = YB_MODULE;
else
goto ok;
else if (h == NULL)
goto ok; /* treat as anydata */
else{
if ((ret = yang_schema_yanglib_parse_mount(h, xt)) < 0)
goto done;
if (ret == 0)
goto ok;
/* Try again */
if ((ret = xml_yang_mount_get(h, xt, NULL, &yspec1)) < 0)
goto done;
if (yspec1)
ybc = YB_MODULE;
else
goto ok;
}
}
}
#else
yspec1 = yspec;
#endif
else
yspec1 = yspec;
xc = NULL; /* Apply on children */
while ((xc = xml_child_each(xt, xc, CX_ELMNT)) != NULL) {
/* It is xml2ns in populate_self_parent that needs improvement */

View file

@ -661,7 +661,6 @@ ys_free1(yang_stmt *ys,
cv_free(cv);
}
if (ys->ys_cvec){
#ifdef CLIXON_YANG_SCHEMA_MOUNT
/* Schema mount uses cvec in unknown to keep track of all yspecs
* Freed here once.
*/
@ -669,7 +668,6 @@ ys_free1(yang_stmt *ys,
strcmp(yang_argument_get(ys), "yangmnt:mount-point")==0){
xml_yang_mount_freeall(ys->ys_cvec);
}
#endif
cvec_free(ys->ys_cvec);
ys->ys_cvec = NULL;
}

View file

@ -133,15 +133,19 @@ yang_schema_mount_point(yang_stmt *y)
/*! Get yangspec mount-point
*
* @param[in] h Clixon handle
* @param[in] x XML moint-point node
* @param[out] vallevel Do or dont do full RFC 7950 validation
* @param[out] yspec YANG stmt spec
* @retval 1 x is a mount-point: yspec may be set
* @retval 0 x is not a mount point
* @retval -1 Error
*/
int
xml_yang_mount_get(cxobj *xt,
yang_stmt **yspec)
xml_yang_mount_get(clicon_handle h,
cxobj *xt,
validate_level *vl,
yang_stmt **yspec)
{
int retval = -1;
cvec *cvv = NULL;
@ -157,6 +161,9 @@ xml_yang_mount_get(cxobj *xt,
goto done;
if (ret == 0)
goto fail;
/* Check validate level */
if (clixon_plugin_yang_mount_all(h, xt, NULL, vl, NULL) < 0)
goto done;
// XXX hardcoded prefix: yangmnt
if ((yu = yang_find(y, Y_UNKNOWN, "yangmnt:mount-point")) == NULL)
goto ok;
@ -168,6 +175,7 @@ xml_yang_mount_get(cxobj *xt,
if ((cv = cvec_find(cvv, xpath)) == NULL)
goto ok;
if (yspec)
*yspec = cv_void_get(cv);
ok:
retval = 1;
@ -301,14 +309,16 @@ yang_schema_mount_statedata_yanglib(clicon_handle h,
cxobj **xret,
cxobj **xerr)
{
int retval = -1;
cvec *cvv = NULL;
cg_var *cv;
cxobj *xmp; /* xml mount-point */
cxobj *yanglib = NULL; /* xml yang-lib */
cbuf *cb = NULL;
yang_stmt *yspec;
int ret;
int retval = -1;
cvec *cvv = NULL;
cg_var *cv;
cxobj *xmp; /* xml mount-point */
cxobj *yanglib = NULL; /* xml yang-lib */
cbuf *cb = NULL;
yang_stmt *yspec;
int ret;
int config = 1;
validate_level vl = VL_FULL;
if ((cb = cbuf_new()) == NULL){
clicon_err(OE_UNIX, 0, "clicon buffer");
@ -325,12 +335,11 @@ yang_schema_mount_statedata_yanglib(clicon_handle h,
xmp = cv_void_get(cv);
yanglib = NULL;
/* User callback */
if (clixon_plugin_yang_mount_all(h, xmp, &yanglib) < 0)
if (clixon_plugin_yang_mount_all(h, xmp, &config, &vl, &yanglib) < 0)
goto done;
if (yanglib == NULL)
continue;
yspec = clicon_dbspec_yang(h);
// if ((ret = xml_bind_yang(h, yanglib, YB_NONE, yspec, &xerr)) < 0)
if ((ret = xml_bind_yang0(h, yanglib, YB_MODULE, yspec, xerr)) < 0)
goto done;
if (ret == 0)
@ -449,12 +458,14 @@ int
yang_schema_yanglib_parse_mount(clicon_handle h,
cxobj *xt)
{
int retval = -1;
cxobj *yanglib = NULL;
yang_stmt *yspec = NULL;
int ret;
int retval = -1;
cxobj *yanglib = NULL;
yang_stmt *yspec = NULL;
int ret;
int config = 1;
validate_level vl = VL_FULL;
if (clixon_plugin_yang_mount_all(h, xt, &yanglib) < 0)
if (clixon_plugin_yang_mount_all(h, xt, &config, &vl, &yanglib) < 0)
goto done;
if (yanglib == NULL)
goto anydata;
@ -504,7 +515,7 @@ yang_schema_get_child(clicon_handle h,
int ret;
x1cname = xml_name(x1c);
if ((ret = xml_yang_mount_get(x1, &yspec1)) < 0)
if ((ret = xml_yang_mount_get(h, x1, NULL, &yspec1)) < 0)
goto done;
if (ret == 1 && yspec1 != NULL){
if (ys_module_by_xml(yspec1, x1c, &ymod1) <0)