suricata
app-layer-htp-range.h
Go to the documentation of this file.
1/* Copyright (C) 2024 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#ifndef SURICATA_APP_LAYER_HTP_RANGE_H
19#define SURICATA_APP_LAYER_HTP_RANGE_H
20
21#include "suricata-common.h"
22
23#include "util-thash.h"
24#include "rust.h"
25
29
30// linked list of ranges : buffer with offset
32 /** red and black tree */
34 /** allocated buffer */
36 /** length of buffer */
38 /** the start of the range (offset relative to the absolute beginning of the file) */
40 /** offset of bytes written in buffer (relative to the start of the range) */
42 /** number of gaped bytes */
45
47
50
51/** Item in hash table for a file in multiple ranges
52 * Thread-safety is ensured with the thread-safe hash table cf THashData
53 * The number of use is increased for each flow opening a new HttpRangeContainerBlock
54 * until it closes this HttpRangeContainerBlock
55 * The design goal is to have concurrency only on opening and closing a range request
56 * and have a lock-free data structure belonging to one Flow
57 * (see HttpRangeContainerBlock below)
58 * for every append in between (we suppose we have many appends per range request)
59 */
60typedef struct HttpRangeContainerFile {
61 /** key for hashtable */
62 uint8_t *key;
63 /** key length */
64 uint32_t len;
65 /** expire time in epoch */
67 /** pointer to hashtable data, for locking and use count */
69 /** total expected size of the file in ranges */
70 uint64_t totalsize;
71 /** size of the file after last sync */
72 uint64_t lastsize;
73 /** streaming buffer config for files below */
75 /** file container, with only one file */
77 /** red and black tree list of ranges which came out of order */
78 struct HTTP_RANGES fragment_tree;
79 /** file flags */
80 uint16_t flags;
81 /** error condition for this range. Its up to timeout handling to cleanup */
82 bool error;
84
85/** A structure representing a single range request :
86 * either skipping, buffering, or appending
87 * As this belongs to a flow, appending data to it is ensured to be thread-safe
88 * Only one block per file has the pointer to the container
89 */
91 /** state where we skip content */
92 uint64_t toskip;
93 /** current out of order range to write into */
95 /** pointer to the main file container, where to directly append data */
97 /** file container we are owning for now */
100
102 const uint8_t *data, uint32_t len);
104 const StreamingBufferConfig *sbcfg, HttpRangeContainerBlock *c, uint16_t flags);
105
106// HttpRangeContainerBlock but trouble with headers inclusion order
107HttpRangeContainerBlock *HttpRangeContainerOpenFile(const unsigned char *key, uint32_t keylen,
108 const Flow *f, const HTTPContentRange *cr, const StreamingBufferConfig *sbcfg,
109 const unsigned char *name, uint16_t name_len, uint16_t flags, const unsigned char *data,
110 uint32_t data_len);
111
113
116int HTPByteRangeSetMemcap(uint64_t);
117
118#endif /* SURICATA_APP_LAYER_HTP_RANGE_H */
uint8_t len
void HttpRangeContainersDestroy(void)
uint32_t HttpRangeContainersTimeoutHash(const SCTime_t ts)
void HttpRangeFreeBlock(HttpRangeContainerBlock *b)
int HttpRangeContainerBufferCompare(HttpRangeContainerBuffer *a, HttpRangeContainerBuffer *b)
void HttpRangeContainersInit(void)
File * HttpRangeClose(const StreamingBufferConfig *sbcfg, HttpRangeContainerBlock *c, uint16_t flags)
int HttpRangeAppendData(const StreamingBufferConfig *sbcfg, HttpRangeContainerBlock *c, const uint8_t *data, uint32_t len)
uint64_t HTPByteRangeMemcapGlobalCounter(void)
HttpRangeContainerBlock * HttpRangeContainerOpenFile(const unsigned char *key, uint32_t keylen, const Flow *f, const HTTPContentRange *cr, const StreamingBufferConfig *sbcfg, const unsigned char *name, uint16_t name_len, uint16_t flags, const unsigned char *data, uint32_t data_len)
uint64_t HTPByteRangeMemuseGlobalCounter(void)
int HTPByteRangeSetMemcap(uint64_t)
uint8_t flags
Definition decode-gre.h:0
uint64_t ts
Flow data structure.
Definition flow.h:356
HttpRangeContainerBuffer * current
HttpRangeContainerFile * container
RB_ENTRY(HttpRangeContainerBuffer) rb
const StreamingBufferConfig * sbcfg
struct HTTP_RANGES fragment_tree
const char * name
#define RB_PROTOTYPE(name, type, field, cmp)
Definition tree.h:385
#define RB_HEAD(name, type)
Definition tree.h:300