suricata
output-eve-bindgen.h
Go to the documentation of this file.
1 /* Copyright (C) 2025 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 /**
19  * \file
20  *
21  * This file contains definitions that should be made available
22  * to rust via bindgen.
23  *
24  */
25 
26 #ifndef SURICATA_OUTPUT_EVE_BINDGEN_H
27 #define SURICATA_OUTPUT_EVE_BINDGEN_H
28 
29 #include "app-layer-protos.h"
30 
31 typedef uint32_t ThreadId;
32 
39 
40 typedef bool (*EveJsonSimpleTxLogFunc)(const void *, void *);
41 
44  const char *name;
46 
48 
50  const char *confname;
51  const char *logname;
53  uint8_t dir;
56 
58 
59 /** \brief Function type for EVE file-type initialization. */
60 typedef int (*SCEveFileTypeInitFunc)(const SCConfNode *conf, const bool threaded, void **init_data);
61 
62 /** \brief Function type for EVE file-type thread initialization. */
64  const void *init_data, const ThreadId thread_id, void **thread_data);
65 
66 /** \brief Function type for EVE file-type writes. */
67 typedef int (*SCEveFileTypeWriteFunc)(
68  const char *buffer, const int buffer_len, const void *init_data, void *thread_data);
69 
70 /** \brief Function type for EVE file-type thread deinitialization. */
71 typedef void (*SCEveFileTypeThreadDeinitFunc)(const void *init_data, void *thread_data);
72 
73 /** \brief Function type for EVE file-type deinitialization. */
74 typedef void (*SCEveFileTypeDeinitFunc)(void *init_data);
75 
76 /** \brief Structure used to define an EVE output file type.
77  *
78  * EVE filetypes implement an object with a file-like interface and
79  * are used to output EVE log records to files, syslog, or
80  * database. They can be built-in such as the syslog (see
81  * SyslogInitialize()) and nullsink (see NullLogInitialize()) outputs,
82  * registered by a library user or dynamically loaded as a plugin.
83  *
84  * The life cycle of an EVE filetype is:
85  * - Init: called once for each EVE instance using this filetype
86  * - ThreadInit: called once for each output thread
87  * - Write: called for each log record
88  * - ThreadDeinit: called once for each output thread on exit
89  * - Deinit: called once for each EVE instance using this filetype on exit
90  *
91  * Examples:
92  * - built-in syslog: \ref src/output-eve-syslog.c
93  * - built-in nullsink: \ref src/output-eve-null.c
94  * - example plugin: \ref examples/plugins/c-json-filetype/filetype.c
95  *
96  * ### Multi-Threaded Note:
97  *
98  * The EVE logging system can be configured by the Suricata user to
99  * run in threaded or non-threaded modes. In the default non-threaded
100  * mode, ThreadInit will only be called once and the filetype does not
101  * need to be concerned with threads.
102  *
103  * However, in **threaded** mode, ThreadInit will be called multiple
104  * times and the filetype needs to be thread aware and thread-safe. If
105  * utilizing a unique resource such as a file for each thread then you
106  * may be naturally thread safe. However, if sharing a single file
107  * handle across all threads then your filetype will have to take care
108  * of locking, etc.
109  */
110 typedef struct SCEveFileType_ {
111  /**
112  * \brief The name of the output, used in the configuration.
113  *
114  * This name is used by the configuration file to specify the EVE
115  * filetype used.
116  *
117  * For example:
118  *
119  * \code{.yaml}
120  * outputs:
121  * - eve-log:
122  * filetype: my-output-name
123  * \endcode
124  */
125  const char *name;
126 
127  /**
128  * \brief Function to initialize this filetype.
129  *
130  * \param conf The ConfNode of the `eve-log` configuration
131  * section this filetype is being initialized for
132  *
133  * \param threaded Flag to specify if the EVE sub-systems is in
134  * threaded mode or not
135  *
136  * \param init_data An output pointer for filetype specific data
137  *
138  * \retval 0 on success, -1 on failure
139  */
141 
142  /**
143  * \brief Initialize thread specific data.
144  *
145  * Initialize any thread specific data. For example, if
146  * implementing a file output you might open the files here, so
147  * you have one output file per thread.
148  *
149  * \param init_data Data setup during Init
150  *
151  * \param thread_id A unique ID to differentiate this thread from
152  * others. If EVE is not in threaded mode this will be called
153  * once with a ThreadId of 0. In threaded mode the ThreadId of
154  * 0 correlates to the main Suricata thread.
155  *
156  * \param thread_data Output pointer for any data required by this
157  * thread.
158  *
159  * \retval 0 on success, -1 on failure
160  */
162 
163  /**
164  * \brief Called for each EVE log record.
165  *
166  * The Write function is called for each log EVE log record. The
167  * provided buffer contains a fully formatted EVE record in JSON
168  * format.
169  *
170  * \param buffer The fully formatted JSON EVE log record
171  *
172  * \param buffer_len The length of the buffer
173  *
174  * \param init_data The data setup in the call to Init
175  *
176  * \param thread_data The data setup in the call to ThreadInit
177  *
178  * \retval 0 on success, -1 on failure
179  */
181 
182  /**
183  * \brief Called to deinitialize each thread.
184  *
185  * This function will be called for each thread. It is where any
186  * resources allocated in ThreadInit should be released.
187  *
188  * \param init_data The data setup in Init
189  *
190  * \param thread_data The data setup in ThreadInit
191  */
193 
194  /**
195  * \brief Final call to deinitialize this filetype.
196  *
197  * Called, usually on exit to deinitialize and free any resources
198  * allocated during Init.
199  *
200  * \param init_data Data setup in the call to Init.
201  */
203 
204  /* Internal list management. */
207 
209 
210 #endif /* ! SURICATA_OUTPUT_EVE_BINDGEN_H */
SCOutputJsonLogDirection
SCOutputJsonLogDirection
Definition: output-eve-bindgen.h:33
SCEveFileType_::Deinit
SCEveFileTypeDeinitFunc Deinit
Final call to deinitialize this filetype.
Definition: output-eve-bindgen.h:202
SCEveFileTypeWriteFunc
int(* SCEveFileTypeWriteFunc)(const char *buffer, const int buffer_len, const void *init_data, void *thread_data)
Function type for EVE file-type writes.
Definition: output-eve-bindgen.h:67
EveJsonTxLoggerRegistrationData::LogTx
EveJsonSimpleTxLogFunc LogTx
Definition: output-eve-bindgen.h:54
SCEveFileType_::Write
SCEveFileTypeWriteFunc Write
Called for each EVE log record.
Definition: output-eve-bindgen.h:180
AppProto
uint16_t AppProto
Definition: app-layer-protos.h:86
SCEveFileTypeInitFunc
int(* SCEveFileTypeInitFunc)(const SCConfNode *conf, const bool threaded, void **init_data)
Function type for EVE file-type initialization.
Definition: output-eve-bindgen.h:60
LOG_DIR_FLOW_TOSERVER
@ LOG_DIR_FLOW_TOSERVER
Definition: output-eve-bindgen.h:37
EveJsonTxLoggerRegistrationData::dir
uint8_t dir
Definition: output-eve-bindgen.h:53
SCEveFileType_::ThreadDeinit
SCEveFileTypeThreadDeinitFunc ThreadDeinit
Called to deinitialize each thread.
Definition: output-eve-bindgen.h:192
SCEveFileType_::ThreadInit
SCEveFileTypeThreadInitFunc ThreadInit
Initialize thread specific data.
Definition: output-eve-bindgen.h:161
EveJsonTxLoggerRegistrationData::alproto
AppProto alproto
Definition: output-eve-bindgen.h:52
SCRegisterEveFileType
bool SCRegisterEveFileType(SCEveFileType *)
Register an Eve file type.
Definition: output-eve.c:100
SCEveFileType_::Init
SCEveFileTypeInitFunc Init
Function to initialize this filetype.
Definition: output-eve-bindgen.h:140
SCEveFileType
struct SCEveFileType_ SCEveFileType
Structure used to define an EVE output file type.
LOG_DIR_FLOW
@ LOG_DIR_FLOW
Definition: output-eve-bindgen.h:35
SCEveJsonSimpleGetLogger
EveJsonSimpleAppLayerLogger * SCEveJsonSimpleGetLogger(AppProto alproto)
Definition: output.c:930
EveJsonTxLoggerRegistrationData
Definition: output-eve-bindgen.h:49
SCEveFileType_::name
const char * name
The name of the output, used in the configuration.
Definition: output-eve-bindgen.h:125
SCEveFileTypeDeinitFunc
void(* SCEveFileTypeDeinitFunc)(void *init_data)
Function type for EVE file-type deinitialization.
Definition: output-eve-bindgen.h:74
EveJsonSimpleAppLayerLogger
Definition: output-eve-bindgen.h:42
EveJsonTxLoggerRegistrationData::logname
const char * logname
Definition: output-eve-bindgen.h:51
EveJsonSimpleAppLayerLogger::LogTx
EveJsonSimpleTxLogFunc LogTx
Definition: output-eve-bindgen.h:43
SCEveFileTypeThreadInitFunc
int(* SCEveFileTypeThreadInitFunc)(const void *init_data, const ThreadId thread_id, void **thread_data)
Function type for EVE file-type thread initialization.
Definition: output-eve-bindgen.h:63
EveJsonSimpleAppLayerLogger::name
const char * name
Definition: output-eve-bindgen.h:44
ThreadId
uint32_t ThreadId
Definition: output-eve-bindgen.h:31
SCEveFileType_::TAILQ_ENTRY
TAILQ_ENTRY(SCEveFileType_) entries
EveJsonTxLoggerRegistrationData::confname
const char * confname
Definition: output-eve-bindgen.h:50
app-layer-protos.h
LOG_DIR_PACKET
@ LOG_DIR_PACKET
Definition: output-eve-bindgen.h:34
SCEveFileTypeThreadDeinitFunc
void(* SCEveFileTypeThreadDeinitFunc)(const void *init_data, void *thread_data)
Function type for EVE file-type thread deinitialization.
Definition: output-eve-bindgen.h:71
LOG_DIR_FLOW_TOCLIENT
@ LOG_DIR_FLOW_TOCLIENT
Definition: output-eve-bindgen.h:36
EveJsonSimpleAppLayerLogger
struct EveJsonSimpleAppLayerLogger EveJsonSimpleAppLayerLogger
EveJsonSimpleTxLogFunc
bool(* EveJsonSimpleTxLogFunc)(const void *, void *)
Definition: output-eve-bindgen.h:40
SCConfNode_
Definition: conf.h:37
SCOutputEvePreRegisterLogger
int SCOutputEvePreRegisterLogger(EveJsonTxLoggerRegistrationData reg_data)
Definition: output.c:1060
EveJsonTxLoggerRegistrationData
struct EveJsonTxLoggerRegistrationData EveJsonTxLoggerRegistrationData
SCEveFileType_
Structure used to define an EVE output file type.
Definition: output-eve-bindgen.h:110