suricata
flow-private.h
Go to the documentation of this file.
1/* Copyright (C) 2007-2016 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 * \file
20 *
21 * \author Victor Julien <victor@inliniac.net>
22 */
23
24#ifndef SURICATA_FLOW_PRIVATE_H
25#define SURICATA_FLOW_PRIVATE_H
26
27#include "flow-hash.h"
28#include "flow-queue.h"
29
30#include "util-atomic.h"
31
32/* global flow flags */
33
34/** Flow engine is in emergency mode. This means it doesn't have enough spare
35 * flows for new flows and/or it's memcap limit it reached. In this state the
36 * flow engine with evaluate flows with lower timeout settings. */
37#define FLOW_EMERGENCY 0x01
38
39/* Flow Time out values */
40#define FLOW_DEFAULT_NEW_TIMEOUT 30
41#define FLOW_DEFAULT_EST_TIMEOUT 300
42#define FLOW_DEFAULT_BYPASSED_TIMEOUT 100
43#define FLOW_IPPROTO_TCP_NEW_TIMEOUT 30
44#define FLOW_IPPROTO_TCP_EST_TIMEOUT 300
45#define FLOW_IPPROTO_TCP_CLOSED_TIMEOUT 10
46#define FLOW_IPPROTO_TCP_BYPASSED_TIMEOUT 100
47#define FLOW_IPPROTO_UDP_NEW_TIMEOUT 30
48#define FLOW_IPPROTO_UDP_EST_TIMEOUT 300
49#define FLOW_IPPROTO_UDP_BYPASSED_TIMEOUT 100
50#define FLOW_IPPROTO_ICMP_NEW_TIMEOUT 30
51#define FLOW_IPPROTO_ICMP_EST_TIMEOUT 300
52#define FLOW_IPPROTO_ICMP_BYPASSED_TIMEOUT 100
53
54#define FLOW_DEFAULT_EMERG_NEW_TIMEOUT 10
55#define FLOW_DEFAULT_EMERG_EST_TIMEOUT 100
56#define FLOW_DEFAULT_EMERG_BYPASSED_TIMEOUT 50
57#define FLOW_IPPROTO_TCP_EMERG_NEW_TIMEOUT 10
58#define FLOW_IPPROTO_TCP_EMERG_EST_TIMEOUT 100
59#define FLOW_IPPROTO_TCP_EMERG_CLOSED_TIMEOUT 5
60#define FLOW_IPPROTO_UDP_EMERG_NEW_TIMEOUT 10
61#define FLOW_IPPROTO_UDP_EMERG_EST_TIMEOUT 100
62#define FLOW_IPPROTO_ICMP_EMERG_NEW_TIMEOUT 10
63#define FLOW_IPPROTO_ICMP_EMERG_EST_TIMEOUT 100
64
65#define FLOW_BYPASSED_TIMEOUT 100
66
67enum {
72
73 /* should be last */
75};
76/* max used in app-layer (counters) */
77#define FLOW_PROTO_APPLAYER_MAX (FLOW_PROTO_UDP + 1)
78
79/*
80 * Variables
81 */
82
83/** FlowProto specific timeouts and free/state functions */
84
88
89/** spare/unused/prealloced flows live here */
90//extern FlowQueue flow_spare_q;
91
92/** queue to pass flows to cleanup/log thread(s) */
94
95extern FlowBucket *flow_hash;
97
98/** flow memuse counter (atomic), for enforcing memcap limit */
99SC_ATOMIC_EXTERN(uint64_t, flow_memuse);
100
103
104static inline uint32_t FlowGetFlowTimeoutDirect(
105 const FlowProtoTimeoutPtr flow_timeouts,
106 const enum FlowState state, const uint8_t protomap)
107{
108 uint32_t timeout;
109 switch (state) {
110 default:
111 case FLOW_STATE_NEW:
112 timeout = flow_timeouts[protomap].new_timeout;
113 break;
115 timeout = flow_timeouts[protomap].est_timeout;
116 break;
118 timeout = flow_timeouts[protomap].closed_timeout;
119 break;
120#ifdef CAPTURE_OFFLOAD
121 case FLOW_STATE_CAPTURE_BYPASSED:
122 timeout = FLOW_BYPASSED_TIMEOUT;
123 break;
124#endif
126 timeout = flow_timeouts[protomap].bypassed_timeout;
127 break;
128 }
129 return timeout;
130}
131
132/** \internal
133 * \brief get timeout for flow
134 *
135 * \param f flow
136 * \param state flow state
137 *
138 * \retval timeout timeout in seconds
139 */
140static inline uint32_t FlowGetFlowTimeout(const Flow *f, enum FlowState state)
141{
142 FlowProtoTimeoutPtr flow_timeouts = SC_ATOMIC_GET(flow_timeouts);
143 return FlowGetFlowTimeoutDirect(flow_timeouts, state, f->protomap);
144}
145
146/** \internal
147 * \brief get timeout policy for flow
148 * \note does not take emergency mode into account. Always
149 * returns the 'normal' policy.
150 *
151 * \param f flow
152 *
153 * \retval timeout timeout in seconds
154 */
155static inline uint32_t FlowGetTimeoutPolicy(const Flow *f)
156{
157 uint32_t timeout;
159 switch (f->flow_state) {
160 default:
161 case FLOW_STATE_NEW:
162 timeout = flow_timeouts[f->protomap].new_timeout;
163 break;
165 timeout = flow_timeouts[f->protomap].est_timeout;
166 break;
168 timeout = flow_timeouts[f->protomap].closed_timeout;
169 break;
170#ifdef CAPTURE_OFFLOAD
171 case FLOW_STATE_CAPTURE_BYPASSED:
172 timeout = FLOW_BYPASSED_TIMEOUT;
173 break;
174#endif
176 timeout = flow_timeouts[f->protomap].bypassed_timeout;
177 break;
178 }
179 return timeout;
180}
181#endif /* SURICATA_FLOW_PRIVATE_H */
FlowBucket * flow_hash
Definition flow-hash.c:59
@ FLOW_PROTO_UDP
@ FLOW_PROTO_DEFAULT
@ FLOW_PROTO_TCP
@ FLOW_PROTO_ICMP
@ FLOW_PROTO_MAX
#define FLOW_BYPASSED_TIMEOUT
FlowConfig flow_config
Definition flow.c:93
FlowProtoTimeout * FlowProtoTimeoutPtr
FlowProtoTimeout flow_timeouts_normal[FLOW_PROTO_MAX]
Definition flow.c:88
FlowQueue flow_recycle_q
FlowProtoTimeout flow_timeouts_emerg[FLOW_PROTO_MAX]
Definition flow.c:89
FlowProtoFreeFunc flow_freefuncs[FLOW_PROTO_MAX]
Definition flow.c:91
FlowState
Definition flow.h:503
@ FLOW_STATE_LOCAL_BYPASSED
Definition flow.h:507
@ FLOW_STATE_NEW
Definition flow.h:504
@ FLOW_STATE_CLOSED
Definition flow.h:506
@ FLOW_STATE_ESTABLISHED
Definition flow.h:505
uint32_t bypassed_timeout
Definition flow.h:522
uint32_t est_timeout
Definition flow.h:520
uint32_t closed_timeout
Definition flow.h:521
uint32_t new_timeout
Definition flow.h:519
Flow data structure.
Definition flow.h:356
FlowStateType flow_state
Definition flow.h:412
uint8_t protomap
Definition flow.h:445
#define SC_ATOMIC_EXTERN(type, name)
wrapper for referencing an atomic variable declared on another file.
#define SC_ATOMIC_GET(name)
Get the value from the atomic variable.