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