~ubuntu-branches/ubuntu/precise/suricata/precise-proposed

« back to all changes in this revision

Viewing changes to src/flow.h

  • Committer: Bazaar Package Importer
  • Author(s): Pierre Chifflier
  • Date: 2010-06-19 17:39:14 UTC
  • mfrom: (1.1.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20100619173914-5vkjfgz24mbia29z
Tags: 0.9.2-1
ImportedĀ UpstreamĀ versionĀ 0.9.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
26
26
 
27
27
#include "decode.h"
28
28
#include "util-var.h"
 
29
#include "util-atomic.h"
29
30
 
30
31
#define FLOW_QUIET      TRUE
31
32
#define FLOW_VERBOSE    FALSE
32
33
 
 
34
#define TOSERVER 0
 
35
#define TOCLIENT 1
 
36
 
33
37
/* per flow flags */
34
38
 
35
39
/** At least on packet from the source address was seen */
59
63
/** All packets in this flow should be accepted */
60
64
#define FLOW_ACTION_PASS            0x0400
61
65
 
 
66
/** Sgh for toserver direction set (even if it's NULL) */
 
67
#define FLOW_SGH_TOSERVER           0x0800
 
68
/** Sgh for toclient direction set (even if it's NULL) */
 
69
#define FLOW_SGH_TOCLIENT           0x1000
 
70
 
62
71
/* pkt flow flags */
63
72
#define FLOW_PKT_TOSERVER               0x01
64
73
#define FLOW_PKT_TOCLIENT               0x02
83
92
 
84
93
    uint32_t emerg_timeout_new;
85
94
    uint32_t emerg_timeout_est;
 
95
    uint32_t flow_try_release;
 
96
    uint32_t emergency_recovery;
86
97
 
87
98
} FlowConfig;
88
99
 
96
107
 
97
108
} FlowKey;
98
109
 
 
110
/**
 
111
 *  \brief Flow data structure.
 
112
 *
 
113
 *  The flow is a global data structure that is created for new packets of a
 
114
 *  flow and then looked up for the following packets of a flow.
 
115
 *
 
116
 *  Locking
 
117
 *
 
118
 *  The flow is updated/used by multiple packets at the same time. This is why
 
119
 *  there is a flow-mutex. It's a mutex and not a spinlock because some
 
120
 *  operations on the flow can be quite expensive, thus spinning would be
 
121
 *  too expensive.
 
122
 *
 
123
 *  The flow "header" (addresses, ports, proto, recursion level) are static
 
124
 *  after the initialization and remain read-only throughout the entire live
 
125
 *  of a flow. This is why we can access those without protection of the lock.
 
126
 */
 
127
 
99
128
typedef struct Flow_
100
129
{
 
130
    /* flow "header", used for hashing and flow lookup. Static after init,
 
131
     * so safe to look at without lock */
101
132
    Address src, dst;
102
133
    union {
103
134
        Port sp;        /**< tcp/udp source port */
110
141
    uint8_t proto;
111
142
    uint8_t recursion_level;
112
143
 
 
144
    /* end of flow "header" */
 
145
 
113
146
    uint16_t flags;
114
147
 
115
148
    /* ts of flow init and last update */
130
163
    /** protocol specific data pointer, e.g. for TcpSession */
131
164
    void *protoctx;
132
165
 
133
 
    /** how many pkts and stream msgs are using the flow *right now* */
134
 
    uint16_t use_cnt;
 
166
    /** how many pkts and stream msgs are using the flow *right now*. This
 
167
     *  variable is atomic so not protected by the Flow mutex "m".
 
168
     *
 
169
     *  On receiving a packet the counter is incremented while the flow
 
170
     *  bucked is locked, which is also the case on timeout pruning.
 
171
     */
 
172
    SC_ATOMIC_DECLARE(unsigned short, use_cnt);
135
173
 
136
174
    /** detection engine state */
137
175
    struct DetectEngineState_ *de_state;
138
176
 
 
177
    /** toclient sgh for this flow. Only use when FLOW_SGH_TOCLIENT flow flag
 
178
     *  has been set. */
 
179
    struct SigGroupHead_ *sgh_toclient;
 
180
    /** toserver sgh for this flow. Only use when FLOW_SGH_TOSERVER flow flag
 
181
     *  has been set. */
 
182
    struct SigGroupHead_ *sgh_toserver;
 
183
 
139
184
    SCMutex m;
140
185
 
141
186
    /* list flow ptrs
147
192
    struct Flow_ *lprev;
148
193
 
149
194
    struct FlowBucket_ *fb;
 
195
 
 
196
    uint16_t alproto; /**< application level protocol */
 
197
    void **aldata; /**< application level storage ptrs */
 
198
    uint8_t alflags; /**< application level specific flags */
 
199
 
150
200
} Flow;
151
201
 
 
202
/** Flow Application Level flags */
 
203
#define FLOW_AL_PROTO_UNKNOWN           0x01
 
204
#define FLOW_AL_PROTO_DETECT_DONE       0x02
 
205
#define FLOW_AL_NO_APPLAYER_INSPECTION  0x04 /** \todo move to flow flags later */
 
206
#define FLOW_AL_STREAM_START            0x08
 
207
#define FLOW_AL_STREAM_EOF              0x10
 
208
#define FLOW_AL_STREAM_TOSERVER         0x20
 
209
#define FLOW_AL_STREAM_TOCLIENT         0x40
 
210
#define FLOW_AL_STREAM_GAP              0x80
 
211
 
152
212
enum {
153
213
    FLOW_STATE_NEW = 0,
154
214
    FLOW_STATE_ESTABLISHED,
171
231
void FlowPrintQueueInfo (void);
172
232
void FlowShutdown(void);
173
233
void FlowSetIPOnlyFlag(Flow *, char);
174
 
void FlowDecrUsecnt(ThreadVars *, Packet *);
 
234
void FlowSetIPOnlyFlagNoLock(Flow *, char);
 
235
 
 
236
void FlowIncrUsecnt(Flow *);
 
237
void FlowDecrUsecnt(Flow *);
 
238
 
 
239
uint32_t FlowPruneFlowsCnt(struct timeval *, int);
 
240
uint32_t FlowKillFlowsCnt(int);
175
241
 
176
242
void *FlowManagerThread(void *td);
177
243
 
182
248
int FlowSetProtoFreeFunc (uint8_t , void (*Free)(void *));
183
249
int FlowSetFlowStateFunc (uint8_t , int (*GetProtoState)(void *));
184
250
void FlowUpdateQueue(Flow *);
 
251
 
185
252
void FlowLockSetNoPacketInspectionFlag(Flow *);
186
253
void FlowSetNoPacketInspectionFlag(Flow *);
187
254
void FlowLockSetNoPayloadInspectionFlag(Flow *);
188
255
void FlowSetNoPayloadInspectionFlag(Flow *);
 
256
void FlowSetSessionNoApplayerInspectionFlag(Flow *);
 
257
 
 
258
int FlowGetPacketDirection(Flow *, Packet *);
 
259
 
 
260
void FlowL7DataPtrInit(Flow *);
 
261
void FlowL7DataPtrFree(Flow *);
189
262
 
190
263
#endif /* __FLOW_H__ */
191
264