51 #define THREADS_MAX (uint16_t)1024
64 size_t queues_size = n * 13;
67 char *queues =
SCCalloc(1, queues_size);
69 SCLogError(
"failed to alloc queues buffer: %s", strerror(errno));
73 for (
int thread = 0; thread < n; thread++) {
74 if (strlen(queues) > 0)
75 strlcat(queues,
",", queues_size);
77 snprintf(qname,
sizeof(qname),
"pickup%d", (int16_t)thread+1);
78 strlcat(queues, qname, queues_size);
81 SCLogDebug(
"%d %"PRIuMAX
", queues %s", n, (uintmax_t)queues_size, queues);
89 const char *decode_mod_name,
const char *thread_name,
const char *live_dev)
100 FatalError(
"RunmodeAutoFpCreatePickupQueuesString failed");
103 if ((nlive <= 1) && (live_dev != NULL)) {
106 void *aconf = ConfigParser(live_dev);
108 FatalError(
"Failed to allocate config for %s", live_dev);
111 const uint16_t threads_count =
MIN(ModThreadsCount(aconf),
THREADS_MAX);
112 SCLogInfo(
"Going to use %" PRIu16
" %s receive thread(s)", threads_count, recv_mod_name);
115 for (uint16_t thread = 0; thread < threads_count; thread++) {
116 const uint16_t thread_id = (uint16_t)(thread + 1);
117 snprintf(tname,
sizeof(tname),
"%s#%02u", thread_name, thread_id);
120 "packetpool",
"packetpool",
121 queues,
"flow",
"pktacqloop");
122 if (tv_receive == NULL) {
126 if (tm_module == NULL) {
127 FatalError(
"TmModuleGetByName failed for %s", recv_mod_name);
132 if (tm_module == NULL) {
133 FatalError(
"TmModuleGetByName %s failed", decode_mod_name);
144 SCLogInfo(
"Using %d live device(s).", nlive);
146 for (
int lthread = 0; lthread < nlive; lthread++) {
151 FatalError(
"Failed to lookup live dev %d", lthread);
155 void *aconf = ConfigParser(dev);
157 FatalError(
"Multidev: Failed to allocate config for %s (%d)", dev, lthread);
160 const uint16_t threads_count =
MIN(ModThreadsCount(aconf),
THREADS_MAX);
161 for (uint16_t thread = 0; thread < threads_count; thread++) {
162 const uint16_t thread_id = (uint16_t)(thread + 1);
163 const size_t printable_threadname_size = strlen(thread_name) + 5 + strlen(dev) + 1;
164 char *printable_threadname =
SCMalloc(printable_threadname_size);
165 if (
unlikely(printable_threadname == NULL)) {
166 FatalError(
"failed to alloc printable thread name: %s", strerror(errno));
169 tname,
sizeof(tname),
"%s#%02u-%s", thread_name, thread_id, visual_devname);
170 snprintf(printable_threadname, printable_threadname_size,
"%s#%02u-%s", thread_name,
175 "packetpool",
"packetpool",
176 queues,
"flow",
"pktacqloop");
177 if (tv_receive == NULL) {
183 FatalError(
"Failed to allocate memory for iface name");
187 if (tm_module == NULL) {
188 FatalError(
"TmModuleGetByName failed for %s", recv_mod_name);
193 if (tm_module == NULL) {
194 FatalError(
"TmModuleGetByName %s failed", decode_mod_name);
207 for (uint16_t thread = 0; thread < thread_max; thread++) {
208 const uint16_t thread_id = (uint16_t)(thread + 1);
210 snprintf(qname,
sizeof(qname),
"pickup%u", thread_id);
211 SCLogDebug(
"tname %s, qname %s", tname, qname);
216 "packetpool",
"packetpool",
218 if (tv_detect_ncpu == NULL) {
222 if (tm_module == NULL) {
223 FatalError(
"TmModuleGetByName for FlowWorker failed");
230 if (tm_module == NULL) {
231 FatalError(
"TmModuleGetByName RespondReject failed");
247 const char *recv_mod_name,
248 const char *decode_mod_name,
const char *thread_name,
249 const char *live_dev,
void *aconf,
250 unsigned char single_mode)
252 uint16_t threads_count;
258 threads_count =
MIN(ModThreadsCount(aconf), thread_max);
259 SCLogInfo(
"%s: creating %" PRIu16
" thread%s", live_dev, threads_count,
260 threads_count > 1 ?
"s" :
"");
264 for (uint16_t thread = 0; thread < threads_count; thread++) {
265 const uint16_t thread_id = (uint16_t)(thread + 1);
267 const size_t printable_threadname_size = strlen(thread_name) + 5 + strlen(live_dev) + 1;
268 char *printable_threadname =
SCMalloc(printable_threadname_size);
269 if (
unlikely(printable_threadname == NULL)) {
270 FatalError(
"failed to alloc printable thread name: %s", strerror(errno));
276 snprintf(tname,
sizeof(tname),
"%s#01-%s", thread_name, visual_devname);
277 snprintf(printable_threadname, printable_threadname_size,
"%s#01-%s", thread_name,
280 snprintf(tname,
sizeof(tname),
"%s#%02u-%s", thread_name, thread_id, visual_devname);
281 snprintf(printable_threadname, printable_threadname_size,
"%s#%02u-%s", thread_name,
282 thread_id, live_dev);
285 "packetpool",
"packetpool",
286 "packetpool",
"packetpool",
294 FatalError(
"Failed to allocate memory for iface name");
298 if (tm_module == NULL) {
299 FatalError(
"TmModuleGetByName failed for %s", recv_mod_name);
304 if (tm_module == NULL) {
305 FatalError(
"TmModuleGetByName %s failed", decode_mod_name);
310 if (tm_module == NULL) {
311 FatalError(
"TmModuleGetByName for FlowWorker failed");
316 if (tm_module == NULL) {
317 FatalError(
"TmModuleGetByName RespondReject failed");
333 const char *decode_mod_name,
const char *thread_name,
const char *live_dev)
337 for (
int ldev = 0; ldev < nlive; ldev++) {
338 const char *live_dev_c = NULL;
341 if ((nlive <= 1) && (live_dev != NULL)) {
342 aconf = ConfigParser(live_dev);
343 live_dev_c = live_dev;
346 aconf = ConfigParser(live_dev_c);
348 RunModeSetLiveCaptureWorkersForDevice(
349 ModThreadsCount, recv_mod_name, decode_mod_name, thread_name, live_dev_c, aconf, 0);
357 const char *recv_mod_name,
358 const char *decode_mod_name,
const char *thread_name,
359 const char *live_dev)
362 const char *live_dev_c = NULL;
366 FatalError(
"Can't use the 'single' runmode with multiple devices");
369 if (live_dev != NULL) {
370 aconf = ConfigParser(live_dev);
371 live_dev_c = live_dev;
374 aconf = ConfigParser(live_dev_c);
377 return RunModeSetLiveCaptureWorkersForDevice(
378 ModThreadsCount, recv_mod_name, decode_mod_name, thread_name, live_dev_c, aconf, 1);
385 const char *recv_mod_name,
386 const char *verdict_mod_name,
387 const char *decode_mod_name)
397 if (queues == NULL) {
398 FatalError(
"RunmodeAutoFpCreatePickupQueuesString failed");
402 for (
int i = 0; i < nqueue; i++) {
404 if (cur_queue == NULL) {
407 memset(tname, 0,
sizeof(tname));
412 "packetpool",
"packetpool",
413 queues,
"flow",
"pktacqloop");
414 if (tv_receive == NULL) {
418 if (tm_module == NULL) {
419 FatalError(
"TmModuleGetByName failed for %s", recv_mod_name);
424 if (tm_module == NULL) {
425 FatalError(
"TmModuleGetByName %s failed", decode_mod_name);
436 for (uint16_t thread = 0; thread < thread_max; thread++) {
437 const uint16_t thread_id = (uint16_t)(thread + 1);
440 snprintf(qname,
sizeof(qname),
"pickup%u", thread_id);
441 SCLogDebug(
"tname %s, qname %s", tname, qname);
446 "verdict-queue",
"simple",
448 if (tv_detect_ncpu == NULL) {
453 if (tm_module == NULL) {
454 FatalError(
"TmModuleGetByName for FlowWorker failed");
466 for (
int i = 0; i < nqueue; i++) {
467 memset(tname, 0,
sizeof(tname));
472 "verdict-queue",
"simple",
473 "packetpool",
"packetpool",
475 if (tv_verdict == NULL) {
479 if (tm_module == NULL) {
480 FatalError(
"TmModuleGetByName %s failed", verdict_mod_name);
485 if (tm_module == NULL) {
486 FatalError(
"TmModuleGetByName for RespondReject failed");
504 const char *recv_mod_name,
505 const char *verdict_mod_name,
506 const char *decode_mod_name)
510 for (
int i = 0; i < nqueue; i++) {
513 if (cur_queue == NULL) {
518 memset(tname, 0,
sizeof(tname));
522 "packetpool",
"packetpool",
523 "packetpool",
"packetpool",
530 if (tm_module == NULL) {
531 FatalError(
"TmModuleGetByName failed for %s", recv_mod_name);
536 if (tm_module == NULL) {
537 FatalError(
"TmModuleGetByName %s failed", decode_mod_name);
542 if (tm_module == NULL) {
543 FatalError(
"TmModuleGetByName for FlowWorker failed");
548 if (tm_module == NULL) {
549 FatalError(
"TmModuleGetByName %s failed", verdict_mod_name);
554 if (tm_module == NULL) {
555 FatalError(
"TmModuleGetByName for RespondReject failed");