suricata
detect-engine-inspect-buffer.h
Go to the documentation of this file.
1 /* Copyright (C) 2025 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_DETECT_ENGINE_INSPECT_BUFFER_H
25 #define SURICATA_DETECT_ENGINE_INSPECT_BUFFER_H
26 
27 /* inspection buffer is a simple structure that is passed between prefilter,
28  * transformation functions and inspection functions.
29  * Initially setup with 'orig' ptr and len, transformations can then take
30  * then and fill the 'buf'. Multiple transformations can update the buffer,
31  * both growing and shrinking it.
32  * Prefilter and inspection will only deal with 'inspect'. */
33 
34 typedef struct InspectionBuffer {
35  const uint8_t *inspect; /**< active pointer, points either to ::buf or ::orig */
36  uint64_t inspect_offset;
37  uint32_t inspect_len; /**< size of active data. See to ::len or ::orig_len */
38  bool initialized; /**< is initialized. ::inspect might be NULL if transform lead to 0 size */
39  uint8_t flags; /**< DETECT_CI_FLAGS_* for use with DetectEngineContentInspection */
40 #ifdef DEBUG_VALIDATION
41  bool multi;
42 #endif
43  uint32_t len; /**< how much is in use */
44  uint8_t *buf;
45  uint32_t size; /**< size of the memory allocation */
46 
47  uint32_t orig_len;
48  const uint8_t *orig;
50 
51 // Forward declarations for types from detect.h
54 typedef struct SigMatch_ SigMatch;
55 
56 void InspectionBufferInit(InspectionBuffer *buffer, uint32_t initial_size);
57 void InspectionBufferSetup(DetectEngineThreadCtx *det_ctx, const int list_id,
58  InspectionBuffer *buffer, const uint8_t *data, const uint32_t data_len);
59 void InspectionBufferSetupAndApplyTransforms(DetectEngineThreadCtx *det_ctx, const int list_id,
60  InspectionBuffer *buffer, const uint8_t *data, const uint32_t data_len,
61  const DetectEngineTransforms *transforms);
63 uint8_t *SCInspectionBufferCheckAndExpand(InspectionBuffer *buffer, uint32_t min_size);
64 void SCInspectionBufferTruncate(InspectionBuffer *buffer, uint32_t buf_len);
65 void InspectionBufferCopy(InspectionBuffer *buffer, uint8_t *buf, uint32_t buf_len);
67  const DetectEngineTransforms *transforms);
69 InspectionBuffer *InspectionBufferGet(DetectEngineThreadCtx *det_ctx, const int list_id);
72  const DetectEngineTransforms *transforms, const uint8_t *data, const uint32_t data_len);
74  DetectEngineThreadCtx *det_ctx, const int list_id, uint32_t local_id);
75 
76 #endif /* SURICATA_DETECT_ENGINE_INSPECT_BUFFER_H */
InspectionBufferGet
InspectionBuffer * InspectionBufferGet(DetectEngineThreadCtx *det_ctx, const int list_id)
Definition: detect-engine-inspect-buffer.c:56
InspectionBufferApplyTransforms
void InspectionBufferApplyTransforms(DetectEngineThreadCtx *det_ctx, InspectionBuffer *buffer, const DetectEngineTransforms *transforms)
Definition: detect-engine-inspect-buffer.c:128
InspectionBuffer::initialized
bool initialized
Definition: detect-engine-inspect-buffer.h:38
DetectEngineTransforms
Definition: detect.h:392
InspectionBufferCopy
void InspectionBufferCopy(InspectionBuffer *buffer, uint8_t *buf, uint32_t buf_len)
Definition: detect-engine-inspect-buffer.c:246
InspectionBuffer
Definition: detect-engine-inspect-buffer.h:34
InspectionBufferSetupMulti
void InspectionBufferSetupMulti(DetectEngineThreadCtx *det_ctx, InspectionBuffer *buffer, const DetectEngineTransforms *transforms, const uint8_t *data, const uint32_t data_len)
setup the buffer with our initial data
Definition: detect-engine-inspect-buffer.c:157
InspectionBuffer::orig
const uint8_t * orig
Definition: detect-engine-inspect-buffer.h:48
InspectionBuffer
struct InspectionBuffer InspectionBuffer
InspectionBuffer::size
uint32_t size
Definition: detect-engine-inspect-buffer.h:45
InspectionBuffer::flags
uint8_t flags
Definition: detect-engine-inspect-buffer.h:39
InspectionBufferClean
void InspectionBufferClean(DetectEngineThreadCtx *det_ctx)
Definition: detect-engine-inspect-buffer.c:30
InspectionBuffer::orig_len
uint32_t orig_len
Definition: detect-engine-inspect-buffer.h:47
InspectionBufferFree
void InspectionBufferFree(InspectionBuffer *buffer)
Definition: detect-engine-inspect-buffer.c:205
DetectEngineThreadCtx_
Definition: detect.h:1200
InspectionBuffer::inspect_offset
uint64_t inspect_offset
Definition: detect-engine-inspect-buffer.h:36
InspectionBuffer::buf
uint8_t * buf
Definition: detect-engine-inspect-buffer.h:44
InspectionBufferSetupAndApplyTransforms
void InspectionBufferSetupAndApplyTransforms(DetectEngineThreadCtx *det_ctx, const int list_id, InspectionBuffer *buffer, const uint8_t *data, const uint32_t data_len, const DetectEngineTransforms *transforms)
setup the buffer with our initial data
Definition: detect-engine-inspect-buffer.c:197
SCInspectionBufferCheckAndExpand
uint8_t * SCInspectionBufferCheckAndExpand(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-inspect-buffer.c:217
InspectionBuffer::inspect_len
uint32_t inspect_len
Definition: detect-engine-inspect-buffer.h:37
InspectionBuffer::inspect
const uint8_t * inspect
Definition: detect-engine-inspect-buffer.h:35
InspectionBuffer::len
uint32_t len
Definition: detect-engine-inspect-buffer.h:43
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-inspect-buffer.c:190
InspectionBufferSetupMultiEmpty
void InspectionBufferSetupMultiEmpty(InspectionBuffer *buffer)
setup the buffer empty
Definition: detect-engine-inspect-buffer.c:144
SigMatch_
a single match condition for a signature
Definition: detect.h:357
SCInspectionBufferTruncate
void SCInspectionBufferTruncate(InspectionBuffer *buffer, uint32_t buf_len)
Definition: detect-engine-inspect-buffer.c:237
InspectionBufferInit
void InspectionBufferInit(InspectionBuffer *buffer, uint32_t initial_size)
Definition: detect-engine-inspect-buffer.c:134
InspectionBufferMultipleForListGet
InspectionBuffer * InspectionBufferMultipleForListGet(DetectEngineThreadCtx *det_ctx, const int list_id, uint32_t local_id)
for a InspectionBufferMultipleForList get a InspectionBuffer
Definition: detect-engine-inspect-buffer.c:76