suricata
flow-hash.h
Go to the documentation of this file.
1 /* Copyright (C) 2007-2012 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_HASH_H__
25 #define __FLOW_HASH_H__
26 
27 /** Spinlocks or Mutex for the flow buckets. */
28 //#define FBLOCK_SPIN
29 #define FBLOCK_MUTEX
30 
31 #ifdef FBLOCK_SPIN
32  #ifdef FBLOCK_MUTEX
33  #error Cannot enable both FBLOCK_SPIN and FBLOCK_MUTEX
34  #endif
35 #endif
36 
37 /* flow hash bucket -- the hash is basically an array of these buckets.
38  * Each bucket contains a flow or list of flows. All these flows have
39  * the same hashkey (the hash is a chained hash). When doing modifications
40  * to the list, the entire bucket is locked. */
41 typedef struct FlowBucket_ {
44 #ifdef FBLOCK_MUTEX
46 #elif defined FBLOCK_SPIN
47  SCSpinlock s;
48 #else
49  #error Enable FBLOCK_SPIN or FBLOCK_MUTEX
50 #endif
51  /** timestamp in seconds of the earliest possible moment a flow
52  * will time out in this row. Set by the flow manager. Cleared
53  * to 0 by workers, either when new flows are added or when a
54  * flow state changes. The flow manager sets this to INT_MAX for
55  * empty buckets. */
56  SC_ATOMIC_DECLARE(int32_t, next_ts);
57 } __attribute__((aligned(CLS))) FlowBucket;
58 
59 #ifdef FBLOCK_SPIN
60  #define FBLOCK_INIT(fb) SCSpinInit(&(fb)->s, 0)
61  #define FBLOCK_DESTROY(fb) SCSpinDestroy(&(fb)->s)
62  #define FBLOCK_LOCK(fb) SCSpinLock(&(fb)->s)
63  #define FBLOCK_TRYLOCK(fb) SCSpinTrylock(&(fb)->s)
64  #define FBLOCK_UNLOCK(fb) SCSpinUnlock(&(fb)->s)
65 #elif defined FBLOCK_MUTEX
66  #define FBLOCK_INIT(fb) SCMutexInit(&(fb)->m, NULL)
67  #define FBLOCK_DESTROY(fb) SCMutexDestroy(&(fb)->m)
68  #define FBLOCK_LOCK(fb) SCMutexLock(&(fb)->m)
69  #define FBLOCK_TRYLOCK(fb) SCMutexTrylock(&(fb)->m)
70  #define FBLOCK_UNLOCK(fb) SCMutexUnlock(&(fb)->m)
71 #else
72  #error Enable FBLOCK_SPIN or FBLOCK_MUTEX
73 #endif
74 
75 /* prototypes */
76 
78 
79 Flow *FlowGetFromFlowKey(FlowKey *key, struct timespec *ttime, const uint32_t hash);
80 Flow *FlowGetExistingFlowFromHash(FlowKey * key, uint32_t hash);
81 uint32_t FlowKeyGetHash(FlowKey *flow_key);
82 
84 
85 #endif /* __FLOW_HASH_H__ */
86 
#define SCMutex
SC_ATOMIC_DECLARE(int32_t, next_ts)
SCMutex m
Definition: flow-hash.h:45
uint32_t FlowKeyGetHash(FlowKey *flow_key)
Definition: flow-hash.c:223
void FlowDisableTcpReuseHandling(void)
#define CLS
Flow * head
Definition: flow-hash.h:42
Flow * FlowGetFromFlowKey(FlowKey *key, struct timespec *ttime, const uint32_t hash)
Get or create a Flow using a FlowKey.
Definition: flow-hash.c:745
struct FlowBucket_ __attribute__((aligned(CLS))) FlowBucket
Structure to hold thread specific data for all decode modules.
Definition: decode.h:632
Flow * tail
Definition: flow-hash.h:43
Definition: flow.h:279
Flow * FlowGetExistingFlowFromHash(FlowKey *key, uint32_t hash)
Look for existing Flow using a FlowKey.
Definition: flow-hash.c:819
#define SCSpinlock
Per thread variable structure.
Definition: threadvars.h:57
Flow * FlowGetFlowFromHash(ThreadVars *tv, DecodeThreadVars *dtv, const Packet *, Flow **)
Get Flow for packet.
Definition: flow-hash.c:602
Flow data structure.
Definition: flow.h:325