suricata
detect-engine.h
Go to the documentation of this file.
1 /* Copyright (C) 2007-2021 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 __DETECT_ENGINE_H__
25 #define __DETECT_ENGINE_H__
26 
27 #include "detect.h"
28 #include "tm-threads.h"
29 #include "flow-private.h"
30 
31 void InspectionBufferInit(InspectionBuffer *buffer, uint32_t initial_size);
32 void InspectionBufferSetup(DetectEngineThreadCtx *det_ctx, const int list_id,
33  InspectionBuffer *buffer, const uint8_t *data, const uint32_t data_len);
35 void InspectionBufferCheckAndExpand(InspectionBuffer *buffer, uint32_t min_size);
36 void InspectionBufferCopy(InspectionBuffer *buffer, uint8_t *buf, uint32_t buf_len);
38  const DetectEngineTransforms *transforms);
40 InspectionBuffer *InspectionBufferGet(DetectEngineThreadCtx *det_ctx, const int list_id);
42  const uint8_t *data, const uint32_t data_len);
44  DetectEngineThreadCtx *det_ctx, const int list_id, uint32_t local_id);
45 
46 /* start up registery funcs */
47 
48 int DetectBufferTypeRegister(const char *name);
49 int DetectBufferTypeGetByName(const char *name);
50 void DetectBufferTypeSupportsMpm(const char *name);
51 void DetectBufferTypeSupportsPacket(const char *name);
52 void DetectBufferTypeSupportsTransformations(const char *name);
53 int DetectBufferTypeMaxId(void);
55 void DetectBufferTypeSetDescriptionByName(const char *name, const char *desc);
56 const char *DetectBufferTypeGetDescriptionByName(const char *name);
57 void DetectBufferTypeRegisterSetupCallback(const char *name,
58  void (*Callback)(const DetectEngineCtx *, Signature *));
59 void DetectBufferTypeRegisterValidateCallback(const char *name,
60  bool (*ValidateCallback)(const Signature *, const char **sigerror));
61 
62 /* detect engine related buffer funcs */
63 
65 const char *DetectEngineBufferTypeGetNameById(const DetectEngineCtx *de_ctx, const int id);
69 const char *DetectEngineBufferTypeGetDescriptionById(const DetectEngineCtx *de_ctx, const int id);
72  DetectEngineCtx *de_ctx, const int id, TransformData *transforms, int transform_cnt);
75  const DetectEngineCtx *de_ctx, const int id, const Signature *s, const char **sigerror);
77  const uint8_t *content, uint16_t content_len, const char **namestr);
81 
82 /* prototypes */
88 
89 int DetectRegisterThreadCtxGlobalFuncs(const char *name,
90  void *(*InitFunc)(void *), void *data, void (*FreeFunc)(void *));
92 
93 TmEcode DetectEngineThreadCtxInit(ThreadVars *, void *, void **);
95 //inline uint32_t DetectEngineGetMaxSigId(DetectEngineCtx *);
96 /* faster as a macro than a inline function on my box -- VJ */
97 #define DetectEngineGetMaxSigId(de_ctx) ((de_ctx)->signum)
99 void DetectEngineRegisterTests(void);
101 
102 uint32_t DetectEngineGetVersion(void);
103 void DetectEngineBumpVersion(void);
107 void DetectEnginePruneFreeList(void);
111 int DetectEngineReload(const SCInstance *suri);
112 int DetectEngineEnabled(void);
113 int DetectEngineMTApply(void);
116 
117 int DetectEngineReloadStart(void);
118 int DetectEngineReloadIsStart(void);
119 void DetectEngineReloadSetIdle(void);
120 int DetectEngineReloadIsIdle(void);
121 
122 int DetectEngineLoadTenantBlocking(uint32_t tenant_id, const char *yaml);
123 int DetectEngineReloadTenantBlocking(uint32_t tenant_id, const char *yaml, int reload_cnt);
124 
125 int DetectEngineTentantRegisterLivedev(uint32_t tenant_id, int device_id);
126 int DetectEngineTentantRegisterVlanId(uint32_t tenant_id, uint16_t vlan_id);
127 int DetectEngineTentantUnregisterVlanId(uint32_t tenant_id, uint16_t vlan_id);
128 int DetectEngineTentantRegisterPcapFile(uint32_t tenant_id);
129 int DetectEngineTentantUnregisterPcapFile(uint32_t tenant_id);
130 
132  const Signature *, const SigMatchData *, Flow *, const uint8_t, void *, void *, uint64_t);
133 
136  const DetectEngineAppInspectionEngine *engine,
137  const Signature *s,
138  Flow *f, uint8_t flags, void *alstate, void *txv, uint64_t tx_id);
139 
141  DetectEngineThreadCtx *det_ctx,
142  const DetectEnginePktInspectionEngine *engine,
143  const Signature *s, Packet *p, uint8_t *alert_flags);
144 
145 /**
146  * \brief Registers an app inspection engine.
147  *
148  * \param name Name of the detection list
149  * \param alproto App layer protocol for which we will register the engine.
150  * \param direction The direction for the engine: SIG_FLAG_TOSERVER or
151  * SIG_FLAG_TOCLIENT
152  * \param progress Minimal progress value for inspect engine to run
153  * \param Callback The engine callback.
154  */
155 void DetectAppLayerInspectEngineRegister2(const char *name,
156  AppProto alproto, uint32_t dir, int progress,
157  InspectEngineFuncPtr2 Callback2,
159 
160 void DetectPktInspectEngineRegister(const char *name,
163 
166 
168  DetectEngineThreadCtx *det_ctx, const Signature *s,
169  Flow *f, Packet *p,
170  uint8_t *alert_flags);
172 
176 
177 int WARN_UNUSED DetectBufferSetActiveList(Signature *s, const int list);
179 
181  ThreadVars *tv, DetectEngineCtx *new_de_ctx, int mt);
182 
183 #endif /* __DETECT_ENGINE_H__ */
tm-threads.h
DetectEngineAppInspectionEngine_
Definition: detect.h:397
DetectBufferSetActiveList
int WARN_UNUSED DetectBufferSetActiveList(Signature *s, const int list)
Definition: detect-engine.c:1009
DetectEngineReloadIsIdle
int DetectEngineReloadIsIdle(void)
Definition: detect-engine.c:1616
DetectBufferTypeRegister
int DetectBufferTypeRegister(const char *name)
Definition: detect-engine.c:793
DetectEnginePktInspectionEngine
Definition: detect.h:449
DetectEngineBufferTypeRegister
int DetectEngineBufferTypeRegister(DetectEngineCtx *de_ctx, const char *name)
Definition: detect-engine.c:890
InspectionBufferGet
InspectionBuffer * InspectionBufferGet(DetectEngineThreadCtx *det_ctx, const int list_id)
Definition: detect-engine.c:1078
DetectBufferTypeGetByName
int DetectBufferTypeGetByName(const char *name)
Definition: detect-engine.c:837
DetectEngineTransforms
Definition: detect.h:378
DetectEnginePktInspectionRun
bool DetectEnginePktInspectionRun(ThreadVars *tv, DetectEngineThreadCtx *det_ctx, const Signature *s, Flow *f, Packet *p, uint8_t *alert_flags)
Definition: detect-engine.c:1499
InspectionBufferMultipleForListGet
InspectionBuffer * InspectionBufferMultipleForListGet(DetectEngineThreadCtx *det_ctx, const int list_id, uint32_t local_id)
for a InspectionBufferMultipleForList get a InspectionBuffer
Definition: detect-engine.c:1098
DetectBufferTypeSetDescriptionByName
void DetectBufferTypeSetDescriptionByName(const char *name, const char *desc)
Definition: detect-engine.c:900
AppProto
uint16_t AppProto
Definition: app-layer-protos.h:77
InspectionBuffer
Definition: detect.h:344
flow-private.h
Flow_
Flow data structure.
Definition: flow.h:353
InspectionBufferFree
void InspectionBufferFree(InspectionBuffer *buffer)
Definition: detect-engine.c:1177
DetectEngineReference
DetectEngineCtx * DetectEngineReference(DetectEngineCtx *)
Definition: detect-engine.c:3298
InspectionBufferGetDataPtr
InspectionBuffer *(* InspectionBufferGetDataPtr)(struct DetectEngineThreadCtx_ *det_ctx, const DetectEngineTransforms *transforms, Flow *f, const uint8_t flow_flags, void *txv, const int list_id)
Definition: detect.h:384
DetectEngineAppInspectionEngine2Signature
int DetectEngineAppInspectionEngine2Signature(DetectEngineCtx *de_ctx, Signature *s)
Definition: detect-engine.c:416
DetectThreadCtxGetGlobalKeywordThreadCtx
void * DetectThreadCtxGetGlobalKeywordThreadCtx(DetectEngineThreadCtx *det_ctx, int id)
Retrieve thread local keyword ctx by id.
Definition: detect-engine.c:3230
DetectEngineCtx_
main detection engine ctx
Definition: detect.h:764
DetectEngineBufferTypeGetDescriptionById
const char * DetectEngineBufferTypeGetDescriptionById(const DetectEngineCtx *de_ctx, const int id)
Definition: detect-engine.c:911
DetectEngineReloadIsStart
int DetectEngineReloadIsStart(void)
Definition: detect-engine.c:1596
DetectEngineResetMaxSigId
void DetectEngineResetMaxSigId(DetectEngineCtx *)
Definition: detect-engine.c:2517
InspectionBufferClean
void InspectionBufferClean(DetectEngineThreadCtx *det_ctx)
Definition: detect-engine.c:1052
InspectionBufferGetPktDataPtr
InspectionBuffer *(* InspectionBufferGetPktDataPtr)(struct DetectEngineThreadCtx_ *det_ctx, const DetectEngineTransforms *transforms, Packet *p, const int list_id)
Definition: detect.h:444
DetectEnginePktInspectionSetup
int DetectEnginePktInspectionSetup(Signature *s)
Definition: detect-engine.c:1546
DetectBufferType_
Definition: detect.h:419
DetectEngineReload
int DetectEngineReload(const SCInstance *suri)
Reload the detection engine.
Definition: detect-engine.c:4106
DetectEngineLoadTenantBlocking
int DetectEngineLoadTenantBlocking(uint32_t tenant_id, const char *yaml)
Load a tenant and wait for loading to complete.
Definition: detect-engine.c:3501
SigMatchData_
Data needed for Match()
Definition: detect.h:329
DetectEngineCtxInit
DetectEngineCtx * DetectEngineCtxInit(void)
Definition: detect-engine.c:2090
TransformData_
Definition: detect.h:373
DetectAppLayerInspectEngineRegister2
void DetectAppLayerInspectEngineRegister2(const char *name, AppProto alproto, uint32_t dir, int progress, InspectEngineFuncPtr2 Callback2, InspectionBufferGetDataPtr GetData)
Registers an app inspection engine.
Definition: detect-engine.c:175
DetectEnginePruneFreeList
void DetectEnginePruneFreeList(void)
Definition: detect-engine.c:4067
DetectEngineBufferTypeSupportsMpm
void DetectEngineBufferTypeSupportsMpm(DetectEngineCtx *de_ctx, const char *name)
Definition: detect-engine.c:937
DetectBufferTypeGetDescriptionByName
const char * DetectBufferTypeGetDescriptionByName(const char *name)
Definition: detect-engine.c:920
DetectBufferTypeRegisterSetupCallback
void DetectBufferTypeRegisterSetupCallback(const char *name, void(*Callback)(const DetectEngineCtx *, Signature *))
Definition: detect-engine.c:971
DetectEngineCtxFree
void DetectEngineCtxFree(DetectEngineCtx *)
Free a DetectEngineCtx::
Definition: detect-engine.c:2135
DetectEngineGetByTenantId
DetectEngineCtx * DetectEngineGetByTenantId(int tenant_id)
Definition: detect-engine.c:3950
DetectEngineThreadCtxInit
TmEcode DetectEngineThreadCtxInit(ThreadVars *, void *, void **)
initialize thread specific detection engine context
Definition: detect-engine.c:2840
DetectEngineUnsetParseMetadata
void DetectEngineUnsetParseMetadata(void)
Definition: detect-engine.c:4270
InspectionBufferSetup
void InspectionBufferSetup(DetectEngineThreadCtx *det_ctx, const int list_id, InspectionBuffer *buffer, const uint8_t *data, const uint32_t data_len)
setup the buffer with our initial data
Definition: detect-engine.c:1159
InspectionBufferPktInspectFunc
int(* InspectionBufferPktInspectFunc)(struct DetectEngineThreadCtx_ *, const struct DetectEnginePktInspectionEngine *engine, const struct Signature_ *s, Packet *p, uint8_t *alert_flags)
Definition: detect.h:437
DetectEngineBufferTypeSupportsTransformations
void DetectEngineBufferTypeSupportsTransformations(DetectEngineCtx *de_ctx, const char *name)
Definition: detect-engine.c:945
DetectEngineBufferTypeSupportsMpmGetById
bool DetectEngineBufferTypeSupportsMpmGetById(const DetectEngineCtx *de_ctx, const int id)
Definition: detect-engine.c:962
DetectSigmatchListEnumToString
const char * DetectSigmatchListEnumToString(enum DetectSigmatchListEnum type)
Definition: detect-engine.c:4280
type
uint8_t type
Definition: decode-icmpv4.h:0
DetectEngineBufferTypeGetByIdTransforms
int DetectEngineBufferTypeGetByIdTransforms(DetectEngineCtx *de_ctx, const int id, TransformData *transforms, int transform_cnt)
Definition: detect-engine.c:1360
de_ctx
DetectEngineCtx * de_ctx
Definition: fuzz_siginit.c:17
DetectEngineReloadTenantBlocking
int DetectEngineReloadTenantBlocking(uint32_t tenant_id, const char *yaml, int reload_cnt)
Reload a tenant and wait for loading to complete.
Definition: detect-engine.c:3515
InspectionBufferCopy
void InspectionBufferCopy(InspectionBuffer *buffer, uint8_t *buf, uint32_t buf_len)
Definition: detect-engine.c:1206
DetectEngineThreadCtx_
Definition: detect.h:1010
DetectEngineReloadSetIdle
void DetectEngineReloadSetIdle(void)
Definition: detect-engine.c:1608
DetectEngineTentantUnregisterPcapFile
int DetectEngineTentantUnregisterPcapFile(uint32_t tenant_id)
Definition: detect-engine.c:3939
DetectEngineGetCurrent
DetectEngineCtx * DetectEngineGetCurrent(void)
Definition: detect-engine.c:3275
DetectEngineCtxInitStubForMT
DetectEngineCtx * DetectEngineCtxInitStubForMT(void)
Definition: detect-engine.c:2080
DetectEngineBufferTypeGetNameById
const char * DetectEngineBufferTypeGetNameById(const DetectEngineCtx *de_ctx, const int id)
Definition: detect-engine.c:867
detect.h
ThreadVars_
Per thread variable structure.
Definition: threadvars.h:58
InspectionBufferApplyTransforms
void InspectionBufferApplyTransforms(InspectionBuffer *buffer, const DetectEngineTransforms *transforms)
Definition: detect-engine.c:1261
DetectEngineThreadCtxDeinit
TmEcode DetectEngineThreadCtxDeinit(ThreadVars *, void *)
Definition: detect-engine.c:3048
DetectEngineBufferRunValidateCallback
bool DetectEngineBufferRunValidateCallback(const DetectEngineCtx *de_ctx, const int id, const Signature *s, const char **sigerror)
Definition: detect-engine.c:999
DetectEngineDeReference
void DetectEngineDeReference(DetectEngineCtx **de_ctx)
Definition: detect-engine.c:3976
DetectEngineMustParseMetadata
int DetectEngineMustParseMetadata(void)
Definition: detect-engine.c:4275
InspectionBufferSetupMulti
void InspectionBufferSetupMulti(InspectionBuffer *buffer, const DetectEngineTransforms *transforms, const uint8_t *data, const uint32_t data_len)
setup the buffer with our initial data
Definition: detect-engine.c:1145
DetectEngineGetVersion
uint32_t DetectEngineGetVersion(void)
Definition: detect-engine.c:3256
DetectBufferGetActiveList
int DetectBufferGetActiveList(DetectEngineCtx *de_ctx, Signature *s)
Definition: detect-engine.c:1022
DetectBufferTypeSupportsTransformations
void DetectBufferTypeSupportsTransformations(const char *name)
Definition: detect-engine.c:827
DetectEngineTentantUnregisterVlanId
int DetectEngineTentantUnregisterVlanId(uint32_t tenant_id, uint16_t vlan_id)
Definition: detect-engine.c:3928
Packet_
Definition: decode.h:417
DetectEngineReloadStart
int DetectEngineReloadStart(void)
Definition: detect-engine.c:1582
DetectBufferTypeSupportsPacket
void DetectBufferTypeSupportsPacket(const char *name)
Definition: detect-engine.c:807
TmEcode
TmEcode
Definition: tm-threads-common.h:81
InspectionBufferInit
void InspectionBufferInit(InspectionBuffer *buffer, uint32_t initial_size)
Definition: detect-engine.c:1135
DetectEngineAddToMaster
int DetectEngineAddToMaster(DetectEngineCtx *de_ctx)
Definition: detect-engine.c:4000
DetectEngineBufferTypeSupportsPacketGetById
bool DetectEngineBufferTypeSupportsPacketGetById(const DetectEngineCtx *de_ctx, const int id)
Definition: detect-engine.c:953
DetectEngineThreadCtxInitForReload
DetectEngineThreadCtx * DetectEngineThreadCtxInitForReload(ThreadVars *tv, DetectEngineCtx *new_de_ctx, int mt)
Definition: detect-engine.c:2903
DetectEngineTentantRegisterPcapFile
int DetectEngineTentantRegisterPcapFile(uint32_t tenant_id)
Definition: detect-engine.c:3933
flags
uint8_t flags
Definition: decode-gre.h:0
DetectPktInspectEngineRegister
void DetectPktInspectEngineRegister(const char *name, InspectionBufferGetPktDataPtr GetPktData, InspectionBufferPktInspectFunc Callback)
register inspect engine at start up time
Definition: detect-engine.c:132
InspectionBufferCheckAndExpand
void InspectionBufferCheckAndExpand(InspectionBuffer *buffer, uint32_t min_size)
make sure that the buffer has at least 'min_size' bytes Expand the buffer if necessary
Definition: detect-engine.c:1189
DetectEngineTentantRegisterLivedev
int DetectEngineTentantRegisterLivedev(uint32_t tenant_id, int device_id)
Definition: detect-engine.c:3918
DetectBufferTypeMaxId
int DetectBufferTypeMaxId(void)
Definition: detect-engine.c:683
DetectEngineSetParseMetadata
void DetectEngineSetParseMetadata(void)
Definition: detect-engine.c:4265
DetectEngineBufferTypeSupportsPacket
void DetectEngineBufferTypeSupportsPacket(DetectEngineCtx *de_ctx, const char *name)
Definition: detect-engine.c:929
DetectEngineBufferRunSetupCallback
void DetectEngineBufferRunSetupCallback(const DetectEngineCtx *de_ctx, const int id, Signature *s)
Definition: detect-engine.c:981
DetectEngineEnabled
int DetectEngineEnabled(void)
Check if detection is enabled.
Definition: detect-engine.c:3242
DetectEngineCtxInitStubForDD
DetectEngineCtx * DetectEngineCtxInitStubForDD(void)
Definition: detect-engine.c:2085
DetectEngineInspectGenericList
int DetectEngineInspectGenericList(const DetectEngineCtx *, DetectEngineThreadCtx *, const Signature *, const SigMatchData *, Flow *, const uint8_t, void *, void *, uint64_t)
Do the content inspection & validation for a signature.
Definition: detect-engine.c:1640
DetectBufferTypeCloseRegistration
void DetectBufferTypeCloseRegistration(void)
Definition: detect-engine.c:1353
tv
ThreadVars * tv
Definition: fuzz_decodepcapfile.c:29
DetectRegisterThreadCtxGlobalFuncs
int DetectRegisterThreadCtxGlobalFuncs(const char *name, void *(*InitFunc)(void *), void *data, void(*FreeFunc)(void *))
Register Thread keyword context Funcs (Global)
Definition: detect-engine.c:3186
DetectEngineMultiTenantEnabled
int DetectEngineMultiTenantEnabled(void)
Definition: detect-engine.c:3307
DetectEngineMoveToFreeList
int DetectEngineMoveToFreeList(DetectEngineCtx *de_ctx)
Definition: detect-engine.c:4016
Signature_
Signature container.
Definition: detect.h:517
DetectEngineMTApply
int DetectEngineMTApply(void)
Definition: detect-engine.c:4210
DetectEngineRegisterTests
void DetectEngineRegisterTests(void)
Definition: detect-engine.c:4539
DetectEngineCtxInitWithPrefix
DetectEngineCtx * DetectEngineCtxInitWithPrefix(const char *prefix)
Definition: detect-engine.c:2095
DetectEngineBufferTypeValidateTransform
bool DetectEngineBufferTypeValidateTransform(DetectEngineCtx *de_ctx, int sm_list, const uint8_t *content, uint16_t content_len, const char **namestr)
Check content byte array compatibility with transforms.
Definition: detect-engine.c:1236
DetectEngineInspectPktBufferGeneric
int DetectEngineInspectPktBufferGeneric(DetectEngineThreadCtx *det_ctx, const DetectEnginePktInspectionEngine *engine, const Signature *s, Packet *p, uint8_t *alert_flags)
Do the content inspection & validation for a signature.
Definition: detect-engine.c:1747
SCInstance_
Definition: suricata.h:123
DetectBufferTypeSupportsMpm
void DetectBufferTypeSupportsMpm(const char *name)
Definition: detect-engine.c:817
DetectEngineBumpVersion
void DetectEngineBumpVersion(void)
Definition: detect-engine.c:3266
DetectSigmatchListEnum
DetectSigmatchListEnum
Definition: detect.h:88
DetectEngineAppInspectionEngineSignatureFree
void DetectEngineAppInspectionEngineSignatureFree(DetectEngineCtx *, Signature *s)
free app inspect engines for a signature
Definition: detect-engine.c:617
DetectEngineInspectBufferGeneric
int DetectEngineInspectBufferGeneric(DetectEngineCtx *de_ctx, DetectEngineThreadCtx *det_ctx, const DetectEngineAppInspectionEngine *engine, const Signature *s, Flow *f, uint8_t flags, void *alstate, void *txv, uint64_t tx_id)
Do the content inspection & validation for a signature.
Definition: detect-engine.c:1682
WARN_UNUSED
#define WARN_UNUSED
Definition: suricata-common.h:384
DetectEngineBufferTypeGetById
const DetectBufferType * DetectEngineBufferTypeGetById(const DetectEngineCtx *de_ctx, const int id)
Definition: detect-engine.c:857
DetectEngineMultiTenantSetup
int DetectEngineMultiTenantSetup(void)
setup multi-detect / multi-tenancy
Definition: detect-engine.c:3650
DetectBufferTypeRegisterValidateCallback
void DetectBufferTypeRegisterValidateCallback(const char *name, bool(*ValidateCallback)(const Signature *, const char **sigerror))
Definition: detect-engine.c:989
InspectEngineFuncPtr2
int(* InspectEngineFuncPtr2)(struct DetectEngineCtx_ *de_ctx, struct DetectEngineThreadCtx_ *det_ctx, const struct DetectEngineAppInspectionEngine_ *engine, const struct Signature_ *s, Flow *f, uint8_t flags, void *alstate, void *txv, uint64_t tx_id)
Definition: detect.h:391
DetectEngineTentantRegisterVlanId
int DetectEngineTentantRegisterVlanId(uint32_t tenant_id, uint16_t vlan_id)
Definition: detect-engine.c:3923