Yang schema mount fix: canonical paths and register on conatiner instead of unknown

This commit is contained in:
Olof hagsand 2023-11-14 19:35:17 +01:00
parent a98bbf0ec6
commit 597cbe882b
4 changed files with 75 additions and 35 deletions

View file

@ -273,14 +273,14 @@ identityref_add_ns(cxobj *x,
return retval; return retval;
} }
/*! Given a top-level yspec and montpoint xpath compute a set of /*! Given a top-level yspec and mountpoint xpath compute a set of
* *
* Manipulate top-level and a mointpoint: * Manipulate top-level and a mointpoint:
* YSPEC: yspec0 yspec1 * YSPEC: yspec0 yspec1
* XML: top0-->bot0-->top1-->bot1 * XML: top0-->bot0-->top1-->bot1
* API-PATH: api-path0 api-path1 * API-PATH: api-path0 api-path1
* api-path01--------- * api-path01---------
* The result computed from the top-level yspec and montpoint xpath are: * The result computed from the top-level yspec and mountpoint xpath are:
* - api_pathfmt10 Combined api-path for both trees * - api_pathfmt10 Combined api-path for both trees
* @param[in] yspec0 Top-level yang-spec * @param[in] yspec0 Top-level yang-spec
* @param[in] mtpoint Mount-point, generic: if there are several with same yang, any will do * @param[in] mtpoint Mount-point, generic: if there are several with same yang, any will do

View file

@ -58,7 +58,7 @@ int yang_schema_mount_point(yang_stmt *y);
int yang_mount_get(yang_stmt *yu, char *xpath, yang_stmt **yspec); int yang_mount_get(yang_stmt *yu, char *xpath, yang_stmt **yspec);
int yang_mount_set(yang_stmt *yu, char *xpath, yang_stmt *yspec); int yang_mount_set(yang_stmt *yu, char *xpath, yang_stmt *yspec);
int xml_yang_mount_get(clicon_handle h, cxobj *x, validate_level *vl, yang_stmt **yspec); int xml_yang_mount_get(clicon_handle h, cxobj *x, validate_level *vl, yang_stmt **yspec);
int xml_yang_mount_set(cxobj *x, yang_stmt *yspec); int xml_yang_mount_set(clicon_handle h, cxobj *x, yang_stmt *yspec);
int xml_yang_mount_freeall(cvec *cvv); int xml_yang_mount_freeall(cvec *cvv);
int yang_schema_mount_statedata(clicon_handle h, yang_stmt *yspec, char *xpath, cvec *nsc, cxobj **xret, cxobj **xerr); int yang_schema_mount_statedata(clicon_handle h, yang_stmt *yspec, char *xpath, cvec *nsc, cxobj **xret, cxobj **xerr);
int yang_schema_mount_statistics(clicon_handle h, cxobj *xt, int modules, cbuf *cb); int yang_schema_mount_statistics(clicon_handle h, cxobj *xt, int modules, cbuf *cb);

View file

@ -1102,6 +1102,7 @@ xpath_traverse_canonical(xpath_tree *xs,
* ... * ...
* if (xpath1) free(xpath1); * if (xpath1) free(xpath1);
* if (nsc1) xml_nsctx_free(nsc1); * if (nsc1) xml_nsctx_free(nsc1);
* if (reason) cbuf_free(reason);
* @endcode * @endcode
* @note Unsolvable issue of mountpoints, eg an xpath of //x:foo where foo is under one or several * @note Unsolvable issue of mountpoints, eg an xpath of //x:foo where foo is under one or several
* mointpoints: a well-defined namespace cannot be determined. Therefore just allow * mointpoints: a well-defined namespace cannot be determined. Therefore just allow

View file

@ -84,6 +84,7 @@
#include "clixon_yang_parse_lib.h" #include "clixon_yang_parse_lib.h"
#include "clixon_plugin.h" #include "clixon_plugin.h"
#include "clixon_xml_bind.h" #include "clixon_xml_bind.h"
#include "clixon_xml_nsctx.h"
#include "clixon_netconf_lib.h" #include "clixon_netconf_lib.h"
#include "clixon_yang_schema_mount.h" #include "clixon_yang_schema_mount.h"
@ -138,14 +139,14 @@ yang_schema_mount_point(yang_stmt *y)
/*! Get yangspec mount-point /*! Get yangspec mount-point
* *
* @param[in] yu Yang unknown node to save the yspecs * @param[in] y Yang container/list containing unknown node
* @param[in] xpath Key for yspec on yu * @param[in] xpath Key for yspec on y
* @param[out] yspec YANG stmt spec * @param[out] yspec YANG stmt spec
* @retval 0 OK * @retval 0 OK
* @retval -1 Error * @retval -1 Error
*/ */
int int
yang_mount_get(yang_stmt *yu, yang_mount_get(yang_stmt *y,
char *xpath, char *xpath,
yang_stmt **yspec) yang_stmt **yspec)
{ {
@ -153,24 +154,24 @@ yang_mount_get(yang_stmt *yu,
cg_var *cv; cg_var *cv;
/* Special value in yang unknown node for mount-points: mapping from xpath->mounted yspec */ /* Special value in yang unknown node for mount-points: mapping from xpath->mounted yspec */
if ((cvv = yang_cvec_get(yu)) != NULL && if ((cvv = yang_cvec_get(y)) != NULL &&
(cv = cvec_find(cvv, xpath)) != NULL && (cv = cvec_find(cvv, xpath)) != NULL &&
yspec) yspec)
*yspec = cv_void_get(cv); *yspec = cv_void_get(cv);
return 0; return 0;
} }
/*! Set yangspec mount-point on yang unknwon node /*! Set yangspec mount-point on yang node containing extension
* *
* Mount-points are stored in unknown yang cvec * Mount-points are stored in unknown yang cvec
* @param[in] yu Yang unknown node to save the yspecs * @param[in] y Yang container/list containing unknown node
* @param[in] xpath Key for yspec on yu, in canonical form * @param[in] xpath Key for yspec on y, in canonical form
* @param[in] yspec Yangspec for this mount-point (consumed) * @param[in] yspec Yangspec for this mount-point (consumed)
* @retval 0 OK * @retval 0 OK
* @retval -1 Error * @retval -1 Error
*/ */
int int
yang_mount_set(yang_stmt *yu, yang_mount_set(yang_stmt *y,
char *xpath, char *xpath,
yang_stmt *yspec) yang_stmt *yspec)
{ {
@ -180,7 +181,7 @@ yang_mount_set(yang_stmt *yu,
cg_var *cv; cg_var *cv;
cg_var *cv2; cg_var *cv2;
if ((cvv = yang_cvec_get(yu)) != NULL && if ((cvv = yang_cvec_get(y)) != NULL &&
(cv = cvec_find(cvv, xpath)) != NULL && (cv = cvec_find(cvv, xpath)) != NULL &&
(yspec0 = cv_void_get(cv)) != NULL){ (yspec0 = cv_void_get(cv)) != NULL){
#if 0 /* Problematic to free yang specs here, upper layers should handle it? */ #if 0 /* Problematic to free yang specs here, upper layers should handle it? */
@ -188,7 +189,7 @@ yang_mount_set(yang_stmt *yu,
#endif #endif
cv_void_set(cv, NULL); cv_void_set(cv, NULL);
} }
else if ((cv = yang_cvec_add(yu, CGV_VOID, xpath)) == NULL) else if ((cv = yang_cvec_add(y, CGV_VOID, xpath)) == NULL)
goto done; goto done;
if ((cv2 = cv_new(CGV_STRING)) == NULL){ if ((cv2 = cv_new(CGV_STRING)) == NULL){
clicon_err(OE_YANG, errno, "cv_new"); clicon_err(OE_YANG, errno, "cv_new");
@ -224,9 +225,13 @@ xml_yang_mount_get(clicon_handle h,
{ {
int retval = -1; int retval = -1;
yang_stmt *y; yang_stmt *y;
yang_stmt *yu; char *xpath0 = NULL;
char *xpath = NULL; // XXX free it
int ret; int ret;
cvec *nsc0 = NULL;
yang_stmt *yspec0;
char *xpath1 = NULL;
cvec *nsc1 = NULL;
cbuf *reason = NULL;
if ((y = xml_spec(xt)) == NULL) if ((y = xml_spec(xt)) == NULL)
goto fail; goto fail;
@ -237,18 +242,29 @@ xml_yang_mount_get(clicon_handle h,
/* Check validate level */ /* Check validate level */
if (vl && clixon_plugin_yang_mount_all(h, xt, NULL, vl, NULL) < 0) if (vl && clixon_plugin_yang_mount_all(h, xt, NULL, vl, NULL) < 0)
goto done; goto done;
// XXX hardcoded prefix: yangmnt if (xml2xpath(xt, NULL, 1, 0, &xpath0) < 0)
if ((yu = yang_find(y, Y_UNKNOWN, "yangmnt:mount-point")) == NULL)
goto ok;
if (xml2xpath(xt, NULL, 1, 0, &xpath) < 0)
goto done; goto done;
if (yang_mount_get(yu, xpath, yspec) < 0) if (xml_nsctx_node(xt, &nsc0) < 0)
goto done;
yspec0 = clicon_dbspec_yang(h);
if ((ret = xpath2canonical(xpath0, nsc0, yspec0, &xpath1, &nsc0, &reason)) < 0)
goto done;
if (ret == 0)
goto fail;
if (yang_mount_get(y, xpath1, yspec) < 0)
goto done; goto done;
ok:
retval = 1; retval = 1;
done: done:
if (xpath) if (xpath0)
free(xpath); free(xpath0);
if (xpath1)
free(xpath1);
if (nsc0)
cvec_free(nsc0);
if (nsc1)
cvec_free(nsc1);
if (reason)
cbuf_free(reason);
return retval; return retval;
fail: fail:
retval = 0; retval = 0;
@ -264,26 +280,49 @@ xml_yang_mount_get(clicon_handle h,
* @retval -1 Error * @retval -1 Error
*/ */
int int
xml_yang_mount_set(cxobj *x, xml_yang_mount_set(clicon_handle h,
cxobj *x,
yang_stmt *yspec) yang_stmt *yspec)
{ {
int retval = -1; int retval = -1;
yang_stmt *y; yang_stmt *y;
yang_stmt *yu; char *xpath0 = NULL;
char *xpath = NULL; char *xpath1 = NULL;
cvec *nsc0 = NULL;
cvec *nsc1 = NULL;
yang_stmt *yspec0;
cbuf *reason = NULL;
int ret;
if ((y = xml_spec(x)) == NULL || if ((y = xml_spec(x)) == NULL){
(yu = yang_find(y, Y_UNKNOWN, "yangmnt:mount-point")) == NULL){ clicon_err(OE_YANG, 0, "No yang-spec");
goto done; goto done;
} }
if (xml2xpath(x, NULL, 1, 0, &xpath) < 0) if (xml2xpath(x, NULL, 1, 0, &xpath0) < 0)
goto done; goto done;
if (yang_mount_set(yu, xpath, yspec) < 0) if (xml_nsctx_node(x, &nsc0) < 0)
goto done;
yspec0 = clicon_dbspec_yang(h);
if ((ret = xpath2canonical(xpath0, nsc0, yspec0, &xpath1, &nsc0, &reason)) < 0)
goto done;
if (ret == 0){
clicon_err(OE_YANG, 0, "%s", cbuf_get(reason));
goto done;
}
if (yang_mount_set(y, xpath1, yspec) < 0)
goto done; goto done;
retval = 0; retval = 0;
done: done:
if (xpath) if (xpath0)
free(xpath); free(xpath0);
if (xpath1)
free(xpath1);
if (nsc0)
cvec_free(nsc0);
if (nsc1)
cvec_free(nsc1);
if (reason)
cbuf_free(reason);
return retval; return retval;
} }
@ -607,7 +646,7 @@ yang_schema_yanglib_parse_mount(clicon_handle h,
goto done; goto done;
if (ret == 0) if (ret == 0)
goto anydata; goto anydata;
if (xml_yang_mount_set(xt, yspec) < 0) if (xml_yang_mount_set(h, xt, yspec) < 0)
goto done; goto done;
yspec = NULL; yspec = NULL;
retval = 1; retval = 1;