suricata
detect-engine-state.h
Go to the documentation of this file.
1 /* Copyright (C) 2007-2013 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  * \ingroup sigstate
20  *
21  * @{
22  */
23 
24 /**
25  * \file
26  *
27  * \brief Data structures and function prototypes for keeping
28  * state for the detection engine.
29  *
30  * \author Victor Julien <victor@inliniac.net>
31  * \author Anoop Saldanha <anoopsaldanha@gmail.com>
32  */
33 
34 #ifndef SURICATA_DETECT_ENGINE_STATE_H
35 #define SURICATA_DETECT_ENGINE_STATE_H
36 
37 #define DETECT_ENGINE_INSPECT_SIG_NO_MATCH 0
38 #define DETECT_ENGINE_INSPECT_SIG_MATCH 1
39 #define DETECT_ENGINE_INSPECT_SIG_CANT_MATCH 2
40 /** indicate that the file inspection portion of a sig didn't match.
41  * This is used to handle state keeping as the detect engine is still
42  * only marginally aware of files. */
43 #define DETECT_ENGINE_INSPECT_SIG_CANT_MATCH_FILES 3
44 /** hack to work around a file inspection limitation. Since there can be
45  * multiple files in a TX and the detection engine really don't know
46  * about that, we have to give the file inspection engine a way to
47  * indicate that one of the files matched, but that there are still
48  * more files that have ongoing inspection. */
49 #define DETECT_ENGINE_INSPECT_SIG_MATCH_MORE_FILES 4
50 
51 /** number of DeStateStoreItem's in one DeStateStore object */
52 #define DE_STATE_CHUNK_SIZE 15
53 
54 /* per sig flags */
55 #define DE_STATE_FLAG_FULL_INSPECT BIT_U32(0)
56 #define DE_STATE_FLAG_SIG_CANT_MATCH BIT_U32(1)
57 /* flag set if file inspecting sig did not match, but might need to be
58  * re-evaluated for a new file in a tx */
59 #define DE_STATE_ID_FILE_INSPECT 2UL
60 #define DE_STATE_FLAG_FILE_INSPECT BIT_U32(DE_STATE_ID_FILE_INSPECT)
61 
62 /* first bit position after the built-ins */
63 #define DE_STATE_FLAG_BASE 3UL
64 
65 /* state flags
66  *
67  * Used by app-layer-parsers to notify us that new files
68  * are available in the tx.
69  */
70 #define DETECT_ENGINE_STATE_FLAG_FILE_NEW BIT_U8(0)
71 
72 typedef struct DeStateStoreItem_ {
73  uint32_t flags;
76 
77 typedef struct DeStateStore_ {
81 
83  DeStateStore *head; /**< head of the list */
84  DeStateStore *cur; /**< current active store */
85  DeStateStore *tail; /**< tail of the list */
87  uint16_t filestore_cnt;
88  uint8_t flags;
89  /* coccinelle: DetectEngineStateDirection:flags:DETECT_ENGINE_STATE_FLAG_ */
91 
92 typedef struct DetectEngineState_ {
95 
96 /**
97  * \brief Alloc a DetectEngineState object.
98  *
99  * \retval Alloc'd instance of DetectEngineState.
100  */
102 
103 /**
104  * \brief Frees a DetectEngineState object.
105  *
106  * \param state DetectEngineState instance to free.
107  */
109 
110 #endif /* SURICATA_DETECT_ENGINE_STATE_H */
111 
112 /**
113  * @}
114  */
DE_STATE_CHUNK_SIZE
#define DE_STATE_CHUNK_SIZE
Definition: detect-engine-state.h:52
DetectEngineStateDirection_::flags
uint8_t flags
Definition: detect-engine-state.h:88
DetectEngineState_
Definition: detect-engine-state.h:92
DetectEngineStateDirection_::cnt
SigIntId cnt
Definition: detect-engine-state.h:86
DetectEngineStateDirection
struct DetectEngineStateDirection_ DetectEngineStateDirection
DetectEngineState
struct DetectEngineState_ DetectEngineState
DetectEngineState_::dir_state
DetectEngineStateDirection dir_state[2]
Definition: detect-engine-state.h:93
DeStateStoreItem_::sid
SigIntId sid
Definition: detect-engine-state.h:74
DetectEngineStateDirection_::cur
DeStateStore * cur
Definition: detect-engine-state.h:84
DeStateStoreItem_::flags
uint32_t flags
Definition: detect-engine-state.h:73
DeStateStore_::next
struct DeStateStore_ * next
Definition: detect-engine-state.h:79
DetectEngineStateAlloc
DetectEngineState * DetectEngineStateAlloc(void)
Alloc a DetectEngineState object.
Definition: detect-engine-state.c:160
DetectEngineStateFree
void DetectEngineStateFree(DetectEngineState *state)
Frees a DetectEngineState object.
Definition: detect-engine-state.c:169
DetectEngineStateDirection_::head
DeStateStore * head
Definition: detect-engine-state.h:83
DeStateStore_
Definition: detect-engine-state.h:77
DetectEngineStateDirection_
Definition: detect-engine-state.h:82
DeStateStore
struct DeStateStore_ DeStateStore
DetectEngineStateDirection_::filestore_cnt
uint16_t filestore_cnt
Definition: detect-engine-state.h:87
DeStateStoreItem
struct DeStateStoreItem_ DeStateStoreItem
DeStateStore_::store
DeStateStoreItem store[DE_STATE_CHUNK_SIZE]
Definition: detect-engine-state.h:78
SigIntId
#define SigIntId
Definition: suricata-common.h:315
DeStateStoreItem_
Definition: detect-engine-state.h:72
DetectEngineStateDirection_::tail
DeStateStore * tail
Definition: detect-engine-state.h:85