Coverage Report

Created: 2025-12-31 06:43

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/suricata7/src/flow-hash.h
Line
Count
Source
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
#ifndef __FLOW_HASH_H__
25
#define __FLOW_HASH_H__
26
27
#include "flow.h"
28
29
/** Spinlocks or Mutex for the flow buckets. */
30
//#define FBLOCK_SPIN
31
#define FBLOCK_MUTEX
32
33
#ifdef FBLOCK_SPIN
34
    #ifdef FBLOCK_MUTEX
35
        #error Cannot enable both FBLOCK_SPIN and FBLOCK_MUTEX
36
    #endif
37
#endif
38
39
/* flow hash bucket -- the hash is basically an array of these buckets.
40
 * Each bucket contains a flow or list of flows. All these flows have
41
 * the same hashkey (the hash is a chained hash). When doing modifications
42
 * to the list, the entire bucket is locked. */
43
typedef struct FlowBucket_ {
44
    /** head of the list of active flows for this row. */
45
    Flow *head;
46
    /** head of the list of evicted flows for this row. Waiting to be
47
     *  collected by the Flow Manager. */
48
    Flow *evicted;
49
#ifdef FBLOCK_MUTEX
50
    SCMutex m;
51
#elif defined FBLOCK_SPIN
52
    SCSpinlock s;
53
#else
54
    #error Enable FBLOCK_SPIN or FBLOCK_MUTEX
55
#endif
56
    /** timestamp in seconds of the earliest possible moment a flow
57
     *  will time out in this row. Set by the flow manager. Cleared
58
     *  to 0 by workers, either when new flows are added or when a
59
     *  flow state changes. The flow manager sets this to UINT_MAX for
60
     *  empty buckets. */
61
    SC_ATOMIC_DECLARE(uint32_t, next_ts);
62
} __attribute__((aligned(CLS))) FlowBucket;
63
64
#ifdef FBLOCK_SPIN
65
    #define FBLOCK_INIT(fb) SCSpinInit(&(fb)->s, 0)
66
    #define FBLOCK_DESTROY(fb) SCSpinDestroy(&(fb)->s)
67
    #define FBLOCK_LOCK(fb) SCSpinLock(&(fb)->s)
68
    #define FBLOCK_TRYLOCK(fb) SCSpinTrylock(&(fb)->s)
69
    #define FBLOCK_UNLOCK(fb) SCSpinUnlock(&(fb)->s)
70
#elif defined FBLOCK_MUTEX
71
2.16M
    #define FBLOCK_INIT(fb) SCMutexInit(&(fb)->m, NULL)
72
0
    #define FBLOCK_DESTROY(fb) SCMutexDestroy(&(fb)->m)
73
6.82M
    #define FBLOCK_LOCK(fb) SCMutexLock(&(fb)->m)
74
0
    #define FBLOCK_TRYLOCK(fb) SCMutexTrylock(&(fb)->m)
75
6.82M
    #define FBLOCK_UNLOCK(fb) SCMutexUnlock(&(fb)->m)
76
#else
77
    #error Enable FBLOCK_SPIN or FBLOCK_MUTEX
78
#endif
79
80
/* prototypes */
81
82
Flow *FlowGetFlowFromHash(ThreadVars *tv, FlowLookupStruct *tctx, Packet *, Flow **);
83
84
Flow *FlowGetFromFlowKey(FlowKey *key, struct timespec *ttime, const uint32_t hash);
85
Flow *FlowGetExistingFlowFromFlowId(int64_t flow_id);
86
uint32_t FlowKeyGetHash(FlowKey *flow_key);
87
uint32_t FlowGetIpPairProtoHash(const Packet *p);
88
89
/** \note f->fb must be locked */
90
static inline void RemoveFromHash(Flow *f, Flow *prev_f)
91
0
{
92
0
    FlowBucket *fb = f->fb;
93
94
    /* remove from the hash */
95
0
    if (prev_f != NULL) {
96
0
        prev_f->next = f->next;
97
0
    } else {
98
0
        fb->head = f->next;
99
0
    }
100
101
0
    f->next = NULL;
102
    f->fb = NULL;
103
0
}
Unexecuted instantiation: app-layer-parser.c:RemoveFromHash
Unexecuted instantiation: app-layer-ssh.c:RemoveFromHash
Unexecuted instantiation: app-layer-ssl.c:RemoveFromHash
Unexecuted instantiation: flow.c:RemoveFromHash
Unexecuted instantiation: flow-hash.c:RemoveFromHash
Unexecuted instantiation: flow-manager.c:RemoveFromHash
Unexecuted instantiation: flow-queue.c:RemoveFromHash
Unexecuted instantiation: flow-spare-pool.c:RemoveFromHash
Unexecuted instantiation: flow-storage.c:RemoveFromHash
Unexecuted instantiation: flow-timeout.c:RemoveFromHash
Unexecuted instantiation: flow-util.c:RemoveFromHash
Unexecuted instantiation: runmode-unix-socket.c:RemoveFromHash
Unexecuted instantiation: tmqh-flow.c:RemoveFromHash
Unexecuted instantiation: util-macset.c:RemoveFromHash
Unexecuted instantiation: app-layer.c:RemoveFromHash
Unexecuted instantiation: app-layer-detect-proto.c:RemoveFromHash
Unexecuted instantiation: decode-ipv6.c:RemoveFromHash
Unexecuted instantiation: detect-engine-alert.c:RemoveFromHash
Unexecuted instantiation: detect-engine.c:RemoveFromHash
Unexecuted instantiation: detect-engine-register.c:RemoveFromHash
Unexecuted instantiation: flow-bit.c:RemoveFromHash
Unexecuted instantiation: flow-bypass.c:RemoveFromHash
Unexecuted instantiation: util-runmodes.c:RemoveFromHash
Unexecuted instantiation: util-unittest-helper.c:RemoveFromHash
104
105
#endif /* __FLOW_HASH_H__ */
106