/src/suricata8/src/defrag-stack.c
Line | Count | Source |
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 | | |
32 | | DefragTrackerStack *DefragTrackerStackInit(DefragTrackerStack *q) |
33 | 78 | { |
34 | 78 | if (q != NULL) { |
35 | 78 | memset(q, 0, sizeof(DefragTrackerStack)); |
36 | 78 | DQLOCK_INIT(q); |
37 | 78 | } |
38 | 78 | return q; |
39 | 78 | } |
40 | | |
41 | | /** |
42 | | * \brief Destroy a tracker queue |
43 | | * |
44 | | * \param q the tracker queue to destroy |
45 | | */ |
46 | | void DefragTrackerStackDestroy(DefragTrackerStack *q) |
47 | 0 | { |
48 | 0 | DQLOCK_DESTROY(q); |
49 | 0 | } |
50 | | |
51 | | /** |
52 | | * \brief add a tracker to a queue |
53 | | * |
54 | | * \param q queue |
55 | | * \param dt tracker |
56 | | */ |
57 | | void DefragTrackerEnqueue(DefragTrackerStack *q, DefragTracker *dt) |
58 | 149k | { |
59 | | #ifdef DEBUG |
60 | | BUG_ON(q == NULL || dt == NULL); |
61 | | #endif |
62 | | |
63 | 149k | DQLOCK_LOCK(q); |
64 | 149k | dt->lnext = q->s; |
65 | 149k | q->s = dt; |
66 | 149k | q->len++; |
67 | | #ifdef DBG_PERF |
68 | | if (q->len > q->dbg_maxlen) |
69 | | q->dbg_maxlen = q->len; |
70 | | #endif /* DBG_PERF */ |
71 | 149k | DQLOCK_UNLOCK(q); |
72 | 149k | } |
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 | | */ |
81 | | DefragTracker *DefragTrackerDequeue(DefragTrackerStack *q) |
82 | 187k | { |
83 | 187k | DQLOCK_LOCK(q); |
84 | | |
85 | 187k | DefragTracker *dt = q->s; |
86 | 187k | if (dt == NULL) { |
87 | 44.4k | DQLOCK_UNLOCK(q); |
88 | 44.4k | return NULL; |
89 | 44.4k | } |
90 | 142k | q->s = dt->lnext; |
91 | 142k | dt->lnext = NULL; |
92 | | |
93 | | #ifdef DEBUG |
94 | | BUG_ON(q->len == 0); |
95 | | #endif |
96 | 142k | if (q->len > 0) |
97 | 142k | q->len--; |
98 | 142k | DQLOCK_UNLOCK(q); |
99 | 142k | return dt; |
100 | 187k | } |
101 | | |
102 | | /** |
103 | | * \brief return stack size |
104 | | */ |
105 | | uint32_t DefragTrackerStackSize(DefragTrackerStack *q) |
106 | 0 | { |
107 | 0 | uint32_t len; |
108 | 0 | DQLOCK_LOCK(q); |
109 | 0 | len = q->len; |
110 | 0 | DQLOCK_UNLOCK(q); |
111 | 0 | return len; |
112 | 0 | } |