suricata
flow-queue.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_QUEUE_H__
25 #define __FLOW_QUEUE_H__
26 
27 #include "suricata-common.h"
28 #include "flow.h"
29 
30 /** Spinlocks or Mutex for the flow queues. */
31 //#define FQLOCK_SPIN
32 #define FQLOCK_MUTEX
33 
34 #ifdef FQLOCK_SPIN
35  #ifdef FQLOCK_MUTEX
36  #error Cannot enable both FQLOCK_SPIN and FQLOCK_MUTEX
37  #endif
38 #endif
39 
40 /* Define a queue for storing flows */
41 typedef struct FlowQueue_
42 {
45  uint32_t len;
46 #ifdef DBG_PERF
47  uint32_t dbg_maxlen;
48 #endif /* DBG_PERF */
49 #ifdef FQLOCK_MUTEX
51 #elif defined FQLOCK_SPIN
52  SCSpinlock s;
53 #else
54  #error Enable FQLOCK_SPIN or FQLOCK_MUTEX
55 #endif
56 } FlowQueue;
57 
58 #ifdef FQLOCK_SPIN
59  #define FQLOCK_INIT(q) SCSpinInit(&(q)->s, 0)
60  #define FQLOCK_DESTROY(q) SCSpinDestroy(&(q)->s)
61  #define FQLOCK_LOCK(q) SCSpinLock(&(q)->s)
62  #define FQLOCK_TRYLOCK(q) SCSpinTrylock(&(q)->s)
63  #define FQLOCK_UNLOCK(q) SCSpinUnlock(&(q)->s)
64 #elif defined FQLOCK_MUTEX
65  #define FQLOCK_INIT(q) SCMutexInit(&(q)->m, NULL)
66  #define FQLOCK_DESTROY(q) SCMutexDestroy(&(q)->m)
67  #define FQLOCK_LOCK(q) SCMutexLock(&(q)->m)
68  #define FQLOCK_TRYLOCK(q) SCMutexTrylock(&(q)->m)
69  #define FQLOCK_UNLOCK(q) SCMutexUnlock(&(q)->m)
70 #else
71  #error Enable FQLOCK_SPIN or FQLOCK_MUTEX
72 #endif
73 
74 /* prototypes */
75 FlowQueue *FlowQueueNew(void);
78 
79 void FlowEnqueue (FlowQueue *, Flow *);
81 
82 void FlowMoveToSpare(Flow *);
83 
84 #endif /* __FLOW_QUEUE_H__ */
85 
#define SCMutex
SCMutex m
Definition: flow-queue.h:50
void FlowQueueDestroy(FlowQueue *)
Destroy a flow queue.
Definition: flow-queue.c:61
FlowQueue * FlowQueueNew(void)
Definition: flow-queue.c:36
Flow * bot
Definition: flow-queue.h:44
FlowQueue * FlowQueueInit(FlowQueue *)
Definition: flow-queue.c:47
Flow * top
Definition: flow-queue.h:43
void FlowMoveToSpare(Flow *)
Transfer a flow from a queue to the spare queue.
Definition: flow-queue.c:146
void FlowEnqueue(FlowQueue *, Flow *)
add a flow to a queue
Definition: flow-queue.c:72
Flow * FlowDequeue(FlowQueue *)
remove a flow from the queue
Definition: flow-queue.c:105
struct FlowQueue_ FlowQueue
#define SCSpinlock
uint32_t len
Definition: flow-queue.h:45
Flow data structure.
Definition: flow.h:325