suricata
detect-engine-helper.h
Go to the documentation of this file.
1 /* Copyright (C) 2023 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 Philippe Antoine <p.antoine@catenacyber.fr>
22  */
23 
24 #ifndef SURICATA_DETECT_ENGINE_HELPER_H
25 #define SURICATA_DETECT_ENGINE_HELPER_H
26 
27 #include "app-layer-protos.h"
29 
30 // type from flow.h with only forward declarations for bindgen
31 typedef struct Flow_ Flow;
32 // type from decode.h with only a forward declaration for bindgen
33 typedef struct Packet_ Packet;
34 // types from detect.h with only forward declarations for bindgen
35 // could be #ifndef SURICATA_BINDGEN_H #include "detect.h" #endif
36 typedef struct DetectEngineCtx_ DetectEngineCtx;
37 typedef struct Signature_ Signature;
38 typedef struct SigMatchCtx_ SigMatchCtx;
41 typedef InspectionBuffer *(*InspectionBufferGetDataPtr)(struct DetectEngineThreadCtx_ *det_ctx,
42  const DetectEngineTransforms *transforms, Flow *f, const uint8_t flow_flags, void *txv,
43  const int list_id);
45  const void *txv, const uint8_t flow_flags, uint32_t local_id, const uint8_t **buf,
46  uint32_t *buf_len);
48  const void *txv, const uint8_t flow_flags, const uint8_t **buf, uint32_t *buf_len);
49 
50 /// App-layer light version of SigTableElmt
51 typedef struct SCSigTableAppLiteElmt {
52  /// keyword name
53  const char *name;
54  /// keyword description
55  const char *desc;
56  /// keyword documentation url
57  const char *url;
58  /// flags SIGMATCH_*
59  uint32_t flags;
60  /// function callback to parse and setup keyword in rule
61  int (*Setup)(DetectEngineCtx *, Signature *, const char *);
62  /// function callback to free structure allocated by setup if any
63  void (*Free)(DetectEngineCtx *, void *);
64  /// function callback to match on an app-layer transaction
65  int (*AppLayerTxMatch)(DetectEngineThreadCtx *, Flow *, uint8_t flags, void *alstate, void *txv,
66  const Signature *, const SigMatchCtx *);
68 
69 typedef struct SCTransformTableElmt {
70  const char *name;
71  const char *desc;
72  const char *url;
73  uint32_t flags;
74  int (*Setup)(DetectEngineCtx *, Signature *, const char *);
75  void (*Free)(DetectEngineCtx *, void *);
76  void (*Transform)(DetectEngineThreadCtx *, InspectionBuffer *, const void *context);
77  bool (*TransformValidate)(const uint8_t *content, uint16_t content_len, const void *context);
78  void (*TransformId)(const uint8_t **id_data, uint32_t *id_length, const void *context);
80 
82 
85  int (*Match)(DetectEngineThreadCtx *, Packet *, const Signature *, const SigMatchCtx *));
86 void SCDetectHelperKeywordAliasRegister(uint16_t kwid, const char *alias);
87 typedef struct SCJsonBuilder SCJsonBuilder;
88 void SCDetectHelperKeywordJsonInfoRegister(uint16_t kwid, void (*cb)(struct SCJsonBuilder *));
90  const char *name, AppProto alproto, uint8_t direction, uint8_t progress);
91 
92 int SCDetectHelperBufferMpmRegister(const char *name, const char *desc, AppProto alproto,
93  uint8_t direction, InspectionSingleBufferGetDataPtr GetData);
95  const char *name, AppProto alproto, uint8_t direction, uint8_t sub_state, uint8_t progress);
96 int SCDetectRegisterMpmGeneric(const char *name, const char *desc, AppProto alproto,
97  uint8_t direction, InspectionBufferGetDataPtr GetData, uint8_t progress);
98 int SCDetectHelperBufferProgressMpmRegister(const char *name, const char *desc, AppProto alproto,
99  uint8_t direction, InspectionSingleBufferGetDataPtr GetData, uint8_t progress);
100 int SCDetectHelperMultiBufferMpmRegister(const char *name, const char *desc, AppProto alproto,
101  uint8_t direction, InspectionMultiBufferGetDataPtr GetData);
102 int SCDetectHelperMultiBufferProgressMpmRegister(const char *name, const char *desc,
103  AppProto alproto, uint8_t direction, InspectionMultiBufferGetDataPtr GetData,
104  uint8_t progress);
105 int SCDetectHelperMultiBufferProgressMpmRegisterSubState(const char *name, const char *desc,
106  AppProto alproto, uint8_t direction, InspectionMultiBufferGetDataPtr GetData,
107  uint8_t sub_state, uint8_t progress);
108 
110 
112 
113 #endif /* SURICATA_DETECT_ENGINE_HELPER_H */
SCJsonBuilder
struct SCJsonBuilder SCJsonBuilder
Definition: detect-engine-helper.h:87
SCSigTableAppLiteElmt::AppLayerTxMatch
int(* AppLayerTxMatch)(DetectEngineThreadCtx *, Flow *, uint8_t flags, void *alstate, void *txv, const Signature *, const SigMatchCtx *)
function callback to match on an app-layer transaction
Definition: detect-engine-helper.h:65
SCDetectHelperMultiBufferProgressMpmRegisterSubState
int SCDetectHelperMultiBufferProgressMpmRegisterSubState(const char *name, const char *desc, AppProto alproto, uint8_t direction, InspectionMultiBufferGetDataPtr GetData, uint8_t sub_state, uint8_t progress)
Definition: detect-engine-helper.c:142
SCSigTableAppLiteElmt::url
const char * url
keyword documentation url
Definition: detect-engine-helper.h:57
SCSigTableAppLiteElmt::name
const char * name
keyword name
Definition: detect-engine-helper.h:53
DetectEngineTransforms
Definition: detect.h:366
SCDetectHelperMultiBufferProgressMpmRegister
int SCDetectHelperMultiBufferProgressMpmRegister(const char *name, const char *desc, AppProto alproto, uint8_t direction, InspectionMultiBufferGetDataPtr GetData, uint8_t progress)
Definition: detect-engine-helper.c:126
name
const char * name
Definition: detect-engine-proto.c:47
SCTransformTableElmt::url
const char * url
Definition: detect-engine-helper.h:72
AppProto
uint16_t AppProto
Definition: app-layer-protos.h:87
InspectionBuffer
Definition: detect-engine-inspect-buffer.h:34
SCTransformTableElmt::Setup
int(* Setup)(DetectEngineCtx *, Signature *, const char *)
Definition: detect-engine-helper.h:74
SCTransformTableElmt
Definition: detect-engine-helper.h:69
Flow_
Flow data structure.
Definition: flow.h:360
DetectEngineCtx_
main detection engine ctx
Definition: detect.h:966
SCDetectHelperTransformRegister
int SCDetectHelperTransformRegister(const SCTransformTableElmt *kw)
Definition: detect-engine-helper.c:227
SCDetectHelperKeywordPacketMatchRegister
void SCDetectHelperKeywordPacketMatchRegister(uint16_t kwid, int(*Match)(DetectEngineThreadCtx *, Packet *, const Signature *, const SigMatchCtx *))
Register a packet match callback for an existing keyword.
Definition: detect-engine-helper.c:211
SCTransformTableElmt::TransformId
void(* TransformId)(const uint8_t **id_data, uint32_t *id_length, const void *context)
Definition: detect-engine-helper.h:78
SCSigTableAppLiteElmt::desc
const char * desc
keyword description
Definition: detect-engine-helper.h:55
SCTransformTableElmt
struct SCTransformTableElmt SCTransformTableElmt
SCTransformTableElmt::desc
const char * desc
Definition: detect-engine-helper.h:71
SCTransformTableElmt::name
const char * name
Definition: detect-engine-helper.h:70
SCTransformTableElmt::flags
uint32_t flags
Definition: detect-engine-helper.h:73
SCSigTableAppLiteElmt
App-layer light version of SigTableElmt.
Definition: detect-engine-helper.h:51
SCTransformTableElmt::TransformValidate
bool(* TransformValidate)(const uint8_t *content, uint16_t content_len, const void *context)
Definition: detect-engine-helper.h:77
detect-engine-inspect-buffer.h
DetectEngineThreadCtx_
Definition: detect.h:1295
SCDetectHelperBufferProgressMpmRegister
int SCDetectHelperBufferProgressMpmRegister(const char *name, const char *desc, AppProto alproto, uint8_t direction, InspectionSingleBufferGetDataPtr GetData, uint8_t progress)
Definition: detect-engine-helper.c:106
SCDetectHelperKeywordAliasRegister
void SCDetectHelperKeywordAliasRegister(uint16_t kwid, const char *alias)
Definition: detect-engine-helper.c:217
SCDetectHelperMultiBufferMpmRegister
int SCDetectHelperMultiBufferMpmRegister(const char *name, const char *desc, AppProto alproto, uint8_t direction, InspectionMultiBufferGetDataPtr GetData)
Definition: detect-engine-helper.c:160
InspectionSingleBufferGetDataPtr
bool(* InspectionSingleBufferGetDataPtr)(const void *txv, const uint8_t flow_flags, const uint8_t **buf, uint32_t *buf_len)
Definition: detect-engine-helper.h:47
SCSigTableAppLiteElmt
struct SCSigTableAppLiteElmt SCSigTableAppLiteElmt
App-layer light version of SigTableElmt.
SCTransformTableElmt::Transform
void(* Transform)(DetectEngineThreadCtx *, InspectionBuffer *, const void *context)
Definition: detect-engine-helper.h:76
SCDetectHelperNewKeywordId
int SCDetectHelperNewKeywordId(void)
Definition: detect-engine-helper.c:167
SCSigTableAppLiteElmt::flags
uint32_t flags
flags SIGMATCH_*
Definition: detect-engine-helper.h:59
SCDetectRegisterBufferLowerMd5Callbacks
void SCDetectRegisterBufferLowerMd5Callbacks(const char *name)
Definition: detect-engine-helper.c:249
SCSigTableAppLiteElmt::Free
void(* Free)(DetectEngineCtx *, void *)
function callback to free structure allocated by setup if any
Definition: detect-engine-helper.h:63
Packet_
Definition: decode.h:528
SCDetectHelperKeywordRegister
uint16_t SCDetectHelperKeywordRegister(const SCSigTableAppLiteElmt *kw)
Definition: detect-engine-helper.c:184
SCDetectHelperBufferProgressRegister
int SCDetectHelperBufferProgressRegister(const char *name, AppProto alproto, uint8_t direction, uint8_t progress)
Definition: detect-engine-helper.c:36
InspectionMultiBufferGetDataPtr
bool(* InspectionMultiBufferGetDataPtr)(struct DetectEngineThreadCtx_ *det_ctx, const void *txv, const uint8_t flow_flags, uint32_t local_id, const uint8_t **buf, uint32_t *buf_len)
Definition: detect-engine-helper.h:44
SigMatchCtx_
Used to start a pointer to SigMatch context Should never be dereferenced without casting to something...
Definition: detect.h:326
SCDetectHelperBufferProgressRegisterSubState
int SCDetectHelperBufferProgressRegisterSubState(const char *name, AppProto alproto, uint8_t direction, uint8_t sub_state, uint8_t progress)
Definition: detect-engine-helper.c:51
SCSigTableAppLiteElmt::Setup
int(* Setup)(DetectEngineCtx *, Signature *, const char *)
function callback to parse and setup keyword in rule
Definition: detect-engine-helper.h:61
SCDetectRegisterMpmGeneric
int SCDetectRegisterMpmGeneric(const char *name, const char *desc, AppProto alproto, uint8_t direction, InspectionBufferGetDataPtr GetData, uint8_t progress)
Definition: detect-engine-helper.c:86
SCDetectHelperBufferMpmRegister
int SCDetectHelperBufferMpmRegister(const char *name, const char *desc, AppProto alproto, uint8_t direction, InspectionSingleBufferGetDataPtr GetData)
Definition: detect-engine-helper.c:66
Signature_
Signature container.
Definition: detect.h:663
SCTransformTableElmt::Free
void(* Free)(DetectEngineCtx *, void *)
Definition: detect-engine-helper.h:75
app-layer-protos.h
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-engine-helper.h:41
SCDetectHelperKeywordJsonInfoRegister
void SCDetectHelperKeywordJsonInfoRegister(uint16_t kwid, void(*cb)(struct SCJsonBuilder *))
Definition: detect-engine-helper.c:222
f
Flow f
Definition: fuzz_dataset.c:32