* 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:
parent
7de80e9fcd
commit
a4e29bcdb7
14 changed files with 151 additions and 72 deletions
|
|
@ -81,7 +81,8 @@ enum startup_mode_t{
|
|||
/* Print registry on file. For debugging. */
|
||||
void clicon_option_dump(clicon_handle h, int dblevel);
|
||||
/* Initialize options: set defaults, read config-file, etc */
|
||||
int clicon_options_main(clicon_handle h);
|
||||
int clicon_options_main(clicon_handle h, yang_spec *yspec);
|
||||
|
||||
/*! Check if a clicon option has a value */
|
||||
int clicon_option_exists(clicon_handle h, const char *name);
|
||||
|
||||
|
|
|
|||
|
|
@ -245,7 +245,6 @@ yang_stmt *ys_dup(yang_stmt *old);
|
|||
int yn_insert(yang_node *yn_parent, yang_stmt *ys_child);
|
||||
yang_stmt *yn_each(yang_node *yn, yang_stmt *ys);
|
||||
char *yang_key2str(int keyword);
|
||||
char *yang_main_module_name(yang_spec *ysp);
|
||||
char *yarg_prefix(yang_stmt *ys);
|
||||
char *yarg_id(yang_stmt *ys);
|
||||
int yang_nodeid_split(char *nodeid, char **prefix, char **id);
|
||||
|
|
@ -264,7 +263,7 @@ int ys_populate(yang_stmt *ys, void *arg);
|
|||
yang_stmt *yang_parse_file(int fd, const char *name, yang_spec *ysp);
|
||||
int yang_parse(clicon_handle h, const char *filename,
|
||||
const char *module, const char *dir,
|
||||
const char *revision, yang_spec *ysp);
|
||||
const char *revision, yang_spec *ysp, yang_stmt **ymodp);
|
||||
int yang_apply(yang_node *yn, enum rfc_6020 key, yang_applyfn_t fn,
|
||||
void *arg);
|
||||
int yang_abs_schema_nodeid(yang_spec *yspec, char *schema_nodeid,
|
||||
|
|
@ -275,8 +274,8 @@ cg_var *ys_parse(yang_stmt *ys, enum cv_type cvtype);
|
|||
int ys_parse_sub(yang_stmt *ys, char *extra);
|
||||
int yang_mandatory(yang_stmt *ys);
|
||||
int yang_config(yang_stmt *ys);
|
||||
int yang_spec_parse_module(clicon_handle h, char *module, char *dir, char *revision, yang_spec *yspec);
|
||||
int yang_spec_parse_file(clicon_handle h, char *filename, char *dir, yang_spec *yspec);
|
||||
int yang_spec_parse_module(clicon_handle h, char *module, char *dir, char *revision, yang_spec *yspec, yang_stmt **ymodp);
|
||||
int yang_spec_parse_file(clicon_handle h, char *filename, char *dir, yang_spec *yspec, yang_stmt **ymodp);
|
||||
cvec *yang_arg2cvec(yang_stmt *ys, char *delimi);
|
||||
int yang_key_match(yang_node *yn, char *name);
|
||||
|
||||
|
|
|
|||
|
|
@ -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");
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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:
|
||||
|
|
|
|||
|
|
@ -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){
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue