]> git.ipfire.org Git - people/ms/suricata.git/commitdiff
app-layer: remove tx detect state setter and getter
authorJason Ish <jason.ish@oisf.net>
Wed, 10 Nov 2021 15:51:15 +0000 (09:51 -0600)
committerVictor Julien <vjulien@oisf.net>
Mon, 22 Nov 2021 09:24:05 +0000 (10:24 +0100)
Instead access detect state through AppLayerParserGetTxData.

src/app-layer-parser.c
src/app-layer-parser.h
src/detect-engine-state.c
src/detect.c

index cf80cc938775e2cc85586180e9a818bb5cbc68f3..106d8fb00eca3f0811a30bff0ac08ae7c6e0a1b3 100644 (file)
@@ -1144,23 +1144,6 @@ int AppLayerParserSupportsFiles(uint8_t ipproto, AppProto alproto)
     return FALSE;
 }
 
-DetectEngineState *AppLayerParserGetTxDetectState(uint8_t ipproto, AppProto alproto, void *tx)
-{
-    SCEnter();
-    AppLayerTxData *d = AppLayerParserGetTxData(ipproto, alproto, tx);
-    DetectEngineState *s = d->de_state;
-    SCReturnPtr(s, "DetectEngineState");
-}
-
-int AppLayerParserSetTxDetectState(const Flow *f,
-                                   void *tx, DetectEngineState *s)
-{
-    SCEnter();
-    AppLayerTxData *d = alp_ctx.ctxs[f->protomap][f->alproto].GetTxData(tx);
-    d->de_state = s;
-    SCReturnInt(0);
-}
-
 AppLayerTxData *AppLayerParserGetTxData(uint8_t ipproto, AppProto alproto, void *tx)
 {
     SCEnter();
index e8304ccfc7719799f7d2a201e8c884cd44668ec9..7624a2e769f0270277e0d3d90334e8f1805b90f0 100644 (file)
@@ -252,9 +252,6 @@ uint64_t AppLayerParserGetTransactionActive(const Flow *f, AppLayerParserState *
 uint8_t AppLayerParserGetFirstDataDir(uint8_t ipproto, AppProto alproto);
 
 int AppLayerParserSupportsFiles(uint8_t ipproto, AppProto alproto);
-int AppLayerParserHasTxDetectState(uint8_t ipproto, AppProto alproto, void *alstate);
-DetectEngineState *AppLayerParserGetTxDetectState(uint8_t ipproto, AppProto alproto, void *tx);
-int AppLayerParserSetTxDetectState(const Flow *f, void *tx, DetectEngineState *s);
 
 AppLayerTxData *AppLayerParserGetTxData(uint8_t ipproto, AppProto alproto, void *tx);
 void AppLayerParserApplyTxConfig(uint8_t ipproto, AppProto alproto,
index a5cf9696bc380ad14413ccd321f3b41c3b785f1f..d9f40bd6deea81bfc025dc755694531eae8f23ee 100644 (file)
@@ -222,19 +222,20 @@ void DetectRunStoreStateTx(
         uint32_t inspect_flags, uint8_t flow_flags,
         const uint16_t file_no_match)
 {
-    DetectEngineState *destate = AppLayerParserGetTxDetectState(f->proto, f->alproto, tx);
-    if (destate == NULL) {
-        destate = DetectEngineStateAlloc();
-        if (destate == NULL)
-            return;
-        if (AppLayerParserSetTxDetectState(f, tx, destate) < 0) {
-            DetectEngineStateFree(destate);
+    AppLayerTxData *tx_data = AppLayerParserGetTxData(f->proto, f->alproto, tx);
+    BUG_ON(tx_data == NULL);
+    if (tx_data == NULL) {
+        SCLogDebug("No TX data for %" PRIu64, tx_id);
+        return;
+    }
+    if (tx_data->de_state == NULL) {
+        tx_data->de_state = DetectEngineStateAlloc();
+        if (tx_data->de_state == NULL)
             return;
-        }
         SCLogDebug("destate created for %"PRIu64, tx_id);
     }
-    DeStateSignatureAppend(destate, s, inspect_flags, flow_flags);
-    StoreStateTxHandleFiles(sgh, f, destate, flow_flags, tx_id, file_no_match);
+    DeStateSignatureAppend(tx_data->de_state, s, inspect_flags, flow_flags);
+    StoreStateTxHandleFiles(sgh, f, tx_data->de_state, flow_flags, tx_id, file_no_match);
 
     SCLogDebug("Stored for TX %"PRIu64, tx_id);
 }
@@ -296,8 +297,11 @@ void DetectEngineStateResetTxs(Flow *f)
     for ( ; inspect_tx_id < total_txs; inspect_tx_id++) {
         void *inspect_tx = AppLayerParserGetTx(f->proto, f->alproto, alstate, inspect_tx_id);
         if (inspect_tx != NULL) {
-            DetectEngineState *tx_de_state = AppLayerParserGetTxDetectState(f->proto, f->alproto, inspect_tx);
-            ResetTxState(tx_de_state);
+            AppLayerTxData *txd = AppLayerParserGetTxData(f->proto, f->alproto, inspect_tx);
+            BUG_ON(txd == NULL);
+            if (txd) {
+                ResetTxState(txd->de_state);
+            }
         }
     }
 }
@@ -625,7 +629,9 @@ static int DeStateSigTest02(void)
     void *tx = AppLayerParserGetTx(IPPROTO_TCP, ALPROTO_HTTP1, f.alstate, 0);
     FAIL_IF_NULL(tx);
 
-    DetectEngineState *tx_de_state = AppLayerParserGetTxDetectState(IPPROTO_TCP, ALPROTO_HTTP1, tx);
+    AppLayerTxData *tx_data = AppLayerParserGetTxData(IPPROTO_TCP, ALPROTO_HTTP1, tx);
+    FAIL_IF_NULL(tx_data);
+    DetectEngineState *tx_de_state = tx_data->de_state;
     FAIL_IF_NULL(tx_de_state);
     FAIL_IF(tx_de_state->dir_state[0].cnt != 1);
     /* http_header(mpm): 5, uri: 3, method: 6, cookie: 7 */
index bb1be9d9a9f66609c3f571a1a40084ebed1dcbdd..8b6ff9c8ebea556ef7479d52e0dcc739ee92f425 100644 (file)
@@ -1235,7 +1235,7 @@ static DetectTransaction GetDetectTx(const uint8_t ipproto, const AppProto alpro
 
     const int tx_progress = AppLayerParserGetStateProgress(ipproto, alproto, tx_ptr, flow_flags);
     const int dir_int = (flow_flags & STREAM_TOSERVER) ? 0 : 1;
-    DetectEngineState *tx_de_state = AppLayerParserGetTxDetectState(ipproto, alproto, tx_ptr);
+    DetectEngineState *tx_de_state = txd->de_state;
     DetectEngineStateDirection *tx_dir_state = tx_de_state ? &tx_de_state->dir_state[dir_int] : NULL;
     uint64_t prefilter_flags = detect_flags & APP_LAYER_TX_PREFILTER_MASK;
     DEBUG_VALIDATE_BUG_ON(prefilter_flags & APP_LAYER_TX_RESERVED_FLAGS);