]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
app-layer: handle unidirectional transactions
authorJason Ish <jason.ish@oisf.net>
Tue, 18 Aug 2020 16:39:42 +0000 (10:39 -0600)
committerVictor Julien <victor@inliniac.net>
Wed, 7 Oct 2020 10:06:23 +0000 (12:06 +0200)
(cherry picked from commit 60ebc27c4eb755800e6d3f4ec1a5d55a5230a214)

src/app-layer-parser.c

index 31d475880b4083228c70bda28ea26be2d6124d75..dc3d13be86b92651b6fc901a91aecf5ff9d1d45f 100644 (file)
@@ -932,6 +932,8 @@ void AppLayerParserTransactionsCleanup(Flow *f)
     uint64_t new_min = min;
     SCLogDebug("start min %"PRIu64, min);
     bool skipped = false;
+    const bool is_unidir = AppLayerParserGetOptionFlags(f->protomap, f->alproto)
+            & APP_LAYER_PARSER_OPT_UNIDIR_TXS;
 
     while (1) {
         AppLayerGetTxIterTuple ires = IterFunc(ipproto, alproto, alstate, i, total_txs, &state);
@@ -955,6 +957,7 @@ void AppLayerParserTransactionsCleanup(Flow *f)
             skipped = true;
             goto next;
         }
+        bool inspected = false;
         if (has_tx_detect_flags) {
             if (f->sgh_toserver != NULL) {
                 uint64_t detect_flags_ts = AppLayerParserGetTxDetectFlags(ipproto, alproto, tx, STREAM_TOSERVER);
@@ -962,7 +965,8 @@ void AppLayerParserTransactionsCleanup(Flow *f)
                     SCLogDebug("%p/%"PRIu64" skipping: TS inspect not done: ts:%"PRIx64,
                             tx, i, detect_flags_ts);
                     skipped = true;
-                    goto next;
+                } else {
+                    inspected = true;
                 }
             }
             if (f->sgh_toclient != NULL) {
@@ -971,10 +975,26 @@ void AppLayerParserTransactionsCleanup(Flow *f)
                     SCLogDebug("%p/%"PRIu64" skipping: TC inspect not done: tc:%"PRIx64,
                             tx, i, detect_flags_tc);
                     skipped = true;
-                    goto next;
+                } else {
+                    inspected = true;
                 }
             }
         }
+
+        /* If not a unidirectional transaction both sides are required to have
+         * been inspected. */
+        if (!is_unidir && skipped) {
+            goto next;
+        }
+
+        /* If this is a unidirectional transaction require only one side to be
+         * inspected, which the inspected flag tells us. This is also guarded
+         * with skip to limit this check to transactions that actually had the
+         * tx inspected flag checked. */
+        if (is_unidir && skipped && !inspected) {
+            goto next;
+        }
+
         if (logger_expectation != 0) {
             LoggerId tx_logged = AppLayerParserGetTxLogged(f, alstate, tx);
             if (tx_logged != logger_expectation) {