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 */
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 {
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(SC_ERR_TM_MODULES_ERROR, "Threading module with the id "
95  "\"%d\" doesn't exist", id);
96  return NULL;
97  }
98 
99  return &tmm_modules[id];
100 }
101 
102 /**
103  * \brief Given a TM Module, returns its id.
104  *
105  * \param tm Pointer to the TM Module.
106  *
107  * \retval id of the TM Module if available; -1 if unavailable.
108  */
110 {
111  TmModule *t;
112  int i;
113 
114  for (i = 0; i < TMM_SIZE; i++) {
115  t = &tmm_modules[i];
116 
117  if (t->name == NULL)
118  continue;
119 
120  if (strcmp(t->name, tm->name) == 0)
121  return i;
122  }
123 
124  return -1;
125 }
126 
127 
128 void TmModuleRunInit(void)
129 {
130  TmModule *t;
131  uint16_t i;
132 
133  for (i = 0; i < TMM_SIZE; i++) {
134  t = &tmm_modules[i];
135 
136  if (t->name == NULL)
137  continue;
138 
139  if (t->Init == NULL)
140  continue;
141 
142  t->Init();
143  }
144 }
145 
147 {
148  TmModule *t;
149  uint16_t i;
150 
151  for (i = 0; i < TMM_SIZE; i++) {
152  t = &tmm_modules[i];
153 
154  if (t->name == NULL)
155  continue;
156 
157  if (t->DeInit == NULL)
158  continue;
159 
160  t->DeInit();
161  }
162 }
163 
164 /** \brief register all unittests for the tm modules */
166 {
167 #ifdef UNITTESTS
168  TmModule *t;
169  uint16_t i;
170 
171  for (i = 0; i < TMM_SIZE; i++) {
172  t = &tmm_modules[i];
173 
174  if (t->name == NULL)
175  continue;
176 
177  g_ut_modules++;
178 
179 
180  if (t->RegisterTests == NULL) {
181  if (coverage_unittests)
182  SCLogWarning(SC_WARN_NO_UNITTESTS, "threading module %s has no unittest "
183  "registration function.", t->name);
184  } else {
185  t->RegisterTests();
186  g_ut_covered++;
187  }
188  }
189 #endif /* UNITTESTS */
190 }
191 
192 #define CASE_CODE(E) case E: return #E
193 
194 /**
195  * \brief Maps the TmmId, to its string equivalent
196  *
197  * \param id tmm id
198  *
199  * \retval string equivalent for the tmm id
200  */
201 const char * TmModuleTmmIdToString(TmmId id)
202 {
203  switch (id) {
240 
242  }
243  return "<unknown>";
244 }
TMM_RECEIVEERFFILE
@ TMM_RECEIVEERFFILE
Definition: tm-threads-common.h:48
TMM_RECEIVENAPATECH
@ TMM_RECEIVENAPATECH
Definition: tm-threads-common.h:57
SC_ERR_TM_MODULES_ERROR
@ SC_ERR_TM_MODULES_ERROR
Definition: util-error.h:167
tm-threads.h
TMM_RECEIVEERFDAG
@ TMM_RECEIVEERFDAG
Definition: tm-threads-common.h:50
ThreadVars_::name
char name[16]
Definition: threadvars.h:64
g_ut_modules
int g_ut_modules
Definition: suricata.c:845
TMM_FLOWRECYCLER
@ TMM_FLOWRECYCLER
Definition: tm-threads-common.h:67
TmModuleTmmIdToString
const char * TmModuleTmmIdToString(TmmId id)
Maps the TmmId, to its string equivalent.
Definition: tm-modules.c:201
TMM_DECODENFQ
@ TMM_DECODENFQ
Definition: tm-threads-common.h:35
SCLogDebug
#define SCLogDebug(...)
Definition: util-debug.h:335
TMM_DECODENAPATECH
@ TMM_DECODENAPATECH
Definition: tm-threads-common.h:58
TMM_STATSLOGGER
@ TMM_STATSLOGGER
Definition: tm-threads-common.h:59
TMM_DECODEPFRING
@ TMM_DECODEPFRING
Definition: tm-threads-common.h:43
threads.h
TMM_RECEIVEPFRING
@ TMM_RECEIVEPFRING
Definition: tm-threads-common.h:42
TmModuleRunDeInit
void TmModuleRunDeInit(void)
Definition: tm-modules.c:146
ThreadVars_::t
pthread_t t
Definition: threadvars.h:58
g_ut_covered
int g_ut_covered
Definition: suricata.c:846
packet-queue.h
TmModuleRegisterTests
void TmModuleRegisterTests(void)
register all unittests for the tm modules
Definition: tm-modules.c:165
TMM_DECODEWINDIVERT
@ TMM_DECODEWINDIVERT
Definition: tm-threads-common.h:64
TmModuleGetByName
TmModule * TmModuleGetByName(const char *name)
get a tm module ptr by name
Definition: tm-modules.c:53
TMM_DECODENFLOG
@ TMM_DECODENFLOG
Definition: tm-threads-common.h:61
TMM_BYPASSEDFLOWMANAGER
@ TMM_BYPASSEDFLOWMANAGER
Definition: tm-threads-common.h:68
TMM_DECODEAFP
@ TMM_DECODEAFP
Definition: tm-threads-common.h:53
util-debug.h
TMM_RECEIVEPCAPFILE
@ TMM_RECEIVEPCAPFILE
Definition: tm-threads-common.h:39
TMM_UNIXMANAGER
@ TMM_UNIXMANAGER
Definition: tm-threads-common.h:71
TmModuleRunInit
void TmModuleRunInit(void)
Definition: tm-modules.c:128
TMM_DECODENETMAP
@ TMM_DECODENETMAP
Definition: tm-threads-common.h:55
ThreadVars_::id
int id
Definition: threadvars.h:86
TmModuleGetIDForTM
int TmModuleGetIDForTM(TmModule *tm)
Given a TM Module, returns its id.
Definition: tm-modules.c:109
TMM_DECODEERFDAG
@ TMM_DECODEERFDAG
Definition: tm-threads-common.h:51
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:73
TmModuleGetById
TmModule * TmModuleGetById(int id)
Returns a TM Module by its id.
Definition: tm-modules.c:90
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:35
TmModule_
Definition: tm-modules.h:43
TMM_FLOWMANAGER
@ TMM_FLOWMANAGER
Definition: tm-threads-common.h:66
TMM_FLOWWORKER
@ TMM_FLOWWORKER
Definition: tm-threads-common.h:34
TMM_RECEIVEAFP
@ TMM_RECEIVEAFP
Definition: tm-threads-common.h:52
suricata-common.h
TMM_DETECTLOADER
@ TMM_DETECTLOADER
Definition: tm-threads-common.h:69
TMM_RESPONDREJECT
@ TMM_RESPONDREJECT
Definition: tm-threads-common.h:44
SCLogError
#define SCLogError(err_code,...)
Macro used to log ERROR messages.
Definition: util-debug.h:294
TMM_RECEIVENFLOG
@ TMM_RECEIVENFLOG
Definition: tm-threads-common.h:60
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:62
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:54
TMM_DECODEPCAP
@ TMM_DECODEPCAP
Definition: tm-threads-common.h:40
SCLogWarning
#define SCLogWarning(err_code,...)
Macro used to log WARNING messages.
Definition: util-debug.h:281
util-logopenfile.h
TMM_RECEIVEPCAP
@ TMM_RECEIVEPCAP
Definition: tm-threads-common.h:38
CASE_CODE
#define CASE_CODE(E)
Definition: tm-modules.c:192
TMM_DECODEIPFW
@ TMM_DECODEIPFW
Definition: tm-threads-common.h:45
TMM_ALERTPCAPINFO
@ TMM_ALERTPCAPINFO
Definition: tm-threads-common.h:56
coverage_unittests
int coverage_unittests
Definition: suricata.c:844
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:63
SC_WARN_NO_UNITTESTS
@ SC_WARN_NO_UNITTESTS
Definition: util-error.h:266