Go to the documentation of this file.
98 static char *active_runmode;
118 static const char *RunModeTranslateModeToName(
int runmode)
140 return "AF_PACKET_DEV";
147 return "NETMAP(DISABLED)";
150 return "UNIX_SOCKET";
155 return "WINDIVERT(DISABLED)";
161 return "DPDK(DISABLED)";
179 static RunMode *RunModeGetCustomMode(
enum SCRunModes runmode,
const char *custom_mode)
182 for (
int i = 0; i < runmodes[runmode].
cnt; i++) {
183 if (strcmp(runmodes[runmode].runmodes[i].
name, custom_mode) == 0)
184 return &runmodes[runmode].
runmodes[i];
200 return active_runmode;
224 return RunModeTranslateModeToName(mainmode);
232 memset(runmodes, 0,
sizeof(runmodes));
257 printf(
"------------------------------------- Runmodes -------------------"
258 "-----------------------\n");
260 printf(
"| %-17s | %-17s | %-10s \n",
261 "RunMode Type",
"Custom Mode ",
"Description");
262 printf(
"|-----------------------------------------------------------------"
263 "-----------------------\n");
267 int mode_displayed = 0;
268 for (j = 0; j < runmodes[i].
cnt; j++) {
269 if (mode_displayed == 1) {
270 printf(
"| ----------------------------------------------"
271 "-----------------------\n");
273 printf(
"| %-17s | %-17s | %-27s \n",
279 printf(
"| %-17s | %-17s | %-27s \n",
280 RunModeTranslateModeToName(runmode->
runmode),
284 if (mode_displayed == 0)
287 if (mode_displayed == 1) {
288 printf(
"|-----------------------------------------------------------------"
289 "-----------------------\n");
294 static const char *RunModeGetConfOrDefault(
int capture_mode,
const char *capture_plugin_name)
296 const char *custom_mode = NULL;
297 const char *val = NULL;
304 if ((custom_mode == NULL) || (strcmp(custom_mode,
"auto") == 0)) {
305 switch (capture_mode) {
315 if (plugin == NULL) {
316 FatalError(
"No capture plugin found with name %s", capture_plugin_name);
364 if (!strcmp(
"worker", custom_mode)) {
366 "to 'workers', please modify your setup.");
367 custom_mode =
"workers";
376 if (runmode == NULL) {
377 runmode = RunModeGetConfOrDefault(capture_mode, capture_plugin_name);
382 RunMode *mode = RunModeGetCustomMode(capture_mode, runmode);
390 if (ips_enabled == 1) {
393 SCLogWarning(
"disabling livedev.use-for-tracking with IPS mode. See ticket #6726.");
404 void RunModeDispatch(
int runmode,
const char *custom_mode,
const char *capture_plugin_name,
405 const char *capture_plugin_args)
407 char *local_custom_mode = NULL;
409 if (custom_mode == NULL) {
410 custom_mode = RunModeGetConfOrDefault(runmode, capture_plugin_name);
411 if (custom_mode == NULL)
415 RunMode *mode = RunModeGetCustomMode(runmode, custom_mode);
417 SCLogError(
"The custom type \"%s\" doesn't exist "
418 "for this runmode type \"%s\". Please use --list-runmodes to "
419 "see available custom types for this runmode",
420 custom_mode, RunModeTranslateModeToName(runmode));
425 if (active_runmode) {
428 active_runmode =
SCStrdup(custom_mode);
429 if (
unlikely(active_runmode == NULL)) {
433 if (strcasecmp(active_runmode,
"autofp") == 0) {
439 if (local_custom_mode != NULL)
440 SCFree(local_custom_mode);
458 static int g_runmode_needs_bypass = 0;
462 g_runmode_needs_bypass = 1;
467 return g_runmode_needs_bypass;
482 int (*RunModeFunc)(
void),
int (*RunModeIsIPSEnabled)(
void))
484 if (RunModeGetCustomMode(runmode,
name) != NULL) {
486 "been registered. Please use an unique name.",
491 void *ptmp =
SCRealloc(runmodes[runmode].runmodes,
492 (runmodes[runmode].
cnt + 1) *
sizeof(
RunMode));
494 SCFree(runmodes[runmode].runmodes);
501 runmodes[runmode].
cnt++;
502 memset(mode, 0x00,
sizeof(*mode));
523 static void RunOutputFreeList(
void)
526 while ((output =
TAILQ_FIRST(&output_free_list))) {
536 static int filedata_logger_count = 0;
540 return filedata_logger_count > 0;
545 switch (run_mode_to_check) {
558 switch(run_mode_to_check) {
589 filedata_logger_count = 0;
606 static void SetupOutput(
651 filedata_logger_count++;
665 static void RunModeInitializeEveOutput(
674 FatalError(
"output types should be a sequence");
682 if (strcmp(
type->val,
"ikev2") == 0) {
683 SCLogWarning(
"eve module 'ikev2' has been replaced by 'ike'");
684 strlcpy(subname,
"eve-log.ike",
sizeof(subname));
686 snprintf(subname,
sizeof(subname),
"eve-log.%s",
type->val);
692 if (sub_output_config != NULL) {
702 if (strcmp(subname, sub_module->
conf_name) == 0) {
715 sub_module->
InitSubFunc(sub_output_config, parent_ctx);
716 if (!result.
ok || result.
ctx == NULL) {
717 FatalError(
"unable to initialize sub-module %s", subname);
720 AddOutputToFreeList(sub_module, result.
ctx);
721 SetupOutput(sub_module->
name, sub_module, result.
ctx, logger_bits);
734 static void RunModeInitializeLuaOutput(
738 BUG_ON(lua_module == NULL);
750 if (strcmp(script->
val,
m->conf_name) == 0) {
758 if (!result.
ok || result.
ctx == NULL) {
762 AddOutputToFreeList(
m, result.
ctx);
763 SetupOutput(
m->name,
m, result.
ctx, logger_bits);
776 if (outputs == NULL) {
783 char tls_log_enabled = 0;
784 char tls_store_present = 0;
792 if (output_config == NULL) {
794 FatalError(
"Failed to lookup configuration child node: %s", output->
val);
797 if (strcmp(output->
val,
"tls-store") == 0) {
798 tls_store_present = 1;
806 if (strcmp(output->
val,
"file-log") == 0) {
808 " use eve.files instead "
810 " for an explanation)");
812 }
else if (strncmp(output->
val,
"unified-",
sizeof(
"unified-") - 1) == 0) {
814 " use Unified2 instead "
816 " for an explanation)");
818 }
else if (strncmp(output->
val,
"unified2-",
sizeof(
"unified2-") - 1) == 0) {
821 }
else if (strcmp(output->
val,
"dns-log") == 0) {
822 SCLogWarning(
"dns-log is not longer available as of Suricata 5.0");
824 }
else if (strcmp(output->
val,
"tls-log") == 0) {
843 }
else if (r.
ctx == NULL) {
853 if (strcmp(output->
val,
"eve-log") == 0) {
854 RunModeInitializeEveOutput(output_config, output_ctx, logger_bits);
859 AddOutputToFreeList(module, output_ctx);
860 }
else if (strcmp(output->
val,
"lua") == 0) {
862 if (output_ctx == NULL)
864 RunModeInitializeLuaOutput(output_config, output_ctx, logger_bits);
865 AddOutputToFreeList(module, output_ctx);
867 AddOutputToFreeList(module, output_ctx);
868 SetupOutput(module->
name, module, output_ctx, logger_bits);
878 if (!tls_store_present && tls_log_enabled) {
881 SCLogWarning(
"Please use 'tls-store' in YAML to configure TLS storage");
886 if (strcmp(output->
val,
"tls-log") == 0) {
889 if (module == NULL) {
890 SCLogWarning(
"No output module named %s, ignoring",
"tls-store");
900 }
else if (r.
ctx == NULL) {
906 AddOutputToFreeList(module, output_ctx);
907 SetupOutput(module->
name, module, output_ctx, logger_bits);
920 SCLogDebug(
"IPPROTO_TCP::%s: g_file_logger_enabled %d g_filedata_logger_enabled %d -> "
932 if (logger_bits[a] == 0)
942 tcp ?
"true" :
"false", udp ?
"true" :
"false");
961 if ((
SCConfGetBool(
"threading.set-cpu-affinity", &affinity)) == 0) {
983 const char *ss = NULL;
984 if ((
SCConfGet(
"threading.stack-size", &ss)) == 1) {
987 FatalError(
"Failed to initialize thread_stack_size output, invalid limit: %s", ss);
992 pthread_attr_init(&attr);
994 if (pthread_attr_getstacksize(&attr, &size) == 0 && size < 512 * 1024) {
996 SCLogNotice(
"thread stack size of %" PRIuMAX
" too small: setting to 512k",
const char * thread_name_workers
const char * RunModeIpsIPFWGetDefaultMode(void)
void FlowManagerThreadSpawn(void)
spawn the flow manager thread
void AffinitySetupLoadFromConfig(void)
Extract CPU affinity configuration from current config file.
@ RUNMODE_ENGINE_ANALYSIS
void TmThreadsSealThreads(void)
const char * thread_name_counter_wakeup
int SCConfValIsTrue(const char *val)
Check if a value is true.
int SCOutputRegisterTxLoggerForSubState(LoggerId id, const char *name, AppProto alproto, const uint8_t sub_state, TxLogger LogFunc, void *initdata, int tc_log_progress, int ts_log_progress, TxLoggerCondition LogCondition, ThreadInitFunc ThreadInit, ThreadDeinitFunc ThreadDeinit)
bool threading_set_cpu_affinity
void RunModeErfFileRegister(void)
void OutputStreamingShutdown(void)
int(* RunModeIsIPSEnabled)(void)
int AppLayerParserProtocolHasLogger(uint8_t ipproto, AppProto alproto)
const char * thread_name_flow_mgr
const char * RunModeErfFileGetDefaultMode(void)
bool IsRunModeOffline(enum SCRunModes run_mode_to_check)
void LogMaintenanceThreadSpawn(void)
void OutputTxShutdown(void)
void TmqhFlowPrintAutofpHandler(void)
void RunModeIdsAFPRegister(void)
int ParseSizeStringU64(const char *size, uint64_t *res)
struct HtpBodyChunk_ * next
void BypassedFlowManagerThreadSpawn(void)
spawn the flow bypass manager thread
void RunModeShutDown(void)
void RunModeDispatch(int runmode, const char *custom_mode, const char *capture_plugin_name, const char *capture_plugin_args)
const char * thread_name_counter_stats
int SCOutputRegisterStreamingLogger(LoggerId id, const char *name, SCStreamingLogger LogFunc, void *initdata, enum SCOutputStreamingType type, ThreadInitFunc ThreadInit, ThreadDeinitFunc ThreadDeinit)
Register a streaming logger.
const char * AppProtoToString(AppProto alproto)
Maps the ALPROTO_*, to its normalized string equivalent.
bool AppLayerParserSupportsFiles(uint8_t ipproto, AppProto alproto)
const char * RunModeAFPGetDefaultMode(void)
const char * thread_name_flow_rec
void OutputFiledataShutdown(void)
int SCConfGet(const char *name, const char **vptr)
Retrieve the value of a configuration node.
const char * RunModeFilePcapGetDefaultMode(void)
#define TAILQ_FOREACH(var, head, field)
const char * thread_name_autofp
OutputModule * OutputGetModuleByConfName(const char *conf_name)
Get an output module by name.
void OutputSetupActiveLoggers(void)
const char * RunModeIdsNflogGetDefaultMode(void)
int SCConfGetBool(const char *name, int *val)
Retrieve a configuration value as a boolean.
void OutputStatsShutdown(void)
#define TAILQ_INSERT_TAIL(head, elm, field)
char * RunmodeGetActive(void)
OutputInitSubFunc InitSubFunc
const char * SCConfNodeLookupChildValue(const SCConfNode *node, const char *name)
Lookup the value of a child configuration node by name.
int SCOutputRegisterFlowLogger(const char *name, FlowLogger LogFunc, void *initdata, ThreadInitFunc ThreadInit, ThreadDeinitFunc ThreadDeinit)
Register a flow logger.
struct RunModes_ RunModes
PacketLogger PacketLogFunc
void TmValidateQueueState(void)
Checks if all the queues allocated so far have at least one reader and writer.
const char * RunModeAFXDPGetDefaultMode(void)
SCFiledataLogger FiledataLogFunc
void RunModeInitializeOutputs(void)
int OutputRegisterStatsLogger(const char *name, StatsLogger LogFunc, OutputCtx *output_ctx, ThreadInitFunc ThreadInit, ThreadDeinitFunc ThreadDeinit)
const char * thread_name_single
bool IsRunModeSystem(enum SCRunModes run_mode_to_check)
const char *(* GetDefaultMode)(void)
void OutputClearActiveLoggers(void)
int SCConfNodeIsSequence(const SCConfNode *node)
Check if a node is a sequence or node.
size_t strlcpy(char *dst, const char *src, size_t siz)
#define TAILQ_ENTRY(type)
const char * RunModeUnixSocketGetDefaultMode(void)
void RunModeIpsNFQRegister(void)
enum SCOutputStreamingType stream_type
void RunModeInitializeThreadSettings(void)
ThreadInitFunc ThreadInit
const char * RunModeDpdkGetDefaultMode(void)
bool RunmodeIsWorkers(void)
#define TAILQ_HEAD_INITIALIZER(head)
OutputModuleList output_modules
#define TAILQ_REMOVE(head, elm, field)
SCRunMode SCRunmodeGet(void)
Get the current run mode.
#define TAILQ_FIRST(head)
const char * thread_name_flow_bypass
bool RunmodeIsAutofp(void)
ThreadDeinitFunc ThreadDeinit
void RunModeListRunmodes(void)
Lists all registered runmodes.
bool g_filedata_logger_enabled
uint64_t threading_set_stack_size
void RunModeEnablesBypassManager(void)
void OutputPacketShutdown(void)
void RunModeIdsNflogRegister(void)
Holds description for a runmode.
void AppLayerParserRegisterLoggerBits(uint8_t ipproto, AppProto alproto, LoggerId bits)
void RunModeIpsIPFWRegister(void)
SCStreamingLogger StreamingLogFunc
#define SCLogWarning(...)
Macro used to log WARNING messages.
const char * RunModeErfDagGetDefaultMode(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.
const char * thread_name_detect_loader
void OutputFileShutdown(void)
void RunModeRegisterNewRunMode(enum SCRunModes runmode, const char *name, const char *description, int(*RunModeFunc)(void), int(*RunModeIsIPSEnabled)(void))
Registers a new runmode.
void FlowRecyclerThreadSpawn(void)
spawn the flow recycler thread
void RunModeErfDagRegister(void)
struct RunMode_ RunMode
Holds description for a runmode.
int SCOutputRegisterPacketLogger(LoggerId logger_id, const char *name, PacketLogger LogFunc, PacketLogCondition ConditionFunc, void *initdata, ThreadInitFunc ThreadInit, ThreadDeinitFunc ThreadDeinit)
Register a packet logger.
int SCOutputRegisterFileLogger(LoggerId id, const char *name, SCFileLogger LogFunc, void *initdata, ThreadInitFunc ThreadInit, ThreadDeinitFunc ThreadDeinit)
Register a file logger.
#define SCLogInfo(...)
Macro used to log INFORMATIONAL messages.
#define WarnInvalidConfEntry(param_name, format, value)
Generic API that can be used by all to log an invalid conf entry.
void RunModeIpsWinDivertRegister(void)
#define SCRealloc(ptr, sz)
SCConfNode * SCConfNodeLookupChild(const SCConfNode *node, const char *name)
Lookup a child configuration node by name.
void RunModeIdsAFXDPRegister(void)
TxLoggerCondition TxLogCondition
void RunModeUnixSocketRegister(void)
void(* DeInit)(struct OutputCtx_ *)
const char * thread_name_heartbeat
#define FatalErrorOnInit(...)
Fatal error IF we're starting up, and configured to consider errors to be fatal errors.
void StatsSpawnThreads(void)
Spawns the wakeup, and the management thread used by the stats api.
int RunModeNeedsBypassManager(void)
bool g_file_logger_enabled
void RunModeIdsPcapRegister(void)
void RunModeRegisterRunModes(void)
Register all runmodes in the engine.
void RunModeFilePcapRegister(void)
PacketLogCondition PacketConditionFunc
struct SCLogConfig_ SCLogConfig
Holds the config state used by the logging api.
const char * RunModeNetmapGetDefaultMode(void)
const char * RunModeIpsNFQGetDefaultMode(void)
SCConfNode * SCConfGetNode(const char *name)
Get a SCConfNode by name.
#define SCLogError(...)
Macro used to log ERROR messages.
void RunModeIdsNetmapRegister(void)
struct OutputFreeList_ OutputFreeList
const char * thread_name_verdict
void RunModeDpdkRegister(void)
#define TAILQ_HEAD(name, type)
void OutputFlowShutdown(void)
int RunModeEngineIsIPS(int capture_mode, const char *runmode, const char *capture_plugin_name)
int SCOutputRegisterFiledataLogger(LoggerId id, const char *name, SCFiledataLogger LogFunc, void *initdata, ThreadInitFunc ThreadInit, ThreadDeinitFunc ThreadDeinit)
Register a file-data logger.
const char * thread_name_unix_socket
OutputModule * output_module
const char * RunModeGetMainMode(void)
int RunModeOutputFiledataEnabled(void)
int LiveGetDeviceCount(void)
Get the number of registered devices.
#define SCLogNotice(...)
Macro used to log NOTICE messages.
void UtRunModeRegister(void)
const char * RunModeIpsWinDivertGetDefaultMode(void)
int SCConfGetFloat(const char *name, float *val)
Retrieve a configuration value as a float.
#define DEBUG_VALIDATE_BUG_ON(exp)
SCCapturePlugin * SCPluginFindCaptureByName(const char *name)
float threading_detect_ratio
const char * RunModeIdsGetDefaultMode(void)