• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

OISF / suricata / 23374838686

21 Mar 2026 07:29AM UTC coverage: 59.341% (-20.0%) from 79.315%
23374838686

Pull #15075

github

web-flow
Merge 90b4e834f into 6587e363a
Pull Request #15075: Stack 8001 v16.4

38 of 70 new or added lines in 10 files covered. (54.29%)

34165 existing lines in 563 files now uncovered.

119621 of 201584 relevant lines covered (59.34%)

650666.92 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

38.46
/src/flow-queue.c
1
/* Copyright (C) 2007-2020 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
 * Flow queue handler functions
24
 */
25

26
#include "suricata-common.h"
27
#include "threads.h"
28
#include "flow-private.h"
29
#include "flow-queue.h"
30
#include "flow-util.h"
31
#include "util-error.h"
32
#include "util-debug.h"
33
#include "util-print.h"
34

35
FlowQueue *FlowQueueNew(void)
36
{
1✔
37
    FlowQueue *q = (FlowQueue *)SCMalloc(sizeof(FlowQueue));
1✔
38
    if (q == NULL) {
1✔
39
        SCLogError("Fatal error encountered in FlowQueueNew. Exiting...");
×
40
        exit(EXIT_SUCCESS);
×
41
    }
×
42
    q = FlowQueueInit(q);
1✔
43
    return q;
1✔
44
}
1✔
45

46
FlowQueue *FlowQueueInit (FlowQueue *q)
47
{
3✔
48
    if (q != NULL) {
3✔
49
        memset(q, 0, sizeof(FlowQueue));
3✔
50
        FQLOCK_INIT(q);
3✔
51
    }
3✔
52
    return q;
3✔
53
}
3✔
54

55
/**
56
 *  \brief Destroy a flow queue
57
 *
58
 *  \param q the flow queue to destroy
59
 */
60
void FlowQueueDestroy (FlowQueue *q)
UNCOV
61
{
×
UNCOV
62
    FQLOCK_DESTROY(q);
×
UNCOV
63
}
×
64

65
void FlowQueuePrivateAppendFlow(FlowQueuePrivate *fqc, Flow *f)
66
{
29,384✔
67
    if (fqc->top == NULL) {
29,384✔
68
        fqc->top = fqc->bot = f;
9,549✔
69
        fqc->len = 1;
9,549✔
70
    } else {
19,835✔
71
        fqc->bot->next = f;
19,835✔
72
        fqc->bot = f;
19,835✔
73
        fqc->len++;
19,835✔
74
    }
19,835✔
75
    f->next = NULL;
29,384✔
76
}
29,384✔
77

78
void FlowQueuePrivatePrependFlow(FlowQueuePrivate *fqc, Flow *f)
79
{
9,384✔
80
    f->next = fqc->top;
9,384✔
81
    fqc->top = f;
9,384✔
82
    if (f->next == NULL) {
9,384✔
83
        fqc->bot = f;
7,644✔
84
    }
7,644✔
85
    fqc->len++;
9,384✔
86
}
9,384✔
87

88
void FlowQueuePrivateAppendPrivate(FlowQueuePrivate *dest, FlowQueuePrivate *src)
UNCOV
89
{
×
UNCOV
90
    if (src->top == NULL)
×
91
        return;
×
92

UNCOV
93
    if (dest->bot == NULL) {
×
UNCOV
94
        dest->top = src->top;
×
UNCOV
95
        dest->bot = src->bot;
×
UNCOV
96
        dest->len = src->len;
×
UNCOV
97
    } else {
×
UNCOV
98
        dest->bot->next = src->top;
×
UNCOV
99
        dest->bot = src->bot;
×
UNCOV
100
        dest->len += src->len;
×
UNCOV
101
    }
×
UNCOV
102
    src->top = src->bot = NULL;
×
UNCOV
103
    src->len = 0;
×
UNCOV
104
}
×
105

106
static inline void FlowQueueAtomicSetNonEmpty(FlowQueue *fq)
UNCOV
107
{
×
UNCOV
108
    if (!SC_ATOMIC_GET(fq->non_empty)) {
×
UNCOV
109
        SC_ATOMIC_SET(fq->non_empty, true);
×
UNCOV
110
    }
×
UNCOV
111
}
×
112
static inline void FlowQueueAtomicSetEmpty(FlowQueue *fq)
UNCOV
113
{
×
UNCOV
114
    if (SC_ATOMIC_GET(fq->non_empty)) {
×
UNCOV
115
        SC_ATOMIC_SET(fq->non_empty, false);
×
UNCOV
116
    }
×
UNCOV
117
}
×
118

119
void FlowQueueAppendPrivate(FlowQueue *fq, FlowQueuePrivate *fqc)
UNCOV
120
{
×
UNCOV
121
    if (fqc->top == NULL)
×
UNCOV
122
        return;
×
123

UNCOV
124
    FQLOCK_LOCK(fq);
×
UNCOV
125
    if (fq->qbot == NULL) {
×
UNCOV
126
        fq->qtop = fqc->top;
×
UNCOV
127
        fq->qbot = fqc->bot;
×
UNCOV
128
        fq->qlen = fqc->len;
×
UNCOV
129
    } else {
×
UNCOV
130
        fq->qbot->next = fqc->top;
×
UNCOV
131
        fq->qbot = fqc->bot;
×
UNCOV
132
        fq->qlen += fqc->len;
×
UNCOV
133
    }
×
UNCOV
134
    FlowQueueAtomicSetNonEmpty(fq);
×
UNCOV
135
    FQLOCK_UNLOCK(fq);
×
UNCOV
136
    fqc->top = fqc->bot = NULL;
×
UNCOV
137
    fqc->len = 0;
×
UNCOV
138
}
×
139

140
FlowQueuePrivate FlowQueueExtractPrivate(FlowQueue *fq)
UNCOV
141
{
×
UNCOV
142
    FQLOCK_LOCK(fq);
×
UNCOV
143
    FlowQueuePrivate fqc = fq->priv;
×
UNCOV
144
    fq->qtop = fq->qbot = NULL;
×
UNCOV
145
    fq->qlen = 0;
×
UNCOV
146
    FlowQueueAtomicSetEmpty(fq);
×
UNCOV
147
    FQLOCK_UNLOCK(fq);
×
UNCOV
148
    return fqc;
×
UNCOV
149
}
×
150

151
Flow *FlowQueuePrivateGetFromTop(FlowQueuePrivate *fqc)
152
{
126,110✔
153
    Flow *f = fqc->top;
126,110✔
154
    if (f == NULL) {
126,110✔
155
        return NULL;
97,342✔
156
    }
97,342✔
157

158
    fqc->top = f->next;
28,768✔
159
    f->next = NULL;
28,768✔
160
    fqc->len--;
28,768✔
161
    if (fqc->top == NULL) {
28,768✔
162
        fqc->bot = NULL;
17,093✔
163
    }
17,093✔
164
    return f;
28,768✔
165
}
126,110✔
166

167
/**
168
 *  \brief add a flow to a queue
169
 *
170
 *  \param q queue
171
 *  \param f flow
172
 */
173
void FlowEnqueue (FlowQueue *q, Flow *f)
UNCOV
174
{
×
175
#ifdef DEBUG
176
    BUG_ON(q == NULL || f == NULL);
177
#endif
UNCOV
178
    FQLOCK_LOCK(q);
×
UNCOV
179
    FlowQueuePrivateAppendFlow(&q->priv, f);
×
UNCOV
180
    FlowQueueAtomicSetNonEmpty(q);
×
UNCOV
181
    FQLOCK_UNLOCK(q);
×
UNCOV
182
}
×
183

184
/**
185
 *  \brief remove a flow from the queue
186
 *
187
 *  \param q queue
188
 *
189
 *  \retval f flow or NULL if empty list.
190
 */
191
Flow *FlowDequeue (FlowQueue *q)
UNCOV
192
{
×
UNCOV
193
    FQLOCK_LOCK(q);
×
UNCOV
194
    Flow *f = FlowQueuePrivateGetFromTop(&q->priv);
×
UNCOV
195
    if (f == NULL)
×
UNCOV
196
        FlowQueueAtomicSetEmpty(q);
×
UNCOV
197
    FQLOCK_UNLOCK(q);
×
UNCOV
198
    return f;
×
UNCOV
199
}
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc