Skip to content

Commit b2ec418

Browse files
authored
Report whole packet bytes in ConnRecord (#91)
1 parent 01a149c commit b2ec418

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

datatypes/src/connection.rs

+16-5
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,16 @@ impl ConnRecord {
4848
self.orig.nb_pkts + self.resp.nb_pkts
4949
}
5050

51+
/// Returns the total number of packet bytes observed, including headers and malformed packets.
52+
#[inline]
53+
pub fn total_pkt_bytes(&self) -> u64 {
54+
self.orig.nb_pkt_bytes + self.resp.nb_pkt_bytes
55+
}
56+
5157
/// Returns the total number of payload bytes observed, excluding those from malformed packets.
5258
#[inline]
53-
pub fn total_bytes(&self) -> u64 {
54-
self.orig.nb_bytes + self.resp.nb_bytes
59+
pub fn total_payload_bytes(&self) -> u64 {
60+
self.orig.nb_payload_bytes + self.resp.nb_payload_bytes
5561
}
5662

5763
/// Returns the connection history.
@@ -257,9 +263,12 @@ pub struct Flow {
257263
pub nb_malformed_pkts: u64,
258264
/// Number of late start packets.
259265
pub nb_late_start_pkts: u64,
266+
/// Number of packet bytes observed in the flow. Includes bytes from malformed
267+
/// segments and ethernet and ip headers.
268+
pub nb_pkt_bytes: u64,
260269
/// Number of payload bytes observed in the flow. Does not include bytes from malformed
261270
/// segments.
262-
pub nb_bytes: u64,
271+
pub nb_payload_bytes: u64,
263272
/// Maximum number of simultaneous content gaps.
264273
///
265274
/// A content gap is a "hole" in the TCP sequence number, indicated re-ordered or missing
@@ -284,7 +293,8 @@ impl Flow {
284293
nb_pkts: 0,
285294
nb_malformed_pkts: 0,
286295
nb_late_start_pkts: 0,
287-
nb_bytes: 0,
296+
nb_pkt_bytes: 0,
297+
nb_payload_bytes: 0,
288298
max_simult_gaps: 0,
289299
data_start: 0,
290300
capacity: DEFAULT_CHUNK_CAPACITY,
@@ -296,14 +306,15 @@ impl Flow {
296306
#[inline]
297307
fn insert_segment(&mut self, segment: &L4Pdu) {
298308
self.nb_pkts += 1;
309+
self.nb_pkt_bytes += segment.mbuf.data_len() as u64;
299310

300311
if segment.offset() > segment.mbuf.data_len()
301312
|| (segment.offset() + segment.length()) > segment.mbuf.data_len()
302313
{
303314
self.nb_malformed_pkts += 1;
304315
return;
305316
}
306-
self.nb_bytes += segment.length() as u64;
317+
self.nb_payload_bytes += segment.length() as u64;
307318

308319
let seq_no = if segment.flags() & SYN != 0 {
309320
segment.seq_no().wrapping_add(1)

0 commit comments

Comments
 (0)