From: Jeff Lucovsky Date: Fri, 26 Mar 2021 12:16:57 +0000 (-0400) Subject: output/plugin: API changes for threaded support X-Git-Tag: suricata-7.0.0-beta1~1638 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=05836a445297308f0d2f59f67c43829791985ba0;p=thirdparty%2Fsuricata.git output/plugin: API changes for threaded support This commit extends the interface to better support file output plugins. --- diff --git a/src/output-json.c b/src/output-json.c index e356b6851e..610757c20d 100644 --- a/src/output-json.c +++ b/src/output-json.c @@ -1194,7 +1194,7 @@ OutputInitResult OutputJsonInitCtx(ConfNode *conf) ConfNode *plugin_conf = ConfNodeLookupChild(conf, json_ctx->plugin->name); void *plugin_data = NULL; - if (json_ctx->plugin->Open(plugin_conf, &plugin_data) < 0) { + if (json_ctx->plugin->Init(plugin_conf, false, &plugin_data) < 0) { LogFileFreeCtx(json_ctx->file_ctx); SCFree(json_ctx); SCFree(output_ctx); diff --git a/src/suricata-plugin.h b/src/suricata-plugin.h index c399640da4..e119bfdf02 100644 --- a/src/suricata-plugin.h +++ b/src/suricata-plugin.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2020 Open Information Security Foundation +/* Copyright (C) 2020-2021 Open Information Security Foundation * * You can copy, redistribute or modify this Program under the terms of * the GNU General Public License version 2 as published by the Free @@ -45,12 +45,22 @@ typedef struct SCPlugin_ { * Structure used to define a file type plugin. * * Currently only used by the Eve output type. + * + * name -- The plugin name. This name is used to identify the plugin: eve-log.filetype and in the + * plugins: section */ typedef struct SCPluginFileType_ { char *name; - int (*Open)(ConfNode *conf, void **data); - int (*Write)(const char *buffer, int buffer_len, void *ctx); - void (*Close)(void *ctx); + /* Init Called on first access */ + int (*Init)(ConfNode *conf, bool threaded, void **init_data); + /* Write - Called on each write to the object */ + int (*Write)(const char *buffer, int buffer_len, void *init_data, void *thread_data); + /* Close - Called on final close */ + void (*Deinit)(void *init_data); + /* ThreadInit - Called for each thread using file object*/ + int (*ThreadInit)(void *init_data, int thread_id, void **thread_data); + /* ThreadDeinit - Called for each thread using file object */ + int (*ThreadDeinit)(void *init_data, void *thread_data); TAILQ_ENTRY(SCPluginFileType_) entries; } SCPluginFileType; @@ -59,6 +69,8 @@ bool SCPluginRegisterFileType(SCPluginFileType *); typedef struct SCCapturePlugin_ { char *name; void (*Init)(const char *args, int plugin_slot, int receive_slot, int decode_slot); + int (*ThreadInit)(void *ctx, int thread_id, void **thread_ctx); + int (*ThreadDeinit)(void *ctx, void *thread_ctx); const char *(*GetDefaultMode)(void); TAILQ_ENTRY(SCCapturePlugin_) entries; } SCCapturePlugin; diff --git a/src/util-logopenfile.c b/src/util-logopenfile.c index 0899b8cf3b..952018d0c2 100644 --- a/src/util-logopenfile.c +++ b/src/util-logopenfile.c @@ -831,8 +831,8 @@ int LogFileFreeCtx(LogFileCtx *lf_ctx) SCFree(lf_ctx->threads); } else { if (lf_ctx->type == LOGFILE_TYPE_PLUGIN) { - if (lf_ctx->plugin->Close != NULL) { - lf_ctx->plugin->Close(lf_ctx->plugin_data); + if (lf_ctx->plugin->Deinit != NULL) { + lf_ctx->plugin->Deinit(lf_ctx->plugin_data); } } else if (lf_ctx->fp != NULL) { lf_ctx->Close(lf_ctx); @@ -889,7 +889,7 @@ int LogFileWrite(LogFileCtx *file_ctx, MemBuffer *buffer) #endif else if (file_ctx->type == LOGFILE_TYPE_PLUGIN) { file_ctx->plugin->Write((const char *)MEMBUFFER_BUFFER(buffer), - MEMBUFFER_OFFSET(buffer), file_ctx->plugin_data); + MEMBUFFER_OFFSET(buffer), file_ctx->plugin_data, NULL); } return 0;