From a21b697fec18cd07b0fadae323f3b54ebdc9c844 Mon Sep 17 00:00:00 2001 From: Philippe Antoine Date: Mon, 25 Nov 2024 16:33:00 +0100 Subject: [PATCH] plugin: versioning for API in app-layer plugins --- examples/plugins/zabbix/src/plugin.rs | 1 + examples/plugins/zabbix/src/suricata.rs | 1 + src/suricata-plugin.h | 5 +++++ src/util-plugin.c | 3 +++ 4 files changed, 10 insertions(+) diff --git a/examples/plugins/zabbix/src/plugin.rs b/examples/plugins/zabbix/src/plugin.rs index e66f852d8a80..2b0e5f9c6d9a 100644 --- a/examples/plugins/zabbix/src/plugin.rs +++ b/examples/plugins/zabbix/src/plugin.rs @@ -8,6 +8,7 @@ use crate::util::SCLog; extern "C" fn zabbix_plugin_init() { SCLog!(suricata::Level::Notice, "Initializing zabbix plugin"); let plugin = SCAppLayerPlugin { + version: 8, name: b"zabbix\0".as_ptr() as *const libc::c_char, logname: b"JsonZabbixLog\0".as_ptr() as *const libc::c_char, confname: b"eve-log.zabbix\0".as_ptr() as *const libc::c_char, diff --git a/examples/plugins/zabbix/src/suricata.rs b/examples/plugins/zabbix/src/suricata.rs index 4ef3a3a73ca9..0bebc36fb576 100644 --- a/examples/plugins/zabbix/src/suricata.rs +++ b/examples/plugins/zabbix/src/suricata.rs @@ -235,6 +235,7 @@ pub enum Level { #[repr(C)] #[allow(non_snake_case)] pub struct SCAppLayerPlugin { + pub version: u64, pub name: *const libc::c_char, pub Register: unsafe extern "C" fn(), pub KeywordsRegister: unsafe extern "C" fn(), diff --git a/src/suricata-plugin.h b/src/suricata-plugin.h index c13187e6ca0d..8bc2183d70fd 100644 --- a/src/suricata-plugin.h +++ b/src/suricata-plugin.h @@ -52,7 +52,12 @@ typedef struct SCCapturePlugin_ { int SCPluginRegisterCapture(SCCapturePlugin *); +// Every change in the API used by plugins should change this number +#define SC_PLUGIN_API_VERSION 8 + typedef struct SCAppLayerPlugin_ { + // versioning to check suricata/plugin API compatibility + uint64_t version; char *name; void (*Register)(void); void (*KeywordsRegister)(void); diff --git a/src/util-plugin.c b/src/util-plugin.c index f1720e7e3f9a..ebcaeace9dd3 100644 --- a/src/util-plugin.c +++ b/src/util-plugin.c @@ -156,6 +156,9 @@ SCCapturePlugin *SCPluginFindCaptureByName(const char *name) int SCPluginRegisterAppLayer(SCAppLayerPlugin *plugin) { + if (plugin->version != SC_PLUGIN_API_VERSION) { + return 1; + } AppProto alproto = AlprotoMax; AppProtoRegisterProtoString(alproto, plugin->name); if (plugin->Register) {