• 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

80.3
/src/packet.c
1
/* Copyright (C) 2007-2022 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
#include "packet.h"
19
#include "pkt-var.h"
20
#include "flow.h"
21
#include "host.h"
22
#include "util-profiling.h"
23
#include "util-validate.h"
24
#include "action-globals.h"
25
#include "rust.h"
26
#include "app-layer-events.h"
27

28
/** \brief issue drop action
29
 *
30
 *  Set drop (+reject) flags in both current and root packet.
31
 *
32
 *  \param action action bit flags. Must be limited to ACTION_DROP_REJECT|ACTION_ALERT
33
 */
34
void PacketDrop(Packet *p, const uint8_t action, enum PacketDropReason r)
35
{
4,611✔
36
    DEBUG_VALIDATE_BUG_ON((action & ~(ACTION_DROP_REJECT | ACTION_ALERT)) != 0);
4,611✔
37

38
    if (p->drop_reason == PKT_DROP_REASON_NOT_SET)
4,611✔
39
        p->drop_reason = (uint8_t)r;
4,553✔
40

41
    if (p->root) {
4,611✔
UNCOV
42
        p->root->action |= action;
×
UNCOV
43
        if (p->root->drop_reason == PKT_DROP_REASON_NOT_SET) {
×
UNCOV
44
            p->root->drop_reason = PKT_DROP_REASON_INNER_PACKET;
×
UNCOV
45
        }
×
UNCOV
46
    }
×
47
    p->action |= action;
4,611✔
48
}
4,611✔
49

50
bool PacketCheckAction(const Packet *p, const uint8_t a)
51
{
244,952✔
52
    if (likely(p->root == NULL)) {
244,952✔
53
        return (p->action & a) != 0;
244,952✔
54
    } else {
244,952✔
55
        /* check against both */
UNCOV
56
        const uint8_t actions = p->action | p->root->action;
×
UNCOV
57
        return (actions & a) != 0;
×
UNCOV
58
    }
×
59
}
244,952✔
60

61
uint8_t PacketGetAction(const Packet *p)
62
{
107,972✔
63
    if (likely(p->root == NULL)) {
107,972✔
64
        return p->action;
107,972✔
65
    } else {
107,972✔
UNCOV
66
        return p->action | p->root->action;
×
UNCOV
67
    }
×
68
}
107,972✔
69

70
/**
71
 *  \brief Initialize a packet structure for use.
72
 */
73
void PacketInit(Packet *p)
74
{
18,736✔
75
    SCSpinInit(&p->persistent.tunnel_lock, 0);
18,736✔
76
    p->alerts.alerts = PacketAlertCreate();
18,736✔
77
    p->livedev = NULL;
18,736✔
78
}
18,736✔
79

80
void PacketReleaseRefs(Packet *p)
81
{
3,131,603✔
82
    FlowDeReference(&p->flow);
3,131,603✔
83
    HostDeReference(&p->host_src);
3,131,603✔
84
    HostDeReference(&p->host_dst);
3,131,603✔
85
}
3,131,603✔
86

87
/**
88
 *  \brief Recycle a packet structure for reuse.
89
 */
90
void PacketReinit(Packet *p)
91
{
2,271,846✔
92
/* clear the address structure by setting all fields to 0 */
93
#define CLEAR_ADDR(a)                                                                              \
2,271,846✔
94
    do {                                                                                           \
4,543,692✔
95
        (a)->family = 0;                                                                           \
4,543,692✔
96
        (a)->addr_data32[0] = 0;                                                                   \
4,543,692✔
97
        (a)->addr_data32[1] = 0;                                                                   \
4,543,692✔
98
        (a)->addr_data32[2] = 0;                                                                   \
4,543,692✔
99
        (a)->addr_data32[3] = 0;                                                                   \
4,543,692✔
100
    } while (0)
4,543,692✔
101

102
    CLEAR_ADDR(&p->src);
2,271,846✔
103
    CLEAR_ADDR(&p->dst);
2,271,846✔
104
    p->sp = 0;
2,271,846✔
105
    p->dp = 0;
2,271,846✔
106
    p->proto = 0;
2,271,846✔
107
    p->recursion_level = 0;
2,271,846✔
108
    PACKET_FREE_EXTDATA(p);
2,271,846✔
109
    p->app_update_direction = 0;
2,271,846✔
110
    p->sig_mask = 0;
2,271,846✔
111
    p->pkt_hooks = 0;
2,271,846✔
112
    const uint32_t pflags = p->flags;
2,271,846✔
113
    p->flags = 0;
2,271,846✔
114
    p->flowflags = 0;
2,271,846✔
115
    p->pkt_src = 0;
2,271,846✔
116
    p->vlan_id[0] = 0;
2,271,846✔
117
    p->vlan_id[1] = 0;
2,271,846✔
118
    p->vlan_idx = 0;
2,271,846✔
119
    p->ttype = PacketTunnelNone;
2,271,846✔
120
    SCTIME_INIT(p->ts);
2,271,846✔
121
    p->datalink = 0;
2,271,846✔
122
    p->drop_reason = 0;
2,271,846✔
123
#define PACKET_RESET_ACTION(p) (p)->action = 0
2,271,846✔
124
    PACKET_RESET_ACTION(p);
2,271,846✔
125
    if (p->pktvar != NULL) {
2,271,846✔
126
        PktVarFree(p->pktvar);
6✔
127
        p->pktvar = NULL;
6✔
128
    }
6✔
129
    PacketClearL2(p);
2,271,846✔
130
    PacketClearL3(p);
2,271,846✔
131
    PacketClearL4(p);
2,271,846✔
132
    p->payload = NULL;
2,271,846✔
133
    p->payload_len = 0;
2,271,846✔
134
    p->BypassPacketsFlow = NULL;
2,271,846✔
135
#define RESET_PKT_LEN(p) ((p)->pktlen = 0)
2,271,846✔
136
    RESET_PKT_LEN(p);
2,271,846✔
137
    p->alerts.discarded = 0;
2,271,846✔
138
    p->alerts.suppressed = 0;
2,271,846✔
139
    p->alerts.drop.action = 0;
2,271,846✔
140
    if (p->alerts.cnt > 0) {
2,271,846✔
141
        if (pflags & PKT_ALERT_CTX_USED)
73,638✔
UNCOV
142
            PacketAlertRecycle(p->alerts.alerts, p->alerts.cnt);
×
143
        p->alerts.cnt = 0;
73,638✔
144
    }
73,638✔
145
    p->tunnel_rtv_cnt = 0;
2,271,846✔
146
    p->tunnel_tpr_cnt = 0;
2,271,846✔
147
    p->events.cnt = 0;
2,271,846✔
148
    AppLayerDecoderEventsResetEvents(p->app_layer_events);
2,271,846✔
149
    p->next = NULL;
2,271,846✔
150
    p->prev = NULL;
2,271,846✔
151
    p->tunnel_verdicted = false;
2,271,846✔
152
    p->root = NULL;
2,271,846✔
153
    p->livedev = NULL;
2,271,846✔
154
    PACKET_PROFILING_RESET(p);
2,271,846✔
155
    p->tenant_id = 0;
2,271,846✔
156
    p->nb_decoded_layers = 0;
2,271,846✔
157
}
2,271,846✔
158

159
void PacketRecycle(Packet *p)
160
{
1,418,158✔
161
    PacketReleaseRefs(p);
1,418,158✔
162
    PacketReinit(p);
1,418,158✔
163
}
1,418,158✔
164

165
/**
166
 *  \brief Cleanup a packet so that we can free it. No memset needed..
167
 */
168
void PacketDestructor(Packet *p)
169
{
18,480✔
170
    PacketReleaseRefs(p);
18,480✔
171
    if (p->pktvar != NULL) {
18,480✔
172
        PktVarFree(p->pktvar);
2✔
173
    }
2✔
174
    PacketAlertFree(p->alerts.alerts);
18,480✔
175
    PACKET_FREE_EXTDATA(p);
18,480✔
176
    SCSpinDestroy(&p->persistent.tunnel_lock);
18,480✔
177
    SCAppLayerDecoderEventsFreeEvents(&p->app_layer_events);
18,480✔
178
    PACKET_PROFILING_RESET(p);
18,480✔
179
}
18,480✔
180

181
inline void SCPacketSetReleasePacket(Packet *p, void (*ReleasePacket)(Packet *p))
182
{
×
183
    p->ReleasePacket = ReleasePacket;
×
184
}
×
185

186
inline void SCPacketSetLiveDevice(Packet *p, LiveDevice *device)
187
{
×
188
    p->livedev = device;
×
189
}
×
190

191
inline void SCPacketSetDatalink(Packet *p, int datalink)
192
{
×
193
    p->datalink = datalink;
×
194
}
×
195

196
inline void SCPacketSetTime(Packet *p, SCTime_t ts)
197
{
×
198
    p->ts = ts;
×
199
}
×
200

201
inline void SCPacketSetSource(Packet *p, enum PktSrcEnum source)
202
{
×
203
    p->pkt_src = (uint8_t)source;
×
204
}
×
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