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");
232 if (tm_module == NULL) {
233 FatalError(
"TmModuleGetByName RespondReject failed");
249 const char *recv_mod_name,
250 const char *decode_mod_name,
const char *thread_name,
251 const char *live_dev,
void *aconf,
252 unsigned char single_mode)
254 uint16_t threads_count;
260 threads_count =
MIN(ModThreadsCount(aconf), thread_max);
261 SCLogInfo(
"%s: creating %" PRIu16
" thread%s", live_dev, threads_count,
262 threads_count > 1 ?
"s" :
"");
266 for (uint16_t thread = 0; thread < threads_count; thread++) {
267 const uint16_t thread_id = (uint16_t)(thread + 1);
269 const size_t printable_threadname_size = strlen(thread_name) + 5 + strlen(live_dev) + 1;
270 char *printable_threadname =
SCMalloc(printable_threadname_size);
271 if (
unlikely(printable_threadname == NULL)) {
272 FatalError(
"failed to alloc printable thread name: %s", strerror(errno));
278 snprintf(tname,
sizeof(tname),
"%s#01-%s", thread_name, visual_devname);
279 snprintf(printable_threadname, printable_threadname_size,
"%s#01-%s", thread_name,
282 snprintf(tname,
sizeof(tname),
"%s#%02u-%s", thread_name, thread_id, visual_devname);
283 snprintf(printable_threadname, printable_threadname_size,
"%s#%02u-%s", thread_name,
284 thread_id, live_dev);
287 "packetpool",
"packetpool",
288 "packetpool",
"packetpool",
296 FatalError(
"Failed to allocate memory for iface name");
300 if (tm_module == NULL) {
301 FatalError(
"TmModuleGetByName failed for %s", recv_mod_name);
306 if (tm_module == NULL) {
307 FatalError(
"TmModuleGetByName %s failed", decode_mod_name);
312 if (tm_module == NULL) {
313 FatalError(
"TmModuleGetByName for FlowWorker failed");
318 if (tm_module == NULL) {
319 FatalError(
"TmModuleGetByName RespondReject failed");
335 const char *decode_mod_name,
const char *thread_name,
const char *live_dev)
339 for (
int ldev = 0; ldev < nlive; ldev++) {
340 const char *live_dev_c = NULL;
343 if ((nlive <= 1) && (live_dev != NULL)) {
344 aconf = ConfigParser(live_dev);
345 live_dev_c = live_dev;
348 aconf = ConfigParser(live_dev_c);
350 RunModeSetLiveCaptureWorkersForDevice(
351 ModThreadsCount, recv_mod_name, decode_mod_name, thread_name, live_dev_c, aconf, 0);
359 const char *recv_mod_name,
360 const char *decode_mod_name,
const char *thread_name,
361 const char *live_dev)
364 const char *live_dev_c = NULL;
368 FatalError(
"Can't use the 'single' runmode with multiple devices");
371 if (live_dev != NULL) {
372 aconf = ConfigParser(live_dev);
373 live_dev_c = live_dev;
376 aconf = ConfigParser(live_dev_c);
379 return RunModeSetLiveCaptureWorkersForDevice(
380 ModThreadsCount, recv_mod_name, decode_mod_name, thread_name, live_dev_c, aconf, 1);
387 const char *recv_mod_name,
388 const char *verdict_mod_name,
389 const char *decode_mod_name)
399 if (queues == NULL) {
400 FatalError(
"RunmodeAutoFpCreatePickupQueuesString failed");
404 for (
int i = 0; i < nqueue; i++) {
406 if (cur_queue == NULL) {
409 memset(tname, 0,
sizeof(tname));
414 "packetpool",
"packetpool",
415 queues,
"flow",
"pktacqloop");
416 if (tv_receive == NULL) {
420 if (tm_module == NULL) {
421 FatalError(
"TmModuleGetByName failed for %s", recv_mod_name);
426 if (tm_module == NULL) {
427 FatalError(
"TmModuleGetByName %s failed", decode_mod_name);
438 for (uint16_t thread = 0; thread < thread_max; thread++) {
439 const uint16_t thread_id = (uint16_t)(thread + 1);
442 snprintf(qname,
sizeof(qname),
"pickup%u", thread_id);
443 SCLogDebug(
"tname %s, qname %s", tname, qname);
448 "verdict-queue",
"simple",
450 if (tv_detect_ncpu == NULL) {
455 if (tm_module == NULL) {
456 FatalError(
"TmModuleGetByName for FlowWorker failed");
470 for (
int i = 0; i < nqueue; i++) {
471 memset(tname, 0,
sizeof(tname));
476 "verdict-queue",
"simple",
477 "packetpool",
"packetpool",
479 if (tv_verdict == NULL) {
483 if (tm_module == NULL) {
484 FatalError(
"TmModuleGetByName %s failed", verdict_mod_name);
489 if (tm_module == NULL) {
490 FatalError(
"TmModuleGetByName for RespondReject failed");
508 const char *recv_mod_name,
509 const char *verdict_mod_name,
510 const char *decode_mod_name)
514 for (
int i = 0; i < nqueue; i++) {
517 if (cur_queue == NULL) {
522 memset(tname, 0,
sizeof(tname));
526 "packetpool",
"packetpool",
527 "packetpool",
"packetpool",
534 if (tm_module == NULL) {
535 FatalError(
"TmModuleGetByName failed for %s", recv_mod_name);
540 if (tm_module == NULL) {
541 FatalError(
"TmModuleGetByName %s failed", decode_mod_name);
546 if (tm_module == NULL) {
547 FatalError(
"TmModuleGetByName for FlowWorker failed");
552 if (tm_module == NULL) {
553 FatalError(
"TmModuleGetByName %s failed", verdict_mod_name);
558 if (tm_module == NULL) {
559 FatalError(
"TmModuleGetByName for RespondReject failed");