diff options
author | Damjan Marion <damarion@cisco.com> | 2017-01-06 14:33:05 +0100 |
---|---|---|
committer | Dave Barach <openvpp@barachs.net> | 2017-01-07 17:41:28 +0000 |
commit | f935e336db1282c1ec67cf703db2d3cfaec32915 (patch) | |
tree | 43f5e1c2a74afd9997cfac123e8f6dc591142b8b | |
parent | f952692c871b78590fcd6f2d1340a77ce59030a6 (diff) |
plugin: add API to get pointer to symbol in different plugin
Change-Id: Ic2fbbd8227d5d0c033e5d7b5f43b859a4889d2f3
Signed-off-by: Damjan Marion <damarion@cisco.com>
-rw-r--r-- | src/vlib/unix/plugin.c | 31 | ||||
-rw-r--r-- | src/vlib/unix/plugin.h | 2 |
2 files changed, 26 insertions, 7 deletions
diff --git a/src/vlib/unix/plugin.c b/src/vlib/unix/plugin.c index b3d5be02ed6..987f7d052e5 100644 --- a/src/vlib/unix/plugin.c +++ b/src/vlib/unix/plugin.c @@ -40,6 +40,20 @@ vnet_get_handoff_structure (void) return (*fp) (); } +void * +vlib_get_plugin_symbol (char *plugin_name, char *symbol_name) +{ + plugin_main_t *pm = &vlib_plugin_main; + uword *p; + plugin_info_t *pi; + + if ((p = hash_get_mem (pm->plugin_by_name_hash, plugin_name)) == 0) + return 0; + + pi = vec_elt_at_index (pm->plugin_info, p[0]); + return dlsym (pi->handle, symbol_name); +} + static int load_one_plugin (plugin_main_t * pm, plugin_info_t * pi, int from_early_init) { @@ -48,7 +62,7 @@ load_one_plugin (plugin_main_t * pm, plugin_info_t * pi, int from_early_init) clib_error_t *error; void *handoff_structure; - handle = dlopen ((char *) pi->name, RTLD_LAZY); + handle = dlopen ((char *) pi->filename, RTLD_LAZY); /* * Note: this can happen if the plugin has an undefined symbol reference, @@ -144,6 +158,7 @@ vlib_load_new_plugins (plugin_main_t * pm, int from_early_init) while ((entry = readdir (dp))) { u8 *plugin_name; + u8 *filename; if (pm->plugin_name_filter) { @@ -153,17 +168,16 @@ vlib_load_new_plugins (plugin_main_t * pm, int from_early_init) goto next; } - plugin_name = format (0, "%s/%s%c", plugin_path[i], - entry->d_name, 0); + filename = format (0, "%s/%s%c", plugin_path[i], entry->d_name, 0); /* Only accept .so */ - char *ext = strrchr ((const char *) plugin_name, '.'); + char *ext = strrchr ((const char *) filename, '.'); /* unreadable */ if (!ext || (strcmp (ext, ".so") != 0) || - stat ((char *) plugin_name, &statb) < 0) + stat ((char *) filename, &statb) < 0) { ignore: - vec_free (plugin_name); + vec_free (filename); continue; } @@ -171,20 +185,23 @@ vlib_load_new_plugins (plugin_main_t * pm, int from_early_init) if (!S_ISREG (statb.st_mode)) goto ignore; + plugin_name = format (0, "%s%c", entry->d_name, 0); p = hash_get_mem (pm->plugin_by_name_hash, plugin_name); if (p == 0) { vec_add2 (pm->plugin_info, pi, 1); pi->name = plugin_name; + pi->filename = filename; pi->file_info = statb; if (load_one_plugin (pm, pi, from_early_init)) { vec_free (plugin_name); + vec_free (filename); _vec_len (pm->plugin_info) = vec_len (pm->plugin_info) - 1; + memset (pi, 0, sizeof (*pi)); continue; } - memset (pi, 0, sizeof (*pi)); hash_set_mem (pm->plugin_by_name_hash, plugin_name, pi - pm->plugin_info); } diff --git a/src/vlib/unix/plugin.h b/src/vlib/unix/plugin.h index f35c9c5de1e..1c74cdd241b 100644 --- a/src/vlib/unix/plugin.h +++ b/src/vlib/unix/plugin.h @@ -61,6 +61,7 @@ typedef struct { u8 *name; + u8 *filename; struct stat file_info; void *handle; } plugin_info_t; @@ -86,6 +87,7 @@ extern plugin_main_t vlib_plugin_main; 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); #endif /* __included_plugin_h__ */ |