From 04b24cf24e670df92f3d24501aa90e79fc258e30 Mon Sep 17 00:00:00 2001 From: Victor Julien Date: Tue, 28 Feb 2017 12:44:02 +0100 Subject: [PATCH] stream: improve needs reassembly code --- src/flow-timeout.c | 4 ++-- src/stream-tcp-reassemble.c | 45 ++++++++++++++++--------------------- src/stream-tcp.h | 2 +- 3 files changed, 22 insertions(+), 29 deletions(-) diff --git a/src/flow-timeout.c b/src/flow-timeout.c index d7ccf8cf82..eb277295f4 100644 --- a/src/flow-timeout.c +++ b/src/flow-timeout.c @@ -304,8 +304,8 @@ int FlowForceReassemblyNeedReassembly(Flow *f, int *server, int *client) SCReturnInt(0); } - *client = StreamNeedsReassembly(ssn, 0); - *server = StreamNeedsReassembly(ssn, 1); + *client = StreamNeedsReassembly(ssn, STREAM_TOSERVER); + *server = StreamNeedsReassembly(ssn, STREAM_TOCLIENT); /* if state is not fully closed we assume that we haven't fully * inspected the app layer state yet */ diff --git a/src/stream-tcp-reassemble.c b/src/stream-tcp-reassemble.c index df208658ad..0366789f5b 100644 --- a/src/stream-tcp-reassemble.c +++ b/src/stream-tcp-reassemble.c @@ -762,14 +762,13 @@ static int StreamTcpReassembleRawCheckLimit(const TcpSession *ssn, /** * \brief see what if any work the TCP session still needs */ -int StreamNeedsReassembly(TcpSession *ssn, int direction) +int StreamNeedsReassembly(const TcpSession *ssn, uint8_t direction) { - TcpStream *stream = NULL; + const TcpStream *stream = NULL; #ifdef DEBUG char *dirstr = NULL; #endif - /* TODO use STREAM_TOCLIENT/STREAM_TOSERVER */ - if (direction == 0) { + if (direction == STREAM_TOSERVER) { stream = &ssn->client; #ifdef DEBUG dirstr = "client"; @@ -796,31 +795,25 @@ int StreamNeedsReassembly(TcpSession *ssn, int direction) use_raw = 0; } - if (stream->seg_list_tail != NULL) { - uint64_t right_edge = TCP_SEG_OFFSET(stream->seg_list_tail) + - TCP_SEG_LEN(stream->seg_list_tail); + uint64_t right_edge = STREAM_BASE_OFFSET(stream) + stream->sb.buf_offset; - SCLogDebug("%s: list %p app %"PRIu64" (use: %s), raw %"PRIu64" (use: %s). Stream right edge: %"PRIu64, - dirstr, - stream->seg_list, - STREAM_APP_PROGRESS(stream), use_app ? "yes" : "no", - STREAM_RAW_PROGRESS(stream), use_raw ? "yes" : "no", - right_edge); - - if (use_raw) { - if (right_edge > STREAM_RAW_PROGRESS(stream)) { - SCLogDebug("%s: STREAM_HAS_UNPROCESSED_SEGMENTS_NEED_ONLY_DETECTION", dirstr); - return STREAM_HAS_UNPROCESSED_SEGMENTS_NEED_ONLY_DETECTION; - } + SCLogDebug("%s: list %p app %"PRIu64" (use: %s), raw %"PRIu64" (use: %s). Stream right edge: %"PRIu64, + dirstr, + stream->seg_list, + STREAM_APP_PROGRESS(stream), use_app ? "yes" : "no", + STREAM_RAW_PROGRESS(stream), use_raw ? "yes" : "no", + right_edge); + if (use_raw) { + if (right_edge > STREAM_RAW_PROGRESS(stream)) { + SCLogDebug("%s: STREAM_HAS_UNPROCESSED_SEGMENTS_NEED_ONLY_DETECTION", dirstr); + return STREAM_HAS_UNPROCESSED_SEGMENTS_NEED_ONLY_DETECTION; } - if (use_app) { - if (right_edge > STREAM_APP_PROGRESS(stream)) { - SCLogDebug("%s: STREAM_HAS_UNPROCESSED_SEGMENTS_NEED_ONLY_DETECTION", dirstr); - return STREAM_HAS_UNPROCESSED_SEGMENTS_NEED_ONLY_DETECTION; - } + } + if (use_app) { + if (right_edge > STREAM_APP_PROGRESS(stream)) { + SCLogDebug("%s: STREAM_HAS_UNPROCESSED_SEGMENTS_NEED_ONLY_DETECTION", dirstr); + return STREAM_HAS_UNPROCESSED_SEGMENTS_NEED_ONLY_DETECTION; } - } else { - SCLogDebug("%s: no list", dirstr); } SCLogDebug("%s: STREAM_HAS_UNPROCESSED_SEGMENTS_NONE", dirstr); diff --git a/src/stream-tcp.h b/src/stream-tcp.h index 11db4a0c82..86646fbed9 100644 --- a/src/stream-tcp.h +++ b/src/stream-tcp.h @@ -187,7 +187,7 @@ enum { }; TmEcode StreamTcp (ThreadVars *, Packet *, void *, PacketQueue *, PacketQueue *); -int StreamNeedsReassembly(TcpSession *ssn, int direction); +int StreamNeedsReassembly(const TcpSession *ssn, uint8_t direction); TmEcode StreamTcpThreadInit(ThreadVars *, void *, void **); TmEcode StreamTcpThreadDeinit(ThreadVars *tv, void *data); void StreamTcpRegisterTests (void);