YANG domain/spec support

cli show mem improvement
This commit is contained in:
Olof hagsand 2024-10-06 20:07:08 +02:00
parent 5ebc5a2219
commit b9ff2d083a
6 changed files with 39 additions and 36 deletions

View file

@ -289,7 +289,7 @@ int yang_stats(yang_stmt *y, enum rfc_6020 keyw, uint64_t *nrp, size_t *s
/* Other functions */
yang_stmt *yspec_new(clixon_handle h, char *name);
yang_stmt *yspec_new1(clixon_handle h, char *domain, char *name);
yang_stmt *yspec_new_shared(clixon_handle h, char *name, char *domain, yang_stmt *yspec0);
yang_stmt *yspec_new_shared(clixon_handle h, char *xpath, char *domain, char *name, yang_stmt *yspec0);
yang_stmt *ydomain_new(clixon_handle h, char *domain);
yang_stmt *ys_new(enum rfc_6020 keyw);
yang_stmt *ys_prune(yang_stmt *yp, int i);

View file

@ -886,44 +886,38 @@ yspec_new1(clixon_handle h,
/*! Create or add a shared yspec
*
* @param[in] h Clixon handle
* @param[in] tag Typically an xpath, saved in cvec
* @param[in] yspec0 Input NULL if no previous shared exist, otherwise a shared yspec but new name
* @retval yspec1 New or (previously shared)
* @retval NULL Error
* @param[in] h Clixon handle
* @param[in] xpath Mount xpath, saved in cvec
* @param[in] domain YANG domain
* @param[in] domain YANG spec name
* @param[in] yspec0 Input NULL if no previous shared exist, otherwise a shared yspec but new name
* @retval yspec1 New or (previously shared)
* @retval NULL Error
* @note yspec name used by concatenating domain and a unique number.
*/
yang_stmt *
yspec_new_shared(clixon_handle h,
char *tag,
char *xpath,
char *domain,
char *name,
yang_stmt *yspec0)
{
yang_stmt *yspec1 = NULL;
cbuf *cb = NULL;
static int nr = 0;
if (yspec0 != NULL){ /* shared */
yspec1 = yspec0;
}
else {
if ((cb = cbuf_new()) == NULL){
clixon_err(OE_YANG, errno, "cbuf_new");
goto done;
}
cprintf(cb, "%s%d", domain, nr++);
if ((yspec1 = yspec_new1(h, domain, cbuf_get(cb))) == NULL)
if ((yspec1 = yspec_new1(h, domain, name)) == NULL)
goto done;
yang_flag_set(yspec1, YANG_FLAG_SPEC_MOUNT);
clixon_debug(CLIXON_DBG_YANG, "new yang-spec: %p", yspec1);
}
if (yang_cvec_add(yspec1, CGV_STRING, tag) < 0){
if (yang_cvec_add(yspec1, CGV_STRING, xpath) < 0){
yspec1 = NULL;
goto done;
}
done:
if (cb)
cbuf_free(cb);
return yspec1;
}

View file

@ -784,7 +784,9 @@ yang_schema_yanglib_parse_mount(clixon_handle h,
yang_stmt *yspec1 = NULL;
char *xpath = NULL;
char *domain = NULL;
cbuf *cb = NULL;
int ret;
static unsigned int nr = 0;
/* 1. Get modstate (xyanglib) of node: xyanglib, by querying backend state (via callback)
* XXX this xyanglib is not proper RFC8525, submodules appear as modules WHY?
@ -819,7 +821,12 @@ yang_schema_yanglib_parse_mount(clixon_handle h,
if (yang_schema_find_share(h, xt, xyanglib, &yspec0) < 0)
goto done;
}
if ((yspec1 = yspec_new_shared(h, xpath, domain, yspec0)) < 0)
if ((cb = cbuf_new()) == NULL){
clixon_err(OE_YANG, errno, "cbuf_new");
goto done;
}
cprintf(cb, "%u", nr++);
if ((yspec1 = yspec_new_shared(h, xpath, domain, cbuf_get(cb), yspec0)) < 0)
goto done;
/* Either yspec0 = NULL and yspec1 is new, or yspec0 == yspec1 != NULL (shared) */
if (yspec0 == NULL && yspec1 != NULL){
@ -835,6 +842,8 @@ yang_schema_yanglib_parse_mount(clixon_handle h,
yspec1 = NULL;
retval = 1;
done:
if (cb)
cbuf_free(cb);
if (xpath)
free(xpath);
if (yspec1)