Plugin infrastructure improvements
This patch replaces requirement for vlib_plugin_register function
in the plugin so file and introduces new macro:
VLIB_PLUGIN_REGISTER () = {
.version = "version string",
.version_required = "requred version",
.default_disabled = 1,
.early_init = "early_init_function_name",
};
Plugin will nor be loaded if .default_disabled is set to 1
unless explicitely enabled in startup.conf.
If .verstion_required is set, plugin will not be loaded if there
is version mismatch between plugin and vpp. This can be bypassed
by setting "skip-version-check" for specific plugin.
If .early-init string is present, plugin loader will try to resolve
this specific symbol in the plugin namespace and make a function call.
Following startup.conf configuration is added:
plugins {
path /path/to/plugin/directory
plugin ila_plugin.so { enable skip-version-check }
plugin acl_plugin.so { disable }
}
Change-Id: I706c691dd34d94ffe9e02b59831af8859a95f061
Signed-off-by: Damjan Marion <damarion@cisco.com>
diff --git a/src/plugins/acl/acl.c b/src/plugins/acl/acl.c
index f4db201..85c9113 100644
--- a/src/plugins/acl/acl.c
+++ b/src/plugins/acl/acl.c
@@ -22,6 +22,7 @@
#include <vnet/l2/l2_classify.h>
#include <vnet/classify/input_acl.h>
+#include <vpp/app/version.h>
#include <vlibapi/api.h>
#include <vlibmemory/api.h>
@@ -128,29 +129,11 @@
_(MACIP_ACL_DUMP, macip_acl_dump) \
_(MACIP_ACL_INTERFACE_GET, macip_acl_interface_get)
-/*
- * This routine exists to convince the vlib plugin framework that
- * we haven't accidentally copied a random .dll into the plugin directory.
- *
- * Also collects global variable pointers passed from the vpp engine
- */
-
-clib_error_t *
-vlib_plugin_register (vlib_main_t * vm, vnet_plugin_handoff_t * h,
- int from_early_init)
-{
- acl_main_t *am = &acl_main;
- clib_error_t *error = 0;
-
- am->vlib_main = vm;
- am->vnet_main = h->vnet_main;
- am->ethernet_main = h->ethernet_main;
-
- l2sess_vlib_plugin_register(vm, h, from_early_init);
-
- return error;
-}
-
+/* *INDENT-OFF* */
+VLIB_PLUGIN_REGISTER () = {
+ .version = VPP_BUILD_VER,
+};
+/* *INDENT-ON* */
static void
vl_api_acl_plugin_get_version_t_handler (vl_api_acl_plugin_get_version_t * mp)
diff --git a/src/plugins/acl/acl.h b/src/plugins/acl/acl.h
index afc9b28..6204678 100644
--- a/src/plugins/acl/acl.h
+++ b/src/plugins/acl/acl.h
@@ -17,7 +17,6 @@
#include <vnet/vnet.h>
#include <vnet/ip/ip.h>
-#include <vnet/ethernet/ethernet.h>
#include <vnet/l2/l2_output.h>
@@ -139,7 +138,6 @@
/* convenience */
vlib_main_t * vlib_main;
vnet_main_t * vnet_main;
- ethernet_main_t * ethernet_main;
} acl_main_t;
extern acl_main_t acl_main;
diff --git a/src/plugins/acl/l2sess.c b/src/plugins/acl/l2sess.c
index cc9bde4..b0385be 100644
--- a/src/plugins/acl/l2sess.c
+++ b/src/plugins/acl/l2sess.c
@@ -31,19 +31,6 @@
#include <vnet/l2/l2_input.h>
void
-l2sess_vlib_plugin_register (vlib_main_t * vm, void* hh,
- int from_early_init)
-{
- l2sess_main_t *sm = &l2sess_main;
- vnet_plugin_handoff_t * h = hh;
- memset (sm, 0, sizeof (*sm));
-
- sm->vlib_main = vm;
- sm->vnet_main = h->vnet_main;
- sm->ethernet_main = h->ethernet_main;
-}
-
-void
l2sess_init_next_features_input (vlib_main_t * vm, l2sess_main_t * sm)
{
#define _(node_name, node_var, is_out, is_ip6, is_track) \
diff --git a/src/plugins/acl/l2sess.h b/src/plugins/acl/l2sess.h
index db89991..888b530 100644
--- a/src/plugins/acl/l2sess.h
+++ b/src/plugins/acl/l2sess.h
@@ -132,7 +132,6 @@
/* convenience */
vlib_main_t * vlib_main;
vnet_main_t * vnet_main;
- ethernet_main_t * ethernet_main;
/* Counter(s) */
u64 counter_attempted_delete_free_session;
diff --git a/src/plugins/flowperpkt/flowperpkt.c b/src/plugins/flowperpkt/flowperpkt.c
index cc35159..6b292ee 100644
--- a/src/plugins/flowperpkt/flowperpkt.c
+++ b/src/plugins/flowperpkt/flowperpkt.c
@@ -24,6 +24,7 @@
*/
#include <vnet/vnet.h>
+#include <vpp/app/version.h>
#include <vnet/plugin/plugin.h>
#include <flowperpkt/flowperpkt.h>
@@ -479,30 +480,11 @@
#define foreach_flowperpkt_plugin_api_msg \
_(FLOWPERPKT_TX_INTERFACE_ADD_DEL, flowperpkt_tx_interface_add_del)
-/**
- * @brief plugin-api required function
- * @param vm vlib_main_t * vlib main data structure pointer
- * @param h vlib_plugin_handoff_t * handoff structure
- * @param from_early_init int notused
- *
- * <em>Notes:</em>
- * This routine exists to convince the vlib plugin framework that
- * we haven't accidentally copied a random .dll into the plugin directory.
- *
- * Also collects global variable pointers passed from the vpp engine
- */
-clib_error_t *
-vlib_plugin_register (vlib_main_t * vm, vnet_plugin_handoff_t * h,
- int from_early_init)
-{
- flowperpkt_main_t *fm = &flowperpkt_main;
- clib_error_t *error = 0;
-
- fm->vlib_main = vm;
- fm->vnet_main = h->vnet_main;
-
- return error;
-}
+/* *INDENT-OFF* */
+VLIB_PLUGIN_REGISTER () = {
+ .version = VPP_BUILD_VER,
+};
+/* *INDENT-ON* */
static clib_error_t *
flowperpkt_tx_interface_add_del_feature_command_fn (vlib_main_t * vm,
@@ -627,6 +609,8 @@
u32 num_threads;
u8 *name;
+ fm->vnet_main = vnet_get_main ();
+
/* Construct the API name */
name = format (0, "flowperpkt_%08x%c", api_version, 0);
diff --git a/src/plugins/ila/ila.c b/src/plugins/ila/ila.c
index 336f4cf..e0f3907 100644
--- a/src/plugins/ila/ila.c
+++ b/src/plugins/ila/ila.c
@@ -18,6 +18,7 @@
#include <vnet/ip/lookup.h>
#include <vnet/dpo/dpo.h>
#include <vnet/fib/fib_table.h>
+#include <vpp/app/version.h>
static ila_main_t ila_main;
@@ -821,14 +822,11 @@
return 0;
}
-clib_error_t *
-vlib_plugin_register (vlib_main_t * vm, vnet_plugin_handoff_t * h,
- int from_early_init)
-{
- clib_error_t *error = 0;
-
- return error;
-}
+/* *INDENT-OFF* */
+VLIB_PLUGIN_REGISTER () = {
+ .version = VPP_BUILD_VER,
+};
+/* *INDENT-ON* */
u8 *format_ila_dpo (u8 * s, va_list * va)
{
diff --git a/src/plugins/ioam/encap/ip6_ioam_trace.c b/src/plugins/ioam/encap/ip6_ioam_trace.c
index 3a6758c..a836dfe 100644
--- a/src/plugins/ioam/encap/ip6_ioam_trace.c
+++ b/src/plugins/ioam/encap/ip6_ioam_trace.c
@@ -16,6 +16,7 @@
#include <vnet/vnet.h>
#include <vnet/pg/pg.h>
#include <vppinfra/error.h>
+#include <vpp/app/version.h>
#include <vnet/ip/ip6.h>
#include <vnet/ip/ip6_hop_by_hop.h>
@@ -349,18 +350,11 @@
};
/* *INDENT-ON* */
-/*
- * This routine exists to convince the vlib plugin framework that
- * we haven't accidentally copied a random .dll into the plugin directory.
- *
- * Also collects global variable pointers passed from the vpp engine
- */
-clib_error_t *
-vlib_plugin_register (vlib_main_t * vm, vnet_plugin_handoff_t * h,
- int from_early_init)
-{
- return 0;
-}
+/* *INDENT-OFF* */
+VLIB_PLUGIN_REGISTER () = {
+ .version = VPP_BUILD_VER,
+};
+/* *INDENT-ON* */
static clib_error_t *
ip6_hop_by_hop_ioam_trace_init (vlib_main_t * vm)
diff --git a/src/plugins/lb/lb.c b/src/plugins/lb/lb.c
index 1d9b987..dc3f5be 100644
--- a/src/plugins/lb/lb.c
+++ b/src/plugins/lb/lb.c
@@ -15,6 +15,7 @@
#include <lb/lb.h>
#include <vnet/plugin/plugin.h>
+#include <vpp/app/version.h>
#include <vnet/api_errno.h>
//GC runs at most once every so many seconds
@@ -730,15 +731,11 @@
return 0;
}
-clib_error_t *
-vlib_plugin_register (vlib_main_t * vm,
- vnet_plugin_handoff_t * h,
- int from_early_init)
-{
- clib_error_t *error = 0;
- return error;
-}
-
+/* *INDENT-OFF* */
+VLIB_PLUGIN_REGISTER () = {
+ .version = VPP_BUILD_VER,
+};
+/* *INDENT-ON* */
u8 *format_lb_dpo (u8 * s, va_list * va)
{
diff --git a/src/plugins/sixrd/sixrd.c b/src/plugins/sixrd/sixrd.c
index 66e631a..71fc181 100644
--- a/src/plugins/sixrd/sixrd.c
+++ b/src/plugins/sixrd/sixrd.c
@@ -19,6 +19,7 @@
#include <vnet/fib/fib_table.h>
#include <vnet/fib/ip6_fib.h>
#include <vnet/adj/adj.h>
+#include <vpp/app/version.h>
/*
* This code supports the following sixrd modes:
@@ -340,27 +341,19 @@
.function = show_sixrd_stats_command_fn,
};
-/*
- * This routine exists to convince the vlib plugin framework that
- * we haven't accidentally copied a random .dll into the plugin directory.
- *
- * Also collects global variable pointers passed from the vpp engine
- */
-clib_error_t *
-vlib_plugin_register (vlib_main_t * vm, vnet_plugin_handoff_t * h,
- int from_early_init)
+/* *INDENT-OFF* */
+VLIB_PLUGIN_REGISTER () = {
+ .version = VPP_BUILD_VER,
+};
+/* *INDENT-ON* */
+
+static clib_error_t * sixrd_init (vlib_main_t * vm)
{
- clib_error_t * error = 0;
sixrd_main_t *mm = &sixrd_main;
mm->vnet_main = vnet_get_main();
mm->vlib_main = vm;
- return error;
-}
-
-static clib_error_t * sixrd_init (vlib_main_t * vm)
-{
sixrd_dpo_module_init ();
return (NULL);
diff --git a/src/plugins/snat/snat.c b/src/plugins/snat/snat.c
index 0fcd6ce..750cc92 100644
--- a/src/plugins/snat/snat.c
+++ b/src/plugins/snat/snat.c
@@ -28,6 +28,7 @@
#include <vlibapi/api.h>
#include <vlibmemory/api.h>
#include <vlibsocket/api.h>
+#include <vpp/app/version.h>
snat_main_t snat_main;
@@ -129,27 +130,11 @@
.runs_before = VNET_FEATURES ("ip4-lookup"),
};
-
-/*
- * This routine exists to convince the vlib plugin framework that
- * we haven't accidentally copied a random .dll into the plugin directory.
- *
- * Also collects global variable pointers passed from the vpp engine
- */
-
-clib_error_t *
-vlib_plugin_register (vlib_main_t * vm, vnet_plugin_handoff_t * h,
- int from_early_init)
-{
- snat_main_t * sm = &snat_main;
- clib_error_t * error = 0;
-
- sm->vlib_main = vm;
- sm->vnet_main = h->vnet_main;
- sm->ethernet_main = h->ethernet_main;
-
- return error;
-}
+/* *INDENT-OFF* */
+VLIB_PLUGIN_REGISTER () = {
+ .version = VPP_BUILD_VER,
+};
+/* *INDENT-ON* */
/*$$$$$ move to an installed header file */
#if (1 || CLIB_DEBUG > 0) /* "trust, but verify" */
diff --git a/src/plugins/snat/snat.h b/src/plugins/snat/snat.h
index 32dc9f9..39cbd3f 100644
--- a/src/plugins/snat/snat.h
+++ b/src/plugins/snat/snat.h
@@ -233,7 +233,6 @@
vnet_main_t * vnet_main;
ip4_main_t * ip4_main;
ip_lookup_main_t * ip4_lookup_main;
- ethernet_main_t * ethernet_main;
api_main_t * api_main;
} snat_main_t;
diff --git a/src/vlib/unix/main.c b/src/vlib/unix/main.c
index 562778e..a04d9f9 100644
--- a/src/vlib/unix/main.c
+++ b/src/vlib/unix/main.c
@@ -503,6 +503,14 @@
vm->heap_base = clib_mem_get_heap ();
ASSERT (vm->heap_base);
+ unformat_init_command_line (&input, (char **) vm->argv);
+ if ((e = vlib_plugin_config (vm, &input)))
+ {
+ clib_error_report (e);
+ return 1;
+ }
+ unformat_free (&input);
+
i = vlib_plugin_early_init (vm);
if (i)
return i;
diff --git a/src/vlib/unix/plugin.c b/src/vlib/unix/plugin.c
index 4039909..4aba95c 100644
--- a/src/vlib/unix/plugin.c
+++ b/src/vlib/unix/plugin.c
@@ -16,29 +16,16 @@
*/
#include <vlib/unix/plugin.h>
+#include <vppinfra/elf.h>
#include <dlfcn.h>
#include <dirent.h>
plugin_main_t vlib_plugin_main;
-void
-vlib_set_get_handoff_structure_cb (void *cb)
-{
- plugin_main_t *pm = &vlib_plugin_main;
- pm->handoff_structure_get_cb = cb;
-}
-
-static void *
-vnet_get_handoff_structure (void)
-{
- void *(*fp) (void);
-
- fp = vlib_plugin_main.handoff_structure_get_cb;
- if (fp == 0)
- return 0;
- else
- return (*fp) ();
-}
+char *vlib_plugin_path __attribute__ ((weak));
+char *vlib_plugin_path = "";
+char *vlib_plugin_app_version __attribute__ ((weak));
+char *vlib_plugin_app_version = "";
void *
vlib_get_plugin_symbol (char *plugin_name, char *symbol_name)
@@ -54,13 +41,99 @@
return dlsym (pi->handle, symbol_name);
}
+static char *
+str_array_to_vec (char *array, int len)
+{
+ char c, *r = 0;
+ int n = 0;
+
+ do
+ {
+ c = array[n];
+ vec_add1 (r, c);
+ }
+ while (c && ++n < len);
+
+ if (c)
+ vec_add1 (r, 0);
+
+ return r;
+}
+
static int
load_one_plugin (plugin_main_t * pm, plugin_info_t * pi, int from_early_init)
{
- void *handle, *register_handle;
- clib_error_t *(*fp) (vlib_main_t *, void *, int);
+ void *handle;
clib_error_t *error;
- void *handoff_structure;
+ elf_main_t em = { 0 };
+ elf_section_t *section;
+ u8 *data;
+ char *version_required;
+ vlib_plugin_registration_t *reg;
+ plugin_config_t *pc = 0;
+ uword *p;
+
+ if (elf_read_file (&em, (char *) pi->filename))
+ return -1;
+
+ error = elf_get_section_by_name (&em, ".vlib_plugin_registration",
+ §ion);
+ if (error)
+ {
+ clib_warning ("Not a plugin: %s\n", (char *) pi->name);
+ return -1;
+ }
+
+ data = elf_get_section_contents (&em, section->index, 1);
+ reg = (vlib_plugin_registration_t *) data;
+
+ if (vec_len (data) != sizeof (*reg))
+ {
+ clib_warning ("vlib_plugin_registration size mismatch in plugin %s\n",
+ (char *) pi->name);
+ goto error;
+ }
+
+ p = hash_get_mem (pm->config_index_by_name, pi->name);
+ if (p)
+ {
+ pc = vec_elt_at_index (pm->configs, p[0]);
+ if (pc->is_disabled)
+ {
+ clib_warning ("Plugin disabled: %s", pi->name);
+ goto error;
+ }
+ if (reg->default_disabled && pc->is_enabled == 0)
+ {
+ clib_warning ("Plugin disabled: %s (default)", pi->name);
+ goto error;
+ }
+ }
+ else if (reg->default_disabled)
+ {
+ clib_warning ("Plugin disabled: %s (default)", pi->name);
+ goto error;
+ }
+
+ version_required = str_array_to_vec ((char *) ®->version_required,
+ sizeof (reg->version_required));
+
+ if ((strlen (version_required) > 0) &&
+ (strncmp (vlib_plugin_app_version, version_required,
+ strlen (version_required))))
+ {
+ clib_warning ("Plugin %s version mismatch: %s != %s",
+ pi->name, vlib_plugin_app_version, reg->version_required);
+ if (!(pc && pc->skip_version_check == 1))
+ {
+ vec_free (version_required);
+ goto error;
+ }
+ }
+
+ vec_free (version_required);
+ vec_free (data);
+ elf_main_free (&em);
handle = dlopen ((char *) pi->filename, RTLD_LAZY);
@@ -77,35 +150,47 @@
pi->handle = handle;
+ reg = dlsym (pi->handle, "vlib_plugin_registration");
- register_handle = dlsym (pi->handle, "vlib_plugin_register");
- if (register_handle == 0)
+ if (reg == 0)
{
- dlclose (handle);
- clib_warning ("Plugin missing vlib_plugin_register: %s\n",
- (char *) pi->name);
- return 1;
+ /* This should never happen unless somebody chagnes registration macro */
+ clib_warning ("Missing plugin registration in plugin '%s'", pi->name);
+ os_exit (1);
}
- fp = register_handle;
+ pi->reg = reg;
+ pi->version = str_array_to_vec ((char *) ®->version,
+ sizeof (reg->version));
- handoff_structure = vnet_get_handoff_structure ();
-
- if (handoff_structure == 0)
- error = clib_error_return (0, "handoff structure callback returned 0");
- else
- error = (*fp) (pm->vlib_main, handoff_structure, from_early_init);
-
- if (error)
+ if (reg && reg->early_init)
{
- clib_error_report (error);
- dlclose (handle);
- return 1;
+ clib_error_t *(*ei) (vlib_main_t *);
+ void *h;
+
+ h = dlsym (pi->handle, reg->early_init);
+ if (h)
+ {
+ ei = h;
+ error = (*ei) (pm->vlib_main);
+ if (error)
+ {
+ clib_error_report (error);
+ os_exit (1);
+ }
+ }
+ else
+ clib_warning ("Plugin %s: early init function %s set but not found",
+ (char *) pi->name, reg->early_init);
}
clib_warning ("Loaded plugin: %s", pi->name);
return 0;
+error:
+ vec_free (data);
+ elf_main_free (&em);
+ return -1;
}
static u8 **
@@ -215,23 +300,16 @@
return 0;
}
-char *vlib_plugin_path __attribute__ ((weak));
-char *vlib_plugin_path = "";
-char *vlib_plugin_name_filter __attribute__ ((weak));
-char *vlib_plugin_name_filter = 0;
-
int
vlib_plugin_early_init (vlib_main_t * vm)
{
plugin_main_t *pm = &vlib_plugin_main;
- pm->plugin_path = format (0, "%s%c", vlib_plugin_path, 0);
+ if (pm->plugin_path == 0)
+ pm->plugin_path = format (0, "%s%c", vlib_plugin_path, 0);
clib_warning ("plugin path %s", pm->plugin_path);
- if (vlib_plugin_name_filter)
- pm->plugin_name_filter = format (0, "%s%c", vlib_plugin_name_filter, 0);
-
pm->plugin_by_name_hash = hash_create_string (0, sizeof (uword));
pm->vlib_main = vm;
@@ -245,19 +323,24 @@
plugin_main_t *pm = &vlib_plugin_main;
u8 *s = 0;
u8 *key = 0;
- uword *value = 0;
+ uword value = 0;
int index = 1;
+ plugin_info_t *pi;
- s = format (s, " Plugin path is: %s\n", pm->plugin_path);
- if (vlib_plugin_name_filter)
- s = format (s, " Plugin filter: %s\n", vlib_plugin_name_filter);
+ s = format (s, " Plugin path is: %s\n\n", pm->plugin_path);
+ s = format (s, " %-41s%s\n", "Plugin", "Version");
- s = format (s, " Plugins loaded: \n");
+ /* *INDENT-OFF* */
hash_foreach_mem (key, value, pm->plugin_by_name_hash,
- {
- if (key != 0)
- s = format (s, " %d.%s\n", index, key); index++;}
- );
+ {
+ if (key != 0)
+ {
+ pi = vec_elt_at_index (pm->plugin_info, value);
+ s = format (s, "%3d. %-40s %s\n", index, key, pi->version);
+ index++;
+ }
+ });
+ /* *INDENT-ON* */
vlib_cli_output (vm, "%v", s);
vec_free (s);
@@ -273,6 +356,148 @@
};
/* *INDENT-ON* */
+static clib_error_t *
+config_one_plugin (vlib_main_t * vm, char *name, unformat_input_t * input)
+{
+ plugin_main_t *pm = &vlib_plugin_main;
+ plugin_config_t *pc;
+ clib_error_t *error = 0;
+ uword *p;
+ int is_enable = 0;
+ int is_disable = 0;
+ int skip_version_check = 0;
+
+ if (pm->config_index_by_name == 0)
+ pm->config_index_by_name = hash_create_string (0, sizeof (uword));
+
+ p = hash_get_mem (pm->config_index_by_name, name);
+
+ if (p)
+ {
+ error = clib_error_return (0, "plugin '%s' already configured", name);
+ goto done;
+ }
+
+ while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
+ {
+ if (unformat (input, "enable"))
+ is_enable = 1;
+ else if (unformat (input, "disable"))
+ is_disable = 1;
+ else if (unformat (input, "skip-version-check"))
+ skip_version_check = 1;
+ else
+ {
+ error = clib_error_return (0, "unknown input '%U'",
+ format_unformat_error, input);
+ goto done;
+ }
+ }
+
+ if (is_enable && is_disable)
+ {
+ error = clib_error_return (0, "please specify either enable or disable"
+ " for plugin '%s'", name);
+ goto done;
+ }
+
+ vec_add2 (pm->configs, pc, 1);
+ hash_set_mem (pm->config_index_by_name, name, pc - pm->configs);
+ pc->is_enabled = is_enable;
+ pc->is_disabled = is_disable;
+ pc->skip_version_check = skip_version_check;
+ pc->name = name;
+
+done:
+ return error;
+}
+
+clib_error_t *
+vlib_plugin_config (vlib_main_t * vm, unformat_input_t * input)
+{
+ plugin_main_t *pm = &vlib_plugin_main;
+ clib_error_t *error = 0;
+ unformat_input_t in;
+
+ unformat_init (&in, 0, 0);
+
+ while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
+ {
+ u8 *s, *v;
+ if (unformat (input, "%s %v", &s, &v))
+ {
+ if (strncmp ((const char *) s, "plugins", 8) == 0)
+ {
+ if (vec_len (in.buffer) > 0)
+ vec_add1 (in.buffer, ' ');
+ vec_add (in.buffer, v, vec_len (v));
+ }
+ }
+ else
+ {
+ error = clib_error_return (0, "unknown input '%U'",
+ format_unformat_error, input);
+ goto done;
+ }
+
+ vec_free (v);
+ vec_free (s);
+ }
+done:
+ input = ∈
+ while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
+ {
+ unformat_input_t sub_input;
+ u8 *s = 0;
+ if (unformat (input, "path %s", &s))
+ pm->plugin_path = s;
+ else if (unformat (input, "plugin %s %U", &s,
+ unformat_vlib_cli_sub_input, &sub_input))
+ {
+ error = config_one_plugin (vm, (char *) s, &sub_input);
+ unformat_free (&sub_input);
+ if (error)
+ goto done2;
+ }
+ else
+ {
+ error = clib_error_return (0, "unknown input '%U'",
+ format_unformat_error, input);
+ {
+ vec_free (s);
+ goto done2;
+ }
+ }
+ }
+
+done2:
+ unformat_free (&in);
+ return error;
+}
+
+/* discard whole 'plugins' section, as it is already consumed prior to
+ plugin load */
+static clib_error_t *
+plugins_config (vlib_main_t * vm, unformat_input_t * input)
+{
+ u8 *junk;
+
+ while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
+ {
+ if (unformat (input, "%s", &junk))
+ {
+ vec_free (junk);
+ return 0;
+ }
+ else
+ return clib_error_return (0, "unknown input '%U'",
+ format_unformat_error, input);
+ }
+ return 0;
+}
+
+VLIB_CONFIG_FUNCTION (plugins_config, "plugins");
+
/*
* fd.io coding-style-patch-verification: ON
*
diff --git a/src/vlib/unix/plugin.h b/src/vlib/unix/plugin.h
index 1c74cdd..01fec35 100644
--- a/src/vlib/unix/plugin.h
+++ b/src/vlib/unix/plugin.h
@@ -56,7 +56,14 @@
* vlib_load_new_plugins().
*/
-
+/* *INDENT-OFF* */
+typedef CLIB_PACKED(struct {
+ u8 default_disabled;
+ const char version[32];
+ const char version_required[32];
+ const char *early_init;
+}) vlib_plugin_registration_t;
+/* *INDENT-ON* */
typedef struct
{
@@ -64,10 +71,22 @@
u8 *filename;
struct stat file_info;
void *handle;
+
+ /* plugin registration */
+ vlib_plugin_registration_t *reg;
+ char *version;
} plugin_info_t;
typedef struct
{
+ char *name;
+ u8 is_disabled;
+ u8 is_enabled;
+ u8 skip_version_check;
+} plugin_config_t;
+
+typedef struct
+{
/* loaded plugin info */
plugin_info_t *plugin_info;
uword *plugin_by_name_hash;
@@ -76,8 +95,9 @@
u8 *plugin_path;
u8 *plugin_name_filter;
- /* handoff structure get callback */
- void *handoff_structure_get_cb;
+ /* plugin configs and hash by name */
+ plugin_config_t *configs;
+ uword *config_index_by_name;
/* usual */
vlib_main_t *vlib_main;
@@ -85,10 +105,15 @@
extern plugin_main_t vlib_plugin_main;
+clib_error_t *vlib_plugin_config (vlib_main_t * vm, unformat_input_t * input);
int vlib_plugin_early_init (vlib_main_t * vm);
int vlib_load_new_plugins (plugin_main_t * pm, int from_early_init);
void *vlib_get_plugin_symbol (char *plugin_name, char *symbol_name);
+#define VLIB_PLUGIN_REGISTER() \
+ vlib_plugin_registration_t vlib_plugin_registration \
+ __attribute__((__section__(".vlib_plugin_registration")))
+
#endif /* __included_plugin_h__ */
/*
diff --git a/src/vnet/plugin/plugin.h b/src/vnet/plugin/plugin.h
index a14a593..6e1a326 100644
--- a/src/vnet/plugin/plugin.h
+++ b/src/vnet/plugin/plugin.h
@@ -20,13 +20,6 @@
#include <vnet/pg/pg.h>
#include <vnet/ethernet/ethernet.h>
#include <vppinfra/error.h>
-
-/* Pointers to Genuine Vnet data structures handed to plugin .dll's */
-typedef struct {
- vnet_main_t * vnet_main;
- ethernet_main_t * ethernet_main;
-} vnet_plugin_handoff_t;
-
-void * vnet_get_handoff_structure (void);
+#include <vlib/unix/plugin.h>
#endif /* included_vnet_plugin_h */
diff --git a/src/vpp/vnet/main.c b/src/vpp/vnet/main.c
index a252b84..4a96ca9 100644
--- a/src/vpp/vnet/main.c
+++ b/src/vpp/vnet/main.c
@@ -18,7 +18,7 @@
#include <vlib/unix/unix.h>
#include <vnet/plugin/plugin.h>
#include <vnet/ethernet/ethernet.h>
-
+#include <vpp/app/version.h>
#include <vpp/api/vpe_msg_enum.h>
@@ -39,16 +39,7 @@
* Load plugins from /usr/lib/vpp_plugins by default
*/
char *vlib_plugin_path = "/usr/lib/vpp_plugins";
-
-void *
-vnet_get_handoff_structure (void)
-{
- static vnet_plugin_handoff_t _rv, *rv = &_rv;
-
- rv->vnet_main = vnet_get_main ();
- rv->ethernet_main = ðernet_main;
- return (void *) rv;
-}
+char *vlib_plugin_app_version = VPP_BUILD_VER;
int
main (int argc, char *argv[])
@@ -59,7 +50,6 @@
uword main_heap_size = (1ULL << 30);
u8 *sizep;
u32 size;
- void vlib_set_get_handoff_structure_cb (void *cb);
#if __x86_64__
CLIB_UNUSED (const char *msg)
@@ -206,7 +196,6 @@
#if DPDK == 0
unix_physmem_init (vm, 0 /* fail_if_physical_memory_not_present */ );
#endif
- vlib_set_get_handoff_structure_cb (&vnet_get_handoff_structure);
return vlib_unix_main (argc, argv);
}
else