suricata
app-layer-frames.h
Go to the documentation of this file.
1/* Copyright (C) 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 SURICATA_APP_LAYER_FRAMES_H
25#define SURICATA_APP_LAYER_FRAMES_H
26
27#include "rust.h"
28
29/** special value for matching any type */
30#define FRAME_ANY_TYPE 62
31/** max 63 to fit the 64 bit per protocol space */
32#define FRAME_STREAM_TYPE 63
33
34typedef int64_t FrameId;
35
36enum {
38#define FRAME_FLAG_TX_ID_SET BIT_U8(FRAME_FLAGE_TX_ID_SET)
40#define FRAME_FLAG_ENDS_AT_EOF BIT_U8(FRAME_FLAGE_ENDS_AT_EOF)
42#define FRAME_FLAG_LOGGED BIT_U8(FRAME_FLAGE_LOGGED)
43};
44
45typedef struct Frame {
46 uint8_t type; /**< protocol specific field type. E.g. NBSS.HDR or SMB.DATA */
47 uint8_t flags; /**< frame flags: FRAME_FLAG_* */
48 uint8_t event_cnt;
49 // TODO one event per frame enough?
50 uint8_t events[4]; /**< per frame store for events */
51 uint64_t offset; /**< offset from the start of the stream */
52 int64_t len;
53 int64_t id;
54 uint64_t tx_id; /**< tx_id to match this frame. UINT64T_MAX if not used. */
55 uint64_t inspect_progress; /**< inspection tracker relative to the start of the frame */
57
58#define FRAMES_STATIC_CNT 3
59
60typedef struct Frames {
61 uint16_t cnt;
62 uint16_t dyn_size; /**< size in elements of `dframes` */
63 uint32_t left_edge_rel;
64 uint64_t base_id;
65 Frame sframes[FRAMES_STATIC_CNT]; /**< static frames */
66 Frame *dframes; /**< dynamically allocated space for more frames */
67#ifdef DEBUG
68 uint8_t ipproto;
69 AppProto alproto;
70#endif
72
77
78void FramesFree(Frames *frames);
79void FramesPrune(Flow *f, Packet *p);
80
81Frame *AppLayerFrameNewByPointer(Flow *f, const StreamSlice *stream_slice,
82 const uint8_t *frame_start, const int64_t len, int dir, uint8_t frame_type);
84 const uint32_t frame_start_rel, const int64_t len, int dir, uint8_t frame_type);
86 const uint64_t frame_start, const int64_t len, int dir, uint8_t frame_type);
87void AppLayerFrameDump(Flow *f);
88
89Frame *FrameGetByIndex(Frames *frames, const uint32_t idx);
90Frame *FrameGetById(Frames *frames, const int64_t id);
91Frame *FrameGetLastOpenByType(Frames *frames, const uint8_t frame_type);
92
93Frame *AppLayerFrameGetById(Flow *f, const int direction, const FrameId frame_id);
94Frame *AppLayerFrameGetLastOpenByType(Flow *f, const int direction, const uint8_t frame_type);
95
97
98void AppLayerFrameAddEvent(Frame *frame, uint8_t e);
99void AppLayerFrameAddEventById(Flow *f, const int dir, const FrameId id, uint8_t e);
100void AppLayerFrameSetLength(Frame *frame, int64_t len);
101void AppLayerFrameSetLengthById(Flow *f, const int dir, const FrameId id, int64_t len);
102void AppLayerFrameSetTxId(Frame *r, uint64_t tx_id);
103void AppLayerFrameSetTxIdById(Flow *f, const int dir, const FrameId id, uint64_t tx_id);
104
105void AppLayerFramesSlide(Flow *f, const uint32_t slide, const uint8_t direction);
106
109
110void FrameConfigInit(void);
111void FrameConfigDeInit(void);
112void FrameConfigEnableAll(void);
113void FrameConfigEnable(const AppProto p, const uint8_t type);
114
115#endif
uint8_t len
void AppLayerFrameSetLength(Frame *frame, int64_t len)
void AppLayerFrameAddEvent(Frame *frame, uint8_t e)
FramesContainer * AppLayerFramesSetupContainer(Flow *f)
Frame * FrameGetById(Frames *frames, const int64_t id)
void FrameConfigEnable(const AppProto p, const uint8_t type)
void AppLayerFrameSetTxId(Frame *r, uint64_t tx_id)
Frame * AppLayerFrameNewByAbsoluteOffset(Flow *f, const StreamSlice *stream_slice, const uint64_t frame_start, const int64_t len, int dir, uint8_t frame_type)
create new frame using the absolute offset from the start of the stream
void AppLayerFrameSetTxIdById(Flow *f, const int dir, const FrameId id, uint64_t tx_id)
void AppLayerFramesSlide(Flow *f, const uint32_t slide, const uint8_t direction)
int64_t FrameId
void AppLayerFrameSetLengthById(Flow *f, const int dir, const FrameId id, int64_t len)
FramesContainer * AppLayerFramesGetContainer(Flow *f)
void AppLayerFrameDump(Flow *f)
Frame * AppLayerFrameNewByPointer(Flow *f, const StreamSlice *stream_slice, const uint8_t *frame_start, const int64_t len, int dir, uint8_t frame_type)
create new frame using a pointer to start of the frame
Frame * AppLayerFrameGetLastOpenByType(Flow *f, const int direction, const uint8_t frame_type)
void FramesPrune(Flow *f, Packet *p)
Frame * AppLayerFrameNewByRelativeOffset(Flow *f, const StreamSlice *stream_slice, const uint32_t frame_start_rel, const int64_t len, int dir, uint8_t frame_type)
create new frame using a relative offset from the start of the stream slice
#define FRAMES_STATIC_CNT
FrameId AppLayerFrameGetId(Frame *r)
void AppLayerFrameAddEventById(Flow *f, const int dir, const FrameId id, uint8_t e)
Frame * AppLayerFrameGetById(Flow *f, const int direction, const FrameId frame_id)
void FrameConfigEnableAll(void)
void FrameConfigDeInit(void)
@ FRAME_FLAGE_ENDS_AT_EOF
@ FRAME_FLAGE_TX_ID_SET
@ FRAME_FLAGE_LOGGED
void FrameConfigInit(void)
Frame * FrameGetLastOpenByType(Frames *frames, const uint8_t frame_type)
void FramesFree(Frames *frames)
Frame * FrameGetByIndex(Frames *frames, const uint32_t idx)
struct StreamSlice StreamSlice
uint16_t AppProto
uint16_t type
Flow data structure.
Definition flow.h:356
uint8_t event_cnt
int64_t id
uint64_t tx_id
uint8_t type
int64_t len
uint8_t events[4]
uint64_t offset
uint8_t flags
uint64_t inspect_progress
uint16_t cnt
uint64_t base_id
Frame * dframes
uint32_t left_edge_rel
uint16_t dyn_size
Frame sframes[FRAMES_STATIC_CNT]