• 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

12.5
/src/threadvars.h
1
/* Copyright (C) 2007-2013 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 SURICATA_THREADVARS_H
25
#define SURICATA_THREADVARS_H
26

27
#include "tm-queues.h"
28
#include "counters.h"
29
#include "packet-queue.h"
30
#include "util-atomic.h"
31
#include "util-storage.h"
32

33
struct TmSlot_;
34

35
/** Thread flags set and read by threads to control the threads */
36
// bit 0 vacant
UNCOV
37
#define THV_INIT_DONE           BIT_U32(1)  /** thread initialization done */
×
38
#define THV_PAUSE               BIT_U32(2)  /** signal thread to pause itself */
1✔
UNCOV
39
#define THV_PAUSED              BIT_U32(3)  /** the thread is paused atm */
×
UNCOV
40
#define THV_KILL                BIT_U32(4)  /** thread has been asked to cleanup and exit */
×
UNCOV
41
#define THV_FAILED              BIT_U32(5)  /** thread has encountered an error and failed */
×
UNCOV
42
#define THV_CLOSED              BIT_U32(6)  /** thread done, should be joinable */
×
43
/* used to indicate the thread is going through de-init.  Introduced as more
44
 * of a hack for solving stream-timeout-shutdown.  Is set by the main thread. */
UNCOV
45
#define THV_DEINIT              BIT_U32(7)
×
UNCOV
46
#define THV_RUNNING_DONE        BIT_U32(8)  /** thread has completed running and is entering
×
47
                                         * the de-init phase */
UNCOV
48
#define THV_REQ_FLOW_LOOP       BIT_U32(9)  /**< request thread to enter flow timeout loop */
×
UNCOV
49
#define THV_FLOW_LOOP           BIT_U32(10) /**< thread is in flow shutdown loop */
×
50

51
/** signal thread's capture method to create a fake packet to force through
52
 *  the engine. This is to force timely handling of maintenance tasks like
53
 *  rule reloads even if no packets are read by the capture method. */
UNCOV
54
#define THV_CAPTURE_INJECT_PKT  BIT_U32(11)
×
UNCOV
55
#define THV_DEAD                BIT_U32(12) /**< thread has been joined with pthread_join() */
×
56
#define THV_RUNNING             BIT_U32(13) /**< thread is running */
10,155✔
57

58
/** \brief Per thread variable structure */
59
typedef struct ThreadVars_ {
60
    pthread_t t;
61
    /** function pointer to the function that runs the packet pipeline for
62
     *  this thread. It is passed directly to pthread_create(), hence the
63
     *  void pointers in and out. */
64
    void *(*tm_func)(void *);
65

66
    char name[16];
67
    char *printable_name;
68

69
    uint8_t thread_setup_flags;
70

71
    /** the type of thread as defined in tm-threads.h (TVT_PPT, TVT_MGMT) */
72
    uint8_t type;
73

74
    uint16_t cpu_affinity; /** cpu or core number to set affinity to */
75
    int thread_priority; /** priority (real time) for this thread. Look at threads.h */
76

77

78
    /** TmModule::flags for each module part of this thread */
79
    uint8_t tmm_flags;
80

81
    uint8_t cap_flags; /**< Flags to indicate the capabilities of all the
82
                            TmModules registered under this thread */
83
    uint8_t inq_id;
84
    uint8_t outq_id;
85

86
    /** local id */
87
    int id;
88

89
    /** incoming queue and handler */
90
    Tmq *inq;
91
    struct Packet_ * (*tmqh_in)(struct ThreadVars_ *);
92

93
    SC_ATOMIC_DECLARE(uint32_t, flags);
94

95
    /** list of TmSlot objects together forming the packet pipeline. */
96
    struct TmSlot_ *tm_slots;
97

98
    /** pointer to the flowworker in the pipeline. Used as starting point
99
     *  for injected packets. Can be NULL if the flowworker is not part
100
     *  of this thread. */
101
    struct TmSlot_ *tm_flowworker;
102

103
    /** outgoing queue and handler */
104
    Tmq *outq;
105
    void *outctx;
106
    void (*tmqh_out)(struct ThreadVars_ *, struct Packet_ *);
107

108
    /** Queue for decoders to temporarily store extra packets they
109
     *  generate. These packets are generated as part of the tunnel
110
     *  handling, and are processed directly after the "real" packet
111
     *  from the current position in the pipeline. */
112
    PacketQueueNoLock decode_pq;
113

114
    /** Stream packet queue for flow time out injection. Either a pointer to the
115
     *  workers input queue or to stream_pq_local */
116
    struct PacketQueue_ *stream_pq;
117
    struct PacketQueue_ *stream_pq_local;
118

119
    /* counters */
120

121
    /** private counter store: counter updates modify this */
122
    StatsThreadContext stats;
123

124
    /** pointer to the next thread */
125
    struct ThreadVars_ *next;
126

127
    /* mutex and condition used by management threads */
128

129
    SCCtrlMutex *ctrl_mutex;
130
    SCCtrlCondT *ctrl_cond;
131

132
    struct FlowQueue_ *flow_queue;
133
    bool break_loop;
134

135
    /** Interface-specific thread affinity */
136
    char *iface_name;
137

138
    Storage storage[];
139
} ThreadVars;
140

141
/** Thread setup flags: */
UNCOV
142
#define THREAD_SET_AFFINITY     0x01 /** CPU/Core affinity */
×
UNCOV
143
#define THREAD_SET_PRIORITY     0x02 /** Real time priority */
×
UNCOV
144
#define THREAD_SET_AFFTYPE      0x04 /** Priority and affinity */
×
145

146
#endif /* SURICATA_THREADVARS_H */
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