]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
app-layer: specify direction in tx cleanup
authorVictor Julien <vjulien@oisf.net>
Fri, 19 Aug 2022 09:08:04 +0000 (11:08 +0200)
committerVictor Julien <vjulien@oisf.net>
Fri, 30 Sep 2022 07:46:05 +0000 (09:46 +0200)
In preparation of per tx files storage.

src/app-layer-htp.c
src/app-layer-ike.c
src/app-layer-parser.c
src/app-layer-parser.h
src/app-layer-rfb.c
src/app-layer-smb.c
src/flow-worker.c
src/tests/fuzz/fuzz_applayerparserparse.c

index a8eac56eff5385ebde2d35a6e037c0eaafa3f41d..78c6abd04a9474e406a82325a9811a3bf8f6212e 100644 (file)
@@ -6792,7 +6792,7 @@ static int HTPParserTest25(void)
             NULL, alp_tctx, f, ALPROTO_HTTP1, STREAM_TOCLIENT, (uint8_t *)str, strlen(str));
     FAIL_IF_NOT(r == 0);
 
-    AppLayerParserTransactionsCleanup(f);
+    AppLayerParserTransactionsCleanup(f, STREAM_TOCLIENT);
 
     uint64_t ret[4];
     UTHAppLayerParserStateGetIds(f->alparser, &ret[0], &ret[1], &ret[2], &ret[3]);
@@ -6804,7 +6804,7 @@ static int HTPParserTest25(void)
     r = AppLayerParserParse(NULL, alp_tctx, f, ALPROTO_HTTP1, STREAM_TOSERVER | STREAM_EOF,
             (uint8_t *)str, strlen(str));
     FAIL_IF_NOT(r == 0);
-    AppLayerParserTransactionsCleanup(f);
+    AppLayerParserTransactionsCleanup(f, STREAM_TOCLIENT);
 
     UTHAppLayerParserStateGetIds(f->alparser, &ret[0], &ret[1], &ret[2], &ret[3]);
     FAIL_IF_NOT(ret[0] == 8); // inspect_id[0] not updated by ..Cleanup() until full tx is done
@@ -6815,7 +6815,7 @@ static int HTPParserTest25(void)
     r = AppLayerParserParse(NULL, alp_tctx, f, ALPROTO_HTTP1, STREAM_TOCLIENT | STREAM_EOF,
             (uint8_t *)str, strlen(str));
     FAIL_IF_NOT(r == 0);
-    AppLayerParserTransactionsCleanup(f);
+    AppLayerParserTransactionsCleanup(f, STREAM_TOCLIENT);
 
     UTHAppLayerParserStateGetIds(f->alparser, &ret[0], &ret[1], &ret[2], &ret[3]);
     FAIL_IF_NOT(ret[0] == 9); // inspect_id[0]
index 110db2bd244427a2ed7b491c91a45815a1de66cc..852d215824da588819e3d2341079f63b0f48d5e6 100644 (file)
@@ -166,7 +166,7 @@ static int IkeParserTest(void)
             sizeof(encrypted));
     FAIL_IF_NOT(r == 0);
 
-    AppLayerParserTransactionsCleanup(&f);
+    AppLayerParserTransactionsCleanup(&f, STREAM_TOCLIENT);
     UTHAppLayerParserStateGetIds(f.alparser, &ret[0], &ret[1], &ret[2], &ret[3]);
     FAIL_IF_NOT(ret[0] == 5); // inspect_id[0]
     FAIL_IF_NOT(ret[1] == 5); // inspect_id[1]
index 6843b22ff885f2db535be9e7d2284985cf09317d..2ace163b10e88a9f192477400082eefd9c44c110 100644 (file)
@@ -926,7 +926,7 @@ extern bool g_filedata_logger_enabled;
 /**
  * \brief remove obsolete (inspected and logged) transactions
  */
-void AppLayerParserTransactionsCleanup(Flow *f)
+void AppLayerParserTransactionsCleanup(Flow *f, const uint8_t pkt_dir)
 {
     SCEnter();
     DEBUG_ASSERT_FLOW_LOCKED(f);
index aede85bf80464f497f93f3708c3dd26eb602177b..fb9f6510bda24138befc0c43b581daff0bcb4a17 100644 (file)
@@ -298,7 +298,7 @@ void AppLayerParserStreamTruncated(uint8_t ipproto, AppProto alproto, void *alst
 AppLayerParserState *AppLayerParserStateAlloc(void);
 void AppLayerParserStateFree(AppLayerParserState *pstate);
 
-void AppLayerParserTransactionsCleanup(Flow *f);
+void AppLayerParserTransactionsCleanup(Flow *f, const uint8_t pkt_dir);
 
 #ifdef DEBUG
 void AppLayerParserStatePrintDetails(AppLayerParserState *pstate);
index c070e37fa6d4640f5a835821bf42563f105b5512..49f67b6d0a92da5f66c370937cfa90213df49083 100644 (file)
@@ -132,14 +132,14 @@ static int RFBParserTest(void)
             NULL, alp_tctx, f, ALPROTO_RFB, STREAM_TOCLIENT, (uint8_t *)server_init, sizeof(server_init));
     FAIL_IF_NOT(r == 0);
 
-    AppLayerParserTransactionsCleanup(f);
+    AppLayerParserTransactionsCleanup(f, STREAM_TOCLIENT);
     UTHAppLayerParserStateGetIds(f->alparser, &ret[0], &ret[1], &ret[2], &ret[3]);
     FAIL_IF_NOT(ret[0] == 1); // inspect_id[0]
     FAIL_IF_NOT(ret[1] == 1); // inspect_id[1]
     FAIL_IF_NOT(ret[2] == 1); // log_id
     FAIL_IF_NOT(ret[3] == 1); // min_id
 
-    AppLayerParserTransactionsCleanup(f);
+    AppLayerParserTransactionsCleanup(f, STREAM_TOCLIENT);
     AppLayerParserThreadCtxFree(alp_tctx);
     StreamTcpFreeConfig(true);
     UTHFreeFlow(f);
index 776e1c2381eeb3d3f02c882469696e05d88ab7fd..a1c3afaaca4e66fa7cfbd82318b6e66f40af0bde 100644 (file)
@@ -111,7 +111,7 @@ static int SMBParserTxCleanupTest(void)
     FAIL_IF_NOT(r == 0);
     req_str[28]++;
 
-    AppLayerParserTransactionsCleanup(f);
+    AppLayerParserTransactionsCleanup(f, STREAM_TOSERVER);
     UTHAppLayerParserStateGetIds(f->alparser, &ret[0], &ret[1], &ret[2], &ret[3]);
     FAIL_IF_NOT(ret[0] == 0); // inspect_id[0]
     FAIL_IF_NOT(ret[1] == 0); // inspect_id[1]
@@ -157,7 +157,7 @@ static int SMBParserTxCleanupTest(void)
     r = AppLayerParserParse(NULL, alp_tctx, f, ALPROTO_SMB,
                                 STREAM_TOCLIENT, (uint8_t *)resp_str, sizeof(resp_str));
     FAIL_IF_NOT(r == 0);
-    AppLayerParserTransactionsCleanup(f);
+    AppLayerParserTransactionsCleanup(f, STREAM_TOCLIENT);
 
     UTHAppLayerParserStateGetIds(f->alparser, &ret[0], &ret[1], &ret[2], &ret[3]);
     FAIL_IF_NOT(ret[0] == 2); // inspect_id[0]
@@ -169,7 +169,7 @@ static int SMBParserTxCleanupTest(void)
     r = AppLayerParserParse(NULL, alp_tctx, f, ALPROTO_SMB,
                                 STREAM_TOCLIENT, (uint8_t *)resp_str, sizeof(resp_str));
     FAIL_IF_NOT(r == 0);
-    AppLayerParserTransactionsCleanup(f);
+    AppLayerParserTransactionsCleanup(f, STREAM_TOCLIENT);
 
     UTHAppLayerParserStateGetIds(f->alparser, &ret[0], &ret[1], &ret[2], &ret[3]);
     FAIL_IF_NOT(ret[0] == 8); // inspect_id[0]
@@ -181,7 +181,7 @@ static int SMBParserTxCleanupTest(void)
     r = AppLayerParserParse(NULL, alp_tctx, f, ALPROTO_SMB,
                                 STREAM_TOSERVER | STREAM_EOF, (uint8_t *)req_str, sizeof(req_str));
     FAIL_IF_NOT(r == 0);
-    AppLayerParserTransactionsCleanup(f);
+    AppLayerParserTransactionsCleanup(f, STREAM_TOSERVER);
 
     UTHAppLayerParserStateGetIds(f->alparser, &ret[0], &ret[1], &ret[2], &ret[3]);
     FAIL_IF_NOT(ret[0] == 8); // inspect_id[0] not updated by ..Cleanup() until full tx is done
@@ -193,7 +193,7 @@ static int SMBParserTxCleanupTest(void)
     r = AppLayerParserParse(NULL, alp_tctx, f, ALPROTO_SMB,
                                 STREAM_TOCLIENT | STREAM_EOF, (uint8_t *)resp_str, sizeof(resp_str));
     FAIL_IF_NOT(r == 0);
-    AppLayerParserTransactionsCleanup(f);
+    AppLayerParserTransactionsCleanup(f, STREAM_TOCLIENT);
 
     UTHAppLayerParserStateGetIds(f->alparser, &ret[0], &ret[1], &ret[2], &ret[3]);
     FAIL_IF_NOT(ret[0] == 9); // inspect_id[0]
index 66fa73baad39aebec06d73afd2f5269f9692275e..b5a8895aa8a9a2c63309158a8ab4f4624fa1a369 100644 (file)
@@ -449,7 +449,7 @@ static void FlowWorkerFlowTimeout(ThreadVars *tv, Packet *p, FlowWorkerThreadDat
     FLOWWORKER_PROFILING_END(p, PROFILE_FLOWWORKER_TCPPRUNE);
 
     /* run tx cleanup last */
-    AppLayerParserTransactionsCleanup(p->flow);
+    AppLayerParserTransactionsCleanup(p->flow, STREAM_FLAGS_FOR_PACKET(p));
 
     FlowDeReference(&p->flow);
     /* flow is unlocked later in FlowFinish() */
@@ -592,7 +592,7 @@ static TmEcode FlowWorker(ThreadVars *tv, Packet *p, void *data)
         }
 
         /* run tx cleanup last */
-        AppLayerParserTransactionsCleanup(p->flow);
+        AppLayerParserTransactionsCleanup(p->flow, STREAM_FLAGS_FOR_PACKET(p));
 
         Flow *f = p->flow;
         FlowDeReference(&p->flow);
index a7c7653673de4a3802d9f8ee290c74b499376c3a..6da5b78b1c4314ec713c89fc8e109df16075d511 100644 (file)
@@ -169,7 +169,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
                 break;
             }
 
-            AppLayerParserTransactionsCleanup(f);
+            AppLayerParserTransactionsCleanup(f, flags & (STREAM_TOSERVER | STREAM_TOCLIENT));
         }
         alsize -= alnext - albuffer + 4;
         albuffer = alnext + 4;