• 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

0.0
/src/ippair-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 "ippair.h"
26
#include "ippair-bit.h"
27
#include "ippair-timeout.h"
28

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

UNCOV
47
    if (IPPairHasBits(h) && IPPairBitsTimedoutCheck(h, ts) == 0) {
×
UNCOV
48
        vars = 1;
×
UNCOV
49
    }
×
UNCOV
50
    if (vars) {
×
UNCOV
51
        return 0;
×
UNCOV
52
    }
×
53

54
    SCLogDebug("ippair %p timed out", h);
×
55
    return 1;
×
UNCOV
56
}
×
57

58
/**
59
 *  \internal
60
 *
61
 *  \brief check all ippairs in a hash row for timing out
62
 *
63
 *  \param hb ippair hash row *LOCKED*
64
 *  \param h last ippair in the hash row
65
 *  \param ts timestamp
66
 *
67
 *  \retval cnt timed out ippairs
68
 */
69
static uint32_t IPPairHashRowTimeout(IPPairHashRow *hb, IPPair *h, SCTime_t ts)
UNCOV
70
{
×
UNCOV
71
    uint32_t cnt = 0;
×
72

UNCOV
73
    do {
×
UNCOV
74
        if (SCMutexTrylock(&h->m) != 0) {
×
75
            h = h->hprev;
×
76
            continue;
×
77
        }
×
78

UNCOV
79
        IPPair *next_ippair = h->hprev;
×
80

81
        /* check if the ippair is fully timed out and
82
         * ready to be discarded. */
UNCOV
83
        if (IPPairTimedOut(h, ts) == 1) {
×
84
            /* remove from the hash */
85
            if (h->hprev != NULL)
×
86
                h->hprev->hnext = h->hnext;
×
87
            if (h->hnext != NULL)
×
88
                h->hnext->hprev = h->hprev;
×
89
            if (hb->head == h)
×
90
                hb->head = h->hnext;
×
91
            if (hb->tail == h)
×
92
                hb->tail = h->hprev;
×
93

94
            h->hnext = NULL;
×
95
            h->hprev = NULL;
×
96

97
            IPPairClearMemory (h);
×
98

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

103
            /* move to spare list */
104
            IPPairMoveToSpare(h);
×
105

106
            cnt++;
×
UNCOV
107
        } else {
×
UNCOV
108
            SCMutexUnlock(&h->m);
×
UNCOV
109
        }
×
110

UNCOV
111
        h = next_ippair;
×
UNCOV
112
    } while (h != NULL);
×
113

UNCOV
114
    return cnt;
×
UNCOV
115
}
×
116

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

UNCOV
129
    for (idx = 0; idx < ippair_config.hash_size; idx++) {
×
UNCOV
130
        IPPairHashRow *hb = &ippair_hash[idx];
×
131

UNCOV
132
        if (HRLOCK_TRYLOCK(hb) != 0)
×
133
            continue;
×
134

135
        /* ippair hash bucket is now locked */
136

UNCOV
137
        if (hb->tail == NULL) {
×
UNCOV
138
            HRLOCK_UNLOCK(hb);
×
UNCOV
139
            continue;
×
UNCOV
140
        }
×
141

142
        /* we have a ippair, or more than one */
UNCOV
143
        cnt += IPPairHashRowTimeout(hb, hb->tail, ts);
×
UNCOV
144
        HRLOCK_UNLOCK(hb);
×
UNCOV
145
    }
×
146

UNCOV
147
    return cnt;
×
UNCOV
148
}
×
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