• 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

11.11
/src/defrag-timeout.c
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
#include "suricata-common.h"
25
#include "decode.h"
26
#include "defrag.h"
27
#include "defrag-hash.h"
28
#include "defrag-timeout.h"
29

30
/** \internal
31
 *  \brief See if we can really discard this tracker. Check use_cnt reference.
32
 *
33
 *  \param dt tracker
34
 *  \param ts timestamp
35
 *
36
 *  \retval 0 not timed out just yet
37
 *  \retval 1 fully timed out, lets kill it
38
 */
39
int DefragTrackerTimedOut(DefragTracker *dt, SCTime_t ts)
40
{
2,102,536✔
41
    /** never prune a trackers that is used by a packet
42
     *  we are currently processing in one of the threads */
43
    if (SC_ATOMIC_GET(dt->use_cnt) > 0) {
2,102,536✔
44
        return 0;
×
45
    }
×
46

47
    /* retain if remove is not set and not timed out */
48
    if (!dt->remove && SCTIME_CMP_GT(dt->timeout, ts))
2,102,536✔
49
        return 0;
2,036,405✔
50

51
    return 1;
66,131✔
52
}
2,102,536✔
53

54
/**
55
 *  \internal
56
 *
57
 *  \brief check all trackers in a hash row for timing out
58
 *
59
 *  \param hb tracker hash row *LOCKED*
60
 *  \param dt last tracker in the hash row
61
 *  \param ts timestamp
62
 *
63
 *  \retval cnt timed out tracker
64
 */
65
static uint32_t DefragTrackerHashRowTimeout(
66
        DefragTrackerHashRow *hb, DefragTracker *dt, SCTime_t ts)
UNCOV
67
{
×
UNCOV
68
    uint32_t cnt = 0;
×
69

UNCOV
70
    DefragTracker *prev_dt = NULL;
×
UNCOV
71
    do {
×
UNCOV
72
        if (SCMutexTrylock(&dt->lock) != 0) {
×
UNCOV
73
            prev_dt = dt;
×
UNCOV
74
            dt = dt->hnext;
×
UNCOV
75
            continue;
×
UNCOV
76
        }
×
77

UNCOV
78
        DefragTracker *next_dt = dt->hnext;
×
79

80
        /* check if the tracker is fully timed out and
81
         * ready to be discarded. */
UNCOV
82
        if (DefragTrackerTimedOut(dt, ts) == 0) {
×
UNCOV
83
            prev_dt = dt;
×
UNCOV
84
            SCMutexUnlock(&dt->lock);
×
UNCOV
85
            dt = next_dt;
×
UNCOV
86
            continue;
×
UNCOV
87
        }
×
88

89
        /* remove from the hash */
UNCOV
90
        if (prev_dt != NULL) {
×
91
            prev_dt->hnext = dt->hnext;
×
UNCOV
92
        } else {
×
UNCOV
93
            hb->head = dt->hnext;
×
UNCOV
94
        }
×
95

UNCOV
96
        dt->hnext = NULL;
×
97

UNCOV
98
        DefragTrackerClearMemory(dt);
×
99

100
        /* no one is referring to this tracker, use_cnt 0, removed from hash
101
         * so we can unlock it and move it back to the spare queue. */
UNCOV
102
        SCMutexUnlock(&dt->lock);
×
103

104
        /* move to spare list */
UNCOV
105
        DefragTrackerMoveToSpare(dt);
×
106

UNCOV
107
        cnt++;
×
108

UNCOV
109
        dt = next_dt;
×
UNCOV
110
    } while (dt != NULL);
×
111

UNCOV
112
    return cnt;
×
UNCOV
113
}
×
114

115
/**
116
 *  \brief time out tracker from the hash
117
 *
118
 *  \param ts timestamp
119
 *
120
 *  \retval cnt number of timed out tracker
121
 */
122
uint32_t DefragTimeoutHash(SCTime_t ts)
UNCOV
123
{
×
UNCOV
124
    uint32_t idx = 0;
×
UNCOV
125
    uint32_t cnt = 0;
×
126

UNCOV
127
    for (idx = 0; idx < defrag_config.hash_size; idx++) {
×
UNCOV
128
        DefragTrackerHashRow *hb = &defragtracker_hash[idx];
×
129

UNCOV
130
        if (DRLOCK_TRYLOCK(hb) != 0)
×
131
            continue;
×
132

133
        /* defrag hash bucket is now locked */
134

UNCOV
135
        if (hb->head == NULL) {
×
UNCOV
136
            DRLOCK_UNLOCK(hb);
×
UNCOV
137
            continue;
×
UNCOV
138
        }
×
139

140
        /* we have a tracker, or more than one */
UNCOV
141
        cnt += DefragTrackerHashRowTimeout(hb, hb->head, ts);
×
UNCOV
142
        DRLOCK_UNLOCK(hb);
×
UNCOV
143
    }
×
144

UNCOV
145
    return cnt;
×
UNCOV
146
}
×
147

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