suricata
tm-modules.c
Go to the documentation of this file.
1 /* Copyright (C) 2007-2010 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 "suricata-common.h"
27 #include "packet-queue.h"
28 #include "tm-threads.h"
29 #include "util-debug.h"
30 #include "threads.h"
31 #include "util-logopenfile.h"
32 
34 
36 {
37  TmModule *t;
38  uint16_t i;
39 
40  for (i = 0; i < TMM_SIZE; i++) {
41  t = &tmm_modules[i];
42 
43  if (t->name == NULL)
44  continue;
45 
46  SCLogDebug("%s:%p", t->name, t->Func);
47  }
48 }
49 
50 /** \brief get a tm module ptr by name
51  * \param name name string
52  * \retval ptr to the module or NULL */
53 TmModule *TmModuleGetByName(const char *name)
54 {
55  TmModule *t;
56  uint16_t i;
57 
58  for (i = 0; i < TMM_SIZE; i++) {
59  t = &tmm_modules[i];
60 
61  if (t->name == NULL)
62  continue;
63 
64  if (strcmp(t->name, name) == 0)
65  return t;
66  }
67 
68  return NULL;
69 }
70 
71 /** \brief get the id of a module from it's name
72  * \param name registered name of the module
73  * \retval id the id or -1 in case of error */
74 int TmModuleGetIdByName(const char *name)
75 {
76  TmModule *tm = TmModuleGetByName(name);
77  if (tm == NULL)
78  return -1;
79  return TmModuleGetIDForTM(tm);
80 }
81 
82 /**
83  * \brief Returns a TM Module by its id.
84  *
85  * \param id Id of the TM Module to return.
86  *
87  * \retval Pointer of the module to be returned if available;
88  * NULL if unavailable.
89  */
91 {
92 
93  if (id < 0 || id >= TMM_SIZE) {
94  SCLogError("Threading module with the id "
95  "\"%d\" doesn't exist",
96  id);
97  return NULL;
98  }
99 
100  return &tmm_modules[id];
101 }
102 
103 /**
104  * \brief Given a TM Module, returns its id.
105  *
106  * \param tm Pointer to the TM Module.
107  *
108  * \retval id of the TM Module if available; -1 if unavailable.
109  */
111 {
112  TmModule *t;
113  int i;
114 
115  for (i = 0; i < TMM_SIZE; i++) {
116  t = &tmm_modules[i];
117 
118  if (t->name == NULL)
119  continue;
120 
121  if (strcmp(t->name, tm->name) == 0)
122  return i;
123  }
124 
125  return -1;
126 }
127 
128 
129 void TmModuleRunInit(void)
130 {
131  TmModule *t;
132  uint16_t i;
133 
134  for (i = 0; i < TMM_SIZE; i++) {
135  t = &tmm_modules[i];
136 
137  if (t->name == NULL)
138  continue;
139 
140  if (t->Init == NULL)
141  continue;
142 
143  t->Init();
144  }
145 }
146 
148 {
149  TmModule *t;
150  uint16_t i;
151 
152  for (i = 0; i < TMM_SIZE; i++) {
153  t = &tmm_modules[i];
154 
155  if (t->name == NULL)
156  continue;
157 
158  if (t->DeInit == NULL)
159  continue;
160 
161  t->DeInit();
162  }
163 }
164 
165 /** \brief register all unittests for the tm modules */
167 {
168 #ifdef UNITTESTS
169  TmModule *t;
170  uint16_t i;
171 
172  for (i = 0; i < TMM_SIZE; i++) {
173  t = &tmm_modules[i];
174 
175  if (t->name == NULL)
176  continue;
177 
178  g_ut_modules++;
179 
180 
181  if (t->RegisterTests == NULL) {
182  if (coverage_unittests)
183  SCLogWarning("threading module %s has no unittest "
184  "registration function.",
185  t->name);
186  } else {
187  t->RegisterTests();
188  g_ut_covered++;
189  }
190  }
191 #endif /* UNITTESTS */
192 }
193 
194 #ifdef PROFILING
195 #define CASE_CODE(E) case E: return #E
196 
197 /**
198  * \brief Maps the TmmId, to its string equivalent
199  *
200  * \param id tmm id
201  *
202  * \retval string equivalent for the tmm id
203  */
204 const char * TmModuleTmmIdToString(TmmId id)
205 {
206  switch (id) {
249 
251  }
252  return "<unknown>";
253 }
254 #endif
TMM_RECEIVEERFFILE
@ TMM_RECEIVEERFFILE
Definition: tm-threads-common.h:50
TMM_RECEIVENAPATECH
@ TMM_RECEIVENAPATECH
Definition: tm-threads-common.h:63
tm-threads.h
TMM_RECEIVEPLUGIN
@ TMM_RECEIVEPLUGIN
Definition: tm-threads-common.h:44
TMM_RECEIVEDPDK
@ TMM_RECEIVEDPDK
Definition: tm-threads-common.h:58
TMM_RECEIVEERFDAG
@ TMM_RECEIVEERFDAG
Definition: tm-threads-common.h:52
g_ut_modules
int g_ut_modules
Definition: suricata.c:878
TMM_FLOWRECYCLER
@ TMM_FLOWRECYCLER
Definition: tm-threads-common.h:73
TmModuleTmmIdToString
const char * TmModuleTmmIdToString(TmmId id)
Maps the TmmId, to its string equivalent.
Definition: tm-modules.c:204
TMM_DECODENFQ
@ TMM_DECODENFQ
Definition: tm-threads-common.h:35
SCLogDebug
#define SCLogDebug(...)
Definition: util-debug.h:269
TMM_DECODENAPATECH
@ TMM_DECODENAPATECH
Definition: tm-threads-common.h:64
TMM_DECODEDPDK
@ TMM_DECODEDPDK
Definition: tm-threads-common.h:59
TMM_STATSLOGGER
@ TMM_STATSLOGGER
Definition: tm-threads-common.h:65
TMM_DECODEPFRING
@ TMM_DECODEPFRING
Definition: tm-threads-common.h:43
threads.h
TMM_RECEIVEPFRING
@ TMM_RECEIVEPFRING
Definition: tm-threads-common.h:42
TMM_RECEIVEAFXDP
@ TMM_RECEIVEAFXDP
Definition: tm-threads-common.h:55
TmModuleRunDeInit
void TmModuleRunDeInit(void)
Definition: tm-modules.c:147
g_ut_covered
int g_ut_covered
Definition: suricata.c:879
packet-queue.h
TmModuleRegisterTests
void TmModuleRegisterTests(void)
register all unittests for the tm modules
Definition: tm-modules.c:166
TMM_DECODEWINDIVERT
@ TMM_DECODEWINDIVERT
Definition: tm-threads-common.h:70
TmModuleGetByName
TmModule * TmModuleGetByName(const char *name)
get a tm module ptr by name
Definition: tm-modules.c:53
TMM_DECODEPLUGIN
@ TMM_DECODEPLUGIN
Definition: tm-threads-common.h:45
TMM_DECODENFLOG
@ TMM_DECODENFLOG
Definition: tm-threads-common.h:67
TMM_BYPASSEDFLOWMANAGER
@ TMM_BYPASSEDFLOWMANAGER
Definition: tm-threads-common.h:74
TMM_DECODEAFP
@ TMM_DECODEAFP
Definition: tm-threads-common.h:56
util-debug.h
TMM_RECEIVEPCAPFILE
@ TMM_RECEIVEPCAPFILE
Definition: tm-threads-common.h:39
TMM_UNIXMANAGER
@ TMM_UNIXMANAGER
Definition: tm-threads-common.h:77
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:57
TmModuleRunInit
void TmModuleRunInit(void)
Definition: tm-modules.c:129
SCLogWarning
#define SCLogWarning(...)
Macro used to log WARNING messages.
Definition: util-debug.h:249
TMM_DECODENETMAP
@ TMM_DECODENETMAP
Definition: tm-threads-common.h:61
TmModuleGetIDForTM
int TmModuleGetIDForTM(TmModule *tm)
Given a TM Module, returns its id.
Definition: tm-modules.c:110
TMM_DECODEERFDAG
@ TMM_DECODEERFDAG
Definition: tm-threads-common.h:53
tmm_modules
TmModule tmm_modules[TMM_SIZE]
Definition: tm-modules.c:33
TMM_DECODEPCAPFILE
@ TMM_DECODEPCAPFILE
Definition: tm-threads-common.h:41
TMM_SIZE
@ TMM_SIZE
Definition: tm-threads-common.h:79
TmModuleGetById
TmModule * TmModuleGetById(int id)
Returns a TM Module by its id.
Definition: tm-modules.c:90
TmModule_::RegisterTests
void(* RegisterTests)(void)
Definition: tm-modules.h:71
TMM_DECODEERFFILE
@ TMM_DECODEERFFILE
Definition: tm-threads-common.h:51
TmModule_::name
const char * name
Definition: tm-modules.h:44
TmModuleDebugList
void TmModuleDebugList(void)
Definition: tm-modules.c:35
TmModule_
Definition: tm-modules.h:43
TMM_FLOWMANAGER
@ TMM_FLOWMANAGER
Definition: tm-threads-common.h:72
TMM_FLOWWORKER
@ TMM_FLOWWORKER
Definition: tm-threads-common.h:34
TMM_RECEIVEAFP
@ TMM_RECEIVEAFP
Definition: tm-threads-common.h:54
suricata-common.h
TMM_DETECTLOADER
@ TMM_DETECTLOADER
Definition: tm-threads-common.h:75
TMM_RESPONDREJECT
@ TMM_RESPONDREJECT
Definition: tm-threads-common.h:46
TMM_RECEIVENFLOG
@ TMM_RECEIVENFLOG
Definition: tm-threads-common.h:66
TMM_RECEIVEIPFW
@ TMM_RECEIVEIPFW
Definition: tm-threads-common.h:49
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:68
TMM_RECEIVENFQ
@ TMM_RECEIVENFQ
Definition: tm-threads-common.h:37
TMM_VERDICTIPFW
@ TMM_VERDICTIPFW
Definition: tm-threads-common.h:48
TMM_RECEIVENETMAP
@ TMM_RECEIVENETMAP
Definition: tm-threads-common.h:60
TMM_DECODEPCAP
@ TMM_DECODEPCAP
Definition: tm-threads-common.h:40
SCLogError
#define SCLogError(...)
Macro used to log ERROR messages.
Definition: util-debug.h:261
util-logopenfile.h
TMM_RECEIVEPCAP
@ TMM_RECEIVEPCAP
Definition: tm-threads-common.h:38
CASE_CODE
#define CASE_CODE(E)
Definition: tm-modules.c:195
TMM_DECODEIPFW
@ TMM_DECODEIPFW
Definition: tm-threads-common.h:47
TMM_ALERTPCAPINFO
@ TMM_ALERTPCAPINFO
Definition: tm-threads-common.h:62
coverage_unittests
int coverage_unittests
Definition: suricata.c:877
TmModuleGetIdByName
int TmModuleGetIdByName(const char *name)
get the id of a module from it's name
Definition: tm-modules.c:74
TMM_VERDICTWINDIVERT
@ TMM_VERDICTWINDIVERT
Definition: tm-threads-common.h:69
TmModule_::DeInit
TmEcode(* DeInit)(void)
Definition: tm-modules.h:69