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 /**
72  * \brief Returns a TM Module by its id.
73  *
74  * \param id Id of the TM Module to return.
75  *
76  * \retval Pointer of the module to be returned if available;
77  * NULL if unavailable.
78  */
80 {
81 
82  if (id < 0 || id >= TMM_SIZE) {
83  SCLogError("Threading module with the id "
84  "\"%d\" doesn't exist",
85  id);
86  return NULL;
87  }
88 
89  return &tmm_modules[id];
90 }
91 
92 /**
93  * \brief Given a TM Module, returns its id.
94  *
95  * \param tm Pointer to the TM Module.
96  *
97  * \retval id of the TM Module if available; -1 if unavailable.
98  */
100 {
101  TmModule *t;
102  int i;
103 
104  for (i = 0; i < TMM_SIZE; i++) {
105  t = &tmm_modules[i];
106 
107  if (t->name == NULL)
108  continue;
109 
110  if (strcmp(t->name, tm->name) == 0)
111  return i;
112  }
113 
114  return -1;
115 }
116 
117 
118 void TmModuleRunInit(void)
119 {
120  TmModule *t;
121  uint16_t i;
122 
123  for (i = 0; i < TMM_SIZE; i++) {
124  t = &tmm_modules[i];
125 
126  if (t->name == NULL)
127  continue;
128 
129  if (t->Init == NULL)
130  continue;
131 
132  t->Init();
133  }
134 }
135 
137 {
138  TmModule *t;
139  uint16_t i;
140 
141  for (i = 0; i < TMM_SIZE; i++) {
142  t = &tmm_modules[i];
143 
144  if (t->name == NULL)
145  continue;
146 
147  if (t->DeInit == NULL)
148  continue;
149 
150  t->DeInit();
151  }
152 }
153 
154 /** \brief register all unittests for the tm modules */
156 {
157 #ifdef UNITTESTS
158  TmModule *t;
159  uint16_t i;
160 
161  for (i = 0; i < TMM_SIZE; i++) {
162  t = &tmm_modules[i];
163 
164  if (t->name == NULL)
165  continue;
166 
167  g_ut_modules++;
168 
169 
170  if (t->RegisterTests == NULL) {
171  if (coverage_unittests)
172  SCLogWarning("threading module %s has no unittest "
173  "registration function.",
174  t->name);
175  } else {
176  t->RegisterTests();
177  g_ut_covered++;
178  }
179  }
180 #endif /* UNITTESTS */
181 }
182 
183 #ifdef PROFILING
184 #define CASE_CODE(E) case E: return #E
185 
186 /**
187  * \brief Maps the TmmId, to its string equivalent
188  *
189  * \param id tmm id
190  *
191  * \retval string equivalent for the tmm id
192  */
193 const char * TmModuleTmmIdToString(TmmId id)
194 {
195  switch (id) {
238 
240  }
241  return "<unknown>";
242 }
243 #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:888
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:193
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:136
g_ut_covered
int g_ut_covered
Definition: suricata.c:889
packet-queue.h
TmModuleRegisterTests
void TmModuleRegisterTests(void)
register all unittests for the tm modules
Definition: tm-modules.c:155
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:69
TmModule_::Func
TmEcode(* Func)(ThreadVars *, Packet *, void *)
Definition: tm-modules.h:53
TMM_DECODEAFXDP
@ TMM_DECODEAFXDP
Definition: tm-threads-common.h:57
TmModuleRunInit
void TmModuleRunInit(void)
Definition: tm-modules.c:118
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:99
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:79
TmModule_::RegisterTests
void(* RegisterTests)(void)
Definition: tm-modules.h:72
TMM_DECODEERFFILE
@ TMM_DECODEERFFILE
Definition: tm-threads-common.h:51
TmModule_::name
const char * name
Definition: tm-modules.h:45
TmModuleDebugList
void TmModuleDebugList(void)
Definition: tm-modules.c:35
TmModule_
Definition: tm-modules.h:44
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:184
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:887
TMM_VERDICTWINDIVERT
@ TMM_VERDICTWINDIVERT
Definition: tm-threads-common.h:69
TmModule_::DeInit
TmEcode(* DeInit)(void)
Definition: tm-modules.h:70