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

jasonish / suricata / 23105300094

15 Mar 2026 06:48AM UTC coverage: 75.784% (-0.7%) from 76.495%
23105300094

push

github

jasonish
github-ci: ubuntu minimal build fixups

- Don't run on the GitHub provided VM, it contains a newer Rust than
  stock Ubuntu does.

252836 of 333628 relevant lines covered (75.78%)

1978514.46 hits per line

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

85.19
/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
{
32,497✔
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) {
32,497✔
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))
32,497✔
49
        return 0;
32,459✔
50

51
    return 1;
38✔
52
}
32,497✔
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)
67
{
71✔
68
    uint32_t cnt = 0;
71✔
69

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

78
        DefragTracker *next_dt = dt->hnext;
71✔
79

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

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

96
        dt->hnext = NULL;
36✔
97

98
        DefragTrackerClearMemory(dt);
36✔
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. */
102
        SCMutexUnlock(&dt->lock);
36✔
103

104
        /* move to spare list */
105
        DefragTrackerMoveToSpare(dt);
36✔
106

107
        cnt++;
36✔
108

109
        dt = next_dt;
36✔
110
    } while (dt != NULL);
71✔
111

112
    return cnt;
51✔
113
}
71✔
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)
123
{
2,607✔
124
    uint32_t idx = 0;
2,607✔
125
    uint32_t cnt = 0;
2,607✔
126

127
    for (idx = 0; idx < defrag_config.hash_size; idx++) {
98,355,759✔
128
        DefragTrackerHashRow *hb = &defragtracker_hash[idx];
98,353,152✔
129

130
        if (DRLOCK_TRYLOCK(hb) != 0)
98,353,152✔
131
            continue;
×
132

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

135
        if (hb->head == NULL) {
98,353,152✔
136
            DRLOCK_UNLOCK(hb);
98,353,081✔
137
            continue;
98,353,081✔
138
        }
98,353,081✔
139

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

145
    return cnt;
2,607✔
146
}
2,607✔
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