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 #include "app-layer-parser.h"
23 
24 #include "util-thash.h"
25 #include "rust-bindings.h"
26 
27 void HttpRangeContainersInit(void);
29 uint32_t HttpRangeContainersTimeoutHash(struct timeval *ts);
30 
31 // linked list of ranges : buffer with offset
32 typedef struct HttpRangeContainerBuffer {
33  /** red and black tree */
35  /** allocated buffer */
36  uint8_t *buffer;
37  /** length of buffer */
38  uint64_t buflen;
39  /** the start of the range (offset relative to the absolute beginning of the file) */
40  uint64_t start;
41  /** offset of bytes written in buffer (relative to the start of the range) */
42  uint64_t offset;
43  /** number of gaped bytes */
44  uint64_t gap;
46 
48 
51 
52 /** Item in hash table for a file in multiple ranges
53  * Thread-safety is ensured with the thread-safe hash table cf THashData
54  * The number of use is increased for each flow opening a new HttpRangeContainerBlock
55  * until it closes this HttpRangeContainerBlock
56  * The design goal is to have concurrency only on opening and closing a range request
57  * and have a lock-free data structure belonging to one Flow
58  * (see HttpRangeContainerBlock below)
59  * for every append in between (we suppose we have many appends per range request)
60  */
61 typedef struct HttpRangeContainerFile {
62  /** key for hashtable */
63  uint8_t *key;
64  /** key length */
65  uint32_t len;
66  /** expire time in epoch */
67  uint32_t expire;
68  /** pointer to hashtable data, for locking and use count */
70  /** total expected size of the file in ranges */
71  uint64_t totalsize;
72  /** size of the file after last sync */
73  uint64_t lastsize;
74  /** file container, with only one file */
76  /** red and black tree list of ranges which came out of order */
77  struct HTTP_RANGES fragment_tree;
78  /** file flags */
79  uint16_t flags;
80  /** error condition for this range. Its up to timeout handling to cleanup */
81  bool error;
83 
84 /** A structure representing a single range request :
85  * either skipping, buffering, or appending
86  * As this belongs to a flow, appending data to it is ensured to be thread-safe
87  * Only one block per file has the pointer to the container
88  */
89 typedef struct HttpRangeContainerBlock {
90  /** state where we skip content */
91  uint64_t toskip;
92  /** current out of order range to write into */
94  /** pointer to the main file container, where to directly append data */
96  /** file container we are owning for now */
99 
100 int HttpRangeAppendData(HttpRangeContainerBlock *c, const uint8_t *data, uint32_t len);
102 
103 // HttpRangeContainerBlock but trouble with headers inclusion order
104 HttpRangeContainerBlock *HttpRangeContainerOpenFile(const unsigned char *key, uint32_t keylen,
105  const Flow *f, const HTTPContentRange *cr, const StreamingBufferConfig *sbcfg,
106  const unsigned char *name, uint16_t name_len, uint16_t flags, const unsigned char *data,
107  uint32_t data_len);
108 
110 
111 #endif /* __APP_LAYER_HTP_RANGE_H__ */
HttpRangeContainerBuffer::gap
uint64_t gap
Definition: app-layer-htp-range.h:44
HttpRangeContainerBuffer::buffer
uint8_t * buffer
Definition: app-layer-htp-range.h:36
FileContainer_
Definition: util-file.h:110
len
uint8_t len
Definition: app-layer-dnp3.h:2
ts
uint64_t ts
Definition: source-erf-file.c:54
HttpRangeContainerBuffer::buflen
uint64_t buflen
Definition: app-layer-htp-range.h:38
HttpRangeContainersDestroy
void HttpRangeContainersDestroy(void)
Definition: app-layer-htp-range.c:185
HttpRangeContainerFile::files
FileContainer * files
Definition: app-layer-htp-range.h:75
Flow_
Flow data structure.
Definition: flow.h:353
HttpRangeContainerBuffer::start
uint64_t start
Definition: app-layer-htp-range.h:40
HttpRangeContainerFile::error
bool error
Definition: app-layer-htp-range.h:81
HttpRangeContainerBlock::toskip
uint64_t toskip
Definition: app-layer-htp-range.h:91
HttpRangeContainerFile::flags
uint16_t flags
Definition: app-layer-htp-range.h:79
HttpRangeContainerBlock
Definition: app-layer-htp-range.h:89
HttpRangeContainerFile
Definition: app-layer-htp-range.h:61
HttpRangeContainerFile::lastsize
uint64_t lastsize
Definition: app-layer-htp-range.h:73
HttpRangeContainerBlock
struct HttpRangeContainerBlock HttpRangeContainerBlock
HttpRangeContainerFile
struct HttpRangeContainerFile HttpRangeContainerFile
HttpRangeContainerBuffer
struct HttpRangeContainerBuffer HttpRangeContainerBuffer
HttpRangeContainerBlock::current
HttpRangeContainerBuffer * current
Definition: app-layer-htp-range.h:93
HttpRangeClose
File * HttpRangeClose(HttpRangeContainerBlock *c, uint16_t flags)
Definition: app-layer-htp-range.c:467
HttpRangeContainerBuffer::RB_ENTRY
RB_ENTRY(HttpRangeContainerBuffer) rb
app-layer-parser.h
HttpRangeContainerFile::expire
uint32_t expire
Definition: app-layer-htp-range.h:67
HttpRangeContainersTimeoutHash
uint32_t HttpRangeContainersTimeoutHash(struct timeval *ts)
Definition: app-layer-htp-range.c:190
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)
HttpRangeAppendData
int HttpRangeAppendData(HttpRangeContainerBlock *c, const uint8_t *data, uint32_t len)
Definition: app-layer-htp-range.c:396
HttpRangeContainerFile::key
uint8_t * key
Definition: app-layer-htp-range.h:63
HttpRangeContainerFile::hdata
THashData * hdata
Definition: app-layer-htp-range.h:69
HttpRangeContainerBlock::container
HttpRangeContainerFile * container
Definition: app-layer-htp-range.h:95
HttpRangeFreeBlock
void HttpRangeFreeBlock(HttpRangeContainerBlock *b)
Definition: app-layer-htp-range.c:605
HttpRangeContainerBuffer::offset
uint64_t offset
Definition: app-layer-htp-range.h:42
File_
Definition: util-file.h:75
HttpRangeContainerBufferCompare
int HttpRangeContainerBufferCompare(HttpRangeContainerBuffer *a, HttpRangeContainerBuffer *b)
Definition: app-layer-htp-range.c:45
THashData_
Definition: util-thash.h:86
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:71
HttpRangeContainerFile::len
uint32_t len
Definition: app-layer-htp-range.h:65
StreamingBufferConfig_
Definition: util-streaming-buffer.h:67
HttpRangeContainerFile::fragment_tree
struct HTTP_RANGES fragment_tree
Definition: app-layer-htp-range.h:77
util-thash.h
RB_PROTOTYPE
RB_PROTOTYPE(HTTP_RANGES, HttpRangeContainerBuffer, rb, HttpRangeContainerBufferCompare)
HttpRangeContainerBlock::files
FileContainer * files
Definition: app-layer-htp-range.h:97
HttpRangeContainerBuffer
Definition: app-layer-htp-range.h:32