diff --git a/CHANGELOG.md b/CHANGELOG.md index 7083ab4c..afa71d0e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -72,8 +72,9 @@ Users may have to change how they access the system ### Minor features +* Restconf: added inline configuration using `-R ` command line as an alternative to making advanced restconf configuration * [Need an option to disable restconf mandatory action of overwriting startup_db #230](https://github.com/clicon/clixon/issues/230) - * Disable RFC 8040 mandatory copy of running to startup after commit + * Configure option `CLICON_RESTCONF_STARTUP_DONTUPDATE` added to disable RFC 8040 mandatory copy of running to startup after commit * Add default network namespace constant: `RESTCONF_NETNS_DEFAULT` with default value "default". * CLI: Two new hide variables added (thanks: shmuelnatan) * hide-database : specifies that a command is not visible in database. This can be useful for setting passwords and not exposing them to users. diff --git a/apps/backend/backend_plugin_restconf.c b/apps/backend/backend_plugin_restconf.c index 9b064256..084d6c9c 100644 --- a/apps/backend/backend_plugin_restconf.c +++ b/apps/backend/backend_plugin_restconf.c @@ -61,10 +61,11 @@ #define RESTCONF_PROCESS "restconf" -/*! Set current debug flag when starting process using -D +/*! Set current debug and log flags when starting process using -D -l * - * process argv list including -D is set on start. But the debug flags may change and this is a way - * to set it dynamically, ie at the time the process is started, not when the backend is started. + * process argv list including -D and -l are set on start. But the debug/log flags may change and + * this is a way to set it dynamically, ie at the time the process is started, not when the backend + * is started. * @param[in] h Clixon backend * @param[in] xt XML target */ @@ -129,6 +130,57 @@ restconf_pseudo_set_log(clicon_handle h, return retval; } +/*! Set current restconf inline config when starting process using -R + * + * process argv list including -R is set on start. Get the running restconfig config, stringify it + * and insert it as a optimization to reading it from the backend. + * @param[in] h Clixon backend + * @param[in] xt XML target + */ +static int +restconf_pseudo_set_inline(clicon_handle h, + cxobj *xt) +{ + int retval = -1; + char **argv; + int argc; + int i; + char *str = NULL; + cxobj *xrestconf; + cbuf *cb = NULL; + + clicon_debug(1, "%s", __FUNCTION__); + if (clixon_process_argv_get(h, RESTCONF_PROCESS, &argv, &argc) < 0) + goto done; + if ((xrestconf = xpath_first(xt, NULL, "restconf")) != NULL) + for (i=0; i i+1 && argv[i+1]){ + if ((cb = cbuf_new()) == NULL){ + clicon_err(OE_XML, errno, "cbuf_new"); + goto done; + } + if (clicon_xml2cbuf(cb, xrestconf, 0, 0, -1) < 0) + goto done; + if ((str = strdup(cbuf_get(cb))) == NULL){ + clicon_err(OE_XML, errno, "stdup"); + goto done; + } + clicon_debug(1, "%s str:%s", __FUNCTION__, str); + if (argv[i+1]) + free(argv[i+1]); + argv[i+1] = str; + break; + } + } + retval = 0; + done: + if (cb) + cbuf_free(cb); + return retval; +} + /*! Process rpc callback function * - if RPC op is start, if enable is true, start the service, if false, error or ignore it * - if RPC op is stop, stop the service @@ -164,6 +216,8 @@ restconf_rpc_wrapper(clicon_handle h, */ if (restconf_pseudo_set_log(h, xt) < 0) goto done; + if (restconf_pseudo_set_inline(h, xt) < 0) + goto done; } break; default: @@ -192,7 +246,7 @@ restconf_pseudo_process_control(clicon_handle h) int nr; cbuf *cb = NULL; - nr = 8; + nr = 10; if ((argv = calloc(nr, sizeof(char *))) == NULL){ clicon_err(OE_UNIX, errno, "calloc"); goto done; @@ -216,9 +270,11 @@ restconf_pseudo_process_control(clicon_handle h) * see restconf_pseudo_set_log which sets flag when process starts */ argv[i++] = "-D"; - argv[i++] = "0"; + argv[i++] = strdup("0"); argv[i++] = "-l"; - argv[i++] = "s"; /* There is also log-destination in clixon-restconf.yang */ + argv[i++] = strdup("s"); /* There is also log-destination in clixon-restconf.yang */ + argv[i++] = "-R"; + argv[i++] = strdup(""); argv[i++] = NULL; assert(i==nr); if (clixon_process_register(h, RESTCONF_PROCESS, @@ -289,6 +345,8 @@ restconf_pseudo_process_commit(clicon_handle h, */ if (restconf_pseudo_set_log(h, xtarget) < 0) goto done; + if (restconf_pseudo_set_inline(h, xtarget) < 0) + goto done; /* Toggle start/stop if enable flag changed */ if ((cx = xpath_first(xtarget, NULL, "/restconf/enable")) != NULL && xml_flag(cx, XML_FLAG_CHANGE|XML_FLAG_ADD)){ diff --git a/apps/restconf/restconf_main_fcgi.c b/apps/restconf/restconf_main_fcgi.c index 6e1d93bf..dae155b6 100644 --- a/apps/restconf/restconf_main_fcgi.c +++ b/apps/restconf/restconf_main_fcgi.c @@ -88,7 +88,7 @@ #include "restconf_stream.h" /* Command line options to be passed to getopt(3) */ -#define RESTCONF_OPTS "hD:f:E:l:p:d:y:a:u:rW:o:" +#define RESTCONF_OPTS "hD:f:E:l:p:d:y:a:u:rW:R:o:" /*! Convert FCGI parameters to clixon runtime data * @param[in] h Clixon handle @@ -177,7 +177,6 @@ restconf_sig_child(int arg) static void usage(clicon_handle h, char *argv0) - { fprintf(stderr, "usage:%s [options]\n" "where options are\n" @@ -192,7 +191,8 @@ usage(clicon_handle h, "\t-u \t Internal socket domain path or IP addr (see -a)\n" "\t-r \t\t Do not drop privileges if run as root\n" - "\t-W \tRun restconf daemon as this user, drop according to CLICON_RESTCONF_PRIVILEGES\n" + "\t-W \t Run restconf daemon as this user, drop according to CLICON_RESTCONF_PRIVILEGES\n" + "\t-R \t Restconf configuration in-line overriding config file\n" "\t-o \"