Skip to content

Commit

Permalink
plugin: versioning for API in app-layer plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
catenacyber committed Dec 10, 2024
1 parent ea628a6 commit a21b697
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 0 deletions.
1 change: 1 addition & 0 deletions examples/plugins/zabbix/src/plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions examples/plugins/zabbix/src/suricata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
5 changes: 5 additions & 0 deletions src/suricata-plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 3 additions & 0 deletions src/util-plugin.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit a21b697

Please sign in to comment.