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