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
29/** Spinlocks or Mutex for the flow queues. */
30//#define FQLOCK_SPIN
31#define FQLOCK_MUTEX
32
33#ifdef FQLOCK_SPIN
34 #ifdef FQLOCK_MUTEX
35 #error Cannot enable both FQLOCK_SPIN and FQLOCK_MUTEX
36 #endif
37#endif
38
45
46/* Define a queue for storing flows */
47typedef struct FlowQueue_
48{
50 SC_ATOMIC_DECLARE(bool,non_empty);
51#ifdef FQLOCK_MUTEX
53#elif defined FQLOCK_SPIN
54 SCSpinlock s;
55#else
56 #error Enable FQLOCK_SPIN or FQLOCK_MUTEX
57#endif
59#define qtop priv.top
60#define qbot priv.bot
61#define qlen priv.len
62
63#ifdef FQLOCK_SPIN
64 #define FQLOCK_INIT(q) SCSpinInit(&(q)->s, 0)
65 #define FQLOCK_DESTROY(q) SCSpinDestroy(&(q)->s)
66 #define FQLOCK_LOCK(q) SCSpinLock(&(q)->s)
67 #define FQLOCK_TRYLOCK(q) SCSpinTrylock(&(q)->s)
68 #define FQLOCK_UNLOCK(q) SCSpinUnlock(&(q)->s)
69#elif defined FQLOCK_MUTEX
70 #define FQLOCK_INIT(q) SCMutexInit(&(q)->m, NULL)
71 #define FQLOCK_DESTROY(q) SCMutexDestroy(&(q)->m)
72 #define FQLOCK_LOCK(q) SCMutexLock(&(q)->m)
73 #define FQLOCK_TRYLOCK(q) SCMutexTrylock(&(q)->m)
74 #define FQLOCK_UNLOCK(q) SCMutexUnlock(&(q)->m)
75#else
76 #error Enable FQLOCK_SPIN or FQLOCK_MUTEX
77#endif
78
79/* prototypes */
83
84void FlowEnqueue (FlowQueue *, Flow *);
87
90
95
96#endif /* SURICATA_FLOW_QUEUE_H */
uint16_t src
struct FlowQueue_ FlowQueue
void FlowQueuePrivatePrependFlow(FlowQueuePrivate *fqc, Flow *f)
Definition flow-queue.c:78
void FlowQueuePrivateAppendFlow(FlowQueuePrivate *fqc, Flow *f)
Definition flow-queue.c:65
void FlowEnqueue(FlowQueue *, Flow *)
add a flow to a queue
Definition flow-queue.c:173
FlowQueue * FlowQueueNew(void)
Definition flow-queue.c:35
void FlowQueueRemove(FlowQueue *fq, Flow *f)
struct FlowQueuePrivate_ FlowQueuePrivate
FlowQueuePrivate FlowQueueExtractPrivate(FlowQueue *fq)
Definition flow-queue.c:140
FlowQueue * FlowQueueInit(FlowQueue *)
Definition flow-queue.c:46
Flow * FlowQueuePrivateGetFromTop(FlowQueuePrivate *fqp)
Definition flow-queue.c:151
void FlowQueuePrivateAppendPrivate(FlowQueuePrivate *dest, FlowQueuePrivate *src)
Definition flow-queue.c:88
void FlowQueueAppendPrivate(FlowQueue *fq, FlowQueuePrivate *fqp)
Definition flow-queue.c:119
Flow * FlowDequeue(FlowQueue *)
remove a flow from the queue
Definition flow-queue.c:191
void FlowQueueDestroy(FlowQueue *)
Destroy a flow queue.
Definition flow-queue.c:60
FlowQueuePrivate priv
Definition flow-queue.h:49
SC_ATOMIC_DECLARE(bool, non_empty)
SCMutex m
Definition flow-queue.h:52
Flow data structure.
Definition flow.h:356
#define SCSpinlock
#define SCMutex