}
struct SuriInstance {
- int running_mode;
+ int run_mode;
char pcap_dev[128];
char *sig_file;
static void SuriInstanceInit(struct SuriInstance *suri)
{
- suri->running_mode = 0;
+ suri->run_mode = RUNMODE_UNKNOWN;
memset(suri->pcap_dev, 0, sizeof(suri->pcap_dev));
suri->sig_file = NULL;
if (strcmp((long_opts[option_index]).name , "pfring") == 0 ||
strcmp((long_opts[option_index]).name , "pfring-int") == 0) {
#ifdef HAVE_PFRING
- run_mode = RUNMODE_PFRING;
+ suri->run_mode = RUNMODE_PFRING;
if (optarg != NULL) {
memset(pcap_dev, 0, sizeof(pcap_dev));
strlcpy(pcap_dev, optarg,
}
else if (strcmp((long_opts[option_index]).name , "af-packet") == 0){
#ifdef HAVE_AF_PACKET
- if (run_mode == RUNMODE_UNKNOWN) {
- run_mode = RUNMODE_AFP_DEV;
+ if (suri->run_mode == RUNMODE_UNKNOWN) {
+ suri->run_mode = RUNMODE_AFP_DEV;
if (optarg) {
LiveRegisterDevice(optarg);
memset(suri->pcap_dev, 0, sizeof(suri->pcap_dev));
((strlen(optarg) < sizeof(suri->pcap_dev)) ?
(strlen(optarg) + 1) : sizeof(suri->pcap_dev)));
}
- } else if (run_mode == RUNMODE_AFP_DEV) {
+ } else if (suri->run_mode == RUNMODE_AFP_DEV) {
SCLogWarning(SC_WARN_PCAP_MULTI_DEV_EXPERIMENTAL, "using "
"multiple devices to get packets is experimental.");
if (optarg) {
return TM_ECODE_FAILED;
#endif
} else if (strcmp((long_opts[option_index]).name , "pcap") == 0) {
- if (run_mode == RUNMODE_UNKNOWN) {
- run_mode = RUNMODE_PCAP_DEV;
+ if (suri->run_mode == RUNMODE_UNKNOWN) {
+ suri->run_mode = RUNMODE_PCAP_DEV;
if (optarg) {
LiveRegisterDevice(optarg);
memset(suri->pcap_dev, 0, sizeof(suri->pcap_dev));
((strlen(optarg) < sizeof(suri->pcap_dev)) ?
(strlen(optarg) + 1) : sizeof(suri->pcap_dev)));
}
- } else if (run_mode == RUNMODE_PCAP_DEV) {
+ } else if (suri->run_mode == RUNMODE_PCAP_DEV) {
#ifdef OS_WIN32
SCLogError(SC_ERR_PCAP_MULTI_DEV_NO_SUPPORT, "pcap multi dev "
"support is not (yet) supported on Windows.");
}
#ifdef BUILD_UNIX_SOCKET
} else if (strcmp((long_opts[option_index]).name , "unix-socket") == 0) {
- if (run_mode == RUNMODE_UNKNOWN) {
- run_mode = RUNMODE_UNIX_SOCKET;
+ if (suri->run_mode == RUNMODE_UNKNOWN) {
+ suri->run_mode = RUNMODE_UNIX_SOCKET;
if (optarg) {
if (ConfSet("unix-command.filename", optarg, 0) != 1) {
fprintf(stderr, "ERROR: Failed to set unix-command.filename.\n");
}
else if(strcmp((long_opts[option_index]).name, "list-unittests") == 0) {
#ifdef UNITTESTS
- /* Set run_mode to unit tests. */
- run_mode = RUNMODE_UNITTEST;
+ suri->run_mode = RUNMODE_LIST_UNITTEST;
#else
fprintf(stderr, "ERROR: Unit tests not enabled. Make sure to pass --enable-unittests to configure when building.\n");
return TM_ECODE_FAILED;
return TM_ECODE_FAILED;
#endif /* UNITTESTS */
} else if (strcmp((long_opts[option_index]).name, "list-runmodes") == 0) {
- suri->running_mode = RUNMODE_LIST_RUNMODES;
+ suri->run_mode = RUNMODE_LIST_RUNMODES;
return TM_ECODE_OK;
} else if (strcmp((long_opts[option_index]).name, "list-keywords") == 0) {
if (optarg) {
}
#ifdef OS_WIN32
else if(strcmp((long_opts[option_index]).name, "service-install") == 0) {
- suri->running_mode = RUNMODE_INSTALL_SERVICE;
+ suri->run_mode = RUNMODE_INSTALL_SERVICE;
return TM_ECODE_OK;
}
else if(strcmp((long_opts[option_index]).name, "service-remove") == 0) {
- suri->running_mode = RUNMODE_REMOVE_SERVICE;
+ suri->run_mode = RUNMODE_REMOVE_SERVICE;
return TM_ECODE_OK;
}
else if(strcmp((long_opts[option_index]).name, "service-change-params") == 0) {
- suri->running_mode = RUNMODE_CHANGE_SERVICE_PARAMS;
+ suri->run_mode = RUNMODE_CHANGE_SERVICE_PARAMS;
return TM_ECODE_OK;
}
#endif /* OS_WIN32 */
#endif /* HAVE_LIBCAP_NG */
}
else if (strcmp((long_opts[option_index]).name, "erf-in") == 0) {
- run_mode = RUNMODE_ERF_FILE;
+ suri->run_mode = RUNMODE_ERF_FILE;
if (ConfSet("erf-file.file", optarg, 0) != 1) {
fprintf(stderr, "ERROR: Failed to set erf-file.file\n");
return TM_ECODE_FAILED;
}
else if (strcmp((long_opts[option_index]).name, "dag") == 0) {
#ifdef HAVE_DAG
- if (run_mode == RUNMODE_UNKNOWN) {
- run_mode = RUNMODE_DAG;
+ if (suri->run_mode == RUNMODE_UNKNOWN) {
+ suri->run_mode = RUNMODE_DAG;
}
- else if (run_mode != RUNMODE_DAG) {
+ else if (suri->run_mode != RUNMODE_DAG) {
SCLogError(SC_ERR_MULTIPLE_RUN_MODE,
"more than one run mode has been specified");
usage(argv[0]);
}
else if (strcmp((long_opts[option_index]).name, "napatech") == 0) {
#ifdef HAVE_NAPATECH
- run_mode = RUNMODE_NAPATECH;
+ suri->run_mode = RUNMODE_NAPATECH;
#else
SCLogError(SC_ERR_NAPATECH_REQUIRED, "libntapi and a Napatech adapter are required"
" to capture packets using --napatech.");
#endif /* HAVE_PCAP_SET_BUFF */
}
else if(strcmp((long_opts[option_index]).name, "build-info") == 0) {
- suri->running_mode = RUNMODE_PRINT_BUILDINFO;
+ suri->run_mode = RUNMODE_PRINT_BUILDINFO;
return TM_ECODE_OK;
}
#ifdef HAVE_MPIPE
break;
#endif /* OS_WIN32 */
case 'h':
- suri->running_mode = RUNMODE_PRINT_USAGE;
+ suri->run_mode = RUNMODE_PRINT_USAGE;
return TM_ECODE_OK;
case 'i':
memset(suri->pcap_dev, 0, sizeof(suri->pcap_dev));
return TM_ECODE_FAILED;
}
- if (run_mode == RUNMODE_UNKNOWN) {
- run_mode = RUNMODE_PCAP_DEV;
+ if (suri->run_mode == RUNMODE_UNKNOWN) {
+ suri->run_mode = RUNMODE_PCAP_DEV;
LiveRegisterDevice(suri->pcap_dev);
- } else if (run_mode == RUNMODE_PCAP_DEV) {
+ } else if (suri->run_mode == RUNMODE_PCAP_DEV) {
#ifdef OS_WIN32
SCLogError(SC_ERR_PCAP_MULTI_DEV_NO_SUPPORT, "pcap multi dev "
"support is not (yet) supported on Windows.");
break;
case 'q':
#ifdef NFQ
- if (run_mode == RUNMODE_UNKNOWN) {
- run_mode = RUNMODE_NFQ;
+ if (suri->run_mode == RUNMODE_UNKNOWN) {
+ suri->run_mode = RUNMODE_NFQ;
SET_ENGINE_MODE_IPS(engine_mode);
if (NFQRegisterQueue(optarg) == -1)
return TM_ECODE_FAILED;
- } else if (run_mode == RUNMODE_NFQ) {
+ } else if (suri->run_mode == RUNMODE_NFQ) {
if (NFQRegisterQueue(optarg) == -1)
return TM_ECODE_FAILED;
} else {
break;
case 'd':
#ifdef IPFW
- if (run_mode == RUNMODE_UNKNOWN) {
- run_mode = RUNMODE_IPFW;
+ if (suri->run_mode == RUNMODE_UNKNOWN) {
+ suri->run_mode = RUNMODE_IPFW;
SET_ENGINE_MODE_IPS(engine_mode);
if (IPFWRegisterQueue(optarg) == -1)
return TM_ECODE_FAILED;
- } else if (run_mode == RUNMODE_IPFW) {
+ } else if (suri->run_mode == RUNMODE_IPFW) {
if (IPFWRegisterQueue(optarg) == -1)
return TM_ECODE_FAILED;
} else {
#endif /* IPFW */
break;
case 'r':
- if (run_mode == RUNMODE_UNKNOWN) {
- run_mode = RUNMODE_PCAP_FILE;
+ if (suri->run_mode == RUNMODE_UNKNOWN) {
+ suri->run_mode = RUNMODE_PCAP_FILE;
} else {
SCLogError(SC_ERR_MULTIPLE_RUN_MODE, "more than one run mode "
"has been specified");
break;
case 'u':
#ifdef UNITTESTS
- if (run_mode == RUNMODE_UNKNOWN) {
- run_mode = RUNMODE_UNITTEST;
- suri->running_mode = RUNMODE_UNITTEST;
+ if (suri->run_mode == RUNMODE_UNKNOWN) {
+ suri->run_mode = RUNMODE_UNITTEST;
} else {
SCLogError(SC_ERR_MULTIPLE_RUN_MODE, "more than one run mode has"
" been specified");
#endif
break;
case 'V':
- suri->running_mode = RUNMODE_PRINT_VERSION;
+ suri->run_mode = RUNMODE_PRINT_VERSION;
return TM_ECODE_OK;
case 'F':
SetBpfStringFromFile(optarg);
}
if (list_app_layer_protocols)
- suri->running_mode = RUNMODE_LIST_APP_LAYERS;
+ suri->run_mode = RUNMODE_LIST_APP_LAYERS;
if (list_cuda_cards)
- suri->running_mode = RUNMODE_LIST_CUDA_CARDS;
+ suri->run_mode = RUNMODE_LIST_CUDA_CARDS;
if (list_keywords)
- suri->running_mode = RUNMODE_LIST_KEYWORDS;
+ suri->run_mode = RUNMODE_LIST_KEYWORDS;
if (list_unittests)
- suri->running_mode = RUNMODE_LIST_UNITTEST;
+ suri->run_mode = RUNMODE_LIST_UNITTEST;
if (dump_config)
- suri->running_mode = RUNMODE_DUMP_CONFIG;
+ suri->run_mode = RUNMODE_DUMP_CONFIG;
if (conf_test)
- suri->running_mode = RUNMODE_CONF_TEST;
+ suri->run_mode = RUNMODE_CONF_TEST;
return TM_ECODE_OK;
}
exit(EXIT_FAILURE);
}
+ /* Treat internal running mode */
switch(suri.running_mode) {
case SC_RUN_LIST_KEYWORDS:
return ListKeywords(suri.keyword_info);
break;
}
+ /* Set the global run mode */
+ run_mode = suri.run_mode;
+
+ if (suri.run_mode == RUNMODE_UNITTEST)
+ return SuriRunUnittests(0, suri.regex_arg);
+
#ifdef REVISION
SCLogInfo("This is %s version %s (rev %s)", PROG_NAME, PROG_VER, xstr(REVISION));
#elif defined RELEASE
CudaBufferInit();
#endif
- if (!CheckValidDaemonModes(suri.daemon, run_mode)) {
+ if (!CheckValidDaemonModes(suri.daemon, suri.run_mode)) {
exit(EXIT_FAILURE);
}
AppLayerDetectProtoThreadInit();
AppLayerParsersInitPostProcess();
- if (suri.running_mode == RUNMODE_DUMP_CONFIG) {
+ if (suri.run_mode == RUNMODE_DUMP_CONFIG) {
ConfDump();
exit(EXIT_SUCCESS);
}
* back on a sane default. */
char *temp_default_packet_size;
if ((ConfGet("default-packet-size", &temp_default_packet_size)) != 1) {
- switch (run_mode) {
+ switch (suri.run_mode) {
case RUNMODE_PCAP_DEV:
case RUNMODE_AFP_DEV:
case RUNMODE_PFRING:
SCLogDebug("Default packet size set to %"PRIu32, default_packet_size);
#ifdef NFQ
- if (run_mode == RUNMODE_NFQ)
+ if (suri.run_mode == RUNMODE_NFQ)
NFQInitConfig(FALSE);
#endif
}
if (run_mode == RUNMODE_UNKNOWN) {
- if (!engine_analysis && !(suri.running_mode == RUNMODE_CONF_TEST)) {
+ if (!engine_analysis && !(suri.run_mode == RUNMODE_CONF_TEST)) {
usage(argv[0]);
exit(EXIT_FAILURE);
}
exit(EXIT_FAILURE);
}
- if(suri.running_mode == RUNMODE_CONF_TEST){
+ if(suri.run_mode == RUNMODE_CONF_TEST){
SCLogInfo("Configuration provided was successfully loaded. Exiting.");
exit(EXIT_SUCCESS);
}