/src/suricata7/src/tm-modules.c
Line | Count | Source (jump to first uncovered line) |
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 | | |
33 | | TmModule tmm_modules[TMM_SIZE]; |
34 | | |
35 | | void TmModuleDebugList(void) |
36 | 71 | { |
37 | 71 | TmModule *t; |
38 | 71 | uint16_t i; |
39 | | |
40 | 2.93k | for (i = 0; i < TMM_SIZE; i++) { |
41 | 2.86k | t = &tmm_modules[i]; |
42 | | |
43 | 2.86k | if (t->name == NULL) |
44 | 890 | continue; |
45 | | |
46 | 1.97k | SCLogDebug("%s:%p", t->name, t->Func); |
47 | 1.97k | } |
48 | 71 | } |
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 | 4 | { |
55 | 4 | TmModule *t; |
56 | 4 | uint16_t i; |
57 | | |
58 | 28 | for (i = 0; i < TMM_SIZE; i++) { |
59 | 28 | t = &tmm_modules[i]; |
60 | | |
61 | 28 | if (t->name == NULL) |
62 | 0 | continue; |
63 | | |
64 | 28 | if (strcmp(t->name, name) == 0) |
65 | 4 | return t; |
66 | 28 | } |
67 | | |
68 | 0 | return NULL; |
69 | 4 | } |
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 | 0 | { |
76 | 0 | TmModule *tm = TmModuleGetByName(name); |
77 | 0 | if (tm == NULL) |
78 | 0 | return -1; |
79 | 0 | return TmModuleGetIDForTM(tm); |
80 | 0 | } |
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 | | */ |
90 | | TmModule *TmModuleGetById(int id) |
91 | 0 | { |
92 | |
|
93 | 0 | if (id < 0 || id >= TMM_SIZE) { |
94 | 0 | SCLogError("Threading module with the id " |
95 | 0 | "\"%d\" doesn't exist", |
96 | 0 | id); |
97 | 0 | return NULL; |
98 | 0 | } |
99 | | |
100 | 0 | return &tmm_modules[id]; |
101 | 0 | } |
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 | | */ |
110 | | int TmModuleGetIDForTM(TmModule *tm) |
111 | 4 | { |
112 | 4 | TmModule *t; |
113 | 4 | int i; |
114 | | |
115 | 28 | for (i = 0; i < TMM_SIZE; i++) { |
116 | 28 | t = &tmm_modules[i]; |
117 | | |
118 | 28 | if (t->name == NULL) |
119 | 0 | continue; |
120 | | |
121 | 28 | if (strcmp(t->name, tm->name) == 0) |
122 | 4 | return i; |
123 | 28 | } |
124 | | |
125 | 0 | return -1; |
126 | 4 | } |
127 | | |
128 | | |
129 | | void TmModuleRunInit(void) |
130 | 71 | { |
131 | 71 | TmModule *t; |
132 | 71 | uint16_t i; |
133 | | |
134 | 2.93k | for (i = 0; i < TMM_SIZE; i++) { |
135 | 2.86k | t = &tmm_modules[i]; |
136 | | |
137 | 2.86k | if (t->name == NULL) |
138 | 355 | continue; |
139 | | |
140 | 2.51k | if (t->Init == NULL) |
141 | 2.51k | continue; |
142 | | |
143 | 0 | t->Init(); |
144 | 0 | } |
145 | 71 | } |
146 | | |
147 | | void TmModuleRunDeInit(void) |
148 | 0 | { |
149 | 0 | TmModule *t; |
150 | 0 | uint16_t i; |
151 | |
|
152 | 0 | for (i = 0; i < TMM_SIZE; i++) { |
153 | 0 | t = &tmm_modules[i]; |
154 | |
|
155 | 0 | if (t->name == NULL) |
156 | 0 | continue; |
157 | | |
158 | 0 | if (t->DeInit == NULL) |
159 | 0 | continue; |
160 | | |
161 | 0 | t->DeInit(); |
162 | 0 | } |
163 | 0 | } |
164 | | |
165 | | /** \brief register all unittests for the tm modules */ |
166 | | void TmModuleRegisterTests(void) |
167 | 0 | { |
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 | 0 | } |
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) { |
207 | | CASE_CODE (TMM_FLOWWORKER); |
208 | | CASE_CODE (TMM_RECEIVENFLOG); |
209 | | CASE_CODE (TMM_DECODENFLOG); |
210 | | CASE_CODE (TMM_DECODENFQ); |
211 | | CASE_CODE (TMM_VERDICTNFQ); |
212 | | CASE_CODE (TMM_RECEIVENFQ); |
213 | | CASE_CODE (TMM_RECEIVEPCAP); |
214 | | CASE_CODE (TMM_RECEIVEPCAPFILE); |
215 | | CASE_CODE (TMM_DECODEPCAP); |
216 | | CASE_CODE (TMM_DECODEPCAPFILE); |
217 | | CASE_CODE (TMM_RECEIVEPFRING); |
218 | | CASE_CODE (TMM_DECODEPFRING); |
219 | | CASE_CODE(TMM_RECEIVEDPDK); |
220 | | CASE_CODE(TMM_DECODEDPDK); |
221 | | CASE_CODE (TMM_RECEIVEPLUGIN); |
222 | | CASE_CODE (TMM_DECODEPLUGIN); |
223 | | CASE_CODE (TMM_RESPONDREJECT); |
224 | | CASE_CODE (TMM_DECODEIPFW); |
225 | | CASE_CODE (TMM_VERDICTIPFW); |
226 | | CASE_CODE (TMM_RECEIVEIPFW); |
227 | | CASE_CODE (TMM_RECEIVEERFFILE); |
228 | | CASE_CODE (TMM_DECODEERFFILE); |
229 | | CASE_CODE (TMM_RECEIVEERFDAG); |
230 | | CASE_CODE (TMM_DECODEERFDAG); |
231 | | CASE_CODE (TMM_RECEIVENAPATECH); |
232 | | CASE_CODE (TMM_DECODENAPATECH); |
233 | | CASE_CODE (TMM_RECEIVEAFP); |
234 | | CASE_CODE(TMM_RECEIVEAFXDP); |
235 | | CASE_CODE (TMM_ALERTPCAPINFO); |
236 | | CASE_CODE (TMM_DECODEAFP); |
237 | | CASE_CODE(TMM_DECODEAFXDP); |
238 | | CASE_CODE (TMM_STATSLOGGER); |
239 | | CASE_CODE (TMM_FLOWMANAGER); |
240 | | CASE_CODE (TMM_FLOWRECYCLER); |
241 | | CASE_CODE (TMM_BYPASSEDFLOWMANAGER); |
242 | | CASE_CODE (TMM_UNIXMANAGER); |
243 | | CASE_CODE (TMM_DETECTLOADER); |
244 | | CASE_CODE (TMM_RECEIVENETMAP); |
245 | | CASE_CODE (TMM_DECODENETMAP); |
246 | | CASE_CODE (TMM_RECEIVEWINDIVERT); |
247 | | CASE_CODE (TMM_VERDICTWINDIVERT); |
248 | | CASE_CODE (TMM_DECODEWINDIVERT); |
249 | | |
250 | | CASE_CODE (TMM_SIZE); |
251 | | } |
252 | | return "<unknown>"; |
253 | | } |
254 | | #endif |