Rust: generic files definition

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
pull/5646/head
Juliana Fajardini 4 years ago committed by Victor Julien
parent d2144c0dfb
commit 5226ba1c15

@ -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)]

@ -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)
}
}
}

@ -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(),
}
}

@ -16,7 +16,6 @@
*/
pub mod detect;
pub mod files;
pub mod http2;
mod huffman;
pub mod logger;

@ -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,

@ -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],

@ -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,

Loading…
Cancel
Save