Skip to content

Commit

Permalink
Protocol Types Fix and Readme updates (#81)
Browse files Browse the repository at this point in the history
* Protocol Types Fix and Readme updates

---------

Co-authored-by: mikemiles-dev <[email protected]>
  • Loading branch information
mikemiles-dev and mikemiles-dev authored Sep 17, 2024
1 parent 0471ad7 commit 3d62759
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 9 deletions.
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

0 comments on commit 3d62759

Please sign in to comment.