]> git.ipfire.org Git - thirdparty/snort3.git/commitdiff
fixed rebuilt buffers count
authorRuss Combs <rucombs@cisco.com>
Thu, 23 Oct 2014 12:48:52 +0000 (08:48 -0400)
committerRuss Combs <rucombs@cisco.com>
Thu, 23 Oct 2014 12:48:52 +0000 (08:48 -0400)
ChangeLog
src/stream/tcp/tcp_session.cc

index 7c8a2de52c5560096d83f1cdb7445f6818becc30..78e075b793a8eff199be7e03b189f6351dd8a9e2 100644 (file)
--- 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
index 56da585e4eca270512ab36f232c395fd2cc584b6..0305434b135552747249a4d444af83e370a2afc7 100644 (file)
@@ -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;