suricata
tm-modules.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 Victor Julien <victor@inliniac.net>
22 *
23 * Thread Module functions
24 */
25
26#include "tm-modules.h"
27#include "util-debug.h"
28
30
32{
33 for (uint16_t i = 0; i < TMM_SIZE; i++) {
34 TmModule *t = &tmm_modules[i];
35
36 if (t->name == NULL)
37 continue;
38
39 SCLogDebug("%s:%p", t->name, t->Func);
40 }
41}
42
43/** \brief get a tm module ptr by name
44 * \param name name string
45 * \retval ptr to the module or NULL */
47{
48 for (uint16_t i = 0; i < TMM_SIZE; i++) {
49 TmModule *t = &tmm_modules[i];
50
51 if (t->name == NULL)
52 continue;
53
54 if (strcmp(t->name, name) == 0)
55 return t;
56 }
57
58 return NULL;
59}
60
61/**
62 * \brief Returns a TM Module by its id.
63 *
64 * \param id Id of the TM Module to return.
65 *
66 * \retval Pointer of the module to be returned if available;
67 * NULL if unavailable.
68 */
70{
71 if (id < 0 || id >= TMM_SIZE) {
72 SCLogError("Threading module with the id "
73 "\"%d\" doesn't exist",
74 id);
75 return NULL;
76 }
77
78 return &tmm_modules[id];
79}
80
81/**
82 * \brief Given a TM Module, returns its id.
83 *
84 * \param tm Pointer to the TM Module.
85 *
86 * \retval id of the TM Module if available; -1 if unavailable.
87 */
89{
90 for (uint16_t i = 0; i < TMM_SIZE; i++) {
91 TmModule *t = &tmm_modules[i];
92
93 if (t->name == NULL)
94 continue;
95
96 if (strcmp(t->name, tm->name) == 0)
97 return i;
98 }
99
100 return -1;
101}
102
103
105{
106 for (uint16_t i = 0; i < TMM_SIZE; i++) {
107 TmModule *t = &tmm_modules[i];
108
109 if (t->name == NULL)
110 continue;
111
112 if (t->Init == NULL)
113 continue;
114
115 t->Init();
116 }
117}
118
120{
121 for (uint16_t i = 0; i < TMM_SIZE; i++) {
122 TmModule *t = &tmm_modules[i];
123
124 if (t->name == NULL)
125 continue;
126
127 if (t->DeInit == NULL)
128 continue;
129
130 t->DeInit();
131 }
132}
133
134/** \brief register all unittests for the tm modules */
136{
137#ifdef UNITTESTS
138 for (uint16_t i = 0; i < TMM_SIZE; i++) {
139 TmModule *t = &tmm_modules[i];
140
141 if (t->name == NULL)
142 continue;
143
144 g_ut_modules++;
145
146
147 if (t->RegisterTests == NULL) {
149 SCLogWarning("threading module %s has no unittest "
150 "registration function.",
151 t->name);
152 } else {
153 t->RegisterTests();
154 g_ut_covered++;
155 }
156 }
157#endif /* UNITTESTS */
158}
159
160#ifdef PROFILING
161#define CASE_CODE(E) case E: return #E
162
163/**
164 * \brief Maps the TmmId, to its string equivalent
165 *
166 * \param id tmm id
167 *
168 * \retval string equivalent for the tmm id
169 */
217#endif
uint32_t id
const char * name
Definition tm-modules.h:48
void(* RegisterTests)(void)
Definition tm-modules.h:75
TmEcode(* DeInit)(void)
Definition tm-modules.h:73
TmEcode(* Init)(void)
Definition tm-modules.h:72
TmEcode(* Func)(ThreadVars *, Packet *, void *)
Definition tm-modules.h:56
int coverage_unittests
Definition suricata.c:943
int g_ut_covered
Definition suricata.c:945
int g_ut_modules
Definition suricata.c:944
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
const char * TmModuleTmmIdToString(TmmId id)
Maps the TmmId, to its string equivalent.
Definition tm-modules.c:170
#define CASE_CODE(E)
Definition tm-modules.c:161
int TmModuleGetIDForTM(TmModule *tm)
Given a TM Module, returns its id.
Definition tm-modules.c:88
TmModule * TmModuleGetById(int id)
Returns a TM Module by its id.
Definition tm-modules.c:69
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
void TmModuleDebugList(void)
Definition tm-modules.c:31
TmmId
Thread Model Module id's.
@ TMM_RECEIVEPLUGIN
@ TMM_DECODENFLOG
@ TMM_DECODEPLUGIN
@ TMM_DECODEERFFILE
@ TMM_FLOWMANAGER
@ TMM_DECODENETMAP
@ TMM_RECEIVEERFFILE
@ TMM_RECEIVEAFXDP
@ TMM_FLOWWORKER
@ TMM_VERDICTNFQ
@ TMM_RECEIVENETMAP
@ TMM_RECEIVEAFP
@ TMM_BYPASSEDFLOWMANAGER
@ TMM_RESPONDREJECT
@ TMM_RECEIVENFLOG
@ TMM_DECODEAFXDP
@ TMM_RECEIVEPCAPFILE
@ TMM_RECEIVEPCAP
@ TMM_DECODEERFDAG
@ TMM_RECEIVEWINDIVERT
@ TMM_RECEIVEDPDK
@ TMM_DECODEPCAP
@ TMM_DECODEIPFW
@ TMM_UNIXMANAGER
@ TMM_DETECTLOADER
@ TMM_VERDICTIPFW
@ TMM_DECODEPCAPFILE
@ TMM_DECODENFQ
@ TMM_SIZE
@ TMM_DECODEWINDIVERT
@ TMM_FLOWRECYCLER
@ TMM_STATSLOGGER
@ TMM_RECEIVENFQ
@ TMM_DECODEDPDK
@ TMM_RECEIVEERFDAG
@ TMM_VERDICTWINDIVERT
@ TMM_RECEIVEIPFW
@ TMM_DECODEAFP
@ TMM_ALERTPCAPINFO
@ TMM_DECODELIB
const char * name
#define SCLogDebug(...)
Definition util-debug.h:275
#define SCLogWarning(...)
Macro used to log WARNING messages.
Definition util-debug.h:255
#define SCLogError(...)
Macro used to log ERROR messages.
Definition util-debug.h:267