- Modified linkage constant in makefile to test for dynamic only

- CLIXON_STATIC_PLUGIN to support statically linked plugins
- Added -H option to clixon_netconf: Do not require hello before request
This commit is contained in:
Olof hagsand 2021-09-25 16:25:41 +02:00
parent b70e22096e
commit c00162aec1
16 changed files with 121 additions and 61 deletions

View file

@ -46,7 +46,7 @@ endif
SH_SUFFIX = @SH_SUFFIX@
INSTALLFLAGS = @INSTALLFLAGS@
LDFLAGS = @LDFLAGS@
ifeq ($(LINKAGE),static)
ifneq ($(LINKAGE),dynamic)
LDFLAGS += -rdynamic -L.
endif
@ -66,10 +66,10 @@ CLIXON_MAJOR = @CLIXON_VERSION_MAJOR@
CLIXON_MINOR = @CLIXON_VERSION_MINOR@
# Use this clixon lib for linking
ifeq ($(LINKAGE),static)
CLIXON_LIB = libclixon.a
else
ifeq ($(LINKAGE),dynamic)
CLIXON_LIB = libclixon$(SH_SUFFIX).$(CLIXON_MAJOR).$(CLIXON_MINOR)
else
CLIXON_LIB = libclixon.a
endif
# For dependency. A little strange that we rely on it being built in the src dir
@ -87,6 +87,10 @@ APPL = clixon_cli
APPSRC = cli_main.c
APPOBJ = $(APPSRC:.c=.o)
# HACK
#EXTRAS += $(top_srcdir)/example/main/example_cli.o
#EXTRAS += $(top_srcdir)/example/main/test_cli.o
# Accessible from plugin
LIBSRC = cli_common.c
LIBSRC += cli_show.c
@ -165,7 +169,7 @@ $(APPL): $(APPOBJ) $(MYLIB) $(LIBDEPS)
ifeq ($(LINKAGE),dynamic)
$(CC) $(LDFLAGS) $(APPOBJ) -L. $(MYLIB) $(LIBS) -o $@
else
$(CC) $(LDFLAGS) $(APPOBJ) -L. $(LIBOBJ) $(LIBS) -o $@
$(CC) $(LDFLAGS) $(APPOBJ) $(EXTRAS) -L. $(LIBOBJ) $(LIBS) -o $@
endif
$(MYLIBDYNAMIC) : $(LIBOBJ) $(LIBDEPS)

View file

@ -412,7 +412,6 @@ main(int argc,
struct passwd *pw;
char *str;
int tabmode;
char *dir;
cvec *nsctx_global = NULL; /* Global namespace context */
size_t cligen_buflen;
size_t cligen_bufthreshold;
@ -623,11 +622,17 @@ main(int argc,
if (clixon_plugin_module_init(h) < 0)
goto done;
/* Load cli plugins before yangs are loaded (eg extension callbacks) */
if ((dir = clicon_cli_dir(h)) != NULL &&
clixon_plugins_load(h, CLIXON_PLUGIN_INIT, dir, NULL) < 0)
goto done;
#ifndef CLIXON_STATIC_PLUGINS
{
char *dir;
/* Load cli .so plugins before yangs are loaded (eg extension callbacks) and
* before CLI is loaded by cli_syntax_load below */
if ((dir = clicon_cli_dir(h)) != NULL &&
clixon_plugins_load(h, CLIXON_PLUGIN_INIT, dir, NULL) < 0)
goto done;
}
#endif
/* Add (hardcoded) netconf features in case ietf-netconf loaded here
* Otherwise it is loaded in netconf_module_load below
*/
@ -685,7 +690,8 @@ main(int argc,
if (autocli_start(h, printgen) < 0)
goto done;
/* Initialize cli syntax */
/* Initialize cli syntax.
* Plugins have already been loaded by clixon_plugins_load above */
if (cli_syntax_load(h) < 0)
goto done;

View file

@ -249,10 +249,16 @@ clixon_str2fn(char *name,
}
/*! Load a file containing syntax and append to specified modes, also load C plugin
*
* First load CLIgen file,
* Then find which .so to load by looking in the "CLICON_PLUGIN" variable in that file.
* Make a lookup of plugins already loaded and resolve callbacks from cligen trees to
* dl symbols in the plugin.
* @param[in] h Clixon handle
* @param[in] filename Name of file where syntax is specified (in syntax-group dir)
* @param[in] dir Name of dir, or NULL
* @param[out] ptall Universal CLIgen parse tree: apply to all modes
* @see clixon_plugins_load Where .so plugin code has been loaded prior to this
*/
static int
cli_load_syntax_file(clicon_handle h,
@ -271,7 +277,9 @@ cli_load_syntax_file(clicon_handle h,
char **vec = NULL;
int i, nvec;
char *plgnam;
#ifndef CLIXON_STATIC_PLUGINS
clixon_plugin_t *cp;
#endif
if ((pt = pt_new()) == NULL){
clicon_err(OE_UNIX, errno, "pt_new");
@ -311,6 +319,7 @@ cli_load_syntax_file(clicon_handle h,
prompt = cvec_find_str(cvv, "CLICON_PROMPT");
plgnam = cvec_find_str(cvv, "CLICON_PLUGIN");
#ifndef CLIXON_STATIC_PLUGINS
if (plgnam != NULL) { /* Find plugin for callback resolving */
if ((cp = clixon_plugin_find(h, plgnam)) != NULL)
handle = clixon_plugin_handle_get(cp);
@ -321,6 +330,7 @@ cli_load_syntax_file(clicon_handle h,
goto done;
}
}
#endif
/* Resolve callback names to function pointers. */
if (cligen_callbackv_str2fn(pt, (cgv_str2fn_t*)clixon_str2fn, handle) < 0){
clicon_err(OE_PLUGIN, 0, "Mismatch between CLIgen file '%s' and CLI plugin file '%s'. Some possible errors:\n\t1. A function given in the CLIgen file does not exist in the plugin (ie link error)\n\t2. The CLIgen spec does not point to the correct plugin .so file (CLICON_PLUGIN=\"%s\" is wrong)",
@ -346,7 +356,7 @@ cli_load_syntax_file(clicon_handle h,
goto done;
if (nvec == 1 && strcmp(vec[0], "*") == 0){
/* Special case: Add this to all modes. Add to special "universal" syntax
/* Special case: Add this to all modes. Add to special "universal" syntax
* and add to all syntaxes after all files have been loaded. At this point
* all modes may not be known (not yet loaded)
*/
@ -377,7 +387,10 @@ done:
return retval;
}
/*! Load a syntax group. Includes both CLI plugin and CLIgen spec syntax files.
/*! CLIgen spec syntax files and create CLIgen trees to drive the CLI syntax generator
*
* CLI .so plugins have been loaded: syntax table in place.
* Now load cligen syntax files and create cligen pt trees.
* @param[in] h Clicon handle
*/
int