]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
dcerpc: convert transaction list to vecdeque
authorJason Ish <jason.ish@oisf.net>
Mon, 2 May 2022 18:19:51 +0000 (12:19 -0600)
committerVictor Julien <vjulien@oisf.net>
Sat, 10 Jun 2023 08:01:06 +0000 (10:01 +0200)
Allows for more efficient removal from front of the list.

Ticket: #5271
(cherry picked from commit dfe76bb905409bf91345e972f2ab157bda51f003)

rust/src/dcerpc/dcerpc.rs
rust/src/dns/dns.rs

index b9ee26e81735aa15ee5b06f4cbdca7522df28a7d..b874954ee2178dc9ae72f3acd15d23b238f17b2c 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (C) 2020 Open Information Security Foundation
+/* Copyright (C) 2020-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
@@ -23,6 +23,7 @@ use nom::error::ErrorKind;
 use nom::number::Endianness;
 use nom;
 use std::cmp;
+use std::collections::VecDeque;
 
 // Constant DCERPC UDP Header length
 pub const DCERPC_HDR_LEN: u16 = 16;
@@ -332,7 +333,7 @@ pub struct DCERPCState {
     pub header: Option<DCERPCHdr>,
     pub bind: Option<DCERPCBind>,
     pub bindack: Option<DCERPCBindAck>,
-    pub transactions: Vec<DCERPCTransaction>,
+    pub transactions: VecDeque<DCERPCTransaction>,
     pub buffer_ts: Vec<u8>,
     pub buffer_tc: Vec<u8>,
     pub pad: u8,
@@ -357,7 +358,7 @@ impl DCERPCState {
             header: None,
             bind: None,
             bindack: None,
-            transactions: Vec::new(),
+            transactions: VecDeque::new(),
             buffer_ts: Vec::new(),
             buffer_tc: Vec::new(),
             pad: 0,
@@ -740,7 +741,7 @@ impl DCERPCState {
                     sc_app_layer_parser_trigger_raw_stream_reassembly(flow, core::STREAM_TOSERVER.into());
                 }
                 tx.frag_cnt_ts = 1;
-                self.transactions.push(tx);
+                self.transactions.push_back(tx);
                 // Bytes parsed with `parse_dcerpc_bind` + (bytes parsed per bindctxitem [44] * number
                 // of bindctxitems)
                 (input.len() - leftover_bytes.len()) as i32 + retval * numctxitems as i32
@@ -921,7 +922,7 @@ impl DCERPCState {
                         tx.ctxid = request.ctxid;
                         tx.opnum = request.opnum;
                         tx.first_request_seen = request.first_request_seen;
-                        self.transactions.push(tx);
+                        self.transactions.push_back(tx);
                     }
                 }
                 let parsed = self.handle_common_stub(
@@ -1064,8 +1065,8 @@ impl DCERPCState {
                     } else {
                         let mut tx = self.create_tx(current_call_id);
                         tx.resp_cmd = x;
-                        self.transactions.push(tx);
-                        self.transactions.last_mut().unwrap()
+                        self.transactions.push_back(tx);
+                        self.transactions.back_mut().unwrap()
                     };
                     tx.resp_done = true;
                     tx.frag_cnt_tc = 1;
@@ -1090,7 +1091,7 @@ impl DCERPCState {
                         None => {
                             let mut tx = self.create_tx(current_call_id);
                             tx.resp_cmd = x;
-                            self.transactions.push(tx);
+                            self.transactions.push_back(tx);
                         }
                     };
                     retval = self.handle_common_stub(
index 4b09cc2988125884fec7d03f6df27448b40a6127..31add6dd640e94c92f886583edea5236ee13bf36 100644 (file)
@@ -428,7 +428,8 @@ impl DNSState {
     pub fn new_tcp() -> DNSState {
         return DNSState{
             tx_id: 0,
-            transactions: VecDeque::new(),
+            transactions: VecDeque
+            ::new(),
             config: None,
             gap: false,
         };