suricata
suricata.h
Go to the documentation of this file.
1 /* Copyright (C) 2007-2014 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 /** \mainpage Doxygen documentation
19  *
20  * \section intro_sec Introduction
21  *
22  * The Suricata Engine is an Open Source Next Generation Intrusion Detection
23  * and Prevention Engine. This engine is not intended to just replace or
24  * emulate the existing tools in the industry, but will bring new ideas and
25  * technologies to the field.
26  *
27  * \section dev_doc Developer documentation
28  *
29  * You've reach the automically generated documentation of Suricata. This
30  * document contains information about architecture and code structure. It
31  * is attended for developers wanting to understand or contribute to Suricata.
32  *
33  * \subsection modules Modules
34  *
35  * Documentation is generate from comments placed in all parts of the code.
36  * But you will also find some groups describing specific functional parts:
37  * - \ref decode
38  * - \ref httplayer
39  * - \ref sigstate
40  * - \ref threshold
41  *
42  * \section archi Architecture
43  *
44  * \subsection datastruct Data structures
45  *
46  * Regarding matching, there is three main data structures which are:
47  * - ::Packet: Data relative to an individual packet with information about
48  * linked structure such as the ::Flow the ::Packet belongs to.
49  * - ::Flow: Information about a flow for example a TCP session
50  *
51  * \subsection runmode Running mode
52  *
53  * Suricata is multithreaded and running modes define how the different
54  * threads are working together. You can see util-runmodes.c for example
55  * of running mode.
56  */
57 
58 /**
59  * \file
60  *
61  * \author Victor Julien <victor@inliniac.net>
62  */
63 
64 #ifndef __SURICATA_H__
65 #define __SURICATA_H__
66 
67 #include "suricata-common.h"
68 #include "packet-queue.h"
69 
70 /* the name of our binary */
71 #define PROG_NAME "Suricata"
72 #define PROG_VER PACKAGE_VERSION
73 
74 /* workaround SPlint error (don't know __gnuc_va_list) */
75 #ifdef S_SPLINT_S
76 # include <err.h>
77 # define CONFIG_DIR "/etc/suricata"
78 #endif
79 
80 #define DEFAULT_CONF_FILE CONFIG_DIR "/suricata.yaml"
81 
82 #define DEFAULT_PID_DIR LOCAL_STATE_DIR "/run/"
83 #define DEFAULT_PID_BASENAME "suricata.pid"
84 #define DEFAULT_PID_FILENAME DEFAULT_PID_DIR DEFAULT_PID_BASENAME
85 
86 #define DOC_URL "https://suricata.readthedocs.io/en/"
87 const char *GetDocURL(void);
88 
89 /* runtime engine control flags */
90 #define SURICATA_STOP (1 << 0) /**< gracefully stop the engine: process all
91  outstanding packets first */
92 #define SURICATA_DONE (1 << 2) /**< packets capture ended */
93 
94 /* Engine stage/status*/
95 enum {
99 };
100 
101 /* Engine is acting as */
105 };
106 
107 void EngineModeSetIPS(void);
108 void EngineModeSetIDS(void);
109 int EngineModeIsIPS(void);
110 int EngineModeIsIDS(void);
111 
112 /* Box is acting as router */
113 enum {
116 };
117 
118 #define IS_SURI_HOST_MODE_SNIFFER_ONLY(host_mode) ((host_mode) == SURI_HOST_IS_SNIFFER_ONLY)
119 #define IS_SURI_HOST_MODE_ROUTER(host_mode) ((host_mode) == SURI_HOST_IS_ROUTER)
120 
121 #include "runmodes.h"
122 
123 typedef struct SCInstance_ {
124  enum RunModes run_mode;
125  enum RunModes aux_run_mode;
126 
127  char pcap_dev[128];
128  char *sig_file;
131  char *regex_arg;
132 
135 #ifndef OS_WIN32
136  const char *user_name;
137  const char *group_name;
138  uint8_t do_setuid;
139  uint8_t do_setgid;
140  uint32_t userid;
141  uint32_t groupid;
142 #endif /* OS_WIN32 */
143 
144  bool system;
147 
150  int daemon;
151  int offline;
152  int verbose;
154 
155  struct timeval start_time;
156 
157  const char *log_dir;
158  const char *progname; /**< pointer to argv[0] */
159  const char *conf_filename;
161 
162  const char *capture_plugin_name;
163  const char *capture_plugin_args;
165 
166 
167 /* memset to zeros, and mutex init! */
168 void GlobalsInitPreConfig(void);
169 
170 extern volatile uint8_t suricata_ctl_flags;
171 extern int g_disable_randomness;
172 extern uint16_t g_vlan_mask;
173 
174 #include <ctype.h>
175 #define u8_tolower(c) tolower((uint8_t)(c))
176 #define u8_toupper(c) toupper((uint8_t)(c))
177 
178 void EngineStop(void);
179 void EngineDone(void);
180 
181 int RunmodeIsUnittests(void);
182 int RunmodeGetCurrent(void);
183 int IsRuleReloadSet(int quiet);
184 
185 int SuriHasSigFile(void);
186 
187 extern int run_mode;
188 
189 int SuricataMain(int argc, char **argv);
190 int InitGlobal(void);
193 
194 void PreRunInit(const int runmode);
195 void PreRunPostPrivsDropInit(const int runmode);
196 void PostRunDeinit(const int runmode, struct timeval *start_time);
197 void RegisterAllModules(void);
198 
199 const char *GetProgramVersion(void);
200 
201 #endif /* __SURICATA_H__ */
202 
SCInstance_::run_mode
enum RunModes run_mode
Definition: suricata.h:124
SCInstance_::groupid
uint32_t groupid
Definition: suricata.h:141
SCInstance_::daemon
int daemon
Definition: suricata.h:150
SCInstance_::checksum_validation
int checksum_validation
Definition: suricata.h:153
SURI_HOST_IS_SNIFFER_ONLY
@ SURI_HOST_IS_SNIFFER_ONLY
Definition: suricata.h:114
SCInstance_::start_time
struct timeval start_time
Definition: suricata.h:155
g_vlan_mask
uint16_t g_vlan_mask
Definition: suricata.c:234
SCInstance
struct SCInstance_ SCInstance
RunmodeIsUnittests
int RunmodeIsUnittests(void)
Definition: suricata.c:264
SCInstance_::group_name
const char * group_name
Definition: suricata.h:137
SCInstance_::runmode_custom_mode
char * runmode_custom_mode
Definition: suricata.h:134
SURICATA_INIT
@ SURICATA_INIT
Definition: suricata.h:96
SCInstance_::userid
uint32_t userid
Definition: suricata.h:140
packet-queue.h
InitGlobal
int InitGlobal(void)
Global initialization common to all runmodes.
Definition: suricata.c:2670
ENGINE_MODE_IPS
@ ENGINE_MODE_IPS
Definition: suricata.h:104
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:391
PreRunPostPrivsDropInit
void PreRunPostPrivsDropInit(const int runmode)
Definition: suricata.c:2033
SCInstance_::conf_filename
const char * conf_filename
Definition: suricata.h:159
SCInstance_::capture_plugin_name
const char * capture_plugin_name
Definition: suricata.h:162
EngineMode
EngineMode
Definition: suricata.h:102
SURICATA_DEINIT
@ SURICATA_DEINIT
Definition: suricata.h:98
SCInstance_::set_datadir
bool set_datadir
Definition: suricata.h:146
SCInstance_::capture_plugin_args
const char * capture_plugin_args
Definition: suricata.h:163
EngineModeIsIPS
int EngineModeIsIPS(void)
Definition: suricata.c:244
EngineDone
void EngineDone(void)
Used to indicate that the current task is done.
Definition: suricata.c:402
RunModes
RunModes
Definition: runmodes.h:27
PostConfLoadedDetectSetup
void PostConfLoadedDetectSetup(SCInstance *suri)
Definition: suricata.c:2321
GlobalsInitPreConfig
void GlobalsInitPreConfig(void)
Definition: suricata.c:316
RunmodeGetCurrent
int RunmodeGetCurrent(void)
Definition: suricata.c:272
SCInstance_::delayed_detect
int delayed_detect
Definition: suricata.h:148
SCInstance_::progname
const char * progname
Definition: suricata.h:158
SCInstance_::pcap_dev
char pcap_dev[128]
Definition: suricata.h:127
SCInstance_::user_name
const char * user_name
Definition: suricata.h:136
SCInstance_::offline
int offline
Definition: suricata.h:151
GetProgramVersion
const char * GetProgramVersion(void)
get string with program version
Definition: suricata.c:1043
EngineModeSetIDS
void EngineModeSetIDS(void)
Definition: suricata.c:259
SCInstance_::verbose
int verbose
Definition: suricata.h:152
SURICATA_RUNTIME
@ SURICATA_RUNTIME
Definition: suricata.h:97
SCInstance_::aux_run_mode
enum RunModes aux_run_mode
Definition: suricata.h:125
SCInstance_::set_logdir
bool set_logdir
Definition: suricata.h:145
SCInstance_::log_dir
const char * log_dir
Definition: suricata.h:157
runmodes.h
EngineModeSetIPS
void EngineModeSetIPS(void)
Definition: suricata.c:254
SURI_HOST_IS_ROUTER
@ SURI_HOST_IS_ROUTER
Definition: suricata.h:115
SCInstance_::strict_rule_parsing_string
char * strict_rule_parsing_string
Definition: suricata.h:160
suricata-common.h
IsRuleReloadSet
int IsRuleReloadSet(int quiet)
SCInstance_::sig_file
char * sig_file
Definition: suricata.h:128
PreRunInit
void PreRunInit(const int runmode)
Definition: suricata.c:2008
SCInstance_::sig_file_exclusive
int sig_file_exclusive
Definition: suricata.h:129
SCInstance_::system
bool system
Definition: suricata.h:144
SCInstance_::pid_filename
char * pid_filename
Definition: suricata.h:130
PostRunDeinit
void PostRunDeinit(const int runmode, struct timeval *start_time)
Definition: suricata.c:2047
EngineModeIsIDS
int EngineModeIsIDS(void)
Definition: suricata.c:249
SCInstance_::do_setgid
uint8_t do_setgid
Definition: suricata.h:139
SCInstance_
Definition: suricata.h:123
SCInstance_::disabled_detect
int disabled_detect
Definition: suricata.h:149
run_mode
int run_mode
Definition: suricata.c:201
ENGINE_MODE_IDS
@ ENGINE_MODE_IDS
Definition: suricata.h:103
RegisterAllModules
void RegisterAllModules(void)
Definition: suricata.c:837
SCInstance_::regex_arg
char * regex_arg
Definition: suricata.h:131
suricata_ctl_flags
volatile uint8_t suricata_ctl_flags
Definition: suricata.c:198
g_disable_randomness
int g_disable_randomness
Definition: suricata.c:227
SCInstance_::keyword_info
char * keyword_info
Definition: suricata.h:133
SCInstance_::do_setuid
uint8_t do_setuid
Definition: suricata.h:138
SuricataMain
int SuricataMain(int argc, char **argv)
Definition: suricata.c:2714
SuriHasSigFile
int SuriHasSigFile(void)
Definition: suricata.c:239
GetDocURL
const char * GetDocURL(void)
Definition: suricata.c:1022
PostConfLoadedSetup
int PostConfLoadedSetup(SCInstance *suri)
Definition: suricata.c:2440