From: Russ Combs Date: Thu, 23 Oct 2014 12:48:52 +0000 (-0400) Subject: fixed rebuilt buffers count X-Git-Tag: 3.0.0-233~1339 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=48dcf6cf381155ead02e38e7e232ef364aacabd0;p=thirdparty%2Fsnort3.git fixed rebuilt buffers count --- diff --git a/ChangeLog b/ChangeLog index 7c8a2de52..78e075b79 100644 --- a/ChangeLog +++ b/ChangeLog @@ -13,7 +13,8 @@ -- doc tweaks -- fixed flow reset ordering of operations -- changed stream to not generate rebuilt packets when the splitter doesn't - reassemble (ie nhttp internal sections) + reassemble packets (ie nhttp internal buffers) +-- added rebuilt buffers count 125 -- discovered can't catch exceptions thrown from Lua to C++; need to diff --git a/src/stream/tcp/tcp_session.cc b/src/stream/tcp/tcp_session.cc index 56da585e4..0305434b1 100644 --- a/src/stream/tcp/tcp_session.cc +++ b/src/stream/tcp/tcp_session.cc @@ -118,7 +118,7 @@ struct TcpStats PegCount segs_released; PegCount segs_used; PegCount rebuilt_packets; - PegCount rebuilt_data; + PegCount rebuilt_buffers; PegCount overlaps; PegCount gaps; PegCount internalEvents; @@ -146,7 +146,7 @@ const char* tcp_pegs[] = "segs released", "segs used", "rebuilt packets", - "rebuilt data", + "rebuilt buffers", "overlaps", "gaps", "internal events", @@ -1944,11 +1944,15 @@ static int FlushStream( unsigned flushbuf_size = flushbuf_end - flushbuf; unsigned bytes_to_copy = getSegmentFlushSize(st, ss, toSeq, flushbuf_size); unsigned bytes_copied = 0; + assert(bytes_to_copy); STREAM5_DEBUG_WRAP(DebugMessage(DEBUG_STREAM_STATE, "Flushing %u bytes from %X\n", bytes_to_copy, ss->seq)); - if ( SEQ_EQ(ss->seq + bytes_to_copy, toSeq) ) + if ( + !ss->next || (bytes_to_copy < ss->size) || + SEQ_EQ(ss->seq + bytes_to_copy, toSeq) + ) flags |= PKT_PDU_TAIL; const StreamBuffer* sb = st->splitter->reassemble( @@ -1958,25 +1962,17 @@ static int FlushStream( if ( sb ) { - unsigned len = s5_pkt->max_dsize; - assert(sb->length <= len); - - if ( sb->length < len ) - len = sb->length; - s5_pkt->data = sb->data; - s5_pkt->dsize = len; + s5_pkt->dsize = sb->length; + // FIXIT-M flushbuf should be eliminated from this function + // since we are actually using the stream splitter buffer + flushbuf = (uint8_t*)s5_pkt->data; + + // ensure we stop here bytes_to_copy = bytes_copied; } - else if ( !bytes_copied ) - { - // FIXIT-P change stream splitter default reassemble - // to copy into external buffer to eliminate this special case - memcpy(flushbuf, ss->payload, bytes_to_copy); - } - else - assert(bytes_to_copy == bytes_copied); + assert(bytes_to_copy == bytes_copied); flushbuf += bytes_to_copy; bytes_flushed += bytes_to_copy; @@ -2020,7 +2016,6 @@ static int FlushStream( } STREAM5_DEBUG_WRAP(bytes_queued -= bytes_flushed;); - STREAM5_DEBUG_WRAP(DebugMessage(DEBUG_STREAM_STATE, "flushed %d bytes / %d segs on stream, " "%d still queued\n", @@ -2108,18 +2103,16 @@ static inline int _flush_to_seq ( const uint8_t* s5_pkt_end = s5_pkt->data + s5_pkt->max_dsize; flushed_bytes = FlushStream(p, st, stop_seq, (uint8_t *)s5_pkt->data, s5_pkt_end); - if (flushed_bytes == 0) - { - /* No more data... bail */ - break; - } - if ( !s5_pkt->dsize ) - tcpStats.rebuilt_data++; + if ( !flushed_bytes ) + break; /* No more data... bail */ + + else if ( !s5_pkt->dsize ) + tcpStats.rebuilt_buffers++; + else { ((TCPHdr *)s5_pkt->ptrs.tcph)->th_seq = htonl(st->seglist_next->seq); s5_pkt->packet_flags |= (PKT_REBUILT_STREAM|PKT_STREAM_EST); - s5_pkt->dsize = (uint16_t)flushed_bytes; if ((p->packet_flags & PKT_PDU_TAIL)) s5_pkt->packet_flags |= PKT_PDU_TAIL;