Commit Graph

38 Commits (ff882cd73f9eda2296435e6420fa43d5f05b19d9)

Author SHA1 Message Date
Victor Julien ff882cd73f streaming: add sbcfg to StreamingBufferClear 3 years ago
Victor Julien 6e5f35e0a0 streaming: add sbcfg to StreamingBufferFree 3 years ago
Victor Julien 96f29440cb streaming: add sbcfg to StreamingBufferAppendRaw 3 years ago
Victor Julien 30ee9165b5 streaming: add sbcfg to StreamingBufferAppend 3 years ago
Victor Julien 3b5deb4ec7 streaming: add sbcfg to StreamingBufferSlideToOffset 3 years ago
Victor Julien b9540d1073 streaming: add sbcfg to StreamingBufferInsertAt 3 years ago
Victor Julien 058dc02e81 streaming: add sbcfg to StreamingBufferAppendNoTrack 3 years ago
Victor Julien 76a256a8b1 streaming: remove inefficient buffer grow logic 3 years ago
Victor Julien 467234659d streaming: remove unused slide logic 3 years ago
Victor Julien 0b36bde9be streaming: remove unused config member 3 years ago
Victor Julien 2cfbefb6c6 streaming: make minimum region gap size configurable 3 years ago
Victor Julien f896f03b7b streaming: add max regions config option 3 years ago
Victor Julien 1dac2467c5 streaming: implement memory regions
In TCP, large gaps in the data could lead to an extremely poor utilization
of the streaming buffer memory. This was caused by the implementation using
a single continues memory allocation from the "stream offset" to the
current data. If a 100 byte segment was inserted for ISN + 20MiB, we would
allocate 20MiB, even if only 100 bytes were actually used.

This patch addresses the issue by implementing a list of memory regions.
The StreamingBuffer structure holds a static "main" region, which can be
extended in the form of a simple list of regions.

    [ main region ] [ gap ] [ aux region ]
    [ sbb ]                 [ sbb ]

On insert, find the correct region and see if the new data fits. If it
doesn't, see if we can expand the current region, or than we need to add
a new region. If expanding the current region means we overlap or get
too close to the next region, we merge them.

On sliding, we free any regions that slide out of window and consolidate
auxilary regions into main where needed.

Bug: #4580.
3 years ago
Victor Julien 989e5c7ba2 streaming/sbb: fix debug message 3 years ago
Victor Julien b31ffde6f4 output: remove error codes from output 3 years ago
Victor Julien e855fa0fe7 error: remove unused alloc error code 3 years ago
Victor Julien df7d8d96c9 streaming/buffer: set hard limit on buffer size
Don't allow the buffer to grow beyond 1GiB. Add a once per thread
warning if it does reach it.

Bug: #5703.
3 years ago
Victor Julien 39cf5b151a src: includes cleanup
Work towards making `suricata-common.h` only introduce system headers
and other things that are independent of complex internal Suricata
data structures.

Update files to compile after this.

Remove special DPDK handling for strlcpy and strlcat, as this caused
many compilation failures w/o including DPDK headers for all files.

Remove packet macros from decode.h and move them into their own file,
turn them into functions and rename them to match our function naming
policy.
3 years ago
Philippe Antoine 5bd19135b0 util: remove malloc from streaming buffer config
as it is unused
3 years ago
Victor Julien 5c76f787f9 streaming/buffer: add debug validation for 'impossible' condition 3 years ago
Victor Julien 3f375fd444 stream/buffer: remove redundant check 3 years ago
Victor Julien 6e90bf4739 streaming: remove unused 'auto slide' support
Add debug validation checks for "impossible" conditions.
3 years ago
Victor Julien 78f5e082f5 stream: fix stream pruning being too aggressive
Pruning of StreamBufferBlocks could remove blocks that fell entirely
after the target offset due to a logic error. This could lead to data
being evicted that was still meant to be processed in theapp-layer
parsers.

Bug: #4953.
4 years ago
Eric Leblond 0e70958e67 util/streaming: improve error handling
It differentiates memory error than regular ones.
4 years ago
Victor Julien be1baa8cab streaming/buffer: account sbb data size
When tracking data track the size of the blocks so that in case
of gaps we can still know how much data we hold.
4 years ago
Victor Julien b856caad94 common: use WARN_UNUSED macro 5 years ago
Victor Julien 2c050187a3 streaming/api: fix overlap check
In some cases a SBB could be seen as overlapping with the requested
offset, when it was in fact precisely before it. In some special cases
this could lead to the stream engine not progressing the 'raw' progress.
6 years ago
Victor Julien ff920472f6 stream-buffer: fix block search compare func
Sbb search function could return the wrong block due to an off by
one error.
7 years ago
Victor Julien c306c02f8f stream-buffer: fix streaming buffer size issue
It was using buffer size instead of the real usage of the buffer.
7 years ago
Victor Julien bbf1f78ffe streaming: keep track of tree 'head' 7 years ago
Victor Julien 450500e667 streaming: use rbtree for stream blocks
Switch StreamBufferBlocks implementation to use RBTREE instead of
a list. This makes inserts/removals and lookups a lot cheaper if
the number of data gaps is large.

Use separate compare functions for inserts and regular lookups.
Inserts care about the offset, while lookups care about the blocks
right edge as well.
7 years ago
Victor Julien 50a5b2e458 scan-build: fix warning in streaming buffer 8 years ago
Victor Julien afed6fe4a2 cleanup: remove all uint use 8 years ago
Victor Julien ab1200fbd7 compiler: more strict compiler warnings
Set flags by default:

    -Wmissing-prototypes
    -Wmissing-declarations
    -Wstrict-prototypes
    -Wwrite-strings
    -Wcast-align
    -Wbad-function-cast
    -Wformat-security
    -Wno-format-nonliteral
    -Wmissing-format-attribute
    -funsigned-char

Fix minor compiler warnings for these new flags on gcc and clang.
8 years ago
Victor Julien 3fa2e8689c streaming: remove BUG_ON and other improvements
Can be triggered by memory limits.
8 years ago
Victor Julien d789dc7e6d streaming: add blocklist
Add list of 'blocks'. This list contains offsets and lengths to
continuous data blocks. This is useful for TCP tracking where we
can have data gaps.

The blocks don't contain any data themselves, instead they contain
lenght and offsets. This way no extra copying is needed.

On inserting new data, existing blocks are expanded instead of
having multiple neighbouring blocks.
8 years ago
Victor Julien 40af9aad02 streaming: improve error handling
When memory allocations happened in HTTP body and general file
tracking, malloc/realloc errors (most likely in the form of memcap
reached conditions) could lead to an endless loop in the buffer
grow logic.

This patch implements proper error handling for all Append/Insert
functions for the streaming API, and it explicitly enables compiler
warnings if the results are ignored.
9 years ago
Victor Julien 81b2984c4e streaming: buffer API
Add a new API to store data from streaming sources, like HTTP body
processing or TCP data.

Currently most of the code uses a pattern of list of data chunks
(e.g. TcpSegment) that is reassembled into a large buffer on-demand.

The Streaming Buffer API changes the logic to store the data in
reassembled form from the start, with the segments/chunks pointing
to the reassembled data.

The main buffer storing the data slides forward, automatically or
manually. The *NoTrack calls allows for a segmentless mode of
operation.

This approach has two main advantages:

1. accessing the reassembled data is virtually cost-free
2. reduction of allocations and memory management
9 years ago