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 SURICATA_FLOW_QUEUE_H
25 #define SURICATA_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 typedef struct FlowQueuePrivate_
41 {
44  uint32_t len;
46 
47 /* Define a queue for storing flows */
48 typedef struct FlowQueue_
49 {
51  SC_ATOMIC_DECLARE(bool,non_empty);
52 #ifdef FQLOCK_MUTEX
54 #elif defined FQLOCK_SPIN
55  SCSpinlock s;
56 #else
57  #error Enable FQLOCK_SPIN or FQLOCK_MUTEX
58 #endif
60 #define qtop priv.top
61 #define qbot priv.bot
62 #define qlen priv.len
63 
64 #ifdef FQLOCK_SPIN
65  #define FQLOCK_INIT(q) SCSpinInit(&(q)->s, 0)
66  #define FQLOCK_DESTROY(q) SCSpinDestroy(&(q)->s)
67  #define FQLOCK_LOCK(q) SCSpinLock(&(q)->s)
68  #define FQLOCK_TRYLOCK(q) SCSpinTrylock(&(q)->s)
69  #define FQLOCK_UNLOCK(q) SCSpinUnlock(&(q)->s)
70 #elif defined FQLOCK_MUTEX
71  #define FQLOCK_INIT(q) SCMutexInit(&(q)->m, NULL)
72  #define FQLOCK_DESTROY(q) SCMutexDestroy(&(q)->m)
73  #define FQLOCK_LOCK(q) SCMutexLock(&(q)->m)
74  #define FQLOCK_TRYLOCK(q) SCMutexTrylock(&(q)->m)
75  #define FQLOCK_UNLOCK(q) SCMutexUnlock(&(q)->m)
76 #else
77  #error Enable FQLOCK_SPIN or FQLOCK_MUTEX
78 #endif
79 
80 /* prototypes */
81 FlowQueue *FlowQueueNew(void);
84 
85 void FlowEnqueue (FlowQueue *, Flow *);
88 
91 
96 
97 #endif /* SURICATA_FLOW_QUEUE_H */
FlowQueuePrivatePrependFlow
void FlowQueuePrivatePrependFlow(FlowQueuePrivate *fqc, Flow *f)
Definition: flow-queue.c:78
FlowQueueExtractPrivate
FlowQueuePrivate FlowQueueExtractPrivate(FlowQueue *fq)
Definition: flow-queue.c:140
FlowQueue_::priv
FlowQueuePrivate priv
Definition: flow-queue.h:50
FlowQueuePrivateGetFromTop
Flow * FlowQueuePrivateGetFromTop(FlowQueuePrivate *fqp)
Definition: flow-queue.c:151
Flow_
Flow data structure.
Definition: flow.h:356
FlowQueueDestroy
void FlowQueueDestroy(FlowQueue *)
Destroy a flow queue.
Definition: flow-queue.c:60
FlowQueue
struct FlowQueue_ FlowQueue
FlowQueueNew
FlowQueue * FlowQueueNew(void)
Definition: flow-queue.c:35
FlowQueuePrivate_::len
uint32_t len
Definition: flow-queue.h:44
FlowQueuePrivateAppendFlow
void FlowQueuePrivateAppendFlow(FlowQueuePrivate *fqc, Flow *f)
Definition: flow-queue.c:65
FlowQueuePrivate_::top
Flow * top
Definition: flow-queue.h:42
FlowQueueInit
FlowQueue * FlowQueueInit(FlowQueue *)
Definition: flow-queue.c:46
FlowQueuePrivate_::bot
Flow * bot
Definition: flow-queue.h:43
FlowQueue_::SC_ATOMIC_DECLARE
SC_ATOMIC_DECLARE(bool, non_empty)
FlowDequeue
Flow * FlowDequeue(FlowQueue *)
remove a flow from the queue
Definition: flow-queue.c:191
FlowQueue_
Definition: flow-queue.h:49
FlowQueue_::m
SCMutex m
Definition: flow-queue.h:53
FlowQueuePrivate
struct FlowQueuePrivate_ FlowQueuePrivate
suricata-common.h
FlowEnqueue
void FlowEnqueue(FlowQueue *, Flow *)
add a flow to a queue
Definition: flow-queue.c:173
FlowQueuePrivate_
Definition: flow-queue.h:41
FlowQueueRemove
void FlowQueueRemove(FlowQueue *fq, Flow *f)
FlowQueueAppendPrivate
void FlowQueueAppendPrivate(FlowQueue *fq, FlowQueuePrivate *fqp)
Definition: flow-queue.c:119
src
uint16_t src
Definition: app-layer-dnp3.h:5
SCSpinlock
#define SCSpinlock
Definition: threads-debug.h:234
flow.h
SCMutex
#define SCMutex
Definition: threads-debug.h:114
FlowQueuePrivateAppendPrivate
void FlowQueuePrivateAppendPrivate(FlowQueuePrivate *dest, FlowQueuePrivate *src)
Definition: flow-queue.c:88