* All yang modules are stored in the clicon_dbspec_yang() option.

* Except clixon-config module due to bug reported below
* Bug: Top-level Yang symbol cannot be called "config" in any imported yang file.
  * datastore uses "config" as reserved keyword for storing any XML whoich collides with code for detecting Yang sanit
This commit is contained in:
Olof hagsand 2018-10-19 15:26:22 +02:00
parent 7de80e9fcd
commit a4e29bcdb7
14 changed files with 151 additions and 72 deletions

View file

@ -988,7 +988,7 @@ netconf_module_load(clicon_handle h)
yspec = clicon_dbspec_yang(h);
/* Load yang spec */
if (yang_spec_parse_module(h, "ietf-netconf", CLIXON_DATADIR, NULL, yspec)< 0)
if (yang_spec_parse_module(h, "ietf-netconf", CLIXON_DATADIR, NULL, yspec, NULL)< 0)
goto done;
if ((xc = clicon_conf_xml(h)) == NULL){
clicon_err(OE_CFG, ENOENT, "Clicon configuration not loaded");

View file

@ -197,21 +197,26 @@ parse_configfile(clicon_handle h,
return retval;
}
/*! Initialize option values
/*! Parse clixon yang file. Parse XML config file. Initialize option values
*
* Set default options, Read config-file, Check that all values are set.
* Parse clixon yang file and save in yspec.
* Read clixon system config files
* @param[in] h clicon handle
* @param[in] h clicon handle
* @param[in] yspec Yang spec of clixon config file
* @note Due to Bug: Top-level Yang symbol cannot be called "config" in any
* imported yang file, the config module needs to be isolated from all
* other yang modules.
*/
int
clicon_options_main(clicon_handle h)
clicon_options_main(clicon_handle h,
yang_spec *yspec)
{
int retval = -1;
char *configfile;
clicon_hash_t *copt = clicon_options(h);
char *suffix;
char xml = 0; /* Configfile is xml, otherwise legacy */
yang_spec *yspec = NULL;
cxobj *xconfig = NULL;
/*
@ -232,9 +237,7 @@ clicon_options_main(clicon_handle h)
goto done;
}
/* Parse clixon yang spec */
if ((yspec = yspec_new()) == NULL)
goto done;
if (yang_parse(h, NULL, "clixon-config", CLIXON_DATADIR, NULL, yspec) < 0)
if (yang_parse(h, NULL, "clixon-config", CLIXON_DATADIR, NULL, yspec, NULL) < 0)
goto done;
/* Read configfile */
if (parse_configfile(h, configfile, yspec, &xconfig) < 0)
@ -249,10 +252,6 @@ clicon_options_main(clicon_handle h)
xml_child_sort = 0;
retval = 0;
done:
#if 0 /* XXX yspec should be part of top-level yang but cant since it will be main module */
if (yspec)
yspec_free(yspec);
#endif
return retval;
}

View file

@ -761,20 +761,6 @@ yang_key2str(int keyword)
return (char*)clicon_int2str(ykmap, keyword);
}
/*! Name of main module of a specification. That is, name of first module
* @param[in] ysp Yang specification
* @retval name Name of first yang module
*/
char *
yang_main_module_name(yang_spec *ysp)
{
yang_stmt *ym;
if ((ym = yang_find((yang_node*)ysp, Y_MODULE, 0)) != NULL)
return ym->ys_argument;
return NULL;
}
/*! Find top module or sub-module given a statement. Ultimate top is yang spec
* The routine recursively finds ancestors.
* @param[in] ys Any yang statement in a yang tree
@ -2109,7 +2095,8 @@ yang_features(clicon_handle h,
* @param[in] filename File name containing Yang specification. Overrides module
* @param[in] module Name of main YANG module. Or absolute file name.
* @param[in] revision Main module revision date string or NULL
* @param[out] ysp Yang specification. Should have been created by caller using yspec_new
* @param[in,out] ysp Yang specification. Should have been created by caller using yspec_new
* @param[out] ymodp Yang module of first, topmost Yang module, if given.
* @retval 0 Everything OK
* @retval -1 Error encountered
* The database symbols are inserted in alphabetical order.
@ -2130,7 +2117,8 @@ yang_parse(clicon_handle h,
const char *module,
const char *dir,
const char *revision,
yang_spec *ysp)
yang_spec *ysp,
yang_stmt **ymodp)
{
int retval = -1;
yang_stmt *ymod = NULL; /* Top-level yang (sub)module */
@ -2189,7 +2177,8 @@ yang_parse(clicon_handle h,
for (i=modnr; i<ysp->yp_len; i++)
if (yang_apply((yang_node*)ysp->yp_stmt[i], -1, ys_schemanode_check, NULL) < 0)
goto done;
if (ymodp)
*ymodp = ymod;
retval = 0;
done:
return retval;
@ -2613,6 +2602,7 @@ yang_config(yang_stmt *ys)
* @param[in] dir Directory where to look for modules and sub-modules
* @param[in] revision Revision, or NULL
* @param[in,out] yspec Modules parse are added to this yangspec
* @param[out] ymodp Yang module of first, topmost Yang module, if given.
* @retval 0 OK
* @retval -1 Error
* @see yang_spec_parse_file
@ -2622,7 +2612,8 @@ yang_spec_parse_module(clicon_handle h,
char *module,
char *dir,
char *revision,
yang_spec *yspec)
yang_spec *yspec,
yang_stmt **ymodp)
{
int retval = -1;
@ -2643,7 +2634,7 @@ yang_spec_parse_module(clicon_handle h,
clicon_err(OE_YANG, EINVAL, "yang dir not set");
goto done;
}
if (yang_parse(h, NULL, module, dir, revision, yspec) < 0)
if (yang_parse(h, NULL, module, dir, revision, yspec, ymodp) < 0)
goto done;
retval = 0;
done:
@ -2655,6 +2646,7 @@ yang_spec_parse_module(clicon_handle h,
* @param[in] filename Actual filename (including dir and revision)
* @param[in] dir Directory for sub-modules
* @param[in,out] yspec Modules parse are added to this yangspec
* @param[out] ymodp Yang module of first, topmost Yang module, if given.
* @retval 0 OK
* @retval -1 Error
* @see yang_spec_parse_module for yang dir,module,revision instead of actual filename
@ -2663,7 +2655,8 @@ int
yang_spec_parse_file(clicon_handle h,
char *filename,
char *dir,
yang_spec *yspec)
yang_spec *yspec,
yang_stmt **ymodp)
{
int retval = -1;
@ -2675,7 +2668,7 @@ yang_spec_parse_file(clicon_handle h,
clicon_err(OE_YANG, EINVAL, "yang dir not set");
goto done;
}
if (yang_parse(h, filename, NULL, dir, NULL, yspec) < 0)
if (yang_parse(h, filename, NULL, dir, NULL, yspec, ymodp) < 0)
goto done;
retval = 0;
done:

View file

@ -94,7 +94,7 @@ yang_modules_init(clicon_handle h)
goto done;
}
/* Ensure revision exists is set */
if (yang_spec_parse_module(h, "ietf-yang-library", CLIXON_DATADIR, NULL, yspec)< 0)
if (yang_spec_parse_module(h, "ietf-yang-library", CLIXON_DATADIR, NULL, yspec, NULL)< 0)
goto done;
/* Find revision */
if (yang_modules_revision(h) == NULL){