]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
Rust: generic files definition
authorJuliana Fajardini <jufajardini@gmail.com>
Wed, 4 Nov 2020 18:07:16 +0000 (18:07 +0000)
committerVictor Julien <victor@inliniac.net>
Wed, 9 Dec 2020 14:15:15 +0000 (15:15 +0100)
Issue: Optimization 3825
- filecontainer: add Files structure, to replace/unify SMBFiles,
NFSFiles and HTTP2Files
- smb/files: delete SMBFiles implementation
- smb/smb: replace SMBFiles with Files
- nfs/nfs: delete NFSFiles implementation, replace its former
 declarations with Files' ones
- http2/http2: replace HTTP2Files with Files
- http2/mod: Delete reference to file files.rs
- http2/files: Delete

rust/src/filecontainer.rs
rust/src/http2/files.rs [deleted file]
rust/src/http2/http2.rs
rust/src/http2/mod.rs
rust/src/nfs/nfs.rs
rust/src/smb/files.rs
rust/src/smb/smb.rs

index 7bf585827610c172b8b45b498b1072d39fc65c2c..7d0fc9d6fcff1455fb2e7bf8d0f45de9e439b37d 100644 (file)
@@ -27,6 +27,39 @@ extern {
 pub const FILE_USE_DETECT:    u16 = 0x2000;
 
 
+// Generic file structure, so it can be used by different protocols
+#[derive(Debug)]
+pub struct Files {
+    pub files_ts: FileContainer,
+    pub files_tc: FileContainer,
+    pub flags_ts: u16,
+    pub flags_tc: u16,
+}
+
+impl Files {
+    pub fn new() -> Files {
+        Files {
+            files_ts:FileContainer::default(),
+            files_tc:FileContainer::default(),
+            flags_ts:0,
+            flags_tc:0,
+        }
+    }
+    pub fn free(&mut self) {
+        self.files_ts.free();
+        self.files_tc.free();
+    }
+
+    pub fn get(&mut self, direction: u8) -> (&mut FileContainer, u16)
+    {
+        if direction == STREAM_TOSERVER {
+            (&mut self.files_ts, self.flags_ts)
+        } else {
+            (&mut self.files_tc, self.flags_tc)
+        }
+    }
+}
+
 pub struct File;
 #[repr(C)]
 #[derive(Debug)]
diff --git a/rust/src/http2/files.rs b/rust/src/http2/files.rs
deleted file mode 100644 (file)
index 4063604..0000000
+++ /dev/null
@@ -1,51 +0,0 @@
-/* Copyright (C) 2020 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
- * Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * version 2 along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301, USA.
- */
-
-use crate::core::*;
-use crate::filecontainer::*;
-
-/// Wrapper around Suricata's internal file container logic.
-#[derive(Debug)]
-pub struct HTTP2Files {
-    pub files_ts: FileContainer,
-    pub files_tc: FileContainer,
-    pub flags_ts: u16,
-    pub flags_tc: u16,
-}
-
-impl HTTP2Files {
-    pub fn new() -> HTTP2Files {
-        HTTP2Files {
-            files_ts: FileContainer::default(),
-            files_tc: FileContainer::default(),
-            flags_ts: 0,
-            flags_tc: 0,
-        }
-    }
-    pub fn free(&mut self) {
-        self.files_ts.free();
-        self.files_tc.free();
-    }
-
-    pub fn get(&mut self, direction: u8) -> (&mut FileContainer, u16) {
-        if direction == STREAM_TOSERVER {
-            (&mut self.files_ts, self.flags_ts)
-        } else {
-            (&mut self.files_tc, self.flags_tc)
-        }
-    }
-}
index a0d97904d808d8def835e0b7e4d7540b4afe26ec..22d633080804159cf62fd1c41a117ef516ffc0e4 100644 (file)
@@ -15,7 +15,6 @@
  * 02110-1301, USA.
  */
 
-use super::files::*;
 use super::parser;
 use crate::applayer::{self, *};
 use crate::core::{
@@ -299,7 +298,7 @@ pub struct HTTP2State {
     dynamic_headers_tc: HTTP2DynTable,
     transactions: Vec<HTTP2Transaction>,
     progress: HTTP2ConnectionState,
-    pub files: HTTP2Files,
+    pub files: Files,
 }
 
 impl HTTP2State {
@@ -315,7 +314,7 @@ impl HTTP2State {
             dynamic_headers_tc: HTTP2DynTable::new(),
             transactions: Vec::new(),
             progress: HTTP2ConnectionState::Http2StateInit,
-            files: HTTP2Files::new(),
+            files: Files::new(),
         }
     }
 
index ad86bdf291ce97aba4054d7e94ee4bc982d88628..f6f5aba1f27708bbfe6b3b4ce544470e6d652b2d 100644 (file)
@@ -16,7 +16,6 @@
  */
 
 pub mod detect;
-pub mod files;
 pub mod http2;
 mod huffman;
 pub mod logger;
index d33d548b431e3577792a61b49955213b36164a8e..9a79d9221c069d596e6e562acbb5d2d125641036 100644 (file)
@@ -259,38 +259,6 @@ impl NFSRequestXidMap {
     }
 }
 
-#[derive(Debug)]
-pub struct NFSFiles {
-    pub files_ts: FileContainer,
-    pub files_tc: FileContainer,
-    pub flags_ts: u16,
-    pub flags_tc: u16,
-}
-
-impl NFSFiles {
-    pub fn new() -> NFSFiles {
-        NFSFiles {
-            files_ts:FileContainer::default(),
-            files_tc:FileContainer::default(),
-            flags_ts:0,
-            flags_tc:0,
-        }
-    }
-    pub fn free(&mut self) {
-        self.files_ts.free();
-        self.files_tc.free();
-    }
-
-    pub fn get(&mut self, direction: u8) -> (&mut FileContainer, u16)
-    {
-        if direction == STREAM_TOSERVER {
-            (&mut self.files_ts, self.flags_ts)
-        } else {
-            (&mut self.files_tc, self.flags_tc)
-        }
-    }
-}
-
 /// little wrapper around the FileTransferTracker::new_chunk method
 pub fn filetracker_newchunk(ft: &mut FileTransferTracker, files: &mut FileContainer,
         flags: u16, name: &Vec<u8>, data: &[u8],
@@ -315,7 +283,7 @@ pub struct NFSState {
     /// transactions list
     pub transactions: Vec<NFSTransaction>,
 
-    pub files: NFSFiles,
+    pub files: Files,
 
     /// partial record tracking
     pub ts_chunk_xid: u32,
@@ -358,7 +326,7 @@ impl NFSState {
             requestmap:HashMap::new(),
             namemap:HashMap::new(),
             transactions: Vec::new(),
-            files:NFSFiles::new(),
+            files:Files::new(),
             ts_chunk_xid:0,
             tc_chunk_xid:0,
             ts_chunk_left:0,
index f1c455fbdb3bbd17d89a5b571e4d3c9aa27839d8..9b18c26b159a5d81cc0b409c100208f5d70c6404 100644 (file)
@@ -47,39 +47,6 @@ impl SMBTransactionFile {
     }
 }
 
-/// Wrapper around Suricata's internal file container logic.
-#[derive(Debug)]
-pub struct SMBFiles {
-    pub files_ts: FileContainer,
-    pub files_tc: FileContainer,
-    pub flags_ts: u16,
-    pub flags_tc: u16,
-}
-
-impl SMBFiles {
-    pub fn new() -> SMBFiles {
-        SMBFiles {
-            files_ts:FileContainer::default(),
-            files_tc:FileContainer::default(),
-            flags_ts:0,
-            flags_tc:0,
-        }
-    }
-    pub fn free(&mut self) {
-        self.files_ts.free();
-        self.files_tc.free();
-    }
-
-    pub fn get(&mut self, direction: u8) -> (&mut FileContainer, u16)
-    {
-        if direction == STREAM_TOSERVER {
-            (&mut self.files_ts, self.flags_ts)
-        } else {
-            (&mut self.files_tc, self.flags_tc)
-        }
-    }
-}
-
 /// little wrapper around the FileTransferTracker::new_chunk method
 pub fn filetracker_newchunk(ft: &mut FileTransferTracker, files: &mut FileContainer,
         flags: u16, name: &Vec<u8>, data: &[u8],
index 3a516b841deb39d9968bf7b87cb57ff75964ada5..42da36272a84a873120919a0028f7155a7341e8a 100644 (file)
@@ -37,6 +37,7 @@ use nom;
 use crate::core::*;
 use crate::applayer;
 use crate::applayer::{AppLayerResult, AppLayerTxData};
+use crate::filecontainer::*;
 
 use crate::smb::nbss_records::*;
 use crate::smb::smb1_records::*;
@@ -755,7 +756,7 @@ pub struct SMBState<> {
     // requests for DCERPC.
     pub ssnguid2vec_map: HashMap<SMBHashKeyHdrGuid, Vec<u8>>,
 
-    pub files: SMBFiles,
+    pub files: Files,
 
     skip_ts: u32,
     skip_tc: u32,
@@ -808,7 +809,7 @@ impl SMBState {
             ssn2vecoffset_map:HashMap::new(),
             ssn2tree_map:HashMap::new(),
             ssnguid2vec_map:HashMap::new(),
-            files: SMBFiles::new(),
+            files: Files::new(),
             skip_ts:0,
             skip_tc:0,
             file_ts_left:0,