* Yang Support of submodule, include and belongs-to.
* Improved unknown handling
* Configure option `CLICON_YANG_DIR` is changed from a single directory to a path of directories
* Note CLIXON_DATADIR (=/usr/local/share/clixon) need to be in the list
This commit is contained in:
parent
56da97cb5b
commit
39a5086218
47 changed files with 977 additions and 469 deletions
|
|
@ -264,7 +264,7 @@ nacm_load_external(clicon_handle h)
|
|||
}
|
||||
if ((yspec = yspec_new()) == NULL)
|
||||
goto done;
|
||||
if (yang_parse(h, NULL, "ietf-netconf-acm", CLIXON_DATADIR, NULL, yspec, NULL) < 0)
|
||||
if (yang_parse(h, NULL, "ietf-netconf-acm", NULL, yspec, NULL) < 0)
|
||||
goto done;
|
||||
fd = fileno(f);
|
||||
/* Read configfile */
|
||||
|
|
@ -753,11 +753,10 @@ main(int argc,
|
|||
/* Load main application yang specification either module or specific file
|
||||
* If -y <file> is given, it overrides main module */
|
||||
if (yang_filename){
|
||||
if (yang_spec_parse_file(h, yang_filename, clicon_yang_dir(h), yspec, NULL) < 0)
|
||||
if (yang_spec_parse_file(h, yang_filename, yspec, NULL) < 0)
|
||||
goto done;
|
||||
}
|
||||
else if (yang_spec_parse_module(h, clicon_yang_module_main(h),
|
||||
clicon_yang_dir(h),
|
||||
clicon_yang_module_revision(h),
|
||||
yspec, NULL) < 0)
|
||||
goto done;
|
||||
|
|
@ -770,11 +769,11 @@ main(int argc,
|
|||
goto done;
|
||||
/* Load yang Restconf stream discovery */
|
||||
if (clicon_option_bool(h, "CLICON_STREAM_DISCOVERY_RFC8040") &&
|
||||
yang_spec_parse_module(h, "ietf-restconf-monitoring", CLIXON_DATADIR, NULL, yspec, NULL)< 0)
|
||||
yang_spec_parse_module(h, "ietf-restconf-monitoring", NULL, yspec, NULL)< 0)
|
||||
goto done;
|
||||
/* Load yang Netconf stream discovery */
|
||||
if (clicon_option_bool(h, "CLICON_STREAM_DISCOVERY_RFC5277") &&
|
||||
yang_spec_parse_module(h, "ietf-netconf-notification", CLIXON_DATADIR, NULL, yspec, NULL)< 0)
|
||||
yang_spec_parse_module(h, "ietf-netconf-notification", NULL, yspec, NULL)< 0)
|
||||
goto done;
|
||||
/* Set options: database dir and yangspec (could be hidden in connect?)*/
|
||||
if (xmldb_setopt(h, "dbdir", clicon_xmldb_dir(h)) < 0)
|
||||
|
|
|
|||
|
|
@ -51,7 +51,7 @@
|
|||
#include <assert.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/param.h>
|
||||
|
||||
#include <math.h> /* For pow() kludge in cvtype_max2str_dup2 */
|
||||
|
||||
/* cligen */
|
||||
#include <cligen/cligen.h>
|
||||
|
|
@ -169,6 +169,28 @@ static int yang2cli_stmt(clicon_handle h, yang_stmt *ys, cbuf *cb,
|
|||
static int yang2cli_var_union(clicon_handle h, yang_stmt *ys, char *origtype,
|
||||
yang_stmt *ytype, cbuf *cb, char *helptext);
|
||||
|
||||
/*! Patched maxstring to account for DEC64 types
|
||||
* @note kludge to fix overflow error -> Fix the original error in cvtype_max2str
|
||||
* by adding a fraction_digits argument.
|
||||
*/
|
||||
static char *
|
||||
cvtype_max2str_dup2(enum cv_type type,
|
||||
int fraction_digits)
|
||||
{
|
||||
int len;
|
||||
char *str;
|
||||
|
||||
if (type!=CGV_DEC64 || fraction_digits==0)
|
||||
return cvtype_max2str_dup(type);
|
||||
if ((len = cvtype_max2str(type, NULL, 0)) < 0)
|
||||
return NULL;
|
||||
if ((str = (char *)malloc(len+1)) == NULL)
|
||||
return NULL;
|
||||
memset(str, '\0', len+1);
|
||||
len = snprintf(str, len+1, "%" PRId64 ".0", (INT64_MAX/((int)pow(10,fraction_digits))));
|
||||
return str;
|
||||
}
|
||||
|
||||
/*! Generate CLI code for Yang leaf statement to CLIgen variable of specific type
|
||||
* Check for completion (of already existent values), ranges (eg range[min:max]) and
|
||||
* patterns, (eg regexp:"[0.9]*").
|
||||
|
|
@ -282,10 +304,12 @@ yang2cli_var_sub(clicon_handle h,
|
|||
}
|
||||
snprintf(r, 512, "%d", MAXPATHLEN);
|
||||
}
|
||||
else if ((r = cvtype_max2str_dup(cvtype)) == NULL){
|
||||
else {
|
||||
if ((r = cvtype_max2str_dup2(cvtype, fraction_digits)) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "cvtype_max2str");
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
}
|
||||
cprintf(cb, "%s]", r); /* range */
|
||||
free(r);
|
||||
|
|
@ -410,7 +434,7 @@ yang2cli_var(clicon_handle h,
|
|||
cbuf *cb,
|
||||
char *helptext)
|
||||
{
|
||||
int retval = -1;
|
||||
int retval = -1;
|
||||
char *origtype;
|
||||
yang_stmt *yrestype; /* resolved type */
|
||||
char *restype; /* resolved type */
|
||||
|
|
@ -513,10 +537,12 @@ yang2cli_leaf(clicon_handle h,
|
|||
if (helptext)
|
||||
cprintf(cbuf, "(\"%s\")", helptext);
|
||||
cprintf(cbuf, " ");
|
||||
yang2cli_var(h, ys, cbuf, helptext);
|
||||
if (yang2cli_var(h, ys, cbuf, helptext) < 0)
|
||||
goto done;
|
||||
}
|
||||
else
|
||||
yang2cli_var(h, ys, cbuf, helptext);
|
||||
if (yang2cli_var(h, ys, cbuf, helptext) < 0)
|
||||
goto done;
|
||||
if (callback){
|
||||
if (cli_callback_generate(h, ys, cbuf) < 0)
|
||||
goto done;
|
||||
|
|
|
|||
|
|
@ -433,11 +433,10 @@ main(int argc, char **argv)
|
|||
/* Load main application yang specification either module or specific file
|
||||
* If -y <file> is given, it overrides main module */
|
||||
if (yang_filename){
|
||||
if (yang_spec_parse_file(h, yang_filename, clicon_yang_dir(h), yspec, &ymod) < 0)
|
||||
if (yang_spec_parse_file(h, yang_filename, yspec, &ymod) < 0)
|
||||
goto done;
|
||||
}
|
||||
else if (yang_spec_parse_module(h, clicon_yang_module_main(h),
|
||||
clicon_yang_dir(h),
|
||||
clicon_yang_module_revision(h),
|
||||
yspec, &ymod) < 0)
|
||||
goto done;
|
||||
|
|
|
|||
|
|
@ -447,11 +447,10 @@ main(int argc,
|
|||
/* Load main application yang specification either module or specific file
|
||||
* If -y <file> is given, it overrides main module */
|
||||
if (yang_filename){
|
||||
if (yang_spec_parse_file(h, yang_filename, clicon_yang_dir(h), yspec, NULL) < 0)
|
||||
if (yang_spec_parse_file(h, yang_filename, yspec, NULL) < 0)
|
||||
goto done;
|
||||
}
|
||||
else if (yang_spec_parse_module(h, clicon_yang_module_main(h),
|
||||
clicon_yang_dir(h),
|
||||
clicon_yang_module_revision(h),
|
||||
yspec, NULL) < 0)
|
||||
goto done;
|
||||
|
|
|
|||
|
|
@ -32,7 +32,13 @@
|
|||
***** END LICENSE BLOCK *****
|
||||
|
||||
*
|
||||
* Code for handling netconf rpc messages according to RFC 4741 and RFC 5277
|
||||
* Code for handling netconf rpc messages according to RFC 4741,5277,6241
|
||||
* All NETCONF protocol elements are defined in the following namespace:
|
||||
* urn:ietf:params:xml:ns:netconf:base:1.0
|
||||
* YANG defines an XML namespace for NETCONF <edit-config> operations,
|
||||
* <error-info> content, and the <action> element. The name of this
|
||||
* namespace is "urn:ietf:params:xml:ns:yang:1".
|
||||
*
|
||||
*****************************************************************************/
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "clixon_config.h" /* generated by config & autoconf */
|
||||
|
|
@ -894,7 +900,7 @@ netconf_application_rpc(clicon_handle h,
|
|||
}
|
||||
cprintf(cb, "/%s:%s", xml_namespace(xn), xml_name(xn));
|
||||
/* Find yang rpc statement, return yang rpc statement if found */
|
||||
if (yang_abs_schema_nodeid(yspec, cbuf_get(cb), Y_RPC, &yrpc) < 0)
|
||||
if (yang_abs_schema_nodeid(yspec, xml_spec(xn), cbuf_get(cb), Y_RPC, &yrpc) < 0)
|
||||
goto done;
|
||||
/* Check if found */
|
||||
if (yrpc != NULL){
|
||||
|
|
|
|||
|
|
@ -517,7 +517,6 @@ main(int argc,
|
|||
char *sockpath;
|
||||
char *path;
|
||||
clicon_handle h;
|
||||
char *yangspec=NULL;
|
||||
char *dir;
|
||||
char *tmp;
|
||||
int logdst = CLICON_LOG_SYSLOG;
|
||||
|
|
@ -619,10 +618,6 @@ main(int argc,
|
|||
argc -= optind;
|
||||
argv += optind;
|
||||
|
||||
/* Overwrite yang module with -y option */
|
||||
if (yangspec)
|
||||
clicon_option_str_set(h, "CLICON_YANG_MODULE_MAIN", yangspec);
|
||||
|
||||
/* Initialize plugins group */
|
||||
if ((dir = clicon_restconf_dir(h)) != NULL)
|
||||
if (clixon_plugins_load(h, CLIXON_PLUGIN_INIT, dir, NULL) < 0)
|
||||
|
|
@ -635,12 +630,11 @@ main(int argc,
|
|||
/* Load main application yang specification either module or specific file
|
||||
* If -y <file> is given, it overrides main module */
|
||||
if (yang_filename){
|
||||
if (yang_spec_parse_file(h, yang_filename, clicon_yang_dir(h), yspec, NULL) < 0)
|
||||
if (yang_spec_parse_file(h, yang_filename, yspec, NULL) < 0)
|
||||
goto done;
|
||||
}
|
||||
else if (yang_spec_parse_module(h, clicon_yang_module_main(h),
|
||||
clicon_yang_dir(h),
|
||||
clicon_yang_module_revision(h),
|
||||
clicon_yang_module_revision(h),
|
||||
yspec, NULL) < 0)
|
||||
goto done;
|
||||
|
||||
|
|
@ -649,10 +643,10 @@ main(int argc,
|
|||
goto done;
|
||||
/* Add system modules */
|
||||
if (clicon_option_bool(h, "CLICON_STREAM_DISCOVERY_RFC8040") &&
|
||||
yang_spec_parse_module(h, "ietf-restconf-monitoring", CLIXON_DATADIR, NULL, yspec, NULL)< 0)
|
||||
yang_spec_parse_module(h, "ietf-restconf-monitoring", NULL, yspec, NULL)< 0)
|
||||
goto done;
|
||||
if (clicon_option_bool(h, "CLICON_STREAM_DISCOVERY_RFC5277") &&
|
||||
yang_spec_parse_module(h, "ietf-netconf-notification", CLIXON_DATADIR, NULL, yspec, NULL)< 0)
|
||||
yang_spec_parse_module(h, "ietf-netconf-notification", NULL, yspec, NULL)< 0)
|
||||
goto done;
|
||||
/* Call start function in all plugins before we go interactive
|
||||
Pass all args after the standard options to plugin_start
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue