Merge remote-tracking branch 'origin/topic/robin/plugin-version-check'

I added another small change - since we are inlining Configure(), we can
just set bro_plugin directly to BRO_PLUGIN_BRO_VERSION in
src/plugin/Plugin.h, instead of depending on the plugin to do it. This
also means we do not need to change init-plugin in bro-aux at this
moment.

BIT-1828 #closed

* origin/topic/robin/plugin-version-check:
  Adding plugin API number into versioned function name, and removing old runtime API version check.
  Extend plugin infrastructure to catch Bro version mismatches at link time.
This commit is contained in:
Johanna Amann 2017-07-25 16:02:41 -07:00
commit 089f87d8da
10 changed files with 80 additions and 34 deletions

View file

@ -243,10 +243,6 @@ bool Manager::ActivateDynamicPluginInternal(const std::string& name, bool ok_if_
plugins_by_path.insert(std::make_pair(normalize_path(dir), current_plugin));
if ( current_plugin->APIVersion() != BRO_PLUGIN_API_VERSION )
reporter->FatalError("plugin's API version does not match Bro (expected %d, got %d in %s)",
BRO_PLUGIN_API_VERSION, current_plugin->APIVersion(), path);
// We execute the pre-script initialization here; this in
// fact could be *during* script initialization if we got
// triggered via @load-plugin.

View file

@ -242,11 +242,6 @@ VersionNumber Plugin::Version() const
return config.version;
}
int Plugin::APIVersion() const
{
return config.api_version;
}
bool Plugin::DynamicPlugin() const
{
return dynamic;

View file

@ -13,10 +13,11 @@
#include "iosource/Component.h"
#include "logging/WriterBackend.h"
// We allow to override this externally for testing purposes.
#ifndef BRO_PLUGIN_API_VERSION
#define BRO_PLUGIN_API_VERSION 5
#endif
// Increase this when making incompatible changes to the plugin API. Note
// that the constant is never used in C code. It's picked up on by CMake.
#define BRO_PLUGIN_API_VERSION 6
#define BRO_PLUGIN_BRO_VERSION BRO_VERSION_FUNCTION
class ODesc;
class Func;
@ -93,16 +94,21 @@ public:
// strong hint.). The attribute seems generally available.
inline Configuration() __attribute__((always_inline));
/**
* One can assign BRO_PLUGIN_BRO_VERSION to this to catch
* version mismatches at link(!) time.
*/
const char* (*bro_version)();
private:
friend class Plugin;
int api_version; // Current BRO_PLUGIN_API_VERSION. Automatically set.
};
inline Configuration::Configuration()
{
name = "";
description = "";
api_version = BRO_PLUGIN_API_VERSION;
bro_version = BRO_PLUGIN_BRO_VERSION;
}
/**
@ -442,15 +448,6 @@ public:
**/
const std::string& PluginPath() const;
/**
* Returns the internal version of the Bro API that this plugin
* relies on. Only plugins that match Bro's current API version can
* be used. For statically compiled plugins this is automatically the
* case, but dynamically loaded plugins may cause a mismatch if they
* were compiled for a different Bro version.
*/
int APIVersion() const;
/**
* Returns a list of all components the plugin provides.
*/