suricata
defrag-stack.c
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 * Defrag tracker queue handler functions
24 */
25
26#include "suricata-common.h"
27#include "defrag-stack.h"
28#include "util-error.h"
29#include "util-debug.h"
30#include "util-print.h"
31
33{
34 if (q != NULL) {
35 memset(q, 0, sizeof(DefragTrackerStack));
36 DQLOCK_INIT(q);
37 }
38 return q;
39}
40
41/**
42 * \brief Destroy a tracker queue
43 *
44 * \param q the tracker queue to destroy
45 */
50
51/**
52 * \brief add a tracker to a queue
53 *
54 * \param q queue
55 * \param dt tracker
56 */
58{
59#ifdef DEBUG
60 BUG_ON(q == NULL || dt == NULL);
61#endif
62
63 DQLOCK_LOCK(q);
64 dt->lnext = q->s;
65 q->s = dt;
66 q->len++;
67#ifdef DBG_PERF
68 if (q->len > q->dbg_maxlen)
69 q->dbg_maxlen = q->len;
70#endif /* DBG_PERF */
72}
73
74/**
75 * \brief remove a tracker from the queue
76 *
77 * \param q queue
78 *
79 * \retval dt tracker or NULL if empty list.
80 */
82{
83 DQLOCK_LOCK(q);
84
85 DefragTracker *dt = q->s;
86 if (dt == NULL) {
88 return NULL;
89 }
90 q->s = dt->lnext;
91 dt->lnext = NULL;
92
93#ifdef DEBUG
94 BUG_ON(q->len == 0);
95#endif
96 if (q->len > 0)
97 q->len--;
99 return dt;
100}
101
102/**
103 * \brief return stack size
104 */
106{
107 uint32_t len;
108 DQLOCK_LOCK(q);
109 len = q->len;
110 DQLOCK_UNLOCK(q);
111 return len;
112}
uint8_t len
uint32_t DefragTrackerStackSize(DefragTrackerStack *q)
return stack size
DefragTracker * DefragTrackerDequeue(DefragTrackerStack *q)
remove a tracker from the queue
DefragTrackerStack * DefragTrackerStackInit(DefragTrackerStack *q)
void DefragTrackerStackDestroy(DefragTrackerStack *q)
Destroy a tracker queue.
void DefragTrackerEnqueue(DefragTrackerStack *q, DefragTracker *dt)
add a tracker to a queue
#define DQLOCK_DESTROY(q)
#define DQLOCK_INIT(q)
#define DQLOCK_LOCK(q)
#define DQLOCK_UNLOCK(q)
DefragTracker * s
struct DefragTracker_ * lnext
Definition defrag.h:122
#define BUG_ON(x)