suricata
tm-modules.h
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 Victor Julien <victor@inliniac.net>
22 */
23
24#ifndef SURICATA_TM_MODULES_H
25#define SURICATA_TM_MODULES_H
26
27#include "tm-threads-common.h"
28#include "threadvars.h"
29#include "decode.h"
30
31/* thread flags */
32#define TM_FLAG_RECEIVE_TM 0x01
33#define TM_FLAG_DECODE_TM 0x02
34#define TM_FLAG_FLOWWORKER_TM 0x04
35#define TM_FLAG_VERDICT_TM 0x08
36#define TM_FLAG_MANAGEMENT_TM 0x10
37#define TM_FLAG_COMMAND_TM 0x20
38
39/* all packet modules combined */
40#define TM_FLAG_PACKET_ALL \
41 (TM_FLAG_RECEIVE_TM | TM_FLAG_DECODE_TM | TM_FLAG_FLOWWORKER_TM | TM_FLAG_VERDICT_TM)
42
43typedef TmEcode (*ThreadInitFunc)(ThreadVars *, const void *, void **);
44typedef TmEcode (*ThreadDeinitFunc)(ThreadVars *, void *);
45typedef void (*ThreadExitPrintStatsFunc)(ThreadVars *, void *);
46
47typedef struct TmModule_ {
48 const char *name;
49
50 /** thread handling */
51 TmEcode (*ThreadInit)(ThreadVars *, const void *, void **);
52 void (*ThreadExitPrintStats)(ThreadVars *, void *);
54
55 /** the packet processing function */
56 TmEcode (*Func)(ThreadVars *, Packet *, void *);
57
58 TmEcode (*PktAcqLoop)(ThreadVars *, void *, void *);
59
60 /** terminates the capture loop in PktAcqLoop */
62
63 /** does a thread still have tasks to complete before it can be killed?
64 * \retval bool
65 * \param tv threadvars
66 * \param thread_data thread module thread data (e.g. FlowWorkerThreadData for FlowWorker) */
67 bool (*ThreadBusy)(ThreadVars *tv, void *thread_data);
68
70
71 /** global Init/DeInit */
72 TmEcode (*Init)(void);
73 TmEcode (*DeInit)(void);
74#ifdef UNITTESTS
75 void (*RegisterTests)(void);
76#endif
77 uint8_t cap_flags; /**< Flags to indicate the capability requirement of
78 the given TmModule */
79 /* Other flags used by the module */
80 uint8_t flags;
82
84
85/**
86 * Structure that output modules use to maintain private data.
87 */
88typedef struct OutputCtx_ {
89
90 /** Pointer to data private to the output. */
91 void *data;
92
93 /** Pointer to a cleanup function. */
94 void (*DeInit)(struct OutputCtx_ *);
95
98
99TmModule *TmModuleGetByName(const char *name);
102TmEcode TmModuleRegister(char *name, int (*module_func)(ThreadVars *, Packet *, void *));
103void TmModuleDebugList(void);
104void TmModuleRegisterTests(void);
105#ifdef PROFILING
106const char * TmModuleTmmIdToString(TmmId id);
107#endif
108void TmModuleRunInit(void);
109void TmModuleRunDeInit(void);
110
111#endif /* SURICATA_TM_MODULES_H */
ThreadVars * tv
void * data
Definition tm-modules.h:91
TAILQ_HEAD(, OutputModule_) submodules
void(* DeInit)(struct OutputCtx_ *)
Definition tm-modules.h:94
Per thread variable structure.
Definition threadvars.h:58
const char * name
Definition tm-modules.h:48
TmEcode(* ThreadDeinit)(ThreadVars *, void *)
Definition tm-modules.h:53
void(* RegisterTests)(void)
Definition tm-modules.h:75
void(* ThreadExitPrintStats)(ThreadVars *, void *)
Definition tm-modules.h:52
bool(* ThreadBusy)(ThreadVars *tv, void *thread_data)
Definition tm-modules.h:67
TmEcode(* DeInit)(void)
Definition tm-modules.h:73
TmEcode(* PktAcqBreakLoop)(ThreadVars *, void *)
Definition tm-modules.h:61
uint8_t cap_flags
Definition tm-modules.h:77
TmEcode(* Init)(void)
Definition tm-modules.h:72
TmEcode(* Func)(ThreadVars *, Packet *, void *)
Definition tm-modules.h:56
TmEcode(* PktAcqLoop)(ThreadVars *, void *, void *)
Definition tm-modules.h:58
uint8_t flags
Definition tm-modules.h:80
TmEcode(* ThreadInit)(ThreadVars *, const void *, void **)
Definition tm-modules.h:51
TmEcode(* Management)(ThreadVars *, void *)
Definition tm-modules.h:69
void TmModuleRegisterTests(void)
register all unittests for the tm modules
Definition tm-modules.c:135
void TmModuleRunDeInit(void)
Definition tm-modules.c:119
void TmModuleRunInit(void)
Definition tm-modules.c:104
void(* ThreadExitPrintStatsFunc)(ThreadVars *, void *)
Definition tm-modules.h:45
const char * TmModuleTmmIdToString(TmmId id)
Maps the TmmId, to its string equivalent.
Definition tm-modules.c:170
struct OutputCtx_ OutputCtx
int TmModuleGetIDForTM(TmModule *tm)
Given a TM Module, returns its id.
Definition tm-modules.c:88
TmEcode TmModuleRegister(char *name, int(*module_func)(ThreadVars *, Packet *, void *))
TmEcode(* ThreadDeinitFunc)(ThreadVars *, void *)
Definition tm-modules.h:44
TmModule * TmModuleGetById(int id)
Returns a TM Module by its id.
Definition tm-modules.c:69
TmEcode(* ThreadInitFunc)(ThreadVars *, const void *, void **)
Definition tm-modules.h:43
TmModule * TmModuleGetByName(const char *name)
get a tm module ptr by name
Definition tm-modules.c:46
TmModule tmm_modules[TMM_SIZE]
Definition tm-modules.c:29
struct TmModule_ TmModule
void TmModuleDebugList(void)
Definition tm-modules.c:31
TmmId
Thread Model Module id's.
@ TMM_SIZE
const char * name