From 3ff72d3efa3eb717e5e6794a96d04266311e1fc2 Mon Sep 17 00:00:00 2001 From: Jason Ish Date: Thu, 7 Mar 2024 16:01:48 -0600 Subject: [PATCH] eve: rename plugin to filetypes EVE filetypes are not always plugins, for example, null and syslog that are built-in filetypes. --- src/output-json.c | 16 ++++++++-------- src/output-json.h | 4 +--- src/util-logopenfile.c | 28 +++++++++++++++------------- src/util-logopenfile.h | 12 ++++++------ 4 files changed, 30 insertions(+), 30 deletions(-) diff --git a/src/output-json.c b/src/output-json.c index ab46abb14b..830027cb02 100644 --- a/src/output-json.c +++ b/src/output-json.c @@ -1008,7 +1008,7 @@ static int LogFileTypePrepare( } } #endif - else if (log_filetype == LOGFILE_TYPE_PLUGIN) { + else if (log_filetype == LOGFILE_TYPE_FILETYPE) { if (json_ctx->file_ctx->threaded) { /* Prepare for threaded log output. */ if (!SCLogOpenThreadedFile(NULL, NULL, json_ctx->file_ctx)) { @@ -1016,11 +1016,11 @@ static int LogFileTypePrepare( } } void *init_data = NULL; - if (json_ctx->plugin->Init(conf, json_ctx->file_ctx->threaded, &init_data) < 0) { + if (json_ctx->filetype->Init(conf, json_ctx->file_ctx->threaded, &init_data) < 0) { return -1; } - json_ctx->file_ctx->plugin.plugin = json_ctx->plugin; - json_ctx->file_ctx->plugin.init_data = init_data; + json_ctx->file_ctx->filetype.filetype = json_ctx->filetype; + json_ctx->file_ctx->filetype.init_data = init_data; } return 0; @@ -1085,10 +1085,10 @@ OutputInitResult OutputJsonInitCtx(ConfNode *conf) enum LogFileType log_filetype = FileTypeFromConf(output_s); if (log_filetype == LOGFILE_TYPE_NOTSET) { - SCEveFileType *plugin = SCEveFindFileType(output_s); - if (plugin != NULL) { - log_filetype = LOGFILE_TYPE_PLUGIN; - json_ctx->plugin = plugin; + SCEveFileType *filetype = SCEveFindFileType(output_s); + if (filetype != NULL) { + log_filetype = LOGFILE_TYPE_FILETYPE; + json_ctx->filetype = filetype; } else FatalError("Invalid JSON output option: %s", output_s); } diff --git a/src/output-json.h b/src/output-json.h index 961e1204c5..531740b2cd 100644 --- a/src/output-json.h +++ b/src/output-json.h @@ -28,10 +28,8 @@ #include "util-buffer.h" #include "util-logopenfile.h" #include "output.h" -#include "rust.h" #include "app-layer-htp-xff.h" -#include "suricata-plugin.h" void OutputJsonRegister(void); @@ -83,7 +81,7 @@ typedef struct OutputJsonCtx_ { enum LogFileType json_out; OutputJsonCommonSettings cfg; HttpXFFCfg *xff_cfg; - SCEveFileType *plugin; + SCEveFileType *filetype; } OutputJsonCtx; typedef struct OutputJsonThreadCtx_ { diff --git a/src/util-logopenfile.c b/src/util-logopenfile.c index 24dfcc4ff7..5675b145be 100644 --- a/src/util-logopenfile.c +++ b/src/util-logopenfile.c @@ -833,12 +833,12 @@ static bool LogFileNewThreadedCtx(LogFileCtx *parent_ctx, const char *log_path, thread->Write = SCLogFileWriteNoLock; thread->Close = SCLogFileCloseNoLock; OutputRegisterFileRotationFlag(&thread->rotation_flag); - } else if (parent_ctx->type == LOGFILE_TYPE_PLUGIN) { + } else if (parent_ctx->type == LOGFILE_TYPE_FILETYPE) { entry->slot_number = SC_ATOMIC_ADD(eve_file_id, 1); SCLogDebug("%s - thread %d [slot %d]", log_path, entry->internal_thread_id, entry->slot_number); - thread->plugin.plugin->ThreadInit( - thread->plugin.init_data, entry->internal_thread_id, &thread->plugin.thread_data); + thread->filetype.filetype->ThreadInit(thread->filetype.init_data, entry->internal_thread_id, + &thread->filetype.thread_data); } thread->threaded = false; thread->parent = parent_ctx; @@ -871,8 +871,9 @@ int LogFileFreeCtx(LogFileCtx *lf_ctx) SCReturnInt(0); } - if (lf_ctx->type == LOGFILE_TYPE_PLUGIN && lf_ctx->parent != NULL) { - lf_ctx->plugin.plugin->ThreadDeinit(lf_ctx->plugin.init_data, lf_ctx->plugin.thread_data); + if (lf_ctx->type == LOGFILE_TYPE_FILETYPE && lf_ctx->parent != NULL) { + lf_ctx->filetype.filetype->ThreadDeinit( + lf_ctx->filetype.init_data, lf_ctx->filetype.thread_data); } if (lf_ctx->threaded) { @@ -885,7 +886,7 @@ int LogFileFreeCtx(LogFileCtx *lf_ctx) } SCFree(lf_ctx->threads); } else { - if (lf_ctx->type != LOGFILE_TYPE_PLUGIN) { + if (lf_ctx->type != LOGFILE_TYPE_FILETYPE) { if (lf_ctx->fp != NULL) { lf_ctx->Close(lf_ctx); } @@ -908,11 +909,11 @@ int LogFileFreeCtx(LogFileCtx *lf_ctx) OutputUnregisterFileRotationFlag(&lf_ctx->rotation_flag); } - /* Deinitialize output plugins. We only want to call this for the - * parent of threaded output, or always for non-threaded + /* Deinitialize output filetypes. We only want to call this for + * the parent of threaded output, or always for non-threaded * output. */ - if (lf_ctx->type == LOGFILE_TYPE_PLUGIN && lf_ctx->parent == NULL) { - lf_ctx->plugin.plugin->Deinit(lf_ctx->plugin.init_data); + if (lf_ctx->type == LOGFILE_TYPE_FILETYPE && lf_ctx->parent == NULL) { + lf_ctx->filetype.filetype->Deinit(lf_ctx->filetype.init_data); } memset(lf_ctx, 0, sizeof(*lf_ctx)); @@ -929,9 +930,10 @@ int LogFileWrite(LogFileCtx *file_ctx, MemBuffer *buffer) MemBufferWriteString(buffer, "\n"); file_ctx->Write((const char *)MEMBUFFER_BUFFER(buffer), MEMBUFFER_OFFSET(buffer), file_ctx); - } else if (file_ctx->type == LOGFILE_TYPE_PLUGIN) { - file_ctx->plugin.plugin->Write((const char *)MEMBUFFER_BUFFER(buffer), - MEMBUFFER_OFFSET(buffer), file_ctx->plugin.init_data, file_ctx->plugin.thread_data); + } else if (file_ctx->type == LOGFILE_TYPE_FILETYPE) { + file_ctx->filetype.filetype->Write((const char *)MEMBUFFER_BUFFER(buffer), + MEMBUFFER_OFFSET(buffer), file_ctx->filetype.init_data, + file_ctx->filetype.thread_data); } #ifdef HAVE_LIBHIREDIS else if (file_ctx->type == LOGFILE_TYPE_REDIS) { diff --git a/src/util-logopenfile.h b/src/util-logopenfile.h index f3ab81565a..5e2fd327d3 100644 --- a/src/util-logopenfile.h +++ b/src/util-logopenfile.h @@ -33,7 +33,6 @@ #include "util-log-redis.h" #endif /* HAVE_LIBHIREDIS */ -#include "suricata-plugin.h" #include "output-eve.h" enum LogFileType { @@ -41,7 +40,8 @@ enum LogFileType { LOGFILE_TYPE_UNIX_DGRAM, LOGFILE_TYPE_UNIX_STREAM, LOGFILE_TYPE_REDIS, - LOGFILE_TYPE_PLUGIN, + /** New style or modular filetypes. */ + LOGFILE_TYPE_FILETYPE, LOGFILE_TYPE_NOTSET }; @@ -66,11 +66,11 @@ typedef struct LogThreadedFileCtx_ { char *append; } LogThreadedFileCtx; -typedef struct LogFilePluginCtx_ { - SCEveFileType *plugin; +typedef struct LogFileTypeCtx_ { + SCEveFileType *filetype; void *init_data; void *thread_data; -} LogFilePluginCtx; +} LogFileTypeCtx; /** Global structure for Output Context */ typedef struct LogFileCtx_ { @@ -91,7 +91,7 @@ typedef struct LogFileCtx_ { int (*Write)(const char *buffer, int buffer_len, struct LogFileCtx_ *fp); void (*Close)(struct LogFileCtx_ *fp); - LogFilePluginCtx plugin; + LogFileTypeCtx filetype; /** It will be locked if the log/alert * record cannot be written to the file in one call */ -- 2.47.2