diff --git a/apps/backend/backend_main.c b/apps/backend/backend_main.c index e0d70a2c..23017ff5 100644 --- a/apps/backend/backend_main.c +++ b/apps/backend/backend_main.c @@ -111,6 +111,8 @@ backend_terminate(clicon_handle h) yspec_free(yspec); if ((yspec = clicon_config_yang(h)) != NULL) yspec_free(yspec); + if ((yspec = clicon_nacm_ext_yang(h)) != NULL) + yspec_free(yspec); if ((nsctx = clicon_nsctx_global_get(h)) != NULL) cvec_free(nsctx); if ((x = clicon_nacm_ext(h)) != NULL) @@ -212,12 +214,13 @@ nacm_load_external(clicon_handle h) clicon_err(OE_XML, 0, "No xml tree in %s", filename); goto done; } + if (clicon_nacm_ext_yang_set(h, yspec) < 0) + goto done; if (clicon_nacm_ext_set(h, xt) < 0) goto done; + retval = 0; done: - // XXX if (yspec) /* The clixon yang-spec is not used after this */ - // XXX yspec_free(yspec); if (f) fclose(f); return retval; diff --git a/lib/clixon/clixon_data.h b/lib/clixon/clixon_data.h index 961ac7aa..a541beac 100644 --- a/lib/clixon/clixon_data.h +++ b/lib/clixon/clixon_data.h @@ -58,6 +58,9 @@ int clicon_dbspec_yang_set(clicon_handle h, yang_stmt *ys); yang_stmt * clicon_config_yang(clicon_handle h); int clicon_config_yang_set(clicon_handle h, yang_stmt *ys); +yang_stmt * clicon_nacm_ext_yang(clicon_handle h); +int clicon_nacm_ext_yang_set(clicon_handle h, yang_stmt *ys); + cvec *clicon_nsctx_global_get(clicon_handle h); int clicon_nsctx_global_set(clicon_handle h, cvec *nsctx); diff --git a/lib/src/clixon_data.c b/lib/src/clixon_data.c index 45e5bc46..2e11bd2b 100644 --- a/lib/src/clixon_data.c +++ b/lib/src/clixon_data.c @@ -146,6 +146,42 @@ clicon_config_yang_set(clicon_handle h, return 0; } +/*! Get YANG specification for external NACM (separate from application yangs) + * @param[in] h Clicon handle + * @retval yspec Yang spec + * @see clicon_nacm_ext for external NACM XML + */ +yang_stmt * +clicon_nacm_ext_yang(clicon_handle h) +{ + clicon_hash_t *cdat = clicon_data(h); + size_t len; + void *p; + + if ((p = clicon_hash_value(cdat, "nacm_ext_yang", &len)) != NULL) + return *(yang_stmt **)p; + return NULL; +} + +/*! Set yang specification for external NACM + * @param[in] h Clicon handle + * @param[in] yspec Yang spec (malloced pointer) + * @see clicon_nacm_ext_set for external NACM XML + */ +int +clicon_nacm_ext_yang_set(clicon_handle h, + yang_stmt *ys) +{ + clicon_hash_t *cdat = clicon_data(h); + + /* It is the pointer to ys that should be copied by hash, + so we send a ptr to the ptr to indicate what to copy. + */ + if (clicon_hash_add(cdat, "nacm_ext_yang", &ys, sizeof(ys)) == NULL) + return -1; + return 0; +} + /*! Get Global "canonical" namespace context * Canonical: use prefix and namespace specified in the yang modules. * @param[in] h Clicon handle