-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
eve-filetypes: separate from plugins, as eve filetypes are not plugins: plugins can register eve filetypes - v1 #10591
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
/* Copyright (C) 2024 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 | ||
* Software Foundation. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* version 2 along with this program; if not, write to the Free Software | ||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA | ||
* 02110-1301, USA. | ||
*/ | ||
|
||
#include "output-eve.h" | ||
#include "util-debug.h" | ||
|
||
static TAILQ_HEAD(, SCEveFileType_) output_types = TAILQ_HEAD_INITIALIZER(output_types); | ||
|
||
static bool IsBuiltinTypeName(const char *name) | ||
{ | ||
const char *builtin[] = { | ||
"regular", | ||
"unix_dgram", | ||
"unix_stream", | ||
"redis", | ||
NULL, | ||
}; | ||
for (int i = 0;; i++) { | ||
if (builtin[i] == NULL) { | ||
break; | ||
} | ||
if (strcmp(builtin[i], name) == 0) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
|
||
SCEveFileType *SCEveFindFileType(const char *name) | ||
{ | ||
SCEveFileType *plugin = NULL; | ||
TAILQ_FOREACH (plugin, &output_types, entries) { | ||
if (strcmp(name, plugin->name) == 0) { | ||
return plugin; | ||
} | ||
} | ||
return NULL; | ||
} | ||
|
||
/** | ||
* \brief Register an Eve file type. | ||
* | ||
* \retval true if registered successfully, false if the file type name | ||
* conflicts with a built-in or previously registered | ||
* file type. | ||
*/ | ||
bool SCRegisterEveFileType(SCEveFileType *plugin) | ||
{ | ||
/* First check that the name doesn't conflict with a built-in filetype. */ | ||
if (IsBuiltinTypeName(plugin->name)) { | ||
SCLogError("Eve file type name conflicts with built-in type: %s", plugin->name); | ||
return false; | ||
} | ||
|
||
/* Now check against previously registered file types. */ | ||
SCEveFileType *existing = NULL; | ||
TAILQ_FOREACH (existing, &output_types, entries) { | ||
if (strcmp(existing->name, plugin->name) == 0) { | ||
SCLogError("Eve file type name conflicts with previously registered type: %s", | ||
plugin->name); | ||
return false; | ||
} | ||
} | ||
|
||
SCLogDebug("Registering EVE file type plugin %s", plugin->name); | ||
TAILQ_INSERT_TAIL(&output_types, plugin, entries); | ||
return true; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/* Copyright (C) 2024 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 | ||
* Software Foundation. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* version 2 along with this program; if not, write to the Free Software | ||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA | ||
* 02110-1301, USA. | ||
*/ | ||
|
||
/** | ||
* \file | ||
* | ||
* \brief EVE logging subsystem | ||
* | ||
* This file will attempt to the main module for EVE logging | ||
* sub-system. Currently most of the API resides in output-json.[ch], | ||
* but due to some circular dependencies between EVE, and LogFileCtx, | ||
* it made it hard to add EVE filetype modules there until some | ||
* include issues are figured out. | ||
*/ | ||
|
||
#ifndef __SURICATA_OUTPUT_EVE_H__ | ||
#define __SURICATA_OUTPUT_EVE_H__ | ||
|
||
#include "suricata-common.h" | ||
#include "conf.h" | ||
|
||
/** | ||
* Structure used to define an Eve output file type plugin. | ||
*/ | ||
typedef struct SCEveFileType_ { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. would be nice to tighten the function signatures a bit, esp with adding const where appropriate There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. DIdn't want to change or break the API with this PR, I have some breaking changes coming for 8.0 that hopefully make it easier, that would be where to change the signatures. |
||
/* The name of the output, used to specify the output in the filetype section | ||
* of the eve-log configuration. */ | ||
const char *name; | ||
/* 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(SCEveFileType_) entries; | ||
} SCEveFileType; | ||
|
||
bool SCRegisterEveFileType(SCEveFileType *); | ||
|
||
SCEveFileType *SCEveFindFileType(const char *name); | ||
|
||
#endif |
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we combine the I think that Thoughts? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The only catch here is that the filetypes don't require anything from the engine, but the captures do, at least now -- the "slot" they fit into. So capture plugins need that extra hook from the engine that file types do not. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,8 +20,7 @@ | |
|
||
#include <stdint.h> | ||
#include <stdbool.h> | ||
|
||
#include "conf.h" | ||
#include <queue.h> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is this meant to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, oops. |
||
|
||
/** | ||
* The size of the data chunk inside each packet structure a plugin | ||
|
@@ -41,28 +40,6 @@ typedef struct SCPlugin_ { | |
|
||
typedef SCPlugin *(*SCPluginRegisterFunc)(void); | ||
|
||
/** | ||
* Structure used to define an Eve output file type plugin. | ||
*/ | ||
typedef struct SCEveFileType_ { | ||
/* The name of the output, used to specify the output in the filetype section | ||
* of the eve-log configuration. */ | ||
const char *name; | ||
/* 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(SCEveFileType_) entries; | ||
} SCEveFileType; | ||
|
||
bool SCRegisterEveFileType(SCEveFileType *); | ||
|
||
typedef struct SCCapturePlugin_ { | ||
char *name; | ||
void (*Init)(const char *args, int plugin_slot, int receive_slot, int decode_slot); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,6 +25,7 @@ | |
#define __UTIL_EBPF_H__ | ||
|
||
#include "flow-bypass.h" | ||
#include "conf.h" | ||
|
||
#ifdef HAVE_PACKET_EBPF | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why SURICATA part of the define here? We normally only base on the file name
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As an include that is part of the library, it should be name spaced as well.
__OUTPUT_EVE_H__
is probably not that generic, but something simpler like__OUTPUT_H__
is more generic with a higher chance of conflicting with a user header.LibHTP, libcurl, etc. all do this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should this type of change go into the whole codebase? Perhaps as a separate change/commit?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm somewhat indifferent here as its not an introducer of merge conflicts like some other changes we have discussed would be. But would be nice I guess, should we also remove the leading double underscores (and trailing) as they are in reserved namespace?