• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

OISF / suricata / 22731000775

05 Mar 2026 06:16PM UTC coverage: 79.035% (-0.2%) from 79.283%
22731000775

Pull #14956

github

web-flow
Merge 0d6798ed1 into 7e97dfd52
Pull Request #14956: Draft: windows-pe keyword

1312 of 1773 new or added lines in 11 files covered. (74.0%)

684 existing lines in 56 files now uncovered.

266003 of 336563 relevant lines covered (79.04%)

3075360.67 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

85.48
/src/decode.h
1
/* Copyright (C) 2007-2024 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_DECODE_H
25
#define SURICATA_DECODE_H
26

27
//#define DBG_THREADS
28
#define COUNTERS
29

30
#include "suricata-common.h"
31
#include "suricata-plugin.h"
32
#include "threadvars.h"
33
#include "util-debug.h"
34
#include "decode-events.h"
35
#include "util-exception-policy-types.h"
36
#include "util-datalink.h"
37
#ifdef PROFILING
38
#include "flow-worker.h"
39
#include "app-layer-protos.h"
40
#endif
41

42
typedef enum {
43
    CHECKSUM_VALIDATION_DISABLE,
44
    CHECKSUM_VALIDATION_ENABLE,
45
    CHECKSUM_VALIDATION_AUTO,
46
    CHECKSUM_VALIDATION_RXONLY,
47
    CHECKSUM_VALIDATION_KERNEL,
48
    CHECKSUM_VALIDATION_OFFLOAD,
49
} ChecksumValidationMode;
50

51
enum PktSrcEnum {
52
    PKT_SRC_WIRE = 1,
53
    PKT_SRC_DECODER_GRE,
54
    PKT_SRC_DECODER_IPV4,
55
    PKT_SRC_DECODER_IPV6,
56
    PKT_SRC_DECODER_TEREDO,
57
    PKT_SRC_DEFRAG,
58
    PKT_SRC_FFR,
59
    PKT_SRC_STREAM_TCP_DETECTLOG_FLUSH,
60
    PKT_SRC_DECODER_VXLAN,
61
    PKT_SRC_DETECT_RELOAD_FLUSH,
62
    PKT_SRC_CAPTURE_TIMEOUT,
63
    PKT_SRC_DECODER_GENEVE,
64
    PKT_SRC_SHUTDOWN_FLUSH,
65
};
66

67
#include "source-nflog.h"
68
#include "source-nfq.h"
69
#include "source-ipfw.h"
70
#include "source-pcap.h"
71
#include "source-af-packet.h"
72
#include "source-netmap.h"
73
#include "source-windivert.h"
74
#ifdef HAVE_DPDK
75
#include "source-dpdk.h"
76
#endif
77
#ifdef HAVE_AF_XDP
78
#include "source-af-xdp.h"
79
#endif
80

81
#include "decode-ethernet.h"
82
#include "decode-gre.h"
83
#include "decode-ppp.h"
84
#include "decode-ipv4.h"
85
#include "decode-ipv6.h"
86
#include "decode-icmpv4.h"
87
#include "decode-icmpv6.h"
88
#include "decode-igmp.h"
89
#include "decode-tcp.h"
90
#include "decode-udp.h"
91
#include "decode-sctp.h"
92
#include "decode-esp.h"
93
#include "decode-vlan.h"
94
#include "decode-mpls.h"
95
#include "decode-arp.h"
96

97
#include "util-validate.h"
98

99
/* for now a uint8_t is enough -- here in decode as it's part of the packet */
100
#define SignatureMask uint8_t
191,362✔
101

102
/* forward declarations */
103
struct DetectionEngineThreadCtx_;
104
typedef struct AppLayerThreadCtx_ AppLayerThreadCtx;
105

106
struct PktPool_;
107

108
/* declare these here as they are called from the
109
 * PACKET_RECYCLE and PACKET_CLEANUP macro's. */
110
typedef struct AppLayerDecoderEvents_ AppLayerDecoderEvents;
111

112
/* Address */
113
typedef struct Address_ {
114
    char family;
115
    union {
116
        uint32_t        address_un_data32[4]; /* type-specific field */
117
        uint16_t        address_un_data16[8]; /* type-specific field */
118
        uint8_t         address_un_data8[16]; /* type-specific field */
119
        struct in6_addr address_un_in6;
120
    } address;
121
} Address;
122

123
#define addr_data32 address.address_un_data32
32,755,734✔
124
#define addr_data16 address.address_un_data16
125
#define addr_data8  address.address_un_data8
126
#define addr_in6addr    address.address_un_in6
127

128
#define COPY_ADDRESS(a, b) do {                    \
748,308✔
129
        (b)->family = (a)->family;                 \
748,308✔
130
        (b)->addr_data32[0] = (a)->addr_data32[0]; \
748,308✔
131
        (b)->addr_data32[1] = (a)->addr_data32[1]; \
748,308✔
132
        (b)->addr_data32[2] = (a)->addr_data32[2]; \
748,308✔
133
        (b)->addr_data32[3] = (a)->addr_data32[3]; \
748,308✔
134
    } while (0)
748,308✔
135

136
/* Set the IPv4 addresses into the Addrs of the Packet.
137
 * Make sure p->ip4h is initialized and validated.
138
 *
139
 * We set the rest of the struct to 0 so we can
140
 * prevent using memset. */
141
#define SET_IPV4_SRC_ADDR(ip4h, a)                                                                 \
142
    do {                                                                                           \
2,655,153✔
143
        (a)->family = AF_INET;                                                                     \
2,655,153✔
144
        (a)->addr_data32[0] = (uint32_t)(ip4h)->s_ip_src.s_addr;                                   \
2,655,153✔
145
        (a)->addr_data32[1] = 0;                                                                   \
2,655,153✔
146
        (a)->addr_data32[2] = 0;                                                                   \
2,655,153✔
147
        (a)->addr_data32[3] = 0;                                                                   \
2,655,153✔
148
    } while (0)
2,655,153✔
149

150
#define SET_IPV4_DST_ADDR(ip4h, a)                                                                 \
151
    do {                                                                                           \
2,655,153✔
152
        (a)->family = AF_INET;                                                                     \
2,655,153✔
153
        (a)->addr_data32[0] = (uint32_t)(ip4h)->s_ip_dst.s_addr;                                   \
2,655,153✔
154
        (a)->addr_data32[1] = 0;                                                                   \
2,655,153✔
155
        (a)->addr_data32[2] = 0;                                                                   \
2,655,153✔
156
        (a)->addr_data32[3] = 0;                                                                   \
2,655,153✔
157
    } while (0)
2,655,153✔
158

159
/* Set the IPv6 addresses into the Addrs of the Packet. */
160
#define SET_IPV6_SRC_ADDR(ip6h, a)                                                                 \
161
    do {                                                                                           \
875,285✔
162
        (a)->family = AF_INET6;                                                                    \
875,285✔
163
        (a)->addr_data32[0] = (ip6h)->s_ip6_src[0];                                                \
875,285✔
164
        (a)->addr_data32[1] = (ip6h)->s_ip6_src[1];                                                \
875,285✔
165
        (a)->addr_data32[2] = (ip6h)->s_ip6_src[2];                                                \
875,285✔
166
        (a)->addr_data32[3] = (ip6h)->s_ip6_src[3];                                                \
875,285✔
167
    } while (0)
875,285✔
168

169
#define SET_IPV6_DST_ADDR(ip6h, a)                                                                 \
170
    do {                                                                                           \
875,285✔
171
        (a)->family = AF_INET6;                                                                    \
875,285✔
172
        (a)->addr_data32[0] = (ip6h)->s_ip6_dst[0];                                                \
875,285✔
173
        (a)->addr_data32[1] = (ip6h)->s_ip6_dst[1];                                                \
875,285✔
174
        (a)->addr_data32[2] = (ip6h)->s_ip6_dst[2];                                                \
875,285✔
175
        (a)->addr_data32[3] = (ip6h)->s_ip6_dst[3];                                                \
875,285✔
176
    } while (0)
875,285✔
177

178
/* Set the TCP ports into the Ports of the Packet.
179
 * Make sure p->tcph is initialized and validated. */
180
#define SET_TCP_SRC_PORT(pkt, prt) do {            \
181
        SET_PORT(TCP_GET_SRC_PORT((pkt)), *(prt)); \
182
    } while (0)
183

184
#define SET_TCP_DST_PORT(pkt, prt) do {            \
185
        SET_PORT(TCP_GET_DST_PORT((pkt)), *(prt)); \
186
    } while (0)
187

188
/* Set the UDP ports into the Ports of the Packet.
189
 * Make sure p->udph is initialized and validated. */
190
#define SET_UDP_SRC_PORT(pkt, prt) do {            \
191
        SET_PORT(UDP_GET_SRC_PORT((pkt)), *(prt)); \
192
    } while (0)
193
#define SET_UDP_DST_PORT(pkt, prt) do {            \
194
        SET_PORT(UDP_GET_DST_PORT((pkt)), *(prt)); \
195
    } while (0)
196

197
#define GET_IPV4_SRC_ADDR_U32(p) ((p)->src.addr_data32[0])
135,715✔
198
#define GET_IPV4_DST_ADDR_U32(p) ((p)->dst.addr_data32[0])
135,715✔
199
#define GET_IPV4_SRC_ADDR_PTR(p) ((p)->src.addr_data32)
1,102,845✔
200
#define GET_IPV4_DST_ADDR_PTR(p) ((p)->dst.addr_data32)
1,220,933✔
201

202
#define GET_IPV6_SRC_IN6ADDR(p) ((p)->src.addr_in6addr)
203
#define GET_IPV6_DST_IN6ADDR(p) ((p)->dst.addr_in6addr)
204
#define GET_IPV6_SRC_ADDR(p) ((p)->src.addr_data32)
1,196,815✔
205
#define GET_IPV6_DST_ADDR(p) ((p)->dst.addr_data32)
1,446,004✔
206
#define GET_TCP_SRC_PORT(p)  ((p)->sp)
207
#define GET_TCP_DST_PORT(p)  ((p)->dp)
208

209
#define GET_PKT_LEN(p)             (p)->pktlen
390,588,400✔
210
#define GET_PKT_DATA(p)            (((p)->ext_pkt == NULL) ? GET_PKT_DIRECT_DATA(p) : (p)->ext_pkt)
131,692,900✔
211
#define GET_PKT_DIRECT_DATA(p)     (p)->pkt_data
10,286,529✔
212
#define GET_PKT_DIRECT_MAX_SIZE(p) (default_packet_size)
55,783✔
213

214
#define SET_PKT_LEN(p, len) do { \
127,048,280✔
215
    (p)->pktlen = (len); \
127,048,280✔
216
    } while (0)
127,048,280✔
217

218
/* Port is just a uint16_t */
219
typedef uint16_t Port;
220
#define SET_PORT(v, p) ((p) = (v))
221
#define COPY_PORT(a,b) ((b) = (a))
222

223
#define CMP_ADDR(a1, a2) \
224
    (((a1)->addr_data32[3] == (a2)->addr_data32[3] && \
6,295,547✔
225
      (a1)->addr_data32[2] == (a2)->addr_data32[2] && \
4,228,323✔
226
      (a1)->addr_data32[1] == (a2)->addr_data32[1] && \
4,228,323✔
227
      (a1)->addr_data32[0] == (a2)->addr_data32[0]))
6,295,547✔
228
#define CMP_PORT(p1, p2) \
229
    ((p1) == (p2))
4,738,775✔
230

231
/*Given a packet pkt offset to the start of the ip header in a packet
232
 *We determine the ip version. */
233
#define IP_GET_RAW_VER(pkt) ((((pkt)[0] & 0xf0) >> 4))
418,257✔
234

235
#define PKT_IS_TCP(p)       (((p)->tcph != NULL))
236
#define PKT_IS_UDP(p)       (((p)->udph != NULL))
237
#define PKT_IS_ICMPV4(p)    (((p)->icmpv4h != NULL))
238
#define PKT_IS_ICMPV6(p)    (((p)->icmpv6h != NULL))
239
#define PKT_IS_TOSERVER(p)  (((p)->flowflags & FLOW_PKT_TOSERVER))
47,257,024✔
240
#define PKT_IS_TOCLIENT(p)  (((p)->flowflags & FLOW_PKT_TOCLIENT))
22,095,482✔
241

242
struct PacketContextData {
243
    char *json_string;
244
    struct PacketContextData *next;
245
};
246

247
/* structure to store the sids/gids/etc the detection engine
248
 * found in this packet */
249
typedef struct PacketAlert_ {
250
    SigIntId iid;   /* Internal ID, used for sorting */
251
    uint8_t action; /* Internal num, used for thresholding */
252
    uint8_t flags;
253
    const struct Signature_ *s;
254
    uint64_t tx_id; /* Used for sorting */
255
    int64_t frame_id;
256
    struct PacketContextData *json_info;
257
} PacketAlert;
258

259
/**
260
 * \defgroup PacketAlertFlags
261
 *
262
 * Available flags for PacketAlert.flags.
263
 *
264
 * @{
265
 */
266
/** flag to indicate the rule action (drop/pass) needs to be applied to the flow */
267
#define PACKET_ALERT_FLAG_APPLY_ACTION_TO_FLOW BIT_U8(0)
20,614✔
268
/** alert was generated based on state */
269
#define PACKET_ALERT_FLAG_STATE_MATCH BIT_U8(1)
112,925✔
270
/** alert was generated based on stream */
271
#define PACKET_ALERT_FLAG_STREAM_MATCH BIT_U8(2)
74,197✔
272
/** alert is in a tx, tx_id set */
273
#define PACKET_ALERT_FLAG_TX BIT_U8(3)
2,252,232✔
274
/** action was changed by rate_filter */
275
#define PACKET_ALERT_FLAG_RATE_FILTER_MODIFIED BIT_U8(4)
2,634✔
276
/** alert is in a frame, frame_id set */
277
#define PACKET_ALERT_FLAG_FRAME BIT_U8(5)
2,983,985✔
278
/** alert in a tx was forced */
279
#define PACKET_ALERT_FLAG_TX_GUESSED BIT_U8(6)
1,143,467✔
280
/** accept should be applied to packet */
281
#define PACKET_ALERT_FLAG_APPLY_ACTION_TO_PACKET BIT_U8(7)
2,661✔
282
/** @} */
283

284
extern uint16_t packet_alert_max;
285
#define PACKET_ALERT_MAX 15
286

287
typedef struct PacketAlerts_ {
288
    uint16_t cnt;
289
    uint16_t discarded;
290
    uint16_t suppressed;
291
    PacketAlert *alerts;
292
    /* single pa used when we're dropping,
293
     * so we can log it out in the drop log. */
294
    PacketAlert drop;
295
} PacketAlerts;
296

297
PacketAlert *PacketAlertCreate(void);
298
void PacketAlertRecycle(PacketAlert *pa_array, uint16_t cnt);
299

300
void PacketAlertFree(PacketAlert *pa);
301

302
/** number of decoder events we support per packet. Power of 2 minus 1
303
 *  for memory layout */
304
#define PACKET_ENGINE_EVENT_MAX 15
139,253,227✔
305

306
/** data structure to store decoder, defrag and stream events */
307
typedef struct PacketEngineEvents_ {
308
    uint8_t cnt;                                /**< number of events */
309
    uint8_t events[PACKET_ENGINE_EVENT_MAX];   /**< array of events */
310
} PacketEngineEvents;
311

312
typedef struct PktVar_ {
313
    uint32_t id;
314
    struct PktVar_ *next; /* right now just implement this as a list,
315
                           * in the long run we have thing of something
316
                           * faster. */
317
    uint16_t key_len;
318
    uint16_t value_len;
319
    uint8_t *key;
320
    uint8_t *value;
321
} PktVar;
322

323
#ifdef PROFILING
324

325
/** \brief Per TMM stats storage */
326
typedef struct PktProfilingTmmData_ {
327
    uint64_t ticks_start;
328
    uint64_t ticks_end;
329
#ifdef PROFILE_LOCKING
330
    uint64_t mutex_lock_cnt;
331
    uint64_t mutex_lock_wait_ticks;
332
    uint64_t mutex_lock_contention;
333
    uint64_t spin_lock_cnt;
334
    uint64_t spin_lock_wait_ticks;
335
    uint64_t spin_lock_contention;
336
    uint64_t rww_lock_cnt;
337
    uint64_t rww_lock_wait_ticks;
338
    uint64_t rww_lock_contention;
339
    uint64_t rwr_lock_cnt;
340
    uint64_t rwr_lock_wait_ticks;
341
    uint64_t rwr_lock_contention;
342
#endif
343
} PktProfilingTmmData;
344

345
typedef struct PktProfilingData_ {
346
    uint64_t ticks_start;
347
    uint64_t ticks_end;
348
} PktProfilingData;
349

350
typedef struct PktProfilingDetectData_ {
351
    uint64_t ticks_start;
352
    uint64_t ticks_end;
353
    uint64_t ticks_spent;
354
} PktProfilingDetectData;
355

356
typedef struct PktProfilingAppData_ {
357
    uint64_t ticks_spent;
358
} PktProfilingAppData;
359

360
typedef struct PktProfilingLoggerData_ {
361
    uint64_t ticks_start;
362
    uint64_t ticks_end;
363
    uint64_t ticks_spent;
364
} PktProfilingLoggerData;
365

366
/** \brief Per pkt stats storage */
367
typedef struct PktProfiling_ {
368
    uint64_t ticks_start;
369
    uint64_t ticks_end;
370

371
    PktProfilingTmmData tmm[TMM_SIZE];
372
    PktProfilingData flowworker[PROFILE_FLOWWORKER_SIZE];
373
    PktProfilingDetectData detect[PROF_DETECT_SIZE];
374
    PktProfilingLoggerData logger[LOGGER_SIZE];
375
    uint64_t proto_detect;
376
    PktProfilingAppData app[];
377
} PktProfiling;
378

379
#endif /* PROFILING */
380

381
enum PacketDropReason {
382
    PKT_DROP_REASON_NOT_SET = 0,
383
    PKT_DROP_REASON_DECODE_ERROR,
384
    PKT_DROP_REASON_DEFRAG_ERROR,
385
    PKT_DROP_REASON_DEFRAG_MEMCAP,
386
    PKT_DROP_REASON_FLOW_MEMCAP,
387
    PKT_DROP_REASON_FLOW_DROP,
388
    PKT_DROP_REASON_APPLAYER_ERROR,
389
    PKT_DROP_REASON_APPLAYER_MEMCAP,
390
    PKT_DROP_REASON_RULES,
391
    PKT_DROP_REASON_RULES_THRESHOLD, /**< detection_filter in action */
392
    PKT_DROP_REASON_STREAM_ERROR,
393
    PKT_DROP_REASON_STREAM_MEMCAP,
394
    PKT_DROP_REASON_STREAM_MIDSTREAM,
395
    PKT_DROP_REASON_STREAM_REASSEMBLY,
396
    PKT_DROP_REASON_STREAM_URG,
397
    PKT_DROP_REASON_NFQ_ERROR,             /**< no nfq verdict, must be error */
398
    PKT_DROP_REASON_INNER_PACKET,          /**< drop issued by inner (tunnel) packet */
399
    PKT_DROP_REASON_DEFAULT_PACKET_POLICY, /**< drop issued by default packet policy */
400
    PKT_DROP_REASON_DEFAULT_APP_POLICY,    /**< drop issued by default app policy */
401
    PKT_DROP_REASON_STREAM_PRE_HOOK,       /**< drop issued in the pre_stream hook */
402
    PKT_DROP_REASON_FLOW_PRE_HOOK,         /**< drop issued in the pre_flow hook */
403
    PKT_DROP_REASON_MAX,
404
};
405

406
enum PacketTunnelType {
407
    PacketTunnelNone,
408
    PacketTunnelRoot,
409
    PacketTunnelChild,
410
};
411

412
/* forward declaration since Packet struct definition requires this */
413
struct PacketQueue_;
414

415
enum PacketL2Types {
416
    PACKET_L2_UNKNOWN = 0,
417
    PACKET_L2_ETHERNET,
418
};
419

420
struct PacketL2 {
421
    enum PacketL2Types type;
422
    union L2Hdrs {
423
        EthernetHdr *ethh;
424
    } hdrs;
425
};
426

427
enum PacketL3Types {
428
    PACKET_L3_UNKNOWN = 0,
429
    PACKET_L3_IPV4,
430
    PACKET_L3_IPV6,
431
    PACKET_L3_ARP,
432
};
433

434
struct PacketL3 {
435
    enum PacketL3Types type;
436
    /* Checksum for IP packets. */
437
    bool csum_set;
438
    uint16_t csum;
439
    union Hdrs {
440
        IPV4Hdr *ip4h;
441
        IPV6Hdr *ip6h;
442
        ARPHdr *arph;
443
    } hdrs;
444
    /* IPv4 and IPv6 are mutually exclusive */
445
    union {
446
        IPV4Vars ip4;
447
        struct {
448
            IPV6Vars v;
449
            IPV6ExtHdrs eh;
450
        } ip6;
451
    } vars;
452
};
453

454
enum PacketL4Types {
455
    PACKET_L4_UNKNOWN = 0,
456
    PACKET_L4_TCP,
457
    PACKET_L4_UDP,
458
    PACKET_L4_ICMPV4,
459
    PACKET_L4_ICMPV6,
460
    PACKET_L4_IGMP,
461
    PACKET_L4_SCTP,
462
    PACKET_L4_GRE,
463
    PACKET_L4_ESP,
464
};
465

466
struct PacketL4 {
467
    enum PacketL4Types type;
468
    bool csum_set;
469
    uint16_t csum;
470
    union L4Hdrs {
471
        TCPHdr *tcph;
472
        UDPHdr *udph;
473
        ICMPV4Hdr *icmpv4h;
474
        ICMPV6Hdr *icmpv6h;
475
        SCTPHdr *sctph;
476
        GREHdr *greh;
477
        ESPHdr *esph;
478
        IGMPHdr *igmph;
479
    } hdrs;
480
    union L4Vars {
481
        TCPVars tcp;
482
        ICMPV4Vars icmpv4;
483
        ICMPV6Vars icmpv6;
484
        IGMPVars igmp;
485
    } vars;
486
};
487

488
/* sizes of the members:
489
 * src: 17 bytes
490
 * dst: 17 bytes
491
 * sp/type: 1 byte
492
 * dp/code: 1 byte
493
 * proto: 1 byte
494
 * recurs: 1 byte
495
 *
496
 * sum of above: 38 bytes
497
 *
498
 * flow ptr: 4/8 bytes
499
 * flags: 1 byte
500
 * flowflags: 1 byte
501
 *
502
 * sum of above 44/48 bytes
503
 */
504
typedef struct Packet_
505
{
506
    /* Addresses, Ports and protocol
507
     * these are on top so we can use
508
     * the Packet as a hash key */
509
    Address src;
510
    Address dst;
511
    union {
512
        Port sp;
513
        // icmp type and code of this packet
514
        struct {
515
            uint8_t type;
516
            uint8_t code;
517
        } icmp_s;
518
    };
519
    union {
520
        Port dp;
521
        // icmp type and code of the expected counterpart (for flows)
522
        struct {
523
            uint8_t type;
524
            uint8_t code;
525
        } icmp_d;
526
    };
527
    uint8_t proto;
528
    /* make sure we can't be attacked on when the tunneled packet
529
     * has the exact same tuple as the lower levels */
530
    uint8_t recursion_level;
531

532
    uint16_t vlan_id[VLAN_MAX_LAYERS];
533
    uint8_t vlan_idx;
534

535
    /* flow */
536
    uint8_t flowflags;
537
    /* coccinelle: Packet:flowflags:FLOW_PKT_ */
538

539
    uint8_t app_update_direction; // enum StreamUpdateDir
540

541
    /** sig mask flags this packet has, used in signature matching */
542
    SignatureMask sig_mask;
543

544
    /** bit flags of SignatureHookPkt values this packet should trigger */
545
    uint16_t pkt_hooks;
546

547
    /* tunnel type: none, root or child */
548
    uint8_t ttype; // enum PacketTunnelType
549

550
    /* Pkt Flags */
551
    uint32_t flags;
552

553
    struct Flow_ *flow;
554

555
    /* raw hash value for looking up the flow, will need to modulated to the
556
     * hash size still */
557
    uint32_t flow_hash;
558

559
    SCTime_t ts;
560

561
    union {
562
        /* nfq stuff */
563
#ifdef HAVE_NFLOG
564
        NFLOGPacketVars nflog_v;
565
#endif /* HAVE_NFLOG */
566
#ifdef NFQ
567
        NFQPacketVars nfq_v;
568
#endif /* NFQ */
569
#ifdef IPFW
570
        IPFWPacketVars ipfw_v;
571
#endif /* IPFW */
572
#ifdef AF_PACKET
573
        AFPPacketVars afp_v;
574
#endif
575
#ifdef HAVE_NETMAP
576
        NetmapPacketVars netmap_v;
577
#endif
578
#ifdef WINDIVERT
579
        WinDivertPacketVars windivert_v;
580
#endif /* WINDIVERT */
581
#ifdef HAVE_DPDK
582
        DPDKPacketVars dpdk_v;
583
#endif
584
#ifdef HAVE_AF_XDP
585
        AFXDPPacketVars afxdp_v;
586
#endif
587
        /* A chunk of memory that a plugin can use for its packet vars. */
588
        uint8_t plugin_v[PLUGIN_VAR_SIZE];
589

590
        /** libpcap vars: shared by Pcap Live mode and Pcap File mode */
591
        PcapPacketVars pcap_v;
592
    };
593

594
    /** The release function for packet structure and data */
595
    void (*ReleasePacket)(struct Packet_ *);
596
    /** The function triggering bypass the flow in the capture method.
597
     * Return 1 for success and 0 on error */
598
    int (*BypassPacketsFlow)(struct Packet_ *);
599

600
    /* pkt vars */
601
    PktVar *pktvar;
602

603
    struct PacketL2 l2;
604
    struct PacketL3 l3;
605
    struct PacketL4 l4;
606

607
    /* ptr to the payload of the packet
608
     * with it's length. */
609
    uint8_t *payload;
610
    uint16_t payload_len;
611

612
    /* IPS action to take */
613
    uint8_t action;
614

615
    uint8_t pkt_src;
616

617
    /* storage: set to pointer to heap and extended via allocation if necessary */
618
    uint32_t pktlen;
619
    uint8_t *ext_pkt;
620

621
    /* Incoming interface */
622
    struct LiveDevice_ *livedev;
623

624
    PacketAlerts alerts;
625

626
    struct Host_ *host_src;
627
    struct Host_ *host_dst;
628

629
    /* engine events */
630
    PacketEngineEvents events;
631

632
    AppLayerDecoderEvents *app_layer_events;
633

634
    /* double linked list ptrs */
635
    struct Packet_ *next;
636
    struct Packet_ *prev;
637

638
    /** data linktype in host order */
639
    int datalink;
640

641
    /* count decoded layers of packet : too many layers
642
     * cause issues with performance and stability (stack exhaustion)
643
     */
644
    uint8_t nb_decoded_layers;
645

646
    /* enum PacketDropReason::PKT_DROP_REASON_* as uint8_t for compactness */
647
    uint8_t drop_reason;
648

649
    /** has verdict on this tunneled packet been issued? */
650
    bool tunnel_verdicted;
651

652
    /* tunnel/encapsulation handling */
653
    struct Packet_ *root; /* in case of tunnel this is a ptr
654
                           * to the 'real' packet, the one we
655
                           * need to set the verdict on --
656
                           * It should always point to the lowest
657
                           * packet in a encapsulated packet */
658

659
    /* ready to set verdict counter, only set in root */
660
    uint16_t tunnel_rtv_cnt;
661
    /* tunnel packet ref count */
662
    uint16_t tunnel_tpr_cnt;
663

664
    /** tenant id for this packet, if any. If 0 then no tenant was assigned. */
665
    uint32_t tenant_id;
666

667
    /* The Packet pool from which this packet was allocated. Used when returning
668
     * the packet to its owner's stack. If NULL, then allocated with malloc.
669
     */
670
    struct PktPool_ *pool;
671

672
#ifdef PROFILING
673
    PktProfiling *profile;
674
#endif
675
    /* things in the packet that live beyond a reinit */
676
    struct {
677
        /** lock to protect access to:
678
         *  - tunnel_rtv_cnt
679
         *  - tunnel_tpr_cnt
680
         *  - tunnel_verdicted
681
         *  - nfq_v.mark (if p->ttype != PacketTunnelNone)
682
         */
683
        SCSpinlock tunnel_lock;
684
    } persistent;
685

686
    /** flex array accessor to allocated packet data. Size of the additional
687
     *  data is `default_packet_size`. If this is insufficient,
688
     *  Packet::ext_pkt will be used instead. */
689
    uint8_t pkt_data[];
690
} Packet;
691

692
static inline bool PacketIsIPv4(const Packet *p);
693
static inline bool PacketIsIPv6(const Packet *p);
694

695
/** highest mtu of the interfaces we monitor */
696
#define DEFAULT_MTU 1500
2,193✔
697
#define MINIMUM_MTU 68      /**< ipv4 minimum: rfc791 */
698

699
#define DEFAULT_PACKET_SIZE (DEFAULT_MTU + ETHERNET_HEADER_LEN)
2,193✔
700
/* storage: maximum ip packet size + link header */
701
#define MAX_PAYLOAD_SIZE (IPV6_HEADER_LEN + 65536 + 28)
8,607✔
702
extern uint32_t default_packet_size;
703
#define SIZE_OF_PACKET (default_packet_size + sizeof(Packet))
704

705
static inline bool PacketIsIPv4(const Packet *p)
706
{
19,664,763✔
707
    return p->l3.type == PACKET_L3_IPV4;
19,664,763✔
708
}
19,664,763✔
709

710
static inline const IPV4Hdr *PacketGetIPv4(const Packet *p)
711
{
4,361,895✔
712
    DEBUG_VALIDATE_BUG_ON(!PacketIsIPv4(p));
4,361,895✔
713
    return p->l3.hdrs.ip4h;
4,361,895✔
714
}
4,361,895✔
715

716
static inline IPV4Hdr *PacketSetIPV4(Packet *p, const uint8_t *buf)
717
{
2,741,341✔
718
    DEBUG_VALIDATE_BUG_ON(p->l3.type != PACKET_L3_UNKNOWN);
2,741,341✔
719
    p->l3.type = PACKET_L3_IPV4;
2,741,341✔
720
    p->l3.hdrs.ip4h = (IPV4Hdr *)buf;
2,741,341✔
721
    return p->l3.hdrs.ip4h;
2,741,341✔
722
}
2,741,341✔
723

724
/* Retrieve proto regardless of IP version */
725
static inline uint8_t PacketGetIPProto(const Packet *p)
726
{
12,387,909✔
727
    if (p->proto != 0) {
12,388,107✔
728
        return p->proto;
12,323,673✔
729
    }
12,323,673✔
730
    if (PacketIsIPv4(p)) {
2,147,548,081✔
731
        const IPV4Hdr *hdr = PacketGetIPv4(p);
58,015✔
732
        return IPV4_GET_RAW_IPPROTO(hdr);
58,015✔
733
    } else if (PacketIsIPv6(p)) {
2,147,541,662✔
734
        return IPV6_GET_L4PROTO(p);
1,476✔
735
    }
1,476✔
736
    return 0;
2,147,488,594✔
737
}
2,147,548,081✔
738

739
static inline uint8_t PacketGetIPv4IPProto(const Packet *p)
740
{
×
741
    if (PacketGetIPv4(p)) {
×
742
        const IPV4Hdr *hdr = PacketGetIPv4(p);
×
743
        return IPV4_GET_RAW_IPPROTO(hdr);
×
744
    }
×
745
    return 0;
×
746
}
×
747

748
static inline const IPV6Hdr *PacketGetIPv6(const Packet *p)
749
{
1,327,093✔
750
    DEBUG_VALIDATE_BUG_ON(!PacketIsIPv6(p));
1,327,093✔
751
    return p->l3.hdrs.ip6h;
1,327,093✔
752
}
1,327,093✔
753

754
static inline IPV6Hdr *PacketSetIPV6(Packet *p, const uint8_t *buf)
755
{
880,809✔
756
    DEBUG_VALIDATE_BUG_ON(p->l3.type != PACKET_L3_UNKNOWN);
880,809✔
757
    p->l3.type = PACKET_L3_IPV6;
880,809✔
758
    p->l3.hdrs.ip6h = (IPV6Hdr *)buf;
880,809✔
759
    return p->l3.hdrs.ip6h;
880,809✔
760
}
880,809✔
761

762
static inline bool PacketIsIPv6(const Packet *p)
763
{
5,904,665✔
764
    return p->l3.type == PACKET_L3_IPV6;
5,904,665✔
765
}
5,904,665✔
766

767
static inline void PacketClearL2(Packet *p)
768
{
143,067,490✔
769
    memset(&p->l2, 0, sizeof(p->l2));
143,067,490✔
770
}
143,067,490✔
771

772
/* Can be called multiple times, e.g. for DCE */
773
static inline EthernetHdr *PacketSetEthernet(Packet *p, const uint8_t *buf)
774
{
124,473,245✔
775
    DEBUG_VALIDATE_BUG_ON(p->l2.type != PACKET_L2_UNKNOWN && p->l2.type != PACKET_L2_ETHERNET);
124,473,245✔
776
    p->l2.type = PACKET_L2_ETHERNET;
124,473,245✔
777
    p->l2.hdrs.ethh = (EthernetHdr *)buf;
124,473,245✔
778
    return p->l2.hdrs.ethh;
124,473,245✔
779
}
124,473,245✔
780

781
static inline const EthernetHdr *PacketGetEthernet(const Packet *p)
782
{
1,061✔
783
    DEBUG_VALIDATE_BUG_ON(p->l2.type != PACKET_L2_ETHERNET);
1,061✔
784
    return p->l2.hdrs.ethh;
1,061✔
785
}
1,061✔
786

787
static inline bool PacketIsEthernet(const Packet *p)
788
{
2,845,532✔
789
    return p->l2.type == PACKET_L2_ETHERNET;
2,845,532✔
790
}
2,845,532✔
791

792
static inline void PacketClearL3(Packet *p)
793
{
143,479,998✔
794
    memset(&p->l3, 0, sizeof(p->l3));
143,479,998✔
795
}
143,479,998✔
796

797
static inline void PacketClearL4(Packet *p)
798
{
141,077,413✔
799
    memset(&p->l4, 0, sizeof(p->l4));
141,077,413✔
800
}
141,077,413✔
801

802
static inline TCPHdr *PacketSetTCP(Packet *p, const uint8_t *buf)
803
{
2,341,872✔
804
    DEBUG_VALIDATE_BUG_ON(p->l4.type != PACKET_L4_UNKNOWN);
2,341,872✔
805
    p->l4.type = PACKET_L4_TCP;
2,341,872✔
806
    p->l4.hdrs.tcph = (TCPHdr *)buf;
2,341,872✔
807
    return p->l4.hdrs.tcph;
2,341,872✔
808
}
2,341,872✔
809

810
static inline const TCPHdr *PacketGetTCP(const Packet *p)
811
{
38,108,990✔
812
    DEBUG_VALIDATE_BUG_ON(p->l4.type != PACKET_L4_TCP);
38,108,990✔
813
    return p->l4.hdrs.tcph;
38,108,990✔
814
}
38,108,990✔
815

816
static inline bool PacketIsTCP(const Packet *p)
817
{
12,090,340✔
818
    return p->l4.type == PACKET_L4_TCP;
12,090,340✔
819
}
12,090,340✔
820

821
static inline UDPHdr *PacketSetUDP(Packet *p, const uint8_t *buf)
822
{
148,334✔
823
    DEBUG_VALIDATE_BUG_ON(p->l4.type != PACKET_L4_UNKNOWN);
148,334✔
824
    p->l4.type = PACKET_L4_UDP;
148,334✔
825
    p->l4.hdrs.udph = (UDPHdr *)buf;
148,334✔
826
    return p->l4.hdrs.udph;
148,334✔
827
}
148,334✔
828

829
static inline const UDPHdr *PacketGetUDP(const Packet *p)
830
{
184✔
831
    DEBUG_VALIDATE_BUG_ON(p->l4.type != PACKET_L4_UDP);
184✔
832
    return p->l4.hdrs.udph;
184✔
833
}
184✔
834

835
static inline bool PacketIsUDP(const Packet *p)
836
{
188,740✔
837
    return p->l4.type == PACKET_L4_UDP;
188,740✔
838
}
188,740✔
839

840
static inline ICMPV4Hdr *PacketSetICMPv4(Packet *p, const uint8_t *buf)
841
{
25,047✔
842
    DEBUG_VALIDATE_BUG_ON(p->l4.type != PACKET_L4_UNKNOWN);
25,047✔
843
    p->l4.type = PACKET_L4_ICMPV4;
25,047✔
844
    p->l4.hdrs.icmpv4h = (ICMPV4Hdr *)buf;
25,047✔
845
    return p->l4.hdrs.icmpv4h;
25,047✔
846
}
25,047✔
847

848
static inline const ICMPV4Hdr *PacketGetICMPv4(const Packet *p)
849
{
3,146✔
850
    DEBUG_VALIDATE_BUG_ON(p->l4.type != PACKET_L4_ICMPV4);
3,146✔
851
    return p->l4.hdrs.icmpv4h;
3,146✔
852
}
3,146✔
853

854
static inline bool PacketIsICMPv4(const Packet *p)
855
{
746,808✔
856
    return p->l4.type == PACKET_L4_ICMPV4;
746,808✔
857
}
746,808✔
858

859
static inline const IPV4Hdr *PacketGetICMPv4EmbIPv4(const Packet *p)
860
{
3,058✔
861
    const uint8_t *start = (const uint8_t *)PacketGetICMPv4(p);
3,058✔
862
    const uint8_t *ip = start + p->l4.vars.icmpv4.emb_ip4h_offset;
3,058✔
863
    return (const IPV4Hdr *)ip;
3,058✔
864
}
3,058✔
865

866
static inline ICMPV6Hdr *PacketSetICMPv6(Packet *p, const uint8_t *buf)
867
{
554,329✔
868
    DEBUG_VALIDATE_BUG_ON(p->l4.type != PACKET_L4_UNKNOWN);
554,329✔
869
    p->l4.type = PACKET_L4_ICMPV6;
554,329✔
870
    p->l4.hdrs.icmpv6h = (ICMPV6Hdr *)buf;
554,329✔
871
    return p->l4.hdrs.icmpv6h;
554,329✔
872
}
554,329✔
873

874
static inline const ICMPV6Hdr *PacketGetICMPv6(const Packet *p)
875
{
1,403,126✔
876
    DEBUG_VALIDATE_BUG_ON(p->l4.type != PACKET_L4_ICMPV6);
1,403,126✔
877
    return p->l4.hdrs.icmpv6h;
1,403,126✔
878
}
1,403,126✔
879

880
static inline bool PacketIsICMPv6(const Packet *p)
881
{
898,495✔
882
    return p->l4.type == PACKET_L4_ICMPV6;
898,495✔
883
}
898,495✔
884

885
static inline SCTPHdr *PacketSetSCTP(Packet *p, const uint8_t *buf)
886
{
207✔
887
    DEBUG_VALIDATE_BUG_ON(p->l4.type != PACKET_L4_UNKNOWN);
207✔
888
    p->l4.type = PACKET_L4_SCTP;
207✔
889
    p->l4.hdrs.sctph = (SCTPHdr *)buf;
207✔
890
    return p->l4.hdrs.sctph;
207✔
891
}
207✔
892

893
static inline const SCTPHdr *PacketGetSCTP(const Packet *p)
894
{
×
895
    DEBUG_VALIDATE_BUG_ON(p->l4.type != PACKET_L4_SCTP);
×
896
    return p->l4.hdrs.sctph;
×
897
}
×
898

899
static inline bool PacketIsSCTP(const Packet *p)
900
{
122✔
901
    return p->l4.type == PACKET_L4_SCTP;
122✔
902
}
122✔
903

904
static inline GREHdr *PacketSetGRE(Packet *p, const uint8_t *buf)
905
{
22,269✔
906
    DEBUG_VALIDATE_BUG_ON(p->l4.type != PACKET_L4_UNKNOWN);
22,269✔
907
    p->l4.type = PACKET_L4_GRE;
22,269✔
908
    p->l4.hdrs.greh = (GREHdr *)buf;
22,269✔
909
    return p->l4.hdrs.greh;
22,269✔
910
}
22,269✔
911

912
static inline const GREHdr *PacketGetGRE(const Packet *p)
913
{
×
914
    DEBUG_VALIDATE_BUG_ON(p->l4.type != PACKET_L4_GRE);
×
915
    return p->l4.hdrs.greh;
×
916
}
×
917

918
static inline bool PacketIsGRE(const Packet *p)
919
{
1✔
920
    return p->l4.type == PACKET_L4_GRE;
1✔
921
}
1✔
922

923
static inline ESPHdr *PacketSetESP(Packet *p, const uint8_t *buf)
924
{
469✔
925
    DEBUG_VALIDATE_BUG_ON(p->l4.type != PACKET_L4_UNKNOWN);
469✔
926
    p->l4.type = PACKET_L4_ESP;
469✔
927
    p->l4.hdrs.esph = (ESPHdr *)buf;
469✔
928
    return p->l4.hdrs.esph;
469✔
929
}
469✔
930

931
static inline const ESPHdr *PacketGetESP(const Packet *p)
932
{
127✔
933
    DEBUG_VALIDATE_BUG_ON(p->l4.type != PACKET_L4_ESP);
127✔
934
    return p->l4.hdrs.esph;
127✔
935
}
127✔
936

937
static inline bool PacketIsESP(const Packet *p)
938
{
2,808,461✔
939
    return p->l4.type == PACKET_L4_ESP;
2,808,461✔
940
}
2,808,461✔
941

942
static inline const ARPHdr *PacketGetARP(const Packet *p)
943
{
7✔
944
    DEBUG_VALIDATE_BUG_ON(p->l3.type != PACKET_L3_ARP);
7✔
945
    return p->l3.hdrs.arph;
7✔
946
}
7✔
947

948
static inline ARPHdr *PacketSetARP(Packet *p, const uint8_t *buf)
949
{
12,612✔
950
    DEBUG_VALIDATE_BUG_ON(p->l3.type != PACKET_L3_UNKNOWN);
12,612✔
951
    p->l3.type = PACKET_L3_ARP;
12,612✔
952
    p->l3.hdrs.arph = (ARPHdr *)buf;
12,612✔
953
    return p->l3.hdrs.arph;
12,612✔
954
}
12,612✔
955

956
static inline bool PacketIsARP(const Packet *p)
957
{
28✔
958
    return p->l3.type == PACKET_L3_ARP;
28✔
959
}
28✔
960

961
static inline IGMPHdr *PacketSetIGMP(Packet *p, const uint8_t *buf)
962
{
2,939✔
963
    DEBUG_VALIDATE_BUG_ON(p->l4.type != PACKET_L4_UNKNOWN);
2,939✔
964
    p->l4.type = PACKET_L4_IGMP;
2,939✔
965
    p->l4.hdrs.igmph = (IGMPHdr *)buf;
2,939✔
966
    return p->l4.hdrs.igmph;
2,939✔
967
}
2,939✔
968

969
static inline const IGMPHdr *PacketGetIGMP(const Packet *p)
970
{
3,176✔
971
    DEBUG_VALIDATE_BUG_ON(p->l4.type != PACKET_L4_IGMP);
3,176✔
972
    return p->l4.hdrs.igmph;
3,176✔
973
}
3,176✔
974

975
static inline bool PacketIsIGMP(const Packet *p)
976
{
3,202✔
977
    return p->l4.type == PACKET_L4_IGMP;
3,202✔
978
}
3,202✔
979

980
/** \brief Structure to hold thread specific data for all decode modules */
981
typedef struct DecodeThreadVars_
982
{
983
    /** Specific context for udp protocol detection (here atm) */
984
    AppLayerThreadCtx *app_tctx;
985

986
    /** stats/counters */
987
    StatsCounterId counter_pkts;
988
    StatsCounterId counter_bytes;
989
    StatsCounterDeriveId counter_avg_pkt_size;
990
    StatsCounterMaxId counter_max_pkt_size;
991
    StatsCounterMaxId counter_max_mac_addrs_src;
992
    StatsCounterMaxId counter_max_mac_addrs_dst;
993

994
    StatsCounterId counter_invalid;
995

996
    StatsCounterId counter_eth;
997
    StatsCounterId counter_chdlc;
998
    StatsCounterId counter_ipv4;
999
    StatsCounterId counter_ipv6;
1000
    StatsCounterId counter_tcp;
1001
    StatsCounterId counter_tcp_syn;
1002
    StatsCounterId counter_tcp_synack;
1003
    StatsCounterId counter_tcp_rst;
1004
    StatsCounterId counter_tcp_urg;
1005
    StatsCounterId counter_udp;
1006
    StatsCounterId counter_icmpv4;
1007
    StatsCounterId counter_icmpv6;
1008
    StatsCounterId counter_igmp;
1009
    StatsCounterId counter_arp;
1010
    StatsCounterId counter_ethertype_unknown;
1011

1012
    StatsCounterId counter_sll;
1013
    StatsCounterId counter_sll2;
1014
    StatsCounterId counter_raw;
1015
    StatsCounterId counter_null;
1016
    StatsCounterId counter_sctp;
1017
    StatsCounterId counter_esp;
1018
    StatsCounterId counter_ppp;
1019
    StatsCounterId counter_geneve;
1020
    StatsCounterId counter_gre;
1021
    StatsCounterId counter_vlan;
1022
    StatsCounterId counter_vlan_qinq;
1023
    StatsCounterId counter_vlan_qinqinq;
1024
    StatsCounterId counter_vxlan;
1025
    StatsCounterId counter_vntag;
1026
    StatsCounterId counter_etag;
1027
    StatsCounterId counter_ieee8021ah;
1028
    StatsCounterId counter_pppoe;
1029
    StatsCounterId counter_teredo;
1030
    StatsCounterId counter_mpls;
1031
    StatsCounterId counter_ipv4inipv4;
1032
    StatsCounterId counter_ipv6inipv4;
1033
    StatsCounterId counter_ipv4inipv6;
1034
    StatsCounterId counter_ipv6inipv6;
1035
    StatsCounterId counter_ipv4_unknown_proto;
1036
    StatsCounterId counter_erspan;
1037
    StatsCounterId counter_nsh;
1038

1039
    /** frag stats - defrag runs in the context of the decoder. */
1040
    StatsCounterId counter_defrag_ipv4_fragments;
1041
    StatsCounterId counter_defrag_ipv4_reassembled;
1042
    StatsCounterId counter_defrag_ipv6_fragments;
1043
    StatsCounterId counter_defrag_ipv6_reassembled;
1044
    StatsCounterId counter_defrag_max_hit;
1045
    StatsCounterId counter_defrag_no_frags;
1046
    StatsCounterId counter_defrag_tracker_soft_reuse;
1047
    StatsCounterId counter_defrag_tracker_hard_reuse;
1048
    StatsCounterId counter_defrag_tracker_timeout;
1049
    ExceptionPolicyCounters counter_defrag_memcap_eps;
1050

1051
    StatsCounterId counter_flow_memcap;
1052
    ExceptionPolicyCounters counter_flow_memcap_eps;
1053

1054
    StatsCounterId counter_tcp_active_sessions;
1055
    StatsCounterId counter_flow_total;
1056
    StatsCounterId counter_flow_active;
1057
    StatsCounterId counter_flow_tcp;
1058
    StatsCounterId counter_flow_udp;
1059
    StatsCounterId counter_flow_icmp4;
1060
    StatsCounterId counter_flow_icmp6;
1061
    StatsCounterId counter_flow_tcp_reuse;
1062
    StatsCounterId counter_flow_elephant;
1063
    StatsCounterId counter_flow_elephant_toserver;
1064
    StatsCounterId counter_flow_elephant_toclient;
1065
    StatsCounterId counter_flow_get_used;
1066
    StatsCounterId counter_flow_get_used_eval;
1067
    StatsCounterId counter_flow_get_used_eval_reject;
1068
    StatsCounterId counter_flow_get_used_eval_busy;
1069
    StatsCounterId counter_flow_get_used_failed;
1070

1071
    StatsCounterId counter_flow_spare_sync;
1072
    StatsCounterId counter_flow_spare_sync_empty;
1073
    StatsCounterId counter_flow_spare_sync_incomplete;
1074
    StatsCounterAvgId counter_flow_spare_sync_avg;
1075

1076
    StatsCounterId counter_engine_events[DECODE_EVENT_MAX];
1077

1078
    /* thread data for flow logging api: only used at forced
1079
     * flow recycle during lookups */
1080
    void *output_flow_thread_data;
1081

1082
} DecodeThreadVars;
1083

1084
void CaptureStatsUpdate(ThreadVars *tv, const Packet *p);
1085
void CaptureStatsSetup(ThreadVars *tv);
1086

1087
#define PACKET_CLEAR_L4VARS(p) do {                         \
1088
        memset(&(p)->l4vars, 0x00, sizeof((p)->l4vars));    \
1089
    } while (0)
1090

1091
/* if p uses extended data, free them */
1092
#define PACKET_FREE_EXTDATA(p) do {                 \
151,353,659✔
1093
        if ((p)->ext_pkt) {                         \
152,232,987✔
1094
            if (!((p)->flags & PKT_ZERO_COPY)) {    \
119,960,725✔
1095
                SCFree((p)->ext_pkt);               \
26,096✔
1096
            }                                       \
26,096✔
1097
            (p)->ext_pkt = NULL;                    \
119,960,725✔
1098
        }                                           \
119,960,725✔
1099
    } while(0)
151,353,659✔
1100

1101
#define TUNNEL_INCR_PKT_RTV_NOLOCK(p) do {                                          \
38,128✔
1102
        ((p)->root ? (p)->root->tunnel_rtv_cnt++ : (p)->tunnel_rtv_cnt++);          \
38,128✔
1103
    } while (0)
38,128✔
1104

1105
static inline void TUNNEL_INCR_PKT_TPR(Packet *p)
1106
{
35,176✔
1107
    Packet *rp = p->root ? p->root : p;
35,176✔
1108
    SCSpinLock(&rp->persistent.tunnel_lock);
35,176✔
1109
    rp->tunnel_tpr_cnt++;
35,176✔
1110
    SCSpinUnlock(&rp->persistent.tunnel_lock);
35,176✔
1111
}
35,176✔
1112

1113
#define TUNNEL_PKT_RTV(p) ((p)->root ? (p)->root->tunnel_rtv_cnt : (p)->tunnel_rtv_cnt)
74,329✔
1114
#define TUNNEL_PKT_TPR(p) ((p)->root ? (p)->root->tunnel_tpr_cnt : (p)->tunnel_tpr_cnt)
74,329✔
1115

1116
static inline bool PacketTunnelIsVerdicted(const Packet *p)
1117
{
31,771✔
1118
    return p->tunnel_verdicted;
31,771✔
1119
}
31,771✔
1120
static inline void PacketTunnelSetVerdicted(Packet *p)
1121
{
772✔
1122
    p->tunnel_verdicted = true;
772✔
1123
}
772✔
1124

1125
enum DecodeTunnelProto {
1126
    DECODE_TUNNEL_ETHERNET,
1127
    DECODE_TUNNEL_ERSPANII,
1128
    DECODE_TUNNEL_ERSPANI,
1129
    DECODE_TUNNEL_VXLAN,
1130
    DECODE_TUNNEL_VLAN,
1131
    DECODE_TUNNEL_IPV4,
1132
    DECODE_TUNNEL_IPV6,
1133
    DECODE_TUNNEL_IPV6_TEREDO, /**< separate protocol for stricter error handling */
1134
    DECODE_TUNNEL_PPP,
1135
    DECODE_TUNNEL_NSH,
1136
    DECODE_TUNNEL_ARP,
1137
    DECODE_TUNNEL_UNSET
1138
};
1139

1140
Packet *PacketTunnelPktSetup(ThreadVars *tv, DecodeThreadVars *dtv, Packet *parent,
1141
                             const uint8_t *pkt, uint32_t len, enum DecodeTunnelProto proto);
1142
Packet *PacketDefragPktSetup(Packet *parent, const uint8_t *pkt, uint32_t len, uint8_t proto);
1143
void PacketDefragPktSetupParent(Packet *parent);
1144
void DecodeRegisterPerfCounters(DecodeThreadVars *, ThreadVars *);
1145
Packet *PacketGetFromQueueOrAlloc(void);
1146
Packet *PacketGetFromAlloc(void);
1147
void PacketDecodeFinalize(ThreadVars *tv, DecodeThreadVars *dtv, Packet *p);
1148
void PacketUpdateEngineEventCounters(ThreadVars *tv,
1149
        DecodeThreadVars *dtv, Packet *p);
1150
void PacketFree(Packet *p);
1151
void PacketFreeOrRelease(Packet *p);
1152
int PacketCallocExtPkt(Packet *p, int datalen);
1153
int PacketCopyData(Packet *p, const uint8_t *pktdata, uint32_t pktlen);
1154
int PacketSetData(Packet *p, const uint8_t *pktdata, uint32_t pktlen);
1155
int PacketCopyDataOffset(Packet *p, uint32_t offset, const uint8_t *data, uint32_t datalen);
1156
const char *PktSrcToString(enum PktSrcEnum pkt_src);
1157
void PacketBypassCallback(Packet *p);
1158
void PacketSwap(Packet *p);
1159

1160
DecodeThreadVars *DecodeThreadVarsAlloc(ThreadVars *);
1161
void DecodeThreadVarsFree(ThreadVars *, DecodeThreadVars *);
1162
void DecodeUpdatePacketCounters(ThreadVars *tv,
1163
                                const DecodeThreadVars *dtv, const Packet *p);
1164
const char *PacketDropReasonToString(enum PacketDropReason r);
1165

1166
/* decoder functions */
1167
int DecodeEthernet(ThreadVars *, DecodeThreadVars *, Packet *, const uint8_t *, uint32_t);
1168
int DecodeSll(ThreadVars *, DecodeThreadVars *, Packet *, const uint8_t *, uint32_t);
1169
int DecodeSll2(ThreadVars *, DecodeThreadVars *, Packet *, const uint8_t *, uint32_t);
1170
int DecodePPP(ThreadVars *, DecodeThreadVars *, Packet *, const uint8_t *, uint32_t);
1171
int DecodePPPOESession(ThreadVars *, DecodeThreadVars *, Packet *, const uint8_t *, uint32_t);
1172
int DecodePPPOEDiscovery(ThreadVars *, DecodeThreadVars *, Packet *, const uint8_t *, uint32_t);
1173
int DecodeNull(ThreadVars *, DecodeThreadVars *, Packet *, const uint8_t *, uint32_t);
1174
int DecodeRaw(ThreadVars *, DecodeThreadVars *, Packet *, const uint8_t *, uint32_t);
1175
int DecodeIPV4(ThreadVars *, DecodeThreadVars *, Packet *, const uint8_t *, uint16_t);
1176
int DecodeIPV6(ThreadVars *, DecodeThreadVars *, Packet *, const uint8_t *, uint16_t);
1177
int DecodeICMPV4(ThreadVars *, DecodeThreadVars *, Packet *, const uint8_t *, uint32_t);
1178
int DecodeICMPV6(ThreadVars *, DecodeThreadVars *, Packet *, const uint8_t *, uint32_t);
1179
int DecodeTCP(ThreadVars *, DecodeThreadVars *, Packet *, const uint8_t *, uint16_t);
1180
int DecodeUDP(ThreadVars *, DecodeThreadVars *, Packet *, const uint8_t *, uint16_t);
1181
int DecodeSCTP(ThreadVars *, DecodeThreadVars *, Packet *, const uint8_t *, uint16_t);
1182
int DecodeESP(ThreadVars *, DecodeThreadVars *, Packet *, const uint8_t *, uint16_t);
1183
int DecodeGRE(ThreadVars *, DecodeThreadVars *, Packet *, const uint8_t *, uint32_t);
1184
int DecodeVLAN(ThreadVars *, DecodeThreadVars *, Packet *, const uint8_t *, uint32_t);
1185
int DecodeVNTag(ThreadVars *, DecodeThreadVars *, Packet *, const uint8_t *, uint32_t);
1186
int DecodeETag(ThreadVars *, DecodeThreadVars *, Packet *, const uint8_t *, uint32_t);
1187
int DecodeIEEE8021ah(ThreadVars *, DecodeThreadVars *, Packet *, const uint8_t *, uint32_t);
1188
int DecodeGeneve(ThreadVars *, DecodeThreadVars *, Packet *, const uint8_t *, uint32_t);
1189
int DecodeVXLAN(ThreadVars *, DecodeThreadVars *, Packet *, const uint8_t *, uint32_t);
1190
int DecodeMPLS(ThreadVars *, DecodeThreadVars *, Packet *, const uint8_t *, uint32_t);
1191
int DecodeERSPAN(ThreadVars *, DecodeThreadVars *, Packet *, const uint8_t *, uint32_t);
1192
int DecodeERSPANTypeI(ThreadVars *, DecodeThreadVars *, Packet *, const uint8_t *, uint32_t);
1193
int DecodeCHDLC(ThreadVars *, DecodeThreadVars *, Packet *, const uint8_t *, uint32_t);
1194
int DecodeTEMPLATE(ThreadVars *, DecodeThreadVars *, Packet *, const uint8_t *, uint32_t);
1195
int DecodeNSH(ThreadVars *, DecodeThreadVars *, Packet *, const uint8_t *, uint32_t);
1196
int DecodeARP(ThreadVars *, DecodeThreadVars *, Packet *, const uint8_t *, uint32_t);
1197
int DecodeIGMP(ThreadVars *, DecodeThreadVars *, Packet *, const uint8_t *, uint32_t);
1198

1199
#ifdef UNITTESTS
1200
void DecodeIPV6FragHeader(Packet *p, const uint8_t *pkt,
1201
                          uint16_t hdrextlen, uint16_t plen,
1202
                          uint16_t prev_hdrextlen);
1203
#endif
1204

1205
void AddressDebugPrint(Address *);
1206

1207
typedef int (*DecoderFunc)(ThreadVars *tv, DecodeThreadVars *dtv, Packet *p,
1208
         const uint8_t *pkt, uint32_t len);
1209
void DecodeGlobalConfig(void);
1210
void PacketAlertGetMaxConfig(void);
1211
void DecodeUnregisterCounters(void);
1212

1213
#define ENGINE_SET_EVENT(p, e) do { \
139,253,227✔
1214
    SCLogDebug("p %p event %d", (p), e); \
139,253,227✔
1215
    if ((p)->events.cnt < PACKET_ENGINE_EVENT_MAX) { \
139,253,227✔
1216
        (p)->events.events[(p)->events.cnt] = e; \
127,892,096✔
1217
        (p)->events.cnt++; \
127,892,096✔
1218
    } \
127,892,096✔
1219
} while(0)
139,253,227✔
1220

1221
#define ENGINE_SET_INVALID_EVENT(p, e) do { \
544,785✔
1222
    p->flags |= PKT_IS_INVALID; \
544,785✔
1223
    ENGINE_SET_EVENT(p, e); \
544,785✔
1224
} while(0)
544,785✔
1225

1226
#define ENGINE_ISSET_EVENT(p, e) ({ \
317,115✔
1227
    int r = 0; \
317,115✔
1228
    uint8_t u; \
317,115✔
1229
    for (u = 0; u < (p)->events.cnt; u++) { \
503,889✔
1230
        if ((p)->events.events[u] == (e)) { \
401,856✔
1231
            r = 1; \
215,082✔
1232
            break; \
215,082✔
1233
        } \
215,082✔
1234
    } \
401,856✔
1235
    r; \
317,115✔
1236
})
317,115✔
1237

1238
#ifndef IPPROTO_IPIP
1239
#define IPPROTO_IPIP 4
1240
#endif
1241

1242
/* older libcs don't contain a def for IPPROTO_DCCP
1243
 * inside of <netinet/in.h>
1244
 * if it isn't defined let's define it here.
1245
 */
1246
#ifndef IPPROTO_DCCP
1247
#define IPPROTO_DCCP 33
1248
#endif
1249

1250
/* older libcs don't contain a def for IPPROTO_SCTP
1251
 * inside of <netinet/in.h>
1252
 * if it isn't defined let's define it here.
1253
 */
1254
#ifndef IPPROTO_SCTP
1255
#define IPPROTO_SCTP 132
1256
#endif
1257

1258
#ifndef IPPROTO_MH
1259
#define IPPROTO_MH 135
1260
#endif
1261

1262
/* Host Identity Protocol (rfc 5201) */
1263
#ifndef IPPROTO_HIP
1264
#define IPPROTO_HIP 139
525,204✔
1265
#endif
1266

1267
#ifndef IPPROTO_SHIM6
1268
#define IPPROTO_SHIM6 140
525,922✔
1269
#endif
1270

1271
/* Packet Flags */
1272

1273
/** Flag to indicate that packet header or contents should not be inspected */
1274
#define PKT_NOPACKET_INSPECTION BIT_U32(0)
127,045,420✔
1275
/** Packet has a PPP_VJ_UCOMP header */
1276
#define PKT_PPP_VJ_UCOMP BIT_U32(1)
8,497✔
1277

1278
/** Flag to indicate that packet contents should not be inspected */
1279
#define PKT_NOPAYLOAD_INSPECTION BIT_U32(2)
2,954,944✔
1280

1281
/** set if PacketAlerts may contain json context data */
1282
#define PKT_ALERT_CTX_USED BIT_U32(3)
129,568✔
1283

1284
/** Packet has matched a tag */
1285
#define PKT_HAS_TAG BIT_U32(4)
2,840,341✔
1286
/** Packet payload was added to reassembled stream */
1287
#define PKT_STREAM_ADD BIT_U32(5)
1,684,956✔
1288
/** Packet is part of established stream */
1289
#define PKT_STREAM_EST BIT_U32(6)
9,909,193✔
1290

1291
// vacancy
1292

1293
#define PKT_HAS_FLOW   BIT_U32(8)
256,025,062✔
1294
/** Pseudo packet to end the stream */
1295
#define PKT_PSEUDO_STREAM_END BIT_U32(9)
350,152,216✔
1296
/** Packet is modified by the stream engine, we need to recalc the csum and       \
1297
                   reinject/replace */
1298
#define PKT_STREAM_MODIFIED BIT_U32(10)
2,262,730✔
1299

1300
// vacancy
1301

1302
/** Exclude packet from pcap logging as it's part of a stream that has reassembly \
1303
                   depth reached. */
1304
#define PKT_STREAM_NOPCAPLOG BIT_U32(12)
397,573✔
1305

1306
// vacancy 2x
1307

1308
/** Packet checksum is not computed (TX packet for example) */
1309
#define PKT_IGNORE_CHECKSUM BIT_U32(15)
1,845,086✔
1310
/** Packet comes from zero copy (ext_pkt must not be freed) */
1311
#define PKT_ZERO_COPY BIT_U32(16)
243,002,617✔
1312

1313
#define PKT_HOST_SRC_LOOKED_UP BIT_U32(17)
278✔
1314
#define PKT_HOST_DST_LOOKED_UP BIT_U32(18)
201✔
1315

1316
/** Packet is a fragment */
1317
#define PKT_IS_FRAGMENT BIT_U32(19)
443,561✔
1318
#define PKT_IS_INVALID  BIT_U32(20)
127,523,794✔
1319
#define PKT_PROFILE     BIT_U32(21)
1320

1321
/** indication by decoder that it feels the packet should be handled by
1322
 *  flow engine: Packet::flow_hash will be set */
1323
#define PKT_WANTS_FLOW BIT_U32(22)
129,008,493✔
1324

1325
/** protocol detection done */
1326
#define PKT_PROTO_DETECT_TS_DONE BIT_U32(23)
77,893✔
1327
#define PKT_PROTO_DETECT_TC_DONE BIT_U32(24)
57,122✔
1328

1329
#define PKT_REBUILT_FRAGMENT                                                                       \
1330
    BIT_U32(25) /**< Packet is rebuilt from                                                        \
4,408✔
1331
                 * fragments. */
1332
#define PKT_DETECT_HAS_STREAMDATA                                                                  \
1333
    BIT_U32(26) /**< Set by Detect() if raw stream data is available. */
3,746,268✔
1334

1335
#define PKT_PSEUDO_DETECTLOG_FLUSH BIT_U32(27) /**< Detect/log flush for protocol upgrade */
192,929,817✔
1336

1337
/** Packet is part of stream in known bad condition (loss, wrong thread),
1338
 *  so flag it for not setting stream events */
1339
#define PKT_STREAM_NO_EVENTS BIT_U32(28)
98,733✔
1340

1341
/** We had no alert on flow before this packet */
1342
#define PKT_FIRST_ALERTS BIT_U32(29)
111,323✔
1343
#define PKT_FIRST_TAG    BIT_U32(30)
31✔
1344

1345
#define PKT_PSEUDO_LOG_FLUSH BIT_U32(31) /**< Detect/log flush for protocol upgrade */
124,459,679✔
1346

1347
/** \brief return 1 if the packet is a pseudo packet */
1348
#define PKT_IS_PSEUDOPKT(p) \
1349
    ((p)->flags & (PKT_PSEUDO_STREAM_END|PKT_PSEUDO_DETECTLOG_FLUSH))
200,037,511✔
1350
#define PKT_IS_FLUSHPKT(p) ((p)->flags & (PKT_PSEUDO_LOG_FLUSH))
124,459,679✔
1351

1352
#define PKT_SET_SRC(p, src_val) ((p)->pkt_src = src_val)
122,393,918✔
1353

1354
#define PKT_DEFAULT_MAX_DECODED_LAYERS 16
1355
extern uint8_t decoder_max_layers;
1356

1357
static inline bool PacketIncreaseCheckLayers(Packet *p)
1358
{
127,652,900✔
1359
    p->nb_decoded_layers++;
127,652,900✔
1360
    if (p->nb_decoded_layers >= decoder_max_layers) {
127,652,900✔
1361
        ENGINE_SET_INVALID_EVENT(p, GENERIC_TOO_MANY_LAYERS);
1,462✔
1362
        return false;
1,462✔
1363
    }
1,462✔
1364
    return true;
127,651,438✔
1365
}
127,652,900✔
1366

1367
/** \brief Set the No payload inspection Flag for the packet.
1368
 *
1369
 * \param p Packet to set the flag in
1370
 */
1371
static inline void DecodeSetNoPayloadInspectionFlag(Packet *p)
1372
{
204,737✔
1373
    p->flags |= PKT_NOPAYLOAD_INSPECTION;
204,737✔
1374
}
204,737✔
1375

1376
/** \brief Set the No packet inspection Flag for the packet.
1377
 *
1378
 * \param p Packet to set the flag in
1379
 */
1380
static inline void DecodeSetNoPacketInspectionFlag(Packet *p)
1381
{
61✔
1382
    p->flags |= PKT_NOPACKET_INSPECTION;
61✔
1383
}
61✔
1384

1385
static inline bool PacketIsTunnelRoot(const Packet *p)
1386
{
74,331✔
1387
    return (p->ttype == PacketTunnelRoot);
74,331✔
1388
}
74,331✔
1389

1390
static inline bool PacketIsTunnelChild(const Packet *p)
1391
{
298,202✔
1392
    return (p->ttype == PacketTunnelChild);
298,202✔
1393
}
298,202✔
1394

1395
static inline bool PacketIsTunnel(const Packet *p)
1396
{
125,561,428✔
1397
    return (p->ttype != PacketTunnelNone);
125,561,428✔
1398
}
125,561,428✔
1399

1400
static inline bool PacketIsNotTunnel(const Packet *p)
UNCOV
1401
{
×
UNCOV
1402
    return (p->ttype == PacketTunnelNone);
×
UNCOV
1403
}
×
1404

1405
static inline bool VerdictTunnelPacketInternal(const Packet *p)
1406
{
×
1407
    const uint16_t outstanding = TUNNEL_PKT_TPR(p) - TUNNEL_PKT_RTV(p);
×
1408
    SCLogDebug("tunnel: outstanding %u", outstanding);
×
UNCOV
1409

×
UNCOV
1410
    /* if there are packets outstanding, we won't verdict this one */
×
1411
    if (PacketIsTunnelRoot(p) && !PacketTunnelIsVerdicted(p) && !outstanding) {
×
1412
        SCLogDebug("root %p: verdict", p);
×
1413
        return true;
×
UNCOV
1414

×
1415
    } else if (PacketIsTunnelChild(p) && outstanding == 1 && p->root &&
×
1416
               PacketTunnelIsVerdicted(p->root)) {
×
1417
        SCLogDebug("tunnel %p: verdict", p);
×
1418
        return true;
×
UNCOV
1419

×
1420
    } else {
×
1421
        return false;
×
1422
    }
×
1423
}
×
1424

1425
/** \brief return true if *this* packet needs to trigger a verdict.
1426
 *
1427
 *  If we have the root packet, and we have none outstanding,
1428
 *  we can verdict now.
1429
 *
1430
 *  If we have a upper layer packet, it's the only one and root
1431
 *  is already processed, we can verdict now.
1432
 *
1433
 *  Otherwise, a future packet will issue the verdict.
1434
 */
1435
static inline bool VerdictTunnelPacket(Packet *p)
1436
{
×
1437
    bool verdict;
×
1438
    SCSpinlock *lock = p->root ? &p->root->persistent.tunnel_lock : &p->persistent.tunnel_lock;
×
1439
    SCSpinLock(lock);
×
1440
    verdict = VerdictTunnelPacketInternal(p);
×
1441
    SCSpinUnlock(lock);
×
1442
    return verdict;
×
1443
}
×
1444

1445
static inline void DecodeLinkLayer(ThreadVars *tv, DecodeThreadVars *dtv,
1446
        const int datalink, Packet *p, const uint8_t *data, const uint32_t len)
1447
{
123,276,423✔
1448
    /* call the decoder */
1449
    switch (datalink) {
123,276,423✔
1450
        case LINKTYPE_ETHERNET:
124,451,792✔
1451
            DecodeEthernet(tv, dtv, p, data, len);
124,451,792✔
1452
            break;
124,451,792✔
1453
        case LINKTYPE_LINUX_SLL:
×
1454
            DecodeSll(tv, dtv, p, data, len);
×
1455
            break;
×
1456
        case LINKTYPE_LINUX_SLL2:
×
1457
            DecodeSll2(tv, dtv, p, data, len);
×
1458
            break;
×
1459
        case LINKTYPE_PPP:
×
1460
            DecodePPP(tv, dtv, p, data, len);
×
1461
            break;
×
1462
        case LINKTYPE_RAW:
×
1463
        case LINKTYPE_GRE_OVER_IP:
×
1464
            DecodeRaw(tv, dtv, p, data, len);
×
1465
            break;
×
1466
        case LINKTYPE_NULL:
×
1467
            DecodeNull(tv, dtv, p, data, len);
×
1468
            break;
×
1469
       case LINKTYPE_CISCO_HDLC:
×
1470
            DecodeCHDLC(tv, dtv, p, data, len);
×
1471
            break;
×
1472
        default:
×
1473
            SCLogError("datalink type "
×
1474
                       "%" PRId32 " not yet supported",
×
1475
                    datalink);
×
1476
            break;
×
1477
    }
123,276,423✔
1478
}
123,276,423✔
1479

1480
/** \brief decode network layer
1481
 *  \retval bool true if successful, false if unknown */
1482
static inline bool DecodeNetworkLayer(ThreadVars *tv, DecodeThreadVars *dtv,
1483
        const uint16_t proto, Packet *p, const uint8_t *data, const uint32_t len)
1484
{
128,016,224✔
1485
    switch (proto) {
128,016,224✔
1486
        case ETHERNET_TYPE_IP: {
2,200,209✔
1487
            uint16_t ip_len = (len < USHRT_MAX) ? (uint16_t)len : (uint16_t)USHRT_MAX;
2,200,209✔
1488
            DecodeIPV4(tv, dtv, p, data, ip_len);
2,200,209✔
1489
            break;
2,200,209✔
1490
        }
×
1491
        case ETHERNET_TYPE_IPV6: {
824,317✔
1492
            uint16_t ip_len = (len < USHRT_MAX) ? (uint16_t)len : (uint16_t)USHRT_MAX;
824,317✔
1493
            DecodeIPV6(tv, dtv, p, data, ip_len);
824,317✔
1494
            break;
824,317✔
1495
        }
×
1496
        case ETHERNET_TYPE_PPPOE_SESS:
8,190✔
1497
            DecodePPPOESession(tv, dtv, p, data, len);
8,190✔
1498
            break;
8,190✔
1499
        case ETHERNET_TYPE_PPPOE_DISC:
2,374✔
1500
            DecodePPPOEDiscovery(tv, dtv, p, data, len);
2,374✔
1501
            break;
2,374✔
1502
        case ETHERNET_TYPE_VLAN:
255,497✔
1503
        case ETHERNET_TYPE_8021AD:
258,138✔
1504
        case ETHERNET_TYPE_8021QINQ:
263,156✔
1505
            if (p->vlan_idx > VLAN_MAX_LAYER_IDX) {
263,156✔
1506
                ENGINE_SET_EVENT(p,VLAN_HEADER_TOO_MANY_LAYERS);
511✔
1507
            } else {
262,645✔
1508
                DecodeVLAN(tv, dtv, p, data, len);
262,645✔
1509
            }
262,645✔
1510
            break;
263,156✔
1511
        case ETHERNET_TYPE_8021AH:
1,815✔
1512
            DecodeIEEE8021ah(tv, dtv, p, data, len);
1,815✔
1513
            break;
1,815✔
1514
        case ETHERNET_TYPE_ARP:
13,517✔
1515
            DecodeARP(tv, dtv, p, data, len);
13,517✔
1516
            break;
13,517✔
1517
        case ETHERNET_TYPE_MPLS_UNICAST:
4,025✔
1518
        case ETHERNET_TYPE_MPLS_MULTICAST:
8,715✔
1519
            DecodeMPLS(tv, dtv, p, data, len);
8,715✔
1520
            break;
8,715✔
1521
        case ETHERNET_TYPE_DCE:
8,425✔
1522
            if (unlikely(len < ETHERNET_DCE_HEADER_LEN)) {
8,425✔
1523
                ENGINE_SET_INVALID_EVENT(p, DCE_PKT_TOO_SMALL);
1,842✔
1524
            } else {
6,585✔
1525
                // DCE layer is ethernet + 2 bytes, followed by another ethernet
1526
                DecodeEthernet(tv, dtv, p, data + 2, len - 2);
6,583✔
1527
            }
6,583✔
1528
            break;
8,425✔
1529
        case ETHERNET_TYPE_ETAG:
4,839✔
1530
            DecodeETag(tv, dtv, p, data, len);
4,839✔
1531
            break;
4,839✔
1532
        case ETHERNET_TYPE_VNTAG:
11,078✔
1533
            DecodeVNTag(tv, dtv, p, data, len);
11,078✔
1534
            break;
11,078✔
1535
        case ETHERNET_TYPE_NSH:
5,784✔
1536
            DecodeNSH(tv, dtv, p, data, len);
5,784✔
1537
            break;
5,784✔
1538
        default:
124,289,794✔
1539
            SCLogDebug("unknown ether type: %" PRIx16 "", proto);
124,289,794✔
1540
            StatsCounterIncr(&tv->stats, dtv->counter_ethertype_unknown);
124,289,794✔
1541
            ENGINE_SET_EVENT(p, ETHERNET_UNKNOWN_ETHERTYPE);
124,289,794✔
1542
            return false;
124,289,794✔
1543
    }
128,016,224✔
1544
    return true;
3,352,419✔
1545
}
128,016,224✔
1546

1547
uint64_t PcapPacketCntGet(const Packet *p);
1548
void PcapPacketCntSet(Packet *p, uint64_t pcap_cnt);
1549

1550
#endif /* SURICATA_DECODE_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