suricata
util-runmodes.c
Go to the documentation of this file.
1 /* Copyright (C) 2011 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 Eric Leblond <eric@regit.org>
22  *
23  * Helper function for runmode.
24  *
25  */
26 
27 #include "suricata-common.h"
28 #include "config.h"
29 #include "tm-threads.h"
30 #include "conf.h"
31 #include "runmodes.h"
32 #include "runmode-af-packet.h"
33 #include "output.h"
34 #include "log-httplog.h"
35 
36 #include "detect-engine.h"
37 #include "detect-engine-mpm.h"
38 
39 #include "alert-fastlog.h"
40 #include "alert-prelude.h"
41 #include "alert-unified2-alert.h"
42 #include "alert-debuglog.h"
43 
44 #include "util-debug.h"
45 #include "util-time.h"
46 #include "util-cpu.h"
47 #include "util-affinity.h"
48 #include "util-device.h"
49 
50 #include "util-runmodes.h"
51 
52 #include "flow-hash.h"
53 
54 /** \brief create a queue string for autofp to pass to
55  * the flow queue handler.
56  *
57  * The string will be "pickup1,pickup2,pickup3\0"
58  */
60 {
61  if (n > 1024)
62  return NULL;
63 
64  /* 13 because pickup12345, = 12 + \0 */
65  size_t queues_size = n * 13;
66  char qname[TM_QUEUE_NAME_MAX];
67 
68  char *queues = SCMalloc(queues_size);
69  if (unlikely(queues == NULL)) {
70  SCLogError(SC_ERR_MEM_ALLOC, "failed to alloc queues buffer: %s", strerror(errno));
71  return NULL;
72  }
73  memset(queues, 0x00, queues_size);
74 
75  for (int thread = 0; thread < n; thread++) {
76  if (strlen(queues) > 0)
77  strlcat(queues, ",", queues_size);
78 
79  snprintf(qname, sizeof(qname), "pickup%d", (int16_t)thread+1);
80  strlcat(queues, qname, queues_size);
81  }
82 
83  SCLogDebug("%d %"PRIuMAX", queues %s", n, (uintmax_t)queues_size, queues);
84  return queues;
85 }
86 
87 /**
88  */
90  ConfigIfaceThreadsCountFunc ModThreadsCount,
91  const char *recv_mod_name,
92  const char *decode_mod_name,
93  const char *thread_name,
94  const char *live_dev)
95 {
96  char tname[TM_THREAD_NAME_MAX];
97  char qname[TM_QUEUE_NAME_MAX];
98  char *queues = NULL;
99 
100  /* Available cpus */
101  uint16_t ncpus = UtilCpuGetNumProcessorsOnline();
102  int nlive = LiveGetDeviceCount();
103  int thread_max = TmThreadGetNbThreads(WORKER_CPU_SET);
104  /* always create at least one thread */
105  if (thread_max == 0)
106  thread_max = ncpus * threading_detect_ratio;
107  if (thread_max < 1)
108  thread_max = 1;
109  if (thread_max > 1024) {
110  SCLogWarning(SC_ERR_RUNMODE, "limited number of 'worker' threads to 1024. Wanted %d", thread_max);
111  thread_max = 1024;
112  }
113 
114  queues = RunmodeAutoFpCreatePickupQueuesString(thread_max);
115  if (queues == NULL) {
116  SCLogError(SC_ERR_RUNMODE, "RunmodeAutoFpCreatePickupQueuesString failed");
117  exit(EXIT_FAILURE);
118  }
119 
120  if ((nlive <= 1) && (live_dev != NULL)) {
121  void *aconf;
122  int threads_count;
123 
124  SCLogDebug("live_dev %s", live_dev);
125 
126  aconf = ConfigParser(live_dev);
127  if (aconf == NULL) {
128  SCLogError(SC_ERR_RUNMODE, "Failed to allocate config for %s",
129  live_dev);
130  exit(EXIT_FAILURE);
131  }
132 
133  threads_count = ModThreadsCount(aconf);
134  SCLogInfo("Going to use %" PRId32 " %s receive thread(s)",
135  threads_count, recv_mod_name);
136 
137  /* create the threads */
138  for (int thread = 0; thread < MIN(thread_max, threads_count); thread++) {
139  snprintf(tname, sizeof(tname), "%s#%02d", thread_name, thread+1);
140  ThreadVars *tv_receive =
142  "packetpool", "packetpool",
143  queues, "flow", "pktacqloop");
144  if (tv_receive == NULL) {
145  SCLogError(SC_ERR_RUNMODE, "TmThreadsCreate failed");
146  exit(EXIT_FAILURE);
147  }
148  TmModule *tm_module = TmModuleGetByName(recv_mod_name);
149  if (tm_module == NULL) {
151  "TmModuleGetByName failed for %s",
152  recv_mod_name);
153  exit(EXIT_FAILURE);
154  }
155  TmSlotSetFuncAppend(tv_receive, tm_module, aconf);
156 
157  tm_module = TmModuleGetByName(decode_mod_name);
158  if (tm_module == NULL) {
160  "TmModuleGetByName %s failed", decode_mod_name);
161  exit(EXIT_FAILURE);
162  }
163  TmSlotSetFuncAppend(tv_receive, tm_module, NULL);
164 
165  TmThreadSetCPU(tv_receive, RECEIVE_CPU_SET);
166 
167  if (TmThreadSpawn(tv_receive) != TM_ECODE_OK) {
168  SCLogError(SC_ERR_RUNMODE, "TmThreadSpawn failed");
169  exit(EXIT_FAILURE);
170  }
171  }
172  } else { /* Multiple input device */
173  SCLogInfo("Using %d live device(s).", nlive);
174 
175  for (int lthread = 0; lthread < nlive; lthread++) {
176  const char *dev = LiveGetDeviceName(lthread);
177  const char *visual_devname = LiveGetShortName(dev);
178  void *aconf;
179  int threads_count;
180 
181  if (dev == NULL) {
182  SCLogError(SC_ERR_RUNMODE, "Failed to lookup live dev %d", lthread);
183  exit(EXIT_FAILURE);
184  }
185  SCLogDebug("dev %s", dev);
186 
187  aconf = ConfigParser(dev);
188  if (aconf == NULL) {
189  SCLogError(SC_ERR_RUNMODE, "Multidev: Failed to allocate config for %s (%d)",
190  dev, lthread);
191  exit(EXIT_FAILURE);
192  }
193 
194  threads_count = ModThreadsCount(aconf);
195  for (int thread = 0; thread < threads_count; thread++) {
196  char *printable_threadname = SCMalloc(sizeof(char) * (strlen(thread_name)+5+strlen(dev)));
197  if (unlikely(printable_threadname == NULL)) {
198  SCLogError(SC_ERR_MEM_ALLOC, "failed to alloc printable thread name: %s", strerror(errno));
199  exit(EXIT_FAILURE);
200  }
201  snprintf(tname, sizeof(tname), "%s#%02d-%s", thread_name,
202  thread+1, visual_devname);
203  snprintf(printable_threadname, strlen(thread_name)+5+strlen(dev),
204  "%s#%02d-%s", thread_name, thread+1,
205  dev);
206 
207  ThreadVars *tv_receive =
209  "packetpool", "packetpool",
210  queues, "flow", "pktacqloop");
211  if (tv_receive == NULL) {
212  SCLogError(SC_ERR_RUNMODE, "TmThreadsCreate failed");
213  exit(EXIT_FAILURE);
214  }
215  tv_receive->printable_name = printable_threadname;
216  TmModule *tm_module = TmModuleGetByName(recv_mod_name);
217  if (tm_module == NULL) {
218  SCLogError(SC_ERR_RUNMODE, "TmModuleGetByName failed for %s", recv_mod_name);
219  exit(EXIT_FAILURE);
220  }
221  TmSlotSetFuncAppend(tv_receive, tm_module, aconf);
222 
223  tm_module = TmModuleGetByName(decode_mod_name);
224  if (tm_module == NULL) {
225  SCLogError(SC_ERR_RUNMODE, "TmModuleGetByName %s failed", decode_mod_name);
226  exit(EXIT_FAILURE);
227  }
228  TmSlotSetFuncAppend(tv_receive, tm_module, NULL);
229 
230  TmThreadSetCPU(tv_receive, RECEIVE_CPU_SET);
231 
232  if (TmThreadSpawn(tv_receive) != TM_ECODE_OK) {
233  SCLogError(SC_ERR_RUNMODE, "TmThreadSpawn failed");
234  exit(EXIT_FAILURE);
235  }
236  }
237  }
238  }
239 
240  for (int thread = 0; thread < thread_max; thread++) {
241  snprintf(tname, sizeof(tname), "%s#%02u", thread_name_workers, thread+1);
242  snprintf(qname, sizeof(qname), "pickup%u", thread+1);
243 
244  SCLogDebug("tname %s, qname %s", tname, qname);
245 
246  ThreadVars *tv_detect_ncpu =
248  qname, "flow",
249  "packetpool", "packetpool",
250  "varslot");
251  if (tv_detect_ncpu == NULL) {
252  SCLogError(SC_ERR_RUNMODE, "TmThreadsCreate failed");
253  exit(EXIT_FAILURE);
254  }
255  TmModule *tm_module = TmModuleGetByName("FlowWorker");
256  if (tm_module == NULL) {
257  SCLogError(SC_ERR_RUNMODE, "TmModuleGetByName for FlowWorker failed");
258  exit(EXIT_FAILURE);
259  }
260  TmSlotSetFuncAppend(tv_detect_ncpu, tm_module, NULL);
261 
262  TmThreadSetCPU(tv_detect_ncpu, WORKER_CPU_SET);
263 
264  TmThreadSetGroupName(tv_detect_ncpu, "Detect");
265 
266  tm_module = TmModuleGetByName("RespondReject");
267  if (tm_module == NULL) {
268  SCLogError(SC_ERR_RUNMODE, "TmModuleGetByName RespondReject failed");
269  exit(EXIT_FAILURE);
270  }
271  TmSlotSetFuncAppend(tv_detect_ncpu, tm_module, NULL);
272 
273  if (TmThreadSpawn(tv_detect_ncpu) != TM_ECODE_OK) {
274  SCLogError(SC_ERR_RUNMODE, "TmThreadSpawn failed");
275  exit(EXIT_FAILURE);
276  }
277  }
278 
279  SCFree(queues);
280  return 0;
281 }
282 
283 /**
284  */
285 static int RunModeSetLiveCaptureWorkersForDevice(ConfigIfaceThreadsCountFunc ModThreadsCount,
286  const char *recv_mod_name,
287  const char *decode_mod_name, const char *thread_name,
288  const char *live_dev, void *aconf,
289  unsigned char single_mode)
290 {
291  int threads_count;
292 
293  if (single_mode) {
294  threads_count = 1;
295  } else {
296  threads_count = ModThreadsCount(aconf);
297  SCLogInfo("Going to use %" PRId32 " thread(s)", threads_count);
298  }
299 
300  /* create the threads */
301  for (int thread = 0; thread < threads_count; thread++) {
302  char tname[TM_THREAD_NAME_MAX];
303  ThreadVars *tv = NULL;
304  TmModule *tm_module = NULL;
305  const char *visual_devname = LiveGetShortName(live_dev);
306  char *printable_threadname = SCMalloc(sizeof(char) * (strlen(thread_name)+5+strlen(live_dev)));
307  if (unlikely(printable_threadname == NULL)) {
308  SCLogError(SC_ERR_MEM_ALLOC, "failed to alloc printable thread name: %s", strerror(errno));
309  exit(EXIT_FAILURE);
310  }
311 
312  if (single_mode) {
313  snprintf(tname, sizeof(tname), "%s#01-%s", thread_name, visual_devname);
314  snprintf(printable_threadname, strlen(thread_name)+5+strlen(live_dev), "%s#01-%s",
315  thread_name, live_dev);
316  } else {
317  snprintf(tname, sizeof(tname), "%s#%02d-%s", thread_name,
318  thread+1, visual_devname);
319  snprintf(printable_threadname, strlen(thread_name)+5+strlen(live_dev), "%s#%02d-%s",
320  thread_name, thread+1, live_dev);
321  }
322  tv = TmThreadCreatePacketHandler(tname,
323  "packetpool", "packetpool",
324  "packetpool", "packetpool",
325  "pktacqloop");
326  if (tv == NULL) {
327  SCLogError(SC_ERR_THREAD_CREATE, "TmThreadsCreate failed");
328  exit(EXIT_FAILURE);
329  }
330  tv->printable_name = printable_threadname;
331 
332  tm_module = TmModuleGetByName(recv_mod_name);
333  if (tm_module == NULL) {
334  SCLogError(SC_ERR_INVALID_VALUE, "TmModuleGetByName failed for %s", recv_mod_name);
335  exit(EXIT_FAILURE);
336  }
337  TmSlotSetFuncAppend(tv, tm_module, aconf);
338 
339  tm_module = TmModuleGetByName(decode_mod_name);
340  if (tm_module == NULL) {
341  SCLogError(SC_ERR_INVALID_VALUE, "TmModuleGetByName %s failed", decode_mod_name);
342  exit(EXIT_FAILURE);
343  }
344  TmSlotSetFuncAppend(tv, tm_module, NULL);
345 
346  tm_module = TmModuleGetByName("FlowWorker");
347  if (tm_module == NULL) {
348  SCLogError(SC_ERR_RUNMODE, "TmModuleGetByName for FlowWorker failed");
349  exit(EXIT_FAILURE);
350  }
351  TmSlotSetFuncAppend(tv, tm_module, NULL);
352 
353  tm_module = TmModuleGetByName("RespondReject");
354  if (tm_module == NULL) {
355  SCLogError(SC_ERR_RUNMODE, "TmModuleGetByName RespondReject failed");
356  exit(EXIT_FAILURE);
357  }
358  TmSlotSetFuncAppend(tv, tm_module, NULL);
359 
361 
362  if (TmThreadSpawn(tv) != TM_ECODE_OK) {
363  SCLogError(SC_ERR_THREAD_SPAWN, "TmThreadSpawn failed");
364  exit(EXIT_FAILURE);
365  }
366  }
367 
368  return 0;
369 }
370 
372  ConfigIfaceThreadsCountFunc ModThreadsCount,
373  const char *recv_mod_name,
374  const char *decode_mod_name, const char *thread_name,
375  const char *live_dev)
376 {
377  int nlive = LiveGetDeviceCount();
378  void *aconf;
379  int ldev;
380 
381  for (ldev = 0; ldev < nlive; ldev++) {
382  const char *live_dev_c = NULL;
383  if ((nlive <= 1) && (live_dev != NULL)) {
384  aconf = ConfigParser(live_dev);
385  live_dev_c = live_dev;
386  if (unlikely(live_dev_c == NULL)) {
387  SCLogError(SC_ERR_MEM_ALLOC, "Can't allocate interface name");
388  exit(EXIT_FAILURE);
389  }
390  } else {
391  live_dev_c = LiveGetDeviceName(ldev);
392  aconf = ConfigParser(live_dev_c);
393  }
394  RunModeSetLiveCaptureWorkersForDevice(ModThreadsCount,
395  recv_mod_name,
396  decode_mod_name,
397  thread_name,
398  live_dev_c,
399  aconf,
400  0);
401  }
402 
403  return 0;
404 }
405 
407  ConfigIfaceThreadsCountFunc ModThreadsCount,
408  const char *recv_mod_name,
409  const char *decode_mod_name, const char *thread_name,
410  const char *live_dev)
411 {
412  int nlive = LiveGetDeviceCount();
413  const char *live_dev_c = NULL;
414  void *aconf;
415 
416  if (nlive > 1) {
418  "Can't use the 'single' runmode with multiple devices");
419  exit(EXIT_FAILURE);
420  }
421 
422  if (live_dev != NULL) {
423  aconf = ConfigParser(live_dev);
424  live_dev_c = live_dev;
425  } else {
426  live_dev_c = LiveGetDeviceName(0);
427  aconf = ConfigParser(live_dev_c);
428  }
429 
430  return RunModeSetLiveCaptureWorkersForDevice(
431  ModThreadsCount,
432  recv_mod_name,
433  decode_mod_name,
434  thread_name,
435  live_dev_c,
436  aconf,
437  1);
438 }
439 
440 
441 /**
442  */
444  const char *recv_mod_name,
445  const char *verdict_mod_name,
446  const char *decode_mod_name)
447 {
448  SCEnter();
449  char tname[TM_THREAD_NAME_MAX];
450  char qname[TM_QUEUE_NAME_MAX];
451  TmModule *tm_module ;
452  const char *cur_queue = NULL;
453  char *queues = NULL;
454 
455  /* Available cpus */
456  uint16_t ncpus = UtilCpuGetNumProcessorsOnline();
457  int nqueue = LiveGetDeviceCount();
458 
459  int thread_max = TmThreadGetNbThreads(WORKER_CPU_SET);
460  /* always create at least one thread */
461  if (thread_max == 0)
462  thread_max = ncpus * threading_detect_ratio;
463  if (thread_max < 1)
464  thread_max = 1;
465  if (thread_max > 1024) {
466  SCLogWarning(SC_ERR_RUNMODE, "limited number of 'worker' threads to 1024. Wanted %d", thread_max);
467  thread_max = 1024;
468  }
469 
470  queues = RunmodeAutoFpCreatePickupQueuesString(thread_max);
471  if (queues == NULL) {
472  SCLogError(SC_ERR_RUNMODE, "RunmodeAutoFpCreatePickupQueuesString failed");
473  exit(EXIT_FAILURE);
474  }
475 
476  for (int i = 0; i < nqueue; i++) {
477  /* create the threads */
478  cur_queue = LiveGetDeviceName(i);
479  if (cur_queue == NULL) {
480  SCLogError(SC_ERR_RUNMODE, "invalid queue number");
481  exit(EXIT_FAILURE);
482  }
483  memset(tname, 0, sizeof(tname));
484  snprintf(tname, sizeof(tname), "%s-%s", thread_name_autofp, cur_queue);
485 
486  ThreadVars *tv_receive =
488  "packetpool", "packetpool",
489  queues, "flow", "pktacqloop");
490  if (tv_receive == NULL) {
491  SCLogError(SC_ERR_RUNMODE, "TmThreadsCreate failed");
492  exit(EXIT_FAILURE);
493  }
494  tm_module = TmModuleGetByName(recv_mod_name);
495  if (tm_module == NULL) {
496  SCLogError(SC_ERR_RUNMODE, "TmModuleGetByName failed for %s", recv_mod_name);
497  exit(EXIT_FAILURE);
498  }
499  TmSlotSetFuncAppend(tv_receive, tm_module, (void *) ConfigParser(i));
500 
501  tm_module = TmModuleGetByName(decode_mod_name);
502  if (tm_module == NULL) {
503  SCLogError(SC_ERR_RUNMODE, "TmModuleGetByName %s failed", decode_mod_name);
504  exit(EXIT_FAILURE);
505  }
506  TmSlotSetFuncAppend(tv_receive, tm_module, NULL);
507 
508  TmThreadSetCPU(tv_receive, RECEIVE_CPU_SET);
509 
510  if (TmThreadSpawn(tv_receive) != TM_ECODE_OK) {
511  SCLogError(SC_ERR_RUNMODE, "TmThreadSpawn failed");
512  exit(EXIT_FAILURE);
513  }
514 
515  }
516  for (int thread = 0; thread < thread_max; thread++) {
517  snprintf(tname, sizeof(tname), "%s#%02u", thread_name_workers, thread+1);
518  snprintf(qname, sizeof(qname), "pickup%u", thread+1);
519 
520  SCLogDebug("tname %s, qname %s", tname, qname);
521 
522  ThreadVars *tv_detect_ncpu =
524  qname, "flow",
525  "verdict-queue", "simple",
526  "varslot");
527  if (tv_detect_ncpu == NULL) {
528  SCLogError(SC_ERR_RUNMODE, "TmThreadsCreate failed");
529  exit(EXIT_FAILURE);
530  }
531 
532  tm_module = TmModuleGetByName("FlowWorker");
533  if (tm_module == NULL) {
534  SCLogError(SC_ERR_RUNMODE, "TmModuleGetByName for FlowWorker failed");
535  exit(EXIT_FAILURE);
536  }
537  TmSlotSetFuncAppend(tv_detect_ncpu, tm_module, NULL);
538 
539  TmThreadSetCPU(tv_detect_ncpu, WORKER_CPU_SET);
540 
541  TmThreadSetGroupName(tv_detect_ncpu, "Detect");
542 
543  if (TmThreadSpawn(tv_detect_ncpu) != TM_ECODE_OK) {
544  SCLogError(SC_ERR_RUNMODE, "TmThreadSpawn failed");
545  exit(EXIT_FAILURE);
546  }
547  }
548 
549  /* create the threads */
550  for (int i = 0; i < nqueue; i++) {
551  memset(tname, 0, sizeof(tname));
552  snprintf(tname, sizeof(tname), "%s#%02d", thread_name_verdict, i);
553 
554  ThreadVars *tv_verdict =
556  "verdict-queue", "simple",
557  "packetpool", "packetpool",
558  "varslot");
559  if (tv_verdict == NULL) {
560  SCLogError(SC_ERR_RUNMODE, "TmThreadsCreate failed");
561  exit(EXIT_FAILURE);
562  }
563  tm_module = TmModuleGetByName(verdict_mod_name);
564  if (tm_module == NULL) {
565  SCLogError(SC_ERR_RUNMODE, "TmModuleGetByName %s failed", verdict_mod_name);
566  exit(EXIT_FAILURE);
567  }
568  TmSlotSetFuncAppend(tv_verdict, tm_module, (void *)ConfigParser(i));
569 
570  tm_module = TmModuleGetByName("RespondReject");
571  if (tm_module == NULL) {
572  SCLogError(SC_ERR_RUNMODE, "TmModuleGetByName for RespondReject failed");
573  exit(EXIT_FAILURE);
574  }
575  TmSlotSetFuncAppend(tv_verdict, tm_module, NULL);
576 
577  TmThreadSetCPU(tv_verdict, VERDICT_CPU_SET);
578 
579  if (TmThreadSpawn(tv_verdict) != TM_ECODE_OK) {
580  SCLogError(SC_ERR_RUNMODE, "TmThreadSpawn failed");
581  exit(EXIT_FAILURE);
582  }
583  }
584 
585  SCFree(queues);
586  return 0;
587 }
588 
589 /**
590  */
592  const char *recv_mod_name,
593  const char *verdict_mod_name,
594  const char *decode_mod_name)
595 {
596  char tname[TM_THREAD_NAME_MAX];
597  ThreadVars *tv = NULL;
598  TmModule *tm_module = NULL;
599  const char *cur_queue = NULL;
600 
601  int nqueue = LiveGetDeviceCount();
602 
603  for (int i = 0; i < nqueue; i++) {
604  /* create the threads */
605  cur_queue = LiveGetDeviceName(i);
606  if (cur_queue == NULL) {
607  SCLogError(SC_ERR_RUNMODE, "invalid queue number");
608  exit(EXIT_FAILURE);
609  }
610  memset(tname, 0, sizeof(tname));
611  snprintf(tname, sizeof(tname), "%s-%s", thread_name_workers, cur_queue);
612 
613  tv = TmThreadCreatePacketHandler(tname,
614  "packetpool", "packetpool",
615  "packetpool", "packetpool",
616  "pktacqloop");
617  if (tv == NULL) {
618  SCLogError(SC_ERR_THREAD_CREATE, "TmThreadsCreate failed");
619  exit(EXIT_FAILURE);
620  }
621 
622  tm_module = TmModuleGetByName(recv_mod_name);
623  if (tm_module == NULL) {
624  SCLogError(SC_ERR_INVALID_VALUE, "TmModuleGetByName failed for %s", recv_mod_name);
625  exit(EXIT_FAILURE);
626  }
627  TmSlotSetFuncAppend(tv, tm_module, (void *) ConfigParser(i));
628 
629  tm_module = TmModuleGetByName(decode_mod_name);
630  if (tm_module == NULL) {
631  SCLogError(SC_ERR_INVALID_VALUE, "TmModuleGetByName %s failed", decode_mod_name);
632  exit(EXIT_FAILURE);
633  }
634  TmSlotSetFuncAppend(tv, tm_module, NULL);
635 
636  tm_module = TmModuleGetByName("FlowWorker");
637  if (tm_module == NULL) {
638  SCLogError(SC_ERR_RUNMODE, "TmModuleGetByName for FlowWorker failed");
639  exit(EXIT_FAILURE);
640  }
641  TmSlotSetFuncAppend(tv, tm_module, NULL);
642 
643  tm_module = TmModuleGetByName(verdict_mod_name);
644  if (tm_module == NULL) {
645  SCLogError(SC_ERR_RUNMODE, "TmModuleGetByName %s failed", verdict_mod_name);
646  exit(EXIT_FAILURE);
647  }
648 
649  TmSlotSetFuncAppend(tv, tm_module, (void *) ConfigParser(i));
650 
651  tm_module = TmModuleGetByName("RespondReject");
652  if (tm_module == NULL) {
653  SCLogError(SC_ERR_RUNMODE, "TmModuleGetByName for RespondReject failed");
654  exit(EXIT_FAILURE);
655  }
656  TmSlotSetFuncAppend(tv, tm_module, NULL);
657 
659 
660  if (TmThreadSpawn(tv) != TM_ECODE_OK) {
661  SCLogError(SC_ERR_RUNMODE, "TmThreadSpawn failed");
662  exit(EXIT_FAILURE);
663  }
664  }
665 
666  return 0;
667 }
void TmSlotSetFuncAppend(ThreadVars *tv, TmModule *tm, const void *data)
Appends a new entry to the slots.
Definition: tm-threads.c:832
const char * LiveGetDeviceName(int number)
Get a pointer to the device name at idx.
Definition: util-device.c:177
TmEcode TmThreadSetCPU(ThreadVars *tv, uint8_t type)
Definition: tm-threads.c:1029
#define SCLogDebug(...)
Definition: util-debug.h:335
float threading_detect_ratio
Definition: runmodes.c:895
int TmThreadGetNbThreads(uint8_t type)
Definition: tm-threads.c:1045
#define unlikely(expr)
Definition: util-optimize.h:35
size_t strlcat(char *, const char *src, size_t siz)
Definition: util-strlcatu.c:45
int RunModeSetIPSAutoFp(ConfigIPSParserFunc ConfigParser, const char *recv_mod_name, const char *verdict_mod_name, const char *decode_mod_name)
#define MIN(x, y)
ThreadVars * TmThreadCreatePacketHandler(const char *name, const char *inq_name, const char *inqh_name, const char *outq_name, const char *outqh_name, const char *slots)
Creates and returns a TV instance for a Packet Processing Thread. This function doesn&#39;t support custo...
Definition: tm-threads.c:1241
void TmThreadSetGroupName(ThreadVars *tv, const char *name)
Definition: tm-threads.c:1832
int LiveGetDeviceCount(void)
Get the number of registered devices.
Definition: util-device.c:157
int RunModeSetIPSWorker(ConfigIPSParserFunc ConfigParser, const char *recv_mod_name, const char *verdict_mod_name, const char *decode_mod_name)
int(* ConfigIfaceThreadsCountFunc)(void *)
Definition: util-runmodes.h:28
int RunModeSetLiveCaptureAutoFp(ConfigIfaceParserFunc ConfigParser, ConfigIfaceThreadsCountFunc ModThreadsCount, const char *recv_mod_name, const char *decode_mod_name, const char *thread_name, const char *live_dev)
Definition: util-runmodes.c:89
#define SCLogError(err_code,...)
Macro used to log ERROR messages.
Definition: util-debug.h:294
char * RunmodeAutoFpCreatePickupQueuesString(int n)
create a queue string for autofp to pass to the flow queue handler.
Definition: util-runmodes.c:59
void *(* ConfigIPSParserFunc)(int)
Definition: util-runmodes.h:27
#define SCEnter(...)
Definition: util-debug.h:337
void *(* ConfigIfaceParserFunc)(const char *)
Definition: util-runmodes.h:26
#define SCLogWarning(err_code,...)
Macro used to log WARNING messages.
Definition: util-debug.h:281
#define TM_QUEUE_NAME_MAX
Definition: tm-threads.h:47
int RunModeSetLiveCaptureSingle(ConfigIfaceParserFunc ConfigParser, ConfigIfaceThreadsCountFunc ModThreadsCount, const char *recv_mod_name, const char *decode_mod_name, const char *thread_name, const char *live_dev)
#define SCMalloc(a)
Definition: util-mem.h:222
#define SCLogInfo(...)
Macro used to log INFORMATIONAL messages.
Definition: util-debug.h:254
#define SCFree(a)
Definition: util-mem.h:322
const char * thread_name_verdict
Definition: runmodes.c:64
char * printable_name
Definition: threadvars.h:60
const char * LiveGetShortName(const char *dev)
Definition: util-device.c:300
const char * thread_name_autofp
Definition: runmodes.c:61
#define TM_THREAD_NAME_MAX
Definition: tm-threads.h:48
TmModule * TmModuleGetByName(const char *name)
get a tm module ptr by name
Definition: tm-modules.c:51
Per thread variable structure.
Definition: threadvars.h:57
int RunModeSetLiveCaptureWorkers(ConfigIfaceParserFunc ConfigParser, ConfigIfaceThreadsCountFunc ModThreadsCount, const char *recv_mod_name, const char *decode_mod_name, const char *thread_name, const char *live_dev)
uint16_t UtilCpuGetNumProcessorsOnline(void)
Get the number of cpus online in the system.
Definition: util-cpu.c:99
TmEcode TmThreadSpawn(ThreadVars *tv)
Spawns a thread associated with the ThreadVars instance tv.
Definition: tm-threads.c:1875
const char * thread_name_workers
Definition: runmodes.c:63