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