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