stream: reduce streaming buffer internals use

pull/8406/head
Victor Julien 3 years ago
parent a24d7dc45c
commit 61e47ad6f5

@ -816,7 +816,7 @@ static inline uint64_t GetLeftEdge(Flow *f, TcpSession *ssn, TcpStream *stream)
left_edge = app_le;
SCLogDebug("left_edge %" PRIu64 ", using only app:%" PRIu64, left_edge, app_le);
} else {
left_edge = STREAM_BASE_OFFSET(stream) + stream->sb.buf_offset;
left_edge = StreamingBufferGetConsecutiveDataRightEdge(&stream->sb);
SCLogDebug("no app & raw: left_edge %"PRIu64" (full stream)", left_edge);
}

@ -100,8 +100,8 @@ RB_PROTOTYPE(TCPSEG, TcpSegment, rb, TcpSegmentCompare);
* Only use if STREAM_HAS_SEEN_DATA is true. */
#define STREAM_SEQ_RIGHT_EDGE(stream) (stream)->segs_right_edge
#define STREAM_RIGHT_EDGE(stream) (STREAM_BASE_OFFSET((stream)) + (STREAM_SEQ_RIGHT_EDGE((stream)) - (stream)->base_seq))
/* return true if we have seen data segments. */
#define STREAM_HAS_SEEN_DATA(stream) (!RB_EMPTY(&(stream)->sb.sbb_tree) || (stream)->sb.stream_offset || (stream)->sb.buf_offset)
/* return true if we have seen data. */
#define STREAM_HAS_SEEN_DATA(stream) StreamingBufferHasData(&(stream)->sb)
typedef struct TcpStream_ {
uint16_t flags:12; /**< Flag specific to the stream e.g. Timestamp */

@ -413,7 +413,7 @@ uint64_t StreamTcpGetAcked(const TcpStream *stream)
uint64_t StreamTcpGetUsable(const TcpStream *stream, const bool eof)
{
uint64_t right_edge = STREAM_BASE_OFFSET(stream) + stream->sb.buf_offset;
uint64_t right_edge = StreamingBufferGetConsecutiveDataRightEdge(&stream->sb);
if (!eof && StreamTcpInlineMode() == FALSE) {
right_edge = MIN(GetAbsLastAck(stream), right_edge);
}
@ -899,7 +899,6 @@ uint8_t StreamNeedsReassembly(const TcpSession *ssn, uint8_t direction)
dirstr = "server";
#endif
}
int use_app = 1;
int use_raw = 1;
@ -913,7 +912,7 @@ uint8_t StreamNeedsReassembly(const TcpSession *ssn, uint8_t direction)
use_raw = 0;
}
uint64_t right_edge = STREAM_BASE_OFFSET(stream) + stream->sb.buf_offset;
const uint64_t right_edge = StreamingBufferGetConsecutiveDataRightEdge(&stream->sb);
SCLogDebug("%s: app %"PRIu64" (use: %s), raw %"PRIu64" (use: %s). Stream right edge: %"PRIu64,
dirstr,
@ -1514,7 +1513,7 @@ void StreamReassembleRawUpdateProgress(TcpSession *ssn, Packet *p, uint64_t prog
/* app is dead */
} else if (progress == 0) {
uint64_t tcp_window = stream->window;
uint64_t stream_right_edge = STREAM_BASE_OFFSET(stream) + stream->sb.buf_offset;
const uint64_t stream_right_edge = StreamingBufferGetConsecutiveDataRightEdge(&stream->sb);
if (tcp_window < stream_right_edge) {
uint64_t new_raw = stream_right_edge - tcp_window;
if (new_raw > STREAM_RAW_PROGRESS(stream)) {

@ -323,9 +323,9 @@ static int FileMagicSize(void)
uint64_t FileDataSize(const File *file)
{
if (file != NULL && file->sb != NULL) {
SCLogDebug("returning %"PRIu64,
file->sb->stream_offset + file->sb->buf_offset);
return file->sb->stream_offset + file->sb->buf_offset;
const uint64_t size = StreamingBufferGetConsecutiveDataRightEdge(file->sb);
SCLogDebug("returning %" PRIu64, size);
return size;
}
SCLogDebug("returning 0 (default)");
return 0;
@ -392,12 +392,13 @@ static int FilePruneFile(File *file)
/* if file has inspect window and min size set, we
* do some house keeping here */
if (file->inspect_window != 0 && file->inspect_min_size != 0) {
const uint64_t file_offset = StreamingBufferGetOffset(file->sb);
uint32_t window = file->inspect_window;
if (file->sb->stream_offset == 0)
if (file_offset == 0)
window = MAX(window, file->inspect_min_size);
uint64_t file_size = FileDataSize(file);
uint64_t data_size = file_size - file->sb->stream_offset;
uint64_t data_size = file_size - file_offset;
SCLogDebug("window %"PRIu32", file_size %"PRIu64", data_size %"PRIu64,
window, file_size, data_size);

@ -106,6 +106,21 @@ typedef struct StreamingBuffer_ {
#endif
} StreamingBuffer;
static inline bool StreamingBufferHasData(const StreamingBuffer *sb)
{
return (sb->stream_offset || sb->buf_offset || !RB_EMPTY(&sb->sbb_tree));
}
static inline uint64_t StreamingBufferGetConsecutiveDataRightEdge(const StreamingBuffer *sb)
{
return sb->stream_offset + sb->buf_offset;
}
static inline uint64_t StreamingBufferGetOffset(const StreamingBuffer *sb)
{
return sb->stream_offset;
}
#ifndef DEBUG
#define STREAMING_BUFFER_INITIALIZER(cfg) \
{ \

Loading…
Cancel
Save