From: Jason Ish Date: Wed, 27 Apr 2022 15:29:30 +0000 (-0600) Subject: rdp: convert transaction list to vecdeque X-Git-Tag: suricata-7.0.0-beta1~666 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4e0ad5e0bd4584d625ad122f0c33908abb17e7a4;p=thirdparty%2Fsuricata.git rdp: convert transaction list to vecdeque Allows for more efficient removal from front of the list. Ticket: #5295 --- diff --git a/rust/src/rdp/rdp.rs b/rust/src/rdp/rdp.rs index 383fa66fd1..8479530676 100644 --- a/rust/src/rdp/rdp.rs +++ b/rust/src/rdp/rdp.rs @@ -1,4 +1,4 @@ -/* Copyright (C) 2019 Open Information Security Foundation +/* Copyright (C) 2022 Open Information Security Foundation * * You can copy, redistribute or modify this Program under the terms of * the GNU General Public License version 2 as published by the Free @@ -24,6 +24,7 @@ use crate::core::{AppProto, Flow, ALPROTO_UNKNOWN, IPPROTO_TCP}; use crate::rdp::parser::*; use nom; use std; +use std::collections::VecDeque; use tls_parser::{parse_tls_plaintext, TlsMessage, TlsMessageHandshake, TlsRecordType}; static mut ALPROTO_RDP: AppProto = ALPROTO_UNKNOWN; @@ -107,7 +108,7 @@ pub extern "C" fn rs_rdp_tx_get_progress( #[derive(Debug, PartialEq)] pub struct RdpState { next_id: u64, - transactions: Vec, + transactions: VecDeque, tls_parsing: bool, bypass_parsing: bool, } @@ -126,7 +127,7 @@ impl RdpState { fn new() -> Self { Self { next_id: 0, - transactions: Vec::new(), + transactions: VecDeque::new(), tls_parsing: false, bypass_parsing: false, } @@ -208,7 +209,7 @@ impl RdpState { T123TpktChild::X224ConnectionRequest(x224) => { let tx = self.new_tx(RdpTransactionItem::X224ConnectionRequest(x224)); - self.transactions.push(tx); + self.transactions.push_back(tx); } // X.223 data packet, evaluate what it encapsulates @@ -217,7 +218,7 @@ impl RdpState { X223DataChild::McsConnectRequest(mcs) => { let tx = self.new_tx(RdpTransactionItem::McsConnectRequest(mcs)); - self.transactions.push(tx); + self.transactions.push_back(tx); } // unknown message in X.223, skip _ => (), @@ -287,7 +288,7 @@ impl RdpState { } let tx = self.new_tx(RdpTransactionItem::TlsCertificateChain(chain)); - self.transactions.push(tx); + self.transactions.push_back(tx); self.bypass_parsing = true; } _ => {} @@ -320,7 +321,7 @@ impl RdpState { T123TpktChild::X224ConnectionConfirm(x224) => { let tx = self.new_tx(RdpTransactionItem::X224ConnectionConfirm(x224)); - self.transactions.push(tx); + self.transactions.push_back(tx); } // X.223 data packet, evaluate what it encapsulates @@ -329,7 +330,7 @@ impl RdpState { X223DataChild::McsConnectResponse(mcs) => { let tx = self .new_tx(RdpTransactionItem::McsConnectResponse(mcs)); - self.transactions.push(tx); + self.transactions.push_back(tx); self.bypass_parsing = true; return AppLayerResult::ok(); } @@ -606,8 +607,8 @@ mod tests { let tx0 = state.new_tx(item0); let tx1 = state.new_tx(item1); assert_eq!(2, state.next_id); - state.transactions.push(tx0); - state.transactions.push(tx1); + state.transactions.push_back(tx0); + state.transactions.push_back(tx1); assert_eq!(2, state.transactions.len()); assert_eq!(1, state.transactions[0].id); assert_eq!(2, state.transactions[1].id); @@ -651,9 +652,9 @@ mod tests { let tx0 = state.new_tx(item0); let tx1 = state.new_tx(item1); let tx2 = state.new_tx(item2); - state.transactions.push(tx0); - state.transactions.push(tx1); - state.transactions.push(tx2); + state.transactions.push_back(tx0); + state.transactions.push_back(tx1); + state.transactions.push_back(tx2); state.free_tx(1); assert_eq!(3, state.next_id); assert_eq!(2, state.transactions.len());