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 */
46 TmModule *TmModuleGetByName(const char *name)
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 
104 void TmModuleRunInit(void)
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) {
148  if (coverage_unittests)
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  */
170 const char * TmModuleTmmIdToString(TmmId id)
171 {
172  switch (id) {
211 
213  }
214  return "<unknown>";
215 }
216 #endif
TMM_RECEIVEERFFILE
@ TMM_RECEIVEERFFILE
Definition: tm-threads-common.h:48
TMM_RECEIVEPLUGIN
@ TMM_RECEIVEPLUGIN
Definition: tm-threads-common.h:42
TMM_RECEIVEDPDK
@ TMM_RECEIVEDPDK
Definition: tm-threads-common.h:56
TMM_RECEIVEERFDAG
@ TMM_RECEIVEERFDAG
Definition: tm-threads-common.h:50
g_ut_modules
int g_ut_modules
Definition: suricata.c:890
TMM_FLOWRECYCLER
@ TMM_FLOWRECYCLER
Definition: tm-threads-common.h:69
TmModuleTmmIdToString
const char * TmModuleTmmIdToString(TmmId id)
Maps the TmmId, to its string equivalent.
Definition: tm-modules.c:170
TMM_DECODENFQ
@ TMM_DECODENFQ
Definition: tm-threads-common.h:35
SCLogDebug
#define SCLogDebug(...)
Definition: util-debug.h:269
TMM_DECODEDPDK
@ TMM_DECODEDPDK
Definition: tm-threads-common.h:57
TMM_STATSLOGGER
@ TMM_STATSLOGGER
Definition: tm-threads-common.h:61
TMM_RECEIVEAFXDP
@ TMM_RECEIVEAFXDP
Definition: tm-threads-common.h:53
TmModuleRunDeInit
void TmModuleRunDeInit(void)
Definition: tm-modules.c:119
g_ut_covered
int g_ut_covered
Definition: suricata.c:891
tm-modules.h
TmModuleRegisterTests
void TmModuleRegisterTests(void)
register all unittests for the tm modules
Definition: tm-modules.c:135
TMM_DECODEWINDIVERT
@ TMM_DECODEWINDIVERT
Definition: tm-threads-common.h:66
TmModuleGetByName
TmModule * TmModuleGetByName(const char *name)
get a tm module ptr by name
Definition: tm-modules.c:46
TMM_DECODEPLUGIN
@ TMM_DECODEPLUGIN
Definition: tm-threads-common.h:43
TMM_DECODENFLOG
@ TMM_DECODENFLOG
Definition: tm-threads-common.h:63
TMM_BYPASSEDFLOWMANAGER
@ TMM_BYPASSEDFLOWMANAGER
Definition: tm-threads-common.h:70
TMM_DECODEAFP
@ TMM_DECODEAFP
Definition: tm-threads-common.h:54
util-debug.h
TMM_RECEIVEPCAPFILE
@ TMM_RECEIVEPCAPFILE
Definition: tm-threads-common.h:39
TMM_UNIXMANAGER
@ TMM_UNIXMANAGER
Definition: tm-threads-common.h:73
TmModule_::Init
TmEcode(* Init)(void)
Definition: tm-modules.h:68
TmModule_::Func
TmEcode(* Func)(ThreadVars *, Packet *, void *)
Definition: tm-modules.h:52
TMM_DECODEAFXDP
@ TMM_DECODEAFXDP
Definition: tm-threads-common.h:55
TmModuleRunInit
void TmModuleRunInit(void)
Definition: tm-modules.c:104
SCLogWarning
#define SCLogWarning(...)
Macro used to log WARNING messages.
Definition: util-debug.h:249
TMM_DECODENETMAP
@ TMM_DECODENETMAP
Definition: tm-threads-common.h:59
TmModuleGetIDForTM
int TmModuleGetIDForTM(TmModule *tm)
Given a TM Module, returns its id.
Definition: tm-modules.c:88
TMM_DECODEERFDAG
@ TMM_DECODEERFDAG
Definition: tm-threads-common.h:51
tmm_modules
TmModule tmm_modules[TMM_SIZE]
Definition: tm-modules.c:29
TMM_DECODEPCAPFILE
@ TMM_DECODEPCAPFILE
Definition: tm-threads-common.h:41
TMM_SIZE
@ TMM_SIZE
Definition: tm-threads-common.h:75
TmModuleGetById
TmModule * TmModuleGetById(int id)
Returns a TM Module by its id.
Definition: tm-modules.c:69
TmModule_::RegisterTests
void(* RegisterTests)(void)
Definition: tm-modules.h:71
TMM_DECODEERFFILE
@ TMM_DECODEERFFILE
Definition: tm-threads-common.h:49
TmModule_::name
const char * name
Definition: tm-modules.h:44
TmModuleDebugList
void TmModuleDebugList(void)
Definition: tm-modules.c:31
TmModule_
Definition: tm-modules.h:43
TMM_FLOWMANAGER
@ TMM_FLOWMANAGER
Definition: tm-threads-common.h:68
TMM_FLOWWORKER
@ TMM_FLOWWORKER
Definition: tm-threads-common.h:34
TMM_RECEIVEAFP
@ TMM_RECEIVEAFP
Definition: tm-threads-common.h:52
TMM_DETECTLOADER
@ TMM_DETECTLOADER
Definition: tm-threads-common.h:71
TMM_RESPONDREJECT
@ TMM_RESPONDREJECT
Definition: tm-threads-common.h:44
TMM_RECEIVENFLOG
@ TMM_RECEIVENFLOG
Definition: tm-threads-common.h:62
TMM_RECEIVEIPFW
@ TMM_RECEIVEIPFW
Definition: tm-threads-common.h:47
TmmId
TmmId
Thread Model Module id's.
Definition: tm-threads-common.h:33
TMM_VERDICTNFQ
@ TMM_VERDICTNFQ
Definition: tm-threads-common.h:36
TMM_RECEIVEWINDIVERT
@ TMM_RECEIVEWINDIVERT
Definition: tm-threads-common.h:64
TMM_RECEIVENFQ
@ TMM_RECEIVENFQ
Definition: tm-threads-common.h:37
TMM_VERDICTIPFW
@ TMM_VERDICTIPFW
Definition: tm-threads-common.h:46
TMM_RECEIVENETMAP
@ TMM_RECEIVENETMAP
Definition: tm-threads-common.h:58
TMM_DECODEPCAP
@ TMM_DECODEPCAP
Definition: tm-threads-common.h:40
SCLogError
#define SCLogError(...)
Macro used to log ERROR messages.
Definition: util-debug.h:261
TMM_RECEIVEPCAP
@ TMM_RECEIVEPCAP
Definition: tm-threads-common.h:38
CASE_CODE
#define CASE_CODE(E)
Definition: tm-modules.c:161
TMM_DECODEIPFW
@ TMM_DECODEIPFW
Definition: tm-threads-common.h:45
TMM_ALERTPCAPINFO
@ TMM_ALERTPCAPINFO
Definition: tm-threads-common.h:60
coverage_unittests
int coverage_unittests
Definition: suricata.c:889
TMM_VERDICTWINDIVERT
@ TMM_VERDICTWINDIVERT
Definition: tm-threads-common.h:65
TmModule_::DeInit
TmEcode(* DeInit)(void)
Definition: tm-modules.h:69