/src/suricata7/src/flow-private.h
Line | Count | Source |
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 __FLOW_PRIVATE_H__ |
25 | | #define __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 | 6.88M | #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 | | |
67 | | enum { |
68 | | FLOW_PROTO_TCP = 0, |
69 | | FLOW_PROTO_UDP, |
70 | | FLOW_PROTO_ICMP, |
71 | | FLOW_PROTO_DEFAULT, |
72 | | |
73 | | /* should be last */ |
74 | | FLOW_PROTO_MAX, |
75 | | }; |
76 | | /* max used in app-layer (counters) */ |
77 | 106 | #define FLOW_PROTO_APPLAYER_MAX FLOW_PROTO_UDP + 1 |
78 | | |
79 | | /* |
80 | | * Variables |
81 | | */ |
82 | | |
83 | | /** FlowProto specific timeouts and free/state functions */ |
84 | | |
85 | | extern FlowProtoTimeout flow_timeouts_normal[FLOW_PROTO_MAX]; |
86 | | extern FlowProtoTimeout flow_timeouts_emerg[FLOW_PROTO_MAX]; |
87 | | extern FlowProtoFreeFunc flow_freefuncs[FLOW_PROTO_MAX]; |
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) */ |
93 | | extern FlowQueue flow_recycle_q; |
94 | | |
95 | | extern FlowBucket *flow_hash; |
96 | | extern FlowConfig flow_config; |
97 | | |
98 | | /** flow memuse counter (atomic), for enforcing memcap limit */ |
99 | | SC_ATOMIC_EXTERN(uint64_t, flow_memuse); |
100 | | |
101 | | typedef FlowProtoTimeout *FlowProtoTimeoutPtr; |
102 | | SC_ATOMIC_EXTERN(FlowProtoTimeoutPtr, flow_timeouts); |
103 | | |
104 | | static inline uint32_t FlowGetFlowTimeoutDirect( |
105 | | const FlowProtoTimeoutPtr flow_timeouts, |
106 | | const enum FlowState state, const uint8_t protomap) |
107 | 0 | { |
108 | 0 | uint32_t timeout; |
109 | 0 | switch (state) { |
110 | 0 | default: |
111 | 0 | case FLOW_STATE_NEW: |
112 | 0 | timeout = flow_timeouts[protomap].new_timeout; |
113 | 0 | break; |
114 | 0 | case FLOW_STATE_ESTABLISHED: |
115 | 0 | timeout = flow_timeouts[protomap].est_timeout; |
116 | 0 | break; |
117 | 0 | case FLOW_STATE_CLOSED: |
118 | 0 | timeout = flow_timeouts[protomap].closed_timeout; |
119 | 0 | break; |
120 | | #ifdef CAPTURE_OFFLOAD |
121 | | case FLOW_STATE_CAPTURE_BYPASSED: |
122 | | timeout = FLOW_BYPASSED_TIMEOUT; |
123 | | break; |
124 | | #endif |
125 | 0 | case FLOW_STATE_LOCAL_BYPASSED: |
126 | 0 | timeout = flow_timeouts[protomap].bypassed_timeout; |
127 | 0 | break; |
128 | 0 | } |
129 | 0 | return timeout; |
130 | 0 | } Unexecuted instantiation: app-layer-parser.c:FlowGetFlowTimeoutDirect Unexecuted instantiation: app-layer-ssh.c:FlowGetFlowTimeoutDirect Unexecuted instantiation: app-layer-ssl.c:FlowGetFlowTimeoutDirect Unexecuted instantiation: flow.c:FlowGetFlowTimeoutDirect Unexecuted instantiation: flow-hash.c:FlowGetFlowTimeoutDirect Unexecuted instantiation: flow-manager.c:FlowGetFlowTimeoutDirect Unexecuted instantiation: flow-queue.c:FlowGetFlowTimeoutDirect Unexecuted instantiation: flow-spare-pool.c:FlowGetFlowTimeoutDirect Unexecuted instantiation: flow-timeout.c:FlowGetFlowTimeoutDirect Unexecuted instantiation: flow-util.c:FlowGetFlowTimeoutDirect Unexecuted instantiation: util-macset.c:FlowGetFlowTimeoutDirect Unexecuted instantiation: app-layer.c:FlowGetFlowTimeoutDirect Unexecuted instantiation: app-layer-detect-proto.c:FlowGetFlowTimeoutDirect Unexecuted instantiation: detect-engine-alert.c:FlowGetFlowTimeoutDirect Unexecuted instantiation: detect-engine.c:FlowGetFlowTimeoutDirect Unexecuted instantiation: detect-engine-register.c:FlowGetFlowTimeoutDirect Unexecuted instantiation: flow-bit.c:FlowGetFlowTimeoutDirect Unexecuted instantiation: flow-bypass.c:FlowGetFlowTimeoutDirect Unexecuted instantiation: util-unittest-helper.c:FlowGetFlowTimeoutDirect |
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 | | */ |
140 | | static inline uint32_t FlowGetFlowTimeout(const Flow *f, enum FlowState state) |
141 | 0 | { |
142 | 0 | FlowProtoTimeoutPtr flow_timeouts = SC_ATOMIC_GET(flow_timeouts); |
143 | 0 | return FlowGetFlowTimeoutDirect(flow_timeouts, state, f->protomap); |
144 | 0 | } Unexecuted instantiation: app-layer-parser.c:FlowGetFlowTimeout Unexecuted instantiation: app-layer-ssh.c:FlowGetFlowTimeout Unexecuted instantiation: app-layer-ssl.c:FlowGetFlowTimeout Unexecuted instantiation: flow.c:FlowGetFlowTimeout Unexecuted instantiation: flow-hash.c:FlowGetFlowTimeout Unexecuted instantiation: flow-manager.c:FlowGetFlowTimeout Unexecuted instantiation: flow-queue.c:FlowGetFlowTimeout Unexecuted instantiation: flow-spare-pool.c:FlowGetFlowTimeout Unexecuted instantiation: flow-timeout.c:FlowGetFlowTimeout Unexecuted instantiation: flow-util.c:FlowGetFlowTimeout Unexecuted instantiation: util-macset.c:FlowGetFlowTimeout Unexecuted instantiation: app-layer.c:FlowGetFlowTimeout Unexecuted instantiation: app-layer-detect-proto.c:FlowGetFlowTimeout Unexecuted instantiation: detect-engine-alert.c:FlowGetFlowTimeout Unexecuted instantiation: detect-engine.c:FlowGetFlowTimeout Unexecuted instantiation: detect-engine-register.c:FlowGetFlowTimeout Unexecuted instantiation: flow-bit.c:FlowGetFlowTimeout Unexecuted instantiation: flow-bypass.c:FlowGetFlowTimeout Unexecuted instantiation: util-unittest-helper.c:FlowGetFlowTimeout |
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 | | */ |
155 | | static inline uint32_t FlowGetTimeoutPolicy(const Flow *f) |
156 | 893k | { |
157 | 893k | uint32_t timeout; |
158 | 893k | FlowProtoTimeoutPtr flow_timeouts = flow_timeouts_normal; |
159 | 893k | switch (f->flow_state) { |
160 | 0 | default: |
161 | 477k | case FLOW_STATE_NEW: |
162 | 477k | timeout = flow_timeouts[f->protomap].new_timeout; |
163 | 477k | break; |
164 | 325k | case FLOW_STATE_ESTABLISHED: |
165 | 325k | timeout = flow_timeouts[f->protomap].est_timeout; |
166 | 325k | break; |
167 | 91.5k | case FLOW_STATE_CLOSED: |
168 | 91.5k | timeout = flow_timeouts[f->protomap].closed_timeout; |
169 | 91.5k | break; |
170 | | #ifdef CAPTURE_OFFLOAD |
171 | | case FLOW_STATE_CAPTURE_BYPASSED: |
172 | | timeout = FLOW_BYPASSED_TIMEOUT; |
173 | | break; |
174 | | #endif |
175 | 23 | case FLOW_STATE_LOCAL_BYPASSED: |
176 | 23 | timeout = flow_timeouts[f->protomap].bypassed_timeout; |
177 | 23 | break; |
178 | 893k | } |
179 | 893k | return timeout; |
180 | 893k | } Unexecuted instantiation: app-layer-parser.c:FlowGetTimeoutPolicy Unexecuted instantiation: app-layer-ssh.c:FlowGetTimeoutPolicy Unexecuted instantiation: app-layer-ssl.c:FlowGetTimeoutPolicy flow.c:FlowGetTimeoutPolicy Line | Count | Source | 156 | 416k | { | 157 | 416k | uint32_t timeout; | 158 | 416k | FlowProtoTimeoutPtr flow_timeouts = flow_timeouts_normal; | 159 | 416k | switch (f->flow_state) { | 160 | 0 | default: | 161 | 0 | case FLOW_STATE_NEW: | 162 | 0 | timeout = flow_timeouts[f->protomap].new_timeout; | 163 | 0 | break; | 164 | 325k | case FLOW_STATE_ESTABLISHED: | 165 | 325k | timeout = flow_timeouts[f->protomap].est_timeout; | 166 | 325k | break; | 167 | 91.5k | case FLOW_STATE_CLOSED: | 168 | 91.5k | timeout = flow_timeouts[f->protomap].closed_timeout; | 169 | 91.5k | break; | 170 | | #ifdef CAPTURE_OFFLOAD | 171 | | case FLOW_STATE_CAPTURE_BYPASSED: | 172 | | timeout = FLOW_BYPASSED_TIMEOUT; | 173 | | break; | 174 | | #endif | 175 | 23 | case FLOW_STATE_LOCAL_BYPASSED: | 176 | 23 | timeout = flow_timeouts[f->protomap].bypassed_timeout; | 177 | 23 | break; | 178 | 416k | } | 179 | 416k | return timeout; | 180 | 416k | } |
Unexecuted instantiation: flow-hash.c:FlowGetTimeoutPolicy Unexecuted instantiation: flow-manager.c:FlowGetTimeoutPolicy Unexecuted instantiation: flow-queue.c:FlowGetTimeoutPolicy Unexecuted instantiation: flow-spare-pool.c:FlowGetTimeoutPolicy Unexecuted instantiation: flow-timeout.c:FlowGetTimeoutPolicy flow-util.c:FlowGetTimeoutPolicy Line | Count | Source | 156 | 477k | { | 157 | 477k | uint32_t timeout; | 158 | 477k | FlowProtoTimeoutPtr flow_timeouts = flow_timeouts_normal; | 159 | 477k | switch (f->flow_state) { | 160 | 0 | default: | 161 | 477k | case FLOW_STATE_NEW: | 162 | 477k | timeout = flow_timeouts[f->protomap].new_timeout; | 163 | 477k | break; | 164 | 0 | case FLOW_STATE_ESTABLISHED: | 165 | 0 | timeout = flow_timeouts[f->protomap].est_timeout; | 166 | 0 | break; | 167 | 0 | case FLOW_STATE_CLOSED: | 168 | 0 | timeout = flow_timeouts[f->protomap].closed_timeout; | 169 | 0 | break; | 170 | | #ifdef CAPTURE_OFFLOAD | 171 | | case FLOW_STATE_CAPTURE_BYPASSED: | 172 | | timeout = FLOW_BYPASSED_TIMEOUT; | 173 | | break; | 174 | | #endif | 175 | 0 | case FLOW_STATE_LOCAL_BYPASSED: | 176 | 0 | timeout = flow_timeouts[f->protomap].bypassed_timeout; | 177 | 0 | break; | 178 | 477k | } | 179 | 477k | return timeout; | 180 | 477k | } |
Unexecuted instantiation: util-macset.c:FlowGetTimeoutPolicy Unexecuted instantiation: app-layer.c:FlowGetTimeoutPolicy Unexecuted instantiation: app-layer-detect-proto.c:FlowGetTimeoutPolicy Unexecuted instantiation: detect-engine-alert.c:FlowGetTimeoutPolicy Unexecuted instantiation: detect-engine.c:FlowGetTimeoutPolicy Unexecuted instantiation: detect-engine-register.c:FlowGetTimeoutPolicy Unexecuted instantiation: flow-bit.c:FlowGetTimeoutPolicy Unexecuted instantiation: flow-bypass.c:FlowGetTimeoutPolicy Unexecuted instantiation: util-unittest-helper.c:FlowGetTimeoutPolicy |
181 | | #endif /* __FLOW_PRIVATE_H__ */ |