diff --git a/src/runmode-af-packet.c b/src/runmode-af-packet.c index 2705ff12c5..031d58846e 100644 --- a/src/runmode-af-packet.c +++ b/src/runmode-af-packet.c @@ -294,7 +294,9 @@ int RunModeIdsAFPSingle(DetectEngineCtx *de_ctx) ConfGet("af-packet.live-interface", &live_dev); ret = RunModeSetLiveCaptureSingle(de_ctx, - ParseAFPConfig, "ReceiveAFP", + ParseAFPConfig, + AFPConfigGeThreadsCount, + "ReceiveAFP", "DecodeAFP", "AFPacket", live_dev); if (ret != 0) { diff --git a/src/runmode-pcap.c b/src/runmode-pcap.c index 190538cd9d..96232f39ec 100644 --- a/src/runmode-pcap.c +++ b/src/runmode-pcap.c @@ -153,7 +153,9 @@ int RunModeIdsPcapSingle(DetectEngineCtx *de_ctx) ConfGet("pcap.single_pcap_dev", &live_dev); ret = RunModeSetLiveCaptureSingle(de_ctx, - ParsePcapConfig, "ReceivePcap", + ParsePcapConfig, + PcapConfigGeThreadsCount, + "ReceivePcap", "DecodePcap", "PcapLive", live_dev); if (ret != 0) { diff --git a/src/util-runmodes.c b/src/util-runmodes.c index 689697f6ac..fef6688560 100644 --- a/src/util-runmodes.c +++ b/src/util-runmodes.c @@ -568,12 +568,16 @@ int RunModeSetLiveCaptureAutoFp(DetectEngineCtx *de_ctx, } int RunModeSetLiveCaptureSingle(DetectEngineCtx *de_ctx, - ConfigIfaceParserFunc configparser, char *recv_mod_name, + ConfigIfaceParserFunc configparser, + ConfigIfaceThreadsCountFunc mod_threads_count, + char *recv_mod_name, char *decode_mod_name, char *thread_name, const char *live_dev) { int nlive = LiveGetDeviceCount(); void *aconf; + int threads_count; + int thread; if (nlive > 1) { SCLogError(SC_ERR_RUNMODE, @@ -587,49 +591,61 @@ int RunModeSetLiveCaptureSingle(DetectEngineCtx *de_ctx, char *live_dev_c = LiveGetDevice(0); aconf = configparser(live_dev_c); } + + threads_count = mod_threads_count(aconf); + SCLogInfo("Going to use %" PRId32 " thread(s)", threads_count); /* create the threads */ - ThreadVars *tv = TmThreadCreatePacketHandler(thread_name, - "packetpool", "packetpool", - "packetpool", "packetpool", - "pktacqloop"); - if (tv == NULL) { - printf("ERROR: TmThreadsCreate failed\n"); - exit(EXIT_FAILURE); - } + for (thread = 0; thread < threads_count; thread++) { + char tname[12]; + char *n_thread_name = NULL; + ThreadVars *tv = NULL; + TmModule *tm_module = NULL; + + snprintf(tname, sizeof(tname), "%s%"PRIu16, thread_name, thread+1); + n_thread_name = SCStrdup(tname); + tv = TmThreadCreatePacketHandler(n_thread_name, + "packetpool", "packetpool", + "packetpool", "packetpool", + "pktacqloop"); + if (tv == NULL) { + printf("ERROR: TmThreadsCreate failed\n"); + exit(EXIT_FAILURE); + } - TmModule *tm_module = TmModuleGetByName(recv_mod_name); - if (tm_module == NULL) { - printf("ERROR: TmModuleGetByName failed for %s\n", recv_mod_name); - exit(EXIT_FAILURE); - } - TmSlotSetFuncAppend(tv, tm_module, aconf); + tm_module = TmModuleGetByName(recv_mod_name); + if (tm_module == NULL) { + printf("ERROR: TmModuleGetByName failed for %s\n", recv_mod_name); + exit(EXIT_FAILURE); + } + TmSlotSetFuncAppend(tv, tm_module, aconf); - tm_module = TmModuleGetByName(decode_mod_name); - if (tm_module == NULL) { - printf("ERROR: TmModuleGetByName %s failed\n", decode_mod_name); - exit(EXIT_FAILURE); - } - TmSlotSetFuncAppend(tv, tm_module, NULL); + tm_module = TmModuleGetByName(decode_mod_name); + if (tm_module == NULL) { + printf("ERROR: TmModuleGetByName %s failed\n", decode_mod_name); + exit(EXIT_FAILURE); + } + TmSlotSetFuncAppend(tv, tm_module, NULL); - tm_module = TmModuleGetByName("StreamTcp"); - if (tm_module == NULL) { - printf("ERROR: TmModuleGetByName StreamTcp failed\n"); - exit(EXIT_FAILURE); - } - TmSlotSetFuncAppend(tv, tm_module, NULL); + tm_module = TmModuleGetByName("StreamTcp"); + if (tm_module == NULL) { + printf("ERROR: TmModuleGetByName StreamTcp failed\n"); + exit(EXIT_FAILURE); + } + TmSlotSetFuncAppend(tv, tm_module, NULL); - tm_module = TmModuleGetByName("Detect"); - if (tm_module == NULL) { - printf("ERROR: TmModuleGetByName Detect failed\n"); - exit(EXIT_FAILURE); - } - TmSlotSetFuncAppend(tv, tm_module, (void *)de_ctx); + tm_module = TmModuleGetByName("Detect"); + if (tm_module == NULL) { + printf("ERROR: TmModuleGetByName Detect failed\n"); + exit(EXIT_FAILURE); + } + TmSlotSetFuncAppend(tv, tm_module, (void *)de_ctx); - SetupOutputs(tv); + SetupOutputs(tv); - if (TmThreadSpawn(tv) != TM_ECODE_OK) { - printf("ERROR: TmThreadSpawn failed\n"); - exit(EXIT_FAILURE); + if (TmThreadSpawn(tv) != TM_ECODE_OK) { + printf("ERROR: TmThreadSpawn failed\n"); + exit(EXIT_FAILURE); + } } return 0; diff --git a/src/util-runmodes.h b/src/util-runmodes.h index 7a8089fc40..e16f8d8d8f 100644 --- a/src/util-runmodes.h +++ b/src/util-runmodes.h @@ -40,7 +40,9 @@ int RunModeSetLiveCaptureAutoFp(DetectEngineCtx *de_ctx, const char *live_dev); int RunModeSetLiveCaptureSingle(DetectEngineCtx *de_ctx, - ConfigIfaceParserFunc configparser, char *recv_mod_name, + ConfigIfaceParserFunc configparser, + ConfigIfaceThreadsCountFunc mod_threads_count, + char *recv_mod_name, char *decode_mod_name, char *thread_name, const char *live_dev);