Skip to content

Commit 61a35b7

Browse files
mikemiles-devMichael Mileusnich
and
Michael Mileusnich
authored
Fixed issue for V5+V7 flowsets (#50)
* Fixed issue for V5+V7 flowsets * Removed dbg --------- Co-authored-by: Michael Mileusnich <[email protected]>
1 parent 9e27ae4 commit 61a35b7

8 files changed

+79
-59
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.2.6"
4+
version = "0.2.7"
55
edition = "2021"
66
77
license = "MIT OR Apache-2.0"

RELEASES.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# 0.2.7
2+
* Added support for multiple flowsets for V5, V7.
3+
14
# 0.2.6
25
* Re-added static and variable versions as public.
36

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.2.7 | :white_check_mark: |
78
| 0.2.6 | :white_check_mark: |
89
| 0.2.5 | :white_check_mark: |
910
| 0.2.4 | :white_check_mark: |

src/snapshots/netflow_parser__tests__tests__it_parses_v5.snap

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ expression: "NetflowParser::default().parse_bytes(&packet)"
55
- V5:
66
header:
77
version: 5
8-
count: 512
8+
count: 1
99
sys_up_time:
1010
secs: 50332
1111
nanos: 672000000
@@ -16,29 +16,29 @@ expression: "NetflowParser::default().parse_bytes(&packet)"
1616
engine_id: 7
1717
sampling_interval: 2057
1818
body:
19-
src_addr: 0.1.2.3
20-
dst_addr: 4.5.6.7
21-
next_hop: 8.9.0.1
22-
input: 515
23-
output: 1029
24-
d_pkts: 101124105
25-
d_octets: 66051
26-
first:
27-
secs: 67438
28-
nanos: 87000000
29-
last:
30-
secs: 134807
31-
nanos: 553000000
32-
src_port: 515
33-
dst_port: 1029
34-
pad1: 6
35-
tcp_flags: 7
36-
protocol_number: 8
37-
protocol_type: Egp
38-
tos: 9
39-
src_as: 1
40-
dst_as: 515
41-
src_mask: 4
42-
dst_mask: 5
43-
pad2: 1543
44-
19+
set:
20+
- src_addr: 0.1.2.3
21+
dst_addr: 4.5.6.7
22+
next_hop: 8.9.0.1
23+
input: 515
24+
output: 1029
25+
d_pkts: 101124105
26+
d_octets: 66051
27+
first:
28+
secs: 67438
29+
nanos: 87000000
30+
last:
31+
secs: 134807
32+
nanos: 553000000
33+
src_port: 515
34+
dst_port: 1029
35+
pad1: 6
36+
tcp_flags: 7
37+
protocol_number: 8
38+
protocol_type: Egp
39+
tos: 9
40+
src_as: 1
41+
dst_as: 515
42+
src_mask: 4
43+
dst_mask: 5
44+
pad2: 1543

src/snapshots/netflow_parser__tests__tests__it_parses_v7.snap

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ expression: "NetflowParser::default().parse_bytes(&packet)"
55
- V7:
66
header:
77
version: 7
8-
count: 512
8+
count: 1
99
sys_up_time:
1010
secs: 50332
1111
nanos: 672000000
@@ -14,30 +14,30 @@ expression: "NetflowParser::default().parse_bytes(&packet)"
1414
flow_sequence: 33752069
1515
reserved: 101124105
1616
body:
17-
src_addr: 0.1.2.3
18-
dst_addr: 4.5.6.7
19-
next_hop: 8.9.0.1
20-
input: 515
21-
output: 1029
22-
d_pkts: 101124105
23-
d_octets: 66051
24-
first:
25-
secs: 67438
26-
nanos: 87000000
27-
last:
28-
secs: 134807
29-
nanos: 553000000
30-
src_port: 515
31-
dst_port: 1029
32-
flags_fields_valid: 6
33-
tcp_flags: 7
34-
protocol_number: 8
35-
protocol_type: Egp
36-
tos: 9
37-
src_as: 1
38-
dst_as: 515
39-
src_mask: 4
40-
dst_mask: 5
41-
flags_fields_invalid: 1543
42-
router_src: 8.9.0.1
43-
17+
set:
18+
- src_addr: 0.1.2.3
19+
dst_addr: 4.5.6.7
20+
next_hop: 8.9.0.1
21+
input: 515
22+
output: 1029
23+
d_pkts: 101124105
24+
d_octets: 66051
25+
first:
26+
secs: 67438
27+
nanos: 87000000
28+
last:
29+
secs: 134807
30+
nanos: 553000000
31+
src_port: 515
32+
dst_port: 1029
33+
flags_fields_valid: 6
34+
tcp_flags: 7
35+
protocol_number: 8
36+
protocol_type: Egp
37+
tos: 9
38+
src_as: 1
39+
dst_as: 515
40+
src_mask: 4
41+
dst_mask: 5
42+
flags_fields_invalid: 1543
43+
router_src: 8.9.0.1

src/static_versions/v5.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ pub struct V5 {
2020
/// V5 Header
2121
pub header: Header,
2222
/// V5 Body
23+
#[nom(Parse = "{ |i| Body::parse(i, header.count) }")]
2324
pub body: Body,
2425
}
2526

@@ -60,7 +61,14 @@ pub struct Header {
6061
}
6162

6263
#[derive(Debug, PartialEq, Eq, Clone, Serialize, Nom)]
64+
#[nom(ExtraArgs(count: u16))]
6365
pub struct Body {
66+
#[nom(Count = "count")]
67+
set: Vec<FlowSet>,
68+
}
69+
70+
#[derive(Debug, PartialEq, Eq, Clone, Serialize, Nom)]
71+
pub struct FlowSet {
6472
/// Source IP address
6573
#[nom(Map = "Ipv4Addr::from", Parse = "be_u32")]
6674
pub src_addr: Ipv4Addr,

src/static_versions/v7.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ pub struct V7 {
2020
/// V7 Header
2121
pub header: Header,
2222
/// V7 Body
23+
#[nom(Parse = "{ |i| Body::parse(i, header.count) }")]
2324
pub body: Body,
2425
}
2526

@@ -55,8 +56,15 @@ pub struct Header {
5556
pub reserved: u32,
5657
}
5758

58-
#[derive(Debug, PartialEq, Eq, Clone, Nom, Serialize)]
59+
#[derive(Debug, PartialEq, Eq, Clone, Serialize, Nom)]
60+
#[nom(ExtraArgs(count: u16))]
5961
pub struct Body {
62+
#[nom(Count = "count")]
63+
set: Vec<FlowSet>,
64+
}
65+
66+
#[derive(Debug, PartialEq, Eq, Clone, Nom, Serialize)]
67+
pub struct FlowSet {
6068
/// Source IP address; in case of destination-only flows, set to zero.
6169
#[nom(Map = "Ipv4Addr::from", Parse = "be_u32")]
6270
pub src_addr: Ipv4Addr,

src/tests.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ mod tests {
4040
#[cfg(not(feature = "unix_timestamp"))]
4141
fn it_parses_v5() {
4242
let packet = [
43-
0, 5, 2, 0, 3, 0, 4, 0, 5, 0, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3,
43+
0, 5, 0, 1, 3, 0, 4, 0, 5, 0, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3,
4444
4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1,
4545
2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7,
4646
];
@@ -68,7 +68,7 @@ mod tests {
6868
#[cfg(not(feature = "unix_timestamp"))]
6969
fn it_parses_v7() {
7070
let packet = [
71-
0, 7, 2, 0, 3, 0, 4, 0, 5, 0, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3,
71+
0, 7, 0, 1, 3, 0, 4, 0, 5, 0, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3,
7272
4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1,
7373
2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1,
7474
];

0 commit comments

Comments
 (0)