Skip to content

Commit 963a14d

Browse files
mikemiles-devmikemiles-dev
and
mikemiles-dev
authored
Added src_mac and dst_mac to NetflowCommonFlowSet to help identify devices on V9, IPFix. (#87)
* Added `src_mac` and `dst_mac` to NetflowCommonFlowSet to help identify devices on V9, IPFix --------- Co-authored-by: mikemiles-dev <[email protected]>
1 parent 224fa99 commit 963a14d

File tree

7 files changed

+73
-1
lines changed

7 files changed

+73
-1
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
name = "netflow_parser"
33
description = "Parser for Netflow Cisco V5, V7, V9, IPFIX"
4-
version = "0.4.6"
4+
version = "0.4.7"
55
edition = "2021"
66
77
license = "MIT OR Apache-2.0"

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@ struct NetflowCommonFlowSet {
7676
protocol_type: Option<ProtocolTypes>,
7777
first_seen: Option<u32>,
7878
last_seen: Option<u32>,
79+
src_mac: Option<String>,
80+
dst_mac: Option<String>,
7981
}
8082
```
8183

RELEASES.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# 0.4.7
2+
* Added `src_mac` and `dst_mac` to NetflowCommonFlowSet to help identify devices on V9, IPFix.
3+
14
# 0.4.6
25
* Added `NetflowParser` function `parse_bytes_as_netflow_common_flowsets`. Will allow the caller
36
to gather all flowsets from all `NetflowPacket` into a single `Vec` of `NetflowCommonFlowSet`.

SECURITY.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
| Version | Supported |
66
| ------- | ------------------ |
7+
| 0.4.7 | :white_check_mark: |
78
| 0.4.6 | :white_check_mark: |
89
| 0.4.5 | :white_check_mark: |
910
| 0.4.4 | :white_check_mark: |

src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@
7676
//! protocol_type: Option<ProtocolTypes>,
7777
//! first_seen: Option<u32>,
7878
//! last_seen: Option<u32>,
79+
//! src_mac: Option<String>,
80+
//! dst_mac: Option<String>,
7981
//! }
8082
//! ```
8183
//!

src/netflow_common.rs

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@ pub struct NetflowCommonFlowSet {
5555
pub first_seen: Option<u32>,
5656
/// Duration of the flow last
5757
pub last_seen: Option<u32>,
58+
/// Source MAC address
59+
pub src_mac: Option<String>,
60+
/// Destination MAC address
61+
pub dst_mac: Option<String>,
5862
}
5963

6064
impl From<&V5> for NetflowCommon {
@@ -75,6 +79,8 @@ impl From<&V5> for NetflowCommon {
7579
protocol_type: Some(set.protocol_type),
7680
first_seen: Some(set.first),
7781
last_seen: Some(set.last),
82+
src_mac: None,
83+
dst_mac: None,
7884
})
7985
.collect(),
8086
}
@@ -99,6 +105,8 @@ impl From<&V7> for NetflowCommon {
99105
protocol_type: Some(set.protocol_type),
100106
first_seen: Some(set.first),
101107
last_seen: Some(set.last),
108+
src_mac: None,
109+
dst_mac: None,
102110
})
103111
.collect(),
104112
}
@@ -144,6 +152,12 @@ impl From<&V9> for NetflowCommon {
144152
last_seen: value_map
145153
.get(&V9Field::LastSwitched)
146154
.and_then(|v| v.try_into().ok()),
155+
src_mac: value_map
156+
.get(&V9Field::InSrcMac)
157+
.and_then(|v| v.try_into().ok()),
158+
dst_mac: value_map
159+
.get(&V9Field::InDstMac)
160+
.and_then(|v| v.try_into().ok()),
147161
});
148162
}
149163
}
@@ -199,6 +213,12 @@ impl From<&IPFix> for NetflowCommon {
199213
last_seen: value_map
200214
.get(&IPFixField::FlowEndSysUpTime)
201215
.and_then(|v| v.try_into().ok()),
216+
src_mac: value_map
217+
.get(&IPFixField::SourceMacaddress)
218+
.and_then(|v| v.try_into().ok()),
219+
dst_mac: value_map
220+
.get(&IPFixField::DestinationMacaddress)
221+
.and_then(|v| v.try_into().ok()),
202222
});
203223
}
204224
}
@@ -412,6 +432,20 @@ mod common_tests {
412432
FieldValue::DataNumber(DataNumber::U32(200)),
413433
),
414434
),
435+
(
436+
7,
437+
(
438+
V9Field::InSrcMac,
439+
FieldValue::MacAddr("00:00:00:00:00:01".to_string()),
440+
),
441+
),
442+
(
443+
8,
444+
(
445+
V9Field::InDstMac,
446+
FieldValue::MacAddr("00:00:00:00:00:02".to_string()),
447+
),
448+
),
415449
])],
416450
}),
417451
},
@@ -440,6 +474,8 @@ mod common_tests {
440474
);
441475
assert_eq!(flowset.first_seen.unwrap(), 100);
442476
assert_eq!(flowset.last_seen.unwrap(), 200);
477+
assert_eq!(flowset.src_mac.as_ref().unwrap(), "00:00:00:00:00:01");
478+
assert_eq!(flowset.dst_mac.as_ref().unwrap(), "00:00:00:00:00:02");
443479
}
444480

445481
#[test]
@@ -513,6 +549,20 @@ mod common_tests {
513549
FieldValue::DataNumber(DataNumber::U32(200)),
514550
),
515551
),
552+
(
553+
7,
554+
(
555+
IPFixField::SourceMacaddress,
556+
FieldValue::MacAddr("00:00:00:00:00:01".to_string()),
557+
),
558+
),
559+
(
560+
8,
561+
(
562+
IPFixField::DestinationMacaddress,
563+
FieldValue::MacAddr("00:00:00:00:00:02".to_string()),
564+
),
565+
),
516566
])],
517567
}),
518568
},
@@ -541,5 +591,7 @@ mod common_tests {
541591
);
542592
assert_eq!(flowset.first_seen.unwrap(), 100);
543593
assert_eq!(flowset.last_seen.unwrap(), 200);
594+
assert_eq!(flowset.src_mac.as_ref().unwrap(), "00:00:00:00:00:01");
595+
assert_eq!(flowset.dst_mac.as_ref().unwrap(), "00:00:00:00:00:02");
544596
}
545597
}

src/variable_versions/data_number.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,18 @@ pub enum FieldValueError {
281281
InvalidDataType,
282282
}
283283

284+
impl TryFrom<&FieldValue> for String {
285+
type Error = FieldValueError;
286+
287+
fn try_from(value: &FieldValue) -> Result<Self, Self::Error> {
288+
match value {
289+
FieldValue::String(s) => Ok(s.clone()),
290+
FieldValue::MacAddr(s) => Ok(s.to_string()),
291+
_ => Err(FieldValueError::InvalidDataType),
292+
}
293+
}
294+
}
295+
284296
impl TryFrom<&FieldValue> for IpAddr {
285297
type Error = FieldValueError;
286298

0 commit comments

Comments
 (0)