From: Philippe Antoine Date: Tue, 13 Dec 2022 08:09:44 +0000 (+0100) Subject: smb: convert transaction list to vecdeque X-Git-Tag: suricata-7.0.0-rc1~170 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1d9183638f930e8e0f22c421ee0ef9fde043106a;p=thirdparty%2Fsuricata.git smb: convert transaction list to vecdeque Allows for more efficient removal from front of the list. Ticket: #5753 --- diff --git a/rust/src/smb/dcerpc.rs b/rust/src/smb/dcerpc.rs index 502b243052..ee9d0702f3 100644 --- a/rust/src/smb/dcerpc.rs +++ b/rust/src/smb/dcerpc.rs @@ -133,8 +133,8 @@ impl SMBState { SMBTransactionDCERPC::new_request(cmd, call_id))); SCLogDebug!("SMB: TX DCERPC created: ID {} hdr {:?}", tx.id, tx.hdr); - self.transactions.push(tx); - let tx_ref = self.transactions.last_mut(); + self.transactions.push_back(tx); + let tx_ref = self.transactions.back_mut(); return tx_ref.unwrap(); } @@ -148,8 +148,8 @@ impl SMBState { SMBTransactionDCERPC::new_response(call_id))); SCLogDebug!("SMB: TX DCERPC created: ID {} hdr {:?}", tx.id, tx.hdr); - self.transactions.push(tx); - let tx_ref = self.transactions.last_mut(); + self.transactions.push_back(tx); + let tx_ref = self.transactions.back_mut(); return tx_ref.unwrap(); } diff --git a/rust/src/smb/debug.rs b/rust/src/smb/debug.rs index 3f706a09fc..86799dd7fa 100644 --- a/rust/src/smb/debug.rs +++ b/rust/src/smb/debug.rs @@ -24,8 +24,8 @@ impl SMBState { #[cfg(feature = "debug")] pub fn _debug_tx_stats(&self) { if self.transactions.len() > 1 { - let txf = self.transactions.first().unwrap(); - let txl = self.transactions.last().unwrap(); + let txf = self.transactions.front().unwrap(); + let txl = self.transactions.back().unwrap(); SCLogDebug!("TXs {} MIN {} MAX {}", self.transactions.len(), txf.id, txl.id); SCLogDebug!("- OLD tx.id {}: {:?}", txf.id, txf); diff --git a/rust/src/smb/files.rs b/rust/src/smb/files.rs index 7852b5ea45..37f60aec21 100644 --- a/rust/src/smb/files.rs +++ b/rust/src/smb/files.rs @@ -81,8 +81,8 @@ impl SMBState { tx.tx_data.file_tx = if direction == Direction::ToServer { STREAM_TOSERVER } else { STREAM_TOCLIENT }; // TODO direction to flag func? SCLogDebug!("SMB: new_file_tx: TX FILE created: ID {} NAME {}", tx.id, String::from_utf8_lossy(file_name)); - self.transactions.push(tx); - let tx_ref = self.transactions.last_mut(); + self.transactions.push_back(tx); + let tx_ref = self.transactions.back_mut(); return tx_ref.unwrap(); } diff --git a/rust/src/smb/session.rs b/rust/src/smb/session.rs index 6eb3d1d273..be7866976d 100644 --- a/rust/src/smb/session.rs +++ b/rust/src/smb/session.rs @@ -47,8 +47,8 @@ impl SMBState { tx.response_done = self.tc_trunc; // no response expected if tc is truncated SCLogDebug!("SMB: TX SESSIONSETUP created: ID {}", tx.id); - self.transactions.push(tx); - let tx_ref = self.transactions.last_mut(); + self.transactions.push_back(tx); + let tx_ref = self.transactions.back_mut(); return tx_ref.unwrap(); } diff --git a/rust/src/smb/smb.rs b/rust/src/smb/smb.rs index 77ca733a4e..77f6604975 100644 --- a/rust/src/smb/smb.rs +++ b/rust/src/smb/smb.rs @@ -30,7 +30,8 @@ use std::str; use std::ffi::{self, CString}; use std::collections::HashMap; - +use std::collections::VecDeque; + use nom7::{Err, Needed}; use nom7::error::{make_error, ErrorKind}; @@ -334,8 +335,8 @@ impl SMBState { tx.response_done = self.tc_trunc; // no response expected if tc is truncated SCLogDebug!("SMB: TX SETFILEPATHINFO created: ID {}", tx.id); - self.transactions.push(tx); - let tx_ref = self.transactions.last_mut(); + self.transactions.push_back(tx); + let tx_ref = self.transactions.back_mut(); return tx_ref.unwrap(); } @@ -353,8 +354,8 @@ impl SMBState { tx.response_done = self.tc_trunc; // no response expected if tc is truncated SCLogDebug!("SMB: TX SETFILEPATHINFO created: ID {}", tx.id); - self.transactions.push(tx); - let tx_ref = self.transactions.last_mut(); + self.transactions.push_back(tx); + let tx_ref = self.transactions.back_mut(); return tx_ref.unwrap(); } } @@ -386,8 +387,8 @@ impl SMBState { tx.response_done = self.tc_trunc; // no response expected if tc is truncated SCLogDebug!("SMB: TX RENAME created: ID {}", tx.id); - self.transactions.push(tx); - let tx_ref = self.transactions.last_mut(); + self.transactions.push_back(tx); + let tx_ref = self.transactions.back_mut(); return tx_ref.unwrap(); } } @@ -712,7 +713,7 @@ pub struct SMBState<> { post_gap_files_checked: bool, /// transactions list - pub transactions: Vec, + pub transactions: VecDeque, /// tx counter for assigning incrementing id's to tx's tx_id: u64, @@ -768,7 +769,7 @@ impl SMBState { tc_trunc: false, check_post_gap_file_txs: false, post_gap_files_checked: false, - transactions: Vec::new(), + transactions: VecDeque::new(), tx_id:0, dialect:0, dialect_vec: None, @@ -872,15 +873,15 @@ impl SMBState { SCLogDebug!("SMB: TX GENERIC created: ID {} tx list {} {:?}", tx.id, self.transactions.len(), &tx); - self.transactions.push(tx); - let tx_ref = self.transactions.last_mut(); + self.transactions.push_back(tx); + let tx_ref = self.transactions.back_mut(); return tx_ref.unwrap(); } pub fn get_last_tx(&mut self, smb_ver: u8, smb_cmd: u16) -> Option<&mut SMBTransaction> { - let tx_ref = self.transactions.last_mut(); + let tx_ref = self.transactions.back_mut(); if let Some(tx) = tx_ref { let found = if tx.vercmd.get_version() == smb_ver { if smb_ver == 1 { @@ -942,8 +943,8 @@ impl SMBState { tx.response_done = self.tc_trunc; // no response expected if tc is truncated SCLogDebug!("SMB: TX NEGOTIATE created: ID {} SMB ver {}", tx.id, smb_ver); - self.transactions.push(tx); - let tx_ref = self.transactions.last_mut(); + self.transactions.push_back(tx); + let tx_ref = self.transactions.back_mut(); return tx_ref.unwrap(); } @@ -977,8 +978,8 @@ impl SMBState { SCLogDebug!("SMB: TX TREECONNECT created: ID {} NAME {}", tx.id, String::from_utf8_lossy(&name)); - self.transactions.push(tx); - let tx_ref = self.transactions.last_mut(); + self.transactions.push_back(tx); + let tx_ref = self.transactions.back_mut(); return tx_ref.unwrap(); } @@ -1011,8 +1012,8 @@ impl SMBState { tx.request_done = true; tx.response_done = self.tc_trunc; // no response expected if tc is truncated - self.transactions.push(tx); - let tx_ref = self.transactions.last_mut(); + self.transactions.push_back(tx); + let tx_ref = self.transactions.back_mut(); return tx_ref.unwrap(); } diff --git a/rust/src/smb/smb2_ioctl.rs b/rust/src/smb/smb2_ioctl.rs index 5db2f4568c..5a3994ecdc 100644 --- a/rust/src/smb/smb2_ioctl.rs +++ b/rust/src/smb/smb2_ioctl.rs @@ -50,8 +50,8 @@ impl SMBState { SCLogDebug!("SMB: TX IOCTL created: ID {} FUNC {:08x}: {}", tx.id, func, &fsctl_func_to_string(func)); - self.transactions.push(tx); - let tx_ref = self.transactions.last_mut(); + self.transactions.push_back(tx); + let tx_ref = self.transactions.back_mut(); return tx_ref.unwrap(); } }