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 
88 #if defined RELEASE
89 #define DOC_VERSION "suricata-" PROG_VER
90 #else
91 #define DOC_VERSION "latest"
92 #endif
93 
94 /* runtime engine control flags */
95 #define SURICATA_STOP (1 << 0) /**< gracefully stop the engine: process all
96  outstanding packets first */
97 #define SURICATA_DONE (1 << 2) /**< packets capture ended */
98 
99 /* Engine stage/status*/
100 enum {
104 };
105 
106 /* Engine is acting as */
110 };
111 
112 void EngineModeSetIPS(void);
113 void EngineModeSetIDS(void);
114 int EngineModeIsIPS(void);
115 int EngineModeIsIDS(void);
116 
117 /* Box is acting as router */
118 enum {
121 };
122 
123 #define IS_SURI_HOST_MODE_SNIFFER_ONLY(host_mode) ((host_mode) == SURI_HOST_IS_SNIFFER_ONLY)
124 #define IS_SURI_HOST_MODE_ROUTER(host_mode) ((host_mode) == SURI_HOST_IS_ROUTER)
125 
126 #include "runmodes.h"
127 
128 typedef struct SCInstance_ {
131 
132  char pcap_dev[128];
133  char *sig_file;
136  char *regex_arg;
137 
140 #ifndef OS_WIN32
141  const char *user_name;
142  const char *group_name;
143  uint8_t do_setuid;
144  uint8_t do_setgid;
145  uint32_t userid;
146  uint32_t groupid;
147 #endif /* OS_WIN32 */
148 
149  bool system;
152 
155  int daemon;
156  int offline;
157  int verbose;
159 
160  struct timeval start_time;
161 
162  const char *log_dir;
163  const char *progname; /**< pointer to argv[0] */
164  const char *conf_filename;
166 } SCInstance;
167 
168 
169 /* memset to zeros, and mutex init! */
170 void GlobalsInitPreConfig(void);
171 
172 extern volatile uint8_t suricata_ctl_flags;
173 extern int g_disable_randomness;
174 extern uint16_t g_vlan_mask;
175 
176 #include <ctype.h>
177 #define u8_tolower(c) tolower((uint8_t)(c))
178 #define u8_toupper(c) toupper((uint8_t)(c))
179 
180 void EngineStop(void);
181 void EngineDone(void);
182 
183 int RunmodeIsUnittests(void);
184 int RunmodeGetCurrent(void);
185 int IsRuleReloadSet(int quiet);
186 
187 int SuriHasSigFile(void);
188 
189 extern int run_mode;
190 
191 int SuricataMain(int argc, char **argv);
192 int InitGlobal(void);
194 
195 void PreRunInit(const int runmode);
196 void PreRunPostPrivsDropInit(const int runmode);
197 void PostRunDeinit(const int runmode, struct timeval *start_time);
198 void RegisterAllModules(void);
199 
200 const char *GetProgramVersion(void);
201 
202 #endif /* __SURICATA_H__ */
203 
SCInstance_::run_mode
enum RunModes run_mode
Definition: suricata.h:129
SCInstance_::groupid
uint32_t groupid
Definition: suricata.h:146
SCInstance_::daemon
int daemon
Definition: suricata.h:155
SCInstance_::checksum_validation
int checksum_validation
Definition: suricata.h:158
SCInstance_::start_time
struct timeval start_time
Definition: suricata.h:160
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:142
SCInstance_::runmode_custom_mode
char * runmode_custom_mode
Definition: suricata.h:139
SURICATA_INIT
@ SURICATA_INIT
Definition: suricata.h:101
SURICATA_DEINIT
@ SURICATA_DEINIT
Definition: suricata.h:103
SURICATA_RUNTIME
@ SURICATA_RUNTIME
Definition: suricata.h:102
SCInstance_::userid
uint32_t userid
Definition: suricata.h:145
packet-queue.h
InitGlobal
int InitGlobal(void)
Global initialization common to all runmodes.
Definition: suricata.c:2643
ENGINE_MODE_IPS
@ ENGINE_MODE_IPS
Definition: suricata.h:109
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:417
PreRunPostPrivsDropInit
void PreRunPostPrivsDropInit(const int runmode)
Definition: suricata.c:2006
SCInstance_::conf_filename
const char * conf_filename
Definition: suricata.h:164
EngineMode
EngineMode
Definition: suricata.h:107
SCInstance_::set_datadir
bool set_datadir
Definition: suricata.h:151
EngineModeIsIPS
int EngineModeIsIPS(void)
Definition: suricata.c:244
EngineDone
void EngineDone(void)
Used to indicate that the current task is done.
Definition: suricata.c:428
RunModes
RunModes
Definition: runmodes.h:27
SURI_HOST_IS_ROUTER
@ SURI_HOST_IS_ROUTER
Definition: suricata.h:120
GlobalsInitPreConfig
void GlobalsInitPreConfig(void)
Definition: suricata.c:330
RunmodeGetCurrent
int RunmodeGetCurrent(void)
Definition: suricata.c:272
SCInstance_::delayed_detect
int delayed_detect
Definition: suricata.h:153
SCInstance_::progname
const char * progname
Definition: suricata.h:163
SCInstance_::pcap_dev
char pcap_dev[128]
Definition: suricata.h:132
SCInstance_::user_name
const char * user_name
Definition: suricata.h:141
SCInstance_::offline
int offline
Definition: suricata.h:156
GetProgramVersion
const char * GetProgramVersion(void)
get string with program version
Definition: suricata.c:1048
EngineModeSetIDS
void EngineModeSetIDS(void)
Definition: suricata.c:259
SCInstance_::verbose
int verbose
Definition: suricata.h:157
SCInstance_::aux_run_mode
enum RunModes aux_run_mode
Definition: suricata.h:130
SCInstance_::set_logdir
bool set_logdir
Definition: suricata.h:150
SCInstance_::log_dir
const char * log_dir
Definition: suricata.h:162
runmodes.h
EngineModeSetIPS
void EngineModeSetIPS(void)
Definition: suricata.c:254
SCInstance_::strict_rule_parsing_string
char * strict_rule_parsing_string
Definition: suricata.h:165
suricata-common.h
IsRuleReloadSet
int IsRuleReloadSet(int quiet)
SCInstance_::sig_file
char * sig_file
Definition: suricata.h:133
PreRunInit
void PreRunInit(const int runmode)
Definition: suricata.c:1982
SCInstance_::sig_file_exclusive
int sig_file_exclusive
Definition: suricata.h:134
SCInstance_::system
bool system
Definition: suricata.h:149
SCInstance_::pid_filename
char * pid_filename
Definition: suricata.h:135
PostRunDeinit
void PostRunDeinit(const int runmode, struct timeval *start_time)
Definition: suricata.c:2020
SURI_HOST_IS_SNIFFER_ONLY
@ SURI_HOST_IS_SNIFFER_ONLY
Definition: suricata.h:119
EngineModeIsIDS
int EngineModeIsIDS(void)
Definition: suricata.c:249
SCInstance_::do_setgid
uint8_t do_setgid
Definition: suricata.h:144
SCInstance_
Definition: suricata.h:128
SCInstance_::disabled_detect
int disabled_detect
Definition: suricata.h:154
run_mode
int run_mode
Definition: suricata.c:201
ENGINE_MODE_IDS
@ ENGINE_MODE_IDS
Definition: suricata.h:108
RegisterAllModules
void RegisterAllModules(void)
Definition: suricata.c:851
SCInstance_::regex_arg
char * regex_arg
Definition: suricata.h:136
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:138
SCInstance_::do_setuid
uint8_t do_setuid
Definition: suricata.h:143
SuricataMain
int SuricataMain(int argc, char **argv)
Definition: suricata.c:2688
SuriHasSigFile
int SuriHasSigFile(void)
Definition: suricata.c:239
PostConfLoadedSetup
int PostConfLoadedSetup(SCInstance *suri)
Definition: suricata.c:2411