Skip to content

Protocol Types Fix and Readme updates #81

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 17, 2024
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.4.2"
version = "0.4.3"
edition = "2021"
author = "[email protected]"
license = "MIT OR Apache-2.0"
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# netflow_parser

## Description

A Netflow Parser library for Cisco V5, V7, V9, IPFIX written in Rust.
Supports chaining of multple versions in the same stream. ({v5 packet}, {v7packet}, {v5packet}, {v9packet}, etc.)

# References
## References
See: <https://en.wikipedia.org/wiki/NetFlow>

# Description

## Example

### V5
Expand Down
4 changes: 4 additions & 0 deletions RELEASES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 0.4.3
* Fixed bug in NetflowCommon where ProtocolType was never set.
* Minior Readme Changes.

# 0.4.2
* Increased coverage.
* Reworked Readme.
Expand Down
1 change: 1 addition & 0 deletions SECURITY.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

| Version | Supported |
| ------- | ------------------ |
| 0.4.3 | :white_check_mark: |
| 0.4.2 | :white_check_mark: |
| 0.4.1 | :white_check_mark: |
| 0.4.0 | :white_check_mark: |
Expand Down
6 changes: 3 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
//! # netflow_parser
//!
//! ## Description
//!
//! A Netflow Parser library for Cisco V5, V7, V9, IPFIX written in Rust.
//! Supports chaining of multple versions in the same stream. ({v5 packet}, {v7packet}, {v5packet}, {v9packet}, etc.)
//!
//! # References
//! ## References
//! See: <https://en.wikipedia.org/wiki/NetFlow>
//!
//! # Description
//!
//! ## Example
//!
//! ### V5
Expand Down
28 changes: 26 additions & 2 deletions src/netflow_common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,15 @@ impl From<&V9> for NetflowCommon {
FieldValue::DataNumber(DataNumber::U32(seen)) => Some(*seen),
_ => None,
}),
protocol_type: None,
protocol_type: values
.iter()
.find(|(k, _)| *k == V9Field::Protocol)
.and_then(|(_, v)| match v {
FieldValue::DataNumber(DataNumber::U8(proto)) => {
Some(ProtocolTypes::from(*proto))
}
_ => None,
}),
});
}
}
Expand Down Expand Up @@ -249,7 +257,15 @@ impl From<&IPFix> for NetflowCommon {
FieldValue::DataNumber(DataNumber::U32(seen)) => Some(*seen),
_ => None,
}),
protocol_type: None,
protocol_type: values
.iter()
.find(|(k, _)| *k == IPFixField::ProtocolIdentifier)
.and_then(|(_, v)| match v {
FieldValue::DataNumber(DataNumber::U8(proto)) => {
Some(ProtocolTypes::from(*proto))
}
_ => None,
}),
});
}
}
Expand Down Expand Up @@ -485,6 +501,10 @@ mod common_tests {
assert_eq!(flowset.src_port.unwrap(), 1234);
assert_eq!(flowset.dst_port.unwrap(), 80);
assert_eq!(flowset.protocol_number.unwrap(), 6);
assert_eq!(
flowset.protocol_type.unwrap(),
crate::protocol::ProtocolTypes::Tcp
);
assert_eq!(flowset.first_seen.unwrap(), 100);
assert_eq!(flowset.last_seen.unwrap(), 200);
}
Expand Down Expand Up @@ -582,6 +602,10 @@ mod common_tests {
assert_eq!(flowset.src_port.unwrap(), 1234);
assert_eq!(flowset.dst_port.unwrap(), 80);
assert_eq!(flowset.protocol_number.unwrap(), 6);
assert_eq!(
flowset.protocol_type.unwrap(),
crate::protocol::ProtocolTypes::Tcp
);
assert_eq!(flowset.first_seen.unwrap(), 100);
assert_eq!(flowset.last_seen.unwrap(), 200);
}
Expand Down
Loading