suricata
output-eve.c
Go to the documentation of this file.
1/* Copyright (C) 2024 Open Information Security Foundation
2 *
3 * You can copy, redistribute or modify this Program under the terms of
4 * the GNU General Public License version 2 as published by the Free
5 * Software Foundation.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 *
12 * You should have received a copy of the GNU General Public License
13 * version 2 along with this program; if not, write to the Free Software
14 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
15 * 02110-1301, USA.
16 */
17
18#include "suricata-common.h"
19#include "output-eve.h"
20#include "util-debug.h"
21#include "rust.h"
22
28
29static EveUserCallback *eve_user_callbacks = NULL;
30
31static TAILQ_HEAD(, SCEveFileType_) output_types = TAILQ_HEAD_INITIALIZER(output_types);
32
34{
35 EveUserCallback *cb = SCCalloc(1, sizeof(*cb));
36 if (cb == NULL) {
37 return false;
38 }
39 cb->Callback = fn;
40 cb->user = user;
41 if (eve_user_callbacks == NULL) {
42 eve_user_callbacks = cb;
43 } else {
44 EveUserCallback *current = eve_user_callbacks;
45 while (current->next != NULL) {
46 current = current->next;
47 }
48 current->next = cb;
49 }
50 return true;
51}
52
53void SCEveRunCallbacks(ThreadVars *tv, const Packet *p, Flow *f, SCJsonBuilder *jb)
54{
55 EveUserCallback *cb = eve_user_callbacks;
56 while (cb != NULL) {
57 cb->Callback(tv, p, f, jb, cb->user);
58 cb = cb->next;
59 }
60}
61
62static bool IsBuiltinTypeName(const char *name)
63{
64 const char *builtin[] = {
65 "regular",
66 "unix_dgram",
67 "unix_stream",
68 "redis",
69 NULL,
70 };
71 for (int i = 0;; i++) {
72 if (builtin[i] == NULL) {
73 break;
74 }
75 if (strcmp(builtin[i], name) == 0) {
76 return true;
77 }
78 }
79 return false;
80}
81
83{
84 SCEveFileType *plugin = NULL;
85 TAILQ_FOREACH (plugin, &output_types, entries) {
86 if (strcmp(name, plugin->name) == 0) {
87 return plugin;
88 }
89 }
90 return NULL;
91}
92
93/**
94 * \brief Register an Eve file type.
95 *
96 * \retval true if registered successfully, false if the file type name
97 * conflicts with a built-in or previously registered
98 * file type.
99 */
101{
102 /* First check that the name doesn't conflict with a built-in filetype. */
103 if (IsBuiltinTypeName(plugin->name)) {
104 SCLogError("Eve file type name conflicts with built-in type: %s", plugin->name);
105 return false;
106 }
107
108 /* Now check against previously registered file types. */
109 SCEveFileType *existing = NULL;
110 TAILQ_FOREACH (existing, &output_types, entries) {
111 if (strcmp(existing->name, plugin->name) == 0) {
112 SCLogError("Eve file type name conflicts with previously registered type: %s",
113 plugin->name);
114 return false;
115 }
116 }
117
118 SCLogDebug("Registering EVE file type plugin %s", plugin->name);
119 TAILQ_INSERT_TAIL(&output_types, plugin, entries);
120 return true;
121}
ThreadVars * tv
void SCEveRunCallbacks(ThreadVars *tv, const Packet *p, Flow *f, SCJsonBuilder *jb)
Definition output-eve.c:53
SCEveFileType * SCEveFindFileType(const char *name)
Definition output-eve.c:82
bool SCRegisterEveFileType(SCEveFileType *plugin)
Register an Eve file type.
Definition output-eve.c:100
struct EveUserCallback_ EveUserCallback
EVE logging subsystem.
void(* SCEveUserCallbackFn)(ThreadVars *tv, const Packet *p, Flow *f, SCJsonBuilder *jb, void *user)
Function type for EVE callbacks.
Definition output-eve.h:190
bool SCEveRegisterCallback(SCEveUserCallbackFn fn, void *user)
Register a callback for adding extra information to EVE logs.
#define TAILQ_FOREACH(var, head, field)
Definition queue.h:252
#define TAILQ_HEAD(name, type)
Definition queue.h:230
#define TAILQ_INSERT_TAIL(head, elm, field)
Definition queue.h:294
#define TAILQ_HEAD_INITIALIZER(head)
Definition queue.h:236
SCEveUserCallbackFn Callback
Definition output-eve.c:24
struct EveUserCallback_ * next
Definition output-eve.c:26
Flow data structure.
Definition flow.h:356
Structure used to define an EVE output file type plugin.
Definition output-eve.h:74
const char * name
The name of the output, used in the configuration.
Definition output-eve.h:89
Per thread variable structure.
Definition threadvars.h:58
const char * name
#define SCLogDebug(...)
Definition util-debug.h:275
#define SCLogError(...)
Macro used to log ERROR messages.
Definition util-debug.h:267
#define SCCalloc(nm, sz)
Definition util-mem.h:53