]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
app-layer: optimize many-tx case 2712/head
authorVictor Julien <victor@inliniac.net>
Fri, 12 May 2017 23:10:20 +0000 (01:10 +0200)
committerVictor Julien <victor@inliniac.net>
Mon, 15 May 2017 12:13:41 +0000 (14:13 +0200)
src/app-layer-parser.c

index 2eced2648667cd6afc1cb26c8fd6bffc28824d7d..9fe63e08eb6e2e8af21e70b78305e580044c084e 100644 (file)
@@ -147,6 +147,8 @@ struct AppLayerParserState_ {
      * unless we have the entire transaction. */
     uint64_t log_id;
 
+    uint64_t min_id;
+
     /* Used to store decoder events. */
     AppLayerDecoderEvents *decoder_events;
 };
@@ -748,7 +750,7 @@ uint64_t AppLayerTransactionGetActiveLogOnly(Flow *f, uint8_t flags)
 
     /* logger is disabled, return highest 'complete' tx id */
     uint64_t total_txs = AppLayerParserGetTxCnt(f, f->alstate);
-    uint64_t idx = AppLayerParserGetTransactionInspectId(f->alparser, flags);
+    uint64_t idx = f->alparser->min_id;
     int state_done_progress = AppLayerParserGetStateProgressCompletionStatus(f->alproto, flags);
     void *tx;
     int state_progress;
@@ -806,8 +808,22 @@ static void AppLayerParserTransactionsCleanup(Flow *f)
 
     uint64_t min = MIN(tx_id_ts, tx_id_tc);
     if (min > 0) {
+        uint64_t x = f->alparser->min_id;
+        for ( ; x < min - 1; x++) {
+            void *tx = AppLayerParserGetTx(f->proto, f->alproto, f->alstate, x);
+            if (tx != 0) {
+                SCLogDebug("while freeing %"PRIu64", also free TX at %"PRIu64, min - 1, x);
+                p->StateTransactionFree(f->alstate, x);
+            }
+        }
+
         SCLogDebug("freeing %"PRIu64" %p", min - 1, p->StateTransactionFree);
-        p->StateTransactionFree(f->alstate, min - 1);
+
+        if ((AppLayerParserGetTx(f->proto, f->alproto, f->alstate, min - 1))) {
+            p->StateTransactionFree(f->alstate, min - 1);
+        }
+        f->alparser->min_id = min - 1;
+        SCLogDebug("f->alparser->min_id %"PRIu64, f->alparser->min_id);
     }
 }