From: Victor Julien Date: Sat, 16 Apr 2022 04:57:56 +0000 (+0200) Subject: filetracker: track total queued data (in_flight) X-Git-Tag: suricata-5.0.9~25 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e82b4e018508d7aed7178cf37d4f3f2aec4c1439;p=thirdparty%2Fsuricata.git filetracker: track total queued data (in_flight) As well as expose number of chunks. Backport note: Modified to support Rust 1.33 -- Jason Ish (cherry picked from commit 2c5ad8858e38fce20155044a06969693fe472d4c) --- diff --git a/rust/src/filetracker.rs b/rust/src/filetracker.rs index 4f93f41806..b31da1ea50 100644 --- a/rust/src/filetracker.rs +++ b/rust/src/filetracker.rs @@ -65,6 +65,8 @@ pub struct FileTransferTracker { chunks: HashMap, cur_ooo_chunk_offset: u64, + + in_flight: u64, } impl FileTransferTracker { @@ -82,6 +84,7 @@ impl FileTransferTracker { file_is_truncated:false, cur_ooo_chunk_offset:0, chunks:HashMap::new(), + in_flight: 0, } } @@ -219,15 +222,19 @@ impl FileTransferTracker { } else { SCLogDebug!("UPDATE: appending data {} to ooo chunk at offset {}/{}", d.len(), self.cur_ooo_chunk_offset, self.tracked); - let c = match self.chunks.entry(self.cur_ooo_chunk_offset) { - Vacant(entry) => { - entry.insert(FileChunk::new(self.chunk_left)) - }, - Occupied(entry) => entry.into_mut(), - }; - self.cur_ooo += d.len() as u64; - c.contains_gap |= is_gap; - c.chunk.extend(d); + { + let c = match self.chunks.entry(self.cur_ooo_chunk_offset) { + Vacant(entry) => { + entry.insert(FileChunk::new(self.chunk_left)) + }, + Occupied(entry) => entry.into_mut(), + }; + self.cur_ooo += d.len() as u64; + c.contains_gap |= is_gap; + c.chunk.extend(d); + } + self.in_flight += d.len() as u64; + SCLogDebug!("{:p} in_flight {}", self, self.in_flight); } consumed += self.chunk_left as usize; @@ -251,6 +258,8 @@ impl FileTransferTracker { let _offset = self.tracked; match self.chunks.remove(&self.tracked) { Some(c) => { + self.in_flight -= c.chunk.len() as u64; + let res = files.file_append(&self.track_id, &c.chunk, c.contains_gap); match res { 0 => { }, @@ -311,6 +320,7 @@ impl FileTransferTracker { c.chunk.extend(data); c.contains_gap |= is_gap; self.cur_ooo += data.len() as u64; + self.in_flight += data.len() as u64; } self.chunk_left -= data.len() as u32; @@ -323,4 +333,11 @@ impl FileTransferTracker { pub fn get_queued_size(&self) -> u64 { self.cur_ooo } + + pub fn get_inflight_size(&self) -> u64 { + self.in_flight + } + pub fn get_inflight_cnt(&self) -> usize { + self.chunks.len() + } }