• 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/host-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 "host.h"
26

27
#include "detect-engine-tag.h"
28

29
#include "host-bit.h"
30
#include "host-timeout.h"
31

32
#include "reputation.h"
33

34
/** \internal
35
 *  \brief See if we can really discard this host. Check use_cnt reference.
36
 *
37
 *  \param h host
38
 *  \param ts timestamp
39
 *
40
 *  \retval 0 not timed out just yet
41
 *  \retval 1 fully timed out, lets kill it
42
 */
43
static int HostHostTimedOut(Host *h, SCTime_t ts)
UNCOV
44
{
×
UNCOV
45
    int busy = 0;
×
46

47
    /** never prune a host that is used by a packet
48
     *  we are currently processing in one of the threads */
UNCOV
49
    if (SC_ATOMIC_GET(h->use_cnt) > 0) {
×
UNCOV
50
        return 0;
×
UNCOV
51
    }
×
52

UNCOV
53
    busy |= (h->iprep && SRepHostTimedOut(h) == 0);
×
UNCOV
54
    busy |= (TagHostHasTag(h) && TagTimeoutCheck(h, ts) == 0);
×
UNCOV
55
    busy |= (HostHasHostBits(h) && HostBitsTimedoutCheck(h, ts) == 0);
×
UNCOV
56
    SCLogDebug("host %p %s", h, busy ? "still active" : "timed out");
×
UNCOV
57
    return !busy;
×
UNCOV
58
}
×
59

60
/**
61
 *  \internal
62
 *
63
 *  \brief check all hosts in a hash row for timing out
64
 *
65
 *  \param hb host hash row *LOCKED*
66
 *  \param h last host in the hash row
67
 *  \param ts timestamp
68
 *
69
 *  \retval cnt timed out hosts
70
 */
71
static uint32_t HostHashRowTimeout(HostHashRow *hb, Host *h, SCTime_t ts)
UNCOV
72
{
×
UNCOV
73
    uint32_t cnt = 0;
×
74

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

UNCOV
81
        Host *next_host = h->hprev;
×
82

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

UNCOV
96
            h->hnext = NULL;
×
UNCOV
97
            h->hprev = NULL;
×
98

UNCOV
99
            HostClearMemory (h);
×
100

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

105
            /* move to spare list */
UNCOV
106
            HostMoveToSpare(h);
×
107

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

UNCOV
113
        h = next_host;
×
UNCOV
114
    } while (h != NULL);
×
115

UNCOV
116
    return cnt;
×
UNCOV
117
}
×
118

119
/**
120
 *  \brief time out hosts from the hash
121
 *
122
 *  \param ts timestamp
123
 *
124
 *  \retval cnt number of timed out host
125
 */
126
uint32_t HostTimeoutHash(SCTime_t ts)
UNCOV
127
{
×
UNCOV
128
    uint32_t idx = 0;
×
UNCOV
129
    uint32_t cnt = 0;
×
130

UNCOV
131
    for (idx = 0; idx < host_config.hash_size; idx++) {
×
UNCOV
132
        HostHashRow *hb = &host_hash[idx];
×
133

UNCOV
134
        if (HRLOCK_TRYLOCK(hb) != 0)
×
135
            continue;
×
136

137
        /* host hash bucket is now locked */
138

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

144
        /* we have a host, or more than one */
UNCOV
145
        cnt += HostHashRowTimeout(hb, hb->tail, ts);
×
UNCOV
146
        HRLOCK_UNLOCK(hb);
×
UNCOV
147
    }
×
148

UNCOV
149
    return cnt;
×
UNCOV
150
}
×
151

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