Go to the documentation of this file.
36 #ifdef HAVE_SYS_RESOURCE_H
38 #include <sys/resource.h>
146 #ifdef SYSTEMD_NOTIFY
171 #define DEFAULT_MAX_PENDING_PACKETS 1024
174 #define VERBOSE_MAX (SC_LOG_DEBUG - SC_LOG_NOTICE)
199 #ifndef AFLFUZZ_NO_RANDOM
324 #ifndef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
325 static void SignalHandlerSigint(
int sig)
329 static void SignalHandlerSigterm(
int sig)
335 #define UNW_LOCAL_ONLY
336 #include <libunwind.h>
337 static void SignalHandlerUnexpected(
int sig_num, siginfo_t *info,
void *context)
342 signal(SIGABRT, SIG_DFL);
343 signal(SIGSEGV, SIG_DFL);
345 if ((r = unw_init_local(&cursor, (unw_context_t *)(context)) != 0)) {
346 SCLogError(
"unable to obtain stack trace: unw_init_local: %s", unw_strerror(r));
350 int cw = snprintf(msg,
sizeof(msg),
"stacktrace:sig %d:", sig_num);
353 size_t offset =
MIN((
size_t)cw,
sizeof(msg) - 1);
356 while (r > 0 &&
offset <
sizeof(msg) - 1) {
357 if (unw_is_signal_frame(&cursor) == 0) {
359 char name[256] =
"?";
360 int ret = unw_get_proc_name(&cursor,
name,
sizeof(
name), &off);
362 if (ret != 0 && ret != -UNW_ENOMEM) {
363 cw = snprintf(msg +
offset,
sizeof(msg) -
offset,
"[unknown]:");
365 cw = snprintf(msg +
offset,
sizeof(msg) -
offset,
"%s+0x%08" PRIx64,
name, off);
372 r = unw_step(&cursor);
373 if (r > 0 &&
offset <
sizeof(msg) - 1) {
380 if (
offset >=
sizeof(msg) - 1)
381 memcpy(msg +
sizeof(msg) - 4,
"...", 4);
386 kill(getpid(), sig_num);
388 #undef UNW_LOCAL_ONLY
398 static void SignalHandlerSigusr2(
int sig)
408 static void SignalHandlerSigHup(
int sig)
461 #ifdef HAVE_AF_PACKET
469 #ifdef BUILD_HYPERSCAN
490 static void OnNotifyRunning(
void)
492 #ifdef SYSTEMD_NOTIFY
518 static int SetBpfString(
int argc,
char *argv[])
520 char *bpf_filter = NULL;
521 uint32_t bpf_len = 0;
526 while(argv[tmpindex] != NULL) {
527 bpf_len+=strlen(argv[tmpindex]) + 1;
539 while(argv[tmpindex] != NULL) {
540 strlcat(bpf_filter, argv[tmpindex],bpf_len);
541 if(argv[tmpindex + 1] != NULL) {
542 strlcat(bpf_filter,
" ", bpf_len);
547 if(strlen(bpf_filter) > 0) {
559 static void SetBpfStringFromFile(
char *filename)
561 char *bpf_filter = NULL;
562 char *bpf_comment_tmp = NULL;
563 char *bpf_comment_start = NULL;
569 fp = fopen(filename,
"r");
571 SCLogError(
"Failed to open file %s", filename);
576 SCLogError(
"Failed to stat file %s", filename);
580 bpf_len = ((size_t)(st.st_size)) + 1;
584 SCLogError(
"Failed to allocate buffer for bpf filter in file %s", filename);
588 nm = fread(bpf_filter, 1, bpf_len - 1, fp);
589 if ((ferror(fp) != 0) || (nm != (bpf_len - 1))) {
590 SCLogError(
"Failed to read complete BPF file %s", filename);
597 bpf_filter[nm] =
'\0';
599 if(strlen(bpf_filter) > 0) {
601 bpf_comment_start = bpf_filter;
602 while((bpf_comment_tmp = strchr(bpf_comment_start,
'#')) != NULL) {
603 while((*bpf_comment_tmp !=
'\0') &&
604 (*bpf_comment_tmp !=
'\r') && (*bpf_comment_tmp !=
'\n'))
606 *bpf_comment_tmp++ =
' ';
608 bpf_comment_start = bpf_comment_tmp;
611 while((bpf_comment_tmp = strchr(bpf_filter,
'\r')) != NULL) {
612 *bpf_comment_tmp =
' ';
614 while((bpf_comment_tmp = strchr(bpf_filter,
'\n')) != NULL) {
615 *bpf_comment_tmp =
' ';
618 while (strlen(bpf_filter) > 0 &&
619 bpf_filter[strlen(bpf_filter)-1] ==
' ')
621 bpf_filter[strlen(bpf_filter)-1] =
'\0';
623 if (strlen(bpf_filter) > 0) {
633 static void PrintUsage(
const char *progname)
640 printf(
"USAGE: %s [OPTIONS] [BPF FILTER]\n\n", progname);
642 printf(
"\n General:\n");
643 printf(
"\t-v : be more verbose (use multiple times to "
644 "increase verbosity)\n");
645 printf(
"\t-c <path> : path to configuration file\n");
646 printf(
"\t-l <dir> : default log directory\n");
647 printf(
"\t--include <path> : additional configuration file\n");
648 printf(
"\t--set name=value : set a configuration value\n");
649 printf(
"\t--pidfile <file> : write pid to this file\n");
650 printf(
"\t-T : test configuration file (use with -c)\n");
651 printf(
"\t--init-errors-fatal : enable fatal failure on signature init "
654 printf(
"\t-D : run as daemon\n");
656 printf(
"\t--service-install : install as service\n");
657 printf(
"\t--service-remove : remove service\n");
658 printf(
"\t--service-change-params : change service startup parameters\n");
660 #ifdef HAVE_LIBCAP_NG
661 printf(
"\t--user <user> : run suricata as this user after init\n");
662 printf(
"\t--group <group> : run suricata as this group after init\n");
664 #ifdef BUILD_UNIX_SOCKET
665 printf(
"\t--unix-socket[=<file>] : use unix socket to control suricata work\n");
667 printf(
"\t--runmode <runmode_id> : specific runmode modification the engine should run. The argument\n"
668 "\t supplied should be the id for the runmode obtained by running\n"
669 "\t --list-runmodes\n");
670 printf(
"\t--plugin <path> : load plugin in addition to config\n");
672 printf(
"\n Capture and IPS:\n");
674 printf(
"\t-F <bpf filter file> : bpf filter file\n");
675 printf(
"\t-k [all|none] : force checksum check (all) or disabled it "
677 printf(
"\t-i <dev or ip> : run in pcap live mode\n");
678 printf(
"\t--pcap[=<dev>] : run in pcap mode, no value select interfaces "
679 "from suricata.yaml\n");
680 #ifdef HAVE_PCAP_SET_BUFF
681 printf(
"\t--pcap-buffer-size : size of the pcap buffer value from 0 - %i\n",INT_MAX);
684 printf(
"\t-q <qid[:qid]> : run in inline nfqueue mode (use colon to "
685 "specify a range of queues)\n");
688 printf(
"\t-d <divert port> : run in inline ipfw divert mode\n");
690 #ifdef HAVE_AF_PACKET
691 printf(
"\t--af-packet[=<dev>] : run in af-packet mode, no value select interfaces from suricata.yaml\n");
694 printf(
"\t--af-xdp[=<dev>] : run in af-xdp mode, no value select "
695 "interfaces from suricata.yaml\n");
698 printf(
"\t--netmap[=<dev>] : run in netmap mode, no value select interfaces from suricata.yaml\n");
701 printf(
"\t--pfring[=<dev>] : run in pfring mode, use interfaces from suricata.yaml\n");
702 printf(
"\t--pfring-int <dev> : run in pfring mode, use interface <dev>\n");
703 printf(
"\t--pfring-cluster-id <id> : pfring cluster id \n");
704 printf(
"\t--pfring-cluster-type <type> : pfring cluster type for PF_RING 4.1.2 and later cluster_round_robin|cluster_flow\n");
707 printf(
"\t--dpdk : run in dpdk mode, uses interfaces from "
711 printf(
"\t--dag <dagX:Y> : process ERF records from DAG interface X, stream Y\n");
714 printf(
"\t--windivert <filter> : run in inline WinDivert mode\n");
715 printf(
"\t--windivert-forward <filter> : run in inline WinDivert mode, as a gateway\n");
718 printf(
"\t--reject-dev <dev> : send reject packets from this interface\n");
721 printf(
"\n Capture Files:\n");
722 printf(
"\t-r <path> : run in pcap file/offline mode\n");
723 printf(
"\t--pcap-file-continuous : when running in pcap mode with a directory, "
724 "continue checking directory for pcaps until interrupted\n");
725 printf(
"\t--pcap-file-delete : when running in replay mode (-r with "
726 "directory or file), will delete pcap files that have been processed when done\n");
727 printf(
"\t--pcap-file-recursive : will descend into subdirectories when running "
728 "in replay mode (-r)\n");
729 printf(
"\t--pcap-file-buffer-size : set read buffer size (setvbuf)\n");
730 printf(
"\t--erf-in <path> : process an ERF file\n");
732 printf(
"\n Detection:\n");
733 printf(
"\t-s <path> : path to signature file loaded in addition to "
734 "suricata.yaml settings (optional)\n");
735 printf(
"\t-S <path> : path to signature file loaded exclusively "
737 printf(
"\t--disable-detection : disable detection engine\n");
738 printf(
"\t--engine-analysis : print reports on analysis of different "
739 "sections in the engine and exit.\n"
740 "\t Please have a look at the conf parameter "
741 "engine-analysis on what reports\n"
742 "\t can be printed\n");
744 printf(
"\n Firewall:\n");
745 printf(
"\t--firewall : enable firewall mode\n");
746 printf(
"\t--firewall-rules-exclusive=<path> : path to firewall rule file loaded "
749 printf(
"\n Info:\n");
750 printf(
"\t-V : display Suricata version\n");
751 printf(
"\t--list-keywords : list keywords implemented by the engine\n");
752 printf(
"\t [=all|json|csv|<kword>]\n");
753 printf(
"\t--list-runmodes : list supported runmodes\n");
754 printf(
"\t--list-app-layer-protos : list supported app layer protocols\n");
755 printf(
"\t--list-rule-protos : list supported rule protocols\n");
756 printf(
"\t--list-app-layer-hooks : list supported app layer hooks for use in "
758 printf(
"\t--list-app-layer-frames : list supported app layer frames for use with "
759 "'frame' keyword\n");
760 printf(
"\t--dump-config : show the running configuration\n");
761 printf(
"\t--dump-features : display provided features\n");
762 printf(
"\t--build-info : display build information\n");
764 printf(
"\n Testing:\n");
765 printf(
"\t--simulate-ips : force engine into IPS mode. Useful for QA\n");
767 printf(
"\t-u : run the unittests and exit\n");
768 printf(
"\t-U=REGEX, --unittest-filter=REGEX : filter unittests with a pcre compatible "
770 printf(
"\t--list-unittests : list unit tests\n");
771 printf(
"\t--fatal-unittests : enable fatal failure on unittest error\n");
772 printf(
"\t--unittests-coverage : display unittest coverage report\n");
775 printf(
"\nTo run " PROG_NAME " with default configuration on "
776 "interface eth0 with signature file \"signatures.rules\", run the "
777 "command as:\n\n%s -c suricata.yaml -s signatures.rules -i eth0 \n\n",
781 static void PrintBuildInfo(
void)
786 char features[2048] =
"";
791 strlcat(features,
"DEBUG ",
sizeof(features));
793 #ifdef DEBUG_VALIDATION
794 strlcat(features,
"DEBUG_VALIDATION ",
sizeof(features));
797 strlcat(features,
"QA_SIMULATION ",
sizeof(features));
800 strlcat(features,
"UNITTESTS ",
sizeof(features));
803 strlcat(features,
"NFQ ",
sizeof(features));
806 strlcat(features,
"IPFW ",
sizeof(features));
808 #ifdef HAVE_PCAP_SET_BUFF
809 strlcat(features,
"PCAP_SET_BUFF ",
sizeof(features));
812 strlcat(features,
"PF_RING ",
sizeof(features));
815 strlcat(features,
"NAPATECH ",
sizeof(features));
817 #ifdef HAVE_AF_PACKET
818 strlcat(features,
"AF_PACKET ",
sizeof(features));
821 strlcat(features,
"NETMAP ",
sizeof(features));
823 #ifdef HAVE_PACKET_FANOUT
824 strlcat(features,
"HAVE_PACKET_FANOUT ",
sizeof(features));
827 strlcat(features,
"DAG ",
sizeof(features));
829 #ifdef HAVE_LIBCAP_NG
830 strlcat(features,
"LIBCAP_NG ",
sizeof(features));
833 strlcat(features,
"LIBNET1.1 ",
sizeof(features));
835 strlcat(features,
"HAVE_HTP_URI_NORMALIZE_HOOK ",
sizeof(features));
836 #ifdef PCRE2_HAVE_JIT
837 strlcat(features,
"PCRE_JIT ",
sizeof(features));
840 strlcat(features,
"HAVE_NSS ",
sizeof(features));
842 strlcat(features,
"HTTP2_DECOMPRESSION ",
sizeof(features));
844 strlcat(features,
"HAVE_LUA ",
sizeof(features));
846 strlcat(features,
"HAVE_JA3 ",
sizeof(features));
849 strlcat(features,
"HAVE_JA4 ",
sizeof(features));
851 strlcat(features,
"HAVE_LIBJANSSON ",
sizeof(features));
853 strlcat(features,
"PROFILING ",
sizeof(features));
855 #ifdef HAVE_PACKET_EBPF
856 strlcat(features,
"EBPF ",
sizeof(features));
858 #ifdef PROFILE_LOCKING
859 strlcat(features,
"PROFILE_LOCKING ",
sizeof(features));
861 #ifdef BUILD_UNIX_SOCKET
862 strlcat(features,
"UNIX_SOCKET ",
sizeof(features));
864 #if defined(TLS_C11) || defined(TLS_GNU)
865 strlcat(features,
"TLS ",
sizeof(features));
868 strlcat(features,
"TLS_C11 ",
sizeof(features));
869 #elif defined(TLS_GNU)
870 strlcat(features,
"TLS_GNU ",
sizeof(features));
873 strlcat(features,
"MAGIC ",
sizeof(features));
875 strlcat(features,
"RUST ",
sizeof(features));
876 #if defined(SC_ADDRESS_SANITIZER)
877 strlcat(features,
"ASAN ",
sizeof(features));
879 #if defined(FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION)
880 strlcat(features,
"FUZZ ",
sizeof(features));
882 #if defined(HAVE_POPCNT64)
883 strlcat(features,
"POPCNT64 ",
sizeof(features));
885 if (strlen(features) == 0) {
886 strlcat(features,
"none",
sizeof(features));
889 printf(
"Features: %s\n", features);
892 memset(features, 0x00,
sizeof(features));
893 #if defined(__SSE4_2__)
894 strlcat(features,
"SSE_4_2 ",
sizeof(features));
896 #if defined(__SSE4_1__)
897 strlcat(features,
"SSE_4_1 ",
sizeof(features));
899 #if defined(__SSE3__)
900 strlcat(features,
"SSE_3 ",
sizeof(features));
902 #if defined(__SSE2__)
903 strlcat(features,
"SSE_2 ",
sizeof(features));
905 if (strlen(features) == 0) {
906 strlcat(features,
"none",
sizeof(features));
908 printf(
"SIMD support: %s\n", features);
911 memset(features, 0x00,
sizeof(features));
912 #if defined(__GCC_HAVE_SYNC_COMPARE_AND_SWAP_1)
913 strlcat(features,
"1 ",
sizeof(features));
915 #if defined(__GCC_HAVE_SYNC_COMPARE_AND_SWAP_2)
916 strlcat(features,
"2 ",
sizeof(features));
918 #if defined(__GCC_HAVE_SYNC_COMPARE_AND_SWAP_4)
919 strlcat(features,
"4 ",
sizeof(features));
921 #if defined(__GCC_HAVE_SYNC_COMPARE_AND_SWAP_8)
922 strlcat(features,
"8 ",
sizeof(features));
924 #if defined(__GCC_HAVE_SYNC_COMPARE_AND_SWAP_16)
925 strlcat(features,
"16 ",
sizeof(features));
927 if (strlen(features) == 0) {
928 strlcat(features,
"none",
sizeof(features));
930 strlcat(features,
"byte(s)",
sizeof(features));
932 printf(
"Atomic intrinsics: %s\n", features);
936 #elif __WORDSIZE == 32
939 bits =
"<unknown>-bits";
942 #if __BYTE_ORDER == __BIG_ENDIAN
943 endian =
"Big-endian";
944 #elif __BYTE_ORDER == __LITTLE_ENDIAN
945 endian =
"Little-endian";
947 endian =
"<unknown>-endian";
950 printf(
"%s, %s architecture\n", bits, endian);
952 printf(
"GCC version %s, C version %"PRIiMAX
"\n", __VERSION__, (intmax_t)__STDC_VERSION__);
954 printf(
"C version %"PRIiMAX
"\n", (intmax_t)__STDC_VERSION__);
958 printf(
"compiled with -fstack-protector\n");
961 printf(
"compiled with -fstack-protector-all\n");
970 #if _FORTIFY_SOURCE == 2
971 printf(
"compiled with _FORTIFY_SOURCE=2\n");
972 #elif _FORTIFY_SOURCE == 1
973 printf(
"compiled with _FORTIFY_SOURCE=1\n");
974 #elif _FORTIFY_SOURCE == 0
975 printf(
"compiled with _FORTIFY_SOURCE=0\n");
978 printf(
"L1 cache line size (CLS)=%d\n",
CLS);
981 tls =
"_Thread_local";
982 #elif defined(TLS_GNU)
985 #error "Unsupported thread local"
987 printf(
"thread local storage method: %s\n", tls);
989 printf(
"compiled with %s\n", htp_get_version());
991 #include "build-info.h"
1087 static TmEcode ParseInterfacesList(
const int runmode,
char *pcap_dev)
1093 if (strlen(pcap_dev) == 0) {
1096 SCLogError(
"No interface found in config for pcap");
1103 if (strlen(pcap_dev)) {
1105 SCLogError(
"Failed to set pfring.live-interface");
1112 char iface_selector[] =
"dpdk.interfaces";
1115 SCLogError(
"No interface found in config for %s", iface_selector);
1119 #ifdef HAVE_AF_PACKET
1122 if (strlen(pcap_dev)) {
1124 SCLogError(
"Failed to set af-packet.live-interface");
1130 SCLogError(
"No interface found in config for af-packet");
1138 if (strlen(pcap_dev)) {
1140 SCLogError(
"Failed to set af-xdp.live-interface");
1146 SCLogError(
"No interface found in config for af-xdp");
1154 if (strlen(pcap_dev)) {
1156 SCLogError(
"Failed to set netmap.live-interface");
1162 SCLogError(
"No interface found in config for netmap");
1171 SCLogError(
"No group found in config for nflog");
1180 static void SCInstanceInit(
SCInstance *suri,
const char *progname)
1182 memset(suri, 0x00,
sizeof(*suri));
1209 #if HAVE_DETECT_DISABLED==1
1219 if (strstr(prog_ver,
"RELEASE") != NULL) {
1239 if (strstr(
PROG_VER,
"-dev") == NULL) {
1250 static TmEcode PrintVersion(
void)
1258 const char *mode = suri->
system ?
"SYSTEM" :
"USER";
1259 SCLogNotice(
"This is %s version %s running in %s mode",
1270 static void SCPrintElapsedTime(
struct timeval *start_time)
1272 if (start_time == NULL)
1274 struct timeval end_time;
1275 memset(&end_time, 0,
sizeof(end_time));
1276 gettimeofday(&end_time, NULL);
1277 uint64_t milliseconds = ((end_time.tv_sec - start_time->tv_sec) * 1000) +
1278 (((1000000 + end_time.tv_usec - start_time->tv_usec) / 1000) - 1000);
1279 SCLogInfo(
"time elapsed %.3fs", (
float)milliseconds/(
float)1000);
1282 static int ParseCommandLineAfpacket(
SCInstance *suri,
const char *in_arg)
1284 #ifdef HAVE_AF_PACKET
1296 SCLogInfo(
"Multiple af-packet option without interface on each is useless");
1300 "has been specified");
1306 SCLogError(
"AF_PACKET not enabled. On Linux "
1307 "host, make sure to pass --enable-af-packet to "
1308 "configure when building.");
1313 static int ParseCommandLineAfxdp(
SCInstance *suri,
const char *in_arg)
1327 SCLogInfo(
"Multiple af-xdp options without interface on each is useless");
1331 "has been specified");
1338 "host, make sure correct libraries are installed,"
1339 " see documentation for information.");
1344 static int ParseCommandLineDpdk(
SCInstance *suri,
const char *in_arg)
1350 SCLogInfo(
"Multiple dpdk options have no effect on Suricata");
1353 "has been specified");
1360 "host, make sure to pass --enable-dpdk to "
1361 "configure when building.");
1366 static int ParseCommandLinePcapLive(
SCInstance *suri,
const char *in_arg)
1368 #if defined(OS_WIN32) && !defined(HAVE_LIBWPCAP)
1370 FatalError(
"Live capture not available. To support live capture compile against Npcap.");
1374 if (in_arg != NULL) {
1377 if (strlen(in_arg) > 9 && strncmp(in_arg,
"DeviceNPF", 9) == 0) {
1378 snprintf(suri->
pcap_dev,
sizeof(suri->
pcap_dev),
"\\Device\\NPF%s", in_arg+9);
1384 if (strcmp(suri->
pcap_dev, in_arg) != 0) {
1386 }
else if (strlen(suri->
pcap_dev) > 0 && isdigit((
unsigned char)suri->
pcap_dev[0])) {
1387 SCLogError(
"failed to find a pcap device for IP %s", in_arg);
1401 "has been specified");
1411 static bool IsLogDirectoryWritable(
const char*
str)
1413 return access(
str, W_OK) == 0;
1422 static void AddCommandLineOptionValue(
1423 const char ***values,
const char *value,
const char *description)
1425 if (*values == NULL) {
1426 *values =
SCCalloc(2,
sizeof(
char *));
1427 if (*values == NULL) {
1428 FatalError(
"Failed to allocate memory for %s: %s", description, strerror(errno));
1430 (*values)[0] = value;
1432 for (
int i = 0;; i++) {
1433 if ((*values)[i] == NULL) {
1434 const char **new_values =
SCRealloc(*values, (i + 2) *
sizeof(
char *));
1435 if (new_values == NULL) {
1437 "Failed to allocate memory for %s: %s", description, strerror(errno));
1439 *values = new_values;
1440 (*values)[i] = value;
1441 (*values)[i + 1] = NULL;
1455 int dump_config = 0;
1456 int dump_features = 0;
1457 int list_app_layer_protocols = 0;
1458 int list_rule_protocols = 0;
1459 int list_app_layer_hooks = 0;
1460 int list_app_layer_frames = 0;
1461 int list_unittests = 0;
1462 int list_runmodes = 0;
1463 int list_keywords = 0;
1468 int is_firewall = 0;
1477 struct option long_opts[] = {
1479 {
"dump-config", 0, &dump_config, 1},
1480 {
"dump-features", 0, &dump_features, 1},
1481 {
"pfring", optional_argument, 0, 0},
1482 {
"pfring-int", required_argument, 0, 0},
1483 {
"pfring-cluster-id", required_argument, 0, 0},
1484 {
"pfring-cluster-type", required_argument, 0, 0},
1488 {
"af-packet", optional_argument, 0, 0},
1489 {
"af-xdp", optional_argument, 0, 0},
1490 {
"netmap", optional_argument, 0, 0},
1491 {
"pcap", optional_argument, 0, 0},
1492 {
"pcap-file-continuous", 0, 0, 0},
1493 {
"pcap-file-delete", 0, 0, 0},
1494 {
"pcap-file-recursive", 0, 0, 0},
1495 {
"pcap-file-buffer-size", required_argument, 0, 0},
1496 {
"simulate-ips", 0, 0 , 0},
1498 {
"strict-rule-keywords", optional_argument, 0, 0},
1500 {
"plugin", required_argument, 0, 0},
1501 {
"capture-plugin", required_argument, 0, 0},
1502 {
"capture-plugin-args", required_argument, 0, 0},
1504 #ifdef BUILD_UNIX_SOCKET
1505 {
"unix-socket", optional_argument, 0, 0},
1507 {
"pcap-buffer-size", required_argument, 0, 0},
1508 {
"unittest-filter", required_argument, 0,
'U'},
1509 {
"list-app-layer-protos", 0, &list_app_layer_protocols, 1},
1510 {
"list-rule-protos", 0, &list_rule_protocols, 1},
1511 {
"list-app-layer-hooks", 0, &list_app_layer_hooks, 1},
1512 {
"list-app-layer-frames", 0, &list_app_layer_frames, 1},
1513 {
"list-unittests", 0, &list_unittests, 1},
1514 {
"list-runmodes", 0, &list_runmodes, 1},
1515 {
"list-keywords", optional_argument, &list_keywords, 1},
1516 {
"runmode", required_argument, NULL, 0},
1519 {
"service-install", 0, 0, 0},
1520 {
"service-remove", 0, 0, 0},
1521 {
"service-change-params", 0, 0, 0},
1523 {
"pidfile", required_argument, 0, 0},
1524 {
"init-errors-fatal", 0, 0, 0},
1525 {
"disable-detection", 0, 0, 0},
1526 {
"disable-hashing", 0, 0, 0},
1527 {
"fatal-unittests", 0, 0, 0},
1529 {
"user", required_argument, 0, 0},
1530 {
"group", required_argument, 0, 0},
1531 {
"erf-in", required_argument, 0, 0},
1532 {
"dag", required_argument, 0, 0},
1533 {
"build-info", 0, &build_info, 1},
1534 {
"data-dir", required_argument, 0, 0},
1536 {
"windivert", required_argument, 0, 0},
1537 {
"windivert-forward", required_argument, 0, 0},
1539 #ifdef HAVE_LIBNET11
1540 {
"reject-dev", required_argument, 0, 0},
1542 {
"set", required_argument, 0, 0},
1544 {
"nflog", optional_argument, 0, 0},
1546 {
"simulate-packet-flow-memcap", required_argument, 0, 0},
1547 {
"simulate-applayer-error-at-offset-ts", required_argument, 0, 0},
1548 {
"simulate-applayer-error-at-offset-tc", required_argument, 0, 0},
1549 {
"simulate-packet-loss", required_argument, 0, 0},
1550 {
"simulate-packet-tcp-reassembly-memcap", required_argument, 0, 0},
1551 {
"simulate-packet-tcp-ssn-memcap", required_argument, 0, 0},
1552 {
"simulate-packet-defrag-memcap", required_argument, 0, 0},
1553 {
"simulate-alert-queue-realloc-failure", 0, 0, 0},
1557 {
"firewall", 0, &is_firewall, 1 },
1558 {
"firewall-rules-exclusive", required_argument, 0, 0},
1560 {
"include", required_argument, 0, 0},
1567 int option_index = 0;
1569 char short_opts[] =
"c:TDhi:l:q:d:r:us:S:U:VF:vk:";
1571 while ((opt = getopt_long(argc, argv, short_opts, long_opts, &option_index)) != -1) {
1574 if (strcmp((long_opts[option_index]).
name,
"help") == 0) {
1577 }
else if (strcmp((long_opts[option_index]).
name,
"pfring") == 0 ||
1578 strcmp((long_opts[option_index]).
name,
"pfring-int") == 0) {
1583 if (optarg != NULL) {
1586 ((strlen(optarg) <
sizeof(suri->
pcap_dev)) ?
1587 (strlen(optarg) + 1) :
sizeof(suri->
pcap_dev)));
1592 "to pass --enable-pfring to configure when building.");
1595 }
else if (strcmp((long_opts[option_index]).
name,
"pfring-cluster-id") == 0) {
1598 SCLogError(
"failed to set pfring.cluster-id");
1603 "to pass --enable-pfring to configure when building.");
1606 }
else if (strcmp((long_opts[option_index]).
name,
"pfring-cluster-type") == 0) {
1609 SCLogError(
"failed to set pfring.cluster-type");
1614 "to pass --enable-pfring to configure when building.");
1617 }
else if (strcmp((long_opts[option_index]).
name,
"plugin") == 0) {
1619 }
else if (strcmp((long_opts[option_index]).
name,
"capture-plugin") == 0) {
1622 }
else if (strcmp((long_opts[option_index]).
name,
"capture-plugin-args") == 0) {
1624 }
else if (strcmp((long_opts[option_index]).
name,
"dpdk") == 0) {
1625 if (ParseCommandLineDpdk(suri, optarg) !=
TM_ECODE_OK) {
1628 }
else if (strcmp((long_opts[option_index]).
name,
"af-packet") == 0) {
1629 if (ParseCommandLineAfpacket(suri, optarg) !=
TM_ECODE_OK) {
1632 }
else if (strcmp((long_opts[option_index]).
name,
"af-xdp") == 0) {
1633 if (ParseCommandLineAfxdp(suri, optarg) !=
TM_ECODE_OK) {
1636 }
else if (strcmp((long_opts[option_index]).
name,
"netmap") == 0) {
1644 ((strlen(optarg) <
sizeof(suri->
pcap_dev)) ?
1645 (strlen(optarg) + 1) :
sizeof(suri->
pcap_dev)));
1651 SCLogInfo(
"Multiple netmap option without interface on each is useless");
1656 "has been specified");
1657 PrintUsage(argv[0]);
1664 }
else if (strcmp((long_opts[option_index]).
name,
"nflog") == 0) {
1674 }
else if (strcmp((long_opts[option_index]).
name,
"pcap") == 0) {
1675 if (ParseCommandLinePcapLive(suri, optarg) !=
TM_ECODE_OK) {
1678 }
else if (strcmp((long_opts[option_index]).
name,
"simulate-ips") == 0) {
1681 }
else if (strcmp((long_opts[option_index]).
name,
"init-errors-fatal") == 0) {
1683 SCLogError(
"failed to set engine init-failure-fatal");
1686 #ifdef BUILD_UNIX_SOCKET
1687 }
else if (strcmp((long_opts[option_index]).
name ,
"unix-socket") == 0) {
1692 SCLogError(
"failed to set unix-command.filename");
1698 "has been specified");
1699 PrintUsage(argv[0]);
1704 else if(strcmp((long_opts[option_index]).
name,
"list-app-layer-protocols") == 0) {
1706 }
else if (strcmp((long_opts[option_index]).
name,
"list-app-layer-hooks") == 0) {
1708 }
else if (strcmp((long_opts[option_index]).
name,
"list-unittests") == 0) {
1712 SCLogError(
"unit tests not enabled. Make sure to pass --enable-unittests to "
1713 "configure when building");
1716 }
else if (strcmp((long_opts[option_index]).
name,
"list-runmodes") == 0) {
1719 }
else if (strcmp((long_opts[option_index]).
name,
"list-keywords") == 0) {
1721 if (strcmp(
"short", optarg) != 0) {
1725 }
else if (strcmp((long_opts[option_index]).
name,
"runmode") == 0) {
1727 }
else if (strcmp((long_opts[option_index]).
name,
"engine-analysis") == 0) {
1731 else if (strcmp((long_opts[option_index]).
name,
"service-install") == 0) {
1732 suri->
run_mode = RUNMODE_INSTALL_SERVICE;
1734 }
else if (strcmp((long_opts[option_index]).
name,
"service-remove") == 0) {
1735 suri->
run_mode = RUNMODE_REMOVE_SERVICE;
1737 }
else if (strcmp((long_opts[option_index]).
name,
"service-change-params") == 0) {
1738 suri->
run_mode = RUNMODE_CHANGE_SERVICE_PARAMS;
1742 else if (strcmp((long_opts[option_index]).
name,
"pidfile") == 0) {
1745 SCLogError(
"strdup failed: %s", strerror(errno));
1748 }
else if (strcmp((long_opts[option_index]).
name,
"disable-detection") == 0) {
1750 }
else if (strcmp((long_opts[option_index]).
name,
"disable-hashing") == 0) {
1754 }
else if (strcmp((long_opts[option_index]).
name,
"fatal-unittests") == 0) {
1758 SCLogError(
"unit tests not enabled. Make sure to pass --enable-unittests to "
1759 "configure when building");
1762 }
else if (strcmp((long_opts[option_index]).
name,
"user") == 0) {
1763 #ifndef HAVE_LIBCAP_NG
1765 " drop privileges, but it was not compiled into Suricata.");
1771 }
else if (strcmp((long_opts[option_index]).
name,
"group") == 0) {
1772 #ifndef HAVE_LIBCAP_NG
1774 " drop privileges, but it was not compiled into Suricata.");
1780 }
else if (strcmp((long_opts[option_index]).
name,
"erf-in") == 0) {
1786 }
else if (strcmp((long_opts[option_index]).
name,
"dag") == 0) {
1792 SCLogError(
"more than one run mode has been specified");
1793 PrintUsage(argv[0]);
1798 SCLogError(
"libdag and a DAG card are required"
1799 " to receive packets using --dag.");
1802 }
else if (strcmp((long_opts[option_index]).
name,
"napatech") == 0) {
1803 #ifdef HAVE_NAPATECH
1806 SCLogError(
"libntapi and a Napatech adapter are required"
1807 " to capture packets using --napatech.");
1810 }
else if (strcmp((long_opts[option_index]).
name,
"pcap-buffer-size") == 0) {
1811 #ifdef HAVE_PCAP_SET_BUFF
1813 SCLogError(
"failed to set pcap-buffer-size");
1818 " doesn't support setting buffer size.");
1820 }
else if (strcmp((long_opts[option_index]).
name,
"build-info") == 0) {
1823 }
else if (strcmp((long_opts[option_index]).
name,
"windivert-forward") == 0) {
1827 if (WinDivertRegisterQueue(
true, optarg) == -1) {
1831 if (WinDivertRegisterQueue(
true, optarg) == -1) {
1836 "has been specified");
1837 PrintUsage(argv[0]);
1841 else if(strcmp((long_opts[option_index]).
name,
"windivert") == 0) {
1844 if (WinDivertRegisterQueue(
false, optarg) == -1) {
1848 if (WinDivertRegisterQueue(
false, optarg) == -1) {
1853 "has been specified");
1854 PrintUsage(argv[0]);
1858 SCLogError(
"WinDivert not enabled. Make sure to pass --enable-windivert to "
1859 "configure when building.");
1862 }
else if(strcmp((long_opts[option_index]).
name,
"reject-dev") == 0) {
1863 #ifdef HAVE_LIBNET11
1865 extern char *g_reject_dev;
1866 extern uint16_t g_reject_dev_mtu;
1867 g_reject_dev = optarg;
1870 g_reject_dev_mtu = (uint16_t)mtu;
1873 SCLogError(
"Libnet 1.1 support not enabled. Compile Suricata with libnet support.");
1877 else if (strcmp((long_opts[option_index]).
name,
"set") == 0) {
1878 if (optarg != NULL) {
1880 char *val = strchr(optarg,
'=');
1882 FatalError(
"Invalid argument for --set, must be key=val.");
1885 FatalError(
"failed to set configuration value %s", optarg);
1889 else if (strcmp((long_opts[option_index]).
name,
"pcap-file-continuous") == 0) {
1891 SCLogError(
"Failed to set pcap-file.continuous");
1895 else if (strcmp((long_opts[option_index]).
name,
"pcap-file-delete") == 0) {
1897 SCLogError(
"Failed to set pcap-file.delete-when-done");
1901 else if (strcmp((long_opts[option_index]).
name,
"pcap-file-recursive") == 0) {
1903 SCLogError(
"failed to set pcap-file.recursive");
1906 }
else if (strcmp((long_opts[option_index]).
name,
"pcap-file-buffer-size") == 0) {
1908 SCLogError(
"failed to set pcap-file.buffer-size");
1911 }
else if (strcmp((long_opts[option_index]).
name,
"data-dir") == 0) {
1912 if (optarg == NULL) {
1913 SCLogError(
"no option argument (optarg) for -d");
1923 " supplied at the command-line (-d %s) doesn't "
1924 "exist. Shutting down the engine.",
1929 }
else if (strcmp((long_opts[option_index]).
name,
"strict-rule-keywords") == 0) {
1930 if (optarg == NULL) {
1936 FatalError(
"failed to duplicate 'strict' string");
1938 }
else if (strcmp((long_opts[option_index]).
name,
"include") == 0) {
1939 AddCommandLineOptionValue(
1941 }
else if (strcmp((long_opts[option_index]).
name,
"firewall-rules-exclusive") == 0) {
1943 SCLogError(
"can't have multiple --firewall-rules-exclusive options");
1951 (long_opts[option_index]).
name, optarg);
1962 SCLogError(
"failed to set engine init-failure-fatal");
1975 if (optarg == NULL) {
1976 SCLogError(
"no option argument (optarg) for -i");
1979 #ifdef HAVE_AF_PACKET
1980 if (ParseCommandLineAfpacket(suri, optarg) !=
TM_ECODE_OK) {
1985 #if defined HAVE_NETMAP
1991 "option%s %s available:"
1993 " NETMAP (--netmap=%s)"
1995 ". Use --pcap=%s to suppress this warning",
1996 i == 1 ?
"" :
"s", i == 1 ?
"is" :
"are"
2004 if (ParseCommandLinePcapLive(suri, optarg) !=
TM_ECODE_OK) {
2010 if (optarg == NULL) {
2011 SCLogError(
"no option argument (optarg) for -l");
2021 " supplied at the command-line (-l %s) doesn't "
2022 "exist. Shutting down the engine.",
2026 if (!IsLogDirectoryWritable(optarg)) {
2028 " supplied at the command-line (-l %s) is not "
2029 "writable. Shutting down the engine.",
2048 "has been specified");
2049 PrintUsage(argv[0]);
2053 SCLogError(
"NFQUEUE not enabled. Make sure to pass --enable-nfqueue to configure when "
2070 "has been specified");
2071 PrintUsage(argv[0]);
2075 SCLogError(
"IPFW not enabled. Make sure to pass --enable-ipfw to configure when "
2086 "has been specified");
2087 PrintUsage(argv[0]);
2092 SCLogError(
"pcap file '%s': %s", optarg, strerror(errno));
2096 SCLogError(
"ERROR: Failed to set pcap-file.file\n");
2103 SCLogError(
"can't have multiple -s options or mix -s and -S.");
2110 SCLogError(
"can't have multiple -S options or mix -s and -S.");
2123 PrintUsage(argv[0]);
2127 SCLogError(
"unit tests not enabled. Make sure to pass --enable-unittests to configure "
2144 if (optarg == NULL) {
2145 SCLogError(
"no option argument (optarg) for -F");
2149 SetBpfStringFromFile(optarg);
2152 static bool ignore_extra =
false;
2155 else if (!ignore_extra) {
2156 SCLogNotice(
"extraneous verbose option(s) ignored");
2157 ignore_extra =
true;
2161 if (optarg == NULL) {
2162 SCLogError(
"no option argument (optarg) for -k");
2165 if (!strcmp(
"all", optarg))
2167 else if (!strcmp(
"none", optarg))
2170 SCLogError(
"option '%s' invalid for -k", optarg);
2175 PrintUsage(argv[0]);
2185 SCLogError(
"can't use -s/-S or --firewall-rules-exclusive when detection is disabled");
2192 if (list_app_layer_protocols)
2194 if (list_rule_protocols)
2196 if (list_app_layer_hooks)
2198 if (list_app_layer_frames)
2216 ret = SetBpfString(optind, argv);
2224 int WindowsInitService(
int argc,
char **argv)
2226 if (SCRunningAsService()) {
2227 char path[MAX_PATH];
2229 strlcpy(path, argv[0], MAX_PATH);
2230 if ((
p = strrchr(path,
'\\'))) {
2233 if (!SetCurrentDirectory(path)) {
2234 SCLogError(
"Can't set current directory to: %s", path);
2237 SCLogInfo(
"Current directory is set to: %s", path);
2238 SCServiceInit(argc, argv);
2243 if (0 != WSAStartup(MAKEWORD(2, 2), &wsaData)) {
2244 SCLogError(
"Can't initialize Windows sockets: %d", WSAGetLastError());
2255 const char *pid_filename;
2258 SCLogInfo(
"Use pid file %s from config file.", pid_filename);
2265 SCLogError(
"strdup failed: %s", strerror(errno));
2284 SCLogError(
"Unable to create PID file, concurrent run of"
2285 " Suricata can occur.");
2286 SCLogError(
"PID file creation WILL be mandatory for daemon mode"
2287 " in future version");
2302 if (
SCConfGet(
"run-as.user", &
id) == 1) {
2306 if (
SCConfGet(
"run-as.group", &
id) == 1) {
2324 static int InitSignalHandler(
SCInstance *suri)
2327 #ifndef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
2332 if (
SCConfGetBool(
"logging.stacktrace-on-signal", &enabled) == 0) {
2337 SCLogInfo(
"Preparing unexpected signal handling");
2338 struct sigaction stacktrace_action;
2339 memset(&stacktrace_action, 0,
sizeof(stacktrace_action));
2340 stacktrace_action.sa_sigaction = SignalHandlerUnexpected;
2341 stacktrace_action.sa_flags = SA_SIGINFO;
2342 sigaction(SIGSEGV, &stacktrace_action, NULL);
2343 sigaction(SIGABRT, &stacktrace_action, NULL);
2366 #ifdef PROFILE_RULES
2367 SCProfilingRulesGlobalInit();
2374 #ifdef PROFILE_RULES
2428 SCPrintElapsedTime(start_time);
2502 PrintUsage(argv[0]);
2512 case RUNMODE_INSTALL_SERVICE:
2513 if (SCServiceInstall(argc, argv)) {
2516 SCLogInfo(
"Suricata service has been successfully installed.");
2518 case RUNMODE_REMOVE_SERVICE:
2519 if (SCServiceRemove()) {
2522 SCLogInfo(
"Suricata service has been successfully removed.");
2524 case RUNMODE_CHANGE_SERVICE_PARAMS:
2525 if (SCServiceChangeParams(argc, argv)) {
2528 SCLogInfo(
"Suricata service startup parameters has been successfully changed.");
2545 SCLogError(
"Please specify a runmode or capture option. "
2546 "Use --list-runmodes to see available runmodes.");
2561 static void SetupDelayedDetect(
SCInstance *suri)
2570 if (decnf != NULL) {
2572 if (strcmp(denode->
val,
"delayed-detect") == 0) {
2583 SCLogInfo(
"Packets will start being processed before signatures are active.");
2601 static int ConfigGetCaptureValue(
SCInstance *suri)
2605 intmax_t tmp_max_pending_packets;
2606 if (
SCConfGetInt(
"max-pending-packets", &tmp_max_pending_packets) != 1)
2608 if (tmp_max_pending_packets < 1 || tmp_max_pending_packets > 2147483648) {
2609 SCLogError(
"Maximum max-pending-packets setting is 2147483648 and must be greater than 0. "
2610 "Please check %s for errors",
2621 const char *temp_default_packet_size;
2622 if ((
SCConfGetNonNull(
"default-packet-size", &temp_default_packet_size)) != 1) {
2625 int strip_trailing_plus = 0;
2635 const int mtu = GetGlobalMTUWin32();
2649 strip_trailing_plus = 1;
2655 for (lthread = 0; lthread < nlive; lthread++) {
2658 (void)
strlcpy(dev, live_dev,
sizeof(dev));
2660 if (strip_trailing_plus) {
2661 size_t len = strlen(dev);
2663 (dev[
len-1] ==
'+' ||
2664 dev[
len-1] ==
'^' ||
2683 SCLogError(
"Error parsing max-pending-packets "
2684 "from conf file - %s. Killing engine",
2685 temp_default_packet_size);
2695 static void PostRunStartedDetectSetup(
const SCInstance *suri)
2709 SCLogNotice(
"Signature(s) loaded, Detect thread(s) activated.");
2721 SetupDelayedDetect(suri);
2724 int default_tenant = 0;
2726 (void)
SCConfGetBool(
"multi-detect.default", &default_tenant);
2729 "detection engine contexts failed.");
2739 FatalError(
"initializing detection engine failed.");
2755 static void PostConfLoadedSetupHostMode(
void)
2757 const char *hostmode = NULL;
2760 if (!strcmp(hostmode,
"router")) {
2762 }
else if (!strcmp(hostmode,
"bridge")) {
2764 }
else if (!strcmp(hostmode,
"sniffer-only")) {
2767 if (strcmp(hostmode,
"auto") != 0) {
2788 SCLogInfo(
"No 'host-mode': suricata is in IPS mode, using "
2789 "default setting 'router'");
2793 SCLogInfo(
"No 'host-mode': suricata is in IDS mode, using "
2794 "default setting 'sniffer-only'");
2806 FatalError(
"could not set USER mode logdir");
2812 FatalError(
"could not set USER mode datadir");
2824 int cnf_firewall_enabled = 0;
2825 if (
SCConfGetBool(
"firewall.enabled", &cnf_firewall_enabled) == 1) {
2826 if (cnf_firewall_enabled == 1) {
2830 FatalError(
"firewall mode enabled through commandline, but disabled in config");
2835 SCLogWarning(
"firewall mode is EXPERIMENTAL and subject to change");
2843 int disable_offloading;
2844 if (
SCConfGetBool(
"capture.disable-offloading", &disable_offloading) == 0)
2845 disable_offloading = 1;
2846 if (disable_offloading) {
2853 const char *cv = NULL;
2855 if (strcmp(cv,
"none") == 0) {
2857 }
else if (strcmp(cv,
"all") == 0) {
2864 SCConfSet(
"stream.checksum-validation",
"0");
2867 SCConfSet(
"stream.checksum-validation",
"1");
2876 #ifdef HAVE_PACKET_EBPF
2878 EBPFRegisterExtension();
2901 SCLogInfo(
"Setting engine mode to IDS mode by default");
2922 const char *custom_umask;
2925 if (
StringParseUint16(&mask, 8, (uint16_t)strlen(custom_umask), custom_umask) > 0) {
2926 umask((mode_t)mask);
2943 SCLogInfo(
"== Carrying out Engine Analysis ==");
2944 const char *temp = NULL;
2945 if (
SCConfGet(
"engine-analysis", &temp) == 0) {
2946 SCLogInfo(
"no engine-analysis parameter(s) defined in conf file. "
2947 "Please define/enable them in the conf to use this "
2966 "basic address vars test failed. Please check %s for errors", suri->
conf_filename);
2995 "supplied by %s (default-log-dir) doesn't exist. "
2996 "Shutting down the engine",
3000 if (!IsLogDirectoryWritable(suri->
log_dir)) {
3002 "supplied by %s (default-log-dir) is not writable. "
3003 "Shutting down the engine",
3021 PostConfLoadedSetupHostMode();
3088 return EXIT_FAILURE;
3111 SCInstanceInit(&
suricata, progname);
3129 if (
SCConfGetBool(
"vlan.use-for-tracking", &tracking) == 1 && !tracking) {
3133 SCLogDebug(
"vlan tracking is %s", tracking == 1 ?
"enabled" :
"disabled");
3134 if (
SCConfGetBool(
"livedev.use-for-tracking", &tracking) == 1 && !tracking) {
3138 if (
SCConfGetBool(
"decoder.recursion-level.use-for-tracking", &tracking) == 1 && !tracking) {
3154 SCLogInfo(
"Running suricata under test mode");
3188 SCLogNotice(
"Configuration provided was successfully loaded. Exiting.");
3231 int limit_nproc = 0;
3232 if (
SCConfGetBool(
"security.limit-noproc", &limit_nproc) == 0) {
3236 #if defined(SC_ADDRESS_SANITIZER)
3239 "\"security.limit-noproc\" (setrlimit()) not set when using address sanitizer");
3245 #if defined(HAVE_SYS_RESOURCE_H) && defined(RLIMIT_NPROC)
3248 SCLogWarning(
"setrlimit has no effect when running as root.");
3251 struct rlimit r = { 0, 0 };
3252 if (setrlimit(RLIMIT_NPROC, &r) != 0) {
3253 SCLogWarning(
"setrlimit failed to prevent process creation.");
3279 PostRunStartedDetectSetup(&
suricata);
@ RUNMODE_LIST_APP_LAYERS
enum SCRunModes SCRunMode
@ RUNMODE_ENGINE_ANALYSIS
void TmModuleUnixManagerRegister(void)
void StatsReleaseResources(void)
Releases the resources allotted by the Stats API.
#define DETECT_ENGINE_MPM_CACHE_OP_PRUNE
void TmModuleReceiveIPFWRegister(void)
Registration Function for RecieveIPFW.
void SuricataMainLoop(void)
int ExceptionSimulationCommandLineParser(const char *name, const char *arg)
char * firewall_rule_file
void AppLayerHtpNeedFileInspection(void)
Sets a flag that informs the HTP app layer that some module in the engine needs the http request file...
void TmThreadDisablePacketThreads(const uint16_t set, const uint16_t check, const uint8_t module_flags)
Disable all packet threads.
enum SCRunModes aux_run_mode
void IPPairInitConfig(bool quiet)
initialize the configuration
void SCLogInitLogModule(SCLogInitData *sc_lid)
Initializes the logging module.
void EngineModeSetIPS(const enum EngineHostMode mode)
void SCEnableDefaultSignalHandlers(void)
Enable default signal handlers.
int LiveDeviceListClean(void)
void DetectEngineDeReference(DetectEngineCtx **de_ctx)
struct timeval start_time
bool IsRunModeOffline(enum SCRunModes run_mode_to_check)
#define SC_ATOMIC_INIT(name)
wrapper for initializing an atomic variable.
SystemHugepageSnapshot * prerun_snap
void TmThreadContinueThreads(void)
Unpauses all threads present in tv_root.
enum DetectEngineType type
int SigLoadSignatures(DetectEngineCtx *de_ctx, char *sig_file, bool sig_file_exclusive)
Load signatures.
const char * firewall_rule_file_exclusive
#define SC_ATOMIC_SET(name, val)
Set the value for the atomic variable.
@ RUNMODE_LIST_APP_LAYER_FRAMES
SCConfNode * SCConfGetRootNode(void)
Get the root configuration node.
DetectEngineCtx * DetectEngineCtxInitStubForDD(void)
void LiveDevRegisterExtension(void)
void OutputTxShutdown(void)
void AppLayerHtpPrintStats(void)
void StatsSetupPostConfigPreOutput(void)
char * runmode_custom_mode
struct HtpBodyChunk_ * next
void TmModuleReceiveNFQRegister(void)
void DetectEngineMpmCacheService(uint32_t op_flags)
int LiveBuildDeviceList(const char *runmode)
void RunModeShutDown(void)
void SCProtoNameInit(void)
void SuricataPostInit(void)
void RunModeDispatch(int runmode, const char *custom_mode, const char *capture_plugin_name, const char *capture_plugin_args)
volatile sig_atomic_t sigint_count
SC_ATOMIC_DECLARE(unsigned int, engine_stage)
void TmModuleRunDeInit(void)
void TmThreadsUnsealThreads(void)
void RegisterFlowBypassInfo(void)
#define SCSetThreadName(n)
int SCConfYamlHandleInclude(SCConfNode *parent, const char *filename)
Include a file in the configuration.
void SCLogDeInitLogModule(void)
De-Initializes the logging module.
void TmModuleDecodeErfFileRegister(void)
Register the ERF file decoder module.
main detection engine ctx
int StringParseUint16(uint16_t *res, int base, size_t len, const char *str)
void DetectEngineReloadSetIdle(void)
void DatalinkTableDeinit(void)
int SCConfGet(const char *name, const char **vptr)
Retrieve the value of a configuration node.
DetectEngineCtx * DetectEngineGetCurrent(void)
int EngineModeIsUnknown(void)
void VarNameStoreInit(void)
void TmModuleFlowRecyclerRegister(void)
int SCConfNodeChildValueIsTrue(const SCConfNode *node, const char *key)
Test if a configuration node has a true value.
void DatalinkTableInit(void)
void Daemonize(void)
Daemonize the process.
void UtilSignalHandlerSetup(int sig, void(*handler)(int))
#define TAILQ_FOREACH(var, head, field)
void EngineModeSetFirewall(const enum EngineHostMode mode)
void TmModuleDecodeAFPRegister(void)
Registration Function for DecodeAFP.
void TmModuleDecodeWinDivertRegister(void)
void UtilCpuEnableSparcMisalignEmulation(void)
Handle memory access miss align on SPARC processors.
int DetectEngineAddToMaster(DetectEngineCtx *de_ctx)
int SCConfGetChildValueBool(const SCConfNode *base, const char *name, int *val)
void TmModuleStatsLoggerRegister(void)
void RegisterAllModules(void)
int DetectEngineMultiTenantSetup(const bool unix_socket)
setup multi-detect / multi-tenancy
void SupportFastPatternForSigMatchTypes(void)
Registers the keywords(SMs) that should be given fp support.
bool EngineHostModeIsSniffer(void)
TmEcode SCParseCommandLine(int argc, char **argv)
int CheckValidDaemonModes(int daemon, int mode)
Check for a valid combination daemon/mode.
void SCGetGroupID(const char *group_name, uint32_t *gid)
Function to get the group ID from the specified group name.
int SCConfGetBool(const char *name, int *val)
Retrieve a configuration value as a boolean.
enum EngineHostMode g_engine_host_mode
void TmThreadDisableReceiveThreads(void)
Disable all threads having the specified TMs.
void StatsInit(void)
Initializes the perf counter api. Things are hard coded currently. More work to be done when we imple...
void PreRunInit(const int runmode)
void MacSetRegisterFlowStorage(void)
void SuricataShutdown(void)
const char * conf_filename
int GetIfaceMTU(const char *dev)
output the link MTU
void GlobalsInitPreConfig(void)
void TmModuleReceiveNetmapRegister(void)
void PacketPoolPostRunmodes(void)
Set the max_pending_return_packets value.
void NFQInitConfig(bool quiet)
To initialize the NFQ global configuration data.
void TmModuleReceiveWinDivertRegister(void)
bool EngineModeIsFirewall(void)
void SCProfilingDestroy(void)
Free resources used by profiling.
void AFPPeersListClean(void)
Clean the global peers list.
void RunModeInitializeOutputs(void)
int DetectPortTestConfVars(void)
void SCThresholdConfGlobalInit(void)
void DecodeUnregisterCounters(void)
const char * capture_plugin_name
int SCConfYamlLoadFile(const char *filename)
Load configuration from a YAML file.
void HostBitInitCtx(void)
bool IsRunModeSystem(enum SCRunModes run_mode_to_check)
const char * capture_plugin_args
void ThresholdRegisterGlobalCounters(void)
void TmModuleLoggerRegister(void)
void PacketPoolInit(void)
int AppLayerDeSetup(void)
De initializes the app layer.
@ RUNMODE_LIST_APP_LAYER_HOOKS
size_t strlcpy(char *dst, const char *src, size_t siz)
void PcapTranslateIPToDevice(char *pcap_dev, size_t len)
void FlowDisableFlowRecyclerThread(void)
Used to disable flow recycler thread(s).
void SCRunmodeSet(SCRunMode run_mode)
Set the current run mode.
void TmModuleDecodePcapFileRegister(void)
void TmModuleBypassedFlowManagerRegister(void)
void IPPairShutdown(void)
shutdown the flow engine
void SCConfInit(void)
Initialize the configuration system.
void DetectParseFreeRegexes(void)
void SCConfDump(void)
Dump configuration to stdout.
void TmModuleDecodeNFLOGRegister(void)
int NFQParseAndRegisterQueues(const char *queues)
Parses and adds Netfilter queue(s).
void FlowInitConfig(bool quiet)
initialize the configuration
int AppLayerSetup(void)
Setup the app layer.
void FeatureTrackingRegister(void)
void TmModuleReceiveDPDKRegister(void)
void UnixManagerThreadSpawnNonRunmode(const bool unix_socket_enabled)
void RunModeInitializeThreadSettings(void)
void StreamTcpInitConfig(bool)
To initialize the stream global configuration data.
int GetIfaceMaxPacketSize(LiveDevice *ld)
output max packet size for a link
SCRunMode SCRunmodeGet(void)
Get the current run mode.
void TmModuleDecodeNetmapRegister(void)
Registration Function for DecodeNetmap.
void PreRunPostPrivsDropInit(const int runmode)
void SigTableCleanup(void)
int DetectEngineMoveToFreeList(DetectEngineCtx *de_ctx)
volatile sig_atomic_t sigterm_count
TmEcode TmThreadWaitOnThreadInit(void)
Used to check if all threads have finished their initialization. On finding an un-initialized thread,...
const char * SCLogLevel2Name(const SCLogLevel lvl)
void TmModuleVerdictNFQRegister(void)
void AppLayerRegisterGlobalCounters(void)
HACK to work around our broken unix manager (re)init loop.
int SCFinalizeRunMode(int argc)
void RunModeListRunmodes(void)
Lists all registered runmodes.
size_t strlcat(char *, const char *src, size_t siz)
void LiveSetOffloadDisable(void)
void StatsSetupPostConfigPostOutput(void)
void EngineModeSetIDS(void)
void TmModuleReceiveAFPRegister(void)
Registration Function for RecieveAFP.
int LiveBuildDeviceListCustom(const char *runmode, const char *itemname)
LiveDevice * LiveGetDevice(const char *name)
Get a pointer to the device at idx.
void UnixSocketKillSocketThread(void)
void TmModuleVerdictIPFWRegister(void)
Registration Function for VerdictIPFW.
int SCConfGetInt(const char *name, intmax_t *val)
Retrieve a configuration value as an integer.
bool g_stats_eps_per_app_proto_errors
void HttpRangeContainersInit(void)
struct timeval last_reload
void TmModuleVerdictWinDivertRegister(void)
void HostCleanup(void)
Cleanup the host engine.
void FlowDisableFlowManagerThread(void)
Used to disable flow manager thread(s).
int SCConfGetNonNull(const char *name, const char **vptr)
Retrieve the non-null value of a configuration node.
int UtilSignalUnblock(int signum)
int DetectEngineEnabled(void)
Check if detection is enabled.
void TmThreadClearThreadsFamily(int family)
#define THV_REQ_FLOW_LOOP
void FlowRateRegisterFlowStorage(void)
void TmModuleRunInit(void)
void HTPAtExitPrintStats(void)
Print the stats of the HTTP requests.
int UtilSignalBlock(int signum)
void SCProfilingPrefilterGlobalInit(void)
void ThresholdDestroy(void)
#define SCLogWarning(...)
Macro used to log WARNING messages.
int PostConfLoadedSetup(SCInstance *suri)
const char * GetProgramVersion(void)
get string with program version
void TmModuleReceivePcapFileRegister(void)
int32_t CoredumpLoadConfig(void)
Configures the core dump size.
int IPFWRegisterQueue(char *queue)
Add an IPFW divert.
int ListAppLayerHooks(const char *conf_filename)
int ListAppLayerProtocols(const char *conf_filename)
void DatasetsDestroy(void)
void UtilCpuPrintSummary(void)
Print a summary of CPUs detected (configured and online)
int profiling_packets_enabled
int SystemDNotifyReady(void)
void TmThreadKillThreads(void)
void OutputDeregisterAll(void)
Deregister all modules. Useful for a memory clean exit.
void PostConfLoadedDetectSetup(SCInstance *suri)
int EngineModeIsIDS(void)
TmModule tmm_modules[TMM_SIZE]
const char * SCConfigGetLogDirectory(void)
void OutputNotifyFileRotation(void)
Notifies all registered file rotation notification flags.
void VarNameStoreDestroy(void)
void TmModuleFlowWorkerRegister(void)
uint32_t max_pending_packets
const char ** additional_configs
#define DEFAULT_PID_FILENAME
volatile sig_atomic_t sighup_count
TmEcode ConfigSetDataDirectory(char *name)
void TmModuleDecodeErfDagRegister(void)
Register the ERF file decoder module.
#define SCDropMainThreadCaps(...)
void TmModuleDebugList(void)
void TmModuleDecodeNFQRegister(void)
void SCProtoNameRelease(void)
int RunmodeIsUnittests(void)
#define SCLogInfo(...)
Macro used to log INFORMATIONAL messages.
void TmModuleReceiveNFLOGRegister(void)
#define DEFAULT_PACKET_SIZE
#define WarnInvalidConfEntry(param_name, format, value)
Generic API that can be used by all to log an invalid conf entry.
#define TM_FLAG_RECEIVE_TM
void TmModuleReceiveErfFileRegister(void)
Register the ERF file receiver (reader) module.
int SCConfSetFromString(const char *input, int final)
Set a configuration parameter from a string.
int SCConfSetFinal(const char *name, const char *val)
Set a final configuration value.
#define SCRealloc(ptr, sz)
void TmModuleDecodeAFXDPRegister(void)
Registration Function for DecodeAFXDP.
uint32_t default_packet_size
void SigTableApplyStrictCommandLineOption(const char *str)
@ DETECT_ENGINE_TYPE_NORMAL
void TmThreadKillThreadsFamily(int family)
void FeatureTrackingRelease(void)
void TmqhCleanup(void)
Clean up registration time allocs.
void StreamTcpFreeConfig(bool quiet)
void DecodeGlobalConfig(void)
char * strict_rule_parsing_string
DetectEngineCtx * DetectEngineCtxInitStubForMT(void)
const char * LiveGetDeviceName(int number)
Get a pointer to the device name at idx.
void FlowShutdown(void)
shutdown the flow engine
void SCHInfoLoadFromConfig(void)
Load the host os policy information from the configuration.
void DetectEngineBumpVersion(void)
void TmModuleFlowManagerRegister(void)
int SCStartInternalRunMode(int argc, char **argv)
int SCPidfileTestRunning(const char *pid_filename)
Check the Suricata pid file (used at the startup)
void HostShutdown(void)
shutdown the flow engine
#define SCFstatFn(fd, statbuf)
void LiveSetOffloadWarn(void)
void ParseSizeDeinit(void)
void SCConfDeInit(void)
De-initializes the configuration system.
void RunModeRegisterRunModes(void)
Register all runmodes in the engine.
int ListRuleProtocols(const char *conf_filename)
void SCProfilingDump(void)
void TmModuleReceiveAFXDPRegister(void)
void EngineStop(void)
make sure threads can stop the engine by calling this function. Purpose: pcap file mode needs to be a...
int ParseSizeStringU32(const char *size, uint32_t *res)
bool EngineHostModeIsBridge(void)
void TmModuleReceiveErfDagRegister(void)
Register the ERF file receiver (reader) module.
void IPPairBitInitCtx(void)
TmEcode ConfigSetLogDirectory(const char *name)
void TmModuleDecodeIPFWRegister(void)
Registration Function for DecodeIPFW.
int ConfUnixSocketIsEnable(void)
#define TM_FLAG_PACKET_ALL
struct SCLogConfig_ SCLogConfig
Holds the config state used by the logging api.
#define DETECT_ENGINE_MPM_CACHE_OP_SAVE
volatile sig_atomic_t sigusr2_count
void SystemHugepageSnapshotDestroy(SystemHugepageSnapshot *s)
void TmModuleDecodePcapRegister(void)
Registration Function for DecodePcap.
TmEcode SCLoadYamlConfig(void)
TmEcode ConfigCheckDataDirectory(const char *data_dir)
SCConfNode * SCConfGetNode(const char *name)
Get a SCConfNode by name.
#define SCLogError(...)
Macro used to log ERROR messages.
int DetectEngineReloadStart(void)
void TopologyDestroy(void)
#define DEFAULT_CONF_FILE
#define SC_LOG_MAX_LOG_MSG_LEN
void AppLayerParserPostStreamSetup(void)
void TmModuleReceivePcapRegister(void)
Registration Function for ReceivePcap.
void SCGetUserID(const char *user_name, const char *group_name, uint32_t *uid, uint32_t *gid)
Function to get the user and group ID from the specified user name.
bool install_signal_handlers
void TmModuleRespondRejectRegister(void)
void CoredumpEnable(void)
Enable coredumps on systems where coredumps can and need to be enabled.
void RunUnittests(int list_unittests, const char *regex_arg)
TmEcode ConfigCheckLogDirectoryExists(const char *log_dir)
int SCConfSet(const char *name, const char *val)
Set a configuration value.
void PacketAlertTagInit(void)
int RunModeEngineIsIPS(int capture_mode, const char *runmode, const char *capture_plugin_name)
DetectEngineCtx * DetectEngineCtxInit(void)
void SCOnLoggingReady(void)
Invokes all registered logging ready callbacks.
void TmModuleDecodeLibRegister(void)
register a "Decode" module for suricata as a library.
int EngineModeIsIPS(void)
int ListAppLayerFrames(const char *conf_filename)
void SCProfilingKeywordsGlobalInit(void)
void EngineDone(void)
Used to indicate that the current task is done.
bool firewall_rule_file_exclusive
const char * GetDocURL(void)
void PostRunDeinit(const int runmode, struct timeval *start_time)
clean up / shutdown code for packet modes
void HostInitConfig(bool quiet)
initialize the configuration
TmEcode TmThreadWaitOnThreadRunning(void)
Waits for all threads to be in a running state.
void HttpRangeContainersDestroy(void)
void SCLogLoadConfig(int daemon, int verbose, uint32_t userid, uint32_t groupid)
int DetectEngineReload(const SCInstance *suri)
Reload the detection engine.
#define DEFAULT_MAX_PENDING_PACKETS
void DetectEngineClearMaster(void)
void SetMasterExceptionPolicy(void)
void TmThreadCheckThreadState(void)
Used to check the thread for certain conditions of failure.
void OutputFilestoreRegisterGlobalCounters(void)
int InitGlobal(void)
Global initialization common to all runmodes.
int LiveGetDeviceCount(void)
Get the number of registered devices.
SystemHugepageSnapshot * SystemHugepageSnapshotCreate(void)
The function creates a snapshot of the system's hugepage usage per NUMA node and per hugepage size....
void SCProfilingSghsGlobalInit(void)
@ RUNMODE_LIST_RULE_PROTOS
int SCPidfileCreate(const char *pidfile)
Write a pid file (used at the startup) This commonly needed by the init scripts.
int LiveRegisterDeviceName(const char *dev)
Add a device for monitoring.
#define SCStatFn(pathname, statbuf)
void LiveDeviceFinalize(void)
void TmModuleDecodeDPDKRegister(void)
Registration Function for DecodeDPDK.
void PacketPoolDestroy(void)
void HTPFreeConfig(void)
Clears the HTTP server configuration memory used by HTP library.
void LandlockSandboxing(SCInstance *suri)
int ListKeywords(const char *keyword_info)
#define SCLogNotice(...)
Macro used to log NOTICE messages.
void SuricataPreInit(const char *progname)
const char ** additional_plugins
void DPDKCleanupEAL(void)
@ RUNMODE_PRINT_BUILDINFO
void SCPidfileRemove(const char *pid_filename)
Remove the pid file (used at the startup)
void NFQContextsClean(void)
Clean global contexts. Must be called on exit.
void SystemHugepageEvaluateHugepages(SystemHugepageSnapshot *pre_s, SystemHugepageSnapshot *post_s)
The function compares two hugepage snapshots and prints out recommendations for hugepage configuratio...
#define DEBUG_VALIDATE_BUG_ON(exp)
void SCProfilingInit(void)
Initialize profiling.
void GlobalsDestroy(void)
@ ENGINE_HOST_IS_SNIFFER_ONLY
int DetectEngineReloadIsStart(void)
int SCStorageFinalize(void)
volatile uint8_t suricata_ctl_flags
#define TM_FLAG_FLOWWORKER_TM
void TagDestroyCtx(void)
Destroy tag context hash tables.
int DetectAddressTestConfVars(void)
void FlowWorkToDoCleanup(void)
Clean up all the flows that have unprocessed segments and have some work to do in the detection engin...
void MpmHSGlobalCleanup(void)
void SCPluginsLoad(const char *capture_plugin_name, const char *capture_plugin_args, const char **additional_plugins)
void TmqResetQueues(void)