suricata
app-layer-htp-range.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 #ifndef __APP_LAYER_HTP_RANGE_H__
19 #define __APP_LAYER_HTP_RANGE_H__
20 
21 #include "suricata-common.h"
22 
23 #include "util-thash.h"
24 #include "rust.h"
25 
26 void HttpRangeContainersInit(void);
29 
30 // linked list of ranges : buffer with offset
31 typedef struct HttpRangeContainerBuffer {
32  /** red and black tree */
34  /** allocated buffer */
35  uint8_t *buffer;
36  /** length of buffer */
37  uint64_t buflen;
38  /** the start of the range (offset relative to the absolute beginning of the file) */
39  uint64_t start;
40  /** offset of bytes written in buffer (relative to the start of the range) */
41  uint64_t offset;
42  /** number of gaped bytes */
43  uint64_t gap;
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  */
60 typedef struct HttpRangeContainerFile {
61  /** key for hashtable */
62  uint8_t *key;
63  /** key length */
64  uint32_t len;
65  /** expire time in epoch */
66  uint32_t expire;
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  */
90 typedef struct HttpRangeContainerBlock {
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
107 HttpRangeContainerBlock *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 
114 #endif /* __APP_LAYER_HTP_RANGE_H__ */
HttpRangeContainerBuffer::gap
uint64_t gap
Definition: app-layer-htp-range.h:43
HttpRangeContainerBuffer::buffer
uint8_t * buffer
Definition: app-layer-htp-range.h:35
FileContainer_
Definition: util-file.h:113
len
uint8_t len
Definition: app-layer-dnp3.h:2
ts
uint64_t ts
Definition: source-erf-file.c:55
HttpRangeContainersTimeoutHash
uint32_t HttpRangeContainersTimeoutHash(const SCTime_t ts)
Definition: app-layer-htp-range.c:188
HttpRangeContainerBuffer::buflen
uint64_t buflen
Definition: app-layer-htp-range.h:37
HttpRangeContainersDestroy
void HttpRangeContainersDestroy(void)
Definition: app-layer-htp-range.c:183
HttpRangeContainerFile::files
FileContainer * files
Definition: app-layer-htp-range.h:76
Flow_
Flow data structure.
Definition: flow.h:357
HttpRangeAppendData
int HttpRangeAppendData(const StreamingBufferConfig *sbcfg, HttpRangeContainerBlock *c, const uint8_t *data, uint32_t len)
Definition: app-layer-htp-range.c:396
HttpRangeContainerBuffer::start
uint64_t start
Definition: app-layer-htp-range.h:39
HttpRangeContainerFile::error
bool error
Definition: app-layer-htp-range.h:82
rust.h
HttpRangeContainerBlock::toskip
uint64_t toskip
Definition: app-layer-htp-range.h:92
HttpRangeContainerFile::flags
uint16_t flags
Definition: app-layer-htp-range.h:80
HttpRangeContainerBlock
Definition: app-layer-htp-range.h:90
HttpRangeContainerFile
Definition: app-layer-htp-range.h:60
HttpRangeClose
File * HttpRangeClose(const StreamingBufferConfig *sbcfg, HttpRangeContainerBlock *c, uint16_t flags)
Definition: app-layer-htp-range.c:469
HttpRangeContainerFile::lastsize
uint64_t lastsize
Definition: app-layer-htp-range.h:72
HttpRangeContainerBlock
struct HttpRangeContainerBlock HttpRangeContainerBlock
HttpRangeContainerFile
struct HttpRangeContainerFile HttpRangeContainerFile
HttpRangeContainerBuffer
struct HttpRangeContainerBuffer HttpRangeContainerBuffer
HttpRangeContainerBlock::current
HttpRangeContainerBuffer * current
Definition: app-layer-htp-range.h:94
HttpRangeContainerBuffer::RB_ENTRY
RB_ENTRY(HttpRangeContainerBuffer) rb
SCTime_t
Definition: util-time.h:40
HttpRangeContainerFile::expire
uint32_t expire
Definition: app-layer-htp-range.h:66
HttpRangeContainerOpenFile
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)
HttpRangeContainerFile::key
uint8_t * key
Definition: app-layer-htp-range.h:62
HttpRangeContainerFile::hdata
THashData * hdata
Definition: app-layer-htp-range.h:68
HttpRangeContainerBlock::container
HttpRangeContainerFile * container
Definition: app-layer-htp-range.h:96
HttpRangeFreeBlock
void HttpRangeFreeBlock(HttpRangeContainerBlock *b)
Definition: app-layer-htp-range.c:613
HttpRangeContainerBuffer::offset
uint64_t offset
Definition: app-layer-htp-range.h:41
File_
Definition: util-file.h:79
HttpRangeContainerBufferCompare
int HttpRangeContainerBufferCompare(HttpRangeContainerBuffer *a, HttpRangeContainerBuffer *b)
Definition: app-layer-htp-range.c:45
THashData_
Definition: util-thash.h:85
RB_HEAD
RB_HEAD(HTTP_RANGES, HttpRangeContainerBuffer)
flags
uint8_t flags
Definition: decode-gre.h:0
HttpRangeContainersInit
void HttpRangeContainersInit(void)
Definition: app-layer-htp-range.c:150
suricata-common.h
HttpRangeContainerFile::totalsize
uint64_t totalsize
Definition: app-layer-htp-range.h:70
HttpRangeContainerFile::len
uint32_t len
Definition: app-layer-htp-range.h:64
StreamingBufferConfig_
Definition: util-streaming-buffer.h:66
HttpRangeContainerFile::fragment_tree
struct HTTP_RANGES fragment_tree
Definition: app-layer-htp-range.h:78
util-thash.h
HttpRangeContainerFile::sbcfg
const StreamingBufferConfig * sbcfg
Definition: app-layer-htp-range.h:74
RB_PROTOTYPE
RB_PROTOTYPE(HTTP_RANGES, HttpRangeContainerBuffer, rb, HttpRangeContainerBufferCompare)
HttpRangeContainerBlock::files
FileContainer * files
Definition: app-layer-htp-range.h:98
HttpRangeContainerBuffer
Definition: app-layer-htp-range.h:31