]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
detect-state: implement tx state reset for reload 1375/head
authorVictor Julien <victor@inliniac.net>
Tue, 10 Mar 2015 16:41:03 +0000 (17:41 +0100)
committerVictor Julien <victor@inliniac.net>
Mon, 16 Mar 2015 14:36:34 +0000 (15:36 +0100)
In case of Detect Reload, we need to reset active tx' state.

src/detect-engine-state.c
src/detect-engine-state.h
src/detect.c

index c19e398f49a212d670e0487c43d4a051122f5879..6ff91afccd59a75e2eaaed24f60840e3f5818f84 100644 (file)
@@ -984,6 +984,45 @@ void DetectEngineStateReset(DetectEngineStateFlow *state, uint8_t direction)
     return;
 }
 
+/** \brief Reset de state for active tx'
+ *  To be used on detect engine reload.
+ *  \param f write LOCKED flow
+ */
+void DetectEngineStateResetTxs(Flow *f)
+{
+    if (AppLayerParserProtocolSupportsTxs(f->proto, f->alproto)) {
+        void *alstate = FlowGetAppState(f);
+        if (!StateIsValid(f->alproto, alstate)) {
+            return;
+        }
+
+        uint64_t inspect_ts = AppLayerParserGetTransactionInspectId(f->alparser, STREAM_TOCLIENT);
+        uint64_t inspect_tc = AppLayerParserGetTransactionInspectId(f->alparser, STREAM_TOSERVER);
+
+        uint64_t inspect_tx_id = MIN(inspect_ts, inspect_tc);
+
+        uint64_t total_txs = AppLayerParserGetTxCnt(f->proto, f->alproto, alstate);
+
+        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);
+                if (tx_de_state == NULL) {
+                    continue;
+                }
+
+                tx_de_state->dir_state[0].cnt = 0;
+                tx_de_state->dir_state[0].filestore_cnt = 0;
+                tx_de_state->dir_state[0].flags = 0;
+
+                tx_de_state->dir_state[1].cnt = 0;
+                tx_de_state->dir_state[1].filestore_cnt = 0;
+                tx_de_state->dir_state[1].flags = 0;
+            }
+        }
+    }
+}
+
 /** \brief get string for match enum */
 const char *DeStateMatchResultToString(DeStateMatchResult res)
 {
index 9a5b7ebab16b3fa824bab839f0d593653b71cb1c..464f7180fd1cb50f4f930fe941f84877976e2d23 100644 (file)
@@ -231,6 +231,8 @@ void DeStateUpdateInspectTransactionId(Flow *f, uint8_t direction);
  */
 void DetectEngineStateReset(DetectEngineStateFlow *state, uint8_t direction);
 
+void DetectEngineStateResetTxs(Flow *f);
+
 void DeStateRegisterTests(void);
 
 #endif /* __DETECT_ENGINE_STATE_H__ */
index 98e3959ce9fa28f56345098a2d96cadc7fdb1f83..2d5ff982242502b9e8800ad2fd822ab9edec31c5 100644 (file)
@@ -1201,6 +1201,7 @@ int SigMatchSignatures(ThreadVars *th_v, DetectEngineCtx *de_ctx, DetectEngineTh
 
                 DetectEngineStateReset(pflow->de_state,
                         (STREAM_TOSERVER|STREAM_TOCLIENT));
+                DetectEngineStateResetTxs(pflow);
             }
 
             /* set the iponly stuff */