49 #define THREADS_MAX (uint16_t)1024
62 size_t queues_size = n * 13;
65 char *queues =
SCCalloc(1, queues_size);
67 SCLogError(
"failed to alloc queues buffer: %s", strerror(errno));
71 for (
int thread = 0; thread < n; thread++) {
72 if (strlen(queues) > 0)
73 strlcat(queues,
",", queues_size);
75 snprintf(qname,
sizeof(qname),
"pickup%d", (int16_t)thread+1);
76 strlcat(queues, qname, queues_size);
79 SCLogDebug(
"%d %"PRIuMAX
", queues %s", n, (uintmax_t)queues_size, queues);
87 const char *decode_mod_name,
const char *thread_name,
const char *live_dev)
98 FatalError(
"RunmodeAutoFpCreatePickupQueuesString failed");
101 if ((nlive <= 1) && (live_dev != NULL)) {
104 void *aconf = ConfigParser(live_dev);
106 FatalError(
"Failed to allocate config for %s", live_dev);
109 const uint16_t threads_count =
MIN(ModThreadsCount(aconf),
THREADS_MAX);
110 SCLogInfo(
"Going to use %" PRIu16
" %s receive thread(s)", threads_count, recv_mod_name);
113 for (uint16_t thread = 0; thread < threads_count; thread++) {
114 const uint16_t thread_id = (uint16_t)(thread + 1);
115 snprintf(tname,
sizeof(tname),
"%s#%02u", thread_name, thread_id);
118 "packetpool",
"packetpool",
119 queues,
"flow",
"pktacqloop");
120 if (tv_receive == NULL) {
124 if (tm_module == NULL) {
125 FatalError(
"TmModuleGetByName failed for %s", recv_mod_name);
130 if (tm_module == NULL) {
131 FatalError(
"TmModuleGetByName %s failed", decode_mod_name);
142 SCLogInfo(
"Using %d live device(s).", nlive);
144 for (
int lthread = 0; lthread < nlive; lthread++) {
149 FatalError(
"Failed to lookup live dev %d", lthread);
153 void *aconf = ConfigParser(dev);
155 FatalError(
"Multidev: Failed to allocate config for %s (%d)", dev, lthread);
158 const uint16_t threads_count =
MIN(ModThreadsCount(aconf),
THREADS_MAX);
159 for (uint16_t thread = 0; thread < threads_count; thread++) {
160 const uint16_t thread_id = (uint16_t)(thread + 1);
161 const size_t printable_threadname_size = strlen(thread_name) + 5 + strlen(dev) + 1;
162 char *printable_threadname =
SCMalloc(printable_threadname_size);
163 if (
unlikely(printable_threadname == NULL)) {
164 FatalError(
"failed to alloc printable thread name: %s", strerror(errno));
167 tname,
sizeof(tname),
"%s#%02u-%s", thread_name, thread_id, visual_devname);
168 snprintf(printable_threadname, printable_threadname_size,
"%s#%02u-%s", thread_name,
173 "packetpool",
"packetpool",
174 queues,
"flow",
"pktacqloop");
175 if (tv_receive == NULL) {
181 FatalError(
"Failed to allocate memory for iface name");
185 if (tm_module == NULL) {
186 FatalError(
"TmModuleGetByName failed for %s", recv_mod_name);
191 if (tm_module == NULL) {
192 FatalError(
"TmModuleGetByName %s failed", decode_mod_name);
205 for (uint16_t thread = 0; thread < thread_max; thread++) {
206 const uint16_t thread_id = (uint16_t)(thread + 1);
208 snprintf(qname,
sizeof(qname),
"pickup%u", thread_id);
209 SCLogDebug(
"tname %s, qname %s", tname, qname);
214 "packetpool",
"packetpool",
216 if (tv_detect_ncpu == NULL) {
220 if (tm_module == NULL) {
221 FatalError(
"TmModuleGetByName for FlowWorker failed");
228 if (tm_module == NULL) {
229 FatalError(
"TmModuleGetByName RespondReject failed");
245 const char *recv_mod_name,
246 const char *decode_mod_name,
const char *thread_name,
247 const char *live_dev,
void *aconf,
248 unsigned char single_mode)
250 uint16_t threads_count;
256 threads_count =
MIN(ModThreadsCount(aconf), thread_max);
257 SCLogInfo(
"%s: creating %" PRIu16
" thread%s", live_dev, threads_count,
258 threads_count > 1 ?
"s" :
"");
262 for (uint16_t thread = 0; thread < threads_count; thread++) {
263 const uint16_t thread_id = (uint16_t)(thread + 1);
265 const size_t printable_threadname_size = strlen(thread_name) + 5 + strlen(live_dev) + 1;
266 char *printable_threadname =
SCMalloc(printable_threadname_size);
267 if (
unlikely(printable_threadname == NULL)) {
268 FatalError(
"failed to alloc printable thread name: %s", strerror(errno));
274 snprintf(tname,
sizeof(tname),
"%s#01-%s", thread_name, visual_devname);
275 snprintf(printable_threadname, printable_threadname_size,
"%s#01-%s", thread_name,
278 snprintf(tname,
sizeof(tname),
"%s#%02u-%s", thread_name, thread_id, visual_devname);
279 snprintf(printable_threadname, printable_threadname_size,
"%s#%02u-%s", thread_name,
280 thread_id, live_dev);
283 "packetpool",
"packetpool",
284 "packetpool",
"packetpool",
292 FatalError(
"Failed to allocate memory for iface name");
296 if (tm_module == NULL) {
297 FatalError(
"TmModuleGetByName failed for %s", recv_mod_name);
302 if (tm_module == NULL) {
303 FatalError(
"TmModuleGetByName %s failed", decode_mod_name);
308 if (tm_module == NULL) {
309 FatalError(
"TmModuleGetByName for FlowWorker failed");
314 if (tm_module == NULL) {
315 FatalError(
"TmModuleGetByName RespondReject failed");
331 const char *decode_mod_name,
const char *thread_name,
const char *live_dev)
335 for (
int ldev = 0; ldev < nlive; ldev++) {
336 const char *live_dev_c = NULL;
339 if ((nlive <= 1) && (live_dev != NULL)) {
340 aconf = ConfigParser(live_dev);
341 live_dev_c = live_dev;
344 aconf = ConfigParser(live_dev_c);
346 RunModeSetLiveCaptureWorkersForDevice(
347 ModThreadsCount, recv_mod_name, decode_mod_name, thread_name, live_dev_c, aconf, 0);
355 const char *recv_mod_name,
356 const char *decode_mod_name,
const char *thread_name,
357 const char *live_dev)
360 const char *live_dev_c = NULL;
364 FatalError(
"Can't use the 'single' runmode with multiple devices");
367 if (live_dev != NULL) {
368 aconf = ConfigParser(live_dev);
369 live_dev_c = live_dev;
372 aconf = ConfigParser(live_dev_c);
375 return RunModeSetLiveCaptureWorkersForDevice(
376 ModThreadsCount, recv_mod_name, decode_mod_name, thread_name, live_dev_c, aconf, 1);
383 const char *recv_mod_name,
384 const char *verdict_mod_name,
385 const char *decode_mod_name)
395 if (queues == NULL) {
396 FatalError(
"RunmodeAutoFpCreatePickupQueuesString failed");
400 for (
int i = 0; i < nqueue; i++) {
402 if (cur_queue == NULL) {
405 memset(tname, 0,
sizeof(tname));
410 "packetpool",
"packetpool",
411 queues,
"flow",
"pktacqloop");
412 if (tv_receive == NULL) {
416 if (tm_module == NULL) {
417 FatalError(
"TmModuleGetByName failed for %s", recv_mod_name);
422 if (tm_module == NULL) {
423 FatalError(
"TmModuleGetByName %s failed", decode_mod_name);
434 for (uint16_t thread = 0; thread < thread_max; thread++) {
435 const uint16_t thread_id = (uint16_t)(thread + 1);
438 snprintf(qname,
sizeof(qname),
"pickup%u", thread_id);
439 SCLogDebug(
"tname %s, qname %s", tname, qname);
444 "verdict-queue",
"simple",
446 if (tv_detect_ncpu == NULL) {
451 if (tm_module == NULL) {
452 FatalError(
"TmModuleGetByName for FlowWorker failed");
464 for (
int i = 0; i < nqueue; i++) {
465 memset(tname, 0,
sizeof(tname));
470 "verdict-queue",
"simple",
471 "packetpool",
"packetpool",
473 if (tv_verdict == NULL) {
477 if (tm_module == NULL) {
478 FatalError(
"TmModuleGetByName %s failed", verdict_mod_name);
483 if (tm_module == NULL) {
484 FatalError(
"TmModuleGetByName for RespondReject failed");
502 const char *recv_mod_name,
503 const char *verdict_mod_name,
504 const char *decode_mod_name)
508 for (
int i = 0; i < nqueue; i++) {
511 if (cur_queue == NULL) {
516 memset(tname, 0,
sizeof(tname));
520 "packetpool",
"packetpool",
521 "packetpool",
"packetpool",
528 if (tm_module == NULL) {
529 FatalError(
"TmModuleGetByName failed for %s", recv_mod_name);
534 if (tm_module == NULL) {
535 FatalError(
"TmModuleGetByName %s failed", decode_mod_name);
540 if (tm_module == NULL) {
541 FatalError(
"TmModuleGetByName for FlowWorker failed");
546 if (tm_module == NULL) {
547 FatalError(
"TmModuleGetByName %s failed", verdict_mod_name);
552 if (tm_module == NULL) {
553 FatalError(
"TmModuleGetByName for RespondReject failed");