suricata
source-lib.c
Go to the documentation of this file.
1/* Copyright (C) 2023-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/** \file
19 *
20 * \author Angelo Mirabella <angelo.mirabella@broadcom.com>
21 *
22 * LIB packet and stream decoding support
23 *
24 */
25
26#include "suricata-common.h"
27#include "source-lib.h"
28#include "util-device-private.h"
29
30/* Set time to the first packet timestamp when replaying a PCAP. */
31static bool time_set = false;
32
33/** \brief initialize the "Decode" module.
34 *
35 * \param tv Pointer to the per-thread structure.
36 * \param initdata Pointer to initialization context.
37 * \param data Pointer to the initialized context.
38 * \return Error code.
39 */
40static TmEcode DecodeLibThreadInit(ThreadVars *tv, const void *initdata, void **data)
41{
42 SCEnter();
43 DecodeThreadVars *dtv = NULL;
44
46
47 if (dtv == NULL)
49
51
52 *data = (void *)dtv;
53
55}
56
57/** \brief deinitialize the "Decode" module.
58 *
59 * \param tv Pointer to the per-thread structure.
60 * \param data Pointer to the context.
61 * \return Error code.
62 */
63static TmEcode DecodeLibThreadDeinit(ThreadVars *tv, void *data)
64{
65 if (data != NULL)
67
68 time_set = false;
70}
71
72/** \brief main decoding function.
73 *
74 * This method receives a packet and tries to identify layer 2 to 4 layers.
75 *
76 * \param tv Pointer to the per-thread structure.
77 * \param p Pointer to the packet.
78 * \param data Pointer to the context.
79 * \return Error code.
80 */
81static TmEcode DecodeLib(ThreadVars *tv, Packet *p, void *data)
82{
83 SCEnter();
85
87
88 /* update counters */
90
91 /* If suri has set vlan during reading, we increase vlan counter */
92 if (p->vlan_idx) {
94 }
95
96 /* call the decoder */
97 DecodeLinkLayer(tv, dtv, p->datalink, p, GET_PKT_DATA(p), GET_PKT_LEN(p));
98
100
102}
103
104/** \brief register a "Decode" module for suricata as a library.
105 *
106 * The "Decode" module is the first module invoked when processing a packet */
void StatsIncr(ThreadVars *tv, uint16_t id)
Increments the local counter.
Definition counters.c:166
#define GET_PKT_DATA(p)
Definition decode.h:209
#define GET_PKT_LEN(p)
Definition decode.h:208
#define PKT_IS_PSEUDOPKT(p)
return 1 if the packet is a pseudo packet
Definition decode.h:1321
DecodeThreadVars * dtv
ThreadVars * tv
void DecodeRegisterPerfCounters(DecodeThreadVars *dtv, ThreadVars *tv)
Definition decode.c:628
void PacketDecodeFinalize(ThreadVars *tv, DecodeThreadVars *dtv, Packet *p)
Finalize decoding of a packet.
Definition decode.c:232
DecodeThreadVars * DecodeThreadVarsAlloc(ThreadVars *tv)
Alloc and setup DecodeThreadVars.
Definition decode.c:804
void DecodeThreadVarsFree(ThreadVars *tv, DecodeThreadVars *dtv)
Definition decode.c:822
void DecodeUpdatePacketCounters(ThreadVars *tv, const DecodeThreadVars *dtv, const Packet *p)
Definition decode.c:770
void TmModuleDecodeLibRegister(void)
register a "Decode" module for suricata as a library.
Definition source-lib.c:107
Structure to hold thread specific data for all decode modules.
Definition decode.h:963
uint16_t counter_vlan
Definition decode.h:1001
int datalink
Definition decode.h:639
uint8_t vlan_idx
Definition decode.h:529
Per thread variable structure.
Definition threadvars.h:58
const char * name
Definition tm-modules.h:48
TmEcode(* ThreadDeinit)(ThreadVars *, void *)
Definition tm-modules.h:53
void(* ThreadExitPrintStats)(ThreadVars *, void *)
Definition tm-modules.h:52
uint8_t cap_flags
Definition tm-modules.h:77
TmEcode(* Func)(ThreadVars *, Packet *, void *)
Definition tm-modules.h:56
uint8_t flags
Definition tm-modules.h:80
TmEcode(* ThreadInit)(ThreadVars *, const void *, void **)
Definition tm-modules.h:51
#define BUG_ON(x)
TmModule tmm_modules[TMM_SIZE]
Definition tm-modules.c:29
#define TM_FLAG_DECODE_TM
Definition tm-modules.h:33
@ TMM_DECODELIB
@ TM_ECODE_FAILED
@ TM_ECODE_OK
#define SCEnter(...)
Definition util-debug.h:277
#define SCReturnInt(x)
Definition util-debug.h:281