plugins: Minor interface improvement

Change the plugin compatibility check to make it more convenient to
define and check the major.minor Wireshark version.

Change-Id: I2a6d2a746682c29504311cce5c457e0a852c3daf
Reviewed-on: https://code.wireshark.org/review/29224
Petri-Dish: João Valverde <j@v6e.pt>
Tested-by: Petri Dish Buildbot
Reviewed-by: João Valverde <j@v6e.pt>
This commit is contained in:
João Valverde 2018-08-21 15:18:56 +01:00 committed by João Valverde
parent 0410a522d5
commit 65d9c473f0
8 changed files with 50 additions and 17 deletions

View File

@ -1418,12 +1418,13 @@ set_target_properties(version PROPERTIES FOLDER "Auxiliary")
set( configure_input "Built with CMake ${CMAKE_VERSION}" ) set( configure_input "Built with CMake ${CMAKE_VERSION}" )
configure_file(${CMAKE_SOURCE_DIR}/cmakeconfig.h.in ${CMAKE_BINARY_DIR}/config.h) configure_file(${CMAKE_SOURCE_DIR}/cmakeconfig.h.in ${CMAKE_BINARY_DIR}/config.h)
configure_file(${CMAKE_SOURCE_DIR}/ws_version.h.in ${CMAKE_BINARY_DIR}/ws_version.h)
set( prefix "${CMAKE_INSTALL_PREFIX}" ) set( prefix "${CMAKE_INSTALL_PREFIX}" )
set( exec_prefix "\${prefix}" ) set( exec_prefix "\${prefix}" )
set( libdir "\${exec_prefix}/${CMAKE_INSTALL_LIBDIR}" ) set( libdir "\${exec_prefix}/${CMAKE_INSTALL_LIBDIR}" )
set( includedir "\${prefix}/include" ) set( includedir "\${prefix}/include" )
set( plugindir "\${libdir}/wireshark/${PLUGIN_VERSION_DIR}" ) set( plugindir "\${libdir}/wireshark/${PLUGIN_VERSION_DIR}" )
set( VERSION_RELEASE "${PROJECT_RELEASE_VERSION}" )
# Doxygen variables # Doxygen variables
file(GLOB TOP_LEVEL_SOURCE_LIST *.c *.cpp *.h) file(GLOB TOP_LEVEL_SOURCE_LIST *.c *.cpp *.h)
@ -2825,6 +2826,7 @@ set(SHARK_PUBLIC_HEADERS
ws_diag_control.h ws_diag_control.h
ws_symbol_export.h ws_symbol_export.h
version_info.h version_info.h
${CMAKE_BINARY_DIR}/ws_version.h
) )
if(NOT WIN32) if(NOT WIN32)

View File

@ -20,7 +20,6 @@ pkg_check_modules(WIRESHARK REQUIRED wireshark>=2.5)
### CMake Bug: If you run into problems please use the "Unix Makefiles" generator. ### CMake Bug: If you run into problems please use the "Unix Makefiles" generator.
### Ninja just wipes the pkg-config variables. ### Ninja just wipes the pkg-config variables.
# https://gitlab.kitware.com/cmake/cmake/issues/17531 (and probably others) # https://gitlab.kitware.com/cmake/cmake/issues/17531 (and probably others)
pkg_get_variable(WIRESHARK_VERSION_RELEASE wireshark VERSION_RELEASE)
pkg_get_variable(WIRESHARK_PLUGIN_DIR wireshark plugindir) pkg_get_variable(WIRESHARK_PLUGIN_DIR wireshark plugindir)
set(PLUGIN_INSTALL_LIBDIR "${WIRESHARK_PLUGIN_DIR}/epan") set(PLUGIN_INSTALL_LIBDIR "${WIRESHARK_PLUGIN_DIR}/epan")
@ -41,7 +40,7 @@ if (CMAKE_COMPILER_IS_GNUCC)
set(CMAKE_C_FLAGS "-Wall -Wextra ${CMAKE_C_FLAGS}") set(CMAKE_C_FLAGS "-Wall -Wextra ${CMAKE_C_FLAGS}")
endif() endif()
add_definitions(-DHAVE_PLUGINS -DVERSION=\"${PROJECT_VERSION}\" -DVERSION_RELEASE=\"${WIRESHARK_VERSION_RELEASE}\") add_definitions(-DHAVE_PLUGINS -DVERSION=\"${PROJECT_VERSION}\")
add_library(hello MODULE hello.c) add_library(hello MODULE hello.c)
set_target_properties(hello PROPERTIES PREFIX "" DEFINE_SYMBOL "") set_target_properties(hello PROPERTIES PREFIX "" DEFINE_SYMBOL "")

View File

@ -14,6 +14,7 @@
#include <epan/packet.h> #include <epan/packet.h>
#include <epan/proto.h> #include <epan/proto.h>
#include <ws_attributes.h> #include <ws_attributes.h>
#include <ws_version.h>
#ifndef VERSION #ifndef VERSION
#define VERSION "0.0.0" #define VERSION "0.0.0"
@ -22,7 +23,8 @@
#define DLL_PUBLIC __attribute__((__visibility__("default"))) #define DLL_PUBLIC __attribute__((__visibility__("default")))
DLL_PUBLIC const gchar plugin_version[] = VERSION; DLL_PUBLIC const gchar plugin_version[] = VERSION;
DLL_PUBLIC const gchar plugin_release[] = VERSION_RELEASE; DLL_PUBLIC const int plugin_want_major = WIRESHARK_VERSION_MAJOR;
DLL_PUBLIC const int plugin_want_minor = WIRESHARK_VERSION_MINOR;
DLL_PUBLIC void plugin_register(void); DLL_PUBLIC void plugin_register(void);

View File

@ -21,7 +21,8 @@
#include "pinfo_stats_tree.h" #include "pinfo_stats_tree.h"
WS_DLL_PUBLIC_DEF const gchar plugin_version[] = PLUGIN_VERSION; WS_DLL_PUBLIC_DEF const gchar plugin_version[] = PLUGIN_VERSION;
WS_DLL_PUBLIC_DEF const gchar plugin_release[] = VERSION_RELEASE; WS_DLL_PUBLIC_DEF const int plugin_want_major = VERSION_MAJOR;
WS_DLL_PUBLIC_DEF const int plugin_want_minor = VERSION_MINOR;
WS_DLL_PUBLIC void plugin_register(void); WS_DLL_PUBLIC void plugin_register(void);

View File

@ -130,7 +130,8 @@ for symbol in regs['codec_register']:
reg_code += """ reg_code += """
WS_DLL_PUBLIC_DEF const gchar plugin_version[] = PLUGIN_VERSION; WS_DLL_PUBLIC_DEF const gchar plugin_version[] = PLUGIN_VERSION;
WS_DLL_PUBLIC_DEF const gchar plugin_release[] = VERSION_RELEASE; WS_DLL_PUBLIC_DEF const int plugin_want_major = VERSION_MAJOR;
WS_DLL_PUBLIC_DEF const int plugin_want_minor = VERSION_MINOR;
WS_DLL_PUBLIC void plugin_register(void); WS_DLL_PUBLIC void plugin_register(void);

View File

@ -4,7 +4,6 @@ libdir=@libdir@
includedir=@includedir@ includedir=@includedir@
sharedlibdir=${libdir} sharedlibdir=${libdir}
plugindir=@plugindir@ plugindir=@plugindir@
VERSION_RELEASE=@VERSION_RELEASE@
Name: Wireshark Name: Wireshark
Description: Network Packet Dissection Library Description: Network Packet Dissection Library

10
ws_version.h.in Normal file
View File

@ -0,0 +1,10 @@
/* ws_version.h.in */
#ifndef __WS_VERSION_H__
#define __WS_VERSION_H__
#define WIRESHARK_VERSION_MAJOR @PROJECT_MAJOR_VERSION@
#define WIRESHARK_VERSION_MINOR @PROJECT_MINOR_VERSION@
#define WIRESHARK_VERSION_MICRO @PROJECT_PATCH_VERSION@
#endif /* __WS_VERSION_H__ */

View File

@ -96,6 +96,33 @@ compare_plugins(gconstpointer a, gconstpointer b)
return g_strcmp0((*(plugin *const *)a)->name, (*(plugin *const *)b)->name); return g_strcmp0((*(plugin *const *)a)->name, (*(plugin *const *)b)->name);
} }
static gboolean
pass_plugin_version_compatibility(GModule *handle, const char *name)
{
gpointer symb;
int major, minor;
if(!g_module_symbol(handle, "plugin_want_major", &symb)) {
report_failure("The plugin '%s' has no \"plugin_want_major\" symbol", name);
return FALSE;
}
major = *(int *)symb;
if(!g_module_symbol(handle, "plugin_want_minor", &symb)) {
report_failure("The plugin '%s' has no \"plugin_want_minor\" symbol", name);
return FALSE;
}
minor = *(int *)symb;
if (major != VERSION_MAJOR || minor != VERSION_MINOR) {
report_failure("The plugin '%s' was compiled for Wireshark version %d.%d",
name, major, minor);
return FALSE;
}
return TRUE;
}
static void static void
scan_plugins_dir(GHashTable *plugins_module, const char *dirpath, plugin_type_e type, gboolean append_type) scan_plugins_dir(GHashTable *plugins_module, const char *dirpath, plugin_type_e type, gboolean append_type)
{ {
@ -105,7 +132,7 @@ scan_plugins_dir(GHashTable *plugins_module, const char *dirpath, plugin_type_e
gchar *plugin_file; /* current file full path */ gchar *plugin_file; /* current file full path */
GModule *handle; /* handle returned by g_module_open */ GModule *handle; /* handle returned by g_module_open */
gpointer symbol; gpointer symbol;
const char *plug_version, *plug_release; const char *plug_version;
plugin *new_plug; plugin *new_plug;
if (append_type) if (append_type)
@ -152,15 +179,7 @@ scan_plugins_dir(GHashTable *plugins_module, const char *dirpath, plugin_type_e
} }
plug_version = (const char *)symbol; plug_version = (const char *)symbol;
if (!g_module_symbol(handle, "plugin_release", &symbol)) if (!pass_plugin_version_compatibility(handle, name)) {
{
report_failure("The plugin '%s' has no \"plugin_release\" symbol", name);
g_module_close(handle);
continue;
}
plug_release = (const char *)symbol;
if (strcmp(plug_release, VERSION_RELEASE) != 0) {
report_failure("The plugin '%s' was compiled for Wireshark version %s", name, plug_release);
g_module_close(handle); g_module_close(handle);
continue; continue;
} }