99static char *active_runmode;
119static const char *RunModeTranslateModeToName(
int runmode)
141 return "AF_PACKET_DEV";
148 return "NETMAP(DISABLED)";
151 return "UNIX_SOCKET";
156 return "WINDIVERT(DISABLED)";
162 return "DPDK(DISABLED)";
180static RunMode *RunModeGetCustomMode(
enum SCRunModes runmode,
const char *custom_mode)
183 for (
int i = 0; i < runmodes[runmode].
cnt; i++) {
184 if (strcmp(runmodes[runmode].runmodes[i].
name, custom_mode) == 0)
185 return &runmodes[runmode].
runmodes[i];
201 return active_runmode;
225 return RunModeTranslateModeToName(mainmode);
233 memset(runmodes, 0,
sizeof(runmodes));
259 printf(
"------------------------------------- Runmodes -------------------"
260 "-----------------------\n");
262 printf(
"| %-17s | %-17s | %-10s \n",
263 "RunMode Type",
"Custom Mode ",
"Description");
264 printf(
"|-----------------------------------------------------------------"
265 "-----------------------\n");
269 int mode_displayed = 0;
270 for (j = 0; j < runmodes[i].
cnt; j++) {
271 if (mode_displayed == 1) {
272 printf(
"| ----------------------------------------------"
273 "-----------------------\n");
275 printf(
"| %-17s | %-17s | %-27s \n",
281 printf(
"| %-17s | %-17s | %-27s \n",
282 RunModeTranslateModeToName(runmode->
runmode),
286 if (mode_displayed == 0)
289 if (mode_displayed == 1) {
290 printf(
"|-----------------------------------------------------------------"
291 "-----------------------\n");
296static const char *RunModeGetConfOrDefault(
int capture_mode,
const char *capture_plugin_name)
298 const char *custom_mode = NULL;
299 const char *val = NULL;
306 if ((custom_mode == NULL) || (strcmp(custom_mode,
"auto") == 0)) {
307 switch (capture_mode) {
317 if (plugin == NULL) {
318 FatalError(
"No capture plugin found with name %s", capture_plugin_name);
369 if (!strcmp(
"worker", custom_mode)) {
371 "to 'workers', please modify your setup.");
372 custom_mode =
"workers";
381 if (runmode == NULL) {
382 runmode = RunModeGetConfOrDefault(capture_mode, capture_plugin_name);
387 RunMode *mode = RunModeGetCustomMode(capture_mode, runmode);
395 if (ips_enabled == 1) {
398 SCLogWarning(
"disabling livedev.use-for-tracking with IPS mode. See ticket #6726.");
409void RunModeDispatch(
int runmode,
const char *custom_mode,
const char *capture_plugin_name,
410 const char *capture_plugin_args)
412 char *local_custom_mode = NULL;
414 if (custom_mode == NULL) {
415 custom_mode = RunModeGetConfOrDefault(runmode, capture_plugin_name);
416 if (custom_mode == NULL)
420 RunMode *mode = RunModeGetCustomMode(runmode, custom_mode);
422 SCLogError(
"The custom type \"%s\" doesn't exist "
423 "for this runmode type \"%s\". Please use --list-runmodes to "
424 "see available custom types for this runmode",
425 custom_mode, RunModeTranslateModeToName(runmode));
430 if (active_runmode) {
433 active_runmode =
SCStrdup(custom_mode);
434 if (
unlikely(active_runmode == NULL)) {
438 if (strcasecmp(active_runmode,
"autofp") == 0) {
444 if (local_custom_mode != NULL)
445 SCFree(local_custom_mode);
463static int g_runmode_needs_bypass = 0;
467 g_runmode_needs_bypass = 1;
472 return g_runmode_needs_bypass;
487 int (*RunModeFunc)(
void),
int (*RunModeIsIPSEnabled)(
void))
489 if (RunModeGetCustomMode(runmode,
name) != NULL) {
491 "been registered. Please use an unique name.",
495 void *ptmp =
SCRealloc(runmodes[runmode].runmodes,
496 (runmodes[runmode].
cnt + 1) *
sizeof(
RunMode));
498 SCFree(runmodes[runmode].runmodes);
505 runmodes[runmode].
cnt++;
506 memset(mode, 0x00,
sizeof(*mode));
527static void RunOutputFreeList(
void)
530 while ((output =
TAILQ_FIRST(&output_free_list))) {
540static int file_logger_count = 0;
541static int filedata_logger_count = 0;
545 return filedata_logger_count > 0;
550 switch (run_mode_to_check) {
563 switch(run_mode_to_check) {
594 file_logger_count = 0;
595 filedata_logger_count = 0;
612static void SetupOutput(
643 logger_bits[
module->alproto] |= BIT_U32(module->logger_id);
649 filedata_logger_count++;
664static void RunModeInitializeEveOutput(
678 if (strcmp(
type->val,
"ikev2") == 0) {
679 SCLogWarning(
"eve module 'ikev2' has been replaced by 'ike'");
680 strlcpy(subname,
"eve-log.ike",
sizeof(subname));
682 snprintf(subname,
sizeof(subname),
"eve-log.%s",
type->val);
688 if (sub_output_config != NULL) {
698 if (strcmp(subname, sub_module->
conf_name) == 0) {
711 sub_module->
InitSubFunc(sub_output_config, parent_ctx);
712 if (!result.
ok || result.
ctx == NULL) {
713 FatalError(
"unable to initialize sub-module %s", subname);
716 AddOutputToFreeList(sub_module, result.
ctx);
717 SetupOutput(sub_module->
name, sub_module, result.
ctx, logger_bits);
730static void RunModeInitializeLuaOutput(
734 BUG_ON(lua_module == NULL);
746 if (strcmp(script->
val,
m->conf_name) == 0) {
754 if (!result.
ok || result.
ctx == NULL) {
758 AddOutputToFreeList(
m, result.
ctx);
759 SetupOutput(
m->name,
m, result.
ctx, logger_bits);
772 if (outputs == NULL) {
779 char tls_log_enabled = 0;
780 char tls_store_present = 0;
788 if (output_config == NULL) {
790 FatalError(
"Failed to lookup configuration child node: %s", output->
val);
793 if (strcmp(output->
val,
"tls-store") == 0) {
794 tls_store_present = 1;
802 if (strcmp(output->
val,
"file-log") == 0) {
804 " use eve.files instead "
806 " for an explanation)");
808 }
else if (strncmp(output->
val,
"unified-",
sizeof(
"unified-") - 1) == 0) {
810 " use Unified2 instead "
812 " for an explanation)");
814 }
else if (strncmp(output->
val,
"unified2-",
sizeof(
"unified2-") - 1) == 0) {
817 }
else if (strcmp(output->
val,
"dns-log") == 0) {
818 SCLogWarning(
"dns-log is not longer available as of Suricata 5.0");
820 }
else if (strcmp(output->
val,
"tls-log") == 0) {
839 }
else if (r.
ctx == NULL) {
849 if (strcmp(output->
val,
"eve-log") == 0) {
850 RunModeInitializeEveOutput(output_config, output_ctx, logger_bits);
855 AddOutputToFreeList(module, output_ctx);
856 }
else if (strcmp(output->
val,
"lua") == 0) {
858 if (output_ctx == NULL)
860 RunModeInitializeLuaOutput(output_config, output_ctx, logger_bits);
861 AddOutputToFreeList(module, output_ctx);
863 AddOutputToFreeList(module, output_ctx);
864 SetupOutput(module->
name, module, output_ctx, logger_bits);
874 if (!tls_store_present && tls_log_enabled) {
877 SCLogWarning(
"Please use 'tls-store' in YAML to configure TLS storage");
882 if (strcmp(output->
val,
"tls-log") == 0) {
884 OutputModule *
module = OutputGetModuleByConfName("tls-store");
885 if (module == NULL) {
886 SCLogWarning(
"No output module named %s, ignoring",
"tls-store");
896 }
else if (r.
ctx == NULL) {
902 AddOutputToFreeList(module, output_ctx);
903 SetupOutput(module->
name, module, output_ctx, logger_bits);
916 SCLogDebug(
"IPPROTO_TCP::%s: g_file_logger_enabled %d g_filedata_logger_enabled %d -> "
928 if (logger_bits[a] == 0)
938 tcp ?
"true" :
"false", udp ?
"true" :
"false");
957 if ((
SCConfGetBool(
"threading.set-cpu-affinity", &affinity)) == 0) {
979 const char *ss = NULL;
980 if ((
SCConfGet(
"threading.stack-size", &ss)) == 1) {
983 FatalError(
"Failed to initialize thread_stack_size output, invalid limit: %s", ss);
988 pthread_attr_init(&attr);
990 if (pthread_attr_getstacksize(&attr, &size) == 0 && size < 512 * 1024) {
992 SCLogNotice(
"thread stack size of %" PRIuMAX
" too small: setting to 512k",
struct HtpBodyChunk_ * next
int AppLayerParserProtocolHasLogger(uint8_t ipproto, AppProto alproto)
bool AppLayerParserSupportsFiles(uint8_t ipproto, AppProto alproto)
void AppLayerParserRegisterLoggerBits(uint8_t ipproto, AppProto alproto, LoggerId bits)
const char * AppProtoToString(AppProto alproto)
Maps the ALPROTO_*, to its string equivalent.
SCConfNode * SCConfNodeLookupChild(const SCConfNode *node, const char *name)
Lookup a child configuration node by name.
SCConfNode * SCConfGetNode(const char *name)
Get a SCConfNode by name.
int SCConfValIsTrue(const char *val)
Check if a value is true.
int SCConfGetFloat(const char *name, float *val)
Retrieve a configuration value as a float.
int SCConfGetBool(const char *name, int *val)
Retrieve a configuration value as a boolean.
const char * SCConfNodeLookupChildValue(const SCConfNode *node, const char *name)
Lookup the value of a child configuration node by name.
int SCConfGet(const char *name, const char **vptr)
Retrieve the value of a configuration node.
void StatsSpawnThreads(void)
Spawns the wakeup, and the management thread used by the stats api.
void BypassedFlowManagerThreadSpawn(void)
spawn the flow bypass manager thread
void FlowManagerThreadSpawn(void)
spawn the flow manager thread
void FlowRecyclerThreadSpawn(void)
spawn the flow recycler thread
void UtRunModeRegister(void)
void LogFlushThreads(void)
void OutputFileShutdown(void)
int SCOutputRegisterFileLogger(LoggerId id, const char *name, SCFileLogger LogFunc, void *initdata, ThreadInitFunc ThreadInit, ThreadDeinitFunc ThreadDeinit)
Register a file logger.
void OutputFiledataShutdown(void)
int SCOutputRegisterFiledataLogger(LoggerId id, const char *name, SCFiledataLogger LogFunc, void *initdata, ThreadInitFunc ThreadInit, ThreadDeinitFunc ThreadDeinit)
Register a file-data logger.
void OutputFlowShutdown(void)
int SCOutputRegisterFlowLogger(const char *name, FlowLogger LogFunc, void *initdata, ThreadInitFunc ThreadInit, ThreadDeinitFunc ThreadDeinit)
Register a flow logger.
int SCOutputRegisterPacketLogger(LoggerId logger_id, const char *name, PacketLogger LogFunc, PacketLogCondition ConditionFunc, void *initdata, ThreadInitFunc ThreadInit, ThreadDeinitFunc ThreadDeinit)
Register a packet logger.
void OutputPacketShutdown(void)
int OutputRegisterStatsLogger(const char *name, StatsLogger LogFunc, OutputCtx *output_ctx, ThreadInitFunc ThreadInit, ThreadDeinitFunc ThreadDeinit)
void OutputStatsShutdown(void)
int SCOutputRegisterStreamingLogger(LoggerId id, const char *name, SCStreamingLogger LogFunc, void *initdata, enum SCOutputStreamingType type, ThreadInitFunc ThreadInit, ThreadDeinitFunc ThreadDeinit)
Register a streaming logger.
void OutputStreamingShutdown(void)
int SCOutputRegisterTxLogger(LoggerId id, const char *name, AppProto alproto, TxLogger LogFunc, void *initdata, int tc_log_progress, int ts_log_progress, TxLoggerCondition LogCondition, ThreadInitFunc ThreadInit, ThreadDeinitFunc ThreadDeinit)
Register a transaction logger.
void OutputTxShutdown(void)
void OutputSetupActiveLoggers(void)
void OutputClearActiveLoggers(void)
OutputModule * OutputGetModuleByConfName(const char *conf_name)
Get an output module by name.
OutputModuleList output_modules
#define TAILQ_FOREACH(var, head, field)
#define TAILQ_HEAD(name, type)
#define TAILQ_INSERT_TAIL(head, elm, field)
#define TAILQ_FIRST(head)
#define TAILQ_REMOVE(head, elm, field)
#define TAILQ_HEAD_INITIALIZER(head)
#define TAILQ_ENTRY(type)
const char * RunModeAFPGetDefaultMode(void)
void RunModeIdsAFPRegister(void)
void RunModeIdsAFXDPRegister(void)
const char * RunModeAFXDPGetDefaultMode(void)
const char * RunModeDpdkGetDefaultMode(void)
void RunModeDpdkRegister(void)
void RunModeErfDagRegister(void)
const char * RunModeErfDagGetDefaultMode(void)
void RunModeErfFileRegister(void)
const char * RunModeErfFileGetDefaultMode(void)
const char * RunModeIpsIPFWGetDefaultMode(void)
void RunModeIpsIPFWRegister(void)
void SCRunModeLibIdsRegister(void)
register runmodes for suricata as a library
const char * SCRunModeLibGetDefaultMode(void)
runmode default mode (live)
void RunModeIdsNetmapRegister(void)
const char * RunModeNetmapGetDefaultMode(void)
void RunModeIdsNflogRegister(void)
const char * RunModeIdsNflogGetDefaultMode(void)
const char * RunModeIpsNFQGetDefaultMode(void)
void RunModeIpsNFQRegister(void)
const char * RunModeFilePcapGetDefaultMode(void)
void RunModeFilePcapRegister(void)
void RunModeIdsPcapRegister(void)
const char * RunModeIdsGetDefaultMode(void)
void RunModeUnixSocketRegister(void)
const char * RunModeUnixSocketGetDefaultMode(void)
const char * RunModeIpsWinDivertGetDefaultMode(void)
void RunModeIpsWinDivertRegister(void)
bool threading_set_cpu_affinity
struct RunMode_ RunMode
Holds description for a runmode.
bool RunmodeIsAutofp(void)
struct OutputFreeList_ OutputFreeList
const char * thread_name_counter_wakeup
bool IsRunModeOffline(enum SCRunModes run_mode_to_check)
void RunModeDispatch(int runmode, const char *custom_mode, const char *capture_plugin_name, const char *capture_plugin_args)
const char * thread_name_heartbeat
char * RunmodeGetActive(void)
const char * thread_name_counter_stats
bool g_filedata_logger_enabled
const char * RunModeGetMainMode(void)
void RunModeShutDown(void)
const char * thread_name_flow_mgr
const char * thread_name_flow_rec
const char * thread_name_flow_bypass
const char * thread_name_single
int RunModeOutputFiledataEnabled(void)
const char * thread_name_verdict
int RunModeEngineIsIPS(int capture_mode, const char *runmode, const char *capture_plugin_name)
uint64_t threading_set_stack_size
void RunModeInitializeThreadSettings(void)
void RunModeEnablesBypassManager(void)
void RunModeRegisterRunModes(void)
Register all runmodes in the engine.
void RunModeListRunmodes(void)
Lists all registered runmodes.
void RunModeInitializeOutputs(void)
struct RunModes_ RunModes
float threading_detect_ratio
void RunModeRegisterNewRunMode(enum SCRunModes runmode, const char *name, const char *description, int(*RunModeFunc)(void), int(*RunModeIsIPSEnabled)(void))
Registers a new runmode.
bool g_file_logger_enabled
bool RunmodeIsWorkers(void)
int RunModeNeedsBypassManager(void)
const char * thread_name_unix_socket
const char * thread_name_autofp
bool IsRunModeSystem(enum SCRunModes run_mode_to_check)
const char * thread_name_detect_loader
const char * thread_name_workers
@ RUNMODE_ENGINE_ANALYSIS
void(* DeInit)(struct OutputCtx_ *)
OutputModule * output_module
PacketLogger PacketLogFunc
PacketLogCondition PacketConditionFunc
enum SCOutputStreamingType stream_type
ThreadDeinitFunc ThreadDeinit
ThreadInitFunc ThreadInit
OutputInitSubFunc InitSubFunc
SCStreamingLogger StreamingLogFunc
SCFiledataLogger FiledataLogFunc
TxLoggerCondition TxLogCondition
Holds description for a runmode.
int(* RunModeIsIPSEnabled)(void)
const char *(* GetDefaultMode)(void)
size_t strlcpy(char *dst, const char *src, size_t siz)
SCRunMode SCRunmodeGet(void)
Get the current run mode.
void TmValidateQueueState(void)
Checks if all the queues allocated so far have at least one reader and writer.
void TmThreadsSealThreads(void)
void TmqhFlowPrintAutofpHandler(void)
void AffinitySetupLoadFromConfig(void)
Extract CPU affinity configuration from current config file.
#define FatalErrorOnInit(...)
Fatal error IF we're starting up, and configured to consider errors to be fatal errors.
#define SCLogNotice(...)
Macro used to log NOTICE messages.
#define SCLogWarning(...)
Macro used to log WARNING messages.
#define SCLogInfo(...)
Macro used to log INFORMATIONAL messages.
#define SCLogError(...)
Macro used to log ERROR messages.
int LiveGetDeviceCount(void)
Get the number of registered devices.
#define SCRealloc(ptr, sz)
int ParseSizeStringU64(const char *size, uint64_t *res)
#define WarnInvalidConfEntry(param_name, format, value)
Generic API that can be used by all to log an invalid conf entry.
SCCapturePlugin * SCPluginFindCaptureByName(const char *name)