suricata
suricata.c
Go to the documentation of this file.
1 /* Copyright (C) 2007-2025 Open Information Security Foundation
2  *
3  * You can copy, redistribute or modify this Program under the terms of
4  * the GNU General Public License version 2 as published by the Free
5  * Software Foundation.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * version 2 along with this program; if not, write to the Free Software
14  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
15  * 02110-1301, USA.
16  */
17 
18 /**
19  * \file
20  *
21  * \author Victor Julien <victor@inliniac.net>
22  */
23 
24 #include "suricata-common.h"
25 
26 #if HAVE_GETOPT_H
27 #include <getopt.h>
28 #endif
29 
30 #if HAVE_SIGNAL_H
31 #include <signal.h>
32 #endif
33 #ifndef OS_WIN32
34 #ifdef HAVE_SYS_RESOURCE_H
35 // setrlimit
36 #include <sys/resource.h>
37 #endif
38 #endif
39 
40 #include "suricata.h"
41 
42 #include "conf.h"
43 #include "conf-yaml-loader.h"
44 
45 #include "decode.h"
46 #include "defrag.h"
47 #include "flow.h"
48 #include "stream-tcp.h"
49 #include "ippair.h"
50 
51 #include "detect.h"
52 #include "detect-parse.h"
53 #include "detect-engine.h"
54 #include "detect-engine-address.h"
55 #include "detect-engine-alert.h"
56 #include "detect-engine-port.h"
57 #include "detect-engine-tag.h"
59 #include "detect-fast-pattern.h"
60 
61 #include "datasets.h"
62 
63 #include "feature.h"
64 
65 #include "flow-bypass.h"
66 #include "flow-manager.h"
67 #include "flow-timeout.h"
68 #include "flow-worker.h"
69 
70 #include "flow-bit.h"
71 #include "host-bit.h"
72 #include "ippair-bit.h"
73 
74 #include "app-layer.h"
75 #include "app-layer-parser.h"
76 #include "app-layer-htp.h"
77 #include "app-layer-htp-range.h"
78 
79 #include "output.h"
80 #include "output-filestore.h"
81 
82 #include "respond-reject.h"
83 
84 #include "runmode-af-packet.h"
85 #include "runmode-af-xdp.h"
86 #include "runmode-netmap.h"
87 #include "runmode-unittests.h"
88 
89 #include "source-nfq.h"
90 #include "source-nfq-prototypes.h"
91 #include "source-nflog.h"
92 #include "source-ipfw.h"
93 #include "source-lib.h"
94 #include "source-pcap.h"
95 #include "source-pcap-file.h"
97 #include "source-erf-file.h"
98 #include "source-erf-dag.h"
99 #include "source-af-packet.h"
100 #include "source-af-xdp.h"
101 #include "source-netmap.h"
102 #include "source-dpdk.h"
103 #include "source-windivert.h"
105 
106 #include "unix-manager.h"
107 
109 #include "util-threshold-config.h"
110 #include "util-reference-config.h"
111 
112 #include "tmqh-packetpool.h"
113 #include "tm-queuehandlers.h"
114 
115 #include "util-affinity.h"
116 #include "util-byte.h"
117 #include "util-conf.h"
118 #include "util-coredump-config.h"
119 #include "util-cpu.h"
120 #include "util-daemon.h"
121 #include "util-device-private.h"
122 #include "util-dpdk.h"
123 #include "util-ebpf.h"
124 #include "util-exception-policy.h"
125 #include "util-host-os-info.h"
126 #include "util-hugepages.h"
127 #include "util-ioctl.h"
128 #include "util-landlock.h"
129 #include "util-macset.h"
130 #include "util-flow-rate.h"
131 #include "util-misc.h"
132 #include "util-mpm-hs.h"
133 #include "util-path.h"
134 #include "util-pidfile.h"
135 #include "util-plugin.h"
136 #include "util-privs.h"
137 #include "util-profiling.h"
138 #include "util-proto-name.h"
139 #include "util-running-modes.h"
140 #include "util-signal.h"
141 #include "util-time.h"
142 #include "util-validate.h"
143 #include "util-var-name.h"
144 #ifdef SYSTEMD_NOTIFY
145 #include "util-systemd.h"
146 #endif
147 
148 #ifdef WINDIVERT
149 #include "decode-sll.h"
150 #include "win32-syscall.h"
151 #endif
152 
153 /*
154  * we put this here, because we only use it here in main.
155  */
156 volatile sig_atomic_t sigint_count = 0;
157 volatile sig_atomic_t sighup_count = 0;
158 volatile sig_atomic_t sigterm_count = 0;
159 volatile sig_atomic_t sigusr2_count = 0;
160 
161 /*
162  * Flag to indicate if the engine is at the initialization
163  * or already processing packets. 3 stages: SURICATA_INIT,
164  * SURICATA_RUNTIME and SURICATA_FINALIZE
165  */
166 SC_ATOMIC_DECLARE(unsigned int, engine_stage);
167 
168 /* Max packets processed simultaneously per thread. */
169 #define DEFAULT_MAX_PENDING_PACKETS 1024
170 
171 /* Maximum number of v's supported */
172 #define VERBOSE_MAX (SC_LOG_DEBUG - SC_LOG_NOTICE)
173 
174 /** suricata engine control flags */
175 volatile uint8_t suricata_ctl_flags = 0;
176 
177 /** Engine mode: inline (ENGINE_MODE_IPS) or just
178  * detection mode (ENGINE_MODE_IDS by default) */
179 static enum EngineMode g_engine_mode = ENGINE_MODE_UNKNOWN;
180 
181 /** Host mode: set if box is sniffing only
182  * or is a router */
184 
185 /** Maximum packets to simultaneously process. */
187 
188 /** global indicating if detection is enabled */
190 
191 /** set caps or not */
192 bool sc_set_caps = false;
193 
194 bool g_system = false;
195 
196 /** disable randomness to get reproducible results across runs */
197 #ifndef AFLFUZZ_NO_RANDOM
199 #else
200 int g_disable_randomness = 1;
201 #endif
202 
203 /** determine (without branching) if we include the vlan_ids when hashing or
204  * comparing flows */
205 uint16_t g_vlan_mask = 0xffff;
206 
207 /** determine (without branching) if we include the livedev ids when hashing or
208  * comparing flows */
209 uint16_t g_livedev_mask = 0xffff;
210 
211 /** determine (without branching) if we include the recursion levels when hashing or
212  * comparing flows */
213 uint8_t g_recurlvl_mask = 0xff;
214 
215 /* flag to disable hashing almost globally, to be similar to disabling nss
216  * support */
217 bool g_disable_hashing = false;
218 
219 /* snapshot of the system's hugepages before system intitialization. */
221 
222 /** add per-proto app-layer error counters for exception policies stats? disabled by default */
224 
225 /** Suricata instance */
227 
228 int SuriHasSigFile(void)
229 {
230  return (suricata.sig_file != NULL);
231 }
232 
234 {
235  return (g_engine_mode == ENGINE_MODE_UNKNOWN);
236 }
237 
239 {
240  DEBUG_VALIDATE_BUG_ON(g_engine_mode == ENGINE_MODE_UNKNOWN);
241  return (g_engine_mode == ENGINE_MODE_FIREWALL);
242 }
243 
244 /* this returns true for firewall mode as well */
246 {
247  DEBUG_VALIDATE_BUG_ON(g_engine_mode == ENGINE_MODE_UNKNOWN);
248  return (g_engine_mode >= ENGINE_MODE_IPS);
249 }
250 
252 {
253  DEBUG_VALIDATE_BUG_ON(g_engine_mode == ENGINE_MODE_UNKNOWN);
254  return (g_engine_mode == ENGINE_MODE_IDS);
255 }
256 
258 {
259  g_engine_mode = ENGINE_MODE_FIREWALL;
260 }
261 
263 {
264  g_engine_mode = ENGINE_MODE_IPS;
265 }
266 
268 {
269  g_engine_mode = ENGINE_MODE_IDS;
270 }
271 
272 #ifdef UNITTESTS
274 {
276  return 1;
277 
278  return 0;
279 }
280 #endif
281 
283 {
284  return suricata.run_mode;
285 }
286 
287 void SCRunmodeSet(SCRunMode run_mode)
288 {
289  suricata.run_mode = run_mode;
290 }
291 
293 {
295 }
296 
297 /** signal handlers
298  *
299  * WARNING: don't use the SCLog* API in the handlers. The API is complex
300  * with memory allocation possibly happening, calls to syslog, json message
301  * construction, etc.
302  */
303 
304 #ifndef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
305 static void SignalHandlerSigint(/*@unused@*/ int sig)
306 {
307  sigint_count = 1;
308 }
309 static void SignalHandlerSigterm(/*@unused@*/ int sig)
310 {
311  sigterm_count = 1;
312 }
313 #ifndef OS_WIN32
314 #if HAVE_LIBUNWIND
315 #define UNW_LOCAL_ONLY
316 #include <libunwind.h>
317 static void SignalHandlerUnexpected(int sig_num, siginfo_t *info, void *context)
318 {
319  char msg[SC_LOG_MAX_LOG_MSG_LEN];
320  unw_cursor_t cursor;
321  /* Restore defaults for signals to avoid loops */
322  signal(SIGABRT, SIG_DFL);
323  signal(SIGSEGV, SIG_DFL);
324  int r;
325  if ((r = unw_init_local(&cursor, (unw_context_t *)(context)) != 0)) {
326  SCLogError("unable to obtain stack trace: unw_init_local: %s", unw_strerror(r));
327  goto terminate;
328  }
329 
330  char *temp = msg;
331  int cw = snprintf(temp, SC_LOG_MAX_LOG_MSG_LEN - (temp - msg), "stacktrace:sig %d:", sig_num);
332  temp += cw;
333  r = 1;
334  while (r > 0) {
335  if (unw_is_signal_frame(&cursor) == 0) {
336  unw_word_t off;
337  char name[256];
338  if (unw_get_proc_name(&cursor, name, sizeof(name), &off) == UNW_ENOMEM) {
339  cw = snprintf(temp, SC_LOG_MAX_LOG_MSG_LEN - (temp - msg), "[unknown]:");
340  } else {
341  cw = snprintf(
342  temp, SC_LOG_MAX_LOG_MSG_LEN - (temp - msg), "%s+0x%08" PRIx64, name, off);
343  }
344  temp += cw;
345  }
346 
347  r = unw_step(&cursor);
348  if (r > 0) {
349  cw = snprintf(temp, SC_LOG_MAX_LOG_MSG_LEN - (temp - msg), ";");
350  temp += cw;
351  }
352  }
353  SCLogError("%s", msg);
354 
355 terminate:
356  // Propagate signal to watchers, if any
357  kill(getpid(), sig_num);
358 }
359 #undef UNW_LOCAL_ONLY
360 #endif /* HAVE_LIBUNWIND */
361 #endif /* !OS_WIN32 */
362 #endif
363 
364 #ifndef OS_WIN32
365 /**
366  * SIGUSR2 handler. Just set sigusr2_count. The main loop will act on
367  * it.
368  */
369 static void SignalHandlerSigusr2(int sig)
370 {
371  if (sigusr2_count < 2)
372  sigusr2_count++;
373 }
374 
375 /**
376  * SIGHUP handler. Just set sighup_count. The main loop will act on
377  * it.
378  */
379 static void SignalHandlerSigHup(/*@unused@*/ int sig)
380 {
381  sighup_count = 1;
382 }
383 #endif
384 
386 {
387  TimeInit();
390  SCProtoNameInit();
391 }
392 
393 void GlobalsDestroy(void)
394 {
395  SCInstance *suri = &suricata;
397  HostShutdown();
398  HTPFreeConfig();
400 
402 
403  /* TODO this can do into it's own func */
405  if (de_ctx) {
408  }
410 
411  AppLayerDeSetup();
412  DatasetsSave();
413  DatasetsDestroy();
415  TagDestroyCtx();
416 
421  TimeDeinit();
422  SigTableCleanup();
423  TmqhCleanup();
425  ParseSizeDeinit();
427 
428 #ifdef HAVE_DPDK
429  DPDKCleanupEAL();
430 #endif
431 
432 #ifdef HAVE_AF_PACKET
434 #endif
435 
436 #ifdef NFQ
438 #endif
439 
440 #ifdef BUILD_HYPERSCAN
442 #endif
443 
444  SCConfDeInit();
445 
447 
449  SCFree(suri->pid_filename);
450  suri->pid_filename = NULL;
451 
454 }
455 
456 /**
457  * \brief Used to send OS specific notification of running threads
458  *
459  * \retval TmEcode TM_ECODE_OK on success; TM_ECODE_FAILED on failure.
460  */
461 static void OnNotifyRunning(void)
462 {
463 #ifdef SYSTEMD_NOTIFY
464  if (SystemDNotifyReady() < 0) {
465  SCLogWarning("failed to notify systemd");
466  }
467 #endif
468 }
469 
470 /** \brief make sure threads can stop the engine by calling this
471  * function. Purpose: pcap file mode needs to be able to tell the
472  * engine the file eof is reached. */
473 void EngineStop(void)
474 {
476 }
477 
478 /**
479  * \brief Used to indicate that the current task is done.
480  *
481  * This is mainly used by pcap-file to tell it has finished
482  * to treat a pcap files when running in unix-socket mode.
483  */
484 void EngineDone(void)
485 {
487 }
488 
489 static int SetBpfString(int argc, char *argv[])
490 {
491  char *bpf_filter = NULL;
492  uint32_t bpf_len = 0;
493  int tmpindex = 0;
494 
495  /* attempt to parse remaining args as bpf filter */
496  tmpindex = argc;
497  while(argv[tmpindex] != NULL) {
498  bpf_len+=strlen(argv[tmpindex]) + 1;
499  tmpindex++;
500  }
501 
502  if (bpf_len == 0)
503  return TM_ECODE_OK;
504 
505  bpf_filter = SCCalloc(1, bpf_len);
506  if (unlikely(bpf_filter == NULL))
507  return TM_ECODE_FAILED;
508 
509  tmpindex = optind;
510  while(argv[tmpindex] != NULL) {
511  strlcat(bpf_filter, argv[tmpindex],bpf_len);
512  if(argv[tmpindex + 1] != NULL) {
513  strlcat(bpf_filter," ", bpf_len);
514  }
515  tmpindex++;
516  }
517 
518  if(strlen(bpf_filter) > 0) {
519  if (SCConfSetFinal("bpf-filter", bpf_filter) != 1) {
520  SCLogError("Failed to set bpf filter.");
521  SCFree(bpf_filter);
522  return TM_ECODE_FAILED;
523  }
524  }
525  SCFree(bpf_filter);
526 
527  return TM_ECODE_OK;
528 }
529 
530 static void SetBpfStringFromFile(char *filename)
531 {
532  char *bpf_filter = NULL;
533  char *bpf_comment_tmp = NULL;
534  char *bpf_comment_start = NULL;
535  size_t bpf_len = 0;
536  SCStat st;
537  FILE *fp = NULL;
538  size_t nm = 0;
539 
540  fp = fopen(filename, "r");
541  if (fp == NULL) {
542  SCLogError("Failed to open file %s", filename);
543  exit(EXIT_FAILURE);
544  }
545 
546  if (SCFstatFn(fileno(fp), &st) != 0) {
547  SCLogError("Failed to stat file %s", filename);
548  exit(EXIT_FAILURE);
549  }
550  // st.st_size is signed on Windows
551  bpf_len = ((size_t)(st.st_size)) + 1;
552 
553  bpf_filter = SCCalloc(1, bpf_len);
554  if (unlikely(bpf_filter == NULL)) {
555  SCLogError("Failed to allocate buffer for bpf filter in file %s", filename);
556  exit(EXIT_FAILURE);
557  }
558 
559  nm = fread(bpf_filter, 1, bpf_len - 1, fp);
560  if ((ferror(fp) != 0) || (nm != (bpf_len - 1))) {
561  SCLogError("Failed to read complete BPF file %s", filename);
562  SCFree(bpf_filter);
563  fclose(fp);
564  exit(EXIT_FAILURE);
565  }
566  fclose(fp);
567  bpf_filter[nm] = '\0';
568 
569  if(strlen(bpf_filter) > 0) {
570  /*replace comments with space*/
571  bpf_comment_start = bpf_filter;
572  while((bpf_comment_tmp = strchr(bpf_comment_start, '#')) != NULL) {
573  while((*bpf_comment_tmp !='\0') &&
574  (*bpf_comment_tmp != '\r') && (*bpf_comment_tmp != '\n'))
575  {
576  *bpf_comment_tmp++ = ' ';
577  }
578  bpf_comment_start = bpf_comment_tmp;
579  }
580  /*remove remaining '\r' and '\n' */
581  while((bpf_comment_tmp = strchr(bpf_filter, '\r')) != NULL) {
582  *bpf_comment_tmp = ' ';
583  }
584  while((bpf_comment_tmp = strchr(bpf_filter, '\n')) != NULL) {
585  *bpf_comment_tmp = ' ';
586  }
587  /* cut trailing spaces */
588  while (strlen(bpf_filter) > 0 &&
589  bpf_filter[strlen(bpf_filter)-1] == ' ')
590  {
591  bpf_filter[strlen(bpf_filter)-1] = '\0';
592  }
593  if (strlen(bpf_filter) > 0) {
594  if (SCConfSetFinal("bpf-filter", bpf_filter) != 1) {
595  SCFree(bpf_filter);
596  FatalError("failed to set bpf filter");
597  }
598  }
599  }
600  SCFree(bpf_filter);
601 }
602 
603 static void PrintUsage(const char *progname)
604 {
605 #ifdef REVISION
606  printf("%s %s (%s)\n", PROG_NAME, PROG_VER, xstr(REVISION));
607 #else
608  printf("%s %s\n", PROG_NAME, PROG_VER);
609 #endif
610  printf("USAGE: %s [OPTIONS] [BPF FILTER]\n\n", progname);
611 
612  printf("\n General:\n");
613  printf("\t-v : be more verbose (use multiple times to "
614  "increase verbosity)\n");
615  printf("\t-c <path> : path to configuration file\n");
616  printf("\t-l <dir> : default log directory\n");
617  printf("\t--include <path> : additional configuration file\n");
618  printf("\t--set name=value : set a configuration value\n");
619  printf("\t--pidfile <file> : write pid to this file\n");
620  printf("\t-T : test configuration file (use with -c)\n");
621  printf("\t--init-errors-fatal : enable fatal failure on signature init "
622  "error\n");
623 #ifndef OS_WIN32
624  printf("\t-D : run as daemon\n");
625 #else
626  printf("\t--service-install : install as service\n");
627  printf("\t--service-remove : remove service\n");
628  printf("\t--service-change-params : change service startup parameters\n");
629 #endif /* OS_WIN32 */
630 #ifdef HAVE_LIBCAP_NG
631  printf("\t--user <user> : run suricata as this user after init\n");
632  printf("\t--group <group> : run suricata as this group after init\n");
633 #endif /* HAVE_LIBCAP_NG */
634 #ifdef BUILD_UNIX_SOCKET
635  printf("\t--unix-socket[=<file>] : use unix socket to control suricata work\n");
636 #endif
637  printf("\t--runmode <runmode_id> : specific runmode modification the engine should run. The argument\n"
638  "\t supplied should be the id for the runmode obtained by running\n"
639  "\t --list-runmodes\n");
640 
641  printf("\n Capture and IPS:\n");
642 
643  printf("\t-F <bpf filter file> : bpf filter file\n");
644  printf("\t-k [all|none] : force checksum check (all) or disabled it "
645  "(none)\n");
646  printf("\t-i <dev or ip> : run in pcap live mode\n");
647  printf("\t--pcap[=<dev>] : run in pcap mode, no value select interfaces "
648  "from suricata.yaml\n");
649 #ifdef HAVE_PCAP_SET_BUFF
650  printf("\t--pcap-buffer-size : size of the pcap buffer value from 0 - %i\n",INT_MAX);
651 #endif /* HAVE_SET_PCAP_BUFF */
652 #ifdef NFQ
653  printf("\t-q <qid[:qid]> : run in inline nfqueue mode (use colon to "
654  "specify a range of queues)\n");
655 #endif /* NFQ */
656 #ifdef IPFW
657  printf("\t-d <divert port> : run in inline ipfw divert mode\n");
658 #endif /* IPFW */
659 #ifdef HAVE_AF_PACKET
660  printf("\t--af-packet[=<dev>] : run in af-packet mode, no value select interfaces from suricata.yaml\n");
661 #endif
662 #ifdef HAVE_AF_XDP
663  printf("\t--af-xdp[=<dev>] : run in af-xdp mode, no value select "
664  "interfaces from suricata.yaml\n");
665 #endif
666 #ifdef HAVE_NETMAP
667  printf("\t--netmap[=<dev>] : run in netmap mode, no value select interfaces from suricata.yaml\n");
668 #endif
669 #ifdef HAVE_PFRING
670  printf("\t--pfring[=<dev>] : run in pfring mode, use interfaces from suricata.yaml\n");
671  printf("\t--pfring-int <dev> : run in pfring mode, use interface <dev>\n");
672  printf("\t--pfring-cluster-id <id> : pfring cluster id \n");
673  printf("\t--pfring-cluster-type <type> : pfring cluster type for PF_RING 4.1.2 and later cluster_round_robin|cluster_flow\n");
674 #endif /* HAVE_PFRING */
675 #ifdef HAVE_DPDK
676  printf("\t--dpdk : run in dpdk mode, uses interfaces from "
677  "suricata.yaml\n");
678 #endif
679 #ifdef HAVE_DAG
680  printf("\t--dag <dagX:Y> : process ERF records from DAG interface X, stream Y\n");
681 #endif
682 #ifdef WINDIVERT
683  printf("\t--windivert <filter> : run in inline WinDivert mode\n");
684  printf("\t--windivert-forward <filter> : run in inline WinDivert mode, as a gateway\n");
685 #endif
686 #ifdef HAVE_LIBNET11
687  printf("\t--reject-dev <dev> : send reject packets from this interface\n");
688 #endif
689 
690  printf("\n Capture Files:\n");
691  printf("\t-r <path> : run in pcap file/offline mode\n");
692  printf("\t--pcap-file-continuous : when running in pcap mode with a directory, "
693  "continue checking directory for pcaps until interrupted\n");
694  printf("\t--pcap-file-delete : when running in replay mode (-r with "
695  "directory or file), will delete pcap files that have been processed when done\n");
696  printf("\t--pcap-file-recursive : will descend into subdirectories when running "
697  "in replay mode (-r)\n");
698  printf("\t--pcap-file-buffer-size : set read buffer size (setvbuf)\n");
699  printf("\t--erf-in <path> : process an ERF file\n");
700 
701  printf("\n Detection:\n");
702  printf("\t-s <path> : path to signature file loaded in addition to "
703  "suricata.yaml settings (optional)\n");
704  printf("\t-S <path> : path to signature file loaded exclusively "
705  "(optional)\n");
706  printf("\t--disable-detection : disable detection engine\n");
707  printf("\t--engine-analysis : print reports on analysis of different "
708  "sections in the engine and exit.\n"
709  "\t Please have a look at the conf parameter "
710  "engine-analysis on what reports\n"
711  "\t can be printed\n");
712 
713  printf("\n Firewall:\n");
714  printf("\t--firewall : enable firewall mode\n");
715  printf("\t--firewall-rules-exclusive=<path> : path to firewall rule file loaded "
716  "exclusively\n");
717 
718  printf("\n Info:\n");
719  printf("\t-V : display Suricata version\n");
720  printf("\t--list-keywords[=all|csv|<kword>] : list keywords implemented by the engine\n");
721  printf("\t--list-runmodes : list supported runmodes\n");
722  printf("\t--list-app-layer-protos : list supported app layer protocols\n");
723  printf("\t--list-rule-protos : list supported rule protocols\n");
724  printf("\t--list-app-layer-hooks : list supported app layer hooks for use in "
725  "rules\n");
726  printf("\t--dump-config : show the running configuration\n");
727  printf("\t--dump-features : display provided features\n");
728  printf("\t--build-info : display build information\n");
729 
730  printf("\n Testing:\n");
731  printf("\t--simulate-ips : force engine into IPS mode. Useful for QA\n");
732 #ifdef UNITTESTS
733  printf("\t-u : run the unittests and exit\n");
734  printf("\t-U=REGEX, --unittest-filter=REGEX : filter unittests with a pcre compatible "
735  "regex\n");
736  printf("\t--list-unittests : list unit tests\n");
737  printf("\t--fatal-unittests : enable fatal failure on unittest error\n");
738  printf("\t--unittests-coverage : display unittest coverage report\n");
739 #endif /* UNITTESTS */
740  printf("\n");
741  printf("\nTo run " PROG_NAME " with default configuration on "
742  "interface eth0 with signature file \"signatures.rules\", run the "
743  "command as:\n\n%s -c suricata.yaml -s signatures.rules -i eth0 \n\n",
744  progname);
745 }
746 
747 static void PrintBuildInfo(void)
748 {
749  const char *bits;
750  const char *endian;
751  char features[2048] = "";
752  const char *tls;
753 
754  printf("This is %s version %s\n", PROG_NAME, GetProgramVersion());
755 #ifdef DEBUG
756  strlcat(features, "DEBUG ", sizeof(features));
757 #endif
758 #ifdef DEBUG_VALIDATION
759  strlcat(features, "DEBUG_VALIDATION ", sizeof(features));
760 #endif
761 #ifdef UNITTESTS
762  strlcat(features, "UNITTESTS ", sizeof(features));
763 #endif
764 #ifdef NFQ
765  strlcat(features, "NFQ ", sizeof(features));
766 #endif
767 #ifdef IPFW
768  strlcat(features, "IPFW ", sizeof(features));
769 #endif
770 #ifdef HAVE_PCAP_SET_BUFF
771  strlcat(features, "PCAP_SET_BUFF ", sizeof(features));
772 #endif
773 #ifdef HAVE_PFRING
774  strlcat(features, "PF_RING ", sizeof(features));
775 #endif
776 #ifdef HAVE_NAPATECH
777  strlcat(features, "NAPATECH ", sizeof(features));
778 #endif
779 #ifdef HAVE_AF_PACKET
780  strlcat(features, "AF_PACKET ", sizeof(features));
781 #endif
782 #ifdef HAVE_NETMAP
783  strlcat(features, "NETMAP ", sizeof(features));
784 #endif
785 #ifdef HAVE_PACKET_FANOUT
786  strlcat(features, "HAVE_PACKET_FANOUT ", sizeof(features));
787 #endif
788 #ifdef HAVE_DAG
789  strlcat(features, "DAG ", sizeof(features));
790 #endif
791 #ifdef HAVE_LIBCAP_NG
792  strlcat(features, "LIBCAP_NG ", sizeof(features));
793 #endif
794 #ifdef HAVE_LIBNET11
795  strlcat(features, "LIBNET1.1 ", sizeof(features));
796 #endif
797  strlcat(features, "HAVE_HTP_URI_NORMALIZE_HOOK ", sizeof(features));
798 #ifdef PCRE2_HAVE_JIT
799  strlcat(features, "PCRE_JIT ", sizeof(features));
800 #endif
801  /* For compatibility, just say we have HAVE_NSS. */
802  strlcat(features, "HAVE_NSS ", sizeof(features));
803  /* HTTP2_DECOMPRESSION is not an optional feature in this major version */
804  strlcat(features, "HTTP2_DECOMPRESSION ", sizeof(features));
805  /* Lua is now vendored in and always available. */
806  strlcat(features, "HAVE_LUA ", sizeof(features));
807 #ifdef HAVE_JA3
808  strlcat(features, "HAVE_JA3 ", sizeof(features));
809 #endif
810 #ifdef HAVE_JA4
811  strlcat(features, "HAVE_JA4 ", sizeof(features));
812 #endif
813  strlcat(features, "HAVE_LIBJANSSON ", sizeof(features));
814 #ifdef PROFILING
815  strlcat(features, "PROFILING ", sizeof(features));
816 #endif
817 #ifdef PROFILE_LOCKING
818  strlcat(features, "PROFILE_LOCKING ", sizeof(features));
819 #endif
820 #if defined(TLS_C11) || defined(TLS_GNU)
821  strlcat(features, "TLS ", sizeof(features));
822 #endif
823 #if defined(TLS_C11)
824  strlcat(features, "TLS_C11 ", sizeof(features));
825 #elif defined(TLS_GNU)
826  strlcat(features, "TLS_GNU ", sizeof(features));
827 #endif
828 #ifdef HAVE_MAGIC
829  strlcat(features, "MAGIC ", sizeof(features));
830 #endif
831  strlcat(features, "RUST ", sizeof(features));
832 #if defined(SC_ADDRESS_SANITIZER)
833  strlcat(features, "ASAN ", sizeof(features));
834 #endif
835 #if defined(HAVE_POPCNT64)
836  strlcat(features, "POPCNT64 ", sizeof(features));
837 #endif
838  if (strlen(features) == 0) {
839  strlcat(features, "none", sizeof(features));
840  }
841 
842  printf("Features: %s\n", features);
843 
844  /* SIMD stuff */
845  memset(features, 0x00, sizeof(features));
846 #if defined(__SSE4_2__)
847  strlcat(features, "SSE_4_2 ", sizeof(features));
848 #endif
849 #if defined(__SSE4_1__)
850  strlcat(features, "SSE_4_1 ", sizeof(features));
851 #endif
852 #if defined(__SSE3__)
853  strlcat(features, "SSE_3 ", sizeof(features));
854 #endif
855 #if defined(__SSE2__)
856  strlcat(features, "SSE_2 ", sizeof(features));
857 #endif
858  if (strlen(features) == 0) {
859  strlcat(features, "none", sizeof(features));
860  }
861  printf("SIMD support: %s\n", features);
862 
863  /* atomics stuff */
864  memset(features, 0x00, sizeof(features));
865 #if defined(__GCC_HAVE_SYNC_COMPARE_AND_SWAP_1)
866  strlcat(features, "1 ", sizeof(features));
867 #endif
868 #if defined(__GCC_HAVE_SYNC_COMPARE_AND_SWAP_2)
869  strlcat(features, "2 ", sizeof(features));
870 #endif
871 #if defined(__GCC_HAVE_SYNC_COMPARE_AND_SWAP_4)
872  strlcat(features, "4 ", sizeof(features));
873 #endif
874 #if defined(__GCC_HAVE_SYNC_COMPARE_AND_SWAP_8)
875  strlcat(features, "8 ", sizeof(features));
876 #endif
877 #if defined(__GCC_HAVE_SYNC_COMPARE_AND_SWAP_16)
878  strlcat(features, "16 ", sizeof(features));
879 #endif
880  if (strlen(features) == 0) {
881  strlcat(features, "none", sizeof(features));
882  } else {
883  strlcat(features, "byte(s)", sizeof(features));
884  }
885  printf("Atomic intrinsics: %s\n", features);
886 
887 #if __WORDSIZE == 64
888  bits = "64-bits";
889 #elif __WORDSIZE == 32
890  bits = "32-bits";
891 #else
892  bits = "<unknown>-bits";
893 #endif
894 
895 #if __BYTE_ORDER == __BIG_ENDIAN
896  endian = "Big-endian";
897 #elif __BYTE_ORDER == __LITTLE_ENDIAN
898  endian = "Little-endian";
899 #else
900  endian = "<unknown>-endian";
901 #endif
902 
903  printf("%s, %s architecture\n", bits, endian);
904 #ifdef __GNUC__
905  printf("GCC version %s, C version %"PRIiMAX"\n", __VERSION__, (intmax_t)__STDC_VERSION__);
906 #else
907  printf("C version %"PRIiMAX"\n", (intmax_t)__STDC_VERSION__);
908 #endif
909 
910 #if __SSP__ == 1
911  printf("compiled with -fstack-protector\n");
912 #endif
913 #if __SSP_ALL__ == 2
914  printf("compiled with -fstack-protector-all\n");
915 #endif
916 /*
917  * Workaround for special defines of _FORTIFY_SOURCE like
918  * FORTIFY_SOURCE=((defined __OPTIMIZE && OPTIMIZE > 0) ? 2 : 0)
919  * which is used by Gentoo for example and would result in the error
920  * 'defined' undeclared when _FORTIFY_SOURCE used via %d in printf func
921  *
922  */
923 #if _FORTIFY_SOURCE == 2
924  printf("compiled with _FORTIFY_SOURCE=2\n");
925 #elif _FORTIFY_SOURCE == 1
926  printf("compiled with _FORTIFY_SOURCE=1\n");
927 #elif _FORTIFY_SOURCE == 0
928  printf("compiled with _FORTIFY_SOURCE=0\n");
929 #endif
930 #ifdef CLS
931  printf("L1 cache line size (CLS)=%d\n", CLS);
932 #endif
933 #if defined(TLS_C11)
934  tls = "_Thread_local";
935 #elif defined(TLS_GNU)
936  tls = "__thread";
937 #else
938 #error "Unsupported thread local"
939 #endif
940  printf("thread local storage method: %s\n", tls);
941 
942  printf("compiled with %s\n", htp_get_version());
943  printf("\n");
944 #include "build-info.h"
945 }
946 
950 
952 {
953  /* commanders */
955  /* managers */
959  /* nfq */
963  /* ipfw */
967  /* pcap live */
970  /* pcap file */
973  /* af-packet */
976  /* af-xdp */
979  /* netmap */
982  /* dag file */
985  /* dag live */
988 
989  /* flow worker */
991  /* respond-reject */
993 
994  /* log api */
997 
999  /* nflog */
1002 
1003  /* windivert */
1007 
1008  /* Dpdk */
1011 
1012  /* Library */
1014 }
1015 
1017 {
1018  SCEnter();
1019 
1020  SCInstance *suri = &suricata;
1021 
1022  if (suri->conf_filename == NULL)
1024 
1025  if (SCConfYamlLoadFile(suri->conf_filename) != 0) {
1026  /* Error already displayed. */
1028  }
1029 
1030  if (suri->additional_configs) {
1031  for (int i = 0; suri->additional_configs[i] != NULL; i++) {
1032  SCLogConfig("Loading additional configuration file %s", suri->additional_configs[i]);
1034  }
1035  }
1036 
1038 }
1039 
1040 static TmEcode ParseInterfacesList(const int runmode, char *pcap_dev)
1041 {
1042  SCEnter();
1043 
1044  /* run the selected runmode */
1045  if (runmode == RUNMODE_PCAP_DEV) {
1046  if (strlen(pcap_dev) == 0) {
1047  int ret = LiveBuildDeviceList("pcap");
1048  if (ret == 0) {
1049  SCLogError("No interface found in config for pcap");
1051  }
1052  }
1053  } else if (runmode == RUNMODE_PLUGIN) {
1054  if (strcmp(suricata.capture_plugin_name, "pfring") == 0) {
1055  /* Special handling for pfring. */
1056  if (strlen(pcap_dev)) {
1057  if (SCConfSetFinal("pfring.live-interface", pcap_dev) != 1) {
1058  SCLogError("Failed to set pfring.live-interface");
1060  }
1061  }
1062  }
1063 #ifdef HAVE_DPDK
1064  } else if (runmode == RUNMODE_DPDK) {
1065  char iface_selector[] = "dpdk.interfaces";
1066  int ret = LiveBuildDeviceList(iface_selector);
1067  if (ret == 0) {
1068  SCLogError("No interface found in config for %s", iface_selector);
1070  }
1071 #endif
1072 #ifdef HAVE_AF_PACKET
1073  } else if (runmode == RUNMODE_AFP_DEV) {
1074  /* iface has been set on command line */
1075  if (strlen(pcap_dev)) {
1076  if (SCConfSetFinal("af-packet.live-interface", pcap_dev) != 1) {
1077  SCLogError("Failed to set af-packet.live-interface");
1079  }
1080  } else {
1081  int ret = LiveBuildDeviceList("af-packet");
1082  if (ret == 0) {
1083  SCLogError("No interface found in config for af-packet");
1085  }
1086  }
1087 #endif
1088 #ifdef HAVE_AF_XDP
1089  } else if (runmode == RUNMODE_AFXDP_DEV) {
1090  /* iface has been set on command line */
1091  if (strlen(pcap_dev)) {
1092  if (SCConfSetFinal("af-xdp.live-interface", pcap_dev) != 1) {
1093  SCLogError("Failed to set af-xdp.live-interface");
1095  }
1096  } else {
1097  int ret = LiveBuildDeviceList("af-xdp");
1098  if (ret == 0) {
1099  SCLogError("No interface found in config for af-xdp");
1101  }
1102  }
1103 #endif
1104 #ifdef HAVE_NETMAP
1105  } else if (runmode == RUNMODE_NETMAP) {
1106  /* iface has been set on command line */
1107  if (strlen(pcap_dev)) {
1108  if (SCConfSetFinal("netmap.live-interface", pcap_dev) != 1) {
1109  SCLogError("Failed to set netmap.live-interface");
1111  }
1112  } else {
1113  int ret = LiveBuildDeviceList("netmap");
1114  if (ret == 0) {
1115  SCLogError("No interface found in config for netmap");
1117  }
1118  }
1119 #endif
1120 #ifdef HAVE_NFLOG
1121  } else if (runmode == RUNMODE_NFLOG) {
1122  int ret = LiveBuildDeviceListCustom("nflog", "group");
1123  if (ret == 0) {
1124  SCLogError("No group found in config for nflog");
1126  }
1127 #endif
1128  }
1129 
1131 }
1132 
1133 static void SCInstanceInit(SCInstance *suri, const char *progname)
1134 {
1135  memset(suri, 0x00, sizeof(*suri));
1136 
1137  suri->progname = progname;
1138  suri->run_mode = RUNMODE_UNKNOWN;
1139 
1140  memset(suri->pcap_dev, 0, sizeof(suri->pcap_dev));
1141  suri->sig_file = NULL;
1142  suri->sig_file_exclusive = false;
1143  suri->pid_filename = NULL;
1144  suri->regex_arg = NULL;
1145 
1146  suri->keyword_info = NULL;
1147  suri->runmode_custom_mode = NULL;
1148 #ifndef OS_WIN32
1149  suri->user_name = NULL;
1150  suri->group_name = NULL;
1151  suri->do_setuid = false;
1152  suri->do_setgid = false;
1153 #endif /* OS_WIN32 */
1154  suri->userid = 0;
1155  suri->groupid = 0;
1156  suri->delayed_detect = 0;
1157  suri->daemon = 0;
1158  suri->offline = 0;
1159  suri->verbose = 0;
1160  /* use -1 as unknown */
1161  suri->checksum_validation = -1;
1162 #if HAVE_DETECT_DISABLED==1
1163  g_detect_disabled = suri->disabled_detect = 1;
1164 #else
1165  g_detect_disabled = suri->disabled_detect = 0;
1166 #endif
1167 }
1168 
1169 const char *GetDocURL(void)
1170 {
1171  const char *prog_ver = GetProgramVersion();
1172  if (strstr(prog_ver, "RELEASE") != NULL) {
1173  return DOC_URL "suricata-" PROG_VER;
1174  }
1175  return DOC_URL "latest";
1176 }
1177 
1178 /** \brief get string with program version
1179  *
1180  * Get the program version as passed to us from AC_INIT
1181  *
1182  * Add 'RELEASE' is no '-dev' in the version. Add the REVISION if passed
1183  * to us.
1184  *
1185  * Possible outputs:
1186  * release: '5.0.1 RELEASE'
1187  * dev with rev: '5.0.1-dev (64a789bbf 2019-10-18)'
1188  * dev w/o rev: '5.0.1-dev'
1189  */
1190 const char *GetProgramVersion(void)
1191 {
1192  if (strstr(PROG_VER, "-dev") == NULL) {
1193  return PROG_VER " RELEASE";
1194  } else {
1195 #ifdef REVISION
1196  return PROG_VER " (" xstr(REVISION) ")";
1197 #else
1198  return PROG_VER;
1199 #endif
1200  }
1201 }
1202 
1203 static TmEcode PrintVersion(void)
1204 {
1205  printf("This is %s version %s\n", PROG_NAME, GetProgramVersion());
1206  return TM_ECODE_OK;
1207 }
1208 
1209 static TmEcode LogVersion(SCInstance *suri)
1210 {
1211  const char *mode = suri->system ? "SYSTEM" : "USER";
1212  SCLogNotice("This is %s version %s running in %s mode",
1213  PROG_NAME, GetProgramVersion(), mode);
1214  return TM_ECODE_OK;
1215 }
1216 
1217 static void SCSetStartTime(SCInstance *suri)
1218 {
1219  memset(&suri->start_time, 0, sizeof(suri->start_time));
1220  gettimeofday(&suri->start_time, NULL);
1221 }
1222 
1223 static void SCPrintElapsedTime(struct timeval *start_time)
1224 {
1225  if (start_time == NULL)
1226  return;
1227  struct timeval end_time;
1228  memset(&end_time, 0, sizeof(end_time));
1229  gettimeofday(&end_time, NULL);
1230  uint64_t milliseconds = ((end_time.tv_sec - start_time->tv_sec) * 1000) +
1231  (((1000000 + end_time.tv_usec - start_time->tv_usec) / 1000) - 1000);
1232  SCLogInfo("time elapsed %.3fs", (float)milliseconds/(float)1000);
1233 }
1234 
1235 static int ParseCommandLineAfpacket(SCInstance *suri, const char *in_arg)
1236 {
1237 #ifdef HAVE_AF_PACKET
1238  if (suri->run_mode == RUNMODE_UNKNOWN) {
1239  suri->run_mode = RUNMODE_AFP_DEV;
1240  if (in_arg) {
1241  LiveRegisterDeviceName(in_arg);
1242  memset(suri->pcap_dev, 0, sizeof(suri->pcap_dev));
1243  strlcpy(suri->pcap_dev, in_arg, sizeof(suri->pcap_dev));
1244  }
1245  } else if (suri->run_mode == RUNMODE_AFP_DEV) {
1246  if (in_arg) {
1247  LiveRegisterDeviceName(in_arg);
1248  } else {
1249  SCLogInfo("Multiple af-packet option without interface on each is useless");
1250  }
1251  } else {
1252  SCLogError("more than one run mode "
1253  "has been specified");
1254  PrintUsage(suri->progname);
1255  return TM_ECODE_FAILED;
1256  }
1257  return TM_ECODE_OK;
1258 #else
1259  SCLogError("AF_PACKET not enabled. On Linux "
1260  "host, make sure to pass --enable-af-packet to "
1261  "configure when building.");
1262  return TM_ECODE_FAILED;
1263 #endif
1264 }
1265 
1266 static int ParseCommandLineAfxdp(SCInstance *suri, const char *in_arg)
1267 {
1268 #ifdef HAVE_AF_XDP
1269  if (suri->run_mode == RUNMODE_UNKNOWN) {
1270  suri->run_mode = RUNMODE_AFXDP_DEV;
1271  if (in_arg) {
1272  LiveRegisterDeviceName(in_arg);
1273  memset(suri->pcap_dev, 0, sizeof(suri->pcap_dev));
1274  strlcpy(suri->pcap_dev, in_arg, sizeof(suri->pcap_dev));
1275  }
1276  } else if (suri->run_mode == RUNMODE_AFXDP_DEV) {
1277  if (in_arg) {
1278  LiveRegisterDeviceName(in_arg);
1279  } else {
1280  SCLogInfo("Multiple af-xdp options without interface on each is useless");
1281  }
1282  } else {
1283  SCLogError("more than one run mode "
1284  "has been specified");
1285  PrintUsage(suri->progname);
1286  return TM_ECODE_FAILED;
1287  }
1288  return TM_ECODE_OK;
1289 #else
1290  SCLogError("AF_XDP not enabled. On Linux "
1291  "host, make sure correct libraries are installed,"
1292  " see documentation for information.");
1293  return TM_ECODE_FAILED;
1294 #endif
1295 }
1296 
1297 static int ParseCommandLineDpdk(SCInstance *suri, const char *in_arg)
1298 {
1299 #ifdef HAVE_DPDK
1300  if (suri->run_mode == RUNMODE_UNKNOWN) {
1301  suri->run_mode = RUNMODE_DPDK;
1302  } else if (suri->run_mode == RUNMODE_DPDK) {
1303  SCLogInfo("Multiple dpdk options have no effect on Suricata");
1304  } else {
1305  SCLogError("more than one run mode "
1306  "has been specified");
1307  PrintUsage(suri->progname);
1308  return TM_ECODE_FAILED;
1309  }
1310  return TM_ECODE_OK;
1311 #else
1312  SCLogError("DPDK not enabled. On Linux "
1313  "host, make sure to pass --enable-dpdk to "
1314  "configure when building.");
1315  return TM_ECODE_FAILED;
1316 #endif
1317 }
1318 
1319 static int ParseCommandLinePcapLive(SCInstance *suri, const char *in_arg)
1320 {
1321 #if defined(OS_WIN32) && !defined(HAVE_LIBWPCAP)
1322  /* If running on Windows without Npcap, bail early as live capture is not supported. */
1323  FatalError("Live capture not available. To support live capture compile against Npcap.");
1324 #endif
1325  memset(suri->pcap_dev, 0, sizeof(suri->pcap_dev));
1326 
1327  if (in_arg != NULL) {
1328  /* some windows shells require escaping of the \ in \Device. Otherwise
1329  * the backslashes are stripped. We put them back here. */
1330  if (strlen(in_arg) > 9 && strncmp(in_arg, "DeviceNPF", 9) == 0) {
1331  snprintf(suri->pcap_dev, sizeof(suri->pcap_dev), "\\Device\\NPF%s", in_arg+9);
1332  } else {
1333  strlcpy(suri->pcap_dev, in_arg, sizeof(suri->pcap_dev));
1334  PcapTranslateIPToDevice(suri->pcap_dev, sizeof(suri->pcap_dev));
1335  }
1336 
1337  if (strcmp(suri->pcap_dev, in_arg) != 0) {
1338  SCLogInfo("translated %s to pcap device %s", in_arg, suri->pcap_dev);
1339  } else if (strlen(suri->pcap_dev) > 0 && isdigit((unsigned char)suri->pcap_dev[0])) {
1340  SCLogError("failed to find a pcap device for IP %s", in_arg);
1341  return TM_ECODE_FAILED;
1342  }
1343  }
1344 
1345  if (suri->run_mode == RUNMODE_UNKNOWN) {
1346  suri->run_mode = RUNMODE_PCAP_DEV;
1347  if (in_arg) {
1349  }
1350  } else if (suri->run_mode == RUNMODE_PCAP_DEV) {
1352  } else {
1353  SCLogError("more than one run mode "
1354  "has been specified");
1355  PrintUsage(suri->progname);
1356  return TM_ECODE_FAILED;
1357  }
1358  return TM_ECODE_OK;
1359 }
1360 
1361 /**
1362  * Helper function to check if log directory is writable
1363  */
1364 static bool IsLogDirectoryWritable(const char* str)
1365 {
1366  if (access(str, W_OK) == 0)
1367  return true;
1368  return false;
1369 }
1370 
1371 extern int g_skip_prefilter;
1372 
1373 TmEcode SCParseCommandLine(int argc, char **argv)
1374 {
1375  SCInstance *suri = &suricata;
1376  int opt;
1377 
1378  int dump_config = 0;
1379  int dump_features = 0;
1380  int list_app_layer_protocols = 0;
1381  int list_rule_protocols = 0;
1382  int list_app_layer_hooks = 0;
1383  int list_unittests = 0;
1384  int list_runmodes = 0;
1385  int list_keywords = 0;
1386  int build_info = 0;
1387  int conf_test = 0;
1388  int engine_analysis = 0;
1389  int ret = TM_ECODE_OK;
1390  int is_firewall = 0;
1391 
1392 #ifdef UNITTESTS
1393  coverage_unittests = 0;
1394  g_ut_modules = 0;
1395  g_ut_covered = 0;
1396 #endif
1397 
1398  // clang-format off
1399  struct option long_opts[] = {
1400  {"help", 0, 0, 0},
1401  {"dump-config", 0, &dump_config, 1},
1402  {"dump-features", 0, &dump_features, 1},
1403  {"pfring", optional_argument, 0, 0},
1404  {"pfring-int", required_argument, 0, 0},
1405  {"pfring-cluster-id", required_argument, 0, 0},
1406  {"pfring-cluster-type", required_argument, 0, 0},
1407 #ifdef HAVE_DPDK
1408  {"dpdk", 0, 0, 0},
1409 #endif
1410  {"af-packet", optional_argument, 0, 0},
1411  {"af-xdp", optional_argument, 0, 0},
1412  {"netmap", optional_argument, 0, 0},
1413  {"pcap", optional_argument, 0, 0},
1414  {"pcap-file-continuous", 0, 0, 0},
1415  {"pcap-file-delete", 0, 0, 0},
1416  {"pcap-file-recursive", 0, 0, 0},
1417  {"pcap-file-buffer-size", required_argument, 0, 0},
1418  {"simulate-ips", 0, 0 , 0},
1419  {"no-random", 0, &g_disable_randomness, 1},
1420  {"strict-rule-keywords", optional_argument, 0, 0},
1421 
1422  {"capture-plugin", required_argument, 0, 0},
1423  {"capture-plugin-args", required_argument, 0, 0},
1424 
1425 #ifdef BUILD_UNIX_SOCKET
1426  {"unix-socket", optional_argument, 0, 0},
1427 #endif
1428  {"pcap-buffer-size", required_argument, 0, 0},
1429  {"unittest-filter", required_argument, 0, 'U'},
1430  {"list-app-layer-protos", 0, &list_app_layer_protocols, 1},
1431  {"list-rule-protos", 0, &list_rule_protocols, 1},
1432  {"list-app-layer-hooks", 0, &list_app_layer_hooks, 1},
1433  {"list-unittests", 0, &list_unittests, 1},
1434  {"list-runmodes", 0, &list_runmodes, 1},
1435  {"list-keywords", optional_argument, &list_keywords, 1},
1436  {"runmode", required_argument, NULL, 0},
1437  {"engine-analysis", 0, &engine_analysis, 1},
1438 #ifdef OS_WIN32
1439  {"service-install", 0, 0, 0},
1440  {"service-remove", 0, 0, 0},
1441  {"service-change-params", 0, 0, 0},
1442 #endif /* OS_WIN32 */
1443  {"pidfile", required_argument, 0, 0},
1444  {"init-errors-fatal", 0, 0, 0},
1445  {"disable-detection", 0, 0, 0},
1446  {"disable-hashing", 0, 0, 0},
1447  {"fatal-unittests", 0, 0, 0},
1448  {"unittests-coverage", 0, &coverage_unittests, 1},
1449  {"user", required_argument, 0, 0},
1450  {"group", required_argument, 0, 0},
1451  {"erf-in", required_argument, 0, 0},
1452  {"dag", required_argument, 0, 0},
1453  {"build-info", 0, &build_info, 1},
1454  {"data-dir", required_argument, 0, 0},
1455 #ifdef WINDIVERT
1456  {"windivert", required_argument, 0, 0},
1457  {"windivert-forward", required_argument, 0, 0},
1458 #endif
1459 #ifdef HAVE_LIBNET11
1460  {"reject-dev", required_argument, 0, 0},
1461 #endif
1462  {"set", required_argument, 0, 0},
1463 #ifdef HAVE_NFLOG
1464  {"nflog", optional_argument, 0, 0},
1465 #endif
1466  {"simulate-packet-flow-memcap", required_argument, 0, 0},
1467  {"simulate-applayer-error-at-offset-ts", required_argument, 0, 0},
1468  {"simulate-applayer-error-at-offset-tc", required_argument, 0, 0},
1469  {"simulate-packet-loss", required_argument, 0, 0},
1470  {"simulate-packet-tcp-reassembly-memcap", required_argument, 0, 0},
1471  {"simulate-packet-tcp-ssn-memcap", required_argument, 0, 0},
1472  {"simulate-packet-defrag-memcap", required_argument, 0, 0},
1473  {"simulate-alert-queue-realloc-failure", 0, 0, 0},
1474 
1475  {"qa-skip-prefilter", 0, &g_skip_prefilter, 1 },
1476 
1477  {"firewall", 0, &is_firewall, 1 },
1478  {"firewall-rules-exclusive", required_argument, 0, 0},
1479 
1480  {"include", required_argument, 0, 0},
1481 
1482  {NULL, 0, NULL, 0}
1483  };
1484  // clang-format on
1485 
1486  /* getopt_long stores the option index here. */
1487  int option_index = 0;
1488 
1489  char short_opts[] = "c:TDhi:l:q:d:r:us:S:U:VF:vk:";
1490 
1491  while ((opt = getopt_long(argc, argv, short_opts, long_opts, &option_index)) != -1) {
1492  switch (opt) {
1493  case 0:
1494  if (strcmp((long_opts[option_index]).name, "help") == 0) {
1495  suri->run_mode = RUNMODE_PRINT_USAGE;
1496  return TM_ECODE_OK;
1497  } else if (strcmp((long_opts[option_index]).name, "pfring") == 0 ||
1498  strcmp((long_opts[option_index]).name, "pfring-int") == 0) {
1499 #ifdef HAVE_PFRING
1500  /* TODO: Which plugin? */
1501  suri->run_mode = RUNMODE_PLUGIN;
1502  suri->capture_plugin_name = "pfring";
1503  if (optarg != NULL) {
1504  memset(suri->pcap_dev, 0, sizeof(suri->pcap_dev));
1505  strlcpy(suri->pcap_dev, optarg,
1506  ((strlen(optarg) < sizeof(suri->pcap_dev)) ?
1507  (strlen(optarg) + 1) : sizeof(suri->pcap_dev)));
1508  LiveRegisterDeviceName(optarg);
1509  }
1510 #else
1511  SCLogError("PF_RING not enabled. Make sure "
1512  "to pass --enable-pfring to configure when building.");
1513  return TM_ECODE_FAILED;
1514 #endif /* HAVE_PFRING */
1515  } else if (strcmp((long_opts[option_index]).name, "pfring-cluster-id") == 0) {
1516 #ifdef HAVE_PFRING
1517  if (SCConfSetFinal("pfring.cluster-id", optarg) != 1) {
1518  SCLogError("failed to set pfring.cluster-id");
1519  return TM_ECODE_FAILED;
1520  }
1521 #else
1522  SCLogError("PF_RING not enabled. Make sure "
1523  "to pass --enable-pfring to configure when building.");
1524  return TM_ECODE_FAILED;
1525 #endif /* HAVE_PFRING */
1526  } else if (strcmp((long_opts[option_index]).name, "pfring-cluster-type") == 0) {
1527 #ifdef HAVE_PFRING
1528  if (SCConfSetFinal("pfring.cluster-type", optarg) != 1) {
1529  SCLogError("failed to set pfring.cluster-type");
1530  return TM_ECODE_FAILED;
1531  }
1532 #else
1533  SCLogError("PF_RING not enabled. Make sure "
1534  "to pass --enable-pfring to configure when building.");
1535  return TM_ECODE_FAILED;
1536 #endif /* HAVE_PFRING */
1537  } else if (strcmp((long_opts[option_index]).name, "capture-plugin") == 0) {
1538  suri->run_mode = RUNMODE_PLUGIN;
1539  suri->capture_plugin_name = optarg;
1540  } else if (strcmp((long_opts[option_index]).name, "capture-plugin-args") == 0) {
1541  suri->capture_plugin_args = optarg;
1542  } else if (strcmp((long_opts[option_index]).name, "dpdk") == 0) {
1543  if (ParseCommandLineDpdk(suri, optarg) != TM_ECODE_OK) {
1544  return TM_ECODE_FAILED;
1545  }
1546  } else if (strcmp((long_opts[option_index]).name, "af-packet") == 0) {
1547  if (ParseCommandLineAfpacket(suri, optarg) != TM_ECODE_OK) {
1548  return TM_ECODE_FAILED;
1549  }
1550  } else if (strcmp((long_opts[option_index]).name, "af-xdp") == 0) {
1551  if (ParseCommandLineAfxdp(suri, optarg) != TM_ECODE_OK) {
1552  return TM_ECODE_FAILED;
1553  }
1554  } else if (strcmp((long_opts[option_index]).name, "netmap") == 0) {
1555 #ifdef HAVE_NETMAP
1556  if (suri->run_mode == RUNMODE_UNKNOWN) {
1557  suri->run_mode = RUNMODE_NETMAP;
1558  if (optarg) {
1559  LiveRegisterDeviceName(optarg);
1560  memset(suri->pcap_dev, 0, sizeof(suri->pcap_dev));
1561  strlcpy(suri->pcap_dev, optarg,
1562  ((strlen(optarg) < sizeof(suri->pcap_dev)) ?
1563  (strlen(optarg) + 1) : sizeof(suri->pcap_dev)));
1564  }
1565  } else if (suri->run_mode == RUNMODE_NETMAP) {
1566  if (optarg) {
1567  LiveRegisterDeviceName(optarg);
1568  } else {
1569  SCLogInfo("Multiple netmap option without interface on each is useless");
1570  break;
1571  }
1572  } else {
1573  SCLogError("more than one run mode "
1574  "has been specified");
1575  PrintUsage(argv[0]);
1576  return TM_ECODE_FAILED;
1577  }
1578 #else
1579  SCLogError("NETMAP not enabled.");
1580  return TM_ECODE_FAILED;
1581 #endif
1582  } else if (strcmp((long_opts[option_index]).name, "nflog") == 0) {
1583 #ifdef HAVE_NFLOG
1584  if (suri->run_mode == RUNMODE_UNKNOWN) {
1585  suri->run_mode = RUNMODE_NFLOG;
1586  LiveBuildDeviceListCustom("nflog", "group");
1587  }
1588 #else
1589  SCLogError("NFLOG not enabled.");
1590  return TM_ECODE_FAILED;
1591 #endif /* HAVE_NFLOG */
1592  } else if (strcmp((long_opts[option_index]).name, "pcap") == 0) {
1593  if (ParseCommandLinePcapLive(suri, optarg) != TM_ECODE_OK) {
1594  return TM_ECODE_FAILED;
1595  }
1596  } else if (strcmp((long_opts[option_index]).name, "simulate-ips") == 0) {
1597  SCLogInfo("Setting IPS mode");
1598  EngineModeSetIPS();
1599  } else if (strcmp((long_opts[option_index]).name, "init-errors-fatal") == 0) {
1600  if (SCConfSetFinal("engine.init-failure-fatal", "1") != 1) {
1601  SCLogError("failed to set engine init-failure-fatal");
1602  return TM_ECODE_FAILED;
1603  }
1604 #ifdef BUILD_UNIX_SOCKET
1605  } else if (strcmp((long_opts[option_index]).name , "unix-socket") == 0) {
1606  if (suri->run_mode == RUNMODE_UNKNOWN) {
1607  suri->run_mode = RUNMODE_UNIX_SOCKET;
1608  if (optarg) {
1609  if (SCConfSetFinal("unix-command.filename", optarg) != 1) {
1610  SCLogError("failed to set unix-command.filename");
1611  return TM_ECODE_FAILED;
1612  }
1613  }
1614  } else {
1615  SCLogError("more than one run mode "
1616  "has been specified");
1617  PrintUsage(argv[0]);
1618  return TM_ECODE_FAILED;
1619  }
1620 #endif
1621  }
1622  else if(strcmp((long_opts[option_index]).name, "list-app-layer-protocols") == 0) {
1623  /* listing all supported app layer protocols */
1624  } else if (strcmp((long_opts[option_index]).name, "list-app-layer-hooks") == 0) {
1625  /* listing all supported app layer hooks */
1626  } else if (strcmp((long_opts[option_index]).name, "list-unittests") == 0) {
1627 #ifdef UNITTESTS
1629 #else
1630  SCLogError("unit tests not enabled. Make sure to pass --enable-unittests to "
1631  "configure when building");
1632  return TM_ECODE_FAILED;
1633 #endif /* UNITTESTS */
1634  } else if (strcmp((long_opts[option_index]).name, "list-runmodes") == 0) {
1636  return TM_ECODE_OK;
1637  } else if (strcmp((long_opts[option_index]).name, "list-keywords") == 0) {
1638  if (optarg) {
1639  if (strcmp("short", optarg) != 0) {
1640  suri->keyword_info = optarg;
1641  }
1642  }
1643  } else if (strcmp((long_opts[option_index]).name, "runmode") == 0) {
1644  suri->runmode_custom_mode = optarg;
1645  } else if (strcmp((long_opts[option_index]).name, "engine-analysis") == 0) {
1646  // do nothing for now
1647  }
1648 #ifdef OS_WIN32
1649  else if (strcmp((long_opts[option_index]).name, "service-install") == 0) {
1650  suri->run_mode = RUNMODE_INSTALL_SERVICE;
1651  return TM_ECODE_OK;
1652  } else if (strcmp((long_opts[option_index]).name, "service-remove") == 0) {
1653  suri->run_mode = RUNMODE_REMOVE_SERVICE;
1654  return TM_ECODE_OK;
1655  } else if (strcmp((long_opts[option_index]).name, "service-change-params") == 0) {
1656  suri->run_mode = RUNMODE_CHANGE_SERVICE_PARAMS;
1657  return TM_ECODE_OK;
1658  }
1659 #endif /* OS_WIN32 */
1660  else if (strcmp((long_opts[option_index]).name, "pidfile") == 0) {
1661  suri->pid_filename = SCStrdup(optarg);
1662  if (suri->pid_filename == NULL) {
1663  SCLogError("strdup failed: %s", strerror(errno));
1664  return TM_ECODE_FAILED;
1665  }
1666  } else if (strcmp((long_opts[option_index]).name, "disable-detection") == 0) {
1667  g_detect_disabled = suri->disabled_detect = 1;
1668  } else if (strcmp((long_opts[option_index]).name, "disable-hashing") == 0) {
1669  g_disable_hashing = true;
1670  // for rust
1671  SCDisableHashing();
1672  } else if (strcmp((long_opts[option_index]).name, "fatal-unittests") == 0) {
1673 #ifdef UNITTESTS
1674  unittests_fatal = 1;
1675 #else
1676  SCLogError("unit tests not enabled. Make sure to pass --enable-unittests to "
1677  "configure when building");
1678  return TM_ECODE_FAILED;
1679 #endif /* UNITTESTS */
1680  } else if (strcmp((long_opts[option_index]).name, "user") == 0) {
1681 #ifndef HAVE_LIBCAP_NG
1682  SCLogError("libcap-ng is required to"
1683  " drop privileges, but it was not compiled into Suricata.");
1684  return TM_ECODE_FAILED;
1685 #else
1686  suri->user_name = optarg;
1687  suri->do_setuid = true;
1688 #endif /* HAVE_LIBCAP_NG */
1689  } else if (strcmp((long_opts[option_index]).name, "group") == 0) {
1690 #ifndef HAVE_LIBCAP_NG
1691  SCLogError("libcap-ng is required to"
1692  " drop privileges, but it was not compiled into Suricata.");
1693  return TM_ECODE_FAILED;
1694 #else
1695  suri->group_name = optarg;
1696  suri->do_setgid = true;
1697 #endif /* HAVE_LIBCAP_NG */
1698  } else if (strcmp((long_opts[option_index]).name, "erf-in") == 0) {
1699  suri->run_mode = RUNMODE_ERF_FILE;
1700  if (SCConfSetFinal("erf-file.file", optarg) != 1) {
1701  SCLogError("failed to set erf-file.file");
1702  return TM_ECODE_FAILED;
1703  }
1704  } else if (strcmp((long_opts[option_index]).name, "dag") == 0) {
1705 #ifdef HAVE_DAG
1706  if (suri->run_mode == RUNMODE_UNKNOWN) {
1707  suri->run_mode = RUNMODE_DAG;
1708  }
1709  else if (suri->run_mode != RUNMODE_DAG) {
1710  SCLogError("more than one run mode has been specified");
1711  PrintUsage(argv[0]);
1712  return TM_ECODE_FAILED;
1713  }
1714  LiveRegisterDeviceName(optarg);
1715 #else
1716  SCLogError("libdag and a DAG card are required"
1717  " to receive packets using --dag.");
1718  return TM_ECODE_FAILED;
1719 #endif /* HAVE_DAG */
1720  } else if (strcmp((long_opts[option_index]).name, "napatech") == 0) {
1721 #ifdef HAVE_NAPATECH
1722  suri->run_mode = RUNMODE_PLUGIN;
1723 #else
1724  SCLogError("libntapi and a Napatech adapter are required"
1725  " to capture packets using --napatech.");
1726  return TM_ECODE_FAILED;
1727 #endif /* HAVE_NAPATECH */
1728  } else if (strcmp((long_opts[option_index]).name, "pcap-buffer-size") == 0) {
1729 #ifdef HAVE_PCAP_SET_BUFF
1730  if (SCConfSetFinal("pcap.buffer-size", optarg) != 1) {
1731  SCLogError("failed to set pcap-buffer-size");
1732  return TM_ECODE_FAILED;
1733  }
1734 #else
1735  SCLogError("The version of libpcap you have"
1736  " doesn't support setting buffer size.");
1737 #endif /* HAVE_PCAP_SET_BUFF */
1738  } else if (strcmp((long_opts[option_index]).name, "build-info") == 0) {
1740  return TM_ECODE_OK;
1741  } else if (strcmp((long_opts[option_index]).name, "windivert-forward") == 0) {
1742 #ifdef WINDIVERT
1743  if (suri->run_mode == RUNMODE_UNKNOWN) {
1744  suri->run_mode = RUNMODE_WINDIVERT;
1745  if (WinDivertRegisterQueue(true, optarg) == -1) {
1746  exit(EXIT_FAILURE);
1747  }
1748  } else if (suri->run_mode == RUNMODE_WINDIVERT) {
1749  if (WinDivertRegisterQueue(true, optarg) == -1) {
1750  exit(EXIT_FAILURE);
1751  }
1752  } else {
1753  SCLogError("more than one run mode "
1754  "has been specified");
1755  PrintUsage(argv[0]);
1756  exit(EXIT_FAILURE);
1757  }
1758  }
1759  else if(strcmp((long_opts[option_index]).name, "windivert") == 0) {
1760  if (suri->run_mode == RUNMODE_UNKNOWN) {
1761  suri->run_mode = RUNMODE_WINDIVERT;
1762  if (WinDivertRegisterQueue(false, optarg) == -1) {
1763  exit(EXIT_FAILURE);
1764  }
1765  } else if (suri->run_mode == RUNMODE_WINDIVERT) {
1766  if (WinDivertRegisterQueue(false, optarg) == -1) {
1767  exit(EXIT_FAILURE);
1768  }
1769  } else {
1770  SCLogError("more than one run mode "
1771  "has been specified");
1772  PrintUsage(argv[0]);
1773  exit(EXIT_FAILURE);
1774  }
1775 #else
1776  SCLogError("WinDivert not enabled. Make sure to pass --enable-windivert to "
1777  "configure when building.");
1778  return TM_ECODE_FAILED;
1779 #endif /* WINDIVERT */
1780  } else if(strcmp((long_opts[option_index]).name, "reject-dev") == 0) {
1781 #ifdef HAVE_LIBNET11
1782  BUG_ON(optarg == NULL); /* for static analysis */
1783  extern char *g_reject_dev;
1784  extern uint16_t g_reject_dev_mtu;
1785  g_reject_dev = optarg;
1786  int mtu = GetIfaceMTU(g_reject_dev);
1787  if (mtu > 0) {
1788  g_reject_dev_mtu = (uint16_t)mtu;
1789  }
1790 #else
1791  SCLogError("Libnet 1.1 support not enabled. Compile Suricata with libnet support.");
1792  return TM_ECODE_FAILED;
1793 #endif
1794  }
1795  else if (strcmp((long_opts[option_index]).name, "set") == 0) {
1796  if (optarg != NULL) {
1797  /* Quick validation. */
1798  char *val = strchr(optarg, '=');
1799  if (val == NULL) {
1800  FatalError("Invalid argument for --set, must be key=val.");
1801  }
1802  if (!SCConfSetFromString(optarg, 1)) {
1803  FatalError("failed to set configuration value %s", optarg);
1804  }
1805  }
1806  }
1807  else if (strcmp((long_opts[option_index]).name, "pcap-file-continuous") == 0) {
1808  if (SCConfSetFinal("pcap-file.continuous", "true") != 1) {
1809  SCLogError("Failed to set pcap-file.continuous");
1810  return TM_ECODE_FAILED;
1811  }
1812  }
1813  else if (strcmp((long_opts[option_index]).name, "pcap-file-delete") == 0) {
1814  if (SCConfSetFinal("pcap-file.delete-when-done", "true") != 1) {
1815  SCLogError("Failed to set pcap-file.delete-when-done");
1816  return TM_ECODE_FAILED;
1817  }
1818  }
1819  else if (strcmp((long_opts[option_index]).name, "pcap-file-recursive") == 0) {
1820  if (SCConfSetFinal("pcap-file.recursive", "true") != 1) {
1821  SCLogError("failed to set pcap-file.recursive");
1822  return TM_ECODE_FAILED;
1823  }
1824  } else if (strcmp((long_opts[option_index]).name, "pcap-file-buffer-size") == 0) {
1825  if (SCConfSetFinal("pcap-file.buffer-size", optarg) != 1) {
1826  SCLogError("failed to set pcap-file.buffer-size");
1827  return TM_ECODE_FAILED;
1828  }
1829  } else if (strcmp((long_opts[option_index]).name, "data-dir") == 0) {
1830  if (optarg == NULL) {
1831  SCLogError("no option argument (optarg) for -d");
1832  return TM_ECODE_FAILED;
1833  }
1834 
1835  if (ConfigSetDataDirectory(optarg) != TM_ECODE_OK) {
1836  SCLogError("Failed to set data directory.");
1837  return TM_ECODE_FAILED;
1838  }
1839  if (ConfigCheckDataDirectory(optarg) != TM_ECODE_OK) {
1840  SCLogError("The data directory \"%s\""
1841  " supplied at the command-line (-d %s) doesn't "
1842  "exist. Shutting down the engine.",
1843  optarg, optarg);
1844  return TM_ECODE_FAILED;
1845  }
1846  suri->set_datadir = true;
1847  } else if (strcmp((long_opts[option_index]).name, "strict-rule-keywords") == 0) {
1848  if (optarg == NULL) {
1849  suri->strict_rule_parsing_string = SCStrdup("all");
1850  } else {
1851  suri->strict_rule_parsing_string = SCStrdup(optarg);
1852  }
1853  if (suri->strict_rule_parsing_string == NULL) {
1854  FatalError("failed to duplicate 'strict' string");
1855  }
1856  } else if (strcmp((long_opts[option_index]).name, "include") == 0) {
1857  if (suri->additional_configs == NULL) {
1858  suri->additional_configs = SCCalloc(2, sizeof(char *));
1859  if (suri->additional_configs == NULL) {
1860  FatalError(
1861  "Failed to allocate memory for additional configuration files: %s",
1862  strerror(errno));
1863  }
1864  suri->additional_configs[0] = optarg;
1865  } else {
1866  for (int i = 0;; i++) {
1867  if (suri->additional_configs[i] == NULL) {
1868  const char **additional_configs =
1869  SCRealloc(suri->additional_configs, (i + 2) * sizeof(char *));
1870  if (additional_configs == NULL) {
1871  FatalError("Failed to allocate memory for additional configuration "
1872  "files: %s",
1873  strerror(errno));
1874  } else {
1875  suri->additional_configs = additional_configs;
1876  }
1877  suri->additional_configs[i] = optarg;
1878  suri->additional_configs[i + 1] = NULL;
1879  break;
1880  }
1881  }
1882  }
1883  } else if (strcmp((long_opts[option_index]).name, "firewall-rules-exclusive") == 0) {
1884  if (suri->firewall_rule_file != NULL) {
1885  SCLogError("can't have multiple --firewall-rules-exclusive options");
1886  return TM_ECODE_FAILED;
1887  }
1888  suri->firewall_rule_file = optarg;
1889  suri->firewall_rule_file_exclusive = true;
1890  suri->is_firewall = true;
1891  } else {
1893  (long_opts[option_index]).name, optarg);
1894  if (r < 0)
1895  return TM_ECODE_FAILED;
1896  }
1897  break;
1898  case 'c':
1899  suri->conf_filename = optarg;
1900  break;
1901  case 'T':
1902  conf_test = 1;
1903  if (SCConfSetFinal("engine.init-failure-fatal", "1") != 1) {
1904  SCLogError("failed to set engine init-failure-fatal");
1905  return TM_ECODE_FAILED;
1906  }
1907  break;
1908 #ifndef OS_WIN32
1909  case 'D':
1910  suri->daemon = 1;
1911  break;
1912 #endif /* OS_WIN32 */
1913  case 'h':
1914  suri->run_mode = RUNMODE_PRINT_USAGE;
1915  return TM_ECODE_OK;
1916  case 'i':
1917  if (optarg == NULL) {
1918  SCLogError("no option argument (optarg) for -i");
1919  return TM_ECODE_FAILED;
1920  }
1921 #ifdef HAVE_AF_PACKET
1922  if (ParseCommandLineAfpacket(suri, optarg) != TM_ECODE_OK) {
1923  return TM_ECODE_FAILED;
1924  }
1925 #else /* not afpacket */
1926  /* warn user if netmap is available */
1927 #if defined HAVE_NETMAP
1928  int i = 0;
1929 #ifdef HAVE_NETMAP
1930  i++;
1931 #endif
1932  SCLogWarning("faster capture "
1933  "option%s %s available:"
1934 #ifdef HAVE_NETMAP
1935  " NETMAP (--netmap=%s)"
1936 #endif
1937  ". Use --pcap=%s to suppress this warning",
1938  i == 1 ? "" : "s", i == 1 ? "is" : "are"
1939 #ifdef HAVE_NETMAP
1940  ,
1941  optarg
1942 #endif
1943  ,
1944  optarg);
1945 #endif /* have faster methods */
1946  if (ParseCommandLinePcapLive(suri, optarg) != TM_ECODE_OK) {
1947  return TM_ECODE_FAILED;
1948  }
1949 #endif
1950  break;
1951  case 'l':
1952  if (optarg == NULL) {
1953  SCLogError("no option argument (optarg) for -l");
1954  return TM_ECODE_FAILED;
1955  }
1956 
1957  if (ConfigSetLogDirectory(optarg) != TM_ECODE_OK) {
1958  SCLogError("Failed to set log directory.");
1959  return TM_ECODE_FAILED;
1960  }
1961  if (ConfigCheckLogDirectoryExists(optarg) != TM_ECODE_OK) {
1962  SCLogError("The logging directory \"%s\""
1963  " supplied at the command-line (-l %s) doesn't "
1964  "exist. Shutting down the engine.",
1965  optarg, optarg);
1966  return TM_ECODE_FAILED;
1967  }
1968  if (!IsLogDirectoryWritable(optarg)) {
1969  SCLogError("The logging directory \"%s\""
1970  " supplied at the command-line (-l %s) is not "
1971  "writable. Shutting down the engine.",
1972  optarg, optarg);
1973  return TM_ECODE_FAILED;
1974  }
1975  suri->set_logdir = true;
1976 
1977  break;
1978  case 'q':
1979 #ifdef NFQ
1980  if (suri->run_mode == RUNMODE_UNKNOWN) {
1981  suri->run_mode = RUNMODE_NFQ;
1982  EngineModeSetIPS();
1983  if (NFQParseAndRegisterQueues(optarg) == -1)
1984  return TM_ECODE_FAILED;
1985  } else if (suri->run_mode == RUNMODE_NFQ) {
1986  if (NFQParseAndRegisterQueues(optarg) == -1)
1987  return TM_ECODE_FAILED;
1988  } else {
1989  SCLogError("more than one run mode "
1990  "has been specified");
1991  PrintUsage(argv[0]);
1992  return TM_ECODE_FAILED;
1993  }
1994 #else
1995  SCLogError("NFQUEUE not enabled. Make sure to pass --enable-nfqueue to configure when "
1996  "building.");
1997  return TM_ECODE_FAILED;
1998 #endif /* NFQ */
1999  break;
2000  case 'd':
2001 #ifdef IPFW
2002  if (suri->run_mode == RUNMODE_UNKNOWN) {
2003  suri->run_mode = RUNMODE_IPFW;
2004  EngineModeSetIPS();
2005  if (IPFWRegisterQueue(optarg) == -1)
2006  return TM_ECODE_FAILED;
2007  } else if (suri->run_mode == RUNMODE_IPFW) {
2008  if (IPFWRegisterQueue(optarg) == -1)
2009  return TM_ECODE_FAILED;
2010  } else {
2011  SCLogError("more than one run mode "
2012  "has been specified");
2013  PrintUsage(argv[0]);
2014  return TM_ECODE_FAILED;
2015  }
2016 #else
2017  SCLogError("IPFW not enabled. Make sure to pass --enable-ipfw to configure when "
2018  "building.");
2019  return TM_ECODE_FAILED;
2020 #endif /* IPFW */
2021  break;
2022  case 'r':
2023  BUG_ON(optarg == NULL); /* for static analysis */
2024  if (suri->run_mode == RUNMODE_UNKNOWN) {
2025  suri->run_mode = RUNMODE_PCAP_FILE;
2026  } else {
2027  SCLogError("more than one run mode "
2028  "has been specified");
2029  PrintUsage(argv[0]);
2030  return TM_ECODE_FAILED;
2031  }
2032  SCStat buf;
2033  if (SCStatFn(optarg, &buf) != 0) {
2034  SCLogError("pcap file '%s': %s", optarg, strerror(errno));
2035  return TM_ECODE_FAILED;
2036  }
2037  if (SCConfSetFinal("pcap-file.file", optarg) != 1) {
2038  SCLogError("ERROR: Failed to set pcap-file.file\n");
2039  return TM_ECODE_FAILED;
2040  }
2041 
2042  break;
2043  case 's':
2044  if (suri->sig_file != NULL) {
2045  SCLogError("can't have multiple -s options or mix -s and -S.");
2046  return TM_ECODE_FAILED;
2047  }
2048  suri->sig_file = optarg;
2049  break;
2050  case 'S':
2051  if (suri->sig_file != NULL) {
2052  SCLogError("can't have multiple -S options or mix -s and -S.");
2053  return TM_ECODE_FAILED;
2054  }
2055  suri->sig_file = optarg;
2056  suri->sig_file_exclusive = true;
2057  break;
2058  case 'u':
2059 #ifdef UNITTESTS
2060  if (suri->run_mode == RUNMODE_UNKNOWN) {
2061  suri->run_mode = RUNMODE_UNITTEST;
2062  } else {
2063  SCLogError("more than one run mode has"
2064  " been specified");
2065  PrintUsage(argv[0]);
2066  return TM_ECODE_FAILED;
2067  }
2068 #else
2069  SCLogError("unit tests not enabled. Make sure to pass --enable-unittests to configure "
2070  "when building.");
2071  return TM_ECODE_FAILED;
2072 #endif /* UNITTESTS */
2073  break;
2074  case 'U':
2075 #ifdef UNITTESTS
2076  suri->regex_arg = optarg;
2077 
2078  if(strlen(suri->regex_arg) == 0)
2079  suri->regex_arg = NULL;
2080 #endif
2081  break;
2082  case 'V':
2084  return TM_ECODE_OK;
2085  case 'F':
2086  if (optarg == NULL) {
2087  SCLogError("no option argument (optarg) for -F");
2088  return TM_ECODE_FAILED;
2089  }
2090 
2091  SetBpfStringFromFile(optarg);
2092  break;
2093  case 'v': {
2094  static bool ignore_extra = false;
2095  if (suri->verbose < VERBOSE_MAX)
2096  suri->verbose++;
2097  else if (!ignore_extra) {
2098  SCLogNotice("extraneous verbose option(s) ignored");
2099  ignore_extra = true;
2100  }
2101  } break;
2102  case 'k':
2103  if (optarg == NULL) {
2104  SCLogError("no option argument (optarg) for -k");
2105  return TM_ECODE_FAILED;
2106  }
2107  if (!strcmp("all", optarg))
2108  suri->checksum_validation = 1;
2109  else if (!strcmp("none", optarg))
2110  suri->checksum_validation = 0;
2111  else {
2112  SCLogError("option '%s' invalid for -k", optarg);
2113  return TM_ECODE_FAILED;
2114  }
2115  break;
2116  default:
2117  PrintUsage(argv[0]);
2118  return TM_ECODE_FAILED;
2119  }
2120  }
2121 
2122  if (is_firewall) {
2123  suri->is_firewall = true;
2124  }
2125 
2126  if (suri->disabled_detect && (suri->sig_file != NULL || suri->firewall_rule_file != NULL)) {
2127  SCLogError("can't use -s/-S or --firewall-rules-exclusive when detection is disabled");
2128  return TM_ECODE_FAILED;
2129  }
2130 
2131  /* save the runmode from the command-line (if any) */
2132  suri->aux_run_mode = suri->run_mode;
2133 
2134  if (list_app_layer_protocols)
2136  if (list_rule_protocols)
2138  if (list_app_layer_hooks)
2140  if (list_keywords)
2142  if (list_unittests)
2144  if (dump_config)
2145  suri->run_mode = RUNMODE_DUMP_CONFIG;
2146  if (dump_features)
2148  if (conf_test)
2149  suri->run_mode = RUNMODE_CONF_TEST;
2150  if (engine_analysis)
2152 
2153  suri->offline = IsRunModeOffline(suri->run_mode);
2154  g_system = suri->system = IsRunModeSystem(suri->run_mode);
2155 
2156  ret = SetBpfString(optind, argv);
2157  if (ret != TM_ECODE_OK)
2158  return ret;
2159 
2160  return TM_ECODE_OK;
2161 }
2162 
2163 #ifdef OS_WIN32
2164 int WindowsInitService(int argc, char **argv)
2165 {
2166  if (SCRunningAsService()) {
2167  char path[MAX_PATH];
2168  char *p = NULL;
2169  strlcpy(path, argv[0], MAX_PATH);
2170  if ((p = strrchr(path, '\\'))) {
2171  *p = '\0';
2172  }
2173  if (!SetCurrentDirectory(path)) {
2174  SCLogError("Can't set current directory to: %s", path);
2175  return -1;
2176  }
2177  SCLogInfo("Current directory is set to: %s", path);
2178  SCServiceInit(argc, argv);
2179  }
2180 
2181  /* Windows socket subsystem initialization */
2182  WSADATA wsaData;
2183  if (0 != WSAStartup(MAKEWORD(2, 2), &wsaData)) {
2184  SCLogError("Can't initialize Windows sockets: %d", WSAGetLastError());
2185  return -1;
2186  }
2187 
2188  return 0;
2189 }
2190 #endif /* OS_WIN32 */
2191 
2192 static int MayDaemonize(SCInstance *suri)
2193 {
2194  if (suri->daemon == 1 && suri->pid_filename == NULL) {
2195  const char *pid_filename;
2196 
2197  if (SCConfGet("pid-file", &pid_filename) == 1) {
2198  SCLogInfo("Use pid file %s from config file.", pid_filename);
2199  } else {
2200  pid_filename = DEFAULT_PID_FILENAME;
2201  }
2202  /* The pid file name may be in config memory, but is needed later. */
2203  suri->pid_filename = SCStrdup(pid_filename);
2204  if (suri->pid_filename == NULL) {
2205  SCLogError("strdup failed: %s", strerror(errno));
2206  return TM_ECODE_FAILED;
2207  }
2208  }
2209 
2210  if (suri->pid_filename != NULL && SCPidfileTestRunning(suri->pid_filename) != 0) {
2211  SCFree(suri->pid_filename);
2212  suri->pid_filename = NULL;
2213  return TM_ECODE_FAILED;
2214  }
2215 
2216  if (suri->daemon == 1) {
2217  Daemonize();
2218  }
2219 
2220  if (suri->pid_filename != NULL) {
2221  if (SCPidfileCreate(suri->pid_filename) != 0) {
2222  SCFree(suri->pid_filename);
2223  suri->pid_filename = NULL;
2224  SCLogError("Unable to create PID file, concurrent run of"
2225  " Suricata can occur.");
2226  SCLogError("PID file creation WILL be mandatory for daemon mode"
2227  " in future version");
2228  }
2229  }
2230 
2231  return TM_ECODE_OK;
2232 }
2233 
2234 /* Initialize the user and group Suricata is to run as. */
2235 static int InitRunAs(SCInstance *suri)
2236 {
2237 #ifndef OS_WIN32
2238  /* Try to get user/group to run suricata as if
2239  command line as not decide of that */
2240  if (!suri->do_setuid && !suri->do_setgid) {
2241  const char *id;
2242  if (SCConfGet("run-as.user", &id) == 1) {
2243  suri->do_setuid = true;
2244  suri->user_name = id;
2245  }
2246  if (SCConfGet("run-as.group", &id) == 1) {
2247  suri->do_setgid = true;
2248  suri->group_name = id;
2249  }
2250  }
2251  /* Get the suricata user ID to given user ID */
2252  if (suri->do_setuid) {
2253  SCGetUserID(suri->user_name, suri->group_name, &suri->userid, &suri->groupid);
2254  sc_set_caps = true;
2255  /* Get the suricata group ID to given group ID */
2256  } else if (suri->do_setgid) {
2257  SCGetGroupID(suri->group_name, &suri->groupid);
2258  sc_set_caps = true;
2259  }
2260 #endif
2261  return TM_ECODE_OK;
2262 }
2263 
2264 static int InitSignalHandler(SCInstance *suri)
2265 {
2266  /* registering signals we use */
2267 #ifndef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
2268  UtilSignalHandlerSetup(SIGINT, SignalHandlerSigint);
2269  UtilSignalHandlerSetup(SIGTERM, SignalHandlerSigterm);
2270 #if HAVE_LIBUNWIND
2271  int enabled;
2272  if (SCConfGetBool("logging.stacktrace-on-signal", &enabled) == 0) {
2273  enabled = 1;
2274  }
2275 
2276  if (enabled) {
2277  SCLogInfo("Preparing unexpected signal handling");
2278  struct sigaction stacktrace_action;
2279  memset(&stacktrace_action, 0, sizeof(stacktrace_action));
2280  stacktrace_action.sa_sigaction = SignalHandlerUnexpected;
2281  stacktrace_action.sa_flags = SA_SIGINFO;
2282  sigaction(SIGSEGV, &stacktrace_action, NULL);
2283  sigaction(SIGABRT, &stacktrace_action, NULL);
2284  }
2285 #endif /* HAVE_LIBUNWIND */
2286 #endif
2287 #ifndef OS_WIN32
2288  UtilSignalHandlerSetup(SIGHUP, SignalHandlerSigHup);
2289  UtilSignalHandlerSetup(SIGPIPE, SIG_IGN);
2290  UtilSignalHandlerSetup(SIGSYS, SIG_IGN);
2291 #endif /* OS_WIN32 */
2292 
2293  return TM_ECODE_OK;
2294 }
2295 
2296 /* initialization code for both the main modes and for
2297  * unix socket mode.
2298  *
2299  * Will be run once per pcap in unix-socket mode */
2300 void PreRunInit(const int runmode)
2301 {
2302  if (runmode == RUNMODE_UNIX_SOCKET)
2303  return;
2304 
2305  StatsInit();
2306 #ifdef PROFILE_RULES
2307  SCProfilingRulesGlobalInit();
2308 #endif
2309 #ifdef PROFILING
2313 #endif /* PROFILING */
2314 #ifdef PROFILE_RULES
2315  SCProfilingInit();
2316 #endif
2317  DefragInit();
2325 }
2326 
2327 /* tasks we need to run before packets start flowing,
2328  * but after we dropped privs */
2329 void PreRunPostPrivsDropInit(const int runmode)
2330 {
2331  if (runmode == RUNMODE_UNIX_SOCKET) {
2332  return;
2333  }
2334 
2337  DatasetsInit();
2339 }
2340 
2341 /** \brief clean up / shutdown code for packet modes
2342  *
2343  * Shuts down packet modes, so regular packet runmodes and the
2344  * per pcap mode in the unix socket. */
2345 void PostRunDeinit(const int runmode, struct timeval *start_time)
2346 {
2347  if (runmode == RUNMODE_UNIX_SOCKET)
2348  return;
2349 
2351 
2352  /* needed by FlowWorkToDoCleanup */
2353  PacketPoolInit();
2354 
2355  /* handle graceful shutdown of the flow engine, it's helper
2356  * threads and the packet threads */
2358  /* disable capture */
2360  /* tell relevant packet threads to enter flow timeout loop */
2363  /* run cleanup on the flow hash */
2365  /* gracefully shut down all packet threads */
2367  SCPrintElapsedTime(start_time);
2369 
2370  /* kill the stats threads */
2373 
2374  /* kill packet threads -- already in 'disabled' state */
2377 
2379 
2380  /* mgt and ppt threads killed, we can run non thread-safe
2381  * shutdown functions */
2384  RunModeShutDown();
2385  FlowShutdown();
2386  IPPairShutdown();
2387  HostCleanup();
2389  DefragDestroy();
2391 #ifdef HAVE_HWLOC
2392  TopologyDestroy();
2393 #endif /* HAVE_HWLOC */
2394 
2395  TmqResetQueues();
2396 #ifdef PROFILING
2398  SCProfilingDump();
2400 #endif
2401 }
2402 
2403 int SCStartInternalRunMode(int argc, char **argv)
2404 {
2405  SCInstance *suri = &suricata;
2406  /* Treat internal running mode */
2407  switch (suri->run_mode) {
2408  case RUNMODE_LIST_KEYWORDS:
2409  return ListKeywords(suri->keyword_info);
2411  if (suri->conf_filename != NULL) {
2412  return ListRuleProtocols(suri->conf_filename);
2413  } else {
2415  }
2417  if (suri->conf_filename != NULL) {
2418  return ListAppLayerProtocols(suri->conf_filename);
2419  } else {
2421  }
2423  if (suri->conf_filename != NULL) {
2424  return ListAppLayerHooks(suri->conf_filename);
2425  } else {
2427  }
2428  case RUNMODE_PRINT_VERSION:
2429  PrintVersion();
2430  return TM_ECODE_DONE;
2432  PrintBuildInfo();
2433  return TM_ECODE_DONE;
2434  case RUNMODE_PRINT_USAGE:
2435  PrintUsage(argv[0]);
2436  return TM_ECODE_DONE;
2437  case RUNMODE_LIST_RUNMODES:
2439  return TM_ECODE_DONE;
2440  case RUNMODE_LIST_UNITTEST:
2441  RunUnittests(1, suri->regex_arg);
2442  case RUNMODE_UNITTEST:
2443  RunUnittests(0, suri->regex_arg);
2444 #ifdef OS_WIN32
2445  case RUNMODE_INSTALL_SERVICE:
2446  if (SCServiceInstall(argc, argv)) {
2447  return TM_ECODE_FAILED;
2448  }
2449  SCLogInfo("Suricata service has been successfully installed.");
2450  return TM_ECODE_DONE;
2451  case RUNMODE_REMOVE_SERVICE:
2452  if (SCServiceRemove()) {
2453  return TM_ECODE_FAILED;
2454  }
2455  SCLogInfo("Suricata service has been successfully removed.");
2456  return TM_ECODE_DONE;
2457  case RUNMODE_CHANGE_SERVICE_PARAMS:
2458  if (SCServiceChangeParams(argc, argv)) {
2459  return TM_ECODE_FAILED;
2460  }
2461  SCLogInfo("Suricata service startup parameters has been successfully changed.");
2462  return TM_ECODE_DONE;
2463 #endif /* OS_WIN32 */
2464  default:
2465  /* simply continue for other running mode */
2466  break;
2467  }
2468  return TM_ECODE_OK;
2469 }
2470 
2472 {
2473  SCInstance *suri = &suricata;
2474  switch (suri->run_mode) {
2475  case RUNMODE_UNKNOWN:
2476  PrintUsage(suri->progname);
2477  return TM_ECODE_FAILED;
2478  default:
2479  break;
2480  }
2481 
2482  if (!CheckValidDaemonModes(suri->daemon, suri->run_mode)) {
2483  return TM_ECODE_FAILED;
2484  }
2485 
2486  return TM_ECODE_OK;
2487 }
2488 
2489 static void SetupDelayedDetect(SCInstance *suri)
2490 {
2491  /* In offline mode delayed init of detect is a bad idea */
2492  if (suri->offline) {
2493  suri->delayed_detect = 0;
2494  } else {
2495  if (SCConfGetBool("detect.delayed-detect", &suri->delayed_detect) != 1) {
2496  SCConfNode *denode = NULL;
2497  SCConfNode *decnf = SCConfGetNode("detect-engine");
2498  if (decnf != NULL) {
2499  TAILQ_FOREACH(denode, &decnf->head, next) {
2500  if (strcmp(denode->val, "delayed-detect") == 0) {
2502  denode, "delayed-detect", &suri->delayed_detect);
2503  }
2504  }
2505  }
2506  }
2507  }
2508 
2509  SCLogConfig("Delayed detect %s", suri->delayed_detect ? "enabled" : "disabled");
2510  if (suri->delayed_detect) {
2511  SCLogInfo("Packets will start being processed before signatures are active.");
2512  }
2513 
2514 }
2515 
2516 static int LoadSignatures(DetectEngineCtx *de_ctx, SCInstance *suri)
2517 {
2519 
2520  if (SigLoadSignatures(de_ctx, suri->sig_file, suri->sig_file_exclusive) < 0) {
2521  SCLogError("Loading signatures failed.");
2522  if (de_ctx->failure_fatal)
2523  return TM_ECODE_FAILED;
2524  }
2525 
2526  return TM_ECODE_OK;
2527 }
2528 
2529 static int ConfigGetCaptureValue(SCInstance *suri)
2530 {
2531  /* Pull the max pending packets from the config, if not found fall
2532  * back on a sane default. */
2533  intmax_t tmp_max_pending_packets;
2534  if (SCConfGetInt("max-pending-packets", &tmp_max_pending_packets) != 1)
2535  tmp_max_pending_packets = DEFAULT_MAX_PENDING_PACKETS;
2536  if (tmp_max_pending_packets < 1 || tmp_max_pending_packets > 2147483648) {
2537  SCLogError("Maximum max-pending-packets setting is 2147483648 and must be greater than 0. "
2538  "Please check %s for errors",
2539  suri->conf_filename);
2540  return TM_ECODE_FAILED;
2541  } else {
2542  max_pending_packets = (uint32_t)tmp_max_pending_packets;
2543  }
2544 
2545  SCLogDebug("Max pending packets set to %" PRIu32, max_pending_packets);
2546 
2547  /* Pull the default packet size from the config, if not found fall
2548  * back on a sane default. */
2549  const char *temp_default_packet_size;
2550  if ((SCConfGet("default-packet-size", &temp_default_packet_size)) != 1) {
2551  int lthread;
2552  int nlive;
2553  int strip_trailing_plus = 0;
2554  switch (suri->run_mode) {
2555  case RUNMODE_AFP_DEV:
2556  /* For AF_PACKET we delay setting the
2557  * default-packet-size until we know more about the
2558  * configuration. */
2559  break;
2560 #ifdef WINDIVERT
2561  case RUNMODE_WINDIVERT: {
2562  /* by default, WinDivert collects from all devices */
2563  const int mtu = GetGlobalMTUWin32();
2564 
2565  if (mtu > 0) {
2566  /* SLL_HEADER_LEN is the longest header + 8 for VLAN */
2567  default_packet_size = mtu + SLL_HEADER_LEN + 8;
2568  break;
2569  }
2571  break;
2572  }
2573 #endif /* WINDIVERT */
2574  case RUNMODE_NETMAP:
2575  /* in netmap igb0+ has a special meaning, however the
2576  * interface really is igb0 */
2577  strip_trailing_plus = 1;
2578  /* fall through */
2579  case RUNMODE_PLUGIN:
2580  case RUNMODE_PCAP_DEV:
2581  case RUNMODE_AFXDP_DEV:
2582  nlive = LiveGetDeviceCount();
2583  for (lthread = 0; lthread < nlive; lthread++) {
2584  const char *live_dev = LiveGetDeviceName(lthread);
2585  char dev[128]; /* need to be able to support GUID names on Windows */
2586  (void)strlcpy(dev, live_dev, sizeof(dev));
2587 
2588  if (strip_trailing_plus) {
2589  size_t len = strlen(dev);
2590  if (len &&
2591  (dev[len-1] == '+' ||
2592  dev[len-1] == '^' ||
2593  dev[len-1] == '*'))
2594  {
2595  dev[len-1] = '\0';
2596  }
2597  }
2598  LiveDevice *ld = LiveGetDevice(dev);
2599  unsigned int iface_max_packet_size = GetIfaceMaxPacketSize(ld);
2600  if (iface_max_packet_size > default_packet_size)
2601  default_packet_size = iface_max_packet_size;
2602  }
2603  if (default_packet_size)
2604  break;
2605  /* fall through */
2606  default:
2608  }
2609  } else {
2610  if (ParseSizeStringU32(temp_default_packet_size, &default_packet_size) < 0) {
2611  SCLogError("Error parsing max-pending-packets "
2612  "from conf file - %s. Killing engine",
2613  temp_default_packet_size);
2614  return TM_ECODE_FAILED;
2615  }
2616  }
2617 
2618  SCLogDebug("Default packet size set to %"PRIu32, default_packet_size);
2619 
2620  return TM_ECODE_OK;
2621 }
2622 
2623 static void PostRunStartedDetectSetup(const SCInstance *suri)
2624 {
2625 #ifndef OS_WIN32
2626  /* registering signal handlers we use. We setup usr2 here, so that one
2627  * can't call it during the first sig load phase or while threads are still
2628  * starting up. */
2629  if (DetectEngineEnabled() && suri->delayed_detect == 0) {
2630  UtilSignalHandlerSetup(SIGUSR2, SignalHandlerSigusr2);
2631  UtilSignalUnblock(SIGUSR2);
2632  }
2633 #endif
2634  if (suri->delayed_detect) {
2635  /* force 'reload', this will load the rules and swap engines */
2636  DetectEngineReload(suri);
2637  SCLogNotice("Signature(s) loaded, Detect thread(s) activated.");
2638 #ifndef OS_WIN32
2639  UtilSignalHandlerSetup(SIGUSR2, SignalHandlerSigusr2);
2640  UtilSignalUnblock(SIGUSR2);
2641 #endif
2642  }
2643 }
2644 
2646 {
2647  DetectEngineCtx *de_ctx = NULL;
2648  if (!suri->disabled_detect) {
2649  SetupDelayedDetect(suri);
2650  int mt_enabled = 0;
2651  (void)SCConfGetBool("multi-detect.enabled", &mt_enabled);
2652  int default_tenant = 0;
2653  if (mt_enabled)
2654  (void)SCConfGetBool("multi-detect.default", &default_tenant);
2656  FatalError("initializing multi-detect "
2657  "detection engine contexts failed.");
2658  }
2659  if (suri->delayed_detect && suri->run_mode != RUNMODE_CONF_TEST) {
2661  } else if (mt_enabled && !default_tenant && suri->run_mode != RUNMODE_CONF_TEST) {
2663  } else {
2665  }
2666  if (de_ctx == NULL) {
2667  FatalError("initializing detection engine failed.");
2668  }
2669 
2671  if (LoadSignatures(de_ctx, suri) != TM_ECODE_OK)
2672  exit(EXIT_FAILURE);
2673  }
2674 
2675  gettimeofday(&de_ctx->last_reload, NULL);
2678  }
2679 }
2680 
2681 static void PostConfLoadedSetupHostMode(void)
2682 {
2683  const char *hostmode = NULL;
2684 
2685  if (SCConfGet("host-mode", &hostmode) == 1) {
2686  if (!strcmp(hostmode, "router")) {
2688  } else if (!strcmp(hostmode, "sniffer-only")) {
2690  } else {
2691  if (strcmp(hostmode, "auto") != 0) {
2692  WarnInvalidConfEntry("host-mode", "%s", "auto");
2693  }
2694  if (EngineModeIsIPS()) {
2696  } else {
2698  }
2699  }
2700  } else {
2701  if (EngineModeIsIPS()) {
2703  SCLogInfo("No 'host-mode': suricata is in IPS mode, using "
2704  "default setting 'router'");
2705  } else {
2707  SCLogInfo("No 'host-mode': suricata is in IDS mode, using "
2708  "default setting 'sniffer-only'");
2709  }
2710  }
2711 }
2712 
2713 static void SetupUserMode(SCInstance *suri)
2714 {
2715  /* apply 'user mode' config updates here */
2716  if (!suri->system) {
2717  if (!suri->set_logdir) {
2718  /* override log dir to current work dir" */
2719  if (ConfigSetLogDirectory((char *)".") != TM_ECODE_OK) {
2720  FatalError("could not set USER mode logdir");
2721  }
2722  }
2723  if (!suri->set_datadir) {
2724  /* override data dir to current work dir" */
2725  if (ConfigSetDataDirectory((char *)".") != TM_ECODE_OK) {
2726  FatalError("could not set USER mode datadir");
2727  }
2728  }
2729  }
2730 }
2731 
2732 /**
2733  * This function is meant to contain code that needs
2734  * to be run once the configuration has been loaded.
2735  */
2737 {
2738  int cnf_firewall_enabled = 0;
2739  if (SCConfGetBool("firewall.enabled", &cnf_firewall_enabled) == 1) {
2740  if (cnf_firewall_enabled == 1) {
2741  suri->is_firewall = true;
2742  } else {
2743  if (suri->is_firewall) {
2744  FatalError("firewall mode enabled through commandline, but disabled in config");
2745  }
2746  }
2747  }
2748  if (suri->is_firewall) {
2749  SCLogWarning("firewall mode is EXPERIMENTAL and subject to change");
2751  }
2752 
2753  /* load the pattern matchers */
2754  MpmTableSetup();
2755  SpmTableSetup();
2756 
2757  int disable_offloading;
2758  if (SCConfGetBool("capture.disable-offloading", &disable_offloading) == 0)
2759  disable_offloading = 1;
2760  if (disable_offloading) {
2762  } else {
2764  }
2765 
2766  if (suri->checksum_validation == -1) {
2767  const char *cv = NULL;
2768  if (SCConfGet("capture.checksum-validation", &cv) == 1) {
2769  if (strcmp(cv, "none") == 0) {
2770  suri->checksum_validation = 0;
2771  } else if (strcmp(cv, "all") == 0) {
2772  suri->checksum_validation = 1;
2773  }
2774  }
2775  }
2776  switch (suri->checksum_validation) {
2777  case 0:
2778  SCConfSet("stream.checksum-validation", "0");
2779  break;
2780  case 1:
2781  SCConfSet("stream.checksum-validation", "1");
2782  break;
2783  }
2784 
2785  if (suri->runmode_custom_mode) {
2786  SCConfSet("runmode", suri->runmode_custom_mode);
2787  }
2788 
2789  StorageInit();
2790 #ifdef HAVE_PACKET_EBPF
2791  if (suri->run_mode == RUNMODE_AFP_DEV) {
2792  EBPFRegisterExtension();
2794  }
2795 #endif
2797 
2800 
2801  SigTableInit();
2802 
2803 #ifdef HAVE_PLUGINS
2805 #endif
2806 
2807  LiveDeviceFinalize(); // must be after EBPF extension registration
2808 
2811  FatalError("IPS mode setup failed");
2812  }
2813 
2814  if (EngineModeIsUnknown()) { // if still uninitialized, set the default
2815  SCLogInfo("Setting engine mode to IDS mode by default");
2816  EngineModeSetIDS();
2817  }
2818 
2820 
2821  SCConfNode *eps = SCConfGetNode("stats.exception-policy");
2822  if (eps != NULL) {
2823  if (SCConfNodeChildValueIsTrue(eps, "per-app-proto-errors")) {
2825  }
2826  }
2827 
2828  /* Must occur prior to output mod registration
2829  and app layer setup. */
2831 
2832  AppLayerSetup();
2833 
2834  /* Suricata will use this umask if provided. By default it will use the
2835  umask passed on from the shell. */
2836  const char *custom_umask;
2837  if (SCConfGet("umask", &custom_umask) == 1) {
2838  uint16_t mask;
2839  if (StringParseUint16(&mask, 8, (uint16_t)strlen(custom_umask), custom_umask) > 0) {
2840  umask((mode_t)mask);
2841  }
2842  }
2843 
2844  if (ConfigGetCaptureValue(suri) != TM_ECODE_OK) {
2846  }
2847 
2848 #ifdef NFQ
2849  if (suri->run_mode == RUNMODE_NFQ)
2850  NFQInitConfig(false);
2851 #endif
2852 
2853  /* Load the Host-OS lookup. */
2855 
2856  if (suri->run_mode == RUNMODE_ENGINE_ANALYSIS) {
2857  SCLogInfo("== Carrying out Engine Analysis ==");
2858  const char *temp = NULL;
2859  if (SCConfGet("engine-analysis", &temp) == 0) {
2860  SCLogInfo("no engine-analysis parameter(s) defined in conf file. "
2861  "Please define/enable them in the conf to use this "
2862  "feature.");
2864  }
2865  }
2866 
2867  /* hardcoded initialization code */
2868  SigTableSetup(); /* load the rule keywords */
2870  TmqhSetup();
2871 
2872  TagInitCtx();
2874  ThresholdInit();
2875  HostBitInitCtx();
2876  IPPairBitInitCtx();
2877 
2878  if (DetectAddressTestConfVars() < 0) {
2879  SCLogError(
2880  "basic address vars test failed. Please check %s for errors", suri->conf_filename);
2882  }
2883  if (DetectPortTestConfVars() < 0) {
2884  SCLogError("basic port vars test failed. Please check %s for errors", suri->conf_filename);
2886  }
2887 
2890 
2891  StorageFinalize();
2892 
2893  TmModuleRunInit();
2894 
2895  if (MayDaemonize(suri) != TM_ECODE_OK)
2897 
2898  if (suri->install_signal_handlers) {
2899  if (InitSignalHandler(suri) != TM_ECODE_OK)
2901  }
2902 
2903  /* Check for the existence of the default logging directory which we pick
2904  * from suricata.yaml. If not found, shut the engine down */
2905  suri->log_dir = SCConfigGetLogDirectory();
2906 
2908  SCLogError("The logging directory \"%s\" "
2909  "supplied by %s (default-log-dir) doesn't exist. "
2910  "Shutting down the engine",
2911  suri->log_dir, suri->conf_filename);
2913  }
2914  if (!IsLogDirectoryWritable(suri->log_dir)) {
2915  SCLogError("The logging directory \"%s\" "
2916  "supplied by %s (default-log-dir) is not writable. "
2917  "Shutting down the engine",
2918  suri->log_dir, suri->conf_filename);
2920  }
2921 
2922  if (suri->disabled_detect) {
2923  SCLogConfig("detection engine disabled");
2924  /* disable raw reassembly */
2925  (void)SCConfSetFinal("stream.reassembly.raw", "false");
2926  }
2927 
2929 
2931 
2933 
2934  /* hostmode depends on engine mode being set */
2935  PostConfLoadedSetupHostMode();
2936 
2937  PreRunInit(suri->run_mode);
2938 
2940 }
2941 
2943 {
2944  SCInstance *suri = &suricata;
2945  while(1) {
2946  if (sigterm_count || sigint_count) {
2948  }
2949 
2951  SCLogNotice("Signal Received. Stopping engine.");
2952  break;
2953  }
2954 
2956 
2957  if (sighup_count > 0) {
2959  sighup_count--;
2960  }
2961 
2962  if (sigusr2_count > 0) {
2963  if (!(DetectEngineReloadIsStart())) {
2965  DetectEngineReload(suri);
2967  sigusr2_count--;
2968  }
2969 
2970  } else if (DetectEngineReloadIsStart()) {
2971  DetectEngineReload(suri);
2973  }
2974 
2975  usleep(10* 1000);
2976  }
2977 }
2978 
2979 /**
2980  * \brief Global initialization common to all runmodes.
2981  *
2982  * This can be used by fuzz targets.
2983  */
2984 
2985 int InitGlobal(void)
2986 {
2987  SC_ATOMIC_INIT(engine_stage);
2988 
2989  /* initialize the logging subsys */
2990  SCLogInitLogModule(NULL);
2991 
2992  SCSetThreadName("Suricata-Main");
2993 
2994  /* Ignore SIGUSR2 as early as possible. We redeclare interest
2995  * once we're done launching threads. The goal is to either die
2996  * completely or handle any and all SIGUSR2s correctly.
2997  */
2998 #ifndef OS_WIN32
2999  UtilSignalHandlerSetup(SIGUSR2, SIG_IGN);
3000  if (UtilSignalBlock(SIGUSR2)) {
3001  SCLogError("SIGUSR2 initialization error");
3002  return EXIT_FAILURE;
3003  }
3004 #endif
3005 
3006  ParseSizeInit();
3008 
3009  /* Initialize the configuration module. */
3010  SCConfInit();
3012 
3013  VarNameStoreInit();
3014 
3015  // zero all module storage
3016  memset(tmm_modules, 0, TMM_SIZE * sizeof(TmModule));
3017 
3018  return 0;
3019 }
3020 
3021 void SuricataPreInit(const char *progname)
3022 {
3023  SCInstanceInit(&suricata, progname);
3024 
3025  if (InitGlobal() != 0) {
3026  exit(EXIT_FAILURE);
3027  }
3028 }
3029 
3030 void SuricataInit(void)
3031 {
3032  /* Initializations for global vars, queues, etc (memsets, mutex init..) */
3034 
3036  SCConfDump();
3037  exit(EXIT_SUCCESS);
3038  }
3039 
3040  int tracking = 1;
3041  if (SCConfGetBool("vlan.use-for-tracking", &tracking) == 1 && !tracking) {
3042  /* Ignore vlan_ids when comparing flows. */
3043  g_vlan_mask = 0x0000;
3044  }
3045  SCLogDebug("vlan tracking is %s", tracking == 1 ? "enabled" : "disabled");
3046  if (SCConfGetBool("livedev.use-for-tracking", &tracking) == 1 && !tracking) {
3047  /* Ignore livedev id when comparing flows. */
3048  g_livedev_mask = 0x0000;
3049  }
3050  if (SCConfGetBool("decoder.recursion-level.use-for-tracking", &tracking) == 1 && !tracking) {
3051  /* Ignore recursion level when comparing flows. */
3052  g_recurlvl_mask = 0x00;
3053  }
3054  SetupUserMode(&suricata);
3055  InitRunAs(&suricata);
3056 
3057  /* Since our config is now loaded we can finish configurating the
3058  * logging module. */
3060 
3061  LogVersion(&suricata);
3064 
3066  SCLogInfo("Running suricata under test mode");
3067 
3068  if (suricata.verbose) {
3069  SCLogInfo("Running with verbose level %d", suricata.verbose);
3070  }
3071 
3072  if (ParseInterfacesList(suricata.aux_run_mode, suricata.pcap_dev) != TM_ECODE_OK) {
3073  exit(EXIT_FAILURE);
3074  }
3075 
3077  exit(EXIT_FAILURE);
3078  }
3079 
3081 
3082  /* Re-enable coredumps after privileges are dropped. */
3083  CoredumpEnable();
3084 
3087  }
3088 
3090 
3091  SCOnLoggingReady();
3092 
3094 
3097  goto out;
3098  } else if (suricata.run_mode == RUNMODE_CONF_TEST){
3099  SCLogNotice("Configuration provided was successfully loaded. Exiting.");
3100  goto out;
3101  } else if (suricata.run_mode == RUNMODE_DUMP_FEATURES) {
3102  FeatureDump();
3103  goto out;
3104  }
3105 
3108 
3109  SCSetStartTime(&suricata);
3112  }
3115  return;
3116 
3117 out:
3118  GlobalsDestroy();
3119  exit(EXIT_SUCCESS);
3120 }
3121 
3123 {
3124  /* Update the engine stage/status flag */
3125  SC_ATOMIC_SET(engine_stage, SURICATA_DEINIT);
3126 
3129  /* kill remaining threads */
3131 }
3132 
3134 {
3135  /* Wait till all the threads have been initialized */
3138  FatalError("Engine initialization failed, "
3139  "aborting...");
3140  }
3141 
3142  int limit_nproc = 0;
3143  if (SCConfGetBool("security.limit-noproc", &limit_nproc) == 0) {
3144  limit_nproc = 0;
3145  }
3146 
3147 #if defined(SC_ADDRESS_SANITIZER)
3148  if (limit_nproc) {
3149  SCLogWarning(
3150  "\"security.limit-noproc\" (setrlimit()) not set when using address sanitizer");
3151  limit_nproc = 0;
3152  }
3153 #endif
3154 
3155  if (limit_nproc) {
3156 #if defined(HAVE_SYS_RESOURCE_H)
3157 #ifdef linux
3158  if (geteuid() == 0) {
3159  SCLogWarning("setrlimit has no effect when running as root.");
3160  }
3161 #endif
3162  struct rlimit r = { 0, 0 };
3163  if (setrlimit(RLIMIT_NPROC, &r) != 0) {
3164  SCLogWarning("setrlimit failed to prevent process creation.");
3165  }
3166 #else
3167  SCLogWarning("setrlimit unavailable.");
3168 #endif
3169  }
3170 
3171  SC_ATOMIC_SET(engine_stage, SURICATA_RUNTIME);
3173 
3174  /* Un-pause all the paused threads */
3176 
3177  /* Must ensure all threads are fully operational before continuing with init process */
3180  exit(EXIT_FAILURE);
3181  }
3182 
3183  /* Print notice and send OS specific notification of threads in running state */
3184  OnNotifyRunning();
3185 
3186  PostRunStartedDetectSetup(&suricata);
3187  if (suricata.run_mode == RUNMODE_DPDK) { // only DPDK uses hpages at the moment
3191  SystemHugepageSnapshotDestroy(postrun_snap);
3192  }
3193  SCPledge();
3194 }
RUNMODE_LIST_APP_LAYERS
@ RUNMODE_LIST_APP_LAYERS
Definition: runmodes.h:47
SCRunMode
enum SCRunModes SCRunMode
RUNMODE_ENGINE_ANALYSIS
@ RUNMODE_ENGINE_ANALYSIS
Definition: runmodes.h:57
util-device-private.h
DefragDestroy
void DefragDestroy(void)
Definition: defrag.c:1129
util-byte.h
SCInstance_::is_firewall
bool is_firewall
Definition: suricata.h:145
TmModuleUnixManagerRegister
void TmModuleUnixManagerRegister(void)
Definition: unix-manager.c:1289
StatsReleaseResources
void StatsReleaseResources(void)
Releases the resources allotted by the Stats API.
Definition: counters.c:1313
source-nflog.h
TagInitCtx
void TagInitCtx(void)
Definition: detect-engine-tag.c:52
TmModuleReceiveIPFWRegister
void TmModuleReceiveIPFWRegister(void)
Registration Function for RecieveIPFW.
Definition: source-ipfw.c:151
flow-bypass.h
len
uint8_t len
Definition: app-layer-dnp3.h:2
SuricataMainLoop
void SuricataMainLoop(void)
Definition: suricata.c:2942
ExceptionSimulationCommandLineParser
int ExceptionSimulationCommandLineParser(const char *name, const char *arg)
Definition: util-exception-policy.c:395
SCInstance_::run_mode
enum SCRunModes run_mode
Definition: suricata.h:134
ippair.h
g_livedev_mask
uint16_t g_livedev_mask
Definition: suricata.c:209
SCInstance_::firewall_rule_file
char * firewall_rule_file
Definition: suricata.h:142
RUNMODE_AFXDP_DEV
@ RUNMODE_AFXDP_DEV
Definition: runmodes.h:37
app-layer-htp-range.h
AppLayerHtpNeedFileInspection
void AppLayerHtpNeedFileInspection(void)
Sets a flag that informs the HTP app layer that some module in the engine needs the http request file...
Definition: app-layer-htp.c:575
detect-engine.h
source-pcap.h
SCInstance_::groupid
uint32_t groupid
Definition: suricata.h:156
g_system
bool g_system
Definition: suricata.c:194
TmThreadDisablePacketThreads
void TmThreadDisablePacketThreads(const uint16_t set, const uint16_t check, const uint8_t module_flags)
Disable all packet threads.
Definition: tm-threads.c:1536
win32-syscall.h
SCInstance_::aux_run_mode
enum SCRunModes aux_run_mode
Definition: suricata.h:135
SCInstance_::daemon
int daemon
Definition: suricata.h:167
IPPairInitConfig
void IPPairInitConfig(bool quiet)
initialize the configuration
Definition: ippair.c:162
SCLogInitLogModule
void SCLogInitLogModule(SCLogInitData *sc_lid)
Initializes the logging module.
Definition: util-debug.c:1391
SLL_HEADER_LEN
#define SLL_HEADER_LEN
Definition: decode-sll.h:27
SCInstance_::checksum_validation
int checksum_validation
Definition: suricata.h:170
SCEnableDefaultSignalHandlers
void SCEnableDefaultSignalHandlers(void)
Enable default signal handlers.
Definition: suricata.c:292
LiveDeviceListClean
int LiveDeviceListClean(void)
Definition: util-device.c:334
SCInstance_::do_setuid
bool do_setuid
Definition: suricata.h:152
DetectEngineDeReference
void DetectEngineDeReference(DetectEngineCtx **de_ctx)
Definition: detect-engine.c:4640
StorageInit
void StorageInit(void)
Definition: util-storage.c:70
SCInstance_::start_time
struct timeval start_time
Definition: suricata.h:173
IsRunModeOffline
bool IsRunModeOffline(enum SCRunModes run_mode_to_check)
Definition: runmodes.c:561
SC_ATOMIC_INIT
#define SC_ATOMIC_INIT(name)
wrapper for initializing an atomic variable.
Definition: util-atomic.h:314
prerun_snap
SystemHugepageSnapshot * prerun_snap
Definition: suricata.c:220
TmThreadContinueThreads
void TmThreadContinueThreads(void)
Unpauses all threads present in tv_root.
Definition: tm-threads.c:1968
RUNMODE_NFLOG
@ RUNMODE_NFLOG
Definition: runmodes.h:32
source-pcap-file.h
SCInstance_::do_setgid
bool do_setgid
Definition: suricata.h:153
CLS
#define CLS
Definition: suricata-common.h:69
stream-tcp.h
DetectEngineCtx_::type
enum DetectEngineType type
Definition: detect.h:1054
SigLoadSignatures
int SigLoadSignatures(DetectEngineCtx *de_ctx, char *sig_file, bool sig_file_exclusive)
Load signatures.
Definition: detect-engine-loader.c:372
runmode-af-packet.h
SCInstance_::group_name
const char * group_name
Definition: suricata.h:151
DetectEngineCtx_::firewall_rule_file_exclusive
const char * firewall_rule_file_exclusive
Definition: detect.h:1145
unlikely
#define unlikely(expr)
Definition: util-optimize.h:35
SC_ATOMIC_SET
#define SC_ATOMIC_SET(name, val)
Set the value for the atomic variable.
Definition: util-atomic.h:386
runmode-unittests.h
RUNMODE_UNKNOWN
@ RUNMODE_UNKNOWN
Definition: runmodes.h:28
TmqhSetup
void TmqhSetup(void)
Definition: tm-queuehandlers.c:39
TVT_PPT
@ TVT_PPT
Definition: tm-threads-common.h:88
SCConfGetRootNode
SCConfNode * SCConfGetRootNode(void)
Get the root configuration node.
Definition: conf.c:222
ENGINE_MODE_FIREWALL
@ ENGINE_MODE_FIREWALL
Definition: suricata.h:111
DetectEngineCtxInitStubForDD
DetectEngineCtx * DetectEngineCtxInitStubForDD(void)
Definition: detect-engine.c:2590
LiveDevRegisterExtension
void LiveDevRegisterExtension(void)
Definition: util-device.c:485
OutputTxShutdown
void OutputTxShutdown(void)
Definition: output-tx.c:667
THV_FLOW_LOOP
#define THV_FLOW_LOOP
Definition: threadvars.h:48
SCLogDebug
#define SCLogDebug(...)
Definition: util-debug.h:279
AppLayerHtpPrintStats
void AppLayerHtpPrintStats(void)
Definition: app-layer-htp.c:2422
util-hugepages.h
StatsSetupPostConfigPreOutput
void StatsSetupPostConfigPreOutput(void)
Definition: counters.c:935
SCInstance_::runmode_custom_mode
char * runmode_custom_mode
Definition: suricata.h:148
util-coredump-config.h
next
struct HtpBodyChunk_ * next
Definition: app-layer-htp.h:0
SigTableSetup
void SigTableSetup(void)
Definition: detect-engine-register.c:549
name
const char * name
Definition: detect-engine-proto.c:48
TmModuleReceiveNFQRegister
void TmModuleReceiveNFQRegister(void)
Definition: source-nfq.c:170
LiveBuildDeviceList
int LiveBuildDeviceList(const char *runmode)
Definition: util-device.c:294
RunModeShutDown
void RunModeShutDown(void)
Definition: runmodes.c:579
SuricataInit
void SuricataInit(void)
Definition: suricata.c:3030
TM_ECODE_DONE
@ TM_ECODE_DONE
Definition: tm-threads-common.h:83
SCProtoNameInit
void SCProtoNameInit(void)
Definition: util-proto-name.c:417
SuricataPostInit
void SuricataPostInit(void)
Definition: suricata.c:3133
ippair-bit.h
RunModeDispatch
void RunModeDispatch(int runmode, const char *custom_mode, const char *capture_plugin_name, const char *capture_plugin_args)
Definition: runmodes.c:409
util-macset.h
sigint_count
volatile sig_atomic_t sigint_count
Definition: suricata.c:156
SC_ATOMIC_DECLARE
SC_ATOMIC_DECLARE(unsigned int, engine_stage)
RUNMODE_NFQ
@ RUNMODE_NFQ
Definition: runmodes.h:31
TmModuleRunDeInit
void TmModuleRunDeInit(void)
Definition: tm-modules.c:119
TmThreadsUnsealThreads
void TmThreadsUnsealThreads(void)
Definition: tm-threads.c:2159
RegisterFlowBypassInfo
void RegisterFlowBypassInfo(void)
Definition: flow-util.c:240
SCSetThreadName
#define SCSetThreadName(n)
Definition: threads.h:305
SCConfYamlHandleInclude
int SCConfYamlHandleInclude(SCConfNode *parent, const char *filename)
Include a file in the configuration.
Definition: conf-yaml-loader.c:115
sc_set_caps
bool sc_set_caps
Definition: suricata.c:192
SCLogDeInitLogModule
void SCLogDeInitLogModule(void)
De-Initializes the logging module.
Definition: util-debug.c:1595
LiveDevice_
Definition: util-device-private.h:32
util-pidfile.h
TmModuleDecodeErfFileRegister
void TmModuleDecodeErfFileRegister(void)
Register the ERF file decoder module.
Definition: source-erf-file.c:98
DetectEngineCtx_
main detection engine ctx
Definition: detect.h:933
StringParseUint16
int StringParseUint16(uint16_t *res, int base, size_t len, const char *str)
Definition: util-byte.c:296
SigTableInit
void SigTableInit(void)
Definition: detect-engine-register.c:537
DetectEngineReloadSetIdle
void DetectEngineReloadSetIdle(void)
Definition: detect-engine.c:1914
SCInstance_::userid
uint32_t userid
Definition: suricata.h:155
source-windivert-prototypes.h
SCConfGet
int SCConfGet(const char *name, const char **vptr)
Retrieve the value of a configuration node.
Definition: conf.c:350
DetectEngineGetCurrent
DetectEngineCtx * DetectEngineGetCurrent(void)
Definition: detect-engine.c:3838
EngineModeIsUnknown
int EngineModeIsUnknown(void)
Definition: suricata.c:233
VarNameStoreInit
void VarNameStoreInit(void)
TmModuleFlowRecyclerRegister
void TmModuleFlowRecyclerRegister(void)
Definition: flow-manager.c:1313
g_skip_prefilter
int g_skip_prefilter
Definition: detect-engine-mpm.c:1121
SCConfNodeChildValueIsTrue
int SCConfNodeChildValueIsTrue(const SCConfNode *node, const char *key)
Test if a configuration node has a true value.
Definition: conf.c:868
Daemonize
void Daemonize(void)
Daemonize the process.
Definition: util-daemon.c:101
UtilSignalHandlerSetup
void UtilSignalHandlerSetup(int sig, void(*handler)(int))
Definition: util-signal.c:60
TAILQ_FOREACH
#define TAILQ_FOREACH(var, head, field)
Definition: queue.h:252
TmModuleDecodeAFPRegister
void TmModuleDecodeAFPRegister(void)
Registration Function for DecodeAFP.
Definition: source-af-packet.c:599
TmModuleDecodeWinDivertRegister
void TmModuleDecodeWinDivertRegister(void)
Definition: source-windivert.c:75
SURICATA_STOP
#define SURICATA_STOP
Definition: suricata.h:94
DetectEngineAddToMaster
int DetectEngineAddToMaster(DetectEngineCtx *de_ctx)
Definition: detect-engine.c:4664
SCConfGetChildValueBool
int SCConfGetChildValueBool(const SCConfNode *base, const char *name, int *val)
Definition: conf.c:515
TmModuleStatsLoggerRegister
void TmModuleStatsLoggerRegister(void)
Definition: output-stats.c:169
RegisterAllModules
void RegisterAllModules(void)
Definition: suricata.c:951
ENGINE_MODE_IPS
@ ENGINE_MODE_IPS
Definition: suricata.h:110
DetectEngineMultiTenantSetup
int DetectEngineMultiTenantSetup(const bool unix_socket)
setup multi-detect / multi-tenancy
Definition: detect-engine.c:4298
flow-bit.h
SupportFastPatternForSigMatchTypes
void SupportFastPatternForSigMatchTypes(void)
Registers the keywords(SMs) that should be given fp support.
Definition: detect-fast-pattern.c:142
util-var-name.h
SCParseCommandLine
TmEcode SCParseCommandLine(int argc, char **argv)
Definition: suricata.c:1373
SCPledge
#define SCPledge(...)
Definition: util-privs.h:99
CheckValidDaemonModes
int CheckValidDaemonModes(int daemon, int mode)
Check for a valid combination daemon/mode.
Definition: util-daemon.c:177
SCGetGroupID
void SCGetGroupID(const char *group_name, uint32_t *gid)
Function to get the group ID from the specified group name.
Definition: util-privs.c:210
SCConfGetBool
int SCConfGetBool(const char *name, int *val)
Retrieve a configuration value as a boolean.
Definition: conf.c:497
unittests_fatal
int unittests_fatal
Definition: util-unittest.c:52
TmThreadDisableReceiveThreads
void TmThreadDisableReceiveThreads(void)
Disable all threads having the specified TMs.
Definition: tm-threads.c:1385
StatsInit
void StatsInit(void)
Initializes the perf counter api. Things are hard coded currently. More work to be done when we imple...
Definition: counters.c:925
util-privs.h
PreRunInit
void PreRunInit(const int runmode)
Definition: suricata.c:2300
TVT_MGMT
@ TVT_MGMT
Definition: tm-threads-common.h:89
SURICATA_DONE
#define SURICATA_DONE
Definition: suricata.h:96
MacSetRegisterFlowStorage
void MacSetRegisterFlowStorage(void)
Definition: util-macset.c:62
EngineModeSetFirewall
void EngineModeSetFirewall(void)
Definition: suricata.c:257
SuricataShutdown
void SuricataShutdown(void)
Definition: suricata.c:3122
SCInstance_::conf_filename
const char * conf_filename
Definition: suricata.h:177
GetIfaceMTU
int GetIfaceMTU(const char *dev)
output the link MTU
Definition: util-ioctl.c:82
GlobalsInitPreConfig
void GlobalsInitPreConfig(void)
Definition: suricata.c:385
TmModuleReceiveNetmapRegister
void TmModuleReceiveNetmapRegister(void)
Definition: source-netmap.c:75
PacketPoolPostRunmodes
void PacketPoolPostRunmodes(void)
Set the max_pending_return_packets value.
Definition: tmqh-packetpool.c:450
NFQInitConfig
void NFQInitConfig(bool quiet)
To initialize the NFQ global configuration data.
Definition: source-nfq.c:208
TmModuleReceiveWinDivertRegister
void TmModuleReceiveWinDivertRegister(void)
Definition: source-windivert.c:61
SystemHugepageSnapshot
Definition: util-hugepages.h:44
EngineModeIsFirewall
bool EngineModeIsFirewall(void)
Definition: suricata.c:238
REVISION
#define REVISION
Definition: suricata-common.h:61
HOST_VERBOSE
#define HOST_VERBOSE
Definition: host.h:92
TM_ECODE_FAILED
@ TM_ECODE_FAILED
Definition: tm-threads-common.h:82
SCProfilingDestroy
void SCProfilingDestroy(void)
Free resources used by profiling.
Definition: util-profiling.c:276
AFPPeersListClean
void AFPPeersListClean(void)
Clean the global peers list.
Definition: source-af-packet.c:581
RunModeInitializeOutputs
void RunModeInitializeOutputs(void)
Definition: runmodes.c:772
DetectPortTestConfVars
int DetectPortTestConfVars(void)
Definition: detect-engine-port.c:1109
SCThresholdConfGlobalInit
void SCThresholdConfGlobalInit(void)
Definition: util-threshold-config.c:102
DecodeUnregisterCounters
void DecodeUnregisterCounters(void)
Definition: decode.c:606
SCInstance_::capture_plugin_name
const char * capture_plugin_name
Definition: suricata.h:181
SCConfYamlLoadFile
int SCConfYamlLoadFile(const char *filename)
Load configuration from a YAML file.
Definition: conf-yaml-loader.c:489
HostBitInitCtx
void HostBitInitCtx(void)
Definition: host-bit.c:49
EngineMode
EngineMode
Definition: suricata.h:106
SCInstance_::set_datadir
bool set_datadir
Definition: suricata.h:160
tmqh-packetpool.h
IsRunModeSystem
bool IsRunModeSystem(enum SCRunModes run_mode_to_check)
Definition: runmodes.c:548
g_ut_covered
int g_ut_covered
Definition: suricata.c:949
SCInstance_::capture_plugin_args
const char * capture_plugin_args
Definition: suricata.h:182
g_recurlvl_mask
uint8_t g_recurlvl_mask
Definition: suricata.c:213
TmModuleLoggerRegister
void TmModuleLoggerRegister(void)
Definition: output.c:925
host_mode
uint8_t host_mode
Definition: suricata.c:183
SURI_HOST_IS_ROUTER
@ SURI_HOST_IS_ROUTER
Definition: suricata.h:126
FeatureDump
void FeatureDump(void)
Definition: feature.c:144
PacketPoolInit
void PacketPoolInit(void)
Definition: tmqh-packetpool.c:235
TM_ECODE_OK
@ TM_ECODE_OK
Definition: tm-threads-common.h:81
AppLayerDeSetup
int AppLayerDeSetup(void)
De initializes the app layer.
Definition: app-layer.c:1091
RUNMODE_LIST_APP_LAYER_HOOKS
@ RUNMODE_LIST_APP_LAYER_HOOKS
Definition: runmodes.h:49
RUNMODE_UNIX_SOCKET
@ RUNMODE_UNIX_SOCKET
Definition: runmodes.h:42
strlcpy
size_t strlcpy(char *dst, const char *src, size_t siz)
Definition: util-strlcpyu.c:43
PcapTranslateIPToDevice
void PcapTranslateIPToDevice(char *pcap_dev, size_t len)
Definition: source-pcap.c:651
FlowDisableFlowRecyclerThread
void FlowDisableFlowRecyclerThread(void)
Used to disable flow recycler thread(s).
Definition: flow-manager.c:1241
SCRunmodeSet
void SCRunmodeSet(SCRunMode run_mode)
Set the current run mode.
Definition: suricata.c:287
ParseSizeInit
void ParseSizeInit(void)
Definition: util-misc.c:36
TmModuleDecodePcapFileRegister
void TmModuleDecodePcapFileRegister(void)
Definition: source-pcap-file.c:129
TmModuleBypassedFlowManagerRegister
void TmModuleBypassedFlowManagerRegister(void)
Definition: flow-bypass.c:220
IPPairShutdown
void IPPairShutdown(void)
shutdown the flow engine
Definition: ippair.c:290
source-erf-dag.h
THV_RUNNING_DONE
#define THV_RUNNING_DONE
Definition: threadvars.h:46
SCConfInit
void SCConfInit(void)
Initialize the configuration system.
Definition: conf.c:120
util-signal.h
DetectParseFreeRegexes
void DetectParseFreeRegexes(void)
Definition: detect-parse.c:3521
SCConfDump
void SCConfDump(void)
Dump configuration to stdout.
Definition: conf.c:761
TmModuleDecodeNFLOGRegister
void TmModuleDecodeNFLOGRegister(void)
Definition: source-nflog.c:55
NFQParseAndRegisterQueues
int NFQParseAndRegisterQueues(const char *queues)
Parses and adds Netfilter queue(s).
Definition: source-nfq.c:881
RUNMODE_NETMAP
@ RUNMODE_NETMAP
Definition: runmodes.h:38
FlowInitConfig
void FlowInitConfig(bool quiet)
initialize the configuration
Definition: flow.c:549
AppLayerSetup
int AppLayerSetup(void)
Setup the app layer.
Definition: app-layer.c:1074
FeatureTrackingRegister
void FeatureTrackingRegister(void)
Definition: feature.c:152
TmModuleReceiveDPDKRegister
void TmModuleReceiveDPDKRegister(void)
Definition: source-dpdk.c:51
UnixManagerThreadSpawnNonRunmode
void UnixManagerThreadSpawnNonRunmode(const bool unix_socket_enabled)
Definition: unix-manager.c:1283
RunModeInitializeThreadSettings
void RunModeInitializeThreadSettings(void)
Definition: runmodes.c:957
StreamTcpInitConfig
void StreamTcpInitConfig(bool)
To initialize the stream global configuration data.
Definition: stream-tcp.c:496
ENGINE_MODE_UNKNOWN
@ ENGINE_MODE_UNKNOWN
Definition: suricata.h:107
app-layer-htp.h
util-flow-rate.h
datasets.h
GetIfaceMaxPacketSize
int GetIfaceMaxPacketSize(LiveDevice *ld)
output max packet size for a link
Definition: util-ioctl.c:121
SCRunmodeGet
SCRunMode SCRunmodeGet(void)
Get the current run mode.
Definition: suricata.c:282
TmModuleDecodeNetmapRegister
void TmModuleDecodeNetmapRegister(void)
Registration Function for DecodeNetmap.
Definition: source-netmap.c:85
PreRunPostPrivsDropInit
void PreRunPostPrivsDropInit(const int runmode)
Definition: suricata.c:2329
feature.h
decode.h
SigTableCleanup
void SigTableCleanup(void)
Definition: detect-engine-register.c:497
DetectEngineMoveToFreeList
int DetectEngineMoveToFreeList(DetectEngineCtx *de_ctx)
Definition: detect-engine.c:4724
sigterm_count
volatile sig_atomic_t sigterm_count
Definition: suricata.c:158
source-nfq.h
de_ctx
DetectEngineCtx * de_ctx
Definition: fuzz_siginit.c:18
TmThreadWaitOnThreadInit
TmEcode TmThreadWaitOnThreadInit(void)
Used to check if all threads have finished their initialization. On finding an un-initialized thread,...
Definition: tm-threads.c:2007
TmModuleVerdictNFQRegister
void TmModuleVerdictNFQRegister(void)
Definition: source-nfq.c:185
SURICATA_RUNTIME
@ SURICATA_RUNTIME
Definition: suricata.h:101
AppLayerRegisterGlobalCounters
void AppLayerRegisterGlobalCounters(void)
HACK to work around our broken unix manager (re)init loop.
Definition: app-layer.c:1155
RunModeListRunmodes
void RunModeListRunmodes(void)
Lists all registered runmodes.
Definition: runmodes.c:257
strlcat
size_t strlcat(char *, const char *src, size_t siz)
Definition: util-strlcatu.c:45
util-cpu.h
suricata
SCInstance suricata
Definition: suricata.c:226
SCInstance_::unix_socket_enabled
bool unix_socket_enabled
Definition: suricata.h:161
LiveSetOffloadDisable
void LiveSetOffloadDisable(void)
Definition: util-device.c:77
StatsSetupPostConfigPostOutput
void StatsSetupPostConfigPostOutput(void)
Definition: counters.c:940
EngineModeSetIDS
void EngineModeSetIDS(void)
Definition: suricata.c:267
RUNMODE_LIST_KEYWORDS
@ RUNMODE_LIST_KEYWORDS
Definition: runmodes.h:46
SpmTableSetup
void SpmTableSetup(void)
Definition: util-spm.c:122
TmModuleReceiveAFPRegister
void TmModuleReceiveAFPRegister(void)
Registration Function for RecieveAFP.
Definition: source-af-packet.c:381
RUNMODE_UNITTEST
@ RUNMODE_UNITTEST
Definition: runmodes.h:41
LiveBuildDeviceListCustom
int LiveBuildDeviceListCustom(const char *runmode, const char *itemname)
Definition: util-device.c:299
util-exception-policy.h
LiveGetDevice
LiveDevice * LiveGetDevice(const char *name)
Get a pointer to the device at idx.
Definition: util-device.c:268
UnixSocketKillSocketThread
void UnixSocketKillSocketThread(void)
Definition: unix-manager.c:1279
TmModuleVerdictIPFWRegister
void TmModuleVerdictIPFWRegister(void)
Registration Function for VerdictIPFW.
Definition: source-ipfw.c:172
flow-worker.h
SCConfGetInt
int SCConfGetInt(const char *name, intmax_t *val)
Retrieve a configuration value as an integer.
Definition: conf.c:414
g_stats_eps_per_app_proto_errors
bool g_stats_eps_per_app_proto_errors
Definition: suricata.c:223
HttpRangeContainersInit
void HttpRangeContainersInit(void)
Definition: app-layer-htp-range.c:172
util-reference-config.h
DetectEngineCtx_::last_reload
struct timeval last_reload
Definition: detect.h:1100
SCInstance_::delayed_detect
int delayed_detect
Definition: suricata.h:165
TmModuleVerdictWinDivertRegister
void TmModuleVerdictWinDivertRegister(void)
Definition: source-windivert.c:68
DetectEngineCtx_::failure_fatal
bool failure_fatal
Definition: detect.h:934
SCInstance_::progname
const char * progname
Definition: suricata.h:176
HostCleanup
void HostCleanup(void)
Cleanup the host engine.
Definition: host.c:332
SCEnter
#define SCEnter(...)
Definition: util-debug.h:281
FlowDisableFlowManagerThread
void FlowDisableFlowManagerThread(void)
Used to disable flow manager thread(s).
Definition: flow-manager.c:133
RUNMODE_DAG
@ RUNMODE_DAG
Definition: runmodes.h:35
util-ebpf.h
SCInstance_::pcap_dev
char pcap_dev[128]
Definition: suricata.h:137
detect.h
util-affinity.h
UtilSignalUnblock
int UtilSignalUnblock(int signum)
Definition: util-signal.c:46
DetectEngineEnabled
int DetectEngineEnabled(void)
Check if detection is enabled.
Definition: detect-engine.c:3805
TmThreadClearThreadsFamily
void TmThreadClearThreadsFamily(int family)
Definition: tm-threads.c:1677
THV_KILL
#define THV_KILL
Definition: threadvars.h:40
THV_REQ_FLOW_LOOP
#define THV_REQ_FLOW_LOOP
Definition: threadvars.h:47
FlowRateRegisterFlowStorage
void FlowRateRegisterFlowStorage(void)
Definition: util-flow-rate.c:60
TmModuleRunInit
void TmModuleRunInit(void)
Definition: tm-modules.c:104
detect-engine-port.h
EngineModeSetIPS
void EngineModeSetIPS(void)
Definition: suricata.c:262
SCInstance_::user_name
const char * user_name
Definition: suricata.h:150
HTPAtExitPrintStats
void HTPAtExitPrintStats(void)
Print the stats of the HTTP requests.
Definition: app-layer-htp.c:1578
util-time.h
UtilSignalBlock
int UtilSignalBlock(int signum)
Definition: util-signal.c:29
SCProfilingPrefilterGlobalInit
void SCProfilingPrefilterGlobalInit(void)
Definition: util-profiling-prefilter.c:61
ThresholdDestroy
void ThresholdDestroy(void)
Definition: detect-engine-threshold.c:71
SCLogWarning
#define SCLogWarning(...)
Macro used to log WARNING messages.
Definition: util-debug.h:259
PostConfLoadedSetup
int PostConfLoadedSetup(SCInstance *suri)
Definition: suricata.c:2736
GetProgramVersion
const char * GetProgramVersion(void)
get string with program version
Definition: suricata.c:1190
engine_analysis
int engine_analysis
app-layer-parser.h
TmModuleReceivePcapFileRegister
void TmModuleReceivePcapFileRegister(void)
Definition: source-pcap-file.c:116
BUG_ON
#define BUG_ON(x)
Definition: suricata-common.h:317
runmode-netmap.h
CoredumpLoadConfig
int32_t CoredumpLoadConfig(void)
Configures the core dump size.
Definition: util-coredump-config.c:95
detect-engine-tag.h
IPFWRegisterQueue
int IPFWRegisterQueue(char *queue)
Add an IPFW divert.
Definition: source-ipfw.c:700
xstr
#define xstr(s)
Definition: suricata-common.h:307
util-profiling.h
ListAppLayerHooks
int ListAppLayerHooks(const char *conf_filename)
Definition: util-running-modes.c:83
ListAppLayerProtocols
int ListAppLayerProtocols(const char *conf_filename)
Definition: util-running-modes.c:46
SCInstance_::offline
int offline
Definition: suricata.h:168
DatasetsDestroy
void DatasetsDestroy(void)
Definition: datasets.c:774
UtilCpuPrintSummary
void UtilCpuPrintSummary(void)
Print a summary of CPUs detected (configured and online)
Definition: util-cpu.c:140
profiling_packets_enabled
int profiling_packets_enabled
Definition: util-profiling.c:94
SystemDNotifyReady
int SystemDNotifyReady(void)
TmThreadKillThreads
void TmThreadKillThreads(void)
Definition: tm-threads.c:1623
OutputDeregisterAll
void OutputDeregisterAll(void)
Deregister all modules. Useful for a memory clean exit.
Definition: output.c:658
source-pcap-file-helper.h
PostConfLoadedDetectSetup
void PostConfLoadedDetectSetup(SCInstance *suri)
Definition: suricata.c:2645
EngineModeIsIDS
int EngineModeIsIDS(void)
Definition: suricata.c:251
RUNMODE_PLUGIN
@ RUNMODE_PLUGIN
Definition: runmodes.h:44
util-systemd.h
tmm_modules
TmModule tmm_modules[TMM_SIZE]
Definition: tm-modules.c:29
conf-yaml-loader.h
decode-sll.h
SCConfigGetLogDirectory
const char * SCConfigGetLogDirectory(void)
Definition: util-conf.c:38
coverage_unittests
int coverage_unittests
Definition: suricata.c:947
DatasetsSave
void DatasetsSave(void)
Definition: datasets.c:852
detect-engine-alert.h
conf.h
util-landlock.h
source-ipfw.h
TMM_SIZE
@ TMM_SIZE
Definition: tm-threads-common.h:76
source-netmap.h
OutputNotifyFileRotation
void OutputNotifyFileRotation(void)
Notifies all registered file rotation notification flags.
Definition: output.c:735
RUNMODE_WINDIVERT
@ RUNMODE_WINDIVERT
Definition: runmodes.h:43
StorageFinalize
int StorageFinalize(void)
Definition: util-storage.c:140
VarNameStoreDestroy
void VarNameStoreDestroy(void)
Definition: util-var-name.c:116
SCInstance_::verbose
int verbose
Definition: suricata.h:169
source-lib.h
TmEcode
TmEcode
Definition: tm-threads-common.h:80
source-windivert.h
TmModuleFlowWorkerRegister
void TmModuleFlowWorkerRegister(void)
Definition: flow-worker.c:816
max_pending_packets
uint32_t max_pending_packets
Definition: suricata.c:186
util-plugin.h
SCInstance_::additional_configs
const char ** additional_configs
Definition: suricata.h:178
flow-timeout.h
DEFAULT_PID_FILENAME
#define DEFAULT_PID_FILENAME
Definition: suricata.h:88
RUNMODE_AFP_DEV
@ RUNMODE_AFP_DEV
Definition: runmodes.h:36
sighup_count
volatile sig_atomic_t sighup_count
Definition: suricata.c:157
ConfigSetDataDirectory
TmEcode ConfigSetDataDirectory(char *name)
Definition: util-conf.c:66
TmModuleDecodeErfDagRegister
void TmModuleDecodeErfDagRegister(void)
Register the ERF file decoder module.
Definition: source-erf-dag.c:151
SCInstance_::set_logdir
bool set_logdir
Definition: suricata.h:159
SCDropMainThreadCaps
#define SCDropMainThreadCaps(...)
Definition: util-privs.h:90
TmModuleDebugList
void TmModuleDebugList(void)
Definition: tm-modules.c:31
TmModuleDecodeNFQRegister
void TmModuleDecodeNFQRegister(void)
Definition: source-nfq.c:194
util-proto-name.h
STREAM_VERBOSE
#define STREAM_VERBOSE
Definition: stream-tcp.h:35
defrag.h
SCProtoNameRelease
void SCProtoNameRelease(void)
Definition: util-proto-name.c:438
MpmTableSetup
void MpmTableSetup(void)
Definition: util-mpm.c:224
SCInstance_::log_dir
const char * log_dir
Definition: suricata.h:175
RunmodeIsUnittests
int RunmodeIsUnittests(void)
Definition: suricata.c:273
source-nfq-prototypes.h
SCPluginsLoad
void SCPluginsLoad(const char *capture_plugin_name, const char *capture_plugin_args)
SCLogInfo
#define SCLogInfo(...)
Macro used to log INFORMATIONAL messages.
Definition: util-debug.h:229
TmModuleReceiveNFLOGRegister
void TmModuleReceiveNFLOGRegister(void)
Definition: source-nflog.c:49
DEFAULT_PACKET_SIZE
#define DEFAULT_PACKET_SIZE
Definition: decode.h:699
WarnInvalidConfEntry
#define WarnInvalidConfEntry(param_name, format, value)
Generic API that can be used by all to log an invalid conf entry.
Definition: util-misc.h:35
TM_FLAG_RECEIVE_TM
#define TM_FLAG_RECEIVE_TM
Definition: tm-modules.h:32
util-host-os-info.h
TmModuleReceiveErfFileRegister
void TmModuleReceiveErfFileRegister(void)
Register the ERF file receiver (reader) module.
Definition: source-erf-file.c:80
SCConfSetFromString
int SCConfSetFromString(const char *input, int final)
Set a configuration parameter from a string.
Definition: conf.c:264
RUNMODE_PRINT_USAGE
@ RUNMODE_PRINT_USAGE
Definition: runmodes.h:53
SCConfSetFinal
int SCConfSetFinal(const char *name, const char *val)
Set a final configuration value.
Definition: conf.c:318
TmModule_
Definition: tm-modules.h:47
SCRealloc
#define SCRealloc(ptr, sz)
Definition: util-mem.h:50
TmModuleDecodeAFXDPRegister
void TmModuleDecodeAFXDPRegister(void)
Registration Function for DecodeAFXDP.
Definition: source-af-xdp.c:91
default_packet_size
uint32_t default_packet_size
Definition: decode.c:77
tm-queuehandlers.h
SigTableApplyStrictCommandLineOption
void SigTableApplyStrictCommandLineOption(const char *str)
Definition: detect-parse.c:344
SURI_HOST_IS_SNIFFER_ONLY
@ SURI_HOST_IS_SNIFFER_ONLY
Definition: suricata.h:125
DETECT_ENGINE_TYPE_NORMAL
@ DETECT_ENGINE_TYPE_NORMAL
Definition: detect.h:903
PROG_NAME
#define PROG_NAME
Definition: suricata.h:75
TmThreadKillThreadsFamily
void TmThreadKillThreadsFamily(int family)
Definition: tm-threads.c:1594
detect-fast-pattern.h
FeatureTrackingRelease
void FeatureTrackingRelease(void)
Definition: feature.c:136
TmqhCleanup
void TmqhCleanup(void)
Clean up registration time allocs.
Definition: tm-queuehandlers.c:49
util-dpdk.h
util-conf.h
StreamTcpFreeConfig
void StreamTcpFreeConfig(bool quiet)
Definition: stream-tcp.c:867
source-dpdk.h
flow-manager.h
DecodeGlobalConfig
void DecodeGlobalConfig(void)
Definition: decode.c:1062
SCInstance_::strict_rule_parsing_string
char * strict_rule_parsing_string
Definition: suricata.h:179
SuriHasSigFile
int SuriHasSigFile(void)
Definition: suricata.c:228
suricata-common.h
DetectEngineCtxInitStubForMT
DetectEngineCtx * DetectEngineCtxInitStubForMT(void)
Definition: detect-engine.c:2585
util-path.h
util-daemon.h
LiveGetDeviceName
const char * LiveGetDeviceName(int number)
Get a pointer to the device name at idx.
Definition: util-device.c:204
VERBOSE_MAX
#define VERBOSE_MAX
Definition: suricata.c:172
FlowShutdown
void FlowShutdown(void)
shutdown the flow engine
Definition: flow.c:693
SCHInfoLoadFromConfig
void SCHInfoLoadFromConfig(void)
Load the host os policy information from the configuration.
Definition: util-host-os-info.c:281
DetectEngineBumpVersion
void DetectEngineBumpVersion(void)
Definition: detect-engine.c:3829
source-af-xdp.h
TmModuleFlowManagerRegister
void TmModuleFlowManagerRegister(void)
Definition: flow-manager.c:1299
SCStartInternalRunMode
int SCStartInternalRunMode(int argc, char **argv)
Definition: suricata.c:2403
SCPidfileTestRunning
int SCPidfileTestRunning(const char *pid_filename)
Check the Suricata pid file (used at the startup)
Definition: util-pidfile.c:105
HostShutdown
void HostShutdown(void)
shutdown the flow engine
Definition: host.c:296
DOC_URL
#define DOC_URL
Definition: suricata.h:90
SCFstatFn
#define SCFstatFn(fd, statbuf)
Definition: util-path.h:34
output-filestore.h
LiveSetOffloadWarn
void LiveSetOffloadWarn(void)
Definition: util-device.c:82
ParseSizeDeinit
void ParseSizeDeinit(void)
Definition: util-misc.c:55
util-classification-config.h
SCConfDeInit
void SCConfDeInit(void)
De-initializes the configuration system.
Definition: conf.c:703
RunModeRegisterRunModes
void RunModeRegisterRunModes(void)
Register all runmodes in the engine.
Definition: runmodes.c:231
ListRuleProtocols
int ListRuleProtocols(const char *conf_filename)
Definition: util-running-modes.c:59
SCStrdup
#define SCStrdup(s)
Definition: util-mem.h:56
FatalError
#define FatalError(...)
Definition: util-debug.h:514
SCProfilingDump
void SCProfilingDump(void)
Definition: util-profiling.c:311
TmModuleReceiveAFXDPRegister
void TmModuleReceiveAFXDPRegister(void)
Definition: source-af-xdp.c:77
EngineStop
void EngineStop(void)
make sure threads can stop the engine by calling this function. Purpose: pcap file mode needs to be a...
Definition: suricata.c:473
SCInstance_::sig_file
char * sig_file
Definition: suricata.h:138
RUNMODE_PRINT_VERSION
@ RUNMODE_PRINT_VERSION
Definition: runmodes.h:51
ParseSizeStringU32
int ParseSizeStringU32(const char *size, uint32_t *res)
Definition: util-misc.c:174
TmModuleReceiveErfDagRegister
void TmModuleReceiveErfDagRegister(void)
Register the ERF file receiver (reader) module.
Definition: source-erf-dag.c:133
IPPairBitInitCtx
void IPPairBitInitCtx(void)
Definition: ippair-bit.c:49
ConfigSetLogDirectory
TmEcode ConfigSetLogDirectory(const char *name)
Definition: util-conf.c:33
util-validate.h
TmModuleDecodeIPFWRegister
void TmModuleDecodeIPFWRegister(void)
Registration Function for DecodeIPFW.
Definition: source-ipfw.c:188
source-af-packet.h
ConfUnixSocketIsEnable
int ConfUnixSocketIsEnable(void)
Definition: util-conf.c:136
TM_FLAG_PACKET_ALL
#define TM_FLAG_PACKET_ALL
Definition: tm-modules.h:40
SCLogConfig
struct SCLogConfig_ SCLogConfig
Holds the config state used by the logging api.
g_vlan_mask
uint16_t g_vlan_mask
Definition: suricata.c:205
RUNMODE_ERF_FILE
@ RUNMODE_ERF_FILE
Definition: runmodes.h:34
DatasetsInit
int DatasetsInit(void)
Definition: datasets.c:622
RUNMODE_DUMP_CONFIG
@ RUNMODE_DUMP_CONFIG
Definition: runmodes.h:54
sigusr2_count
volatile sig_atomic_t sigusr2_count
Definition: suricata.c:159
SystemHugepageSnapshotDestroy
void SystemHugepageSnapshotDestroy(SystemHugepageSnapshot *s)
Definition: util-hugepages.c:304
TmModuleDecodePcapRegister
void TmModuleDecodePcapRegister(void)
Registration Function for DecodePcap.
Definition: source-pcap.c:153
util-running-modes.h
SCLoadYamlConfig
TmEcode SCLoadYamlConfig(void)
Definition: suricata.c:1016
unix-manager.h
runmode-af-xdp.h
str
#define str(s)
Definition: suricata-common.h:308
ConfigCheckDataDirectory
TmEcode ConfigCheckDataDirectory(const char *data_dir)
Definition: util-conf.c:99
SCConfGetNode
SCConfNode * SCConfGetNode(const char *name)
Get a SCConfNode by name.
Definition: conf.c:181
SCLogError
#define SCLogError(...)
Macro used to log ERROR messages.
Definition: util-debug.h:271
g_detect_disabled
int g_detect_disabled
Definition: suricata.c:189
DetectEngineReloadStart
int DetectEngineReloadStart(void)
Definition: detect-engine.c:1888
SCFree
#define SCFree(p)
Definition: util-mem.h:61
TopologyDestroy
void TopologyDestroy(void)
DEFAULT_CONF_FILE
#define DEFAULT_CONF_FILE
Definition: suricata.h:84
SC_LOG_MAX_LOG_MSG_LEN
#define SC_LOG_MAX_LOG_MSG_LEN
Definition: util-debug.h:89
AppLayerParserPostStreamSetup
void AppLayerParserPostStreamSetup(void)
Definition: app-layer-parser.c:272
TmModuleReceivePcapRegister
void TmModuleReceivePcapRegister(void)
Registration Function for ReceivePcap.
Definition: source-pcap.c:135
RUNMODE_DPDK
@ RUNMODE_DPDK
Definition: runmodes.h:39
SCGetUserID
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.
Definition: util-privs.c:143
util-ioctl.h
detect-parse.h
RUNMODE_PCAP_DEV
@ RUNMODE_PCAP_DEV
Definition: runmodes.h:29
SCInstance_::system
bool system
Definition: suricata.h:158
SCInstance_::pid_filename
char * pid_filename
Definition: suricata.h:140
SCInstance_::install_signal_handlers
bool install_signal_handlers
Definition: suricata.h:163
TmModuleRespondRejectRegister
void TmModuleRespondRejectRegister(void)
Definition: respond-reject.c:50
SURICATA_DEINIT
@ SURICATA_DEINIT
Definition: suricata.h:102
CoredumpEnable
void CoredumpEnable(void)
Enable coredumps on systems where coredumps can and need to be enabled.
Definition: util-coredump-config.c:62
RunUnittests
void RunUnittests(int list_unittests, const char *regex_arg)
Definition: runmode-unittests.c:237
source-erf-file.h
ConfigCheckLogDirectoryExists
TmEcode ConfigCheckLogDirectoryExists(const char *log_dir)
Definition: util-conf.c:56
SCConfSet
int SCConfSet(const char *name, const char *val)
Set a configuration value.
Definition: conf.c:239
TimeDeinit
void TimeDeinit(void)
Definition: util-time.c:87
PacketAlertTagInit
void PacketAlertTagInit(void)
Definition: detect-engine-alert.c:46
RunModeEngineIsIPS
int RunModeEngineIsIPS(int capture_mode, const char *runmode, const char *capture_plugin_name)
Definition: runmodes.c:379
DetectEngineCtxInit
DetectEngineCtx * DetectEngineCtxInit(void)
Definition: detect-engine.c:2595
SCOnLoggingReady
void SCOnLoggingReady(void)
Invokes all registered logging ready callbacks.
Definition: output.c:778
TmModuleDecodeLibRegister
void TmModuleDecodeLibRegister(void)
register a "Decode" module for suricata as a library.
Definition: source-lib.c:107
EngineModeIsIPS
int EngineModeIsIPS(void)
Definition: suricata.c:245
SCProfilingKeywordsGlobalInit
void SCProfilingKeywordsGlobalInit(void)
Definition: util-profiling-keywords.c:61
suricata.h
EngineDone
void EngineDone(void)
Used to indicate that the current task is done.
Definition: suricata.c:484
SCInstance_::firewall_rule_file_exclusive
bool firewall_rule_file_exclusive
Definition: suricata.h:143
FLOW_QUIET
#define FLOW_QUIET
Definition: flow.h:43
GetDocURL
const char * GetDocURL(void)
Definition: suricata.c:1169
util-mpm-hs.h
PostRunDeinit
void PostRunDeinit(const int runmode, struct timeval *start_time)
clean up / shutdown code for packet modes
Definition: suricata.c:2345
HostInitConfig
void HostInitConfig(bool quiet)
initialize the configuration
Definition: host.c:168
TmThreadWaitOnThreadRunning
TmEcode TmThreadWaitOnThreadRunning(void)
Waits for all threads to be in a running state.
Definition: tm-threads.c:1899
HttpRangeContainersDestroy
void HttpRangeContainersDestroy(void)
Definition: app-layer-htp-range.c:205
RUNMODE_CONF_TEST
@ RUNMODE_CONF_TEST
Definition: runmodes.h:55
SCLogLoadConfig
void SCLogLoadConfig(int daemon, int verbose, uint32_t userid, uint32_t groupid)
Definition: util-debug.c:1421
DetectEngineReload
int DetectEngineReload(const SCInstance *suri)
Reload the detection engine.
Definition: detect-engine.c:4791
DEFAULT_MAX_PENDING_PACKETS
#define DEFAULT_MAX_PENDING_PACKETS
Definition: suricata.c:169
SCInstance_
Definition: suricata.h:133
DetectEngineClearMaster
void DetectEngineClearMaster(void)
Definition: detect-engine.c:4764
SetMasterExceptionPolicy
void SetMasterExceptionPolicy(void)
Definition: util-exception-policy.c:65
id
uint32_t id
Definition: detect-flowbits.c:944
TmThreadCheckThreadState
void TmThreadCheckThreadState(void)
Used to check the thread for certain conditions of failure.
Definition: tm-threads.c:1984
OutputFilestoreRegisterGlobalCounters
void OutputFilestoreRegisterGlobalCounters(void)
Definition: output-filestore.c:537
InitGlobal
int InitGlobal(void)
Global initialization common to all runmodes.
Definition: suricata.c:2985
SCInstance_::disabled_detect
int disabled_detect
Definition: suricata.h:166
LiveGetDeviceCount
int LiveGetDeviceCount(void)
Get the number of registered devices.
Definition: util-device.c:170
SystemHugepageSnapshotCreate
SystemHugepageSnapshot * SystemHugepageSnapshotCreate(void)
The function creates a snapshot of the system's hugepage usage per NUMA node and per hugepage size....
Definition: util-hugepages.c:323
SCProfilingSghsGlobalInit
void SCProfilingSghsGlobalInit(void)
Definition: util-profiling-rulegroups.c:61
RUNMODE_LIST_RULE_PROTOS
@ RUNMODE_LIST_RULE_PROTOS
Definition: runmodes.h:48
SCPidfileCreate
int SCPidfileCreate(const char *pidfile)
Write a pid file (used at the startup) This commonly needed by the init scripts.
Definition: util-pidfile.c:42
LiveRegisterDeviceName
int LiveRegisterDeviceName(const char *dev)
Add a device for monitoring.
Definition: util-device.c:103
SCStatFn
#define SCStatFn(pathname, statbuf)
Definition: util-path.h:35
ENGINE_MODE_IDS
@ ENGINE_MODE_IDS
Definition: suricata.h:108
LiveDeviceFinalize
void LiveDeviceFinalize(void)
Definition: util-device.c:462
TmModuleDecodeDPDKRegister
void TmModuleDecodeDPDKRegister(void)
Registration Function for DecodeDPDK.
Definition: source-dpdk.c:65
SCInstance_::sig_file_exclusive
bool sig_file_exclusive
Definition: suricata.h:139
PROG_VER
#define PROG_VER
Definition: suricata.h:76
util-misc.h
PacketPoolDestroy
void PacketPoolDestroy(void)
Definition: tmqh-packetpool.c:265
HTPFreeConfig
void HTPFreeConfig(void)
Clears the HTTP server configuration memory used by HTP library.
Definition: app-layer-htp.c:1591
flow.h
LandlockSandboxing
void LandlockSandboxing(SCInstance *suri)
Definition: util-landlock.c:36
respond-reject.h
SCInstance_::regex_arg
char * regex_arg
Definition: suricata.h:141
ListKeywords
int ListKeywords(const char *keyword_info)
Definition: util-running-modes.c:34
SCLogNotice
#define SCLogNotice(...)
Macro used to log NOTICE messages.
Definition: util-debug.h:247
SuricataPreInit
void SuricataPreInit(const char *progname)
Definition: suricata.c:3021
RUNMODE_PCAP_FILE
@ RUNMODE_PCAP_FILE
Definition: runmodes.h:30
DPDKCleanupEAL
void DPDKCleanupEAL(void)
Definition: util-dpdk.c:30
SCCalloc
#define SCCalloc(nm, sz)
Definition: util-mem.h:53
SCReturnInt
#define SCReturnInt(x)
Definition: util-debug.h:285
RUNMODE_PRINT_BUILDINFO
@ RUNMODE_PRINT_BUILDINFO
Definition: runmodes.h:52
SCConfNode_
Definition: conf.h:37
SCPidfileRemove
void SCPidfileRemove(const char *pid_filename)
Remove the pid file (used at the startup)
Definition: util-pidfile.c:83
SCConfNode_::val
char * val
Definition: conf.h:39
ThresholdInit
void ThresholdInit(void)
Definition: detect-engine-threshold.c:66
TimeInit
void TimeInit(void)
Definition: util-time.c:79
SCInstance_::keyword_info
char * keyword_info
Definition: suricata.h:147
RUNMODE_LIST_UNITTEST
@ RUNMODE_LIST_UNITTEST
Definition: runmodes.h:56
NFQContextsClean
void NFQContextsClean(void)
Clean global contexts. Must be called on exit.
Definition: source-nfq.c:1303
SystemHugepageEvaluateHugepages
void SystemHugepageEvaluateHugepages(SystemHugepageSnapshot *pre_s, SystemHugepageSnapshot *post_s)
The function compares two hugepage snapshots and prints out recommendations for hugepage configuratio...
Definition: util-hugepages.c:363
DEBUG_VALIDATE_BUG_ON
#define DEBUG_VALIDATE_BUG_ON(exp)
Definition: util-validate.h:102
SCFinalizeRunMode
int SCFinalizeRunMode(void)
Definition: suricata.c:2471
SCStat
struct stat SCStat
Definition: util-path.h:33
SCProfilingInit
void SCProfilingInit(void)
Initialize profiling.
Definition: util-profiling.c:133
g_ut_modules
int g_ut_modules
Definition: suricata.c:948
detect-engine-address.h
GlobalsDestroy
void GlobalsDestroy(void)
Definition: suricata.c:393
output.h
util-threshold-config.h
DefragInit
void DefragInit(void)
Definition: defrag.c:1109
DetectEngineReloadIsStart
int DetectEngineReloadIsStart(void)
Definition: detect-engine.c:1902
suricata_ctl_flags
volatile uint8_t suricata_ctl_flags
Definition: suricata.c:175
RUNMODE_IPFW
@ RUNMODE_IPFW
Definition: runmodes.h:33
host-bit.h
detect-engine-threshold.h
TM_FLAG_FLOWWORKER_TM
#define TM_FLAG_FLOWWORKER_TM
Definition: tm-modules.h:34
RUNMODE_LIST_RUNMODES
@ RUNMODE_LIST_RUNMODES
Definition: runmodes.h:50
app-layer.h
TagDestroyCtx
void TagDestroyCtx(void)
Destroy tag context hash tables.
Definition: detect-engine-tag.c:72
DetectAddressTestConfVars
int DetectAddressTestConfVars(void)
Definition: detect-engine-address.c:1218
g_disable_randomness
int g_disable_randomness
Definition: suricata.c:198
geteuid
#define geteuid()
Definition: win32-misc.h:41
FlowWorkToDoCleanup
void FlowWorkToDoCleanup(void)
Clean up all the flows that have unprocessed segments and have some work to do in the detection engin...
Definition: flow-timeout.c:422
MpmHSGlobalCleanup
void MpmHSGlobalCleanup(void)
RUNMODE_DUMP_FEATURES
@ RUNMODE_DUMP_FEATURES
Definition: runmodes.h:63
g_disable_hashing
bool g_disable_hashing
Definition: suricata.c:217
TmqResetQueues
void TmqResetQueues(void)
Definition: tm-queues.c:80