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

jasonish / suricata / 23114797756

15 Mar 2026 04:48PM UTC coverage: 79.303% (-0.007%) from 79.31%
23114797756

push

github

jasonish
fixup

265901 of 335299 relevant lines covered (79.3%)

5138115.35 hits per line

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

92.59
/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
{
1,429,366✔
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) {
1,429,366✔
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))
1,429,366✔
49
        return 0;
1,385,454✔
50

51
    return 1;
43,912✔
52
}
1,429,366✔
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
{
1,139✔
68
    uint32_t cnt = 0;
1,139✔
69

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

78
        DefragTracker *next_dt = dt->hnext;
1,146✔
79

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

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

96
        dt->hnext = NULL;
65✔
97

98
        DefragTrackerClearMemory(dt);
65✔
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);
65✔
103

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

107
        cnt++;
65✔
108

109
        dt = next_dt;
65✔
110
    } while (dt != NULL);
1,147✔
111

112
    return cnt;
481✔
113
}
1,139✔
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
{
5,287✔
124
    uint32_t idx = 0;
5,287✔
125
    uint32_t cnt = 0;
5,287✔
126

127
    for (idx = 0; idx < defrag_config.hash_size; idx++) {
267,789,479✔
128
        DefragTrackerHashRow *hb = &defragtracker_hash[idx];
267,784,192✔
129

130
        if (DRLOCK_TRYLOCK(hb) != 0)
267,784,192✔
131
            continue;
×
132

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

135
        if (hb->head == NULL) {
267,784,192✔
136
            DRLOCK_UNLOCK(hb);
267,783,053✔
137
            continue;
267,783,053✔
138
        }
267,783,053✔
139

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

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