plugins: check version for all plugins

pull/12862/head
Philippe Antoine 8 months ago committed by Victor Julien
parent 5742df3783
commit c164cfcf6b

@ -118,7 +118,10 @@ static void Init(void)
}
const SCPlugin PluginRegistration = {
.version = SC_API_VERSION,
.suricata_version = SC_PACKAGE_VERSION,
.name = "CustomLogger",
.plugin_version = "1.0.0",
.author = "Firstname Lastname",
.license = "GPLv2",
.Init = Init,

@ -206,7 +206,10 @@ void PluginInit(void)
}
const SCPlugin PluginRegistration = {
.version = SC_API_VERSION,
.suricata_version = SC_PACKAGE_VERSION,
.name = FILETYPE_NAME,
.plugin_version = "0.1.0",
.author = "FirstName LastName <name@example.org>",
.license = "GPL-2.0-only",
.Init = PluginInit,

@ -44,7 +44,10 @@ static void SCPluginInit(void)
}
const SCPlugin PluginRegistration = {
.version = SC_API_VERSION,
.suricata_version = SC_PACKAGE_VERSION,
.name = "ci-capture",
.plugin_version = "0.1.0",
.author = "OISF Developer",
.license = "GPL-2.0-only",
.Init = SCPluginInit,

@ -44,7 +44,10 @@ void SCPluginInit(void)
}
const SCPlugin PluginRegistration = {
.version = SC_API_VERSION,
.suricata_version = SC_PACKAGE_VERSION,
.name = "napatech",
.plugin_version = "1.0.0",
.author = "Open Information Security Foundation",
.license = "GPLv2",
.Init = SCPluginInit,

@ -44,7 +44,10 @@ void SCPluginInit(void)
}
const SCPlugin PluginRegistration = {
.version = SC_API_VERSION,
.suricata_version = SC_PACKAGE_VERSION,
.name = "pfring",
.plugin_version = "1.0.0",
.author = "Open Information Security Foundation",
.license = "GPLv2",
.Init = SCPluginInit,

@ -1,5 +1,6 @@
// This file is automatically generated. Do not edit.
pub const SC_PACKAGE_VERSION: &[u8; 10] = b"8.0.0-dev\0";
#[repr(u32)]
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
pub enum AppProtoEnum {
@ -54,11 +55,15 @@ extern "C" {
alproto: AppProto, proto_name: *const ::std::os::raw::c_char,
);
}
pub const SC_API_VERSION: u64 = 2048;
#[doc = " Structure to define a Suricata plugin."]
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct SCPlugin_ {
pub version: u64,
pub suricata_version: *const ::std::os::raw::c_char,
pub name: *const ::std::os::raw::c_char,
pub plugin_version: *const ::std::os::raw::c_char,
pub license: *const ::std::os::raw::c_char,
pub author: *const ::std::os::raw::c_char,
pub Init: ::std::option::Option<unsafe extern "C" fn()>,
@ -105,11 +110,9 @@ pub type SCCapturePlugin = SCCapturePlugin_;
extern "C" {
pub fn SCPluginRegisterCapture(arg1: *mut SCCapturePlugin) -> ::std::os::raw::c_int;
}
pub const SC_PLUGIN_API_VERSION: u64 = 8;
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct SCAppLayerPlugin_ {
pub version: u64,
pub name: *const ::std::os::raw::c_char,
pub Register: ::std::option::Option<unsafe extern "C" fn()>,
pub KeywordsRegister: ::std::option::Option<unsafe extern "C" fn()>,

@ -22,6 +22,7 @@
#include <stdbool.h>
#include "queue.h"
#include "autoconf.h"
/**
* The size of the data chunk inside each packet structure a plugin
@ -29,11 +30,20 @@
*/
#define PLUGIN_VAR_SIZE 64
// Do not reuse autoconf PACKAGE_VERSION which is a string
// Defined as major version.minor version (no patch version)
static const uint64_t SC_API_VERSION = 0x0800;
#define SC_PACKAGE_VERSION PACKAGE_VERSION
/**
* Structure to define a Suricata plugin.
*/
typedef struct SCPlugin_ {
// versioning to check suricata/plugin API compatibility
uint64_t version;
const char *suricata_version;
const char *name;
const char *plugin_version;
const char *license;
const char *author;
void (*Init)(void);
@ -52,12 +62,7 @@ typedef struct SCCapturePlugin_ {
int SCPluginRegisterCapture(SCCapturePlugin *);
// Every change in the API used by plugins should change this number
static const uint64_t SC_PLUGIN_API_VERSION = 8;
typedef struct SCAppLayerPlugin_ {
// versioning to check suricata/plugin API compatibility
uint64_t version;
const char *name;
void (*Register)(void);
void (*KeywordsRegister)(void);

@ -50,6 +50,12 @@ static TAILQ_HEAD(, SCCapturePlugin_) capture_plugins = TAILQ_HEAD_INITIALIZER(c
bool RegisterPlugin(SCPlugin *plugin, void *lib)
{
if (plugin->version != SC_API_VERSION) {
SCLogError("Suricata and plugin versions differ: plugin has %" PRIx64
" (%s) vs Suricata %" PRIx64 " (plugin was built with %s)",
plugin->version, plugin->plugin_version, SC_API_VERSION, plugin->suricata_version);
return false;
}
BUG_ON(plugin->name == NULL);
BUG_ON(plugin->author == NULL);
BUG_ON(plugin->license == NULL);
@ -63,8 +69,9 @@ bool RegisterPlugin(SCPlugin *plugin, void *lib)
node->plugin = plugin;
node->lib = lib;
TAILQ_INSERT_TAIL(&plugins, node, entries);
SCLogNotice("Initializing plugin %s; author=%s; license=%s", plugin->name, plugin->author,
plugin->license);
SCLogNotice("Initializing plugin %s; version= %s; author=%s; license=%s; built from %s",
plugin->name, plugin->plugin_version, plugin->author, plugin->license,
plugin->suricata_version);
(*plugin->Init)();
return true;
}
@ -156,9 +163,6 @@ SCCapturePlugin *SCPluginFindCaptureByName(const char *name)
int SCPluginRegisterAppLayer(SCAppLayerPlugin *plugin)
{
if (plugin->version != SC_PLUGIN_API_VERSION) {
return 1;
}
AppProto alproto = g_alproto_max;
AppProtoRegisterProtoString(alproto, plugin->name);
if (plugin->Register) {

Loading…
Cancel
Save