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 automatically 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_SURICATA_H
65#define SURICATA_SURICATA_H
66
67#ifdef __cplusplus
68extern "C"
69{
70#endif
71
72#include "suricata-common.h"
73
74/* the name of our binary */
75#define PROG_NAME "Suricata"
76#define PROG_VER PACKAGE_VERSION
77
78/* workaround SPlint error (don't know __gnuc_va_list) */
79#ifdef S_SPLINT_S
80# include <err.h>
81# define CONFIG_DIR "/etc/suricata"
82#endif
83
84#define DEFAULT_CONF_FILE CONFIG_DIR "/suricata.yaml"
85
86#define DEFAULT_PID_DIR LOCAL_STATE_DIR "/run/"
87#define DEFAULT_PID_BASENAME "suricata.pid"
88#define DEFAULT_PID_FILENAME DEFAULT_PID_DIR DEFAULT_PID_BASENAME
89
90#define DOC_URL "https://docs.suricata.io/en/"
91const char *GetDocURL(void);
92
93/* runtime engine control flags */
94#define SURICATA_STOP (1 << 0) /**< gracefully stop the engine: process all
95 outstanding packets first */
96#define SURICATA_DONE (1 << 2) /**< packets capture ended */
97
98/* Engine stage/status*/
99enum {
104
105/* Engine is acting as */
109 /* order matters, we need to be able to do IPS is true for >= ENGINE_MODE_IPS */
112};
113
114/* superset of IPS mode */
115void EngineModeSetFirewall(void);
116void EngineModeSetIPS(void);
117void EngineModeSetIDS(void);
118int EngineModeIsUnknown(void);
119bool EngineModeIsFirewall(void);
120int EngineModeIsIPS(void);
121int EngineModeIsIDS(void);
122
123/* Box is acting as router */
124enum {
127};
128
129#define IS_SURI_HOST_MODE_SNIFFER_ONLY(host_mode) ((host_mode) == SURI_HOST_IS_SNIFFER_ONLY)
130
131#include "runmodes.h"
132
133typedef struct SCInstance_ {
136
137 char pcap_dev[128];
138 char *sig_file;
144 /* is firewall mode enabled */
146
149#ifndef OS_WIN32
150 const char *user_name;
151 const char *group_name;
154#endif /* OS_WIN32 */
155 uint32_t userid;
156 uint32_t groupid;
157
158 bool system;
162
163 bool install_signal_handlers; /**< Install default signal handlers */
164
172
173 struct timeval start_time;
174
175 const char *log_dir;
176 const char *progname; /**< pointer to argv[0] */
177 const char *conf_filename;
178 const char **additional_configs;
180
184
185
186/* memset to zeros, and mutex init! */
187void GlobalsInitPreConfig(void);
188
189extern volatile uint8_t suricata_ctl_flags;
190extern int g_disable_randomness;
191extern uint16_t g_vlan_mask;
192extern uint16_t g_livedev_mask;
193extern uint8_t g_recurlvl_mask;
194
195/* Flag to disable hashing (almost) globally. */
196extern bool g_disable_hashing;
197
198void EngineStop(void);
199void EngineDone(void);
200
201#ifdef UNITTESTS
202int RunmodeIsUnittests(void);
203#else
204#define RunmodeIsUnittests() 0
205#endif
206
207/**
208 * \brief Get the current run mode.
209 */
211
212/**
213 * \brief Set the current run mode.
214 *
215 * Mainly exposed outside of suricata.c as a unit-test helper.
216 */
217void SCRunmodeSet(SCRunMode run_mode);
218
219/**
220 * \brief Enable default signal handlers.
221 */
223
224int SuriHasSigFile(void);
225
226void SuricataPreInit(const char *progname);
227void SuricataInit(void);
228void SuricataPostInit(void);
229void SuricataMainLoop(void);
230void SuricataShutdown(void);
231int InitGlobal(void);
232void GlobalsDestroy(void);
235int SCFinalizeRunMode(void);
236TmEcode SCParseCommandLine(int argc, char **argv);
237int SCStartInternalRunMode(int argc, char **argv);
239
240void PreRunInit(const int runmode);
241void PreRunPostPrivsDropInit(const int runmode);
242void PostRunDeinit(const int runmode, struct timeval *start_time);
243void RegisterAllModules(void);
244
245#ifdef OS_WIN32
246int WindowsInitService(int argc, char **argv);
247#endif
248
249const char *GetProgramVersion(void);
250
251#ifdef __cplusplus
252}
253#endif
254
255#endif /* SURICATA_SURICATA_H */
SCRunModes
Definition runmodes.h:27
enum SCRunModes SCRunMode
bool do_setuid
Definition suricata.h:152
struct timeval start_time
Definition suricata.h:173
char * runmode_custom_mode
Definition suricata.h:148
char * sig_file
Definition suricata.h:138
const char * group_name
Definition suricata.h:151
int checksum_validation
Definition suricata.h:170
bool is_firewall
Definition suricata.h:145
const char * capture_plugin_args
Definition suricata.h:182
char * strict_rule_parsing_string
Definition suricata.h:179
char * firewall_rule_file
Definition suricata.h:142
bool sig_file_exclusive
Definition suricata.h:139
enum SCRunModes run_mode
Definition suricata.h:134
const char * capture_plugin_name
Definition suricata.h:181
const char * progname
Definition suricata.h:176
uint32_t userid
Definition suricata.h:155
char * regex_arg
Definition suricata.h:141
bool set_logdir
Definition suricata.h:159
bool do_setgid
Definition suricata.h:153
bool system
Definition suricata.h:158
const char * user_name
Definition suricata.h:150
bool firewall_rule_file_exclusive
Definition suricata.h:143
const char ** additional_configs
Definition suricata.h:178
const char * conf_filename
Definition suricata.h:177
enum SCRunModes aux_run_mode
Definition suricata.h:135
bool unix_socket_enabled
Definition suricata.h:161
bool set_datadir
Definition suricata.h:160
int output_flush_interval
Definition suricata.h:171
char pcap_dev[128]
Definition suricata.h:137
const char * log_dir
Definition suricata.h:175
uint32_t groupid
Definition suricata.h:156
char * keyword_info
Definition suricata.h:147
char * pid_filename
Definition suricata.h:140
int disabled_detect
Definition suricata.h:166
bool install_signal_handlers
Definition suricata.h:163
int delayed_detect
Definition suricata.h:165
void EngineDone(void)
Used to indicate that the current task is done.
Definition suricata.c:481
void SuricataInit(void)
Definition suricata.c:3012
uint16_t g_livedev_mask
Definition suricata.c:206
void PostRunDeinit(const int runmode, struct timeval *start_time)
clean up / shutdown code for packet modes
Definition suricata.c:2331
int InitGlobal(void)
Global initialization common to all runmodes.
Definition suricata.c:2965
struct SCInstance_ SCInstance
void PostConfLoadedDetectSetup(SCInstance *suri)
Definition suricata.c:2625
void SCEnableDefaultSignalHandlers(void)
Enable default signal handlers.
Definition suricata.c:289
void EngineModeSetFirewall(void)
Definition suricata.c:254
void PreRunInit(const int runmode)
Definition suricata.c:2286
void PreRunPostPrivsDropInit(const int runmode)
Definition suricata.c:2315
EngineMode
Definition suricata.h:106
@ ENGINE_MODE_IDS
Definition suricata.h:108
@ ENGINE_MODE_FIREWALL
Definition suricata.h:111
@ ENGINE_MODE_UNKNOWN
Definition suricata.h:107
@ ENGINE_MODE_IPS
Definition suricata.h:110
bool g_disable_hashing
Definition suricata.c:214
void SuricataShutdown(void)
Definition suricata.c:3100
TmEcode SCLoadYamlConfig(void)
Definition suricata.c:1012
bool EngineModeIsFirewall(void)
Definition suricata.c:235
uint8_t g_recurlvl_mask
Definition suricata.c:210
int EngineModeIsIPS(void)
Definition suricata.c:242
SCRunMode SCRunmodeGet(void)
Get the current run mode.
Definition suricata.c:279
int SCFinalizeRunMode(void)
Definition suricata.c:2451
volatile uint8_t suricata_ctl_flags
Definition suricata.c:172
int EngineModeIsUnknown(void)
Definition suricata.c:230
void EngineModeSetIDS(void)
Definition suricata.c:264
@ SURI_HOST_IS_SNIFFER_ONLY
Definition suricata.h:125
@ SURI_HOST_IS_ROUTER
Definition suricata.h:126
void EngineModeSetIPS(void)
Definition suricata.c:259
int SCStartInternalRunMode(int argc, char **argv)
Definition suricata.c:2389
uint16_t g_vlan_mask
Definition suricata.c:202
int SuriHasSigFile(void)
Definition suricata.c:225
int g_disable_randomness
Definition suricata.c:195
void GlobalsDestroy(void)
Definition suricata.c:390
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:470
void SCRunmodeSet(SCRunMode run_mode)
Set the current run mode.
Definition suricata.c:284
TmEcode SCParseCommandLine(int argc, char **argv)
Definition suricata.c:1369
void SuricataMainLoop(void)
Definition suricata.c:2922
void RegisterAllModules(void)
Definition suricata.c:947
void SuricataPreInit(const char *progname)
Definition suricata.c:3003
const char * GetDocURL(void)
Definition suricata.c:1165
void SuricataPostInit(void)
Definition suricata.c:3111
void GlobalsInitPreConfig(void)
Definition suricata.c:382
@ SURICATA_DEINIT
Definition suricata.h:102
@ SURICATA_RUNTIME
Definition suricata.h:101
@ SURICATA_INIT
Definition suricata.h:100
const char * GetProgramVersion(void)
get string with program version
Definition suricata.c:1186
int EngineModeIsIDS(void)
Definition suricata.c:248
int RunmodeIsUnittests(void)
Definition suricata.c:270
int PostConfLoadedSetup(SCInstance *suri)
Definition suricata.c:2716