]> git.ipfire.org Git - people/ms/suricata.git/commitdiff
dcerpc: implement tx free function
authorVictor Julien <victor@inliniac.net>
Sat, 19 Sep 2020 18:57:35 +0000 (20:57 +0200)
committerVictor Julien <victor@inliniac.net>
Fri, 25 Sep 2020 05:24:59 +0000 (07:24 +0200)
rust/src/dcerpc/dcerpc.rs

index fdf5c8e163040e1c160b9e8cab7bac6704043a7f..a08dab6b39446166c6f3612ede795f3a02b8e1ab 100644 (file)
@@ -349,6 +349,27 @@ impl DCERPCState {
         tx
     }
 
+    pub fn free_tx(&mut self, tx_id: u64) {
+        SCLogDebug!("Freeing TX with ID {} TX.ID {}", tx_id, tx_id+1);
+        let len = self.transactions.len();
+        let mut found = false;
+        let mut index = 0;
+        for i in 0..len {
+            let tx = &self.transactions[i];
+            if tx.id as u64 == tx_id { //+ 1 {
+                found = true;
+                index = i;
+                SCLogDebug!("tx {} progress {}/{}", tx.id, tx.req_done, tx.resp_done);
+                break;
+            }
+        }
+        if found {
+            SCLogDebug!("freeing TX with ID {} TX.ID {} at index {} left: {} max id: {}",
+                            tx_id, tx_id+1, index, self.transactions.len(), self.tx_id);
+            self.transactions.remove(index);
+        }
+    }
+
     fn get_hdr_drep_0(&self) -> u8 {
         if let Some(ref hdr) = &self.header {
             return hdr.packed_drep[0];
@@ -1155,8 +1176,10 @@ pub unsafe extern "C" fn rs_dcerpc_state_free(state: *mut std::os::raw::c_void)
 }
 
 #[no_mangle]
-pub extern "C" fn rs_dcerpc_state_transaction_free(_state: *mut std::os::raw::c_void, _tx_id: u64) {
-    // do nothing
+pub extern "C" fn rs_dcerpc_state_transaction_free(state: *mut std::os::raw::c_void, tx_id: u64) {
+    let dce_state = cast_pointer!(state, DCERPCState);
+    SCLogDebug!("freeing tx {}", tx_id as u64);
+    dce_state.free_tx(tx_id);
 }
 
 #[no_mangle]