diff options
author | João Valverde <joao.valverde@tecnico.ulisboa.pt> | 2017-10-01 00:56:03 +0100 |
---|---|---|
committer | João Valverde <j@v6e.pt> | 2017-12-14 08:43:57 +0000 |
commit | 995812c5f1add94df1c237596939130c1704b099 (patch) | |
tree | 42542c56b9a70c7d2d231c8bc36649be35af46b4 /doc | |
parent | a9821caab8a1f2c6e265bd5b63a060f1f241c704 (diff) |
Refactor plugin registration and loading
Put different types of plugins (libwiretap, libwireshark) in different
subdirectories, give libwiretap and libwireshark init routines that
load the plugins, and have them scan the appropriate subdirectories
so that we don't even *try* to, for example, load libwireshark plugins
in programs that only use libwiretap.
Compiled plugins are stored in subfolders of the plugin folders, with
the subfolder name being the Wireshark minor version number (X.Y). There is
another hierarchical level for each Wireshark library (libwireshark, libwscodecs
and libwiretap).
The folder names are respectively plugins/X.Y/{epan,codecs,wiretap}.
Currently we only distribute "epan" (libwireshark) plugins.
Change-Id: I3438787a6f45820d64ba4ca91cbe3c8864708acb
Reviewed-on: https://code.wireshark.org/review/23983
Petri-Dish: João Valverde <j@v6e.pt>
Tested-by: Petri Dish Buildbot
Reviewed-by: João Valverde <j@v6e.pt>
Diffstat (limited to 'doc')
-rw-r--r-- | doc/README.plugins | 41 | ||||
-rw-r--r-- | doc/plugins.example/Makefile.am | 10 | ||||
-rw-r--r-- | doc/plugins.example/configure.ac | 9 | ||||
-rw-r--r-- | doc/plugins.example/hello.c | 21 |
4 files changed, 67 insertions, 14 deletions
diff --git a/doc/README.plugins b/doc/README.plugins index f66f993938..e06842571a 100644 --- a/doc/README.plugins +++ b/doc/README.plugins @@ -42,8 +42,8 @@ For your plugins/foo/Makefile.am file, see the corresponding file in plugins/gryphon. Replace all occurrences of "gryphon" in those files with "foo". -Your plugins/foo/Makefile.am also needs to list the main source file(s), -which exports register_*() and handoff_*(), for your dissector in the +Your plugins/foo/Makefile.am also needs to list the main source file +which exports plugin_register() for your dissector in the DISSECTOR_SRC variable. All other supporting source files should be listed in the DISSECTOR_SUPPORT_SRC variable. The header files for your dissector, if any, must be listed in the @@ -236,7 +236,39 @@ make install 5. Update "old style" plugins -5.1 How to update an "old style" plugin (using plugin_register and +5.1 How to update an "old style" plugin (since Wireshark 2.5) + +Plugins need exactly three visible symbols: plugin_version, plugin_release and +plugin_register. Each plugin is either a libwscodecs plugin, libwiretap plugin or +libwireshark plugin and the library will call "plugin_register" after +loading the plugin. "plugin_register" in turn calls all the hooks necessary +to enable the plugin. So if you had two function like so: + + WS_DLL_PUBLIC void plugin_register(void); + WS_DLL_PUBLIC void plugin_reg_handoff(void); + + void plugin_register(void) {...}; + void plugin_reg_handoff(void) {...}; + +You'll have to rewrite it as: + + WS_DLL_PUBLIC void plugin_register(void); + + static void proto_register_foo(void) {...}; + static void proto_reg_handoff_foo(void) {...}; + + void plugin_register(void) + { + static proto_plugin plugin_foo; + + plugin_foo.register_protoinfo = proto_register_foo; + plugin_foo.register_handoff = proto_reg_handoff_foo; + proto_register_plugin(&plugin_foo); + } + +See doc/plugins.example for an example. + +5.2 How to update an "old style" plugin (using plugin_register and plugin_reg_handoff functions). The plugin registration has changed with the extension of the build @@ -269,7 +301,7 @@ stips the parts outlined below: This will leave a clean dissector source file without plugin specifics. -5.2 How to update an "old style" plugin (using plugin_init function) +5.3 How to update an "old style" plugin (using plugin_init function) The plugin registering has changed between 0.10.9 and 0.10.10; everyone is encouraged to update their plugins as outlined below: @@ -283,7 +315,6 @@ is encouraged to update their plugins as outlined below: o Change the Makefile.am file to match the one of the DOCSIS plugin. - 6 How to plugin related interface options To demonstrate the functionality of the plugin interface options, a demonstration diff --git a/doc/plugins.example/Makefile.am b/doc/plugins.example/Makefile.am index df90503908..d33e186757 100644 --- a/doc/plugins.example/Makefile.am +++ b/doc/plugins.example/Makefile.am @@ -11,13 +11,15 @@ WARNFLAGS = -Wall -Wextra plugindir := $(shell PKG_CONFIG_PATH=$(PKG_CONFIG_PATH) $(PKG_CONFIG) --define-variable=libdir=$(libdir) --variable plugindir wireshark) -release_version := $(notdir $(plugindir)) +epan_plugindir = $(plugindir)/epan -plugin_LTLIBRARIES = hello.la +VERSION_RELEASE := $(shell PKG_CONFIG_PATH=$(PKG_CONFIG_PATH) $(PKG_CONFIG) --variable VERSION_RELEASE wireshark) + +epan_plugin_LTLIBRARIES = hello.la hello_la_SOURCES = hello.c -hello_la_CPPFLAGS = -DVERSION_RELEASE=\"$(release_version)\" +hello_la_CPPFLAGS = -DVERSION_RELEASE=\"$(VERSION_RELEASE)\" hello_la_CFLAGS = $(WIRESHARK_CFLAGS) -fvisibility=hidden $(WARNFLAGS) @@ -25,7 +27,7 @@ hello_la_LDFLAGS = -module -avoid-version -shared hello_la_LIBADD = $(WIRESHARK_LIBS) -homedir = $${HOME}/.local/lib/wireshark/plugins/$(release_version) +homedir = $${HOME}/.local/lib/wireshark/plugins/$(VERSION_RELEASE)/epan install-home: $(MKDIR_P) $(homedir) || exit 1; \ diff --git a/doc/plugins.example/configure.ac b/doc/plugins.example/configure.ac index 07e9845d10..df66a02cc2 100644 --- a/doc/plugins.example/configure.ac +++ b/doc/plugins.example/configure.ac @@ -22,6 +22,15 @@ AC_CONFIG_SRCDIR([hello.c]) dnl Requires Wireshark 2.5.0 or greater. PKG_CHECK_MODULES([WIRESHARK], [wireshark >= 2.5]) +saved_CFLAGS="$CFLAGS"; saved_LIBS="$LIBS"; +CFLAGS="$WIRESHARK_CFLAGS" +LIBS="$WIRESHARK_LIBS" +AC_CHECK_FUNCS([proto_register_plugin], + [AC_DEFINE([HAVE_PLUGINS], 1, [Define to 1 if Wireshark supports loading plugins])], + [AC_MSG_ERROR([Wireshark was compiled without support for plugins])] +) +CFLAGS="$saved_CFLAGS"; LIBS="$saved_LIBS" + AC_CONFIG_HEADER([config.h]) AC_CONFIG_FILES([Makefile]) diff --git a/doc/plugins.example/hello.c b/doc/plugins.example/hello.c index fce0a5372b..455b4741a6 100644 --- a/doc/plugins.example/hello.c +++ b/doc/plugins.example/hello.c @@ -12,6 +12,7 @@ #endif #include <epan/packet.h> +#include <epan/proto.h> #include <ws_attributes.h> #ifndef VERSION @@ -25,8 +26,6 @@ DLL_PUBLIC const gchar plugin_release[] = VERSION_RELEASE; DLL_PUBLIC void plugin_register(void); -DLL_PUBLIC void plugin_reg_handoff(void); - static int proto_hello = -1; static dissector_handle_t handle_hello; @@ -38,14 +37,26 @@ dissect_hello(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *tree, void *dat return tvb_captured_length(tvb); } -void plugin_register(void) +static void +proto_register_hello(void) { - proto_hello = proto_register_protocol("Wireshark Hello Plugin", "Hello", "hello"); + proto_hello = proto_register_protocol("Wireshark Hello Plugin", "Hello WS", "hello_ws"); handle_hello = create_dissector_handle(dissect_hello, proto_hello); register_postdissector(handle_hello); } -void plugin_reg_handoff(void) +static void +proto_reg_handoff_hello(void) { /* empty */ } + +void +plugin_register(void) +{ + static proto_plugin plug; + + plug.register_protoinfo = proto_register_hello; + plug.register_handoff = proto_reg_handoff_hello; /* or NULL */ + proto_register_plugin(&plug); +} |