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