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);
28 uint32_t HttpRangeContainersTimeoutHash(struct timeval *ts);
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  /** file container, with only one file */
75  /** red and black tree list of ranges which came out of order */
76  struct HTTP_RANGES fragment_tree;
77  /** file flags */
78  uint16_t flags;
79  /** error condition for this range. Its up to timeout handling to cleanup */
80  bool error;
82 
83 /** A structure representing a single range request :
84  * either skipping, buffering, or appending
85  * As this belongs to a flow, appending data to it is ensured to be thread-safe
86  * Only one block per file has the pointer to the container
87  */
88 typedef struct HttpRangeContainerBlock {
89  /** state where we skip content */
90  uint64_t toskip;
91  /** current out of order range to write into */
93  /** pointer to the main file container, where to directly append data */
95  /** file container we are owning for now */
98 
99 int HttpRangeAppendData(HttpRangeContainerBlock *c, const uint8_t *data, uint32_t len);
101 
102 // HttpRangeContainerBlock but trouble with headers inclusion order
103 HttpRangeContainerBlock *HttpRangeContainerOpenFile(const unsigned char *key, uint32_t keylen,
104  const Flow *f, const HTTPContentRange *cr, const StreamingBufferConfig *sbcfg,
105  const unsigned char *name, uint16_t name_len, uint16_t flags, const unsigned char *data,
106  uint32_t data_len);
107 
109 
110 #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:110
len
uint8_t len
Definition: app-layer-dnp3.h:2
ts
uint64_t ts
Definition: source-erf-file.c:55
HttpRangeContainerBuffer::buflen
uint64_t buflen
Definition: app-layer-htp-range.h:37
HttpRangeContainersDestroy
void HttpRangeContainersDestroy(void)
Definition: app-layer-htp-range.c:185
HttpRangeContainerFile::files
FileContainer * files
Definition: app-layer-htp-range.h:74
Flow_
Flow data structure.
Definition: flow.h:353
HttpRangeContainerBuffer::start
uint64_t start
Definition: app-layer-htp-range.h:39
HttpRangeContainerFile::error
bool error
Definition: app-layer-htp-range.h:80
rust.h
HttpRangeContainerBlock::toskip
uint64_t toskip
Definition: app-layer-htp-range.h:90
HttpRangeContainerFile::flags
uint16_t flags
Definition: app-layer-htp-range.h:78
HttpRangeContainerBlock
Definition: app-layer-htp-range.h:88
HttpRangeContainerFile
Definition: app-layer-htp-range.h:60
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:92
HttpRangeClose
File * HttpRangeClose(HttpRangeContainerBlock *c, uint16_t flags)
Definition: app-layer-htp-range.c:467
HttpRangeContainerBuffer::RB_ENTRY
RB_ENTRY(HttpRangeContainerBuffer) rb
HttpRangeContainerFile::expire
uint32_t expire
Definition: app-layer-htp-range.h:66
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:62
HttpRangeContainerFile::hdata
THashData * hdata
Definition: app-layer-htp-range.h:68
HttpRangeContainerBlock::container
HttpRangeContainerFile * container
Definition: app-layer-htp-range.h:94
HttpRangeFreeBlock
void HttpRangeFreeBlock(HttpRangeContainerBlock *b)
Definition: app-layer-htp-range.c:611
HttpRangeContainerBuffer::offset
uint64_t offset
Definition: app-layer-htp-range.h:41
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:84
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:64
HttpRangeContainerFile::fragment_tree
struct HTTP_RANGES fragment_tree
Definition: app-layer-htp-range.h:76
util-thash.h
RB_PROTOTYPE
RB_PROTOTYPE(HTTP_RANGES, HttpRangeContainerBuffer, rb, HttpRangeContainerBufferCompare)
HttpRangeContainerBlock::files
FileContainer * files
Definition: app-layer-htp-range.h:96
HttpRangeContainerBuffer
Definition: app-layer-htp-range.h:31