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