25 char *vlib_plugin_path __attribute__ ((weak));
26 char *vlib_plugin_path =
"";
41 return dlsym (pi->
handle, symbol_name);
55 while (c && ++n < len);
71 char *version_required;
72 vlib_plugin_registration_t *reg;
88 reg = (vlib_plugin_registration_t *) data;
90 if (
vec_len (data) !=
sizeof (*reg))
92 clib_warning (
"vlib_plugin_registration size mismatch in plugin %s\n",
106 if (reg->default_disabled && pc->
is_enabled == 0)
112 else if (reg->default_disabled)
119 sizeof (reg->version_required));
121 if ((strlen (version_required) > 0) &&
122 (strncmp (vlib_plugin_app_version, version_required,
123 strlen (version_required))))
126 pi->
name, vlib_plugin_app_version, reg->version_required);
138 handle = dlopen ((
char *) pi->
filename, RTLD_LAZY);
153 reg = dlsym (pi->
handle,
"vlib_plugin_registration");
164 sizeof (reg->version));
171 h = dlsym (pi->
handle, reg->early_init);
183 clib_warning (
"Plugin %s: early init function %s set but not found",
184 (
char *) pi->
name, reg->early_init);
187 if (reg->description)
232 return strcmp ((
char *) p1->
name, (
char *) p2->
name);
239 struct dirent *entry;
244 u32 *load_fail_indices = 0;
249 for (i = 0; i <
vec_len (plugin_path); i++)
251 dp = opendir ((
char *) plugin_path[i]);
256 while ((entry = readdir (dp)))
269 filename =
format (0,
"%s/%s%c", plugin_path[i], entry->d_name, 0);
272 char *ext = strrchr ((
const char *) filename,
'.');
274 if (!ext || (strcmp (ext,
".so") != 0) ||
275 stat ((
char *) filename, &statb) < 0)
283 if (!S_ISREG (statb.st_mode))
286 plugin_name =
format (0,
"%s%c", entry->d_name, 0);
293 pi->
name = plugin_name;
334 if (vec_len (load_fail_indices) > 0)
336 for (i = vec_len (load_fail_indices) - 1; i >= 0; i--)
380 s =
format (s,
" %-41s%-33s%s\n",
"Plugin",
"Version",
"Description");
387 pi = vec_elt_at_index (pm->plugin_info, value);
388 s = format (s,
"%3d. %-40s %-32s %s\n", index, key, pi->version,
389 pi->reg->description ? pi->reg->description :
"");
403 .path =
"show plugins",
404 .short_help =
"show loaded plugins",
418 int skip_version_check = 0;
435 else if (
unformat (input,
"disable"))
437 else if (
unformat (input,
"skip-version-check"))
438 skip_version_check = 1;
447 if (is_enable && is_disable)
450 " for plugin '%s'", name);
477 if (
unformat (input,
"%s %v", &s, &v))
479 if (strncmp ((
const char *) s,
"plugins", 8) == 0)
502 if (
unformat (input,
"path %s", &s))
504 else if (
unformat (input,
"plugin %s %U", &s,
plugin_config_t * configs
static void elf_main_free(elf_main_t *em)
sll srl srl sll sra u16x4 i
static clib_error_t * plugins_config(vlib_main_t *vm, unformat_input_t *input)
static int plugin_name_sort_cmp(void *a1, void *a2)
#define vec_add1(V, E)
Add 1 element to end of vector (unspecified alignment).
clib_error_t * vlib_plugin_config(vlib_main_t *vm, unformat_input_t *input)
#define vec_add2(V, P, N)
Add N elements to end of vector V, return pointer to new elements in P.
#define hash_set_mem(h, key, value)
#define vec_add(V, E, N)
Add N elements to end of vector V (no header, unspecified alignment)
static int load_one_plugin(plugin_main_t *pm, plugin_info_t *pi, int from_early_init)
vlib_plugin_registration_t * reg
#define vec_elt_at_index(v, i)
Get vector value at index i checking that i is in bounds.
#define clib_error_return(e, args...)
int vlib_plugin_early_init(vlib_main_t *vm)
#define hash_create_string(elts, value_bytes)
uword * config_index_by_name
#define hash_unset_mem(h, key)
#define VLIB_CONFIG_FUNCTION(x, n,...)
plugin_info_t * plugin_info
#define hash_foreach_mem(key_var, value_var, h, body)
#define vec_free(V)
Free vector's memory (no header).
#define clib_warning(format, args...)
clib_error_t * elf_read_file(elf_main_t *em, char *file_name)
char * vlib_plugin_app_version
static clib_error_t * config_one_plugin(vlib_main_t *vm, char *name, unformat_input_t *input)
#define VLIB_CLI_COMMAND(x,...)
#define vec_delete(V, N, M)
Delete N elements starting at element M.
static void * elf_get_section_contents(elf_main_t *em, uword section_index, uword elt_size)
#define clib_error_report(e)
int vlib_load_new_plugins(plugin_main_t *pm, int from_early_init)
void * vlib_get_plugin_symbol(char *plugin_name, char *symbol_name)
static u8 ** split_plugin_path(plugin_main_t *pm)
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
uword unformat_vlib_cli_sub_input(unformat_input_t *i, va_list *args)
#define vec_sort_with_function(vec, f)
Sort a vector using the supplied element comparison function.
#define hash_get_mem(h, key)
clib_error_t * elf_get_section_by_name(elf_main_t *em, char *section_name, elf_section_t **result)
void vlib_cli_output(vlib_main_t *vm, char *fmt,...)
static char * str_array_to_vec(char *array, int len)
plugin_main_t vlib_plugin_main
uword * plugin_by_name_hash
static clib_error_t * vlib_plugins_show_cmd_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)