]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
plugins: check version for all plugins
authorPhilippe Antoine <pantoine@oisf.net>
Thu, 6 Mar 2025 13:15:27 +0000 (14:15 +0100)
committerVictor Julien <victor@inliniac.net>
Sat, 29 Mar 2025 05:38:00 +0000 (06:38 +0100)
examples/plugins/c-custom-loggers/custom-logger.c
examples/plugins/c-json-filetype/filetype.c
examples/plugins/ci-capture/plugin.c
plugins/napatech/plugin.c
plugins/pfring/plugin.c
rust/sys/src/sys.rs
src/suricata-plugin.h
src/util-plugin.c

index d533b8830dec28b46708c4ecd94f43e6576d3a0b..c74066faf83d1152e341fa083f33a4ea3e80631e 100644 (file)
@@ -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,
index a66b9779dfb3161e3c28e15f238d9a1bd1d2d1d7..ad60b2e59b0a7f0981623fb8143932a740234433 100644 (file)
@@ -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,
index 26a2a749ef5d97b91b12e821270922e5bcca80b4..5bcf3c19113b0589d836947969e02e82e5a21687 100644 (file)
@@ -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,
index 71631bf7f93ba8a690d1a8199a4aec83fccff7a8..d3104d5cc72dca0f3cbd61af2a378f9f72a485e0 100644 (file)
@@ -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,
index 0f41ee45fdb749a18df800544c3ae79a16f8792e..145f8f440cdadf5707ddd228bd5186d9561a5d37 100644 (file)
@@ -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,
index 057d566f1847c6806c0b1e2a82d5429612a4b452..cadf3de72591e6633440988fb7443e4463adadc4 100644 (file)
@@ -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()>,
index fbc4979611e6b50b7ff6618b992fd0f80172baf8..7c51fef6330a0c887891e0f0721a44a3925848d7 100644 (file)
@@ -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
  */
 #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);
index eb2ce7647e66d4c1be1d22b87d8ccd2006d95950..ed534f247000edc1a7b1ece0b952250f1492a57d 100644 (file)
@@ -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) {