suricata
output.c
Go to the documentation of this file.
1 /* Copyright (C) 2007-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 /**
19  * \file
20  *
21  * \author OISF, Jason Ish <jason.ish@oisf.net>
22  * \author Endace Technology Limited, Jason Ish <jason.ish@endace.com>
23  *
24  * The root logging output for all non-application logging.
25  *
26  * The loggers are made up of a hierarchy of loggers. At the top we
27  * have the root logger which is the main entry point to
28  * logging. Under the root there exists parent loggers that are the
29  * entry point for specific types of loggers such as packet logger,
30  * transaction loggers, etc. Each parent logger may have 0 or more
31  * loggers that actual handle the job of producing output to something
32  * like a file.
33  */
34 
35 #include "suricata-common.h"
36 #include "flow.h"
37 #include "conf.h"
38 #include "tm-threads.h"
39 #include "util-error.h"
40 #include "util-debug.h"
41 #include "output.h"
42 
43 #include "alert-fastlog.h"
44 #include "alert-debuglog.h"
45 #include "alert-syslog.h"
46 #include "output-json.h"
47 #include "output-json-alert.h"
48 #include "output-json-anomaly.h"
49 #include "output-json-flow.h"
50 #include "output-json-netflow.h"
51 #include "log-cf-common.h"
52 #include "output-json-drop.h"
53 #include "output-eve-stream.h"
54 #include "log-httplog.h"
55 #include "output-json-http.h"
56 #include "output-json-dns.h"
57 #include "log-tlslog.h"
58 #include "log-tlsstore.h"
59 #include "output-json-tls.h"
60 #include "log-pcap.h"
61 // for SSHTxLogCondition
62 #include "app-layer-ssh.h"
63 #include "output-json-file.h"
64 #include "output-json-smtp.h"
65 #include "output-json-stats.h"
66 #include "log-tcp-data.h"
67 #include "log-stats.h"
68 #include "output-json-nfs.h"
69 #include "output-json-ftp.h"
70 // for misplaced EveFTPDataAddMetadata
71 #include "app-layer-ftp.h"
72 #include "output-json-smb.h"
73 #include "output-json-ike.h"
74 #include "output-json-dhcp.h"
75 #include "output-json-mqtt.h"
76 #include "output-json-pgsql.h"
77 #include "output-lua.h"
78 #include "output-json-dnp3.h"
79 #include "output-json-metadata.h"
80 #include "output-json-dcerpc.h"
81 #include "output-json-frame.h"
82 #include "app-layer-parser.h"
83 #include "output-filestore.h"
84 #include "output-json-arp.h"
85 
86 typedef struct RootLogger_ {
92 
93  TAILQ_ENTRY(RootLogger_) entries;
95 
96 /* List of registered root loggers. These are registered at start up and
97  * are independent of configuration. Later we will build a list of active
98  * loggers based on configuration. */
99 static TAILQ_HEAD(, RootLogger_) registered_loggers =
100  TAILQ_HEAD_INITIALIZER(registered_loggers);
101 
102 /* List of active root loggers. This means that at least one logger is enabled
103  * for each root logger type in the config. */
104 static TAILQ_HEAD(, RootLogger_) active_loggers =
105  TAILQ_HEAD_INITIALIZER(active_loggers);
106 
107 typedef struct LoggerThreadStoreNode_ {
108  void *thread_data;
109  TAILQ_ENTRY(LoggerThreadStoreNode_) entries;
111 
112 typedef TAILQ_HEAD(LoggerThreadStore_, LoggerThreadStoreNode_) LoggerThreadStore;
113 
114 /**
115  * The list of all registered (known) output modules.
116  */
118 
119 /**
120  * Registry of flags to be updated on file rotation notification.
121  */
122 typedef struct OutputFileRolloverFlag_ {
123  int *flag;
124 
125  TAILQ_ENTRY(OutputFileRolloverFlag_) entries;
127 
128 TAILQ_HEAD(, OutputFileRolloverFlag_) output_file_rotation_flags =
129  TAILQ_HEAD_INITIALIZER(output_file_rotation_flags);
130 
131 void OutputRegisterRootLoggers(void);
132 void OutputRegisterLoggers(void);
133 
134 /**
135  * \brief Register an output module.
136  *
137  * This function will register an output module so it can be
138  * configured with the configuration file.
139  *
140  * \retval Returns 0 on success, -1 on failure.
141  */
142 void OutputRegisterModule(const char *name, const char *conf_name,
143  OutputInitFunc InitFunc)
144 {
145  OutputModule *module = SCCalloc(1, sizeof(*module));
146  if (unlikely(module == NULL))
147  goto error;
148 
149  module->name = name;
150  module->conf_name = conf_name;
151  module->InitFunc = InitFunc;
152  TAILQ_INSERT_TAIL(&output_modules, module, entries);
153 
154  SCLogDebug("Output module \"%s\" registered.", name);
155 
156  return;
157 
158 error:
159  FatalError("Fatal error encountered in OutputRegisterModule. Exiting...");
160 }
161 
162 /**
163  * \brief Register a packet output module.
164  *
165  * This function will register an output module so it can be
166  * configured with the configuration file.
167  *
168  * \retval Returns 0 on success, -1 on failure.
169  */
170 void OutputRegisterPacketModule(LoggerId id, const char *name, const char *conf_name,
171  OutputInitFunc InitFunc, OutputPacketLoggerFunctions *output_module_functions)
172 {
173  if (unlikely(output_module_functions->LogFunc == NULL ||
174  output_module_functions->ConditionFunc == NULL)) {
175  goto error;
176  }
177 
178  OutputModule *module = SCCalloc(1, sizeof(*module));
179  if (unlikely(module == NULL)) {
180  goto error;
181  }
182 
183  module->logger_id = id;
184  module->name = name;
185  module->conf_name = conf_name;
186  module->InitFunc = InitFunc;
187  module->PacketLogFunc = output_module_functions->LogFunc;
188  module->PacketFlushFunc = output_module_functions->FlushFunc;
189  module->PacketConditionFunc = output_module_functions->ConditionFunc;
190  module->ThreadInit = output_module_functions->ThreadInitFunc;
191  module->ThreadDeinit = output_module_functions->ThreadDeinitFunc;
192  TAILQ_INSERT_TAIL(&output_modules, module, entries);
193 
194  SCLogDebug("Packet logger \"%s\" registered.", name);
195  return;
196 error:
197  FatalError("Fatal error encountered. Exiting...");
198 }
199 
200 /**
201  * \brief Register a packet output sub-module.
202  *
203  * This function will register an output module so it can be
204  * configured with the configuration file.
205  *
206  * \retval Returns 0 on success, -1 on failure.
207  */
208 void OutputRegisterPacketSubModule(LoggerId id, const char *parent_name, const char *name,
209  const char *conf_name, OutputInitSubFunc InitFunc,
210  OutputPacketLoggerFunctions *output_logger_functions)
211 {
212  if (unlikely(output_logger_functions->LogFunc == NULL ||
213  output_logger_functions->ConditionFunc == NULL)) {
214  goto error;
215  }
216 
217  OutputModule *module = SCCalloc(1, sizeof(*module));
218  if (unlikely(module == NULL)) {
219  goto error;
220  }
221 
222  module->logger_id = id;
223  module->name = name;
224  module->conf_name = conf_name;
225  module->parent_name = parent_name;
226  module->InitSubFunc = InitFunc;
227  module->PacketLogFunc = output_logger_functions->LogFunc;
228  module->PacketFlushFunc = output_logger_functions->FlushFunc;
229  module->PacketConditionFunc = output_logger_functions->ConditionFunc;
230  module->ThreadInit = output_logger_functions->ThreadInitFunc;
231  module->ThreadDeinit = output_logger_functions->ThreadDeinitFunc;
232  TAILQ_INSERT_TAIL(&output_modules, module, entries);
233 
234  SCLogDebug("Packet logger \"%s\" registered.", name);
235  return;
236 error:
237  FatalError("Fatal error encountered. Exiting...");
238 }
239 
240 /**
241  * \brief Wrapper function for tx output modules.
242  *
243  * This function will register an output module so it can be
244  * configured with the configuration file.
245  *
246  * \retval Returns 0 on success, -1 on failure.
247  */
248 static void OutputRegisterTxModuleWrapper(LoggerId id, const char *name, const char *conf_name,
249  OutputInitFunc InitFunc, AppProto alproto, TxLogger TxLogFunc, int tc_log_progress,
250  int ts_log_progress, TxLoggerCondition TxLogCondition, ThreadInitFunc ThreadInit,
251  ThreadDeinitFunc ThreadDeinit)
252 {
253  if (unlikely(TxLogFunc == NULL)) {
254  goto error;
255  }
256 
257  OutputModule *module = SCCalloc(1, sizeof(*module));
258  if (unlikely(module == NULL)) {
259  goto error;
260  }
261 
262  module->logger_id = id;
263  module->name = name;
264  module->conf_name = conf_name;
265  module->InitFunc = InitFunc;
266  module->TxLogFunc = TxLogFunc;
267  module->TxLogCondition = TxLogCondition;
268  module->alproto = alproto;
269  module->tc_log_progress = tc_log_progress;
270  module->ts_log_progress = ts_log_progress;
271  module->ThreadInit = ThreadInit;
272  module->ThreadDeinit = ThreadDeinit;
273  TAILQ_INSERT_TAIL(&output_modules, module, entries);
274 
275  SCLogDebug("Tx logger \"%s\" registered.", name);
276  return;
277 error:
278  FatalError("Fatal error encountered. Exiting...");
279 }
280 
281 static void OutputRegisterTxSubModuleWrapper(LoggerId id, const char *parent_name, const char *name,
282  const char *conf_name, OutputInitSubFunc InitFunc, AppProto alproto, TxLogger TxLogFunc,
283  int tc_log_progress, int ts_log_progress, TxLoggerCondition TxLogCondition,
284  ThreadInitFunc ThreadInit, ThreadDeinitFunc ThreadDeinit)
285 {
286  if (unlikely(TxLogFunc == NULL)) {
287  goto error;
288  }
289 
290  OutputModule *module = SCCalloc(1, sizeof(*module));
291  if (unlikely(module == NULL)) {
292  goto error;
293  }
294 
295  module->logger_id = id;
296  module->name = name;
297  module->conf_name = conf_name;
298  module->parent_name = parent_name;
299  module->InitSubFunc = InitFunc;
300  module->TxLogFunc = TxLogFunc;
301  module->TxLogCondition = TxLogCondition;
302  module->alproto = alproto;
303  module->tc_log_progress = tc_log_progress;
304  module->ts_log_progress = ts_log_progress;
305  module->ThreadInit = ThreadInit;
306  module->ThreadDeinit = ThreadDeinit;
307  TAILQ_INSERT_TAIL(&output_modules, module, entries);
308 
309  SCLogDebug("Tx logger for alproto %d \"%s\" registered.", alproto, name);
310  return;
311 error:
312  FatalError("Fatal error encountered. Exiting...");
313 }
314 
315 /**
316  * \brief Register a tx output module with condition.
317  *
318  * This function will register an output module so it can be
319  * configured with the configuration file.
320  *
321  * \retval Returns 0 on success, -1 on failure.
322  */
323 void OutputRegisterTxModuleWithCondition(LoggerId id, const char *name, const char *conf_name,
324  OutputInitFunc InitFunc, AppProto alproto, TxLogger TxLogFunc,
325  TxLoggerCondition TxLogCondition, ThreadInitFunc ThreadInit, ThreadDeinitFunc ThreadDeinit)
326 {
327  OutputRegisterTxModuleWrapper(id, name, conf_name, InitFunc, alproto, TxLogFunc, -1, -1,
328  TxLogCondition, ThreadInit, ThreadDeinit);
329 }
330 
331 void OutputRegisterTxSubModuleWithCondition(LoggerId id, const char *parent_name, const char *name,
332  const char *conf_name, OutputInitSubFunc InitFunc, AppProto alproto, TxLogger TxLogFunc,
333  TxLoggerCondition TxLogCondition, ThreadInitFunc ThreadInit, ThreadDeinitFunc ThreadDeinit)
334 {
335  OutputRegisterTxSubModuleWrapper(id, parent_name, name, conf_name, InitFunc, alproto, TxLogFunc,
336  -1, -1, TxLogCondition, ThreadInit, ThreadDeinit);
337 }
338 
339 /**
340  * \brief Register a tx output module with progress.
341  *
342  * This function will register an output module so it can be
343  * configured with the configuration file.
344  *
345  * \retval Returns 0 on success, -1 on failure.
346  */
347 void OutputRegisterTxModuleWithProgress(LoggerId id, const char *name, const char *conf_name,
348  OutputInitFunc InitFunc, AppProto alproto, TxLogger TxLogFunc, int tc_log_progress,
349  int ts_log_progress, ThreadInitFunc ThreadInit, ThreadDeinitFunc ThreadDeinit)
350 {
351  OutputRegisterTxModuleWrapper(id, name, conf_name, InitFunc, alproto, TxLogFunc,
352  tc_log_progress, ts_log_progress, NULL, ThreadInit, ThreadDeinit);
353 }
354 
355 void OutputRegisterTxSubModuleWithProgress(LoggerId id, const char *parent_name, const char *name,
356  const char *conf_name, OutputInitSubFunc InitFunc, AppProto alproto, TxLogger TxLogFunc,
357  int tc_log_progress, int ts_log_progress, ThreadInitFunc ThreadInit,
358  ThreadDeinitFunc ThreadDeinit)
359 {
360  OutputRegisterTxSubModuleWrapper(id, parent_name, name, conf_name, InitFunc, alproto, TxLogFunc,
361  tc_log_progress, ts_log_progress, NULL, ThreadInit, ThreadDeinit);
362 }
363 
364 /**
365  * \brief Register a tx output module.
366  *
367  * This function will register an output module so it can be
368  * configured with the configuration file.
369  *
370  * \retval Returns 0 on success, -1 on failure.
371  */
372 void OutputRegisterTxModule(LoggerId id, const char *name, const char *conf_name,
373  OutputInitFunc InitFunc, AppProto alproto, TxLogger TxLogFunc, ThreadInitFunc ThreadInit,
374  ThreadDeinitFunc ThreadDeinit)
375 {
376  OutputRegisterTxModuleWrapper(id, name, conf_name, InitFunc, alproto, TxLogFunc, -1, -1, NULL,
377  ThreadInit, ThreadDeinit);
378 }
379 
380 void OutputRegisterTxSubModule(LoggerId id, const char *parent_name, const char *name,
381  const char *conf_name, OutputInitSubFunc InitFunc, AppProto alproto, TxLogger TxLogFunc,
382  ThreadInitFunc ThreadInit, ThreadDeinitFunc ThreadDeinit)
383 {
384  OutputRegisterTxSubModuleWrapper(id, parent_name, name, conf_name, InitFunc, alproto, TxLogFunc,
385  -1, -1, NULL, ThreadInit, ThreadDeinit);
386 }
387 
388 /**
389  * \brief Register a file output sub-module.
390  *
391  * This function will register an output module so it can be
392  * configured with the configuration file.
393  *
394  * \retval Returns 0 on success, -1 on failure.
395  */
396 void OutputRegisterFileSubModule(LoggerId id, const char *parent_name, const char *name,
397  const char *conf_name, OutputInitSubFunc InitFunc, SCFileLogger FileLogFunc,
398  ThreadInitFunc ThreadInit, ThreadDeinitFunc ThreadDeinit)
399 {
400  if (unlikely(FileLogFunc == NULL)) {
401  goto error;
402  }
403 
404  OutputModule *module = SCCalloc(1, sizeof(*module));
405  if (unlikely(module == NULL)) {
406  goto error;
407  }
408 
409  module->logger_id = id;
410  module->name = name;
411  module->conf_name = conf_name;
412  module->parent_name = parent_name;
413  module->InitSubFunc = InitFunc;
414  module->FileLogFunc = FileLogFunc;
415  module->ThreadInit = ThreadInit;
416  module->ThreadDeinit = ThreadDeinit;
417  TAILQ_INSERT_TAIL(&output_modules, module, entries);
418 
419  SCLogDebug("File logger \"%s\" registered.", name);
420  return;
421 error:
422  FatalError("Fatal error encountered. Exiting...");
423 }
424 
425 /**
426  * \brief Register a file data output module.
427  *
428  * This function will register an output module so it can be
429  * configured with the configuration file.
430  *
431  * \retval Returns 0 on success, -1 on failure.
432  */
433 void OutputRegisterFiledataModule(LoggerId id, const char *name, const char *conf_name,
434  OutputInitFunc InitFunc, SCFiledataLogger FiledataLogFunc, ThreadInitFunc ThreadInit,
435  ThreadDeinitFunc ThreadDeinit)
436 {
437  if (unlikely(FiledataLogFunc == NULL)) {
438  goto error;
439  }
440 
441  OutputModule *module = SCCalloc(1, sizeof(*module));
442  if (unlikely(module == NULL)) {
443  goto error;
444  }
445 
446  module->logger_id = id;
447  module->name = name;
448  module->conf_name = conf_name;
449  module->InitFunc = InitFunc;
450  module->FiledataLogFunc = FiledataLogFunc;
451  module->ThreadInit = ThreadInit;
452  module->ThreadDeinit = ThreadDeinit;
453  TAILQ_INSERT_TAIL(&output_modules, module, entries);
454 
455  SCLogDebug("Filedata logger \"%s\" registered.", name);
456  return;
457 error:
458  FatalError("Fatal error encountered. Exiting...");
459 }
460 
461 /**
462  * \brief Register a flow output sub-module.
463  *
464  * This function will register an output module so it can be
465  * configured with the configuration file.
466  *
467  * \retval Returns 0 on success, -1 on failure.
468  */
469 void OutputRegisterFlowSubModule(LoggerId id, const char *parent_name, const char *name,
470  const char *conf_name, OutputInitSubFunc InitFunc, FlowLogger FlowLogFunc,
471  ThreadInitFunc ThreadInit, ThreadDeinitFunc ThreadDeinit)
472 {
473  if (unlikely(FlowLogFunc == NULL)) {
474  goto error;
475  }
476 
477  OutputModule *module = SCCalloc(1, sizeof(*module));
478  if (unlikely(module == NULL)) {
479  goto error;
480  }
481 
482  module->logger_id = id;
483  module->name = name;
484  module->conf_name = conf_name;
485  module->parent_name = parent_name;
486  module->InitSubFunc = InitFunc;
487  module->FlowLogFunc = FlowLogFunc;
488  module->ThreadInit = ThreadInit;
489  module->ThreadDeinit = ThreadDeinit;
490  TAILQ_INSERT_TAIL(&output_modules, module, entries);
491 
492  SCLogDebug("Flow logger \"%s\" registered.", name);
493  return;
494 error:
495  FatalError("Fatal error encountered. Exiting...");
496 }
497 
498 /**
499  * \brief Register a streaming data output module.
500  *
501  * This function will register an output module so it can be
502  * configured with the configuration file.
503  *
504  * \retval Returns 0 on success, -1 on failure.
505  */
506 void OutputRegisterStreamingModule(LoggerId id, const char *name, const char *conf_name,
507  OutputInitFunc InitFunc, SCStreamingLogger StreamingLogFunc,
508  enum SCOutputStreamingType stream_type, ThreadInitFunc ThreadInit,
509  ThreadDeinitFunc ThreadDeinit)
510 {
511  if (unlikely(StreamingLogFunc == NULL)) {
512  goto error;
513  }
514 
515  OutputModule *module = SCCalloc(1, sizeof(*module));
516  if (unlikely(module == NULL)) {
517  goto error;
518  }
519 
520  module->logger_id = id;
521  module->name = name;
522  module->conf_name = conf_name;
523  module->InitFunc = InitFunc;
524  module->StreamingLogFunc = StreamingLogFunc;
525  module->stream_type = stream_type;
526  module->ThreadInit = ThreadInit;
527  module->ThreadDeinit = ThreadDeinit;
528  TAILQ_INSERT_TAIL(&output_modules, module, entries);
529 
530  SCLogDebug("Streaming logger \"%s\" registered.", name);
531  return;
532 error:
533  FatalError("Fatal error encountered. Exiting...");
534 }
535 
536 /**
537  * \brief Register a stats data output module.
538  *
539  * This function will register an output module so it can be
540  * configured with the configuration file.
541  *
542  * \retval Returns 0 on success, -1 on failure.
543  */
544 void OutputRegisterStatsModule(LoggerId id, const char *name, const char *conf_name,
545  OutputInitFunc InitFunc, StatsLogger StatsLogFunc, ThreadInitFunc ThreadInit,
546  ThreadDeinitFunc ThreadDeinit)
547 {
548  if (unlikely(StatsLogFunc == NULL)) {
549  goto error;
550  }
551 
552  OutputModule *module = SCCalloc(1, sizeof(*module));
553  if (unlikely(module == NULL)) {
554  goto error;
555  }
556 
557  module->logger_id = id;
558  module->name = name;
559  module->conf_name = conf_name;
560  module->InitFunc = InitFunc;
561  module->StatsLogFunc = StatsLogFunc;
562  module->ThreadInit = ThreadInit;
563  module->ThreadDeinit = ThreadDeinit;
564  TAILQ_INSERT_TAIL(&output_modules, module, entries);
565 
566  SCLogDebug("Stats logger \"%s\" registered.", name);
567  return;
568 error:
569  FatalError("Fatal error encountered. Exiting...");
570 }
571 
572 /**
573  * \brief Register a stats data output sub-module.
574  *
575  * This function will register an output module so it can be
576  * configured with the configuration file.
577  *
578  * \retval Returns 0 on success, -1 on failure.
579  */
580 void OutputRegisterStatsSubModule(LoggerId id, const char *parent_name, const char *name,
581  const char *conf_name, OutputInitSubFunc InitFunc, StatsLogger StatsLogFunc,
582  ThreadInitFunc ThreadInit, ThreadDeinitFunc ThreadDeinit)
583 {
584  if (unlikely(StatsLogFunc == NULL)) {
585  goto error;
586  }
587 
588  OutputModule *module = SCCalloc(1, sizeof(*module));
589  if (unlikely(module == NULL)) {
590  goto error;
591  }
592 
593  module->logger_id = id;
594  module->name = name;
595  module->conf_name = conf_name;
596  module->parent_name = parent_name;
597  module->InitSubFunc = InitFunc;
598  module->StatsLogFunc = StatsLogFunc;
599  module->ThreadInit = ThreadInit;
600  module->ThreadDeinit = ThreadDeinit;
601  TAILQ_INSERT_TAIL(&output_modules, module, entries);
602 
603  SCLogDebug("Stats logger \"%s\" registered.", name);
604  return;
605 error:
606  FatalError("Fatal error encountered. Exiting...");
607 }
608 
609 /**
610  * \brief Get an output module by name.
611  *
612  * \retval The OutputModule with the given name or NULL if no output module
613  * with the given name is registered.
614  */
616 {
617  OutputModule *module;
618 
619  TAILQ_FOREACH(module, &output_modules, entries) {
620  if (strcmp(module->conf_name, conf_name) == 0)
621  return module;
622  }
623 
624  return NULL;
625 }
626 
627 static EveJsonSimpleAppLayerLogger *simple_json_applayer_loggers;
628 
629 /**
630  * \brief Deregister all modules. Useful for a memory clean exit.
631  */
633 {
634  OutputModule *module;
635 
636  while ((module = TAILQ_FIRST(&output_modules))) {
637  TAILQ_REMOVE(&output_modules, module, entries);
638  SCFree(module);
639  }
640  SCFree(simple_json_applayer_loggers);
641  simple_json_applayer_loggers = NULL;
642 }
643 
644 static int drop_loggers = 0;
645 
647 {
648  if (drop_loggers)
649  return -1;
650  drop_loggers++;
651  return 0;
652 }
653 
655 {
656  if (drop_loggers)
657  drop_loggers--;
658 }
659 
660 /**
661  * \brief Register a flag for file rotation notification.
662  *
663  * \param flag A pointer that will be set to 1 when file rotation is
664  * requested.
665  */
667 {
668  OutputFileRolloverFlag *flag_entry = SCCalloc(1, sizeof(*flag_entry));
669  if (unlikely(flag_entry == NULL)) {
670  SCLogError("Failed to allocate memory to register file rotation flag");
671  return;
672  }
673  flag_entry->flag = flag;
674  TAILQ_INSERT_TAIL(&output_file_rotation_flags, flag_entry, entries);
675 }
676 
677 /**
678  * \brief Unregister a file rotation flag.
679  *
680  * Note that it is safe to call this function with a flag that may not
681  * have been registered, in which case this function won't do
682  * anything.
683  *
684  * \param flag A pointer that has been previously registered for file
685  * rotation notifications.
686  */
688 {
689  OutputFileRolloverFlag *entry, *next;
690  for (entry = TAILQ_FIRST(&output_file_rotation_flags); entry != NULL;
691  entry = next) {
692  next = TAILQ_NEXT(entry, entries);
693  if (entry->flag == flag) {
694  TAILQ_REMOVE(&output_file_rotation_flags, entry, entries);
695  SCFree(entry);
696  break;
697  }
698  }
699 }
700 
701 /**
702  * \brief Notifies all registered file rotation notification flags.
703  */
706  TAILQ_FOREACH(flag, &output_file_rotation_flags, entries) {
707  *(flag->flag) = 1;
708  }
709 }
710 
711 TmEcode OutputLoggerFlush(ThreadVars *tv, Packet *p, void *thread_data)
712 {
713  LoggerThreadStore *thread_store = (LoggerThreadStore *)thread_data;
714  RootLogger *logger = TAILQ_FIRST(&active_loggers);
715  LoggerThreadStoreNode *thread_store_node = TAILQ_FIRST(thread_store);
716  while (logger && thread_store_node) {
717  if (logger->FlushFunc)
718  logger->FlushFunc(tv, p, thread_store_node->thread_data);
719 
720  logger = TAILQ_NEXT(logger, entries);
721  thread_store_node = TAILQ_NEXT(thread_store_node, entries);
722  }
723  return TM_ECODE_OK;
724 }
725 
726 TmEcode OutputLoggerLog(ThreadVars *tv, Packet *p, void *thread_data)
727 {
728  LoggerThreadStore *thread_store = (LoggerThreadStore *)thread_data;
729  RootLogger *logger = TAILQ_FIRST(&active_loggers);
730  LoggerThreadStoreNode *thread_store_node = TAILQ_FIRST(thread_store);
731  while (logger && thread_store_node) {
732  logger->LogFunc(tv, p, thread_store_node->thread_data);
733 
734  logger = TAILQ_NEXT(logger, entries);
735  thread_store_node = TAILQ_NEXT(thread_store_node, entries);
736  }
737  return TM_ECODE_OK;
738 }
739 
740 TmEcode OutputLoggerThreadInit(ThreadVars *tv, const void *initdata, void **data)
741 {
742  LoggerThreadStore *thread_store = SCCalloc(1, sizeof(*thread_store));
743  if (thread_store == NULL) {
744  return TM_ECODE_FAILED;
745  }
746  TAILQ_INIT(thread_store);
747  *data = (void *)thread_store;
748 
749  RootLogger *logger;
750  TAILQ_FOREACH(logger, &active_loggers, entries) {
751 
752  void *child_thread_data = NULL;
753  if (logger->ThreadInit != NULL) {
754  if (logger->ThreadInit(tv, initdata, &child_thread_data) == TM_ECODE_OK) {
755  LoggerThreadStoreNode *thread_store_node =
756  SCCalloc(1, sizeof(*thread_store_node));
757  if (thread_store_node == NULL) {
758  /* Undo everything, calling de-init will take care
759  * of that. */
760  OutputLoggerThreadDeinit(tv, thread_store);
761  return TM_ECODE_FAILED;
762  }
763  thread_store_node->thread_data = child_thread_data;
764  TAILQ_INSERT_TAIL(thread_store, thread_store_node, entries);
765  }
766  }
767  }
768  return TM_ECODE_OK;
769 }
770 
772 {
773  if (thread_data == NULL)
774  return TM_ECODE_FAILED;
775 
776  LoggerThreadStore *thread_store = (LoggerThreadStore *)thread_data;
777  RootLogger *logger = TAILQ_FIRST(&active_loggers);
778  LoggerThreadStoreNode *thread_store_node = TAILQ_FIRST(thread_store);
779  while (logger && thread_store_node) {
780  if (logger->ThreadDeinit != NULL) {
781  logger->ThreadDeinit(tv, thread_store_node->thread_data);
782  }
783  logger = TAILQ_NEXT(logger, entries);
784  thread_store_node = TAILQ_NEXT(thread_store_node, entries);
785  }
786 
787  /* Free the thread store. */
788  while ((thread_store_node = TAILQ_FIRST(thread_store)) != NULL) {
789  TAILQ_REMOVE(thread_store, thread_store_node, entries);
790  SCFree(thread_store_node);
791  }
792  SCFree(thread_store);
793 
794  return TM_ECODE_OK;
795 }
796 
798  OutputLogFunc LogFunc, OutputGetActiveCountFunc ActiveCntFunc)
799 {
800  BUG_ON(LogFunc == NULL);
801 
802  RootLogger *logger = SCCalloc(1, sizeof(*logger));
803  if (logger == NULL) {
804  FatalError("failed to alloc root logger");
805  }
806  logger->ThreadInit = ThreadInit;
807  logger->ThreadDeinit = ThreadDeinit;
808  logger->LogFunc = LogFunc;
809  logger->ActiveCntFunc = ActiveCntFunc;
810  TAILQ_INSERT_TAIL(&registered_loggers, logger, entries);
811 }
812 
813 static void OutputRegisterActiveLogger(RootLogger *reg)
814 {
815  RootLogger *logger = SCCalloc(1, sizeof(*logger));
816  if (logger == NULL) {
817  FatalError("failed to alloc root logger");
818  }
819  logger->ThreadInit = reg->ThreadInit;
820  logger->ThreadDeinit = reg->ThreadDeinit;
821  logger->LogFunc = reg->LogFunc;
822  logger->ActiveCntFunc = reg->ActiveCntFunc;
823  TAILQ_INSERT_TAIL(&active_loggers, logger, entries);
824 }
825 
827 {
828  RootLogger *logger = TAILQ_FIRST(&registered_loggers);
829  while (logger) {
830  uint32_t cnt = logger->ActiveCntFunc();
831  if (cnt) {
832  OutputRegisterActiveLogger(logger);
833  }
834 
835  logger = TAILQ_NEXT(logger, entries);
836  }
837 }
838 
840 {
841  RootLogger *logger;
842  while ((logger = TAILQ_FIRST(&active_loggers)) != NULL) {
843  TAILQ_REMOVE(&active_loggers, logger, entries);
844  SCFree(logger);
845  }
846 }
847 
849 {
852 }
853 
855 {
856  if (alproto < g_alproto_max) {
857  return &simple_json_applayer_loggers[alproto];
858  }
859  return NULL;
860 }
861 
862 static void RegisterSimpleJsonApplayerLogger(
863  AppProto alproto, EveJsonSimpleTxLogFunc LogTx, const char *name)
864 {
865  simple_json_applayer_loggers[alproto].LogTx = LogTx;
866  if (name) {
867  simple_json_applayer_loggers[alproto].name = name;
868  } else {
869  simple_json_applayer_loggers[alproto].name = AppProtoToString(alproto);
870  }
871 }
872 
873 /**
874  * \brief Register all root loggers.
875  */
877 {
878  simple_json_applayer_loggers = SCCalloc(g_alproto_max, sizeof(EveJsonSimpleAppLayerLogger));
879  if (unlikely(simple_json_applayer_loggers == NULL)) {
880  FatalError("Failed to allocate simple_json_applayer_loggers");
881  }
882  // ALPROTO_HTTP1 special: uses some options flags
883  RegisterSimpleJsonApplayerLogger(ALPROTO_FTP, EveFTPLogCommand, NULL);
884  // ALPROTO_SMTP special: uses state
885  RegisterSimpleJsonApplayerLogger(ALPROTO_TLS, JsonTlsLogJSONExtended, NULL);
886  // no cast here but done in rust for SSHTransaction
887  RegisterSimpleJsonApplayerLogger(ALPROTO_SSH, SCSshLogJson, NULL);
888  // ALPROTO_SMB special: uses state
889  // ALPROTO_DCERPC special: uses state
890  RegisterSimpleJsonApplayerLogger(ALPROTO_DNS, AlertJsonDns, NULL);
891  // either need a cast here or in rust for ModbusTransaction, done here
892  RegisterSimpleJsonApplayerLogger(
893  ALPROTO_MODBUS, (EveJsonSimpleTxLogFunc)rs_modbus_to_json, NULL);
894  RegisterSimpleJsonApplayerLogger(ALPROTO_ENIP, SCEnipLoggerLog, NULL);
895  RegisterSimpleJsonApplayerLogger(ALPROTO_DNP3, AlertJsonDnp3, NULL);
896  // ALPROTO_NFS special: uses state
897  // underscore instead of dash for ftp_data
898  RegisterSimpleJsonApplayerLogger(ALPROTO_FTPDATA, EveFTPDataAddMetadata, "ftp_data");
899  RegisterSimpleJsonApplayerLogger(
900  ALPROTO_TFTP, (EveJsonSimpleTxLogFunc)rs_tftp_log_json_request, NULL);
901  // ALPROTO_IKE special: uses state
902  RegisterSimpleJsonApplayerLogger(
903  ALPROTO_KRB5, (EveJsonSimpleTxLogFunc)rs_krb5_log_json_response, NULL);
904  RegisterSimpleJsonApplayerLogger(ALPROTO_QUIC, rs_quic_to_json, NULL);
905  // ALPROTO_DHCP TODO missing
906  RegisterSimpleJsonApplayerLogger(
907  ALPROTO_SNMP, (EveJsonSimpleTxLogFunc)rs_snmp_log_json_response, NULL);
908  RegisterSimpleJsonApplayerLogger(ALPROTO_SIP, (EveJsonSimpleTxLogFunc)rs_sip_log_json, NULL);
909  RegisterSimpleJsonApplayerLogger(ALPROTO_RFB, rs_rfb_logger_log, NULL);
910  RegisterSimpleJsonApplayerLogger(ALPROTO_MQTT, JsonMQTTAddMetadata, NULL);
911  RegisterSimpleJsonApplayerLogger(ALPROTO_PGSQL, JsonPgsqlAddMetadata, NULL);
912  RegisterSimpleJsonApplayerLogger(ALPROTO_WEBSOCKET, rs_websocket_logger_log, NULL);
913  RegisterSimpleJsonApplayerLogger(ALPROTO_LDAP, rs_ldap_logger_log, NULL);
914  RegisterSimpleJsonApplayerLogger(ALPROTO_DOH2, AlertJsonDoh2, NULL);
915  RegisterSimpleJsonApplayerLogger(ALPROTO_TEMPLATE, rs_template_logger_log, NULL);
916  RegisterSimpleJsonApplayerLogger(ALPROTO_RDP, (EveJsonSimpleTxLogFunc)rs_rdp_to_json, NULL);
917  // special case : http2 is logged in http object
918  RegisterSimpleJsonApplayerLogger(ALPROTO_HTTP2, rs_http2_log_json, "http");
919  // underscore instead of dash for bittorrent_dht
920  RegisterSimpleJsonApplayerLogger(
921  ALPROTO_BITTORRENT_DHT, SCBittorrentDhtLogger, "bittorrent_dht");
922 
928 }
929 
930 static int JsonGenericLogger(ThreadVars *tv, void *thread_data, const Packet *p, Flow *f,
931  void *state, void *tx, uint64_t tx_id, int dir)
932 {
933  OutputJsonThreadCtx *thread = thread_data;
935  if (al == NULL) {
936  return TM_ECODE_FAILED;
937  }
938 
939  JsonBuilder *js = CreateEveHeader(p, dir, al->name, NULL, thread->ctx);
940  if (unlikely(js == NULL)) {
941  return TM_ECODE_FAILED;
942  }
943 
944  if (!al->LogTx(tx, js)) {
945  goto error;
946  }
947 
948  OutputJsonBuilderBuffer(tv, p, p->flow, js, thread);
949  jb_free(js);
950 
951  return TM_ECODE_OK;
952 
953 error:
954  jb_free(js);
955  return TM_ECODE_FAILED;
956 }
957 
958 static int JsonGenericDirPacketLogger(ThreadVars *tv, void *thread_data, const Packet *p, Flow *f,
959  void *state, void *tx, uint64_t tx_id)
960 {
961  return JsonGenericLogger(tv, thread_data, p, f, state, tx, tx_id, LOG_DIR_PACKET);
962 }
963 
964 static int JsonGenericDirFlowLogger(ThreadVars *tv, void *thread_data, const Packet *p, Flow *f,
965  void *state, void *tx, uint64_t tx_id)
966 {
967  return JsonGenericLogger(tv, thread_data, p, f, state, tx, tx_id, LOG_DIR_FLOW);
968 }
969 
970 #define ARRAY_CAP_STEP 16
971 static EveJsonTxLoggerRegistrationData *preregistered_loggers = NULL;
972 static size_t preregistered_loggers_nb = 0;
973 static size_t preregistered_loggers_cap = 0;
974 
975 // Plugins can preregister logger with this function :
976 // When an app-layer plugin is loaded, it wants to register its logger
977 // But the plugin is loaded before loggers can register
978 // The preregistration data will later be used by OutputRegisterLoggers
980 {
981  if (preregistered_loggers_nb == preregistered_loggers_cap) {
982  void *tmp = SCRealloc(
983  preregistered_loggers, sizeof(EveJsonTxLoggerRegistrationData) *
984  (preregistered_loggers_cap + ARRAY_CAP_STEP));
985  if (tmp == NULL) {
986  return 1;
987  }
988  preregistered_loggers_cap += ARRAY_CAP_STEP;
989  preregistered_loggers = tmp;
990  }
991  preregistered_loggers[preregistered_loggers_nb] = reg_data;
992  preregistered_loggers_nb++;
993  return 0;
994 }
995 
996 /**
997  * \brief Register all non-root logging modules.
998  */
1000 {
1001  /* custom format log*/
1003 
1004  LuaLogRegister();
1005  /* fast log */
1007  /* debug log */
1009  /* syslog log */
1013  /* json log */
1015  /* email logs */
1017  /* http log */
1020  OutputRegisterTxSubModuleWithProgress(LOGGER_JSON_TX, "eve-log", "LogHttp2Log", "eve-log.http2",
1021  OutputJsonLogInitSub, ALPROTO_HTTP2, JsonGenericDirFlowLogger, HTTP2StateClosed,
1022  HTTP2StateClosed, JsonLogThreadInit, JsonLogThreadDeinit);
1023  /* tls log */
1027  /* ssh */
1028  OutputRegisterTxSubModuleWithCondition(LOGGER_JSON_TX, "eve-log", "JsonSshLog", "eve-log.ssh",
1029  OutputJsonLogInitSub, ALPROTO_SSH, JsonGenericDirFlowLogger, SSHTxLogCondition,
1031  /* pcap log */
1032  PcapLogRegister();
1033  /* file log */
1036  /* dns */
1038  /* modbus */
1039  OutputRegisterTxSubModule(LOGGER_JSON_TX, "eve-log", "JsonModbusLog", "eve-log.modbus",
1040  OutputJsonLogInitSub, ALPROTO_MODBUS, JsonGenericDirFlowLogger, JsonLogThreadInit,
1042 
1043  SCLogDebug("modbus json logger registered.");
1044  /* tcp streaming data */
1046  /* log stats */
1048 
1051  /* flow/netflow */
1054  /* json stats */
1056 
1057  /* DNP3. */
1060 
1061  /* NFS JSON logger. */
1063  /* TFTP JSON logger. */
1064  OutputRegisterTxSubModule(LOGGER_JSON_TX, "eve-log", "JsonTFTPLog", "eve-log.tftp",
1065  OutputJsonLogInitSub, ALPROTO_TFTP, JsonGenericDirPacketLogger, JsonLogThreadInit,
1067 
1068  SCLogDebug("TFTP JSON logger registered.");
1069  /* FTP and FTP-DATA JSON loggers. */
1070  OutputRegisterTxSubModule(LOGGER_JSON_TX, "eve-log", "JsonFTPLog", "eve-log.ftp",
1071  OutputJsonLogInitSub, ALPROTO_FTP, JsonGenericDirFlowLogger, JsonLogThreadInit,
1073  OutputRegisterTxSubModule(LOGGER_JSON_TX, "eve-log", "JsonFTPLog", "eve-log.ftp",
1074  OutputJsonLogInitSub, ALPROTO_FTPDATA, JsonGenericDirFlowLogger, JsonLogThreadInit,
1076  SCLogDebug("FTP JSON logger registered.");
1077 
1078  /* SMB JSON logger. */
1080  /* IKE JSON logger. */
1082  /* KRB5 JSON logger. */
1083  OutputRegisterTxSubModule(LOGGER_JSON_TX, "eve-log", "JsonKRB5Log", "eve-log.krb5",
1084  OutputJsonLogInitSub, ALPROTO_KRB5, JsonGenericDirPacketLogger, JsonLogThreadInit,
1086 
1087  SCLogDebug("KRB5 JSON logger registered.");
1088  /* QUIC JSON logger. */
1089  OutputRegisterTxSubModule(LOGGER_JSON_TX, "eve-log", "JsonQuicLog", "eve-log.quic",
1090  OutputJsonLogInitSub, ALPROTO_QUIC, JsonGenericDirPacketLogger, JsonLogThreadInit,
1092 
1093  SCLogDebug("quic json logger registered.");
1094  /* DHCP JSON logger. */
1096  /* SNMP JSON logger. */
1097  OutputRegisterTxSubModule(LOGGER_JSON_TX, "eve-log", "JsonSNMPLog", "eve-log.snmp",
1098  OutputJsonLogInitSub, ALPROTO_SNMP, JsonGenericDirPacketLogger, JsonLogThreadInit,
1100 
1101  SCLogDebug("SNMP JSON logger registered.");
1102  /* SIP JSON logger. */
1103  OutputRegisterTxSubModule(LOGGER_JSON_TX, "eve-log", "JsonSIPLog", "eve-log.sip",
1104  OutputJsonLogInitSub, ALPROTO_SIP, JsonGenericDirPacketLogger, JsonLogThreadInit,
1106 
1107  SCLogDebug("SIP JSON logger registered.");
1108  /* RFB JSON logger. */
1109  OutputRegisterTxSubModule(LOGGER_JSON_TX, "eve-log", "JsonRFBLog", "eve-log.rfb",
1110  OutputJsonLogInitSub, ALPROTO_RFB, JsonGenericDirPacketLogger, JsonLogThreadInit,
1112  /* MQTT JSON logger. */
1114  /* Pgsql JSON logger. */
1116  /* WebSocket JSON logger. */
1117  OutputRegisterTxSubModule(LOGGER_JSON_TX, "eve-log", "JsonWebSocketLog", "eve-log.websocket",
1118  OutputJsonLogInitSub, ALPROTO_WEBSOCKET, JsonGenericDirPacketLogger, JsonLogThreadInit,
1120  /* Enip JSON logger. */
1121  OutputRegisterTxSubModule(LOGGER_JSON_TX, "eve-log", "JsonEnipLog", "eve-log.enip",
1122  OutputJsonLogInitSub, ALPROTO_ENIP, JsonGenericDirFlowLogger, JsonLogThreadInit,
1124  /* Ldap JSON logger. */
1125  OutputRegisterTxSubModule(LOGGER_JSON_TX, "eve-log", "JsonLdapLog", "eve-log.ldap",
1126  OutputJsonLogInitSub, ALPROTO_LDAP, JsonGenericDirFlowLogger, JsonLogThreadInit,
1128  /* DoH2 JSON logger. */
1130  /* Template JSON logger. */
1131  OutputRegisterTxSubModule(LOGGER_JSON_TX, "eve-log", "JsonTemplateLog", "eve-log.template",
1132  OutputJsonLogInitSub, ALPROTO_TEMPLATE, JsonGenericDirPacketLogger, JsonLogThreadInit,
1134  /* RDP JSON logger. */
1135  OutputRegisterTxSubModule(LOGGER_JSON_TX, "eve-log", "JsonRdpLog", "eve-log.rdp",
1136  OutputJsonLogInitSub, ALPROTO_RDP, JsonGenericDirPacketLogger, JsonLogThreadInit,
1138  SCLogDebug("rdp json logger registered.");
1139  /* DCERPC JSON logger. */
1141  /* app layer frames */
1143  /* BitTorrent DHT JSON logger */
1144  if (ConfGetNode("app-layer.protocols.bittorrent-dht") != NULL) {
1145  /* Register as an eve sub-module. */
1146  OutputRegisterTxSubModule(LOGGER_JSON_TX, "eve-log", "JsonBitTorrentDHTLog",
1147  "eve-log.bittorrent-dht", OutputJsonLogInitSub, ALPROTO_BITTORRENT_DHT,
1148  JsonGenericDirPacketLogger, JsonLogThreadInit, JsonLogThreadDeinit);
1149  }
1150  /* ARP JSON logger */
1152 
1153  for (size_t i = 0; i < preregistered_loggers_nb; i++) {
1154  OutputRegisterTxSubModule(LOGGER_JSON_TX, "eve-log", preregistered_loggers[i].logname,
1155  preregistered_loggers[i].confname, OutputJsonLogInitSub,
1156  preregistered_loggers[i].alproto, JsonGenericDirFlowLogger, JsonLogThreadInit,
1158  SCLogDebug(
1159  "%s JSON logger registered.", AppProtoToString(preregistered_loggers[i].alproto));
1160  RegisterSimpleJsonApplayerLogger(
1161  preregistered_loggers[i].alproto, preregistered_loggers[i].LogTx, NULL);
1162  }
1163 }
RootLogger_::ThreadDeinit
ThreadDeinitFunc ThreadDeinit
Definition: output.c:90
log-stats.h
OutputModule_::parent_name
const char * parent_name
Definition: output.h:61
OutputFileRolloverFlag
OutputFileRolloverFlag
Definition: output.c:126
LogTlsStoreRegister
void LogTlsStoreRegister(void)
Definition: log-tlsstore.c:437
tm-threads.h
OutputModule_::FileLogFunc
SCFileLogger FileLogFunc
Definition: output.h:73
output-json-ftp.h
OutputJsonLogInitSub
OutputInitResult OutputJsonLogInitSub(ConfNode *conf, OutputCtx *parent_ctx)
Definition: output-json-common.c:82
OutputDropLoggerEnable
int OutputDropLoggerEnable(void)
Definition: output.c:646
OutputRegisterStreamingModule
void OutputRegisterStreamingModule(LoggerId id, const char *name, const char *conf_name, OutputInitFunc InitFunc, SCStreamingLogger StreamingLogFunc, enum SCOutputStreamingType stream_type, ThreadInitFunc ThreadInit, ThreadDeinitFunc ThreadDeinit)
Register a streaming data output module.
Definition: output.c:506
LoggerThreadStoreNode
LoggerThreadStoreNode
Definition: output.c:110
OutputLogFunc
TmEcode(* OutputLogFunc)(ThreadVars *, Packet *, void *)
Definition: output.h:53
JsonDoh2LogRegister
void JsonDoh2LogRegister(void)
Definition: output-json-dns.c:678
app-layer-ssh.h
JsonDCERPCLogRegister
void JsonDCERPCLogRegister(void)
Definition: output-json-dcerpc.c:67
OutputTxLoggerRegister
void OutputTxLoggerRegister(void)
Definition: output-tx.c:655
alert-debuglog.h
TAILQ_INIT
#define TAILQ_INIT(head)
Definition: queue.h:262
JsonPgsqlLogRegister
void JsonPgsqlLogRegister(void)
Definition: output-json-pgsql.c:184
ALPROTO_DNS
@ ALPROTO_DNS
Definition: app-layer-protos.h:47
OutputJsonThreadCtx_::ctx
OutputJsonCtx * ctx
Definition: output-json.h:90
OutputModule_::PacketFlushFunc
PacketLogger PacketFlushFunc
Definition: output.h:69
AlertJsonDoh2
bool AlertJsonDoh2(void *txptr, JsonBuilder *js)
Definition: output-json-dns.c:257
ALPROTO_ENIP
@ ALPROTO_ENIP
Definition: app-layer-protos.h:49
OutputRegisterTxSubModuleWithProgress
void OutputRegisterTxSubModuleWithProgress(LoggerId id, const char *parent_name, const char *name, const char *conf_name, OutputInitSubFunc InitFunc, AppProto alproto, TxLogger TxLogFunc, int tc_log_progress, int ts_log_progress, ThreadInitFunc ThreadInit, ThreadDeinitFunc ThreadDeinit)
Definition: output.c:355
unlikely
#define unlikely(expr)
Definition: util-optimize.h:35
JsonSMBLogRegister
void JsonSMBLogRegister(void)
Definition: output-json-smb.c:79
ALPROTO_TLS
@ ALPROTO_TLS
Definition: app-layer-protos.h:39
OutputRegisterRootLogger
void OutputRegisterRootLogger(ThreadInitFunc ThreadInit, ThreadDeinitFunc ThreadDeinit, OutputLogFunc LogFunc, OutputGetActiveCountFunc ActiveCntFunc)
Definition: output.c:797
output-json-mqtt.h
SCLogDebug
#define SCLogDebug(...)
Definition: util-debug.h:269
output-eve-stream.h
OutputFileLoggerRegister
void OutputFileLoggerRegister(void)
Definition: output-file.c:235
RootLogger_::FlushFunc
OutputFlushFunc FlushFunc
Definition: output.c:88
next
struct HtpBodyChunk_ * next
Definition: app-layer-htp.h:0
OutputPacketLoggerFunctions_::FlushFunc
PacketLogger FlushFunc
Definition: output.h:89
ALPROTO_MODBUS
@ ALPROTO_MODBUS
Definition: app-layer-protos.h:48
AppProto
uint16_t AppProto
Definition: app-layer-protos.h:85
ALPROTO_QUIC
@ ALPROTO_QUIC
Definition: app-layer-protos.h:57
SCFileLogger
int(* SCFileLogger)(ThreadVars *, void *thread_data, const Packet *, const File *, void *tx, const uint64_t tx_id, uint8_t direction)
Definition: output-file.h:48
SCEveJsonSimpleGetLogger
EveJsonSimpleAppLayerLogger * SCEveJsonSimpleGetLogger(AppProto alproto)
Definition: output.c:854
ConfGetNode
ConfNode * ConfGetNode(const char *name)
Get a ConfNode by name.
Definition: conf.c:181
JsonLogThreadInit
TmEcode JsonLogThreadInit(ThreadVars *t, const void *initdata, void **data)
Definition: output-json-common.c:99
OutputModule_::name
const char * name
Definition: output.h:59
Flow_
Flow data structure.
Definition: flow.h:354
LogTlsLogRegister
void LogTlsLogRegister(void)
Definition: log-tlslog.c:500
OutputModule_::logger_id
LoggerId logger_id
Definition: output.h:58
LoggerId
LoggerId
Definition: suricata-common.h:469
AppProtoToString
const char * AppProtoToString(AppProto alproto)
Maps the ALPROTO_*, to its string equivalent.
Definition: app-layer-protos.c:40
AlertFastLogRegister
void AlertFastLogRegister(void)
Definition: alert-fastlog.c:77
output-json-pgsql.h
JsonFileLogRegister
void JsonFileLogRegister(void)
Definition: output-json-file.c:352
OutputJsonBuilderBuffer
void OutputJsonBuilderBuffer(ThreadVars *tv, const Packet *p, Flow *f, JsonBuilder *js, OutputJsonThreadCtx *ctx)
Definition: output-json.c:965
output-json-frame.h
OutputModule_::ts_log_progress
int ts_log_progress
Definition: output.h:81
OutputRegisterStatsSubModule
void OutputRegisterStatsSubModule(LoggerId id, const char *parent_name, const char *name, const char *conf_name, OutputInitSubFunc InitFunc, StatsLogger StatsLogFunc, ThreadInitFunc ThreadInit, ThreadDeinitFunc ThreadDeinit)
Register a stats data output sub-module.
Definition: output.c:580
output-json-netflow.h
JsonDNP3LogRegister
void JsonDNP3LogRegister(void)
Definition: output-json-dnp3.c:364
LogCustomFormatRegister
void LogCustomFormatRegister(void)
Definition: log-cf-common.c:271
TAILQ_FOREACH
#define TAILQ_FOREACH(var, head, field)
Definition: queue.h:252
output-json-arp.h
OutputGetModuleByConfName
OutputModule * OutputGetModuleByConfName(const char *conf_name)
Get an output module by name.
Definition: output.c:615
output-json-tls.h
SSHTxLogCondition
bool SSHTxLogCondition(ThreadVars *tv, const Packet *p, void *state, void *tx, uint64_t tx_id)
Definition: app-layer-ssh.c:74
ALPROTO_SIP
@ ALPROTO_SIP
Definition: app-layer-protos.h:60
OutputRegisterTxSubModule
void OutputRegisterTxSubModule(LoggerId id, const char *parent_name, const char *name, const char *conf_name, OutputInitSubFunc InitFunc, AppProto alproto, TxLogger TxLogFunc, ThreadInitFunc ThreadInit, ThreadDeinitFunc ThreadDeinit)
Definition: output.c:380
OutputSetupActiveLoggers
void OutputSetupActiveLoggers(void)
Definition: output.c:826
AlertSyslogRegister
void AlertSyslogRegister(void)
Function to register the AlertSyslog module.
Definition: alert-syslog.c:384
OutputModule_::StatsLogFunc
StatsLogger StatsLogFunc
Definition: output.h:77
ALPROTO_LDAP
@ ALPROTO_LDAP
Definition: app-layer-protos.h:66
JsonDHCPLogRegister
void JsonDHCPLogRegister(void)
Definition: output-json-dhcp.c:146
TxLogger
int(* TxLogger)(ThreadVars *, void *thread_data, const Packet *, Flow *f, void *state, void *tx, uint64_t tx_id)
Transaction logger function pointer type.
Definition: output-tx.h:34
FlowLogger
int(* FlowLogger)(ThreadVars *, void *thread_data, Flow *f)
Flow logger function pointer type.
Definition: output-flow.h:36
ALPROTO_FTP
@ ALPROTO_FTP
Definition: app-layer-protos.h:37
TAILQ_INSERT_TAIL
#define TAILQ_INSERT_TAIL(head, elm, field)
Definition: queue.h:294
PcapLogRegister
void PcapLogRegister(void)
Definition: log-pcap.c:210
OutputModule_::InitSubFunc
OutputInitSubFunc InitSubFunc
Definition: output.h:63
OutputRegisterFiledataModule
void OutputRegisterFiledataModule(LoggerId id, const char *name, const char *conf_name, OutputInitFunc InitFunc, SCFiledataLogger FiledataLogFunc, ThreadInitFunc ThreadInit, ThreadDeinitFunc ThreadDeinit)
Register a file data output module.
Definition: output.c:433
SCFiledataLogger
int(* SCFiledataLogger)(ThreadVars *, void *thread_data, const Packet *, File *, void *tx, const uint64_t tx_id, const uint8_t *, uint32_t, uint8_t, uint8_t dir)
File-data logger function pointer type.
Definition: output-filedata.h:51
ALPROTO_SSH
@ ALPROTO_SSH
Definition: app-layer-protos.h:40
app-layer-ftp.h
OutputModule_::PacketLogFunc
PacketLogger PacketLogFunc
Definition: output.h:68
TM_ECODE_FAILED
@ TM_ECODE_FAILED
Definition: tm-threads-common.h:81
EveJsonSimpleTxLogFunc
bool(* EveJsonSimpleTxLogFunc)(void *, struct JsonBuilder *)
Definition: output.h:175
OutputModule_::FiledataLogFunc
SCFiledataLogger FiledataLogFunc
Definition: output.h:74
JsonStatsLogRegister
void JsonStatsLogRegister(void)
Definition: output-json-stats.c:501
LogTcpDataLogRegister
void LogTcpDataLogRegister(void)
Definition: log-tcp-data.c:46
OutputRegisterRootLoggers
void OutputRegisterRootLoggers(void)
Register all root loggers.
Definition: output.c:876
OutputLoggerThreadDeinit
TmEcode OutputLoggerThreadDeinit(ThreadVars *tv, void *thread_data)
Definition: output.c:771
OutputRegisterTxModule
void OutputRegisterTxModule(LoggerId id, const char *name, const char *conf_name, OutputInitFunc InitFunc, AppProto alproto, TxLogger TxLogFunc, ThreadInitFunc ThreadInit, ThreadDeinitFunc ThreadDeinit)
Register a tx output module.
Definition: output.c:372
OutputModule_::alproto
AppProto alproto
Definition: output.h:78
JsonTlsLogRegister
void JsonTlsLogRegister(void)
Definition: output-json-tls.c:668
OutputRegisterFileSubModule
void OutputRegisterFileSubModule(LoggerId id, const char *parent_name, const char *name, const char *conf_name, OutputInitSubFunc InitFunc, SCFileLogger FileLogFunc, ThreadInitFunc ThreadInit, ThreadDeinitFunc ThreadDeinit)
Register a file output sub-module.
Definition: output.c:396
alert-syslog.h
JsonFlowLogRegister
void JsonFlowLogRegister(void)
Definition: output-json-flow.c:356
OutputPacketLoggerFunctions_::ConditionFunc
PacketLogCondition ConditionFunc
Definition: output.h:90
JsonPgsqlAddMetadata
bool JsonPgsqlAddMetadata(void *vtx, JsonBuilder *jb)
Definition: output-json-pgsql.c:62
TmModuleLoggerRegister
void TmModuleLoggerRegister(void)
Definition: output.c:848
JsonTlsLogJSONExtended
bool JsonTlsLogJSONExtended(void *vtx, JsonBuilder *tjs)
Definition: output-json-tls.c:458
output-json-dcerpc.h
EveFTPDataAddMetadata
bool EveFTPDataAddMetadata(void *vtx, JsonBuilder *jb)
Definition: app-layer-ftp.c:1376
TM_ECODE_OK
@ TM_ECODE_OK
Definition: tm-threads-common.h:80
OutputJsonRegister
void OutputJsonRegister(void)
Definition: output-json.c:83
OutputClearActiveLoggers
void OutputClearActiveLoggers(void)
Definition: output.c:839
ALPROTO_KRB5
@ ALPROTO_KRB5
Definition: app-layer-protos.h:56
OutputJsonThreadCtx_
Definition: output-json.h:89
ALPROTO_SNMP
@ ALPROTO_SNMP
Definition: app-layer-protos.h:59
TAILQ_ENTRY
#define TAILQ_ENTRY(type)
Definition: queue.h:239
RootLogger_::LogFunc
OutputLogFunc LogFunc
Definition: output.c:87
output-json-dnp3.h
OutputRegisterFileRotationFlag
void OutputRegisterFileRotationFlag(int *flag)
Register a flag for file rotation notification.
Definition: output.c:666
LogHttpLogRegister
void LogHttpLogRegister(void)
Definition: log-httplog.c:65
AlertJsonDnp3
bool AlertJsonDnp3(void *vtx, JsonBuilder *js)
Definition: output-json-dnp3.c:213
OutputRegisterFlowSubModule
void OutputRegisterFlowSubModule(LoggerId id, const char *parent_name, const char *name, const char *conf_name, OutputInitSubFunc InitFunc, FlowLogger FlowLogFunc, ThreadInitFunc ThreadInit, ThreadDeinitFunc ThreadDeinit)
Register a flow output sub-module.
Definition: output.c:469
OutputModule_::stream_type
enum SCOutputStreamingType stream_type
Definition: output.h:79
OutputModule_::ThreadInit
ThreadInitFunc ThreadInit
Definition: output.h:65
OutputRegisterTxModuleWithCondition
void OutputRegisterTxModuleWithCondition(LoggerId id, const char *name, const char *conf_name, OutputInitFunc InitFunc, AppProto alproto, TxLogger TxLogFunc, TxLoggerCondition TxLogCondition, ThreadInitFunc ThreadInit, ThreadDeinitFunc ThreadDeinit)
Register a tx output module with condition.
Definition: output.c:323
TAILQ_HEAD_INITIALIZER
#define TAILQ_HEAD_INITIALIZER(head)
Definition: queue.h:236
output_modules
OutputModuleList output_modules
OutputInitSubFunc
OutputInitResult(* OutputInitSubFunc)(ConfNode *, OutputCtx *)
Definition: output.h:52
JsonAnomalyLogRegister
void JsonAnomalyLogRegister(void)
Definition: output-json-anomaly.c:458
TAILQ_REMOVE
#define TAILQ_REMOVE(head, elm, field)
Definition: queue.h:312
util-debug.h
output-json-flow.h
TAILQ_FIRST
#define TAILQ_FIRST(head)
Definition: queue.h:250
OutputStreamingLoggerRegister
void OutputStreamingLoggerRegister(void)
Definition: output-streaming.c:434
util-error.h
OutputRegisterStatsModule
void OutputRegisterStatsModule(LoggerId id, const char *name, const char *conf_name, OutputInitFunc InitFunc, StatsLogger StatsLogFunc, ThreadInitFunc ThreadInit, ThreadDeinitFunc ThreadDeinit)
Register a stats data output module.
Definition: output.c:544
log-tcp-data.h
g_alproto_max
AppProto g_alproto_max
Definition: app-layer-protos.c:29
OutputModule_::ThreadDeinit
ThreadDeinitFunc ThreadDeinit
Definition: output.h:66
ALPROTO_DNP3
@ ALPROTO_DNP3
Definition: app-layer-protos.h:50
output-json.h
OutputRegisterTxModuleWithProgress
void OutputRegisterTxModuleWithProgress(LoggerId id, const char *name, const char *conf_name, OutputInitFunc InitFunc, AppProto alproto, TxLogger TxLogFunc, int tc_log_progress, int ts_log_progress, ThreadInitFunc ThreadInit, ThreadDeinitFunc ThreadDeinit)
Register a tx output module with progress.
Definition: output.c:347
output-json-file.h
OutputRegisterModule
void OutputRegisterModule(const char *, const char *, OutputInitFunc)
CreateEveHeader
JsonBuilder * CreateEveHeader(const Packet *p, enum OutputJsonLogDirection dir, const char *event_type, JsonAddrInfo *addr, OutputJsonCtx *eve_ctx)
Definition: output-json.c:807
JsonIKELogRegister
void JsonIKELogRegister(void)
Definition: output-json-ike.c:182
ThreadVars_
Per thread variable structure.
Definition: threadvars.h:58
ThreadInitFunc
TmEcode(* ThreadInitFunc)(ThreadVars *, const void *, void **)
Definition: tm-modules.h:39
OutputModule_::StreamingLogFunc
SCStreamingLogger StreamingLogFunc
Definition: output.h:76
log-tlslog.h
EveFTPLogCommand
bool EveFTPLogCommand(void *vtx, JsonBuilder *jb)
Definition: output-json-ftp.c:49
OutputLoggerThreadInit
TmEcode OutputLoggerThreadInit(ThreadVars *tv, const void *initdata, void **data)
Definition: output.c:740
app-layer-parser.h
JsonMQTTLogRegister
void JsonMQTTLogRegister(void)
Definition: output-json-mqtt.c:193
BUG_ON
#define BUG_ON(x)
Definition: suricata-common.h:309
OutputFilestoreRegister
void OutputFilestoreRegister(void)
Definition: output-filestore.c:506
OutputFlushFunc
TmEcode(* OutputFlushFunc)(ThreadVars *, Packet *, void *)
Definition: output.h:54
OutputRegisterLoggers
void OutputRegisterLoggers(void)
Register all non-root logging modules.
Definition: output.c:999
OutputModule_::conf_name
const char * conf_name
Definition: output.h:60
output-json-anomaly.h
OutputModule_::FlowLogFunc
FlowLogger FlowLogFunc
Definition: output.h:75
OutputDeregisterAll
void OutputDeregisterAll(void)
Deregister all modules. Useful for a memory clean exit.
Definition: output.c:632
Packet_
Definition: decode.h:476
RootLogger_::ActiveCntFunc
OutputGetActiveCountFunc ActiveCntFunc
Definition: output.c:91
OutputPacketLoggerRegister
void OutputPacketLoggerRegister(void)
Definition: output-packet.c:194
EveJsonTxLoggerRegistrationData
Definition: output.h:184
ALPROTO_RDP
@ ALPROTO_RDP
Definition: app-layer-protos.h:69
conf.h
OutputNotifyFileRotation
void OutputNotifyFileRotation(void)
Notifies all registered file rotation notification flags.
Definition: output.c:704
TAILQ_HEAD
typedef TAILQ_HEAD(LoggerThreadStore_, LoggerThreadStoreNode_)
Definition: output.c:112
TmEcode
TmEcode
Definition: tm-threads-common.h:79
ALPROTO_DOH2
@ ALPROTO_DOH2
Definition: app-layer-protos.h:67
name
const char * name
Definition: tm-threads.c:2081
EveStreamLogRegister
void EveStreamLogRegister(void)
Definition: output-eve-stream.c:453
ALPROTO_TFTP
@ ALPROTO_TFTP
Definition: app-layer-protos.h:54
RootLogger_::ThreadInit
ThreadInitFunc ThreadInit
Definition: output.c:89
ALPROTO_HTTP2
@ ALPROTO_HTTP2
Definition: app-layer-protos.h:70
EveJsonSimpleAppLayerLogger
Definition: output.h:177
log-pcap.h
SCRealloc
#define SCRealloc(ptr, sz)
Definition: util-mem.h:50
alert-fastlog.h
TxLoggerCondition
bool(* TxLoggerCondition)(ThreadVars *, const Packet *, void *state, void *tx, uint64_t tx_id)
Transaction logger condition function pointer type.
Definition: output-tx.h:41
LogStatsLogRegister
void LogStatsLogRegister(void)
Definition: log-stats.c:285
OutputPacketLoggerFunctions_::ThreadDeinitFunc
ThreadDeinitFunc ThreadDeinitFunc
Definition: output.h:92
JsonFrameLogRegister
void JsonFrameLogRegister(void)
Definition: output-json-frame.c:561
cnt
uint32_t cnt
Definition: tmqh-packetpool.h:7
Packet_::flow
struct Flow_ * flow
Definition: decode.h:515
OutputModule_::TxLogCondition
TxLoggerCondition TxLogCondition
Definition: output.h:72
LOG_DIR_PACKET
@ LOG_DIR_PACKET
Definition: output-json.h:37
AlertJsonDns
bool AlertJsonDns(void *txptr, JsonBuilder *js)
Definition: output-json-dns.c:251
suricata-common.h
output-json-stats.h
EveJsonSimpleAppLayerLogger::LogTx
EveJsonSimpleTxLogFunc LogTx
Definition: output.h:178
ARRAY_CAP_STEP
#define ARRAY_CAP_STEP
Definition: output.c:970
output-json-nfs.h
ALPROTO_PGSQL
@ ALPROTO_PGSQL
Definition: app-layer-protos.h:63
TAILQ_NEXT
#define TAILQ_NEXT(elm, field)
Definition: queue.h:307
OutputPacketLoggerFunctions_::LogFunc
PacketLogger LogFunc
Definition: output.h:88
OutputRegisterPacketModule
void OutputRegisterPacketModule(LoggerId id, const char *name, const char *conf_name, OutputInitFunc InitFunc, OutputPacketLoggerFunctions *output_module_functions)
Register a packet output module.
Definition: output.c:170
ALPROTO_FTPDATA
@ ALPROTO_FTPDATA
Definition: app-layer-protos.h:53
output-filestore.h
FatalError
#define FatalError(...)
Definition: util-debug.h:502
LuaLogRegister
void LuaLogRegister(void)
Definition: output-lua.c:931
ALPROTO_WEBSOCKET
@ ALPROTO_WEBSOCKET
Definition: app-layer-protos.h:65
OutputRegisterPacketSubModule
void OutputRegisterPacketSubModule(LoggerId id, const char *parent_name, const char *name, const char *conf_name, OutputInitSubFunc InitFunc, OutputPacketLoggerFunctions *output_logger_functions)
Register a packet output sub-module.
Definition: output.c:208
JsonSmtpLogRegister
void JsonSmtpLogRegister(void)
Definition: output-json-smtp.c:192
tv
ThreadVars * tv
Definition: fuzz_decodepcapfile.c:32
log-httplog.h
JsonMetadataLogRegister
void JsonMetadataLogRegister(void)
Definition: output-json-metadata.c:95
output-json-alert.h
OutputModule_::PacketConditionFunc
PacketLogCondition PacketConditionFunc
Definition: output.h:70
RootLogger
struct RootLogger_ RootLogger
LOG_DIR_FLOW
@ LOG_DIR_FLOW
Definition: output-json.h:38
output-json-dns.h
OutputGetActiveCountFunc
uint32_t(* OutputGetActiveCountFunc)(void)
Definition: output.h:55
OutputPacketLoggerFunctions_::ThreadInitFunc
ThreadInitFunc ThreadInitFunc
Definition: output.h:91
log-cf-common.h
output-json-metadata.h
LOGGER_JSON_TX
@ LOGGER_JSON_TX
Definition: suricata-common.h:477
EveJsonSimpleAppLayerLogger::name
const char * name
Definition: output.h:179
JsonDnsLogRegister
void JsonDnsLogRegister(void)
Definition: output-json-dns.c:671
SCLogError
#define SCLogError(...)
Macro used to log ERROR messages.
Definition: util-debug.h:261
OutputLoggerLog
TmEcode OutputLoggerLog(ThreadVars *tv, Packet *p, void *thread_data)
Definition: output.c:726
SCFree
#define SCFree(p)
Definition: util-mem.h:61
output-json-dhcp.h
OutputLoggerFlush
TmEcode OutputLoggerFlush(ThreadVars *tv, Packet *p, void *thread_data)
Definition: output.c:711
JsonMQTTAddMetadata
bool JsonMQTTAddMetadata(void *vtx, JsonBuilder *js)
Definition: output-json-mqtt.c:63
JsonDropLogRegister
void JsonDropLogRegister(void)
Definition: output-json-drop.c:391
output-json-ike.h
StatsLogger
int(* StatsLogger)(ThreadVars *, void *thread_data, const StatsTable *)
Definition: output-stats.h:50
OutputModule_::TxLogFunc
TxLogger TxLogFunc
Definition: output.h:71
ALPROTO_MQTT
@ ALPROTO_MQTT
Definition: app-layer-protos.h:62
OutputModule_::tc_log_progress
int tc_log_progress
Definition: output.h:80
OutputInitFunc
OutputInitResult(* OutputInitFunc)(ConfNode *)
Definition: output.h:51
ALPROTO_TEMPLATE
@ ALPROTO_TEMPLATE
Definition: app-layer-protos.h:68
output-lua.h
ALPROTO_RFB
@ ALPROTO_RFB
Definition: app-layer-protos.h:61
JsonHttpLogRegister
void JsonHttpLogRegister(void)
Definition: output-json-http.c:648
ALPROTO_BITTORRENT_DHT
@ ALPROTO_BITTORRENT_DHT
Definition: app-layer-protos.h:71
output-json-smb.h
JsonArpLogRegister
void JsonArpLogRegister(void)
Definition: output-json-arp.c:104
SCOutputStreamingType
SCOutputStreamingType
Definition: output-streaming.h:35
output-json-smtp.h
JsonLogThreadDeinit
TmEcode JsonLogThreadDeinit(ThreadVars *t, void *data)
Definition: output-json-common.c:132
output-json-http.h
OutputPreRegisterLogger
int OutputPreRegisterLogger(EveJsonTxLoggerRegistrationData reg_data)
Definition: output.c:979
flow.h
OutputModule_
Definition: output.h:57
AlertDebugLogRegister
void AlertDebugLogRegister(void)
Definition: alert-debuglog.c:482
OutputUnregisterFileRotationFlag
void OutputUnregisterFileRotationFlag(int *flag)
Unregister a file rotation flag.
Definition: output.c:687
OutputRegisterTxSubModuleWithCondition
void OutputRegisterTxSubModuleWithCondition(LoggerId id, const char *parent_name, const char *name, const char *conf_name, OutputInitSubFunc InitFunc, AppProto alproto, TxLogger TxLogFunc, TxLoggerCondition TxLogCondition, ThreadInitFunc ThreadInit, ThreadDeinitFunc ThreadDeinit)
Definition: output.c:331
log-tlsstore.h
Flow_::alproto
AppProto alproto
application level protocol
Definition: flow.h:448
SCCalloc
#define SCCalloc(nm, sz)
Definition: util-mem.h:53
OutputFiledataLoggerRegister
void OutputFiledataLoggerRegister(void)
Definition: output-filedata.c:271
OutputPacketLoggerFunctions_
Definition: output.h:87
SCStreamingLogger
int(* SCStreamingLogger)(ThreadVars *, void *thread_data, const Flow *f, const uint8_t *data, uint32_t data_len, uint64_t tx_id, uint8_t flags)
Definition: output-streaming.h:41
output.h
JsonAlertLogRegister
void JsonAlertLogRegister(void)
Definition: output-json-alert.c:1074
JsonNFSLogRegister
void JsonNFSLogRegister(void)
Definition: output-json-nfs.c:110
OutputDropLoggerDisable
void OutputDropLoggerDisable(void)
Definition: output.c:654
JsonNetFlowLogRegister
void JsonNetFlowLogRegister(void)
Definition: output-json-netflow.c:295
ThreadDeinitFunc
TmEcode(* ThreadDeinitFunc)(ThreadVars *, void *)
Definition: tm-modules.h:40
OutputModule_::InitFunc
OutputInitFunc InitFunc
Definition: output.h:62
RootLogger_
Definition: output.c:86
output-json-drop.h