Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "netflow_parser"
description = "Parser for Netflow Cisco V5, V7, V9, IPFIX"
version = "0.6.6"
version = "0.6.7"
edition = "2024"
authors = ["michael.mileusnich@gmail.com"]
license = "MIT OR Apache-2.0"
Expand Down
5 changes: 5 additions & 0 deletions RELEASES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# 0.6.7
* Performance optimizations in V5 and V7 serialization - eliminated unnecessary Vec allocations in `to_be_bytes()`.
* Improved error handling in IPFIX data parsing - parse errors on non-empty templates now properly propagate instead of silently converting to Empty flowsets, while maintaining backward compatibility for empty templates.
* Added capacity pre-allocation for V9 flowset vectors to reduce reallocations during parsing.

# 0.6.6
* Added configurable field mappings for V9 and IPFIX in NetflowCommon.
* New `V9FieldMappingConfig` and `IPFixFieldMappingConfig` structs allow customizing which fields map to `NetflowCommonFlowSet`.
Expand Down
8 changes: 4 additions & 4 deletions src/static_versions/v5.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,8 @@ impl V5 {
let header_version = self.header.version.to_be_bytes();
let header_count = self.header.count.to_be_bytes();
let header_sys_up_time = self.header.sys_up_time.to_be_bytes();
let mut header_unix_timestamp = self.header.unix_secs.to_be_bytes().to_vec();
let header_unix_nsecs = self.header.unix_nsecs.to_be_bytes().to_vec();
header_unix_timestamp.extend_from_slice(&header_unix_nsecs);
let header_unix_secs = self.header.unix_secs.to_be_bytes();
let header_unix_nsecs = self.header.unix_nsecs.to_be_bytes();
let header_flow_seq = self.header.flow_sequence.to_be_bytes();
let header_engine_type = self.header.engine_type.to_be_bytes();
let header_engine_id = self.header.engine_id.to_be_bytes();
Expand All @@ -132,7 +131,8 @@ impl V5 {
result.extend_from_slice(&header_version);
result.extend_from_slice(&header_count);
result.extend_from_slice(&header_sys_up_time);
result.extend_from_slice(&header_unix_timestamp);
result.extend_from_slice(&header_unix_secs);
result.extend_from_slice(&header_unix_nsecs);
result.extend_from_slice(&header_flow_seq);
result.extend_from_slice(&header_engine_type);
result.extend_from_slice(&header_engine_id);
Expand Down
8 changes: 4 additions & 4 deletions src/static_versions/v7.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,8 @@ impl V7 {
let header_version = self.header.version.to_be_bytes();
let header_count = self.header.count.to_be_bytes();
let header_sys_up_time = self.header.sys_up_time.to_be_bytes();
let mut header_unix_timestamp = self.header.unix_secs.to_be_bytes().to_vec();
let header_unix_nsecs = self.header.unix_nsecs.to_be_bytes().to_vec();
header_unix_timestamp.extend_from_slice(&header_unix_nsecs);
let header_unix_secs = self.header.unix_secs.to_be_bytes();
let header_unix_nsecs = self.header.unix_nsecs.to_be_bytes();
let header_flow_seq = self.header.flow_sequence.to_be_bytes();
let reserved = self.header.reserved.to_be_bytes();

Expand All @@ -131,7 +130,8 @@ impl V7 {
result.extend_from_slice(&header_version);
result.extend_from_slice(&header_count);
result.extend_from_slice(&header_sys_up_time);
result.extend_from_slice(&header_unix_timestamp);
result.extend_from_slice(&header_unix_secs);
result.extend_from_slice(&header_unix_nsecs);
result.extend_from_slice(&header_flow_seq);
result.extend_from_slice(&reserved);

Expand Down
16 changes: 10 additions & 6 deletions src/variable_versions/ipfix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,14 +237,18 @@ impl FlowSetBody {
// Parse Data
_ => {
if let Some(template) = parser.templates.get(&id) {
match Data::parse(i, template) {
Ok((i, data)) => Ok((i, FlowSetBody::Data(data))),
Err(_) => Ok((i, FlowSetBody::Empty)),
if template.get_fields().is_empty() {
Ok((i, FlowSetBody::Empty))
} else {
let (i, data) = Data::parse(i, template)?;
Ok((i, FlowSetBody::Data(data)))
}
} else if let Some(options_template) = parser.ipfix_options_templates.get(&id) {
match OptionsData::parse(i, options_template) {
Ok((i, data)) => Ok((i, FlowSetBody::OptionsData(data))),
Err(_) => Ok((i, FlowSetBody::Empty)),
if options_template.get_fields().is_empty() {
Ok((i, FlowSetBody::Empty))
} else {
let (i, data) = OptionsData::parse(i, options_template)?;
Ok((i, FlowSetBody::OptionsData(data)))
}
} else if let Some(v9_template) = parser.v9_templates.get(&id) {
let (i, data) = V9Data::parse(i, v9_template)?;
Expand Down
8 changes: 5 additions & 3 deletions src/variable_versions/v9.rs
Original file line number Diff line number Diff line change
Expand Up @@ -449,15 +449,17 @@ impl FlowSetParser {
parser: &mut V9Parser,
record_count: u16,
) -> IResult<&'a [u8], Vec<FlowSet>> {
let (remaining, flowsets) =
(0..record_count).try_fold((i, Vec::new()), |(remaining, mut flowsets), _| {
let (remaining, flowsets) = (0..record_count).try_fold(
(i, Vec::with_capacity(record_count as usize)),
|(remaining, mut flowsets), _| {
if remaining.is_empty() {
return Ok((remaining, flowsets));
}
let (i, flowset) = FlowSet::parse(remaining, parser)?;
flowsets.push(flowset);
Ok((i, flowsets))
})?;
},
)?;

Ok((remaining, flowsets))
}
Expand Down