suricata
detect-engine.h
Go to the documentation of this file.
1 /* Copyright (C) 2007-2010 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(InspectionBuffer *buffer, const uint8_t *data, const uint32_t data_len);
34 void InspectionBufferCheckAndExpand(InspectionBuffer *buffer, uint32_t min_size);
35 void InspectionBufferCopy(InspectionBuffer *buffer, uint8_t *buf, uint32_t buf_len);
37  const DetectEngineTransforms *transforms);
39 InspectionBuffer *InspectionBufferGet(DetectEngineThreadCtx *det_ctx, const int list_id);
42 
43 int DetectBufferTypeRegister(const char *name);
44 int DetectBufferTypeGetByName(const char *name);
45 void DetectBufferTypeSupportsMpm(const char *name);
46 void DetectBufferTypeSupportsPacket(const char *name);
47 void DetectBufferTypeSupportsTransformations(const char *name);
48 int DetectBufferTypeMaxId(void);
50 void DetectBufferTypeSetDescriptionByName(const char *name, const char *desc);
51 const char *DetectBufferTypeGetDescriptionByName(const char *name);
52 void DetectBufferTypeRegisterSetupCallback(const char *name,
53  void (*Callback)(const DetectEngineCtx *, Signature *));
54 void DetectBufferTypeRegisterValidateCallback(const char *name,
55  bool (*ValidateCallback)(const Signature *, const char **sigerror));
56 
58  int *transforms, int transform_cnt);
59 const char *DetectBufferTypeGetNameById(const DetectEngineCtx *de_ctx, const int id);
62 const char *DetectBufferTypeGetDescriptionById(const DetectEngineCtx *de_ctx, const int id);
63 void DetectBufferRunSetupCallback(const DetectEngineCtx *de_ctx, const int id, Signature *s);
64 bool DetectBufferRunValidateCallback(const DetectEngineCtx *de_ctx, const int id, const Signature *s, const char **sigerror);
65 
66 /* prototypes */
72 
73 int DetectRegisterThreadCtxGlobalFuncs(const char *name,
74  void *(*InitFunc)(void *), void *data, void (*FreeFunc)(void *));
76 
77 TmEcode DetectEngineThreadCtxInit(ThreadVars *, void *, void **);
79 //inline uint32_t DetectEngineGetMaxSigId(DetectEngineCtx *);
80 /* faster as a macro than a inline function on my box -- VJ */
81 #define DetectEngineGetMaxSigId(de_ctx) ((de_ctx)->signum)
83 void DetectEngineRegisterTests(void);
85 
86 uint32_t DetectEngineGetVersion(void);
87 void DetectEngineBumpVersion(void);
91 void DetectEnginePruneFreeList(void);
95 int DetectEngineReload(const SCInstance *suri);
96 int DetectEngineEnabled(void);
97 int DetectEngineMTApply(void);
100 
101 int DetectEngineReloadStart(void);
102 int DetectEngineReloadIsStart(void);
103 void DetectEngineReloadSetIdle(void);
104 int DetectEngineReloadIsIdle(void);
105 
106 int DetectEngineLoadTenantBlocking(uint32_t tenant_id, const char *yaml);
107 int DetectEngineReloadTenantBlocking(uint32_t tenant_id, const char *yaml, int reload_cnt);
108 
109 int DetectEngineTentantRegisterLivedev(uint32_t tenant_id, int device_id);
110 int DetectEngineTentantRegisterVlanId(uint32_t tenant_id, uint16_t vlan_id);
111 int DetectEngineTentantUnregisterVlanId(uint32_t tenant_id, uint16_t vlan_id);
112 int DetectEngineTentantRegisterPcapFile(uint32_t tenant_id);
113 int DetectEngineTentantUnregisterPcapFile(uint32_t tenant_id);
114 
117  const Signature *, const SigMatchData *,
118  Flow *, const uint8_t, void *, void *,
119  uint64_t);
120 
123  const DetectEngineAppInspectionEngine *engine,
124  const Signature *s,
125  Flow *f, uint8_t flags, void *alstate, void *txv, uint64_t tx_id);
126 
128  DetectEngineThreadCtx *det_ctx,
129  const DetectEnginePktInspectionEngine *engine,
130  const Signature *s, Packet *p, uint8_t *alert_flags);
131 
132 /**
133  * \brief Registers an app inspection engine.
134  *
135  * \param name Name of the detection list
136  * \param alproto App layer protocol for which we will register the engine.
137  * \param direction The direction for the engine: SIG_FLAG_TOSERVER or
138  * SIG_FLAG_TOCLIENT
139  * \param progress Minimal progress value for inspect engine to run
140  * \param Callback The engine callback.
141  */
142 void DetectAppLayerInspectEngineRegister(const char *name,
143  AppProto alproto, uint32_t dir,
144  int progress, InspectEngineFuncPtr Callback);
145 void DetectAppLayerInspectEngineRegister2(const char *name,
146  AppProto alproto, uint32_t dir, int progress,
147  InspectEngineFuncPtr2 Callback2,
149 
150 void DetectPktInspectEngineRegister(const char *name,
153 
156 
158  DetectEngineThreadCtx *det_ctx, const Signature *s,
159  Flow *f, Packet *p,
160  uint8_t *alert_flags);
162 
166 
167 int WARN_UNUSED DetectBufferSetActiveList(Signature *s, const int list);
169 
170 #endif /* __DETECT_ENGINE_H__ */
tm-threads.h
DetectEngineAppInspectionEngine_
Definition: detect.h:395
DetectBufferSetActiveList
int WARN_UNUSED DetectBufferSetActiveList(Signature *s, const int list)
Definition: detect-engine.c:972
DetectEngineReloadIsIdle
int DetectEngineReloadIsIdle(void)
Definition: detect-engine.c:1509
DetectBufferTypeRegister
int DetectBufferTypeRegister(const char *name)
Definition: detect-engine.c:816
DetectEnginePktInspectionEngine
Definition: detect.h:454
InspectionBufferGet
InspectionBuffer * InspectionBufferGet(DetectEngineThreadCtx *det_ctx, const int list_id)
Definition: detect-engine.c:1041
InspectionBufferSetup
void InspectionBufferSetup(InspectionBuffer *buffer, const uint8_t *data, const uint32_t data_len)
setup the buffer with our initial data
Definition: detect-engine.c:1100
DetectBufferTypeGetNameById
const char * DetectBufferTypeGetNameById(const DetectEngineCtx *de_ctx, const int id)
Definition: detect-engine.c:869
DetectBufferTypeGetByName
int DetectBufferTypeGetByName(const char *name)
Definition: detect-engine.c:860
DetectEngineTransforms
Definition: detect.h:369
DetectEnginePktInspectionRun
bool DetectEnginePktInspectionRun(ThreadVars *tv, DetectEngineThreadCtx *det_ctx, const Signature *s, Flow *f, Packet *p, uint8_t *alert_flags)
Definition: detect-engine.c:1394
DetectBufferTypeSetDescriptionByName
void DetectBufferTypeSetDescriptionByName(const char *name, const char *desc)
Definition: detect-engine.c:888
AppProto
uint16_t AppProto
Definition: app-layer-protos.h:71
InspectionBuffer
Definition: detect.h:342
flow-private.h
Flow_
Flow data structure.
Definition: flow.h:342
InspectionBufferFree
void InspectionBufferFree(InspectionBuffer *buffer)
Definition: detect-engine.c:1107
DetectEngineReference
DetectEngineCtx * DetectEngineReference(DetectEngineCtx *)
Definition: detect-engine.c:3147
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:375
DetectEngineAppInspectionEngine2Signature
int DetectEngineAppInspectionEngine2Signature(DetectEngineCtx *de_ctx, Signature *s)
Definition: detect-engine.c:466
DetectThreadCtxGetGlobalKeywordThreadCtx
void * DetectThreadCtxGetGlobalKeywordThreadCtx(DetectEngineThreadCtx *det_ctx, int id)
Retrieve thread local keyword ctx by id.
Definition: detect-engine.c:3079
DetectEngineCtx_
main detection engine ctx
Definition: detect.h:761
DetectEngineReloadIsStart
int DetectEngineReloadIsStart(void)
Definition: detect-engine.c:1489
DetectEngineAppInspectionEngineSignatureFree
void DetectEngineAppInspectionEngineSignatureFree(Signature *s)
free app inspect engines for a signature
Definition: detect-engine.c:667
DetectEngineResetMaxSigId
void DetectEngineResetMaxSigId(DetectEngineCtx *)
Definition: detect-engine.c:2403
InspectionBufferClean
void InspectionBufferClean(DetectEngineThreadCtx *det_ctx)
Definition: detect-engine.c:1015
InspectionBufferGetPktDataPtr
InspectionBuffer *(* InspectionBufferGetPktDataPtr)(struct DetectEngineThreadCtx_ *det_ctx, const DetectEngineTransforms *transforms, Packet *p, const int list_id)
Definition: detect.h:449
DetectEnginePktInspectionSetup
int DetectEnginePktInspectionSetup(Signature *s)
Definition: detect-engine.c:1439
InspectionBufferGetMulti
InspectionBufferMultipleForList * InspectionBufferGetMulti(DetectEngineThreadCtx *det_ctx, const int list_id)
Definition: detect-engine.c:1080
DetectEngineReload
int DetectEngineReload(const SCInstance *suri)
Reload the detection engine.
Definition: detect-engine.c:3955
DetectBufferTypeGetByIdTransforms
int DetectBufferTypeGetByIdTransforms(DetectEngineCtx *de_ctx, const int id, int *transforms, int transform_cnt)
Definition: detect-engine.c:1244
DetectEngineLoadTenantBlocking
int DetectEngineLoadTenantBlocking(uint32_t tenant_id, const char *yaml)
Load a tenant and wait for loading to complete.
Definition: detect-engine.c:3350
SigMatchData_
Data needed for Match()
Definition: detect.h:327
DetectEngineCtxInit
DetectEngineCtx * DetectEngineCtxInit(void)
Definition: detect-engine.c:1985
DetectAppLayerInspectEngineRegister2
void DetectAppLayerInspectEngineRegister2(const char *name, AppProto alproto, uint32_t dir, int progress, InspectEngineFuncPtr2 Callback2, InspectionBufferGetDataPtr GetData)
register inspect engine at start up time
Definition: detect-engine.c:231
DetectEnginePruneFreeList
void DetectEnginePruneFreeList(void)
Definition: detect-engine.c:3916
DetectBufferTypeGetDescriptionByName
const char * DetectBufferTypeGetDescriptionByName(const char *name)
Definition: detect-engine.c:906
DetectBufferTypeRegisterSetupCallback
void DetectBufferTypeRegisterSetupCallback(const char *name, void(*Callback)(const DetectEngineCtx *, Signature *))
Definition: detect-engine.c:933
DetectEngineCtxFree
void DetectEngineCtxFree(DetectEngineCtx *)
Free a DetectEngineCtx::
Definition: detect-engine.c:2030
DetectEngineGetByTenantId
DetectEngineCtx * DetectEngineGetByTenantId(int tenant_id)
Definition: detect-engine.c:3799
DetectEngineThreadCtxInit
TmEcode DetectEngineThreadCtxInit(ThreadVars *, void *, void **)
initialize thread specific detection engine context
Definition: detect-engine.c:2726
InspectionBufferMultipleForList
Definition: detect.h:362
DetectEngineUnsetParseMetadata
void DetectEngineUnsetParseMetadata(void)
Definition: detect-engine.c:4116
DetectBufferTypeSupportsPacketGetById
bool DetectBufferTypeSupportsPacketGetById(const DetectEngineCtx *de_ctx, const int id)
Definition: detect-engine.c:915
InspectionBufferMultipleForListGet
InspectionBuffer * InspectionBufferMultipleForListGet(InspectionBufferMultipleForList *fb, uint32_t local_id)
for a InspectionBufferMultipleForList get a InspectionBuffer
Definition: detect-engine.c:1054
InspectionBufferPktInspectFunc
int(* InspectionBufferPktInspectFunc)(struct DetectEngineThreadCtx_ *, const struct DetectEnginePktInspectionEngine *engine, const struct Signature_ *s, Packet *p, uint8_t *alert_flags)
Definition: detect.h:442
DetectSigmatchListEnumToString
const char * DetectSigmatchListEnumToString(enum DetectSigmatchListEnum type)
Definition: detect-engine.c:4126
type
uint8_t type
Definition: decode-icmpv4.h:2
de_ctx
DetectEngineCtx * de_ctx
Definition: fuzz_siginit.c:16
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:3364
InspectionBufferCopy
void InspectionBufferCopy(InspectionBuffer *buffer, uint8_t *buf, uint32_t buf_len)
Definition: detect-engine.c:1136
DetectEngineThreadCtx_
Definition: detect.h:1004
DetectEngineReloadSetIdle
void DetectEngineReloadSetIdle(void)
Definition: detect-engine.c:1501
DetectEngineTentantUnregisterPcapFile
int DetectEngineTentantUnregisterPcapFile(uint32_t tenant_id)
Definition: detect-engine.c:3788
DetectEngineGetCurrent
DetectEngineCtx * DetectEngineGetCurrent(void)
Definition: detect-engine.c:3124
InspectEngineFuncPtr
int(* InspectEngineFuncPtr)(ThreadVars *tv, struct DetectEngineCtx_ *de_ctx, struct DetectEngineThreadCtx_ *det_ctx, const struct Signature_ *sig, const SigMatchData *smd, Flow *f, uint8_t flags, void *alstate, void *tx, uint64_t tx_id)
Definition: detect.h:381
DetectBufferTypeGetDescriptionById
const char * DetectBufferTypeGetDescriptionById(const DetectEngineCtx *de_ctx, const int id)
Definition: detect-engine.c:897
DetectEngineCtxInitStubForMT
DetectEngineCtx * DetectEngineCtxInitStubForMT(void)
Definition: detect-engine.c:1975
detect.h
ThreadVars_
Per thread variable structure.
Definition: threadvars.h:57
InspectionBufferApplyTransforms
void InspectionBufferApplyTransforms(InspectionBuffer *buffer, const DetectEngineTransforms *transforms)
Definition: detect-engine.c:1148
DetectBufferTypeSupportsMpmGetById
bool DetectBufferTypeSupportsMpmGetById(const DetectEngineCtx *de_ctx, const int id)
Definition: detect-engine.c:924
DetectEngineThreadCtxDeinit
TmEcode DetectEngineThreadCtxDeinit(ThreadVars *, void *)
Definition: detect-engine.c:2934
DetectEngineDeReference
void DetectEngineDeReference(DetectEngineCtx **de_ctx)
Definition: detect-engine.c:3825
DetectEngineMustParseMetadata
int DetectEngineMustParseMetadata(void)
Definition: detect-engine.c:4121
DetectEngineGetVersion
uint32_t DetectEngineGetVersion(void)
Definition: detect-engine.c:3105
DetectAppLayerInspectEngineRegister
void DetectAppLayerInspectEngineRegister(const char *name, AppProto alproto, uint32_t dir, int progress, InspectEngineFuncPtr Callback)
Registers an app inspection engine.
Definition: detect-engine.c:170
DetectBufferGetActiveList
int DetectBufferGetActiveList(DetectEngineCtx *de_ctx, Signature *s)
Definition: detect-engine.c:985
DetectBufferTypeSupportsTransformations
void DetectBufferTypeSupportsTransformations(const char *name)
Definition: detect-engine.c:850
DetectEngineTentantUnregisterVlanId
int DetectEngineTentantUnregisterVlanId(uint32_t tenant_id, uint16_t vlan_id)
Definition: detect-engine.c:3777
Packet_
Definition: decode.h:408
DetectEngineInspectGenericList
int DetectEngineInspectGenericList(ThreadVars *, 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:1533
DetectEngineReloadStart
int DetectEngineReloadStart(void)
Definition: detect-engine.c:1475
DetectBufferTypeSupportsPacket
void DetectBufferTypeSupportsPacket(const char *name)
Definition: detect-engine.c:830
TmEcode
TmEcode
Definition: tm-threads-common.h:77
InspectionBufferInit
void InspectionBufferInit(InspectionBuffer *buffer, uint32_t initial_size)
Definition: detect-engine.c:1090
DetectEngineAddToMaster
int DetectEngineAddToMaster(DetectEngineCtx *de_ctx)
Definition: detect-engine.c:3849
DetectEngineTentantRegisterPcapFile
int DetectEngineTentantRegisterPcapFile(uint32_t tenant_id)
Definition: detect-engine.c:3782
DetectBufferRunValidateCallback
bool DetectBufferRunValidateCallback(const DetectEngineCtx *de_ctx, const int id, const Signature *s, const char **sigerror)
Definition: detect-engine.c:962
DetectBufferRunSetupCallback
void DetectBufferRunSetupCallback(const DetectEngineCtx *de_ctx, const int id, Signature *s)
Definition: detect-engine.c:943
flags
uint8_t flags
Definition: decode-gre.h:2
DetectPktInspectEngineRegister
void DetectPktInspectEngineRegister(const char *name, InspectionBufferGetPktDataPtr GetPktData, InspectionBufferPktInspectFunc Callback)
register inspect engine at start up time
Definition: detect-engine.c:128
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:1119
DetectEngineTentantRegisterLivedev
int DetectEngineTentantRegisterLivedev(uint32_t tenant_id, int device_id)
Definition: detect-engine.c:3767
DetectBufferTypeMaxId
int DetectBufferTypeMaxId(void)
Definition: detect-engine.c:735
DetectEngineSetParseMetadata
void DetectEngineSetParseMetadata(void)
Definition: detect-engine.c:4111
DetectEngineEnabled
int DetectEngineEnabled(void)
Check if detection is enabled.
Definition: detect-engine.c:3091
DetectEngineCtxInitStubForDD
DetectEngineCtx * DetectEngineCtxInitStubForDD(void)
Definition: detect-engine.c:1980
DetectBufferTypeCloseRegistration
void DetectBufferTypeCloseRegistration(void)
Definition: detect-engine.c:1237
tv
ThreadVars * tv
Definition: fuzz_decodepcapfile.c:32
DetectRegisterThreadCtxGlobalFuncs
int DetectRegisterThreadCtxGlobalFuncs(const char *name, void *(*InitFunc)(void *), void *data, void(*FreeFunc)(void *))
Register Thread keyword context Funcs (Global)
Definition: detect-engine.c:3035
DetectEngineMultiTenantEnabled
int DetectEngineMultiTenantEnabled(void)
Definition: detect-engine.c:3156
DetectEngineMoveToFreeList
int DetectEngineMoveToFreeList(DetectEngineCtx *de_ctx)
Definition: detect-engine.c:3865
Signature_
Signature container.
Definition: detect.h:522
DetectEngineMTApply
int DetectEngineMTApply(void)
Definition: detect-engine.c:4056
DetectEngineRegisterTests
void DetectEngineRegisterTests(void)
Definition: detect-engine.c:4422
DetectEngineCtxInitWithPrefix
DetectEngineCtx * DetectEngineCtxInitWithPrefix(const char *prefix)
Definition: detect-engine.c:1990
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:1643
SCInstance_
Definition: suricata.h:128
DetectBufferTypeSupportsMpm
void DetectBufferTypeSupportsMpm(const char *name)
Definition: detect-engine.c:840
DetectEngineBumpVersion
void DetectEngineBumpVersion(void)
Definition: detect-engine.c:3115
DetectSigmatchListEnum
DetectSigmatchListEnum
Definition: detect.h:88
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:1578
WARN_UNUSED
#define WARN_UNUSED
Definition: suricata-common.h:372
DetectEngineMultiTenantSetup
int DetectEngineMultiTenantSetup(void)
setup multi-detect / multi-tenancy
Definition: detect-engine.c:3499
DetectBufferTypeRegisterValidateCallback
void DetectBufferTypeRegisterValidateCallback(const char *name, bool(*ValidateCallback)(const Signature *, const char **sigerror))
Definition: detect-engine.c:952
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:389
DetectEngineTentantRegisterVlanId
int DetectEngineTentantRegisterVlanId(uint32_t tenant_id, uint16_t vlan_id)
Definition: detect-engine.c:3772